@media-quest/builder 0.0.9 → 0.0.11
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/public-api.d.mts +31 -26
- package/dist/public-api.d.ts +31 -26
- package/dist/public-api.js +49 -42
- package/dist/public-api.mjs +47 -40
- package/package.json +2 -2
- package/src/Builder-page.spec.ts +2 -1
- package/src/Builder-page.ts +3 -1
- package/src/Builder-schema.spec.ts +3 -2
- package/src/Builder-schema.ts +13 -19
- package/src/primitives/page-prefix.ts +58 -0
- package/src/primitives/prefix.ts +0 -0
- package/src/primitives/schema-prefix.ts +52 -0
- package/src/primitives/varID.ts +11 -0
- package/src/public-api.ts +4 -1
- package/src/rulebuilder/Builder-rule.spec.ts +3 -1
- package/src/rulebuilder/Builder-rule.ts +2 -2
- package/src/rulebuilder/RuleAction.ts +84 -0
- package/src/rulebuilder/RuleBuilder-test-utils.ts +32 -12
- package/src/rulebuilder/RuleVariable.ts +3 -1
- package/src/rulebuilder/SingleSelectItem.ts +2 -2
- package/src/rulebuilder/condition/Builder-condition.spec.ts +2 -1
- package/src/rulebuilder/multi-select-item.ts +57 -54
- package/src/rulebuilder/page-action-manager.ts +2 -1
- package/src/prefix.ts +0 -107
- /package/src/{prefix.spec.ts → primitives/prefix.spec.ts} +0 -0
|
@@ -1,70 +1,73 @@
|
|
|
1
1
|
import { ExcludeByPageAction, ExcludeByTagAction } from "./RuleAction";
|
|
2
2
|
|
|
3
3
|
export abstract class MultiSelectItem<T> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
private readonly _isSelectedInitially: boolean;
|
|
5
|
+
private readonly _selectLabel;
|
|
6
|
+
private readonly _toolTip;
|
|
7
|
+
private readonly _searchString;
|
|
8
|
+
public isSelected: boolean;
|
|
9
|
+
get selectLabel(): string {
|
|
10
|
+
return this._selectLabel;
|
|
11
|
+
}
|
|
12
|
+
get tooltip() {
|
|
13
|
+
return this._toolTip;
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
get searchString() {
|
|
17
|
+
return this._searchString;
|
|
18
|
+
}
|
|
19
|
+
protected constructor(
|
|
20
|
+
readonly data: T,
|
|
21
|
+
isSelected: boolean,
|
|
22
|
+
) {
|
|
23
|
+
this._isSelectedInitially = isSelected;
|
|
24
|
+
this.isSelected = isSelected;
|
|
25
|
+
this._searchString = this.getSearchString();
|
|
26
|
+
this._toolTip = this.getTooltip();
|
|
27
|
+
this._selectLabel = this.getSelectLabel();
|
|
28
|
+
}
|
|
29
|
+
protected abstract getSelectLabel(): string;
|
|
30
|
+
protected abstract getTooltip(): string;
|
|
31
|
+
protected abstract getSearchString(): string;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
export class ExcludeByTagSelectItem extends MultiSelectItem<ExcludeByTagAction> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
public static readonly create = (tagData: ExcludeByTagAction, isSelected: boolean) => {
|
|
36
|
+
return new ExcludeByTagSelectItem(tagData, isSelected);
|
|
37
|
+
};
|
|
38
|
+
protected constructor(data: ExcludeByTagAction, isSelected: boolean) {
|
|
39
|
+
super(data, isSelected);
|
|
40
|
+
}
|
|
41
|
+
protected getSearchString(): string {
|
|
42
|
+
return this.data.tag;
|
|
43
|
+
}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
protected getSelectLabel(): string {
|
|
46
|
+
return this.data.tag + " (" + this.data.pageCount + ")";
|
|
47
|
+
}
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
protected getTooltip(): string {
|
|
50
|
+
return this.data.tag + " (used in " + this.data.pageCount + " pages)";
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
export class ExcludeByPageIdSelectItem extends MultiSelectItem<ExcludeByPageAction> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
public static create = (ruleActionPage: ExcludeByPageAction, isSelected: boolean) => {
|
|
56
|
+
return new ExcludeByPageIdSelectItem(ruleActionPage, isSelected);
|
|
57
|
+
};
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
protected constructor(data: ExcludeByPageAction, isSelected: boolean) {
|
|
60
|
+
super(data, isSelected);
|
|
61
|
+
}
|
|
62
|
+
protected getSearchString(): string {
|
|
63
|
+
return this.data.pagePrefix + this.data.mainText;
|
|
64
|
+
}
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
protected getSelectLabel(): string {
|
|
67
|
+
return this.data.pagePrefix + " (" + this.data.pageNumber + ")";
|
|
68
|
+
}
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
protected getTooltip(): string {
|
|
71
|
+
return this.data.mainText;
|
|
72
|
+
}
|
|
70
73
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RuleInput } from "./RuleInput";
|
|
2
2
|
import { ExcludeByPageIdSelectItem } from "./multi-select-item";
|
|
3
3
|
import { ExcludeByPageAction } from "./RuleAction";
|
|
4
|
+
import { PageID } from "@media-quest/engine";
|
|
4
5
|
|
|
5
6
|
export class PageActionManager {
|
|
6
7
|
private readonly _initialSelection: Set<string>;
|
|
@@ -17,7 +18,7 @@ export class PageActionManager {
|
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
getCurrentSelection(): ReadonlyArray<
|
|
21
|
+
getCurrentSelection(): ReadonlyArray<PageID> {
|
|
21
22
|
const selected = this.selectItems.filter((item) => item.isSelected).map((itm) => itm.data.pageId);
|
|
22
23
|
return selected;
|
|
23
24
|
}
|
package/src/prefix.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
export type SchemaPrefixValue = string & { __SCHEMA_PREFIX__: true };
|
|
2
|
-
export type PagePrefixValue = string & { __PAGE_PREFIX__: true };
|
|
3
|
-
// export type QuestionPrefixValue = string & { __QUESTION_PREFIX__: true };
|
|
4
|
-
export type VarID = `${SchemaPrefixValue}_${PagePrefixValue}`;
|
|
5
|
-
export const VarID = {
|
|
6
|
-
create: (schemaPrefix: SchemaPrefixValue, pagePrefix: PagePrefixValue): VarID => {
|
|
7
|
-
const varId = schemaPrefix + "_" + pagePrefix;
|
|
8
|
-
return varId as VarID;
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
const createRandomPrefix = <const P extends string>(length: number): P => {
|
|
12
|
-
const letters = "abcdefghijklmnopqrstuvyz";
|
|
13
|
-
const all = letters + letters.toUpperCase();
|
|
14
|
-
let result = "";
|
|
15
|
-
for (let i = 0; i < length; i++) {
|
|
16
|
-
const char = all.charAt(Math.floor(Math.random() * all.length));
|
|
17
|
-
result += char;
|
|
18
|
-
}
|
|
19
|
-
return result as P;
|
|
20
|
-
};
|
|
21
|
-
export class SchemaPrefix {
|
|
22
|
-
public static readonly MIN_LENGTH = 1;
|
|
23
|
-
private static randomLen = 5;
|
|
24
|
-
public static readonly MAX_LENGTH = 16;
|
|
25
|
-
public static fromValue = (value: SchemaPrefixValue): SchemaPrefix => {
|
|
26
|
-
return new SchemaPrefix(value);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
public static fromValueOrThrow = (value: string): SchemaPrefix => {
|
|
30
|
-
if (!SchemaPrefix.isValid(value)) throw new Error("Invalid prefix");
|
|
31
|
-
return new SchemaPrefix(value);
|
|
32
|
-
};
|
|
33
|
-
public static fromString = (value: string): SchemaPrefix | false => {
|
|
34
|
-
if (!SchemaPrefix.isValid(value)) return false;
|
|
35
|
-
return new SchemaPrefix(value);
|
|
36
|
-
};
|
|
37
|
-
public static castOrCreateRandom = (value: string): SchemaPrefix => {
|
|
38
|
-
const v = SchemaPrefix.isValid(value) ? value : createRandomPrefix<SchemaPrefixValue>(SchemaPrefix.randomLen);
|
|
39
|
-
return new SchemaPrefix(v);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
public static isValid = (prefix: string | 999): prefix is SchemaPrefixValue => {
|
|
43
|
-
if (typeof prefix !== "string") return false;
|
|
44
|
-
if (prefix.length < SchemaPrefix.MIN_LENGTH) return false;
|
|
45
|
-
if (prefix.length > SchemaPrefix.MAX_LENGTH) return false;
|
|
46
|
-
return true;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
get value(): SchemaPrefixValue {
|
|
50
|
-
return this._value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
set value(value: string) {
|
|
54
|
-
if (!SchemaPrefix.isValid(value)) {
|
|
55
|
-
console.log("INVALID PREFIX", value);
|
|
56
|
-
} else {
|
|
57
|
-
this._value = value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
private constructor(private _value: SchemaPrefixValue) {}
|
|
61
|
-
}
|
|
62
|
-
export class PagePrefix {
|
|
63
|
-
public static readonly MIN_LENGTH = 1;
|
|
64
|
-
private static randomLen = 5;
|
|
65
|
-
public static readonly MAX_LENGTH = 16;
|
|
66
|
-
public static fromValue = (value: PagePrefixValue): PagePrefix => {
|
|
67
|
-
return new PagePrefix(value);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
public static create = (): PagePrefix => {
|
|
71
|
-
const v = createRandomPrefix<PagePrefixValue>(PagePrefix.randomLen);
|
|
72
|
-
return new PagePrefix(v);
|
|
73
|
-
};
|
|
74
|
-
public static fromString = (value: string): PagePrefix | false => {
|
|
75
|
-
if (!PagePrefix.isValid(value)) return false;
|
|
76
|
-
return new PagePrefix(value);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
public static fromStringOrThrow = (value: string): PagePrefixValue => {
|
|
80
|
-
if (!PagePrefix.isValid(value)) throw new Error("Invalid prefix");
|
|
81
|
-
return value;
|
|
82
|
-
};
|
|
83
|
-
public static castOrCreateRandom = (value: string): PagePrefix => {
|
|
84
|
-
const v = PagePrefix.isValid(value) ? value : createRandomPrefix<PagePrefixValue>(PagePrefix.randomLen);
|
|
85
|
-
return new PagePrefix(v);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
public static isValid = (prefix: string | 999): prefix is PagePrefixValue => {
|
|
89
|
-
if (typeof prefix !== "string") return false;
|
|
90
|
-
if (prefix.length < SchemaPrefix.MIN_LENGTH) return false;
|
|
91
|
-
if (prefix.length > SchemaPrefix.MAX_LENGTH) return false;
|
|
92
|
-
return true;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
get value(): PagePrefixValue {
|
|
96
|
-
return this._value;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
set value(value: string) {
|
|
100
|
-
if (!PagePrefix.isValid(value)) {
|
|
101
|
-
console.log("INVALID PREFIX", value);
|
|
102
|
-
} else {
|
|
103
|
-
this._value = value;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
private constructor(private _value: PagePrefixValue) {}
|
|
107
|
-
}
|
|
File without changes
|