@nascentdigital/funnel-editor-contentful 5.0.1 → 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/EditorApp.js +11 -9
- package/dist/EditorPageRouter.d.ts +1 -0
- package/dist/EditorPageRouter.js +40 -0
- package/dist/EntryEditor.js +30 -29
- package/dist/EntrySidebar.js +1 -1
- package/dist/asset/index.d.ts +1 -0
- package/dist/{core/api → asset}/index.js +1 -3
- package/dist/{core → asset}/repository/AssetRepository.js +3 -3
- package/dist/asset/repository/index.d.ts +1 -0
- package/dist/asset/repository/index.js +17 -0
- 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 +75 -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 +210 -0
- package/dist/collection/repository/index.d.ts +1 -0
- package/dist/collection/repository/index.js +17 -0
- package/dist/collection/screens/CollectionEditor.js +23 -6
- 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/ContentfulAsset.d.ts +3 -3
- package/dist/core/contentful/ContentfulAsset.js +5 -4
- package/dist/core/contentful/ContentfulCollection.d.ts +1 -1
- package/dist/core/contentful/ContentfulRefs.js +9 -9
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.js +1 -2
- package/dist/core/repository/CollectionSerializer.d.ts +1 -1
- package/dist/core/repository/CollectionSerializer.js +1 -1
- package/dist/core/repository/LocalCollectionRepository.d.ts +2 -2
- package/dist/core/repository/LocalPageRepository.d.ts +1 -1
- package/dist/core/repository/PageSerializer.d.ts +1 -1
- package/dist/core/repository/PageSerializer.js +2 -1
- package/dist/core/repository/RemoteCollectionRepository.d.ts +2 -2
- package/dist/core/repository/index.d.ts +0 -1
- package/dist/core/repository/index.js +0 -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/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 +22 -11
- package/dist/{core → page}/domain/Page.js +138 -0
- package/dist/page/domain/index.d.ts +1 -0
- package/dist/page/domain/index.js +17 -0
- package/dist/page/index.d.ts +2 -0
- package/dist/page/index.js +2 -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 +23 -7
- package/package.json +8 -4
- 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/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/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
- /package/dist/{core → asset}/repository/AssetRepository.d.ts +0 -0
package/dist/EditorApp.js
CHANGED
|
@@ -6,25 +6,27 @@ const app_sdk_1 = require("@contentful/app-sdk");
|
|
|
6
6
|
const react_apps_toolkit_1 = require("@contentful/react-apps-toolkit");
|
|
7
7
|
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
8
8
|
const core_1 = require("./core");
|
|
9
|
+
const EditorPageRouter_1 = require("./EditorPageRouter");
|
|
9
10
|
const EntryEditor_1 = require("./EntryEditor");
|
|
10
11
|
const EntrySidebar_1 = require("./EntrySidebar");
|
|
11
12
|
// editor
|
|
12
13
|
function EditorApp() {
|
|
13
|
-
// hooks
|
|
14
|
+
// bind hooks
|
|
14
15
|
const sdk = (0, react_apps_toolkit_1.useSDK)();
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// page
|
|
17
|
+
if (sdk.location.is(app_sdk_1.locations.LOCATION_PAGE)) {
|
|
18
|
+
return ((0, jsx_runtime_1.jsx)(components_1.AppStateContainer, { children: (0, jsx_runtime_1.jsx)(core_1.ContentfulClientContainer, { sdk: sdk, children: (0, jsx_runtime_1.jsx)(EditorPageRouter_1.EditorPageRouter, {}) }) }));
|
|
19
|
+
}
|
|
20
|
+
// entry
|
|
21
|
+
else if (sdk.location.is(app_sdk_1.locations.LOCATION_ENTRY_EDITOR)) {
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(components_1.AppStateContainer, { children: (0, jsx_runtime_1.jsx)(core_1.AppBridgeContainer, { children: (0, jsx_runtime_1.jsx)(core_1.ContentfulClientContainer, { sdk: sdk, children: (0, jsx_runtime_1.jsx)(EntryEditor_1.EntryEditor, {}) }) }) }));
|
|
19
23
|
}
|
|
20
24
|
// entry sidebar
|
|
21
25
|
else if (sdk.location.is(app_sdk_1.locations.LOCATION_ENTRY_SIDEBAR)) {
|
|
22
|
-
|
|
26
|
+
return ((0, jsx_runtime_1.jsx)(components_1.AppStateContainer, { children: (0, jsx_runtime_1.jsx)(core_1.AppBridgeContainer, { children: (0, jsx_runtime_1.jsx)(EntrySidebar_1.EntrySidebar, {}) }) }));
|
|
23
27
|
}
|
|
24
28
|
// fallback
|
|
25
29
|
else {
|
|
26
|
-
|
|
30
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: "Unsupported location" }));
|
|
27
31
|
}
|
|
28
|
-
// render
|
|
29
|
-
return ((0, jsx_runtime_1.jsx)(components_1.AppStateContainer, { children: (0, jsx_runtime_1.jsx)(core_1.AppBridgeContainer, { children: (0, jsx_runtime_1.jsx)(core_1.EditorApiContainer, { children: content }) }) }));
|
|
30
32
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function EditorPageRouter(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EditorPageRouter = EditorPageRouter;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_apps_toolkit_1 = require("@contentful/react-apps-toolkit");
|
|
6
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
7
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const react_router_1 = require("react-router");
|
|
10
|
+
const asset_1 = require("./asset");
|
|
11
|
+
const collection_1 = require("./collection");
|
|
12
|
+
const core_1 = require("./core");
|
|
13
|
+
const explore_1 = require("./explore");
|
|
14
|
+
const page_1 = require("./page");
|
|
15
|
+
// router
|
|
16
|
+
function EditorPageRouter() {
|
|
17
|
+
// bind props + hooks
|
|
18
|
+
const sdk = (0, react_apps_toolkit_1.useSDK)();
|
|
19
|
+
const contentfulClient = (0, core_1.useContentfulClient)();
|
|
20
|
+
const appState = (0, components_1.useAppState)();
|
|
21
|
+
const { regionalization } = funnel_core_1.AppConfig.brandConfig();
|
|
22
|
+
const region = funnel_core_1.RegionsConfig.getDefaultRegion(regionalization);
|
|
23
|
+
// create repositories
|
|
24
|
+
const { assetRepository, collectionRepository, pageRepository } = (0, react_1.useMemo)(() => ({
|
|
25
|
+
assetRepository: new asset_1.AssetRepository(sdk),
|
|
26
|
+
collectionRepository: new collection_1.CollectionRepository({ sdk, contentfulClient }),
|
|
27
|
+
pageRepository: new page_1.PageRepository({ sdk, contentfulClient })
|
|
28
|
+
}), [sdk, contentfulClient]);
|
|
29
|
+
// create contexts
|
|
30
|
+
const siteContext = (0, react_1.useMemo)(() => {
|
|
31
|
+
const site = new components_1.Site({ appState, repository: pageRepository, region });
|
|
32
|
+
return { site };
|
|
33
|
+
}, [appState, pageRepository, region]);
|
|
34
|
+
const collectionsContext = (0, react_1.useMemo)(() => {
|
|
35
|
+
const collections = new components_1.Collections({ appState, repository: collectionRepository });
|
|
36
|
+
return { collections };
|
|
37
|
+
}, [appState, collectionRepository]);
|
|
38
|
+
// render
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(react_router_1.BrowserRouter, { children: (0, jsx_runtime_1.jsx)(components_1.AssetRepositoryContext.Provider, { value: assetRepository, children: (0, jsx_runtime_1.jsx)(components_1.CollectionRepositoryContext.Provider, { value: collectionRepository, children: (0, jsx_runtime_1.jsx)(components_1.PageRepositoryContext.Provider, { value: pageRepository, children: (0, jsx_runtime_1.jsx)(components_1.SiteContext.Provider, { value: siteContext, children: (0, jsx_runtime_1.jsx)(components_1.CollectionsContext.Provider, { value: collectionsContext, children: (0, jsx_runtime_1.jsx)(components_1.DialogContainer, { children: (0, jsx_runtime_1.jsx)(components_1.CenterSheetContainer, { children: (0, jsx_runtime_1.jsx)(components_1.SplashContainer, { message: "Initializing...", children: (0, jsx_runtime_1.jsx)(react_router_1.Routes, { children: (0, jsx_runtime_1.jsxs)(react_router_1.Route, { path: "/contentful", children: [(0, jsx_runtime_1.jsx)(react_router_1.Route, { index: true, element: (0, jsx_runtime_1.jsx)(explore_1.Dashboard, {}) }), (0, jsx_runtime_1.jsxs)(react_router_1.Route, { path: "pages", children: [(0, jsx_runtime_1.jsx)(react_router_1.Route, { index: true, element: (0, jsx_runtime_1.jsx)(explore_1.SiteExplorer, {}) }), (0, jsx_runtime_1.jsx)(react_router_1.Route, { path: ":page", element: (0, jsx_runtime_1.jsx)(explore_1.PageExplorer, {}) })] })] }) }) }) }) }) }) }) }) }) }) }));
|
|
40
|
+
}
|
package/dist/EntryEditor.js
CHANGED
|
@@ -3,48 +3,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EntryEditor = EntryEditor;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_apps_toolkit_1 = require("@contentful/react-apps-toolkit");
|
|
6
|
+
const contentful_1 = require("@nascentdigital/funnel-cms/contentful");
|
|
7
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
6
8
|
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
7
9
|
const react_1 = require("react");
|
|
10
|
+
const asset_1 = require("./asset");
|
|
8
11
|
const collection_1 = require("./collection");
|
|
9
12
|
const core_1 = require("./core");
|
|
10
13
|
const page_1 = require("./page");
|
|
11
14
|
// entry editor
|
|
12
15
|
function EntryEditor() {
|
|
13
|
-
// hooks
|
|
16
|
+
// bind props + hooks
|
|
14
17
|
const sdk = (0, react_apps_toolkit_1.useSDK)();
|
|
18
|
+
const contentfulClient = (0, core_1.useContentfulClient)();
|
|
15
19
|
const appState = (0, components_1.useAppState)();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}, [sdk]);
|
|
24
|
-
// create remote page repository
|
|
25
|
-
const remotePageRepository = (0, react_1.useMemo)(() => {
|
|
26
|
-
return new core_1.RemotePageRepository(sdk);
|
|
27
|
-
}, [sdk]);
|
|
28
|
-
// create collections context
|
|
29
|
-
const collectionsContext = (0, react_1.useMemo)(() => {
|
|
30
|
-
const collections = new components_1.Collections({ appState, repository: remoteCollectionRepository });
|
|
31
|
-
return { collections };
|
|
32
|
-
}, [appState, remoteCollectionRepository]);
|
|
33
|
-
// create site context
|
|
34
|
-
const siteContext = (0, react_1.useMemo)(() => {
|
|
35
|
-
const site = new components_1.Site({ appState, repository: remotePageRepository, region: 'ca' });
|
|
36
|
-
return { site };
|
|
37
|
-
}, [appState, remotePageRepository]);
|
|
20
|
+
const { regionalization } = funnel_core_1.AppConfig.brandConfig();
|
|
21
|
+
let region = funnel_core_1.RegionsConfig.getDefaultRegion(regionalization);
|
|
22
|
+
// create repositories
|
|
23
|
+
const { assetRepository, collectionRepository, pageRepository } = (0, react_1.useMemo)(() => ({
|
|
24
|
+
assetRepository: new asset_1.AssetRepository(sdk),
|
|
25
|
+
collectionRepository: new collection_1.CollectionRepository({ sdk, contentfulClient }),
|
|
26
|
+
pageRepository: new page_1.PageRepository({ sdk, contentfulClient })
|
|
27
|
+
}), [sdk, contentfulClient]);
|
|
38
28
|
// page editor
|
|
39
29
|
let content;
|
|
40
|
-
const {
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
const { entry } = sdk;
|
|
31
|
+
const { contentType: { sys: { id } } } = entry.getSys();
|
|
32
|
+
if (id === contentful_1.ContentfulPageData.contentType) {
|
|
33
|
+
region = entry.fields.region.getValue();
|
|
34
|
+
content = ((0, jsx_runtime_1.jsx)(page_1.ContentfulPageControllerContainer, { children: (0, jsx_runtime_1.jsx)(page_1.PageEditor, {}) }));
|
|
43
35
|
}
|
|
44
36
|
// collection editor
|
|
45
|
-
else if (id ===
|
|
46
|
-
content = ((0, jsx_runtime_1.jsx)(collection_1.
|
|
37
|
+
else if (id === contentful_1.ContentfulCollectionData.contentType) {
|
|
38
|
+
content = ((0, jsx_runtime_1.jsx)(collection_1.ContentfulCollectionControllerContainer, { children: (0, jsx_runtime_1.jsx)(collection_1.CollectionEditor, {}) }));
|
|
47
39
|
}
|
|
40
|
+
// create contexts
|
|
41
|
+
const siteContext = (0, react_1.useMemo)(() => {
|
|
42
|
+
const site = new components_1.Site({ appState, repository: pageRepository, region });
|
|
43
|
+
return { site };
|
|
44
|
+
}, [appState, pageRepository, region]);
|
|
45
|
+
const collectionsContext = (0, react_1.useMemo)(() => {
|
|
46
|
+
const collections = new components_1.Collections({ appState, repository: collectionRepository });
|
|
47
|
+
return { collections };
|
|
48
|
+
}, [appState, collectionRepository]);
|
|
48
49
|
// render
|
|
49
|
-
return ((0, jsx_runtime_1.jsx)(components_1.
|
|
50
|
+
return ((0, jsx_runtime_1.jsx)(components_1.AssetRepositoryContext.Provider, { value: assetRepository, children: (0, jsx_runtime_1.jsx)(components_1.CollectionRepositoryContext.Provider, { value: collectionRepository, children: (0, jsx_runtime_1.jsx)(components_1.PageRepositoryContext.Provider, { value: pageRepository, children: (0, jsx_runtime_1.jsx)(components_1.SiteContext.Provider, { value: siteContext, children: (0, jsx_runtime_1.jsx)(components_1.CollectionsContext.Provider, { value: collectionsContext, children: (0, jsx_runtime_1.jsx)(components_1.DialogContainer, { children: (0, jsx_runtime_1.jsx)(components_1.CenterSheetContainer, { children: (0, jsx_runtime_1.jsx)(components_1.SplashContainer, { message: "Initializing...", children: content }) }) }) }) }) }) }) }));
|
|
50
51
|
}
|
package/dist/EntrySidebar.js
CHANGED
|
@@ -20,5 +20,5 @@ function EntrySidebar() {
|
|
|
20
20
|
return () => subscription.unsubscribe();
|
|
21
21
|
});
|
|
22
22
|
// render
|
|
23
|
-
return ((0, jsx_runtime_1.
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)("h3", { children: ["Entry sidebar ", itemId] }) }));
|
|
24
24
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './repository';
|
|
@@ -14,6 +14,4 @@ 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("./EditorApiContainer"), exports);
|
|
19
|
-
__exportStar(require("./useEditorApi"), exports);
|
|
17
|
+
__exportStar(require("./repository"), exports);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AssetRepository = void 0;
|
|
4
4
|
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
-
const
|
|
5
|
+
const core_1 = require("../../core");
|
|
6
6
|
// class
|
|
7
7
|
class AssetRepository {
|
|
8
8
|
constructor(sdk) {
|
|
@@ -25,9 +25,9 @@ class AssetRepository {
|
|
|
25
25
|
}
|
|
26
26
|
async uploadFile(args) {
|
|
27
27
|
// upload asset
|
|
28
|
-
const asset = await
|
|
28
|
+
const asset = await core_1.ContentfulAsset.upload(args, this.sdk);
|
|
29
29
|
// return result
|
|
30
|
-
return
|
|
30
|
+
return core_1.ContentfulAsset.serialize(asset, this.sdk.locales.default);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
exports.AssetRepository = AssetRepository;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AssetRepository';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AssetRepository"), exports);
|
|
@@ -1,35 +1,41 @@
|
|
|
1
|
+
import { EntrySys } from '@contentful/app-sdk';
|
|
1
2
|
import { CollectionGroup, CollectionTarget, ICollection, ICollectionController } from '@nascentdigital/funnel-editor/components';
|
|
2
3
|
import { type Observable } from 'rxjs';
|
|
3
|
-
import { Collection
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly
|
|
4
|
+
import { Collection } from '../domain';
|
|
5
|
+
import { CollectionRepository } from '../repository';
|
|
6
|
+
export declare class ContentfulCollectionController implements ICollectionController {
|
|
7
|
+
readonly collectionRepository: CollectionRepository;
|
|
7
8
|
private readonly _eventBus;
|
|
8
9
|
private _state;
|
|
9
10
|
private _collectionGroup?;
|
|
10
11
|
private _collection?;
|
|
11
|
-
private
|
|
12
|
-
|
|
12
|
+
private _collectionSys?;
|
|
13
|
+
private _queuedSave?;
|
|
14
|
+
private _queuedSync?;
|
|
15
|
+
private _collectionSubscription?;
|
|
16
|
+
constructor(args: ContentfulCollectionController.ConstructorArgs);
|
|
13
17
|
get events$(): Observable<ICollectionController.Event | ICollection.Event>;
|
|
14
18
|
get state(): ICollectionController.State;
|
|
15
19
|
private set state(value);
|
|
16
20
|
get ready(): boolean;
|
|
17
|
-
get languages(): ("id" | "
|
|
21
|
+
get languages(): ("id" | "aa" | "ab" | "ae" | "af" | "ak" | "am" | "an" | "ar" | "as" | "av" | "ay" | "az" | "ba" | "be" | "bg" | "bh" | "bi" | "bm" | "bn" | "bo" | "br" | "bs" | "ca" | "ce" | "ch" | "co" | "cr" | "cs" | "cu" | "cv" | "cy" | "da" | "de" | "dv" | "dz" | "ee" | "el" | "en" | "eo" | "es" | "et" | "eu" | "fa" | "ff" | "fi" | "fj" | "fo" | "fr" | "fy" | "ga" | "gd" | "gl" | "gn" | "gu" | "gv" | "ha" | "he" | "hi" | "ho" | "hr" | "ht" | "hu" | "hy" | "hz" | "ia" | "ie" | "ig" | "ii" | "ik" | "io" | "is" | "it" | "iu" | "ja" | "jv" | "ka" | "kg" | "ki" | "kj" | "kk" | "kl" | "km" | "kn" | "ko" | "kr" | "ks" | "ku" | "kv" | "kw" | "ky" | "la" | "lb" | "lg" | "li" | "ln" | "lo" | "lt" | "lu" | "lv" | "mg" | "mh" | "mi" | "mk" | "ml" | "mn" | "mr" | "ms" | "mt" | "my" | "na" | "nb" | "nd" | "ne" | "ng" | "nl" | "nn" | "no" | "nr" | "nv" | "ny" | "oc" | "oj" | "om" | "or" | "os" | "pa" | "pi" | "pl" | "ps" | "pt" | "qu" | "rm" | "rn" | "ro" | "ru" | "rw" | "sa" | "sc" | "sd" | "se" | "sg" | "si" | "sk" | "sl" | "sm" | "sn" | "so" | "sq" | "sr" | "ss" | "st" | "su" | "sv" | "sw" | "ta" | "te" | "tg" | "th" | "ti" | "tk" | "tl" | "tn" | "to" | "tr" | "ts" | "tt" | "tw" | "ty" | "ug" | "uk" | "ur" | "uz" | "ve" | "vi" | "vo" | "wa" | "wo" | "xh" | "yi" | "yo" | "za" | "zh" | "zu")[];
|
|
22
|
+
get collectionSys(): EntrySys | undefined;
|
|
23
|
+
private set collectionSys(value);
|
|
18
24
|
get collectionGroup(): CollectionGroup | undefined;
|
|
19
25
|
private set collectionGroup(value);
|
|
20
26
|
get collection(): Collection | undefined;
|
|
21
27
|
set collection(collection: Collection | undefined);
|
|
22
|
-
sync(
|
|
28
|
+
sync(updatedSys: EntrySys): Promise<void>;
|
|
23
29
|
load(): Promise<void>;
|
|
24
30
|
createLanguage(target: CollectionTarget): Promise<void>;
|
|
25
31
|
unpublish(): Promise<void>;
|
|
26
32
|
save(collection: Collection): Promise<void>;
|
|
27
33
|
reload(): Promise<void>;
|
|
34
|
+
private processQueues;
|
|
28
35
|
private raiseEvent;
|
|
29
36
|
}
|
|
30
|
-
export declare namespace
|
|
37
|
+
export declare namespace ContentfulCollectionController {
|
|
31
38
|
type ConstructorArgs = {
|
|
32
|
-
|
|
33
|
-
remoteRepository: RemoteCollectionRepository;
|
|
39
|
+
collectionRepository: CollectionRepository;
|
|
34
40
|
};
|
|
35
41
|
}
|
|
@@ -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
|
+
}
|