@nascentdigital/funnel-core 8.1.2 → 8.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schema/Meta.d.ts +4 -0
- package/dist/schema/Meta.js +32 -0
- package/dist/schema/Page.d.ts +4 -3
- package/dist/schema/Page.js +6 -4
- package/dist/types/MaybeArray.d.ts +1 -0
- package/dist/types/MaybeArray.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/ui/fields/FieldList.d.ts +3 -1
- package/dist/ui/fields/FieldList.js +20 -1
- package/dist/ui/fields/ObjectField.d.ts +2 -0
- package/dist/ui/fields/ObjectField.js +27 -4
- package/dist/utils/ArrayUtils.d.ts +3 -2
- package/dist/utils/ArrayUtils.js +4 -0
- package/package.json +2 -2
package/dist/schema/Meta.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare class Meta {
|
|
2
2
|
readonly id: Meta.Id;
|
|
3
|
+
readonly editable: boolean;
|
|
3
4
|
constructor(args: Meta.ConstructorArgs);
|
|
4
5
|
}
|
|
5
6
|
export declare namespace Meta {
|
|
@@ -9,7 +10,10 @@ export declare namespace Meta {
|
|
|
9
10
|
}
|
|
10
11
|
const NoIndex: Meta;
|
|
11
12
|
const Internal: Meta;
|
|
13
|
+
function tryParse(value: string | undefined): Meta | undefined;
|
|
14
|
+
function parse(value: string | undefined): Meta;
|
|
12
15
|
type ConstructorArgs = {
|
|
13
16
|
id: Id;
|
|
17
|
+
editable: boolean;
|
|
14
18
|
};
|
|
15
19
|
}
|
package/dist/schema/Meta.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Meta = void 0;
|
|
4
4
|
// class
|
|
5
|
+
const errors_1 = require("../errors");
|
|
5
6
|
class Meta {
|
|
6
7
|
constructor(args) {
|
|
7
8
|
this.id = args.id;
|
|
9
|
+
this.editable = args.editable;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.Meta = Meta;
|
|
@@ -17,8 +19,38 @@ exports.Meta = Meta;
|
|
|
17
19
|
// definitions
|
|
18
20
|
Meta.NoIndex = new Meta({
|
|
19
21
|
id: 'no-index',
|
|
22
|
+
editable: true
|
|
20
23
|
});
|
|
21
24
|
Meta.Internal = new Meta({
|
|
22
25
|
id: 'internal',
|
|
26
|
+
editable: false
|
|
23
27
|
});
|
|
28
|
+
// helpers
|
|
29
|
+
function tryParse(value) {
|
|
30
|
+
// skip if no value
|
|
31
|
+
if (!value) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// otherwise, attempt to parse
|
|
35
|
+
const normalizedValue = value.trim().toLowerCase();
|
|
36
|
+
switch (normalizedValue) {
|
|
37
|
+
case 'no-index':
|
|
38
|
+
return Meta.NoIndex;
|
|
39
|
+
case 'internal':
|
|
40
|
+
return Meta.Internal;
|
|
41
|
+
default:
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
Meta.tryParse = tryParse;
|
|
46
|
+
function parse(value) {
|
|
47
|
+
// throw if value is undefined
|
|
48
|
+
const meta = tryParse(value);
|
|
49
|
+
if (!meta) {
|
|
50
|
+
throw new errors_1.ArgumentError(`Invalid meta: ${value}`, 'meta');
|
|
51
|
+
}
|
|
52
|
+
// otherwise, return meta
|
|
53
|
+
return meta;
|
|
54
|
+
}
|
|
55
|
+
Meta.parse = parse;
|
|
24
56
|
})(Meta || (exports.Meta = Meta = {}));
|
package/dist/schema/Page.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StringKeyOf, Tagged } from 'type-fest';
|
|
2
2
|
import { Language, Localized } from '../regionalization';
|
|
3
|
-
import { PartialBy, UndefinedToNull } from '../types';
|
|
3
|
+
import { PartialBy, UndefinedToNull, MaybeArray } from '../types';
|
|
4
4
|
import { Asset } from './Asset';
|
|
5
5
|
import { Block } from './Block';
|
|
6
6
|
import type { ChangeSet } from './ChangeSet';
|
|
@@ -54,7 +54,7 @@ export declare namespace Page {
|
|
|
54
54
|
}
|
|
55
55
|
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;
|
|
56
56
|
namespace Update {
|
|
57
|
-
type Page = Page.Name | Page.Tags | Page.Slug | Page.Url | Page.Preview | Page.Errors | Page.Publication;
|
|
57
|
+
type Page = Page.Name | Page.Tags | Page.Meta | Page.Slug | Page.Url | Page.Preview | Page.Errors | Page.Publication;
|
|
58
58
|
namespace Page {
|
|
59
59
|
type Factory<TProp extends keyof LegacyData> = {
|
|
60
60
|
type: 'page';
|
|
@@ -63,6 +63,7 @@ export declare namespace Page {
|
|
|
63
63
|
};
|
|
64
64
|
export type Name = Factory<'name'>;
|
|
65
65
|
export type Tags = Factory<'tags'>;
|
|
66
|
+
export type Meta = Factory<'meta'>;
|
|
66
67
|
export type Slug = Factory<'slug'>;
|
|
67
68
|
export type Url = Factory<'url'>;
|
|
68
69
|
export type Preview = Omit<Factory<'preview'>, 'value'> & {
|
|
@@ -330,7 +331,7 @@ export declare namespace Page {
|
|
|
330
331
|
namespace ConstructorArgs {
|
|
331
332
|
type Base<TContent extends Content = Content, TPreview extends PreviewTarget<TContent> = PreviewTarget<TContent>> = {
|
|
332
333
|
route: Localized.Maybe<PageRoute>;
|
|
333
|
-
meta?:
|
|
334
|
+
meta?: MaybeArray<Meta.Id>;
|
|
334
335
|
tags?: ReadonlyArray<TagGroup>;
|
|
335
336
|
name: string;
|
|
336
337
|
description?: string;
|
package/dist/schema/Page.js
CHANGED
|
@@ -14,21 +14,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.Page = void 0;
|
|
15
15
|
const errors_1 = require("../errors");
|
|
16
16
|
const utils_1 = require("../utils");
|
|
17
|
+
const Meta_1 = require("./Meta");
|
|
17
18
|
const Tag_1 = require("./Tag");
|
|
18
19
|
// class
|
|
19
20
|
class Page {
|
|
20
21
|
// constructor
|
|
21
22
|
constructor(args) {
|
|
22
|
-
var _a, _b
|
|
23
|
+
var _a, _b;
|
|
23
24
|
// initialize common instance variables
|
|
24
25
|
this.variant = args.variant;
|
|
25
26
|
this.route = args.route;
|
|
26
|
-
this.meta = (
|
|
27
|
-
this.tags = (
|
|
27
|
+
this.meta = utils_1.ArrayUtils.coerce(args.meta).map(Meta_1.Meta.parse);
|
|
28
|
+
this.tags = (_a = args.tags) !== null && _a !== void 0 ? _a : [];
|
|
28
29
|
this.name = args.name;
|
|
29
30
|
this.description = args.description;
|
|
30
31
|
this.displayName = args.displayName;
|
|
31
|
-
this.optional = (
|
|
32
|
+
this.optional = (_b = args.optional) !== null && _b !== void 0 ? _b : false;
|
|
32
33
|
this.preview = args.preview;
|
|
33
34
|
this.content = args.content;
|
|
34
35
|
this.navigation = args.navigation;
|
|
@@ -75,6 +76,7 @@ class Page {
|
|
|
75
76
|
return new Page({
|
|
76
77
|
variant: 'dynamic',
|
|
77
78
|
route: args.route,
|
|
79
|
+
meta: args.meta,
|
|
78
80
|
tags: args.tags,
|
|
79
81
|
name: args.name,
|
|
80
82
|
preview: args.preview,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MaybeArray<T> = ReadonlySet<T> | ReadonlyArray<T> | T | null | undefined;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./Callback"), exports);
|
|
|
19
19
|
__exportStar(require("./DateString"), exports);
|
|
20
20
|
__exportStar(require("./FilterConditionally"), exports);
|
|
21
21
|
__exportStar(require("./If"), exports);
|
|
22
|
+
__exportStar(require("./MaybeArray"), exports);
|
|
22
23
|
__exportStar(require("./MaybeConditionalValue"), exports);
|
|
23
24
|
__exportStar(require("./Mutable"), exports);
|
|
24
25
|
__exportStar(require("./Ordinal"), exports);
|
|
@@ -2,6 +2,7 @@ import { Observable } from 'rxjs';
|
|
|
2
2
|
import * as Schema from '../../schema';
|
|
3
3
|
import { EventBus } from '../../services';
|
|
4
4
|
import { Field } from './Field';
|
|
5
|
+
import { FieldModel } from './FieldModel';
|
|
5
6
|
import { FieldValidator } from './FieldValidator';
|
|
6
7
|
import { ObjectField } from './ObjectField';
|
|
7
8
|
export declare class FieldList {
|
|
@@ -21,7 +22,7 @@ export declare class FieldList {
|
|
|
21
22
|
private _optIn?;
|
|
22
23
|
private _optOut?;
|
|
23
24
|
constructor(args: FieldList.ConstructorArgs);
|
|
24
|
-
get events$(): Observable<
|
|
25
|
+
get events$(): Observable<FieldModel.Event>;
|
|
25
26
|
get initialValue(): Schema.Field.Data.ForCompositeType<FieldList.ListSchema> | undefined;
|
|
26
27
|
get items(): ReadonlyArray<FieldList.Item>;
|
|
27
28
|
get isNew(): boolean;
|
|
@@ -33,6 +34,7 @@ export declare class FieldList {
|
|
|
33
34
|
get hasValue(): boolean;
|
|
34
35
|
get value(): FieldList.ListValue | undefined;
|
|
35
36
|
set value(value: FieldList.ListValue | undefined);
|
|
37
|
+
coerceValue(value: FieldList.ListValue | undefined): void;
|
|
36
38
|
get modified(): boolean;
|
|
37
39
|
get changed(): boolean;
|
|
38
40
|
get canOptOut(): boolean;
|
|
@@ -52,6 +52,7 @@ const services_1 = require("../../services");
|
|
|
52
52
|
const utils_1 = require("../../utils");
|
|
53
53
|
const Field_1 = require("./Field");
|
|
54
54
|
const FieldListValidator_1 = require("./FieldListValidator");
|
|
55
|
+
const FieldModel_1 = require("./FieldModel");
|
|
55
56
|
const FieldValidator_1 = require("./FieldValidator");
|
|
56
57
|
const ObjectField_1 = require("./ObjectField");
|
|
57
58
|
// class
|
|
@@ -77,7 +78,8 @@ class FieldList {
|
|
|
77
78
|
this._errors = this._validator.validate(this, this.value);
|
|
78
79
|
}
|
|
79
80
|
get events$() {
|
|
80
|
-
return this.eventBus.events$.pipe((0, rxjs_1.filter)(FieldList.Event.filter
|
|
81
|
+
return this.eventBus.events$.pipe((0, rxjs_1.filter)(e => (FieldList.Event.filter(e) && e.field === this)
|
|
82
|
+
|| (FieldModel_1.FieldModel.Event.filter(e) && !!this.items.find(item => item.field === e.field))));
|
|
81
83
|
}
|
|
82
84
|
get initialValue() {
|
|
83
85
|
return this._initialValue;
|
|
@@ -136,6 +138,23 @@ class FieldList {
|
|
|
136
138
|
// raise event
|
|
137
139
|
this.raiseEvent('changed');
|
|
138
140
|
}
|
|
141
|
+
coerceValue(value) {
|
|
142
|
+
// ignore if the values are the same
|
|
143
|
+
if (utils_1.Value.equals(this.value, value)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// update
|
|
147
|
+
const { eventBus, schema, publishedValue } = this;
|
|
148
|
+
this._items = deserializeItems({
|
|
149
|
+
eventBus,
|
|
150
|
+
schema,
|
|
151
|
+
value,
|
|
152
|
+
publishedValue
|
|
153
|
+
});
|
|
154
|
+
this._modifiedOn = Date.now();
|
|
155
|
+
// revalidate
|
|
156
|
+
this.validate();
|
|
157
|
+
}
|
|
139
158
|
get modified() {
|
|
140
159
|
const { value, initialValue } = this;
|
|
141
160
|
return this._optIn || !utils_1.Value.equals(value, initialValue);
|
|
@@ -23,6 +23,7 @@ export declare class ObjectField<TObject extends Schema.ObjectField = Schema.Obj
|
|
|
23
23
|
private _optOut?;
|
|
24
24
|
constructor(args: ObjectField.ConstructorArgs);
|
|
25
25
|
get events$(): Observable<FieldModel.Event>;
|
|
26
|
+
get fieldsChanged$(): Observable<FieldModel.Event>;
|
|
26
27
|
get initialValue(): ObjectField.Value<TObject> | undefined;
|
|
27
28
|
get exists(): boolean;
|
|
28
29
|
get isNew(): boolean;
|
|
@@ -35,6 +36,7 @@ export declare class ObjectField<TObject extends Schema.ObjectField = Schema.Obj
|
|
|
35
36
|
get hasValue(): boolean;
|
|
36
37
|
get value(): ObjectField.Value<TObject>;
|
|
37
38
|
set value(value: ObjectField.Value<TObject>);
|
|
39
|
+
coerceValue(value: ObjectField.Value<TObject>): void;
|
|
38
40
|
get modified(): boolean;
|
|
39
41
|
get changed(): boolean;
|
|
40
42
|
get preview(): ObjectField.Preview;
|
|
@@ -27,6 +27,9 @@ class ObjectField {
|
|
|
27
27
|
return this.eventBus.events$.pipe((0, rxjs_1.filter)(e => (ObjectField.Event.filter(e) && e.field === this)
|
|
28
28
|
|| (FieldModel_1.FieldModel.Event.filter(e) && this._fields.includes(e.field))));
|
|
29
29
|
}
|
|
30
|
+
get fieldsChanged$() {
|
|
31
|
+
return (0, rxjs_1.merge)(...this._fields.map(field => field.events$));
|
|
32
|
+
}
|
|
30
33
|
get initialValue() {
|
|
31
34
|
return this._initialValue;
|
|
32
35
|
}
|
|
@@ -91,17 +94,37 @@ class ObjectField {
|
|
|
91
94
|
}
|
|
92
95
|
set value(value) {
|
|
93
96
|
var _a;
|
|
94
|
-
//
|
|
97
|
+
// coerce values (prevent multiple events)
|
|
98
|
+
const values = (_a = value.value) !== null && _a !== void 0 ? _a : {};
|
|
99
|
+
Object.entries(this._content).forEach(([key, field]) => {
|
|
100
|
+
if (field instanceof ObjectField) {
|
|
101
|
+
field.coerceValue(values[key]);
|
|
102
|
+
}
|
|
103
|
+
else if (field instanceof FieldList_1.FieldList) {
|
|
104
|
+
field.coerceValue(values[key]);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
field.coerceValue(values[key]);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
// mark modified
|
|
111
|
+
this._modifiedOn = Date.now();
|
|
112
|
+
// raise single event
|
|
113
|
+
this.raiseEvent('changed');
|
|
114
|
+
}
|
|
115
|
+
coerceValue(value) {
|
|
116
|
+
var _a;
|
|
117
|
+
// coerce values
|
|
95
118
|
const values = (_a = value.value) !== null && _a !== void 0 ? _a : {};
|
|
96
119
|
Object.entries(this._content).forEach(([key, field]) => {
|
|
97
120
|
if (field instanceof ObjectField) {
|
|
98
|
-
field.
|
|
121
|
+
field.coerceValue(values[key]);
|
|
99
122
|
}
|
|
100
123
|
else if (field instanceof FieldList_1.FieldList) {
|
|
101
|
-
field.
|
|
124
|
+
field.coerceValue(values[key]);
|
|
102
125
|
}
|
|
103
126
|
else {
|
|
104
|
-
field.
|
|
127
|
+
field.coerceValue(values[key]);
|
|
105
128
|
}
|
|
106
129
|
});
|
|
107
130
|
// mark modified
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { JsonValue } from 'type-fest';
|
|
2
|
-
import { Transform } from '../types';
|
|
2
|
+
import { MaybeArray, Transform } from '../types';
|
|
3
3
|
export declare namespace ArrayUtils {
|
|
4
4
|
function isReadonlyArray<T>(value: unknown): value is readonly T[];
|
|
5
5
|
function isReadonlySet<T>(value: unknown): value is ReadonlySet<T>;
|
|
6
|
-
function coerce<T>(maybeArray:
|
|
6
|
+
function coerce<T>(maybeArray: MaybeArray<T>): T[];
|
|
7
7
|
function first<T>(array: ReadonlyArray<T>): T | undefined;
|
|
8
8
|
function last<T>(array: ReadonlyArray<T>): T | undefined;
|
|
9
|
+
function removeDuplicates<T>(array: ReadonlyArray<T>): T[];
|
|
9
10
|
/**
|
|
10
11
|
* Creates a sequential array of items from [start, end] inclusive, incrementing by 1.
|
|
11
12
|
*
|
package/dist/utils/ArrayUtils.js
CHANGED
|
@@ -37,6 +37,10 @@ var ArrayUtils;
|
|
|
37
37
|
: undefined;
|
|
38
38
|
}
|
|
39
39
|
ArrayUtils.last = last;
|
|
40
|
+
function removeDuplicates(array) {
|
|
41
|
+
return Array.from(new Set(array));
|
|
42
|
+
}
|
|
43
|
+
ArrayUtils.removeDuplicates = removeDuplicates;
|
|
40
44
|
/**
|
|
41
45
|
* Creates a sequential array of items from [start, end] inclusive, incrementing by 1.
|
|
42
46
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nascentdigital/funnel-core",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "git+https://github.com/nascentdigital/funnel.git",
|
|
6
6
|
"directory": "libs/core"
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"jest-tsd": "^0.2.2",
|
|
66
66
|
"ts-jest": "^29.3.2"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "68d48abbc294945af6b56a8489644b210e5ac661"
|
|
69
69
|
}
|