@widgetic/editor 4.1.18 → 4.1.20

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.
Files changed (94) hide show
  1. package/dist/components/WidgetPreview.svelte +77 -14
  2. package/dist/components/editors/CompositionEditorApp.svelte +71 -35
  3. package/dist/components/editors/CompositionEditorApp.svelte.d.ts +3 -1
  4. package/dist/components/editors/ContentTabBulkDrop.svelte +268 -0
  5. package/dist/components/editors/ContentTabBulkDrop.svelte.d.ts +37 -0
  6. package/dist/components/editors/EmbedAssistantPanel.svelte +303 -0
  7. package/dist/components/editors/EmbedAssistantPanel.svelte.d.ts +29 -0
  8. package/dist/components/editors/EmbedEditor.svelte +221 -15
  9. package/dist/components/editors/EmbedEditor.svelte.d.ts +31 -3
  10. package/dist/components/editors/PropsEditor.svelte +223 -30
  11. package/dist/components/editors/PropsEditor.svelte.d.ts +11 -0
  12. package/dist/components/editors/propsEditorContentStateFlatten.d.ts +12 -0
  13. package/dist/components/editors/propsEditorContentStateFlatten.js +40 -0
  14. package/dist/components/ic/BrowserInputController.svelte +184 -21
  15. package/dist/components/ic/BrowserInputController.svelte.d.ts +2 -0
  16. package/dist/components/ic/CheckboxInputController.svelte +11 -0
  17. package/dist/components/ic/ColorPickerInputController.svelte +2 -1
  18. package/dist/components/ic/DatePickerInputController.svelte +5 -3
  19. package/dist/components/ic/FontInputController.svelte +9 -4
  20. package/dist/components/ic/InputControllerHeader.svelte +4 -3
  21. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +13 -0
  22. package/dist/components/ic/NumberControls.svelte +140 -17
  23. package/dist/components/ic/RadioGroupInputController.svelte +11 -0
  24. package/dist/components/ic/RangeCalendarInputController.svelte +38 -13
  25. package/dist/components/ic/TextAreaInputController.svelte +593 -321
  26. package/dist/components/ic/TextAreaPreviewInputController.svelte +46 -58
  27. package/dist/components/ic/VectorInputController.svelte +0 -1
  28. package/dist/components/ic/numberControlsValueArea.d.ts +29 -0
  29. package/dist/components/ic/numberControlsValueArea.js +51 -0
  30. package/dist/components/ic/optionGroupCardPointerDown.d.ts +9 -0
  31. package/dist/components/ic/optionGroupCardPointerDown.js +20 -0
  32. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +48 -6
  33. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +4 -1
  34. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte +34 -0
  35. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte.d.ts +24 -0
  36. package/dist/components/ic/shared/fileBrowserOverlayEscape.d.ts +29 -0
  37. package/dist/components/ic/shared/fileBrowserOverlayEscape.js +21 -0
  38. package/dist/composition/compositionApi.d.ts +16 -0
  39. package/dist/composition/compositionApi.js +16 -1
  40. package/dist/composition/compositionEditorController.d.ts +46 -0
  41. package/dist/composition/compositionEditorController.js +277 -5
  42. package/dist/composition/compositionEditorSchemaCache.d.ts +35 -0
  43. package/dist/composition/compositionEditorSchemaCache.js +82 -0
  44. package/dist/contentBulkDrop/applyContentPlan.d.ts +18 -0
  45. package/dist/contentBulkDrop/applyContentPlan.js +55 -0
  46. package/dist/contentBulkDrop/bulkDropSummary.d.ts +4 -0
  47. package/dist/contentBulkDrop/bulkDropSummary.js +12 -0
  48. package/dist/contentBulkDrop/dragIntent.d.ts +7 -0
  49. package/dist/contentBulkDrop/dragIntent.js +24 -0
  50. package/dist/contentBulkDrop/filterDropFiles.d.ts +2 -0
  51. package/dist/contentBulkDrop/filterDropFiles.js +21 -0
  52. package/dist/contentBulkDrop/formatFileSize.d.ts +2 -0
  53. package/dist/contentBulkDrop/formatFileSize.js +13 -0
  54. package/dist/contentBulkDrop/types.d.ts +34 -0
  55. package/dist/contentBulkDrop/types.js +1 -0
  56. package/dist/contentBulkDrop/uploadQueue.d.ts +41 -0
  57. package/dist/contentBulkDrop/uploadQueue.js +114 -0
  58. package/dist/drafts/compositionDraft.d.ts +65 -0
  59. package/dist/drafts/compositionDraft.js +136 -0
  60. package/dist/drafts/compositionEditorViewState.d.ts +9 -0
  61. package/dist/drafts/compositionEditorViewState.js +33 -0
  62. package/dist/drafts/draftJournal.d.ts +59 -0
  63. package/dist/drafts/draftJournal.js +261 -0
  64. package/dist/embed/__fixtures__/gatewayGeneratedEmbedCodes.json +25 -0
  65. package/dist/embed/__fixtures__/generatedEmbedCodes.json +320 -0
  66. package/dist/embed/embedSchema.json +409 -0
  67. package/dist/embed/parseCompositionEmbedCode.d.ts +21 -0
  68. package/dist/embed/parseCompositionEmbedCode.js +379 -0
  69. package/dist/embedAssistant/embedAssistantEvents.d.ts +22 -0
  70. package/dist/embedAssistant/embedAssistantEvents.js +39 -0
  71. package/dist/embedAssistant/embedAssistantStream.d.ts +30 -0
  72. package/dist/embedAssistant/embedAssistantStream.js +125 -0
  73. package/dist/embedAssistant/highlightTiming.d.ts +1 -0
  74. package/dist/embedAssistant/highlightTiming.js +6 -0
  75. package/dist/embedAssistant/types.d.ts +27 -0
  76. package/dist/embedAssistant/types.js +1 -0
  77. package/dist/i18n/labels.js +8 -4
  78. package/dist/i18n/language.d.ts +38 -2
  79. package/dist/i18n/messages.d.ts +38 -1
  80. package/dist/i18n/messages.js +40 -1
  81. package/dist/i18n/translate.d.ts +1 -1
  82. package/dist/index.d.ts +3 -1
  83. package/dist/index.js +2 -0
  84. package/dist/utils/FontManager.d.ts +2 -0
  85. package/dist/utils/FontManager.js +16 -1
  86. package/dist/utils/isEditableEventTarget.d.ts +5 -0
  87. package/dist/utils/isEditableEventTarget.js +25 -0
  88. package/dist/utils/linkUrlValidation.d.ts +17 -0
  89. package/dist/utils/linkUrlValidation.js +120 -0
  90. package/dist/utils/mediaFileValue.d.ts +12 -0
  91. package/dist/utils/mediaFileValue.js +24 -0
  92. package/dist/utils/placeRichTextCaretAtDocumentEnd.d.ts +11 -0
  93. package/dist/utils/placeRichTextCaretAtDocumentEnd.js +26 -0
  94. package/package.json +7 -7
@@ -46,6 +46,40 @@
46
46
  const placeholder: string = config.placeholder || '';
47
47
 
48
48
  let isShowingTextArea = false;
49
+ let resolvedPortalTarget: string | HTMLElement = portalTarget;
50
+
51
+ /** Props panel may pass the tab root before the scroll viewport is bound; resolve on open. */
52
+ function resolveTextAreaPortalTarget(): string | HTMLElement {
53
+ // Round 26: the scroll viewport is NOT a host for the editor. It is as tall as the whole list of controllers (1,500 px for a long
54
+ // Content tab), so an editor placed in it ran past the bottom edge of the panel and the gap under it sat at the end of the list,
55
+ // out of sight. The tab shell below clips that list: it is exactly the area the person sees under the tabs.
56
+ const tabRoot =
57
+ (portalTarget instanceof HTMLElement
58
+ ? portalTarget.closest('.tab-content-container, .tab-design-container')
59
+ : null) ??
60
+ (typeof portalTarget === 'string' ? document.getElementById(portalTarget) : null) ??
61
+ document.querySelector<HTMLElement>(
62
+ '.tab-content-container:not(.hidden), .tab-design-container:not(.hidden)'
63
+ );
64
+
65
+ if (!(tabRoot instanceof HTMLElement)) {
66
+ return portalTarget || 'tab-content-container';
67
+ }
68
+
69
+ const hasVisibleViewport = [...tabRoot.querySelectorAll<HTMLElement>('.props-editor-scroll-viewport')].some(
70
+ (viewport) => {
71
+ const viewportRect = viewport.getBoundingClientRect();
72
+ return viewportRect.width > 0 && viewportRect.height > 0;
73
+ }
74
+ );
75
+
76
+ // The inner Radix viewport is as tall as the scroll content; the tab shell clips the visible controller area.
77
+ if (hasVisibleViewport && tabRoot.clientHeight > 0) {
78
+ return tabRoot;
79
+ }
80
+
81
+ return portalTarget;
82
+ }
49
83
 
50
84
  // Add a computed property to determine if we're showing placeholder
51
85
  $: isShowingPlaceholder = !value && placeholder;
@@ -56,12 +90,6 @@
56
90
  // Add this to track the current color
57
91
  let currentColor = '#1a1a1a'; // Default color
58
92
 
59
- // Add this near the top with other state declarations
60
- let isPortalHovered = false;
61
-
62
- // Add this to store the background rect ref
63
- let backgroundRectRef: HTMLDivElement;
64
-
65
93
  // The box the text editor is shown in. The editor is found through it: a search of the whole `document` finds nothing
66
94
  // inside a module's shadow root, and finds the customer's own text editor (and focuses it) when the page has one.
67
95
  let portalContentRef: HTMLDivElement | undefined;
@@ -91,18 +119,13 @@
91
119
  }
92
120
 
93
121
  function handleClick() {
94
- // console.log('Opening text area in portal');
122
+ if (!isShowingTextArea) {
123
+ resolvedPortalTarget = resolveTextAreaPortalTarget();
124
+ }
95
125
  isShowingTextArea = !isShowingTextArea;
96
126
  }
97
127
 
98
- $: if (isShowingTextArea) {
99
- setTimeout(() => {
100
- const editor = portalContentRef?.querySelector('.ProseMirror');
101
- if (editor instanceof HTMLElement) {
102
- editor.focus();
103
- }
104
- }, 100); // Give a bit more time for the portal to mount
105
- }
128
+ // Initial caret placement and focus are handled inside TextAreaInputController when the portal editor mounts.
106
129
 
107
130
  // Update value reactively to track color changes
108
131
  $: {
@@ -118,31 +141,6 @@
118
141
  // console.log('[TextAreaPreview] compact preview html', value.slice(0, 180));
119
142
  }
120
143
 
121
- function handlePortalMouseEnter() {
122
- // console.log('Portal mouse entered');
123
- isPortalHovered = true;
124
- }
125
-
126
- function handlePortalMouseLeave(event: MouseEvent) {
127
- // if (!backgroundRectRef) return;
128
- // console.log('Portal mouse leave: ', event, backgroundRectRef.getBoundingClientRect());
129
-
130
- // Get mouse position relative to the portal content
131
- const { offsetX, offsetY } = event;
132
- const offsetWidth = backgroundRectRef.getBoundingClientRect().width;
133
- const offsetHeight = backgroundRectRef.getBoundingClientRect().height;
134
- // console.log('Portal mouse leave mousePosition: ', offsetX, offsetY, offsetWidth, offsetHeight);
135
-
136
- // Check if cursor is within the background rect boundaries
137
- if (0 < offsetX && offsetX < offsetWidth && 0 < offsetY && offsetY < offsetHeight) {
138
- // console.log('Portal mouse leave mousePosition: ', offsetX, offsetY, offsetWidth, offsetHeight);
139
- return;
140
- }
141
-
142
- // console.log('Portal mouse leave mousePosition: ', offsetX, offsetY, offsetWidth, offsetHeight);
143
- isPortalHovered = false;
144
- }
145
-
146
144
  // Add keyboard event handler for Escape key
147
145
  function handleKeydown(event: KeyboardEvent) {
148
146
  if (event.key === 'Escape' && isShowingTextArea) {
@@ -223,7 +221,7 @@
223
221
 
224
222
  <!-- Text Area Input Controller in Portal -->
225
223
  {#if isShowingTextArea}
226
- <Portal target={portalTarget} class="text-area-portal absolute inset-0 z-50 flex max-h-full min-h-0 flex-col overflow-hidden">
224
+ <Portal target={resolvedPortalTarget} class="text-area-portal absolute inset-0 z-50 flex max-h-full min-h-0 flex-col overflow-hidden">
227
225
  <!-- Blocking overlay: clicks pass through to portalled popovers; only the editor card receives pointer events. -->
228
226
  <div
229
227
  class="text-area-portal-overlay pointer-events-auto absolute inset-0 z-0 bg-background {isClosing
@@ -232,28 +230,18 @@
232
230
  style="transform: translateZ(0); backface-visibility: hidden;"
233
231
  role="presentation"
234
232
  ></div>
235
- <!-- svelte-ignore a11y_no_static_element_interactions -->
236
233
  <div
237
234
  bind:this={portalContentRef}
238
- class="text-area-portal-content pointer-events-auto absolute z-10 mx-6 mb-6 mt-4 flex min-h-0 max-h-[calc(100%-2rem)] flex-1 flex-col inset-x-0 bottom-0 top-4 {isClosing
235
+ class="text-area-portal-content pointer-events-auto absolute inset-x-6 top-0 bottom-6 z-10 flex min-h-0 min-w-0 flex-1 flex-col {isClosing
239
236
  ? 'scale-out-animation'
240
237
  : 'scale-in-animation'}"
241
238
  style="transform: translateZ(0); backface-visibility: hidden;"
242
- on:mouseenter={handlePortalMouseEnter}
243
- on:mouseleave={handlePortalMouseLeave}
244
239
  >
245
- <!-- Background rect that defines our hover boundaries -->
246
- <!-- Add portal border radius -->
247
- <div
248
- bind:this={backgroundRectRef}
249
- class="portal-background-rect absolute inset-0 bg-transparent pointer-events-none"
250
- style="border-radius: var(--radius-lg);"
251
- ></div>
252
-
240
+ <!-- The editor fills the controllers area, 24 px in from both sides and 24 px up from the bottom (the same gutter the cards
241
+ have), so it has no hover ring: a ring is drawn outside the box and the panel clips it, which left two dark lines down
242
+ the sides of the editor. The backdrop above covers the whole area, gutters included, so no card shows in the gap. -->
253
243
  <TextAreaInputController
254
- class="text-area w-full h-full transition-colors duration-fast {isPortalHovered
255
- ? 'ring-2 ring-ring ring-offset-2 ring-offset-background'
256
- : ''}"
244
+ class="text-area w-full h-full transition-colors duration-fast"
257
245
  {label}
258
246
  bind:value
259
247
  onChange={handleFullEditorChange}
@@ -391,7 +379,7 @@
391
379
 
392
380
  :global(.scale-in-animation) {
393
381
  animation: scaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
394
- transform-origin: center center;
382
+ transform-origin: top center;
395
383
  will-change: transform, opacity;
396
384
  backface-visibility: hidden;
397
385
  }
@@ -425,7 +413,7 @@
425
413
 
426
414
  :global(.scale-out-animation) {
427
415
  animation: scaleOut 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
428
- transform-origin: center center;
416
+ transform-origin: top center;
429
417
  will-change: transform, opacity;
430
418
  backface-visibility: hidden;
431
419
  pointer-events: none;
@@ -1953,7 +1953,6 @@
1953
1953
  <EditorFileBrowserOverlay
1954
1954
  portalTarget="props-editor-file-browser-portal"
1955
1955
  fileFilter="svg"
1956
- instanceId={`vector-input-${controllerId}`}
1957
1956
  addToEditorLabel={$t('editor.file.useFile')}
1958
1957
  onClose={closeVectorFileBrowser}
1959
1958
  on:select={handleVectorFileBrowserSelect}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Pointer routing for the number stepper value hit area (`NumberControls.svelte`).
3
+ * Kept pure so Node can test the rules without mounting Svelte.
4
+ */
5
+ type TextInputElement = HTMLInputElement | {
6
+ value: string;
7
+ setSelectionRange: (s: number, e: number) => void;
8
+ };
9
+ /**
10
+ * True when a mousedown on this target should focus the number input instead of letting the
11
+ * browser move focus to `body` or start a document-level selection in dead space beside the digits.
12
+ */
13
+ export declare function shouldRoutePointerToNumberInput(target: EventTarget | null, inputId: string): boolean;
14
+ /** Caret placement after routing a press into the field. */
15
+ export declare function selectionAfterValueAreaPress(value: string, extendSelection: boolean): {
16
+ start: number;
17
+ end: number;
18
+ };
19
+ /**
20
+ * True when the pointer is in the empty stretch of an auto-sized field after the last digit
21
+ * (HTML `size` / average ch-width used to leave this dead band).
22
+ */
23
+ export declare function isPointerPastTextEnd(text: string, inputLeft: number, clientX: number, textWidth: number): boolean;
24
+ /** While dragging from empty chrome into the digits, select the whole value for the next key. */
25
+ export declare function selectionWhileDraggingFromValueChrome(valueLength: number, pointerPastTextEnd: boolean, extendSelection: boolean): {
26
+ start: number;
27
+ end: number;
28
+ } | null;
29
+ export type { TextInputElement };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Pointer routing for the number stepper value hit area (`NumberControls.svelte`).
3
+ * Kept pure so Node can test the rules without mounting Svelte.
4
+ */
5
+ function hasClosest(target) {
6
+ return (typeof target === 'object' &&
7
+ target !== null &&
8
+ 'closest' in target &&
9
+ typeof target.closest === 'function');
10
+ }
11
+ /**
12
+ * True when a mousedown on this target should focus the number input instead of letting the
13
+ * browser move focus to `body` or start a document-level selection in dead space beside the digits.
14
+ */
15
+ export function shouldRoutePointerToNumberInput(target, inputId) {
16
+ if (!hasClosest(target))
17
+ return false;
18
+ if (target.closest('button'))
19
+ return false;
20
+ const input = document.getElementById(inputId);
21
+ if (!input || !('value' in input))
22
+ return false;
23
+ if (target === input)
24
+ return false;
25
+ return Boolean(target.closest('.number-controls-hit-area'));
26
+ }
27
+ /** Caret placement after routing a press into the field. */
28
+ export function selectionAfterValueAreaPress(value, extendSelection) {
29
+ if (extendSelection) {
30
+ return { start: 0, end: value.length };
31
+ }
32
+ const end = value.length;
33
+ return { start: end, end };
34
+ }
35
+ /**
36
+ * True when the pointer is in the empty stretch of an auto-sized field after the last digit
37
+ * (HTML `size` / average ch-width used to leave this dead band).
38
+ */
39
+ export function isPointerPastTextEnd(text, inputLeft, clientX, textWidth) {
40
+ return clientX - inputLeft > textWidth + 0.5;
41
+ }
42
+ /** While dragging from empty chrome into the digits, select the whole value for the next key. */
43
+ export function selectionWhileDraggingFromValueChrome(valueLength, pointerPastTextEnd, extendSelection) {
44
+ if (valueLength === 0)
45
+ return null;
46
+ if (extendSelection)
47
+ return { start: 0, end: valueLength };
48
+ if (pointerPastTextEnd)
49
+ return null;
50
+ return { start: 0, end: valueLength };
51
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Checkbox / radio IC cards keep focus (and their ring) when the pointer presses non-control
3
+ * surfaces (label text, row chrome, padding, gaps) instead of blurring to `body`.
4
+ *
5
+ * Only real focusable controls are excluded. `label` is omitted on purpose: pressing label text
6
+ * must not move focus to `body` while the control inside the card stays focused.
7
+ */
8
+ /** When true, `mousedown` should call `preventDefault()` so the active control stays focused. */
9
+ export declare function shouldPreventOptionGroupBackgroundFocusSteal(target: EventTarget | null): boolean;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Checkbox / radio IC cards keep focus (and their ring) when the pointer presses non-control
3
+ * surfaces (label text, row chrome, padding, gaps) instead of blurring to `body`.
4
+ *
5
+ * Only real focusable controls are excluded. `label` is omitted on purpose: pressing label text
6
+ * must not move focus to `body` while the control inside the card stays focused.
7
+ */
8
+ const FOCUSABLE_CONTROL_SELECTOR = 'button,a,input,textarea,select,[role="checkbox"],[role="radio"],[contenteditable="true"]';
9
+ function hasClosest(target) {
10
+ return (typeof target === 'object' &&
11
+ target !== null &&
12
+ 'closest' in target &&
13
+ typeof target.closest === 'function');
14
+ }
15
+ /** When true, `mousedown` should call `preventDefault()` so the active control stays focused. */
16
+ export function shouldPreventOptionGroupBackgroundFocusSteal(target) {
17
+ if (!hasClosest(target))
18
+ return false;
19
+ return !target.closest(FOCUSABLE_CONTROL_SELECTOR);
20
+ }
@@ -8,18 +8,25 @@
8
8
  * The control fixes the type of file (`fileFilter`): the browser then draws no "Filter by" (the user cannot change the
9
9
  * type) and the upload takes only that type. `fileFilter="all"` (any file) keeps the filter.
10
10
  */
11
+ import { onMount } from 'svelte';
12
+ import { get } from 'svelte/store';
11
13
  import { Portal } from '@widgetic/design-system/components';
14
+ import { modalState } from '@widgetic/design-system/components/modals/modalStore';
12
15
  import { FileBrowser } from '@widgetic/file-browser';
13
16
  import { IconX } from '@widgetic/design-system/icons';
14
17
  import { useEditorMediaLibrary } from '../../../mediaLibraryContext';
15
18
  import { useEditorLanguage } from '../../../i18n/language';
19
+ import { shouldCloseFileBrowserOverlayOnEscape } from './fileBrowserOverlayEscape';
16
20
 
17
21
  /** Where the overlay is drawn: the panel's own host (it then fills the panel), or any other element or id (a dialog). */
18
22
  export let portalTarget: string | HTMLElement = 'portal-element';
19
23
  /** The type of file the control takes: it decides what the browser lists, offers to filter by, and accepts as upload. */
20
24
  export let fileFilter: 'all' | 'image' | 'video' | 'audio' | 'document' | 'font' | 'svg' = 'all';
21
- /** Tells this browser from the others on the page (it keeps its own folder and sort between visits). */
22
- export let instanceId: string;
25
+ /**
26
+ * localStorage scope for folder memory (must match `WIDGETIC_EDITOR_FILE_PICKER_INSTANCE_ID` in file-browser).
27
+ * All file fields share one remembered folder.
28
+ */
29
+ export let instanceId: string = 'widgetic-editor-file-picker';
23
30
  /** The file the control has now: the browser keeps "use" disabled until a different one is picked. */
24
31
  export let activeFileId: string | null = null;
25
32
  /** The text of the button that hands the picked file to the control. */
@@ -39,6 +46,40 @@
39
46
  (portalTarget instanceof HTMLElement && portalTarget.id === 'props-editor-file-browser-portal');
40
47
  /** The type is fixed by the control, so there is nothing to filter by; only "any file" can still be narrowed down. */
41
48
  $: showFilters = fileFilter === 'all';
49
+ /** Flat host libraries have no folders; partner pages must not use our localStorage keys. */
50
+ const rememberEditorFolder = getEditorMediaLibrary() == null;
51
+
52
+ /** The top-most dialog when this overlay opened: a dialog with a higher generation was opened inside the browser. */
53
+ const generationWhenOverlayOpened = get(modalState).generation ?? 0;
54
+
55
+ /**
56
+ * Escape closes the overlay like any other modal, unless something above it owns the key: a dialog the browser
57
+ * opened (the preview, rename, new folder, move, delete) or a menu or dropdown that already handled it. Those close
58
+ * first; the next Escape closes the overlay. See fileBrowserOverlayEscape.ts for why the modal store is read here.
59
+ */
60
+ function handleOverlayEscape(event: KeyboardEvent) {
61
+ try {
62
+ const currentModalState = get(modalState);
63
+ const shouldClose = shouldCloseFileBrowserOverlayOnEscape({
64
+ key: event.key,
65
+ defaultPrevented: event.defaultPrevented,
66
+ modalOpen: currentModalState.isOpen,
67
+ modalGeneration: currentModalState.generation ?? 0,
68
+ generationWhenOverlayOpened
69
+ });
70
+ if (!shouldClose) return;
71
+ event.preventDefault();
72
+ event.stopPropagation();
73
+ onClose();
74
+ } catch (error) {
75
+ console.error('[EditorFileBrowserOverlay] Escape handler failed', error);
76
+ }
77
+ }
78
+
79
+ onMount(() => {
80
+ window.addEventListener('keydown', handleOverlayEscape);
81
+ return () => window.removeEventListener('keydown', handleOverlayEscape);
82
+ });
42
83
  </script>
43
84
 
44
85
  <Portal target={portalTarget}>
@@ -87,18 +128,19 @@
87
128
  </div>
88
129
 
89
130
  <div class="editor-file-browser-body flex min-h-0 flex-1 flex-col overflow-hidden">
90
- <!-- With a media library the File Browser keeps nothing about this visit (the filter it was left on, the
91
- folder it was left in) in the page's localStorage: that storage belongs to the page this editor sits in,
92
- which can be a partner's. Without one (the Widgetic site) it remembers them, as it always did. -->
131
+ <!-- With a host media library (flat list) we remember nothing in localStorage. With Widgetic folders we
132
+ remember only the folder path (`rememberFolder`), never filter/sort — the control fixes the file type. -->
93
133
  <FileBrowser
94
134
  class="h-full min-h-0 flex-1"
95
135
  {instanceId}
96
136
  initialFilter={fileFilter}
97
137
  restrictUpload={fileFilter !== 'all'}
98
138
  {showFilters}
139
+ showSorting={false}
99
140
  useDemoContent={false}
100
141
  mediaLibrary={getEditorMediaLibrary()}
101
- persistHistory={!getEditorMediaLibrary()}
142
+ persistHistory={false}
143
+ rememberFolder={rememberEditorFolder}
102
144
  allowSelecting={true}
103
145
  showAddToEditor={true}
104
146
  maxSelections={1}
@@ -14,7 +14,10 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
14
14
  declare const EditorFileBrowserOverlay: $$__sveltets_2_IsomorphicComponent<{
15
15
  /** Where the overlay is drawn: the panel's own host (it then fills the panel), or any other element or id (a dialog). */ portalTarget?: string | HTMLElement;
16
16
  /** The type of file the control takes: it decides what the browser lists, offers to filter by, and accepts as upload. */ fileFilter?: "all" | "image" | "video" | "audio" | "document" | "font" | "svg";
17
- /** Tells this browser from the others on the page (it keeps its own folder and sort between visits). */ instanceId: string;
17
+ /**
18
+ * localStorage scope for folder memory (must match `WIDGETIC_EDITOR_FILE_PICKER_INSTANCE_ID` in file-browser).
19
+ * All file fields share one remembered folder.
20
+ */ instanceId?: string;
18
21
  /** The file the control has now: the browser keeps "use" disabled until a different one is picked. */ activeFileId?: string | null;
19
22
  /** The text of the button that hands the picked file to the control. */ addToEditorLabel?: string | undefined;
20
23
  /** Called when the user closes the browser without picking (the X, or a click outside when it is a dialog). */ onClose?: () => void;
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ import { FilePreview, type FileSystemItem } from '@widgetic/file-browser';
3
+ import { Portal } from '@widgetic/design-system/components';
4
+
5
+ /** Portal host id or element (same as the file browser overlay). */
6
+ export let portalTarget: string | HTMLElement = 'portal-element';
7
+ export let file: FileSystemItem;
8
+ export let open = true;
9
+ export let onClose: () => void = () => {};
10
+
11
+ function handleClose() {
12
+ open = false;
13
+ onClose();
14
+ }
15
+ </script>
16
+
17
+ {#if open}
18
+ <Portal target={portalTarget}>
19
+ <div
20
+ class="editor-selected-file-preview-host pointer-events-none absolute inset-0 z-[10000000] flex items-center justify-center p-6"
21
+ >
22
+ <div class="pointer-events-auto max-h-full max-w-full">
23
+ <FilePreview
24
+ {file}
25
+ {open}
26
+ allowSelecting={false}
27
+ currentFiles={[file]}
28
+ target="editor-selected-file-preview"
29
+ on:close={handleClose}
30
+ />
31
+ </div>
32
+ </div>
33
+ </Portal>
34
+ {/if}
@@ -0,0 +1,24 @@
1
+ import { type FileSystemItem } from '@widgetic/file-browser';
2
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
+ $$bindings?: Bindings;
5
+ } & Exports;
6
+ (internal: unknown, props: Props & {
7
+ $$events?: Events;
8
+ $$slots?: Slots;
9
+ }): Exports & {
10
+ $set?: any;
11
+ $on?: any;
12
+ };
13
+ z_$$bindings?: Bindings;
14
+ }
15
+ declare const EditorSelectedFilePreviewOverlay: $$__sveltets_2_IsomorphicComponent<{
16
+ /** Portal host id or element (same as the file browser overlay). */ portalTarget?: string | HTMLElement;
17
+ file: FileSystemItem;
18
+ open?: boolean;
19
+ onClose?: () => void;
20
+ }, {
21
+ [evt: string]: CustomEvent<any>;
22
+ }, {}, {}, string>;
23
+ type EditorSelectedFilePreviewOverlay = InstanceType<typeof EditorSelectedFilePreviewOverlay>;
24
+ export default EditorSelectedFilePreviewOverlay;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Escape and the editor's File Browser overlay: Escape closes the top-most thing, like it does for any other modal.
3
+ *
4
+ * What can sit above the overlay while it is open:
5
+ * - a dialog of the design system that the File Browser opened (the preview of a file, rename, new folder, move,
6
+ * delete). It closes itself on Escape, but it registers its key listener after the overlay did, so the overlay is
7
+ * asked first and has to look at the modal store instead of waiting for the dialog to handle the key;
8
+ * - a menu, a dropdown or a search that already took the key: they mark it as handled before it reaches the window.
9
+ *
10
+ * Only when nothing above the overlay owns the key does the overlay close.
11
+ */
12
+ export interface FileBrowserOverlayEscapeContext {
13
+ /** `event.key` of the key press. */
14
+ key: string;
15
+ /** `event.defaultPrevented`: an inner control already handled the key. */
16
+ defaultPrevented: boolean;
17
+ /** Whether a design-system modal is open now. */
18
+ modalOpen: boolean;
19
+ /** The generation of the top-most open modal now (0 when none is open). */
20
+ modalGeneration: number;
21
+ /**
22
+ * The generation of the top-most open modal when the overlay opened (0 when none was open). Generations only grow,
23
+ * so a modal with a higher number was opened inside the browser and is above the overlay; a modal with the same
24
+ * number was already there when the overlay opened and is below it.
25
+ */
26
+ generationWhenOverlayOpened: number;
27
+ }
28
+ /** True when this Escape should close the overlay (nothing above the overlay handles it). */
29
+ export declare function shouldCloseFileBrowserOverlayOnEscape(context: FileBrowserOverlayEscapeContext): boolean;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Escape and the editor's File Browser overlay: Escape closes the top-most thing, like it does for any other modal.
3
+ *
4
+ * What can sit above the overlay while it is open:
5
+ * - a dialog of the design system that the File Browser opened (the preview of a file, rename, new folder, move,
6
+ * delete). It closes itself on Escape, but it registers its key listener after the overlay did, so the overlay is
7
+ * asked first and has to look at the modal store instead of waiting for the dialog to handle the key;
8
+ * - a menu, a dropdown or a search that already took the key: they mark it as handled before it reaches the window.
9
+ *
10
+ * Only when nothing above the overlay owns the key does the overlay close.
11
+ */
12
+ /** True when this Escape should close the overlay (nothing above the overlay handles it). */
13
+ export function shouldCloseFileBrowserOverlayOnEscape(context) {
14
+ if (context.key !== 'Escape')
15
+ return false;
16
+ if (context.defaultPrevented)
17
+ return false;
18
+ if (context.modalOpen && context.modalGeneration > context.generationWhenOverlayOpened)
19
+ return false;
20
+ return true;
21
+ }
@@ -23,6 +23,7 @@
23
23
  * to read and embed the document, which takes longer than any other call, so it has a limit of its own.
24
24
  */
25
25
  import { type JsonRecord } from './compositionHelpers.js';
26
+ import type { ContentFromFilesApiResult } from '../contentBulkDrop/types.js';
26
27
  import { type KnowledgeDocument, type KnowledgeFileInput, type KnowledgeListing, type KnowledgeTextInput } from './knowledgeDocuments.js';
27
28
  /** Why the token is being asked for. `expired` means the API just refused the previous one. */
28
29
  export type TokenReason = 'initial' | 'expired';
@@ -73,6 +74,11 @@ export interface SaveCompositionOptions extends CompositionRequestOptions {
73
74
  * `content`. Left out, the save is made without the check.
74
75
  */
75
76
  ifMatchVersion?: number;
77
+ /**
78
+ * Lets the request finish after the page is gone (`fetch` `keepalive`): for a tab close or hide, when the body is
79
+ * small enough (under 64 KB in the browser).
80
+ */
81
+ keepalive?: boolean;
76
82
  }
77
83
  /**
78
84
  * What the API says about who is editing a composition (`/edit-leases/composition/{id}`): the answer to asking to edit,
@@ -166,6 +172,16 @@ export interface CompositionApi {
166
172
  peekEditLease(compositionId: string, options?: CompositionRequestOptions): Promise<EditLeaseAnswer>;
167
173
  /** Gives up this tab's claim (nothing happens when it holds none, or somebody else does now). */
168
174
  releaseEditLease(compositionId: string, sessionId: string, options?: ReleaseEditLeaseOptions): Promise<void>;
175
+ /** Plans how library files map onto the content list (bulk drop). */
176
+ planContentFromFiles(compositionId: string, body: {
177
+ files: Array<{
178
+ name: string;
179
+ mimeType: string;
180
+ sizeBytes?: number;
181
+ mediaId?: string;
182
+ }>;
183
+ apply?: boolean;
184
+ }, options?: CompositionRequestOptions): Promise<ContentFromFilesApiResult>;
169
185
  /** The documents the widget's AI answers from (AI Answers), and how much of the knowledge base they use. */
170
186
  listKnowledgeDocuments(compositionId: string, options?: CompositionRequestOptions): Promise<KnowledgeListing>;
171
187
  /**
@@ -404,7 +404,8 @@ export function createCompositionApi(options) {
404
404
  signal: saveOptions.signal,
405
405
  idempotencyKey,
406
406
  // Quoted, the way the API writes the ETag of a composition.
407
- ifMatch: ifMatchVersion === undefined ? undefined : `"${ifMatchVersion}"`
407
+ ifMatch: ifMatchVersion === undefined ? undefined : `"${ifMatchVersion}"`,
408
+ keepalive: saveOptions.keepalive
408
409
  });
409
410
  return isRecord(record) ? record : {};
410
411
  },
@@ -468,6 +469,20 @@ export function createCompositionApi(options) {
468
469
  },
469
470
  async removeKnowledgeDocument(compositionId, documentId, requestOptions = {}) {
470
471
  await request('DELETE', knowledgePath(compositionId, `/documents/${encodeURIComponent(checkedDocumentId(documentId))}`), requestOptions);
472
+ },
473
+ async planContentFromFiles(compositionId, body, requestOptions = {}) {
474
+ const answer = await request('POST', compositionPath(compositionId, '/content-items/from-files'), { body, signal: requestOptions.signal });
475
+ if (!isRecord(answer))
476
+ throw invalidResponse('The API gave no bulk drop plan.');
477
+ const plan = answer.plan;
478
+ if (!isRecord(plan) || !Array.isArray(plan.items) || !isRecord(plan.summary)) {
479
+ throw invalidResponse('The API gave an invalid bulk drop plan.');
480
+ }
481
+ return {
482
+ plan,
483
+ applied: answer.applied === true,
484
+ ...(isRecord(answer.content) ? { content: answer.content } : {})
485
+ };
471
486
  }
472
487
  };
473
488
  }