@defra/forms-model 3.0.462 → 3.0.463
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/module/conditions/condition-abstract.js +3 -0
- package/dist/module/conditions/condition-abstract.js.map +1 -1
- package/dist/module/conditions/condition-group.js +3 -0
- package/dist/module/conditions/condition-group.js.map +1 -1
- package/dist/module/conditions/condition-model.js +4 -1
- package/dist/module/conditions/condition-model.js.map +1 -1
- package/dist/module/conditions/helpers.js +3 -0
- package/dist/module/conditions/helpers.js.map +1 -1
- package/dist/module/conditions/index.js +1 -1
- package/dist/module/conditions/index.js.map +1 -1
- package/dist/module/conditions/migration.js +13 -7
- package/dist/module/conditions/migration.js.map +1 -1
- package/dist/types/conditions/condition-abstract.d.ts +1 -0
- package/dist/types/conditions/condition-abstract.d.ts.map +1 -1
- package/dist/types/conditions/condition-group.d.ts +1 -0
- package/dist/types/conditions/condition-group.d.ts.map +1 -1
- package/dist/types/conditions/condition-model.d.ts +1 -0
- package/dist/types/conditions/condition-model.d.ts.map +1 -1
- package/dist/types/conditions/helpers.d.ts +9 -5
- package/dist/types/conditions/helpers.d.ts.map +1 -1
- package/dist/types/conditions/index.d.ts +1 -1
- package/dist/types/conditions/index.d.ts.map +1 -1
- package/dist/types/conditions/migration.d.ts +3 -0
- package/dist/types/conditions/migration.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/conditions/condition-abstract.ts +6 -0
- package/src/conditions/condition-group.ts +4 -0
- package/src/conditions/condition-model.ts +7 -0
- package/src/conditions/helpers.ts +12 -9
- package/src/conditions/index.ts +6 -1
- package/src/conditions/migration.ts +20 -7
@@ -10,6 +10,9 @@ export class ConditionAbstract {
|
|
10
10
|
coordinatorString() {
|
11
11
|
return this.coordinator ? `${this.coordinator} ` : '';
|
12
12
|
}
|
13
|
+
coordinatorHtml() {
|
14
|
+
return this.coordinator ? `<span class="govuk-!-font-weight-bold">${this.coordinator.toUpperCase()}</span> ` : '';
|
15
|
+
}
|
13
16
|
getCoordinator() {
|
14
17
|
return this.coordinator;
|
15
18
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-abstract.js","names":["Coordinator","ConditionAbstract","coordinator","constructor","Object","values","includes","Error","coordinatorString","getCoordinator","setCoordinator","isGroup","getGroupedConditions","_asFirstCondition","asFirstCondition","clone","conditionString","conditionExpression"],"sources":["../../../src/conditions/condition-abstract.ts"],"sourcesContent":["import { Coordinator } from '~/src/conditions/enums.js'\n\nexport class ConditionAbstract {\n coordinator?: Coordinator\n\n constructor(coordinator?: Coordinator) {\n if (coordinator && !Object.values(Coordinator).includes(coordinator)) {\n throw Error(`coordinator ${coordinator} is not a valid coordinator`)\n }\n\n this.coordinator = coordinator\n }\n\n coordinatorString(): string {\n return this.coordinator ? `${this.coordinator} ` : ''\n }\n\n getCoordinator(): Coordinator | undefined {\n return this.coordinator\n }\n\n setCoordinator(coordinator?: Coordinator) {\n this.coordinator = coordinator\n }\n\n isGroup() {\n return false\n }\n\n getGroupedConditions() {\n return [this]\n }\n\n _asFirstCondition() {\n delete this.coordinator\n }\n\n asFirstCondition() {\n throw Error(\n 'Unsupported Operation. Method asFirstCondition have not been implemented'\n )\n }\n\n clone() {\n throw Error('Unsupported Operation. Method clone have not been implemented')\n }\n\n conditionString() {\n throw Error(\n 'Unsupported Operation. Method conditionString have not been implemented'\n )\n }\n\n conditionExpression() {\n throw Error(\n 'Unsupported Operation. Method conditionExpression have not been implemented'\n )\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW;AAEpB,OAAO,MAAMC,iBAAiB,CAAC;EAC7BC,WAAW;EAEXC,WAAWA,CAACD,WAAyB,EAAE;IACrC,IAAIA,WAAW,IAAI,CAACE,MAAM,CAACC,MAAM,CAACL,WAAW,CAAC,CAACM,QAAQ,CAACJ,WAAW,CAAC,EAAE;MACpE,MAAMK,KAAK,CAAC,eAAeL,WAAW,6BAA6B,CAAC;IACtE;IAEA,IAAI,CAACA,WAAW,GAAGA,WAAW;EAChC;EAEAM,iBAAiBA,CAAA,EAAW;IAC1B,OAAO,IAAI,CAACN,WAAW,GAAG,GAAG,IAAI,CAACA,WAAW,GAAG,GAAG,EAAE;EACvD;EAEAO,cAAcA,CAAA,EAA4B;IACxC,OAAO,IAAI,
|
1
|
+
{"version":3,"file":"condition-abstract.js","names":["Coordinator","ConditionAbstract","coordinator","constructor","Object","values","includes","Error","coordinatorString","coordinatorHtml","toUpperCase","getCoordinator","setCoordinator","isGroup","getGroupedConditions","_asFirstCondition","asFirstCondition","clone","conditionString","conditionExpression"],"sources":["../../../src/conditions/condition-abstract.ts"],"sourcesContent":["import { Coordinator } from '~/src/conditions/enums.js'\n\nexport class ConditionAbstract {\n coordinator?: Coordinator\n\n constructor(coordinator?: Coordinator) {\n if (coordinator && !Object.values(Coordinator).includes(coordinator)) {\n throw Error(`coordinator ${coordinator} is not a valid coordinator`)\n }\n\n this.coordinator = coordinator\n }\n\n coordinatorString(): string {\n return this.coordinator ? `${this.coordinator} ` : ''\n }\n\n coordinatorHtml(): string {\n return this.coordinator\n ? `<span class=\"govuk-!-font-weight-bold\">${this.coordinator.toUpperCase()}</span> `\n : ''\n }\n\n getCoordinator(): Coordinator | undefined {\n return this.coordinator\n }\n\n setCoordinator(coordinator?: Coordinator) {\n this.coordinator = coordinator\n }\n\n isGroup() {\n return false\n }\n\n getGroupedConditions() {\n return [this]\n }\n\n _asFirstCondition() {\n delete this.coordinator\n }\n\n asFirstCondition() {\n throw Error(\n 'Unsupported Operation. Method asFirstCondition have not been implemented'\n )\n }\n\n clone() {\n throw Error('Unsupported Operation. Method clone have not been implemented')\n }\n\n conditionString() {\n throw Error(\n 'Unsupported Operation. Method conditionString have not been implemented'\n )\n }\n\n conditionExpression() {\n throw Error(\n 'Unsupported Operation. Method conditionExpression have not been implemented'\n )\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW;AAEpB,OAAO,MAAMC,iBAAiB,CAAC;EAC7BC,WAAW;EAEXC,WAAWA,CAACD,WAAyB,EAAE;IACrC,IAAIA,WAAW,IAAI,CAACE,MAAM,CAACC,MAAM,CAACL,WAAW,CAAC,CAACM,QAAQ,CAACJ,WAAW,CAAC,EAAE;MACpE,MAAMK,KAAK,CAAC,eAAeL,WAAW,6BAA6B,CAAC;IACtE;IAEA,IAAI,CAACA,WAAW,GAAGA,WAAW;EAChC;EAEAM,iBAAiBA,CAAA,EAAW;IAC1B,OAAO,IAAI,CAACN,WAAW,GAAG,GAAG,IAAI,CAACA,WAAW,GAAG,GAAG,EAAE;EACvD;EAEAO,eAAeA,CAAA,EAAW;IACxB,OAAO,IAAI,CAACP,WAAW,GACnB,0CAA0C,IAAI,CAACA,WAAW,CAACQ,WAAW,CAAC,CAAC,UAAU,GAClF,EAAE;EACR;EAEAC,cAAcA,CAAA,EAA4B;IACxC,OAAO,IAAI,CAACT,WAAW;EACzB;EAEAU,cAAcA,CAACV,WAAyB,EAAE;IACxC,IAAI,CAACA,WAAW,GAAGA,WAAW;EAChC;EAEAW,OAAOA,CAAA,EAAG;IACR,OAAO,KAAK;EACd;EAEAC,oBAAoBA,CAAA,EAAG;IACrB,OAAO,CAAC,IAAI,CAAC;EACf;EAEAC,iBAAiBA,CAAA,EAAG;IAClB,OAAO,IAAI,CAACb,WAAW;EACzB;EAEAc,gBAAgBA,CAAA,EAAG;IACjB,MAAMT,KAAK,CACT,0EACF,CAAC;EACH;EAEAU,KAAKA,CAAA,EAAG;IACN,MAAMV,KAAK,CAAC,+DAA+D,CAAC;EAC9E;EAEAW,eAAeA,CAAA,EAAG;IAChB,MAAMX,KAAK,CACT,yEACF,CAAC;EACH;EAEAY,mBAAmBA,CAAA,EAAG;IACpB,MAAMZ,KAAK,CACT,6EACF,CAAC;EACH;AACF","ignoreList":[]}
|
@@ -11,6 +11,9 @@ export class ConditionGroup {
|
|
11
11
|
coordinatorString() {
|
12
12
|
return this.conditions[0].coordinatorString();
|
13
13
|
}
|
14
|
+
coordinatorHtml() {
|
15
|
+
return this.conditions[0].coordinatorHtml();
|
16
|
+
}
|
14
17
|
conditionString() {
|
15
18
|
const copy = [...this.conditions];
|
16
19
|
copy.splice(0, 1);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-group.js","names":["conditionFrom","toExpression","toPresentationString","ConditionGroup","conditions","constructor","Array","isArray","length","Error","coordinatorString","conditionString","copy","splice","map","condition","join","conditionExpression","asFirstCondition","getCoordinator","setCoordinator","coordinator","isGroup","getGroupedConditions","clone","from","toJSON","structuredClone","obj"],"sources":["../../../src/conditions/condition-group.ts"],"sourcesContent":["import { conditionFrom } from '~/src/conditions/condition-model.js'\nimport { type ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { type Condition } from '~/src/conditions/condition.js'\nimport { type Coordinator } from '~/src/conditions/enums.js'\nimport { toExpression, toPresentationString } from '~/src/conditions/helpers.js'\nimport { type ConditionGroupData } from '~/src/conditions/types.js'\n\nexport class ConditionGroup {\n conditions: (Condition | ConditionRef | ConditionGroup)[]\n\n constructor(conditions: (Condition | ConditionRef | ConditionGroup)[] = []) {\n if (!Array.isArray(conditions) || conditions.length < 2) {\n throw Error('Cannot construct a condition group from a single condition')\n }\n\n this.conditions = conditions\n }\n\n coordinatorString(): string {\n return this.conditions[0].coordinatorString()\n }\n\n conditionString(): string {\n const copy = [...this.conditions]\n copy.splice(0, 1)\n return `(${this.conditions[0].conditionString()} ${copy\n .map((condition) => toPresentationString(condition))\n .join(' ')})`\n }\n\n conditionExpression(): string {\n const copy = [...this.conditions]\n copy.splice(0, 1)\n return `(${this.conditions[0].conditionExpression()} ${copy\n .map((condition) => toExpression(condition))\n .join(' ')})`\n }\n\n asFirstCondition() {\n this.conditions[0].asFirstCondition()\n return this\n }\n\n getCoordinator(): Coordinator | undefined {\n return this.conditions[0].getCoordinator()\n }\n\n setCoordinator(coordinator?: Coordinator) {\n this.conditions[0].setCoordinator(coordinator)\n }\n\n isGroup() {\n return true\n }\n\n getGroupedConditions(): (Condition | ConditionRef | ConditionGroup)[] {\n return this.conditions.map((condition) => condition.clone())\n }\n\n clone(): ConditionGroup {\n return ConditionGroup.from(this)\n }\n\n toJSON(): ConditionGroupData {\n const { conditions } = this.clone()\n\n return structuredClone({\n conditions: conditions.map((condition) => condition.toJSON())\n })\n }\n\n static from(obj: ConditionGroupData | ConditionGroup): ConditionGroup {\n return new ConditionGroup(\n obj.conditions.map((condition) => {\n return 'clone' in condition\n ? condition.clone()\n : conditionFrom(condition)\n })\n )\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa;AAItB,SAASC,YAAY,EAAEC,oBAAoB;AAG3C,OAAO,MAAMC,cAAc,CAAC;EAC1BC,UAAU;EAEVC,WAAWA,CAACD,UAAyD,GAAG,EAAE,EAAE;IAC1E,IAAI,CAACE,KAAK,CAACC,OAAO,CAACH,UAAU,CAAC,IAAIA,UAAU,CAACI,MAAM,GAAG,CAAC,EAAE;MACvD,MAAMC,KAAK,CAAC,4DAA4D,CAAC;IAC3E;IAEA,IAAI,CAACL,UAAU,GAAGA,UAAU;EAC9B;EAEAM,iBAAiBA,CAAA,EAAW;IAC1B,OAAO,IAAI,CAACN,UAAU,CAAC,CAAC,CAAC,CAACM,iBAAiB,CAAC,CAAC;EAC/C;EAEAC,eAAeA,CAAA,EAAW;IACxB,MAAMC,IAAI,GAAG,CAAC,GAAG,IAAI,
|
1
|
+
{"version":3,"file":"condition-group.js","names":["conditionFrom","toExpression","toPresentationString","ConditionGroup","conditions","constructor","Array","isArray","length","Error","coordinatorString","coordinatorHtml","conditionString","copy","splice","map","condition","join","conditionExpression","asFirstCondition","getCoordinator","setCoordinator","coordinator","isGroup","getGroupedConditions","clone","from","toJSON","structuredClone","obj"],"sources":["../../../src/conditions/condition-group.ts"],"sourcesContent":["import { conditionFrom } from '~/src/conditions/condition-model.js'\nimport { type ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { type Condition } from '~/src/conditions/condition.js'\nimport { type Coordinator } from '~/src/conditions/enums.js'\nimport { toExpression, toPresentationString } from '~/src/conditions/helpers.js'\nimport { type ConditionGroupData } from '~/src/conditions/types.js'\n\nexport class ConditionGroup {\n conditions: (Condition | ConditionRef | ConditionGroup)[]\n\n constructor(conditions: (Condition | ConditionRef | ConditionGroup)[] = []) {\n if (!Array.isArray(conditions) || conditions.length < 2) {\n throw Error('Cannot construct a condition group from a single condition')\n }\n\n this.conditions = conditions\n }\n\n coordinatorString(): string {\n return this.conditions[0].coordinatorString()\n }\n\n coordinatorHtml(): string {\n return this.conditions[0].coordinatorHtml()\n }\n\n conditionString(): string {\n const copy = [...this.conditions]\n copy.splice(0, 1)\n return `(${this.conditions[0].conditionString()} ${copy\n .map((condition) => toPresentationString(condition))\n .join(' ')})`\n }\n\n conditionExpression(): string {\n const copy = [...this.conditions]\n copy.splice(0, 1)\n return `(${this.conditions[0].conditionExpression()} ${copy\n .map((condition) => toExpression(condition))\n .join(' ')})`\n }\n\n asFirstCondition() {\n this.conditions[0].asFirstCondition()\n return this\n }\n\n getCoordinator(): Coordinator | undefined {\n return this.conditions[0].getCoordinator()\n }\n\n setCoordinator(coordinator?: Coordinator) {\n this.conditions[0].setCoordinator(coordinator)\n }\n\n isGroup() {\n return true\n }\n\n getGroupedConditions(): (Condition | ConditionRef | ConditionGroup)[] {\n return this.conditions.map((condition) => condition.clone())\n }\n\n clone(): ConditionGroup {\n return ConditionGroup.from(this)\n }\n\n toJSON(): ConditionGroupData {\n const { conditions } = this.clone()\n\n return structuredClone({\n conditions: conditions.map((condition) => condition.toJSON())\n })\n }\n\n static from(obj: ConditionGroupData | ConditionGroup): ConditionGroup {\n return new ConditionGroup(\n obj.conditions.map((condition) => {\n return 'clone' in condition\n ? condition.clone()\n : conditionFrom(condition)\n })\n )\n }\n}\n"],"mappings":"AAAA,SAASA,aAAa;AAItB,SAASC,YAAY,EAAEC,oBAAoB;AAG3C,OAAO,MAAMC,cAAc,CAAC;EAC1BC,UAAU;EAEVC,WAAWA,CAACD,UAAyD,GAAG,EAAE,EAAE;IAC1E,IAAI,CA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;IACxC,OAAO,IAAI,CAAChB,UAAU,CAAC,CAAC,CAAC,CAACgB,cAAc,CAAC,CAAC;EAC5C;EAEAC,cAAcA,CAACC,WAAyB,EAAE;IACxC,IAAI,CAAClB,UAAU,CAAC,CAAC,CAAC,CAACiB,cAAc,CAACC,WAAW,CAAC;EAChD;EAEAC,OAAOA,CAAA,EAAG;IACR,OAAO,IAAI;EACb;EAEAC,oBAAoBA,CAAA,EAAkD;IACpE,OAAO,IAAI,CAACpB,UAAU,CAACW,GAAG,CAAEC,SAAS,IAAKA,SAAS,CAACS,KAAK,CAAC,CAAC,CAAC;EAC9D;EAEAA,KAAKA,CAAA,EAAmB;IACtB,OAAOtB,cAAc,CAACuB,IAAI,CAAC,IAAI,CAAC;EAClC;EAEAC,MAAMA,CAAA,EAAuB;IAC3B,MAAM;MAAEvB;IAAW,CAAC,GAAG,IAAI,CAACqB,KAAK,CAAC,CAAC;IAEnC,OAAOG,eAAe,CAAC;MACrBxB,UAAU,EAAEA,UAAU,CAACW,GAAG,CAAEC,SAAS,IAAKA,SAAS,CAACW,MAAM,CAAC,CAAC;IAC9D,CAAC,CAAC;EACJ;EAEA,OAAOD,IAAIA,CAACG,GAAwC,EAAkB;IACpE,OAAO,IAAI1B,cAAc,CACvB0B,GAAG,CAACzB,UAAU,CAACW,GAAG,CAAEC,SAAS,IAAK;MAChC,OAAO,OAAO,IAAIA,SAAS,GACvBA,SAAS,CAACS,KAAK,CAAC,CAAC,GACjBzB,aAAa,CAACgB,SAAS,CAAC;IAC9B,CAAC,CACH,CAAC;EACH;AACF","ignoreList":[]}
|
@@ -3,7 +3,7 @@ import { ConditionGroup } from "./condition-group.js";
|
|
3
3
|
import { ConditionRef } from "./condition-ref.js";
|
4
4
|
import { Condition } from "./condition.js";
|
5
5
|
import { Coordinator } from "./enums.js";
|
6
|
-
import { hasConditionGroup, hasConditionName, toExpression, toPresentationString } from "./helpers.js";
|
6
|
+
import { hasConditionGroup, hasConditionName, toExpression, toPresentationHtml, toPresentationString } from "./helpers.js";
|
7
7
|
export class ConditionsModel {
|
8
8
|
#groupedConditions = [];
|
9
9
|
#userGroupedConditions = [];
|
@@ -102,6 +102,9 @@ export class ConditionsModel {
|
|
102
102
|
toPresentationString() {
|
103
103
|
return this.#groupedConditions.map(condition => toPresentationString(condition)).join(' ');
|
104
104
|
}
|
105
|
+
toPresentationHtml() {
|
106
|
+
return this.#groupedConditions.map(condition => toPresentationHtml(condition)).join(' ');
|
107
|
+
}
|
105
108
|
toExpression() {
|
106
109
|
return this.#groupedConditions.map(condition => toExpression(condition)).join(' ');
|
107
110
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-model.js","names":["ConditionGroupDef","ConditionGroup","ConditionRef","Condition","Coordinator","hasConditionGroup","hasConditionName","toExpression","toPresentationString","ConditionsModel","groupedConditions","userGroupedConditions","conditionName","undefined","clone","toReturn","map","it","clear","name","add","condition","coordinatorExpected","length","getCoordinator","Error","push","_applyGroups","replace","index","splice","remove","indexes","filter","_condition","includes","asFirstCondition","addGroups","groupDefs","_group","splitGroup","_ungroup","moveEarlier","switchCoordinators","moveLater","setCoordinator","asPerUserGroupings","hasConditions","lastIndex","join","correctedUserGroups","conditions","_autoGroupDefs","reduce","groups","groupDef","find","contains","startsWith","groupConditions","applyTo","splitIndex","isGroup","copy","getGroupedConditions","orPositions","forEach","OR","hasOr","hasAnd","AND","start","position","thisIsTheLastOr","thereAreMoreConditions","toJSON","from","obj","conditionFrom"],"sources":["../../../src/conditions/condition-model.ts"],"sourcesContent":["import { ConditionGroupDef } from '~/src/conditions/condition-group-def.js'\nimport { ConditionGroup } from '~/src/conditions/condition-group.js'\nimport { ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { Condition } from '~/src/conditions/condition.js'\nimport { Coordinator } from '~/src/conditions/enums.js'\nimport {\n hasConditionGroup,\n hasConditionName,\n toExpression,\n toPresentationString\n} from '~/src/conditions/helpers.js'\nimport {\n type ConditionData,\n type ConditionGroupData,\n type ConditionRefData,\n type ConditionsModelData\n} from '~/src/conditions/types.js'\n\nexport class ConditionsModel {\n #groupedConditions: (Condition | ConditionRef | ConditionGroup)[] = []\n #userGroupedConditions: (Condition | ConditionRef | ConditionGroup)[] = []\n #conditionName: string | undefined = undefined\n\n clone() {\n const toReturn = new ConditionsModel()\n toReturn.#groupedConditions = this.#groupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#userGroupedConditions = this.#userGroupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#conditionName = this.#conditionName\n return toReturn\n }\n\n clear() {\n this.#userGroupedConditions = []\n this.#groupedConditions = []\n this.#conditionName = undefined\n return this\n }\n\n set name(name) {\n this.#conditionName = name\n }\n\n get name() {\n return this.#conditionName\n }\n\n add(condition: Condition | ConditionRef | ConditionGroup) {\n const coordinatorExpected = this.#userGroupedConditions.length !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n }\n\n this.#userGroupedConditions.push(condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n replace(index: number, condition: Condition | ConditionRef | ConditionGroup) {\n const coordinatorExpected = index !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n } else if (index >= this.#userGroupedConditions.length) {\n throw Error(\n `Cannot replace condition ${index} as no such condition exists`\n )\n }\n\n this.#userGroupedConditions.splice(index, 1, condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n remove(indexes: number[]) {\n this.#userGroupedConditions = this.#userGroupedConditions\n .filter((_condition, index) => !indexes.includes(index))\n .map((condition, index) =>\n index === 0 ? condition.asFirstCondition() : condition\n )\n\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n addGroups(groupDefs: ConditionGroupDef[]) {\n this.#userGroupedConditions = this._group(\n this.#userGroupedConditions,\n groupDefs\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n splitGroup(index: number) {\n this.#userGroupedConditions = this._ungroup(\n this.#userGroupedConditions,\n index\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n moveEarlier(index: number) {\n if (index > 0 && index < this.#userGroupedConditions.length) {\n this.#userGroupedConditions.splice(\n index - 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 1) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n moveLater(index: number) {\n if (index >= 0 && index < this.#userGroupedConditions.length - 1) {\n this.#userGroupedConditions.splice(\n index + 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 0) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n switchCoordinators() {\n this.#userGroupedConditions[1].setCoordinator(\n this.#userGroupedConditions[0].getCoordinator()\n )\n this.#userGroupedConditions[0].setCoordinator()\n }\n\n get asPerUserGroupings() {\n return [...this.#userGroupedConditions]\n }\n\n get hasConditions() {\n return this.#userGroupedConditions.length > 0\n }\n\n get lastIndex() {\n return this.#userGroupedConditions.length - 1\n }\n\n toPresentationString() {\n return this.#groupedConditions\n .map((condition) => toPresentationString(condition))\n .join(' ')\n }\n\n toExpression() {\n return this.#groupedConditions\n .map((condition) => toExpression(condition))\n .join(' ')\n }\n\n _applyGroups(\n userGroupedConditions: (Condition | ConditionRef | ConditionGroup)[]\n ) {\n const correctedUserGroups = userGroupedConditions.map((condition) =>\n condition instanceof ConditionGroup && condition.conditions.length > 2\n ? new ConditionGroup(\n this._group(\n condition.conditions,\n this._autoGroupDefs(condition.conditions)\n )\n )\n : condition\n )\n\n return this._group(\n correctedUserGroups,\n this._autoGroupDefs(correctedUserGroups)\n )\n }\n\n _group(\n conditions: (Condition | ConditionRef | ConditionGroup)[],\n groupDefs: ConditionGroupDef[]\n ) {\n return conditions.reduce<(Condition | ConditionRef | ConditionGroup)[]>(\n (groups, condition, index, conditions) => {\n const groupDef = groupDefs.find((groupDef) => groupDef.contains(index))\n\n if (groupDef) {\n if (groupDef.startsWith(index)) {\n const groupConditions = groupDef.applyTo(conditions)\n groups.push(new ConditionGroup(groupConditions))\n }\n } else {\n groups.push(condition)\n }\n\n return groups\n },\n []\n )\n }\n\n _ungroup(\n conditions: (Condition | ConditionRef | ConditionGroup)[],\n splitIndex: number\n ) {\n if (conditions[splitIndex].isGroup()) {\n const copy = [...conditions]\n copy.splice(\n splitIndex,\n 1,\n ...conditions[splitIndex].getGroupedConditions()\n )\n return copy\n }\n return conditions\n }\n\n _autoGroupDefs(conditions: (Condition | ConditionRef | ConditionGroup)[]) {\n const orPositions: number[] = []\n\n conditions.forEach((condition, index) => {\n if (condition.getCoordinator() === Coordinator.OR) {\n orPositions.push(index)\n }\n })\n\n const hasOr = orPositions.length > 0\n const hasAnd = !!conditions.find(\n (condition) => condition.getCoordinator() === Coordinator.AND\n )\n\n if (hasAnd && hasOr) {\n let start = 0\n const groupDefs: ConditionGroupDef[] = []\n orPositions.forEach((position, index) => {\n if (start < position - 1) {\n groupDefs.push(new ConditionGroupDef(start, position - 1))\n }\n const thisIsTheLastOr = orPositions.length === index + 1\n const thereAreMoreConditions = conditions.length - 1 > position\n if (thisIsTheLastOr && thereAreMoreConditions) {\n groupDefs.push(new ConditionGroupDef(position, conditions.length - 1))\n }\n start = position\n })\n return groupDefs\n }\n\n return []\n }\n\n toJSON() {\n const name = this.#conditionName\n const conditions = this.#userGroupedConditions\n return {\n name: name ?? '',\n conditions: conditions.map((it) => it.toJSON())\n }\n }\n\n // TODO:- why is this not a constructor?\n static from(obj: ConditionsModel | ConditionsModelData) {\n if (obj instanceof ConditionsModel) {\n return obj\n }\n const toReturn = new ConditionsModel()\n toReturn.#conditionName = obj.name\n toReturn.#userGroupedConditions = obj.conditions.map(conditionFrom)\n toReturn.#groupedConditions = toReturn._applyGroups(\n toReturn.#userGroupedConditions\n )\n return toReturn\n }\n}\n\nexport function conditionFrom(\n it: ConditionData | ConditionRefData | ConditionGroupData\n): Condition | ConditionRef | ConditionGroup {\n if (hasConditionGroup(it)) {\n return new ConditionGroup(it.conditions.map(conditionFrom))\n }\n\n if (hasConditionName(it)) {\n return ConditionRef.from(it)\n }\n\n return Condition.from(it)\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,YAAY;AACrB,SAASC,SAAS;AAClB,SAASC,WAAW;AACpB,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,EACZC,oBAAoB;AAStB,OAAO,MAAMC,eAAe,CAAC;EAC3B,CAACC,iBAAiB,GAAkD,EAAE;EACtE,CAACC,qBAAqB,GAAkD,EAAE;EAC1E,CAACC,aAAa,GAAuBC,SAAS;EAE9CC,KAAKA,CAAA,EAAG;IACN,MAAMC,QAAQ,GAAG,IAAIN,eAAe,CAAC,CAAC;IACtCM,QAAQ,CAAC,CAACL,iBAAiB,GAAG,IAAI,CAAC,CAACA,iBAAiB,CAACM,GAAG,CAAEC,EAAE,IAC3DA,EAAE,CAACH,KAAK,CAAC,CACX,CAAC;IACDC,QAAQ,CAAC,CAACJ,qBAAqB,GAAG,IAAI,CAAC,CAACA,qBAAqB,CAACK,GAAG,CAAEC,EAAE,IACnEA,EAAE,CAACH,KAAK,CAAC,CACX,CAAC;IACDC,QAAQ,CAAC,CAACH,aAAa,GAAG,IAAI,CAAC,CAACA,aAAa;IAC7C,OAAOG,QAAQ;EACjB;EAEAG,KAAKA,CAAA,EAAG;IACN,IAAI,CAAC,CAACP,qBAAqB,GAAG,EAAE;IAChC,IAAI,CAAC,CAACD,iBAAiB,GAAG,EAAE;IAC5B,IAAI,CAAC,CAACE,aAAa,GAAGC,SAAS;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M9D,QAAQ,GAAG,IAAIN,eAAe,CAAC,CAAC;IACtCM,QAAQ,CAAC,CAACH,aAAa,GAAGiE,GAAG,CAAC1D,IAAI;IAClCJ,QAAQ,CAAC,CAACJ,qBAAqB,GAAGkE,GAAG,CAAC1B,UAAU,CAACnC,GAAG,CAAC8D,aAAa,CAAC;IACnE/D,QAAQ,CAAC,CAACL,iBAAiB,GAAGK,QAAQ,CAACY,YAAY,CACjDZ,QAAQ,CAAC,CAACJ,qBACZ,CAAC;IACD,OAAOI,QAAQ;EACjB;AACF;AAEA,OAAO,SAAS+D,aAAaA,CAC3B7D,EAAyD,EACd;EAC3C,IAAIZ,iBAAiB,CAACY,EAAE,CAAC,EAAE;IACzB,OAAO,IAAIhB,cAAc,CAACgB,EAAE,CAACkC,UAAU,CAACnC,GAAG,CAAC8D,aAAa,CAAC,CAAC;EAC7D;EAEA,IAAIxE,gBAAgB,CAACW,EAAE,CAAC,EAAE;IACxB,OAAOf,YAAY,CAAC0E,IAAI,CAAC3D,EAAE,CAAC;EAC9B;EAEA,OAAOd,SAAS,CAACyE,IAAI,CAAC3D,EAAE,CAAC;AAC3B","ignoreList":[]}
|
1
|
+
{"version":3,"file":"condition-model.js","names":["ConditionGroupDef","ConditionGroup","ConditionRef","Condition","Coordinator","hasConditionGroup","hasConditionName","toExpression","toPresentationHtml","toPresentationString","ConditionsModel","groupedConditions","userGroupedConditions","conditionName","undefined","clone","toReturn","map","it","clear","name","add","condition","coordinatorExpected","length","getCoordinator","Error","push","_applyGroups","replace","index","splice","remove","indexes","filter","_condition","includes","asFirstCondition","addGroups","groupDefs","_group","splitGroup","_ungroup","moveEarlier","switchCoordinators","moveLater","setCoordinator","asPerUserGroupings","hasConditions","lastIndex","join","correctedUserGroups","conditions","_autoGroupDefs","reduce","groups","groupDef","find","contains","startsWith","groupConditions","applyTo","splitIndex","isGroup","copy","getGroupedConditions","orPositions","forEach","OR","hasOr","hasAnd","AND","start","position","thisIsTheLastOr","thereAreMoreConditions","toJSON","from","obj","conditionFrom"],"sources":["../../../src/conditions/condition-model.ts"],"sourcesContent":["import { ConditionGroupDef } from '~/src/conditions/condition-group-def.js'\nimport { ConditionGroup } from '~/src/conditions/condition-group.js'\nimport { ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { Condition } from '~/src/conditions/condition.js'\nimport { Coordinator } from '~/src/conditions/enums.js'\nimport {\n hasConditionGroup,\n hasConditionName,\n toExpression,\n toPresentationHtml,\n toPresentationString\n} from '~/src/conditions/helpers.js'\nimport {\n type ConditionData,\n type ConditionGroupData,\n type ConditionRefData,\n type ConditionsModelData\n} from '~/src/conditions/types.js'\n\nexport class ConditionsModel {\n #groupedConditions: (Condition | ConditionRef | ConditionGroup)[] = []\n #userGroupedConditions: (Condition | ConditionRef | ConditionGroup)[] = []\n #conditionName: string | undefined = undefined\n\n clone() {\n const toReturn = new ConditionsModel()\n toReturn.#groupedConditions = this.#groupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#userGroupedConditions = this.#userGroupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#conditionName = this.#conditionName\n return toReturn\n }\n\n clear() {\n this.#userGroupedConditions = []\n this.#groupedConditions = []\n this.#conditionName = undefined\n return this\n }\n\n set name(name) {\n this.#conditionName = name\n }\n\n get name() {\n return this.#conditionName\n }\n\n add(condition: Condition | ConditionRef | ConditionGroup) {\n const coordinatorExpected = this.#userGroupedConditions.length !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n }\n\n this.#userGroupedConditions.push(condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n replace(index: number, condition: Condition | ConditionRef | ConditionGroup) {\n const coordinatorExpected = index !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n } else if (index >= this.#userGroupedConditions.length) {\n throw Error(\n `Cannot replace condition ${index} as no such condition exists`\n )\n }\n\n this.#userGroupedConditions.splice(index, 1, condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n remove(indexes: number[]) {\n this.#userGroupedConditions = this.#userGroupedConditions\n .filter((_condition, index) => !indexes.includes(index))\n .map((condition, index) =>\n index === 0 ? condition.asFirstCondition() : condition\n )\n\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n addGroups(groupDefs: ConditionGroupDef[]) {\n this.#userGroupedConditions = this._group(\n this.#userGroupedConditions,\n groupDefs\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n splitGroup(index: number) {\n this.#userGroupedConditions = this._ungroup(\n this.#userGroupedConditions,\n index\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n moveEarlier(index: number) {\n if (index > 0 && index < this.#userGroupedConditions.length) {\n this.#userGroupedConditions.splice(\n index - 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 1) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n moveLater(index: number) {\n if (index >= 0 && index < this.#userGroupedConditions.length - 1) {\n this.#userGroupedConditions.splice(\n index + 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 0) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n switchCoordinators() {\n this.#userGroupedConditions[1].setCoordinator(\n this.#userGroupedConditions[0].getCoordinator()\n )\n this.#userGroupedConditions[0].setCoordinator()\n }\n\n get asPerUserGroupings() {\n return [...this.#userGroupedConditions]\n }\n\n get hasConditions() {\n return this.#userGroupedConditions.length > 0\n }\n\n get lastIndex() {\n return this.#userGroupedConditions.length - 1\n }\n\n toPresentationString() {\n return this.#groupedConditions\n .map((condition) => toPresentationString(condition))\n .join(' ')\n }\n\n toPresentationHtml() {\n return this.#groupedConditions\n .map((condition) => toPresentationHtml(condition))\n .join(' ')\n }\n\n toExpression() {\n return this.#groupedConditions\n .map((condition) => toExpression(condition))\n .join(' ')\n }\n\n _applyGroups(\n userGroupedConditions: (Condition | ConditionRef | ConditionGroup)[]\n ) {\n const correctedUserGroups = userGroupedConditions.map((condition) =>\n condition instanceof ConditionGroup && condition.conditions.length > 2\n ? new ConditionGroup(\n this._group(\n condition.conditions,\n this._autoGroupDefs(condition.conditions)\n )\n )\n : condition\n )\n\n return this._group(\n correctedUserGroups,\n this._autoGroupDefs(correctedUserGroups)\n )\n }\n\n _group(\n conditions: (Condition | ConditionRef | ConditionGroup)[],\n groupDefs: ConditionGroupDef[]\n ) {\n return conditions.reduce<(Condition | ConditionRef | ConditionGroup)[]>(\n (groups, condition, index, conditions) => {\n const groupDef = groupDefs.find((groupDef) => groupDef.contains(index))\n\n if (groupDef) {\n if (groupDef.startsWith(index)) {\n const groupConditions = groupDef.applyTo(conditions)\n groups.push(new ConditionGroup(groupConditions))\n }\n } else {\n groups.push(condition)\n }\n\n return groups\n },\n []\n )\n }\n\n _ungroup(\n conditions: (Condition | ConditionRef | ConditionGroup)[],\n splitIndex: number\n ) {\n if (conditions[splitIndex].isGroup()) {\n const copy = [...conditions]\n copy.splice(\n splitIndex,\n 1,\n ...conditions[splitIndex].getGroupedConditions()\n )\n return copy\n }\n return conditions\n }\n\n _autoGroupDefs(conditions: (Condition | ConditionRef | ConditionGroup)[]) {\n const orPositions: number[] = []\n\n conditions.forEach((condition, index) => {\n if (condition.getCoordinator() === Coordinator.OR) {\n orPositions.push(index)\n }\n })\n\n const hasOr = orPositions.length > 0\n const hasAnd = !!conditions.find(\n (condition) => condition.getCoordinator() === Coordinator.AND\n )\n\n if (hasAnd && hasOr) {\n let start = 0\n const groupDefs: ConditionGroupDef[] = []\n orPositions.forEach((position, index) => {\n if (start < position - 1) {\n groupDefs.push(new ConditionGroupDef(start, position - 1))\n }\n const thisIsTheLastOr = orPositions.length === index + 1\n const thereAreMoreConditions = conditions.length - 1 > position\n if (thisIsTheLastOr && thereAreMoreConditions) {\n groupDefs.push(new ConditionGroupDef(position, conditions.length - 1))\n }\n start = position\n })\n return groupDefs\n }\n\n return []\n }\n\n toJSON() {\n const name = this.#conditionName\n const conditions = this.#userGroupedConditions\n return {\n name: name ?? '',\n conditions: conditions.map((it) => it.toJSON())\n }\n }\n\n // TODO:- why is this not a constructor?\n static from(obj: ConditionsModel | ConditionsModelData) {\n if (obj instanceof ConditionsModel) {\n return obj\n }\n const toReturn = new ConditionsModel()\n toReturn.#conditionName = obj.name\n toReturn.#userGroupedConditions = obj.conditions.map(conditionFrom)\n toReturn.#groupedConditions = toReturn._applyGroups(\n toReturn.#userGroupedConditions\n )\n return toReturn\n }\n}\n\nexport function conditionFrom(\n it: ConditionData | ConditionRefData | ConditionGroupData\n): Condition | ConditionRef | ConditionGroup {\n if (hasConditionGroup(it)) {\n return new ConditionGroup(it.conditions.map(conditionFrom))\n }\n\n if (hasConditionName(it)) {\n return ConditionRef.from(it)\n }\n\n return Condition.from(it)\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,YAAY;AACrB,SAASC,SAAS;AAClB,SAASC,WAAW;AACpB,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,EACZC,kBAAkB,EAClBC,oBAAoB;AAStB,OAAO,MAAMC,eAAe,CAAC;EAC3B,CAACC,iBAAiB,GAAkD,EAAE;EACtE,CAACC,qBAAqB,GAAkD,EAAE;EAC1E,CAACC,aAAa,GAAuBC,SAAS;EAE9CC,KAAKA,CAAA,EAAG;IACN,MAAMC,QAAQ,GAAG,IAAIN,eAAe,CAAC,CAAC;IACtCM,QAAQ,CAAC,CAACL,iBAAiB,GAAG,IAAI,CAAC,CAACA,iBAAiB,CAACM,GAAG,CAAE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,EAAE,CAAC;EAC9B;EAEA,OAAOf,SAAS,CAAC0E,IAAI,CAAC3D,EAAE,CAAC;AAC3B","ignoreList":[]}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
export function toPresentationString(condition) {
|
2
2
|
return `${condition.coordinatorString()}${condition.conditionString()}`;
|
3
3
|
}
|
4
|
+
export function toPresentationHtml(condition) {
|
5
|
+
return `${condition.coordinatorHtml()}${condition.conditionString()}`;
|
6
|
+
}
|
4
7
|
export function toExpression(condition) {
|
5
8
|
return `${condition.coordinatorString()}${condition.conditionExpression()}`;
|
6
9
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.js","names":["toPresentationString","condition","coordinatorString","conditionString","toExpression","conditionExpression","hasConditionField","hasConditionGroup","hasConditionName","hasNestedCondition","value","conditions","some","isDuplicateCondition","conditionName","name"],"sources":["../../../src/conditions/helpers.ts"],"sourcesContent":["import { type ConditionGroup } from '~/src/conditions/condition-group.js'\nimport { type ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { type Condition } from '~/src/conditions/condition.js'\nimport {\n type ConditionData,\n type ConditionGroupData,\n type ConditionRefData\n} from '~/src/conditions/types.js'\nimport { type ConditionWrapper } from '~/src/form/form-definition/types.js'\n\
|
1
|
+
{"version":3,"file":"helpers.js","names":["toPresentationString","condition","coordinatorString","conditionString","toPresentationHtml","coordinatorHtml","toExpression","conditionExpression","hasConditionField","hasConditionGroup","hasConditionName","hasNestedCondition","value","conditions","some","isDuplicateCondition","conditionName","name"],"sources":["../../../src/conditions/helpers.ts"],"sourcesContent":["import { type ConditionGroup } from '~/src/conditions/condition-group.js'\nimport { type ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { type Condition } from '~/src/conditions/condition.js'\nimport {\n type ConditionData,\n type ConditionGroupData,\n type ConditionRefData\n} from '~/src/conditions/types.js'\nimport { type ConditionWrapper } from '~/src/form/form-definition/types.js'\n\ntype ConditionType = Condition | ConditionRef | ConditionGroup\ntype ConditionDataType = ConditionGroupData | ConditionData | ConditionRefData\n\nexport function toPresentationString(condition: ConditionType) {\n return `${condition.coordinatorString()}${condition.conditionString()}`\n}\n\nexport function toPresentationHtml(condition: ConditionType) {\n return `${condition.coordinatorHtml()}${condition.conditionString()}`\n}\n\nexport function toExpression(condition: ConditionType) {\n return `${condition.coordinatorString()}${condition.conditionExpression()}`\n}\n\nexport const hasConditionField = (\n condition?: ConditionDataType\n): condition is ConditionData => {\n return !!condition && 'field' in condition\n}\n\nexport const hasConditionGroup = (\n condition?: ConditionDataType\n): condition is ConditionGroupData => {\n return !!condition && 'conditions' in condition\n}\n\nexport const hasConditionName = (\n condition?: ConditionDataType\n): condition is ConditionRefData => {\n return !!condition && 'conditionName' in condition\n}\n\nexport const hasNestedCondition = (condition?: ConditionWrapper) => {\n return !!condition?.value.conditions.some(hasConditionName)\n}\n\nexport const isDuplicateCondition = (\n conditions: ConditionWrapper[],\n conditionName: string\n) => {\n return conditions.some((condition) => condition.name === conditionName)\n}\n"],"mappings":"AAaA,OAAO,SAASA,oBAAoBA,CAACC,SAAwB,EAAE;EAC7D,OAAO,GAAGA,SAAS,CAACC,iBAAiB,CAAC,CAAC,GAAGD,SAAS,CAACE,eAAe,CAAC,CAAC,EAAE;AACzE;AAEA,OAAO,SAASC,kBAAkBA,CAACH,SAAwB,EAAE;EAC3D,OAAO,GAAGA,SAAS,CAACI,eAAe,CAAC,CAAC,GAAGJ,SAAS,CAACE,eAAe,CAAC,CAAC,EAAE;AACvE;AAEA,OAAO,SAASG,YAAYA,CAACL,SAAwB,EAAE;EACrD,OAAO,GAAGA,SAAS,CAACC,iBAAiB,CAAC,CAAC,GAAGD,SAAS,CAACM,mBAAmB,CAAC,CAAC,EAAE;AAC7E;AAEA,OAAO,MAAMC,iBAAiB,GAC5BP,SAA6B,IACE;EAC/B,OAAO,CAAC,CAACA,SAAS,IAAI,OAAO,IAAIA,SAAS;AAC5C,CAAC;AAED,OAAO,MAAMQ,iBAAiB,GAC5BR,SAA6B,IACO;EACpC,OAAO,CAAC,CAACA,SAAS,IAAI,YAAY,IAAIA,SAAS;AACjD,CAAC;AAED,OAAO,MAAMS,gBAAgB,GAC3BT,SAA6B,IACK;EAClC,OAAO,CAAC,CAACA,SAAS,IAAI,eAAe,IAAIA,SAAS;AACpD,CAAC;AAED,OAAO,MAAMU,kBAAkB,GAAIV,SAA4B,IAAK;EAClE,OAAO,CAAC,CAACA,SAAS,EAAEW,KAAK,CAACC,UAAU,CAACC,IAAI,CAACJ,gBAAgB,CAAC;AAC7D,CAAC;AAED,OAAO,MAAMK,oBAAoB,GAAGA,CAClCF,UAA8B,EAC9BG,aAAqB,KAClB;EACH,OAAOH,UAAU,CAACC,IAAI,CAAEb,SAAS,IAAKA,SAAS,CAACgB,IAAI,KAAKD,aAAa,CAAC;AACzE,CAAC","ignoreList":[]}
|
@@ -7,6 +7,6 @@ export { ConditionGroup } from "./condition-group.js";
|
|
7
7
|
export { ConditionsModel } from "./condition-model.js";
|
8
8
|
export { ConditionGroupDef } from "./condition-group-def.js";
|
9
9
|
export { hasConditionField, hasConditionGroup, hasConditionName, hasNestedCondition, isDuplicateCondition, toExpression, toPresentationString } from "./helpers.js";
|
10
|
-
export { convertConditionWrapperFromV2 } from "./migration.js";
|
10
|
+
export { convertConditionWrapperFromV2, isConditionWrapper, isConditionWrapperV2 } from "./migration.js";
|
11
11
|
export { ConditionType, Coordinator, DateDirections, DateUnits, Operator, OperatorName } from "./enums.js";
|
12
12
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["absoluteDateOperatorNames","getExpression","getOperatorNames","relativeDateOperatorNames","ConditionValue","RelativeDateValue","conditionValueFrom","ConditionField","Condition","ConditionRef","ConditionGroup","ConditionsModel","ConditionGroupDef","hasConditionField","hasConditionGroup","hasConditionName","hasNestedCondition","isDuplicateCondition","toExpression","toPresentationString","convertConditionWrapperFromV2","ConditionType","Coordinator","DateDirections","DateUnits","Operator","OperatorName"],"sources":["../../../src/conditions/index.ts"],"sourcesContent":["export {\n absoluteDateOperatorNames,\n getExpression,\n getOperatorNames,\n relativeDateOperatorNames\n} from '~/src/conditions/condition-operators.js'\n\nexport {\n ConditionValue,\n RelativeDateValue,\n conditionValueFrom\n} from '~/src/conditions/condition-values.js'\n\nexport { ConditionField } from '~/src/conditions/condition-field.js'\nexport { Condition } from '~/src/conditions/condition.js'\nexport { ConditionRef } from '~/src/conditions/condition-ref.js'\nexport { ConditionGroup } from '~/src/conditions/condition-group.js'\nexport { ConditionsModel } from '~/src/conditions/condition-model.js'\nexport { ConditionGroupDef } from '~/src/conditions/condition-group-def.js'\nexport {\n hasConditionField,\n hasConditionGroup,\n hasConditionName,\n hasNestedCondition,\n isDuplicateCondition,\n toExpression,\n toPresentationString\n} from '~/src/conditions/helpers.js'\n\nexport {
|
1
|
+
{"version":3,"file":"index.js","names":["absoluteDateOperatorNames","getExpression","getOperatorNames","relativeDateOperatorNames","ConditionValue","RelativeDateValue","conditionValueFrom","ConditionField","Condition","ConditionRef","ConditionGroup","ConditionsModel","ConditionGroupDef","hasConditionField","hasConditionGroup","hasConditionName","hasNestedCondition","isDuplicateCondition","toExpression","toPresentationString","convertConditionWrapperFromV2","isConditionWrapper","isConditionWrapperV2","ConditionType","Coordinator","DateDirections","DateUnits","Operator","OperatorName"],"sources":["../../../src/conditions/index.ts"],"sourcesContent":["export {\n absoluteDateOperatorNames,\n getExpression,\n getOperatorNames,\n relativeDateOperatorNames\n} from '~/src/conditions/condition-operators.js'\n\nexport {\n ConditionValue,\n RelativeDateValue,\n conditionValueFrom\n} from '~/src/conditions/condition-values.js'\n\nexport { ConditionField } from '~/src/conditions/condition-field.js'\nexport { Condition } from '~/src/conditions/condition.js'\nexport { ConditionRef } from '~/src/conditions/condition-ref.js'\nexport { ConditionGroup } from '~/src/conditions/condition-group.js'\nexport { ConditionsModel } from '~/src/conditions/condition-model.js'\nexport { ConditionGroupDef } from '~/src/conditions/condition-group-def.js'\nexport {\n hasConditionField,\n hasConditionGroup,\n hasConditionName,\n hasNestedCondition,\n isDuplicateCondition,\n toExpression,\n toPresentationString\n} from '~/src/conditions/helpers.js'\n\nexport {\n convertConditionWrapperFromV2,\n isConditionWrapper,\n isConditionWrapperV2,\n type RuntimeFormModel\n} from '~/src/conditions/migration.js'\n\nexport {\n ConditionType,\n Coordinator,\n DateDirections,\n DateUnits,\n Operator,\n OperatorName\n} from '~/src/conditions/enums.js'\n"],"mappings":"AAAA,SACEA,yBAAyB,EACzBC,aAAa,EACbC,gBAAgB,EAChBC,yBAAyB;AAG3B,SACEC,cAAc,EACdC,iBAAiB,EACjBC,kBAAkB;AAGpB,SAASC,cAAc;AACvB,SAASC,SAAS;AAClB,SAASC,YAAY;AACrB,SAASC,cAAc;AACvB,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SACEC,iBAAiB,EACjBC,iBAAiB,EACjBC,gBAAgB,EAChBC,kBAAkB,EAClBC,oBAAoB,EACpBC,YAAY,EACZC,oBAAoB;AAGtB,SACEC,6BAA6B,EAC7BC,kBAAkB,EAClBC,oBAAoB;AAItB,SACEC,aAAa,EACbC,WAAW,EACXC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,YAAY","ignoreList":[]}
|
@@ -28,7 +28,7 @@ function createConditionValueDataFromStringValueDataV2(value) {
|
|
28
28
|
return {
|
29
29
|
type: ConditionType.Value,
|
30
30
|
value: value.value,
|
31
|
-
display:
|
31
|
+
display: value.value
|
32
32
|
};
|
33
33
|
}
|
34
34
|
function isConditionDataV2(condition) {
|
@@ -59,16 +59,22 @@ function convertConditionDataV2(model, condition, coordinator) {
|
|
59
59
|
};
|
60
60
|
}
|
61
61
|
function convertConditionRefDataFromV2(model, condition, coordinator) {
|
62
|
-
const
|
63
|
-
if (!
|
62
|
+
const refCondition = model.getConditionById(condition.conditionId);
|
63
|
+
if (!refCondition) {
|
64
64
|
throw Error('Component not found');
|
65
65
|
}
|
66
66
|
return {
|
67
|
-
conditionName:
|
68
|
-
conditionDisplayName:
|
67
|
+
conditionName: refCondition.name,
|
68
|
+
conditionDisplayName: refCondition.displayName,
|
69
69
|
coordinator
|
70
70
|
};
|
71
71
|
}
|
72
|
+
export function isConditionWrapperV2(wrapper) {
|
73
|
+
return Array.isArray(wrapper.conditions);
|
74
|
+
}
|
75
|
+
export function isConditionWrapper(wrapper) {
|
76
|
+
return !isConditionWrapperV2(wrapper);
|
77
|
+
}
|
72
78
|
export function convertConditionWrapperFromV2(conditionWrapper, model) {
|
73
79
|
let coordinator;
|
74
80
|
if (conditionWrapper.conditions.length > 1 && !conditionWrapper.coordinator) {
|
@@ -81,12 +87,12 @@ export function convertConditionWrapperFromV2(conditionWrapper, model) {
|
|
81
87
|
displayName: conditionWrapper.displayName,
|
82
88
|
value: {
|
83
89
|
name: conditionWrapper.name,
|
84
|
-
conditions: conditionWrapper.conditions.map(condition => {
|
90
|
+
conditions: conditionWrapper.conditions.map((condition, index) => {
|
85
91
|
let newCondition;
|
86
92
|
if (isConditionDataV2(condition)) {
|
87
93
|
newCondition = convertConditionDataV2(model, condition, coordinator);
|
88
94
|
} else {
|
89
|
-
newCondition = convertConditionRefDataFromV2(model, condition, coordinator);
|
95
|
+
newCondition = convertConditionRefDataFromV2(model, condition, index > 0 ? coordinator : undefined);
|
90
96
|
}
|
91
97
|
return newCondition;
|
92
98
|
})
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"migration.js","names":["ConditionType","isConditionListItemRefValueDataV2","value","type","ListItemRef","isConditionStringValueDataV2","StringValue","getListItem","model","listId","itemId","foundList","getListById","Error","item","items","find","id","createConditionValueDataFromListItemRefV2","refValue","display","text","Value","toString","createConditionValueDataFromStringValueDataV2","isConditionDataV2","condition","convertConditionDataV2","coordinator","component","getComponentById","componentId","newValue","field","name","title","operator","convertConditionRefDataFromV2","conditionId","conditionName","conditionDisplayName","
|
1
|
+
{"version":3,"file":"migration.js","names":["ConditionType","isConditionListItemRefValueDataV2","value","type","ListItemRef","isConditionStringValueDataV2","StringValue","getListItem","model","listId","itemId","foundList","getListById","Error","item","items","find","id","createConditionValueDataFromListItemRefV2","refValue","display","text","Value","toString","createConditionValueDataFromStringValueDataV2","isConditionDataV2","condition","convertConditionDataV2","coordinator","component","getComponentById","componentId","newValue","field","name","title","operator","convertConditionRefDataFromV2","refCondition","getConditionById","conditionId","conditionName","conditionDisplayName","displayName","isConditionWrapperV2","wrapper","Array","isArray","conditions","isConditionWrapper","convertConditionWrapperFromV2","conditionWrapper","length","newConditionWrapper","map","index","newCondition","undefined"],"sources":["../../../src/conditions/migration.ts"],"sourcesContent":["import {\n type ComponentDef,\n type ConditionalComponentType\n} from '~/src/components/types.js'\nimport { ConditionType, type Coordinator } from '~/src/conditions/enums.js'\nimport {\n type ConditionData,\n type ConditionDataV2,\n type ConditionListItemRefValueDataV2,\n type ConditionRefData,\n type ConditionRefDataV2,\n type ConditionStringValueDataV2,\n type ConditionValueData,\n type RelativeDateValueData\n} from '~/src/conditions/types.js'\nimport {\n type ConditionWrapper,\n type ConditionWrapperV2,\n type List\n} from '~/src/form/form-definition/types.js'\n\nfunction isConditionListItemRefValueDataV2(\n value:\n | ConditionListItemRefValueDataV2\n | ConditionStringValueDataV2\n | RelativeDateValueData\n): value is ConditionListItemRefValueDataV2 {\n return value.type === ConditionType.ListItemRef\n}\n\nfunction isConditionStringValueDataV2(\n value:\n | ConditionListItemRefValueDataV2\n | ConditionStringValueDataV2\n | RelativeDateValueData\n): value is ConditionStringValueDataV2 {\n return value.type === ConditionType.StringValue\n}\n\nfunction getListItem(model: RuntimeFormModel, listId: string, itemId: string) {\n const foundList = model.getListById(listId)\n\n if (!foundList) {\n throw Error('List not found')\n }\n\n const item = foundList.items.find((item) => item.id === itemId)\n\n if (!item) {\n throw Error('List item not found')\n }\n\n return item\n}\n\nfunction createConditionValueDataFromListItemRefV2(\n value: ConditionListItemRefValueDataV2,\n model: RuntimeFormModel\n): ConditionValueData {\n const refValue = getListItem(model, value.listId, value.itemId)\n\n return {\n display: refValue.text,\n type: ConditionType.Value,\n value: refValue.value.toString()\n }\n}\n\nfunction createConditionValueDataFromStringValueDataV2(\n value: ConditionStringValueDataV2\n): ConditionValueData {\n return {\n type: ConditionType.Value,\n value: value.value,\n display: value.value\n }\n}\n\nfunction isConditionDataV2(\n condition: ConditionDataV2 | ConditionRefDataV2\n): condition is ConditionDataV2 {\n return 'componentId' in condition\n}\n\nfunction convertConditionDataV2(\n model: RuntimeFormModel,\n condition: ConditionDataV2,\n coordinator: Coordinator | undefined\n): ConditionData {\n const component = model.getComponentById(condition.componentId)\n\n if (!component) {\n throw Error('Component not found')\n }\n\n let newValue\n if (isConditionListItemRefValueDataV2(condition.value)) {\n newValue = createConditionValueDataFromListItemRefV2(condition.value, model)\n } else if (isConditionStringValueDataV2(condition.value)) {\n newValue = createConditionValueDataFromStringValueDataV2(condition.value)\n } else {\n newValue = condition.value\n }\n\n return {\n field: {\n name: component.name,\n type: component.type as ConditionalComponentType /** @todo fix this */,\n display: component.title\n },\n operator: condition.operator,\n value: newValue,\n coordinator\n }\n}\n\nfunction convertConditionRefDataFromV2(\n model: RuntimeFormModel,\n condition: ConditionRefDataV2,\n coordinator: Coordinator | undefined\n): ConditionRefData {\n const refCondition = model.getConditionById(condition.conditionId)\n\n if (!refCondition) {\n throw Error('Component not found')\n }\n\n return {\n conditionName: refCondition.name,\n conditionDisplayName: refCondition.displayName,\n coordinator\n }\n}\n\nexport function isConditionWrapperV2(\n wrapper: ConditionWrapper | ConditionWrapperV2\n): wrapper is ConditionWrapperV2 {\n return Array.isArray((wrapper as ConditionWrapperV2).conditions)\n}\n\nexport function isConditionWrapper(\n wrapper: ConditionWrapper | ConditionWrapperV2\n): wrapper is ConditionWrapper {\n return !isConditionWrapperV2(wrapper)\n}\n\nexport function convertConditionWrapperFromV2(\n conditionWrapper: ConditionWrapperV2,\n model: RuntimeFormModel\n): ConditionWrapper {\n let coordinator\n\n if (conditionWrapper.conditions.length > 1 && !conditionWrapper.coordinator) {\n throw new Error('Coordinator is required for multiple conditions')\n } else {\n coordinator = conditionWrapper.coordinator\n }\n\n const newConditionWrapper: ConditionWrapper = {\n name: conditionWrapper.name,\n displayName: conditionWrapper.displayName,\n value: {\n name: conditionWrapper.name,\n conditions: conditionWrapper.conditions.map((condition, index) => {\n let newCondition: ConditionData | ConditionRefData\n\n if (isConditionDataV2(condition)) {\n newCondition = convertConditionDataV2(model, condition, coordinator)\n } else {\n newCondition = convertConditionRefDataFromV2(\n model,\n condition,\n index > 0 ? coordinator : undefined\n )\n }\n\n return newCondition\n })\n }\n }\n\n return newConditionWrapper\n}\n\nexport interface RuntimeFormModel {\n getListById: (listId: string) => List | undefined\n getComponentById: (componentId: string) => ComponentDef | undefined\n getConditionById: (conditionId: string) => ConditionWrapperV2 | undefined\n}\n"],"mappings":"AAIA,SAASA,aAAa;AAiBtB,SAASC,iCAAiCA,CACxCC,KAGyB,EACiB;EAC1C,OAAOA,KAAK,CAACC,IAAI,KAAKH,aAAa,CAACI,WAAW;AACjD;AAEA,SAASC,4BAA4BA,CACnCH,KAGyB,EACY;EACrC,OAAOA,KAAK,CAACC,IAAI,KAAKH,aAAa,CAACM,WAAW;AACjD;AAEA,SAASC,WAAWA,CAACC,KAAuB,EAAEC,MAAc,EAAEC,MAAc,EAAE;EAC5E,MAAMC,SAAS,GAAGH,KAAK,CAACI,WAAW,CAACH,MAAM,CAAC;EAE3C,IAAI,CAACE,SAAS,EAAE;IACd,MAAME,KAAK,CAAC,gBAAgB,CAAC;EAC/B;EAEA,MAAMC,IAAI,GAAGH,SAAS,CAACI,KAAK,CAACC,IAAI,CAAEF,IAAI,IAAKA,IAAI,CAACG,EAAE,KAAKP,MAAM,CAAC;EAE/D,IAAI,CAACI,IAAI,EAAE;IACT,MAAMD,KAAK,CAAC,qBAAqB,CAAC;EACpC;EAEA,OAAOC,IAAI;AACb;AAEA,SAASI,yCAAyCA,CAChDhB,KAAsC,EACtCM,KAAuB,EACH;EACpB,MAAMW,QAAQ,GAAGZ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CAACM,GAAG,CAAC,CAAC5B,SAAS,EAAE6B,KAAK,KAAK;QAChE,IAAIC,YAA8C;QAElD,IAAI/B,iBAAiB,CAACC,SAAS,CAAC,EAAE;UAChC8B,YAAY,GAAG7B,sBAAsB,CAACnB,KAAK,EAAEkB,SAAS,EAAEE,WAAW,CAAC;QACtE,CAAC,MAAM;UACL4B,YAAY,GAAGnB,6BAA6B,CAC1C7B,KAAK,EACLkB,SAAS,EACT6B,KAAK,GAAG,CAAC,GAAG3B,WAAW,GAAG6B,SAC5B,CAAC;QACH;QAEA,OAAOD,YAAY;MACrB,CAAC;IACH;EACF,CAAC;EAED,OAAOH,mBAAmB;AAC5B","ignoreList":[]}
|
@@ -3,6 +3,7 @@ export declare class ConditionAbstract {
|
|
3
3
|
coordinator?: Coordinator;
|
4
4
|
constructor(coordinator?: Coordinator);
|
5
5
|
coordinatorString(): string;
|
6
|
+
coordinatorHtml(): string;
|
6
7
|
getCoordinator(): Coordinator | undefined;
|
7
8
|
setCoordinator(coordinator?: Coordinator): void;
|
8
9
|
isGroup(): boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-abstract.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD,qBAAa,iBAAiB;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAA;gBAEb,WAAW,CAAC,EAAE,WAAW;IAQrC,iBAAiB,IAAI,MAAM;IAI3B,cAAc,IAAI,WAAW,GAAG,SAAS;IAIzC,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW;IAIxC,OAAO;IAIP,oBAAoB;IAIpB,iBAAiB;IAIjB,gBAAgB;IAMhB,KAAK;IAIL,eAAe;IAMf,mBAAmB;CAKpB"}
|
1
|
+
{"version":3,"file":"condition-abstract.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD,qBAAa,iBAAiB;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAA;gBAEb,WAAW,CAAC,EAAE,WAAW;IAQrC,iBAAiB,IAAI,MAAM;IAI3B,eAAe,IAAI,MAAM;IAMzB,cAAc,IAAI,WAAW,GAAG,SAAS;IAIzC,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW;IAIxC,OAAO;IAIP,oBAAoB;IAIpB,iBAAiB;IAIjB,gBAAgB;IAMhB,KAAK;IAIL,eAAe;IAMf,mBAAmB;CAKpB"}
|
@@ -6,6 +6,7 @@ export declare class ConditionGroup {
|
|
6
6
|
conditions: (Condition | ConditionRef | ConditionGroup)[];
|
7
7
|
constructor(conditions?: (Condition | ConditionRef | ConditionGroup)[]);
|
8
8
|
coordinatorString(): string;
|
9
|
+
coordinatorHtml(): string;
|
9
10
|
conditionString(): string;
|
10
11
|
conditionExpression(): string;
|
11
12
|
asFirstCondition(): this;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-group.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAE5D,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAEnE,qBAAa,cAAc;IACzB,UAAU,EAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE,CAAA;gBAE7C,UAAU,GAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAO;IAQ1E,iBAAiB,IAAI,MAAM;IAI3B,eAAe,IAAI,MAAM;IAQzB,mBAAmB,IAAI,MAAM;IAQ7B,gBAAgB;IAKhB,cAAc,IAAI,WAAW,GAAG,SAAS;IAIzC,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW;IAIxC,OAAO;IAIP,oBAAoB,IAAI,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE;IAIrE,KAAK,IAAI,cAAc;IAIvB,MAAM,IAAI,kBAAkB;IAQ5B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,GAAG,cAAc,GAAG,cAAc;CAStE"}
|
1
|
+
{"version":3,"file":"condition-group.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAE5D,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAEnE,qBAAa,cAAc;IACzB,UAAU,EAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE,CAAA;gBAE7C,UAAU,GAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAO;IAQ1E,iBAAiB,IAAI,MAAM;IAI3B,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM;IAQzB,mBAAmB,IAAI,MAAM;IAQ7B,gBAAgB;IAKhB,cAAc,IAAI,WAAW,GAAG,SAAS;IAIzC,cAAc,CAAC,WAAW,CAAC,EAAE,WAAW;IAIxC,OAAO;IAIP,oBAAoB,IAAI,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE;IAIrE,KAAK,IAAI,cAAc;IAIvB,MAAM,IAAI,kBAAkB;IAQ5B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,GAAG,cAAc,GAAG,cAAc;CAStE"}
|
@@ -21,6 +21,7 @@ export declare class ConditionsModel {
|
|
21
21
|
get hasConditions(): boolean;
|
22
22
|
get lastIndex(): number;
|
23
23
|
toPresentationString(): string;
|
24
|
+
toPresentationHtml(): string;
|
24
25
|
toExpression(): string;
|
25
26
|
_applyGroups(userGroupedConditions: (Condition | ConditionRef | ConditionGroup)[]): (Condition | ConditionRef | ConditionGroup)[];
|
26
27
|
_group(conditions: (Condition | ConditionRef | ConditionGroup)[], groupDefs: ConditionGroupDef[]): (Condition | ConditionRef | ConditionGroup)[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-model.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;
|
1
|
+
{"version":3,"file":"condition-model.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AASzD,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACzB,MAAM,2BAA2B,CAAA;AAElC,qBAAa,eAAe;;IAK1B,KAAK;IAYL,KAAK;IAOL,IAAI,IAAI,CAAC,IAAI,oBAAA,EAEZ;IAED,IAAI,IAAI,uBAEP;IAED,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,YAAY,GAAG,cAAc;IAexD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,YAAY,GAAG,cAAc;IAmB3E,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;IAWxB,SAAS,CAAC,SAAS,EAAE,iBAAiB,EAAE;IASxC,UAAU,CAAC,KAAK,EAAE,MAAM;IASxB,WAAW,CAAC,KAAK,EAAE,MAAM;IAezB,SAAS,CAAC,KAAK,EAAE,MAAM;IAevB,kBAAkB;IAOlB,IAAI,kBAAkB,kDAErB;IAED,IAAI,aAAa,YAEhB;IAED,IAAI,SAAS,WAEZ;IAED,oBAAoB;IAMpB,kBAAkB;IAMlB,YAAY;IAMZ,YAAY,CACV,qBAAqB,EAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE;IAmBtE,MAAM,CACJ,UAAU,EAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE,EACzD,SAAS,EAAE,iBAAiB,EAAE;IAqBhC,QAAQ,CACN,UAAU,EAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE,EACzD,UAAU,EAAE,MAAM;IAcpB,cAAc,CAAC,UAAU,EAAE,CAAC,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC,EAAE;IAkCxE,MAAM;;;;IAUN,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,GAAG,mBAAmB;CAYvD;AAED,wBAAgB,aAAa,CAC3B,EAAE,EAAE,aAAa,GAAG,gBAAgB,GAAG,kBAAkB,GACxD,SAAS,GAAG,YAAY,GAAG,cAAc,CAU3C"}
|
@@ -3,11 +3,15 @@ import { type ConditionRef } from '../conditions/condition-ref.js';
|
|
3
3
|
import { type Condition } from '../conditions/condition.js';
|
4
4
|
import { type ConditionData, type ConditionGroupData, type ConditionRefData } from '../conditions/types.js';
|
5
5
|
import { type ConditionWrapper } from '../form/form-definition/types.js';
|
6
|
-
|
7
|
-
|
8
|
-
export declare
|
9
|
-
export declare
|
10
|
-
export declare
|
6
|
+
type ConditionType = Condition | ConditionRef | ConditionGroup;
|
7
|
+
type ConditionDataType = ConditionGroupData | ConditionData | ConditionRefData;
|
8
|
+
export declare function toPresentationString(condition: ConditionType): string;
|
9
|
+
export declare function toPresentationHtml(condition: ConditionType): string;
|
10
|
+
export declare function toExpression(condition: ConditionType): string;
|
11
|
+
export declare const hasConditionField: (condition?: ConditionDataType) => condition is ConditionData;
|
12
|
+
export declare const hasConditionGroup: (condition?: ConditionDataType) => condition is ConditionGroupData;
|
13
|
+
export declare const hasConditionName: (condition?: ConditionDataType) => condition is ConditionRefData;
|
11
14
|
export declare const hasNestedCondition: (condition?: ConditionWrapper) => boolean;
|
12
15
|
export declare const isDuplicateCondition: (conditions: ConditionWrapper[], conditionName: string) => boolean;
|
16
|
+
export {};
|
13
17
|
//# sourceMappingURL=helpers.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/conditions/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AAE3E,
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/conditions/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACzE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AAE3E,KAAK,aAAa,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,CAAA;AAC9D,KAAK,iBAAiB,GAAG,kBAAkB,GAAG,aAAa,GAAG,gBAAgB,CAAA;AAE9E,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,aAAa,UAE5D;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,aAAa,UAE1D;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,aAAa,UAEpD;AAED,eAAO,MAAM,iBAAiB,GAC5B,YAAY,iBAAiB,KAC5B,SAAS,IAAI,aAEf,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,YAAY,iBAAiB,KAC5B,SAAS,IAAI,kBAEf,CAAA;AAED,eAAO,MAAM,gBAAgB,GAC3B,YAAY,iBAAiB,KAC5B,SAAS,IAAI,gBAEf,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,YAAY,gBAAgB,YAE9D,CAAA;AAED,eAAO,MAAM,oBAAoB,GAC/B,YAAY,gBAAgB,EAAE,EAC9B,eAAe,MAAM,YAGtB,CAAA"}
|
@@ -7,6 +7,6 @@ export { ConditionGroup } from '../conditions/condition-group.js';
|
|
7
7
|
export { ConditionsModel } from '../conditions/condition-model.js';
|
8
8
|
export { ConditionGroupDef } from '../conditions/condition-group-def.js';
|
9
9
|
export { hasConditionField, hasConditionGroup, hasConditionName, hasNestedCondition, isDuplicateCondition, toExpression, toPresentationString } from '../conditions/helpers.js';
|
10
|
-
export { convertConditionWrapperFromV2 } from '../conditions/migration.js';
|
10
|
+
export { convertConditionWrapperFromV2, isConditionWrapper, isConditionWrapperV2, type RuntimeFormModel } from '../conditions/migration.js';
|
11
11
|
export { ConditionType, Coordinator, DateDirections, DateUnits, Operator, OperatorName } from '../conditions/enums.js';
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/conditions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EAC1B,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACrB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/conditions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EAC1B,MAAM,yCAAyC,CAAA;AAEhD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACrB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,6BAA6B,EAC7B,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,gBAAgB,EACtB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EACL,aAAa,EACb,WAAW,EACX,cAAc,EACd,SAAS,EACT,QAAQ,EACR,YAAY,EACb,MAAM,2BAA2B,CAAA"}
|
@@ -1,8 +1,11 @@
|
|
1
1
|
import { type ComponentDef } from '../components/types.js';
|
2
2
|
import { type ConditionWrapper, type ConditionWrapperV2, type List } from '../form/form-definition/types.js';
|
3
|
+
export declare function isConditionWrapperV2(wrapper: ConditionWrapper | ConditionWrapperV2): wrapper is ConditionWrapperV2;
|
4
|
+
export declare function isConditionWrapper(wrapper: ConditionWrapper | ConditionWrapperV2): wrapper is ConditionWrapper;
|
3
5
|
export declare function convertConditionWrapperFromV2(conditionWrapper: ConditionWrapperV2, model: RuntimeFormModel): ConditionWrapper;
|
4
6
|
export interface RuntimeFormModel {
|
5
7
|
getListById: (listId: string) => List | undefined;
|
6
8
|
getComponentById: (componentId: string) => ComponentDef | undefined;
|
9
|
+
getConditionById: (conditionId: string) => ConditionWrapperV2 | undefined;
|
7
10
|
}
|
8
11
|
//# sourceMappingURL=migration.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/conditions/migration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,2BAA2B,CAAA;AAYlC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,IAAI,EACV,MAAM,qCAAqC,CAAA;AAmH5C,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,kBAAkB,EACpC,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,CAiClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,CAAA;IACjD,gBAAgB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/conditions/migration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,2BAA2B,CAAA;AAYlC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,IAAI,EACV,MAAM,qCAAqC,CAAA;AAmH5C,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,GAAG,kBAAkB,GAC7C,OAAO,IAAI,kBAAkB,CAE/B;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,gBAAgB,GAAG,kBAAkB,GAC7C,OAAO,IAAI,gBAAgB,CAE7B;AAED,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,kBAAkB,EACpC,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,CAiClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,CAAA;IACjD,gBAAgB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAA;IACnE,gBAAgB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,kBAAkB,GAAG,SAAS,CAAA;CAC1E"}
|
package/package.json
CHANGED
@@ -15,6 +15,12 @@ export class ConditionAbstract {
|
|
15
15
|
return this.coordinator ? `${this.coordinator} ` : ''
|
16
16
|
}
|
17
17
|
|
18
|
+
coordinatorHtml(): string {
|
19
|
+
return this.coordinator
|
20
|
+
? `<span class="govuk-!-font-weight-bold">${this.coordinator.toUpperCase()}</span> `
|
21
|
+
: ''
|
22
|
+
}
|
23
|
+
|
18
24
|
getCoordinator(): Coordinator | undefined {
|
19
25
|
return this.coordinator
|
20
26
|
}
|
@@ -20,6 +20,10 @@ export class ConditionGroup {
|
|
20
20
|
return this.conditions[0].coordinatorString()
|
21
21
|
}
|
22
22
|
|
23
|
+
coordinatorHtml(): string {
|
24
|
+
return this.conditions[0].coordinatorHtml()
|
25
|
+
}
|
26
|
+
|
23
27
|
conditionString(): string {
|
24
28
|
const copy = [...this.conditions]
|
25
29
|
copy.splice(0, 1)
|
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
hasConditionGroup,
|
8
8
|
hasConditionName,
|
9
9
|
toExpression,
|
10
|
+
toPresentationHtml,
|
10
11
|
toPresentationString
|
11
12
|
} from '~/src/conditions/helpers.js'
|
12
13
|
import {
|
@@ -166,6 +167,12 @@ export class ConditionsModel {
|
|
166
167
|
.join(' ')
|
167
168
|
}
|
168
169
|
|
170
|
+
toPresentationHtml() {
|
171
|
+
return this.#groupedConditions
|
172
|
+
.map((condition) => toPresentationHtml(condition))
|
173
|
+
.join(' ')
|
174
|
+
}
|
175
|
+
|
169
176
|
toExpression() {
|
170
177
|
return this.#groupedConditions
|
171
178
|
.map((condition) => toExpression(condition))
|
@@ -8,32 +8,35 @@ import {
|
|
8
8
|
} from '~/src/conditions/types.js'
|
9
9
|
import { type ConditionWrapper } from '~/src/form/form-definition/types.js'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
type ConditionType = Condition | ConditionRef | ConditionGroup
|
12
|
+
type ConditionDataType = ConditionGroupData | ConditionData | ConditionRefData
|
13
|
+
|
14
|
+
export function toPresentationString(condition: ConditionType) {
|
14
15
|
return `${condition.coordinatorString()}${condition.conditionString()}`
|
15
16
|
}
|
16
17
|
|
17
|
-
export function
|
18
|
-
condition
|
19
|
-
|
18
|
+
export function toPresentationHtml(condition: ConditionType) {
|
19
|
+
return `${condition.coordinatorHtml()}${condition.conditionString()}`
|
20
|
+
}
|
21
|
+
|
22
|
+
export function toExpression(condition: ConditionType) {
|
20
23
|
return `${condition.coordinatorString()}${condition.conditionExpression()}`
|
21
24
|
}
|
22
25
|
|
23
26
|
export const hasConditionField = (
|
24
|
-
condition?:
|
27
|
+
condition?: ConditionDataType
|
25
28
|
): condition is ConditionData => {
|
26
29
|
return !!condition && 'field' in condition
|
27
30
|
}
|
28
31
|
|
29
32
|
export const hasConditionGroup = (
|
30
|
-
condition?:
|
33
|
+
condition?: ConditionDataType
|
31
34
|
): condition is ConditionGroupData => {
|
32
35
|
return !!condition && 'conditions' in condition
|
33
36
|
}
|
34
37
|
|
35
38
|
export const hasConditionName = (
|
36
|
-
condition?:
|
39
|
+
condition?: ConditionDataType
|
37
40
|
): condition is ConditionRefData => {
|
38
41
|
return !!condition && 'conditionName' in condition
|
39
42
|
}
|
package/src/conditions/index.ts
CHANGED
@@ -27,7 +27,12 @@ export {
|
|
27
27
|
toPresentationString
|
28
28
|
} from '~/src/conditions/helpers.js'
|
29
29
|
|
30
|
-
export {
|
30
|
+
export {
|
31
|
+
convertConditionWrapperFromV2,
|
32
|
+
isConditionWrapper,
|
33
|
+
isConditionWrapperV2,
|
34
|
+
type RuntimeFormModel
|
35
|
+
} from '~/src/conditions/migration.js'
|
31
36
|
|
32
37
|
export {
|
33
38
|
ConditionType,
|
@@ -72,7 +72,7 @@ function createConditionValueDataFromStringValueDataV2(
|
|
72
72
|
return {
|
73
73
|
type: ConditionType.Value,
|
74
74
|
value: value.value,
|
75
|
-
display:
|
75
|
+
display: value.value
|
76
76
|
}
|
77
77
|
}
|
78
78
|
|
@@ -119,19 +119,31 @@ function convertConditionRefDataFromV2(
|
|
119
119
|
condition: ConditionRefDataV2,
|
120
120
|
coordinator: Coordinator | undefined
|
121
121
|
): ConditionRefData {
|
122
|
-
const
|
122
|
+
const refCondition = model.getConditionById(condition.conditionId)
|
123
123
|
|
124
|
-
if (!
|
124
|
+
if (!refCondition) {
|
125
125
|
throw Error('Component not found')
|
126
126
|
}
|
127
127
|
|
128
128
|
return {
|
129
|
-
conditionName:
|
130
|
-
conditionDisplayName:
|
129
|
+
conditionName: refCondition.name,
|
130
|
+
conditionDisplayName: refCondition.displayName,
|
131
131
|
coordinator
|
132
132
|
}
|
133
133
|
}
|
134
134
|
|
135
|
+
export function isConditionWrapperV2(
|
136
|
+
wrapper: ConditionWrapper | ConditionWrapperV2
|
137
|
+
): wrapper is ConditionWrapperV2 {
|
138
|
+
return Array.isArray((wrapper as ConditionWrapperV2).conditions)
|
139
|
+
}
|
140
|
+
|
141
|
+
export function isConditionWrapper(
|
142
|
+
wrapper: ConditionWrapper | ConditionWrapperV2
|
143
|
+
): wrapper is ConditionWrapper {
|
144
|
+
return !isConditionWrapperV2(wrapper)
|
145
|
+
}
|
146
|
+
|
135
147
|
export function convertConditionWrapperFromV2(
|
136
148
|
conditionWrapper: ConditionWrapperV2,
|
137
149
|
model: RuntimeFormModel
|
@@ -149,7 +161,7 @@ export function convertConditionWrapperFromV2(
|
|
149
161
|
displayName: conditionWrapper.displayName,
|
150
162
|
value: {
|
151
163
|
name: conditionWrapper.name,
|
152
|
-
conditions: conditionWrapper.conditions.map((condition) => {
|
164
|
+
conditions: conditionWrapper.conditions.map((condition, index) => {
|
153
165
|
let newCondition: ConditionData | ConditionRefData
|
154
166
|
|
155
167
|
if (isConditionDataV2(condition)) {
|
@@ -158,7 +170,7 @@ export function convertConditionWrapperFromV2(
|
|
158
170
|
newCondition = convertConditionRefDataFromV2(
|
159
171
|
model,
|
160
172
|
condition,
|
161
|
-
coordinator
|
173
|
+
index > 0 ? coordinator : undefined
|
162
174
|
)
|
163
175
|
}
|
164
176
|
|
@@ -173,4 +185,5 @@ export function convertConditionWrapperFromV2(
|
|
173
185
|
export interface RuntimeFormModel {
|
174
186
|
getListById: (listId: string) => List | undefined
|
175
187
|
getComponentById: (componentId: string) => ComponentDef | undefined
|
188
|
+
getConditionById: (conditionId: string) => ConditionWrapperV2 | undefined
|
176
189
|
}
|