@nascentdigital/funnel-core 6.1.9 → 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.
- package/dist/schema/Block.d.ts +10 -0
- package/dist/schema/Block.js +22 -0
- package/dist/schema/Optional.d.ts +2 -2
- package/dist/schema/Page.d.ts +7 -1
- package/dist/schema/PageModel.d.ts +1 -0
- package/dist/schema/PageModel.js +53 -4
- package/dist/schema/Site.js +2 -2
- package/dist/schema/blocks/PanelledBlock.d.ts +2 -0
- package/dist/schema/blocks/PanelledBlock.js +4 -0
- package/dist/schema/config/index.d.ts +1 -0
- package/dist/schema/config/index.js +2 -0
- package/dist/schema/field/Config.d.ts +10 -0
- package/dist/schema/field/Config.js +19 -0
- package/dist/schema/field/Field.d.ts +8 -8
- package/dist/schema/field/base/EnumField.d.ts +1 -0
- package/dist/schema/field/base/EnumField.js +8 -5
- package/dist/schema/field/config/BooleanConfig.d.ts +14 -0
- package/dist/schema/field/config/BooleanConfig.js +18 -0
- package/dist/schema/field/config/EnumConfig.d.ts +22 -0
- package/dist/schema/field/config/EnumConfig.js +62 -0
- package/dist/schema/field/config/TextConfig.d.ts +14 -0
- package/dist/schema/field/config/TextConfig.js +18 -0
- package/dist/schema/field/config/index.d.ts +3 -0
- package/dist/schema/field/config/index.js +19 -0
- package/dist/schema/field/index.d.ts +2 -0
- package/dist/schema/field/index.js +2 -0
- package/dist/services/Logger.d.ts +3 -1
- package/dist/services/Logger.js +11 -1
- package/dist/ui/fields/ConfigModel.d.ts +6 -0
- package/dist/ui/fields/ConfigModel.js +49 -0
- package/dist/ui/fields/Field.d.ts +8 -4
- package/dist/ui/fields/Field.js +32 -7
- package/dist/ui/fields/FieldList.d.ts +1 -1
- package/dist/ui/fields/FieldList.js +3 -0
- package/dist/ui/fields/ObjectField.d.ts +1 -1
- package/dist/ui/fields/ObjectField.js +3 -0
- package/dist/ui/fields/index.d.ts +1 -0
- package/dist/ui/fields/index.js +1 -0
- package/package.json +2 -2
package/dist/schema/Block.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class Block<TId extends string = string, TFields extends Fields =
|
|
|
15
15
|
readonly config: Block.Config.UnwrapOptional<TConfig>;
|
|
16
16
|
readonly getConfig?: Block.GetConfig<TFields, TConfig>;
|
|
17
17
|
protected constructor(args: Block.ConstructorArgs<TId, TFields, TConfig>);
|
|
18
|
+
get isPanelled(): boolean;
|
|
18
19
|
optional(): Optional<Block<TId, TFields, TConfig>>;
|
|
19
20
|
unwrap(): this;
|
|
20
21
|
modify(args: Block.ModifyArgs<TId, TFields, TConfig>): Block<TId, TFields, TConfig>;
|
|
@@ -39,6 +40,13 @@ export declare namespace Block {
|
|
|
39
40
|
}
|
|
40
41
|
type Config = Record<string, Optional.Maybe<Field.Type.Simple.Configuration>>;
|
|
41
42
|
namespace Config {
|
|
43
|
+
type Variant = 'base' | 'mobile' | 'tablet';
|
|
44
|
+
namespace Variant {
|
|
45
|
+
const values: ReadonlyArray<Variant>;
|
|
46
|
+
type Override = Exclude<Variant, 'base'>;
|
|
47
|
+
type BlockKey = Extract<keyof Data, 'config' | 'configMobile' | 'configTablet'>;
|
|
48
|
+
function getBlockKey(variant: Variant): BlockKey;
|
|
49
|
+
}
|
|
42
50
|
type UnwrapOptional<TConfig extends Config> = {
|
|
43
51
|
[key in keyof TConfig]: Optional.InnerType<TConfig[key]>;
|
|
44
52
|
};
|
|
@@ -64,6 +72,8 @@ export declare namespace Block {
|
|
|
64
72
|
id: T['id'];
|
|
65
73
|
version: number;
|
|
66
74
|
config: Data.ForConfig<T['config']>;
|
|
75
|
+
configMobile?: Data.ForConfig<T['config']>;
|
|
76
|
+
configTablet?: Data.ForConfig<T['config']>;
|
|
67
77
|
fields: Data.ForFields<T['fields']>;
|
|
68
78
|
};
|
|
69
79
|
namespace Data {
|
package/dist/schema/Block.js
CHANGED
|
@@ -30,6 +30,9 @@ class Block {
|
|
|
30
30
|
: {};
|
|
31
31
|
this.getConfig = args.getConfig;
|
|
32
32
|
}
|
|
33
|
+
get isPanelled() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
33
36
|
optional() {
|
|
34
37
|
return new Optional_1.Optional(this);
|
|
35
38
|
}
|
|
@@ -131,6 +134,25 @@ exports.Block = Block;
|
|
|
131
134
|
}
|
|
132
135
|
Property.normalize = normalize;
|
|
133
136
|
})(Property = Block.Property || (Block.Property = {}));
|
|
137
|
+
let Config;
|
|
138
|
+
(function (Config) {
|
|
139
|
+
let Variant;
|
|
140
|
+
(function (Variant) {
|
|
141
|
+
// constants
|
|
142
|
+
Variant.values = ['base', 'mobile', 'tablet'];
|
|
143
|
+
function getBlockKey(variant) {
|
|
144
|
+
switch (variant) {
|
|
145
|
+
case 'mobile':
|
|
146
|
+
return 'configMobile';
|
|
147
|
+
case 'tablet':
|
|
148
|
+
return 'configTablet';
|
|
149
|
+
default:
|
|
150
|
+
return 'config';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
Variant.getBlockKey = getBlockKey;
|
|
154
|
+
})(Variant = Config.Variant || (Config.Variant = {}));
|
|
155
|
+
})(Config = Block.Config || (Block.Config = {}));
|
|
134
156
|
let Data;
|
|
135
157
|
(function (Data) {
|
|
136
158
|
// helpers
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Block } from './Block';
|
|
2
|
-
import { Field } from './field';
|
|
2
|
+
import { Config, Field } from './field';
|
|
3
3
|
export declare class Optional<T extends Optional.Content = Optional.Content> {
|
|
4
4
|
readonly type = "optional";
|
|
5
5
|
readonly schema: T;
|
|
@@ -10,7 +10,7 @@ export declare class Optional<T extends Optional.Content = Optional.Content> {
|
|
|
10
10
|
require(): T;
|
|
11
11
|
}
|
|
12
12
|
export declare namespace Optional {
|
|
13
|
-
type Content = Field.Type | Block;
|
|
13
|
+
type Content = Field.Type | Config.Type | Block;
|
|
14
14
|
type Maybe<T extends Content> = T | Optional<T>;
|
|
15
15
|
type InnerType<T extends Content | Optional<Content>> = T extends Optional<Content> ? T['schema'] : T;
|
|
16
16
|
function unwrap<T extends Content = any>(maybeOptional: Maybe<T>): unwrap.Result<T>;
|
package/dist/schema/Page.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare namespace Page {
|
|
|
50
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;
|
|
51
51
|
}[StringKeyOf<Content.Blocks<TContent>>];
|
|
52
52
|
}
|
|
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;
|
|
53
|
+
type Update = Update.Page | Update.BlockCreate | Update.BlockDelete | Update.BlockConfig | Update.SectionInsert | Update.SectionDelete | Update.SectionReorder | Update.SectionBlockName | Update.ObjectInsert | Update.ArrayInsert | Update.ArrayDelete | Update.ArrayReorder | Update.Value;
|
|
54
54
|
namespace Update {
|
|
55
55
|
type Page = Page.Name | Page.Tags | Page.Slug | Page.Url | Page.Preview | Page.Errors | Page.Publication;
|
|
56
56
|
namespace Page {
|
|
@@ -79,6 +79,12 @@ export declare namespace Page {
|
|
|
79
79
|
type: 'block.delete';
|
|
80
80
|
path: [string, string];
|
|
81
81
|
};
|
|
82
|
+
type BlockConfig = {
|
|
83
|
+
type: 'block.config';
|
|
84
|
+
path: string[];
|
|
85
|
+
variant: Block.Config.Variant;
|
|
86
|
+
value: Block.Data.ForConfig | null;
|
|
87
|
+
};
|
|
82
88
|
type Value = {
|
|
83
89
|
type: 'value';
|
|
84
90
|
path: string[];
|
|
@@ -18,6 +18,7 @@ export declare class PageModel<TPage extends Page = Page> {
|
|
|
18
18
|
update(updates: ReadonlyArray<Page.Update>): void;
|
|
19
19
|
private updatePage;
|
|
20
20
|
private updateBlockCreate;
|
|
21
|
+
private updateBlockConfig;
|
|
21
22
|
private updateBlockDelete;
|
|
22
23
|
private updateSectionInsert;
|
|
23
24
|
private updateSectionDelete;
|
package/dist/schema/PageModel.js
CHANGED
|
@@ -16,6 +16,7 @@ const app_1 = require("../app");
|
|
|
16
16
|
const errors_1 = require("../errors");
|
|
17
17
|
const regionalization_1 = require("../regionalization");
|
|
18
18
|
const utils_1 = require("../utils");
|
|
19
|
+
const Block_1 = require("./Block");
|
|
19
20
|
const field_1 = require("./field");
|
|
20
21
|
const Page_1 = require("./Page");
|
|
21
22
|
const PageRoute_1 = require("./PageRoute");
|
|
@@ -67,6 +68,9 @@ class PageModel {
|
|
|
67
68
|
case 'block.delete':
|
|
68
69
|
this.updateBlockDelete(update);
|
|
69
70
|
break;
|
|
71
|
+
case 'block.config':
|
|
72
|
+
this.updateBlockConfig(update);
|
|
73
|
+
break;
|
|
70
74
|
case 'section.insert':
|
|
71
75
|
this.updateSectionInsert(update);
|
|
72
76
|
break;
|
|
@@ -131,6 +135,51 @@ class PageModel {
|
|
|
131
135
|
root[key] = update.block;
|
|
132
136
|
}
|
|
133
137
|
}
|
|
138
|
+
updateBlockConfig(update) {
|
|
139
|
+
var _a;
|
|
140
|
+
console.debug(`[PageChanges/updateBlockConfig] executing block config update`, update);
|
|
141
|
+
// resolve target
|
|
142
|
+
const { data: page } = this;
|
|
143
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
144
|
+
const root = ((_a = page[area]) !== null && _a !== void 0 ? _a : {});
|
|
145
|
+
const target = this.find(root, {
|
|
146
|
+
path,
|
|
147
|
+
parentPath: [area],
|
|
148
|
+
issues: []
|
|
149
|
+
});
|
|
150
|
+
// skip if target can't be resolved (track issue)
|
|
151
|
+
if (!target) {
|
|
152
|
+
// TODO: track issue
|
|
153
|
+
console.warn(`[PageChanges/updateBlockConfig] no target to update for path`, { area, path });
|
|
154
|
+
// stop processing
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// skip if target isn't a block
|
|
158
|
+
else if (target.type !== 'block') {
|
|
159
|
+
// TODO: track issue
|
|
160
|
+
console.warn(`[PageChanges/updateBlockConfig] target is not a block`, { area, path, target });
|
|
161
|
+
// stop processing
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// replace config
|
|
165
|
+
const { variant, value } = update;
|
|
166
|
+
const blockKey = Block_1.Block.Config.Variant.getBlockKey(variant);
|
|
167
|
+
if (value) {
|
|
168
|
+
console.debug(`[PageChanges/updateBlockConfig] setting block "${blockKey}" to`, value);
|
|
169
|
+
target[blockKey] = value;
|
|
170
|
+
}
|
|
171
|
+
// or delete it (make sure we're not nuking the base)
|
|
172
|
+
else if (variant !== 'base') {
|
|
173
|
+
console.debug(`[PageChanges/updateBlockConfig] clearing block "${blockKey}"`);
|
|
174
|
+
delete target[blockKey];
|
|
175
|
+
}
|
|
176
|
+
// or skip
|
|
177
|
+
else {
|
|
178
|
+
// TODO: track issue
|
|
179
|
+
console.warn(`[PageChanges/updateBlockConfig] unable to delete core config`, { area, path, target });
|
|
180
|
+
}
|
|
181
|
+
console.warn(`[PageChanges/updateValue] updated value for "${path.join('.')}" to:`, value);
|
|
182
|
+
}
|
|
134
183
|
updateBlockDelete(update) {
|
|
135
184
|
var _a;
|
|
136
185
|
// resolve target
|
|
@@ -493,13 +542,13 @@ class PageModel {
|
|
|
493
542
|
else if (target.type === 'block') {
|
|
494
543
|
// update config
|
|
495
544
|
const bucket = utils_1.ArrayUtils.last(parentPath);
|
|
496
|
-
if (bucket === 'config') {
|
|
545
|
+
if (bucket === 'config' || bucket === 'configMobile' || bucket === 'configTablet') {
|
|
497
546
|
// get config (or create it)
|
|
498
|
-
let config = target
|
|
547
|
+
let config = target[bucket];
|
|
499
548
|
if (!config) {
|
|
500
549
|
console.debug(`[PageChanges/setValue] creating new config for block at "${parentPath.join('.')}"`);
|
|
501
550
|
config = {};
|
|
502
|
-
target
|
|
551
|
+
target[bucket] = config;
|
|
503
552
|
}
|
|
504
553
|
// delete if there's no value
|
|
505
554
|
if (data === null || data === undefined) {
|
|
@@ -686,7 +735,7 @@ class PageModel {
|
|
|
686
735
|
}
|
|
687
736
|
// fail if there's not at least 2 keys
|
|
688
737
|
else if (path.length < 2) {
|
|
689
|
-
console.warn(`[PageChanges/findInBlock] invalid path for block in "${block.
|
|
738
|
+
console.warn(`[PageChanges/findInBlock] invalid path for block in "${block.id}/${parentPath.join('.')}"`, path);
|
|
690
739
|
return undefined;
|
|
691
740
|
}
|
|
692
741
|
// fail if we can't pull the bucket
|
package/dist/schema/Site.js
CHANGED
|
@@ -108,8 +108,8 @@ exports.Site = Site;
|
|
|
108
108
|
// look for collection fields
|
|
109
109
|
if (value instanceof field_1.CollectionField) {
|
|
110
110
|
collections.push(...value.collections);
|
|
111
|
-
//
|
|
112
|
-
return
|
|
111
|
+
// keep recursing
|
|
112
|
+
return true;
|
|
113
113
|
}
|
|
114
114
|
// otherwise keep recursing
|
|
115
115
|
return true;
|
|
@@ -8,6 +8,7 @@ export declare class PanelledBlock<TId extends string = string, TFields extends
|
|
|
8
8
|
readonly defaultPanelLayouts: PanelledBlock.DefaultPanelLayouts;
|
|
9
9
|
readonly defaultLayoutConfigs: PanelledBlock.DefaultLayoutConfigs<TConfig>;
|
|
10
10
|
protected constructor({ getConfig, defaultContent, getLayout, defaultPanelLayouts, defaultLayoutConfigs, ...args }: PanelledBlock.ConstructorArgs<TId, TFields, TConfig>);
|
|
11
|
+
get isPanelled(): boolean;
|
|
11
12
|
modify(args: Block.ModifyArgs<TId, TFields, TConfig>): PanelledBlock<TId, TFields, TConfig>;
|
|
12
13
|
/**
|
|
13
14
|
* Rename a block's name which is used in the editor.
|
|
@@ -57,6 +58,7 @@ export declare namespace PanelledBlock {
|
|
|
57
58
|
type GetLayout<TFields extends Fields = Fields, TConfig extends Config = Config> = Transform<GetLayout.Args<TFields, TConfig>, BlockLayout>;
|
|
58
59
|
namespace GetLayout {
|
|
59
60
|
type Args<TFields extends Fields, TConfig extends Config> = {
|
|
61
|
+
variant: Block.Config.Variant;
|
|
60
62
|
config: Partial<Block.Data.ForConfig<Config.UnwrapOptional<TConfig>>> | Partial<Block.LinkedData.ForConfig<Config.UnwrapOptional<TConfig>>>;
|
|
61
63
|
fields: Partial<Block.Data.ForFields<TFields>> | Partial<Block.LinkedData.ForFields<TFields>>;
|
|
62
64
|
};
|
|
@@ -28,6 +28,9 @@ class PanelledBlock extends Block_1.Block {
|
|
|
28
28
|
this.defaultPanelLayouts = defaultPanelLayouts !== null && defaultPanelLayouts !== void 0 ? defaultPanelLayouts : {};
|
|
29
29
|
this.defaultLayoutConfigs = defaultLayoutConfigs !== null && defaultLayoutConfigs !== void 0 ? defaultLayoutConfigs : {};
|
|
30
30
|
}
|
|
31
|
+
get isPanelled() {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
31
34
|
modify(args) {
|
|
32
35
|
// create new block (re-map required fields)
|
|
33
36
|
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));
|
|
@@ -64,6 +67,7 @@ class PanelledBlock extends Block_1.Block {
|
|
|
64
67
|
return fields;
|
|
65
68
|
}, Object.assign({}, this.editableFields)),
|
|
66
69
|
config: this.config,
|
|
70
|
+
getConfig: this.getConfig,
|
|
67
71
|
getLayout: this.getLayout,
|
|
68
72
|
defaultContent: this.defaultContent,
|
|
69
73
|
defaultPanelLayouts: this.defaultPanelLayouts,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BooleanField, EnumField, TextField } from './base';
|
|
2
|
+
import { BooleanConfig, EnumConfig, TextConfig } from './config/index';
|
|
3
|
+
import type { Field } from './Field';
|
|
4
|
+
export declare namespace Config {
|
|
5
|
+
type Type = BooleanConfig | EnumConfig | TextConfig;
|
|
6
|
+
function isConfig(field: Field | Type): field is Config.Type;
|
|
7
|
+
const text: (args: TextConfig.ConstructorArgs) => TextField;
|
|
8
|
+
const enumeration: <T extends EnumField.Options>(args: EnumConfig.ConstructorArgs<T>) => EnumField<T>;
|
|
9
|
+
const boolean: (args: BooleanConfig.ConstructorArgs) => BooleanField;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Config = void 0;
|
|
4
|
+
const index_1 = require("./config/index");
|
|
5
|
+
// namespace
|
|
6
|
+
var Config;
|
|
7
|
+
(function (Config) {
|
|
8
|
+
// guard
|
|
9
|
+
function isConfig(field) {
|
|
10
|
+
return field instanceof index_1.BooleanConfig
|
|
11
|
+
|| field instanceof index_1.EnumConfig
|
|
12
|
+
|| field instanceof index_1.TextConfig;
|
|
13
|
+
}
|
|
14
|
+
Config.isConfig = isConfig;
|
|
15
|
+
// factories
|
|
16
|
+
Config.text = (args) => new index_1.TextConfig(args);
|
|
17
|
+
Config.enumeration = (args) => new index_1.EnumConfig(args);
|
|
18
|
+
Config.boolean = (args) => new index_1.BooleanConfig(args);
|
|
19
|
+
})(Config || (exports.Config = Config = {}));
|
|
@@ -2,7 +2,7 @@ import type { RequiredBy } from '../../types';
|
|
|
2
2
|
import { Collection as CollectionType } from '../Collection';
|
|
3
3
|
import { Optional } from '../Optional';
|
|
4
4
|
import type { Page as PageType } from '../Page';
|
|
5
|
-
import { AssetField, BooleanField, CollectionField, DateField, DynamicPagesField, EmbeddedVideoField, EnumField, FormField, LinkField, ListField, ObjectField, PageField, RichTextField, TextField, TimestampField } from './';
|
|
5
|
+
import { AssetField, BooleanConfig, BooleanField, CollectionField, DateField, DynamicPagesField, EmbeddedVideoField, EnumConfig, EnumField, FormField, LinkField, ListField, ObjectField, PageField, RichTextField, TextConfig, TextField, TimestampField } from './';
|
|
6
6
|
export declare abstract class Field<TChild extends Field.Type = Field.Type> {
|
|
7
7
|
readonly name: string;
|
|
8
8
|
readonly hint?: string;
|
|
@@ -26,7 +26,7 @@ export declare namespace Field {
|
|
|
26
26
|
type Type = Type.Simple | Type.Composite;
|
|
27
27
|
namespace Type {
|
|
28
28
|
type Id = Simple.Id | Composite.Id;
|
|
29
|
-
type Simple = Simple.NonAggregate | Simple.Aggregate;
|
|
29
|
+
type Simple = Simple.NonAggregate | Simple.Aggregate | Simple.Configuration;
|
|
30
30
|
namespace Simple {
|
|
31
31
|
type Id = Simple['type'];
|
|
32
32
|
type Text = TextField | RichTextField | EnumField;
|
|
@@ -35,7 +35,7 @@ export declare namespace Field {
|
|
|
35
35
|
type MaybeRef = CollectionField;
|
|
36
36
|
type NonAggregate = Text | BooleanField | DateField | TimestampField | DynamicPagesField;
|
|
37
37
|
type NonRef = NonAggregate | LinkField | FormField | EmbeddedVideoField;
|
|
38
|
-
type Configuration =
|
|
38
|
+
type Configuration = TextField | EnumField | BooleanField;
|
|
39
39
|
type Aggregate = Complex | Ref;
|
|
40
40
|
namespace Aggregate {
|
|
41
41
|
function filter(field: Type): field is Aggregate;
|
|
@@ -50,11 +50,11 @@ export declare namespace Field {
|
|
|
50
50
|
}
|
|
51
51
|
type Value<T extends Type = Type> = T extends Type.Simple ? Value.ForSimpleType<T> : T extends Type.Composite ? Value.ForCompositeType<T> : never;
|
|
52
52
|
namespace Value {
|
|
53
|
-
type ForSimpleType<T extends Type.Simple> = T extends TextField ? TextField.Value : T extends RichTextField ? RichTextField.Value : T extends EnumField ? EnumField.Value<T> : T extends BooleanField ? BooleanField.Value : T extends DateField ? DateField.Value : T extends DynamicPagesField ? DynamicPagesField.Value : T extends TimestampField ? TimestampField.Value : T extends LinkField ? LinkField.Value : T extends FormField ? FormField.Value : T extends EmbeddedVideoField ? EmbeddedVideoField.Value : T extends AssetField<infer F> ? AssetField.Value<F> : T extends CollectionField<infer C> ? CollectionField.Value<C> : T extends PageField<infer S> ? PageField.Value<S> :
|
|
54
|
-
type ForSimpleRefType<T extends Type.Simple.MaybeRef> = T extends CollectionField ? CollectionField.Value.ForRef :
|
|
55
|
-
type ForSimpleInlineType<T extends Type.Simple.MaybeRef> = T extends CollectionField ? CollectionField.Value.ForInline :
|
|
56
|
-
type ForCompositeType<T extends Type.Composite> = T extends ObjectField ? ObjectField.Value<T> : T extends ListField ? ListField.Value<T> :
|
|
57
|
-
type ForOptionalType<T extends Optional.Maybe<Type>> = T extends Optional<any> ? Value<T['schema']> | undefined : T extends Type ? Value<T> :
|
|
53
|
+
type ForSimpleType<T extends Type.Simple> = T extends TextField ? TextField.Value : T extends TextConfig ? TextField.Value : T extends RichTextField ? RichTextField.Value : T extends EnumField ? EnumField.Value<T> : T extends EnumConfig ? EnumField.Value<T> : T extends BooleanField ? BooleanField.Value : T extends BooleanConfig ? BooleanField.Value : T extends DateField ? DateField.Value : T extends DynamicPagesField ? DynamicPagesField.Value : T extends TimestampField ? TimestampField.Value : T extends LinkField ? LinkField.Value : T extends FormField ? FormField.Value : T extends EmbeddedVideoField ? EmbeddedVideoField.Value : T extends AssetField<infer F> ? AssetField.Value<F> : T extends CollectionField<infer C> ? CollectionField.Value<C> : T extends PageField<infer S> ? PageField.Value<S> : never;
|
|
54
|
+
type ForSimpleRefType<T extends Type.Simple.MaybeRef> = T extends CollectionField ? CollectionField.Value.ForRef : never;
|
|
55
|
+
type ForSimpleInlineType<T extends Type.Simple.MaybeRef> = T extends CollectionField ? CollectionField.Value.ForInline : never;
|
|
56
|
+
type ForCompositeType<T extends Type.Composite> = T extends ObjectField ? ObjectField.Value<T> : T extends ListField ? ListField.Value<T> : never;
|
|
57
|
+
type ForOptionalType<T extends Optional.Maybe<Type>> = T extends Optional<any> ? Value<T['schema']> | undefined : T extends Type ? Value<T> : never;
|
|
58
58
|
}
|
|
59
59
|
type LinkedValue<T extends Type = Type> = T extends Type.Simple ? LinkedValue.ForSimpleType<T> : T extends Type.Composite ? LinkedValue.ForCompositeType<T> : never;
|
|
60
60
|
namespace LinkedValue {
|
|
@@ -14,6 +14,7 @@ export declare class EnumField<TOptions extends EnumField.Options = EnumField.Op
|
|
|
14
14
|
keepOptions<TKey extends StringKeyOf<TOptions>>(...keys: ReadonlyArray<TKey>): EnumField<TOptions>;
|
|
15
15
|
isValidOption<TKey extends StringKeyOf<TOptions>>(key: TKey | undefined): boolean;
|
|
16
16
|
setDefault<TKey extends StringKeyOf<TOptions>>(key: TKey | undefined): EnumField<TOptions>;
|
|
17
|
+
protected new(args: EnumField.ConstructorArgs<TOptions>): EnumField<TOptions>;
|
|
17
18
|
}
|
|
18
19
|
export declare namespace EnumField {
|
|
19
20
|
type Value<TField extends EnumField> = StringKeyOf<TField['options']>;
|
|
@@ -31,10 +31,10 @@ class EnumField extends index_1.Field {
|
|
|
31
31
|
modify(_a) {
|
|
32
32
|
var _b;
|
|
33
33
|
var { options } = _a, args = __rest(_a, ["options"]);
|
|
34
|
-
return new
|
|
34
|
+
return this.new(Object.assign({ semantics: this.semantics, name: this.name, hint: this.hint, description: this.description, required: this.required, options: (_b = options) !== null && _b !== void 0 ? _b : this.options, defaultOption: this.defaultOption }, args));
|
|
35
35
|
}
|
|
36
36
|
updateOptions(options) {
|
|
37
|
-
return new
|
|
37
|
+
return this.new({
|
|
38
38
|
semantics: this.semantics,
|
|
39
39
|
name: this.name,
|
|
40
40
|
hint: this.hint,
|
|
@@ -55,7 +55,7 @@ class EnumField extends index_1.Field {
|
|
|
55
55
|
});
|
|
56
56
|
// create new enum
|
|
57
57
|
const { defaultOption } = this;
|
|
58
|
-
return new
|
|
58
|
+
return this.new({
|
|
59
59
|
semantics: this.semantics,
|
|
60
60
|
name: this.name,
|
|
61
61
|
hint: this.hint,
|
|
@@ -80,7 +80,7 @@ class EnumField extends index_1.Field {
|
|
|
80
80
|
return options;
|
|
81
81
|
}, {});
|
|
82
82
|
// create new enum
|
|
83
|
-
return new
|
|
83
|
+
return this.new({
|
|
84
84
|
semantics: this.semantics,
|
|
85
85
|
name: this.name,
|
|
86
86
|
hint: this.hint,
|
|
@@ -99,7 +99,7 @@ class EnumField extends index_1.Field {
|
|
|
99
99
|
return key in this.options;
|
|
100
100
|
}
|
|
101
101
|
setDefault(key) {
|
|
102
|
-
return new
|
|
102
|
+
return this.new({
|
|
103
103
|
semantics: this.semantics,
|
|
104
104
|
name: this.name,
|
|
105
105
|
hint: this.hint,
|
|
@@ -109,6 +109,9 @@ class EnumField extends index_1.Field {
|
|
|
109
109
|
defaultOption: key
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
+
new(args) {
|
|
113
|
+
return new EnumField(args);
|
|
114
|
+
}
|
|
112
115
|
}
|
|
113
116
|
exports.EnumField = EnumField;
|
|
114
117
|
// extension
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BooleanField } from '../base/BooleanField';
|
|
2
|
+
export declare class BooleanConfig extends BooleanField {
|
|
3
|
+
readonly responsive: boolean;
|
|
4
|
+
constructor(args: BooleanConfig.ConstructorArgs);
|
|
5
|
+
modify(args: BooleanConfig.ModifyArgs): BooleanConfig;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace BooleanConfig {
|
|
8
|
+
type ConstructorArgs = BooleanField.ConstructorArgs & {
|
|
9
|
+
responsive?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type ModifyArgs = BooleanField.ModifyArgs & {
|
|
12
|
+
responsive?: boolean;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BooleanConfig = void 0;
|
|
4
|
+
const BooleanField_1 = require("../base/BooleanField");
|
|
5
|
+
// class
|
|
6
|
+
class BooleanConfig extends BooleanField_1.BooleanField {
|
|
7
|
+
constructor(args) {
|
|
8
|
+
var _a;
|
|
9
|
+
// construct base
|
|
10
|
+
super(args);
|
|
11
|
+
// initialize instance variable
|
|
12
|
+
this.responsive = (_a = args.responsive) !== null && _a !== void 0 ? _a : false;
|
|
13
|
+
}
|
|
14
|
+
modify(args) {
|
|
15
|
+
return new BooleanConfig(Object.assign({ semantics: this.semantics, name: this.name, hint: this.hint, description: this.description, required: this.required, defaultValue: this.defaultValue, responsive: this.responsive }, args));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BooleanConfig = BooleanConfig;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StringKeyOf } from 'type-fest';
|
|
2
|
+
import { EnumField } from '../base/EnumField';
|
|
3
|
+
export declare class EnumConfig<TOptions extends EnumField.Options = EnumField.Options> extends EnumField<TOptions> {
|
|
4
|
+
readonly responsive: boolean;
|
|
5
|
+
constructor(args: EnumConfig.ConstructorArgs<TOptions>);
|
|
6
|
+
modify({ options, ...args }: EnumConfig.ModifyArgs<TOptions>): EnumConfig<TOptions>;
|
|
7
|
+
updateOptions(options: Partial<TOptions>): EnumConfig<TOptions>;
|
|
8
|
+
removeOption<TKey extends StringKeyOf<TOptions>>(key: TKey): EnumConfig<TOptions>;
|
|
9
|
+
removeOptions<TKey extends StringKeyOf<TOptions>>(...keys: ReadonlyArray<TKey>): EnumConfig<TOptions>;
|
|
10
|
+
keepOptions<TKey extends StringKeyOf<TOptions>>(...keys: ReadonlyArray<TKey>): EnumConfig<TOptions>;
|
|
11
|
+
setDefault<TKey extends StringKeyOf<TOptions>>(key: TKey | undefined): EnumConfig<TOptions>;
|
|
12
|
+
makeResponsive(responsive?: boolean): EnumConfig<TOptions>;
|
|
13
|
+
protected new({ responsive, ...args }: EnumConfig.ConstructorArgs<TOptions>): EnumConfig<TOptions>;
|
|
14
|
+
}
|
|
15
|
+
export declare namespace EnumConfig {
|
|
16
|
+
type ConstructorArgs<TOptions extends EnumField.Options> = EnumField.ConstructorArgs<TOptions> & {
|
|
17
|
+
responsive?: boolean;
|
|
18
|
+
};
|
|
19
|
+
type ModifyArgs<TOptions extends EnumField.Options> = EnumField.ModifyArgs<TOptions> & {
|
|
20
|
+
responsive?: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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.EnumConfig = void 0;
|
|
15
|
+
const EnumField_1 = require("../base/EnumField");
|
|
16
|
+
// class
|
|
17
|
+
class EnumConfig extends EnumField_1.EnumField {
|
|
18
|
+
constructor(args) {
|
|
19
|
+
var _a;
|
|
20
|
+
// construct base
|
|
21
|
+
super(args);
|
|
22
|
+
// initialize instance variable
|
|
23
|
+
this.responsive = (_a = args.responsive) !== null && _a !== void 0 ? _a : false;
|
|
24
|
+
}
|
|
25
|
+
modify(_a) {
|
|
26
|
+
var _b;
|
|
27
|
+
var { options } = _a, args = __rest(_a, ["options"]);
|
|
28
|
+
return this.new(Object.assign({ semantics: this.semantics, name: this.name, hint: this.hint, description: this.description, required: this.required, options: (_b = options) !== null && _b !== void 0 ? _b : this.options, defaultOption: this.defaultOption, responsive: this.responsive }, args));
|
|
29
|
+
}
|
|
30
|
+
updateOptions(options) {
|
|
31
|
+
return super.updateOptions(options);
|
|
32
|
+
}
|
|
33
|
+
removeOption(key) {
|
|
34
|
+
return super.removeOption(key);
|
|
35
|
+
}
|
|
36
|
+
removeOptions(...keys) {
|
|
37
|
+
return super.removeOptions(...keys);
|
|
38
|
+
}
|
|
39
|
+
keepOptions(...keys) {
|
|
40
|
+
return super.keepOptions(...keys);
|
|
41
|
+
}
|
|
42
|
+
setDefault(key) {
|
|
43
|
+
return super.setDefault(key);
|
|
44
|
+
}
|
|
45
|
+
makeResponsive(responsive = true) {
|
|
46
|
+
return this.new({
|
|
47
|
+
semantics: this.semantics,
|
|
48
|
+
name: this.name,
|
|
49
|
+
hint: this.hint,
|
|
50
|
+
description: this.description,
|
|
51
|
+
required: this.required,
|
|
52
|
+
options: this.options,
|
|
53
|
+
defaultOption: this.defaultOption,
|
|
54
|
+
responsive
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
new(_a) {
|
|
58
|
+
var { responsive } = _a, args = __rest(_a, ["responsive"]);
|
|
59
|
+
return new EnumConfig(Object.assign(Object.assign({}, args), { responsive: responsive !== null && responsive !== void 0 ? responsive : this.responsive }));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.EnumConfig = EnumConfig;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TextField } from '../base/TextField';
|
|
2
|
+
export declare class TextConfig extends TextField {
|
|
3
|
+
readonly responsive: boolean;
|
|
4
|
+
constructor(args: TextConfig.ConstructorArgs);
|
|
5
|
+
modify(args: TextConfig.ModifyArgs): TextConfig;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace TextConfig {
|
|
8
|
+
type ConstructorArgs = TextField.ConstructorArgs & {
|
|
9
|
+
responsive?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type ModifyArgs = TextField.ModifyArgs & {
|
|
12
|
+
responsive?: boolean;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextConfig = void 0;
|
|
4
|
+
const TextField_1 = require("../base/TextField");
|
|
5
|
+
// class
|
|
6
|
+
class TextConfig extends TextField_1.TextField {
|
|
7
|
+
constructor(args) {
|
|
8
|
+
var _a;
|
|
9
|
+
// construct base
|
|
10
|
+
super(args);
|
|
11
|
+
// initialize instance variable
|
|
12
|
+
this.responsive = (_a = args.responsive) !== null && _a !== void 0 ? _a : false;
|
|
13
|
+
}
|
|
14
|
+
modify(args) {
|
|
15
|
+
return new TextConfig(Object.assign({ name: this.name, hint: this.hint, description: this.description, required: this.required, semantics: this.semantics, regex: this.regex, exact: this.exact, minLength: this.minLength, maxLength: this.maxLength, responsive: this.responsive }, args));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.TextConfig = TextConfig;
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./BooleanConfig"), exports);
|
|
18
|
+
__exportStar(require("./EnumConfig"), exports);
|
|
19
|
+
__exportStar(require("./TextConfig"), exports);
|
|
@@ -15,5 +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"), exports);
|
|
18
|
+
__exportStar(require("./Config"), exports);
|
|
18
19
|
__exportStar(require("./base"), exports);
|
|
19
20
|
__exportStar(require("./composite"), exports);
|
|
21
|
+
__exportStar(require("./config/index"), exports);
|
|
@@ -16,6 +16,8 @@ export declare class Logger {
|
|
|
16
16
|
d(message: string, ...args: any[]): void;
|
|
17
17
|
verbose(message: string, ...args: any[]): void;
|
|
18
18
|
v(message: string, ...args: any[]): void;
|
|
19
|
+
silly(message: string, ...args: any[]): void;
|
|
20
|
+
s(message: string, ...args: any[]): void;
|
|
19
21
|
trace(message: string, ...args: any[]): void;
|
|
20
22
|
t(message: string, ...args: any[]): void;
|
|
21
23
|
private log;
|
|
@@ -29,7 +31,7 @@ export declare namespace Logger {
|
|
|
29
31
|
type Delimiter = typeof delimiter;
|
|
30
32
|
type WithoutRoot = Exclude<Context, Root>;
|
|
31
33
|
}
|
|
32
|
-
type Level = 'error' | 'warn' | 'info' | 'debug' | 'verbose' | 'trace';
|
|
34
|
+
type Level = 'error' | 'warn' | 'info' | 'debug' | 'verbose' | 'silly' | 'trace';
|
|
33
35
|
namespace Level {
|
|
34
36
|
const values: ReadonlyArray<Level>;
|
|
35
37
|
function compare(lhs: Level, rhs: Level): number;
|
package/dist/services/Logger.js
CHANGED
|
@@ -84,6 +84,12 @@ class Logger {
|
|
|
84
84
|
v(message, ...args) {
|
|
85
85
|
this.log('verbose', message, args);
|
|
86
86
|
}
|
|
87
|
+
silly(message, ...args) {
|
|
88
|
+
this.s(message, ...args);
|
|
89
|
+
}
|
|
90
|
+
s(message, ...args) {
|
|
91
|
+
this.log('silly', message, args);
|
|
92
|
+
}
|
|
87
93
|
trace(message, ...args) {
|
|
88
94
|
this.t(message, ...args);
|
|
89
95
|
}
|
|
@@ -135,6 +141,9 @@ class Logger {
|
|
|
135
141
|
case 'verbose':
|
|
136
142
|
console.debug(formattedMessage, ...args);
|
|
137
143
|
break;
|
|
144
|
+
case 'silly':
|
|
145
|
+
console.debug(formattedMessage, ...args);
|
|
146
|
+
break;
|
|
138
147
|
case 'trace':
|
|
139
148
|
console.trace(formattedMessage, ...args);
|
|
140
149
|
break;
|
|
@@ -157,7 +166,7 @@ Logger._loggers = new Map();
|
|
|
157
166
|
(function (Level) {
|
|
158
167
|
// values
|
|
159
168
|
Level.values = [
|
|
160
|
-
'trace', 'verbose', 'debug', 'info', 'warn', 'error'
|
|
169
|
+
'trace', 'silly', 'verbose', 'debug', 'info', 'warn', 'error'
|
|
161
170
|
];
|
|
162
171
|
// helpers
|
|
163
172
|
function compare(lhs, rhs) {
|
|
@@ -220,6 +229,7 @@ Logger._loggers = new Map();
|
|
|
220
229
|
Configuration.defaults = {
|
|
221
230
|
levels: {
|
|
222
231
|
trace: false,
|
|
232
|
+
silly: false,
|
|
223
233
|
verbose: false,
|
|
224
234
|
debug: false,
|
|
225
235
|
info: false,
|
|
@@ -0,0 +1,49 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ConfigModel = void 0;
|
|
37
|
+
const Schema = __importStar(require("../../schema"));
|
|
38
|
+
const Field_1 = require("./Field");
|
|
39
|
+
// extension
|
|
40
|
+
var ConfigModel;
|
|
41
|
+
(function (ConfigModel) {
|
|
42
|
+
// filter
|
|
43
|
+
function filter(value) {
|
|
44
|
+
return value
|
|
45
|
+
&& value instanceof Field_1.Field
|
|
46
|
+
&& Schema.Config.isConfig(value.schema);
|
|
47
|
+
}
|
|
48
|
+
ConfigModel.filter = filter;
|
|
49
|
+
})(ConfigModel || (exports.ConfigModel = ConfigModel = {}));
|
|
@@ -4,7 +4,8 @@ import { EventBus } from '../../services';
|
|
|
4
4
|
import { FieldValidator } from './FieldValidator';
|
|
5
5
|
export declare class Field<TSchema extends Schema.Field.Type = Schema.Field.Type> {
|
|
6
6
|
private readonly eventBus;
|
|
7
|
-
readonly
|
|
7
|
+
private readonly _schema;
|
|
8
|
+
private _schemaOverride?;
|
|
8
9
|
readonly id: string;
|
|
9
10
|
readonly name: string;
|
|
10
11
|
readonly required: boolean;
|
|
@@ -25,6 +26,9 @@ export declare class Field<TSchema extends Schema.Field.Type = Schema.Field.Type
|
|
|
25
26
|
private _shouldFocus?;
|
|
26
27
|
constructor(args: Field.ConstructorArgs<TSchema>);
|
|
27
28
|
get events$(): Observable<Field.Event>;
|
|
29
|
+
get schema(): TSchema;
|
|
30
|
+
get schemaOverride(): TSchema | undefined;
|
|
31
|
+
overrideSchema(schema: TSchema | undefined, coerce?: boolean): void;
|
|
28
32
|
get isComposite(): boolean;
|
|
29
33
|
get exists(): boolean;
|
|
30
34
|
get valid(): boolean;
|
|
@@ -52,11 +56,11 @@ export declare class Field<TSchema extends Schema.Field.Type = Schema.Field.Type
|
|
|
52
56
|
optOut(): void;
|
|
53
57
|
get shouldFocus(): boolean;
|
|
54
58
|
didFocus(): void;
|
|
55
|
-
validate(
|
|
59
|
+
validate(coerce?: boolean): ReadonlyArray<FieldValidator.Error>;
|
|
56
60
|
migrate(previous: Field<TSchema>): void;
|
|
57
61
|
onSaveStart(): void;
|
|
58
62
|
onSaveComplete(): void;
|
|
59
|
-
reset(initialValue?: Schema.Field.Data<TSchema> | null): void;
|
|
63
|
+
reset(initialValue?: Schema.Field.Data<TSchema> | null, coerce?: boolean): void;
|
|
60
64
|
clone({ schema, eventBus, name, required }?: Field.CloneArgs<TSchema>): Field<TSchema>;
|
|
61
65
|
private raiseEvent;
|
|
62
66
|
}
|
|
@@ -83,7 +87,7 @@ export declare namespace Field {
|
|
|
83
87
|
field: Field;
|
|
84
88
|
}
|
|
85
89
|
namespace Event {
|
|
86
|
-
type Type = 'changed' | 'editing' | 'validation' | 'reset';
|
|
90
|
+
type Type = 'changed' | 'editing' | 'validation' | 'reset' | 'schema' | 'saved';
|
|
87
91
|
function filter(event: EventBus.Event): event is Event;
|
|
88
92
|
function create(event: EventBus.Args<Event>): Event;
|
|
89
93
|
}
|
package/dist/ui/fields/Field.js
CHANGED
|
@@ -46,7 +46,7 @@ class Field {
|
|
|
46
46
|
var _a;
|
|
47
47
|
// initialize instance variables
|
|
48
48
|
this.eventBus = args.eventBus;
|
|
49
|
-
this.
|
|
49
|
+
this._schema = args.schema;
|
|
50
50
|
this.id = args.id;
|
|
51
51
|
this.name = args.name;
|
|
52
52
|
this.required = args.required;
|
|
@@ -67,6 +67,23 @@ class Field {
|
|
|
67
67
|
get events$() {
|
|
68
68
|
return this.eventBus.events$.pipe((0, rxjs_1.filter)(Field.Event.filter), (0, rxjs_1.filter)(e => e.field === this));
|
|
69
69
|
}
|
|
70
|
+
get schema() {
|
|
71
|
+
const { _schema, _schemaOverride } = this;
|
|
72
|
+
return _schemaOverride !== null && _schemaOverride !== void 0 ? _schemaOverride : _schema;
|
|
73
|
+
}
|
|
74
|
+
get schemaOverride() {
|
|
75
|
+
return this._schemaOverride;
|
|
76
|
+
}
|
|
77
|
+
overrideSchema(schema, coerce = false) {
|
|
78
|
+
// update schema
|
|
79
|
+
this._schemaOverride = schema;
|
|
80
|
+
// revalidate
|
|
81
|
+
this.validate(true);
|
|
82
|
+
// raise change (if required)
|
|
83
|
+
if (!coerce) {
|
|
84
|
+
this.raiseEvent('schema');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
70
87
|
get isComposite() {
|
|
71
88
|
switch (this.schema.type) {
|
|
72
89
|
case 'asset':
|
|
@@ -256,7 +273,7 @@ class Field {
|
|
|
256
273
|
didFocus() {
|
|
257
274
|
delete this._shouldFocus;
|
|
258
275
|
}
|
|
259
|
-
validate(
|
|
276
|
+
validate(coerce = false) {
|
|
260
277
|
// validate (use custom if available)
|
|
261
278
|
const { _value, _validator, customValidator } = this;
|
|
262
279
|
let errors = _validator.validate(this, _value);
|
|
@@ -270,7 +287,7 @@ class Field {
|
|
|
270
287
|
// update errors
|
|
271
288
|
this._errors = errors;
|
|
272
289
|
// raise event if not silent
|
|
273
|
-
if (!
|
|
290
|
+
if (!coerce) {
|
|
274
291
|
this.raiseEvent('validation');
|
|
275
292
|
}
|
|
276
293
|
// return errors
|
|
@@ -290,14 +307,17 @@ class Field {
|
|
|
290
307
|
// reset to initial value if not modified or if save is newer
|
|
291
308
|
const { _modifiedOn, _savingOn } = this;
|
|
292
309
|
if (_savingOn && (!_modifiedOn || _savingOn >= _modifiedOn)) {
|
|
310
|
+
// commit changes
|
|
293
311
|
this._initialValue = this._value;
|
|
294
312
|
delete this._optIn;
|
|
295
313
|
delete this._optOut;
|
|
314
|
+
// raise save event
|
|
315
|
+
this.raiseEvent('saved');
|
|
296
316
|
}
|
|
297
317
|
// clear saving flag
|
|
298
318
|
delete this._savingOn;
|
|
299
319
|
}
|
|
300
|
-
reset(initialValue) {
|
|
320
|
+
reset(initialValue, coerce = false) {
|
|
301
321
|
// reset initial value if it's set
|
|
302
322
|
if (initialValue !== undefined) {
|
|
303
323
|
this._initialValue = initialValue !== null && initialValue !== void 0 ? initialValue : undefined;
|
|
@@ -307,12 +327,15 @@ class Field {
|
|
|
307
327
|
delete this._optOut;
|
|
308
328
|
this.value = this._initialValue;
|
|
309
329
|
// revalidate
|
|
310
|
-
this.validate();
|
|
330
|
+
this.validate(coerce);
|
|
311
331
|
// clear sandbox
|
|
312
332
|
this._sandboxed = false;
|
|
313
333
|
this._sandboxedValue = undefined;
|
|
314
334
|
// raise reset event
|
|
315
|
-
|
|
335
|
+
if (!coerce) {
|
|
336
|
+
console.trace('[Field/reset] raising event', this);
|
|
337
|
+
this.raiseEvent('reset');
|
|
338
|
+
}
|
|
316
339
|
}
|
|
317
340
|
clone({ schema, eventBus, name, required } = {}) {
|
|
318
341
|
return new Field({
|
|
@@ -322,7 +345,9 @@ class Field {
|
|
|
322
345
|
name: name !== null && name !== void 0 ? name : this.name,
|
|
323
346
|
publishedValue: this.publishedValue,
|
|
324
347
|
initialValue: this.initialValue,
|
|
325
|
-
required: required !== null && required !== void 0 ? required : this.required
|
|
348
|
+
required: required !== null && required !== void 0 ? required : this.required,
|
|
349
|
+
customValidator: this._customValidator,
|
|
350
|
+
tags: this.tags.values().toArray()
|
|
326
351
|
});
|
|
327
352
|
}
|
|
328
353
|
raiseEvent(type) {
|
|
@@ -78,7 +78,7 @@ export declare namespace FieldList {
|
|
|
78
78
|
field: FieldList;
|
|
79
79
|
}
|
|
80
80
|
namespace Event {
|
|
81
|
-
type Type = 'changed' | 'validation';
|
|
81
|
+
type Type = 'changed' | 'validation' | 'saved';
|
|
82
82
|
function filter(event: EventBus.Event): event is Event;
|
|
83
83
|
function create(event: EventBus.Args<Event>): Event;
|
|
84
84
|
}
|
|
@@ -288,9 +288,12 @@ class FieldList {
|
|
|
288
288
|
// reset to initial value if not modified or if save is newer
|
|
289
289
|
const { _modifiedOn, _savingOn } = this;
|
|
290
290
|
if (_savingOn && (!_modifiedOn || _savingOn >= _modifiedOn)) {
|
|
291
|
+
// commit changes
|
|
291
292
|
this._initialValue = this.value;
|
|
292
293
|
delete this._optIn;
|
|
293
294
|
delete this._optOut;
|
|
295
|
+
// raise save event
|
|
296
|
+
this.raiseEvent('saved');
|
|
294
297
|
}
|
|
295
298
|
// clear saving flag
|
|
296
299
|
delete this._savingOn;
|
|
@@ -78,7 +78,7 @@ export declare namespace ObjectField {
|
|
|
78
78
|
field: ObjectField;
|
|
79
79
|
}
|
|
80
80
|
namespace Event {
|
|
81
|
-
type Type = 'changed';
|
|
81
|
+
type Type = 'changed' | 'saved';
|
|
82
82
|
function filter(event: EventBus.Event): event is Event;
|
|
83
83
|
function create(event: EventBus.Args<Event>): Event;
|
|
84
84
|
}
|
|
@@ -199,9 +199,12 @@ class ObjectField {
|
|
|
199
199
|
// reset to initial value if not modified or if save is newer
|
|
200
200
|
const { _modifiedOn, _savingOn } = this;
|
|
201
201
|
if (_savingOn && (!_modifiedOn || _savingOn >= _modifiedOn)) {
|
|
202
|
+
// commit changes
|
|
202
203
|
this._initialValue = this.value;
|
|
203
204
|
delete this._optIn;
|
|
204
205
|
delete this._optOut;
|
|
206
|
+
// raise save event
|
|
207
|
+
this.raiseEvent('saved');
|
|
205
208
|
}
|
|
206
209
|
// clear saving flag
|
|
207
210
|
delete this._savingOn;
|
package/dist/ui/fields/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ConfigModel"), exports);
|
|
17
18
|
__exportStar(require("./Field"), exports);
|
|
18
19
|
__exportStar(require("./FieldList"), exports);
|
|
19
20
|
__exportStar(require("./FieldListValidator"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nascentdigital/funnel-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
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": "
|
|
68
|
+
"gitHead": "4da4fb0b92a8e3cb75bf668e0c9f63d82783f59b"
|
|
69
69
|
}
|