@media-quest/builder 0.0.2 → 0.0.4

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.
Files changed (27) hide show
  1. package/dist/public-api.d.mts +35 -11
  2. package/dist/public-api.d.ts +35 -11
  3. package/dist/public-api.js +455 -47
  4. package/dist/public-api.mjs +427 -37
  5. package/package.json +3 -4
  6. package/src/Builder-option.ts +51 -52
  7. package/src/Builder-schema.ts +1 -0
  8. package/src/public-api.ts +3 -0
  9. package/src/rulebuilder/Builder-rule.spec.ts +266 -182
  10. package/src/rulebuilder/Builder-rule.ts +106 -67
  11. package/src/rulebuilder/Rule2.ts +87 -0
  12. package/src/rulebuilder/RuleBuilder-test-utils.ts +250 -239
  13. package/src/rulebuilder/RuleVariable.ts +13 -9
  14. package/src/rulebuilder/SingleSelectItem.ts +118 -118
  15. package/src/rulebuilder/{Builder-condition-group.ts → condition/Builder-condition-group.ts} +42 -33
  16. package/src/rulebuilder/condition/Builder-condition.spec.ts +185 -0
  17. package/src/rulebuilder/condition/Builder-condition.ts +208 -0
  18. package/src/rulebuilder/index.ts +11 -11
  19. package/src/rulebuilder/jump-to-action-manager.ts +26 -26
  20. package/src/rulebuilder/page-action-manager.ts +23 -13
  21. package/src/rulebuilder/tag-action-manager.ts +23 -13
  22. package/src/theme/default-theme-compiler.ts +26 -1
  23. package/src/rulebuilder/Builder-condition.spec.ts +0 -169
  24. package/src/rulebuilder/Builder-condition.ts +0 -186
  25. /package/src/rulebuilder/{Builder-condition-group.spec.ts → condition/Builder-condition-group.spec.ts} +0 -0
  26. /package/src/rulebuilder/{Builder-operator.spec.ts → condition/Builder-operator.spec.ts} +0 -0
  27. /package/src/rulebuilder/{Builder-operator.ts → condition/Builder-operator.ts} +0 -0
@@ -379,6 +379,15 @@ var QuestionVariable = class {
379
379
  kind = "question-variable";
380
380
  dataType = "numericWithOptions";
381
381
  };
382
+ var CustomVariable = class {
383
+ constructor(varId, label, options) {
384
+ this.varId = varId;
385
+ this.label = label;
386
+ this.options = options;
387
+ }
388
+ kind = "configuration-variable";
389
+ dataType = "numericWithOptions";
390
+ };
382
391
 
383
392
  // src/Builder-page.ts
384
393
  import { DUtil as DUtil2 } from "@media-quest/engine";
@@ -807,7 +816,7 @@ var TagCollection = class _TagCollection {
807
816
  }
808
817
  };
809
818
 
810
- // src/rulebuilder/Builder-operator.ts
819
+ // src/rulebuilder/condition/Builder-operator.ts
811
820
  var BuilderOperatorSymbols = {
812
821
  equal: true,
813
822
  notEqual: true,
@@ -838,7 +847,7 @@ var BuilderOperator;
838
847
  };
839
848
  })(BuilderOperator || (BuilderOperator = {}));
840
849
 
841
- // src/rulebuilder/Builder-condition.ts
850
+ // src/rulebuilder/condition/Builder-condition.ts
842
851
  var BuilderCondition = class _BuilderCondition extends BuilderObject {
843
852
  objectType = "builder-condition";
844
853
  static NUMBER_OPERATORS = [
@@ -920,6 +929,29 @@ var BuilderCondition = class _BuilderCondition extends BuilderObject {
920
929
  }
921
930
  return { isValid: true };
922
931
  }
932
+ toEngineCondition() {
933
+ const val = this.value;
934
+ const op = this._operator;
935
+ const v = this._variable;
936
+ if (!val)
937
+ return false;
938
+ if (!op)
939
+ return false;
940
+ if (!v)
941
+ return false;
942
+ if (op === "equal") {
943
+ const engineCondition = {
944
+ kind: "numeric-condition",
945
+ value: val.value,
946
+ valueLabel: val.label,
947
+ referenceId: v.varId,
948
+ referenceLabel: v.label,
949
+ operator: "eq"
950
+ };
951
+ return engineCondition;
952
+ }
953
+ return false;
954
+ }
923
955
  findVariableInUniverse(variableId) {
924
956
  const v = this._variableList.find((v2) => v2.varId === variableId);
925
957
  return v ?? false;
@@ -993,7 +1025,7 @@ var BuilderCondition = class _BuilderCondition extends BuilderObject {
993
1025
  }
994
1026
  };
995
1027
 
996
- // src/rulebuilder/Builder-condition-group.ts
1028
+ // src/rulebuilder/condition/Builder-condition-group.ts
997
1029
  var ConditionGroupType = {
998
1030
  all: true,
999
1031
  any: true,
@@ -1021,9 +1053,7 @@ var BuilderConditionGroup = class _BuilderConditionGroup extends BuilderObject {
1021
1053
  this.name = dto.name;
1022
1054
  this._type = dto.type;
1023
1055
  const conditionList = Array.isArray(dto.conditions) ? dto.conditions : [];
1024
- this._conditions = conditionList.map(
1025
- (dto2) => BuilderCondition.fromDto(dto2, variableList)
1026
- );
1056
+ this._conditions = conditionList.map((dto2) => BuilderCondition.fromDto(dto2, variableList));
1027
1057
  this._variableList = variableList;
1028
1058
  }
1029
1059
  get conditions() {
@@ -1049,9 +1079,7 @@ var BuilderConditionGroup = class _BuilderConditionGroup extends BuilderObject {
1049
1079
  return this.toJson();
1050
1080
  }
1051
1081
  toJson() {
1052
- const conditions = [
1053
- ...this._conditions.map((c) => c.toJson())
1054
- ];
1082
+ const conditions = [...this._conditions.map((c) => c.toJson())];
1055
1083
  return {
1056
1084
  name: this.name,
1057
1085
  conditions,
@@ -1059,6 +1087,29 @@ var BuilderConditionGroup = class _BuilderConditionGroup extends BuilderObject {
1059
1087
  kind: "condition-group"
1060
1088
  };
1061
1089
  }
1090
+ toEngineConditionComplex() {
1091
+ const comp = {
1092
+ kind: "complex-condition",
1093
+ all: [],
1094
+ some: [],
1095
+ name: ""
1096
+ };
1097
+ const conditions = [];
1098
+ this.conditions.forEach((c) => {
1099
+ const maybeSimple = c.toEngineCondition();
1100
+ if (maybeSimple) {
1101
+ conditions.push(maybeSimple);
1102
+ }
1103
+ });
1104
+ if (this._type === "all") {
1105
+ return { ...comp, all: conditions };
1106
+ }
1107
+ if (this._type === "any") {
1108
+ return { ...comp, some: conditions };
1109
+ }
1110
+ console.log("INVALID COMPLEX CONDITION. TODO IMPLEMENT range, and count.");
1111
+ return false;
1112
+ }
1062
1113
  get type() {
1063
1114
  return this._type;
1064
1115
  }
@@ -1146,6 +1197,11 @@ var TagActionManager = class {
1146
1197
  const selected = this.selectItems.filter((item) => item.isSelected).map((itm) => itm.data.tag);
1147
1198
  return selected;
1148
1199
  }
1200
+ getEngineActions() {
1201
+ const selected = this.selectItems.filter((item) => item.isSelected);
1202
+ const tagActions = selected.map((s) => s.data);
1203
+ return [...tagActions];
1204
+ }
1149
1205
  };
1150
1206
 
1151
1207
  // src/rulebuilder/page-action-manager.ts
@@ -1165,6 +1221,11 @@ var PageActionManager = class {
1165
1221
  const selected = this.selectItems.filter((item) => item.isSelected).map((itm) => itm.data.pageId);
1166
1222
  return selected;
1167
1223
  }
1224
+ getEngineAction() {
1225
+ const selectItems = this.selectItems.filter((item) => item.isSelected);
1226
+ const actions = selectItems.map((item) => item.data);
1227
+ return [...actions];
1228
+ }
1168
1229
  };
1169
1230
 
1170
1231
  // src/rulebuilder/jump-to-action-manager.ts
@@ -1199,6 +1260,248 @@ var JumpToActionManager = class {
1199
1260
  }
1200
1261
  };
1201
1262
 
1263
+ // src/rulebuilder/Builder-rule.ts
1264
+ import { DUtil as DUtil3 } from "@media-quest/engine";
1265
+
1266
+ // src/rulebuilder/RuleBuilder-test-utils.ts
1267
+ var RuleBuilderTestUtils;
1268
+ ((RuleBuilderTestUtils2) => {
1269
+ RuleBuilderTestUtils2.createOptions = () => [
1270
+ BuilderOption.create(0, "Nei"),
1271
+ BuilderOption.create(1, "Ja"),
1272
+ BuilderOption.create(9, "Vet ikke")
1273
+ ];
1274
+ RuleBuilderTestUtils2.excludeByTagAction = (tag) => {
1275
+ const pageCount = Math.floor(Math.random() * 10);
1276
+ const action = {
1277
+ kind: "exclude-by-tag",
1278
+ tag,
1279
+ description: "Description for tag: " + tag,
1280
+ pageCount
1281
+ };
1282
+ return action;
1283
+ };
1284
+ RuleBuilderTestUtils2.excludeByPageIdAction = (pageId, pageNumber) => {
1285
+ const action = {
1286
+ kind: "exclude-by-pageId",
1287
+ mainText: "",
1288
+ pageId,
1289
+ pageNumber
1290
+ };
1291
+ return action;
1292
+ };
1293
+ RuleBuilderTestUtils2.jumpToPageAction = (pageId, pageNumber) => {
1294
+ const action = {
1295
+ kind: "jump-to-page",
1296
+ mainText: "TEXT: " + pageId,
1297
+ pageId,
1298
+ pageNumber
1299
+ };
1300
+ return action;
1301
+ };
1302
+ RuleBuilderTestUtils2.excludeByTagActionList = () => {
1303
+ const list = [
1304
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag1"),
1305
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag2"),
1306
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag3"),
1307
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag4"),
1308
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag5"),
1309
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag6"),
1310
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag7"),
1311
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag8"),
1312
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag9"),
1313
+ (0, RuleBuilderTestUtils2.excludeByTagAction)("tag10")
1314
+ ];
1315
+ return list;
1316
+ };
1317
+ RuleBuilderTestUtils2.createRuleVariable = (id, pageNumber) => new QuestionVariable(id, "Har du " + id + "?", (0, RuleBuilderTestUtils2.createOptions)(), pageNumber);
1318
+ RuleBuilderTestUtils2.createBuilderVariables_A_H = () => [
1319
+ (0, RuleBuilderTestUtils2.createRuleVariable)("a", 3),
1320
+ (0, RuleBuilderTestUtils2.createRuleVariable)("b", 4),
1321
+ (0, RuleBuilderTestUtils2.createRuleVariable)("c", 5),
1322
+ (0, RuleBuilderTestUtils2.createRuleVariable)("d", 6),
1323
+ (0, RuleBuilderTestUtils2.createRuleVariable)("e", 7),
1324
+ (0, RuleBuilderTestUtils2.createRuleVariable)("f", 8),
1325
+ (0, RuleBuilderTestUtils2.createRuleVariable)("g", 9),
1326
+ (0, RuleBuilderTestUtils2.createRuleVariable)("h", 10)
1327
+ ];
1328
+ RuleBuilderTestUtils2.createConditionDto = (variable) => {
1329
+ const operator = Math.random() > 0 ? "equal" : "notEqual";
1330
+ const opt = variable.options[0];
1331
+ return {
1332
+ kind: "condition",
1333
+ name: "condition 1",
1334
+ variableId: variable.varId,
1335
+ operator,
1336
+ value: opt.value
1337
+ };
1338
+ };
1339
+ RuleBuilderTestUtils2.createConditionGroupDto = (conditions) => {
1340
+ return {
1341
+ kind: "condition-group",
1342
+ conditions,
1343
+ type: "all",
1344
+ name: "random-group-name"
1345
+ };
1346
+ };
1347
+ RuleBuilderTestUtils2.createBuilderRuleDto = () => {
1348
+ const variables = (0, RuleBuilderTestUtils2.createBuilderVariables_A_H)();
1349
+ const condition0 = (0, RuleBuilderTestUtils2.createConditionDto)(variables[0]);
1350
+ const condition1 = (0, RuleBuilderTestUtils2.createConditionDto)(variables[1]);
1351
+ const condition3 = (0, RuleBuilderTestUtils2.createConditionDto)(variables[3]);
1352
+ const condition5 = (0, RuleBuilderTestUtils2.createConditionDto)(variables[5]);
1353
+ const group = (0, RuleBuilderTestUtils2.createConditionGroupDto)([condition0, condition3]);
1354
+ const rule = {
1355
+ name: "rule-name",
1356
+ conditions: [condition1, group, condition5],
1357
+ excludeTags: [],
1358
+ excludePages: [],
1359
+ jumpToPage: false,
1360
+ type: "all"
1361
+ };
1362
+ return [];
1363
+ };
1364
+ RuleBuilderTestUtils2.createExcludeByPageIdList = () => [
1365
+ ExcludeByPageIdSelectItem.create(
1366
+ {
1367
+ kind: "exclude-by-pageId",
1368
+ pageId: "page_a",
1369
+ pageNumber: 5,
1370
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1371
+ },
1372
+ false
1373
+ ),
1374
+ ExcludeByPageIdSelectItem.create(
1375
+ {
1376
+ kind: "exclude-by-pageId",
1377
+ pageId: "page_b",
1378
+ pageNumber: 5,
1379
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1380
+ },
1381
+ true
1382
+ ),
1383
+ ExcludeByPageIdSelectItem.create(
1384
+ {
1385
+ kind: "exclude-by-pageId",
1386
+ pageId: "page_c",
1387
+ pageNumber: 5,
1388
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1389
+ },
1390
+ false
1391
+ ),
1392
+ ExcludeByPageIdSelectItem.create(
1393
+ {
1394
+ kind: "exclude-by-pageId",
1395
+ pageId: "page_d",
1396
+ pageNumber: 5,
1397
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1398
+ },
1399
+ false
1400
+ ),
1401
+ ExcludeByPageIdSelectItem.create(
1402
+ {
1403
+ kind: "exclude-by-pageId",
1404
+ pageId: "page_e",
1405
+ pageNumber: 5,
1406
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1407
+ },
1408
+ true
1409
+ ),
1410
+ ExcludeByPageIdSelectItem.create(
1411
+ {
1412
+ kind: "exclude-by-pageId",
1413
+ pageId: "page_f",
1414
+ pageNumber: 5,
1415
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1416
+ },
1417
+ false
1418
+ ),
1419
+ ExcludeByPageIdSelectItem.create(
1420
+ {
1421
+ kind: "exclude-by-pageId",
1422
+ pageId: "page_g",
1423
+ pageNumber: 5,
1424
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1425
+ },
1426
+ true
1427
+ ),
1428
+ ExcludeByPageIdSelectItem.create(
1429
+ {
1430
+ kind: "exclude-by-pageId",
1431
+ pageId: "page_h",
1432
+ pageNumber: 5,
1433
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1434
+ },
1435
+ false
1436
+ ),
1437
+ ExcludeByPageIdSelectItem.create(
1438
+ {
1439
+ kind: "exclude-by-pageId",
1440
+ pageId: "page_i",
1441
+ pageNumber: 5,
1442
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1443
+ },
1444
+ false
1445
+ ),
1446
+ ExcludeByPageIdSelectItem.create(
1447
+ {
1448
+ kind: "exclude-by-pageId",
1449
+ pageId: "page_j",
1450
+ pageNumber: 5,
1451
+ mainText: "Har du noen gang v\xE6rt deprimeri?? "
1452
+ },
1453
+ true
1454
+ )
1455
+ ];
1456
+ RuleBuilderTestUtils2.createExcludeByTagList = () => [
1457
+ ExcludeByTagSelectItem.create(
1458
+ {
1459
+ kind: "exclude-by-tag",
1460
+ tag: "Can_read",
1461
+ pageCount: 5,
1462
+ description: ""
1463
+ },
1464
+ false
1465
+ ),
1466
+ ExcludeByTagSelectItem.create(
1467
+ {
1468
+ kind: "exclude-by-tag",
1469
+ tag: "Is grownup",
1470
+ pageCount: 1,
1471
+ description: ""
1472
+ },
1473
+ true
1474
+ ),
1475
+ ExcludeByTagSelectItem.create(
1476
+ {
1477
+ kind: "exclude-by-tag",
1478
+ tag: "speaks english",
1479
+ pageCount: 3,
1480
+ description: ""
1481
+ },
1482
+ false
1483
+ ),
1484
+ ExcludeByTagSelectItem.create(
1485
+ {
1486
+ kind: "exclude-by-tag",
1487
+ tag: "has work",
1488
+ pageCount: 7,
1489
+ description: ""
1490
+ },
1491
+ false
1492
+ ),
1493
+ ExcludeByTagSelectItem.create(
1494
+ {
1495
+ kind: "exclude-by-tag",
1496
+ tag: "is-depressed",
1497
+ pageCount: 2,
1498
+ description: ""
1499
+ },
1500
+ false
1501
+ )
1502
+ ];
1503
+ })(RuleBuilderTestUtils || (RuleBuilderTestUtils = {}));
1504
+
1202
1505
  // src/rulebuilder/Builder-rule.ts
1203
1506
  var BuilderRule = class _BuilderRule extends BuilderObject {
1204
1507
  constructor(dto, _ruleInput) {
@@ -1214,26 +1517,14 @@ var BuilderRule = class _BuilderRule extends BuilderObject {
1214
1517
  acc.push(condition);
1215
1518
  }
1216
1519
  if (curr.kind === "condition-group") {
1217
- const conditionGroup = BuilderConditionGroup.fromDto(
1218
- curr,
1219
- conditionInput
1220
- );
1520
+ const conditionGroup = BuilderConditionGroup.fromDto(curr, conditionInput);
1221
1521
  acc.push(conditionGroup);
1222
1522
  }
1223
1523
  return acc;
1224
1524
  }, []);
1225
- this._pageActionManager = new PageActionManager(
1226
- _ruleInput.excludeByPageIdActions,
1227
- dto.excludePages
1228
- );
1229
- this._tagActionManager = new TagActionManager(
1230
- _ruleInput.excludeByTagActions,
1231
- dto.excludeTags
1232
- );
1233
- this.jumpToActionManager = new JumpToActionManager(
1234
- _ruleInput.jumpToPageActions,
1235
- dto.jumpToPage
1236
- );
1525
+ this._pageActionManager = new PageActionManager(_ruleInput.excludeByPageIdActions, dto.excludePages);
1526
+ this._tagActionManager = new TagActionManager(_ruleInput.excludeByTagActions, dto.excludeTags);
1527
+ this.jumpToActionManager = new JumpToActionManager(_ruleInput.jumpToPageActions, dto.jumpToPage);
1237
1528
  }
1238
1529
  objectType = "builder-rule";
1239
1530
  _type = "all";
@@ -1275,9 +1566,7 @@ var BuilderRule = class _BuilderRule extends BuilderObject {
1275
1566
  return true;
1276
1567
  }
1277
1568
  addCondition() {
1278
- const condition = BuilderCondition.create(
1279
- this._ruleInput.getConditionInput()
1280
- );
1569
+ const condition = BuilderCondition.create(this._ruleInput.getConditionInput());
1281
1570
  this._conditions.push(condition);
1282
1571
  return condition;
1283
1572
  }
@@ -1288,10 +1577,7 @@ var BuilderRule = class _BuilderRule extends BuilderObject {
1288
1577
  type: "all",
1289
1578
  conditions: []
1290
1579
  };
1291
- const newGroup = BuilderConditionGroup.fromDto(
1292
- dto,
1293
- this._ruleInput.questionVars
1294
- );
1580
+ const newGroup = BuilderConditionGroup.fromDto(dto, this._ruleInput.questionVars);
1295
1581
  this._conditions.push(newGroup);
1296
1582
  return newGroup;
1297
1583
  }
@@ -1313,6 +1599,70 @@ var BuilderRule = class _BuilderRule extends BuilderObject {
1313
1599
  };
1314
1600
  return dto;
1315
1601
  }
1602
+ toEngineRule() {
1603
+ const conditions = [];
1604
+ this._conditions.forEach((c) => {
1605
+ if (c) {
1606
+ if (c instanceof BuilderCondition) {
1607
+ const simpleCondition = c.toEngineCondition();
1608
+ if (simpleCondition) {
1609
+ conditions.push(simpleCondition);
1610
+ }
1611
+ }
1612
+ if (c instanceof BuilderConditionGroup) {
1613
+ const complexCondition = c.toEngineConditionComplex();
1614
+ if (complexCondition)
1615
+ conditions.push(complexCondition);
1616
+ }
1617
+ }
1618
+ });
1619
+ let all = [];
1620
+ let some = [];
1621
+ if (this.type === "all") {
1622
+ all = [...conditions];
1623
+ }
1624
+ const pageQueCommands = [];
1625
+ const maybeJumpToPage = this.jumpToActionManager.selected;
1626
+ if (maybeJumpToPage) {
1627
+ const jumpCommand = {
1628
+ kind: "PAGE_QUE_JUMP_TO_PAGE_COMMAND",
1629
+ target: "PAGE_QUE",
1630
+ targetId: "PAGE_QUE",
1631
+ payload: { pageId: maybeJumpToPage.data.pageId }
1632
+ };
1633
+ pageQueCommands.push(jumpCommand);
1634
+ }
1635
+ const excludePageByIdList = this._pageActionManager.getEngineAction().map((a) => a.pageId);
1636
+ if (excludePageByIdList.length) {
1637
+ const command = {
1638
+ kind: "PAGE_QUE_EXCLUDE_BY_PAGE_ID_COMMAND",
1639
+ target: "PAGE_QUE",
1640
+ targetId: "PAGE_QUE",
1641
+ payload: { pageIds: [...excludePageByIdList] }
1642
+ };
1643
+ pageQueCommands.push(command);
1644
+ }
1645
+ const excludeTags = this._tagActionManager.getEngineActions().map((tagA) => tagA.tag);
1646
+ if (excludeTags.length) {
1647
+ const excludeTagsCommand = {
1648
+ kind: "PAGE_QUE_EXCLUDE_BY_TAG_COMMAND",
1649
+ target: "PAGE_QUE",
1650
+ targetId: "PAGE_QUE",
1651
+ payload: { tagIds: [...excludeTags] }
1652
+ };
1653
+ pageQueCommands.push(excludeTagsCommand);
1654
+ }
1655
+ const id = DUtil3.randomObjectId();
1656
+ const rule = {
1657
+ id: "",
1658
+ description: this.name,
1659
+ all,
1660
+ some,
1661
+ onFailure: [],
1662
+ onSuccess: pageQueCommands
1663
+ };
1664
+ return rule;
1665
+ }
1316
1666
  };
1317
1667
 
1318
1668
  // src/theme/AbstractThemeCompiler.ts
@@ -1534,17 +1884,37 @@ var ThemeUtils;
1534
1884
 
1535
1885
  // src/theme/default-theme-compiler.ts
1536
1886
  import {
1537
- DUtil as DUtil3
1887
+ DUtil as DUtil4,
1888
+ Rule as Rule2
1538
1889
  } from "@media-quest/engine";
1539
- var U3 = DUtil3;
1890
+ var U3 = DUtil4;
1540
1891
  var generateElementId = () => U3.randomString(32);
1541
1892
  var DefaultThemeCompiler = class extends AbstractThemeCompiler {
1542
1893
  name = "Ispe default theme.";
1894
+ TAG = "[ DEFAULT_THEME_COMPILER ]: ";
1543
1895
  constructor() {
1544
1896
  super(DefaultTheme);
1545
1897
  }
1898
+ compileRules(source) {
1899
+ const builderSchema = BuilderSchema.fromJson(source);
1900
+ const ruleInput = builderSchema.getRuleInput();
1901
+ const pageQueRules = [];
1902
+ source.rules.forEach((rule) => {
1903
+ const engineRule = BuilderRule.fromDto(rule, ruleInput).toEngineRule();
1904
+ if (!Rule2.isEmpty(engineRule)) {
1905
+ pageQueRules.push(engineRule);
1906
+ } else {
1907
+ console.groupCollapsed(this.TAG, "Throws away empty rule.");
1908
+ console.log(rule);
1909
+ console.log(ruleInput);
1910
+ console.groupEnd();
1911
+ }
1912
+ });
1913
+ return pageQueRules;
1914
+ }
1546
1915
  compile(source) {
1547
1916
  const pages = source.pages.map((p) => this.compilePage(p, source.id));
1917
+ const rules = this.compileRules(source);
1548
1918
  const dto = {
1549
1919
  backgroundColor: source.backgroundColor,
1550
1920
  baseHeight: source.baseHeight,
@@ -1554,7 +1924,7 @@ var DefaultThemeCompiler = class extends AbstractThemeCompiler {
1554
1924
  pages,
1555
1925
  predefinedFacts: [],
1556
1926
  prefix: source.prefix,
1557
- rules: [],
1927
+ rules,
1558
1928
  stateFromEvent: [
1559
1929
  {
1560
1930
  onEvent: "VIDEO_ENDED_EVENT",
@@ -1875,8 +2245,8 @@ var DefaultThemeCompiler = class extends AbstractThemeCompiler {
1875
2245
  };
1876
2246
 
1877
2247
  // src/Builder-schema.ts
1878
- import { DUtil as DUtil4 } from "@media-quest/engine";
1879
- var U4 = DUtil4;
2248
+ import { DUtil as DUtil5 } from "@media-quest/engine";
2249
+ var U4 = DUtil5;
1880
2250
  var BuilderSchema = class _BuilderSchema {
1881
2251
  constructor(id, name, prefix) {
1882
2252
  this.id = id;
@@ -1972,6 +2342,7 @@ var BuilderSchema = class _BuilderSchema {
1972
2342
  input
1973
2343
  );
1974
2344
  this._rules.push(rule);
2345
+ return rule;
1975
2346
  }
1976
2347
  deleteRule(rule) {
1977
2348
  this._rules = this._rules.filter((r) => r !== rule);
@@ -2118,12 +2489,31 @@ var BuilderText = class _BuilderText extends BuilderObject {
2118
2489
  }
2119
2490
  };
2120
2491
  export {
2492
+ BuilderCondition,
2493
+ BuilderConditionGroup,
2121
2494
  BuilderMainText,
2495
+ BuilderOperator,
2122
2496
  BuilderOption,
2123
2497
  BuilderPage,
2124
2498
  BuilderQuestion,
2499
+ BuilderRule,
2125
2500
  BuilderSchema,
2126
2501
  BuilderTag,
2127
2502
  BuilderText,
2503
+ BuilderVariableOption,
2504
+ CustomVariable,
2505
+ ExcludeByPageIdSelectItem,
2506
+ ExcludeByTagSelectItem,
2507
+ JumpToActionManager,
2508
+ JumpToPageSelectItem,
2509
+ MultiSelectItem,
2510
+ OperatorSelectItem,
2511
+ PageActionManager,
2512
+ QuestionVariable,
2513
+ RuleInput,
2514
+ RuleOptionSelectItem,
2515
+ RuleVariableSelectItem,
2516
+ SingleSelectItem,
2517
+ TagActionManager,
2128
2518
  TagCollection
2129
2519
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@media-quest/builder",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Builder library for Media-quest schemas",
5
5
  "main": "dist/public-api.js",
6
6
  "module": "dist/public-api.mjs",
@@ -10,10 +10,9 @@
10
10
  "check": "tsc --watch --noEmit",
11
11
  "clean": "rimraf dist",
12
12
  "build": "npm run clean && tsup src/public-api.ts --format cjs,esm --dts",
13
- "prepublishOnly": "npm run build",
14
- "postpublish": "npm run clean"
13
+ "prepublishOnly": "npm run build"
15
14
  },
16
15
  "dependencies": {
17
- "@media-quest/engine": "0.0.2"
16
+ "@media-quest/engine": "0.0.4"
18
17
  }
19
18
  }