@nascentdigital/funnel-editor-contentful 5.0.2 → 5.0.3
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 +2 -2
- package/dist/EditorPageRouter.js +3 -9
- package/dist/EditorPageRoutes.d.ts +1 -0
- package/dist/EditorPageRoutes.js +16 -0
- package/dist/EntryEditor.js +1 -1
- package/dist/EntrySidebar.js +26 -5
- package/dist/NotFound.d.ts +1 -0
- package/dist/NotFound.js +18 -0
- package/dist/asset/repository/AssetRepository.d.ts +11 -3
- package/dist/asset/repository/AssetRepository.js +6 -5
- package/dist/collection/domain/Collection.js +2 -1
- package/dist/collection/repository/CollectionRepository.d.ts +3 -3
- package/dist/collection/repository/CollectionRepository.js +19 -6
- package/dist/core/bridge/AppBridge.d.ts +31 -0
- package/dist/core/bridge/AppBridge.js +160 -0
- package/dist/core/bridge/AppBridgeContainer.d.ts +3 -3
- package/dist/core/bridge/AppBridgeContainer.js +8 -44
- package/dist/core/bridge/AppBridgeContext.d.ts +7 -8
- package/dist/core/bridge/AppBridgeContext.js +1 -6
- package/dist/core/bridge/BridgeLifecycleMessage.d.ts +7 -0
- package/dist/core/bridge/BridgeLifecycleMessage.js +12 -0
- package/dist/core/bridge/IAppBridgeMessage.d.ts +16 -0
- package/dist/core/bridge/IAppBridgeMessage.js +12 -0
- package/dist/core/bridge/index.d.ts +2 -1
- package/dist/core/bridge/index.js +2 -1
- package/dist/core/bridge/useAppBridge.d.ts +2 -8
- package/dist/core/bridge/useAppBridge.js +24 -15
- package/dist/core/index.d.ts +0 -2
- package/dist/core/index.js +0 -2
- package/dist/explore/components/header/Header.d.ts +14 -0
- package/dist/explore/components/{Header.js → header/Header.js} +10 -8
- package/dist/explore/components/header/HeaderActions.d.ts +8 -0
- package/dist/explore/components/header/HeaderActions.js +37 -0
- package/dist/explore/components/header/HeaderContainer.d.ts +2 -0
- package/dist/explore/components/header/HeaderContainer.js +15 -0
- package/dist/explore/components/header/HeaderContext.d.ts +7 -0
- package/dist/explore/components/header/HeaderContext.js +6 -0
- package/dist/explore/components/header/HeaderController.d.ts +39 -0
- package/dist/explore/components/header/HeaderController.js +100 -0
- package/dist/explore/components/header/HeaderOptions.d.ts +10 -0
- package/dist/explore/components/header/HeaderOptions.js +26 -0
- package/dist/explore/components/header/index.d.ts +5 -0
- package/dist/{core/contentful → explore/components/header}/index.js +5 -5
- package/dist/explore/components/header/useHeader.d.ts +2 -0
- package/dist/explore/components/header/useHeader.js +30 -0
- package/dist/explore/components/index.d.ts +2 -1
- package/dist/explore/components/index.js +2 -1
- package/dist/explore/components/pages/PagesExplorerLayout.d.ts +4 -0
- package/dist/explore/components/pages/PagesExplorerLayout.js +28 -0
- package/dist/explore/components/pages/index.d.ts +1 -0
- package/dist/{core/repository → explore/components/pages}/index.js +1 -4
- package/dist/explore/index.d.ts +1 -0
- package/dist/explore/index.js +1 -0
- package/dist/explore/screens/Dashboard.d.ts +3 -0
- package/dist/explore/screens/Dashboard.js +34 -1
- package/dist/explore/screens/PageExplorer.d.ts +10 -0
- package/dist/explore/screens/PageExplorer.js +121 -1
- package/dist/explore/screens/PagesExplorer.d.ts +7 -0
- package/dist/explore/screens/PagesExplorer.js +98 -0
- package/dist/explore/screens/index.d.ts +1 -1
- package/dist/explore/screens/index.js +1 -1
- package/dist/page/bridge/BlockChangedMessage.d.ts +25 -0
- package/dist/page/bridge/BlockChangedMessage.js +18 -0
- package/dist/page/bridge/PageBridgeHub.d.ts +8 -0
- package/dist/page/bridge/PageBridgeHub.js +51 -0
- package/dist/page/bridge/index.d.ts +2 -0
- package/dist/page/bridge/index.js +18 -0
- package/dist/page/domain/Page.d.ts +2 -2
- package/dist/page/domain/Page.js +2 -1
- package/dist/page/index.d.ts +1 -0
- package/dist/page/index.js +1 -0
- package/dist/page/repository/PageRepository.d.ts +3 -3
- package/dist/page/repository/PageRepository.js +25 -8
- package/dist/page/screens/PageEditor.js +14 -6
- package/package.json +5 -5
- package/dist/core/bridge/AppMessage.d.ts +0 -19
- package/dist/core/bridge/AppMessage.js +0 -19
- package/dist/core/contentful/Contentful.d.ts +0 -33
- package/dist/core/contentful/Contentful.js +0 -67
- package/dist/core/contentful/ContentfulAsset.d.ts +0 -23
- package/dist/core/contentful/ContentfulAsset.js +0 -89
- package/dist/core/contentful/ContentfulCollection.d.ts +0 -29
- package/dist/core/contentful/ContentfulCollection.js +0 -97
- package/dist/core/contentful/ContentfulPage.d.ts +0 -31
- package/dist/core/contentful/ContentfulPage.js +0 -84
- package/dist/core/contentful/ContentfulRefs.d.ts +0 -16
- package/dist/core/contentful/ContentfulRefs.js +0 -152
- package/dist/core/contentful/index.d.ts +0 -5
- package/dist/core/repository/CollectionSerializer.d.ts +0 -9
- package/dist/core/repository/CollectionSerializer.js +0 -41
- package/dist/core/repository/LocalCollectionRepository.d.ts +0 -27
- package/dist/core/repository/LocalCollectionRepository.js +0 -143
- package/dist/core/repository/LocalPageRepository.d.ts +0 -16
- package/dist/core/repository/LocalPageRepository.js +0 -153
- package/dist/core/repository/PageSerializer.d.ts +0 -9
- package/dist/core/repository/PageSerializer.js +0 -48
- package/dist/core/repository/RemoteCollectionRepository.d.ts +0 -19
- package/dist/core/repository/RemoteCollectionRepository.js +0 -236
- package/dist/core/repository/RemotePageRepository.d.ts +0 -14
- package/dist/core/repository/RemotePageRepository.js +0 -113
- package/dist/core/repository/index.d.ts +0 -4
- package/dist/explore/components/Header.d.ts +0 -26
- package/dist/explore/screens/SiteExplorer.d.ts +0 -1
- package/dist/explore/screens/SiteExplorer.js +0 -24
|
@@ -1,152 +0,0 @@
|
|
|
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.ContentfulRefs = void 0;
|
|
15
|
-
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
|
-
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
17
|
-
const ContentfulAsset_1 = require("./ContentfulAsset");
|
|
18
|
-
const ContentfulCollection_1 = require("./ContentfulCollection");
|
|
19
|
-
const ContentfulPage_1 = require("./ContentfulPage");
|
|
20
|
-
// namespace
|
|
21
|
-
var ContentfulRefs;
|
|
22
|
-
(function (ContentfulRefs) {
|
|
23
|
-
function find(data) {
|
|
24
|
-
// prepare sets
|
|
25
|
-
const assets = new Set();
|
|
26
|
-
const pages = new Set();
|
|
27
|
-
const collections = new Set();
|
|
28
|
-
// extract actual refs
|
|
29
|
-
funnel_core_1.ObjectUtils.walk(data, ({ value }) => {
|
|
30
|
-
// track assets
|
|
31
|
-
if (funnel_core_1.Schema.Asset.filter(value)) {
|
|
32
|
-
// track file (if it's real)
|
|
33
|
-
const assetId = funnel_core_1.Schema.Asset.getId(value);
|
|
34
|
-
if (assetId) {
|
|
35
|
-
assets.add(assetId);
|
|
36
|
-
}
|
|
37
|
-
// don't recurse
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
// track page links
|
|
41
|
-
else if (funnel_core_1.Schema.Field.Data.InternalLink.filter(value)) {
|
|
42
|
-
// track page (only if the id's real)
|
|
43
|
-
const pageId = funnel_core_1.Schema.Field.Data.InternalLink.getId(value);
|
|
44
|
-
if (pageId && pageId !== funnel_core_1.Schema.Page.Id.draft) {
|
|
45
|
-
pages.add(pageId);
|
|
46
|
-
}
|
|
47
|
-
// don't recurse
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
// transform collection refs
|
|
51
|
-
else if (funnel_core_1.Schema.Field.Data.Collection.Ref.filter(value)) {
|
|
52
|
-
// track collection (only if the id's real)
|
|
53
|
-
const collectionId = funnel_core_1.Schema.Field.Data.Collection.Ref.getId(value);
|
|
54
|
-
if (collectionId && collectionId !== funnel_core_1.Schema.Collection.Id.draft) {
|
|
55
|
-
collections.add(collectionId);
|
|
56
|
-
}
|
|
57
|
-
// don't recurse
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
// transform page refs
|
|
61
|
-
else if (funnel_core_1.Schema.Field.Data.Page.filter(value)) {
|
|
62
|
-
// track page (only if the id's real)
|
|
63
|
-
const pageId = funnel_core_1.Schema.Field.Data.Page.getId(value);
|
|
64
|
-
if (pageId && pageId !== funnel_core_1.Schema.Page.Id.draft) {
|
|
65
|
-
pages.add(pageId);
|
|
66
|
-
}
|
|
67
|
-
// don't recurse
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
// otherwise recurse deeper
|
|
71
|
-
else {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
// return refs
|
|
76
|
-
return {
|
|
77
|
-
assets,
|
|
78
|
-
pages,
|
|
79
|
-
collections
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
ContentfulRefs.find = find;
|
|
83
|
-
function serialize(refs, locale) {
|
|
84
|
-
var _a, _b, _c, _d;
|
|
85
|
-
// create empty refs
|
|
86
|
-
const assets = [];
|
|
87
|
-
const pages = [];
|
|
88
|
-
const collections = [];
|
|
89
|
-
// loop over references and serialize
|
|
90
|
-
const { Entry: entries = [], Asset: files = [] } = (_a = refs.includes) !== null && _a !== void 0 ? _a : {};
|
|
91
|
-
for (const entry of entries) {
|
|
92
|
-
switch (entry.sys.contentType.sys.id) {
|
|
93
|
-
// asset
|
|
94
|
-
case ContentfulAsset_1.ContentfulAsset.contentTypeId: {
|
|
95
|
-
// try to find file
|
|
96
|
-
const fileId = entry.fields.media[locale].sys.id;
|
|
97
|
-
const file = files.find(file => file.sys.id === fileId);
|
|
98
|
-
if (!file) {
|
|
99
|
-
throw new funnel_core_1.NotFoundError(`cannot find Contentful media "${fileId}" for asset "${entry.sys.id}"`);
|
|
100
|
-
}
|
|
101
|
-
console.debug('[ContentfulRefs/serialize] parsing asset', { entry, file });
|
|
102
|
-
assets.push({
|
|
103
|
-
__root: 'asset',
|
|
104
|
-
type: 'asset',
|
|
105
|
-
value: {
|
|
106
|
-
id: entry.sys.id,
|
|
107
|
-
name: entry.fields.name[locale],
|
|
108
|
-
description: (_d = (_b = entry.fields.description[locale]) !== null && _b !== void 0 ? _b : (_c = file.fields.description) === null || _c === void 0 ? void 0 : _c[locale]) !== null && _d !== void 0 ? _d : undefined,
|
|
109
|
-
type: entry.fields.type[locale],
|
|
110
|
-
brand: entry.fields.brand[locale],
|
|
111
|
-
scope: entry.fields.scope[locale],
|
|
112
|
-
tags: [],
|
|
113
|
-
url: 'https:' + file.fields.file[locale].url,
|
|
114
|
-
size: entry.fields.size[locale],
|
|
115
|
-
metadata: entry.fields.metadata[locale]
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
// page
|
|
121
|
-
case ContentfulPage_1.ContentfulPage.contentTypeId: {
|
|
122
|
-
// convert to link and get template
|
|
123
|
-
const pageEntry = entry;
|
|
124
|
-
const _e = ContentfulPage_1.ContentfulPage.serializeRemoteLink(pageEntry, locale), { type, tags } = _e, data = __rest(_e, ["type", "tags"]);
|
|
125
|
-
const template = funnel_core_1.Schema.Site.getPage(type, data.region);
|
|
126
|
-
// push link
|
|
127
|
-
pages.push(Object.assign({ template, tags: components_1.TagSerializer.deserializeTags({
|
|
128
|
-
groups: template.tags,
|
|
129
|
-
tagsData: tags
|
|
130
|
-
}) }, data));
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
// collection
|
|
134
|
-
case ContentfulCollection_1.ContentfulCollection.contentTypeId: {
|
|
135
|
-
// convert to link and get template
|
|
136
|
-
const collectionEntry = entry;
|
|
137
|
-
const data = ContentfulCollection_1.ContentfulCollection.serializeRemote(collectionEntry, locale);
|
|
138
|
-
// push data
|
|
139
|
-
collections.push(data);
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// return
|
|
145
|
-
return {
|
|
146
|
-
assets,
|
|
147
|
-
pages,
|
|
148
|
-
collections
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
ContentfulRefs.serialize = serialize;
|
|
152
|
-
})(ContentfulRefs || (exports.ContentfulRefs = ContentfulRefs = {}));
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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 = {}));
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
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 = {}));
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import { EventBus, Schema } from '@nascentdigital/funnel-core';
|
|
2
|
-
import { Page } from '../../page/domain';
|
|
3
|
-
export declare namespace PageSerializer {
|
|
4
|
-
type DeserializePageArgs = {
|
|
5
|
-
data: Schema.Page.Data;
|
|
6
|
-
eventBus: EventBus;
|
|
7
|
-
};
|
|
8
|
-
function deserializePage({ data, eventBus }: DeserializePageArgs): Page;
|
|
9
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
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.PageSerializer = 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("../../page/domain");
|
|
18
|
-
// namespace
|
|
19
|
-
var PageSerializer;
|
|
20
|
-
(function (PageSerializer) {
|
|
21
|
-
function deserializePage({ data, eventBus }) {
|
|
22
|
-
// destructure
|
|
23
|
-
const { snapshot, discover, content, tags } = data, dataRest = __rest(data
|
|
24
|
-
// determine latest snapshot (if any)
|
|
25
|
-
, ["snapshot", "discover", "content", "tags"]);
|
|
26
|
-
// determine latest snapshot (if any)
|
|
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({
|
|
38
|
-
key,
|
|
39
|
-
schema: schema.unwrap(),
|
|
40
|
-
eventBus,
|
|
41
|
-
content: content[key],
|
|
42
|
-
snapshot: contentSnapshot[key],
|
|
43
|
-
})), eventBus,
|
|
44
|
-
// references get hydrated from remote page repository
|
|
45
|
-
files: [], pages: [], collections: [] }));
|
|
46
|
-
}
|
|
47
|
-
PageSerializer.deserializePage = deserializePage;
|
|
48
|
-
})(PageSerializer || (exports.PageSerializer = PageSerializer = {}));
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|