@solid-labs/fab-one-widget 0.1.9 → 0.1.10

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.
@@ -14,6 +14,8 @@ interface MeasurementStore {
14
14
  setAligned: (aligned: boolean) => void;
15
15
  setCut: (cut: boolean) => void;
16
16
  isSelectionComplete: () => boolean;
17
+ /** Reset the entire store to its initial state */
18
+ reset: () => void;
17
19
  }
18
20
  export declare const useMeasurementStore: import("zustand").UseBoundStore<import("zustand").StoreApi<MeasurementStore>>;
19
21
  export {};
@@ -26,6 +26,16 @@ declare class GirthManagerWidgetElement extends HTMLElement {
26
26
  set wasmModule(value: unknown);
27
27
  connectedCallback(): void;
28
28
  disconnectedCallback(): void;
29
+ /**
30
+ * Reset the widget to its initial state without removing it from the DOM.
31
+ * Unmounts and re-mounts the React tree, clearing all internal state
32
+ * (Zustand store, WASM memory, landmarks, measurements).
33
+ *
34
+ * Usage in Angular:
35
+ * this.widgetEl.nativeElement.reset();
36
+ * this.widgetEl.nativeElement.request = { ... }; // re-initialize
37
+ */
38
+ reset(): void;
29
39
  attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
30
40
  private _handleComplete;
31
41
  private _render;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { G as a, a as c, c as i, g as s } from "./GirthManagerWidget-CaXgi08X.js";
1
+ import { G as a, a as c, c as i, g as s } from "./GirthManagerWidget-4s6WGZUV.js";
2
2
  export {
3
3
  a as GirthManagerWidget,
4
4
  c as arrayToCircumference,
@@ -1,12 +1,12 @@
1
- import { createElement as s } from "react";
2
- import { createRoot as i } from "react-dom/client";
3
- import { G as o } from "./GirthManagerWidget-CaXgi08X.js";
1
+ import { createElement as i } from "react";
2
+ import { createRoot as s } from "react-dom/client";
3
+ import { G as o } from "./GirthManagerWidget-4s6WGZUV.js";
4
4
  class n extends HTMLElement {
5
5
  constructor() {
6
- super(...arguments), this._root = null, this._request = null, this._wasmModule = void 0, this._handleComplete = (e) => {
6
+ super(...arguments), this._root = null, this._request = null, this._wasmModule = void 0, this._handleComplete = (t) => {
7
7
  this.dispatchEvent(
8
8
  new CustomEvent("widgetComplete", {
9
- detail: e,
9
+ detail: t,
10
10
  bubbles: true,
11
11
  composed: true
12
12
  })
@@ -19,28 +19,28 @@ class n extends HTMLElement {
19
19
  get request() {
20
20
  return this._request;
21
21
  }
22
- set request(e) {
23
- if (typeof e == "string")
22
+ set request(t) {
23
+ if (typeof t == "string")
24
24
  try {
25
- this._request = JSON.parse(e);
25
+ this._request = JSON.parse(t);
26
26
  } catch {
27
- console.error("[GirthManagerWidget] Invalid JSON for request attribute:", e);
27
+ console.error("[GirthManagerWidget] Invalid JSON for request attribute:", t);
28
28
  return;
29
29
  }
30
30
  else
31
- this._request = e;
31
+ this._request = t;
32
32
  this._render();
33
33
  }
34
34
  /** Set the pre-loaded WASM v2 module (geo-wasm). Must be set before or alongside request. */
35
35
  get wasmModule() {
36
36
  return this._wasmModule;
37
37
  }
38
- set wasmModule(e) {
39
- this._wasmModule = e, this._render();
38
+ set wasmModule(t) {
39
+ this._wasmModule = t, this._render();
40
40
  }
41
41
  connectedCallback() {
42
- const e = this.attachShadow({ mode: "open" }), t = document.createElement("div");
43
- t.style.width = "100%", t.style.height = "100%", e.appendChild(t), this._root = i(t);
42
+ const t = this.attachShadow({ mode: "open" }), e = document.createElement("div");
43
+ e.style.width = "100%", e.style.height = "100%", t.appendChild(e), this._root = s(e);
44
44
  const r = this.getAttribute("request");
45
45
  if (r && !this._request)
46
46
  try {
@@ -54,8 +54,24 @@ class n extends HTMLElement {
54
54
  var _a;
55
55
  (_a = this._root) == null ? void 0 : _a.unmount(), this._root = null;
56
56
  }
57
- attributeChangedCallback(e, t, r) {
58
- if (e === "request" && r)
57
+ /**
58
+ * Reset the widget to its initial state without removing it from the DOM.
59
+ * Unmounts and re-mounts the React tree, clearing all internal state
60
+ * (Zustand store, WASM memory, landmarks, measurements).
61
+ *
62
+ * Usage in Angular:
63
+ * this.widgetEl.nativeElement.reset();
64
+ * this.widgetEl.nativeElement.request = { ... }; // re-initialize
65
+ */
66
+ reset() {
67
+ var _a;
68
+ if (!this._root) return;
69
+ this._root.unmount();
70
+ const t = (_a = this.shadowRoot) == null ? void 0 : _a.querySelector("div");
71
+ t && (this._root = s(t)), this._request = null, this._wasmModule = void 0;
72
+ }
73
+ attributeChangedCallback(t, e, r) {
74
+ if (t === "request" && r)
59
75
  try {
60
76
  this._request = JSON.parse(r), this._render();
61
77
  } catch {
@@ -64,7 +80,7 @@ class n extends HTMLElement {
64
80
  }
65
81
  _render() {
66
82
  !this._root || !this._request || this._root.render(
67
- s(o, {
83
+ i(o, {
68
84
  request: this._request,
69
85
  onComplete: this._handleComplete,
70
86
  wasmModule: this._wasmModule
@@ -1 +1 @@
1
- {"version":3,"file":"web-component.js","sources":["../src/web-component.ts"],"sourcesContent":["import { createElement } from \"react\"\nimport { createRoot, type Root } from \"react-dom/client\"\nimport { GirthManagerWidget } from \"./GirthManagerWidget\"\nimport type { WidgetRequest, WidgetResponse } from \"./types\"\n\n/**\n * Custom Element wrapper for Angular integration.\n *\n * Usage in Angular:\n * // In the component class:\n * async ngAfterViewInit() {\n * const wasm = await import('geo-wasm');\n * await wasm.default();\n * this.widgetEl.nativeElement.wasmModule = wasm;\n * this.widgetEl.nativeElement.request = { spacing_type: 'BK', scan_url: '...' };\n * }\n *\n * // In the template:\n * <girth-manager-widget #widgetEl (widgetComplete)=\"onComplete($event)\"></girth-manager-widget>\n */\nclass GirthManagerWidgetElement extends HTMLElement {\n private _root: Root | null = null\n private _request: WidgetRequest | null = null\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _wasmModule: any = undefined\n\n static get observedAttributes() {\n return [\"request\"]\n }\n\n get request(): WidgetRequest | null {\n return this._request\n }\n\n set request(value: WidgetRequest | string | null) {\n if (typeof value === \"string\") {\n try {\n this._request = JSON.parse(value)\n } catch {\n console.error(\"[GirthManagerWidget] Invalid JSON for request attribute:\", value)\n return\n }\n } else {\n this._request = value\n }\n this._render()\n }\n\n /** Set the pre-loaded WASM v2 module (geo-wasm). Must be set before or alongside request. */\n get wasmModule() {\n return this._wasmModule\n }\n\n set wasmModule(value: unknown) {\n this._wasmModule = value\n this._render()\n }\n\n connectedCallback() {\n const shadow = this.attachShadow({ mode: \"open\" })\n const container = document.createElement(\"div\")\n container.style.width = \"100%\"\n container.style.height = \"100%\"\n shadow.appendChild(container)\n this._root = createRoot(container)\n\n // Parse request from attribute if set before connection\n const attrValue = this.getAttribute(\"request\")\n if (attrValue && !this._request) {\n try {\n this._request = JSON.parse(attrValue)\n } catch {\n console.error(\"[GirthManagerWidget] Invalid JSON in request attribute\")\n }\n }\n\n this._render()\n }\n\n disconnectedCallback() {\n this._root?.unmount()\n this._root = null\n }\n\n attributeChangedCallback(name: string, _oldValue: string, newValue: string) {\n if (name === \"request\" && newValue) {\n try {\n this._request = JSON.parse(newValue)\n this._render()\n } catch {\n console.error(\"[GirthManagerWidget] Invalid JSON in request attribute\")\n }\n }\n }\n\n private _handleComplete = (response: WidgetResponse) => {\n this.dispatchEvent(\n new CustomEvent(\"widgetComplete\", {\n detail: response,\n bubbles: true,\n composed: true,\n })\n )\n }\n\n private _render() {\n if (!this._root || !this._request) return\n\n this._root.render(\n createElement(GirthManagerWidget, {\n request: this._request,\n onComplete: this._handleComplete,\n wasmModule: this._wasmModule,\n })\n )\n }\n}\n\n// Register the custom element\nif (!customElements.get(\"girth-manager-widget\")) {\n customElements.define(\"girth-manager-widget\", GirthManagerWidgetElement)\n}\n\nexport { GirthManagerWidgetElement }\nexport type { WidgetRequest, WidgetResponse }\n"],"names":["GirthManagerWidgetElement","response","value","shadow","container","createRoot","attrValue","name","_oldValue","newValue","createElement","GirthManagerWidget"],"mappings":";;;AAoBA,MAAMA,UAAkC,YAAY;AAAA,EAApD,cAAA;AAAA,UAAA,GAAA,SAAA,GACI,KAAQ,QAAqB,MAC7B,KAAQ,WAAiC,MAEzC,KAAQ,cA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C,GAAkB;AACxE,QAAIF,MAAS,aAAaE;AACtB,UAAI;AACA,aAAK,WAAW,KAAK,MAAMA,CAAQ,GACnC,KAAK,QAAA;AAAA,MACT,QAAQ;AACJ,gBAAQ,MAAM,wDAAwD;AAAA,MAC1E;AAAA,EAER;AAAA,EAYQ,UAAU;AACd,IAAI,CAAC,KAAK,SAAS,CAAC,KAAK,YAEzB,KAAK,MAAM;AAAA,MACPC,EAAcC,GAAoB;AAAA,QAC9B,SAAS,KAAK;AAAA,QACd,YAAY,KAAK;AAAA,QACjB,YAAY,KAAK;AAAA,MAAA,CACpB;AAAA,IAAA;AAAA,EAET;AACJ;AAGK,eAAe,IAAI,sBAAsB,KAC1C,eAAe,OAAO,wBAAwBX,CAAyB;"}
1
+ {"version":3,"file":"web-component.js","sources":["../src/web-component.ts"],"sourcesContent":["import { createElement } from \"react\"\nimport { createRoot, type Root } from \"react-dom/client\"\nimport { GirthManagerWidget } from \"./GirthManagerWidget\"\nimport type { WidgetRequest, WidgetResponse } from \"./types\"\n\n/**\n * Custom Element wrapper for Angular integration.\n *\n * Usage in Angular:\n * // In the component class:\n * async ngAfterViewInit() {\n * const wasm = await import('geo-wasm');\n * await wasm.default();\n * this.widgetEl.nativeElement.wasmModule = wasm;\n * this.widgetEl.nativeElement.request = { spacing_type: 'BK', scan_url: '...' };\n * }\n *\n * // In the template:\n * <girth-manager-widget #widgetEl (widgetComplete)=\"onComplete($event)\"></girth-manager-widget>\n */\nclass GirthManagerWidgetElement extends HTMLElement {\n private _root: Root | null = null\n private _request: WidgetRequest | null = null\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _wasmModule: any = undefined\n\n static get observedAttributes() {\n return [\"request\"]\n }\n\n get request(): WidgetRequest | null {\n return this._request\n }\n\n set request(value: WidgetRequest | string | null) {\n if (typeof value === \"string\") {\n try {\n this._request = JSON.parse(value)\n } catch {\n console.error(\"[GirthManagerWidget] Invalid JSON for request attribute:\", value)\n return\n }\n } else {\n this._request = value\n }\n this._render()\n }\n\n /** Set the pre-loaded WASM v2 module (geo-wasm). Must be set before or alongside request. */\n get wasmModule() {\n return this._wasmModule\n }\n\n set wasmModule(value: unknown) {\n this._wasmModule = value\n this._render()\n }\n\n connectedCallback() {\n const shadow = this.attachShadow({ mode: \"open\" })\n const container = document.createElement(\"div\")\n container.style.width = \"100%\"\n container.style.height = \"100%\"\n shadow.appendChild(container)\n this._root = createRoot(container)\n\n // Parse request from attribute if set before connection\n const attrValue = this.getAttribute(\"request\")\n if (attrValue && !this._request) {\n try {\n this._request = JSON.parse(attrValue)\n } catch {\n console.error(\"[GirthManagerWidget] Invalid JSON in request attribute\")\n }\n }\n\n this._render()\n }\n\n disconnectedCallback() {\n this._root?.unmount()\n this._root = null\n }\n\n /**\n * Reset the widget to its initial state without removing it from the DOM.\n * Unmounts and re-mounts the React tree, clearing all internal state\n * (Zustand store, WASM memory, landmarks, measurements).\n *\n * Usage in Angular:\n * this.widgetEl.nativeElement.reset();\n * this.widgetEl.nativeElement.request = { ... }; // re-initialize\n */\n reset() {\n if (!this._root) return\n // Unmount the current React tree (clears all component state)\n this._root.unmount()\n // Re-create the root on the same container\n const container = this.shadowRoot?.querySelector(\"div\")\n if (container) {\n this._root = createRoot(container)\n }\n this._request = null\n this._wasmModule = undefined\n }\n\n attributeChangedCallback(name: string, _oldValue: string, newValue: string) {\n if (name === \"request\" && newValue) {\n try {\n this._request = JSON.parse(newValue)\n this._render()\n } catch {\n console.error(\"[GirthManagerWidget] Invalid JSON in request attribute\")\n }\n }\n }\n\n private _handleComplete = (response: WidgetResponse) => {\n this.dispatchEvent(\n new CustomEvent(\"widgetComplete\", {\n detail: response,\n bubbles: true,\n composed: true,\n })\n )\n }\n\n private _render() {\n if (!this._root || !this._request) return\n\n this._root.render(\n createElement(GirthManagerWidget, {\n request: this._request,\n onComplete: this._handleComplete,\n wasmModule: this._wasmModule,\n })\n )\n }\n}\n\n// Register the custom element\nif (!customElements.get(\"girth-manager-widget\")) {\n customElements.define(\"girth-manager-widget\", GirthManagerWidgetElement)\n}\n\nexport { GirthManagerWidgetElement }\nexport type { WidgetRequest, WidgetResponse }\n"],"names":["GirthManagerWidgetElement","response","value","shadow","container","createRoot","attrValue","name","_oldValue","newValue","createElement","GirthManagerWidget"],"mappings":";;;AAoBA,MAAMA,UAAkC,YAAY;AAAA,EAApD,cAAA;AAAA,UAAA,GAAA,SAAA,GACI,KAAQ,QAAqB,MAC7B,KAAQ,WAAiC,MAEzC,KAAQ,cAAmB,QA6F3B,KAAQ,kBAAkB,CAACC,MAA6B;AACpD,WAAK;AAAA,QACD,IAAI,YAAY,kBAAkB;AAAA,UAC9B,QAAQA;AAAA,UACR,SAAS;AAAA,UACT,UAAU;AAAA,QAAA,CACb;AAAA,MAAA;AAAA,IAET;AAAA,EAAA;AAAA,EAnGA,WAAW,qBAAqB;AAC5B,WAAO,CAAC,SAAS;AAAA,EACrB;AAAA,EAEA,IAAI,UAAgC;AAChC,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,QAAQC,GAAsC;AAC9C,QAAI,OAAOA,KAAU;AACjB,UAAI;AACA,aAAK,WAAW,KAAK,MAAMA,CAAK;AAAA,MACpC,QAAQ;AACJ,gBAAQ,MAAM,4DAA4DA,CAAK;AAC/E;AAAA,MACJ;AAAA;AAEA,WAAK,WAAWA;AAEpB,SAAK,QAAA;AAAA,EACT;AAAA;AAAA,EAGA,IAAI,aAAa;AACb,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,WAAWA,GAAgB;AAC3B,SAAK,cAAcA,GACnB,KAAK,QAAA;AAAA,EACT;AAAA,EAEA,oBAAoB;AAChB,UAAMC,IAAS,KAAK,aAAa,EAAE,MAAM,QAAQ,GAC3CC,IAAY,SAAS,cAAc,KAAK;AAC9C,IAAAA,EAAU,MAAM,QAAQ,QACxBA,EAAU,MAAM,SAAS,QACzBD,EAAO,YAAYC,CAAS,GAC5B,KAAK,QAAQC,EAAWD,CAAS;AAGjC,UAAME,IAAY,KAAK,aAAa,SAAS;AAC7C,QAAIA,KAAa,CAAC,KAAK;AACnB,UAAI;AACA,aAAK,WAAW,KAAK,MAAMA,CAAS;AAAA,MACxC,QAAQ;AACJ,gBAAQ,MAAM,wDAAwD;AAAA,MAC1E;AAGJ,SAAK,QAAA;AAAA,EACT;AAAA,EAEA,uBAAuB;AACnB,SAAK,OAAO,QAAA,GACZ,KAAK,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,QAAQ;AACJ,QAAI,CAAC,KAAK,MAAO;AAEjB,SAAK,MAAM,QAAA;AAEX,UAAMF,IAAY,KAAK,YAAY,cAAc,KAAK;AACtD,IAAIA,MACA,KAAK,QAAQC,EAAWD,CAAS,IAErC,KAAK,WAAW,MAChB,KAAK,cAAc;AAAA,EACvB;AAAA,EAEA,yBAAyBG,GAAcC,GAAmBC,GAAkB;AACxE,QAAIF,MAAS,aAAaE;AACtB,UAAI;AACA,aAAK,WAAW,KAAK,MAAMA,CAAQ,GACnC,KAAK,QAAA;AAAA,MACT,QAAQ;AACJ,gBAAQ,MAAM,wDAAwD;AAAA,MAC1E;AAAA,EAER;AAAA,EAYQ,UAAU;AACd,IAAI,CAAC,KAAK,SAAS,CAAC,KAAK,YAEzB,KAAK,MAAM;AAAA,MACPC,EAAcC,GAAoB;AAAA,QAC9B,SAAS,KAAK;AAAA,QACd,YAAY,KAAK;AAAA,QACjB,YAAY,KAAK;AAAA,MAAA,CACpB;AAAA,IAAA;AAAA,EAET;AACJ;AAGK,eAAe,IAAI,sBAAsB,KAC1C,eAAe,OAAO,wBAAwBX,CAAyB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-labs/fab-one-widget",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/girth-manager-web-widget/src/index.d.ts",