@nascentdigital/funnel-editor 5.0.2 → 6.0.0

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.
Files changed (49) hide show
  1. package/dist/collection/hooks/CollectionController.d.ts +7 -2
  2. package/dist/collection/hooks/CollectionController.js +2 -2
  3. package/dist/collection/screens/CollectionEditor.js +5 -4
  4. package/dist/components.d.ts +4 -1
  5. package/dist/components.js +5 -1
  6. package/dist/core/client/EditorApiClient.js +1 -1
  7. package/dist/core/components/fields/page/PagePicker.js +1 -1
  8. package/dist/core/components/interaction/Popup.js +23 -11
  9. package/dist/core/components/layout/InfoPanel.js +1 -1
  10. package/dist/core/components/visuals/Icon.d.ts +1 -1
  11. package/dist/core/components/visuals/Icon.js +3 -0
  12. package/dist/core/domain/IPage.d.ts +13 -14
  13. package/dist/core/domain/IPage.js +30 -0
  14. package/dist/core/domain/Page.d.ts +3 -5
  15. package/dist/core/domain/Page.js +8 -1
  16. package/dist/core/domain/PageOverview.d.ts +6 -0
  17. package/dist/core/domain/PageOverview.js +17 -0
  18. package/dist/core/domain/PageRefStoreProxy.d.ts +4 -6
  19. package/dist/core/domain/PageRefStoreProxy.js +16 -50
  20. package/dist/core/domain/PageStatus.d.ts +28 -0
  21. package/dist/core/domain/PageStatus.js +2 -0
  22. package/dist/core/domain/PageSummary.d.ts +9 -7
  23. package/dist/core/domain/PageSummary.js +12 -16
  24. package/dist/core/domain/Pages.js +1 -4
  25. package/dist/core/domain/Section.js +2 -2
  26. package/dist/core/domain/index.d.ts +1 -0
  27. package/dist/core/domain/index.js +1 -0
  28. package/dist/core/repository/IPageRepository.d.ts +5 -1
  29. package/dist/core/repository/PageRepository.d.ts +1 -0
  30. package/dist/core/repository/PageRepository.js +14 -5
  31. package/dist/explore/components/CreateCollectionDialog.js +1 -1
  32. package/dist/explore/screens/PageExplorer.js +2 -1
  33. package/dist/page/components/BlockEditor.d.ts +3 -1
  34. package/dist/page/components/BlockEditor.js +4 -3
  35. package/dist/page/components/config/BlockConfigurationProvider.d.ts +10 -2
  36. package/dist/page/components/config/BlockConfigurationProvider.js +11 -3
  37. package/dist/page/components/config/BlockPreview.d.ts +4 -2
  38. package/dist/page/components/config/BlockPreview.js +5 -11
  39. package/dist/page/components/config/index.d.ts +1 -0
  40. package/dist/page/components/config/index.js +1 -0
  41. package/dist/page/components/config/useBlockConfiguration$.d.ts +3 -0
  42. package/dist/page/components/config/useBlockConfiguration$.js +22 -0
  43. package/dist/page/components/panels/BlockConfigPanel.js +3 -3
  44. package/dist/page/hooks/PageController.d.ts +3 -3
  45. package/dist/page/hooks/PageController.js +4 -3
  46. package/dist/page/screens/PageEditor.js +4 -4
  47. package/dist/styles/index.css +40 -19
  48. package/dist/styles/tailwind.js +2 -1
  49. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import { Collection, CollectionGroup, CollectionRepository, CollectionTarget, EditorApiClient, ICollection } from '../../core';
1
+ import { Collection, CollectionGroup, CollectionRepository, CollectionTarget, ICollection } from '../../core';
2
2
  import { ICollectionController } from './ICollectionController';
3
3
  export declare class CollectionController implements ICollectionController {
4
4
  private readonly _eventBus;
@@ -9,7 +9,7 @@ export declare class CollectionController implements ICollectionController {
9
9
  private _collection?;
10
10
  private _saveQueuedFor?;
11
11
  private _subscription?;
12
- constructor(editorApi: EditorApiClient);
12
+ constructor({ collectionRepository }: CollectionController.ConstructorArgs);
13
13
  get events$(): import("rxjs").Observable<ICollection.Event | ICollectionController.Event>;
14
14
  get state(): ICollectionController.State;
15
15
  private set state(value);
@@ -27,3 +27,8 @@ export declare class CollectionController implements ICollectionController {
27
27
  unpublish(): Promise<void>;
28
28
  private raiseEvent;
29
29
  }
30
+ export declare namespace CollectionController {
31
+ type ConstructorArgs = {
32
+ collectionRepository: CollectionRepository;
33
+ };
34
+ }
@@ -7,10 +7,10 @@ const core_1 = require("../../core");
7
7
  const ICollectionController_1 = require("./ICollectionController");
8
8
  // class
9
9
  class CollectionController {
10
- constructor(editorApi) {
10
+ constructor({ collectionRepository }) {
11
11
  // initialize instance variables
12
12
  this._eventBus = new funnel_core_1.EventBus();
13
- this.repository = new core_1.CollectionRepository(editorApi);
13
+ this.repository = collectionRepository;
14
14
  this._state = 'uninitialized';
15
15
  }
16
16
  get events$() {
@@ -13,7 +13,8 @@ function CollectionEditor({ type, groupId, language }) {
13
13
  // bind hooks
14
14
  const router = (0, core_1.useEditorRouter)();
15
15
  const splash = (0, core_1.useSplash)();
16
- const editorApi = (0, core_1.useEditorApi)();
16
+ const collectionRepository = (0, core_1.useCollectionRepository)();
17
+ const pageRepository = (0, core_1.usePageRepository)();
17
18
  const pageRefStore = (0, core_1.usePossiblePageRefStore)();
18
19
  const target = (0, react_2.useMemo)(() => ({
19
20
  template: funnel_core_1.Schema.Site.getCollection(type),
@@ -23,15 +24,15 @@ function CollectionEditor({ type, groupId, language }) {
23
24
  }), [type, groupId, language]);
24
25
  const { controller, controllerContext } = (0, react_2.useMemo)(() => {
25
26
  // return controller + context
26
- const controller = new hooks_1.CollectionController(editorApi);
27
+ const controller = new hooks_1.CollectionController({ collectionRepository });
27
28
  return {
28
29
  controller,
29
30
  controllerContext: { controller }
30
31
  };
31
- }, [editorApi]);
32
+ }, [collectionRepository]);
32
33
  const { collection } = controller;
33
34
  const collectionContext = (0, react_2.useMemo)(() => ({ collection }), [collection]);
34
- const pageRefStoreProxy = (0, react_2.useMemo)(() => new core_1.PageRefStoreProxy({ editorApi, language, parent: pageRefStore }), [editorApi, language, pageRefStore]);
35
+ const pageRefStoreProxy = (0, react_2.useMemo)(() => new core_1.PageRefStoreProxy({ pageRepository, language, parent: pageRefStore }), [pageRepository, language, pageRefStore]);
35
36
  // load any needed page refs
36
37
  (0, react_2.useEffect)(() => {
37
38
  pageRefStoreProxy
@@ -15,7 +15,10 @@ export * from './core/repository/SerializeCollectionUpdate';
15
15
  export * from './core/repository/SerializePageUpdate';
16
16
  export * from './core/repository/TagSerializer';
17
17
  export * from './core/splash';
18
- export * from './page/hooks';
18
+ export * from './explore/components/CreatePageDialog';
19
+ export * from './explore/components/CreateCollectionDialog';
20
+ export * from './page/components/config';
19
21
  export * from './page/components/SettingsEditor';
22
+ export * from './page/hooks';
20
23
  export * from './collection/hooks';
21
24
  export { PageNav, BlockEditor };
@@ -35,8 +35,12 @@ __exportStar(require("./core/repository/SerializeCollectionUpdate"), exports);
35
35
  __exportStar(require("./core/repository/SerializePageUpdate"), exports);
36
36
  __exportStar(require("./core/repository/TagSerializer"), exports);
37
37
  __exportStar(require("./core/splash"), exports);
38
+ // explore
39
+ __exportStar(require("./explore/components/CreatePageDialog"), exports);
40
+ __exportStar(require("./explore/components/CreateCollectionDialog"), exports);
38
41
  // page
39
- __exportStar(require("./page/hooks"), exports);
42
+ __exportStar(require("./page/components/config"), exports);
40
43
  __exportStar(require("./page/components/SettingsEditor"), exports);
44
+ __exportStar(require("./page/hooks"), exports);
41
45
  // collection
42
46
  __exportStar(require("./collection/hooks"), exports);
@@ -33,7 +33,7 @@ class EditorApiClient {
33
33
  });
34
34
  }
35
35
  getPreviewUrl(url) {
36
- return `/api/preview?token=${this._token}&redirect=${url}`;
36
+ return `/api/preview?redirect=${url}`;
37
37
  }
38
38
  async getAssets(data) {
39
39
  return this.sendCommand('getAssets', data);
@@ -138,7 +138,7 @@ exports.PagePicker = (0, react_1.forwardRef)(function PagePicker({ language }, r
138
138
  pages.sync()
139
139
  .then(() => {
140
140
  setPagesSchema(pages.template);
141
- setPages(pages.items.map(page => page.getClosestPageRef(language, site.defaultLanguage)));
141
+ setPages(pages.items.map(page => page.getClosestPageRef({ region: site.region.id, language, fallbackLanguage: site.defaultLanguage })));
142
142
  })
143
143
  .catch(e => setError(feedback_1.ErrorMessage.coerce(e)));
144
144
  }
@@ -28,10 +28,11 @@ const Animate_1 = require("./Animate");
28
28
  function Popup(_a) {
29
29
  var { className, style = {}, anchor, anchorOffset = 4, placement = 'bottom', animation = 'in-out', backdrop = 'none', disabled = false, disableDismiss = false, disableOverlay = false, open = false, onOpened: onOpenedRaw = funnel_core_1.Fn.NoOp, onClose = funnel_core_1.Fn.NoOp, onClosed: onClosedRaw = funnel_core_1.Fn.NoOp, onKeyDown: onKeyDownRaw, children } = _a, props = __rest(_a, ["className", "style", "anchor", "anchorOffset", "placement", "animation", "backdrop", "disabled", "disableDismiss", "disableOverlay", "open", "onOpened", "onClose", "onClosed", "onKeyDown", "children"]);
30
30
  // bind context
31
- const id = (0, react_1.useId)();
31
+ const containerId = (0, react_1.useId)();
32
+ const backdropId = (0, react_1.useId)();
32
33
  const anchorId = typeof anchor === 'string'
33
34
  ? anchor
34
- : id;
35
+ : containerId;
35
36
  const [contentRef, contentElement] = (0, client_1.useRefElement)();
36
37
  const openRef = (0, react_1.useRef)(open);
37
38
  openRef.current = open;
@@ -44,11 +45,11 @@ function Popup(_a) {
44
45
  // lock when opened
45
46
  let unlock = undefined;
46
47
  if (open) {
47
- unlock = funnel_core_1.Browser.lockFocus(`#${CSS.escape(id)}`);
48
+ unlock = funnel_core_1.Browser.lockFocus(`#${CSS.escape(containerId)}`);
48
49
  }
49
50
  // unlock on unmount
50
51
  return () => unlock && unlock();
51
- }, [open, id]);
52
+ }, [open, containerId]);
52
53
  // skip for SSR
53
54
  if (!funnel_core_1.Browser.available) {
54
55
  return null;
@@ -78,10 +79,20 @@ function Popup(_a) {
78
79
  onClosedRef.current();
79
80
  }
80
81
  };
82
+ const onContainerClick = (e) => {
83
+ // close only if the container is directly clicked
84
+ const target = e.target;
85
+ if ((target === null || target === void 0 ? void 0 : target.id) === containerId) {
86
+ // stop bubbling
87
+ e.stopPropagation();
88
+ // close
89
+ onClose();
90
+ }
91
+ };
81
92
  const onBackdropClick = (e) => {
82
93
  // close only if the backdrop is directly clicked
83
94
  const target = e.target;
84
- if ((target === null || target === void 0 ? void 0 : target.id) === id) {
95
+ if ((target === null || target === void 0 ? void 0 : target.id) === backdropId) {
85
96
  // stop bubbling
86
97
  e.stopPropagation();
87
98
  // close
@@ -92,14 +103,15 @@ function Popup(_a) {
92
103
  const { popupContainerClassName, popupClassName, popupStyles } = getPopupClassNames({ anchor, anchorId, anchorOffset, placement });
93
104
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [anchor && typeof anchor !== 'string' &&
94
105
  (0, jsx_runtime_1.jsx)(Popup.AnchorElement, { tag: "div", anchorId: anchorId, children: anchor }), (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { mode: "wait", children: open &&
95
- (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { id: id, className: (0, classnames_1.default)(popupContainerClassName, 'fixed inset-0 z-popup', {
106
+ (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { id: containerId, className: (0, classnames_1.default)(popupContainerClassName, 'fixed inset-0 z-popup', {
96
107
  'pointer-events-none': disableOverlay
97
- }), variants: Animate_1.Animate.Variants.fade, initial: animation !== 'out' ? 'initial' : 'animate', animate: "animate", exit: animation !== 'in' ? 'exit' : 'animate', onAnimationComplete: definition => onAnimationComplete(definition), onClick: disableDismiss ? undefined : onBackdropClick, children: [backdrop !== 'none' &&
98
- (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { className: (0, classnames_1.default)('fixed inset-0 z-backdrop', {
99
- 'backdrop-blur-[9px] bg-glass/backdrop will-change-[backdrop-filter]': backdrop === 'glass'
100
- }) }, "backdrop"), (0, jsx_runtime_1.jsx)("div", Object.assign({}, props, { ref: contentRef, className: (0, classnames_1.default)(className, popupClassName, 'pointer-events-auto'), style: anchor
108
+ }), variants: Animate_1.Animate.Variants.fade, initial: animation !== 'out' ? 'initial' : 'animate', animate: "animate", exit: animation !== 'in' ? 'exit' : 'animate', onAnimationComplete: definition => onAnimationComplete(definition), onClick: disableDismiss ? undefined : onContainerClick, children: [backdrop !== 'none' &&
109
+ (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { id: backdropId, className: (0, classnames_1.default)('fixed inset-0 z-backdrop', {
110
+ 'backdrop-blur-[9px] bg-glass/backdrop will-change-[backdrop-filter]': backdrop === 'glass',
111
+ 'pointer-events-auto': !disableDismiss
112
+ }), onClick: disableDismiss ? undefined : onBackdropClick }, "backdrop"), (0, jsx_runtime_1.jsx)("div", Object.assign({}, props, { ref: contentRef, className: (0, classnames_1.default)(className, popupClassName, 'pointer-events-auto'), style: anchor
101
113
  ? Popup.getAnchorStyle(anchorId, Object.assign({ margin: `${anchorOffset !== null && anchorOffset !== void 0 ? anchorOffset : 0}px` }, popupStyles))
102
- : popupStyles, onKeyDown: onKeyDown, children: children }))] }, id) }) }), document.body)] }));
114
+ : popupStyles, onKeyDown: onKeyDown, children: children }))] }, containerId) }) }), document.body)] }));
103
115
  }
104
116
  // extension
105
117
  (function (Popup) {
@@ -41,7 +41,7 @@ function InfoPanel(_a) {
41
41
  };
42
42
  // render
43
43
  return ((0, jsx_runtime_1.jsxs)("section", { className: (0, classnames_1.default)(className, 'flex flex-col p-l7', 'bg-surface1 rounded-xxl'), children: [(0, jsx_runtime_1.jsxs)("div", { className: "shrink-0 flex items-center gap-l4", children: [status &&
44
- (0, jsx_runtime_1.jsx)(feedback_1.StatusIcon, { variant: status, size: "md" }), (0, jsx_runtime_1.jsx)("h3", { className: "flex-1 heading-sm text-content-primary ellipsis", children: title }), menu &&
44
+ (0, jsx_runtime_1.jsx)(feedback_1.StatusIcon, { variant: status, size: "md" }), (0, jsx_runtime_1.jsx)("h3", { className: "flex-1 heading-sm text-content-primary ellipsis", children: title }), menu.items.length > 0 &&
45
45
  (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(interaction_1.IconButton, { anchorId: anchorId, className: "shrink-0", icon: "EllipsisVertical", onClick: onMenuOpen }), (0, jsx_runtime_1.jsx)(interaction_1.Menu, { controller: menu, onItemClick: onMenuClick })] })] }), caption &&
46
46
  (0, jsx_runtime_1.jsx)(funnel_ui_1.Markup, { className: (0, classnames_1.default)('markup-caption mt-l6', {
47
47
  'text-destructive-content bg-destructive/tint0 p-l5 rounded-md': status === 'error'
@@ -6,7 +6,7 @@ export declare namespace Icon {
6
6
  size?: Size;
7
7
  };
8
8
  type Size = 'xl' | 'lg' | 'md' | 'sm' | 'xs' | 'xxs' | 'nav' | 'card' | Sizing;
9
- type Variant = 'Archive' | 'ArrowLeft' | 'ArrowRight' | 'ArrowLeftRight' | 'Atom' | 'Blocks' | 'Bold' | 'Check' | 'ChevronDown' | 'ChevronRight' | 'ChevronUp' | 'Circle' | 'CircleAlert' | 'CircleCheck' | 'CircleCheckBig' | 'CirclePlus' | 'CircleQuestionMark' | 'CloudCheck' | 'CloudUpload' | 'CornerDownRight' | 'EllipsisVertical' | 'Eye' | 'EyeOff' | 'File' | 'FileDown' | 'FilePlusCorner' | 'FileSearchCorner' | 'Goal' | 'Globe' | 'GripVertical' | 'HatGlasses' | 'History' | 'Highlighter' | 'Image' | 'ImageDown' | 'Info' | 'Italic' | 'Layers' | 'LayoutTemplate' | 'Link' | 'Link2' | 'List' | 'ListChecks' | 'ListIndentDecrease' | 'ListIndentIncrease' | 'ListOrdered' | 'Lock' | 'LockOpen' | 'Mail' | 'MessageSquareQuote' | 'Minus' | 'Monitor' | 'MonitorCog' | 'Moon' | 'NotebookPen' | 'Pencil' | 'Pin' | 'Plus' | 'Redo' | 'RefreshCw' | 'RotateCcw' | 'RotateCw' | 'Search' | 'SearchCode' | 'Settings' | 'Smartphone' | 'SquarePlay' | 'Star' | 'Strikethrough' | 'Subscript' | 'Sun' | 'Superscript' | 'TextAlignStart' | 'Trash' | 'TriangleAlert' | 'Trophy' | 'Underline' | 'Undo' | 'Upload' | 'UserRound' | 'X';
9
+ type Variant = 'Archive' | 'ArrowLeft' | 'ArrowRight' | 'ArrowLeftRight' | 'Atom' | 'Blocks' | 'Bold' | 'Check' | 'ChevronDown' | 'ChevronRight' | 'ChevronUp' | 'Circle' | 'CircleAlert' | 'CircleCheck' | 'CircleCheckBig' | 'CirclePlus' | 'CircleQuestionMark' | 'CloudCheck' | 'CloudUpload' | 'Copy' | 'CornerDownRight' | 'EllipsisVertical' | 'Eye' | 'EyeOff' | 'File' | 'FileDown' | 'FilePlusCorner' | 'FileSearchCorner' | 'Goal' | 'Globe' | 'GripVertical' | 'HatGlasses' | 'History' | 'Highlighter' | 'Image' | 'ImageDown' | 'Info' | 'Italic' | 'Layers' | 'LayoutTemplate' | 'Link' | 'Link2' | 'List' | 'ListChecks' | 'ListIndentDecrease' | 'ListIndentIncrease' | 'ListOrdered' | 'Lock' | 'LockOpen' | 'Mail' | 'MessageSquareQuote' | 'Minus' | 'Monitor' | 'MonitorCog' | 'Moon' | 'NotebookPen' | 'Pencil' | 'Pin' | 'Plus' | 'Redo' | 'RefreshCw' | 'RotateCcw' | 'RotateCw' | 'Search' | 'SearchCode' | 'Settings' | 'Smartphone' | 'SquarePlay' | 'Star' | 'Strikethrough' | 'Subscript' | 'Sun' | 'Superscript' | 'TextAlignStart' | 'Trash' | 'TriangleAlert' | 'Trophy' | 'Underline' | 'Undo' | 'Upload' | 'UserRound' | 'X';
10
10
  namespace Variant {
11
11
  function filter(value: any): value is Variant;
12
12
  }
@@ -37,6 +37,7 @@ function Icon({ className, variant, size: sizing = 'md' }) {
37
37
  'CircleQuestionMark',
38
38
  'CloudCheck',
39
39
  'CloudUpload',
40
+ 'Copy',
40
41
  'CornerDownRight',
41
42
  'EllipsisVertical',
42
43
  'Eye',
@@ -150,6 +151,8 @@ function getIcon(variant) {
150
151
  return lucide_react_1.CloudCheck;
151
152
  case 'CloudUpload':
152
153
  return lucide_react_1.CloudUpload;
154
+ case 'Copy':
155
+ return lucide_react_1.Copy;
153
156
  case 'CornerDownRight':
154
157
  return lucide_react_1.CornerDownRight;
155
158
  case 'EllipsisVertical':
@@ -8,8 +8,10 @@ import type { IPageRefStore } from './IPageRefStore';
8
8
  import type { ITagged } from './ITagged';
9
9
  import type { Item } from './Item';
10
10
  import type { PageSettings } from './PageSettings';
11
+ import type { PageStatus } from './PageStatus';
11
12
  import type { PageSummary } from './PageSummary';
12
13
  import type { Section } from './Section';
14
+ import { SectionBlock } from './SectionBlock';
13
15
  export interface IPage extends IAssetStore, ICollectionStore, IPageRefStore, ITagged {
14
16
  readonly template: Schema.Page;
15
17
  readonly id: Schema.Page.Id;
@@ -26,6 +28,8 @@ export interface IPage extends IAssetStore, ICollectionStore, IPageRefStore, ITa
26
28
  readonly url: string;
27
29
  readonly createdOn: number;
28
30
  readonly updatedOn: number;
31
+ readonly errors: IPage.Errors;
32
+ readonly status: PageStatus;
29
33
  readonly asRef: IPage.Ref;
30
34
  publication: number | undefined;
31
35
  slug: string | undefined;
@@ -35,23 +39,17 @@ export declare namespace IPage {
35
39
  type Content = ReadonlyArray<Block | Section>;
36
40
  type Area = 'discover' | 'content';
37
41
  type Savable = Section | Block | FieldModel;
38
- type Ref = {
42
+ type Errors = {
43
+ page: IPage;
44
+ items: Array<Block | SectionBlock>;
45
+ };
46
+ type Ref = Omit<Schema.Page.Data.AsLink, 'type' | 'tags'> & {
39
47
  template: Schema.Page;
40
- id: Schema.Page.Id;
41
- groupId: Schema.Page.GroupId;
42
- brand: string;
43
- language: Language;
44
- region: string;
45
- url: string;
46
- slug?: string;
47
- name: string;
48
48
  tags: Schema.Tag[];
49
- state: Schema.Page.State;
50
- errors: boolean;
51
- createdOn: number;
52
- updatedOn: number;
53
- publishedOn?: number;
54
49
  };
50
+ namespace Ref {
51
+ function fromData({ tags, ...data }: Schema.Page.Data.AsLink): Ref;
52
+ }
55
53
  type References = {
56
54
  pages: Ref[];
57
55
  collections: Schema.Collection.Data.AsLink[];
@@ -70,4 +68,5 @@ export declare namespace IPage {
70
68
  function filter(event: EventBus.Event): event is Event;
71
69
  function create(event: EventBus.Args<Event>): Event;
72
70
  }
71
+ function getPreviewUrl(path: string): URL;
73
72
  }
@@ -1,10 +1,30 @@
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.IPage = void 0;
4
15
  const funnel_core_1 = require("@nascentdigital/funnel-core");
5
16
  // extension
6
17
  var IPage;
7
18
  (function (IPage) {
19
+ let Ref;
20
+ (function (Ref) {
21
+ function fromData(_a) {
22
+ var { tags } = _a, data = __rest(_a, ["tags"]);
23
+ const template = funnel_core_1.Schema.Site.getPage(data.type, data.region);
24
+ return Object.assign({ template, tags: template.parseTags(tags !== null && tags !== void 0 ? tags : []) }, data);
25
+ }
26
+ Ref.fromData = fromData;
27
+ })(Ref = IPage.Ref || (IPage.Ref = {}));
8
28
  let Event;
9
29
  (function (Event) {
10
30
  // methods
@@ -17,4 +37,14 @@ var IPage;
17
37
  }
18
38
  Event.create = create;
19
39
  })(Event = IPage.Event || (IPage.Event = {}));
40
+ // helpers
41
+ function getPreviewUrl(path) {
42
+ // get base url
43
+ const url = new URL('/api/preview', window.location.href);
44
+ // apply args
45
+ url.searchParams.set('redirect', path);
46
+ // return url
47
+ return url;
48
+ }
49
+ IPage.getPreviewUrl = getPreviewUrl;
20
50
  })(IPage || (exports.IPage = IPage = {}));
@@ -3,6 +3,7 @@ import { EventBus, FieldModel, Language, Schema } from '@nascentdigital/funnel-c
3
3
  import { Observable } from 'rxjs';
4
4
  import { Asset, Block, IAssetStore, ICollectionStore, IPage, IPageRefStore, ITagged, PageSummary, Section, SectionBlock } from './';
5
5
  import { PageSettings } from './PageSettings';
6
+ import { PageStatus } from './PageStatus';
6
7
  export declare class Page implements IAssetStore, ICollectionStore, IPageRefStore, ITagged {
7
8
  readonly template: Schema.Page;
8
9
  readonly eventBus: EventBus;
@@ -82,7 +83,8 @@ export declare class Page implements IAssetStore, ICollectionStore, IPageRefStor
82
83
  get items(): Array<Block | Section>;
83
84
  get changes(): Page.Changes;
84
85
  get initialErrors(): boolean;
85
- get errors(): Page.Errors;
86
+ get errors(): IPage.Errors;
87
+ get status(): PageStatus;
86
88
  get hasErrors(): boolean;
87
89
  get asRef(): IPage.Ref;
88
90
  /**
@@ -147,10 +149,6 @@ export declare namespace Page {
147
149
  page: Page;
148
150
  items: Array<Block | Section>;
149
151
  };
150
- type Errors = {
151
- page: Page;
152
- items: Array<Block | Section>;
153
- };
154
152
  type WithSummary = {
155
153
  summary: PageSummary;
156
154
  page?: Page;
@@ -288,10 +288,17 @@ class Page {
288
288
  get errors() {
289
289
  return {
290
290
  page: this,
291
- items: this.items.filter(item => (!item.activated && item.required)
291
+ items: this.items
292
+ .filter(item => (!item.activated && item.required)
292
293
  || (item.activated && !item.valid))
294
+ .flatMap(item => item instanceof _1.Section
295
+ ? item.errors.blocks
296
+ : item)
293
297
  };
294
298
  }
299
+ get status() {
300
+ throw new funnel_core_1.NotImplementedError('The Strapi editor currently uses errors/changes for UI');
301
+ }
295
302
  get hasErrors() {
296
303
  return this.errors.items.length > 0;
297
304
  }
@@ -17,14 +17,20 @@ export declare class StaticPageOverview extends PageOverviewBase {
17
17
  readonly refs: Readonly<Record<Language, Schema.Page.Data.AsLink>>;
18
18
  readonly languages: ReadonlyArray<Language>;
19
19
  constructor({ refs, ...args }: StaticPageOverview.ConstructorArgs);
20
+ get pages(): Schema.Page.Data.AsLink<Schema.Page<Schema.Page.Content, string>, string>[];
20
21
  get isEmpty(): boolean;
21
22
  hasLanguage(language: Language): boolean;
23
+ findPage({ region, language }: StaticPageOverview.FindPageArgs): Schema.Page.Data.AsLink | undefined;
22
24
  getClosestPageRef(language: Language, fallback?: Language): IPage.Ref | undefined;
23
25
  }
24
26
  export declare namespace StaticPageOverview {
25
27
  type ConstructorArgs = Omit<PageOverviewBase.ConstructorArgs, 'variant'> & {
26
28
  refs: Record<Language, Schema.Page.Data.AsLink>;
27
29
  };
30
+ type FindPageArgs = {
31
+ region: string;
32
+ language?: Language;
33
+ };
28
34
  }
29
35
  export declare class DynamicPageOverview extends PageOverviewBase {
30
36
  readonly count: number;
@@ -32,12 +32,29 @@ class StaticPageOverview extends PageOverviewBase {
32
32
  this.refs = refs;
33
33
  this.languages = Object.keys(refs).map(funnel_core_1.Language.parse);
34
34
  }
35
+ get pages() {
36
+ return Object.values(this.refs);
37
+ }
35
38
  get isEmpty() {
36
39
  return this.languages.length === 0;
37
40
  }
38
41
  hasLanguage(language) {
39
42
  return this.languages.includes(language);
40
43
  }
44
+ findPage({ region, language }) {
45
+ var _a;
46
+ // narrow down to region
47
+ const pages = this.pages.filter(page => page.region === region);
48
+ // return exact match (if any) if a language is provided
49
+ if (language) {
50
+ return pages.find(page => page.language === language);
51
+ }
52
+ // or pick the best match
53
+ else {
54
+ const { defaultLanguage } = funnel_core_1.AppConfig.brandConfig().regionalization.regions[region];
55
+ return (_a = pages.find(page => page.language === defaultLanguage)) !== null && _a !== void 0 ? _a : pages[0];
56
+ }
57
+ }
41
58
  getClosestPageRef(language, fallback) {
42
59
  var _a, _b;
43
60
  const { template, languages, refs } = this;
@@ -1,15 +1,14 @@
1
1
  import { Language, Schema } from '@nascentdigital/funnel-core';
2
2
  import { Observable } from 'rxjs';
3
- import { EditorApiClient } from '../client';
3
+ import { IPageRepository } from '../repository';
4
4
  import { IPageRefStore } from './IPageRefStore';
5
5
  import { IPage } from './IPage';
6
6
  export declare class PageRefStoreProxy implements IPageRefStore {
7
+ readonly pageRepository: IPageRepository;
7
8
  readonly language: Language;
8
9
  private _parentStore;
9
10
  private readonly _pages;
10
- private readonly _pageIds;
11
11
  private readonly _syncing$;
12
- private readonly _editorApi;
13
12
  constructor(args: PageRefStoreProxy.ConstructorArgs);
14
13
  get syncing(): boolean;
15
14
  get stable$(): Observable<boolean>;
@@ -22,10 +21,9 @@ export declare class PageRefStoreProxy implements IPageRefStore {
22
21
  }
23
22
  export declare namespace PageRefStoreProxy {
24
23
  type ConstructorArgs = {
25
- editorApi: EditorApiClient;
26
- parent?: IPageRefStore;
24
+ pageRepository: IPageRepository;
27
25
  language: Language;
26
+ parent?: IPageRefStore;
28
27
  pages?: ReadonlyArray<IPage.Ref>;
29
- pageIds?: ReadonlyArray<Schema.Page.Id>;
30
28
  };
31
29
  }
@@ -1,15 +1,4 @@
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
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.PageRefStoreProxy = void 0;
15
4
  const funnel_core_1 = require("@nascentdigital/funnel-core");
@@ -18,12 +7,13 @@ const rxjs_1 = require("rxjs");
18
7
  class PageRefStoreProxy {
19
8
  constructor(args) {
20
9
  var _a;
10
+ this.pageRepository = args.pageRepository;
21
11
  this.language = args.language;
22
12
  this._parentStore = args.parent;
23
- this._editorApi = args.editorApi;
24
- this._pages = [...(_a = args.pages) !== null && _a !== void 0 ? _a : []];
25
- this._pageIds = new Set(args.pageIds);
26
13
  this._syncing$ = new rxjs_1.BehaviorSubject(true);
14
+ // set current pages
15
+ this._pages = new Map();
16
+ (_a = args.pages) === null || _a === void 0 ? void 0 : _a.forEach(page => this._pages.set(page.id, page));
27
17
  }
28
18
  get syncing() {
29
19
  return this._syncing$.getValue();
@@ -39,26 +29,19 @@ class PageRefStoreProxy {
39
29
  return this;
40
30
  }
41
31
  async load(pageIds) {
42
- // merge in potentially new ids
43
- pageIds === null || pageIds === void 0 ? void 0 : pageIds.forEach(id => this._pageIds.add(id));
44
- // get ids with no references
45
- const missingIds = Array.from(this._pageIds).filter(id => !this.getPageRef(id));
46
- // bail if no loading needed
47
- if (missingIds.length === 0) {
32
+ // determine pages that need to be fetched
33
+ const pageIdsRequested = new Set(pageIds);
34
+ const loadedPageIds = new Set(this._pages.keys());
35
+ const pageIdsToFetch = pageIdsRequested.difference(loadedPageIds);
36
+ // bail if no fetching needed
37
+ if (pageIdsToFetch.size === 0) {
48
38
  this._syncing$.next(false);
49
39
  return;
50
40
  }
51
41
  // fetch missing page refs
52
- const pageLinks = await this._editorApi.getPageSummaries({ ids: missingIds, version: 'draft' });
53
- const pageRefs = pageLinks.map((_a) => {
54
- var { tags } = _a, page = __rest(_a, ["tags"]);
55
- // get page template/schema
56
- const template = funnel_core_1.Schema.Site.getPage(page.type, page.region);
57
- // return page ref
58
- return Object.assign(Object.assign({ template }, page), { tags: template.tags.flatMap(tagGroup => tagGroup.parse(tags)) });
59
- });
42
+ const refs = await this.pageRepository.getSummaries({ ids: [...pageIdsToFetch], version: 'draft' });
60
43
  // add to store
61
- this._pages.push(...pageRefs);
44
+ refs.forEach(ref => this._pages.set(ref.id, ref));
62
45
  // signal syncing is finished
63
46
  this._syncing$.next(false);
64
47
  }
@@ -69,7 +52,7 @@ class PageRefStoreProxy {
69
52
  return undefined;
70
53
  }
71
54
  // first try looking in current store
72
- const pageRef = this._pages.find(ref => ref.id === pageId);
55
+ const pageRef = this._pages.get(pageId);
73
56
  if (pageRef) {
74
57
  return pageRef;
75
58
  }
@@ -87,32 +70,15 @@ class PageRefStoreProxy {
87
70
  // return
88
71
  // }
89
72
  // replace ref if it exists
90
- const { _pages } = this;
91
- const pageId = page.id;
92
- const refIndex = _pages.findIndex(ref => ref.id === pageId);
93
- if (refIndex >= 0) {
94
- _pages[refIndex] = page;
95
- }
96
- // or add ref
97
- else {
98
- _pages.push(page);
99
- }
73
+ this._pages.set(page.id, page);
100
74
  }
101
75
  removePageRef(pageId) {
102
76
  // try to remove from parent first
103
77
  // if (this._parentStore?.removePageRef(pageId)) {
104
78
  // return true
105
79
  // }
106
- // skip if file isn't there
107
- const { _pages } = this;
108
- const refIndex = _pages.findIndex(ref => ref.id === pageId);
109
- if (refIndex < 0) {
110
- return false;
111
- }
112
- // remove file
113
- _pages.splice(refIndex, 1);
114
- // indicate success
115
- return true;
80
+ // remove page
81
+ return this._pages.delete(pageId);
116
82
  }
117
83
  }
118
84
  exports.PageRefStoreProxy = PageRefStoreProxy;
@@ -0,0 +1,28 @@
1
+ export type PageStatus = {
2
+ published: boolean;
3
+ content: Array<PageStatus.ForBlock | PageStatus.ForSection>;
4
+ };
5
+ export declare namespace PageStatus {
6
+ type ForPageItem = {
7
+ identifier: string;
8
+ name: string;
9
+ valid: boolean;
10
+ };
11
+ type ForBlock = ForPageItem & {
12
+ type: 'block';
13
+ required: boolean;
14
+ status: ForBlock.Status;
15
+ };
16
+ namespace ForBlock {
17
+ type Status = 'new' | 'modified' | 'unchanged';
18
+ }
19
+ type ForSection = ForPageItem & {
20
+ type: 'section';
21
+ min: number;
22
+ items: ForBlock[];
23
+ status: ForSection.Status;
24
+ };
25
+ namespace ForSection {
26
+ type Status = 'modified' | 'unchanged';
27
+ }
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });