@nascentdigital/funnel-core 6.0.1 → 6.1.1

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,6 @@
1
1
  import { StringKeyOf } from 'type-fest';
2
2
  import { Transform } from '../types';
3
- import { BlockLayout } from '../ui/block-layout';
3
+ import type { BlockLayout, PanelLayout, PanelSlot } from '../ui/block-layout';
4
4
  import { Field } from './field';
5
5
  import { Fields } from './Fields';
6
6
  import { Optional } from './Optional';
@@ -16,14 +16,32 @@ export declare class Block<TId extends string = string, TFields extends Fields =
16
16
  readonly config: Block.Config.UnwrapOptional<TConfig>;
17
17
  readonly getConfig?: Block.GetConfig<TConfig, TFields>;
18
18
  readonly getLayout?: Block.GetLayout<TConfig, TFields>;
19
+ readonly defaultContent?: Block.DefaultContent<TFields>;
20
+ readonly defaultPanelLayouts?: Block.DefaultPanelLayouts;
21
+ readonly defaultLayoutConfigs?: Block.DefaultLayoutConfigs<TConfig>;
19
22
  private constructor();
20
23
  optional(): Optional<Block<TId, TFields, TConfig>>;
21
24
  unwrap(): this;
22
25
  modify(args: Block.ModifyArgs<TId, TFields, TConfig>): Block<TId, TFields, TConfig>;
26
+ /**
27
+ * Rename a block's name which is used in the editor.
28
+ */
23
29
  rename(name: string): Block<TId, TFields, TConfig>;
24
30
  hide(...keys: ReadonlyArray<Fields.OptionalKeys<TFields>>): Block<TId, TFields, TConfig>;
25
31
  override(override: Fields.Override<TFields>): Block<TId, TFields, TConfig>;
26
32
  extend<TAdditionalFields extends Fields>(fields: TAdditionalFields): Block<TId, TFields & TAdditionalFields, TConfig>;
33
+ /**
34
+ * Set default content when block gets created.
35
+ */
36
+ 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>;
27
45
  static create<TId extends string, TFields extends Fields, TConfig extends Block.Config>(args: Block.FactoryArgs<TId, TFields, TConfig>): Block<TId, TFields, TConfig>;
28
46
  }
29
47
  export declare namespace Block {
@@ -39,8 +57,8 @@ export declare namespace Block {
39
57
  type GetConfig<TConfig extends Config = Config, TFields extends Fields = Fields> = Transform<GetConfig.Args<TConfig, TFields>, GetConfig.Result<TConfig>>;
40
58
  namespace GetConfig {
41
59
  type Args<TConfig extends Config, TFields extends Fields> = {
60
+ block: Block<any, TFields, TConfig>;
42
61
  config: Partial<Data.ForConfig<Config.UnwrapOptional<TConfig>>>;
43
- configSchema: Config.UnwrapOptional<TConfig>;
44
62
  fields: Partial<Data.ForFields<TFields>> | Partial<LinkedData.ForFields<TFields>>;
45
63
  };
46
64
  type Result<TConfig extends Config> = {
@@ -56,11 +74,17 @@ export declare namespace Block {
56
74
  fields: Partial<Data.ForFields<TFields>> | Partial<LinkedData.ForFields<TFields>>;
57
75
  };
58
76
  }
77
+ 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>>>;
59
80
  type Config = Record<string, Optional.Maybe<Field.Type.Simple.Configuration>>;
60
81
  namespace Config {
61
82
  type UnwrapOptional<TConfig extends Config> = {
62
83
  [key in keyof TConfig]: Optional.InnerType<TConfig[key]>;
63
84
  };
85
+ type Value<TConfig extends Config> = {
86
+ [key in keyof TConfig]?: Field.Value<Optional.InnerType<TConfig[key]>>;
87
+ };
64
88
  }
65
89
  type Data<T extends Block = Block> = {
66
90
  type: 'block';
@@ -110,6 +134,9 @@ export declare namespace Block {
110
134
  config?: TConfig;
111
135
  getConfig?: GetConfig<TConfig, TFields>;
112
136
  getLayout?: GetLayout<TConfig, TFields>;
137
+ defaultContent?: DefaultContent<TFields>;
138
+ defaultPanelLayouts?: DefaultPanelLayouts;
139
+ defaultLayoutConfigs?: DefaultLayoutConfigs<TConfig>;
113
140
  };
114
141
  type ModifyArgs<TId extends string, TFields extends Fields, TConfig extends Config> = Partial<Pick<ConstructorArgs<TId, TFields, TConfig>, 'name' | 'hint' | 'required'>>;
115
142
  type FactoryArgs<TId extends string, TFields extends Fields, TConfig extends Config = Config> = Omit<ConstructorArgs<TId, TFields, TConfig>, 'editableFields' | 'required'>;
@@ -30,6 +30,9 @@ class Block {
30
30
  : {};
31
31
  this.getConfig = args.getConfig;
32
32
  this.getLayout = args.getLayout;
33
+ this.defaultContent = args.defaultContent;
34
+ this.defaultPanelLayouts = args.defaultPanelLayouts;
35
+ this.defaultLayoutConfigs = args.defaultLayoutConfigs;
33
36
  }
34
37
  optional() {
35
38
  return new Optional_1.Optional(this);
@@ -39,8 +42,11 @@ class Block {
39
42
  }
40
43
  modify(args) {
41
44
  // create new block (re-map required fields)
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, getLayout: this.getLayout }, args));
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));
43
46
  }
47
+ /**
48
+ * Rename a block's name which is used in the editor.
49
+ */
44
50
  rename(name) {
45
51
  return this.modify({ name });
46
52
  }
@@ -71,7 +77,10 @@ class Block {
71
77
  }, Object.assign({}, this.editableFields)),
72
78
  config: this.config,
73
79
  getConfig: this.getConfig,
74
- getLayout: this.getLayout
80
+ getLayout: this.getLayout,
81
+ defaultContent: this.defaultContent,
82
+ defaultPanelLayouts: this.defaultPanelLayouts,
83
+ defaultLayoutConfigs: this.defaultLayoutConfigs,
75
84
  });
76
85
  }
77
86
  override(override) {
@@ -88,7 +97,10 @@ class Block {
88
97
  editableFields: Object.assign(Object.assign({}, this.editableFields), overrides),
89
98
  config: this.config,
90
99
  getConfig: this.getConfig,
91
- getLayout: this.getLayout
100
+ getLayout: this.getLayout,
101
+ defaultContent: this.defaultContent,
102
+ defaultPanelLayouts: this.defaultPanelLayouts,
103
+ defaultLayoutConfigs: this.defaultLayoutConfigs,
92
104
  });
93
105
  }
94
106
  extend(fields) {
@@ -102,7 +114,82 @@ class Block {
102
114
  editableFields: Object.assign(Object.assign({}, this.editableFields), Fields_1.Fields.unwrap(fields)),
103
115
  config: this.config,
104
116
  getConfig: this.getConfig,
105
- getLayout: this.getLayout
117
+ getLayout: this.getLayout,
118
+ defaultContent: this.defaultContent,
119
+ defaultPanelLayouts: this.defaultPanelLayouts,
120
+ defaultLayoutConfigs: this.defaultLayoutConfigs,
121
+ });
122
+ }
123
+ /**
124
+ * Set default content when block gets created.
125
+ */
126
+ withContent(defaultContent) {
127
+ return new Block({
128
+ id: this.id,
129
+ name: this.name,
130
+ hint: this.hint,
131
+ required: this.required,
132
+ version: this.version,
133
+ fields: this.fields,
134
+ editableFields: this.editableFields,
135
+ config: this.config,
136
+ 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
106
193
  });
107
194
  }
108
195
  static create(args) {
@@ -116,7 +203,10 @@ class Block {
116
203
  editableFields: Fields_1.Fields.unwrap(args.fields),
117
204
  config: args.config,
118
205
  getConfig: args.getConfig,
119
- getLayout: args.getLayout
206
+ getLayout: args.getLayout,
207
+ defaultContent: args.defaultContent,
208
+ defaultPanelLayouts: args.defaultPanelLayouts,
209
+ defaultLayoutConfigs: args.defaultLayoutConfigs,
120
210
  });
121
211
  }
122
212
  }
@@ -14,7 +14,7 @@ import { Section } from './Section';
14
14
  import type { Seo } from './Seo';
15
15
  import { Tag } from './Tag';
16
16
  import { TagGroup } from './TagGroup';
17
- export declare class Page<TContent extends Page.Content = Page.Content, TPreview extends Page.PreviewTarget<TContent> = Page.PreviewTarget<TContent>> {
17
+ export declare class Page<TContent extends Page.Content = any, TPreview extends Page.PreviewTarget<TContent> = any> {
18
18
  private _type?;
19
19
  readonly variant: Page.Variant;
20
20
  readonly route: Localized.Maybe<PageRoute>;
@@ -25,13 +25,14 @@ export declare class Page<TContent extends Page.Content = Page.Content, TPreview
25
25
  readonly optional: boolean;
26
26
  readonly preview?: TPreview;
27
27
  readonly content: TContent;
28
+ readonly navigation: ReadonlyArray<Page.Content.BlockKeys<TContent>>;
28
29
  readonly parent?: string;
29
30
  private constructor();
30
31
  get type(): Page.Type;
31
32
  parseTags(tags: Tag.Data[]): Tag[];
32
33
  bind(type: Page.Type): void;
33
- static static<TContent extends Page.Content, TPreview extends Page.PreviewTarget<TContent>>({ route, ...args }: Page.FactoryArgs.Static<TContent, TPreview>): Page<TContent, TPreview>;
34
- static dynamic<TContent extends Page.Content, TPreview extends Page.PreviewTarget<TContent>>(args: Page.FactoryArgs.Dynamic<TContent, TPreview>): Page<TContent, TPreview>;
34
+ static static<TContent extends Page.Content, TPreview extends Page.PreviewTarget<TContent>>({ route, navigation, ...args }: Page.FactoryArgs.Static<TContent, TPreview>): Page<TContent, TPreview>;
35
+ static dynamic<TContent extends Page.Content, TPreview extends Page.PreviewTarget<TContent>>({ navigation, ...args }: Page.FactoryArgs.Dynamic<TContent, TPreview>): Page<TContent, TPreview>;
35
36
  }
36
37
  export declare namespace Page {
37
38
  type Content = Record<string, Content.Item>;
@@ -40,12 +41,13 @@ export declare namespace Page {
40
41
  type Blocks<TContent extends Content = Content> = {
41
42
  [TKey in StringKeyOf<TContent>]: TContent[TKey] extends Block ? TContent[TKey] : never;
42
43
  };
44
+ type BlockKeys<TContent extends Content = Content> = StringKeyOf<Blocks<TContent>>;
43
45
  }
44
46
  type PreviewTarget<TContent extends Content = Content> = StringKeyOf<Content.Blocks<TContent>>;
45
- type DisplayName<TContent extends Content = Content> = DisplayName.For<TContent>;
47
+ type DisplayName<TContent extends Content = any> = DisplayName.For<TContent>;
46
48
  namespace DisplayName {
47
49
  type For<TContent extends Content> = {
48
- [TKey in StringKeyOf<Content.Blocks<TContent>>]: TContent[TKey] extends Block<infer TId, infer TFields> ? `${TKey}.${keyof Fields.TextLikeFields<TFields>}` : never;
50
+ [TKey in StringKeyOf<Content.Blocks<TContent>>]: TContent[TKey] extends Block<infer TId, infer TFields> ? StringKeyOf<Fields.TextLikeFields<TFields>> extends string ? `${TKey}.${StringKeyOf<Fields.TextLikeFields<TFields>>}` : never : never;
49
51
  }[StringKeyOf<Content.Blocks<TContent>>];
50
52
  }
51
53
  type Update = Update.Page | Update.BlockCreate | Update.BlockDelete | Update.SectionInsert | Update.SectionDelete | Update.SectionReorder | Update.SectionBlockName | Update.ObjectInsert | Update.ArrayInsert | Update.ArrayDelete | Update.ArrayReorder | Update.Value;
@@ -229,7 +231,7 @@ export declare namespace Page {
229
231
  type Prop = Props.Id | Extract<Props.Content, 'preview'> | Props.Links | Props.Audit;
230
232
  const props: ReadonlyArray<Prop>;
231
233
  function from(data: LegacyData): AsPreview;
232
- function filter(data: LegacyData | AsPreview): data is Preview;
234
+ function filter(data: LegacyData | AsPreview): data is AsPreview;
233
235
  }
234
236
  type AsContent<TPage extends Page = Page, TRegion extends string = string> = Pick<LegacyData<TPage, TRegion>, AsContent.Prop>;
235
237
  namespace AsContent {
@@ -325,6 +327,7 @@ export declare namespace Page {
325
327
  optional?: boolean;
326
328
  preview?: TPreview;
327
329
  content: TContent;
330
+ navigation: ReadonlyArray<Content.BlockKeys<TContent>>;
328
331
  };
329
332
  type Static<TContent extends Content = Content, TPreview extends PreviewTarget<TContent> = PreviewTarget<TContent>> = Base<TContent, TPreview> & {
330
333
  variant: Extract<Variant, 'static'>;
@@ -341,8 +344,9 @@ export declare namespace Page {
341
344
  }
342
345
  }
343
346
  namespace FactoryArgs {
344
- type Base<TContent extends Content, TPreview extends PreviewTarget<TContent>> = Omit<ConstructorArgs.Base<TContent, TPreview>, 'route'> & {
347
+ type Base<TContent extends Content, TPreview extends PreviewTarget<TContent>> = Omit<ConstructorArgs.Base<TContent, TPreview>, 'route' | 'navigation'> & {
345
348
  route: Localized.Maybe<string>;
349
+ navigation?: Content.BlockKeys<TContent> | ReadonlyArray<Content.BlockKeys<TContent>>;
346
350
  };
347
351
  export type Static<TContent extends Content, TPreview extends PreviewTarget<TContent>> = Base<TContent, TPreview>;
348
352
  export type Dynamic<TContent extends Content, TPreview extends PreviewTarget<TContent>> = Base<TContent, TPreview> & Pick<ConstructorArgs.Dynamic<TContent, TPreview>, 'parent'>;
@@ -30,6 +30,7 @@ class Page {
30
30
  this.optional = (_b = args.optional) !== null && _b !== void 0 ? _b : false;
31
31
  this.preview = args.preview;
32
32
  this.content = args.content;
33
+ this.navigation = args.navigation;
33
34
  // or dynamic args (basic)
34
35
  if (Page.ConstructorArgs.Dynamic.filter(args)) {
35
36
  this.parent = args.parent;
@@ -65,10 +66,11 @@ class Page {
65
66
  this._type = type;
66
67
  }
67
68
  static static(_a) {
68
- var { route } = _a, args = __rest(_a, ["route"]);
69
- return new Page(Object.assign({ variant: 'static', route: route }, args));
69
+ var { route, navigation = [] } = _a, args = __rest(_a, ["route", "navigation"]);
70
+ return new Page(Object.assign({ variant: 'static', route: route, navigation: typeof navigation === 'string' ? [navigation] : navigation }, args));
70
71
  }
71
- static dynamic(args) {
72
+ static dynamic(_a) {
73
+ var { navigation = [] } = _a, args = __rest(_a, ["navigation"]);
72
74
  return new Page({
73
75
  variant: 'dynamic',
74
76
  route: args.route,
@@ -76,8 +78,9 @@ class Page {
76
78
  name: args.name,
77
79
  preview: args.preview,
78
80
  content: args.content,
81
+ navigation: typeof navigation === 'string' ? [navigation] : navigation,
79
82
  displayName: args.displayName,
80
- parent: args.parent,
83
+ parent: args.parent
81
84
  });
82
85
  }
83
86
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Site = void 0;
4
+ const app_1 = require("../app");
4
5
  const errors_1 = require("../errors");
5
6
  const utils_1 = require("../utils");
6
7
  const field_1 = require("./field");
@@ -11,6 +12,14 @@ class Site {
11
12
  // initialize instance variables
12
13
  this.regions = args.regions;
13
14
  this.collections = args.collections;
15
+ // blow up if we're mossing a region
16
+ const { regionalization } = app_1.AppConfig.brandConfig();
17
+ const expectedRegionIds = new Set(app_1.RegionsConfig.getRegions(regionalization).map(({ id }) => id));
18
+ const providedRegionIds = new Set(Object.keys(this.regions));
19
+ const missingRegionIds = expectedRegionIds.difference(providedRegionIds);
20
+ if (missingRegionIds.size > 0) {
21
+ throw new errors_1.ArgumentError('Site configuration is missing the following region(s): ' + missingRegionIds.values().toArray().join(', '));
22
+ }
14
23
  // bind pages within each region
15
24
  Object.values(this.regions).forEach(region => Object.entries(region).forEach(([pageType, page]) => page.bind(pageType)));
16
25
  }
@@ -0,0 +1,4 @@
1
+ export type PanelLayout = 'none' | 'solo' | 'stack.v' | 'stack.h' | 'brick.v' | 'brick.t' | 'brick.r' | 'brick.b' | 'brick.l' | 'nested' | 'nested.h' | 'nested.v' | 'nested.t' | 'nested.r' | 'nested.b' | 'nested.l';
2
+ export declare namespace PanelLayout {
3
+ type WithMultiSlots = Exclude<PanelLayout, 'solo'>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export type PanelSlot = 'M' | 'V' | 'L';
2
+ export type PanelSlots = {
3
+ message: boolean;
4
+ visual: boolean;
5
+ list: boolean;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,3 @@
1
1
  export * from './BlockLayout';
2
+ export * from './PanelLayout';
3
+ export * from './PanelSlot';
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BlockLayout"), exports);
18
+ __exportStar(require("./PanelLayout"), exports);
19
+ __exportStar(require("./PanelSlot"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-core",
3
- "version": "6.0.1",
3
+ "version": "6.1.1",
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": "83e335312f91fb90aae73dfc31b3df1ec1895f76"
68
+ "gitHead": "697c3651dedb43a6e6ff373a495cb29c7e7e1fc6"
69
69
  }