@nascentdigital/funnel-core 6.1.0 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schema/Block.d.ts +29 -2
- package/dist/schema/Block.js +95 -5
- package/dist/ui/block-layout/PanelLayout.d.ts +4 -0
- package/dist/ui/block-layout/PanelLayout.js +2 -0
- package/dist/ui/block-layout/PanelSlot.d.ts +6 -0
- package/dist/ui/block-layout/PanelSlot.js +2 -0
- package/dist/ui/block-layout/index.d.ts +2 -0
- package/dist/ui/block-layout/index.js +2 -0
- package/dist/ui/fields/Field.d.ts +5 -0
- package/dist/ui/fields/Field.js +5 -0
- package/package.json +2 -2
package/dist/schema/Block.d.ts
CHANGED
|
@@ -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'>;
|
package/dist/schema/Block.js
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
+
}
|
|
@@ -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);
|
|
@@ -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
|
}
|
package/dist/ui/fields/Field.js
CHANGED
|
@@ -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 = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nascentdigital/funnel-core",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.2",
|
|
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": "d72a93d505884f030d595ecf66c64351ebfc8ed1"
|
|
69
69
|
}
|