@nascentdigital/funnel-editor 4.6.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EditorApp.js +1 -1
- package/dist/EditorRoutes.js +7 -5
- package/dist/changesets/screens/ChangeSetViewer.js +1 -1
- package/dist/changesets/screens/ChangeSetsExplorer.js +1 -2
- package/dist/collection/hooks/CollectionController.d.ts +5 -16
- package/dist/collection/hooks/CollectionController.js +18 -37
- package/dist/collection/hooks/ICollectionController.d.ts +24 -0
- package/dist/collection/hooks/ICollectionController.js +20 -0
- package/dist/collection/hooks/index.d.ts +1 -0
- package/dist/collection/hooks/index.js +1 -0
- package/dist/collection/hooks/useCollectionController.d.ts +3 -3
- package/dist/collection/screens/CollectionEditor.js +2 -2
- package/dist/components.d.ts +20 -0
- package/dist/components.js +41 -0
- package/dist/core/components/feedback/dialog/MinimalDialogLayout.js +1 -1
- package/dist/core/components/fields/BooleanField.d.ts +2 -1
- package/dist/core/components/fields/BooleanField.js +2 -2
- package/dist/core/components/fields/DateField.d.ts +2 -1
- package/dist/core/components/fields/DateField.js +2 -2
- package/dist/core/components/fields/DynamicPagesEditor.d.ts +2 -1
- package/dist/core/components/fields/DynamicPagesEditor.js +1 -1
- package/dist/core/components/fields/EnumField.d.ts +2 -1
- package/dist/core/components/fields/EnumField.js +2 -2
- package/dist/core/components/fields/FieldCard.d.ts +1 -0
- package/dist/core/components/fields/FieldCard.js +8 -1
- package/dist/core/components/fields/FieldEditor.d.ts +2 -1
- package/dist/core/components/fields/FieldEditor.js +11 -11
- package/dist/core/components/fields/FieldLayout.d.ts +2 -1
- package/dist/core/components/fields/FieldLayout.js +3 -3
- package/dist/core/components/fields/ListEditor.d.ts +2 -1
- package/dist/core/components/fields/ListEditor.js +5 -6
- package/dist/core/components/fields/OptInField.d.ts +2 -1
- package/dist/core/components/fields/OptInField.js +2 -2
- package/dist/core/components/fields/RichTextEditor.js +1 -1
- package/dist/core/components/fields/RichTextField.d.ts +2 -1
- package/dist/core/components/fields/RichTextField.js +3 -5
- package/dist/core/components/fields/TextField.d.ts +2 -0
- package/dist/core/components/fields/TextField.js +2 -2
- package/dist/core/components/fields/TimestampField.d.ts +2 -1
- package/dist/core/components/fields/TimestampField.js +3 -3
- package/dist/core/components/fields/asset/AssetEditor.js +12 -44
- package/dist/core/components/fields/asset/AssetPicker.js +6 -6
- package/dist/core/components/fields/asset/AssetUploader.js +23 -31
- package/dist/core/components/fields/asset/preview/VideoPreview.js +16 -11
- package/dist/core/components/fields/asset/useAssetFields.d.ts +2 -17
- package/dist/core/components/fields/asset/useAssetFields.js +0 -21
- package/dist/core/components/fields/collection/CollectionEditor.js +1 -1
- package/dist/core/components/fields/collection/CollectionPicker.d.ts +2 -2
- package/dist/core/components/fields/collection/CollectionPicker.js +3 -4
- package/dist/core/components/fields/dynamicPages/PagePriorityDialog.js +1 -1
- package/dist/core/components/fields/embed/EmbeddedVideoEditor.js +34 -27
- package/dist/core/components/fields/factories/FieldValueFactory.js +11 -4
- package/dist/core/components/fields/factories/MediaFactory.d.ts +13 -0
- package/dist/core/components/fields/factories/MediaFactory.js +256 -0
- package/dist/core/components/fields/list/CreateFieldButton.js +1 -1
- package/dist/core/components/fields/media/MediaCard.d.ts +7 -0
- package/dist/core/components/fields/media/MediaCard.js +92 -0
- package/dist/core/components/fields/media/MediaEditor.d.ts +37 -0
- package/dist/core/components/fields/media/MediaEditor.js +235 -0
- package/dist/core/components/fields/media/MediaPicker.d.ts +15 -0
- package/dist/core/components/fields/media/MediaPicker.js +251 -0
- package/dist/core/components/fields/media/index.d.ts +3 -0
- package/dist/core/components/fields/media/index.js +19 -0
- package/dist/core/components/fields/object/ObjectEditor.js +1 -1
- package/dist/core/components/fields/page/PagePicker.d.ts +2 -2
- package/dist/core/components/fields/page/PagePicker.js +1 -1
- package/dist/core/components/interaction/Combobox.js +1 -1
- package/dist/core/components/interaction/DateTimePicker.d.ts +0 -1
- package/dist/core/components/interaction/DateTimePicker.js +0 -2
- package/dist/core/components/interaction/MultiSelectControls.js +2 -5
- package/dist/core/components/interaction/Popup.js +1 -0
- package/dist/core/components/interaction/QuickEditor.js +1 -1
- package/dist/core/components/interaction/QuickPicker.js +1 -1
- package/dist/core/components/interaction/SideSheet.js +1 -1
- package/dist/core/components/interaction/centersheet/CenterSheet.js +7 -1
- package/dist/core/components/interaction/centersheet/CenterSheetContainer.js +3 -1
- package/dist/core/components/transitions/FadeIn.js +2 -14
- package/dist/core/components/visuals/Icon.d.ts +1 -1
- package/dist/core/components/visuals/Icon.js +3 -0
- package/dist/core/containers/AssetRepositoryContainer.d.ts +2 -0
- package/dist/core/containers/AssetRepositoryContainer.js +18 -0
- package/dist/core/containers/CollectionRepositoryContainer.d.ts +2 -0
- package/dist/core/containers/CollectionRepositoryContainer.js +18 -0
- package/dist/core/containers/PageRepositoryContainer.d.ts +2 -0
- package/dist/core/containers/PageRepositoryContainer.js +18 -0
- package/dist/core/containers/index.d.ts +3 -0
- package/dist/core/containers/index.js +19 -0
- package/dist/core/domain/Block.d.ts +1 -0
- package/dist/core/domain/Block.js +8 -5
- package/dist/core/domain/BlockConfiguration.d.ts +4 -1
- package/dist/core/domain/BlockConfiguration.js +64 -3
- package/dist/core/domain/Collection.d.ts +10 -28
- package/dist/core/domain/Collection.js +2 -16
- package/dist/core/domain/CollectionBrowser.d.ts +3 -2
- package/dist/core/domain/CollectionBrowser.js +3 -3
- package/dist/core/domain/CollectionFieldProxy.d.ts +12 -8
- package/dist/core/domain/CollectionFieldProxy.js +14 -8
- package/dist/core/domain/CollectionGroup.d.ts +0 -5
- package/dist/core/domain/CollectionGroup.js +0 -7
- package/dist/core/domain/CollectionSummary.d.ts +2 -2
- package/dist/core/domain/Collections.d.ts +3 -3
- package/dist/core/domain/Collections.js +4 -4
- package/dist/core/domain/ICollection.d.ts +71 -0
- package/dist/core/domain/ICollection.js +20 -0
- package/dist/core/domain/IPage.d.ts +72 -0
- package/dist/core/domain/IPage.js +20 -0
- package/dist/core/domain/IPageRefStore.d.ts +3 -3
- package/dist/core/domain/ItemBase.d.ts +6 -6
- package/dist/core/domain/ItemBase.js +5 -5
- package/dist/core/domain/Page.d.ts +9 -22
- package/dist/core/domain/Page.js +3 -18
- package/dist/core/domain/PageOverview.d.ts +2 -2
- package/dist/core/domain/PageRefStoreProxy.d.ts +4 -4
- package/dist/core/domain/PageSettings.d.ts +3 -3
- package/dist/core/domain/PageSummary.d.ts +2 -2
- package/dist/core/domain/Pages.js +4 -6
- package/dist/core/domain/SectionBlock.js +2 -1
- package/dist/core/domain/Site.d.ts +4 -4
- package/dist/core/domain/Site.js +3 -3
- package/dist/core/domain/index.d.ts +2 -1
- package/dist/core/domain/index.js +2 -1
- package/dist/core/hooks/index.d.ts +4 -3
- package/dist/core/hooks/index.js +4 -3
- package/dist/core/hooks/useAssetRepository.d.ts +3 -0
- package/dist/core/hooks/useAssetRepository.js +11 -0
- package/dist/core/hooks/useCollection.d.ts +4 -4
- package/dist/core/hooks/useCollectionRepository.d.ts +3 -2
- package/dist/core/hooks/useCollectionRepository.js +4 -4
- package/dist/core/hooks/usePage.d.ts +4 -4
- package/dist/core/hooks/usePageRef.d.ts +1 -1
- package/dist/core/hooks/usePageRepository.d.ts +3 -2
- package/dist/core/hooks/usePageRepository.js +4 -4
- package/dist/core/hooks/useTempFields.d.ts +2 -3
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/repository/AssetRepository.d.ts +10 -0
- package/dist/core/repository/AssetRepository.js +22 -0
- package/dist/core/repository/CollectionRepository.d.ts +21 -20
- package/dist/core/repository/CollectionRepository.js +23 -161
- package/dist/core/repository/CollectionSerializer.d.ts +4 -1
- package/dist/core/repository/CollectionSerializer.js +3 -3
- package/dist/core/repository/IAssetRepository.d.ts +25 -0
- package/dist/core/repository/ICollectionRepository.d.ts +62 -0
- package/dist/core/repository/ICollectionRepository.js +2 -0
- package/dist/core/repository/IPageRepository.d.ts +40 -0
- package/dist/core/repository/IPageRepository.js +2 -0
- package/dist/core/repository/PageRepository.d.ts +6 -9
- package/dist/core/repository/PageRepository.js +7 -280
- package/dist/core/repository/PageSerializer.d.ts +34 -1
- package/dist/core/repository/PageSerializer.js +4 -0
- package/dist/core/repository/SerializeCollectionUpdate.d.ts +8 -0
- package/dist/core/repository/SerializeCollectionUpdate.js +168 -0
- package/dist/core/repository/SerializePageUpdate.d.ts +11 -0
- package/dist/core/repository/SerializePageUpdate.js +292 -0
- package/dist/core/repository/index.d.ts +4 -0
- package/dist/core/repository/index.js +4 -0
- package/dist/dashboard/screens/Dashboard.js +1 -1
- package/dist/devtools/screens/Devtools.js +1 -1
- package/dist/explore/components/CreatePageDialog.d.ts +2 -2
- package/dist/explore/screens/CollectionExplorer.js +1 -1
- package/dist/explore/screens/CollectionsExplorer.js +1 -1
- package/dist/explore/screens/PageExplorer.js +1 -1
- package/dist/explore/screens/SiteExplorer.js +1 -1
- package/dist/page/components/BlockEditor.js +1 -1
- package/dist/page/components/PageHeader.d.ts +2 -2
- package/dist/page/components/PageNotCreated.d.ts +2 -2
- package/dist/page/components/PageNotFound.d.ts +2 -2
- package/dist/page/components/SettingsEditor.js +0 -7
- package/dist/page/components/config/BlockConfigButton.d.ts +2 -1
- package/dist/page/components/config/BlockConfigButton.js +84 -24
- package/dist/page/components/config/BlockPreview.d.ts +8 -0
- package/dist/page/components/config/BlockPreview.js +53 -0
- package/dist/page/components/config/index.d.ts +1 -1
- package/dist/page/components/config/index.js +1 -1
- package/dist/page/components/config/preview/ColumnLayout.d.ts +10 -0
- package/dist/page/components/config/preview/ColumnLayout.js +15 -0
- package/dist/page/components/config/preview/ItemLayout.d.ts +12 -0
- package/dist/page/components/config/preview/ItemLayout.js +45 -0
- package/dist/page/components/config/preview/ListPanel.d.ts +12 -0
- package/dist/page/components/config/preview/ListPanel.js +14 -0
- package/dist/page/components/config/preview/MessagePanel.d.ts +12 -0
- package/dist/page/components/config/preview/MessagePanel.js +21 -0
- package/dist/page/components/config/preview/Panel.d.ts +15 -0
- package/dist/page/components/config/preview/Panel.js +74 -0
- package/dist/page/components/config/preview/RowLayout.d.ts +10 -0
- package/dist/page/components/config/preview/RowLayout.js +26 -0
- package/dist/page/components/config/preview/StackLayout.d.ts +10 -0
- package/dist/page/components/config/preview/StackLayout.js +15 -0
- package/dist/page/components/config/preview/VisualPanel.d.ts +12 -0
- package/dist/page/components/config/preview/VisualPanel.js +27 -0
- package/dist/page/components/config/preview/index.d.ts +3 -0
- package/dist/page/components/config/preview/index.js +19 -0
- package/dist/page/components/panels/BlockConfigPanel.js +4 -4
- package/dist/page/hooks/IPageController.d.ts +42 -0
- package/dist/page/hooks/IPageController.js +32 -0
- package/dist/page/hooks/PageController.d.ts +11 -36
- package/dist/page/hooks/PageController.js +7 -33
- package/dist/page/hooks/index.d.ts +1 -0
- package/dist/page/hooks/index.js +1 -0
- package/dist/page/hooks/usePageController.d.ts +3 -3
- package/dist/page/screens/PageEditor.js +1 -1
- package/dist/styles/index.css +809 -60
- package/dist/styles/tailwind.js +1 -0
- package/dist/users/screens/UserExplorer.js +1 -1
- package/package.json +3 -2
- package/dist/core/domain/TranslateSchema.d.ts +0 -7
- package/dist/page/components/config/LegacyBlockPreview.d.ts +0 -8
- package/dist/page/components/config/LegacyBlockPreview.js +0 -452
- /package/dist/core/{domain/TranslateSchema.js → repository/IAssetRepository.js} +0 -0
|
@@ -15,6 +15,7 @@ exports.PageRepository = void 0;
|
|
|
15
15
|
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
16
|
const domain_1 = require("../domain");
|
|
17
17
|
const PageSerializer_1 = require("./PageSerializer");
|
|
18
|
+
const SerializePageUpdate_1 = require("./SerializePageUpdate");
|
|
18
19
|
// class
|
|
19
20
|
class PageRepository {
|
|
20
21
|
constructor(editorApi) {
|
|
@@ -91,6 +92,9 @@ class PageRepository {
|
|
|
91
92
|
// unpublish page
|
|
92
93
|
await this.editorApi.unpublishPage(page.id);
|
|
93
94
|
}
|
|
95
|
+
async getOverview(args) {
|
|
96
|
+
return this.editorApi.getPagesOverview(Object.assign(Object.assign({}, args), { version: 'draft' }));
|
|
97
|
+
}
|
|
94
98
|
serializePageUpdate(page, savables) {
|
|
95
99
|
var _a, _b;
|
|
96
100
|
// root page updates
|
|
@@ -158,18 +162,18 @@ class PageRepository {
|
|
|
158
162
|
...rootPageUpdates,
|
|
159
163
|
...discover.reduce((updates, block) => {
|
|
160
164
|
// try to update block
|
|
161
|
-
|
|
165
|
+
SerializePageUpdate_1.SerializePageUpdate.serializeBlockUpdate(updates, block, 'discover', savables);
|
|
162
166
|
// keep reducing
|
|
163
167
|
return updates;
|
|
164
168
|
}, []),
|
|
165
169
|
...content.reduce((updates, item) => {
|
|
166
170
|
// handle block
|
|
167
171
|
if (item instanceof domain_1.Block) {
|
|
168
|
-
|
|
172
|
+
SerializePageUpdate_1.SerializePageUpdate.serializeBlockUpdate(updates, item, 'content', savables);
|
|
169
173
|
}
|
|
170
174
|
// or section
|
|
171
175
|
else {
|
|
172
|
-
|
|
176
|
+
SerializePageUpdate_1.SerializePageUpdate.serializeSectionUpdate(updates, item, 'content', savables);
|
|
173
177
|
}
|
|
174
178
|
// keep reducing
|
|
175
179
|
return updates;
|
|
@@ -181,282 +185,5 @@ class PageRepository {
|
|
|
181
185
|
]
|
|
182
186
|
};
|
|
183
187
|
}
|
|
184
|
-
serializeSectionUpdate(updates, section, parentPath, savables) {
|
|
185
|
-
// track insert/update
|
|
186
|
-
let sectionChanged = false;
|
|
187
|
-
const path = [parentPath, section.key];
|
|
188
|
-
const { blocks, initialBlocks = [] } = section;
|
|
189
|
-
const blockIds = [];
|
|
190
|
-
blocks.forEach((sectionBlock, index) => {
|
|
191
|
-
// track id
|
|
192
|
-
const { id, block } = sectionBlock;
|
|
193
|
-
blockIds.push(id);
|
|
194
|
-
// track insert
|
|
195
|
-
const originalIndex = initialBlocks.findIndex(item => item.id === id);
|
|
196
|
-
if (originalIndex < 0) {
|
|
197
|
-
// add as insertion
|
|
198
|
-
updates.push({
|
|
199
|
-
type: 'section.insert',
|
|
200
|
-
path,
|
|
201
|
-
index,
|
|
202
|
-
section: {
|
|
203
|
-
type: 'section',
|
|
204
|
-
version: section.schema.version
|
|
205
|
-
},
|
|
206
|
-
block: sectionBlock.value
|
|
207
|
-
});
|
|
208
|
-
// mark changed
|
|
209
|
-
sectionChanged = true;
|
|
210
|
-
// track nested savables for section-block insertion
|
|
211
|
-
const fields = [...block.config, ...block.fields];
|
|
212
|
-
fields.forEach(field => {
|
|
213
|
-
if (field.modified) {
|
|
214
|
-
savables.push(field);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
// recurse update if it's set
|
|
219
|
-
else if (block.modified) {
|
|
220
|
-
// track name field
|
|
221
|
-
if (block.nameField.modified) {
|
|
222
|
-
// send update
|
|
223
|
-
updates.push({
|
|
224
|
-
type: 'section.blockName',
|
|
225
|
-
path,
|
|
226
|
-
id,
|
|
227
|
-
value: funnel_core_1.Schema.TextField.Value.fromData(block.nameField.value) || null
|
|
228
|
-
});
|
|
229
|
-
// track change
|
|
230
|
-
savables.push(block.nameField);
|
|
231
|
-
}
|
|
232
|
-
// serialize config fields
|
|
233
|
-
this.serializeFieldsUpdate(updates, block.config, [...path, id, 'config'], savables);
|
|
234
|
-
// serialize content fields
|
|
235
|
-
this.serializeFieldsUpdate(updates, block.fields, [...path, id, 'fields'], savables);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
// track delete/reorder
|
|
239
|
-
let reordered = false;
|
|
240
|
-
initialBlocks.forEach(({ id }, index) => {
|
|
241
|
-
// add to deleted list if the original doesn't exist anymore
|
|
242
|
-
const blockIndex = blockIds.findIndex(blockId => blockId === id);
|
|
243
|
-
if (blockIndex < 0) {
|
|
244
|
-
// delete
|
|
245
|
-
updates.push({
|
|
246
|
-
type: 'section.delete',
|
|
247
|
-
path,
|
|
248
|
-
id
|
|
249
|
-
});
|
|
250
|
-
// track reorder
|
|
251
|
-
sectionChanged = true;
|
|
252
|
-
}
|
|
253
|
-
// or mark reorder if index isn't the same
|
|
254
|
-
else if (blockIndex !== index) {
|
|
255
|
-
reordered = true;
|
|
256
|
-
sectionChanged = true;
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
// track reorder
|
|
260
|
-
if (reordered) {
|
|
261
|
-
updates.push({
|
|
262
|
-
type: 'section.reorder',
|
|
263
|
-
path,
|
|
264
|
-
ids: blockIds
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
// track section change (if any)
|
|
268
|
-
if (sectionChanged) {
|
|
269
|
-
savables.push(section);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
serializeBlockUpdate(updates, block, parentPath, savables) {
|
|
273
|
-
// ignore if block isn't activated
|
|
274
|
-
if (!block.activated) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
// create a new block if it's new
|
|
278
|
-
else if (block.isNew) {
|
|
279
|
-
// create update
|
|
280
|
-
updates.push({
|
|
281
|
-
type: 'block.create',
|
|
282
|
-
path: [parentPath, block.key],
|
|
283
|
-
block: block.value
|
|
284
|
-
});
|
|
285
|
-
// track block
|
|
286
|
-
savables.push(block);
|
|
287
|
-
// track nested savables for block insertion
|
|
288
|
-
const fields = [...block.config, ...block.fields];
|
|
289
|
-
fields.forEach(field => {
|
|
290
|
-
if (field.modified) {
|
|
291
|
-
savables.push(field);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
// or just track updated fields
|
|
296
|
-
else {
|
|
297
|
-
// serialize config fields
|
|
298
|
-
this.serializeFieldsUpdate(updates, block.config, [parentPath, block.key, 'config'], savables);
|
|
299
|
-
// serialize content fields
|
|
300
|
-
this.serializeFieldsUpdate(updates, block.fields, [parentPath, block.key, 'fields'], savables);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
serializeFieldsUpdate(updates, fields, parentPath, savables) {
|
|
304
|
-
// handle fields in block
|
|
305
|
-
fields.forEach(field => {
|
|
306
|
-
if (field instanceof funnel_core_1.Field) {
|
|
307
|
-
this.serializeFieldUpdate(updates, field, parentPath, savables);
|
|
308
|
-
}
|
|
309
|
-
else if (field instanceof funnel_core_1.ObjectField) {
|
|
310
|
-
this.serializeObjectFieldUpdate(updates, field, parentPath, savables);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
this.serializeListUpdate(updates, field, parentPath, savables);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
// return changes (for chaining)
|
|
317
|
-
return updates;
|
|
318
|
-
}
|
|
319
|
-
serializeObjectFieldUpdate(updates, field, parentPath, savables) {
|
|
320
|
-
var _a;
|
|
321
|
-
// create object if it's new
|
|
322
|
-
if (field.isNew) {
|
|
323
|
-
// add insert
|
|
324
|
-
updates.push({
|
|
325
|
-
type: 'object.insert',
|
|
326
|
-
path: [...parentPath, field.id],
|
|
327
|
-
value: (_a = field.value) !== null && _a !== void 0 ? _a : null
|
|
328
|
-
});
|
|
329
|
-
// track save
|
|
330
|
-
savables.push(field);
|
|
331
|
-
}
|
|
332
|
-
// or process subfields
|
|
333
|
-
else if (field.exists) {
|
|
334
|
-
// save fields
|
|
335
|
-
this.serializeFieldsUpdate(updates, field.fields, [...parentPath, field.id], savables);
|
|
336
|
-
// track save
|
|
337
|
-
savables.push(field);
|
|
338
|
-
}
|
|
339
|
-
// or process opted out field
|
|
340
|
-
else if (field.optedOut) {
|
|
341
|
-
// remove field
|
|
342
|
-
updates.push({
|
|
343
|
-
type: 'value',
|
|
344
|
-
path: [...parentPath, field.id],
|
|
345
|
-
value: null
|
|
346
|
-
});
|
|
347
|
-
// track save
|
|
348
|
-
savables.push(field);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
serializeFieldUpdate(updates, field, parentPath, savables) {
|
|
352
|
-
var _a;
|
|
353
|
-
// track change if modified (ignore if field is sandboxed)
|
|
354
|
-
if (field.modified && !field.sandboxed) {
|
|
355
|
-
// set field
|
|
356
|
-
updates.push({
|
|
357
|
-
type: 'value',
|
|
358
|
-
path: [...parentPath, field.id],
|
|
359
|
-
value: ((_a = field.value) !== null && _a !== void 0 ? _a : null)
|
|
360
|
-
});
|
|
361
|
-
// track save
|
|
362
|
-
savables.push(field);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
serializeListUpdate(updates, list, parentPath, savables) {
|
|
366
|
-
var _a, _b;
|
|
367
|
-
// create list if it's new
|
|
368
|
-
if (list.isNew) {
|
|
369
|
-
// add new list
|
|
370
|
-
updates.push({
|
|
371
|
-
type: 'value',
|
|
372
|
-
path: [...parentPath, list.id],
|
|
373
|
-
value: funnel_core_1.Schema.Field.Data.newValue('list')
|
|
374
|
-
});
|
|
375
|
-
// track save
|
|
376
|
-
savables.push(list);
|
|
377
|
-
}
|
|
378
|
-
// or drop list on opt-out
|
|
379
|
-
else if (list.optedOut) {
|
|
380
|
-
// drop list
|
|
381
|
-
updates.push({
|
|
382
|
-
type: 'value',
|
|
383
|
-
path: [...parentPath, list.id],
|
|
384
|
-
value: null
|
|
385
|
-
});
|
|
386
|
-
// track save
|
|
387
|
-
savables.push(list);
|
|
388
|
-
}
|
|
389
|
-
// or if it is modified (otherwise ignore)
|
|
390
|
-
else if (list.modified) {
|
|
391
|
-
// add new list if there's nothing and it's new
|
|
392
|
-
const path = [...parentPath, list.id];
|
|
393
|
-
const { value: currentValue, items: fields, initialValue } = list;
|
|
394
|
-
const currentItems = (_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.value) !== null && _a !== void 0 ? _a : [];
|
|
395
|
-
const initialItems = (_b = initialValue === null || initialValue === void 0 ? void 0 : initialValue.value) !== null && _b !== void 0 ? _b : [];
|
|
396
|
-
const fieldIds = [];
|
|
397
|
-
// track inserts/updates of elements
|
|
398
|
-
currentItems.forEach((item, index) => {
|
|
399
|
-
// track id
|
|
400
|
-
const { id, field } = fields[index];
|
|
401
|
-
fieldIds.push(item.id);
|
|
402
|
-
// track insert
|
|
403
|
-
const originalIndex = initialItems.findIndex(initialItem => initialItem.id === id);
|
|
404
|
-
if (originalIndex < 0) {
|
|
405
|
-
updates.push({
|
|
406
|
-
type: 'array.insert',
|
|
407
|
-
path,
|
|
408
|
-
index,
|
|
409
|
-
id,
|
|
410
|
-
value: item
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
// track update
|
|
414
|
-
else if (field.modified) {
|
|
415
|
-
// object field updates should be recursed and indexed
|
|
416
|
-
if (field instanceof funnel_core_1.ObjectField) {
|
|
417
|
-
this.serializeFieldsUpdate(updates, field.fields, [...path, id], savables);
|
|
418
|
-
}
|
|
419
|
-
// basic field updates can be done inline
|
|
420
|
-
else {
|
|
421
|
-
updates.push({
|
|
422
|
-
type: 'value',
|
|
423
|
-
path: [...path, id],
|
|
424
|
-
value: item
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
// track delete/reorder
|
|
430
|
-
let reordered = false;
|
|
431
|
-
let deleted = 0;
|
|
432
|
-
initialItems.forEach(({ id }, index) => {
|
|
433
|
-
// add to deleted list if the original doesn't exist anymore
|
|
434
|
-
const fieldIndex = fieldIds.findIndex(fieldId => fieldId === id) + deleted;
|
|
435
|
-
if (fieldIndex < 0) {
|
|
436
|
-
updates.push({
|
|
437
|
-
type: 'array.delete',
|
|
438
|
-
path,
|
|
439
|
-
id
|
|
440
|
-
});
|
|
441
|
-
// track deletion
|
|
442
|
-
++deleted;
|
|
443
|
-
}
|
|
444
|
-
// or mark reorder if index isn't the same
|
|
445
|
-
else if (fieldIndex !== index) {
|
|
446
|
-
reordered = true;
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
// track reorder
|
|
450
|
-
if (reordered) {
|
|
451
|
-
updates.push({
|
|
452
|
-
type: 'array.reorder',
|
|
453
|
-
path,
|
|
454
|
-
ids: fieldIds
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
// track save
|
|
458
|
-
savables.push(list);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
188
|
}
|
|
462
189
|
exports.PageRepository = PageRepository;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventBus, Schema } from '@nascentdigital/funnel-core';
|
|
2
|
-
import { Page } from '../domain';
|
|
2
|
+
import { Block, Page, Section, SectionBlock } from '../domain';
|
|
3
3
|
import { PageTarget } from './PageTarget';
|
|
4
4
|
export declare namespace PageSerializer {
|
|
5
5
|
type DeserializePageWithSummaryArgs = Schema.Page.Data.AsGroup & PageTarget & {
|
|
@@ -12,4 +12,37 @@ export declare namespace PageSerializer {
|
|
|
12
12
|
eventBus: EventBus;
|
|
13
13
|
};
|
|
14
14
|
function deserializePage({ flattenedPage, target, eventBus }: DeserializePageArgs): Page;
|
|
15
|
+
type DeserializeContentArgs = {
|
|
16
|
+
key: string;
|
|
17
|
+
eventBus: EventBus;
|
|
18
|
+
schema: Schema.Section | Schema.Block;
|
|
19
|
+
content: Schema.Section.Data | Schema.Block.Data | undefined;
|
|
20
|
+
snapshot: Schema.Section.Data | Schema.Block.Data | undefined;
|
|
21
|
+
};
|
|
22
|
+
function deserializeContent({ key, schema, content, eventBus, snapshot }: DeserializeContentArgs): Block | Section;
|
|
23
|
+
type DeserializeSectionArgs = {
|
|
24
|
+
key: string;
|
|
25
|
+
eventBus: EventBus;
|
|
26
|
+
schema: Schema.Section;
|
|
27
|
+
content: Schema.Section.Data | undefined;
|
|
28
|
+
snapshot: Schema.Section.Data | undefined;
|
|
29
|
+
};
|
|
30
|
+
function deserializeSection({ key, eventBus, schema, content, snapshot }: DeserializeSectionArgs): Section;
|
|
31
|
+
type DeserializeSectionBlockArgs = {
|
|
32
|
+
id: string;
|
|
33
|
+
key: string;
|
|
34
|
+
eventBus: EventBus;
|
|
35
|
+
schema: Schema.Block;
|
|
36
|
+
content: Schema.Section.Data.ForBlock | undefined;
|
|
37
|
+
snapshot: Schema.Section.Data.ForBlock | undefined;
|
|
38
|
+
};
|
|
39
|
+
function deserializeSectionBlock({ id, key, eventBus, schema, content, snapshot }: DeserializeSectionBlockArgs): SectionBlock;
|
|
40
|
+
type DeserializeBlockArgs = {
|
|
41
|
+
key: string;
|
|
42
|
+
eventBus: EventBus;
|
|
43
|
+
schema: Schema.Block;
|
|
44
|
+
content: Schema.Block.Data | undefined;
|
|
45
|
+
snapshot: Schema.Block.Data | undefined;
|
|
46
|
+
};
|
|
47
|
+
function deserializeBlock({ key, eventBus, schema, content: blockContent, snapshot }: DeserializeBlockArgs): Block;
|
|
15
48
|
}
|
|
@@ -103,6 +103,7 @@ var PageSerializer;
|
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
PageSerializer.deserializeContent = deserializeContent;
|
|
106
107
|
function deserializeSection({ key, eventBus, schema, content, snapshot }) {
|
|
107
108
|
// TODO: handle version mismatch (between schema + content) and upgrading
|
|
108
109
|
if (content && content.version !== schema.version) {
|
|
@@ -132,6 +133,7 @@ var PageSerializer;
|
|
|
132
133
|
exists: content !== undefined
|
|
133
134
|
});
|
|
134
135
|
}
|
|
136
|
+
PageSerializer.deserializeSection = deserializeSection;
|
|
135
137
|
function deserializeSectionBlock({ id, key, eventBus, schema, content, snapshot }) {
|
|
136
138
|
// create block and return it (upgrade is handled in block deserialization)
|
|
137
139
|
return new domain_1.SectionBlock({
|
|
@@ -143,6 +145,7 @@ var PageSerializer;
|
|
|
143
145
|
exists: true
|
|
144
146
|
});
|
|
145
147
|
}
|
|
148
|
+
PageSerializer.deserializeSectionBlock = deserializeSectionBlock;
|
|
146
149
|
function deserializeBlock({ key, eventBus, schema, content: blockContent, snapshot }) {
|
|
147
150
|
// throw if there's a type mismatch
|
|
148
151
|
const { type = schema.type, version = schema.version, config = {}, fields = {} } = blockContent !== null && blockContent !== void 0 ? blockContent : {};
|
|
@@ -178,4 +181,5 @@ var PageSerializer;
|
|
|
178
181
|
name: config.name
|
|
179
182
|
});
|
|
180
183
|
}
|
|
184
|
+
PageSerializer.deserializeBlock = deserializeBlock;
|
|
181
185
|
})(PageSerializer || (exports.PageSerializer = PageSerializer = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Field, FieldList, FieldModel, ObjectField, Schema } from '@nascentdigital/funnel-core';
|
|
2
|
+
import { ICollectionRepository } from './ICollectionRepository';
|
|
3
|
+
export declare namespace SerializeCollectionUpdate {
|
|
4
|
+
function serializeFieldsUpdate(updates: Schema.Collection.Update[], fields: ReadonlyArray<FieldModel>, parentPath: ReadonlyArray<string>, savables: ICollectionRepository.Savable[]): Schema.Collection.Update[];
|
|
5
|
+
function serializeObjectFieldUpdate(updates: Schema.Collection.Update[], field: ObjectField, parentPath: ReadonlyArray<string>, savables: ICollectionRepository.Savable[]): void;
|
|
6
|
+
function serializeFieldUpdate(updates: Schema.Collection.Update[], field: Field, parentPath: ReadonlyArray<string>, savables: ICollectionRepository.Savable[]): void;
|
|
7
|
+
function serializeListUpdate(updates: Schema.Collection.Update[], list: FieldList, parentPath: ReadonlyArray<string>, savables: ICollectionRepository.Savable[]): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SerializeCollectionUpdate = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
// namespace
|
|
6
|
+
var SerializeCollectionUpdate;
|
|
7
|
+
(function (SerializeCollectionUpdate) {
|
|
8
|
+
// helper
|
|
9
|
+
function serializeFieldsUpdate(updates, fields, parentPath, savables) {
|
|
10
|
+
// handle fields in block
|
|
11
|
+
fields.forEach(field => {
|
|
12
|
+
if (field instanceof funnel_core_1.Field) {
|
|
13
|
+
serializeFieldUpdate(updates, field, parentPath, savables);
|
|
14
|
+
}
|
|
15
|
+
else if (field instanceof funnel_core_1.ObjectField) {
|
|
16
|
+
serializeObjectFieldUpdate(updates, field, parentPath, savables);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
serializeListUpdate(updates, field, parentPath, savables);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
// return changes (for chaining)
|
|
23
|
+
return updates;
|
|
24
|
+
}
|
|
25
|
+
SerializeCollectionUpdate.serializeFieldsUpdate = serializeFieldsUpdate;
|
|
26
|
+
function serializeObjectFieldUpdate(updates, field, parentPath, savables) {
|
|
27
|
+
var _a;
|
|
28
|
+
// create object if it's new
|
|
29
|
+
if (field.isNew) {
|
|
30
|
+
updates.push({
|
|
31
|
+
type: 'object.insert',
|
|
32
|
+
path: [...parentPath, field.id],
|
|
33
|
+
value: (_a = field.value) !== null && _a !== void 0 ? _a : null
|
|
34
|
+
});
|
|
35
|
+
// track save
|
|
36
|
+
savables.push(field);
|
|
37
|
+
}
|
|
38
|
+
// or process subfields
|
|
39
|
+
else if (field.exists) {
|
|
40
|
+
// save fields
|
|
41
|
+
serializeFieldsUpdate(updates, field.fields, [...parentPath, field.id], savables);
|
|
42
|
+
// track save
|
|
43
|
+
savables.push(field);
|
|
44
|
+
}
|
|
45
|
+
// or process opted out field
|
|
46
|
+
else if (field.optedOut) {
|
|
47
|
+
updates.push({
|
|
48
|
+
type: 'value',
|
|
49
|
+
path: [...parentPath, field.id],
|
|
50
|
+
value: null
|
|
51
|
+
});
|
|
52
|
+
// track save
|
|
53
|
+
savables.push(field);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
SerializeCollectionUpdate.serializeObjectFieldUpdate = serializeObjectFieldUpdate;
|
|
57
|
+
function serializeFieldUpdate(updates, field, parentPath, savables) {
|
|
58
|
+
var _a;
|
|
59
|
+
// track change if modified (ignore if field is sandboxed)
|
|
60
|
+
if (field.modified && !field.sandboxed) {
|
|
61
|
+
// set field
|
|
62
|
+
updates.push({
|
|
63
|
+
type: 'value',
|
|
64
|
+
path: [...parentPath, field.id],
|
|
65
|
+
value: ((_a = field.value) !== null && _a !== void 0 ? _a : null)
|
|
66
|
+
});
|
|
67
|
+
// track save
|
|
68
|
+
savables.push(field);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
SerializeCollectionUpdate.serializeFieldUpdate = serializeFieldUpdate;
|
|
72
|
+
function serializeListUpdate(updates, list, parentPath, savables) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
// create list if it's new
|
|
75
|
+
if (list.isNew) {
|
|
76
|
+
// add new list
|
|
77
|
+
updates.push({
|
|
78
|
+
type: 'value',
|
|
79
|
+
path: [...parentPath, list.id],
|
|
80
|
+
value: funnel_core_1.Schema.Field.Data.newValue('list')
|
|
81
|
+
});
|
|
82
|
+
// track save
|
|
83
|
+
savables.push(list);
|
|
84
|
+
}
|
|
85
|
+
// or drop list on opt-out
|
|
86
|
+
else if (list.optedOut) {
|
|
87
|
+
// drop list
|
|
88
|
+
updates.push({
|
|
89
|
+
type: 'value',
|
|
90
|
+
path: [...parentPath, list.id],
|
|
91
|
+
value: null
|
|
92
|
+
});
|
|
93
|
+
// track save
|
|
94
|
+
savables.push(list);
|
|
95
|
+
}
|
|
96
|
+
// or skip if not modified
|
|
97
|
+
else if (list.modified) {
|
|
98
|
+
// track insert/update
|
|
99
|
+
const path = [...parentPath, list.id];
|
|
100
|
+
const { value: currentValue, items: fields, initialValue } = list;
|
|
101
|
+
const currentItems = (_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.value) !== null && _a !== void 0 ? _a : [];
|
|
102
|
+
const initialItems = (_b = initialValue === null || initialValue === void 0 ? void 0 : initialValue.value) !== null && _b !== void 0 ? _b : [];
|
|
103
|
+
const fieldIds = [];
|
|
104
|
+
currentItems.forEach((item, index) => {
|
|
105
|
+
// track id
|
|
106
|
+
const { id, field } = fields[index];
|
|
107
|
+
fieldIds.push(item.id);
|
|
108
|
+
// track insert
|
|
109
|
+
const originalIndex = initialItems.findIndex(initialItem => initialItem.id === id);
|
|
110
|
+
if (originalIndex < 0) {
|
|
111
|
+
updates.push({
|
|
112
|
+
type: 'array.insert',
|
|
113
|
+
path,
|
|
114
|
+
index,
|
|
115
|
+
id,
|
|
116
|
+
value: item
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
// track update
|
|
120
|
+
else if (field.modified) {
|
|
121
|
+
// object field updates should be recursed and indexed
|
|
122
|
+
if (field instanceof funnel_core_1.ObjectField) {
|
|
123
|
+
serializeFieldsUpdate(updates, field.fields, [...path, id], savables);
|
|
124
|
+
}
|
|
125
|
+
// basic field updates can be done inline
|
|
126
|
+
else {
|
|
127
|
+
updates.push({
|
|
128
|
+
type: 'value',
|
|
129
|
+
path: [...path, id],
|
|
130
|
+
value: item
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
// track delete/reorder
|
|
136
|
+
let reordered = false;
|
|
137
|
+
let deleted = 0;
|
|
138
|
+
initialItems.forEach(({ id }, index) => {
|
|
139
|
+
// add to deleted list if the original doesn't exist anymore
|
|
140
|
+
const fieldIndex = fieldIds.findIndex(fieldId => fieldId === id) + deleted;
|
|
141
|
+
if (fieldIndex < 0) {
|
|
142
|
+
updates.push({
|
|
143
|
+
type: 'array.delete',
|
|
144
|
+
path,
|
|
145
|
+
id
|
|
146
|
+
});
|
|
147
|
+
// track deletion
|
|
148
|
+
++deleted;
|
|
149
|
+
}
|
|
150
|
+
// or mark reorder if index isn't the same
|
|
151
|
+
else if (fieldIndex !== index) {
|
|
152
|
+
reordered = true;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
// track reorder
|
|
156
|
+
if (reordered) {
|
|
157
|
+
updates.push({
|
|
158
|
+
type: 'array.reorder',
|
|
159
|
+
path,
|
|
160
|
+
ids: fieldIds
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// track save
|
|
164
|
+
savables.push(list);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
SerializeCollectionUpdate.serializeListUpdate = serializeListUpdate;
|
|
168
|
+
})(SerializeCollectionUpdate || (exports.SerializeCollectionUpdate = SerializeCollectionUpdate = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Field, FieldList, FieldModel, ObjectField, Schema } from '@nascentdigital/funnel-core';
|
|
2
|
+
import type { Block, Section } from '../domain';
|
|
3
|
+
export declare namespace SerializePageUpdate {
|
|
4
|
+
type Savable = Section | Block | FieldModel;
|
|
5
|
+
function serializeSectionUpdate(updates: Schema.Page.Update[], section: Section, parentPath: string, savables: Savable[]): void;
|
|
6
|
+
function serializeBlockUpdate(updates: Schema.Page.Update[], block: Block, parentPath: string, savables: Savable[]): void;
|
|
7
|
+
function serializeFieldsUpdate(updates: Schema.Page.Update[], fields: ReadonlyArray<FieldModel>, parentPath: ReadonlyArray<string>, savables: Savable[]): Schema.Page.Update[];
|
|
8
|
+
function serializeObjectFieldUpdate(updates: Schema.Page.Update[], field: ObjectField, parentPath: ReadonlyArray<string>, savables: Savable[]): void;
|
|
9
|
+
function serializeFieldUpdate(updates: Schema.Page.Update[], field: Field, parentPath: ReadonlyArray<string>, savables: Savable[]): void;
|
|
10
|
+
function serializeListUpdate(updates: Schema.Page.Update[], list: FieldList, parentPath: ReadonlyArray<string>, savables: Savable[]): void;
|
|
11
|
+
}
|