@useinsider/guido 3.28.1-beta.c5eeeb7 → 3.28.1-beta.d3309a6

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 (47) hide show
  1. package/README.md +10 -0
  2. package/dist/@types/config/schemas.js +142 -129
  3. package/dist/@types/display-condition.js +45 -21
  4. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +25 -19
  5. package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +77 -55
  6. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +1 -1
  7. package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +62 -43
  8. package/dist/components/organisms/display-conditions/LogicBuilderConnector.vue.js +18 -0
  9. package/dist/components/organisms/display-conditions/LogicBuilderConnector.vue2.js +25 -0
  10. package/dist/components/organisms/display-conditions/LogicBuilderField.vue.js +28 -0
  11. package/dist/components/organisms/display-conditions/LogicBuilderField.vue2.js +28 -0
  12. package/dist/components/organisms/display-conditions/LogicBuilderGroup.vue.js +30 -0
  13. package/dist/components/organisms/display-conditions/LogicBuilderGroup.vue2.js +32 -0
  14. package/dist/components/organisms/display-conditions/LogicBuilderRow.vue.js +28 -0
  15. package/dist/components/organisms/display-conditions/LogicBuilderRow.vue2.js +60 -0
  16. package/dist/composables/useDisplayConditions.js +83 -68
  17. package/dist/composables/useScrollToInvalid.js +15 -0
  18. package/dist/config/migrator/itemsBlockMigrator.js +187 -186
  19. package/dist/enums/html-validator.js +1 -1
  20. package/dist/extensions/DisplayConditions/constants.js +19 -10
  21. package/dist/extensions/DisplayConditions/control.js +120 -99
  22. package/dist/extensions/DisplayConditions/display-conditions.css.js +58 -6
  23. package/dist/extensions/DisplayConditions/extension.js +18 -14
  24. package/dist/guido.css +1 -1
  25. package/dist/node_modules/valibot/dist/index.js +118 -102
  26. package/dist/package.json.js +6 -6
  27. package/dist/services/displayConditionApi.js +18 -19
  28. package/dist/src/@types/config/schemas.d.ts +65 -0
  29. package/dist/src/@types/display-condition.d.ts +67 -0
  30. package/dist/src/components/organisms/display-conditions/LogicBuilderConnector.vue.d.ts +19 -0
  31. package/dist/src/components/organisms/display-conditions/LogicBuilderField.vue.d.ts +22 -0
  32. package/dist/src/components/organisms/display-conditions/LogicBuilderGroup.vue.d.ts +24 -0
  33. package/dist/src/components/organisms/display-conditions/LogicBuilderRow.vue.d.ts +25 -0
  34. package/dist/src/components/wrappers/WpModal.vue.d.ts +1 -1
  35. package/dist/src/composables/useConfig.d.ts +42 -2
  36. package/dist/src/composables/useDisplayConditions.d.ts +1 -1
  37. package/dist/src/composables/useScrollToInvalid.d.ts +6 -0
  38. package/dist/src/extensions/DisplayConditions/constants.d.ts +2 -0
  39. package/dist/src/extensions/DisplayConditions/control.d.ts +1 -0
  40. package/dist/src/stores/config.d.ts +441 -21
  41. package/dist/src/utils/displayConditionBuilder.d.ts +29 -0
  42. package/dist/src/utils/displayConditionRules.d.ts +12 -0
  43. package/dist/src/utils/displayConditionSummary.d.ts +11 -0
  44. package/dist/utils/displayConditionBuilder.js +50 -0
  45. package/dist/utils/displayConditionRules.js +91 -0
  46. package/dist/utils/displayConditionSummary.js +28 -0
  47. package/package.json +1 -1
@@ -0,0 +1,29 @@
1
+ import type { AttributeType, DisplayConditionAttribute, LogicOperator, RuleOperator, RuleTree } from '@@/Types/display-condition';
2
+ export interface BuilderRow {
3
+ id: number;
4
+ attribute: string;
5
+ type: AttributeType;
6
+ operator: RuleOperator | '';
7
+ values: string[];
8
+ }
9
+ export interface BuilderGroup {
10
+ id: number;
11
+ condition: LogicOperator;
12
+ rows: BuilderRow[];
13
+ }
14
+ export interface BuilderState {
15
+ condition: LogicOperator;
16
+ groups: BuilderGroup[];
17
+ }
18
+ export type RowField = 'attribute' | 'operator' | 'value';
19
+ export type RowErrors = Partial<Record<RowField, true>>;
20
+ export declare const emptyRow: () => BuilderRow;
21
+ export declare const copyRow: (row: BuilderRow) => BuilderRow;
22
+ export declare const emptyGroup: () => BuilderGroup;
23
+ export declare const emptyBuilder: () => BuilderState;
24
+ export declare const builderFromTree: (tree: RuleTree) => BuilderState;
25
+ export declare const isMultiValue: (operator: RuleOperator | "") => boolean;
26
+ export declare const withAttribute: (row: BuilderRow, attribute: DisplayConditionAttribute) => BuilderRow;
27
+ export declare const withOperator: (row: BuilderRow, operator: RuleOperator) => BuilderRow;
28
+ export declare const findRowErrors: (row: BuilderRow) => RowErrors;
29
+ export declare const treeFromBuilder: (state: BuilderState) => RuleTree | null;
@@ -0,0 +1,12 @@
1
+ import type { AttributeType, DisplayConditionSyntax, RuleOperator, RuleTree } from '@@/Types/display-condition';
2
+ export declare const OPERATORS_BY_TYPE: Record<AttributeType, RuleOperator[]>;
3
+ export declare const MULTI_VALUE_OPERATORS: readonly RuleOperator[];
4
+ export declare const LOGIC_BUILDER_AFTER_SCRIPT = "{% endif %}";
5
+ export declare const operatorsFor: (type: AttributeType) => RuleOperator[];
6
+ export declare const isValidRuleValue: (type: AttributeType, value: string) => boolean;
7
+ export declare const parseRuleTree: (raw: unknown) => RuleTree | null;
8
+ export declare const compileRuleTree: (tree: RuleTree, syntax: DisplayConditionSyntax, scope: string) => {
9
+ beforeScript: string;
10
+ afterScript: string;
11
+ };
12
+ export declare const readLogicBuilderRules: (extraData: string | undefined) => RuleTree | null;
@@ -0,0 +1,11 @@
1
+ import type { DisplayConditionAttribute, LogicOperator, RuleOperator, RuleTree } from '@@/Types/display-condition';
2
+ export declare const OPERATOR_TRANS_SUFFIX: Record<RuleOperator, string>;
3
+ export interface RuleSummaryGroup {
4
+ condition: LogicOperator;
5
+ lines: string[];
6
+ }
7
+ export interface RuleSummary {
8
+ condition: LogicOperator;
9
+ groups: RuleSummaryGroup[];
10
+ }
11
+ export declare const summarizeRuleTree: (tree: RuleTree, attributes: DisplayConditionAttribute[], operatorLabel: (operator: RuleOperator) => string) => RuleSummary;
@@ -0,0 +1,50 @@
1
+ import { isValidRuleValue as s, MULTI_VALUE_OPERATORS as u, operatorsFor as l } from "./displayConditionRules.js";
2
+ let a = 0;
3
+ const r = () => ++a, p = () => ({
4
+ id: r(),
5
+ attribute: "",
6
+ type: "string",
7
+ operator: "",
8
+ values: []
9
+ }), m = (t) => ({ ...t, id: r(), values: [...t.values] }), c = () => ({ id: r(), condition: "and", rows: [p()] }), g = () => ({ condition: "and", groups: [c()] }), b = (t) => ({
10
+ condition: t.condition,
11
+ groups: t.groups.map((e) => ({
12
+ id: r(),
13
+ condition: e.condition,
14
+ rows: e.rules.map((o) => ({ id: r(), ...o, values: [...o.values] }))
15
+ }))
16
+ }), d = (t) => t !== "" && u.includes(t), f = (t, e) => {
17
+ const o = t.operator && l(e.type).includes(t.operator) ? t.operator : "";
18
+ return { ...t, attribute: e.key, type: e.type, operator: o, values: [] };
19
+ }, h = (t, e) => ({
20
+ ...t,
21
+ operator: e,
22
+ values: d(e) ? t.values : t.values.slice(0, 1)
23
+ }), v = (t) => {
24
+ const e = {}, o = t.values.filter((i) => i.trim());
25
+ return t.attribute || (e.attribute = !0), t.operator || (e.operator = !0), (!o.length || !o.every((i) => s(t.type, i))) && (e.value = !0), e;
26
+ }, R = (t) => t.groups.length > 0 && t.groups.every((o) => o.rows.length > 0 && o.rows.every((i) => !Object.keys(v(i)).length)) ? {
27
+ version: 1,
28
+ condition: t.condition,
29
+ groups: t.groups.map((o) => ({
30
+ condition: o.condition,
31
+ rules: o.rows.map((i) => ({
32
+ attribute: i.attribute,
33
+ type: i.type,
34
+ operator: i.operator,
35
+ values: i.values.filter((n) => n.trim()).map((n) => i.type === "number" ? n.trim() : n)
36
+ }))
37
+ }))
38
+ } : null;
39
+ export {
40
+ b as builderFromTree,
41
+ m as copyRow,
42
+ g as emptyBuilder,
43
+ c as emptyGroup,
44
+ p as emptyRow,
45
+ v as findRowErrors,
46
+ d as isMultiValue,
47
+ R as treeFromBuilder,
48
+ f as withAttribute,
49
+ h as withOperator
50
+ };
@@ -0,0 +1,91 @@
1
+ import { RuleTreeSchema as O } from "../@types/display-condition.js";
2
+ import { safeParse as $ } from "../node_modules/valibot/dist/index.js";
3
+ const N = {
4
+ string: ["is", "isNot", "contains", "notContains", "isOneOf", "isNotOneOf"],
5
+ number: ["is", "isNot", "isOneOf", "isNotOneOf"],
6
+ boolean: ["is", "isNot"],
7
+ date: ["is", "isNot", "isOneOf", "isNotOneOf"],
8
+ strings: ["contains", "notContains", "isOneOf", "isNotOneOf"]
9
+ }, L = ["isOneOf", "isNotOneOf"], k = "{% endif %}", g = /^-?\d+(\.\d+)?$/, R = /^\d{4}-\d{2}-\d{2}$/, T = /[{}]|[^\S ]/, U = (t) => N[t] ?? [], B = (t, n) => {
10
+ if (!n.trim() || T.test(n))
11
+ return !1;
12
+ switch (t) {
13
+ case "number":
14
+ return g.test(n.trim());
15
+ case "boolean":
16
+ return n === "true" || n === "false";
17
+ case "date":
18
+ return R.test(n);
19
+ default:
20
+ return !(n.includes('"') && n.includes("'"));
21
+ }
22
+ }, E = (t) => {
23
+ let n = t;
24
+ if (typeof t == "string")
25
+ try {
26
+ n = JSON.parse(t);
27
+ } catch {
28
+ return null;
29
+ }
30
+ const s = $(O, n);
31
+ return s.success ? s.output : null;
32
+ }, S = (t, n, s) => t === "number" ? String(Number(n.trim())) : t === "boolean" ? n === "true" ? "true" : "false" : s === "pongo" ? `"${n.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"` : n.includes('"') ? `'${n}'` : `"${n}"`, a = (t, n) => n.length === 1 ? n[0] : { kind: t, nodes: n }, _ = (t, n) => {
33
+ const { attribute: s, type: o, operator: u, values: i } = t, c = (e, l) => {
34
+ const f = S(o, l, n);
35
+ return {
36
+ kind: "cmp",
37
+ text: e === "contains" && n === "pongo" ? `${f} in ${s}` : `${s} ${e} ${f}`
38
+ };
39
+ }, r = o === "strings" ? "contains" : "==";
40
+ switch (u) {
41
+ case "isNot":
42
+ return c("!=", i[0]);
43
+ case "contains":
44
+ return c("contains", i[0]);
45
+ case "notContains":
46
+ return { kind: "not", node: c("contains", i[0]) };
47
+ case "isOneOf":
48
+ return a("any", i.map((e) => c(r, e)));
49
+ case "isNotOneOf":
50
+ return o === "strings" ? { kind: "not", node: a("any", i.map((e) => c("contains", e))) } : a("all", i.map((e) => c("!=", e)));
51
+ default:
52
+ return c("==", i[0]);
53
+ }
54
+ }, b = (t, n) => a(
55
+ t.condition === "and" ? "all" : "any",
56
+ t.groups.map((s) => a(
57
+ s.condition === "and" ? "all" : "any",
58
+ s.rules.map((o) => _(o, n))
59
+ ))
60
+ ), d = (t) => t === "all" ? " and " : " or ", p = (t) => t.kind === "cmp" ? t.text : t.kind === "not" ? `(${p(t.node)}) != true` : t.nodes.map((n) => n.kind !== "cmp" && n.kind !== t.kind && n.kind !== "not" ? `(${p(n)})` : p(n)).join(d(t.kind)), A = (t, n) => {
61
+ const s = [];
62
+ let o = 0;
63
+ const u = (r) => {
64
+ const e = `${n}_${o++}`, [l, f] = r.kind === "not" ? ["unless", "endunless"] : ["if", "endif"], m = i(r.kind === "not" ? r.node : r);
65
+ return s.push(`{% assign ${e} = false %}{% ${l} ${m} %}{% assign ${e} = true %}{% ${f} %}`), e;
66
+ }, i = (r) => r.kind === "cmp" ? r.text : r.kind === "not" ? u(r) : r.nodes.map((e) => e.kind === "cmp" ? e.text : e.kind === r.kind ? i(e) : u(e)).join(d(r.kind)), c = t.kind === "not" ? u(t) : i(t);
67
+ return `${s.join("")}{% if ${c} %}`;
68
+ }, C = (t, n, s) => {
69
+ const o = b(t, n);
70
+ return {
71
+ beforeScript: n === "pongo" ? `{% if ${p(o)} %}` : A(o, s),
72
+ afterScript: k
73
+ };
74
+ }, j = (t) => {
75
+ try {
76
+ const n = JSON.parse(t || "{}");
77
+ return (n == null ? void 0 : n.method) === "logicBuilder" ? E(n.rules) : null;
78
+ } catch {
79
+ return null;
80
+ }
81
+ };
82
+ export {
83
+ k as LOGIC_BUILDER_AFTER_SCRIPT,
84
+ L as MULTI_VALUE_OPERATORS,
85
+ N as OPERATORS_BY_TYPE,
86
+ C as compileRuleTree,
87
+ B as isValidRuleValue,
88
+ U as operatorsFor,
89
+ E as parseRuleTree,
90
+ j as readLogicBuilderRules
91
+ };
@@ -0,0 +1,28 @@
1
+ const m = {
2
+ is: "is",
3
+ isNot: "is-not",
4
+ contains: "contains",
5
+ notContains: "not-contains",
6
+ isOneOf: "is-one-of",
7
+ isNotOneOf: "is-not-one-of"
8
+ }, r = (i, e, c) => {
9
+ const a = new Map(e.map((n) => [n.key, n])), p = (n) => {
10
+ const o = a.get(n.attribute), d = (s) => {
11
+ var t;
12
+ return ((t = o == null ? void 0 : o.options.find((l) => l.value === s)) == null ? void 0 : t.label) ?? s;
13
+ };
14
+ return [
15
+ (o == null ? void 0 : o.label) ?? n.attribute,
16
+ c(n.operator),
17
+ n.values.map(d).join(", ")
18
+ ].join(" ");
19
+ };
20
+ return {
21
+ condition: i.condition,
22
+ groups: i.groups.map((n) => ({ condition: n.condition, lines: n.rules.map(p) }))
23
+ };
24
+ };
25
+ export {
26
+ m as OPERATOR_TRANS_SUFFIX,
27
+ r as summarizeRuleTree
28
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useinsider/guido",
3
- "version": "3.28.1-beta.c5eeeb7",
3
+ "version": "3.28.1-beta.d3309a6",
4
4
  "description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
5
5
  "main": "./dist/guido.umd.cjs",
6
6
  "module": "./dist/library.js",