@nascentdigital/funnel-editor 6.1.7 → 7.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 (82) hide show
  1. package/dist/collection/components/CollectionHeader.js +17 -3
  2. package/dist/core/components/fields/EnumField.js +3 -1
  3. package/dist/core/components/fields/FieldHeader.js +16 -23
  4. package/dist/core/components/fields/FieldLayout.d.ts +1 -1
  5. package/dist/core/components/fields/FieldLayout.js +10 -18
  6. package/dist/core/components/fields/collection/CollectionEditor.js +7 -7
  7. package/dist/core/components/index.d.ts +1 -0
  8. package/dist/core/components/index.js +1 -0
  9. package/dist/core/components/interaction/Combobox.js +17 -28
  10. package/dist/core/components/interaction/Popup.js +14 -2
  11. package/dist/core/components/interaction/QuickPicker.js +0 -1
  12. package/dist/core/components/panels/MessagePanel.d.ts +7 -0
  13. package/dist/core/components/panels/MessagePanel.js +53 -0
  14. package/dist/core/components/panels/index.d.ts +2 -0
  15. package/dist/core/components/panels/index.js +18 -0
  16. package/dist/core/components/panels/visual/MediaEditor.d.ts +12 -0
  17. package/dist/core/components/panels/visual/MediaEditor.js +47 -0
  18. package/dist/core/components/panels/visual/VisualPanel.d.ts +7 -0
  19. package/dist/core/components/panels/visual/VisualPanel.js +332 -0
  20. package/dist/core/components/panels/visual/index.d.ts +1 -0
  21. package/dist/core/components/panels/visual/index.js +17 -0
  22. package/dist/core/components/visuals/Icon.d.ts +1 -1
  23. package/dist/core/components/visuals/Icon.js +12 -0
  24. package/dist/core/domain/Block.d.ts +18 -8
  25. package/dist/core/domain/Block.js +101 -78
  26. package/dist/core/domain/BlockConfiguration.d.ts +38 -32
  27. package/dist/core/domain/BlockConfiguration.js +348 -255
  28. package/dist/core/domain/CollectionFieldProxy.d.ts +1 -0
  29. package/dist/core/domain/CollectionFieldProxy.js +5 -0
  30. package/dist/core/domain/CollectionSummary.d.ts +1 -1
  31. package/dist/core/domain/CollectionSummary.js +1 -1
  32. package/dist/core/domain/Collections.d.ts +2 -0
  33. package/dist/core/domain/Collections.js +6 -0
  34. package/dist/core/domain/IPage.d.ts +3 -2
  35. package/dist/core/domain/Item.d.ts +1 -1
  36. package/dist/core/domain/ItemBase.d.ts +2 -0
  37. package/dist/core/domain/ItemBase.js +9 -0
  38. package/dist/core/domain/Page.d.ts +1 -1
  39. package/dist/core/domain/SectionBlock.d.ts +4 -5
  40. package/dist/core/domain/SectionBlock.js +3 -10
  41. package/dist/core/hooks/useBlockConfiguration.d.ts +1 -7
  42. package/dist/core/hooks/useBlockConfiguration.js +1 -6
  43. package/dist/core/repository/PageSerializer.js +11 -10
  44. package/dist/core/repository/SerializeCollectionUpdate.js +4 -4
  45. package/dist/core/repository/SerializePageUpdate.d.ts +2 -1
  46. package/dist/core/repository/SerializePageUpdate.js +79 -24
  47. package/dist/page/components/BlockEditor.js +3 -3
  48. package/dist/page/components/config/BlockConfigButton.d.ts +3 -1
  49. package/dist/page/components/config/BlockConfigButton.js +12 -24
  50. package/dist/page/components/config/BlockPreview.d.ts +7 -6
  51. package/dist/page/components/config/BlockPreview.js +30 -15
  52. package/dist/page/components/config/index.d.ts +1 -2
  53. package/dist/page/components/config/index.js +1 -2
  54. package/dist/page/components/config/preview/ColumnLayout.d.ts +7 -4
  55. package/dist/page/components/config/preview/ColumnLayout.js +14 -2
  56. package/dist/page/components/config/preview/ItemLayout.d.ts +7 -4
  57. package/dist/page/components/config/preview/ItemLayout.js +24 -11
  58. package/dist/page/components/config/preview/ListPanel.d.ts +7 -4
  59. package/dist/page/components/config/preview/ListPanel.js +4 -2
  60. package/dist/page/components/config/preview/MessagePanel.d.ts +7 -4
  61. package/dist/page/components/config/preview/MessagePanel.js +6 -3
  62. package/dist/page/components/config/preview/Panel.d.ts +14 -4
  63. package/dist/page/components/config/preview/Panel.js +25 -7
  64. package/dist/page/components/config/preview/PreviewSize.d.ts +1 -0
  65. package/dist/page/components/config/preview/PreviewSize.js +2 -0
  66. package/dist/page/components/config/preview/RowLayout.d.ts +7 -4
  67. package/dist/page/components/config/preview/RowLayout.js +15 -3
  68. package/dist/page/components/config/preview/StackLayout.d.ts +7 -4
  69. package/dist/page/components/config/preview/StackLayout.js +14 -2
  70. package/dist/page/components/config/preview/VisualPanel.d.ts +7 -4
  71. package/dist/page/components/config/preview/VisualPanel.js +7 -5
  72. package/dist/page/components/config/preview/index.d.ts +2 -0
  73. package/dist/page/components/config/preview/index.js +2 -0
  74. package/dist/page/components/panels/BlockConfigPanel.d.ts +7 -1
  75. package/dist/page/components/panels/BlockConfigPanel.js +9 -7
  76. package/dist/page/screens/PageEditor.js +3 -4
  77. package/dist/styles/index.css +74 -56
  78. package/package.json +2 -2
  79. package/dist/page/components/config/BlockConfigurationProvider.d.ts +0 -16
  80. package/dist/page/components/config/BlockConfigurationProvider.js +0 -25
  81. package/dist/page/components/config/useBlockConfiguration$.d.ts +0 -3
  82. package/dist/page/components/config/useBlockConfiguration$.js +0 -22
@@ -6,46 +6,34 @@ const funnel_ui_1 = require("@nascentdigital/funnel-ui");
6
6
  const rxjs_1 = require("rxjs");
7
7
  const BlockConfiguration_1 = require("./BlockConfiguration");
8
8
  const ItemBase_1 = require("./ItemBase");
9
+ const Section_1 = require("./Section");
9
10
  // class
10
11
  class Block extends ItemBase_1.ItemBase {
11
12
  constructor(args) {
12
13
  // construct base
13
14
  super(args);
14
15
  // initialize instance variables
16
+ this.log = funnel_core_1.Logger.get('editor:page:block');
15
17
  this.schema = args.schema;
16
- this.config = args.config;
18
+ this._configData = args.configData;
17
19
  this.fields = args.fields;
18
- this.nameField = new funnel_core_1.Field({
19
- id: '_nd-blockName',
20
- name: 'Name',
21
- schema: funnel_core_1.Schema.Field.text({
22
- name: 'Name',
23
- description: `This is the name used to identify this block.`,
24
- hint: 'Please provide a name',
25
- semantics: 'short',
26
- required: true
27
- }),
28
- eventBus: args.eventBus,
29
- initialValue: args.name
30
- ? funnel_core_1.Schema.TextField.Value.toData(args.name)
31
- : undefined,
32
- publishedValue: undefined,
33
- required: true
34
- });
35
20
  // group fields
36
21
  const messageKeys = Object.keys(funnel_ui_1.MessagePanel.Fields.getSchema());
37
22
  this.messageFields = this.fields.filter(field => messageKeys.includes(field.id));
38
23
  this.visualFields = this.fields.filter(field => field.id === 'visual');
39
24
  this.listsFields = this.fields.filter(field => field.id === 'list');
40
25
  this.extendedFields = this.fields.filter(field => !messageKeys.includes(field.id) && field.id !== 'visual' && field.id !== 'list');
41
- // listen to field changes
42
- this.fieldChanged$.subscribe(event => this.onFieldChange(event));
26
+ // listen to field saves
27
+ this.fieldChanged$
28
+ .pipe((0, rxjs_1.filter)(event => event.type === 'saved'))
29
+ .subscribe(event => this.onFieldChange(event));
43
30
  }
44
31
  get identifier() {
45
32
  return this.key;
46
33
  }
47
34
  get name() {
48
- return funnel_core_1.Schema.TextField.Value.fromData(this.nameField.value) || this.schema.name;
35
+ const { _nameField, schema } = this;
36
+ return funnel_core_1.Schema.TextField.Value.fromData(_nameField === null || _nameField === void 0 ? void 0 : _nameField.value) || schema.name;
49
37
  }
50
38
  get state() {
51
39
  return this.activated
@@ -59,20 +47,31 @@ class Block extends ItemBase_1.ItemBase {
59
47
  .pipe((0, rxjs_1.filter)(funnel_core_1.Field.Event.filter), (0, rxjs_1.filter)(event => (event.type === 'changed' || event.type === 'reset')
60
48
  && this.fields.includes(event.field)));
61
49
  }
50
+ get configData() {
51
+ var _a, _b;
52
+ return (_b = (_a = this._configuration) === null || _a === void 0 ? void 0 : _a.configData) !== null && _b !== void 0 ? _b : this._configData;
53
+ }
54
+ get configuration() {
55
+ // throw if accessed too early
56
+ const { _configuration } = this;
57
+ if (!_configuration) {
58
+ throw new funnel_core_1.InvalidOperationError('Cannot to access Block configuration before being bound to parent');
59
+ }
60
+ // return configuration
61
+ return _configuration;
62
+ }
62
63
  get value() {
63
- const { schema, config, fields } = this;
64
+ var _a;
65
+ const { log, schema, name, _configuration, fields } = this;
66
+ const { base = {}, mobile, tablet } = (_a = _configuration === null || _configuration === void 0 ? void 0 : _configuration.value) !== null && _a !== void 0 ? _a : {};
67
+ log.d(`value/${name}`, { id: schema.id, base, mobile, tablet });
64
68
  return {
65
69
  type: 'block',
66
70
  id: schema.id,
67
71
  version: schema.version,
68
- config: config.length === 0
69
- ? undefined
70
- : config.reduce((values, field) => {
71
- // bind config (force casting value in case it's not set)
72
- values[field.id] = field.value;
73
- // keep reducing
74
- return values;
75
- }, {}),
72
+ config: base,
73
+ configMobile: mobile && Object.keys(mobile).length > 0 ? mobile : undefined,
74
+ configTablet: tablet && Object.keys(tablet).length > 0 ? tablet : undefined,
76
75
  fields: fields.reduce((values, field) => {
77
76
  // bind content
78
77
  values[field.id] = field.value;
@@ -82,70 +81,85 @@ class Block extends ItemBase_1.ItemBase {
82
81
  };
83
82
  }
84
83
  get modified() {
84
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
85
85
  // ignore if not activated
86
- const { activated, isNew, nameField, config, fields } = this;
86
+ const { log, name, activated, isNew, _nameField, _configuration, configData, fields } = this;
87
87
  if (isNew && !activated) {
88
88
  return false;
89
89
  }
90
- return (isNew && activated)
91
- || nameField.modified
92
- || config.some(field => field.modified)
93
- || fields.some(field => field.modified);
90
+ const { base = {}, mobile, tablet } = (_a = _configuration === null || _configuration === void 0 ? void 0 : _configuration.value) !== null && _a !== void 0 ? _a : {};
91
+ const modified = (isNew && activated)
92
+ || (!!_nameField && _nameField.modified)
93
+ || fields.some(field => field.modified)
94
+ || !funnel_core_1.Value.equals(base, (_b = configData.base) === null || _b === void 0 ? void 0 : _b.config)
95
+ || !funnel_core_1.Value.equals(mobile, (_c = configData.mobile) === null || _c === void 0 ? void 0 : _c.config)
96
+ || !funnel_core_1.Value.equals(tablet, (_d = configData.tablet) === null || _d === void 0 ? void 0 : _d.config);
97
+ log.s(`modified/${name} - block modified = ${modified}`, {
98
+ isNew,
99
+ activated,
100
+ configBase: {
101
+ modified: !funnel_core_1.Value.equals(base, (_e = configData.base) === null || _e === void 0 ? void 0 : _e.config),
102
+ from: (_f = configData.base) === null || _f === void 0 ? void 0 : _f.config,
103
+ to: base
104
+ },
105
+ configMobile: {
106
+ modified: !funnel_core_1.Value.equals(mobile, (_g = configData.mobile) === null || _g === void 0 ? void 0 : _g.config),
107
+ from: (_h = configData.mobile) === null || _h === void 0 ? void 0 : _h.config,
108
+ to: mobile
109
+ },
110
+ configTablet: {
111
+ modified: !funnel_core_1.Value.equals(tablet, (_j = configData.tablet) === null || _j === void 0 ? void 0 : _j.config),
112
+ from: (_k = configData.tablet) === null || _k === void 0 ? void 0 : _k.config,
113
+ to: tablet
114
+ }
115
+ });
116
+ return modified;
94
117
  }
95
118
  get changes() {
119
+ var _a;
120
+ const { _configuration, fields } = this;
96
121
  return {
97
122
  block: this,
98
- config: this.config.filter(field => field.changed),
99
- fields: this.fields.filter(field => field.changed)
123
+ config: (_a = _configuration === null || _configuration === void 0 ? void 0 : _configuration.fields.filter(field => field.changed)) !== null && _a !== void 0 ? _a : [],
124
+ fields: fields.filter(field => field.changed)
100
125
  };
101
126
  }
102
127
  get valid() {
103
- return this.config.every(field => field.valid)
104
- && this.fields.every(field => field.valid);
128
+ return this.fields.every(field => field.valid);
105
129
  }
106
130
  get errors() {
107
131
  return {
108
132
  block: this,
109
- config: this.config.filter(field => !field.valid),
133
+ config: [],
110
134
  fields: this.fields.filter(field => !field.valid)
111
135
  };
112
136
  }
113
- bind(parentContext) {
114
- // invoke base
115
- super.bind(parentContext);
116
- // sync config if we are already activated
117
- if (this.activated) {
118
- this.syncBlockConfig();
119
- }
137
+ get sectionBlock() {
138
+ return this._sectionBlock;
120
139
  }
121
- getConfiguration() {
122
- const { root } = this;
123
- return new BlockConfiguration_1.BlockConfiguration({ block: this, assetStore: root, collectionStore: root });
140
+ get nameField() {
141
+ return this._nameField;
124
142
  }
125
- getConfig(fieldId) {
126
- // get field (or throw)
127
- const field = this.config.find(field => field.id === fieldId);
128
- if (!field) {
129
- throw new funnel_core_1.IllegalStateError(`Unable to resolve config ${this.name}/${fieldId}`);
130
- }
131
- // return field
132
- return field;
133
- }
134
- setConfig(config) {
135
- console.warn(`[Block/setConfig] updating "${this.name}" config with:`, config);
136
- // map fields
137
- config.forEach(updatedField => {
138
- // find source field (or ignore)
139
- const { id, schema } = updatedField;
140
- const field = this.config.find(field => field.id === id && field.schema === schema);
141
- if (!field) {
142
- console.warn(`[Block/setConfig] unable to find field [${schema.type}/${id}]`);
143
- }
144
- // sync basic field
145
- else {
146
- field.value = updatedField.value;
143
+ onBind(parentContext) {
144
+ // look for owning parent (if any)
145
+ const { parent } = parentContext;
146
+ if (parent instanceof Section_1.Section) {
147
+ for (const sectionBlock of parent.blocks) {
148
+ if (sectionBlock.block === this) {
149
+ this._sectionBlock = sectionBlock;
150
+ }
147
151
  }
148
- });
152
+ }
153
+ // create config if we are already activated
154
+ if (this.activated) {
155
+ const { root, configData } = this;
156
+ this._configuration = new BlockConfiguration_1.BlockConfiguration({
157
+ configData,
158
+ block: this,
159
+ assetStore: root,
160
+ collectionStore: root
161
+ });
162
+ }
149
163
  }
150
164
  getField(fieldId) {
151
165
  // get field (or throw)
@@ -283,7 +297,7 @@ class Block extends ItemBase_1.ItemBase {
283
297
  key: this.key,
284
298
  schema: this.schema,
285
299
  eventBus: this.eventBus,
286
- config: this.config.map(config => config.clone()),
300
+ configData: funnel_core_1.ObjectUtils.clone(this.configData),
287
301
  fields: this.fields.map(field => field.clone()),
288
302
  required: this.required,
289
303
  exists: forceExists || this.activated
@@ -303,9 +317,11 @@ class Block extends ItemBase_1.ItemBase {
303
317
  // call base
304
318
  super.onActivate();
305
319
  this._modifiedOn = Date.now();
320
+ this.log.d('onActivate - activating block');
306
321
  // apply default content if specified
307
322
  const { defaultContent } = this.schema;
308
323
  if (defaultContent) {
324
+ this.log.d('onActivate - applying default content', defaultContent);
309
325
  // opt into array of fields
310
326
  if (Array.isArray(defaultContent)) {
311
327
  for (const fieldId of defaultContent) {
@@ -328,16 +344,23 @@ class Block extends ItemBase_1.ItemBase {
328
344
  break;
329
345
  }
330
346
  });
347
+ // bind configuration
348
+ const { root, configData } = this;
349
+ this._configuration = new BlockConfiguration_1.BlockConfiguration({
350
+ configData,
351
+ block: this,
352
+ assetStore: root,
353
+ collectionStore: root
354
+ });
331
355
  }
332
356
  syncBlockConfig() {
357
+ var _a;
333
358
  // guard: block fields must be ready AND block must exist and be activated
334
359
  if (!this.activated) {
335
360
  throw new funnel_core_1.InvalidOperationError('Cannot sync config for an unactivated block');
336
361
  }
337
- // get configuration using existing fields + config data
338
- const config = this.getConfiguration();
339
- // save the config
340
- config.save();
362
+ // sync all configuration
363
+ (_a = this._configuration) === null || _a === void 0 ? void 0 : _a.syncAll();
341
364
  }
342
365
  onFieldChange(event) {
343
366
  // sync config changes
@@ -1,33 +1,36 @@
1
- import { BlockLayout, EventBus, Field, FieldModel, Schema } from '@nascentdigital/funnel-core';
1
+ import { BlockLayout, EventBus, Field, FieldModel, Logger, Schema } from '@nascentdigital/funnel-core';
2
2
  import { ListPanel, MessagePanel, PanelLayout, SlotVariation, VisualPanel } from '@nascentdigital/funnel-ui';
3
3
  import { Block } from './Block';
4
4
  import { IAssetStore } from './IAssetStore';
5
5
  import { ICollectionStore } from './ICollectionStore';
6
- import { SectionBlock } from './SectionBlock';
7
6
  export declare class BlockConfiguration {
7
+ readonly log: Logger;
8
8
  readonly eventBus: EventBus;
9
9
  readonly assetStore: IAssetStore;
10
10
  readonly collectionStore: ICollectionStore;
11
- readonly sectionBlock?: SectionBlock;
12
11
  readonly block: Block;
13
- private _fields;
14
- private _editableFields;
15
- private _scope;
12
+ readonly configData: Block.ConfigData;
13
+ private readonly _fields;
14
+ private readonly _createdVariants;
15
+ private readonly _deletedVariants;
16
+ private _variant;
16
17
  private _layout?;
17
18
  private _slotState;
18
- private _defaultConfig?;
19
- private _isConfigInDefault?;
20
- constructor({ block: blockOrSectionBlock, assetStore, collectionStore }: BlockConfiguration.ConstructorArgs);
21
- get fields(): ReadonlyArray<FieldModel.Config>;
22
- get editableFields(): ReadonlyArray<FieldModel.Config>;
23
- set editableFields(fields: ReadonlyArray<FieldModel.Config>);
24
- get scope(): BlockConfiguration.Scope;
25
- set scope(scope: BlockConfiguration.Scope);
26
- get blocksFields(): FieldModel.Config[];
19
+ private _value?;
20
+ private _modifiedOn?;
21
+ private _savingOn?;
22
+ constructor({ block, assetStore, collectionStore, configData, variant }: BlockConfiguration.ConstructorArgs);
23
+ get events$(): import("rxjs").Observable<BlockConfiguration.Event>;
24
+ get fields(): FieldModel.Config[];
25
+ getFields(variant: Schema.Block.Config.Variant): ReadonlyArray<FieldModel.Config>;
26
+ get value(): Record<Schema.Block.Config.Variant, Schema.Block.Data.ForConfig | undefined>;
27
+ get variant(): Schema.Block.Config.Variant;
28
+ set variant(variant: Schema.Block.Config.Variant);
29
+ isVariantAvailable(variant: Schema.Block.Config.Variant): boolean;
30
+ get blockFields(): FieldModel.Config[];
31
+ get blockExtendedFields(): FieldModel.Config[];
27
32
  get blockFieldData(): Schema.Block.Data.ForFields<Schema.Fields>;
28
- get desktopFields(): FieldModel.Config[];
29
- get mobileFields(): FieldModel.Config[];
30
- get nameField(): FieldModel.Config | undefined;
33
+ get nameField(): Field<Schema.TextField> | undefined;
31
34
  get themeField(): FieldModel.Config | undefined;
32
35
  get layoutField(): Field<Schema.EnumField<Schema.EnumField.Options<PanelLayout>>> | undefined;
33
36
  get slotState(): Readonly<BlockConfiguration.SlotState>;
@@ -40,23 +43,20 @@ export declare class BlockConfiguration {
40
43
  get visualFields(): Record<keyof VisualPanel.Config.Keys<'visual'>, FieldModel.Config | undefined>;
41
44
  get extendedFields(): Record<string, FieldModel.Config>;
42
45
  get layout(): BlockLayout | undefined;
43
- get events$(): import("rxjs").Observable<EventBus.Event<string, string>>;
44
- get valid(): boolean;
45
- get modified(): boolean;
46
+ getPossibleField(fieldId: string): FieldModel.Config | undefined;
46
47
  getField(fieldId: string): FieldModel.Config;
47
48
  getFieldData(fieldId: string): Schema.Field.LinkedData | undefined;
48
- getEditableField(fieldId: string): FieldModel.Config | undefined;
49
- save(): void;
50
- resetToDefault(): void;
51
- get isConfigInDefault(): boolean | undefined;
52
- setLayout(layout: PanelLayout): void;
53
- sync(): void;
54
- reset(): void;
55
- private setConfigValues;
49
+ setPanelLayout(layout: PanelLayout): void;
50
+ sync({ variant: targetVariant, coerce }?: Partial<BlockConfiguration.SyncArgs>): void;
51
+ private syncLayout;
52
+ syncAll(coerce?: boolean): void;
53
+ createVariant(variant: Schema.Block.Config.Variant.Override): void;
54
+ deleteVariant(variant: Schema.Block.Config.Variant.Override): void;
55
+ onSaveStart(): void;
56
+ onSaveComplete(): void;
56
57
  private raiseEvent;
57
58
  }
58
59
  export declare namespace BlockConfiguration {
59
- type Scope = 'desktop' | 'mobile';
60
60
  type SlotState = {
61
61
  field?: Field<Schema.EnumField<Schema.EnumField.Options<SlotVariation>>>;
62
62
  options: ReadonlyArray<SlotVariation>;
@@ -66,13 +66,19 @@ export declare namespace BlockConfiguration {
66
66
  type ConstructorArgs = {
67
67
  assetStore: IAssetStore;
68
68
  collectionStore: ICollectionStore;
69
- block: Block | SectionBlock;
69
+ block: Block;
70
+ configData: Block.ConfigData;
71
+ variant?: Schema.Block.Config.Variant;
72
+ };
73
+ type SyncArgs = {
74
+ variant?: Schema.Block.Config.Variant;
75
+ coerce?: boolean;
70
76
  };
71
77
  interface Event extends EventBus.Event<'BlockConfiguration', Event.Type> {
72
78
  configuration: BlockConfiguration;
73
79
  }
74
80
  namespace Event {
75
- type Type = 'changed' | 'modified';
81
+ type Type = 'changed' | 'modified' | 'layout.updated';
76
82
  function filter(event: EventBus.Event): event is Event;
77
83
  function create(event: EventBus.Args<Event>): Event;
78
84
  }