@nascentdigital/funnel-editor-contentful 4.6.7 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Editor.d.ts +6 -1
- package/dist/Editor.js +17 -1
- package/dist/EditorApp.js +11 -9
- package/dist/EditorPageRouter.d.ts +1 -0
- package/dist/EditorPageRouter.js +40 -0
- package/dist/EntryEditor.js +43 -1
- package/dist/EntrySidebar.js +18 -1
- package/dist/asset/index.d.ts +1 -0
- package/dist/{page/hooks → asset}/index.js +1 -1
- package/dist/asset/repository/AssetRepository.d.ts +10 -0
- package/dist/asset/repository/AssetRepository.js +33 -0
- package/dist/asset/repository/index.d.ts +1 -0
- package/dist/{core/api → asset/repository}/index.js +1 -3
- package/dist/collection/controller/ContentfulCollectionController.d.ts +41 -0
- package/dist/collection/controller/ContentfulCollectionController.js +278 -0
- package/dist/collection/controller/ContentfulCollectionControllerContainer.d.ts +5 -0
- package/dist/collection/controller/ContentfulCollectionControllerContainer.js +28 -0
- package/dist/collection/controller/index.d.ts +3 -0
- package/dist/collection/controller/index.js +19 -0
- package/dist/collection/controller/useContentfulCollectionController.d.ts +2 -0
- package/dist/collection/controller/useContentfulCollectionController.js +8 -0
- package/dist/collection/domain/Collection.d.ts +108 -0
- package/dist/collection/domain/Collection.js +386 -0
- package/dist/collection/domain/index.d.ts +1 -0
- package/dist/collection/domain/index.js +17 -0
- package/dist/collection/index.d.ts +3 -0
- package/dist/collection/index.js +19 -0
- package/dist/collection/repository/CollectionRepository.d.ts +49 -0
- package/dist/collection/repository/CollectionRepository.js +210 -0
- package/dist/collection/repository/index.d.ts +1 -0
- package/dist/collection/repository/index.js +17 -0
- package/dist/collection/screens/CollectionEditor.d.ts +1 -0
- package/dist/collection/screens/CollectionEditor.js +59 -0
- package/dist/collection/screens/index.d.ts +1 -0
- package/dist/collection/screens/index.js +17 -0
- package/dist/core/bridge/AppBridgeContainer.d.ts +9 -0
- package/dist/core/bridge/AppBridgeContainer.js +55 -0
- package/dist/core/bridge/AppBridgeContext.d.ts +8 -0
- package/dist/core/bridge/AppBridgeContext.js +11 -0
- package/dist/core/bridge/AppMessage.d.ts +19 -0
- package/dist/core/bridge/AppMessage.js +19 -0
- package/dist/core/bridge/index.d.ts +4 -0
- package/dist/core/bridge/index.js +20 -0
- package/dist/core/bridge/useAppBridge.d.ts +8 -0
- package/dist/core/bridge/useAppBridge.js +24 -0
- package/dist/core/client/ContentfulClientContainer.d.ts +8 -0
- package/dist/core/client/ContentfulClientContainer.js +43 -0
- package/dist/core/client/ContentfulClientContext.d.ts +8 -0
- package/dist/core/client/ContentfulClientContext.js +8 -0
- package/dist/core/client/index.d.ts +3 -0
- package/dist/core/client/index.js +19 -0
- package/dist/core/client/useContentfulClient.d.ts +4 -0
- package/dist/core/client/useContentfulClient.js +24 -0
- package/dist/core/contentful/Contentful.d.ts +33 -0
- package/dist/core/contentful/Contentful.js +67 -0
- package/dist/core/contentful/ContentfulAsset.d.ts +23 -0
- package/dist/core/contentful/ContentfulAsset.js +89 -0
- package/dist/core/contentful/ContentfulCollection.d.ts +29 -0
- package/dist/core/contentful/ContentfulCollection.js +97 -0
- package/dist/core/contentful/ContentfulPage.d.ts +31 -0
- package/dist/core/contentful/ContentfulPage.js +84 -0
- package/dist/core/contentful/ContentfulRefs.d.ts +16 -0
- package/dist/core/contentful/ContentfulRefs.js +152 -0
- package/dist/core/contentful/index.d.ts +5 -0
- package/dist/core/contentful/index.js +21 -0
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +3 -2
- package/dist/core/repository/CollectionSerializer.d.ts +9 -0
- package/dist/core/repository/CollectionSerializer.js +41 -0
- package/dist/core/repository/LocalCollectionRepository.d.ts +27 -0
- package/dist/core/repository/LocalCollectionRepository.js +143 -0
- package/dist/core/repository/LocalPageRepository.d.ts +16 -0
- package/dist/core/repository/LocalPageRepository.js +153 -0
- package/dist/core/repository/PageSerializer.d.ts +3 -3
- package/dist/core/repository/PageSerializer.js +18 -14
- package/dist/core/repository/RemoteCollectionRepository.d.ts +19 -0
- package/dist/core/repository/RemoteCollectionRepository.js +236 -0
- package/dist/core/repository/RemotePageRepository.d.ts +14 -0
- package/dist/core/repository/RemotePageRepository.js +113 -0
- package/dist/core/repository/index.d.ts +4 -1
- package/dist/core/repository/index.js +4 -1
- package/dist/explore/components/Header.d.ts +26 -0
- package/dist/explore/components/Header.js +31 -0
- package/dist/explore/components/index.d.ts +1 -0
- package/dist/explore/components/index.js +17 -0
- package/dist/explore/index.d.ts +1 -0
- package/dist/explore/index.js +17 -0
- package/dist/explore/screens/Dashboard.d.ts +1 -0
- package/dist/explore/screens/Dashboard.js +22 -0
- package/dist/explore/screens/PageExplorer.d.ts +1 -0
- package/dist/explore/screens/PageExplorer.js +9 -0
- package/dist/explore/screens/SiteExplorer.d.ts +1 -0
- package/dist/explore/screens/SiteExplorer.js +24 -0
- package/dist/explore/screens/index.d.ts +3 -0
- package/dist/explore/screens/index.js +19 -0
- package/dist/page/{hooks/PageController.d.ts → controller/ContentfulPageController.d.ts} +17 -6
- package/dist/page/controller/ContentfulPageController.js +277 -0
- package/dist/page/controller/ContentfulPageControllerContainer.d.ts +5 -0
- package/dist/page/controller/ContentfulPageControllerContainer.js +28 -0
- package/dist/page/controller/index.d.ts +3 -0
- package/dist/page/controller/index.js +19 -0
- package/dist/page/controller/useContentfulPageController.d.ts +2 -0
- package/dist/page/controller/useContentfulPageController.js +8 -0
- package/dist/{core → page}/domain/Page.d.ts +71 -10
- package/dist/page/domain/Page.js +631 -0
- package/dist/page/index.d.ts +3 -0
- package/dist/page/index.js +3 -0
- package/dist/page/repository/PageRepository.d.ts +45 -0
- package/dist/page/repository/PageRepository.js +224 -0
- package/dist/page/repository/index.d.ts +1 -0
- package/dist/page/repository/index.js +17 -0
- package/dist/page/screens/PageEditor.js +29 -15
- package/package.json +10 -4
- package/dist/core/api/EditorApiClient.d.ts +0 -7
- package/dist/core/api/EditorApiClient.js +0 -29
- package/dist/core/api/EditorApiContainer.d.ts +0 -5
- package/dist/core/api/EditorApiContainer.js +0 -16
- package/dist/core/api/EditorApiContext.d.ts +0 -7
- package/dist/core/api/EditorApiContext.js +0 -6
- package/dist/core/api/index.d.ts +0 -3
- package/dist/core/api/useEditorApi.d.ts +0 -2
- package/dist/core/api/useEditorApi.js +0 -12
- package/dist/core/domain/Page.js +0 -180
- package/dist/core/repository/PageRepository.d.ts +0 -12
- package/dist/core/repository/PageRepository.js +0 -23
- package/dist/page/hooks/PageController.js +0 -107
- package/dist/page/hooks/index.d.ts +0 -1
- /package/dist/{core → page}/domain/index.d.ts +0 -0
- /package/dist/{core → page}/domain/index.js +0 -0
|
@@ -0,0 +1,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
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { AssetClient, CollectionClient } from '@nascentdigital/funnel-cms';
|
|
2
|
+
import { ContentfulCollectionData, ContentfulData } from '@nascentdigital/funnel-cms/contentful';
|
|
3
|
+
import { EventBus, Field, FieldModel, Language, Schema } from '@nascentdigital/funnel-core';
|
|
4
|
+
import { Asset, CollectionFieldProxy, CollectionGroup, ICollection, IPage } from '@nascentdigital/funnel-editor/components';
|
|
5
|
+
import { Observable } from 'rxjs';
|
|
6
|
+
export declare class Collection implements ICollection {
|
|
7
|
+
readonly template: Schema.Collection;
|
|
8
|
+
readonly eventBus: EventBus;
|
|
9
|
+
readonly id: Schema.Collection.Id;
|
|
10
|
+
readonly groupId: Schema.Collection.GroupId;
|
|
11
|
+
readonly brand?: string;
|
|
12
|
+
readonly language: Language;
|
|
13
|
+
readonly version: number;
|
|
14
|
+
readonly nameField: Field<Schema.TextField>;
|
|
15
|
+
readonly pageIds: Schema.Page.Id[];
|
|
16
|
+
private _initialTags;
|
|
17
|
+
private readonly _tags;
|
|
18
|
+
readonly fields: ReadonlyArray<FieldModel>;
|
|
19
|
+
private readonly _assets;
|
|
20
|
+
private readonly _collections;
|
|
21
|
+
private readonly _pages;
|
|
22
|
+
readonly createdOn: number;
|
|
23
|
+
private _updatedOn;
|
|
24
|
+
private _modifiedOn?;
|
|
25
|
+
readonly publishedOn?: number;
|
|
26
|
+
private readonly _subscription;
|
|
27
|
+
private _state;
|
|
28
|
+
private _initialErrors;
|
|
29
|
+
private _syncing;
|
|
30
|
+
private _savingOn?;
|
|
31
|
+
readonly references: Readonly<ContentfulData.References>;
|
|
32
|
+
constructor(args: Collection.ConstructorArgs);
|
|
33
|
+
get events$(): Observable<ICollection.Events>;
|
|
34
|
+
get stable$(): Observable<boolean>;
|
|
35
|
+
get state(): Schema.Collection.State;
|
|
36
|
+
private set state(value);
|
|
37
|
+
get syncing(): boolean;
|
|
38
|
+
set syncing(syncing: boolean);
|
|
39
|
+
get type(): Schema.Collection.Type;
|
|
40
|
+
get modified(): boolean;
|
|
41
|
+
get changes(): ICollection.Changes;
|
|
42
|
+
get initialErrors(): boolean;
|
|
43
|
+
get errors(): ICollection.Errors;
|
|
44
|
+
get valid(): boolean;
|
|
45
|
+
get allFields(): FieldModel[];
|
|
46
|
+
get name(): string;
|
|
47
|
+
set name(name: string);
|
|
48
|
+
get published(): boolean;
|
|
49
|
+
get updatedOn(): number;
|
|
50
|
+
get assets(): ReadonlyArray<Asset>;
|
|
51
|
+
get collections(): ReadonlyArray<Schema.Collection.Data.AsLink>;
|
|
52
|
+
get tagGroups(): ReadonlyArray<Schema.TagGroup>;
|
|
53
|
+
get initialTags(): ReadonlySet<Schema.Tag<string, string>>;
|
|
54
|
+
get tags(): ReadonlySet<Schema.Tag>;
|
|
55
|
+
hydrateStores(references: ICollection.References): void;
|
|
56
|
+
getAssetScope(range: Schema.AssetScope.Range): Schema.AssetScope;
|
|
57
|
+
getSearchScope(): AssetClient.GetAssets.Scope;
|
|
58
|
+
getAsset(id: Asset.Id): Asset | undefined;
|
|
59
|
+
addAsset(asset: Asset): void;
|
|
60
|
+
removeAsset(assetId: Asset.Id): boolean;
|
|
61
|
+
getCollection(collectionId: Schema.Collection.Id): Schema.Collection.Data.AsLink | undefined;
|
|
62
|
+
addCollection(collection: Schema.Collection.Data.AsLink): void;
|
|
63
|
+
removeCollection(collectionId: Schema.Collection.Id): boolean;
|
|
64
|
+
getPageRef(pageId: Schema.Page.Id | undefined): IPage.Ref | undefined;
|
|
65
|
+
addPageRef(page: IPage.Ref): void;
|
|
66
|
+
removePageRef(pageId: Schema.Page.Id): boolean;
|
|
67
|
+
addTag(tag: Schema.Tag): void;
|
|
68
|
+
removeTag(tag: Schema.Tag): void;
|
|
69
|
+
onSaveStart(): void;
|
|
70
|
+
onSaveComplete(updatedOn: number): void;
|
|
71
|
+
private raiseEvent;
|
|
72
|
+
}
|
|
73
|
+
export declare namespace Collection {
|
|
74
|
+
type ConstructorArgs = {
|
|
75
|
+
template: Schema.Collection;
|
|
76
|
+
eventBus: EventBus;
|
|
77
|
+
id: Schema.Collection.Id;
|
|
78
|
+
groupId: Schema.Collection.GroupId;
|
|
79
|
+
brand?: string;
|
|
80
|
+
language: Language;
|
|
81
|
+
version: number;
|
|
82
|
+
name: string;
|
|
83
|
+
tags: Schema.Tag[];
|
|
84
|
+
fields: FieldModel[];
|
|
85
|
+
files?: Asset[];
|
|
86
|
+
collections?: Schema.Collection.Data.AsLink[];
|
|
87
|
+
pageIds?: Schema.Page.Id[];
|
|
88
|
+
state: Schema.Collection.State;
|
|
89
|
+
errors: boolean;
|
|
90
|
+
changeSetId?: Schema.ChangeSet.Id;
|
|
91
|
+
snapshotId?: Schema.CollectionSnapshot.Id;
|
|
92
|
+
snapshot?: Schema.CollectionSnapshot;
|
|
93
|
+
createdOn: number;
|
|
94
|
+
updatedOn: number;
|
|
95
|
+
publishedOn?: number;
|
|
96
|
+
references: ContentfulData.References;
|
|
97
|
+
};
|
|
98
|
+
type WithGroup = {
|
|
99
|
+
group: CollectionGroup;
|
|
100
|
+
collection?: Collection;
|
|
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;
|
|
108
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
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.Collection = void 0;
|
|
15
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
|
+
const components_1 = require("@nascentdigital/funnel-editor/components");
|
|
17
|
+
const rxjs_1 = require("rxjs");
|
|
18
|
+
// class
|
|
19
|
+
class Collection {
|
|
20
|
+
constructor(args) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
// initialize instance variables
|
|
23
|
+
this.template = args.template;
|
|
24
|
+
this.eventBus = args.eventBus;
|
|
25
|
+
this.id = args.id;
|
|
26
|
+
this.groupId = args.groupId;
|
|
27
|
+
this.brand = args.brand;
|
|
28
|
+
this.language = args.language;
|
|
29
|
+
this.version = args.version;
|
|
30
|
+
this.nameField = new funnel_core_1.Field({
|
|
31
|
+
id: 'name',
|
|
32
|
+
name: 'Name',
|
|
33
|
+
schema: funnel_core_1.Schema.Field.text({
|
|
34
|
+
name: 'Name',
|
|
35
|
+
description: `This is the name used to identify this ${args.template.name}.`,
|
|
36
|
+
hint: 'Please provide a name',
|
|
37
|
+
semantics: 'short',
|
|
38
|
+
required: true
|
|
39
|
+
}),
|
|
40
|
+
eventBus: args.eventBus,
|
|
41
|
+
initialValue: funnel_core_1.Schema.TextField.Value.toData(args.name),
|
|
42
|
+
publishedValue: funnel_core_1.Schema.TextField.Value.coerceData((_a = args.snapshot) === null || _a === void 0 ? void 0 : _a.name),
|
|
43
|
+
required: true
|
|
44
|
+
});
|
|
45
|
+
this._initialTags = new Set(args.tags);
|
|
46
|
+
this.pageIds = (_b = args.pageIds) !== null && _b !== void 0 ? _b : [];
|
|
47
|
+
this._tags = new Set(args.tags);
|
|
48
|
+
this.fields = args.fields;
|
|
49
|
+
this._assets = (_c = args.files) !== null && _c !== void 0 ? _c : [];
|
|
50
|
+
this._collections = (_d = args.collections) !== null && _d !== void 0 ? _d : [];
|
|
51
|
+
this._pages = [];
|
|
52
|
+
this.createdOn = args.createdOn;
|
|
53
|
+
this._updatedOn = args.updatedOn;
|
|
54
|
+
this.publishedOn = args.publishedOn;
|
|
55
|
+
this.references = args.references;
|
|
56
|
+
this._state = args.state;
|
|
57
|
+
this._initialErrors = args.errors;
|
|
58
|
+
this._syncing = false;
|
|
59
|
+
// listen to block/field changes
|
|
60
|
+
this._subscription = this.eventBus.events$
|
|
61
|
+
.pipe((0, rxjs_1.filter)(e => (funnel_core_1.Field.Event.filter(e) && e.type === 'changed' && !e.field.sandboxed)
|
|
62
|
+
|| (funnel_core_1.FieldList.Event.filter(e) && e.type === 'changed')
|
|
63
|
+
|| (funnel_core_1.ObjectField.Event.filter(e) && e.type === 'changed')
|
|
64
|
+
|| (components_1.Item.Event.filter(e) && e.type === 'changed')))
|
|
65
|
+
.subscribe(() => this.raiseEvent('changed'));
|
|
66
|
+
}
|
|
67
|
+
get events$() {
|
|
68
|
+
return this.eventBus.events$;
|
|
69
|
+
}
|
|
70
|
+
get stable$() {
|
|
71
|
+
return this.eventBus.events$
|
|
72
|
+
.pipe((0, rxjs_1.map)(() => !this._syncing && !this.modified), (0, rxjs_1.distinctUntilChanged)());
|
|
73
|
+
}
|
|
74
|
+
get state() {
|
|
75
|
+
return this._state;
|
|
76
|
+
}
|
|
77
|
+
set state(state) {
|
|
78
|
+
// skip if unchanged
|
|
79
|
+
if (this._state === state) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// update state
|
|
83
|
+
this._state = state;
|
|
84
|
+
this._modifiedOn = Date.now();
|
|
85
|
+
// raise change
|
|
86
|
+
this.raiseEvent('changed');
|
|
87
|
+
}
|
|
88
|
+
get syncing() {
|
|
89
|
+
return this._syncing;
|
|
90
|
+
}
|
|
91
|
+
set syncing(syncing) {
|
|
92
|
+
this._syncing = syncing;
|
|
93
|
+
this.raiseEvent('changed');
|
|
94
|
+
}
|
|
95
|
+
get type() {
|
|
96
|
+
return this.template.type;
|
|
97
|
+
}
|
|
98
|
+
get modified() {
|
|
99
|
+
const { nameField, initialTags, _tags, fields, initialErrors } = this;
|
|
100
|
+
return nameField.modified
|
|
101
|
+
|| initialTags.symmetricDifference(_tags).size > 0
|
|
102
|
+
|| fields.some(field => field.modified)
|
|
103
|
+
|| initialErrors !== (this.errors.fields.length > 0);
|
|
104
|
+
}
|
|
105
|
+
get changes() {
|
|
106
|
+
return {
|
|
107
|
+
collection: this,
|
|
108
|
+
fields: this.allFields.filter(field => field.changed)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
get initialErrors() {
|
|
112
|
+
return this._initialErrors;
|
|
113
|
+
}
|
|
114
|
+
get errors() {
|
|
115
|
+
return {
|
|
116
|
+
collection: this,
|
|
117
|
+
fields: this.allFields.filter(field => !field.valid)
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
get valid() {
|
|
121
|
+
return this.errors.fields.length === 0;
|
|
122
|
+
}
|
|
123
|
+
get allFields() {
|
|
124
|
+
const { nameField, fields } = this;
|
|
125
|
+
return [nameField, ...fields];
|
|
126
|
+
}
|
|
127
|
+
get name() {
|
|
128
|
+
var _a;
|
|
129
|
+
return (_a = funnel_core_1.Schema.TextField.Value.fromData(this.nameField.value)) !== null && _a !== void 0 ? _a : '';
|
|
130
|
+
}
|
|
131
|
+
set name(name) {
|
|
132
|
+
this.nameField.value = funnel_core_1.Schema.TextField.Value.toData(name);
|
|
133
|
+
}
|
|
134
|
+
get published() {
|
|
135
|
+
return this.publishedOn !== undefined;
|
|
136
|
+
}
|
|
137
|
+
get updatedOn() {
|
|
138
|
+
return this._updatedOn;
|
|
139
|
+
}
|
|
140
|
+
get assets() {
|
|
141
|
+
return this._assets;
|
|
142
|
+
}
|
|
143
|
+
get collections() {
|
|
144
|
+
return this._collections;
|
|
145
|
+
}
|
|
146
|
+
get tagGroups() {
|
|
147
|
+
return this.template.tags;
|
|
148
|
+
}
|
|
149
|
+
get initialTags() {
|
|
150
|
+
return this._initialTags;
|
|
151
|
+
}
|
|
152
|
+
get tags() {
|
|
153
|
+
return this._tags;
|
|
154
|
+
}
|
|
155
|
+
hydrateStores(references) {
|
|
156
|
+
this._assets.push(...references.assets);
|
|
157
|
+
this._collections.push(...references.collections);
|
|
158
|
+
}
|
|
159
|
+
getAssetScope(range) {
|
|
160
|
+
switch (range) {
|
|
161
|
+
case 'global':
|
|
162
|
+
return funnel_core_1.Schema.AssetScope.global;
|
|
163
|
+
case 'type':
|
|
164
|
+
return new funnel_core_1.Schema.CollectionTypeAssetScope(this.type);
|
|
165
|
+
case 'instance':
|
|
166
|
+
return new funnel_core_1.Schema.CollectionInstanceAssetScope(this.groupId);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
getSearchScope() {
|
|
170
|
+
return {
|
|
171
|
+
target: 'collection',
|
|
172
|
+
type: this.type,
|
|
173
|
+
groupId: this.groupId
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
getAsset(id) {
|
|
177
|
+
return this._assets.find(asset => asset.value.id === id);
|
|
178
|
+
}
|
|
179
|
+
addAsset(asset) {
|
|
180
|
+
// replace asset if it exists
|
|
181
|
+
const { _assets } = this;
|
|
182
|
+
const { id } = asset.value;
|
|
183
|
+
const assetIndex = _assets.findIndex(asset => asset.value.id === id);
|
|
184
|
+
if (assetIndex >= 0) {
|
|
185
|
+
_assets[assetIndex] = asset;
|
|
186
|
+
}
|
|
187
|
+
// or add asset
|
|
188
|
+
else {
|
|
189
|
+
_assets.push(asset);
|
|
190
|
+
}
|
|
191
|
+
// raise event
|
|
192
|
+
this.raiseEvent('changed');
|
|
193
|
+
}
|
|
194
|
+
removeAsset(assetId) {
|
|
195
|
+
// skip if asset isn't there
|
|
196
|
+
const { _assets } = this;
|
|
197
|
+
const assetIndex = _assets.findIndex(asset => asset.value.id === assetId);
|
|
198
|
+
if (assetIndex < 0) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
// remove asset
|
|
202
|
+
_assets.splice(assetIndex, 1);
|
|
203
|
+
// raise event
|
|
204
|
+
this.raiseEvent('changed');
|
|
205
|
+
// indicate success
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
getCollection(collectionId) {
|
|
209
|
+
return this._collections.find(collection => collection.id === collectionId);
|
|
210
|
+
}
|
|
211
|
+
addCollection(collection) {
|
|
212
|
+
// replace collection if it exists
|
|
213
|
+
const { _collections } = this;
|
|
214
|
+
const collectionId = collection.id;
|
|
215
|
+
const collectionIndex = _collections.findIndex(collection => collection.id === collectionId);
|
|
216
|
+
if (collectionIndex >= 0) {
|
|
217
|
+
_collections[collectionIndex] = collection;
|
|
218
|
+
}
|
|
219
|
+
// or add collection
|
|
220
|
+
else {
|
|
221
|
+
_collections.push(collection);
|
|
222
|
+
}
|
|
223
|
+
// raise event
|
|
224
|
+
this.raiseEvent('changed');
|
|
225
|
+
}
|
|
226
|
+
removeCollection(collectionId) {
|
|
227
|
+
// skip if collection isn't there
|
|
228
|
+
const { _collections } = this;
|
|
229
|
+
const collectionIndex = _collections.findIndex(collection => collection.id === collectionId);
|
|
230
|
+
if (collectionIndex < 0) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
// remove collection
|
|
234
|
+
_collections.splice(collectionIndex, 1);
|
|
235
|
+
// raise event
|
|
236
|
+
this.raiseEvent('changed');
|
|
237
|
+
// indicate success
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
getPageRef(pageId) {
|
|
241
|
+
return pageId && pageId !== funnel_core_1.Schema.Page.Id.draft
|
|
242
|
+
? this._pages.find(ref => ref.id === pageId)
|
|
243
|
+
: undefined;
|
|
244
|
+
}
|
|
245
|
+
addPageRef(page) {
|
|
246
|
+
// throw if page is a draft
|
|
247
|
+
if (page.id === funnel_core_1.Schema.Page.Id.draft) {
|
|
248
|
+
throw new funnel_core_1.InvalidOperationError('Cannot add draft Page as reference');
|
|
249
|
+
}
|
|
250
|
+
// replace ref if it exists
|
|
251
|
+
const { _pages } = this;
|
|
252
|
+
const pageId = page.id;
|
|
253
|
+
const refIndex = _pages.findIndex(ref => ref.id === pageId);
|
|
254
|
+
if (refIndex >= 0) {
|
|
255
|
+
_pages[refIndex] = page;
|
|
256
|
+
}
|
|
257
|
+
// or add ref
|
|
258
|
+
else {
|
|
259
|
+
_pages.push(page);
|
|
260
|
+
}
|
|
261
|
+
// raise event
|
|
262
|
+
this.raiseEvent('changed');
|
|
263
|
+
}
|
|
264
|
+
removePageRef(pageId) {
|
|
265
|
+
// skip if file isn't there
|
|
266
|
+
const { _pages } = this;
|
|
267
|
+
const refIndex = _pages.findIndex(ref => ref.id === pageId);
|
|
268
|
+
if (refIndex < 0) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
// remove file
|
|
272
|
+
_pages.splice(refIndex, 1);
|
|
273
|
+
// raise event
|
|
274
|
+
this.raiseEvent('changed');
|
|
275
|
+
// indicate success
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
addTag(tag) {
|
|
279
|
+
// skip if page has tag
|
|
280
|
+
const { _tags } = this;
|
|
281
|
+
if (_tags.has(tag)) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
// add tag
|
|
285
|
+
_tags.add(tag);
|
|
286
|
+
this._modifiedOn = Date.now();
|
|
287
|
+
// raise event
|
|
288
|
+
this.raiseEvent('modified');
|
|
289
|
+
}
|
|
290
|
+
removeTag(tag) {
|
|
291
|
+
// skip if tag isn't there
|
|
292
|
+
const { _tags } = this;
|
|
293
|
+
if (!_tags.has(tag)) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
// add tag
|
|
297
|
+
_tags.delete(tag);
|
|
298
|
+
this._modifiedOn = Date.now();
|
|
299
|
+
// raise event
|
|
300
|
+
this.raiseEvent('modified');
|
|
301
|
+
}
|
|
302
|
+
onSaveStart() {
|
|
303
|
+
this._savingOn = Date.now();
|
|
304
|
+
}
|
|
305
|
+
onSaveComplete(updatedOn) {
|
|
306
|
+
// update fundamentals
|
|
307
|
+
this._updatedOn = updatedOn;
|
|
308
|
+
this._state = 'draft';
|
|
309
|
+
// reset to values to match save
|
|
310
|
+
const { _modifiedOn, _savingOn } = this;
|
|
311
|
+
if (_savingOn && (!_modifiedOn || _savingOn >= _modifiedOn)) {
|
|
312
|
+
// sync data
|
|
313
|
+
this._initialErrors = !this.valid;
|
|
314
|
+
this._initialTags = new Set(this._tags);
|
|
315
|
+
}
|
|
316
|
+
// clear saving flag
|
|
317
|
+
delete this._savingOn;
|
|
318
|
+
}
|
|
319
|
+
raiseEvent(type) {
|
|
320
|
+
this.eventBus.publish(components_1.ICollection.Event.create({ type, collection: this }));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
exports.Collection = Collection;
|
|
324
|
+
// extension
|
|
325
|
+
(function (Collection) {
|
|
326
|
+
function fromSchemaData({ data, references }) {
|
|
327
|
+
// setup
|
|
328
|
+
const { snapshot, fields, tags } = data, collectionArgs = __rest(data, ["snapshot", "fields", "tags"]);
|
|
329
|
+
const { files = {}, collections = {} } = references !== null && references !== void 0 ? references : {};
|
|
330
|
+
const { fields: fieldsSnapshot = {} } = snapshot !== null && snapshot !== void 0 ? snapshot : {};
|
|
331
|
+
const template = funnel_core_1.Schema.Site.getCollection(data.type);
|
|
332
|
+
const eventBus = new funnel_core_1.EventBus();
|
|
333
|
+
// create collection
|
|
334
|
+
return new Collection(Object.assign(Object.assign({}, collectionArgs), { eventBus,
|
|
335
|
+
template, tags: components_1.TagSerializer.deserializeTags({
|
|
336
|
+
groups: template.tags,
|
|
337
|
+
tagsData: tags !== null && tags !== void 0 ? tags : []
|
|
338
|
+
}), fields: Object.entries(template.editableFields).map(([id, schema]) => components_1.FieldSerializer.deserializeField({
|
|
339
|
+
id,
|
|
340
|
+
eventBus,
|
|
341
|
+
schema,
|
|
342
|
+
content: fields[id],
|
|
343
|
+
snapshot: fieldsSnapshot[id]
|
|
344
|
+
})), files: Object.values(files), collections: Object.values(collections) }));
|
|
345
|
+
}
|
|
346
|
+
Collection.fromSchemaData = fromSchemaData;
|
|
347
|
+
function toUpdates(collection, savables) {
|
|
348
|
+
// add name updates
|
|
349
|
+
const { id, nameField, name, initialTags, tags, fields, initialErrors, valid } = collection;
|
|
350
|
+
const updates = [];
|
|
351
|
+
if (nameField.modified) {
|
|
352
|
+
updates.push({
|
|
353
|
+
type: 'collection',
|
|
354
|
+
property: 'name',
|
|
355
|
+
value: name
|
|
356
|
+
});
|
|
357
|
+
// track change
|
|
358
|
+
savables.push(nameField);
|
|
359
|
+
}
|
|
360
|
+
// add tag updates
|
|
361
|
+
if (initialTags.symmetricDifference(tags).size > 0) {
|
|
362
|
+
updates.push({
|
|
363
|
+
type: 'collection',
|
|
364
|
+
property: 'tags',
|
|
365
|
+
value: Array.from(tags).map(tag => tag.data)
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
// add errors updates
|
|
369
|
+
if (initialErrors !== !valid) {
|
|
370
|
+
updates.push({
|
|
371
|
+
type: 'collection',
|
|
372
|
+
property: 'errors',
|
|
373
|
+
value: !valid
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
// add fields
|
|
377
|
+
components_1.SerializeCollectionUpdate.serializeFieldsUpdate(updates, fields, ['fields'], savables);
|
|
378
|
+
// return updates
|
|
379
|
+
return {
|
|
380
|
+
id,
|
|
381
|
+
updates,
|
|
382
|
+
updatedOn: Date.now()
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
Collection.toUpdates = toUpdates;
|
|
386
|
+
})(Collection || (exports.Collection = Collection = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Collection';
|
|
@@ -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("./Collection"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./screens"), exports);
|
|
18
|
+
__exportStar(require("./controller"), exports);
|
|
19
|
+
__exportStar(require("./repository"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EditorAppSDK, EntrySys } 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;
|
|
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;
|
|
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
|
+
}
|