@nascentdigital/funnel-editor 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.
Files changed (62) hide show
  1. package/dist/components.d.ts +1 -0
  2. package/dist/components.js +1 -0
  3. package/dist/core/components/fields/OptInField.js +42 -2
  4. package/dist/core/components/fields/asset/AssetEditor.d.ts +1 -2
  5. package/dist/core/components/fields/asset/AssetEditor.js +18 -6
  6. package/dist/core/components/fields/asset/AssetUploader.d.ts +1 -2
  7. package/dist/core/components/fields/asset/AssetUploader.js +18 -6
  8. package/dist/core/components/fields/collection/CollectionEditor.d.ts +2 -1
  9. package/dist/core/components/fields/collection/CollectionEditor.js +17 -3
  10. package/dist/core/components/fields/embed/EmbeddedVideoEditor.d.ts +2 -2
  11. package/dist/core/components/fields/embed/EmbeddedVideoEditor.js +17 -5
  12. package/dist/core/components/fields/factories/AssetFactory.d.ts +3 -3
  13. package/dist/core/components/fields/factories/AssetFactory.js +18 -13
  14. package/dist/core/components/fields/factories/CollectionFactory.d.ts +3 -3
  15. package/dist/core/components/fields/factories/CollectionFactory.js +20 -13
  16. package/dist/core/components/fields/factories/EmbeddedVideoFactory.d.ts +3 -3
  17. package/dist/core/components/fields/factories/EmbeddedVideoFactory.js +17 -8
  18. package/dist/core/components/fields/factories/FieldValueFactory.d.ts +7 -5
  19. package/dist/core/components/fields/factories/FieldValueFactory.js +49 -12
  20. package/dist/core/components/fields/factories/LinkFactory.d.ts +3 -3
  21. package/dist/core/components/fields/factories/LinkFactory.js +17 -8
  22. package/dist/core/components/fields/factories/MediaFactory.d.ts +3 -3
  23. package/dist/core/components/fields/factories/MediaFactory.js +105 -149
  24. package/dist/core/components/fields/factories/ObjectFactory.d.ts +3 -2
  25. package/dist/core/components/fields/factories/ObjectFactory.js +16 -2
  26. package/dist/core/components/fields/factories/TextFactory.d.ts +3 -3
  27. package/dist/core/components/fields/factories/TextFactory.js +16 -10
  28. package/dist/core/components/fields/link/LinkEditor.d.ts +2 -2
  29. package/dist/core/components/fields/link/LinkEditor.js +18 -6
  30. package/dist/core/components/fields/media/MediaEditor.d.ts +2 -3
  31. package/dist/core/components/fields/media/MediaEditor.js +40 -11
  32. package/dist/core/components/fields/media/index.d.ts +0 -1
  33. package/dist/core/components/fields/media/index.js +0 -1
  34. package/dist/core/components/fields/object/ObjectEditor.d.ts +2 -1
  35. package/dist/core/components/fields/object/ObjectEditor.js +15 -1
  36. package/dist/core/components/interaction/Popup.d.ts +11 -7
  37. package/dist/core/components/interaction/Popup.js +8 -6
  38. package/dist/core/components/interaction/QuickInput.d.ts +2 -4
  39. package/dist/core/components/interaction/QuickInput.js +6 -2
  40. package/dist/core/components/interaction/menu/Menu.d.ts +8 -19
  41. package/dist/core/components/interaction/menu/Menu.js +26 -60
  42. package/dist/core/components/interaction/menu/useMenuController.d.ts +4 -2
  43. package/dist/core/components/interaction/menu/useMenuController.js +4 -1
  44. package/dist/core/domain/CollectionFieldProxy.js +1 -1
  45. package/dist/core/domain/Collections.js +0 -2
  46. package/dist/core/domain/ICollection.d.ts +1 -0
  47. package/dist/core/domain/IPage.d.ts +2 -1
  48. package/dist/core/domain/Site.js +0 -2
  49. package/dist/core/hooks/useCollectionRepository.d.ts +1 -1
  50. package/dist/core/hooks/useCollections.js +4 -0
  51. package/dist/core/hooks/usePageRepository.d.ts +1 -1
  52. package/dist/core/hooks/useSite.js +4 -0
  53. package/dist/core/repository/CollectionRepository.d.ts +2 -2
  54. package/dist/core/repository/ICollectionRepository.d.ts +2 -3
  55. package/dist/core/repository/SerializeCollectionUpdate.d.ts +5 -5
  56. package/dist/core/repository/SerializePageUpdate.d.ts +7 -8
  57. package/dist/core/splash/SplashContainer.d.ts +4 -2
  58. package/dist/core/splash/SplashContainer.js +3 -3
  59. package/dist/styles/index.css +8 -8
  60. package/package.json +2 -2
  61. package/dist/core/components/fields/media/MediaPicker.d.ts +0 -15
  62. package/dist/core/components/fields/media/MediaPicker.js +0 -251
@@ -1,4 +1,15 @@
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.FieldValueFactory = FieldValueFactory;
4
15
  const jsx_runtime_1 = require("react/jsx-runtime");
@@ -14,46 +25,72 @@ const ObjectFactory_1 = require("./ObjectFactory");
14
25
  const PageFactory_1 = require("./PageFactory");
15
26
  const TextFactory_1 = require("./TextFactory");
16
27
  // factory
17
- function FieldValueFactory({ anchor, itemSchema, field, onCommit = funnel_core_1.Fn.NoOp, onCancel = funnel_core_1.Fn.NoOp }) {
18
- var _a, _b, _c, _d, _e, _f, _g;
28
+ function FieldValueFactory(_a) {
29
+ var _b, _c, _d, _e, _f, _g, _h;
30
+ var { itemSchema, field, onCommit = funnel_core_1.Fn.NoOp, onCancel = funnel_core_1.Fn.NoOp } = _a, popupProps = __rest(_a, ["itemSchema", "field", "onCommit", "onCancel"]);
19
31
  // bind language
20
32
  const brandConfig = funnel_core_1.AppConfig.brandConfig();
21
33
  const page = (0, hooks_1.usePossiblePage)();
22
34
  const collection = (0, hooks_1.usePossibleCollection)();
23
- const region = (_a = page === null || page === void 0 ? void 0 : page.region) !== null && _a !== void 0 ? _a : funnel_core_1.RegionsConfig.getDefaultRegion(brandConfig.regionalization);
24
- const language = (_c = (_b = page === null || page === void 0 ? void 0 : page.language) !== null && _b !== void 0 ? _b : collection === null || collection === void 0 ? void 0 : collection.language) !== null && _c !== void 0 ? _c : funnel_core_1.RegionsConfig.getDefaultLanguage(brandConfig.regionalization);
35
+ const region = (_b = page === null || page === void 0 ? void 0 : page.region) !== null && _b !== void 0 ? _b : funnel_core_1.RegionsConfig.getDefaultRegion(brandConfig.regionalization);
36
+ const language = (_d = (_c = page === null || page === void 0 ? void 0 : page.language) !== null && _c !== void 0 ? _c : collection === null || collection === void 0 ? void 0 : collection.language) !== null && _d !== void 0 ? _d : funnel_core_1.RegionsConfig.getDefaultLanguage(brandConfig.regionalization);
25
37
  const commit = (item) => {
26
38
  onCommit(item);
27
39
  };
28
40
  const cancel = () => {
29
41
  onCancel();
30
42
  };
43
+ console.debug('[FieldValueFactory] creating field', { field, itemSchema });
31
44
  // handle based on item type
32
45
  switch (itemSchema.type) {
33
46
  case 'text':
34
- return ((0, jsx_runtime_1.jsx)(TextFactory_1.TextFactory, { schema: itemSchema, initialValue: field === null || field === void 0 ? void 0 : field.value, anchor: anchor, onCommit: item => commit(item), onCancel: cancel }));
47
+ return ((0, jsx_runtime_1.jsx)(TextFactory_1.TextFactory, Object.assign({ schema: itemSchema, initialValue: field === null || field === void 0 ? void 0 : field.value, onCommit: item => commit(item), onCancel: cancel }, popupProps)));
35
48
  case 'link':
36
- return ((0, jsx_runtime_1.jsx)(LinkFactory_1.LinkFactory, { schema: itemSchema, initialValue: field === null || field === void 0 ? void 0 : field.value, region: region, language: language, anchor: anchor, onCommit: item => commit(item), onCancel: cancel }));
49
+ return ((0, jsx_runtime_1.jsx)(LinkFactory_1.LinkFactory, Object.assign({ schema: itemSchema, initialValue: field === null || field === void 0 ? void 0 : field.value, region: region, language: language, onCommit: item => commit(item), onCancel: cancel }, popupProps)));
37
50
  case 'embedded.video':
38
- return ((0, jsx_runtime_1.jsx)(EmbeddedVideoFactory_1.EmbeddedVideoFactory, { schema: itemSchema, initialValue: field === null || field === void 0 ? void 0 : field.value, language: language, anchor: anchor, onCommit: item => commit(item), onCancel: cancel }));
51
+ return ((0, jsx_runtime_1.jsx)(EmbeddedVideoFactory_1.EmbeddedVideoFactory, Object.assign({ schema: itemSchema, initialValue: field === null || field === void 0 ? void 0 : field.value, language: language, onCommit: item => commit(item), onCancel: cancel }, popupProps)));
39
52
  case 'asset': {
40
- return ((0, jsx_runtime_1.jsx)(AssetFactory_1.AssetFactory, { schema: itemSchema, assetId: (_e = (_d = field === null || field === void 0 ? void 0 : field.value) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.id, anchor: anchor, onCommit: item => commit(item), onCancel: cancel }));
53
+ return ((0, jsx_runtime_1.jsx)(AssetFactory_1.AssetFactory, Object.assign({ schema: itemSchema, assetId: (_f = (_e = field === null || field === void 0 ? void 0 : field.value) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.id, onCommit: item => commit(item), onCancel: cancel }, popupProps)));
41
54
  }
42
55
  case 'page':
43
- return ((0, jsx_runtime_1.jsx)(PageFactory_1.PageFactory, { schema: itemSchema, region: region, language: language, onCommit: item => commit(item), onCancel: cancel }));
56
+ return ((0, jsx_runtime_1.jsx)(PageFactory_1.PageFactory, Object.assign({ schema: itemSchema, region: region, language: language, onCommit: item => commit(item), onCancel: cancel }, popupProps)));
44
57
  case 'collection':
45
58
  // custom handling for media
46
59
  if (funnel_ui_1.Media.Schema.filter(itemSchema)) {
47
- return ((0, jsx_runtime_1.jsx)(MediaFactory_1.MediaFactory, { schema: itemSchema, language: language, media: (_f = field === null || field === void 0 ? void 0 : field.value) === null || _f === void 0 ? void 0 : _f.value, anchor: anchor, onCommit: item => commit(funnel_core_1.Schema.CollectionField.Value.toData(item)), onCancel: cancel }));
60
+ console.debug('[FieldValueFactory] creating factory for MediaFactory');
61
+ return ((0, jsx_runtime_1.jsx)(MediaFactory_1.MediaFactory, Object.assign({ schema: itemSchema, language: language, media: (_g = field === null || field === void 0 ? void 0 : field.value) === null || _g === void 0 ? void 0 : _g.value, onCommit: item => commit(funnel_core_1.Schema.CollectionField.Value.toData(item)), onCancel: cancel }, popupProps)));
48
62
  }
49
63
  // or generic collection
50
64
  else {
51
- return ((0, jsx_runtime_1.jsx)(CollectionFactory_1.CollectionFactory, { schema: itemSchema, language: language, collection: (_g = field === null || field === void 0 ? void 0 : field.value) === null || _g === void 0 ? void 0 : _g.value, anchor: anchor, onCommit: item => commit(item), onCancel: cancel }));
65
+ return ((0, jsx_runtime_1.jsx)(CollectionFactory_1.CollectionFactory, Object.assign({ schema: itemSchema, language: language, collection: (_h = field === null || field === void 0 ? void 0 : field.value) === null || _h === void 0 ? void 0 : _h.value, onCommit: item => commit(item), onCancel: cancel }, popupProps)));
52
66
  }
53
67
  case 'object':
54
- return ((0, jsx_runtime_1.jsx)(ObjectFactory_1.ObjectFactory, { schema: itemSchema, field: field, onCommit: item => commit(item), onCancel: cancel }));
68
+ return ((0, jsx_runtime_1.jsx)(ObjectFactory_1.ObjectFactory, Object.assign({ schema: itemSchema, field: field, onCommit: item => commit(item), onCancel: cancel }, popupProps)));
55
69
  default:
56
70
  console.debug('[FieldValueFactory] no support for ', itemSchema);
57
71
  return null;
58
72
  }
59
73
  }
74
+ // extension
75
+ (function (FieldValueFactory) {
76
+ // helpers
77
+ function isCompatibleField(field) {
78
+ // skip if field isn't there
79
+ if (!field) {
80
+ return false;
81
+ }
82
+ // or accept if it's an object
83
+ switch (field.schema.type) {
84
+ case 'link':
85
+ case 'embedded.video':
86
+ case 'asset':
87
+ case 'page':
88
+ case 'collection':
89
+ case 'object':
90
+ return true;
91
+ default:
92
+ return false;
93
+ }
94
+ }
95
+ FieldValueFactory.isCompatibleField = isCompatibleField;
96
+ })(FieldValueFactory || (exports.FieldValueFactory = FieldValueFactory = {}));
@@ -1,12 +1,12 @@
1
1
  import { Callback, Language, Schema } from '@nascentdigital/funnel-core';
2
- export declare function LinkFactory({ schema, initialValue, region, language, anchor, onCommit, onCancel }: LinkFactory.Props): import("react/jsx-runtime").JSX.Element;
2
+ import { Popup } from '../../interaction';
3
+ export declare function LinkFactory({ schema, initialValue, region, language, onCommit, onCancel, ...popupProps }: LinkFactory.Props): import("react/jsx-runtime").JSX.Element;
3
4
  export declare namespace LinkFactory {
4
- type Props = {
5
+ type Props = Popup.Props.Delegated & {
5
6
  schema: Schema.LinkField;
6
7
  initialValue?: Schema.Field.Data<Schema.LinkField>;
7
8
  region: string;
8
9
  language: Language;
9
- anchor: string;
10
10
  onCommit: Callback<Schema.Field.Data<Schema.LinkField>>;
11
11
  onCancel: Callback.Void;
12
12
  };
@@ -1,15 +1,27 @@
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.LinkFactory = LinkFactory;
4
15
  const jsx_runtime_1 = require("react/jsx-runtime");
5
16
  const react_1 = require("react");
6
17
  const link_1 = require("../link");
7
18
  // component
8
- function LinkFactory({ schema, initialValue, region, language, anchor, onCommit, onCancel }) {
19
+ function LinkFactory(_a) {
20
+ var { schema, initialValue, region, language, onCommit, onCancel } = _a, popupProps = __rest(_a, ["schema", "initialValue", "region", "language", "onCommit", "onCancel"]);
9
21
  // bind refs
10
22
  const editorRef = (0, react_1.useRef)(null);
11
- const anchorRef = (0, react_1.useRef)(anchor);
12
- anchorRef.current = anchor;
23
+ const popupPropsRef = (0, react_1.useRef)(popupProps);
24
+ popupPropsRef.current = popupProps;
13
25
  const onCommitRef = (0, react_1.useRef)(onCommit);
14
26
  onCommitRef.current = onCommit;
15
27
  const onCancelRef = (0, react_1.useRef)(onCancel);
@@ -20,11 +32,8 @@ function LinkFactory({ schema, initialValue, region, language, anchor, onCommit,
20
32
  const onEdit = async () => {
21
33
  var _a;
22
34
  // start editor (cancel if dismissed)
23
- const value = await ((_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.edit({
24
- schema,
25
- initialValue,
26
- anchor: anchorRef.current
27
- }));
35
+ const value = await ((_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.edit(Object.assign({ schema,
36
+ initialValue }, (popupPropsRef.current))));
28
37
  if (!value) {
29
38
  onCancelRef.current();
30
39
  }
@@ -1,12 +1,12 @@
1
1
  import { Callback, Language } from '@nascentdigital/funnel-core';
2
2
  import { Media } from '@nascentdigital/funnel-ui';
3
- export declare function MediaFactory({ schema, language, media: initialValue, anchor, onCommit: onCommitRaw, onCancel: onCancelRaw }: MediaFactory.Props): import("react/jsx-runtime").JSX.Element;
3
+ import { Popup } from '../../interaction';
4
+ export declare function MediaFactory({ schema, language, media: initialValue, onCommit: onCommitRaw, onCancel: onCancelRaw, ...popupProps }: MediaFactory.Props): import("react/jsx-runtime").JSX.Element;
4
5
  export declare namespace MediaFactory {
5
- type Props = {
6
+ type Props = Popup.Props.Delegated & {
6
7
  schema: Media.Schema;
7
8
  language: Language;
8
9
  media?: Media.Value;
9
- anchor: string;
10
10
  onCommit: Callback<Media.Value>;
11
11
  onCancel: Callback.Void;
12
12
  };
@@ -1,4 +1,15 @@
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.MediaFactory = MediaFactory;
4
15
  const jsx_runtime_1 = require("react/jsx-runtime");
@@ -10,64 +21,54 @@ const asset_1 = require("../asset");
10
21
  const embed_1 = require("../embed");
11
22
  const media_1 = require("../media");
12
23
  // component
13
- function MediaFactory({ schema, language, media: initialValue, anchor, onCommit: onCommitRaw, onCancel: onCancelRaw }) {
24
+ function MediaFactory(_a) {
25
+ var { schema, language, media: initialValue, onCommit: onCommitRaw, onCancel: onCancelRaw } = _a, popupProps = __rest(_a, ["schema", "language", "media", "onCommit", "onCancel"]);
14
26
  // bind refs
15
27
  const menu = (0, interaction_1.useMenuController)();
16
- const pickerRef = (0, react_1.useRef)(null);
17
28
  const editorRef = (0, react_1.useRef)(null);
18
29
  const assetPickerRef = (0, react_1.useRef)(null);
19
30
  const assetUploaderRef = (0, react_1.useRef)(null);
20
31
  const embeddedVideoEditorRef = (0, react_1.useRef)(null);
21
- const anchorRef = (0, react_1.useRef)(anchor);
22
- anchorRef.current = anchor;
32
+ const popupPropsRef = (0, react_1.useRef)(popupProps);
33
+ popupPropsRef.current = popupProps;
23
34
  const onCommitRef = (0, react_1.useRef)(onCommitRaw);
24
35
  onCommitRef.current = onCommitRaw;
25
36
  const onCancelRef = (0, react_1.useRef)(onCancelRaw);
26
37
  onCancelRef.current = onCancelRaw;
27
38
  const collectionOptions = schema.collections;
39
+ const getPickerArgs = (0, react_1.useCallback)(() => {
40
+ var _a, _b, _c;
41
+ return ({
42
+ assetPicker: (_a = assetPickerRef.current) !== null && _a !== void 0 ? _a : undefined,
43
+ assetUploader: (_b = assetUploaderRef.current) !== null && _b !== void 0 ? _b : undefined,
44
+ embeddedVideoEditor: (_c = embeddedVideoEditorRef.current) !== null && _c !== void 0 ? _c : undefined,
45
+ popupProps: popupPropsRef.current
46
+ });
47
+ }, []);
28
48
  // open menu when bound
29
49
  (0, react_1.useEffect)(() => {
50
+ console.debug('[MediaFactory] mounting media factory for', { schema, collectionOptions, initialValue });
30
51
  // open menu if new
52
+ const popupProps = popupPropsRef.current;
31
53
  if (!initialValue) {
32
54
  menu.items = mediaMenuOption;
33
- menu.open(anchorRef.current);
55
+ menu.open(popupProps.anchor);
34
56
  }
35
57
  // or open editor
36
58
  else {
37
59
  // blow up if editor isn't available (shouldn't happen)
38
60
  const editor = editorRef.current;
39
- const anchor = anchorRef.current;
40
61
  if (!editor) {
41
62
  throw new funnel_core_1.IllegalStateError('Unable to resolve reference to MediaEditor');
42
63
  }
43
64
  // start picker (cancel if nothing was picked
44
- editor.edit({
45
- schema,
46
- target: { type: 'media', media: initialValue },
47
- anchor
48
- })
65
+ editor.edit(Object.assign({ schema, target: { type: 'media', media: initialValue } }, popupProps))
49
66
  .then(async (media) => {
50
- var _a;
51
67
  console.debug('[MediaFactory/onEdit] editing completed', media);
52
68
  // cancel if there's no media
53
69
  if (!media) {
54
70
  onCancelRef.current();
55
71
  }
56
- // or switch to picker
57
- else if (media === 'pick') {
58
- // start picker (cancel if nothing was picked
59
- const media = await ((_a = pickerRef.current) === null || _a === void 0 ? void 0 : _a.pick({ schema }));
60
- if (!media) {
61
- onCancelRef.current();
62
- }
63
- // otherwise, return result
64
- else {
65
- onCommitRef.current({
66
- id: media.id,
67
- type: media.template.type
68
- });
69
- }
70
- }
71
72
  // or commit change
72
73
  else {
73
74
  onCommitRef.current(media);
@@ -80,132 +81,27 @@ function MediaFactory({ schema, language, media: initialValue, anchor, onCommit:
80
81
  const onEdit = async (target) => {
81
82
  var _a;
82
83
  // start picker (cancel if nothing was picked
83
- const media = await ((_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.edit({
84
- schema,
85
- target,
86
- anchor
87
- }));
84
+ const media = await ((_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.edit(Object.assign({ schema,
85
+ target }, (popupPropsRef.current))));
88
86
  // stop if cancelled
89
87
  if (!media) {
90
88
  onCancel();
91
89
  }
92
- // or switch to picker
93
- else if (media === 'pick') {
94
- // pick media
95
- const pick = await onPickMedia();
96
- // cancel if nothing got picked
97
- if (!pick) {
98
- onCancel();
99
- }
100
- // or commit selection
101
- else {
102
- onCommit({
103
- id: pick.id,
104
- type: pick.template.type
105
- });
106
- }
107
- }
108
90
  // otherwise, return result
109
91
  else {
110
92
  onCommit(media);
111
93
  }
112
94
  };
113
- const onPickMedia = async () => {
114
- var _a;
115
- // start picker (cancel if nothing was picked
116
- const media = await ((_a = pickerRef.current) === null || _a === void 0 ? void 0 : _a.pick({ schema }));
117
- return media !== null && media !== void 0 ? media : undefined;
118
- };
119
- const onUploadAsset = async () => {
120
- var _a;
121
- // launch uploader (or skip if there's no result)
122
- const result = await ((_a = assetUploaderRef.current) === null || _a === void 0 ? void 0 : _a.upload({
123
- schema: mediaUploadSchema,
124
- anchor
125
- }));
126
- if (!result) {
127
- return undefined;
128
- }
129
- // or switch to picking
130
- else if (result === 'pick') {
131
- return onPickAsset();
132
- }
133
- // create new image media
134
- const { value: asset } = result;
135
- if (funnel_core_1.Schema.AssetField.LinkedValue.Image.filter(asset)) {
136
- console.debug('[MediaFactory] creating new image media');
137
- return asset;
138
- }
139
- // or create new video media
140
- else if (funnel_core_1.Schema.AssetField.LinkedValue.Video.filter(asset)) {
141
- console.debug('[MediaFactory] creating new video media');
142
- return asset;
143
- }
144
- // or abort
145
- else {
146
- return undefined;
147
- }
148
- };
149
- const onPickAsset = async () => {
150
- var _a;
151
- // launch picker (or cancel if nothing is selected)
152
- const result = await ((_a = assetPickerRef.current) === null || _a === void 0 ? void 0 : _a.pick({
153
- schema: mediaUploadSchema
154
- }));
155
- if (!result) {
156
- return undefined;
157
- }
158
- // or launch uploader if the directive was received
159
- else if (result === 'upload') {
160
- return onUploadAsset();
161
- }
162
- // create new image media
163
- const { value: asset } = result;
164
- if (funnel_core_1.Schema.AssetField.LinkedValue.Image.filter(asset)) {
165
- console.debug('[MediaFactory] creating new image media');
166
- return asset;
167
- }
168
- // or create new video media
169
- else if (funnel_core_1.Schema.AssetField.LinkedValue.Video.filter(asset)) {
170
- console.debug('[MediaFactory] creating new video media');
171
- return asset;
172
- }
173
- // or abort
174
- else {
175
- return undefined;
176
- }
177
- };
178
- const onLinkVideo = async () => {
179
- var _a, _b;
180
- // start editor (cancel if dismissed)
181
- const value = await ((_a = embeddedVideoEditorRef.current) === null || _a === void 0 ? void 0 : _a.edit({
182
- schema: funnel_ui_1.Media.Video.Source.schema.content.remote.schema,
183
- anchor: anchorRef.current
184
- }));
185
- return (_b = value === null || value === void 0 ? void 0 : value.value) !== null && _b !== void 0 ? _b : undefined;
186
- };
187
95
  const onMenuSelect = async (option) => {
188
96
  // process based on option
97
+ const pickerArgs = getPickerArgs();
189
98
  switch (option) {
190
- case 'pick': {
191
- // pick media (or cancel if nothing was picked)
192
- const media = await onPickMedia();
193
- if (!media) {
194
- onCancel();
195
- }
196
- // or commit
197
- else {
198
- onCommitRef.current({
199
- id: media.id,
200
- type: media.template.type
201
- });
202
- }
203
- // stop processing
204
- break;
205
- }
99
+ case 'pick.asset':
206
100
  case 'add.asset': {
207
101
  // get visual (or cancel)
208
- const asset = await onUploadAsset();
102
+ const asset = option === 'pick.asset'
103
+ ? await pickAsset(pickerArgs)
104
+ : await uploadAsset(pickerArgs);
209
105
  if (!asset) {
210
106
  onCancel();
211
107
  break;
@@ -219,7 +115,7 @@ function MediaFactory({ schema, language, media: initialValue, anchor, onCommit:
219
115
  }
220
116
  case 'add.url': {
221
117
  // link video (or cancel)
222
- const video = await onLinkVideo();
118
+ const video = await linkVideo(pickerArgs);
223
119
  if (!video) {
224
120
  onCancel();
225
121
  break;
@@ -234,23 +130,83 @@ function MediaFactory({ schema, language, media: initialValue, anchor, onCommit:
234
130
  const onCommit = (media) => onCommitRef.current(media);
235
131
  const onCancel = () => onCancelRef.current();
236
132
  // render
237
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(interaction_1.Menu, { controller: menu, onItemClick: onMenuSelect, onClose: onCancel }), (0, jsx_runtime_1.jsx)(media_1.MediaPicker, { ref: pickerRef, language: language }), (0, jsx_runtime_1.jsx)(media_1.MediaEditor, { ref: editorRef, language: language }), (0, jsx_runtime_1.jsx)(asset_1.AssetUploader, { ref: assetUploaderRef }), (0, jsx_runtime_1.jsx)(asset_1.AssetPicker, { ref: assetPickerRef }), (0, jsx_runtime_1.jsx)(embed_1.EmbeddedVideoEditor, { ref: embeddedVideoEditorRef, language: language })] }));
133
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(interaction_1.Menu, Object.assign({ controller: menu, onItemClick: onMenuSelect, onClose: onCancel }, popupProps)), (0, jsx_runtime_1.jsx)(media_1.MediaEditor, { ref: editorRef, language: language }), (0, jsx_runtime_1.jsx)(asset_1.AssetUploader, { ref: assetUploaderRef }), (0, jsx_runtime_1.jsx)(asset_1.AssetPicker, { ref: assetPickerRef }), (0, jsx_runtime_1.jsx)(embed_1.EmbeddedVideoEditor, { ref: embeddedVideoEditorRef, language: language })] }));
238
134
  }
239
135
  const mediaMenuOption = [
240
136
  {
241
- id: 'pick',
242
- label: 'Use existing media',
243
- icon: 'FileSearchCorner'
137
+ id: 'pick.asset',
138
+ label: 'Select from library',
139
+ icon: 'Image'
244
140
  },
245
141
  {
246
142
  id: 'add.asset',
247
- label: 'Upload new asset',
248
- icon: 'ImageDown'
143
+ label: 'Upload asset',
144
+ icon: 'Upload'
249
145
  },
250
146
  {
251
147
  id: 'add.url',
252
- label: 'Link to Video',
253
- icon: 'Link2'
148
+ label: 'Add video link',
149
+ icon: 'Link'
254
150
  }
255
151
  ];
256
- const mediaUploadSchema = funnel_core_1.Schema.Field.visual({ name: 'Image or Video' });
152
+ const mediaAssetSchema = funnel_core_1.Schema.Field.visual({ name: 'Image or Video' });
153
+ async function uploadAsset(args) {
154
+ // launch uploader (or skip if there's no result)
155
+ const { assetUploader, popupProps = {} } = args;
156
+ const result = await (assetUploader === null || assetUploader === void 0 ? void 0 : assetUploader.upload(Object.assign({ schema: mediaAssetSchema }, popupProps)));
157
+ if (!result) {
158
+ return undefined;
159
+ }
160
+ // or switch to picking
161
+ else if (result === 'pick') {
162
+ return pickAsset(args);
163
+ }
164
+ // create new image media
165
+ const { value: asset } = result;
166
+ if (funnel_core_1.Schema.AssetField.LinkedValue.Image.filter(asset)) {
167
+ console.debug('[MediaFactory] creating new image media');
168
+ return asset;
169
+ }
170
+ // or create new video media
171
+ else if (funnel_core_1.Schema.AssetField.LinkedValue.Video.filter(asset)) {
172
+ console.debug('[MediaFactory] creating new video media');
173
+ return asset;
174
+ }
175
+ // or abort
176
+ else {
177
+ return undefined;
178
+ }
179
+ }
180
+ async function pickAsset(args) {
181
+ // launch picker (or cancel if nothing is selected)
182
+ const { assetPicker, popupProps = {} } = args;
183
+ const result = await (assetPicker === null || assetPicker === void 0 ? void 0 : assetPicker.pick(Object.assign({ schema: mediaAssetSchema }, popupProps)));
184
+ if (!result) {
185
+ return undefined;
186
+ }
187
+ // or launch uploader if the directive was received
188
+ else if (result === 'upload') {
189
+ return uploadAsset(args);
190
+ }
191
+ // create new image media
192
+ const { value: asset } = result;
193
+ if (funnel_core_1.Schema.AssetField.LinkedValue.Image.filter(asset)) {
194
+ console.debug('[MediaFactory] creating new image media');
195
+ return asset;
196
+ }
197
+ // or create new video media
198
+ else if (funnel_core_1.Schema.AssetField.LinkedValue.Video.filter(asset)) {
199
+ console.debug('[MediaFactory] creating new video media');
200
+ return asset;
201
+ }
202
+ // or abort
203
+ else {
204
+ return undefined;
205
+ }
206
+ }
207
+ async function linkVideo({ embeddedVideoEditor, popupProps = {} }) {
208
+ var _a;
209
+ // start editor (cancel if dismissed)
210
+ const value = await (embeddedVideoEditor === null || embeddedVideoEditor === void 0 ? void 0 : embeddedVideoEditor.edit(Object.assign({ schema: funnel_ui_1.Media.Video.Source.schema.content.remote.schema }, popupProps)));
211
+ return (_a = value === null || value === void 0 ? void 0 : value.value) !== null && _a !== void 0 ? _a : undefined;
212
+ }
@@ -1,7 +1,8 @@
1
1
  import { Callback, ObjectField, Schema } from '@nascentdigital/funnel-core';
2
- export declare function ObjectFactory({ schema, field, onCommit, onCancel }: ObjectFactory.Props): import("react/jsx-runtime").JSX.Element;
2
+ import { Popup } from '../../interaction';
3
+ export declare function ObjectFactory({ schema, fieldId, field, onCommit, onCancel, ...popupProps }: ObjectFactory.Props): import("react/jsx-runtime").JSX.Element;
3
4
  export declare namespace ObjectFactory {
4
- type Props = {
5
+ type Props = Popup.Props.Delegated & {
5
6
  schema: Schema.ObjectField;
6
7
  fieldId?: string;
7
8
  field?: ObjectField;
@@ -1,13 +1,27 @@
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.ObjectFactory = ObjectFactory;
4
15
  const jsx_runtime_1 = require("react/jsx-runtime");
5
16
  const react_1 = require("react");
6
17
  const object_1 = require("../object");
7
18
  // component
8
- function ObjectFactory({ schema, field, onCommit, onCancel }) {
19
+ function ObjectFactory(_a) {
20
+ var { schema, fieldId, field, onCommit, onCancel } = _a, popupProps = __rest(_a, ["schema", "fieldId", "field", "onCommit", "onCancel"]);
9
21
  // bind refs
10
22
  const editorRef = (0, react_1.useRef)(null);
23
+ const popupPropsRef = (0, react_1.useRef)(popupProps);
24
+ popupPropsRef.current = popupProps;
11
25
  const onCommitRef = (0, react_1.useRef)(onCommit);
12
26
  onCommitRef.current = onCommit;
13
27
  const onCancelRef = (0, react_1.useRef)(onCancel);
@@ -20,7 +34,7 @@ function ObjectFactory({ schema, field, onCommit, onCancel }) {
20
34
  // start editor (cancel if dismissed)
21
35
  const value = await ((_a = editorRef.current) === null || _a === void 0 ? void 0 : _a.edit({
22
36
  schema,
23
- field
37
+ field,
24
38
  }));
25
39
  if (!value) {
26
40
  console.debug('[ObjectFactory] editing cancelled');
@@ -1,10 +1,10 @@
1
1
  import { Callback, Schema } from '@nascentdigital/funnel-core';
2
- export declare function TextFactory({ schema, initialValue, anchor, onCommit, onCancel }: TextFactory.Props): import("react/jsx-runtime").JSX.Element;
2
+ import { Popup } from '../../interaction';
3
+ export declare function TextFactory({ schema, initialValue, onCommit, onCancel, ...popupProps }: TextFactory.Props): import("react/jsx-runtime").JSX.Element;
3
4
  export declare namespace TextFactory {
4
- type Props = {
5
+ type Props = Popup.Props.Delegated & {
5
6
  schema: Schema.TextField;
6
7
  initialValue?: Schema.Field.Data<Schema.TextField>;
7
- anchor: string;
8
8
  onCommit: Callback<Schema.Field.Data<Schema.TextField>>;
9
9
  onCancel: Callback.Void;
10
10
  };
@@ -1,4 +1,15 @@
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.TextFactory = TextFactory;
4
15
  const jsx_runtime_1 = require("react/jsx-runtime");
@@ -6,11 +17,12 @@ const funnel_core_1 = require("@nascentdigital/funnel-core");
6
17
  const react_1 = require("react");
7
18
  const interaction_1 = require("../../interaction");
8
19
  // component
9
- function TextFactory({ schema, initialValue, anchor, onCommit, onCancel }) {
20
+ function TextFactory(_a) {
21
+ var { schema, initialValue, onCommit, onCancel } = _a, popupProps = __rest(_a, ["schema", "initialValue", "onCommit", "onCancel"]);
10
22
  // bind refs
11
23
  const quickInputRef = (0, react_1.useRef)(null);
12
- const anchorRef = (0, react_1.useRef)(anchor);
13
- anchorRef.current = anchor;
24
+ const popupPropsRef = (0, react_1.useRef)(popupProps);
25
+ popupPropsRef.current = popupProps;
14
26
  const onCommitRef = (0, react_1.useRef)(onCommit);
15
27
  onCommitRef.current = onCommit;
16
28
  const onCancelRef = (0, react_1.useRef)(onCancel);
@@ -25,13 +37,7 @@ function TextFactory({ schema, initialValue, anchor, onCommit, onCancel }) {
25
37
  throw new funnel_core_1.IllegalStateError('Unable to resolve QuickInput ref');
26
38
  }
27
39
  // start editor (cancel if dismissed)
28
- const value = await quickInput.open({
29
- schema,
30
- anchor: anchorRef.current,
31
- initialValue: initialValue === null || initialValue === void 0 ? void 0 : initialValue.value,
32
- placement: 'right',
33
- anchorOffset: 2
34
- });
40
+ const value = await quickInput.open(Object.assign({ schema, initialValue: initialValue === null || initialValue === void 0 ? void 0 : initialValue.value }, (popupPropsRef.current)));
35
41
  if (!value) {
36
42
  onCancelRef.current();
37
43
  }
@@ -1,4 +1,5 @@
1
1
  import { Language, Schema } from '@nascentdigital/funnel-core';
2
+ import { Popup } from '../../interaction';
2
3
  export declare const LinkEditor: import("react").ForwardRefExoticComponent<LinkEditor.Props & import("react").RefAttributes<LinkEditor.Ref>>;
3
4
  export declare namespace LinkEditor {
4
5
  type Props = {
@@ -8,9 +9,8 @@ export declare namespace LinkEditor {
8
9
  interface Ref {
9
10
  edit(options: Options): Promise<Schema.Field.Data<Schema.LinkField> | undefined>;
10
11
  }
11
- type Options = {
12
+ type Options = Popup.Props.Delegated & {
12
13
  schema: Schema.LinkField;
13
14
  initialValue?: Schema.Field.Data<Schema.LinkField>;
14
- anchor: string;
15
15
  };
16
16
  }