vim-web 0.3.44-dev.69 → 0.3.44-dev.70

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.
@@ -0,0 +1,4 @@
1
+ import { StateRef } from "../helpers/reactUtils";
2
+ export declare function InputNumber(props: {
3
+ state: StateRef<number>;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -74,7 +74,7 @@ export declare function useStateRef<T>(initialValue: T | (() => T)): {
74
74
  * Sets a validation function to process any new state value before updating.
75
75
  * @param on - A function that validates (and optionally transforms) the new state value.
76
76
  */
77
- useValidate(on: (value: T) => T): void;
77
+ useValidate(on: (next: T, current: T) => T): void;
78
78
  /**
79
79
  * Sets a confirmation function to process the state value during confirmation.
80
80
  * @param on - A function that confirms (and optionally transforms) the current state value.
@@ -7,11 +7,15 @@ export interface PanelFieldText extends BasePanelField {
7
7
  type: "text";
8
8
  state: StateRef<string>;
9
9
  }
10
+ export interface PanelFieldNumber extends BasePanelField {
11
+ type: "number";
12
+ state: StateRef<number>;
13
+ }
10
14
  export interface PanelFieldBool extends BasePanelField {
11
15
  type: "bool";
12
16
  state: StateRef<boolean>;
13
17
  }
14
- export type PanelField = PanelFieldText | PanelFieldBool;
18
+ export type PanelField = PanelFieldText | PanelFieldBool | PanelFieldNumber;
15
19
  export interface GenericPanelProps {
16
20
  showPanel: StateRef<boolean>;
17
21
  header?: React.ReactNode;
@@ -16,9 +16,9 @@ export interface SectionBoxRef {
16
16
  sectionBox: ArgActionRef<THREE.Box3>;
17
17
  getBox: () => THREE.Box3;
18
18
  showOffsetPanel: StateRef<boolean>;
19
- topOffset: StateRef<string>;
20
- sideOffset: StateRef<string>;
21
- bottomOffset: StateRef<string>;
19
+ topOffset: StateRef<number>;
20
+ sideOffset: StateRef<number>;
21
+ bottomOffset: StateRef<number>;
22
22
  getSelectionBox: AsyncFuncRef<THREE.Box3 | undefined>;
23
23
  getSceneBox: AsyncFuncRef<THREE.Box3>;
24
24
  }
@@ -8,7 +8,7 @@ export interface IsolationRef {
8
8
  autoIsolate: StateRef<boolean>;
9
9
  showPanel: StateRef<boolean>;
10
10
  showGhost: StateRef<boolean>;
11
- ghostOpacity: StateRef<string>;
11
+ ghostOpacity: StateRef<number>;
12
12
  showRooms: StateRef<boolean>;
13
13
  onAutoIsolate: FuncRef<void>;
14
14
  onVisibilityChange: FuncRef<void>;
@@ -5,7 +5,6 @@ export * from './math3d';
5
5
  export * from './partial';
6
6
  export * from './promise';
7
7
  export * from './result';
8
- export * from './strings';
9
8
  export * from './threeUtils';
10
9
  export * from './url';
11
10
  export * from './validation';
@@ -50741,17 +50741,6 @@ void main() {
50741
50741
  }
50742
50742
  return Math.min(Math.max(value, min2), max2);
50743
50743
  }
50744
- function sanitize(value, strict, fallback) {
50745
- if (!strict) {
50746
- if (value === "" || value === "-") return value;
50747
- }
50748
- const num = parseFloat(value);
50749
- console.log(num);
50750
- if (isNaN(num)) {
50751
- return strict ? fallback.toString() : void 0;
50752
- }
50753
- return String(num);
50754
- }
50755
50744
  function addBox(b1, b2) {
50756
50745
  const r = b1.clone();
50757
50746
  r.min.x += b2.min.x;
@@ -74692,10 +74681,10 @@ Averrage Date/Second ${avgDataRatePS} kb
74692
74681
  }
74693
74682
  }
74694
74683
  const event = React2.useRef(new distExports.SimpleEventDispatcher());
74695
- const validate = React2.useRef((value2) => value2);
74684
+ const validate = React2.useRef((next, current) => next);
74696
74685
  const confirm = React2.useRef((value2) => value2);
74697
74686
  const set2 = (value2) => {
74698
- const finalValue = validate.current(value2);
74687
+ const finalValue = validate.current(value2, ref.current);
74699
74688
  if (finalValue === ref.current) return;
74700
74689
  ref.current = finalValue;
74701
74690
  setValue(finalValue);
@@ -74746,7 +74735,7 @@ Averrage Date/Second ${avgDataRatePS} kb
74746
74735
  * @param on - A function that validates (and optionally transforms) the new state value.
74747
74736
  */
74748
74737
  useValidate(on) {
74749
- set2(on(ref.current));
74738
+ set2(on(ref.current, ref.current));
74750
74739
  React2.useEffect(() => {
74751
74740
  validate.current = on;
74752
74741
  }, []);
@@ -75560,6 +75549,44 @@ Averrage Date/Second ${avgDataRatePS} kb
75560
75549
  return /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingBox, { content: modal });
75561
75550
  }
75562
75551
  }
75552
+ function InputNumber(props) {
75553
+ const defaultValue = React2.useRef(props.state.get());
75554
+ const externalValue = React2.useSyncExternalStore(
75555
+ (callback) => props.state.onChange.subscribe(callback),
75556
+ () => props.state.get()
75557
+ );
75558
+ const [inputValue, setInputValue] = React2.useState(externalValue.toString());
75559
+ React2.useEffect(() => {
75560
+ const parsed = parseFloat(inputValue);
75561
+ if (isNaN(parsed) || parsed !== externalValue) {
75562
+ setInputValue(externalValue.toString());
75563
+ }
75564
+ }, [externalValue]);
75565
+ const handleChange = (e) => {
75566
+ const input = e.target.value;
75567
+ setInputValue(input);
75568
+ const parsed = parseFloat(input);
75569
+ if (!isNaN(parsed)) {
75570
+ props.state.set(parsed);
75571
+ }
75572
+ };
75573
+ const handleBlur = () => {
75574
+ const parsed = parseFloat(inputValue);
75575
+ const value = isNaN(parsed) ? defaultValue.current : parsed;
75576
+ props.state.set(value);
75577
+ setInputValue(props.state.get().toString());
75578
+ };
75579
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
75580
+ "input",
75581
+ {
75582
+ type: "number",
75583
+ value: inputValue,
75584
+ onChange: handleChange,
75585
+ onBlur: handleBlur,
75586
+ className: "vc-border vc-inline vc-border-gray-300 vc-py-1 vc-w-full vc-px-1"
75587
+ }
75588
+ );
75589
+ }
75563
75590
  function GenericPanel(props) {
75564
75591
  const [panelPosition, setPanelPosition] = React2.useState({
75565
75592
  top: 0,
@@ -75584,17 +75611,19 @@ Averrage Date/Second ${avgDataRatePS} kb
75584
75611
  };
75585
75612
  }, [props.showPanel.get()]);
75586
75613
  if (!props.showPanel.get()) return null;
75587
- const createTextBox = (field) => /* @__PURE__ */ jsxRuntimeExports.jsx(
75588
- "input",
75589
- {
75590
- id: field.id,
75591
- type: "text",
75592
- value: field.state.get(),
75593
- onChange: (e) => field.state.set(e.target.value),
75594
- className: "vc-border vc-inline vc-border-gray-300 vc-py-1 vc-w-full vc-px-1",
75595
- onBlur: () => field.state.confirm()
75596
- }
75597
- );
75614
+ const createTextBox = (field) => {
75615
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
75616
+ "input",
75617
+ {
75618
+ id: field.id,
75619
+ type: "number",
75620
+ value: field.state.get(),
75621
+ onChange: (e) => field.state.set(e.target.value),
75622
+ className: "vc-border vc-inline vc-border-gray-300 vc-py-1 vc-w-full vc-px-1",
75623
+ onBlur: () => field.state.confirm()
75624
+ }
75625
+ );
75626
+ };
75598
75627
  const createCheckbox = (field) => /* @__PURE__ */ jsxRuntimeExports.jsx(
75599
75628
  "input",
75600
75629
  {
@@ -75607,7 +75636,9 @@ Averrage Date/Second ${avgDataRatePS} kb
75607
75636
  );
75608
75637
  const renderField = (field) => {
75609
75638
  let fieldElement = null;
75610
- if (field.type === "text") {
75639
+ if (field.type === "number") {
75640
+ fieldElement = /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { state: field.state });
75641
+ } else if (field.type === "text") {
75611
75642
  fieldElement = createTextBox(field);
75612
75643
  } else if (field.type === "bool") {
75613
75644
  fieldElement = createCheckbox(field);
@@ -75678,9 +75709,9 @@ Averrage Date/Second ${avgDataRatePS} kb
75678
75709
  header: "Section Box Offsets",
75679
75710
  showPanel: props.state.showOffsetPanel,
75680
75711
  fields: [
75681
- { type: "text", id: "topOffset", label: "Top Offset", state: props.state.topOffset },
75682
- { type: "text", id: "sideOffset", label: "Side Offset", state: props.state.sideOffset },
75683
- { type: "text", id: "bottomOffset", label: "Bottom Offset", state: props.state.bottomOffset }
75712
+ { type: "number", id: "topOffset", label: "Top Offset", state: props.state.topOffset },
75713
+ { type: "number", id: "sideOffset", label: "Side Offset", state: props.state.sideOffset },
75714
+ { type: "number", id: "bottomOffset", label: "Bottom Offset", state: props.state.bottomOffset }
75684
75715
  ]
75685
75716
  });
75686
75717
  }
@@ -75689,9 +75720,9 @@ Averrage Date/Second ${avgDataRatePS} kb
75689
75720
  const visible2 = useStateRef(false);
75690
75721
  const showOffsetPanel = useStateRef(false);
75691
75722
  const auto = useStateRef(false);
75692
- const topOffset = useStateRef("1");
75693
- const sideOffset = useStateRef("1");
75694
- const bottomOffset = useStateRef("1");
75723
+ const topOffset = useStateRef(1);
75724
+ const sideOffset = useStateRef(1);
75725
+ const bottomOffset = useStateRef(1);
75695
75726
  const boxRef = React2.useRef(adapter.getBox());
75696
75727
  const getSelectionBox = useAsyncFuncRef(adapter.getSelectionBox);
75697
75728
  const getSceneBox = useAsyncFuncRef(adapter.getSceneBox);
@@ -75714,9 +75745,6 @@ Averrage Date/Second ${avgDataRatePS} kb
75714
75745
  });
75715
75746
  visible2.useValidate((v) => enable.get() && v);
75716
75747
  showOffsetPanel.useValidate((v) => enable.get() && v);
75717
- topOffset.useConfirm((v) => sanitize(v, true, 1));
75718
- sideOffset.useConfirm((v) => sanitize(v, true, 1));
75719
- bottomOffset.useConfirm((v) => sanitize(v, true, 1));
75720
75748
  topOffset.useOnChange((v) => sectionBox2.call(boxRef.current));
75721
75749
  sideOffset.useOnChange((v) => sectionBox2.call(boxRef.current));
75722
75750
  bottomOffset.useOnChange((v) => sectionBox2.call(boxRef.current));
@@ -75727,7 +75755,7 @@ Averrage Date/Second ${avgDataRatePS} kb
75727
75755
  const sectionBox2 = useArgActionRef((baseBox) => {
75728
75756
  if (baseBox === void 0) return;
75729
75757
  boxRef.current = baseBox;
75730
- const newBox = addBox(baseBox, offsetsToBox3(topOffset.get(), sideOffset.get(), bottomOffset.get()));
75758
+ const newBox = addBox(baseBox, offsetsToBox3_(topOffset.get(), sideOffset.get(), bottomOffset.get()));
75731
75759
  adapter.setBox(newBox);
75732
75760
  });
75733
75761
  const sectionSelection2 = useFuncRef(async () => {
@@ -75755,14 +75783,10 @@ Averrage Date/Second ${avgDataRatePS} kb
75755
75783
  getSelectionBox
75756
75784
  };
75757
75785
  }
75758
- function offsetsToBox3(top, side, bottom) {
75759
- const getNumber = (s) => {
75760
- const num = parseFloat(s);
75761
- return isNaN(num) ? 0 : num;
75762
- };
75786
+ function offsetsToBox3_(top, side, bottom) {
75763
75787
  return new Box3(
75764
- new Vector3(-getNumber(side), -getNumber(side), -getNumber(bottom)),
75765
- new Vector3(getNumber(side), getNumber(side), getNumber(top))
75788
+ new Vector3(-side, -side, -bottom),
75789
+ new Vector3(side, side, top)
75766
75790
  );
75767
75791
  }
75768
75792
  function useWebglSectionBox(viewer) {
@@ -75853,7 +75877,7 @@ Averrage Date/Second ${avgDataRatePS} kb
75853
75877
  fields: [
75854
75878
  { type: "bool", id: "showGhost", label: "Show Ghost", state: props.state.showGhost },
75855
75879
  // { type: 'bool', id: 'showRooms', label: 'Show Rooms', state: props.state.showRooms },
75856
- { type: "text", id: "ghostOpacity", label: "Ghost Opacity", state: props.state.ghostOpacity }
75880
+ { type: "number", id: "ghostOpacity", label: "Ghost Opacity", state: props.state.ghostOpacity }
75857
75881
  ]
75858
75882
  });
75859
75883
  }
@@ -75864,7 +75888,7 @@ Averrage Date/Second ${avgDataRatePS} kb
75864
75888
  const showPanel = useStateRef(false);
75865
75889
  const showRooms = useStateRef(false);
75866
75890
  const showGhost = useStateRef(false);
75867
- const ghostOpacity = useStateRef(() => adapter.getGhostOpacity().toFixed(4));
75891
+ const ghostOpacity = useStateRef(() => adapter.getGhostOpacity());
75868
75892
  const onAutoIsolate = useFuncRef(() => {
75869
75893
  if (adapter.hasSelection()) {
75870
75894
  adapter.isolateSelection();
@@ -75884,13 +75908,15 @@ Averrage Date/Second ${avgDataRatePS} kb
75884
75908
  if (autoIsolate2.get()) onAutoIsolate.call();
75885
75909
  });
75886
75910
  }, []);
75887
- ghostOpacity.useConfirm((v) => sanitize(v, true, 0.04));
75888
75911
  autoIsolate2.useOnChange((v) => {
75889
75912
  if (v) onAutoIsolate.call();
75890
75913
  });
75891
75914
  showGhost.useOnChange((v) => adapter.showGhost(v));
75892
75915
  showRooms.useOnChange((v) => adapter.setShowRooms(v));
75893
- ghostOpacity.useOnChange((v) => adapter.setGhostOpacity(parseFloat(v)));
75916
+ ghostOpacity.useValidate((next, current) => {
75917
+ return next <= 0 ? current : next;
75918
+ });
75919
+ ghostOpacity.useOnChange((v) => adapter.setGhostOpacity(v));
75894
75920
  return {
75895
75921
  adapter: _adapter,
75896
75922
  visibility,