@nascentdigital/funnel-editor 6.1.0 → 6.1.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.
@@ -15,6 +15,7 @@ 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 './core/config/EditorConfig';
18
19
  export * from './explore/components/CreatePageDialog';
19
20
  export * from './explore/components/CreateCollectionDialog';
20
21
  export * from './page/components/config';
@@ -35,6 +35,7 @@ __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
+ __exportStar(require("./core/config/EditorConfig"), exports);
38
39
  // explore
39
40
  __exportStar(require("./explore/components/CreatePageDialog"), exports);
40
41
  __exportStar(require("./explore/components/CreateCollectionDialog"), exports);
@@ -26,14 +26,14 @@ export declare class Block<TBlock extends Schema.Block = Schema.Block> extends I
26
26
  get errors(): Block.Errors;
27
27
  bind(parentContext: ParentContext): void;
28
28
  getConfiguration(): BlockConfiguration;
29
- getConfig(fieldId: Block.ConfigId<TBlock>): FieldModel;
29
+ getConfig(fieldId: Block.ConfigId<TBlock>): FieldModel.Config;
30
30
  setConfig(config: ReadonlyArray<FieldModel.Config>): void;
31
31
  getField(fieldId: Block.FieldId<TBlock>): FieldModel;
32
32
  getTextField(fieldId: Block.FieldId<TBlock>): Field<Schema.TextField> | undefined;
33
33
  repair(): void;
34
34
  onSaveStart(): void;
35
35
  onSaveComplete(): void;
36
- clone(forceExists?: boolean): Block;
36
+ clone(forceExists?: boolean, parentContext?: ItemBase.ParentContext): Block;
37
37
  protected onActivate(): void;
38
38
  protected syncBlockConfig(): void;
39
39
  protected onFieldChange(event: Field.Event): void;
@@ -277,7 +277,7 @@ class Block extends ItemBase_1.ItemBase {
277
277
  // clear saving flag
278
278
  delete this._savingOn;
279
279
  }
280
- clone(forceExists = false) {
280
+ clone(forceExists = false, parentContext) {
281
281
  // create block
282
282
  const block = new Block({
283
283
  key: this.key,
@@ -288,6 +288,10 @@ class Block extends ItemBase_1.ItemBase {
288
288
  required: this.required,
289
289
  exists: forceExists || this.activated
290
290
  });
291
+ // bind parent context
292
+ if (parentContext) {
293
+ block.bind(parentContext);
294
+ }
291
295
  // activate it
292
296
  if (forceExists) {
293
297
  block.onActivate();
@@ -299,6 +303,17 @@ class Block extends ItemBase_1.ItemBase {
299
303
  // call base
300
304
  super.onActivate();
301
305
  this._modifiedOn = Date.now();
306
+ // apply default content if specified
307
+ const { defaultContent } = this.schema;
308
+ if (defaultContent) {
309
+ // opt into array of fields
310
+ if (Array.isArray(defaultContent)) {
311
+ for (const fieldId of defaultContent) {
312
+ const field = this.getField(fieldId);
313
+ field.optIn();
314
+ }
315
+ }
316
+ }
302
317
  // pre-populate all fields
303
318
  this.fields.forEach(field => {
304
319
  // skip if there's an existing value OR it's not required
@@ -43,14 +43,16 @@ export declare class BlockConfiguration {
43
43
  get events$(): import("rxjs").Observable<EventBus.Event<string, string>>;
44
44
  get valid(): boolean;
45
45
  get modified(): boolean;
46
- getField(fieldId: string): FieldModel;
46
+ getField(fieldId: string): FieldModel.Config;
47
47
  getFieldData(fieldId: string): Schema.Field.LinkedData | undefined;
48
48
  getEditableField(fieldId: string): FieldModel.Config | undefined;
49
49
  save(): void;
50
50
  resetToDefault(): void;
51
51
  get isConfigInDefault(): boolean | undefined;
52
+ setLayout(layout: PanelLayout): void;
52
53
  sync(): void;
53
54
  reset(): void;
55
+ private setConfigValues;
54
56
  private raiseEvent;
55
57
  }
56
58
  export declare namespace BlockConfiguration {
@@ -398,6 +398,30 @@ class BlockConfiguration {
398
398
  get isConfigInDefault() {
399
399
  return this._isConfigInDefault;
400
400
  }
401
+ setLayout(layout) {
402
+ var _a;
403
+ // bail if no layout field (shouldn't happen)
404
+ const { block, layoutField } = this;
405
+ if (!layoutField) {
406
+ return;
407
+ }
408
+ // bail if no change in layout
409
+ const previousLayout = (_a = layoutField.value) === null || _a === void 0 ? void 0 : _a.value;
410
+ if (previousLayout === layout) {
411
+ return;
412
+ }
413
+ // update layout if different
414
+ layoutField.value = funnel_core_1.Schema.EnumField.Value.toData(layout);
415
+ // finish here if no layout change
416
+ if (!block.schema.defaultLayoutConfigs) {
417
+ return;
418
+ }
419
+ // set config for layout
420
+ const configForLayout = block.schema.defaultLayoutConfigs[layout];
421
+ if (configForLayout) {
422
+ this.setConfigValues(configForLayout);
423
+ }
424
+ }
401
425
  sync() {
402
426
  var _a;
403
427
  // recompute the editable fields
@@ -411,7 +435,7 @@ class BlockConfiguration {
411
435
  const blockSchema = block.schema;
412
436
  const { getConfig, getLayout } = blockSchema;
413
437
  const { updatedConfig = configData, updatedConfigSchema = blockSchema.config, defaultConfig = {} } = getConfig
414
- ? getConfig({ configSchema: blockSchema.config, config: configData, fields: fieldData })
438
+ ? getConfig({ config: configData, fields: fieldData, block: block.schema })
415
439
  : {};
416
440
  // create new config fields
417
441
  const configFields = fields
@@ -481,6 +505,14 @@ class BlockConfiguration {
481
505
  // force sync
482
506
  this.sync();
483
507
  }
508
+ setConfigValues(config) {
509
+ Object.entries(config).forEach(([fieldId, value]) => {
510
+ const field = this.getEditableField(fieldId);
511
+ if (field) {
512
+ field.value = funnel_core_1.Schema.Field.Data.ForSimpleType.fromValue(field.schema, value);
513
+ }
514
+ });
515
+ }
484
516
  raiseEvent(type) {
485
517
  this.eventBus.publish(BlockConfiguration.Event.create({ type, configuration: this }));
486
518
  }
@@ -7,7 +7,7 @@ const SectionBlock_1 = require("./SectionBlock");
7
7
  // class
8
8
  class Section extends ItemBase_1.ItemBase {
9
9
  constructor(args) {
10
- var _a;
10
+ var _a, _b;
11
11
  // construct base
12
12
  super(args);
13
13
  // initialize instance variables
@@ -15,21 +15,7 @@ class Section extends ItemBase_1.ItemBase {
15
15
  this.availableBlocks = args.availableBlocks;
16
16
  this._initialBlocks = args.blocks;
17
17
  // use existing blocks
18
- const blocks = (_a = args.blocks) === null || _a === void 0 ? void 0 : _a.slice();
19
- if (blocks) {
20
- this._blocks = blocks;
21
- }
22
- // or force presets
23
- else {
24
- // find preset in schema (or throw - should never happen)
25
- const presets = this.schema.preset;
26
- // bind blocks
27
- const { availableBlocks } = this;
28
- this._blocks = presets
29
- .map(key => availableBlocks.find(block => block.key === key))
30
- .filter(funnel_core_1.Value.isDefined)
31
- .map(SectionBlock_1.SectionBlock.for);
32
- }
18
+ this._blocks = (_b = (_a = args.blocks) === null || _a === void 0 ? void 0 : _a.slice()) !== null && _b !== void 0 ? _b : [];
33
19
  // mark as activated
34
20
  this.activated = true;
35
21
  }
@@ -91,12 +77,12 @@ class Section extends ItemBase_1.ItemBase {
91
77
  if (!blockTemplate) {
92
78
  throw new funnel_core_1.ArgumentError(`Unable to find block matching "${identifier}"`);
93
79
  }
80
+ // parent context for block to create
81
+ const parentContext = { parent: this, area: this.area };
94
82
  // create new section block
95
- const block = SectionBlock_1.SectionBlock.for(blockTemplate);
83
+ const block = SectionBlock_1.SectionBlock.for({ block: blockTemplate, parentContext });
96
84
  this._blocks.push(block);
97
85
  this._modifiedOn = Date.now();
98
- // bind block
99
- block.bind({ parent: this, area: this.area });
100
86
  // raise change
101
87
  this.raiseEvent('changed');
102
88
  // return block
@@ -26,7 +26,7 @@ export declare class SectionBlock<TBlock extends Schema.Block = Schema.Block> ex
26
26
  getConfiguration(): BlockConfiguration;
27
27
  bind(parentContext: ItemBase.ParentContext): void;
28
28
  repair(): void;
29
- static for(block: Block): SectionBlock<Schema.Block<string, any, any>>;
29
+ static for({ block, parentContext }: SectionBlock.ForArgs): SectionBlock<Schema.Block<string, any, any>>;
30
30
  }
31
31
  export declare namespace SectionBlock {
32
32
  type Id = Tagged<string, 'SectionBlock.Id'>;
@@ -34,4 +34,8 @@ export declare namespace SectionBlock {
34
34
  id: string;
35
35
  block: Block<TBlock>;
36
36
  };
37
+ type ForArgs = {
38
+ block: Block;
39
+ parentContext: ItemBase.ParentContext;
40
+ };
37
41
  }
@@ -79,15 +79,23 @@ class SectionBlock extends ItemBase_1.ItemBase {
79
79
  // repair all blocks
80
80
  this.block.repair();
81
81
  }
82
- static for(block) {
83
- return new SectionBlock({
82
+ static for({ block, parentContext }) {
83
+ // create section block
84
+ const sectionBlock = new SectionBlock({
84
85
  id: funnel_core_1.Value.uuid(),
85
86
  key: block.key,
86
87
  eventBus: block.eventBus,
87
- block: block.clone(true),
88
+ block: block.clone(),
88
89
  required: block.required,
89
90
  exists: true
90
91
  });
92
+ // bind parent context
93
+ sectionBlock.bind(parentContext);
94
+ // active block
95
+ // important that we activate after parent context bound
96
+ sectionBlock.block.activated = true;
97
+ // return
98
+ return sectionBlock;
91
99
  }
92
100
  }
93
101
  exports.SectionBlock = SectionBlock;
@@ -6,6 +6,7 @@ export declare namespace FieldSerializer {
6
6
  schema: Schema.Field.Type;
7
7
  content: any | undefined;
8
8
  snapshot: any | undefined;
9
+ config?: boolean;
9
10
  };
10
- function deserializeField({ id, eventBus, schema, content, snapshot }: DeserializeFieldArgs): FieldModel;
11
+ function deserializeField({ id, eventBus, schema, content, snapshot, config }: DeserializeFieldArgs): FieldModel;
11
12
  }
@@ -5,7 +5,7 @@ const funnel_core_1 = require("@nascentdigital/funnel-core");
5
5
  // namespace
6
6
  var FieldSerializer;
7
7
  (function (FieldSerializer) {
8
- function deserializeField({ id, eventBus, schema, content, snapshot }) {
8
+ function deserializeField({ id, eventBus, schema, content, snapshot, config }) {
9
9
  var _a;
10
10
  // deserialize based on type
11
11
  switch (schema.type) {
@@ -30,7 +30,8 @@ var FieldSerializer;
30
30
  name: schema.name,
31
31
  publishedValue: snapshot !== null && snapshot !== void 0 ? snapshot : undefined,
32
32
  initialValue: content !== null && content !== void 0 ? content : undefined,
33
- required: schema.required
33
+ required: schema.required,
34
+ tags: config ? funnel_core_1.Field.Tag.config : undefined
34
35
  });
35
36
  // handle lists (may nest more complex types)
36
37
  case 'list': {
@@ -174,7 +174,8 @@ var PageSerializer;
174
174
  eventBus,
175
175
  schema: schema,
176
176
  content: config[id],
177
- snapshot: snapshotConfig[id]
177
+ snapshot: snapshotConfig[id],
178
+ config: true
178
179
  })),
179
180
  required: schema.required,
180
181
  exists: blockContent !== undefined,
@@ -68,9 +68,8 @@ function BlockConfigButton({ target, anchorId: anchorOverrideId, children = 'Con
68
68
  })),
69
69
  selectedItem: layoutData === null || layoutData === void 0 ? void 0 : layoutData.value
70
70
  }));
71
- // update if something was picked
72
71
  if (selectedLayout) {
73
- layoutField.value = funnel_core_1.Schema.EnumField.Value.toData(selectedLayout);
72
+ configuration.setLayout(selectedLayout);
74
73
  }
75
74
  };
76
75
  // set variables
@@ -132,7 +132,7 @@ class PageController {
132
132
  if ((core_1.IPage.Event.filter(e) && e.type === 'modified')
133
133
  || core_1.Item.Event.filter(e)
134
134
  || funnel_core_1.FieldList.Event.filter(e)
135
- || (funnel_core_1.Field.Event.filter(e) && e.field.isComposite)) {
135
+ || (funnel_core_1.Field.Event.filter(e) && (e.field.isComposite || e.field.tags.has(funnel_core_1.Field.Tag.config)))) {
136
136
  return (0, rxjs_1.interval)(0);
137
137
  }
138
138
  else {
@@ -501,10 +501,10 @@ video {
501
501
  }
502
502
 
503
503
  [popover]{
504
- inset: var(--toolwind-toggle-KEI8fYJXFG, 0px);
505
- background-color: var(--toolwind-toggle-KOvFIgzD4R, canvas);
506
- color: var(--toolwind-toggle-GyRYyCKe0G, canvastext);
507
- margin: var(--toolwind-toggle-OlerKDJe5b, auto);
504
+ inset: var(--toolwind-toggle-P1jy2UBqoP, 0px);
505
+ background-color: var(--toolwind-toggle-sNXb0Mo8fj, canvas);
506
+ color: var(--toolwind-toggle-qB02Svyt5l, canvastext);
507
+ margin: var(--toolwind-toggle-p8tQUweuhM, auto);
508
508
  }
509
509
  html, body, #__next, #root, .Editor-wrap{
510
510
  position: relative;
@@ -6012,10 +6012,10 @@ img.nd-Visual-image {
6012
6012
  .anchored\/\[--nd-popup-anchor\]:where(.anchored\/\[--nd-popup-anchor\]){
6013
6013
  position: absolute;
6014
6014
  view-transition-name: --tw-anchor-view-transition-2j1919322s193433343934192p322r2w33362l;
6015
- --toolwind-toggle-KEI8fYJXFG: auto;
6016
- --toolwind-toggle-KOvFIgzD4R: transparent;
6017
- --toolwind-toggle-GyRYyCKe0G: inherit;
6018
- --toolwind-toggle-OlerKDJe5b: 0px;
6015
+ --toolwind-toggle-P1jy2UBqoP: auto;
6016
+ --toolwind-toggle-sNXb0Mo8fj: transparent;
6017
+ --toolwind-toggle-qB02Svyt5l: inherit;
6018
+ --toolwind-toggle-p8tQUweuhM: 0px;
6019
6019
  }
6020
6020
  .counter-l1{
6021
6021
  counter-reset: l1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-editor",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -92,5 +92,5 @@
92
92
  "ts-jest": "^29",
93
93
  "type-fest": "^4"
94
94
  },
95
- "gitHead": "7b491cfadfcb458bf5882ec8da6c9c5401d61312"
95
+ "gitHead": "d72a93d505884f030d595ecf66c64351ebfc8ed1"
96
96
  }