@nascentdigital/funnel-editor-contentful 4.6.7 → 5.0.2
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/Editor.d.ts +6 -1
- package/dist/Editor.js +17 -1
- package/dist/EditorApp.js +11 -9
- package/dist/EditorPageRouter.d.ts +1 -0
- package/dist/EditorPageRouter.js +40 -0
- package/dist/EntryEditor.js +43 -1
- package/dist/EntrySidebar.js +18 -1
- package/dist/asset/index.d.ts +1 -0
- package/dist/{page/hooks → asset}/index.js +1 -1
- package/dist/asset/repository/AssetRepository.d.ts +10 -0
- package/dist/asset/repository/AssetRepository.js +33 -0
- package/dist/asset/repository/index.d.ts +1 -0
- package/dist/{core/api → asset/repository}/index.js +1 -3
- package/dist/collection/controller/ContentfulCollectionController.d.ts +41 -0
- package/dist/collection/controller/ContentfulCollectionController.js +278 -0
- package/dist/collection/controller/ContentfulCollectionControllerContainer.d.ts +5 -0
- package/dist/collection/controller/ContentfulCollectionControllerContainer.js +28 -0
- package/dist/collection/controller/index.d.ts +3 -0
- package/dist/collection/controller/index.js +19 -0
- package/dist/collection/controller/useContentfulCollectionController.d.ts +2 -0
- package/dist/collection/controller/useContentfulCollectionController.js +8 -0
- package/dist/collection/domain/Collection.d.ts +108 -0
- package/dist/collection/domain/Collection.js +386 -0
- package/dist/collection/domain/index.d.ts +1 -0
- package/dist/collection/domain/index.js +17 -0
- package/dist/collection/index.d.ts +3 -0
- package/dist/collection/index.js +19 -0
- package/dist/collection/repository/CollectionRepository.d.ts +49 -0
- package/dist/collection/repository/CollectionRepository.js +210 -0
- package/dist/collection/repository/index.d.ts +1 -0
- package/dist/collection/repository/index.js +17 -0
- package/dist/collection/screens/CollectionEditor.d.ts +1 -0
- package/dist/collection/screens/CollectionEditor.js +59 -0
- package/dist/collection/screens/index.d.ts +1 -0
- package/dist/collection/screens/index.js +17 -0
- package/dist/core/bridge/AppBridgeContainer.d.ts +9 -0
- package/dist/core/bridge/AppBridgeContainer.js +55 -0
- package/dist/core/bridge/AppBridgeContext.d.ts +8 -0
- package/dist/core/bridge/AppBridgeContext.js +11 -0
- package/dist/core/bridge/AppMessage.d.ts +19 -0
- package/dist/core/bridge/AppMessage.js +19 -0
- package/dist/core/bridge/index.d.ts +4 -0
- package/dist/core/bridge/index.js +20 -0
- package/dist/core/bridge/useAppBridge.d.ts +8 -0
- package/dist/core/bridge/useAppBridge.js +24 -0
- package/dist/core/client/ContentfulClientContainer.d.ts +8 -0
- package/dist/core/client/ContentfulClientContainer.js +43 -0
- package/dist/core/client/ContentfulClientContext.d.ts +8 -0
- package/dist/core/client/ContentfulClientContext.js +8 -0
- package/dist/core/client/index.d.ts +3 -0
- package/dist/core/client/index.js +19 -0
- package/dist/core/client/useContentfulClient.d.ts +4 -0
- package/dist/core/client/useContentfulClient.js +24 -0
- package/dist/core/contentful/Contentful.d.ts +33 -0
- package/dist/core/contentful/Contentful.js +67 -0
- package/dist/core/contentful/ContentfulAsset.d.ts +23 -0
- package/dist/core/contentful/ContentfulAsset.js +89 -0
- package/dist/core/contentful/ContentfulCollection.d.ts +29 -0
- package/dist/core/contentful/ContentfulCollection.js +97 -0
- package/dist/core/contentful/ContentfulPage.d.ts +31 -0
- package/dist/core/contentful/ContentfulPage.js +84 -0
- package/dist/core/contentful/ContentfulRefs.d.ts +16 -0
- package/dist/core/contentful/ContentfulRefs.js +152 -0
- package/dist/core/contentful/index.d.ts +5 -0
- package/dist/core/contentful/index.js +21 -0
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +3 -2
- package/dist/core/repository/CollectionSerializer.d.ts +9 -0
- package/dist/core/repository/CollectionSerializer.js +41 -0
- package/dist/core/repository/LocalCollectionRepository.d.ts +27 -0
- package/dist/core/repository/LocalCollectionRepository.js +143 -0
- package/dist/core/repository/LocalPageRepository.d.ts +16 -0
- package/dist/core/repository/LocalPageRepository.js +153 -0
- package/dist/core/repository/PageSerializer.d.ts +3 -3
- package/dist/core/repository/PageSerializer.js +18 -14
- package/dist/core/repository/RemoteCollectionRepository.d.ts +19 -0
- package/dist/core/repository/RemoteCollectionRepository.js +236 -0
- package/dist/core/repository/RemotePageRepository.d.ts +14 -0
- package/dist/core/repository/RemotePageRepository.js +113 -0
- package/dist/core/repository/index.d.ts +4 -1
- package/dist/core/repository/index.js +4 -1
- package/dist/explore/components/Header.d.ts +26 -0
- package/dist/explore/components/Header.js +31 -0
- package/dist/explore/components/index.d.ts +1 -0
- package/dist/explore/components/index.js +17 -0
- package/dist/explore/index.d.ts +1 -0
- package/dist/explore/index.js +17 -0
- package/dist/explore/screens/Dashboard.d.ts +1 -0
- package/dist/explore/screens/Dashboard.js +22 -0
- package/dist/explore/screens/PageExplorer.d.ts +1 -0
- package/dist/explore/screens/PageExplorer.js +9 -0
- package/dist/explore/screens/SiteExplorer.d.ts +1 -0
- package/dist/explore/screens/SiteExplorer.js +24 -0
- package/dist/explore/screens/index.d.ts +3 -0
- package/dist/explore/screens/index.js +19 -0
- package/dist/page/{hooks/PageController.d.ts → controller/ContentfulPageController.d.ts} +17 -6
- package/dist/page/controller/ContentfulPageController.js +277 -0
- package/dist/page/controller/ContentfulPageControllerContainer.d.ts +5 -0
- package/dist/page/controller/ContentfulPageControllerContainer.js +28 -0
- package/dist/page/controller/index.d.ts +3 -0
- package/dist/page/controller/index.js +19 -0
- package/dist/page/controller/useContentfulPageController.d.ts +2 -0
- package/dist/page/controller/useContentfulPageController.js +8 -0
- package/dist/{core → page}/domain/Page.d.ts +71 -10
- package/dist/page/domain/Page.js +631 -0
- package/dist/page/index.d.ts +3 -0
- package/dist/page/index.js +3 -0
- package/dist/page/repository/PageRepository.d.ts +45 -0
- package/dist/page/repository/PageRepository.js +224 -0
- package/dist/page/repository/index.d.ts +1 -0
- package/dist/page/repository/index.js +17 -0
- package/dist/page/screens/PageEditor.js +29 -15
- package/package.json +10 -4
- package/dist/core/api/EditorApiClient.d.ts +0 -7
- package/dist/core/api/EditorApiClient.js +0 -29
- package/dist/core/api/EditorApiContainer.d.ts +0 -5
- package/dist/core/api/EditorApiContainer.js +0 -16
- package/dist/core/api/EditorApiContext.d.ts +0 -7
- package/dist/core/api/EditorApiContext.js +0 -6
- package/dist/core/api/index.d.ts +0 -3
- package/dist/core/api/useEditorApi.d.ts +0 -2
- package/dist/core/api/useEditorApi.js +0 -12
- package/dist/core/domain/Page.js +0 -180
- package/dist/core/repository/PageRepository.d.ts +0 -12
- package/dist/core/repository/PageRepository.js +0 -23
- package/dist/page/hooks/PageController.js +0 -107
- package/dist/page/hooks/index.d.ts +0 -1
- /package/dist/{core → page}/domain/index.d.ts +0 -0
- /package/dist/{core → page}/domain/index.js +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventBus, Schema } from '@nascentdigital/funnel-core';
|
|
2
|
+
import { Collection } from '../../collection/domain';
|
|
3
|
+
export declare namespace CollectionSerializer {
|
|
4
|
+
type DeserializeCollectionArgs = {
|
|
5
|
+
flattenedCollection: Schema.Collection.FlattenedData;
|
|
6
|
+
eventBus: EventBus;
|
|
7
|
+
};
|
|
8
|
+
function deserializeCollection({ flattenedCollection, eventBus }: DeserializeCollectionArgs): Collection;
|
|
9
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.CollectionSerializer = void 0;
|
|
15
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
17
|
+
const domain_1 = require("../../collection/domain");
|
|
18
|
+
// namespace
|
|
19
|
+
var CollectionSerializer;
|
|
20
|
+
(function (CollectionSerializer) {
|
|
21
|
+
function deserializeCollection({ flattenedCollection, eventBus }) {
|
|
22
|
+
// destructure
|
|
23
|
+
const { data } = flattenedCollection;
|
|
24
|
+
const { snapshot, fields } = data, dataRest = __rest(data
|
|
25
|
+
// determine latest snapshot (if any)
|
|
26
|
+
, ["snapshot", "fields"]);
|
|
27
|
+
// determine latest snapshot (if any)
|
|
28
|
+
const { fields: fieldsSnapshot = {} } = snapshot !== null && snapshot !== void 0 ? snapshot : {};
|
|
29
|
+
// get collection schema
|
|
30
|
+
const template = funnel_core_1.Schema.Site.getCollection(data.type);
|
|
31
|
+
// create collection
|
|
32
|
+
return new domain_1.Collection(Object.assign(Object.assign({}, dataRest), { template, fields: Object.entries(template.editableFields).map(([id, schema]) => components_1.FieldSerializer.deserializeField({
|
|
33
|
+
id,
|
|
34
|
+
eventBus,
|
|
35
|
+
schema,
|
|
36
|
+
content: fields[id],
|
|
37
|
+
snapshot: fieldsSnapshot[id]
|
|
38
|
+
})), eventBus }));
|
|
39
|
+
}
|
|
40
|
+
CollectionSerializer.deserializeCollection = deserializeCollection;
|
|
41
|
+
})(CollectionSerializer || (exports.CollectionSerializer = CollectionSerializer = {}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EditorAppSDK } from '@contentful/app-sdk';
|
|
2
|
+
import { CollectionClient } from '@nascentdigital/funnel-cms';
|
|
3
|
+
import { EventBus, Schema } from '@nascentdigital/funnel-core';
|
|
4
|
+
import { CollectionFieldProxy, ICollection, ICollectionRepository } from '@nascentdigital/funnel-editor/components';
|
|
5
|
+
import { Collection } from '../../collection/domain';
|
|
6
|
+
export declare class LocalCollectionRepository implements ICollectionRepository {
|
|
7
|
+
readonly sdk: EditorAppSDK;
|
|
8
|
+
constructor(sdk: EditorAppSDK);
|
|
9
|
+
load({ eventBus }: LocalCollectionRepository.LoadArgs): Promise<Collection | undefined>;
|
|
10
|
+
create(args: ICollectionRepository.Create.Args): Promise<ICollection.WithGroup>;
|
|
11
|
+
createRaw(args: ICollectionRepository.Create.Args): Promise<Schema.Collection.Data.AsGroup>;
|
|
12
|
+
createLanguage(args: ICollectionRepository.CreateLang.Args): Promise<ICollection.WithGroup>;
|
|
13
|
+
save(collection: Collection): Promise<Collection>;
|
|
14
|
+
unpublish(collection: ICollection): Promise<void>;
|
|
15
|
+
getOverview(args: ICollectionRepository.GetOverview.Args): Promise<ICollectionRepository.GetOverview.Result>;
|
|
16
|
+
getItems(args: ICollectionRepository.GetItems.Args): Promise<ICollectionRepository.GetItems.Result>;
|
|
17
|
+
get(args: ICollectionRepository.Get.Args): Promise<ICollectionRepository.Get.Result>;
|
|
18
|
+
update(args: ICollectionRepository.Update.Args): Promise<ICollectionRepository.Update.Result>;
|
|
19
|
+
serializeUpdate(collection: Collection | CollectionFieldProxy, savables: ICollection.Savable[]): ICollectionRepository.SerializeUpdates.Result;
|
|
20
|
+
private onSave;
|
|
21
|
+
}
|
|
22
|
+
export declare namespace LocalCollectionRepository {
|
|
23
|
+
type LoadArgs = {
|
|
24
|
+
eventBus: EventBus;
|
|
25
|
+
};
|
|
26
|
+
function currentCollectionGroup(sdk: EditorAppSDK): CollectionClient.GetGroup.Result;
|
|
27
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalCollectionRepository = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
6
|
+
const contentful_1 = require("../contentful");
|
|
7
|
+
const CollectionSerializer_1 = require("./CollectionSerializer");
|
|
8
|
+
// class
|
|
9
|
+
class LocalCollectionRepository {
|
|
10
|
+
constructor(sdk) {
|
|
11
|
+
this.sdk = sdk;
|
|
12
|
+
}
|
|
13
|
+
async load({ eventBus }) {
|
|
14
|
+
var _a;
|
|
15
|
+
// fetch current collection
|
|
16
|
+
const { collection: flattenedCollection } = (_a = LocalCollectionRepository.currentCollectionGroup(this.sdk)) !== null && _a !== void 0 ? _a : {};
|
|
17
|
+
if (!flattenedCollection) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
// deserialize collection
|
|
21
|
+
return CollectionSerializer_1.CollectionSerializer.deserializeCollection({
|
|
22
|
+
eventBus,
|
|
23
|
+
flattenedCollection
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async create(args) {
|
|
27
|
+
throw new funnel_core_1.NotImplementedError();
|
|
28
|
+
}
|
|
29
|
+
async createRaw(args) {
|
|
30
|
+
throw new funnel_core_1.NotImplementedError();
|
|
31
|
+
}
|
|
32
|
+
async createLanguage(args) {
|
|
33
|
+
throw new funnel_core_1.NotImplementedError();
|
|
34
|
+
}
|
|
35
|
+
async save(collection) {
|
|
36
|
+
// serialize to collection data
|
|
37
|
+
const collectionData = contentful_1.ContentfulCollection.serialize(this.sdk.entry);
|
|
38
|
+
// serialize collection updates
|
|
39
|
+
const savables = [];
|
|
40
|
+
const { updates } = this.serializeUpdate(collection, savables);
|
|
41
|
+
// start all updates
|
|
42
|
+
collection.onSaveStart();
|
|
43
|
+
savables.forEach(savable => savable.onSaveStart());
|
|
44
|
+
// create model and apply updates
|
|
45
|
+
const collectionModel = new funnel_core_1.Schema.CollectionModel(collectionData);
|
|
46
|
+
collectionModel.update(updates);
|
|
47
|
+
// deserialize and apply changes
|
|
48
|
+
const updatedContentfulCollection = contentful_1.ContentfulCollection.deserialize(collectionData);
|
|
49
|
+
const updatedOn = await this.onSave(updatedContentfulCollection);
|
|
50
|
+
// complete updates
|
|
51
|
+
savables.forEach(savable => savable.onSaveComplete());
|
|
52
|
+
collection.onSaveComplete(updatedOn);
|
|
53
|
+
// return collection
|
|
54
|
+
return collection;
|
|
55
|
+
}
|
|
56
|
+
async unpublish(collection) {
|
|
57
|
+
throw new funnel_core_1.NotImplementedError();
|
|
58
|
+
}
|
|
59
|
+
async getOverview(args) {
|
|
60
|
+
throw new funnel_core_1.NotImplementedError();
|
|
61
|
+
}
|
|
62
|
+
async getItems(args) {
|
|
63
|
+
throw new funnel_core_1.NotImplementedError();
|
|
64
|
+
}
|
|
65
|
+
async get(args) {
|
|
66
|
+
throw new funnel_core_1.NotImplementedError();
|
|
67
|
+
}
|
|
68
|
+
async update(args) {
|
|
69
|
+
throw new funnel_core_1.NotImplementedError();
|
|
70
|
+
}
|
|
71
|
+
serializeUpdate(collection, savables) {
|
|
72
|
+
// add name updates
|
|
73
|
+
const { id, nameField, name, initialTags, tags, fields, initialErrors, valid } = collection;
|
|
74
|
+
const updates = [];
|
|
75
|
+
if (nameField.modified) {
|
|
76
|
+
updates.push({
|
|
77
|
+
type: 'collection',
|
|
78
|
+
property: 'name',
|
|
79
|
+
value: name
|
|
80
|
+
});
|
|
81
|
+
// track change
|
|
82
|
+
savables.push(nameField);
|
|
83
|
+
}
|
|
84
|
+
// add tag updates
|
|
85
|
+
if (initialTags.symmetricDifference(tags).size > 0) {
|
|
86
|
+
updates.push({
|
|
87
|
+
type: 'collection',
|
|
88
|
+
property: 'tags',
|
|
89
|
+
value: Array.from(tags).map(tag => tag.data)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// add errors updates
|
|
93
|
+
if (initialErrors !== !valid) {
|
|
94
|
+
updates.push({
|
|
95
|
+
type: 'collection',
|
|
96
|
+
property: 'errors',
|
|
97
|
+
value: !valid
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// add fields
|
|
101
|
+
components_1.SerializeCollectionUpdate.serializeFieldsUpdate(updates, fields, ['fields'], savables);
|
|
102
|
+
// return updates
|
|
103
|
+
return {
|
|
104
|
+
id,
|
|
105
|
+
updates,
|
|
106
|
+
updatedOn: Date.now()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async onSave(contentfulCollection) {
|
|
110
|
+
// TODO: need to improve saving to entry, need to save only needed fields
|
|
111
|
+
// entry
|
|
112
|
+
const entry = this.sdk.entry;
|
|
113
|
+
// update fields
|
|
114
|
+
await Promise.all([
|
|
115
|
+
entry.fields.name.setValue(contentfulCollection.name),
|
|
116
|
+
entry.fields.fields.setValue(contentfulCollection.fields),
|
|
117
|
+
entry.fields.state.setValue(contentfulCollection.state),
|
|
118
|
+
entry.fields.errors.setValue(contentfulCollection.errors)
|
|
119
|
+
]);
|
|
120
|
+
// update references
|
|
121
|
+
const links = contentful_1.ContentfulCollection.deserializeLinks(contentfulCollection);
|
|
122
|
+
await entry.fields.references.setValue(links);
|
|
123
|
+
// manually trigger save
|
|
124
|
+
await entry.save();
|
|
125
|
+
// return updated on
|
|
126
|
+
return new Date(entry.getSys().updatedAt).getTime();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.LocalCollectionRepository = LocalCollectionRepository;
|
|
130
|
+
// extension
|
|
131
|
+
(function (LocalCollectionRepository) {
|
|
132
|
+
function currentCollectionGroup(sdk) {
|
|
133
|
+
return {
|
|
134
|
+
group: {},
|
|
135
|
+
collection: {
|
|
136
|
+
data: contentful_1.ContentfulCollection.serialize(sdk.entry),
|
|
137
|
+
files: {},
|
|
138
|
+
collections: {}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
LocalCollectionRepository.currentCollectionGroup = currentCollectionGroup;
|
|
143
|
+
})(LocalCollectionRepository || (exports.LocalCollectionRepository = LocalCollectionRepository = {}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EditorAppSDK } from '@contentful/app-sdk';
|
|
2
|
+
import { EventBus } from '@nascentdigital/funnel-core';
|
|
3
|
+
import { Page } from '../../page/domain';
|
|
4
|
+
export declare class LocalPageRepository {
|
|
5
|
+
readonly sdk: EditorAppSDK;
|
|
6
|
+
constructor(sdk: EditorAppSDK);
|
|
7
|
+
load({ eventBus }: LocalPageRepository.LoadArgs): Promise<Page>;
|
|
8
|
+
save(page: Page): Promise<Page>;
|
|
9
|
+
private serializePageUpdates;
|
|
10
|
+
private onSave;
|
|
11
|
+
}
|
|
12
|
+
export declare namespace LocalPageRepository {
|
|
13
|
+
type LoadArgs = {
|
|
14
|
+
eventBus: EventBus;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalPageRepository = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
6
|
+
const contentful_1 = require("../contentful");
|
|
7
|
+
const PageSerializer_1 = require("./PageSerializer");
|
|
8
|
+
// class
|
|
9
|
+
class LocalPageRepository {
|
|
10
|
+
constructor(sdk) {
|
|
11
|
+
this.sdk = sdk;
|
|
12
|
+
}
|
|
13
|
+
async load({ eventBus }) {
|
|
14
|
+
// entry to page data
|
|
15
|
+
const data = contentful_1.ContentfulPage.serialize(this.sdk.entry);
|
|
16
|
+
// page data to domain
|
|
17
|
+
return PageSerializer_1.PageSerializer.deserializePage({ eventBus, data });
|
|
18
|
+
}
|
|
19
|
+
async save(page) {
|
|
20
|
+
// serialize to page data
|
|
21
|
+
const pageData = contentful_1.ContentfulPage.serialize(this.sdk.entry);
|
|
22
|
+
// serialize page updates
|
|
23
|
+
const savables = [];
|
|
24
|
+
const updates = this.serializePageUpdates(page, savables);
|
|
25
|
+
// start all updates
|
|
26
|
+
page.onSaveStart();
|
|
27
|
+
savables.forEach(savable => savable.onSaveStart());
|
|
28
|
+
// create model and apply updates
|
|
29
|
+
const pageModel = new funnel_core_1.Schema.PageModel(pageData);
|
|
30
|
+
pageModel.update(updates);
|
|
31
|
+
pageModel.sync();
|
|
32
|
+
// deserialize and apply changes
|
|
33
|
+
const updatedContentfulPage = contentful_1.ContentfulPage.deserialize(pageData);
|
|
34
|
+
const updatedOn = await this.onSave(updatedContentfulPage);
|
|
35
|
+
// complete updates
|
|
36
|
+
savables.forEach(savable => savable.onSaveComplete());
|
|
37
|
+
page.onSaveComplete(updatedOn);
|
|
38
|
+
// return page
|
|
39
|
+
return page;
|
|
40
|
+
}
|
|
41
|
+
serializePageUpdates(page, savables) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
// root page updates
|
|
44
|
+
const rootPageUpdates = [];
|
|
45
|
+
// name
|
|
46
|
+
if (page.initialName !== page.name) {
|
|
47
|
+
rootPageUpdates.push({
|
|
48
|
+
type: 'page',
|
|
49
|
+
property: 'name',
|
|
50
|
+
value: page.name
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// tags
|
|
54
|
+
if (page.initialTags.symmetricDifference(page.tags).size > 0) {
|
|
55
|
+
rootPageUpdates.push({
|
|
56
|
+
type: 'page',
|
|
57
|
+
property: 'tags',
|
|
58
|
+
value: Array.from(page.tags).map(tag => tag.data)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// slug + url
|
|
62
|
+
if (page.initialSlug !== page.slug) {
|
|
63
|
+
rootPageUpdates.push({
|
|
64
|
+
type: 'page',
|
|
65
|
+
property: 'slug',
|
|
66
|
+
value: (_a = page.slug) !== null && _a !== void 0 ? _a : null
|
|
67
|
+
});
|
|
68
|
+
rootPageUpdates.push({
|
|
69
|
+
type: 'page',
|
|
70
|
+
property: 'url',
|
|
71
|
+
value: page.url
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// preview
|
|
75
|
+
const previewBlock = page.getPreviewBlock();
|
|
76
|
+
if (previewBlock && previewBlock.modified) {
|
|
77
|
+
rootPageUpdates.push({
|
|
78
|
+
type: 'page',
|
|
79
|
+
property: 'preview',
|
|
80
|
+
value: previewBlock.value
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// errors
|
|
84
|
+
if (page.initialErrors !== !page.valid) {
|
|
85
|
+
rootPageUpdates.push({
|
|
86
|
+
type: 'page',
|
|
87
|
+
property: 'errors',
|
|
88
|
+
value: !page.valid
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// publication
|
|
92
|
+
if (page.initialPublication !== page.publication) {
|
|
93
|
+
rootPageUpdates.push({
|
|
94
|
+
type: 'page',
|
|
95
|
+
property: 'publication',
|
|
96
|
+
value: (_b = page.publication) !== null && _b !== void 0 ? _b : null
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// discover updates
|
|
100
|
+
const discoverUpdates = page.discover.reduce((updates, block) => {
|
|
101
|
+
// try to update block
|
|
102
|
+
components_1.SerializePageUpdate.serializeBlockUpdate(updates, block, 'discover', savables);
|
|
103
|
+
// keep reducing
|
|
104
|
+
return updates;
|
|
105
|
+
}, []);
|
|
106
|
+
// content updates
|
|
107
|
+
const contentUpdates = page.content.reduce((updates, item) => {
|
|
108
|
+
// handle block
|
|
109
|
+
if (item instanceof components_1.Block) {
|
|
110
|
+
components_1.SerializePageUpdate.serializeBlockUpdate(updates, item, 'content', savables);
|
|
111
|
+
}
|
|
112
|
+
// or section
|
|
113
|
+
else {
|
|
114
|
+
components_1.SerializePageUpdate.serializeSectionUpdate(updates, item, 'content', savables);
|
|
115
|
+
}
|
|
116
|
+
// keep reducing
|
|
117
|
+
return updates;
|
|
118
|
+
}, []);
|
|
119
|
+
// delete block updates
|
|
120
|
+
const deletedBlockUpdates = page.deleteBlocks.map(block => ({
|
|
121
|
+
type: 'block.delete',
|
|
122
|
+
path: [block.area, block.key]
|
|
123
|
+
}));
|
|
124
|
+
// return updates
|
|
125
|
+
return [
|
|
126
|
+
...rootPageUpdates,
|
|
127
|
+
...discoverUpdates,
|
|
128
|
+
...contentUpdates,
|
|
129
|
+
...deletedBlockUpdates
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
async onSave(contentfulPage) {
|
|
133
|
+
// TODO: need to improve saving to entry, need to save only needed fields
|
|
134
|
+
// local entry
|
|
135
|
+
const entry = this.sdk.entry;
|
|
136
|
+
// save fields
|
|
137
|
+
await Promise.all([
|
|
138
|
+
entry.fields.url.setValue(contentfulPage.url),
|
|
139
|
+
entry.fields.state.setValue(contentfulPage.state),
|
|
140
|
+
entry.fields.errors.setValue(contentfulPage.errors),
|
|
141
|
+
entry.fields.preview.setValue(contentfulPage.preview),
|
|
142
|
+
entry.fields.content.setValue(contentfulPage.content),
|
|
143
|
+
]);
|
|
144
|
+
// update references
|
|
145
|
+
const links = contentful_1.ContentfulPage.deserializeLinks(contentfulPage);
|
|
146
|
+
await entry.fields.references.setValue(links);
|
|
147
|
+
// manually trigger save
|
|
148
|
+
await entry.save();
|
|
149
|
+
// grab latest updated time
|
|
150
|
+
return new Date(entry.getSys().updatedAt).getTime();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.LocalPageRepository = LocalPageRepository;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventBus, Schema } from '@nascentdigital/funnel-core';
|
|
2
|
-
import { Page } from '
|
|
2
|
+
import { Page } from '../../page/domain';
|
|
3
3
|
export declare namespace PageSerializer {
|
|
4
4
|
type DeserializePageArgs = {
|
|
5
|
-
|
|
5
|
+
data: Schema.Page.Data;
|
|
6
6
|
eventBus: EventBus;
|
|
7
7
|
};
|
|
8
|
-
function deserializePage({
|
|
8
|
+
function deserializePage({ data, eventBus }: DeserializePageArgs): Page;
|
|
9
9
|
}
|
|
@@ -14,31 +14,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.PageSerializer = void 0;
|
|
15
15
|
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
16
|
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
17
|
-
const domain_1 = require("
|
|
17
|
+
const domain_1 = require("../../page/domain");
|
|
18
18
|
// namespace
|
|
19
19
|
var PageSerializer;
|
|
20
20
|
(function (PageSerializer) {
|
|
21
|
-
function deserializePage({
|
|
21
|
+
function deserializePage({ data, eventBus }) {
|
|
22
22
|
// destructure
|
|
23
|
-
const {
|
|
24
|
-
const { snapshot, content } = data, dataRest = __rest(data
|
|
23
|
+
const { snapshot, discover, content, tags } = data, dataRest = __rest(data
|
|
25
24
|
// determine latest snapshot (if any)
|
|
26
|
-
, ["snapshot", "content"]);
|
|
25
|
+
, ["snapshot", "discover", "content", "tags"]);
|
|
27
26
|
// determine latest snapshot (if any)
|
|
28
|
-
const { content: contentSnapshot = {} } = snapshot !== null && snapshot !== void 0 ? snapshot : {};
|
|
29
|
-
//
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
// create
|
|
33
|
-
|
|
27
|
+
const { discover: discoverSnapshot = {}, content: contentSnapshot = {} } = snapshot !== null && snapshot !== void 0 ? snapshot : {};
|
|
28
|
+
// get page schema
|
|
29
|
+
const template = funnel_core_1.Schema.Site.getPage(data.type, data.region);
|
|
30
|
+
console.debug('[PageSerializer.deserializePage] template', { template, data });
|
|
31
|
+
// create page
|
|
32
|
+
return new domain_1.Page(Object.assign(Object.assign({}, dataRest), { template, tags: components_1.TagSerializer.deserializeTags({
|
|
33
|
+
groups: template.tags,
|
|
34
|
+
tagsData: tags
|
|
35
|
+
}), discover: [
|
|
36
|
+
components_1.PageSerializer.deserializeBlock({ schema: funnel_core_1.Schema.Seo, eventBus, key: 'seo', content: discover['seo'], snapshot: discoverSnapshot['seo'] })
|
|
37
|
+
], content: Object.entries(template.content).map(([key, schema]) => components_1.PageSerializer.deserializeContent({
|
|
34
38
|
key,
|
|
35
39
|
schema: schema.unwrap(),
|
|
36
40
|
eventBus,
|
|
37
41
|
content: content[key],
|
|
38
42
|
snapshot: contentSnapshot[key],
|
|
39
|
-
})), eventBus
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
})), eventBus,
|
|
44
|
+
// references get hydrated from remote page repository
|
|
45
|
+
files: [], pages: [], collections: [] }));
|
|
42
46
|
}
|
|
43
47
|
PageSerializer.deserializePage = deserializePage;
|
|
44
48
|
})(PageSerializer || (exports.PageSerializer = PageSerializer = {}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EditorAppSDK } from '@contentful/app-sdk';
|
|
2
|
+
import { Schema } from '@nascentdigital/funnel-core';
|
|
3
|
+
import { CollectionFieldProxy, ICollection, ICollectionRepository } from '@nascentdigital/funnel-editor/components';
|
|
4
|
+
import { Collection } from '../../collection/domain';
|
|
5
|
+
export declare class RemoteCollectionRepository implements ICollectionRepository {
|
|
6
|
+
readonly sdk: EditorAppSDK;
|
|
7
|
+
constructor(sdk: EditorAppSDK);
|
|
8
|
+
create(args: ICollectionRepository.Create.Args): Promise<ICollectionRepository.Create.Result>;
|
|
9
|
+
createRaw(args: ICollectionRepository.CreateRaw.Args): Promise<ICollectionRepository.CreateRaw.Result>;
|
|
10
|
+
createLanguage(args: ICollectionRepository.CreateLang.Args): Promise<ICollection.WithGroup>;
|
|
11
|
+
save(collection: ICollection): Promise<ICollection>;
|
|
12
|
+
unpublish(collection: ICollection): Promise<void>;
|
|
13
|
+
getOverview(args: ICollectionRepository.GetOverview.Args): Promise<ICollectionRepository.GetOverview.Result>;
|
|
14
|
+
getItems({ type, tags, language }: ICollectionRepository.GetItems.Args): Promise<ICollectionRepository.GetItems.Result>;
|
|
15
|
+
get({ id }: ICollectionRepository.Get.Args): Promise<ICollectionRepository.Get.Result>;
|
|
16
|
+
update(args: ICollectionRepository.Update.Args): Promise<ICollectionRepository.Update.Result>;
|
|
17
|
+
serializeUpdate(collection: Collection | CollectionFieldProxy, savables: ICollection.Savable[]): ICollectionRepository.SerializeUpdates.Result;
|
|
18
|
+
getReferences(collectionId: Schema.Collection.Id): Promise<ICollection.References>;
|
|
19
|
+
}
|