@nascentdigital/funnel-editor-contentful 5.0.1 → 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 +11 -9
- package/dist/EditorPageRouter.d.ts +1 -0
- package/dist/EditorPageRouter.js +34 -0
- package/dist/EditorPageRoutes.d.ts +1 -0
- package/dist/EditorPageRoutes.js +16 -0
- package/dist/EntryEditor.js +30 -29
- package/dist/EntrySidebar.js +26 -5
- package/dist/NotFound.d.ts +1 -0
- package/dist/NotFound.js +18 -0
- package/dist/asset/index.d.ts +1 -0
- package/dist/{core/api → asset}/index.js +1 -3
- package/dist/{core → asset}/repository/AssetRepository.d.ts +11 -3
- package/dist/{core → asset}/repository/AssetRepository.js +6 -5
- package/dist/asset/repository/index.d.ts +1 -0
- package/dist/{core → asset}/repository/index.js +0 -4
- package/dist/collection/controller/{LocalCollectionController.d.ts → ContentfulCollectionController.d.ts} +17 -11
- 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 -4
- package/dist/collection/controller/index.js +3 -4
- package/dist/collection/controller/useContentfulCollectionController.d.ts +2 -0
- package/dist/collection/controller/useContentfulCollectionController.js +8 -0
- package/dist/{core → collection}/domain/Collection.d.ts +11 -2
- package/dist/{core → collection}/domain/Collection.js +76 -0
- package/dist/{core → collection}/domain/index.d.ts +0 -1
- package/dist/{core → collection}/domain/index.js +0 -1
- package/dist/collection/index.d.ts +1 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/repository/CollectionRepository.d.ts +49 -0
- package/dist/collection/repository/CollectionRepository.js +223 -0
- package/dist/collection/repository/index.d.ts +1 -0
- package/dist/{core/contentful → collection/repository}/index.js +1 -5
- package/dist/collection/screens/CollectionEditor.js +23 -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/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/index.d.ts +1 -4
- package/dist/core/index.js +1 -4
- package/dist/explore/components/header/Header.d.ts +14 -0
- package/dist/explore/components/header/Header.js +33 -0
- 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/{core/api/EditorApiContext.js → explore/components/header/HeaderContext.js} +2 -2
- 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/explore/components/header/index.js +21 -0
- 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 -0
- package/dist/explore/components/index.js +18 -0
- 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/explore/components/pages/index.js +17 -0
- package/dist/explore/index.d.ts +2 -0
- package/dist/explore/index.js +18 -0
- package/dist/explore/screens/Dashboard.d.ts +4 -0
- package/dist/explore/screens/Dashboard.js +55 -0
- package/dist/explore/screens/PageExplorer.d.ts +11 -0
- package/dist/explore/screens/PageExplorer.js +129 -0
- package/dist/explore/screens/PagesExplorer.d.ts +7 -0
- package/dist/explore/screens/PagesExplorer.js +98 -0
- package/dist/explore/screens/index.d.ts +3 -0
- package/dist/explore/screens/index.js +19 -0
- 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/controller/{LocalPageController.d.ts → ContentfulPageController.d.ts} +15 -9
- 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 -3
- package/dist/page/controller/index.js +3 -3
- 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 +23 -12
- package/dist/{core → page}/domain/Page.js +139 -0
- package/dist/page/domain/index.d.ts +1 -0
- package/dist/page/domain/index.js +17 -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 +241 -0
- package/dist/page/repository/index.d.ts +1 -0
- package/dist/page/repository/index.js +17 -0
- package/dist/page/screens/PageEditor.js +36 -12
- package/package.json +9 -5
- package/dist/collection/controller/LocalCollectionController.js +0 -200
- package/dist/collection/controller/LocalCollectionControllerContainer.d.ts +0 -8
- package/dist/collection/controller/LocalCollectionControllerContainer.js +0 -36
- package/dist/collection/controller/LocalCollectionControllerContext.d.ts +0 -7
- package/dist/collection/controller/LocalCollectionControllerContext.js +0 -6
- package/dist/collection/controller/useLocalCollectionController.d.ts +0 -2
- package/dist/collection/controller/useLocalCollectionController.js +0 -10
- 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/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/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 -88
- 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 -47
- 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 -5
- package/dist/page/controller/LocalPageController.js +0 -190
- package/dist/page/controller/LocalPageControllerContainer.d.ts +0 -8
- package/dist/page/controller/LocalPageControllerContainer.js +0 -36
- package/dist/page/controller/LocalPageControllerContext.d.ts +0 -7
- package/dist/page/controller/LocalPageControllerContext.js +0 -6
- package/dist/page/controller/useLocalPageController.d.ts +0 -2
- package/dist/page/controller/useLocalPageController.js +0 -10
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContentfulCollectionController = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
// class
|
|
8
|
+
class ContentfulCollectionController {
|
|
9
|
+
constructor(args) {
|
|
10
|
+
// initialize instance variables
|
|
11
|
+
this.collectionRepository = args.collectionRepository;
|
|
12
|
+
this._eventBus = new funnel_core_1.EventBus();
|
|
13
|
+
this._state = 'uninitialized';
|
|
14
|
+
}
|
|
15
|
+
get events$() {
|
|
16
|
+
return this._eventBus.events$
|
|
17
|
+
.pipe((0, rxjs_1.filter)(e => components_1.ICollectionController.Event.filter(e) || components_1.ICollection.Event.filter(e)));
|
|
18
|
+
}
|
|
19
|
+
get state() {
|
|
20
|
+
return this._state;
|
|
21
|
+
}
|
|
22
|
+
set state(value) {
|
|
23
|
+
// skip if unchanged
|
|
24
|
+
if (this._state === value) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// or update
|
|
28
|
+
this._state = value;
|
|
29
|
+
// raise event
|
|
30
|
+
this.raiseEvent('state.changed');
|
|
31
|
+
// process queues if ready (might be noop)
|
|
32
|
+
if (value === 'ready') {
|
|
33
|
+
this.processQueues().catch(console.error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get ready() {
|
|
37
|
+
const { _state } = this;
|
|
38
|
+
return _state !== 'uninitialized' && _state !== 'initializing';
|
|
39
|
+
}
|
|
40
|
+
get languages() {
|
|
41
|
+
const brand = funnel_core_1.AppConfig.brandConfig();
|
|
42
|
+
return funnel_core_1.RegionsConfig.getLanguages(brand.regionalization);
|
|
43
|
+
}
|
|
44
|
+
get collectionSys() {
|
|
45
|
+
return this._collectionSys;
|
|
46
|
+
}
|
|
47
|
+
set collectionSys(sys) {
|
|
48
|
+
this._collectionSys = sys;
|
|
49
|
+
}
|
|
50
|
+
get collectionGroup() {
|
|
51
|
+
return this._collectionGroup;
|
|
52
|
+
}
|
|
53
|
+
set collectionGroup(collectionGroup) {
|
|
54
|
+
// skip if group is the same
|
|
55
|
+
if (this._collectionGroup === collectionGroup) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// update group
|
|
59
|
+
this._collectionGroup = collectionGroup;
|
|
60
|
+
// raise event
|
|
61
|
+
this.raiseEvent('collectionGroup.changed');
|
|
62
|
+
}
|
|
63
|
+
get collection() {
|
|
64
|
+
return this._collection;
|
|
65
|
+
}
|
|
66
|
+
set collection(collection) {
|
|
67
|
+
// skip if collection is the same
|
|
68
|
+
if (this._collection === collection) {
|
|
69
|
+
console.debug('[ContentfulCollectionController] ignoring collection change for', collection);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// unbind previous subscription (if any)
|
|
73
|
+
if (this._collectionSubscription) {
|
|
74
|
+
this._collectionSubscription.unsubscribe();
|
|
75
|
+
delete this._collectionSubscription;
|
|
76
|
+
}
|
|
77
|
+
console.debug('[ContentfulCollectionController] updating to new collection', collection);
|
|
78
|
+
// update collection
|
|
79
|
+
this._collection = collection;
|
|
80
|
+
// subscribe to collection changes
|
|
81
|
+
if (collection) {
|
|
82
|
+
this._collectionSubscription = collection.events$
|
|
83
|
+
.pipe((0, rxjs_1.filter)(e => {
|
|
84
|
+
// handle collection events
|
|
85
|
+
if (components_1.ICollection.Event.filter(e)) {
|
|
86
|
+
return e.type === 'modified';
|
|
87
|
+
}
|
|
88
|
+
// or item/object/list events
|
|
89
|
+
else if (components_1.Item.Event.filter(e)
|
|
90
|
+
|| components_1.Item.Event.filter(e)
|
|
91
|
+
|| funnel_core_1.ObjectField.Event.filter(e)
|
|
92
|
+
|| funnel_core_1.FieldList.Event.filter(e)) {
|
|
93
|
+
return e.type === 'changed';
|
|
94
|
+
}
|
|
95
|
+
// or field
|
|
96
|
+
else {
|
|
97
|
+
return funnel_core_1.Field.Event.filter(e) && (e.type === 'changed' || e.type === 'reset');
|
|
98
|
+
}
|
|
99
|
+
}), (0, rxjs_1.debounce)(e => {
|
|
100
|
+
if ((components_1.ICollection.Event.filter(e) && e.type === 'modified')
|
|
101
|
+
|| components_1.Item.Event.filter(e)
|
|
102
|
+
|| funnel_core_1.FieldList.Event.filter(e)
|
|
103
|
+
|| (funnel_core_1.Field.Event.filter(e) && e.field.isComposite)) {
|
|
104
|
+
return (0, rxjs_1.interval)(0);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return (0, rxjs_1.interval)(2000);
|
|
108
|
+
}
|
|
109
|
+
}))
|
|
110
|
+
.subscribe(async () => {
|
|
111
|
+
if (collection.modified && this._collection === collection) {
|
|
112
|
+
await this.save(collection);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// raise event
|
|
117
|
+
this.raiseEvent('collection.changed');
|
|
118
|
+
}
|
|
119
|
+
async sync(updatedSys) {
|
|
120
|
+
// skip if there's no active collection/sys
|
|
121
|
+
const { collection, collectionSys, state, collectionRepository } = this;
|
|
122
|
+
if (!collection || !collectionSys) {
|
|
123
|
+
console.warn('[ContentfulCollectionController/sync] ignoring update before initial load');
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// or skip if collection version is unchanged
|
|
127
|
+
else if (collection.id === updatedSys.id && collectionSys.version >= updatedSys.version) {
|
|
128
|
+
console.debug('[ContentfulCollectionController/sync] ignoring update - current version is fresh');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// or ignore if booting up
|
|
132
|
+
else if (state === 'uninitialized' || state === 'initializing' || state === 'loading') {
|
|
133
|
+
console.debug('[ContentfulCollectionController/sync] ignoring sync while loading');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// or queue if saving
|
|
137
|
+
else if (this.state === 'saving') {
|
|
138
|
+
console.debug('[ContentfulCollectionController/sync] queueing collection sync - updated while saving');
|
|
139
|
+
this._queuedSync = updatedSys;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// try to sync
|
|
143
|
+
try {
|
|
144
|
+
console.debug('[ContentfulCollectionController/sync] starting sync');
|
|
145
|
+
// update state
|
|
146
|
+
this.state = 'loading';
|
|
147
|
+
// perform sync
|
|
148
|
+
const result = await collectionRepository.sync({ collection, sys: updatedSys });
|
|
149
|
+
// update sys
|
|
150
|
+
this.collectionSys = result.sys;
|
|
151
|
+
// update collection (if unchanged)
|
|
152
|
+
if (this.collection !== result.collection) {
|
|
153
|
+
this.collection = result.collection;
|
|
154
|
+
}
|
|
155
|
+
// update summary (if any)
|
|
156
|
+
if (result.collectionGroup) {
|
|
157
|
+
this.collectionGroup = result.collectionGroup;
|
|
158
|
+
}
|
|
159
|
+
console.debug('[ContentfulCollectionController/sync] sync complete');
|
|
160
|
+
// clear state
|
|
161
|
+
this.state = 'ready';
|
|
162
|
+
}
|
|
163
|
+
// catch error
|
|
164
|
+
catch (e) {
|
|
165
|
+
console.error('[ContentfulCollectionController/sync] sync failed', e);
|
|
166
|
+
this.state = 'error';
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async load() {
|
|
170
|
+
// mark as loading (or initialing if loading for first time)
|
|
171
|
+
this.state = this._state === 'uninitialized'
|
|
172
|
+
? 'initializing'
|
|
173
|
+
: 'loading';
|
|
174
|
+
// try to fetch collection
|
|
175
|
+
try {
|
|
176
|
+
// load collection
|
|
177
|
+
const { collectionGroup, collection, sys } = await this.collectionRepository.load();
|
|
178
|
+
// set collection/group
|
|
179
|
+
this.collectionGroup = collectionGroup;
|
|
180
|
+
this.collection = collection;
|
|
181
|
+
this._collectionSys = sys;
|
|
182
|
+
// update state
|
|
183
|
+
this.state = 'ready';
|
|
184
|
+
}
|
|
185
|
+
// handle load error
|
|
186
|
+
catch (e) {
|
|
187
|
+
console.error('[ContentfulCollectionController] failed to load collection', e);
|
|
188
|
+
// set error state
|
|
189
|
+
this.state = 'error';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async createLanguage(target) {
|
|
193
|
+
throw new funnel_core_1.NotImplementedError();
|
|
194
|
+
}
|
|
195
|
+
async unpublish() {
|
|
196
|
+
throw new funnel_core_1.NotImplementedError();
|
|
197
|
+
}
|
|
198
|
+
async save(collection) {
|
|
199
|
+
// ignore if not ready
|
|
200
|
+
if (this._state !== 'ready') {
|
|
201
|
+
console.debug(`[ContentfulCollectionController/save] queuing save while in "${this._state}" state`);
|
|
202
|
+
this._queuedSave = collection;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
// clear save if queued
|
|
206
|
+
delete this._queuedSave;
|
|
207
|
+
// skip if collection isn't modified
|
|
208
|
+
if (!collection.modified) {
|
|
209
|
+
console.debug('[ContentfulCollectionController/save] ignore unmodified collection');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// try to save collection
|
|
213
|
+
try {
|
|
214
|
+
console.debug('[ContentfulCollectionController/save] starting save');
|
|
215
|
+
// mark as syncing
|
|
216
|
+
collection.syncing = true;
|
|
217
|
+
// update state
|
|
218
|
+
this.state = 'saving';
|
|
219
|
+
// save page
|
|
220
|
+
this.collection = await this.collectionRepository.save(collection);
|
|
221
|
+
// update state
|
|
222
|
+
this.state = 'ready';
|
|
223
|
+
console.debug('[ContentfulCollectionController/save] save finished');
|
|
224
|
+
}
|
|
225
|
+
// handle error
|
|
226
|
+
catch (e) {
|
|
227
|
+
console.error('[ContentfulCollectionController/save] save failed', e);
|
|
228
|
+
// update state
|
|
229
|
+
this.state = 'error';
|
|
230
|
+
}
|
|
231
|
+
// complete
|
|
232
|
+
finally {
|
|
233
|
+
collection.syncing = false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async reload() {
|
|
237
|
+
throw new funnel_core_1.NotImplementedError();
|
|
238
|
+
}
|
|
239
|
+
async processQueues() {
|
|
240
|
+
// try to save (if queued)
|
|
241
|
+
const { _queuedSave, _collection } = this;
|
|
242
|
+
if (_queuedSave) {
|
|
243
|
+
// nuke if collection differs (keep going afterward)
|
|
244
|
+
if (_collection !== _queuedSave) {
|
|
245
|
+
console.debug('[ContentfulCollectionController/processQueues] ignoring queued save for old page');
|
|
246
|
+
delete this._queuedSave;
|
|
247
|
+
}
|
|
248
|
+
// otherwise, try to save
|
|
249
|
+
else {
|
|
250
|
+
console.debug('[ContentfulCollectionController/processQueues] restarting queued save');
|
|
251
|
+
// save
|
|
252
|
+
this.save(_collection).catch(console.error);
|
|
253
|
+
// stop processing
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// try to sync
|
|
258
|
+
const { _queuedSync, _collectionSys } = this;
|
|
259
|
+
if (_queuedSync) {
|
|
260
|
+
// clear sync
|
|
261
|
+
delete this._queuedSync;
|
|
262
|
+
// reload if entity is different
|
|
263
|
+
if (_queuedSync.id !== (_collectionSys === null || _collectionSys === void 0 ? void 0 : _collectionSys.id)) {
|
|
264
|
+
console.debug('[ContentfulCollectionController/processQueues] reloading on entity change');
|
|
265
|
+
this.load().catch(console.error);
|
|
266
|
+
}
|
|
267
|
+
// otherwise, try to sync
|
|
268
|
+
else {
|
|
269
|
+
console.debug('[ContentfulCollectionController/processQueues] retrying sync');
|
|
270
|
+
this.sync(_queuedSync).catch(console.error);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
raiseEvent(type) {
|
|
275
|
+
this._eventBus.publish(components_1.ICollectionController.Event.create({ type, controller: this }));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
exports.ContentfulCollectionController = ContentfulCollectionController;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
export declare function ContentfulCollectionControllerContainer({ children }: ContentfulCollectionControllerContainer.Props): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare namespace ContentfulCollectionControllerContainer {
|
|
4
|
+
type Props = PropsWithChildren;
|
|
5
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContentfulCollectionControllerContainer = ContentfulCollectionControllerContainer;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_apps_toolkit_1 = require("@contentful/react-apps-toolkit");
|
|
6
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const ContentfulCollectionController_1 = require("./ContentfulCollectionController");
|
|
9
|
+
// container
|
|
10
|
+
function ContentfulCollectionControllerContainer({ children }) {
|
|
11
|
+
// bind context
|
|
12
|
+
const collectionRepository = (0, components_1.useCollectionRepository)();
|
|
13
|
+
const sdk = (0, react_apps_toolkit_1.useSDK)();
|
|
14
|
+
const context = (0, react_1.useMemo)(() => ({
|
|
15
|
+
controller: new ContentfulCollectionController_1.ContentfulCollectionController({ collectionRepository })
|
|
16
|
+
}), [collectionRepository]);
|
|
17
|
+
// list to collection changes
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
// get controller
|
|
20
|
+
const { controller } = context;
|
|
21
|
+
// sync on change
|
|
22
|
+
sdk.entry.onSysChanged(sys => {
|
|
23
|
+
controller.sync(sys).catch(console.error);
|
|
24
|
+
});
|
|
25
|
+
}, [sdk, context]);
|
|
26
|
+
// render
|
|
27
|
+
return ((0, jsx_runtime_1.jsx)(components_1.CollectionControllerContext.Provider, { value: context, children: children }));
|
|
28
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './useLocalCollectionController';
|
|
1
|
+
export * from './ContentfulCollectionController';
|
|
2
|
+
export * from './ContentfulCollectionControllerContainer';
|
|
3
|
+
export * from './useContentfulCollectionController';
|
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./useLocalCollectionController"), exports);
|
|
17
|
+
__exportStar(require("./ContentfulCollectionController"), exports);
|
|
18
|
+
__exportStar(require("./ContentfulCollectionControllerContainer"), exports);
|
|
19
|
+
__exportStar(require("./useContentfulCollectionController"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useContentfulCollectionController = useContentfulCollectionController;
|
|
4
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
5
|
+
// hook
|
|
6
|
+
function useContentfulCollectionController() {
|
|
7
|
+
return (0, components_1.useCollectionController)();
|
|
8
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { AssetClient } from '@nascentdigital/funnel-cms';
|
|
1
|
+
import { AssetClient, CollectionClient } from '@nascentdigital/funnel-cms';
|
|
2
|
+
import { ContentfulCollectionData, ContentfulData } from '@nascentdigital/funnel-cms/contentful';
|
|
2
3
|
import { EventBus, Field, FieldModel, Language, Schema } from '@nascentdigital/funnel-core';
|
|
3
|
-
import { Asset, CollectionGroup, ICollection, IPage } from '@nascentdigital/funnel-editor/components';
|
|
4
|
+
import { Asset, CollectionFieldProxy, CollectionGroup, ICollection, IPage } from '@nascentdigital/funnel-editor/components';
|
|
4
5
|
import { Observable } from 'rxjs';
|
|
5
6
|
export declare class Collection implements ICollection {
|
|
6
7
|
readonly template: Schema.Collection;
|
|
@@ -27,6 +28,7 @@ export declare class Collection implements ICollection {
|
|
|
27
28
|
private _initialErrors;
|
|
28
29
|
private _syncing;
|
|
29
30
|
private _savingOn?;
|
|
31
|
+
readonly references: Readonly<ContentfulData.References>;
|
|
30
32
|
constructor(args: Collection.ConstructorArgs);
|
|
31
33
|
get events$(): Observable<ICollection.Events>;
|
|
32
34
|
get stable$(): Observable<boolean>;
|
|
@@ -91,9 +93,16 @@ export declare namespace Collection {
|
|
|
91
93
|
createdOn: number;
|
|
92
94
|
updatedOn: number;
|
|
93
95
|
publishedOn?: number;
|
|
96
|
+
references: ContentfulData.References;
|
|
94
97
|
};
|
|
95
98
|
type WithGroup = {
|
|
96
99
|
group: CollectionGroup;
|
|
97
100
|
collection?: Collection;
|
|
98
101
|
};
|
|
102
|
+
type FromSchemaData = {
|
|
103
|
+
data: ContentfulCollectionData.ForSchema;
|
|
104
|
+
references?: Schema.Collection.References;
|
|
105
|
+
};
|
|
106
|
+
function fromSchemaData({ data, references }: FromSchemaData): Collection;
|
|
107
|
+
function toUpdates(collection: Collection | CollectionFieldProxy, savables: ICollection.Savable[]): CollectionClient.Update.Args;
|
|
99
108
|
}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.Collection = void 0;
|
|
15
|
+
const contentful_1 = require("@nascentdigital/funnel-cms/contentful");
|
|
4
16
|
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
17
|
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
6
18
|
const rxjs_1 = require("rxjs");
|
|
@@ -41,6 +53,7 @@ class Collection {
|
|
|
41
53
|
this.createdOn = args.createdOn;
|
|
42
54
|
this._updatedOn = args.updatedOn;
|
|
43
55
|
this.publishedOn = args.publishedOn;
|
|
56
|
+
this.references = args.references;
|
|
44
57
|
this._state = args.state;
|
|
45
58
|
this._initialErrors = args.errors;
|
|
46
59
|
this._syncing = false;
|
|
@@ -309,3 +322,66 @@ class Collection {
|
|
|
309
322
|
}
|
|
310
323
|
}
|
|
311
324
|
exports.Collection = Collection;
|
|
325
|
+
// extension
|
|
326
|
+
(function (Collection) {
|
|
327
|
+
function fromSchemaData({ data, references }) {
|
|
328
|
+
// setup
|
|
329
|
+
const { snapshot, fields, tags } = data, collectionArgs = __rest(data, ["snapshot", "fields", "tags"]);
|
|
330
|
+
const { files = {}, collections = {} } = references !== null && references !== void 0 ? references : {};
|
|
331
|
+
const { fields: fieldsSnapshot = {} } = snapshot !== null && snapshot !== void 0 ? snapshot : {};
|
|
332
|
+
const template = funnel_core_1.Schema.Site.getCollection(data.type);
|
|
333
|
+
const eventBus = new funnel_core_1.EventBus();
|
|
334
|
+
// create collection
|
|
335
|
+
return new Collection(Object.assign(Object.assign({}, collectionArgs), { eventBus,
|
|
336
|
+
template, tags: components_1.TagSerializer.deserializeTags({
|
|
337
|
+
groups: template.tags,
|
|
338
|
+
tagsData: tags !== null && tags !== void 0 ? tags : []
|
|
339
|
+
}), fields: Object.entries(template.editableFields).map(([id, schema]) => components_1.FieldSerializer.deserializeField({
|
|
340
|
+
id,
|
|
341
|
+
eventBus,
|
|
342
|
+
schema,
|
|
343
|
+
content: fields[id],
|
|
344
|
+
snapshot: fieldsSnapshot[id]
|
|
345
|
+
})), files: Object.values(files), collections: Object.values(collections), references: contentful_1.ContentfulData.findReferences(fields) }));
|
|
346
|
+
}
|
|
347
|
+
Collection.fromSchemaData = fromSchemaData;
|
|
348
|
+
function toUpdates(collection, savables) {
|
|
349
|
+
// add name updates
|
|
350
|
+
const { id, nameField, name, initialTags, tags, fields, initialErrors, valid } = collection;
|
|
351
|
+
const updates = [];
|
|
352
|
+
if (nameField.modified) {
|
|
353
|
+
updates.push({
|
|
354
|
+
type: 'collection',
|
|
355
|
+
property: 'name',
|
|
356
|
+
value: name
|
|
357
|
+
});
|
|
358
|
+
// track change
|
|
359
|
+
savables.push(nameField);
|
|
360
|
+
}
|
|
361
|
+
// add tag updates
|
|
362
|
+
if (initialTags.symmetricDifference(tags).size > 0) {
|
|
363
|
+
updates.push({
|
|
364
|
+
type: 'collection',
|
|
365
|
+
property: 'tags',
|
|
366
|
+
value: Array.from(tags).map(tag => tag.data)
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
// add errors updates
|
|
370
|
+
if (initialErrors !== !valid) {
|
|
371
|
+
updates.push({
|
|
372
|
+
type: 'collection',
|
|
373
|
+
property: 'errors',
|
|
374
|
+
value: !valid
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
// add fields
|
|
378
|
+
components_1.SerializeCollectionUpdate.serializeFieldsUpdate(updates, fields, ['fields'], savables);
|
|
379
|
+
// return updates
|
|
380
|
+
return {
|
|
381
|
+
id,
|
|
382
|
+
updates,
|
|
383
|
+
updatedOn: Date.now()
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
Collection.toUpdates = toUpdates;
|
|
387
|
+
})(Collection || (exports.Collection = Collection = {}));
|
package/dist/collection/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./screens"), exports);
|
|
18
18
|
__exportStar(require("./controller"), exports);
|
|
19
|
+
__exportStar(require("./repository"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EditorAppSDK, EntrySys, PageAppSDK } from '@contentful/app-sdk';
|
|
2
|
+
import { ContentfulContentClient } from '@nascentdigital/funnel-cms/contentful';
|
|
3
|
+
import { Schema } from '@nascentdigital/funnel-core';
|
|
4
|
+
import { CollectionFieldProxy, CollectionGroup, ICollection, ICollectionRepository } from '@nascentdigital/funnel-editor/components';
|
|
5
|
+
import { Collection } from '../domain';
|
|
6
|
+
export declare class CollectionRepository implements ICollectionRepository {
|
|
7
|
+
readonly sdk: EditorAppSDK | PageAppSDK;
|
|
8
|
+
readonly contentfulClient: ContentfulContentClient;
|
|
9
|
+
constructor(args: CollectionRepository.ConstructorArgs);
|
|
10
|
+
getOverview(args: ICollectionRepository.GetOverview.Args): Promise<ICollectionRepository.GetOverview.Result>;
|
|
11
|
+
getItems(args: ICollectionRepository.GetItems.Args): Promise<ICollectionRepository.GetItems.Result>;
|
|
12
|
+
get(args: ICollectionRepository.Get.Args): Promise<ICollectionRepository.Get.Result>;
|
|
13
|
+
create(args: ICollectionRepository.Create.Args): Promise<ICollectionRepository.Create.Result>;
|
|
14
|
+
createRaw(args: ICollectionRepository.CreateRaw.Args): Promise<ICollectionRepository.CreateRaw.Result>;
|
|
15
|
+
createLanguage(args: ICollectionRepository.CreateLang.Args): Promise<ICollectionRepository.CreateLang.Result>;
|
|
16
|
+
update(args: ICollectionRepository.Update.Args): Promise<ICollectionRepository.Update.Result>;
|
|
17
|
+
serializeUpdate(collection: ICollection | CollectionFieldProxy, savables: ICollection.Savable[]): ICollectionRepository.SerializeUpdates.Result;
|
|
18
|
+
load(sys?: EntrySys): Promise<CollectionRepository.Load.Result>;
|
|
19
|
+
save(collection: Collection): Promise<Collection>;
|
|
20
|
+
sync({ collection, sys }: CollectionRepository.Sync.Args): Promise<CollectionRepository.Sync.Result>;
|
|
21
|
+
unpublish(collection: ICollection): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare namespace CollectionRepository {
|
|
24
|
+
type ConstructorArgs = {
|
|
25
|
+
sdk: EditorAppSDK | PageAppSDK;
|
|
26
|
+
contentfulClient: ContentfulContentClient;
|
|
27
|
+
};
|
|
28
|
+
namespace Load {
|
|
29
|
+
type Args = {
|
|
30
|
+
collectionId?: Schema.Collection.Id;
|
|
31
|
+
};
|
|
32
|
+
type Result = {
|
|
33
|
+
collectionGroup: CollectionGroup;
|
|
34
|
+
collection: Collection;
|
|
35
|
+
sys: EntrySys;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
namespace Sync {
|
|
39
|
+
type Args = {
|
|
40
|
+
collection: Collection;
|
|
41
|
+
sys: EntrySys;
|
|
42
|
+
};
|
|
43
|
+
type Result = {
|
|
44
|
+
collectionGroup?: CollectionGroup;
|
|
45
|
+
collection: Collection;
|
|
46
|
+
sys: EntrySys;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|