@media-quest/builder 0.0.9 → 0.0.10
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 +2 -0
- package/dist/public-api.d.ts +2 -0
- package/dist/public-api.js +8 -5
- package/dist/public-api.mjs +8 -5
- package/package.json +2 -2
- package/src/Builder-schema.ts +3 -0
- package/src/rulebuilder/RuleAction.ts +3 -0
- package/src/rulebuilder/RuleBuilder-test-utils.ts +30 -12
- package/src/rulebuilder/SingleSelectItem.ts +2 -2
- package/src/rulebuilder/multi-select-item.ts +62 -54
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@media-quest/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Builder library for Media-quest schemas",
|
|
5
5
|
"main": "dist/public-api.js",
|
|
6
6
|
"module": "dist/public-api.mjs",
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
"prepublishOnly": "npm run build"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@media-quest/engine": "0.0.
|
|
16
|
+
"@media-quest/engine": "0.0.10"
|
|
17
17
|
}
|
|
18
18
|
}
|
package/src/Builder-schema.ts
CHANGED
|
@@ -213,15 +213,18 @@ export class BuilderSchema {
|
|
|
213
213
|
const pageVariables = page.getQuestionVariables(this._prefix, index);
|
|
214
214
|
qVars.push(...pageVariables);
|
|
215
215
|
const mainText = page.mainText.text;
|
|
216
|
+
const pagePrefix = page.prefix;
|
|
216
217
|
const jumpAction: JumpToPageAction = {
|
|
217
218
|
kind: "jump-to-page",
|
|
218
219
|
pageId: page.id,
|
|
220
|
+
pagePrefix,
|
|
219
221
|
pageNumber: index,
|
|
220
222
|
mainText: page.mainText.text,
|
|
221
223
|
};
|
|
222
224
|
const excludePageAction: ExcludeByPageAction = {
|
|
223
225
|
kind: "exclude-by-pageId",
|
|
224
226
|
pageId: page.id,
|
|
227
|
+
pagePrefix,
|
|
225
228
|
pageNumber: index,
|
|
226
229
|
mainText,
|
|
227
230
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { PageID } from "@media-quest/engine";
|
|
2
|
+
import { PagePrefixValue } from "../prefix";
|
|
2
3
|
|
|
3
4
|
export interface ExcludeByPageAction {
|
|
4
5
|
readonly kind: "exclude-by-pageId";
|
|
5
6
|
readonly pageId: PageID;
|
|
7
|
+
readonly pagePrefix: PagePrefixValue;
|
|
6
8
|
readonly mainText: string;
|
|
7
9
|
readonly pageNumber: number;
|
|
8
10
|
}
|
|
@@ -10,6 +12,7 @@ export interface ExcludeByPageAction {
|
|
|
10
12
|
export interface JumpToPageAction {
|
|
11
13
|
readonly kind: "jump-to-page";
|
|
12
14
|
readonly pageId: PageID;
|
|
15
|
+
readonly pagePrefix: PagePrefixValue;
|
|
13
16
|
readonly mainText: string;
|
|
14
17
|
readonly pageNumber: number;
|
|
15
18
|
}
|
|
@@ -7,9 +7,13 @@ import type { BuilderOperator } from "./condition/Builder-operator";
|
|
|
7
7
|
import type { ExcludeByPageAction, ExcludeByTagAction, JumpToPageAction } from "./RuleAction";
|
|
8
8
|
import { ExcludeByPageIdSelectItem, ExcludeByTagSelectItem } from "./multi-select-item";
|
|
9
9
|
import { PageID } from "@media-quest/engine";
|
|
10
|
-
import { PagePrefix, VarID, SchemaPrefix } from "../prefix";
|
|
10
|
+
import { PagePrefix, VarID, SchemaPrefix, PagePrefixValue } from "../prefix";
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const idPxx = () => {
|
|
13
|
+
const id = PageID.create();
|
|
14
|
+
const prefix = PagePrefix.fromStringOrThrow("pxx");
|
|
15
|
+
return { id, prefix: prefix };
|
|
16
|
+
};
|
|
13
17
|
export namespace RuleBuilderTestUtils {
|
|
14
18
|
export const createOptions = () => [
|
|
15
19
|
BuilderOption.create(0, "Nei"),
|
|
@@ -29,18 +33,22 @@ export namespace RuleBuilderTestUtils {
|
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
export const excludeByPageIdAction = (pageId: PageID, pageNumber: number) => {
|
|
36
|
+
const pagePrefix = PagePrefix.castOrCreateRandom("").value;
|
|
32
37
|
const action: ExcludeByPageAction = {
|
|
33
38
|
kind: "exclude-by-pageId",
|
|
34
39
|
mainText: "",
|
|
35
40
|
pageId,
|
|
41
|
+
pagePrefix,
|
|
36
42
|
pageNumber,
|
|
37
43
|
};
|
|
38
44
|
return action;
|
|
39
45
|
};
|
|
40
46
|
export const jumpToPageAction = (pageId: PageID, pageNumber: number) => {
|
|
47
|
+
const pagePrefix = PagePrefix.castOrCreateRandom("").value;
|
|
41
48
|
const action: JumpToPageAction = {
|
|
42
49
|
kind: "jump-to-page",
|
|
43
50
|
mainText: "TEXT: " + pageId,
|
|
51
|
+
pagePrefix,
|
|
44
52
|
pageId,
|
|
45
53
|
pageNumber,
|
|
46
54
|
};
|
|
@@ -150,7 +158,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
150
158
|
ExcludeByPageIdSelectItem.create(
|
|
151
159
|
{
|
|
152
160
|
kind: "exclude-by-pageId",
|
|
153
|
-
pageId:
|
|
161
|
+
pageId: idPxx().id,
|
|
162
|
+
pagePrefix: idPxx().prefix,
|
|
154
163
|
pageNumber: 5,
|
|
155
164
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
156
165
|
},
|
|
@@ -160,7 +169,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
160
169
|
ExcludeByPageIdSelectItem.create(
|
|
161
170
|
{
|
|
162
171
|
kind: "exclude-by-pageId",
|
|
163
|
-
pageId:
|
|
172
|
+
pageId: idPxx().id,
|
|
173
|
+
pagePrefix: idPxx().prefix,
|
|
164
174
|
pageNumber: 5,
|
|
165
175
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
166
176
|
},
|
|
@@ -170,7 +180,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
170
180
|
ExcludeByPageIdSelectItem.create(
|
|
171
181
|
{
|
|
172
182
|
kind: "exclude-by-pageId",
|
|
173
|
-
pageId:
|
|
183
|
+
pageId: idPxx().id,
|
|
184
|
+
pagePrefix: idPxx().prefix,
|
|
174
185
|
pageNumber: 5,
|
|
175
186
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
176
187
|
},
|
|
@@ -180,7 +191,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
180
191
|
ExcludeByPageIdSelectItem.create(
|
|
181
192
|
{
|
|
182
193
|
kind: "exclude-by-pageId",
|
|
183
|
-
pageId:
|
|
194
|
+
pageId: idPxx().id,
|
|
195
|
+
pagePrefix: idPxx().prefix,
|
|
184
196
|
pageNumber: 5,
|
|
185
197
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
186
198
|
},
|
|
@@ -190,7 +202,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
190
202
|
ExcludeByPageIdSelectItem.create(
|
|
191
203
|
{
|
|
192
204
|
kind: "exclude-by-pageId",
|
|
193
|
-
pageId:
|
|
205
|
+
pageId: idPxx().id,
|
|
206
|
+
pagePrefix: idPxx().prefix,
|
|
194
207
|
pageNumber: 5,
|
|
195
208
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
196
209
|
},
|
|
@@ -199,7 +212,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
199
212
|
ExcludeByPageIdSelectItem.create(
|
|
200
213
|
{
|
|
201
214
|
kind: "exclude-by-pageId",
|
|
202
|
-
pageId:
|
|
215
|
+
pageId: idPxx().id,
|
|
216
|
+
pagePrefix: idPxx().prefix,
|
|
203
217
|
pageNumber: 5,
|
|
204
218
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
205
219
|
},
|
|
@@ -209,7 +223,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
209
223
|
ExcludeByPageIdSelectItem.create(
|
|
210
224
|
{
|
|
211
225
|
kind: "exclude-by-pageId",
|
|
212
|
-
pageId:
|
|
226
|
+
pageId: idPxx().id,
|
|
227
|
+
pagePrefix: idPxx().prefix,
|
|
213
228
|
pageNumber: 5,
|
|
214
229
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
215
230
|
},
|
|
@@ -219,7 +234,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
219
234
|
ExcludeByPageIdSelectItem.create(
|
|
220
235
|
{
|
|
221
236
|
kind: "exclude-by-pageId",
|
|
222
|
-
pageId:
|
|
237
|
+
pageId: idPxx().id,
|
|
238
|
+
pagePrefix: idPxx().prefix,
|
|
223
239
|
pageNumber: 5,
|
|
224
240
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
225
241
|
},
|
|
@@ -229,7 +245,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
229
245
|
ExcludeByPageIdSelectItem.create(
|
|
230
246
|
{
|
|
231
247
|
kind: "exclude-by-pageId",
|
|
232
|
-
pageId:
|
|
248
|
+
pageId: idPxx().id,
|
|
249
|
+
pagePrefix: idPxx().prefix,
|
|
233
250
|
pageNumber: 5,
|
|
234
251
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
235
252
|
},
|
|
@@ -239,7 +256,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
239
256
|
ExcludeByPageIdSelectItem.create(
|
|
240
257
|
{
|
|
241
258
|
kind: "exclude-by-pageId",
|
|
242
|
-
pageId:
|
|
259
|
+
pageId: idPxx().id,
|
|
260
|
+
pagePrefix: idPxx().prefix,
|
|
243
261
|
pageNumber: 5,
|
|
244
262
|
mainText: "Har du noen gang vært deprimeri?? ",
|
|
245
263
|
},
|
|
@@ -122,11 +122,11 @@ export class JumpToPageSelectItem extends SingleSelectItem<JumpToPageAction> {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
protected getSearchString(): string {
|
|
125
|
-
return this.data.
|
|
125
|
+
return this.data.pagePrefix + this.data.mainText;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
protected getSelectLabel(): string {
|
|
129
|
-
return this.data.
|
|
129
|
+
return this.data.pagePrefix + " (" + this.data.pageNumber + ")";
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
protected getTooltip(): string {
|
|
@@ -1,70 +1,78 @@
|
|
|
1
1
|
import { ExcludeByPageAction, ExcludeByTagAction } from "./RuleAction";
|
|
2
2
|
|
|
3
|
+
interface IMultiSelectItem<T> {
|
|
4
|
+
isSelected: boolean;
|
|
5
|
+
readonly tooltip: string;
|
|
6
|
+
readonly searchString: string;
|
|
7
|
+
}
|
|
3
8
|
export abstract class MultiSelectItem<T> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
private readonly _isSelectedInitially: boolean;
|
|
10
|
+
private readonly _selectLabel;
|
|
11
|
+
private readonly _toolTip;
|
|
12
|
+
private readonly _searchString;
|
|
13
|
+
public isSelected: boolean;
|
|
14
|
+
get selectLabel(): string {
|
|
15
|
+
return this._selectLabel;
|
|
16
|
+
}
|
|
17
|
+
get tooltip() {
|
|
18
|
+
return this._toolTip;
|
|
19
|
+
}
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
get searchString() {
|
|
22
|
+
return this._searchString;
|
|
23
|
+
}
|
|
24
|
+
protected constructor(
|
|
25
|
+
readonly data: T,
|
|
26
|
+
isSelected: boolean,
|
|
27
|
+
) {
|
|
28
|
+
this._isSelectedInitially = isSelected;
|
|
29
|
+
this.isSelected = isSelected;
|
|
30
|
+
this._searchString = this.getSearchString();
|
|
31
|
+
this._toolTip = this.getTooltip();
|
|
32
|
+
this._selectLabel = this.getSelectLabel();
|
|
33
|
+
}
|
|
34
|
+
protected abstract getSelectLabel(): string;
|
|
35
|
+
protected abstract getTooltip(): string;
|
|
36
|
+
protected abstract getSearchString(): string;
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
export class ExcludeByTagSelectItem extends MultiSelectItem<ExcludeByTagAction> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
public static readonly create = (tagData: ExcludeByTagAction, isSelected: boolean) => {
|
|
41
|
+
return new ExcludeByTagSelectItem(tagData, isSelected);
|
|
42
|
+
};
|
|
43
|
+
protected constructor(data: ExcludeByTagAction, isSelected: boolean) {
|
|
44
|
+
super(data, isSelected);
|
|
45
|
+
}
|
|
46
|
+
protected getSearchString(): string {
|
|
47
|
+
return this.data.tag;
|
|
48
|
+
}
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
protected getSelectLabel(): string {
|
|
51
|
+
return this.data.tag + " (" + this.data.pageCount + ")";
|
|
52
|
+
}
|
|
45
53
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
protected getTooltip(): string {
|
|
55
|
+
return this.data.tag + " (used in " + this.data.pageCount + " pages)";
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
export class ExcludeByPageIdSelectItem extends MultiSelectItem<ExcludeByPageAction> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
public static create = (ruleActionPage: ExcludeByPageAction, isSelected: boolean) => {
|
|
61
|
+
return new ExcludeByPageIdSelectItem(ruleActionPage, isSelected);
|
|
62
|
+
};
|
|
55
63
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
protected constructor(data: ExcludeByPageAction, isSelected: boolean) {
|
|
65
|
+
super(data, isSelected);
|
|
66
|
+
}
|
|
67
|
+
protected getSearchString(): string {
|
|
68
|
+
return this.data.pagePrefix + this.data.mainText;
|
|
69
|
+
}
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
protected getSelectLabel(): string {
|
|
72
|
+
return this.data.pagePrefix + " (" + this.data.pageNumber + ")";
|
|
73
|
+
}
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
protected getTooltip(): string {
|
|
76
|
+
return this.data.mainText;
|
|
77
|
+
}
|
|
70
78
|
}
|