@helpai/elements 0.7.0 → 0.7.1

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/index.mjs CHANGED
@@ -884,10 +884,11 @@ function pickInitialPanelSize(mode, size, viewportWidth) {
884
884
  }
885
885
  return "normal";
886
886
  }
887
- function resolveInitialPanelState(options, viewportWidth, persistedPanelOpen) {
887
+ function resolveInitialPanelState(options, viewportWidth, persistedPanelOpen, persistedPanelSize = null) {
888
888
  const isInlineLike = options.mode === "inline" || options.mode === "standalone" || options.mode === "page";
889
889
  const panelOpen = isInlineLike || (persistedPanelOpen ?? !options.startMinimized);
890
- const panelSize = pickInitialPanelSize(options.mode, options.size, viewportWidth);
890
+ const honorsPersisted = options.mode !== "standalone" && options.mode !== "page" && options.mode !== "inline";
891
+ const panelSize = honorsPersisted && persistedPanelSize ? persistedPanelSize : pickInitialPanelSize(options.mode, options.size, viewportWidth);
891
892
  return { panelOpen, panelSize };
892
893
  }
893
894
  function currentViewportWidth() {
@@ -1810,6 +1811,7 @@ function createPersistence(widgetId, storage = defaultStorage) {
1810
1811
  const KEY_CHAT = `${prefix}.sessionId`;
1811
1812
  const KEY_USER_PREFS = `${prefix}.userPrefs`;
1812
1813
  const KEY_PANEL_OPEN = `${prefix}.panelOpen`;
1814
+ const KEY_PANEL_SIZE = `${prefix}.panelSize`;
1813
1815
  const KEY_CALLOUT_DISMISSED = `${prefix}.calloutDismissed`;
1814
1816
  const KEY_SIDEBAR_COLLAPSED = `${prefix}.sidebarCollapsed`;
1815
1817
  const KEY_ACTIVE_MODULE = `${prefix}.activeModule`;
@@ -1864,6 +1866,13 @@ function createPersistence(widgetId, storage = defaultStorage) {
1864
1866
  savePanelOpen(open) {
1865
1867
  storage.set(KEY_PANEL_OPEN, open ? "1" : "0");
1866
1868
  },
1869
+ loadPanelSize() {
1870
+ const raw = storage.get(KEY_PANEL_SIZE);
1871
+ return raw === "normal" || raw === "expanded" || raw === "fullscreen" ? raw : null;
1872
+ },
1873
+ savePanelSize(size) {
1874
+ storage.set(KEY_PANEL_SIZE, size);
1875
+ },
1867
1876
  loadCalloutDismissed(currentText) {
1868
1877
  if (!currentText) return false;
1869
1878
  const dismissedText = storage.get(KEY_CALLOUT_DISMISSED);
@@ -5218,7 +5227,7 @@ function App({ options, hostElement, bus }) {
5218
5227
  const [sessionReady, setSessionReady] = useState11(false);
5219
5228
  const isInlineLike = options.mode === "standalone" || options.mode === "inline";
5220
5229
  const initialPanelRef = useRef8(
5221
- resolveInitialPanelState(options, currentViewportWidth(), persistence.loadPanelOpen())
5230
+ resolveInitialPanelState(options, currentViewportWidth(), persistence.loadPanelOpen(), persistence.loadPanelSize())
5222
5231
  );
5223
5232
  const [isOpen, setIsOpen] = useState11(initialPanelRef.current.panelOpen);
5224
5233
  const initialPanelApplied = useRef8(false);
@@ -5289,13 +5298,19 @@ function App({ options, hostElement, bus }) {
5289
5298
  }, [feedback, patchAndSync]);
5290
5299
  useEffect17(() => {
5291
5300
  if (initialSizeApplied.current || !options.size.initialSize) return;
5292
- setPanelSize(pickInitialPanelSize(options.mode, options.size, currentViewportWidth()));
5293
5301
  initialSizeApplied.current = true;
5294
- }, [options.mode, options.size]);
5302
+ if (persistence.loadPanelSize()) return;
5303
+ setPanelSize(pickInitialPanelSize(options.mode, options.size, currentViewportWidth()));
5304
+ }, [options.mode, options.size, persistence]);
5295
5305
  useEffect17(() => {
5296
5306
  if (!sessionReady || initialPanelApplied.current) return;
5297
5307
  initialPanelApplied.current = true;
5298
- const state = resolveInitialPanelState(options, currentViewportWidth(), persistence.loadPanelOpen());
5308
+ const state = resolveInitialPanelState(
5309
+ options,
5310
+ currentViewportWidth(),
5311
+ persistence.loadPanelOpen(),
5312
+ persistence.loadPanelSize()
5313
+ );
5299
5314
  setIsOpen(state.panelOpen);
5300
5315
  setPanelSize(state.panelSize);
5301
5316
  }, [sessionReady, options, persistence]);
@@ -5591,17 +5606,19 @@ function App({ options, hostElement, bus }) {
5591
5606
  if (chatId) homeNav.switchTab(chatId);
5592
5607
  }, [handleClear, homeNav, options]);
5593
5608
  const handleExpand = useCallback8(() => {
5594
- const next = panelSize !== "expanded";
5595
- log16.info("expand", { from: panelSize, expanded: next });
5596
- setPanelSize((s) => s === "expanded" ? "normal" : "expanded");
5597
- bus.emit("expand", next);
5598
- }, [bus, panelSize]);
5609
+ const nextSize = panelSize === "expanded" ? "normal" : "expanded";
5610
+ log16.info("expand", { from: panelSize, expanded: nextSize === "expanded" });
5611
+ setPanelSize(nextSize);
5612
+ persistence.savePanelSize(nextSize);
5613
+ bus.emit("expand", nextSize === "expanded");
5614
+ }, [bus, panelSize, persistence]);
5599
5615
  const handleFullscreen = useCallback8(() => {
5600
- const next = panelSize !== "fullscreen";
5601
- log16.info("fullscreen", { from: panelSize, fullscreen: next });
5602
- setPanelSize((s) => s === "fullscreen" ? "normal" : "fullscreen");
5603
- bus.emit("fullscreen", next);
5604
- }, [bus, panelSize]);
5616
+ const nextSize = panelSize === "fullscreen" ? "normal" : "fullscreen";
5617
+ log16.info("fullscreen", { from: panelSize, fullscreen: nextSize === "fullscreen" });
5618
+ setPanelSize(nextSize);
5619
+ persistence.savePanelSize(nextSize);
5620
+ bus.emit("fullscreen", nextSize === "fullscreen");
5621
+ }, [bus, panelSize, persistence]);
5605
5622
  const handlePopOut = useCallback8(() => {
5606
5623
  if (!options.popOutUrl) return;
5607
5624
  const url = new URL(options.popOutUrl);
@@ -6168,7 +6185,8 @@ function resolveInitialHostMode(options) {
6168
6185
  const { panelOpen, panelSize } = resolveInitialPanelState(
6169
6186
  options,
6170
6187
  currentViewportWidth(),
6171
- persistence.loadPanelOpen()
6188
+ persistence.loadPanelOpen(),
6189
+ persistence.loadPanelSize()
6172
6190
  );
6173
6191
  return computeHostMode(options.mode, panelSize, panelOpen);
6174
6192
  }
package/package.json CHANGED
@@ -80,5 +80,5 @@
80
80
  ],
81
81
  "type": "module",
82
82
  "types": "./index.d.ts",
83
- "version": "0.7.0"
83
+ "version": "0.7.1"
84
84
  }
package/web-component.mjs CHANGED
@@ -948,10 +948,11 @@ function pickInitialPanelSize(mode, size, viewportWidth) {
948
948
  }
949
949
  return "normal";
950
950
  }
951
- function resolveInitialPanelState(options, viewportWidth, persistedPanelOpen) {
951
+ function resolveInitialPanelState(options, viewportWidth, persistedPanelOpen, persistedPanelSize = null) {
952
952
  const isInlineLike = options.mode === "inline" || options.mode === "standalone" || options.mode === "page";
953
953
  const panelOpen = isInlineLike || (persistedPanelOpen ?? !options.startMinimized);
954
- const panelSize = pickInitialPanelSize(options.mode, options.size, viewportWidth);
954
+ const honorsPersisted = options.mode !== "standalone" && options.mode !== "page" && options.mode !== "inline";
955
+ const panelSize = honorsPersisted && persistedPanelSize ? persistedPanelSize : pickInitialPanelSize(options.mode, options.size, viewportWidth);
955
956
  return { panelOpen, panelSize };
956
957
  }
957
958
  function currentViewportWidth() {
@@ -1874,6 +1875,7 @@ function createPersistence(widgetId, storage = defaultStorage) {
1874
1875
  const KEY_CHAT = `${prefix}.sessionId`;
1875
1876
  const KEY_USER_PREFS = `${prefix}.userPrefs`;
1876
1877
  const KEY_PANEL_OPEN = `${prefix}.panelOpen`;
1878
+ const KEY_PANEL_SIZE = `${prefix}.panelSize`;
1877
1879
  const KEY_CALLOUT_DISMISSED = `${prefix}.calloutDismissed`;
1878
1880
  const KEY_SIDEBAR_COLLAPSED = `${prefix}.sidebarCollapsed`;
1879
1881
  const KEY_ACTIVE_MODULE = `${prefix}.activeModule`;
@@ -1928,6 +1930,13 @@ function createPersistence(widgetId, storage = defaultStorage) {
1928
1930
  savePanelOpen(open) {
1929
1931
  storage.set(KEY_PANEL_OPEN, open ? "1" : "0");
1930
1932
  },
1933
+ loadPanelSize() {
1934
+ const raw = storage.get(KEY_PANEL_SIZE);
1935
+ return raw === "normal" || raw === "expanded" || raw === "fullscreen" ? raw : null;
1936
+ },
1937
+ savePanelSize(size) {
1938
+ storage.set(KEY_PANEL_SIZE, size);
1939
+ },
1931
1940
  loadCalloutDismissed(currentText) {
1932
1941
  if (!currentText) return false;
1933
1942
  const dismissedText = storage.get(KEY_CALLOUT_DISMISSED);
@@ -5282,7 +5291,7 @@ function App({ options, hostElement, bus }) {
5282
5291
  const [sessionReady, setSessionReady] = useState11(false);
5283
5292
  const isInlineLike = options.mode === "standalone" || options.mode === "inline";
5284
5293
  const initialPanelRef = useRef8(
5285
- resolveInitialPanelState(options, currentViewportWidth(), persistence.loadPanelOpen())
5294
+ resolveInitialPanelState(options, currentViewportWidth(), persistence.loadPanelOpen(), persistence.loadPanelSize())
5286
5295
  );
5287
5296
  const [isOpen, setIsOpen] = useState11(initialPanelRef.current.panelOpen);
5288
5297
  const initialPanelApplied = useRef8(false);
@@ -5353,13 +5362,19 @@ function App({ options, hostElement, bus }) {
5353
5362
  }, [feedback, patchAndSync]);
5354
5363
  useEffect17(() => {
5355
5364
  if (initialSizeApplied.current || !options.size.initialSize) return;
5356
- setPanelSize(pickInitialPanelSize(options.mode, options.size, currentViewportWidth()));
5357
5365
  initialSizeApplied.current = true;
5358
- }, [options.mode, options.size]);
5366
+ if (persistence.loadPanelSize()) return;
5367
+ setPanelSize(pickInitialPanelSize(options.mode, options.size, currentViewportWidth()));
5368
+ }, [options.mode, options.size, persistence]);
5359
5369
  useEffect17(() => {
5360
5370
  if (!sessionReady || initialPanelApplied.current) return;
5361
5371
  initialPanelApplied.current = true;
5362
- const state = resolveInitialPanelState(options, currentViewportWidth(), persistence.loadPanelOpen());
5372
+ const state = resolveInitialPanelState(
5373
+ options,
5374
+ currentViewportWidth(),
5375
+ persistence.loadPanelOpen(),
5376
+ persistence.loadPanelSize()
5377
+ );
5363
5378
  setIsOpen(state.panelOpen);
5364
5379
  setPanelSize(state.panelSize);
5365
5380
  }, [sessionReady, options, persistence]);
@@ -5655,17 +5670,19 @@ function App({ options, hostElement, bus }) {
5655
5670
  if (chatId) homeNav.switchTab(chatId);
5656
5671
  }, [handleClear, homeNav, options]);
5657
5672
  const handleExpand = useCallback8(() => {
5658
- const next = panelSize !== "expanded";
5659
- log16.info("expand", { from: panelSize, expanded: next });
5660
- setPanelSize((s) => s === "expanded" ? "normal" : "expanded");
5661
- bus.emit("expand", next);
5662
- }, [bus, panelSize]);
5673
+ const nextSize = panelSize === "expanded" ? "normal" : "expanded";
5674
+ log16.info("expand", { from: panelSize, expanded: nextSize === "expanded" });
5675
+ setPanelSize(nextSize);
5676
+ persistence.savePanelSize(nextSize);
5677
+ bus.emit("expand", nextSize === "expanded");
5678
+ }, [bus, panelSize, persistence]);
5663
5679
  const handleFullscreen = useCallback8(() => {
5664
- const next = panelSize !== "fullscreen";
5665
- log16.info("fullscreen", { from: panelSize, fullscreen: next });
5666
- setPanelSize((s) => s === "fullscreen" ? "normal" : "fullscreen");
5667
- bus.emit("fullscreen", next);
5668
- }, [bus, panelSize]);
5680
+ const nextSize = panelSize === "fullscreen" ? "normal" : "fullscreen";
5681
+ log16.info("fullscreen", { from: panelSize, fullscreen: nextSize === "fullscreen" });
5682
+ setPanelSize(nextSize);
5683
+ persistence.savePanelSize(nextSize);
5684
+ bus.emit("fullscreen", nextSize === "fullscreen");
5685
+ }, [bus, panelSize, persistence]);
5669
5686
  const handlePopOut = useCallback8(() => {
5670
5687
  if (!options.popOutUrl) return;
5671
5688
  const url = new URL(options.popOutUrl);
@@ -5955,7 +5972,8 @@ function resolveInitialHostMode(options) {
5955
5972
  const { panelOpen, panelSize } = resolveInitialPanelState(
5956
5973
  options,
5957
5974
  currentViewportWidth(),
5958
- persistence.loadPanelOpen()
5975
+ persistence.loadPanelOpen(),
5976
+ persistence.loadPanelSize()
5959
5977
  );
5960
5978
  return computeHostMode(options.mode, panelSize, panelOpen);
5961
5979
  }