@widgetic/editor 4.1.17 → 4.1.19

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 (112) hide show
  1. package/dist/components/PreviewChromeControls.svelte +2 -2
  2. package/dist/components/WidgetPreview.svelte +79 -16
  3. package/dist/components/editors/CompositionEditorApp.svelte +71 -35
  4. package/dist/components/editors/CompositionEditorApp.svelte.d.ts +3 -1
  5. package/dist/components/editors/ContentTabBulkDrop.svelte +268 -0
  6. package/dist/components/editors/ContentTabBulkDrop.svelte.d.ts +37 -0
  7. package/dist/components/editors/EmbedAssistantPanel.svelte +303 -0
  8. package/dist/components/editors/EmbedAssistantPanel.svelte.d.ts +29 -0
  9. package/dist/components/editors/EmbedEditor.svelte +221 -15
  10. package/dist/components/editors/EmbedEditor.svelte.d.ts +31 -3
  11. package/dist/components/editors/PropsEditor.svelte +326 -37
  12. package/dist/components/editors/PropsEditor.svelte.d.ts +11 -0
  13. package/dist/components/editors/propsEditorContentStateFlatten.d.ts +12 -0
  14. package/dist/components/editors/propsEditorContentStateFlatten.js +40 -0
  15. package/dist/components/ic/AngleInputController.svelte +9 -5
  16. package/dist/components/ic/BrowserInputController.svelte +208 -132
  17. package/dist/components/ic/BrowserInputController.svelte.d.ts +2 -0
  18. package/dist/components/ic/CheckboxInputController.svelte +11 -0
  19. package/dist/components/ic/ColorPickerInputController.svelte +122 -49
  20. package/dist/components/ic/DatePickerInputController.svelte +23 -13
  21. package/dist/components/ic/FixedPositionInputController.svelte +1 -1
  22. package/dist/components/ic/FontInputController.svelte +48 -47
  23. package/dist/components/ic/InputControllerHeader.svelte +5 -4
  24. package/dist/components/ic/KnowledgeDocumentsInputController.svelte +20 -7
  25. package/dist/components/ic/NumberControls.svelte +163 -35
  26. package/dist/components/ic/PositionInputController.svelte +24 -15
  27. package/dist/components/ic/RadioGroupInputController.svelte +11 -0
  28. package/dist/components/ic/RangeCalendarInputController.svelte +73 -28
  29. package/dist/components/ic/RoundedCornersInputController.svelte +2 -2
  30. package/dist/components/ic/SliderInputController.svelte +11 -4
  31. package/dist/components/ic/TextAreaInputController.svelte +620 -327
  32. package/dist/components/ic/TextAreaPreviewInputController.svelte +53 -64
  33. package/dist/components/ic/TextInputController.svelte +15 -2
  34. package/dist/components/ic/TimeInputController.svelte +1 -1
  35. package/dist/components/ic/VectorInputController.svelte +152 -20
  36. package/dist/components/ic/numberControlsValueArea.d.ts +29 -0
  37. package/dist/components/ic/numberControlsValueArea.js +51 -0
  38. package/dist/components/ic/optionGroupCardPointerDown.d.ts +9 -0
  39. package/dist/components/ic/optionGroupCardPointerDown.js +20 -0
  40. package/dist/components/ic/shared/DropdownChevron.svelte +2 -2
  41. package/dist/components/ic/shared/DropdownChevron.svelte.d.ts +1 -1
  42. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +174 -0
  43. package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +30 -0
  44. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte +34 -0
  45. package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte.d.ts +24 -0
  46. package/dist/components/ic/shared/ItemGrid.svelte +2 -2
  47. package/dist/components/ic/shared/RecentItemsSection.svelte +6 -6
  48. package/dist/components/ic/shared/editableFieldClasses.d.ts +15 -0
  49. package/dist/components/ic/shared/editableFieldClasses.js +15 -0
  50. package/dist/components/ic/shared/fileBrowserOverlayEscape.d.ts +29 -0
  51. package/dist/components/ic/shared/fileBrowserOverlayEscape.js +21 -0
  52. package/dist/components/ic/shared/index.d.ts +1 -0
  53. package/dist/components/ic/shared/index.js +1 -0
  54. package/dist/components/ui/calendar-editor-fit/EditorCalendarStyles.svelte +41 -9
  55. package/dist/composition/compositionApi.d.ts +16 -0
  56. package/dist/composition/compositionApi.js +16 -1
  57. package/dist/composition/compositionEditorController.d.ts +46 -0
  58. package/dist/composition/compositionEditorController.js +277 -5
  59. package/dist/composition/compositionEditorSchemaCache.d.ts +35 -0
  60. package/dist/composition/compositionEditorSchemaCache.js +82 -0
  61. package/dist/contentBulkDrop/applyContentPlan.d.ts +18 -0
  62. package/dist/contentBulkDrop/applyContentPlan.js +55 -0
  63. package/dist/contentBulkDrop/bulkDropSummary.d.ts +4 -0
  64. package/dist/contentBulkDrop/bulkDropSummary.js +12 -0
  65. package/dist/contentBulkDrop/dragIntent.d.ts +7 -0
  66. package/dist/contentBulkDrop/dragIntent.js +24 -0
  67. package/dist/contentBulkDrop/filterDropFiles.d.ts +2 -0
  68. package/dist/contentBulkDrop/filterDropFiles.js +21 -0
  69. package/dist/contentBulkDrop/formatFileSize.d.ts +2 -0
  70. package/dist/contentBulkDrop/formatFileSize.js +13 -0
  71. package/dist/contentBulkDrop/types.d.ts +34 -0
  72. package/dist/contentBulkDrop/types.js +1 -0
  73. package/dist/contentBulkDrop/uploadQueue.d.ts +41 -0
  74. package/dist/contentBulkDrop/uploadQueue.js +114 -0
  75. package/dist/drafts/compositionDraft.d.ts +65 -0
  76. package/dist/drafts/compositionDraft.js +136 -0
  77. package/dist/drafts/compositionEditorViewState.d.ts +9 -0
  78. package/dist/drafts/compositionEditorViewState.js +33 -0
  79. package/dist/drafts/draftJournal.d.ts +59 -0
  80. package/dist/drafts/draftJournal.js +261 -0
  81. package/dist/embed/__fixtures__/gatewayGeneratedEmbedCodes.json +25 -0
  82. package/dist/embed/__fixtures__/generatedEmbedCodes.json +320 -0
  83. package/dist/embed/parseCompositionEmbedCode.d.ts +21 -0
  84. package/dist/embed/parseCompositionEmbedCode.js +376 -0
  85. package/dist/embedAssistant/embedAssistantEvents.d.ts +22 -0
  86. package/dist/embedAssistant/embedAssistantEvents.js +39 -0
  87. package/dist/embedAssistant/embedAssistantStream.d.ts +30 -0
  88. package/dist/embedAssistant/embedAssistantStream.js +125 -0
  89. package/dist/embedAssistant/highlightTiming.d.ts +1 -0
  90. package/dist/embedAssistant/highlightTiming.js +6 -0
  91. package/dist/embedAssistant/types.d.ts +27 -0
  92. package/dist/embedAssistant/types.js +1 -0
  93. package/dist/i18n/labels.js +8 -4
  94. package/dist/i18n/language.d.ts +297 -3
  95. package/dist/i18n/messages.d.ts +38 -1
  96. package/dist/i18n/messages.js +40 -1
  97. package/dist/i18n/translate.d.ts +1 -1
  98. package/dist/index.d.ts +3 -1
  99. package/dist/index.js +2 -0
  100. package/dist/utils/FontManager.d.ts +2 -0
  101. package/dist/utils/FontManager.js +16 -1
  102. package/dist/utils/angleMath.d.ts +2 -0
  103. package/dist/utils/angleMath.js +6 -0
  104. package/dist/utils/isEditableEventTarget.d.ts +5 -0
  105. package/dist/utils/isEditableEventTarget.js +25 -0
  106. package/dist/utils/linkUrlValidation.d.ts +17 -0
  107. package/dist/utils/linkUrlValidation.js +120 -0
  108. package/dist/utils/mediaFileValue.d.ts +12 -0
  109. package/dist/utils/mediaFileValue.js +24 -0
  110. package/dist/utils/placeRichTextCaretAtDocumentEnd.d.ts +11 -0
  111. package/dist/utils/placeRichTextCaretAtDocumentEnd.js +26 -0
  112. package/package.json +6 -6
@@ -13,7 +13,7 @@
13
13
  const browser = typeof window !== 'undefined';
14
14
 
15
15
  // Svelte imports
16
- import { onMount, onDestroy, createEventDispatcher, afterUpdate } from 'svelte';
16
+ import { onMount, onDestroy, createEventDispatcher, afterUpdate, tick } from 'svelte';
17
17
  const dispatch = createEventDispatcher();
18
18
  import { writable, get, type Writable } from 'svelte/store';
19
19
  import type {
@@ -86,6 +86,11 @@
86
86
  import FontManager from '../../utils/FontManager';
87
87
  import { conditionHolds } from '../../utils/visibilityCondition';
88
88
  import { removeEditorStorageValuesStartingWith } from '../../utils/editorStorage';
89
+ import {
90
+ readCompositionEditorViewState,
91
+ writeCompositionEditorViewState,
92
+ type CompositionEditorViewStateV1
93
+ } from '../../drafts/compositionEditorViewState.js';
89
94
  import { reorderableList, moveListItem, type ItemReorderOptions } from '../../utils/itemReorder';
90
95
  import {
91
96
  lockPointerStyle,
@@ -95,11 +100,17 @@
95
100
  type SearchableTree
96
101
  } from '../../utils/shadowDom';
97
102
  import { config as appConfig } from '../../config';
103
+ import { hydrateBrowserFileValue } from '../../utils/mediaFileValue';
98
104
  import { provideEditorMediaLibrary } from '../../mediaLibraryContext';
99
105
  import { provideEditorPickFile, type PartnerPickFileFn } from '../../pickFileContext';
100
106
  import { provideEditorStoreFileUrl, type StoreFileUrlFn } from '../../fileStorageUrlContext';
101
107
  import { useEditorLanguage } from '../../i18n/language';
108
+ import { isEditableEventTarget } from '../../utils/isEditableEventTarget';
109
+ import { flattenContentStateFromParent, isItemFieldStateKey } from './propsEditorContentStateFlatten';
102
110
  import type { MediaLibraryProvider } from '@widgetic/file-browser';
111
+ import ContentTabBulkDrop from './ContentTabBulkDrop.svelte';
112
+ import { applyContentPlan } from '../../contentBulkDrop/applyContentPlan.js';
113
+ import type { ContentFromFilesPlan } from '../../contentBulkDrop/types.js';
103
114
 
104
115
  /**
105
116
  * STYLES from Widgetic Design System
@@ -152,6 +163,9 @@
152
163
 
153
164
  /** Portal slot for FileBrowser overlay — scoped to editor panel, not document body. */
154
165
  let fileBrowserPortalHost: HTMLDivElement | null = null;
166
+ /** Tab scroll panels — passed to textarea preview portals so overlays stay inside the card. */
167
+ let designTabPortalHost: HTMLDivElement | null = null;
168
+ let contentTabPortalHost: HTMLDivElement | null = null;
155
169
 
156
170
  // Determine if the first accordion item should be open by default
157
171
  export let defaultOpen: boolean = true;
@@ -170,6 +184,8 @@
170
184
 
171
185
  /** Optional content below the shared toolbar, before property fields. */
172
186
  export let headerContent = undefined;
187
+ /** Bottom padding inside the scroll area (the embed editor, which has no controls below the list, uses 16px / `pb-4`). */
188
+ export let scrollAreaBottomPaddingClass = 'pb-6';
173
189
  /**
174
190
  * The space above the first accordion when there is only one tab. Under a header block (the Embed code header) Figma's panel gap
175
191
  * puts the first accordion 16 below it; without a header the list starts 24 below the panel's top edge.
@@ -186,6 +202,8 @@
186
202
  // Initial values from saved composition (merged over schema defaults)
187
203
  export let initialDesignValues: Record<string, any> = {};
188
204
  export let initialContentValues: Record<string, any> = {};
205
+ /** Property ids to flash briefly when the embed assistant applies options. */
206
+ export let flashPropertyIds: string[] = [];
189
207
 
190
208
  /**
191
209
  * Where the file controls (images, video, audio, documents) get their files from. Without it they show the
@@ -194,10 +212,18 @@
194
212
  * storage (a CMS, an S3 bucket, a DAM) can be used with no Widgetic storage at all.
195
213
  */
196
214
  export let mediaLibrary: MediaLibraryProvider | undefined = undefined;
215
+ /** Calls POST /compositions/:id/content-items/from-files (plan only). Wired by CompositionEditorApp. */
216
+ export let requestContentFromFilesPlan:
217
+ | ((files: Array<{ name: string; mimeType: string; sizeBytes?: number; mediaId: string }>) => Promise<ContentFromFilesPlan>)
218
+ | undefined = undefined;
197
219
  /** When given, file fields call this instead of opening the built-in File Browser. */
198
220
  export let pickFile: PartnerPickFileFn | undefined = undefined;
199
221
  /** When given, resolves the url stored with a picked file (partner `mediaLibrary.urlResolver`). */
200
222
  export let storeFileUrl: StoreFileUrlFn | undefined = undefined;
223
+ /** When set (composition id), tab, scroll, accordions and open content cards persist in sessionStorage. */
224
+ export let viewStatePersistenceKey: string | undefined = undefined;
225
+ /** Device preview mode, stored with the props-panel view state by the composition editor shell. */
226
+ export let persistedDeviceView: 'desktop' | 'mobile' = 'desktop';
201
227
  // The file controls are created from the schema several components down: give them the library through context.
202
228
  provideEditorMediaLibrary(() => mediaLibrary);
203
229
  provideEditorPickFile(() => pickFile);
@@ -226,7 +252,11 @@
226
252
  let hasLoggedDesign = false; // Prevents duplicate logging of design tab info
227
253
  let hasLoggedContent = false; // Prevents duplicate logging of content tab info
228
254
  let designState: Record<string, InputValue> = { ...initialDesignValues }; // Stores design property values
229
- let contentState: Record<string, InputValue> = { ...initialContentValues }; // Stores content property values
255
+ let contentState: Record<string, InputValue> = flattenContentStateFromParent(
256
+ initialContentValues,
257
+ contentSchema,
258
+ hydrateBrowserFileValue
259
+ );
230
260
 
231
261
  let prevInitialDesignValues = initialDesignValues;
232
262
  $: if (initialDesignValues !== prevInitialDesignValues) {
@@ -237,7 +267,20 @@
237
267
  let prevInitialContentValues = initialContentValues;
238
268
  $: if (initialContentValues !== prevInitialContentValues) {
239
269
  prevInitialContentValues = initialContentValues;
240
- contentState = { ...initialContentValues };
270
+ // The parent stores item fields under `items[id][prop]`; the controllers read the flat `itemId__prop` keys.
271
+ // An item field the editor already holds wins, so a full file object (thumbnail, hash) survives the parent
272
+ // echoing back only its url, and the content thumbnails do not revert to the folder icon.
273
+ const parentContentState = flattenContentStateFromParent(
274
+ initialContentValues,
275
+ contentSchema,
276
+ hydrateBrowserFileValue
277
+ );
278
+ const mergedContentState: Record<string, InputValue> = { ...contentState };
279
+ for (const [stateKey, parentValue] of Object.entries(parentContentState)) {
280
+ if (isItemFieldStateKey(stateKey) && mergedContentState[stateKey] !== undefined) continue;
281
+ mergedContentState[stateKey] = parentValue as InputValue;
282
+ }
283
+ contentState = mergedContentState;
241
284
  }
242
285
  let isGenericContentOpen = true; // Controls generic content section visibility
243
286
  let lastFocusedDesignController: string | null = null; // Tracks last focused design input
@@ -484,7 +527,7 @@
484
527
  const liveOnItem = propKey != null ? (item as Record<string, unknown>)[propKey] : undefined;
485
528
  const seed = pickLiveContentValue(parentValue, liveOnItem, prop.value);
486
529
  if (seed !== undefined && seed !== '') {
487
- patch[key] = seed as InputValue;
530
+ patch[key] = (typeof seed === 'object' ? hydrateBrowserFileValue(seed) : seed) as InputValue;
488
531
  needsUpdate = true;
489
532
  }
490
533
  }
@@ -521,13 +564,6 @@
521
564
 
522
565
  // Drag handles are now declarative (on:mousedown in template) — no imperative setup needed
523
566
 
524
- if (defaultOpen && designSchema?.[0]?.components?.[0]?.propertyGroups) {
525
- // Open all property groups by default
526
- designOpenAccordion = designSchema[0].components
527
- .flatMap((c: any) => (c.propertyGroups || []).map((pg: PropertyGroup) => pg.name))
528
- .filter(Boolean);
529
- }
530
-
531
567
  // Return cleanup function
532
568
  return () => {
533
569
  if (cleanup) cleanup();
@@ -546,6 +582,7 @@
546
582
  * ON DESTROY
547
583
  */
548
584
  onDestroy(() => {
585
+ if (viewStatePersistTimer) clearTimeout(viewStatePersistTimer);
549
586
  // Clean up drag listeners
550
587
  if (browser) {
551
588
  document.removeEventListener('mousemove', handleDragMove);
@@ -989,8 +1026,11 @@
989
1026
  const stateValue = schema === 'design' ? designState[propertyId] : contentState[propertyId];
990
1027
  let initialValue = stateValue !== undefined ? stateValue : (property.value !== undefined ? property.value : property.defaultValue);
991
1028
 
992
- // portalTarget for overlays (browser = full editor panel; textarea preview = tab panel)
993
- let portalTarget: string | HTMLElement = schema === 'design' ? 'tab-design-container' : 'tab-content-container';
1029
+ // portalTarget for overlays (browser = full editor panel; textarea = the tab shell, which is the visible controller area under the tabs: it clips the scrolling list, so the edit mode fits what the person sees, the gap under it included. The scroll viewport inside it is as tall as the whole list, round 26)
1030
+ let portalTarget: string | HTMLElement =
1031
+ schema === 'design'
1032
+ ? (designTabPortalHost ?? 'tab-design-container')
1033
+ : (contentTabPortalHost ?? 'tab-content-container');
994
1034
  if (inputController.type.toLowerCase() === 'browser') {
995
1035
  portalTarget = fileBrowserPortalHost ?? 'props-editor-file-browser-portal';
996
1036
  }
@@ -1275,6 +1315,7 @@
1275
1315
  closeAllDropdowns();
1276
1316
  scrollPosition = measurements.scrollTop;
1277
1317
  }
1318
+ schedulePersistViewState();
1278
1319
  });
1279
1320
  }, 16);
1280
1321
 
@@ -1282,10 +1323,113 @@
1282
1323
  let openItems = new Set<string>();
1283
1324
  let draggedItem: string | null = null;
1284
1325
  let previouslyOpen = new Set<string>();
1326
+ let viewStateRestored = false;
1327
+ let viewStatePersistTimer: ReturnType<typeof setTimeout> | null = null;
1328
+
1329
+ function validContentItemIds(): Set<string> {
1330
+ return new Set(
1331
+ contentItems
1332
+ .map((item) => (item && typeof item === 'object' ? item.id : undefined))
1333
+ .filter((id): id is string => typeof id === 'string' && id !== '')
1334
+ );
1335
+ }
1336
+
1337
+ function restoreViewStateFromSession() {
1338
+ if (!viewStatePersistenceKey || viewStateRestored) return;
1339
+ viewStateRestored = true;
1340
+ const stored = readCompositionEditorViewState(viewStatePersistenceKey, validContentItemIds());
1341
+ if (!stored) return;
1342
+ if (designSchema && contentSchema) {
1343
+ currentTab = stored.activeTab;
1344
+ } else if (contentSchema) {
1345
+ currentTab = 'content';
1346
+ } else if (designSchema) {
1347
+ currentTab = 'design';
1348
+ }
1349
+ designOpenAccordion = stored.designOpenAccordion;
1350
+ contentOpenAccordion = stored.contentOpenAccordion;
1351
+ if (stored.designOpenAccordion.length > 0) {
1352
+ markAccordionSectionsMounted('design', stored.designOpenAccordion);
1353
+ }
1354
+ if (stored.openContentItemIds.length > 0) {
1355
+ openItems = new Set(stored.openContentItemIds);
1356
+ markAccordionSectionsMounted('content', stored.openContentItemIds);
1357
+ }
1358
+ void tick().then(() => {
1359
+ if (designContentWrapper) designContentWrapper.scrollTop = stored.designScrollTop;
1360
+ if (contentWrapper) contentWrapper.scrollTop = stored.contentScrollTop;
1361
+ });
1362
+ }
1363
+
1364
+ function buildViewStateSnapshot(): CompositionEditorViewStateV1 {
1365
+ const openList = [...openItems];
1366
+ return {
1367
+ v: 1,
1368
+ activeTab: currentTab === 'design' ? 'design' : 'content',
1369
+ designOpenAccordion: [...designOpenAccordion],
1370
+ contentOpenAccordion: [...contentOpenAccordion],
1371
+ openContentItemIds: openList,
1372
+ designScrollTop: designContentWrapper?.scrollTop ?? 0,
1373
+ contentScrollTop: contentWrapper?.scrollTop ?? 0,
1374
+ deviceView: persistedDeviceView,
1375
+ activeContentItemId: openList[0] ?? null
1376
+ };
1377
+ }
1378
+
1379
+ function schedulePersistViewState() {
1380
+ if (!browser || !viewStatePersistenceKey || !viewStateRestored) return;
1381
+ if (viewStatePersistTimer) clearTimeout(viewStatePersistTimer);
1382
+ viewStatePersistTimer = setTimeout(() => {
1383
+ viewStatePersistTimer = null;
1384
+ writeCompositionEditorViewState(viewStatePersistenceKey!, buildViewStateSnapshot());
1385
+ }, 250);
1386
+ }
1387
+
1388
+ $: if (browser && viewStatePersistenceKey && (designSchema || contentSchema) && !viewStateRestored) {
1389
+ restoreViewStateFromSession();
1390
+ }
1391
+
1392
+ $: if (browser && viewStatePersistenceKey && viewStateRestored) {
1393
+ currentTab;
1394
+ designOpenAccordion;
1395
+ contentOpenAccordion;
1396
+ openItems;
1397
+ persistedDeviceView;
1398
+ schedulePersistViewState();
1399
+ }
1285
1400
 
1286
1401
  // Add after the state declarations
1287
1402
  $: isItemOpen = (itemId: string) => openItems.has(itemId);
1288
1403
 
1404
+ /**
1405
+ * A content card keeps its body mounted for a while after it closes. A closed Collapsible only hides its content, so a
1406
+ * card that was open a moment ago opens again as a display change and not as a mount of all its input controllers
1407
+ * (which took 60 to 170 ms for the card with every kind of controller when the machine was busy). Only the last few
1408
+ * closed bodies are kept, so a long list does not keep every card it ever opened alive: each kept body still follows
1409
+ * the schema, and that is the price of keeping it.
1410
+ */
1411
+ const MAX_CLOSED_ITEM_BODIES_KEPT = 4;
1412
+ let closedItemBodies: string[] = [];
1413
+ let previousOpenItemIds = new Set<string>();
1414
+
1415
+ /** Works out which cards closed since the last run, from the open set alone, so every way a card closes is covered. */
1416
+ function trackClosedItemBodies(currentOpenItems: Set<string>) {
1417
+ try {
1418
+ const justClosedItemIds = [...previousOpenItemIds].filter((itemId) => !currentOpenItems.has(itemId));
1419
+ const stillKeptItemIds = closedItemBodies.filter(
1420
+ (itemId) => !currentOpenItems.has(itemId) && !justClosedItemIds.includes(itemId)
1421
+ );
1422
+ // "Last few closed bodies": the oldest ones are dropped first.
1423
+ closedItemBodies = [...stillKeptItemIds, ...justClosedItemIds].slice(-MAX_CLOSED_ITEM_BODIES_KEPT);
1424
+ previousOpenItemIds = new Set(currentOpenItems);
1425
+ } catch (error) {
1426
+ console.error('[PropsEditor] Could not track the closed content card bodies:', error);
1427
+ }
1428
+ }
1429
+ // Keep this statement above `isItemBodyMounted`: that one reads what this one assigns.
1430
+ $: trackClosedItemBodies(openItems);
1431
+ $: isItemBodyMounted = (itemId: string) => openItems.has(itemId) || closedItemBodies.includes(itemId);
1432
+
1289
1433
  /**
1290
1434
  * Manages the open/closed state of content items
1291
1435
  * @param itemId - Identifier for the content item to toggle
@@ -1384,13 +1528,73 @@
1384
1528
  }
1385
1529
 
1386
1530
  // Update the Accordion components to include value prop
1531
+ /** Accordion bodies stay unmounted until first open so heavy input controllers are not created eagerly. */
1532
+ let designAccordionMounted = new Set<string>();
1533
+ let contentAccordionMounted = new Set<string>();
1534
+
1535
+ function collectDesignAccordionGroupNames(schema: typeof designSchema): string[] {
1536
+ if (!schema?.[0]?.components) return [];
1537
+ return schema[0].components
1538
+ .flatMap((component: DesignSchemaComponentView) =>
1539
+ (component.propertyGroups || []).map((group: PropertyGroup) => group.name)
1540
+ )
1541
+ .filter(Boolean);
1542
+ }
1543
+
1544
+ function markAccordionSectionsMounted(tab: 'design' | 'content', sectionIds: string[]) {
1545
+ const targetSet = tab === 'design' ? designAccordionMounted : contentAccordionMounted;
1546
+ let grew = false;
1547
+ for (const sectionId of sectionIds) {
1548
+ if (!targetSet.has(sectionId)) {
1549
+ targetSet.add(sectionId);
1550
+ grew = true;
1551
+ }
1552
+ }
1553
+ if (grew) {
1554
+ if (tab === 'design') {
1555
+ designAccordionMounted = new Set(targetSet);
1556
+ } else {
1557
+ contentAccordionMounted = new Set(targetSet);
1558
+ }
1559
+ }
1560
+ }
1561
+
1562
+ let defaultOpenDesignSchemaRef: typeof designSchema | undefined = undefined;
1563
+
1564
+ /** First paint: every default-open section is open and mounted before the user sees a frame. */
1565
+ $: if (defaultOpen && designSchema && designSchema !== defaultOpenDesignSchemaRef) {
1566
+ defaultOpenDesignSchemaRef = designSchema;
1567
+ const groupNames = collectDesignAccordionGroupNames(designSchema);
1568
+ if (groupNames.length > 0) {
1569
+ designOpenAccordion = groupNames;
1570
+ markAccordionSectionsMounted('design', groupNames);
1571
+ }
1572
+ }
1573
+
1387
1574
  function handleAccordionChange(value: string | string[]) {
1388
1575
  const arr = Array.isArray(value) ? value : [value];
1576
+ const previousOpen = currentTab === 'design' ? designOpenAccordion : contentOpenAccordion;
1577
+ const newlyOpenedSections = arr.filter((sectionId) => !previousOpen.includes(sectionId));
1389
1578
  if (currentTab === 'design') {
1390
1579
  designOpenAccordion = arr;
1391
1580
  } else {
1392
1581
  contentOpenAccordion = arr;
1393
1582
  }
1583
+ if (newlyOpenedSections.length > 0) {
1584
+ const tab: 'design' | 'content' = currentTab === 'design' ? 'design' : 'content';
1585
+ const mountNow =
1586
+ defaultOpen && newlyOpenedSections.length === arr.length && previousOpen.length === 0;
1587
+ if (mountNow) {
1588
+ markAccordionSectionsMounted(tab, newlyOpenedSections);
1589
+ } else {
1590
+ // Mount heavy accordion bodies after the open animation paints (avoids long tasks on the click frame).
1591
+ requestAnimationFrame(() => {
1592
+ requestAnimationFrame(() => {
1593
+ markAccordionSectionsMounted(tab, newlyOpenedSections);
1594
+ });
1595
+ });
1596
+ }
1597
+ }
1394
1598
  }
1395
1599
 
1396
1600
  // Stores content property values for open groups
@@ -1431,6 +1635,7 @@
1431
1635
  // console.log("handleKeyDown triggered: key=", event.key, "shiftKey=", event.shiftKey);
1432
1636
  // The listener is on the window, so it hears every key typed on the page. Only the ones typed in the editor
1433
1637
  // count: on a customer's page Shift+Arrow in their own text boxes must not open and close our items.
1638
+ if (isEditableEventTarget(event)) return;
1434
1639
  if (rootElement && !event.composedPath().includes(rootElement)) return;
1435
1640
  if (event.shiftKey && event.key === 'ArrowDown') {
1436
1641
  // console.log("Expanding all content items");
@@ -1572,6 +1777,40 @@
1572
1777
  return genericIds !== itemIds;
1573
1778
  }
1574
1779
 
1780
+ function handleBulkPlanReady(event: CustomEvent<{ plan: ContentFromFilesPlan; mediaIds: Map<string, import('@widgetic/file-browser').MediaLibraryFile> }>) {
1781
+ try {
1782
+ const { plan, mediaIds } = event.detail;
1783
+ if (!contentSchema || !Array.isArray(contentSchema.contentItems)) return;
1784
+ const applied = applyContentPlan(
1785
+ contentSchema.contentItems as Array<{ id: string; title: string; properties: Array<Record<string, unknown>> }>,
1786
+ itemTemplate,
1787
+ plan,
1788
+ mediaIds
1789
+ );
1790
+ if (!applied) {
1791
+ console.warn('[BulkDrop] Could not apply plan: no item template');
1792
+ return;
1793
+ }
1794
+ contentSchema = { ...contentSchema, contentItems: applied.contentItems };
1795
+ contentState = { ...contentState, ...applied.contentState };
1796
+ dispatch('updated', { contentSchema });
1797
+ dispatchContentItemsChanged(contentSchema.contentItems);
1798
+ const lastId = applied.newItemIds[applied.newItemIds.length - 1];
1799
+ if (!lastId) return;
1800
+ openItems = new Set([...openItems, lastId]);
1801
+ const itemIndex = contentSchema.contentItems.findIndex((item: ContentItem) => item.id === lastId);
1802
+ if (itemIndex >= 0) {
1803
+ dispatch('goToItem', { index: itemIndex });
1804
+ void tick().then(() => {
1805
+ const node = contentItemsContainer?.querySelector(`[data-id="${lastId}"]`);
1806
+ node?.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
1807
+ });
1808
+ }
1809
+ } catch (error) {
1810
+ console.error('[BulkDrop] Failed to apply plan:', error);
1811
+ }
1812
+ }
1813
+
1575
1814
  function handleAddNewItem() {
1576
1815
  try {
1577
1816
  if (!contentSchema) {
@@ -1670,7 +1909,7 @@
1670
1909
 
1671
1910
  function unwrapContentMediaValue(raw: unknown): unknown {
1672
1911
  if (raw && typeof raw === 'object' && 'url' in (raw as Record<string, unknown>)) {
1673
- return (raw as { url?: string }).url ?? '';
1912
+ return hydrateBrowserFileValue(raw);
1674
1913
  }
1675
1914
  return raw;
1676
1915
  }
@@ -2076,7 +2315,7 @@
2076
2315
  class="drag-handle-container flex cursor-move items-center justify-center opacity-100 duration-fast transition-opacity {showSaveButton ? 'h-8' : 'h-4'}"
2077
2316
  onmousedown={handleDragStart}
2078
2317
  >
2079
- <IconGripHorizontal class="size-4 stroke-[1.333] text-muted-foreground {dragHandleClass}" />
2318
+ <IconGripHorizontal class="size-4 stroke-2 text-muted-foreground {dragHandleClass}" />
2080
2319
  </div>
2081
2320
  {#if showSaveButton}
2082
2321
  {#if titleLabel}
@@ -2098,7 +2337,7 @@
2098
2337
  onmousedown={(e) => e.stopPropagation()}
2099
2338
  >
2100
2339
  {#if saveSaving}
2101
- <IconLoader2 class="size-4 animate-spin stroke-[1.333]" aria-hidden="true" />
2340
+ <IconLoader2 class="size-4 animate-spin stroke-2" aria-hidden="true" />
2102
2341
  {/if}
2103
2342
  {saveSaving ? $t('editor.props.saving') : $t('editor.props.save')}
2104
2343
  </Button>
@@ -2137,7 +2376,9 @@
2137
2376
  {/if}
2138
2377
 
2139
2378
  <!-- Design Tab Content -->
2140
- <div class="tab-design-container grow scroll-area hidden {headerContent ? 'min-h-0 flex-1 overflow-hidden' : 'overflow-y-auto'}"
2379
+ <div
2380
+ bind:this={designTabPortalHost}
2381
+ class="tab-design-container grow scroll-area relative hidden min-h-0 flex-1 overflow-hidden"
2141
2382
  class:hidden={currentTab !== 'design'}
2142
2383
  style="max-height: {!designSchema || !contentSchema ? '100%' : `calc(100% - ${HEADER_HEIGHT}px)`}"
2143
2384
  data-scrollable={$designScrollState.shouldShowScroll}
@@ -2146,10 +2387,10 @@
2146
2387
  class="h-full"
2147
2388
  type="hover"
2148
2389
  scrollHideDelay={0}
2149
- scrollbarYClasses="flex w-6 touch-none select-none px-2 pb-6 transition-colors duration-fast {headerContent ? 'bg-transparent' : 'bg-background'} {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'} [&>div]:w-2 [&>div]:cursor-pointer [&>div]:rounded-full [&>div]:bg-border [&>div]:duration-fast [&>div]:hover:bg-muted-foreground/30"
2390
+ scrollbarYClasses="flex w-6 touch-none select-none px-2 {scrollAreaBottomPaddingClass} bg-transparent transition-colors duration-fast {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'} [&>div]:w-2 [&>div]:cursor-pointer [&>div]:rounded-full [&>div]:bg-border [&>div]:duration-fast [&>div]:hover:bg-muted-foreground/30"
2150
2391
  >
2151
- <div class="scroll-viewport" data-radix-scroll-area-viewport bind:this={designScrollViewport}>
2152
- <div class="px-6 pb-6 {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'}" bind:this={designContentWrapper}>
2392
+ <div class="scroll-viewport props-editor-scroll-viewport relative" data-radix-scroll-area-viewport bind:this={designScrollViewport}>
2393
+ <div class="props-editor-scroll-inner {scrollAreaBottomPaddingClass} {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'}" bind:this={designContentWrapper}>
2153
2394
  <Tabs.Content
2154
2395
  value="design"
2155
2396
  class="design-tab-content mt-0! tabs-content-container w-full outline-none {isFirstLoad ? 'initial-load' : !isInitialTabLoad ? 'animate-slide-left' : ''}"
@@ -2181,6 +2422,7 @@
2181
2422
 
2182
2423
  <!-- The DS body pads 4 / 16 / 16 / 16 (Figma Accordion Item). Every row carries 6 above and below its 36px control (48 pitch), so the list pulls 6 back at both ends and the padding lands on the controls. -->
2183
2424
  <Accordion.Content class="accordion-content w-full min-w-0" data-accordion-content>
2425
+ {#if designAccordionMounted.has(propertyGroup.name)}
2184
2426
  <div class="properties-list -my-1.5 flex w-full flex-col">
2185
2427
  {#each propertyGroup.properties as property, propertyIndex (propertyGroup.name + '_' + (property.id ?? property.name ?? propertyIndex))}
2186
2428
  {@const result = renderInputController('design', property, propertyIndex, groupIndex === 0)}
@@ -2211,7 +2453,7 @@
2211
2453
  </div>
2212
2454
  {:else}
2213
2455
  <InputControllerRow
2214
- class="ictrl input-controller p-0 {isPositionIc ? 'position-controller' : ''} {isPositionIc && isDragging ? 'position-dragging' : ''}"
2456
+ class="ictrl input-controller p-0 {isPositionIc ? 'position-controller' : ''} {isPositionIc && isDragging ? 'position-dragging' : ''} {flashPropertyIds.includes(stateKey) ? 'rounded-lg ring-2 ring-[#5c7a59] motion-reduce:transition-none' : ''}"
2215
2457
  dataState={rowDataState}
2216
2458
  label={header.label}
2217
2459
  helpText={header.helpText}
@@ -2227,6 +2469,7 @@
2227
2469
  {/if}
2228
2470
  {/each}
2229
2471
  </div>
2472
+ {/if}
2230
2473
  </Accordion.Content>
2231
2474
  </Accordion.Item>
2232
2475
  {/each}
@@ -2253,7 +2496,9 @@
2253
2496
 
2254
2497
  <!-- Content Tab Content -->
2255
2498
  {#if contentSchema}
2256
- <div class="tab-content-container scroll-area hidden grow overflow-y-auto"
2499
+ <div
2500
+ bind:this={contentTabPortalHost}
2501
+ class="tab-content-container scroll-area relative hidden min-h-0 grow overflow-hidden"
2257
2502
  class:hidden={currentTab !== 'content'}
2258
2503
  style="max-height: {!contentSchema || !designSchema ? '100%' : `calc(100% - ${HEADER_HEIGHT}px)`}"
2259
2504
  data-scrollable={$contentScrollState.shouldShowScroll}
@@ -2262,10 +2507,10 @@
2262
2507
  class="h-full"
2263
2508
  type="hover"
2264
2509
  scrollHideDelay={0}
2265
- scrollbarYClasses="flex w-6 touch-none select-none px-2 pb-6 transition-colors duration-fast {headerContent ? 'bg-transparent' : 'bg-background'} {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'} [&>div]:w-2 [&>div]:cursor-pointer [&>div]:rounded-full [&>div]:bg-border [&>div]:duration-fast [&>div]:hover:bg-muted-foreground/30"
2510
+ scrollbarYClasses="flex w-6 touch-none select-none px-2 {scrollAreaBottomPaddingClass} bg-transparent transition-colors duration-fast {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'} [&>div]:w-2 [&>div]:cursor-pointer [&>div]:rounded-full [&>div]:bg-border [&>div]:duration-fast [&>div]:hover:bg-muted-foreground/30"
2266
2511
  >
2267
- <div class="scroll-viewport" data-radix-scroll-area-viewport bind:this={contentScrollViewport}>
2268
- <div class="px-6 pb-6 {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'}" bind:this={contentWrapper}>
2512
+ <div class="scroll-viewport props-editor-scroll-viewport relative" data-radix-scroll-area-viewport bind:this={contentScrollViewport}>
2513
+ <div class="props-editor-scroll-inner {scrollAreaBottomPaddingClass} {!designSchema || !contentSchema ? singleTabTopPaddingClass : 'pt-0'}" bind:this={contentWrapper}>
2269
2514
  <Tabs.Content
2270
2515
  value="content"
2271
2516
  class="content-tab-content mt-0! tabs-content-container w-full {isFirstLoad ? 'initial-load' : !isInitialTabLoad ? 'animate-slide-right' : ''}"
@@ -2274,6 +2519,12 @@
2274
2519
  >
2275
2520
  <!-- Content tab body text: Card defaults to text-card-foreground (16px); force Body 14/20 on controls. -->
2276
2521
  <div class="tab-content-root w-full text-body" style="position: relative; z-index: 1;">
2522
+ <ContentTabBulkDrop
2523
+ enabled={Boolean(requestContentFromFilesPlan && mediaLibrary)}
2524
+ {mediaLibrary}
2525
+ requestPlan={requestContentFromFilesPlan}
2526
+ on:planReady={handleBulkPlanReady}
2527
+ />
2277
2528
  <!-- Generic Content Collapsible Card -->
2278
2529
  {#if shouldShowGenericContentSection(contentSchema)}
2279
2530
  <Card.Root class="generic-content-card relative mt-0 overflow-hidden rounded-xl border-0 bg-popover text-body shadow-none ring-1 ring-inset ring-border" style="position: relative; z-index: 1;">
@@ -2284,12 +2535,12 @@
2284
2535
  <Collapsible.Trigger class="generic-content-trigger w-full focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background">
2285
2536
  <div class="flex h-12 cursor-pointer items-center gap-2 px-4 hover:bg-accent duration-fast transition-colors">
2286
2537
  <h3 class="text-body-medium text-foreground flex-1 text-start content-title">{contentSchema?.genericContent?.title || $t('editor.props.contentCard')}</h3>
2287
- <IconChevronDown class="chevron size-4 shrink-0 stroke-[1.333] text-muted-foreground transition-transform duration-base {isGenericContentOpen ? 'rotate-180' : ''}" />
2538
+ <IconChevronDown class="chevron size-4 shrink-0 stroke-2 text-muted-foreground transition-transform duration-base {isGenericContentOpen ? 'rotate-180' : ''}" />
2288
2539
  </div>
2289
2540
  </Collapsible.Trigger>
2290
2541
 
2291
2542
  <Collapsible.Content>
2292
- {#if isGenericContentOpen}
2543
+ <!-- Always mounted: the Collapsible only hides a closed body, so closing and opening this card (the one with every kind of controller) is a display change and not a mount of all its controllers. It is open by default, so the controllers are mounted anyway. -->
2293
2544
  <Card.Content class="p-0 px-4">
2294
2545
  <!-- Figma Content Card body: 4 / 16 / 16 / 16; every row carries 6 above and below its 36px control (48 pitch), so the list pulls 6 back at both ends. -->
2295
2546
  <div class="pt-1 pb-4">
@@ -2308,13 +2559,18 @@
2308
2559
 
2309
2560
  {#if isVisible}
2310
2561
  {@const isFontIc = property.inputController.type.toLowerCase() === 'font'}
2562
+ {@const stateKey = property.id || property.name}
2563
+ {@const reactiveValue = contentState[stateKey]}
2311
2564
  <!-- A panel (the documents of AI Answers) is a list and a form: it gets the whole width under its header. -->
2312
2565
  {@const isPanelIc = property.inputController.type.toLowerCase() === 'knowledgedocuments'}
2313
2566
  {#if isFontIc}
2314
2567
  <div class="ictrl input-controller font-ic-host flex w-full flex-col items-stretch p-0">
2315
2568
  <div class="ic-input-ct w-full">
2316
2569
  <InputControllerRenderer
2317
- controller={describeInputController(InputComponent, props)}
2570
+ controller={describeInputController(InputComponent, {
2571
+ ...props,
2572
+ value: reactiveValue !== undefined ? reactiveValue : props.value
2573
+ })}
2318
2574
  />
2319
2575
  </div>
2320
2576
  </div>
@@ -2345,7 +2601,6 @@
2345
2601
  </div>
2346
2602
  </div>
2347
2603
  </Card.Content>
2348
- {/if}
2349
2604
  </Collapsible.Content>
2350
2605
  </Collapsible.Root>
2351
2606
  </Card.Root>
@@ -2377,7 +2632,7 @@
2377
2632
  <div class="flex h-12 cursor-pointer items-center hover:bg-accent duration-fast transition-colors">
2378
2633
  <!-- 32 wide, grip centred: the 16px icon sits 8 from the start and the title begins at 32 (Figma Card Header). -->
2379
2634
  <div class="drag-handle flex w-8 shrink-0 cursor-move items-center justify-center touch-none">
2380
- <IconGripVertical class="size-4 stroke-[1.333] text-muted-foreground duration-fast transition-colors" />
2635
+ <IconGripVertical class="size-4 stroke-2 text-muted-foreground duration-fast transition-colors" />
2381
2636
  </div>
2382
2637
 
2383
2638
  <!-- Item Title — user caption/title wins; Slide N / Item 0N follow list position -->
@@ -2386,13 +2641,14 @@
2386
2641
  </h4>
2387
2642
 
2388
2643
  <div class="pe-4">
2389
- <IconChevronDown class="chevron size-4 shrink-0 stroke-[1.333] text-muted-foreground transition-transform duration-base {isItemOpen(item.id) ? 'rotate-180' : ''}" />
2644
+ <IconChevronDown class="chevron size-4 shrink-0 stroke-2 text-muted-foreground transition-transform duration-base {isItemOpen(item.id) ? 'rotate-180' : ''}" />
2390
2645
  </div>
2391
2646
  </div>
2392
2647
  </Collapsible.Trigger>
2393
2648
 
2394
2649
  <Collapsible.Content>
2395
- {#if isItemOpen(item.id)}
2650
+ <!-- Mounted while open and for a while after it closes (see `closedItemBodies`). -->
2651
+ {#if isItemBodyMounted(item.id)}
2396
2652
  <Card.Content class="p-0 px-4">
2397
2653
  <div class="pt-1 pb-4">
2398
2654
  <div class="properties-list -my-1.5 flex w-full flex-col">
@@ -2411,12 +2667,17 @@
2411
2667
 
2412
2668
  {#if isVisible && InputComponent}
2413
2669
  {@const isFontIc = (property.inputController?.type || '').toLowerCase() === 'font'}
2670
+ {@const stateKey = `${item.id}__${property.id || property.name}`}
2671
+ {@const reactiveValue = contentState[stateKey]}
2414
2672
  {@const isPanelIc = (property.inputController?.type || '').toLowerCase() === 'knowledgedocuments'}
2415
2673
  {#if isFontIc}
2416
2674
  <div class="ictrl input-controller font-ic-host flex w-full flex-col items-stretch p-0">
2417
2675
  <div class="ic-input-ct w-full">
2418
2676
  <InputControllerRenderer
2419
- controller={describeInputController(InputComponent, props)}
2677
+ controller={describeInputController(InputComponent, {
2678
+ ...props,
2679
+ value: reactiveValue !== undefined ? reactiveValue : props.value
2680
+ })}
2420
2681
  />
2421
2682
  </div>
2422
2683
  </div>
@@ -2472,14 +2733,21 @@
2472
2733
 
2473
2734
  {#if canAddContentItem()}
2474
2735
  <div class="content-add-item-ct mt-4">
2475
- <button
2736
+ <Button
2476
2737
  type="button"
2477
- class="flex h-12 w-full items-center justify-center gap-2 rounded-xl border border-brand bg-brand-subtle text-body-medium text-foreground duration-fast transition-colors hover:bg-accent focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
2738
+ variant="stroke"
2739
+ size="default"
2740
+ class="content-add-item-button w-full"
2478
2741
  onclick={handleAddNewItem}
2479
2742
  >
2480
- <IconPlus class="size-4 stroke-[1.333] text-brand" aria-hidden="true" />
2743
+ <IconPlus class="size-4 text-brand" aria-hidden="true" />
2481
2744
  {$t('editor.props.addItem')}
2482
- </button>
2745
+ </Button>
2746
+ {#if requestContentFromFilesPlan && mediaLibrary}
2747
+ <p class="text-caption text-muted-foreground mt-2 w-full text-center">
2748
+ {$t('editor.contentBulkDrop.idleHint')}
2749
+ </p>
2750
+ {/if}
2483
2751
  </div>
2484
2752
  {/if}
2485
2753
  </div>
@@ -2505,6 +2773,27 @@
2505
2773
  --has-both-schemas: 0;
2506
2774
  }
2507
2775
 
2776
+ /* Keep the vertical scrollbar inside the panel's horizontal padding so it never sits on card borders. */
2777
+ :global(.props-editor-container .props-editor-scroll-viewport) {
2778
+ scrollbar-gutter: stable;
2779
+ padding-inline: 1.5rem;
2780
+ background: transparent;
2781
+ }
2782
+
2783
+ :global(.props-editor-container .scroll-area) {
2784
+ background: transparent;
2785
+ }
2786
+
2787
+ /* Inset the vertical scrollbar by the panel's horizontal padding so it never sits on card borders. */
2788
+ :global(.props-editor-container [data-orientation='vertical'][data-state]) {
2789
+ inset-inline-end: 1.5rem;
2790
+ }
2791
+
2792
+ :global(.props-editor-container .props-editor-scroll-inner) {
2793
+ padding-inline: 0;
2794
+ min-width: 0;
2795
+ }
2796
+
2508
2797
  /* Both tabs: design content sits below the tab list when both schemas exist. */
2509
2798
  .props-editor-container:has(.tabs-header) {
2510
2799
  --has-both-schemas: 1rem;