@plitzi/sdk-shared 0.32.5 → 0.32.7
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/CHANGELOG.md +16 -0
- package/dist/dataSource/getBindingsDetails.mjs +17 -23
- package/dist/dataSource/helpers/getSourceName.d.ts +4 -0
- package/dist/dataSource/helpers/getSourceName.mjs +4 -0
- package/dist/dataSource/helpers/index.d.ts +2 -0
- package/dist/dataSource/helpers/index.mjs +2 -0
- package/dist/dataSource/hooks/useRegisterSource.mjs +20 -18
- package/dist/dataSource/index.d.ts +1 -0
- package/dist/dataSource/index.mjs +5 -4
- package/dist/dataSource/utility/twigTemplate.mjs +3 -2
- package/dist/helpers/index.mjs +7 -5
- package/dist/helpers/twigWrapper/AST.d.ts +116 -0
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.d.ts +7 -0
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +220 -0
- package/dist/helpers/twigWrapper/Evaluator/helpers.d.ts +4 -0
- package/dist/helpers/twigWrapper/Evaluator/helpers.mjs +4 -0
- package/dist/helpers/twigWrapper/Evaluator/index.d.ts +2 -0
- package/dist/helpers/twigWrapper/Evaluator/index.mjs +2 -0
- package/dist/helpers/twigWrapper/Lexer/Lexer.d.ts +2 -0
- package/dist/helpers/twigWrapper/Lexer/Lexer.mjs +53 -0
- package/dist/helpers/twigWrapper/Lexer/index.d.ts +3 -0
- package/dist/helpers/twigWrapper/Lexer/index.mjs +3 -0
- package/dist/helpers/twigWrapper/Lexer/types.d.ts +17 -0
- package/dist/helpers/twigWrapper/Lexer/types.mjs +10 -0
- package/dist/helpers/twigWrapper/Parser/Cursor.d.ts +14 -0
- package/dist/helpers/twigWrapper/Parser/Cursor.mjs +63 -0
- package/dist/helpers/twigWrapper/Parser/ExpressionParser.d.ts +3 -0
- package/dist/helpers/twigWrapper/Parser/ExpressionParser.mjs +296 -0
- package/dist/helpers/twigWrapper/Parser/Parser.d.ts +3 -0
- package/dist/helpers/twigWrapper/Parser/Parser.mjs +237 -0
- package/dist/helpers/twigWrapper/Parser/helpers.d.ts +2 -0
- package/dist/helpers/twigWrapper/Parser/helpers.mjs +18 -0
- package/dist/helpers/twigWrapper/Parser/index.d.ts +2 -0
- package/dist/helpers/twigWrapper/Parser/index.mjs +2 -0
- package/dist/helpers/twigWrapper/Parser/types.d.ts +5 -0
- package/dist/helpers/twigWrapper/TemplateCache/TemplateCache.d.ts +17 -0
- package/dist/helpers/twigWrapper/TemplateCache/TemplateCache.mjs +64 -0
- package/dist/helpers/twigWrapper/TemplateCache/index.d.ts +1 -0
- package/dist/helpers/twigWrapper/TemplateCache/index.mjs +2 -0
- package/dist/helpers/twigWrapper/bench.bench.d.ts +1 -0
- package/dist/helpers/twigWrapper/charClass.d.ts +44 -0
- package/dist/helpers/twigWrapper/charClass.mjs +59 -0
- package/dist/helpers/twigWrapper/filters/filters.d.ts +14 -0
- package/dist/helpers/twigWrapper/filters/filters.mjs +372 -0
- package/dist/helpers/twigWrapper/filters/index.d.ts +1 -0
- package/dist/helpers/twigWrapper/filters/index.mjs +2 -0
- package/dist/helpers/twigWrapper/index.d.ts +5 -0
- package/dist/helpers/twigWrapper/index.mjs +4 -0
- package/dist/helpers/twigWrapper/processTwig/helpers.d.ts +7 -0
- package/dist/helpers/twigWrapper/processTwig/helpers.mjs +34 -0
- package/dist/helpers/twigWrapper/processTwig/index.d.ts +1 -0
- package/dist/helpers/twigWrapper/processTwig/index.mjs +2 -0
- package/dist/helpers/twigWrapper/processTwig/processTwig.d.ts +1 -0
- package/dist/helpers/twigWrapper/processTwig/processTwig.mjs +24 -0
- package/dist/helpers/twigWrapper/tokens/hasValidToken.d.ts +1 -0
- package/dist/helpers/twigWrapper/tokens/hasValidToken.mjs +9 -0
- package/dist/helpers/twigWrapper/tokens/tokenPatterns.d.ts +2 -0
- package/dist/helpers/twigWrapper/tokens/tokenPatterns.mjs +4 -0
- package/dist/hooks/useNetwork.mjs +1 -1
- package/dist/index.mjs +37 -34
- package/dist/network/graphql/builder/Mutations/Segment/SegmentAddMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/SegmentAddTemplateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/SegmentUpdateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentAddElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentCloneElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentMoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentRemoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Segment/space/elements/SegmentUpdateElementsMutation.mjs +24 -0
- package/dist/network/graphql/builder/Mutations/Segment/style/selectors/SegmentStyleRemoveSelectorsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Segment/style/selectors/SegmentStyleRemoveSelectorsMutation.mjs +12 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceAddElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceAddTemplateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceCloneElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceMoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceRemoveElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateElementsMutation.mjs +24 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSchemaMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Space/pages/SpaceAddPageMutation.mjs +9 -2
- package/dist/network/graphql/builder/Mutations/Space/pages/SpaceUpdatePageMutation.mjs +1 -0
- package/dist/network/graphql/builder/Mutations/Style/selectors/StyleRemoveSelectorsMutation.d.ts +2 -0
- package/dist/network/graphql/builder/Mutations/Style/selectors/StyleRemoveSelectorsMutation.mjs +12 -0
- package/dist/network/graphql/builder/Mutations/index.d.ts +8 -0
- package/dist/network/graphql/builder/Mutations/index.mjs +124 -116
- package/dist/network/graphql/builder/Queries/InitQuery.mjs +2 -0
- package/dist/network/graphql/builder/Queries/Segment/SegmentQuery.mjs +1 -0
- package/dist/network/graphql/builder/Queries/Segment/SegmentsQuery.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/SegmentAddTemplateSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentAddElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentCloneElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentUpdateElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentUpdateElementsSubscription.d.ts +7 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/space/elements/SegmentUpdateElementsSubscription.mjs +27 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/style/selectors/SegmentStyleRemoveSelectorsSubscription.d.ts +8 -0
- package/dist/network/graphql/builder/Subscriptions/Segment/style/selectors/SegmentStyleRemoveSelectorsSubscription.mjs +13 -0
- package/dist/network/graphql/builder/Subscriptions/Space/SpaceAddTemplateSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/SpaceUpdatedSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceAddElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceCloneElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceUpdateElementSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceUpdateElementsSubscription.d.ts +6 -0
- package/dist/network/graphql/builder/Subscriptions/Space/elements/SpaceUpdateElementsSubscription.mjs +26 -0
- package/dist/network/graphql/builder/Subscriptions/Space/pages/SpaceAddPageSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/pages/SpaceHomePageSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Space/pages/SpaceUpdatePageSubscription.mjs +1 -0
- package/dist/network/graphql/builder/Subscriptions/Style/selector/StyleRemoveSelectorsSubscription.d.ts +7 -0
- package/dist/network/graphql/builder/Subscriptions/Style/selector/StyleRemoveSelectorsSubscription.mjs +12 -0
- package/dist/network/graphql/builder/Subscriptions/index.d.ts +12 -0
- package/dist/network/graphql/builder/Subscriptions/index.mjs +94 -86
- package/dist/network/graphql/sdk/Queries/InitQuery.mjs +2 -0
- package/dist/network/graphql/sdk/Queries/Segment/SegmentQuery.mjs +1 -0
- package/dist/network/graphql/sdk/Queries/Segment/SegmentsQuery.mjs +1 -0
- package/dist/store/index.d.ts +33 -33
- package/dist/style/styleConstants.mjs +12 -8
- package/dist/types/CommonTypes.d.ts +1 -3
- package/dist/types/EventBridgeTypes.d.ts +1 -1
- package/dist/types/InteractionTypes.d.ts +2 -1
- package/dist/types/SchemaTypes.d.ts +6 -11
- package/dist/types/ServerTypes.d.ts +59 -0
- package/dist/types/StyleTypes.d.ts +1 -0
- package/package.json +176 -21
- package/dist/helpers/twigWrapper.d.ts +0 -4
- package/dist/helpers/twigWrapper.mjs +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @plitzi/sdk-shared
|
|
2
2
|
|
|
3
|
+
## 0.32.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- v0.32.7
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @plitzi/nexus@0.32.7
|
|
10
|
+
|
|
11
|
+
## 0.32.6
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- v0.32.6
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @plitzi/nexus@0.32.6
|
|
18
|
+
|
|
3
19
|
## 0.32.5
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -3,11 +3,11 @@ import { camelCase as t, get as n, set as r } from "@plitzi/plitzi-ui";
|
|
|
3
3
|
import { QueryBuilderEvaluator as i } from "@plitzi/plitzi-ui/QueryBuilder";
|
|
4
4
|
import { produce as a } from "immer";
|
|
5
5
|
//#region src/dataSource/getBindingsDetails.ts
|
|
6
|
-
var o = (e, t, r, i, a
|
|
7
|
-
let
|
|
6
|
+
var o = (e, t, r, i, a) => {
|
|
7
|
+
let o = i === "initialState" ? `definition.${i}.${a}` : `${i}.${a}`;
|
|
8
8
|
return {
|
|
9
|
-
fromValue:
|
|
10
|
-
toValue: n(
|
|
9
|
+
fromValue: t ? n(e, t, n(r, o)) : void 0,
|
|
10
|
+
toValue: n(r, o, t ? n(e, t) : void 0)
|
|
11
11
|
};
|
|
12
12
|
}, s = (s, c, l = {}) => {
|
|
13
13
|
let { attributes: u, definition: d } = c, { bindings: f } = d;
|
|
@@ -22,25 +22,19 @@ var o = (e, t, r, i, a, o) => {
|
|
|
22
22
|
}, (a) => {
|
|
23
23
|
Object.keys(f).forEach((c) => {
|
|
24
24
|
!f[c] || !Array.isArray(f[c]) || !f[c].length || f[c].forEach((l) => {
|
|
25
|
-
let { source: u,
|
|
26
|
-
if (!
|
|
27
|
-
c === "style" && (
|
|
28
|
-
let { fromValue:
|
|
29
|
-
|
|
30
|
-
let {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
default:
|
|
42
|
-
}
|
|
43
|
-
}), (typeof v == "boolean" || typeof v == "number" || v) && (c === "initialState" ? r(a, `definition.${c}.${h}`, v) : r(a, `${c}.${h}`, v));
|
|
25
|
+
let { source: u, transformers: d, when: f, enabled: p = !0 } = l, { to: m } = l;
|
|
26
|
+
if (!m || f && !i(f, s, !1, !0) || !p) return;
|
|
27
|
+
c === "style" && (m = t(m));
|
|
28
|
+
let { fromValue: h, toValue: g } = o(s, u, a, c, m), _ = h;
|
|
29
|
+
d && Array.isArray(d) && d.length > 0 && d.forEach((t) => {
|
|
30
|
+
let { action: r, params: i, enabled: o = !0 } = t;
|
|
31
|
+
if (!o) return;
|
|
32
|
+
let c = n(e, `${r}.callback`);
|
|
33
|
+
typeof c == "function" && (_ = c(_, i, a, {
|
|
34
|
+
...s,
|
|
35
|
+
sourceTo: g
|
|
36
|
+
}));
|
|
37
|
+
}), (typeof _ == "boolean" || typeof _ == "number" || _) && (c === "initialState" ? r(a, `definition.${c}.${m}`, _) : r(a, `${c}.${m}`, _));
|
|
44
38
|
});
|
|
45
39
|
});
|
|
46
40
|
});
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { makeId as e } from "../../helpers/utils.mjs";
|
|
2
2
|
import { useEffect as t, useMemo as n } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { createStoreHook as i } from "@plitzi/nexus/react";
|
|
3
|
+
import { createStoreHook as r } from "@plitzi/nexus/react";
|
|
5
4
|
//#region src/dataSource/hooks/useRegisterSource.ts
|
|
6
|
-
var
|
|
7
|
-
let { useStoreSetter:
|
|
8
|
-
t(() =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
var i = ({ id: i = "", source: a, name: o, fields: s = [] }) => {
|
|
6
|
+
let { useStoreSetter: c } = r(), l = c(), u = n(() => `${i}_${e(8)}`, [i]);
|
|
7
|
+
t(() => {
|
|
8
|
+
if (a) return l(`sources.${u}`, {
|
|
9
|
+
id: u,
|
|
10
|
+
meta: {
|
|
11
|
+
id: i,
|
|
12
|
+
source: a,
|
|
13
|
+
name: o,
|
|
14
|
+
fields: s
|
|
15
|
+
}
|
|
16
|
+
}), () => l(`sources.${u}`, void 0, { unmount: !0 });
|
|
17
|
+
}, [u, a]), t(() => {
|
|
18
|
+
a && l(`sources.${u}.meta.fields`, s);
|
|
18
19
|
}, [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
u
|
|
20
|
+
s,
|
|
21
|
+
a,
|
|
22
|
+
u,
|
|
23
|
+
l
|
|
22
24
|
]);
|
|
23
25
|
};
|
|
24
26
|
//#endregion
|
|
25
|
-
export {
|
|
27
|
+
export { i as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import e from "./
|
|
2
|
-
import t
|
|
3
|
-
import r from "./
|
|
4
|
-
|
|
1
|
+
import e from "./helpers/getSourceName.mjs";
|
|
2
|
+
import t from "./hooks/useRegisterSource.mjs";
|
|
3
|
+
import n, { utilityOptions as r } from "./utility/index.mjs";
|
|
4
|
+
import i from "./getBindingsDetails.mjs";
|
|
5
|
+
export { i as getBindingsDetails, e as getSourceName, t as useRegisterSource, n as utility, r as utilityOptions };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { processTwig as e } from "../../helpers/twigWrapper.mjs";
|
|
1
|
+
import { processTwig as e } from "../../helpers/twigWrapper/processTwig/processTwig.mjs";
|
|
2
2
|
var t = {
|
|
3
3
|
action: "twigTemplate",
|
|
4
4
|
title: "Twig Template",
|
|
@@ -12,10 +12,11 @@ var t = {
|
|
|
12
12
|
callback: (t, n, r, i = {}) => {
|
|
13
13
|
let { template: a } = n, o = t;
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
let n = e(a, {
|
|
16
16
|
source: t,
|
|
17
17
|
...i
|
|
18
18
|
});
|
|
19
|
+
(typeof n == "string" || typeof n == "object" && n) && (o = n);
|
|
19
20
|
} catch {
|
|
20
21
|
o = t;
|
|
21
22
|
}
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -2,8 +2,10 @@ import e from "./fetchManifest.mjs";
|
|
|
2
2
|
import t from "./generateFacade.mjs";
|
|
3
3
|
import n from "./syntaxHighlight.mjs";
|
|
4
4
|
import { formatDate as r, formatDateUTC as i, formatFromNow as a, formatUTCToLocal as o, getDurationMs as s, isDate as c, isValidFormat as l, parseDate as u, toUnixSeconds as d } from "./formatDate.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
5
|
+
import { filters as f } from "./twigWrapper/filters/filters.mjs";
|
|
6
|
+
import { processTwig as p } from "./twigWrapper/processTwig/processTwig.mjs";
|
|
7
|
+
import { hasValidToken as m } from "./twigWrapper/tokens/hasValidToken.mjs";
|
|
8
|
+
import { ParamsFromURL as h, delay as g, emptyObject as _, generateID as v, getDisplayName as y, getKeyDecoded as b, getPathsFromObeject as x, hexToRGB as S, isInViewport as C, isTestMode as w, makeId as T } from "./utils.mjs";
|
|
9
|
+
import { disableReactDevTools as E } from "./security.mjs";
|
|
10
|
+
import { createStripTypenameLink as D, stripTypenameDeep as O } from "./stripTypename.mjs";
|
|
11
|
+
export { h as ParamsFromURL, D as createStripTypenameLink, g as delay, E as disableReactDevTools, _ as emptyObject, e as fetchManifest, f as filters, r as formatDate, i as formatDateUTC, a as formatFromNow, o as formatUTCToLocal, t as generateFacade, v as generateID, y as getDisplayName, s as getDurationMs, b as getKeyDecoded, x as getPathsFromObeject, m as hasValidToken, S as hexToRGB, c as isDate, C as isInViewport, w as isTestMode, l as isValidFormat, T as makeId, u as parseDate, p as processTwig, O as stripTypenameDeep, n as syntaxHighlight, d as toUnixSeconds };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export type ASTNode = TextNode | VariableNode | IfNode | ForNode | SetNode | ApplyNode | BreakNode | ContinueNode;
|
|
2
|
+
export type TextNode = {
|
|
3
|
+
readonly type: 'text';
|
|
4
|
+
readonly value: string;
|
|
5
|
+
};
|
|
6
|
+
export type VariableNode = {
|
|
7
|
+
readonly type: 'variable';
|
|
8
|
+
readonly raw: boolean;
|
|
9
|
+
readonly expression: Expression;
|
|
10
|
+
readonly source: string;
|
|
11
|
+
};
|
|
12
|
+
export type IfNode = {
|
|
13
|
+
readonly type: 'if';
|
|
14
|
+
readonly condition: Expression;
|
|
15
|
+
readonly body: ASTNode[];
|
|
16
|
+
readonly elseifClauses: readonly {
|
|
17
|
+
readonly condition: Expression;
|
|
18
|
+
readonly body: ASTNode[];
|
|
19
|
+
}[];
|
|
20
|
+
readonly elseBody: ASTNode[] | null;
|
|
21
|
+
};
|
|
22
|
+
export type ForNode = {
|
|
23
|
+
readonly type: 'for';
|
|
24
|
+
readonly valueVar: string;
|
|
25
|
+
readonly keyVar: string | null;
|
|
26
|
+
readonly collection: Expression;
|
|
27
|
+
readonly body: ASTNode[];
|
|
28
|
+
readonly elseBody: ASTNode[] | null;
|
|
29
|
+
readonly source?: string;
|
|
30
|
+
};
|
|
31
|
+
export type SetNode = {
|
|
32
|
+
readonly type: 'set';
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly value: Expression | ASTNode[];
|
|
35
|
+
};
|
|
36
|
+
export type ApplyNode = {
|
|
37
|
+
readonly type: 'apply';
|
|
38
|
+
readonly filters: FilterCall[];
|
|
39
|
+
readonly body: ASTNode[];
|
|
40
|
+
};
|
|
41
|
+
export type BreakNode = {
|
|
42
|
+
readonly type: 'break';
|
|
43
|
+
};
|
|
44
|
+
export type ContinueNode = {
|
|
45
|
+
readonly type: 'continue';
|
|
46
|
+
};
|
|
47
|
+
export type Expression = LiteralNode | ArrayLiteralNode | ObjectLiteralNode | RangeNode | PathNode | FunctionNode | FilterExpression | ConcatNode | UnaryNode | BinaryNode | DefaultNode | TernaryNode | ArrowFunctionNode;
|
|
48
|
+
export type LiteralNode = {
|
|
49
|
+
readonly type: 'literal';
|
|
50
|
+
readonly value: string | number | boolean;
|
|
51
|
+
};
|
|
52
|
+
export type ArrayLiteralNode = {
|
|
53
|
+
readonly type: 'array';
|
|
54
|
+
readonly elements: readonly Expression[];
|
|
55
|
+
};
|
|
56
|
+
export type ObjectLiteralNode = {
|
|
57
|
+
readonly type: 'object';
|
|
58
|
+
readonly entries: readonly {
|
|
59
|
+
readonly key: Expression;
|
|
60
|
+
readonly value: Expression;
|
|
61
|
+
}[];
|
|
62
|
+
};
|
|
63
|
+
export type RangeNode = {
|
|
64
|
+
readonly type: 'range';
|
|
65
|
+
readonly start: Expression;
|
|
66
|
+
readonly end: Expression;
|
|
67
|
+
};
|
|
68
|
+
export type PathNode = {
|
|
69
|
+
readonly type: 'path';
|
|
70
|
+
readonly segments: readonly string[];
|
|
71
|
+
};
|
|
72
|
+
export type FunctionNode = {
|
|
73
|
+
readonly type: 'function';
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly args: readonly Expression[];
|
|
76
|
+
};
|
|
77
|
+
export type FilterExpression = {
|
|
78
|
+
readonly type: 'filter';
|
|
79
|
+
readonly subject: Expression;
|
|
80
|
+
readonly filters: readonly FilterCall[];
|
|
81
|
+
};
|
|
82
|
+
export type FilterCall = {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly args: readonly Expression[];
|
|
85
|
+
};
|
|
86
|
+
export type ConcatNode = {
|
|
87
|
+
readonly type: 'concat';
|
|
88
|
+
readonly parts: readonly Expression[];
|
|
89
|
+
};
|
|
90
|
+
export type UnaryNode = {
|
|
91
|
+
readonly type: 'unary';
|
|
92
|
+
readonly operator: 'not' | '-';
|
|
93
|
+
readonly operand: Expression;
|
|
94
|
+
};
|
|
95
|
+
export type BinaryNode = {
|
|
96
|
+
readonly type: 'binary';
|
|
97
|
+
readonly operator: string;
|
|
98
|
+
readonly left: Expression;
|
|
99
|
+
readonly right: Expression;
|
|
100
|
+
};
|
|
101
|
+
export type DefaultNode = {
|
|
102
|
+
readonly type: 'default';
|
|
103
|
+
readonly value: Expression;
|
|
104
|
+
readonly defaultExpr: Expression;
|
|
105
|
+
};
|
|
106
|
+
export type TernaryNode = {
|
|
107
|
+
readonly type: 'ternary';
|
|
108
|
+
readonly condition: Expression;
|
|
109
|
+
readonly trueExpr: Expression;
|
|
110
|
+
readonly falseExpr: Expression;
|
|
111
|
+
};
|
|
112
|
+
export type ArrowFunctionNode = {
|
|
113
|
+
readonly type: 'arrow';
|
|
114
|
+
readonly params: readonly string[];
|
|
115
|
+
readonly body: Expression;
|
|
116
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ASTNode } from '../AST';
|
|
2
|
+
export type EvalResult = {
|
|
3
|
+
readonly output: string;
|
|
4
|
+
readonly variables: Record<string, unknown>;
|
|
5
|
+
readonly hasSet: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const evaluate: (nodes: readonly ASTNode[], context: Record<string, unknown>, keepEmptyTokens?: boolean) => EvalResult;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { isTruthy as e, resolveCollection as t, resolveObjectEntries as n, valueIn as r } from "./helpers.mjs";
|
|
2
|
+
import { ARROW_PARAMS as i, filters as a, isRawMarker as o, unwrapRaw as s } from "../filters/filters.mjs";
|
|
3
|
+
//#region src/helpers/twigWrapper/Evaluator/Evaluator.ts
|
|
4
|
+
var c = [], l = (e, t, n = !1) => {
|
|
5
|
+
let r = new u(t, n);
|
|
6
|
+
return {
|
|
7
|
+
output: r.evalNodes(e),
|
|
8
|
+
variables: r.variables,
|
|
9
|
+
hasSet: r.hasSet
|
|
10
|
+
};
|
|
11
|
+
}, u = class l {
|
|
12
|
+
variables;
|
|
13
|
+
keepEmptyTokens;
|
|
14
|
+
breakFlag = !1;
|
|
15
|
+
continueFlag = !1;
|
|
16
|
+
hasSet = !1;
|
|
17
|
+
constructor(e, t = !1) {
|
|
18
|
+
this.variables = { ...e }, this.keepEmptyTokens = t;
|
|
19
|
+
}
|
|
20
|
+
evalNodes(e) {
|
|
21
|
+
let t = e.length;
|
|
22
|
+
if (t === 0) return "";
|
|
23
|
+
if (t === 1) return this.evalNode(e[0]);
|
|
24
|
+
let n = "";
|
|
25
|
+
for (let r = 0; r < t && (n += this.evalNode(e[r]), !(this.breakFlag || this.continueFlag)); r++);
|
|
26
|
+
return n;
|
|
27
|
+
}
|
|
28
|
+
evalNode(e) {
|
|
29
|
+
switch (e.type) {
|
|
30
|
+
case "text": return e.value;
|
|
31
|
+
case "variable": return this.evalVariable(e);
|
|
32
|
+
case "if": return this.evalIf(e);
|
|
33
|
+
case "for": return this.evalFor(e);
|
|
34
|
+
case "set": return this.evalSet(e);
|
|
35
|
+
case "apply": return this.evalApply(e);
|
|
36
|
+
case "break": return this.breakFlag = !0, "";
|
|
37
|
+
case "continue": return this.continueFlag = !0, "";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
evalVariable(e) {
|
|
41
|
+
let t = this.evalExpression(e.expression);
|
|
42
|
+
return this.keepEmptyTokens && (t == null || t === "") ? e.source : o(t) ? String(s(t)) : typeof t == "function" ? "" : t != null && typeof t != "object" ? String(t) : e.raw ? t == null ? "" : String(t) : typeof t == "object" && t ? JSON.stringify(t) : "";
|
|
43
|
+
}
|
|
44
|
+
evalIf(t) {
|
|
45
|
+
if (e(this.evalExpression(t.condition))) return this.evalNodes(t.body);
|
|
46
|
+
for (let n of t.elseifClauses) if (e(this.evalExpression(n.condition))) return this.evalNodes(n.body);
|
|
47
|
+
return t.elseBody ? this.evalNodes(t.elseBody) : "";
|
|
48
|
+
}
|
|
49
|
+
evalFor(e) {
|
|
50
|
+
let r = this.evalExpression(e.collection);
|
|
51
|
+
if (e.source !== void 0 && r === void 0) return e.source;
|
|
52
|
+
let i, a = null;
|
|
53
|
+
if (e.keyVar !== null) {
|
|
54
|
+
let t = n(r);
|
|
55
|
+
if (!t || t.length === 0) return e.elseBody ? this.evalNodes(e.elseBody) : "";
|
|
56
|
+
let o = t.length;
|
|
57
|
+
a = Array(o), i = Array(o);
|
|
58
|
+
for (let e = 0; e < o; e++) a[e] = t[e][0], i[e] = t[e][1];
|
|
59
|
+
} else {
|
|
60
|
+
let n = t(r);
|
|
61
|
+
if (!n || n.length === 0) return e.elseBody ? this.evalNodes(e.elseBody) : "";
|
|
62
|
+
i = n;
|
|
63
|
+
}
|
|
64
|
+
return this.runLoop(e, i, a);
|
|
65
|
+
}
|
|
66
|
+
runLoop(e, t, n) {
|
|
67
|
+
let { valueVar: r, keyVar: i, body: a } = e, o = t.length, s = this.variables.loop, c = {
|
|
68
|
+
index: 0,
|
|
69
|
+
index0: 0,
|
|
70
|
+
first: !1,
|
|
71
|
+
last: !1,
|
|
72
|
+
length: o,
|
|
73
|
+
revindex: 0
|
|
74
|
+
};
|
|
75
|
+
this.variables.loop = c;
|
|
76
|
+
let l = "";
|
|
77
|
+
for (let e = 0; e < o; e++) {
|
|
78
|
+
if (c.index = e + 1, c.index0 = e, c.first = e === 0, c.last = e === o - 1, c.revindex = o - e, n !== null && i !== null && (this.variables[i] = n[e]), this.variables[r] = t[e], l += this.evalNodes(a), this.breakFlag) {
|
|
79
|
+
this.breakFlag = !1;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
this.continueFlag &&= !1;
|
|
83
|
+
}
|
|
84
|
+
return s === void 0 ? delete this.variables.loop : this.variables.loop = s, l;
|
|
85
|
+
}
|
|
86
|
+
evalSet(e) {
|
|
87
|
+
return this.hasSet = !0, this.variables[e.name] = Array.isArray(e.value) ? this.evalNodes(e.value) : this.evalExpression(e.value), "";
|
|
88
|
+
}
|
|
89
|
+
evalApply(e) {
|
|
90
|
+
let t = this.applyFilters(this.evalNodes(e.body), e.filters);
|
|
91
|
+
return o(t) ? String(s(t)) : typeof t == "object" && t ? JSON.stringify(t) : t == null ? "" : String(t);
|
|
92
|
+
}
|
|
93
|
+
applyFilters(e, t) {
|
|
94
|
+
let n = e;
|
|
95
|
+
for (let e of t) {
|
|
96
|
+
let t = a[e.name];
|
|
97
|
+
t !== void 0 && (n = t(n, e.args.length === 0 ? c : this.evalArgs(e.args)));
|
|
98
|
+
}
|
|
99
|
+
return n;
|
|
100
|
+
}
|
|
101
|
+
evalArgs(e) {
|
|
102
|
+
let t = e.length, n = Array(t);
|
|
103
|
+
for (let r = 0; r < t; r++) n[r] = this.evalExpression(e[r]);
|
|
104
|
+
return n;
|
|
105
|
+
}
|
|
106
|
+
evalExpression(t) {
|
|
107
|
+
switch (t.type) {
|
|
108
|
+
case "literal": return t.value;
|
|
109
|
+
case "array": {
|
|
110
|
+
let e = t.elements, n = Array(e.length);
|
|
111
|
+
for (let t = 0; t < e.length; t++) n[t] = this.evalExpression(e[t]);
|
|
112
|
+
return n;
|
|
113
|
+
}
|
|
114
|
+
case "object": {
|
|
115
|
+
let e = {};
|
|
116
|
+
for (let n of t.entries) {
|
|
117
|
+
let t = this.evalExpression(n.key), r = typeof t == "string" ? t : typeof t == "number" || typeof t == "boolean" ? String(t) : "";
|
|
118
|
+
e[r] = this.evalExpression(n.value);
|
|
119
|
+
}
|
|
120
|
+
return e;
|
|
121
|
+
}
|
|
122
|
+
case "range": return this.evalRange(t.start, t.end);
|
|
123
|
+
case "path": return this.resolvePath(t.segments);
|
|
124
|
+
case "function": return this.evalFunction(t.name, t.args);
|
|
125
|
+
case "filter": return this.applyFilters(this.evalExpression(t.subject), t.filters);
|
|
126
|
+
case "concat": {
|
|
127
|
+
let e = t.parts, n = e.length, r = "";
|
|
128
|
+
for (let t = 0; t < n; t++) {
|
|
129
|
+
let n = this.evalExpression(e[t]);
|
|
130
|
+
r += n == null ? "" : String(n);
|
|
131
|
+
}
|
|
132
|
+
return r;
|
|
133
|
+
}
|
|
134
|
+
case "unary": return t.operator === "-" ? -Number(this.evalExpression(t.operand)) : !e(this.evalExpression(t.operand));
|
|
135
|
+
case "binary": return this.evalBinary(t.operator, t.left, t.right);
|
|
136
|
+
case "default": return this.evalExpression(t.value) ?? this.evalExpression(t.defaultExpr);
|
|
137
|
+
case "ternary": return e(this.evalExpression(t.condition)) ? this.evalExpression(t.trueExpr) : this.evalExpression(t.falseExpr);
|
|
138
|
+
case "arrow": return this.createArrowFunction(t.params, t.body);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
createArrowFunction(e, t) {
|
|
142
|
+
let n = { ...this.variables }, r = this.keepEmptyTokens, a = (...i) => {
|
|
143
|
+
let a = new l(n, r);
|
|
144
|
+
for (let t = 0; t < e.length; t++) a.variables[e[t]] = i[t];
|
|
145
|
+
return a.evalExpression(t);
|
|
146
|
+
};
|
|
147
|
+
return a[i] = e.length, a;
|
|
148
|
+
}
|
|
149
|
+
resolvePath(e) {
|
|
150
|
+
let t = e.length;
|
|
151
|
+
if (t === 0) return;
|
|
152
|
+
let n = this.variables[e[0]];
|
|
153
|
+
for (let r = 1; r < t; r++) {
|
|
154
|
+
if (n == null) return;
|
|
155
|
+
n = n[e[r]];
|
|
156
|
+
}
|
|
157
|
+
return n;
|
|
158
|
+
}
|
|
159
|
+
evalRange(e, t) {
|
|
160
|
+
let n = Number(this.evalExpression(e)), r = Number(this.evalExpression(t)), i = n <= r, a = (i ? r - n : n - r) + 1, o = Array(a);
|
|
161
|
+
for (let e = 0; e < a; e++) o[e] = i ? n + e : n - e;
|
|
162
|
+
return o;
|
|
163
|
+
}
|
|
164
|
+
evalFunction(e, t) {
|
|
165
|
+
let n = this.evalArgs(t);
|
|
166
|
+
switch (e) {
|
|
167
|
+
case "cycle": {
|
|
168
|
+
let e = n[0], t = n[1];
|
|
169
|
+
return Array.isArray(e) && typeof t == "number" ? e[t % e.length] : "";
|
|
170
|
+
}
|
|
171
|
+
case "max": return this.minMax(n, Math.max);
|
|
172
|
+
case "min": return this.minMax(n, Math.min);
|
|
173
|
+
case "range": return this.rangeFunction(n);
|
|
174
|
+
default: return "";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
minMax(e, t) {
|
|
178
|
+
return e.length === 0 ? void 0 : t(...e.length === 1 && Array.isArray(e[0]) ? e[0] : e);
|
|
179
|
+
}
|
|
180
|
+
rangeFunction(e) {
|
|
181
|
+
if (e.length === 0) return [];
|
|
182
|
+
if (e.length === 1) {
|
|
183
|
+
let t = Number(e[0]), n = Array(t + 1);
|
|
184
|
+
for (let e = 0; e <= t; e++) n[e] = e;
|
|
185
|
+
return n;
|
|
186
|
+
}
|
|
187
|
+
let t = Number(e[0]), n = Number(e[1]), r = e.length > 2 ? Number(e[2]) : t <= n ? 1 : -1;
|
|
188
|
+
if (r === 0) return [];
|
|
189
|
+
let i = Math.floor((r > 0 ? n - t : t - n) / Math.abs(r)) + 1;
|
|
190
|
+
if (i <= 0) return [];
|
|
191
|
+
let a = Array(i);
|
|
192
|
+
for (let e = 0; e < i; e++) a[e] = t + e * r;
|
|
193
|
+
return a;
|
|
194
|
+
}
|
|
195
|
+
evalBinary(t, n, i) {
|
|
196
|
+
if (t === "or") return e(this.evalExpression(n)) || e(this.evalExpression(i));
|
|
197
|
+
if (t === "and") return e(this.evalExpression(n)) && e(this.evalExpression(i));
|
|
198
|
+
let a = this.evalExpression(n), o = this.evalExpression(i), s = typeof a == "number" && typeof o == "number";
|
|
199
|
+
switch (t) {
|
|
200
|
+
case "+": return s ? a + o : Number(a) + Number(o);
|
|
201
|
+
case "-": return s ? a - o : Number(a) - Number(o);
|
|
202
|
+
case "*": return s ? a * o : Number(a) * Number(o);
|
|
203
|
+
case "/": return s ? a / o : Number(a) / Number(o);
|
|
204
|
+
case "%": return s ? a % o : Number(a) % Number(o);
|
|
205
|
+
case "==": return a === o || String(a) === String(o);
|
|
206
|
+
case "!=": return a !== o && String(a) !== String(o);
|
|
207
|
+
case ">": return s ? a > o : Number(a) > Number(o);
|
|
208
|
+
case "<": return s ? a < o : Number(a) < Number(o);
|
|
209
|
+
case ">=": return s ? a >= o : Number(a) >= Number(o);
|
|
210
|
+
case "<=": return s ? a <= o : Number(a) <= Number(o);
|
|
211
|
+
case "in": return r(a, o);
|
|
212
|
+
case "not in": return !r(a, o);
|
|
213
|
+
case "is": return a === o;
|
|
214
|
+
case "is not": return a !== o;
|
|
215
|
+
default: return !1;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
//#endregion
|
|
220
|
+
export { l as evaluate };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const isTruthy: (value: unknown) => boolean;
|
|
2
|
+
export declare const valueIn: (needle: unknown, haystack: unknown) => boolean;
|
|
3
|
+
export declare const resolveCollection: (value: unknown) => unknown[] | null;
|
|
4
|
+
export declare const resolveObjectEntries: (value: unknown) => [string, unknown][] | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/helpers/twigWrapper/Evaluator/helpers.ts
|
|
2
|
+
var e = (e) => !(e == null || e === !1 || e === "" || e === 0 || Array.isArray(e) && e.length === 0), t = (e, t) => typeof t == "string" ? t.includes(String(e)) : Array.isArray(t) ? t.includes(e) : typeof t == "object" && t ? String(e) in t : !1, n = (e) => Array.isArray(e) ? e : typeof e == "object" && e ? Object.values(e) : null, r = (e) => typeof e == "object" && e && !Array.isArray(e) ? Object.entries(e) : null;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as isTruthy, n as resolveCollection, r as resolveObjectEntries, t as valueIn };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/helpers/twigWrapper/Lexer/Lexer.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t = [], n = 0;
|
|
4
|
+
for (; n < e.length;) {
|
|
5
|
+
let r = e.indexOf("{{", n), i = e.indexOf("{%", n), a, o;
|
|
6
|
+
if (r === -1 && i === -1) break;
|
|
7
|
+
if (r === -1 ? (a = i, o = !0) : i === -1 || r < i ? (a = r, o = !1) : (a = i, o = !0), a > n && t.push({
|
|
8
|
+
type: "text",
|
|
9
|
+
value: e.slice(n, a)
|
|
10
|
+
}), !o && e.charCodeAt(a + 2) === 123) {
|
|
11
|
+
let r = e.indexOf("}}}", a + 3);
|
|
12
|
+
if (r === -1) return {
|
|
13
|
+
tokens: t,
|
|
14
|
+
error: "Unclosed triple-brace token"
|
|
15
|
+
};
|
|
16
|
+
t.push({
|
|
17
|
+
type: "variable",
|
|
18
|
+
content: e.slice(a + 3, r),
|
|
19
|
+
raw: !0
|
|
20
|
+
}), n = r + 3;
|
|
21
|
+
} else if (o) {
|
|
22
|
+
let r = e.indexOf("%}", a + 2);
|
|
23
|
+
if (r === -1) return {
|
|
24
|
+
tokens: t,
|
|
25
|
+
error: "Unclosed tag"
|
|
26
|
+
};
|
|
27
|
+
t.push({
|
|
28
|
+
type: "tag",
|
|
29
|
+
content: e.slice(a + 2, r)
|
|
30
|
+
}), n = r + 2;
|
|
31
|
+
} else {
|
|
32
|
+
let r = e.indexOf("}}", a + 2);
|
|
33
|
+
if (r === -1) return {
|
|
34
|
+
tokens: t,
|
|
35
|
+
error: "Unclosed double-brace token"
|
|
36
|
+
};
|
|
37
|
+
t.push({
|
|
38
|
+
type: "variable",
|
|
39
|
+
content: e.slice(a + 2, r),
|
|
40
|
+
raw: !1
|
|
41
|
+
}), n = r + 2;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return n < e.length && t.push({
|
|
45
|
+
type: "text",
|
|
46
|
+
value: e.slice(n)
|
|
47
|
+
}), {
|
|
48
|
+
tokens: t,
|
|
49
|
+
error: null
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { e as lex };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Token = {
|
|
2
|
+
readonly type: 'text';
|
|
3
|
+
readonly value: string;
|
|
4
|
+
} | {
|
|
5
|
+
readonly type: 'variable';
|
|
6
|
+
readonly content: string;
|
|
7
|
+
readonly raw: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: 'tag';
|
|
10
|
+
readonly content: string;
|
|
11
|
+
};
|
|
12
|
+
export type LexResult = {
|
|
13
|
+
tokens: Token[];
|
|
14
|
+
error: string | null;
|
|
15
|
+
};
|
|
16
|
+
export declare const reconstructSource: (content: string, raw: boolean) => string;
|
|
17
|
+
export declare const reconstructToken: (token: Token) => string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/helpers/twigWrapper/Lexer/types.ts
|
|
2
|
+
var e = (e, t) => t ? `{{{${e}}}}` : `{{${e}}}`, t = (t) => {
|
|
3
|
+
switch (t.type) {
|
|
4
|
+
case "text": return t.value;
|
|
5
|
+
case "variable": return e(t.content, t.raw);
|
|
6
|
+
case "tag": return `{%${t.content}%}`;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { e as reconstructSource, t as reconstructToken };
|