@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.
- package/dist/components/WidgetPreview.svelte +77 -14
- package/dist/components/editors/CompositionEditorApp.svelte +71 -35
- package/dist/components/editors/CompositionEditorApp.svelte.d.ts +3 -1
- package/dist/components/editors/ContentTabBulkDrop.svelte +268 -0
- package/dist/components/editors/ContentTabBulkDrop.svelte.d.ts +37 -0
- package/dist/components/editors/EmbedAssistantPanel.svelte +303 -0
- package/dist/components/editors/EmbedAssistantPanel.svelte.d.ts +29 -0
- package/dist/components/editors/EmbedEditor.svelte +221 -15
- package/dist/components/editors/EmbedEditor.svelte.d.ts +31 -3
- package/dist/components/editors/PropsEditor.svelte +223 -30
- package/dist/components/editors/PropsEditor.svelte.d.ts +11 -0
- package/dist/components/editors/propsEditorContentStateFlatten.d.ts +12 -0
- package/dist/components/editors/propsEditorContentStateFlatten.js +40 -0
- package/dist/components/ic/BrowserInputController.svelte +184 -21
- package/dist/components/ic/BrowserInputController.svelte.d.ts +2 -0
- package/dist/components/ic/CheckboxInputController.svelte +11 -0
- package/dist/components/ic/ColorPickerInputController.svelte +2 -1
- package/dist/components/ic/DatePickerInputController.svelte +5 -3
- package/dist/components/ic/FontInputController.svelte +9 -4
- package/dist/components/ic/InputControllerHeader.svelte +4 -3
- package/dist/components/ic/KnowledgeDocumentsInputController.svelte +13 -0
- package/dist/components/ic/NumberControls.svelte +140 -17
- package/dist/components/ic/RadioGroupInputController.svelte +11 -0
- package/dist/components/ic/RangeCalendarInputController.svelte +38 -13
- package/dist/components/ic/TextAreaInputController.svelte +593 -321
- package/dist/components/ic/TextAreaPreviewInputController.svelte +46 -58
- package/dist/components/ic/VectorInputController.svelte +0 -1
- package/dist/components/ic/numberControlsValueArea.d.ts +29 -0
- package/dist/components/ic/numberControlsValueArea.js +51 -0
- package/dist/components/ic/optionGroupCardPointerDown.d.ts +9 -0
- package/dist/components/ic/optionGroupCardPointerDown.js +20 -0
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte +48 -6
- package/dist/components/ic/shared/EditorFileBrowserOverlay.svelte.d.ts +4 -1
- package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte +34 -0
- package/dist/components/ic/shared/EditorSelectedFilePreviewOverlay.svelte.d.ts +24 -0
- package/dist/components/ic/shared/fileBrowserOverlayEscape.d.ts +29 -0
- package/dist/components/ic/shared/fileBrowserOverlayEscape.js +21 -0
- package/dist/composition/compositionApi.d.ts +16 -0
- package/dist/composition/compositionApi.js +16 -1
- package/dist/composition/compositionEditorController.d.ts +46 -0
- package/dist/composition/compositionEditorController.js +277 -5
- package/dist/composition/compositionEditorSchemaCache.d.ts +35 -0
- package/dist/composition/compositionEditorSchemaCache.js +82 -0
- package/dist/contentBulkDrop/applyContentPlan.d.ts +18 -0
- package/dist/contentBulkDrop/applyContentPlan.js +55 -0
- package/dist/contentBulkDrop/bulkDropSummary.d.ts +4 -0
- package/dist/contentBulkDrop/bulkDropSummary.js +12 -0
- package/dist/contentBulkDrop/dragIntent.d.ts +7 -0
- package/dist/contentBulkDrop/dragIntent.js +24 -0
- package/dist/contentBulkDrop/filterDropFiles.d.ts +2 -0
- package/dist/contentBulkDrop/filterDropFiles.js +21 -0
- package/dist/contentBulkDrop/formatFileSize.d.ts +2 -0
- package/dist/contentBulkDrop/formatFileSize.js +13 -0
- package/dist/contentBulkDrop/types.d.ts +34 -0
- package/dist/contentBulkDrop/types.js +1 -0
- package/dist/contentBulkDrop/uploadQueue.d.ts +41 -0
- package/dist/contentBulkDrop/uploadQueue.js +114 -0
- package/dist/drafts/compositionDraft.d.ts +65 -0
- package/dist/drafts/compositionDraft.js +136 -0
- package/dist/drafts/compositionEditorViewState.d.ts +9 -0
- package/dist/drafts/compositionEditorViewState.js +33 -0
- package/dist/drafts/draftJournal.d.ts +59 -0
- package/dist/drafts/draftJournal.js +261 -0
- package/dist/embed/__fixtures__/gatewayGeneratedEmbedCodes.json +25 -0
- package/dist/embed/__fixtures__/generatedEmbedCodes.json +320 -0
- package/dist/embed/embedSchema.json +409 -0
- package/dist/embed/parseCompositionEmbedCode.d.ts +21 -0
- package/dist/embed/parseCompositionEmbedCode.js +379 -0
- package/dist/embedAssistant/embedAssistantEvents.d.ts +22 -0
- package/dist/embedAssistant/embedAssistantEvents.js +39 -0
- package/dist/embedAssistant/embedAssistantStream.d.ts +30 -0
- package/dist/embedAssistant/embedAssistantStream.js +125 -0
- package/dist/embedAssistant/highlightTiming.d.ts +1 -0
- package/dist/embedAssistant/highlightTiming.js +6 -0
- package/dist/embedAssistant/types.d.ts +27 -0
- package/dist/embedAssistant/types.js +1 -0
- package/dist/i18n/labels.js +8 -4
- package/dist/i18n/language.d.ts +38 -2
- package/dist/i18n/messages.d.ts +38 -1
- package/dist/i18n/messages.js +40 -1
- package/dist/i18n/translate.d.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/utils/FontManager.d.ts +2 -0
- package/dist/utils/FontManager.js +16 -1
- package/dist/utils/isEditableEventTarget.d.ts +5 -0
- package/dist/utils/isEditableEventTarget.js +25 -0
- package/dist/utils/linkUrlValidation.d.ts +17 -0
- package/dist/utils/linkUrlValidation.js +120 -0
- package/dist/utils/mediaFileValue.d.ts +12 -0
- package/dist/utils/mediaFileValue.js +24 -0
- package/dist/utils/placeRichTextCaretAtDocumentEnd.d.ts +11 -0
- package/dist/utils/placeRichTextCaretAtDocumentEnd.js +26 -0
- package/package.json +7 -7
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EmbedAssistantWireConfig } from '../../embedAssistant/types.js';
|
|
1
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> {
|
|
2
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
4
|
$$bindings?: Bindings;
|
|
@@ -15,6 +16,7 @@ declare const EmbedEditor: $$__sveltets_2_IsomorphicComponent<{
|
|
|
15
16
|
/** Component configuration — existing public props and methods are preserved. */ class?: string;
|
|
16
17
|
style?: string;
|
|
17
18
|
/** The title of the code box. Without one, the editor's own word in the language of the page. */ embedHeaderText?: string | undefined;
|
|
19
|
+
/** Where the "Learn more" link under the code box leads: the end-user guide "How does Embed work?". */ embedHelpUrl?: string;
|
|
18
20
|
embedCode?: string;
|
|
19
21
|
height?: number;
|
|
20
22
|
embedSchema: any;
|
|
@@ -23,18 +25,44 @@ declare const EmbedEditor: $$__sveltets_2_IsomorphicComponent<{
|
|
|
23
25
|
/** Show Save status control in the shared drag bar (composition embed overlay). */ showSaveButton?: boolean;
|
|
24
26
|
/** True when local embed option edits are not yet persisted. */ saveDirty?: boolean;
|
|
25
27
|
/** True while a save request is in flight. */ saveSaving?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Where the open values came from (`saved`, `widget_default`, or `none`). When `widget_default`, shows the reuse hint until the user edits.
|
|
30
|
+
*/ settingsSource?: "saved" | "widget_default" | "none" | undefined;
|
|
31
|
+
/** Schema defaults used by the Reset action when settings came from widget defaults. */ schemaDefaults?: Record<string, unknown>;
|
|
32
|
+
/** Autosave status line from the host (`Saving…`, `Saved`, or a retry message). */ embedAutosaveStatus?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional embed assistant wiring from the host. When omitted, no assistant tab is shown.
|
|
35
|
+
*/ assistant?: EmbedAssistantWireConfig | undefined;
|
|
26
36
|
updateValue?: (propertyId: string, value: any) => void;
|
|
27
37
|
setPosition?: (left: number, top: number) => void;
|
|
28
|
-
getPosition?: () =>
|
|
38
|
+
getPosition?: () => {
|
|
39
|
+
left: number;
|
|
40
|
+
top: number;
|
|
41
|
+
};
|
|
29
42
|
}, {
|
|
30
43
|
save: CustomEvent<any>;
|
|
31
|
-
|
|
44
|
+
drop: DragEvent;
|
|
45
|
+
cut: ClipboardEvent;
|
|
46
|
+
propertyChange: CustomEvent<{
|
|
47
|
+
propertyId?: string;
|
|
48
|
+
value?: unknown;
|
|
49
|
+
opacity?: number;
|
|
50
|
+
}>;
|
|
51
|
+
settingsPasted: CustomEvent<{
|
|
52
|
+
settings: Record<string, unknown>;
|
|
53
|
+
}>;
|
|
54
|
+
settingsReset: CustomEvent<{
|
|
55
|
+
settings: Record<string, unknown>;
|
|
56
|
+
}>;
|
|
32
57
|
} & {
|
|
33
58
|
[evt: string]: CustomEvent<any>;
|
|
34
59
|
}, {}, {
|
|
35
60
|
updateValue: (propertyId: string, value: any) => void;
|
|
36
61
|
setPosition: (left: number, top: number) => void;
|
|
37
|
-
getPosition: () =>
|
|
62
|
+
getPosition: () => {
|
|
63
|
+
left: number;
|
|
64
|
+
top: number;
|
|
65
|
+
};
|
|
38
66
|
}, string>;
|
|
39
67
|
type EmbedEditor = InstanceType<typeof EmbedEditor>;
|
|
40
68
|
export default EmbedEditor;
|
|
@@ -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
|
|
@@ -173,6 +184,8 @@
|
|
|
173
184
|
|
|
174
185
|
/** Optional content below the shared toolbar, before property fields. */
|
|
175
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';
|
|
176
189
|
/**
|
|
177
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
|
|
178
191
|
* puts the first accordion 16 below it; without a header the list starts 24 below the panel's top edge.
|
|
@@ -189,6 +202,8 @@
|
|
|
189
202
|
// Initial values from saved composition (merged over schema defaults)
|
|
190
203
|
export let initialDesignValues: Record<string, any> = {};
|
|
191
204
|
export let initialContentValues: Record<string, any> = {};
|
|
205
|
+
/** Property ids to flash briefly when the embed assistant applies options. */
|
|
206
|
+
export let flashPropertyIds: string[] = [];
|
|
192
207
|
|
|
193
208
|
/**
|
|
194
209
|
* Where the file controls (images, video, audio, documents) get their files from. Without it they show the
|
|
@@ -197,10 +212,18 @@
|
|
|
197
212
|
* storage (a CMS, an S3 bucket, a DAM) can be used with no Widgetic storage at all.
|
|
198
213
|
*/
|
|
199
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;
|
|
200
219
|
/** When given, file fields call this instead of opening the built-in File Browser. */
|
|
201
220
|
export let pickFile: PartnerPickFileFn | undefined = undefined;
|
|
202
221
|
/** When given, resolves the url stored with a picked file (partner `mediaLibrary.urlResolver`). */
|
|
203
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';
|
|
204
227
|
// The file controls are created from the schema several components down: give them the library through context.
|
|
205
228
|
provideEditorMediaLibrary(() => mediaLibrary);
|
|
206
229
|
provideEditorPickFile(() => pickFile);
|
|
@@ -229,7 +252,11 @@
|
|
|
229
252
|
let hasLoggedDesign = false; // Prevents duplicate logging of design tab info
|
|
230
253
|
let hasLoggedContent = false; // Prevents duplicate logging of content tab info
|
|
231
254
|
let designState: Record<string, InputValue> = { ...initialDesignValues }; // Stores design property values
|
|
232
|
-
let contentState: Record<string, InputValue> =
|
|
255
|
+
let contentState: Record<string, InputValue> = flattenContentStateFromParent(
|
|
256
|
+
initialContentValues,
|
|
257
|
+
contentSchema,
|
|
258
|
+
hydrateBrowserFileValue
|
|
259
|
+
);
|
|
233
260
|
|
|
234
261
|
let prevInitialDesignValues = initialDesignValues;
|
|
235
262
|
$: if (initialDesignValues !== prevInitialDesignValues) {
|
|
@@ -240,7 +267,20 @@
|
|
|
240
267
|
let prevInitialContentValues = initialContentValues;
|
|
241
268
|
$: if (initialContentValues !== prevInitialContentValues) {
|
|
242
269
|
prevInitialContentValues = initialContentValues;
|
|
243
|
-
|
|
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;
|
|
244
284
|
}
|
|
245
285
|
let isGenericContentOpen = true; // Controls generic content section visibility
|
|
246
286
|
let lastFocusedDesignController: string | null = null; // Tracks last focused design input
|
|
@@ -487,7 +527,7 @@
|
|
|
487
527
|
const liveOnItem = propKey != null ? (item as Record<string, unknown>)[propKey] : undefined;
|
|
488
528
|
const seed = pickLiveContentValue(parentValue, liveOnItem, prop.value);
|
|
489
529
|
if (seed !== undefined && seed !== '') {
|
|
490
|
-
patch[key] = seed as InputValue;
|
|
530
|
+
patch[key] = (typeof seed === 'object' ? hydrateBrowserFileValue(seed) : seed) as InputValue;
|
|
491
531
|
needsUpdate = true;
|
|
492
532
|
}
|
|
493
533
|
}
|
|
@@ -524,17 +564,6 @@
|
|
|
524
564
|
|
|
525
565
|
// Drag handles are now declarative (on:mousedown in template) — no imperative setup needed
|
|
526
566
|
|
|
527
|
-
if (defaultOpen && designSchema?.[0]?.components?.[0]?.propertyGroups) {
|
|
528
|
-
// Open all property groups by default
|
|
529
|
-
designOpenAccordion = designSchema[0].components
|
|
530
|
-
.flatMap((c: any) => (c.propertyGroups || []).map((pg: PropertyGroup) => pg.name))
|
|
531
|
-
.filter(Boolean);
|
|
532
|
-
const initialDesignSections = [...designOpenAccordion];
|
|
533
|
-
requestAnimationFrame(() => {
|
|
534
|
-
markAccordionSectionsMounted('design', initialDesignSections);
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
|
|
538
567
|
// Return cleanup function
|
|
539
568
|
return () => {
|
|
540
569
|
if (cleanup) cleanup();
|
|
@@ -553,6 +582,7 @@
|
|
|
553
582
|
* ON DESTROY
|
|
554
583
|
*/
|
|
555
584
|
onDestroy(() => {
|
|
585
|
+
if (viewStatePersistTimer) clearTimeout(viewStatePersistTimer);
|
|
556
586
|
// Clean up drag listeners
|
|
557
587
|
if (browser) {
|
|
558
588
|
document.removeEventListener('mousemove', handleDragMove);
|
|
@@ -996,7 +1026,7 @@
|
|
|
996
1026
|
const stateValue = schema === 'design' ? designState[propertyId] : contentState[propertyId];
|
|
997
1027
|
let initialValue = stateValue !== undefined ? stateValue : (property.value !== undefined ? property.value : property.defaultValue);
|
|
998
1028
|
|
|
999
|
-
// portalTarget for overlays (browser = full editor panel; textarea
|
|
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)
|
|
1000
1030
|
let portalTarget: string | HTMLElement =
|
|
1001
1031
|
schema === 'design'
|
|
1002
1032
|
? (designTabPortalHost ?? 'tab-design-container')
|
|
@@ -1285,6 +1315,7 @@
|
|
|
1285
1315
|
closeAllDropdowns();
|
|
1286
1316
|
scrollPosition = measurements.scrollTop;
|
|
1287
1317
|
}
|
|
1318
|
+
schedulePersistViewState();
|
|
1288
1319
|
});
|
|
1289
1320
|
}, 16);
|
|
1290
1321
|
|
|
@@ -1292,6 +1323,80 @@
|
|
|
1292
1323
|
let openItems = new Set<string>();
|
|
1293
1324
|
let draggedItem: string | null = null;
|
|
1294
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
|
+
}
|
|
1295
1400
|
|
|
1296
1401
|
// Add after the state declarations
|
|
1297
1402
|
$: isItemOpen = (itemId: string) => openItems.has(itemId);
|
|
@@ -1427,6 +1532,15 @@
|
|
|
1427
1532
|
let designAccordionMounted = new Set<string>();
|
|
1428
1533
|
let contentAccordionMounted = new Set<string>();
|
|
1429
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
|
+
|
|
1430
1544
|
function markAccordionSectionsMounted(tab: 'design' | 'content', sectionIds: string[]) {
|
|
1431
1545
|
const targetSet = tab === 'design' ? designAccordionMounted : contentAccordionMounted;
|
|
1432
1546
|
let grew = false;
|
|
@@ -1445,6 +1559,18 @@
|
|
|
1445
1559
|
}
|
|
1446
1560
|
}
|
|
1447
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
|
+
|
|
1448
1574
|
function handleAccordionChange(value: string | string[]) {
|
|
1449
1575
|
const arr = Array.isArray(value) ? value : [value];
|
|
1450
1576
|
const previousOpen = currentTab === 'design' ? designOpenAccordion : contentOpenAccordion;
|
|
@@ -1456,12 +1582,18 @@
|
|
|
1456
1582
|
}
|
|
1457
1583
|
if (newlyOpenedSections.length > 0) {
|
|
1458
1584
|
const tab: 'design' | 'content' = currentTab === 'design' ? 'design' : 'content';
|
|
1459
|
-
|
|
1460
|
-
|
|
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).
|
|
1461
1591
|
requestAnimationFrame(() => {
|
|
1462
|
-
|
|
1592
|
+
requestAnimationFrame(() => {
|
|
1593
|
+
markAccordionSectionsMounted(tab, newlyOpenedSections);
|
|
1594
|
+
});
|
|
1463
1595
|
});
|
|
1464
|
-
}
|
|
1596
|
+
}
|
|
1465
1597
|
}
|
|
1466
1598
|
}
|
|
1467
1599
|
|
|
@@ -1503,6 +1635,7 @@
|
|
|
1503
1635
|
// console.log("handleKeyDown triggered: key=", event.key, "shiftKey=", event.shiftKey);
|
|
1504
1636
|
// The listener is on the window, so it hears every key typed on the page. Only the ones typed in the editor
|
|
1505
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;
|
|
1506
1639
|
if (rootElement && !event.composedPath().includes(rootElement)) return;
|
|
1507
1640
|
if (event.shiftKey && event.key === 'ArrowDown') {
|
|
1508
1641
|
// console.log("Expanding all content items");
|
|
@@ -1644,6 +1777,40 @@
|
|
|
1644
1777
|
return genericIds !== itemIds;
|
|
1645
1778
|
}
|
|
1646
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
|
+
|
|
1647
1814
|
function handleAddNewItem() {
|
|
1648
1815
|
try {
|
|
1649
1816
|
if (!contentSchema) {
|
|
@@ -1742,7 +1909,7 @@
|
|
|
1742
1909
|
|
|
1743
1910
|
function unwrapContentMediaValue(raw: unknown): unknown {
|
|
1744
1911
|
if (raw && typeof raw === 'object' && 'url' in (raw as Record<string, unknown>)) {
|
|
1745
|
-
return (raw
|
|
1912
|
+
return hydrateBrowserFileValue(raw);
|
|
1746
1913
|
}
|
|
1747
1914
|
return raw;
|
|
1748
1915
|
}
|
|
@@ -2220,10 +2387,10 @@
|
|
|
2220
2387
|
class="h-full"
|
|
2221
2388
|
type="hover"
|
|
2222
2389
|
scrollHideDelay={0}
|
|
2223
|
-
scrollbarYClasses="flex w-6 touch-none select-none px-2
|
|
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"
|
|
2224
2391
|
>
|
|
2225
|
-
<div class="scroll-viewport props-editor-scroll-viewport" data-radix-scroll-area-viewport bind:this={designScrollViewport}>
|
|
2226
|
-
<div class="props-editor-scroll-inner
|
|
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}>
|
|
2227
2394
|
<Tabs.Content
|
|
2228
2395
|
value="design"
|
|
2229
2396
|
class="design-tab-content mt-0! tabs-content-container w-full outline-none {isFirstLoad ? 'initial-load' : !isInitialTabLoad ? 'animate-slide-left' : ''}"
|
|
@@ -2286,7 +2453,7 @@
|
|
|
2286
2453
|
</div>
|
|
2287
2454
|
{:else}
|
|
2288
2455
|
<InputControllerRow
|
|
2289
|
-
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' : ''}"
|
|
2290
2457
|
dataState={rowDataState}
|
|
2291
2458
|
label={header.label}
|
|
2292
2459
|
helpText={header.helpText}
|
|
@@ -2340,10 +2507,10 @@
|
|
|
2340
2507
|
class="h-full"
|
|
2341
2508
|
type="hover"
|
|
2342
2509
|
scrollHideDelay={0}
|
|
2343
|
-
scrollbarYClasses="flex w-6 touch-none select-none px-2
|
|
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"
|
|
2344
2511
|
>
|
|
2345
|
-
<div class="scroll-viewport props-editor-scroll-viewport" data-radix-scroll-area-viewport bind:this={contentScrollViewport}>
|
|
2346
|
-
<div class="props-editor-scroll-inner
|
|
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}>
|
|
2347
2514
|
<Tabs.Content
|
|
2348
2515
|
value="content"
|
|
2349
2516
|
class="content-tab-content mt-0! tabs-content-container w-full {isFirstLoad ? 'initial-load' : !isInitialTabLoad ? 'animate-slide-right' : ''}"
|
|
@@ -2352,6 +2519,12 @@
|
|
|
2352
2519
|
>
|
|
2353
2520
|
<!-- Content tab body text: Card defaults to text-card-foreground (16px); force Body 14/20 on controls. -->
|
|
2354
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
|
+
/>
|
|
2355
2528
|
<!-- Generic Content Collapsible Card -->
|
|
2356
2529
|
{#if shouldShowGenericContentSection(contentSchema)}
|
|
2357
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;">
|
|
@@ -2386,13 +2559,18 @@
|
|
|
2386
2559
|
|
|
2387
2560
|
{#if isVisible}
|
|
2388
2561
|
{@const isFontIc = property.inputController.type.toLowerCase() === 'font'}
|
|
2562
|
+
{@const stateKey = property.id || property.name}
|
|
2563
|
+
{@const reactiveValue = contentState[stateKey]}
|
|
2389
2564
|
<!-- A panel (the documents of AI Answers) is a list and a form: it gets the whole width under its header. -->
|
|
2390
2565
|
{@const isPanelIc = property.inputController.type.toLowerCase() === 'knowledgedocuments'}
|
|
2391
2566
|
{#if isFontIc}
|
|
2392
2567
|
<div class="ictrl input-controller font-ic-host flex w-full flex-col items-stretch p-0">
|
|
2393
2568
|
<div class="ic-input-ct w-full">
|
|
2394
2569
|
<InputControllerRenderer
|
|
2395
|
-
controller={describeInputController(InputComponent,
|
|
2570
|
+
controller={describeInputController(InputComponent, {
|
|
2571
|
+
...props,
|
|
2572
|
+
value: reactiveValue !== undefined ? reactiveValue : props.value
|
|
2573
|
+
})}
|
|
2396
2574
|
/>
|
|
2397
2575
|
</div>
|
|
2398
2576
|
</div>
|
|
@@ -2489,12 +2667,17 @@
|
|
|
2489
2667
|
|
|
2490
2668
|
{#if isVisible && InputComponent}
|
|
2491
2669
|
{@const isFontIc = (property.inputController?.type || '').toLowerCase() === 'font'}
|
|
2670
|
+
{@const stateKey = `${item.id}__${property.id || property.name}`}
|
|
2671
|
+
{@const reactiveValue = contentState[stateKey]}
|
|
2492
2672
|
{@const isPanelIc = (property.inputController?.type || '').toLowerCase() === 'knowledgedocuments'}
|
|
2493
2673
|
{#if isFontIc}
|
|
2494
2674
|
<div class="ictrl input-controller font-ic-host flex w-full flex-col items-stretch p-0">
|
|
2495
2675
|
<div class="ic-input-ct w-full">
|
|
2496
2676
|
<InputControllerRenderer
|
|
2497
|
-
controller={describeInputController(InputComponent,
|
|
2677
|
+
controller={describeInputController(InputComponent, {
|
|
2678
|
+
...props,
|
|
2679
|
+
value: reactiveValue !== undefined ? reactiveValue : props.value
|
|
2680
|
+
})}
|
|
2498
2681
|
/>
|
|
2499
2682
|
</div>
|
|
2500
2683
|
</div>
|
|
@@ -2560,6 +2743,11 @@
|
|
|
2560
2743
|
<IconPlus class="size-4 text-brand" aria-hidden="true" />
|
|
2561
2744
|
{$t('editor.props.addItem')}
|
|
2562
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}
|
|
2563
2751
|
</div>
|
|
2564
2752
|
{/if}
|
|
2565
2753
|
</div>
|
|
@@ -2589,6 +2777,11 @@
|
|
|
2589
2777
|
:global(.props-editor-container .props-editor-scroll-viewport) {
|
|
2590
2778
|
scrollbar-gutter: stable;
|
|
2591
2779
|
padding-inline: 1.5rem;
|
|
2780
|
+
background: transparent;
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
:global(.props-editor-container .scroll-area) {
|
|
2784
|
+
background: transparent;
|
|
2592
2785
|
}
|
|
2593
2786
|
|
|
2594
2787
|
/* Inset the vertical scrollbar by the panel's horizontal padding so it never sits on card borders. */
|
|
@@ -2,6 +2,7 @@ import type { ContentSchemaView, DesignSchemaView } from '../../schemaViews.js';
|
|
|
2
2
|
import { type PartnerPickFileFn } from '../../pickFileContext';
|
|
3
3
|
import { type StoreFileUrlFn } from '../../fileStorageUrlContext';
|
|
4
4
|
import type { MediaLibraryProvider } from '@widgetic/file-browser';
|
|
5
|
+
import type { ContentFromFilesPlan } from '../../contentBulkDrop/types.js';
|
|
5
6
|
/**
|
|
6
7
|
* STYLES from Widgetic Design System
|
|
7
8
|
* Note: props-editor.css global rules (body, *) moved to app.css (standalone only).
|
|
@@ -41,6 +42,7 @@ declare const PropsEditor: $$__sveltets_2_IsomorphicComponent<{
|
|
|
41
42
|
/** True when local edits are not yet persisted. */ saveDirty?: boolean;
|
|
42
43
|
/** True while a save request is in flight. */ saveSaving?: boolean;
|
|
43
44
|
/** Optional content below the shared toolbar, before property fields. */ headerContent?: any;
|
|
45
|
+
/** Bottom padding inside the scroll area (the embed editor, which has no controls below the list, uses 16px / `pb-4`). */ scrollAreaBottomPaddingClass?: string;
|
|
44
46
|
headerClass?: string;
|
|
45
47
|
dragHandleClass?: string;
|
|
46
48
|
title?: string | undefined;
|
|
@@ -48,14 +50,23 @@ declare const PropsEditor: $$__sveltets_2_IsomorphicComponent<{
|
|
|
48
50
|
/** Optional layout wrapper moved by this editor's built-in drag and position API. */ positionTarget?: any;
|
|
49
51
|
initialDesignValues?: Record<string, any>;
|
|
50
52
|
initialContentValues?: Record<string, any>;
|
|
53
|
+
/** Property ids to flash briefly when the embed assistant applies options. */ flashPropertyIds?: string[];
|
|
51
54
|
/**
|
|
52
55
|
* Where the file controls (images, video, audio, documents) get their files from. Without it they show the
|
|
53
56
|
* Widgetic account's uploads, as they always have (configured with `setFileBrowserUploadConfig`). With a
|
|
54
57
|
* `MediaLibraryProvider` they list, upload, rename and delete through its functions instead, so a partner's own
|
|
55
58
|
* storage (a CMS, an S3 bucket, a DAM) can be used with no Widgetic storage at all.
|
|
56
59
|
*/ mediaLibrary?: MediaLibraryProvider | undefined;
|
|
60
|
+
/** Calls POST /compositions/:id/content-items/from-files (plan only). Wired by CompositionEditorApp. */ requestContentFromFilesPlan?: ((files: Array<{
|
|
61
|
+
name: string;
|
|
62
|
+
mimeType: string;
|
|
63
|
+
sizeBytes?: number;
|
|
64
|
+
mediaId: string;
|
|
65
|
+
}>) => Promise<ContentFromFilesPlan>) | undefined;
|
|
57
66
|
/** When given, file fields call this instead of opening the built-in File Browser. */ pickFile?: PartnerPickFileFn | undefined;
|
|
58
67
|
/** When given, resolves the url stored with a picked file (partner `mediaLibrary.urlResolver`). */ storeFileUrl?: StoreFileUrlFn | undefined;
|
|
68
|
+
/** When set (composition id), tab, scroll, accordions and open content cards persist in sessionStorage. */ viewStatePersistenceKey?: string | undefined;
|
|
69
|
+
/** Device preview mode, stored with the props-panel view state by the composition editor shell. */ persistedDeviceView?: "desktop" | "mobile";
|
|
59
70
|
updateDesignValue?: (propertyId: string, value: any) => void;
|
|
60
71
|
setPosition?: (left: number, top: number) => void;
|
|
61
72
|
getPosition?: () => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ContentSchemaView } from '../../schemaViews.js';
|
|
2
|
+
export type ContentStateValue = string | number | boolean | Record<string, unknown> | null;
|
|
3
|
+
/** True for the flat `itemId__prop` keys the input controllers of a content item read and write. */
|
|
4
|
+
export declare function isItemFieldStateKey(stateKey: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Maps parent `initialContentValues` (with nested `items`) into flat `itemId__prop` state keys
|
|
7
|
+
* used by input controllers inside PropsEditor.
|
|
8
|
+
*
|
|
9
|
+
* `transformItemValue` runs on every item field value on its way into the flat map (the editor passes the one that
|
|
10
|
+
* rebuilds a full file reference from what the parent echoes back).
|
|
11
|
+
*/
|
|
12
|
+
export declare function flattenContentStateFromParent(initial: Record<string, ContentStateValue> | undefined, schema: ContentSchemaView | undefined, transformItemValue?: (value: ContentStateValue) => ContentStateValue): Record<string, ContentStateValue>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Separator between an item id and a property id in the flat state keys (`itemId__prop`). */
|
|
2
|
+
const ITEM_FIELD_KEY_SEPARATOR = '__';
|
|
3
|
+
/** True for the flat `itemId__prop` keys the input controllers of a content item read and write. */
|
|
4
|
+
export function isItemFieldStateKey(stateKey) {
|
|
5
|
+
return stateKey.includes(ITEM_FIELD_KEY_SEPARATOR);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Maps parent `initialContentValues` (with nested `items`) into flat `itemId__prop` state keys
|
|
9
|
+
* used by input controllers inside PropsEditor.
|
|
10
|
+
*
|
|
11
|
+
* `transformItemValue` runs on every item field value on its way into the flat map (the editor passes the one that
|
|
12
|
+
* rebuilds a full file reference from what the parent echoes back).
|
|
13
|
+
*/
|
|
14
|
+
export function flattenContentStateFromParent(initial, schema, transformItemValue = (value) => value) {
|
|
15
|
+
const flat = {};
|
|
16
|
+
if (!initial || typeof initial !== 'object')
|
|
17
|
+
return flat;
|
|
18
|
+
for (const [key, value] of Object.entries(initial)) {
|
|
19
|
+
if (key === 'items' || key === 'contentItemsSnapshot')
|
|
20
|
+
continue;
|
|
21
|
+
flat[key] = value;
|
|
22
|
+
}
|
|
23
|
+
const items = initial.items;
|
|
24
|
+
if (items && Array.isArray(schema?.contentItems)) {
|
|
25
|
+
for (const item of schema.contentItems) {
|
|
26
|
+
const itemValues = items[item.id];
|
|
27
|
+
if (!itemValues)
|
|
28
|
+
continue;
|
|
29
|
+
for (const prop of item.properties || []) {
|
|
30
|
+
const propKey = prop.id || prop.name;
|
|
31
|
+
if (propKey == null)
|
|
32
|
+
continue;
|
|
33
|
+
if (itemValues[propKey] !== undefined) {
|
|
34
|
+
flat[`${item.id}${ITEM_FIELD_KEY_SEPARATOR}${propKey}`] = transformItemValue(itemValues[propKey]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return flat;
|
|
40
|
+
}
|