@nascentdigital/funnel-core 6.1.1 → 6.1.3

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.
@@ -1,6 +1,5 @@
1
1
  import { StringKeyOf } from 'type-fest';
2
2
  import { Transform } from '../types';
3
- import type { BlockLayout, PanelLayout, PanelSlot } from '../ui/block-layout';
4
3
  import { Field } from './field';
5
4
  import { Fields } from './Fields';
6
5
  import { Optional } from './Optional';
@@ -14,12 +13,9 @@ export declare class Block<TId extends string = string, TFields extends Fields =
14
13
  readonly fields: TFields;
15
14
  readonly editableFields: Fields.UnwrapOptional<TFields>;
16
15
  readonly config: Block.Config.UnwrapOptional<TConfig>;
17
- readonly getConfig?: Block.GetConfig<TConfig, TFields>;
18
- readonly getLayout?: Block.GetLayout<TConfig, TFields>;
16
+ readonly getConfig?: Block.GetConfig<TFields, TConfig>;
19
17
  readonly defaultContent?: Block.DefaultContent<TFields>;
20
- readonly defaultPanelLayouts?: Block.DefaultPanelLayouts;
21
- readonly defaultLayoutConfigs?: Block.DefaultLayoutConfigs<TConfig>;
22
- private constructor();
18
+ protected constructor(args: Block.ConstructorArgs<TId, TFields, TConfig>);
23
19
  optional(): Optional<Block<TId, TFields, TConfig>>;
24
20
  unwrap(): this;
25
21
  modify(args: Block.ModifyArgs<TId, TFields, TConfig>): Block<TId, TFields, TConfig>;
@@ -34,14 +30,6 @@ export declare class Block<TId extends string = string, TFields extends Fields =
34
30
  * Set default content when block gets created.
35
31
  */
36
32
  withContent(defaultContent: Block.DefaultContent<TFields>): Block<TId, TFields, TConfig>;
37
- /**
38
- * Specify a default layout for a set of active panels.
39
- */
40
- useLayout(layout: PanelLayout.WithMultiSlots, activePanels: string[] | string): Block<TId, TFields, TConfig>;
41
- /**
42
- * Specify default configs for a layout.
43
- */
44
- useConfig(panelLayout: PanelLayout | PanelLayout[], config: Block.Config.Value<TConfig>): Block<TId, TFields, TConfig>;
45
33
  static create<TId extends string, TFields extends Fields, TConfig extends Block.Config>(args: Block.FactoryArgs<TId, TFields, TConfig>): Block<TId, TFields, TConfig>;
46
34
  }
47
35
  export declare namespace Block {
@@ -54,9 +42,18 @@ export declare namespace Block {
54
42
  };
55
43
  function normalize<TFields extends Fields>(property: Property<TFields>): Split<TFields>;
56
44
  }
57
- type GetConfig<TConfig extends Config = Config, TFields extends Fields = Fields> = Transform<GetConfig.Args<TConfig, TFields>, GetConfig.Result<TConfig>>;
45
+ type Config = Record<string, Optional.Maybe<Field.Type.Simple.Configuration>>;
46
+ namespace Config {
47
+ type UnwrapOptional<TConfig extends Config> = {
48
+ [key in keyof TConfig]: Optional.InnerType<TConfig[key]>;
49
+ };
50
+ type Value<TConfig extends Config> = {
51
+ [key in keyof TConfig]?: Field.Value<Optional.InnerType<TConfig[key]>>;
52
+ };
53
+ }
54
+ type GetConfig<TFields extends Fields = Fields, TConfig extends Config = Config> = Transform<GetConfig.Args<TFields, TConfig>, GetConfig.Result<TConfig>>;
58
55
  namespace GetConfig {
59
- type Args<TConfig extends Config, TFields extends Fields> = {
56
+ type Args<TFields extends Fields, TConfig extends Config> = {
60
57
  block: Block<any, TFields, TConfig>;
61
58
  config: Partial<Data.ForConfig<Config.UnwrapOptional<TConfig>>>;
62
59
  fields: Partial<Data.ForFields<TFields>> | Partial<LinkedData.ForFields<TFields>>;
@@ -67,25 +64,7 @@ export declare namespace Block {
67
64
  updatedConfigSchema?: Partial<Config.UnwrapOptional<TConfig>>;
68
65
  };
69
66
  }
70
- type GetLayout<TConfig extends Config = Config, TFields extends Fields = Fields> = Transform<GetLayout.Args<TConfig, TFields>, BlockLayout>;
71
- namespace GetLayout {
72
- type Args<TConfig extends Config, TFields extends Fields> = {
73
- config: Partial<Data.ForConfig<Config.UnwrapOptional<TConfig>>> | Partial<LinkedData.ForConfig<Config.UnwrapOptional<TConfig>>>;
74
- fields: Partial<Data.ForFields<TFields>> | Partial<LinkedData.ForFields<TFields>>;
75
- };
76
- }
77
67
  type DefaultContent<TFields extends Fields = Fields> = Array<keyof TFields>;
78
- type DefaultPanelLayouts = Partial<Record<PanelLayout, Set<PanelSlot>[]>>;
79
- type DefaultLayoutConfigs<TConfig extends Config = Config> = Partial<Record<PanelLayout, Config.Value<TConfig>>>;
80
- type Config = Record<string, Optional.Maybe<Field.Type.Simple.Configuration>>;
81
- namespace Config {
82
- type UnwrapOptional<TConfig extends Config> = {
83
- [key in keyof TConfig]: Optional.InnerType<TConfig[key]>;
84
- };
85
- type Value<TConfig extends Config> = {
86
- [key in keyof TConfig]?: Field.Value<Optional.InnerType<TConfig[key]>>;
87
- };
88
- }
89
68
  type Data<T extends Block = Block> = {
90
69
  type: 'block';
91
70
  id: T['id'];
@@ -132,11 +111,8 @@ export declare namespace Block {
132
111
  fields: TFields;
133
112
  editableFields: Fields.UnwrapOptional<TFields>;
134
113
  config?: TConfig;
135
- getConfig?: GetConfig<TConfig, TFields>;
136
- getLayout?: GetLayout<TConfig, TFields>;
114
+ getConfig?: GetConfig<TFields, TConfig>;
137
115
  defaultContent?: DefaultContent<TFields>;
138
- defaultPanelLayouts?: DefaultPanelLayouts;
139
- defaultLayoutConfigs?: DefaultLayoutConfigs<TConfig>;
140
116
  };
141
117
  type ModifyArgs<TId extends string, TFields extends Fields, TConfig extends Config> = Partial<Pick<ConstructorArgs<TId, TFields, TConfig>, 'name' | 'hint' | 'required'>>;
142
118
  type FactoryArgs<TId extends string, TFields extends Fields, TConfig extends Config = Config> = Omit<ConstructorArgs<TId, TFields, TConfig>, 'editableFields' | 'required'>;
@@ -29,10 +29,7 @@ class Block {
29
29
  }, {})
30
30
  : {};
31
31
  this.getConfig = args.getConfig;
32
- this.getLayout = args.getLayout;
33
32
  this.defaultContent = args.defaultContent;
34
- this.defaultPanelLayouts = args.defaultPanelLayouts;
35
- this.defaultLayoutConfigs = args.defaultLayoutConfigs;
36
33
  }
37
34
  optional() {
38
35
  return new Optional_1.Optional(this);
@@ -42,7 +39,7 @@ class Block {
42
39
  }
43
40
  modify(args) {
44
41
  // create new block (re-map required fields)
45
- return new Block(Object.assign({ id: this.id, name: this.name, hint: this.hint, required: this.required, version: this.version, fields: this.fields, editableFields: this.editableFields, config: this.config, getConfig: this.getConfig, getLayout: this.getLayout, defaultContent: this.defaultContent, defaultPanelLayouts: this.defaultPanelLayouts, defaultLayoutConfigs: this.defaultLayoutConfigs }, args));
42
+ return new Block(Object.assign({ id: this.id, name: this.name, hint: this.hint, required: this.required, version: this.version, fields: this.fields, editableFields: this.editableFields, config: this.config, getConfig: this.getConfig, defaultContent: this.defaultContent }, args));
46
43
  }
47
44
  /**
48
45
  * Rename a block's name which is used in the editor.
@@ -77,10 +74,7 @@ class Block {
77
74
  }, Object.assign({}, this.editableFields)),
78
75
  config: this.config,
79
76
  getConfig: this.getConfig,
80
- getLayout: this.getLayout,
81
- defaultContent: this.defaultContent,
82
- defaultPanelLayouts: this.defaultPanelLayouts,
83
- defaultLayoutConfigs: this.defaultLayoutConfigs,
77
+ defaultContent: this.defaultContent
84
78
  });
85
79
  }
86
80
  override(override) {
@@ -97,10 +91,7 @@ class Block {
97
91
  editableFields: Object.assign(Object.assign({}, this.editableFields), overrides),
98
92
  config: this.config,
99
93
  getConfig: this.getConfig,
100
- getLayout: this.getLayout,
101
- defaultContent: this.defaultContent,
102
- defaultPanelLayouts: this.defaultPanelLayouts,
103
- defaultLayoutConfigs: this.defaultLayoutConfigs,
94
+ defaultContent: this.defaultContent
104
95
  });
105
96
  }
106
97
  extend(fields) {
@@ -114,10 +105,7 @@ class Block {
114
105
  editableFields: Object.assign(Object.assign({}, this.editableFields), Fields_1.Fields.unwrap(fields)),
115
106
  config: this.config,
116
107
  getConfig: this.getConfig,
117
- getLayout: this.getLayout,
118
- defaultContent: this.defaultContent,
119
- defaultPanelLayouts: this.defaultPanelLayouts,
120
- defaultLayoutConfigs: this.defaultLayoutConfigs,
108
+ defaultContent: this.defaultContent
121
109
  });
122
110
  }
123
111
  /**
@@ -134,62 +122,7 @@ class Block {
134
122
  editableFields: this.editableFields,
135
123
  config: this.config,
136
124
  getConfig: this.getConfig,
137
- getLayout: this.getLayout,
138
- defaultContent: defaultContent,
139
- defaultPanelLayouts: this.defaultPanelLayouts,
140
- defaultLayoutConfigs: this.defaultLayoutConfigs,
141
- });
142
- }
143
- /**
144
- * Specify a default layout for a set of active panels.
145
- */
146
- useLayout(layout, activePanels) {
147
- var _a;
148
- // update default panel layouts
149
- const defaultPanelLayouts = (_a = this.defaultPanelLayouts) !== null && _a !== void 0 ? _a : {};
150
- defaultPanelLayouts[layout] = utils_1.ArrayUtils.coerce(activePanels).map(panels => new Set(panels.toUpperCase().split('')));
151
- // return new block
152
- return new Block({
153
- id: this.id,
154
- name: this.name,
155
- hint: this.hint,
156
- required: this.required,
157
- version: this.version,
158
- fields: this.fields,
159
- editableFields: this.editableFields,
160
- config: this.config,
161
- getConfig: this.getConfig,
162
- getLayout: this.getLayout,
163
- defaultContent: this.defaultContent,
164
- defaultPanelLayouts,
165
- defaultLayoutConfigs: this.defaultLayoutConfigs,
166
- });
167
- }
168
- /**
169
- * Specify default configs for a layout.
170
- */
171
- useConfig(panelLayout, config) {
172
- var _a;
173
- // update default layout configs
174
- const defaultLayoutConfigs = (_a = this.defaultLayoutConfigs) !== null && _a !== void 0 ? _a : {};
175
- utils_1.ArrayUtils.coerce(panelLayout).forEach(layout => {
176
- defaultLayoutConfigs[layout] = config;
177
- });
178
- // return new block
179
- return new Block({
180
- id: this.id,
181
- name: this.name,
182
- hint: this.hint,
183
- required: this.required,
184
- version: this.version,
185
- fields: this.fields,
186
- editableFields: this.editableFields,
187
- config: this.config,
188
- getConfig: this.getConfig,
189
- getLayout: this.getLayout,
190
- defaultContent: this.defaultContent,
191
- defaultPanelLayouts: this.defaultPanelLayouts,
192
- defaultLayoutConfigs
125
+ defaultContent: defaultContent
193
126
  });
194
127
  }
195
128
  static create(args) {
@@ -203,10 +136,7 @@ class Block {
203
136
  editableFields: Fields_1.Fields.unwrap(args.fields),
204
137
  config: args.config,
205
138
  getConfig: args.getConfig,
206
- getLayout: args.getLayout,
207
- defaultContent: args.defaultContent,
208
- defaultPanelLayouts: args.defaultPanelLayouts,
209
- defaultLayoutConfigs: args.defaultLayoutConfigs,
139
+ defaultContent: args.defaultContent
210
140
  });
211
141
  }
212
142
  }
@@ -0,0 +1,81 @@
1
+ import { Transform } from '../../types';
2
+ import type { BlockLayout, PanelLayout, PanelSlot } from '../../ui';
3
+ import { Block } from '../Block';
4
+ import { Fields, Fields as FieldsModel } from '../Fields';
5
+ export declare class PanelledBlock<TId extends string = string, TFields extends PanelledBlock.Fields = any, TConfig extends PanelledBlock.Config = any> extends Block<TId, TFields, TConfig> {
6
+ readonly getLayout?: PanelledBlock.GetLayout<TFields, TConfig>;
7
+ readonly defaultPanelLayouts: PanelledBlock.DefaultPanelLayouts;
8
+ readonly defaultLayoutConfigs: PanelledBlock.DefaultLayoutConfigs<TConfig>;
9
+ protected constructor({ getConfig, getLayout, defaultPanelLayouts, defaultLayoutConfigs, ...args }: PanelledBlock.ConstructorArgs<TId, TFields, TConfig>);
10
+ modify(args: Block.ModifyArgs<TId, TFields, TConfig>): PanelledBlock<TId, TFields, TConfig>;
11
+ /**
12
+ * Rename a block's name which is used in the editor.
13
+ */
14
+ rename(name: string): PanelledBlock<TId, TFields, TConfig>;
15
+ hide(...keys: ReadonlyArray<Fields.OptionalKeys<TFields>>): PanelledBlock<TId, TFields, TConfig>;
16
+ override(override: Fields.Override<TFields>): PanelledBlock<TId, TFields, TConfig>;
17
+ extend<TAdditionalFields extends Fields>(fields: TAdditionalFields): PanelledBlock<TId, TFields & TAdditionalFields, TConfig>;
18
+ /**
19
+ * Set default content when block gets created.
20
+ */
21
+ withContent(defaultContent: Block.DefaultContent<TFields>): Block<TId, TFields, TConfig>;
22
+ /**
23
+ * Specify a default layout for a set of active panels.
24
+ */
25
+ useLayout(layout: PanelLayout.WithMultiSlots, activePanels: string[] | string): PanelledBlock<TId, TFields, TConfig>;
26
+ /**
27
+ * Specify default configs for a layout.
28
+ */
29
+ useConfig(panelLayout: PanelLayout | PanelLayout[], config: PanelledBlock.Config.Value<TConfig>): PanelledBlock<TId, TFields, TConfig>;
30
+ static create<TId extends string, TFields extends PanelledBlock.Fields, TConfig extends PanelledBlock.Config>(args: PanelledBlock.FactoryArgs<TId, TFields, TConfig>): PanelledBlock<TId, TFields, TConfig>;
31
+ }
32
+ export declare namespace PanelledBlock {
33
+ type Fields = FieldsModel;
34
+ namespace Fields {
35
+ type UnwrapOptional<TFields extends Fields> = FieldsModel.UnwrapOptional<TFields>;
36
+ }
37
+ type Config = Block.Config;
38
+ namespace Config {
39
+ type UnwrapOptional<TConfig extends Config> = Block.Config.UnwrapOptional<TConfig>;
40
+ type Value<TConfig extends Config> = Block.Config.Value<TConfig>;
41
+ }
42
+ type GetConfig<TFields extends Fields = Fields, TConfig extends Config = Config> = Transform<GetConfig.Args<TFields, TConfig>, GetConfig.Result<TConfig>>;
43
+ namespace GetConfig {
44
+ type Args<TFields extends Fields, TConfig extends Config> = {
45
+ block: PanelledBlock<any, TFields, TConfig>;
46
+ config: Partial<Block.Data.ForConfig<Config.UnwrapOptional<TConfig>>>;
47
+ fields: Partial<Block.Data.ForFields<TFields>> | Partial<Block.LinkedData.ForFields<TFields>>;
48
+ };
49
+ type Result<TConfig extends Config> = {
50
+ updatedConfig?: Partial<Block.Data.ForConfig<Config.UnwrapOptional<TConfig>>>;
51
+ defaultConfig?: Partial<Block.Data.ForConfig<Config.UnwrapOptional<TConfig>>>;
52
+ updatedConfigSchema?: Partial<Config.UnwrapOptional<TConfig>>;
53
+ };
54
+ }
55
+ type GetLayout<TFields extends Fields = Fields, TConfig extends Config = Config> = Transform<GetLayout.Args<TFields, TConfig>, BlockLayout>;
56
+ namespace GetLayout {
57
+ type Args<TFields extends Fields, TConfig extends Config> = {
58
+ config: Partial<Block.Data.ForConfig<Config.UnwrapOptional<TConfig>>> | Partial<Block.LinkedData.ForConfig<Config.UnwrapOptional<TConfig>>>;
59
+ fields: Partial<Block.Data.ForFields<TFields>> | Partial<Block.LinkedData.ForFields<TFields>>;
60
+ };
61
+ }
62
+ type DefaultPanelLayouts = Partial<Record<PanelLayout, Set<PanelSlot>[]>>;
63
+ type DefaultLayoutConfigs<TConfig extends Config = Config> = Partial<Record<PanelLayout, Config.Value<TConfig>>>;
64
+ type ConstructorArgs<TId extends string, TFields extends Fields, TConfig extends Config = Config> = {
65
+ id: TId;
66
+ name: string;
67
+ hint?: string;
68
+ required?: boolean;
69
+ version: number;
70
+ fields: TFields;
71
+ editableFields: Fields.UnwrapOptional<TFields>;
72
+ config?: TConfig;
73
+ getConfig?: GetConfig<TFields, TConfig>;
74
+ getLayout?: GetLayout<TFields, TConfig>;
75
+ defaultContent?: Block.DefaultContent<TFields>;
76
+ defaultPanelLayouts?: DefaultPanelLayouts;
77
+ defaultLayoutConfigs?: DefaultLayoutConfigs<TConfig>;
78
+ };
79
+ type ModifyArgs<TId extends string, TFields extends Fields, TConfig extends Config> = Partial<Pick<ConstructorArgs<TId, TFields, TConfig>, 'name' | 'hint' | 'required'>>;
80
+ type FactoryArgs<TId extends string, TFields extends Fields, TConfig extends Config = Config> = Omit<ConstructorArgs<TId, TFields, TConfig>, 'editableFields' | 'required'>;
81
+ }
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PanelledBlock = void 0;
15
+ const errors_1 = require("../../errors");
16
+ const utils_1 = require("../../utils");
17
+ const Block_1 = require("../Block");
18
+ const Fields_1 = require("../Fields");
19
+ // class
20
+ class PanelledBlock extends Block_1.Block {
21
+ constructor(_a) {
22
+ var { getConfig, getLayout, defaultPanelLayouts, defaultLayoutConfigs } = _a, args = __rest(_a, ["getConfig", "getLayout", "defaultPanelLayouts", "defaultLayoutConfigs"]);
23
+ // construct base
24
+ super(Object.assign(Object.assign({}, args), { getConfig: getConfig }));
25
+ // initialize instance variables
26
+ this.getLayout = getLayout;
27
+ this.defaultPanelLayouts = defaultPanelLayouts !== null && defaultPanelLayouts !== void 0 ? defaultPanelLayouts : {};
28
+ this.defaultLayoutConfigs = defaultLayoutConfigs !== null && defaultLayoutConfigs !== void 0 ? defaultLayoutConfigs : {};
29
+ }
30
+ modify(args) {
31
+ // create new block (re-map required fields)
32
+ return new PanelledBlock(Object.assign({ id: this.id, name: this.name, hint: this.hint, required: this.required, version: this.version, fields: this.fields, editableFields: this.editableFields, config: this.config, getConfig: this.getConfig, getLayout: this.getLayout, defaultContent: this.defaultContent, defaultPanelLayouts: this.defaultPanelLayouts, defaultLayoutConfigs: this.defaultLayoutConfigs }, args));
33
+ }
34
+ /**
35
+ * Rename a block's name which is used in the editor.
36
+ */
37
+ rename(name) {
38
+ return this.modify({ name });
39
+ }
40
+ hide(...keys) {
41
+ // create new block with removed fields
42
+ return new PanelledBlock({
43
+ id: this.id,
44
+ name: this.name,
45
+ hint: this.hint,
46
+ version: this.version,
47
+ required: this.required,
48
+ fields: this.fields,
49
+ editableFields: keys.reduce((fields, key) => {
50
+ // handle field if not already pruned
51
+ const field = fields[key];
52
+ if (field) {
53
+ // throw if field is required
54
+ if (field.required) {
55
+ throw new errors_1.InvalidOperationError(`Cannot hide required field: ${String(key)} in block: ${this.name}`);
56
+ }
57
+ // otherwise delete field if not already pruned
58
+ else {
59
+ delete fields[key];
60
+ }
61
+ }
62
+ // keep reducing
63
+ return fields;
64
+ }, Object.assign({}, this.editableFields)),
65
+ config: this.config,
66
+ getLayout: this.getLayout,
67
+ defaultContent: this.defaultContent,
68
+ defaultPanelLayouts: this.defaultPanelLayouts,
69
+ defaultLayoutConfigs: this.defaultLayoutConfigs
70
+ });
71
+ }
72
+ override(override) {
73
+ // get overrides from function
74
+ const overrides = override(this.fields);
75
+ // create new block with persisted field spec and overridden fields in unwrapped fields
76
+ return new PanelledBlock({
77
+ id: this.id,
78
+ name: this.name,
79
+ hint: this.hint,
80
+ version: this.version,
81
+ required: this.required,
82
+ fields: this.fields,
83
+ editableFields: Object.assign(Object.assign({}, this.editableFields), overrides),
84
+ config: this.config,
85
+ getConfig: this.getConfig,
86
+ getLayout: this.getLayout,
87
+ defaultContent: this.defaultContent,
88
+ defaultPanelLayouts: this.defaultPanelLayouts,
89
+ defaultLayoutConfigs: this.defaultLayoutConfigs
90
+ });
91
+ }
92
+ extend(fields) {
93
+ return new PanelledBlock({
94
+ id: this.id,
95
+ name: this.name,
96
+ hint: this.hint,
97
+ required: this.required,
98
+ version: this.version,
99
+ fields: Object.assign(Object.assign({}, this.fields), fields),
100
+ editableFields: Object.assign(Object.assign({}, this.editableFields), Fields_1.Fields.unwrap(fields)),
101
+ config: this.config,
102
+ getConfig: this.getConfig,
103
+ getLayout: this.getLayout,
104
+ defaultContent: this.defaultContent,
105
+ defaultPanelLayouts: this.defaultPanelLayouts,
106
+ defaultLayoutConfigs: this.defaultLayoutConfigs
107
+ });
108
+ }
109
+ /**
110
+ * Set default content when block gets created.
111
+ */
112
+ withContent(defaultContent) {
113
+ return new Block_1.Block({
114
+ id: this.id,
115
+ name: this.name,
116
+ hint: this.hint,
117
+ required: this.required,
118
+ version: this.version,
119
+ fields: this.fields,
120
+ editableFields: this.editableFields,
121
+ config: this.config,
122
+ getConfig: this.getConfig,
123
+ defaultContent: defaultContent
124
+ });
125
+ }
126
+ /**
127
+ * Specify a default layout for a set of active panels.
128
+ */
129
+ useLayout(layout, activePanels) {
130
+ // update default panel layouts
131
+ const defaultPanelLayouts = Object.assign({}, this.defaultPanelLayouts);
132
+ defaultPanelLayouts[layout] = utils_1.ArrayUtils.coerce(activePanels).map(panels => new Set(panels.toUpperCase().split('')));
133
+ // return new block
134
+ return new PanelledBlock({
135
+ id: this.id,
136
+ name: this.name,
137
+ hint: this.hint,
138
+ required: this.required,
139
+ version: this.version,
140
+ fields: this.fields,
141
+ editableFields: this.editableFields,
142
+ config: this.config,
143
+ getConfig: this.getConfig,
144
+ getLayout: this.getLayout,
145
+ defaultContent: this.defaultContent,
146
+ defaultPanelLayouts,
147
+ defaultLayoutConfigs: this.defaultLayoutConfigs,
148
+ });
149
+ }
150
+ /**
151
+ * Specify default configs for a layout.
152
+ */
153
+ useConfig(panelLayout, config) {
154
+ // update default layout configs
155
+ const defaultLayoutConfigs = Object.assign({}, this.defaultLayoutConfigs);
156
+ utils_1.ArrayUtils.coerce(panelLayout).forEach(layout => {
157
+ defaultLayoutConfigs[layout] = config;
158
+ });
159
+ // return new block
160
+ return new PanelledBlock({
161
+ id: this.id,
162
+ name: this.name,
163
+ hint: this.hint,
164
+ required: this.required,
165
+ version: this.version,
166
+ fields: this.fields,
167
+ editableFields: this.editableFields,
168
+ config: this.config,
169
+ getConfig: this.getConfig,
170
+ getLayout: this.getLayout,
171
+ defaultContent: this.defaultContent,
172
+ defaultPanelLayouts: this.defaultPanelLayouts,
173
+ defaultLayoutConfigs
174
+ });
175
+ }
176
+ static create(args) {
177
+ // create new block with both field spec and unwrapped fields
178
+ return new PanelledBlock({
179
+ id: args.id,
180
+ name: args.name,
181
+ hint: args.hint,
182
+ version: args.version,
183
+ fields: args.fields,
184
+ editableFields: Fields_1.Fields.unwrap(args.fields),
185
+ config: args.config,
186
+ getConfig: args.getConfig,
187
+ getLayout: args.getLayout,
188
+ defaultContent: args.defaultContent,
189
+ defaultPanelLayouts: args.defaultPanelLayouts,
190
+ defaultLayoutConfigs: args.defaultLayoutConfigs,
191
+ });
192
+ }
193
+ }
194
+ exports.PanelledBlock = PanelledBlock;
@@ -0,0 +1 @@
1
+ export * from './PanelledBlock';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./PanelledBlock"), exports);
@@ -1,4 +1,5 @@
1
1
  export * from './field/index';
2
+ export * from './blocks';
2
3
  export * from './Asset';
3
4
  export * from './AssetScope';
4
5
  export * from './Block';
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./field/index"), exports);
18
+ __exportStar(require("./blocks"), exports);
18
19
  __exportStar(require("./Asset"), exports);
19
20
  __exportStar(require("./AssetScope"), exports);
20
21
  __exportStar(require("./Block"), exports);
@@ -8,6 +8,7 @@ export declare class Field<TSchema extends Schema.Field.Type = Schema.Field.Type
8
8
  readonly id: string;
9
9
  readonly name: string;
10
10
  readonly required: boolean;
11
+ readonly tags: ReadonlySet<string>;
11
12
  private readonly publishedValue;
12
13
  private _initialValue;
13
14
  private _value;
@@ -75,6 +76,7 @@ export declare namespace Field {
75
76
  initialValue?: Value<TSchema>;
76
77
  required: boolean;
77
78
  customValidator?: FieldValidator;
79
+ tags?: string[] | string;
78
80
  };
79
81
  type Value<TSchema extends Schema.Field.Type = Schema.Field.Type> = Schema.Field.Data<TSchema>;
80
82
  interface Event extends EventBus.Event<'Field', Event.Type> {
@@ -85,4 +87,7 @@ export declare namespace Field {
85
87
  function filter(event: EventBus.Event): event is Event;
86
88
  function create(event: EventBus.Args<Event>): Event;
87
89
  }
90
+ const Tag: {
91
+ readonly config: "config";
92
+ };
88
93
  }
@@ -51,6 +51,7 @@ class Field {
51
51
  this.name = args.name;
52
52
  this.required = args.required;
53
53
  this.publishedValue = args.publishedValue;
54
+ this.tags = new Set(utils_1.ArrayUtils.coerce(args.tags));
54
55
  this._initialValue = (_a = args.initialValue) !== null && _a !== void 0 ? _a : this.defaultValue;
55
56
  this._value = this._initialValue;
56
57
  this._editing = false;
@@ -343,4 +344,8 @@ exports.Field = Field;
343
344
  }
344
345
  Event.create = create;
345
346
  })(Event = Field.Event || (Field.Event = {}));
347
+ // tags
348
+ Field.Tag = {
349
+ config: 'config'
350
+ };
346
351
  })(Field || (exports.Field = Field = {}));
@@ -18,6 +18,11 @@ export declare namespace ObjectUtils {
18
18
  function splitProps<TProps extends object, TSubKey extends keyof Required<TProps>>(mixedProps: TProps, keys: ReadonlyArray<TSubKey>): SplitProps<TProps, TSubKey>;
19
19
  function slice<TProps extends object, TSubKey extends keyof Required<TProps>>(mixedProps: TProps, ...keys: ReadonlyArray<TSubKey>): Pick<TProps, TSubKey>;
20
20
  function drop<TProps extends object, TSubKey extends keyof Required<TProps>>(mixedProps: TProps, ...keys: ReadonlyArray<TSubKey>): Omit<TProps, TSubKey>;
21
+ /**
22
+ * Creates a new object with all undefined properties (shallow) dropped
23
+ * @param object - the object to process
24
+ */
25
+ function dropUndefined<T extends object>(object: T): Partial<T>;
21
26
  /**
22
27
  * Creates a new object with the updated entry (adding it if required)
23
28
  * @param object - the existing object to copy + change
@@ -53,6 +53,24 @@ var ObjectUtils;
53
53
  return splitProps(mixedProps, keys).props;
54
54
  }
55
55
  ObjectUtils.drop = drop;
56
+ /**
57
+ * Creates a new object with all undefined properties (shallow) dropped
58
+ * @param object - the object to process
59
+ */
60
+ function dropUndefined(object) {
61
+ return Object.entries(object).reduce((cleaned, [key, value]) => {
62
+ // don't include undefined properties
63
+ if (value === undefined) {
64
+ return cleaned;
65
+ }
66
+ // add property to cleaned object
67
+ else {
68
+ cleaned[key] = value;
69
+ return cleaned;
70
+ }
71
+ }, {});
72
+ }
73
+ ObjectUtils.dropUndefined = dropUndefined;
56
74
  /**
57
75
  * Creates a new object with the updated entry (adding it if required)
58
76
  * @param object - the existing object to copy + change
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-core",
3
- "version": "6.1.1",
3
+ "version": "6.1.3",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/nascentdigital/funnel.git",
6
6
  "directory": "libs/core"
@@ -65,5 +65,5 @@
65
65
  "jest-tsd": "^0.2.2",
66
66
  "ts-jest": "^29.3.2"
67
67
  },
68
- "gitHead": "697c3651dedb43a6e6ff373a495cb29c7e7e1fc6"
68
+ "gitHead": "f22371fb54de07cd115522c18e5c2c51ba72aa49"
69
69
  }