@nascentdigital/funnel-core 4.6.7 → 5.0.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.
@@ -81,6 +81,7 @@ export declare namespace Block {
81
81
  } & {
82
82
  [key in keyof T]: Field.Data<Optional.InnerType<T[key]>>;
83
83
  };
84
+ function filter(value: any): value is Data;
84
85
  }
85
86
  type LinkedData<T extends Block = Block> = Omit<Data<T>, 'fields'> & {
86
87
  fields: LinkedData.ForFields<T['fields']>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Block = void 0;
4
4
  const errors_1 = require("../errors");
5
+ const utils_1 = require("../utils");
5
6
  const Fields_1 = require("./Fields");
6
7
  const Optional_1 = require("./Optional");
7
8
  // class
@@ -132,4 +133,16 @@ exports.Block = Block;
132
133
  }
133
134
  Property.normalize = normalize;
134
135
  })(Property = Block.Property || (Block.Property = {}));
136
+ let Data;
137
+ (function (Data) {
138
+ // helpers
139
+ function filter(value) {
140
+ return !!value
141
+ && utils_1.Value.typeOf(value) === 'object'
142
+ && value.type === 'block'
143
+ && typeof value.id === 'string'
144
+ && typeof value.version === 'number';
145
+ }
146
+ Data.filter = filter;
147
+ })(Data = Block.Data || (Block.Data = {}));
135
148
  })(Block || (exports.Block = Block = {}));
@@ -1,6 +1,6 @@
1
1
  import { StringKeyOf } from 'type-fest';
2
2
  import { Transform } from '../types';
3
- import { AssetField, EnumField, Field, ListField, RichTextField, TextField } from './field';
3
+ import { AssetField, CollectionField, EnumField, Field, ListField, RichTextField, TextField } from './field';
4
4
  import { Optional } from './Optional';
5
5
  export type Fields = Record<string, Optional.Maybe<Field.Type>>;
6
6
  export declare namespace Fields {
@@ -38,6 +38,12 @@ export declare namespace Fields {
38
38
  namespace ListFields {
39
39
  type Keys<TFields extends Fields> = StringKeyOf<ListFields<TFields>>;
40
40
  }
41
+ type CollectionFields<TFields extends Fields> = {
42
+ [key in keyof TFields as TFields[key] extends CollectionField ? key : TFields[key] extends _Optional<CollectionField> ? key : never]: TFields[key];
43
+ };
44
+ namespace CollectionFields {
45
+ type Keys<TFields extends Fields> = StringKeyOf<CollectionFields<TFields>>;
46
+ }
41
47
  function unwrap<TFields extends Fields>(fields: TFields): UnwrapOptional<TFields>;
42
48
  }
43
49
  type _Optional<T extends Optional.Content> = Optional<T>;
@@ -112,7 +112,7 @@ exports.AssetField = AssetField;
112
112
  })(Tags = AssetField.Tags || (AssetField.Tags = {}));
113
113
  let Value;
114
114
  (function (Value) {
115
- // guard
115
+ // guards
116
116
  function filter(value) {
117
117
  return !!value
118
118
  && typeof value === 'object'
@@ -1,8 +1,8 @@
1
+ import { Size } from '../../../ui';
1
2
  import { Field } from '../index';
2
3
  export declare class EmbeddedVideoField extends Field<EmbeddedVideoField> {
3
4
  readonly type: "embedded.video";
4
- readonly allowMuting: boolean;
5
- constructor({ allowMuting, ...args }: EmbeddedVideoField.ConstructorArgs);
5
+ constructor(args: EmbeddedVideoField.ConstructorArgs);
6
6
  modify(args: EmbeddedVideoField.ModifyArgs): EmbeddedVideoField;
7
7
  }
8
8
  export declare namespace EmbeddedVideoField {
@@ -16,8 +16,8 @@ export declare namespace EmbeddedVideoField {
16
16
  type Youtube = {
17
17
  type: 'youtube';
18
18
  videoId: string;
19
+ dimensions: Size;
19
20
  thumbUrl: string;
20
- muted?: boolean;
21
21
  };
22
22
  namespace Youtube {
23
23
  function filter(data: Value): data is Youtube;
@@ -25,9 +25,9 @@ export declare namespace EmbeddedVideoField {
25
25
  type Vimeo = {
26
26
  type: 'vimeo';
27
27
  videoId: string;
28
+ dimensions: Size;
28
29
  thumbUrl: string;
29
30
  hash?: string;
30
- muted?: boolean;
31
31
  };
32
32
  namespace Vimeo {
33
33
  function filter(data: Value): data is Vimeo;
@@ -38,8 +38,6 @@ export declare namespace EmbeddedVideoField {
38
38
  function fromUrl(url?: URL): Value | undefined;
39
39
  function toUrl(value: Value, type?: 'watch' | 'embed'): URL;
40
40
  }
41
- type ConstructorArgs = Field.ConstructorArgs & {
42
- allowMuting?: boolean;
43
- };
41
+ type ConstructorArgs = Field.ConstructorArgs;
44
42
  type ModifyArgs = Omit<Partial<ConstructorArgs>, 'required'>;
45
43
  }
@@ -1,30 +1,16 @@
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
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.EmbeddedVideoField = void 0;
15
4
  const index_1 = require("../index");
16
5
  // class
17
6
  class EmbeddedVideoField extends index_1.Field {
18
- constructor(_a) {
19
- var { allowMuting = true } = _a, args = __rest(_a, ["allowMuting"]);
7
+ constructor(args) {
20
8
  // construct base
21
9
  super(args);
22
10
  this.type = 'embedded.video';
23
- // initialize instance variables
24
- this.allowMuting = allowMuting;
25
11
  }
26
12
  modify(args) {
27
- return new EmbeddedVideoField(Object.assign({ name: this.name, hint: this.hint, description: this.description, required: this.required, allowMuting: this.allowMuting }, args));
13
+ return new EmbeddedVideoField(Object.assign({ name: this.name, hint: this.hint, description: this.description, required: this.required }, args));
28
14
  }
29
15
  }
30
16
  exports.EmbeddedVideoField = EmbeddedVideoField;
@@ -102,7 +88,8 @@ exports.EmbeddedVideoField = EmbeddedVideoField;
102
88
  return {
103
89
  type: 'youtube',
104
90
  videoId: pathComponents[1],
105
- thumbUrl: ''
91
+ thumbUrl: '',
92
+ dimensions: { width: 0, height: 0 }
106
93
  };
107
94
  }
108
95
  else if (action === 'watch') {
@@ -112,7 +99,8 @@ exports.EmbeddedVideoField = EmbeddedVideoField;
112
99
  {
113
100
  type: 'youtube',
114
101
  videoId,
115
- thumbUrl: ''
102
+ thumbUrl: '',
103
+ dimensions: { width: 0, height: 0 }
116
104
  }
117
105
  : undefined;
118
106
  }
@@ -130,6 +118,7 @@ exports.EmbeddedVideoField = EmbeddedVideoField;
130
118
  {
131
119
  type: 'vimeo',
132
120
  videoId,
121
+ dimensions: { width: 0, height: 0 },
133
122
  thumbUrl: '',
134
123
  hash
135
124
  }
@@ -142,6 +131,7 @@ exports.EmbeddedVideoField = EmbeddedVideoField;
142
131
  return {
143
132
  type: 'vimeo',
144
133
  videoId: pathComponents[1],
134
+ dimensions: { width: 0, height: 0 },
145
135
  thumbUrl: '',
146
136
  hash
147
137
  };
@@ -1,11 +1,11 @@
1
- import { Optional } from '../../Optional';
2
- import { Field, ListField, AssetField } from '../index';
1
+ import type { Optional } from '../../Optional';
2
+ import { AssetField, Field, ListField } from '../index';
3
3
  export declare class ObjectField<TContent extends ObjectField.Content = ObjectField.Content> extends Field<ObjectField<TContent>> {
4
4
  readonly type: "object";
5
5
  readonly content: TContent;
6
6
  readonly preview: Readonly<ObjectField.Preview<TContent>>;
7
7
  constructor(args: ObjectField.ConstructorArgs<TContent>);
8
- modify(args: ObjectField.ModifyArgs): ObjectField<TContent>;
8
+ modify(args: ObjectField.ModifyArgs<TContent>): ObjectField<TContent>;
9
9
  }
10
10
  export declare namespace ObjectField {
11
11
  type _Optional<T extends Optional.Content> = Optional<T>;
@@ -46,7 +46,7 @@ export declare namespace ObjectField {
46
46
  preview: Preview<TContent>;
47
47
  content: TContent;
48
48
  };
49
- export type ModifyArgs = Partial<Field.ConstructorArgs>;
49
+ export type ModifyArgs<TContent extends Content> = Partial<ConstructorArgs<TContent>>;
50
50
  export type Preview<TContent extends Content = Content> = {
51
51
  title: keyof Content.Required<Content.Text<TContent>>;
52
52
  subtitle?: keyof Content.Text<TContent>;
@@ -1,16 +1,18 @@
1
1
  import { Observable } from 'rxjs';
2
+ import { StringKeyOf } from 'type-fest';
2
3
  import * as Schema from '../../schema';
3
4
  import { EventBus } from '../../services';
4
5
  import { Field } from './Field';
5
6
  import { FieldList } from './FieldList';
6
7
  import { FieldModel } from './FieldModel';
7
8
  import { FieldValidator } from './FieldValidator';
8
- export declare class ObjectField {
9
- readonly schema: Schema.ObjectField;
9
+ import { SchemaToField } from './SchemaToField';
10
+ export declare class ObjectField<TObject extends Schema.ObjectField = Schema.ObjectField> {
11
+ readonly schema: TObject;
10
12
  readonly id: string;
11
13
  readonly name: string;
12
14
  readonly required: boolean;
13
- readonly publishedValue: ObjectField.Value | undefined;
15
+ readonly publishedValue: ObjectField.Value<TObject> | undefined;
14
16
  private readonly eventBus;
15
17
  private readonly _content;
16
18
  private readonly _fields;
@@ -21,7 +23,7 @@ export declare class ObjectField {
21
23
  private _optOut?;
22
24
  constructor(args: ObjectField.ConstructorArgs);
23
25
  get events$(): Observable<FieldModel.Event>;
24
- get initialValue(): ObjectField.Value | undefined;
26
+ get initialValue(): ObjectField.Value<TObject> | undefined;
25
27
  get exists(): boolean;
26
28
  get isNew(): boolean;
27
29
  get valid(): boolean;
@@ -29,9 +31,10 @@ export declare class ObjectField {
29
31
  get errors(): FieldValidator.Error[];
30
32
  get content(): Readonly<ObjectField.Fields>;
31
33
  get fields(): readonly ObjectField.FieldsValues[];
34
+ getField<TFields extends ObjectField.GetField.Fields<TObject>, TFieldId extends StringKeyOf<TFields>>(fieldId: TFieldId): SchemaToField<TFields[TFieldId]>;
32
35
  get hasValue(): boolean;
33
- get value(): ObjectField.Value;
34
- set value(value: ObjectField.Value);
36
+ get value(): ObjectField.Value<TObject>;
37
+ set value(value: ObjectField.Value<TObject>);
35
38
  get modified(): boolean;
36
39
  get changed(): boolean;
37
40
  get preview(): ObjectField.Preview;
@@ -44,12 +47,24 @@ export declare class ObjectField {
44
47
  getString(key: string | undefined): string | undefined;
45
48
  onSaveStart(): void;
46
49
  onSaveComplete(): void;
47
- reset(initialValue?: ObjectField.Value | null): void;
50
+ reset(initialValue?: ObjectField.Value<TObject> | null): void;
48
51
  clone(): ObjectField;
49
52
  private raiseEvent;
50
53
  static forSchema(schema: Schema.ObjectField): ObjectField;
51
54
  }
52
55
  export declare namespace ObjectField {
56
+ type Fields = Record<string, FieldsValues>;
57
+ type FieldsValues = Field | FieldList | ObjectField;
58
+ type Value<TObject extends Schema.ObjectField = Schema.ObjectField> = Schema.Field.Data<TObject>;
59
+ type Data<TObject extends Schema.ObjectField = Schema.ObjectField> = Value<TObject>['value'];
60
+ type Preview = {
61
+ title: Field<Schema.TextField | Schema.RichTextField>;
62
+ subtitle?: Field<Schema.TextField | Schema.RichTextField>;
63
+ visual?: Field<Schema.AssetField>;
64
+ };
65
+ namespace GetField {
66
+ type Fields<TObject extends Schema.ObjectField> = Schema.Fields.UnwrapOptional<TObject['content']>;
67
+ }
53
68
  type ConstructorArgs = {
54
69
  eventBus: EventBus;
55
70
  schema: Schema.ObjectField;
@@ -59,15 +74,6 @@ export declare namespace ObjectField {
59
74
  initialValue?: Value;
60
75
  required: boolean;
61
76
  };
62
- type Value = Schema.Field.Data<Schema.ObjectField>;
63
- type Fields = Record<string, FieldsValues>;
64
- type FieldsValues = Field | FieldList | ObjectField;
65
- type Data = Record<string, Schema.Field.Data<Schema.ObjectField.Content.Type>>;
66
- type Preview = {
67
- title: Field<Schema.TextField | Schema.RichTextField>;
68
- subtitle?: Field<Schema.TextField | Schema.RichTextField>;
69
- visual?: Field<Schema.AssetField>;
70
- };
71
77
  interface Event extends EventBus.Event<'ObjectField', Event.Type> {
72
78
  field: ObjectField;
73
79
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectField = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
+ const errors_1 = require("../../errors");
5
6
  const services_1 = require("../../services");
6
7
  const utils_1 = require("../../utils");
7
8
  const Field_1 = require("./Field");
@@ -61,6 +62,15 @@ class ObjectField {
61
62
  get fields() {
62
63
  return this._fields;
63
64
  }
65
+ getField(fieldId) {
66
+ // find field (or throw)
67
+ const field = this._fields.find(field => field.id === fieldId);
68
+ if (!field) {
69
+ throw new errors_1.IllegalStateError(`${this.schema.type} object doesn't seem to have the ${fieldId} field`);
70
+ }
71
+ // return field
72
+ return field;
73
+ }
64
74
  get hasValue() {
65
75
  return this._fields.some(field => field.hasValue);
66
76
  }
@@ -68,8 +78,9 @@ class ObjectField {
68
78
  // reduce value from fields
69
79
  return {
70
80
  type: 'object',
71
- value: this._fields.reduce((values, { id, value }) => {
81
+ value: this._fields.reduce((valuesRaw, { id, value }) => {
72
82
  // bind value if it's set
83
+ const values = valuesRaw;
73
84
  if (value !== undefined) {
74
85
  values[id] = value;
75
86
  }
@@ -279,9 +290,15 @@ function deserializeFields({ eventBus, schema, initialValue }) {
279
290
  case 'richtext':
280
291
  case 'enum':
281
292
  case 'boolean':
293
+ case 'timestamp':
294
+ case 'date':
282
295
  case 'link':
283
296
  case 'asset':
297
+ case 'embedded.video':
298
+ case 'page':
299
+ case 'dynamic.pages':
284
300
  case 'collection':
301
+ case 'form':
285
302
  fields[id] = new Field_1.Field({
286
303
  eventBus,
287
304
  schema: fieldSchema,
@@ -0,0 +1,7 @@
1
+ import * as Schema from '../../schema';
2
+ import { Field } from './Field';
3
+ import { ObjectField } from './ObjectField';
4
+ export type SchemaToField<T extends Schema.Field.Type> = T extends Schema.TextField ? Field<Schema.TextField> : T extends Schema.RichTextField ? Field<Schema.RichTextField> : T extends Schema.EnumField ? Field<Schema.EnumField> : T extends Schema.BooleanField ? Field<Schema.BooleanField> : T extends Schema.DateField ? Field<Schema.DateField> : T extends Schema.TimestampField ? Field<Schema.TimestampField> : T extends Schema.LinkField ? Field<Schema.LinkField> : T extends Schema.EmbeddedVideoField ? Field<Schema.EmbeddedVideoField> : T extends Schema.AssetField<infer F> ? Field<Schema.AssetField<F>> : T extends Schema.CollectionField ? Field<Schema.CollectionField> : T extends Schema.PageField ? Field<Schema.PageField> : T extends Schema.ObjectField<infer O> ? ObjectField<T> : T extends Schema.DynamicPagesField ? Field<Schema.DynamicPagesField> : never;
5
+ export type SchemaToFields<TFields extends Record<string, Schema.Optional.Maybe<Schema.Field.Type>>> = {
6
+ [TKey in keyof TFields]: SchemaToField<Schema.Optional.InnerType<TFields[TKey]>>;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -5,4 +5,5 @@ export * from './FieldModel';
5
5
  export * from './FieldSerializer';
6
6
  export * from './FieldValidator';
7
7
  export * from './ObjectField';
8
+ export * from './SchemaToField';
8
9
  export * from './validators/ValidatorHelper';
@@ -21,4 +21,5 @@ __exportStar(require("./FieldModel"), exports);
21
21
  __exportStar(require("./FieldSerializer"), exports);
22
22
  __exportStar(require("./FieldValidator"), exports);
23
23
  __exportStar(require("./ObjectField"), exports);
24
+ __exportStar(require("./SchemaToField"), exports);
24
25
  __exportStar(require("./validators/ValidatorHelper"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-core",
3
- "version": "4.6.7",
3
+ "version": "5.0.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": "b17e33b4400391b3984e61225c572f097c4c26c9"
68
+ "gitHead": "6ac66e04e5d6d10b959826b84cf3827422ddf47b"
69
69
  }