vim-web 1.0.0-alpha.7 → 1.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vim-web.js CHANGED
@@ -74053,8 +74053,6 @@ class MutableState {
74053
74053
  this._value = value;
74054
74054
  this._onChange.dispatch(value);
74055
74055
  }
74056
- confirm() {
74057
- }
74058
74056
  get onChange() {
74059
74057
  return this._onChange.asEvent();
74060
74058
  }
@@ -74092,7 +74090,6 @@ function useStateRef(initialValue, isLazy = false, storageKey) {
74092
74090
  }
74093
74091
  const event = useRef(new distExports.SimpleEventDispatcher());
74094
74092
  const validate = useRef((next, current) => next);
74095
- const confirm = useRef((value) => value);
74096
74093
  const set3 = (value) => {
74097
74094
  const finalValue = validate.current(value, ref.current);
74098
74095
  if (finalValue === ref.current) return;
@@ -74110,12 +74107,6 @@ function useStateRef(initialValue, isLazy = false, storageKey) {
74110
74107
  },
74111
74108
  set: set3,
74112
74109
  onChange: event.current.asEvent(),
74113
- /**
74114
- * Confirms the current state by applying the confirm function and updating the state.
74115
- */
74116
- confirm() {
74117
- set3(confirm.current(ref.current));
74118
- },
74119
74110
  /**
74120
74111
  * Registers a callback to be invoked when the state changes.
74121
74112
  * Accepts a sync function, a cleanup function, or a function returning a Promise<void> (which will be ignored).
@@ -74159,15 +74150,6 @@ function useStateRef(initialValue, isLazy = false, storageKey) {
74159
74150
  useEffect(() => {
74160
74151
  validate.current = on;
74161
74152
  }, []);
74162
- },
74163
- /**
74164
- * Sets a confirmation function to process the state value during confirmation.
74165
- * @param on - A function that confirms (and optionally transforms) the current state value.
74166
- */
74167
- useConfirm(on) {
74168
- useEffect(() => {
74169
- confirm.current = on;
74170
- }, []);
74171
74153
  }
74172
74154
  };
74173
74155
  }
@@ -80019,8 +80001,7 @@ function GenericTextField(props) {
80019
80001
  onChange: (e) => {
80020
80002
  refresher.refresh();
80021
80003
  props.state.set(e.target.value);
80022
- },
80023
- onBlur: () => props.state.confirm()
80004
+ }
80024
80005
  }
80025
80006
  );
80026
80007
  }
@@ -84347,7 +84328,7 @@ const BimTree = forwardRef((props, ref) => {
84347
84328
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
84348
84329
  ControlledTreeEnvironment,
84349
84330
  {
84350
- renderDepthOffset: div.current ? Math.min(div.current.clientWidth * 0.04, 10) : 10,
84331
+ renderDepthOffset: 10,
84351
84332
  items: props.treeData.nodes,
84352
84333
  getItemTitle: (item) => item.title,
84353
84334
  showLiveDescription: false,
@@ -87164,7 +87145,7 @@ function getDefaultSettings() {
87164
87145
  },
87165
87146
  isolation: {
87166
87147
  autoIsolate: false,
87167
- showGhost: false,
87148
+ showGhost: true,
87168
87149
  transparency: true,
87169
87150
  showRooms: false
87170
87151
  },
@@ -87360,19 +87341,12 @@ function getIsolationSettings(isolation) {
87360
87341
  }
87361
87342
  ];
87362
87343
  }
87363
- function makeInitialUiState(ui) {
87364
- return Object.fromEntries(
87365
- Object.entries(ui).map(([k, v]) => [k, isTrue(v)])
87366
- );
87367
- }
87368
- function tog(id2, label, key, src, uiState, setUiKey) {
87344
+ function tog(id2, label, key, src, refs) {
87369
87345
  if (src[key] === "AlwaysTrue" || src[key] === "AlwaysFalse") return [];
87370
- const state = createState(uiState[key]);
87371
- state.onChange.subscribe((v) => setUiKey(key, v));
87372
- return [{ type: "bool", id: id2, label, state }];
87346
+ return [{ type: "bool", id: id2, label, state: refs[key] }];
87373
87347
  }
87374
- function getWebglSettingsContent(viewer, isolation, uiState, setUiKey, srcUi) {
87375
- const t = (id2, label, key) => tog(id2, label, key, srcUi, uiState, setUiKey);
87348
+ function getWebglSettingsContent(viewer, isolation, refs, srcUi) {
87349
+ const t = (id2, label, key) => tog(id2, label, key, srcUi, refs);
87376
87350
  const scrollSpeedState = createState(viewer.inputs.scrollSpeed);
87377
87351
  scrollSpeedState.onChange.subscribe((v) => {
87378
87352
  viewer.inputs.scrollSpeed = v;
@@ -87433,6 +87407,110 @@ function getWebglSettingsContent(viewer, isolation, uiState, setUiKey, srcUi) {
87433
87407
  ...t(SettingsPanelKeys.ControlBarMiscShowMaximiseButtonToggle, "Maximise", "miscMaximise")
87434
87408
  ];
87435
87409
  }
87410
+ function useWebglUiState(initialSettings) {
87411
+ const { refs, values } = useUiRefs(initialSettings);
87412
+ const ui = useMemo(() => ({
87413
+ // Panels
87414
+ logo: refs.panelLogo,
87415
+ controlBar: refs.panelControlBar,
87416
+ bimTree: refs.panelBimTree,
87417
+ bimInfo: refs.panelBimInfo,
87418
+ axes: refs.panelAxes,
87419
+ performance: refs.panelPerformance,
87420
+ // Axes panel
87421
+ axesOrthographic: refs.axesOrthographic,
87422
+ axesHome: refs.axesHome,
87423
+ // Cursors
87424
+ cursorOrbit: refs.cursorOrbit,
87425
+ cursorLookAround: refs.cursorLookAround,
87426
+ cursorPan: refs.cursorPan,
87427
+ cursorZoom: refs.cursorZoom,
87428
+ // Camera
87429
+ cameraAuto: refs.cameraAuto,
87430
+ cameraFrameScene: refs.cameraFrameScene,
87431
+ cameraFrameSelection: refs.cameraFrameSelection,
87432
+ // Section box
87433
+ sectioningEnable: refs.sectioningEnable,
87434
+ sectioningFitToSelection: refs.sectioningFitToSelection,
87435
+ sectioningReset: refs.sectioningReset,
87436
+ sectioningShow: refs.sectioningShow,
87437
+ sectioningAuto: refs.sectioningAuto,
87438
+ sectioningSettings: refs.sectioningSettings,
87439
+ // Measure
87440
+ measureEnable: refs.measureEnable,
87441
+ // Visibility
87442
+ visibilityClearSelection: refs.visibilityClearSelection,
87443
+ visibilityShowAll: refs.visibilityShowAll,
87444
+ visibilityToggle: refs.visibilityToggle,
87445
+ visibilityIsolate: refs.visibilityIsolate,
87446
+ visibilityAutoIsolate: refs.visibilityAutoIsolate,
87447
+ visibilitySettings: refs.visibilitySettings,
87448
+ // Misc
87449
+ miscProjectInspector: refs.miscProjectInspector,
87450
+ miscSettings: refs.miscSettings,
87451
+ miscHelp: refs.miscHelp,
87452
+ miscMaximise: refs.miscMaximise
87453
+ }), []);
87454
+ return { ui, refs, uiValues: values };
87455
+ }
87456
+ function useUltraUiState(initialSettings) {
87457
+ const { refs, values } = useUiRefs(initialSettings);
87458
+ const ui = useMemo(() => ({
87459
+ // Panels
87460
+ logo: refs.panelLogo,
87461
+ controlBar: refs.panelControlBar,
87462
+ // Cursors
87463
+ cursorOrbit: refs.cursorOrbit,
87464
+ cursorLookAround: refs.cursorLookAround,
87465
+ cursorPan: refs.cursorPan,
87466
+ cursorZoom: refs.cursorZoom,
87467
+ // Camera
87468
+ cameraAuto: refs.cameraAuto,
87469
+ cameraFrameScene: refs.cameraFrameScene,
87470
+ cameraFrameSelection: refs.cameraFrameSelection,
87471
+ // Section box
87472
+ sectioningEnable: refs.sectioningEnable,
87473
+ sectioningFitToSelection: refs.sectioningFitToSelection,
87474
+ sectioningReset: refs.sectioningReset,
87475
+ sectioningShow: refs.sectioningShow,
87476
+ sectioningAuto: refs.sectioningAuto,
87477
+ sectioningSettings: refs.sectioningSettings,
87478
+ // Visibility
87479
+ visibilityClearSelection: refs.visibilityClearSelection,
87480
+ visibilityShowAll: refs.visibilityShowAll,
87481
+ visibilityToggle: refs.visibilityToggle,
87482
+ visibilityIsolate: refs.visibilityIsolate,
87483
+ visibilityAutoIsolate: refs.visibilityAutoIsolate,
87484
+ visibilitySettings: refs.visibilitySettings,
87485
+ // Misc
87486
+ miscSettings: refs.miscSettings,
87487
+ miscHelp: refs.miscHelp
87488
+ }), []);
87489
+ return { ui, refs, uiValues: values };
87490
+ }
87491
+ function useUiRefs(initialSettings) {
87492
+ const [values, setValues] = useState(
87493
+ () => Object.fromEntries(
87494
+ Object.entries(initialSettings).map(([k, v]) => [k, isTrue(v)])
87495
+ )
87496
+ );
87497
+ const refs = useMemo(() => {
87498
+ const result = {};
87499
+ for (const [key, initial] of Object.entries(initialSettings)) {
87500
+ result[key] = createState(isTrue(initial));
87501
+ }
87502
+ return result;
87503
+ }, []);
87504
+ useEffect(() => {
87505
+ const unsubs = Object.keys(refs).map(
87506
+ (key) => refs[key].onChange.subscribe((v) => {
87507
+ setValues((prev) => ({ ...prev, [key]: v }));
87508
+ })
87509
+ );
87510
+ return () => unsubs.forEach((u) => u());
87511
+ }, []);
87512
+ return { refs, values };
87513
+ }
87436
87514
  function createWebglViewer(container, settings2 = {}, coreSettings = {}) {
87437
87515
  const cmpContainer = container instanceof HTMLElement ? createContainer(container) : container ?? createContainer();
87438
87516
  const viewer = createCoreWebglViewer(coreSettings);
@@ -87464,8 +87542,7 @@ function createWebglViewer(container, settings2 = {}, coreSettings = {}) {
87464
87542
  const WebglViewerComponent = forwardRef((props, ref) => {
87465
87543
  const settings2 = createSettings(props.settings ?? {}, getDefaultSettings());
87466
87544
  const modal = useRef(null);
87467
- const [uiState, setUiState] = useState(() => makeInitialUiState(settings2.ui));
87468
- const setUiKey = (key, value) => setUiState((prev) => ({ ...prev, [key]: value }));
87545
+ const { ui: uiApi, refs: uiRefs, uiValues: uiState } = useWebglUiState(settings2.ui);
87469
87546
  const effectiveSettings = { ...settings2, ui: { ...settings2.ui, ...uiState } };
87470
87547
  useEffect(() => {
87471
87548
  if (!settings2.capacity.canReadLocalStorage) disableLocalStorage();
@@ -87518,6 +87595,7 @@ const WebglViewerComponent = forwardRef((props, ref) => {
87518
87595
  return modal.current;
87519
87596
  },
87520
87597
  bimInfo: bimInfoRef,
87598
+ ui: uiApi,
87521
87599
  dispose: () => {
87522
87600
  }
87523
87601
  }), []);
@@ -87547,7 +87625,7 @@ const WebglViewerComponent = forwardRef((props, ref) => {
87547
87625
  SettingsPanel,
87548
87626
  {
87549
87627
  visible: side.getContent() === "settings",
87550
- content: getWebglSettingsContent(props.viewer, isolationRef, uiState, setUiKey, settings2.ui)
87628
+ content: getWebglSettingsContent(props.viewer, isolationRef, uiRefs, settings2.ui)
87551
87629
  }
87552
87630
  )
87553
87631
  ] });
@@ -87954,6 +88032,7 @@ async function createUltraViewer(container, settings2) {
87954
88032
  }
87955
88033
  const UltraViewerComponent = forwardRef((props, ref) => {
87956
88034
  const settings2 = createSettings(props.settings ?? {}, getDefaultUltraSettings());
88035
+ const { ui: uiApi, uiValues: uiState } = useUltraUiState(settings2.ui);
87957
88036
  const sectionBoxRef = useUltraSectionBox(props.core, settings2.sectionBox);
87958
88037
  const framing = useUltraFraming(props.core, sectionBoxRef, settings2.camera.autoCamera);
87959
88038
  const isolationPanelHandle = useRef(null);
@@ -87993,6 +88072,7 @@ const UltraViewerComponent = forwardRef((props, ref) => {
87993
88072
  },
87994
88073
  dispose: () => {
87995
88074
  },
88075
+ ui: uiApi,
87996
88076
  controlBar: controlBarApi,
87997
88077
  load: patchLoad(props.core, modalHandle),
87998
88078
  unload: (vim) => props.core.unload(vim)
@@ -88024,13 +88104,13 @@ const UltraViewerComponent = forwardRef((props, ref) => {
88024
88104
  ),
88025
88105
  /* @__PURE__ */ jsxRuntimeExports.jsx(RestOfScreen, { side, content: () => {
88026
88106
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
88027
- whenTrue(settings2.ui.panelLogo, /* @__PURE__ */ jsxRuntimeExports.jsx(LogoMemo, {})),
88107
+ uiState.panelLogo && /* @__PURE__ */ jsxRuntimeExports.jsx(LogoMemo, {}),
88028
88108
  /* @__PURE__ */ jsxRuntimeExports.jsx(Overlay, { canvas: props.core.viewport.canvas }),
88029
88109
  /* @__PURE__ */ jsxRuntimeExports.jsx(
88030
88110
  ControlBar,
88031
88111
  {
88032
88112
  content: controlBar,
88033
- show: isTrue(settings2.ui.panelControlBar)
88113
+ show: uiState.panelControlBar
88034
88114
  }
88035
88115
  ),
88036
88116
  /* @__PURE__ */ jsxRuntimeExports.jsx(SectionBoxPanel$1, { ref: sectionBoxPanelHandle, state: sectionBoxRef }),