@plitzi/sdk-schema 0.30.19

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.
@@ -0,0 +1,90 @@
1
+ import { Element, PageFolder, Schema, SchemaVariable, DropPosition, Style } from '@plitzi/sdk-shared';
2
+ export declare const SchemaActions: {
3
+ readonly SCHEMA_UPDATE: "SCHEMA_UPDATE";
4
+ readonly SCHEMA_ADD_PAGE: "SCHEMA_ADD_PAGE";
5
+ readonly SCHEMA_HOME_PAGE: "SCHEMA_HOME_PAGE";
6
+ readonly SCHEMA_UPDATE_PAGE: "SCHEMA_UPDATE_PAGE";
7
+ readonly SCHEMA_REMOVE_PAGE: "SCHEMA_REMOVE_PAGE";
8
+ readonly SCHEMA_ADD_PAGE_FOLDER: "SCHEMA_ADD_PAGE_FOLDER";
9
+ readonly SCHEMA_UPDATE_PAGE_FOLDER: "SCHEMA_UPDATE_PAGE_FOLDER";
10
+ readonly SCHEMA_REMOVE_PAGE_FOLDER: "SCHEMA_REMOVE_PAGE_FOLDER";
11
+ readonly SCHEMA_ADD_VARIABLE: "SCHEMA_ADD_VARIABLE";
12
+ readonly SCHEMA_UPDATE_VARIABLE: "SCHEMA_UPDATE_VARIABLE";
13
+ readonly SCHEMA_REMOVE_VARIABLE: "SCHEMA_REMOVE_VARIABLE";
14
+ readonly SCHEMA_ADD_ELEMENT: "SCHEMA_ADD_ELEMENT";
15
+ readonly SCHEMA_REMOVE_ELEMENT: "SCHEMA_REMOVE_ELEMENT";
16
+ readonly SCHEMA_MOVE_ELEMENT: "SCHEMA_MOVE_ELEMENT";
17
+ readonly SCHEMA_CLONE_ELEMENT: "SCHEMA_CLONE_ELEMENT";
18
+ readonly SCHEMA_UPDATE_ELEMENT: "SCHEMA_UPDATE_ELEMENT";
19
+ readonly SCHEMA_ADD_TEMPLATE: "SCHEMA_ADD_TEMPLATE";
20
+ readonly SCHEMA_UPDATE_SETTINGS: "SCHEMA_UPDATE_SETTINGS";
21
+ };
22
+ export type SchemaReducerActionsBase = {
23
+ fromSubscriptions?: boolean;
24
+ };
25
+ export type SchemaReducerActions = SchemaReducerActionsBase & ({
26
+ type: 'SCHEMA_UPDATE';
27
+ schema: Schema;
28
+ } | {
29
+ type: 'SCHEMA_ADD_PAGE';
30
+ page: Element;
31
+ } | {
32
+ type: 'SCHEMA_HOME_PAGE';
33
+ pageId: string;
34
+ } | {
35
+ type: 'SCHEMA_UPDATE_PAGE';
36
+ page: Element;
37
+ } | {
38
+ type: 'SCHEMA_REMOVE_PAGE';
39
+ pageId: string;
40
+ } | {
41
+ type: 'SCHEMA_ADD_PAGE_FOLDER';
42
+ pageFolder: PageFolder;
43
+ } | {
44
+ type: 'SCHEMA_UPDATE_PAGE_FOLDER';
45
+ pageFolder: PageFolder;
46
+ } | {
47
+ type: 'SCHEMA_REMOVE_PAGE_FOLDER';
48
+ pageFolderId: string;
49
+ } | {
50
+ type: 'SCHEMA_ADD_VARIABLE';
51
+ variable: SchemaVariable;
52
+ } | {
53
+ type: 'SCHEMA_UPDATE_VARIABLE';
54
+ variable: SchemaVariable;
55
+ } | {
56
+ type: 'SCHEMA_REMOVE_VARIABLE';
57
+ name: string;
58
+ } | {
59
+ type: 'SCHEMA_ADD_ELEMENT' | 'SCHEMA_ADD_TEMPLATE';
60
+ to: string;
61
+ data: Element;
62
+ dropPosition: DropPosition;
63
+ initialItems: Record<string, Element>;
64
+ variables?: SchemaVariable[];
65
+ style?: Style;
66
+ } | {
67
+ type: 'SCHEMA_REMOVE_ELEMENT';
68
+ elementId: string;
69
+ } | {
70
+ type: 'SCHEMA_MOVE_ELEMENT';
71
+ elementId: string;
72
+ from: string;
73
+ to: string;
74
+ dropPosition: DropPosition;
75
+ } | {
76
+ type: 'SCHEMA_CLONE_ELEMENT';
77
+ to: string;
78
+ data: Element;
79
+ dropPosition: DropPosition;
80
+ initialItems: Record<string, Element>;
81
+ } | {
82
+ type: 'SCHEMA_UPDATE_ELEMENT';
83
+ element: Element;
84
+ } | {
85
+ type: 'SCHEMA_UPDATE_SETTINGS';
86
+ path: string;
87
+ value: string | number | boolean;
88
+ });
89
+ declare const SchemaReducer: (state: Schema, action: SchemaReducerActions) => Schema;
90
+ export default SchemaReducer;
@@ -0,0 +1,145 @@
1
+ import e from "./helpers/FlatMap.mjs";
2
+ import { get as t, has as n, set as r } from "@plitzi/plitzi-ui/helpers";
3
+ import { produce as i } from "immer";
4
+ //#region src/SchemaReducer.ts
5
+ var a = {
6
+ SCHEMA_UPDATE: "SCHEMA_UPDATE",
7
+ SCHEMA_ADD_PAGE: "SCHEMA_ADD_PAGE",
8
+ SCHEMA_HOME_PAGE: "SCHEMA_HOME_PAGE",
9
+ SCHEMA_UPDATE_PAGE: "SCHEMA_UPDATE_PAGE",
10
+ SCHEMA_REMOVE_PAGE: "SCHEMA_REMOVE_PAGE",
11
+ SCHEMA_ADD_PAGE_FOLDER: "SCHEMA_ADD_PAGE_FOLDER",
12
+ SCHEMA_UPDATE_PAGE_FOLDER: "SCHEMA_UPDATE_PAGE_FOLDER",
13
+ SCHEMA_REMOVE_PAGE_FOLDER: "SCHEMA_REMOVE_PAGE_FOLDER",
14
+ SCHEMA_ADD_VARIABLE: "SCHEMA_ADD_VARIABLE",
15
+ SCHEMA_UPDATE_VARIABLE: "SCHEMA_UPDATE_VARIABLE",
16
+ SCHEMA_REMOVE_VARIABLE: "SCHEMA_REMOVE_VARIABLE",
17
+ SCHEMA_ADD_ELEMENT: "SCHEMA_ADD_ELEMENT",
18
+ SCHEMA_REMOVE_ELEMENT: "SCHEMA_REMOVE_ELEMENT",
19
+ SCHEMA_MOVE_ELEMENT: "SCHEMA_MOVE_ELEMENT",
20
+ SCHEMA_CLONE_ELEMENT: "SCHEMA_CLONE_ELEMENT",
21
+ SCHEMA_UPDATE_ELEMENT: "SCHEMA_UPDATE_ELEMENT",
22
+ SCHEMA_ADD_TEMPLATE: "SCHEMA_ADD_TEMPLATE",
23
+ SCHEMA_UPDATE_SETTINGS: "SCHEMA_UPDATE_SETTINGS"
24
+ }, o = (o, s) => {
25
+ switch (s.type) {
26
+ case a.SCHEMA_UPDATE: return {
27
+ ...o,
28
+ ...s.schema
29
+ };
30
+ case a.SCHEMA_ADD_PAGE: {
31
+ let { page: e } = s;
32
+ return i(o, (t) => {
33
+ r(t, "flat", {
34
+ ...t.flat,
35
+ [e.id]: e
36
+ }), t.pages.push(e.id);
37
+ });
38
+ }
39
+ case a.SCHEMA_HOME_PAGE: {
40
+ let { flat: e, pages: n } = o, { pageId: a } = s, c;
41
+ return n.forEach((n) => {
42
+ if (c) return;
43
+ let r = e[n];
44
+ t(r, "attributes.default", !1) && (c = r);
45
+ }), c ? i(o, (e) => {
46
+ r(e.flat, `${a}.attributes.default`, !0), r(e.flat, `${c.id}.attributes.default`, !1);
47
+ }) : i(o, (e) => {
48
+ r(e.flat, `${a}.attributes.default`, !0);
49
+ });
50
+ }
51
+ case a.SCHEMA_UPDATE_PAGE: {
52
+ let { page: e } = s;
53
+ return i(o, (t) => {
54
+ r(t.flat, e.id, e);
55
+ });
56
+ }
57
+ case a.SCHEMA_REMOVE_PAGE: {
58
+ let { pageId: t } = s;
59
+ return i(o, (n) => {
60
+ e.removeElement(n.flat, t, !0), n.pages = n.pages.filter((e) => e !== t);
61
+ });
62
+ }
63
+ case a.SCHEMA_ADD_PAGE_FOLDER: {
64
+ let { pageFolder: e } = s;
65
+ return i(o, (t) => {
66
+ t.pageFolders.push(e);
67
+ });
68
+ }
69
+ case a.SCHEMA_UPDATE_PAGE_FOLDER: {
70
+ let { pageFolder: e } = s;
71
+ return i(o, (t) => {
72
+ let n = t.pageFolders.findIndex((t) => t.id === e.id);
73
+ n !== -1 && (t.pageFolders[n] = e);
74
+ });
75
+ }
76
+ case a.SCHEMA_REMOVE_PAGE_FOLDER: {
77
+ let { pageFolderId: e } = s;
78
+ return i(o, (t) => {
79
+ t.pageFolders = t.pageFolders.filter((t) => t.id !== e);
80
+ });
81
+ }
82
+ case a.SCHEMA_ADD_VARIABLE: {
83
+ let { variable: e } = s;
84
+ return i(o, (t) => {
85
+ t.variables ||= [], t.variables.push(e);
86
+ });
87
+ }
88
+ case a.SCHEMA_UPDATE_VARIABLE: {
89
+ let { variable: e } = s;
90
+ return o.variables ? i(o, (t) => {
91
+ let n = t.variables.findIndex((t) => t.name === e.name);
92
+ t.variables[n] && (t.variables[n] = e);
93
+ }) : o;
94
+ }
95
+ case a.SCHEMA_REMOVE_VARIABLE: {
96
+ let { name: e } = s;
97
+ return o.variables ? i(o, (t) => {
98
+ t.variables = t.variables.filter((t) => t.name !== e);
99
+ }) : o;
100
+ }
101
+ case a.SCHEMA_ADD_TEMPLATE:
102
+ case a.SCHEMA_ADD_ELEMENT: {
103
+ let { to: t, data: n, dropPosition: a, initialItems: c, variables: l = [] } = s;
104
+ return i(o, (i) => {
105
+ if (e.addElement(i.flat, n, t, a, c), l.length > 0) {
106
+ let e = l.filter((e) => i.variables && !i.variables.find((t) => t.name === e.name));
107
+ r(i, "variables", [...i.variables ?? [], ...e]);
108
+ }
109
+ });
110
+ }
111
+ case a.SCHEMA_REMOVE_ELEMENT: {
112
+ let { elementId: t } = s;
113
+ return i(o, (n) => {
114
+ e.removeElement(n.flat, t);
115
+ });
116
+ }
117
+ case a.SCHEMA_MOVE_ELEMENT: {
118
+ let { from: t, to: n, elementId: r, dropPosition: a } = s;
119
+ return i(o, (i) => {
120
+ e.moveElement(i.flat, t, n, r, a);
121
+ });
122
+ }
123
+ case a.SCHEMA_CLONE_ELEMENT: {
124
+ let { to: t, data: n, dropPosition: r, initialItems: a } = s;
125
+ return i(o, (i) => {
126
+ e.addElement(i.flat, n, t, r, a);
127
+ });
128
+ }
129
+ case a.SCHEMA_UPDATE_ELEMENT: {
130
+ let { element: e } = s;
131
+ return i(o, (t) => {
132
+ r(t.flat, e.id, e);
133
+ });
134
+ }
135
+ case a.SCHEMA_UPDATE_SETTINGS: {
136
+ let { path: e, value: t } = s;
137
+ return i(o, (i) => {
138
+ e && n(o.settings, e) ? r(i.settings, e, t) : e || r(i, "settings", t);
139
+ });
140
+ }
141
+ default: return o;
142
+ }
143
+ };
144
+ //#endregion
145
+ export { a as SchemaActions, o as default };
@@ -0,0 +1,70 @@
1
+ import { Style, Element, Schema, DropPosition, SchemaVariable } from '@plitzi/sdk-shared';
2
+ export type FlatMapProps = {
3
+ flat?: Schema['flat'];
4
+ variables?: Schema['variables'];
5
+ };
6
+ declare class FlatMap {
7
+ flat: Schema['flat'];
8
+ variables: Schema['variables'];
9
+ constructor(props?: FlatMapProps);
10
+ addElement: (data: Element, to: Element["id"], dropPosition?: DropPosition, initialItems?: Record<Element["id"], Element>) => boolean;
11
+ updateElement: (element?: Element) => boolean;
12
+ moveElement: (from: Element["id"], to: Element["id"], elementId: Element["id"], dropPosition?: DropPosition) => boolean;
13
+ getElement: (elementId: Element["id"]) => Element<Omit<{
14
+ [key: string]: unknown;
15
+ }, "subType">>;
16
+ cloneElements: (elementId: Element["id"], parentId?: Element["id"], rootId?: Element["id"], excludeRoot?: boolean) => {
17
+ acum: Record<Element["id"], Element>;
18
+ item?: Element;
19
+ };
20
+ removeElement: (elementId: Element["id"], removePage?: boolean) => boolean;
21
+ addVariables: (variables: Schema["variables"]) => boolean;
22
+ addVariable: (variable: SchemaVariable) => boolean;
23
+ updateVariable: (variable: SchemaVariable) => boolean;
24
+ removeVariables: (variables: string[]) => boolean;
25
+ removeVariable: (variable: string) => boolean;
26
+ parentTree: (elementId: Element["id"]) => string[];
27
+ childTree: (elementId: Element["id"]) => string[];
28
+ isValidElement: (element?: Partial<Element>) => boolean;
29
+ flatAsTemplate: (style: Style, elementId: Element["id"], excludeRoot?: boolean) => {
30
+ elements: {
31
+ acum: Record<Element["id"], Element>;
32
+ item?: Element;
33
+ };
34
+ elementsStyle: Style;
35
+ variables: SchemaVariable[];
36
+ };
37
+ getElementVariables: (style: Style, elementId: Element["id"], flat?: Record<string, Element<Omit<{
38
+ [key: string]: unknown;
39
+ }, "subType">>>, variables?: SchemaVariable[]) => SchemaVariable[];
40
+ static getInstance: (props: FlatMapProps) => FlatMap;
41
+ static addElement: (flat: Schema["flat"], data: Element, to: Element["id"], dropPosition?: DropPosition, initialItems?: Record<Element["id"], Element>) => boolean;
42
+ static updateElement: (flat: Schema["flat"], element: Element) => boolean;
43
+ static moveElement: (flat: Schema["flat"], from: Element["id"], to: Element["id"], elementId: Element["id"], dropPosition?: DropPosition) => boolean;
44
+ static getElement: (flat: Schema["flat"], elementId: Element["id"]) => Element<Omit<{
45
+ [key: string]: unknown;
46
+ }, "subType">>;
47
+ static cloneElements: (flat: Schema["flat"], elementId: Element["id"], parentId?: Element["id"], rootId?: Element["id"], excludeRoot?: boolean) => {
48
+ acum: Record<Element["id"], Element>;
49
+ item?: Element;
50
+ };
51
+ static removeElement: (flat: Schema["flat"], elementId: Element["id"], removePage?: boolean) => boolean;
52
+ static addVariables: (schemaVariables: Schema["variables"], variables: Schema["variables"]) => boolean;
53
+ static addVariable: (schemaVariables: Schema["variables"], variable: SchemaVariable) => boolean;
54
+ static updateVariable: (schemaVariables: Schema["variables"], variable: SchemaVariable) => boolean;
55
+ static removeVariables: (schemaVariables: Schema["variables"], variables: string[]) => boolean;
56
+ static removeVariable: (schemaVariables: Schema["variables"], variable: string) => boolean;
57
+ static parentTree: (flat: Schema["flat"], elementId: Element["id"]) => string[];
58
+ static childTree: (flat: Schema["flat"], elementId: Element["id"]) => string[];
59
+ static isValidElement: (flat: Schema["flat"], element: Element) => boolean;
60
+ static flatAsTemplate: (schema: Schema, style: Style, elementId: Element["id"], excludeRoot?: boolean) => {
61
+ elements: {
62
+ acum: Record<Element["id"], Element>;
63
+ item?: Element;
64
+ };
65
+ elementsStyle: Style;
66
+ variables: SchemaVariable[];
67
+ };
68
+ static getElementVariables: (schema: Schema, style: Style, elementId: Element["id"]) => SchemaVariable[];
69
+ }
70
+ export default FlatMap;
@@ -0,0 +1,267 @@
1
+ import { get as e, set as t } from "@plitzi/plitzi-ui/helpers";
2
+ import { generateID as n } from "@plitzi/sdk-shared/helpers/utils";
3
+ import { VARIABLE_REGEX as r } from "@plitzi/sdk-shared/schema/schemaConstants";
4
+ import { EMPTY_STYLE_SCHEMA as i } from "@plitzi/sdk-shared/style/styleConstants";
5
+ import a from "@plitzi/sdk-style/helpers/calculateInheriting";
6
+ //#region src/helpers/FlatMap.ts
7
+ var o = class {
8
+ flat;
9
+ variables;
10
+ constructor(e = {}) {
11
+ let { flat: t, variables: n } = e;
12
+ if (!t) throw Error("Flat is required");
13
+ this.flat = t, this.variables = n ?? [];
14
+ }
15
+ addElement = (n, r, i = "inside", a = {}) => {
16
+ let o;
17
+ if (i !== "custom") {
18
+ if (i !== "inside") {
19
+ let e = this.flat[r];
20
+ if (!e) return !1;
21
+ e.definition.parentId && (o = this.flat[e.definition.parentId]);
22
+ } else o = this.flat[r];
23
+ if (!o) return !1;
24
+ }
25
+ if (i !== "custom" && (this.flat[n.id] || !Array.isArray(e(o, "definition.items"))) || !this.isValidElement(n)) return !1;
26
+ switch (t(this.flat, n.id, n), i) {
27
+ case "left":
28
+ case "top": {
29
+ let i = e(o, "definition.items", []);
30
+ if (i.splice(i.findIndex((e) => e === r), 0, n.id), !o) return !1;
31
+ t(this.flat, `${o.id}.definition.items`, i), t(this.flat, `${n.id}.definition.parentId`, o.id), t(this.flat, `${n.id}.definition.rootId`, o.definition.rootId);
32
+ break;
33
+ }
34
+ case "right":
35
+ case "bottom": {
36
+ let i = e(o, "definition.items", []);
37
+ if (i.splice(i.findIndex((e) => e === r) + 1, 0, n.id), !o) return !1;
38
+ t(this.flat, `${o.id}.definition.items`, i), t(this.flat, `${n.id}.definition.parentId`, o.id), t(this.flat, `${n.id}.definition.rootId`, o.definition.rootId);
39
+ break;
40
+ }
41
+ case "inside": {
42
+ let i = e(o, "definition.items", []);
43
+ if (!o) return !1;
44
+ t(this.flat, `${r}.definition.items`, [...i, n.id]), t(this.flat, `${n.id}.definition.parentId`, r), t(this.flat, `${n.id}.definition.rootId`, o.definition.rootId);
45
+ break;
46
+ }
47
+ case "custom": break;
48
+ default: return !1;
49
+ }
50
+ return Object.keys(a).length > 0 && Object.keys(a).forEach((e) => {
51
+ this.flat[e] = a[e];
52
+ }), !0;
53
+ };
54
+ updateElement = (e) => !e || !this.flat[e.id] ? !1 : (this.flat[e.id] = e, !0);
55
+ moveElement = (n, r, i, a = "inside") => {
56
+ if (i === r || !this.flat[n]) return !1;
57
+ let o = this.flat[r];
58
+ if (!o) return !1;
59
+ let s = this.flat[r];
60
+ for (; s;) {
61
+ let t = e(s, "definition.parentId");
62
+ if (!t) break;
63
+ if (s.id === i) return !1;
64
+ s = this.flat[t];
65
+ }
66
+ if (!s) return !1;
67
+ let c = e(this.flat, `${n}.definition.items`, []).filter((e) => e !== i);
68
+ if ([
69
+ "left",
70
+ "top",
71
+ "right",
72
+ "bottom"
73
+ ].includes(a)) {
74
+ if (!o.definition.parentId) return !1;
75
+ let s = this.flat[o.definition.parentId];
76
+ if (!s) return !1;
77
+ let l = e(s, "definition.items", []);
78
+ s.id === n && (l = c);
79
+ let u = l.findIndex((e) => e === r);
80
+ ["right", "bottom"].includes(a) && u++, l.splice(u, 0, i), t(this.flat, `${n}.definition.items`, c), t(this.flat, `${s.id}.definition.items`, l), t(this.flat, `${i}.definition.parentId`, s.id);
81
+ } else if (a === "inside") {
82
+ if (!this.flat[r]) return !1;
83
+ let a = e(this.flat, `${r}.definition.items`, []);
84
+ n === r && (a = c), a = [...a, i], t(this.flat, `${n}.definition.items`, c), t(this.flat, `${r}.definition.items`, a), t(this.flat, `${i}.definition.parentId`, r);
85
+ }
86
+ return !0;
87
+ };
88
+ getElement = (t) => e(this.flat, t);
89
+ cloneElements = (r, i = "", a = "", o = !1) => {
90
+ let s = {
91
+ acum: {},
92
+ item: void 0
93
+ }, c = {}, l = this.flat[r];
94
+ if (!l) return s;
95
+ let u = [r, ...this.childTree(r)].reduce((e, t) => {
96
+ let r = this.flat[t];
97
+ return r ? (c[r.id] = n(r.id), a ? {
98
+ ...e,
99
+ [r.id]: {
100
+ ...r,
101
+ definition: {
102
+ ...r.definition,
103
+ rootId: a
104
+ }
105
+ }
106
+ } : {
107
+ ...e,
108
+ [r.id]: r
109
+ }) : e;
110
+ }, {});
111
+ try {
112
+ let e = JSON.stringify(u);
113
+ e = Object.keys(c).reduce((e, t) => e.replace(new RegExp(t, "g"), c[t]), e), s.acum = JSON.parse(e), s.item = s.acum[c[r]];
114
+ } catch (e) {
115
+ return console.error("Error parsing elements", e), {
116
+ acum: {},
117
+ item: void 0
118
+ };
119
+ }
120
+ o && delete s.acum[c[r]];
121
+ let d = this.flat[i];
122
+ return (!d || !Array.isArray(e(d, "definition.items"))) && (i = e(d, "definition.parentId", e(l, "definition.parentId"))), i && t(s, "item.definition.parentId", i), s;
123
+ };
124
+ removeElement = (n, r = !1) => {
125
+ let i = this.flat[n];
126
+ if (!i || i.definition.type === "page" && !r || r && e(i, "attributes.default", !1)) return !1;
127
+ let a = e(i, "definition.items");
128
+ a && a.length > 0 && a.forEach((e) => this.removeElement(e));
129
+ let o = e(i, "definition.parentId"), s = o ? this.flat[o] : void 0;
130
+ if (o && s) {
131
+ let { definition: { items: e = [] } } = s;
132
+ t(s, "definition.items", e.filter((e) => e !== n)), this.flat[o] = s;
133
+ }
134
+ return delete this.flat[n], !0;
135
+ };
136
+ addVariables = (e) => {
137
+ if (e && e.length > 0) {
138
+ let t = e.filter((e) => !this.variables.find((t) => t.name === e.name));
139
+ return this.variables.push(...t), t.length > 0;
140
+ }
141
+ return !1;
142
+ };
143
+ addVariable = (e) => e ? this.addVariables([e]) : !1;
144
+ updateVariable = (e) => {
145
+ if (!e) return !1;
146
+ let t = this.variables.findIndex((e) => e.name === e.name);
147
+ return t === -1 ? !1 : (this.variables[t] = e, !0);
148
+ };
149
+ removeVariables = (e) => {
150
+ e = e.filter(Boolean);
151
+ let t = this.variables.length;
152
+ return this.variables = this.variables.filter((t) => e.includes(t.name)), t !== this.variables.length;
153
+ };
154
+ removeVariable = (e) => this.removeVariables([e]);
155
+ parentTree = (t) => {
156
+ let n = this.flat[t], r = [];
157
+ if (!n) return r;
158
+ do {
159
+ if (e(n, "definition.type") === "page") {
160
+ let t = e(n, "attributes.layout"), i = e(n, "attributes.layoutContainer");
161
+ t && i && r.push(i, ...this.parentTree(i));
162
+ }
163
+ t !== n.id && r.push(n.id), n = e(this.flat, e(n, "definition.parentId"), void 0);
164
+ } while (n);
165
+ return r;
166
+ };
167
+ childTree = (t) => {
168
+ let n = this.flat[t];
169
+ if (!n) return [];
170
+ let r = [], i = e(n, "definition.items");
171
+ return i && i.forEach((e) => r.push(e, ...this.childTree(e))), r;
172
+ };
173
+ isValidElement = (e) => {
174
+ if (!e) return !1;
175
+ let { id: t, attributes: n, definition: r } = e;
176
+ if (!t || !r || !n) return !1;
177
+ let { type: i, label: a, styleSelectors: o, rootId: s } = r;
178
+ return !(!i || a === void 0 || typeof o != "object" || s === void 0);
179
+ };
180
+ flatAsTemplate = (n, r, o = !1) => {
181
+ let s = i, c = [];
182
+ if (!r) return {
183
+ elements: {
184
+ acum: {},
185
+ item: void 0
186
+ },
187
+ elementsStyle: s,
188
+ variables: c
189
+ };
190
+ let l = e(this.flat, r);
191
+ if (!l) return {
192
+ elements: {
193
+ acum: {},
194
+ item: void 0
195
+ },
196
+ elementsStyle: s,
197
+ variables: c
198
+ };
199
+ let u = this.cloneElements(r, l.definition.parentId);
200
+ return u.item ? (Object.values(u.acum).forEach((e) => {
201
+ let { id: r } = e;
202
+ if (t(u.acum, `${r}.definition.rootId`, u.item?.id), a(e, void 0, this.flat, n.platform, {}, { includeSelf: !0 }).tree.forEach((e) => {
203
+ let { displayMode: t, name: r } = e;
204
+ !(r in s.platform[t]) && r in n.platform[t] && (s.platform[t][r] = n.platform[t][r]);
205
+ }), this.variables.length > 0) {
206
+ let e = this.getElementVariables(n, r, u.acum);
207
+ c = [...c, ...e];
208
+ }
209
+ }), t(u.acum, `${u.item.id}.definition.parentId`, null), o && delete u.acum[u.item.id], c.length > 1 && (c = [...new Set(c)]), {
210
+ elements: u,
211
+ elementsStyle: s,
212
+ variables: c
213
+ }) : {
214
+ elements: {
215
+ acum: {},
216
+ item: void 0
217
+ },
218
+ elementsStyle: s,
219
+ variables: c
220
+ };
221
+ };
222
+ getElementVariables = (t, n, i = this.flat, a = this.variables) => {
223
+ let o = [], s = e(i, `${n}.definition.styleSelectors`);
224
+ if (!s) return o;
225
+ let c = new RegExp(r, "g");
226
+ return Object.values(s).filter(Boolean).forEach((e) => {
227
+ Object.values(t.platform).forEach((t) => {
228
+ let n = t[e];
229
+ n && [...JSON.stringify(n.attributes).matchAll(c)].forEach((e) => {
230
+ let t = a.find((t) => t.name === e[1] || t.name === e[2]);
231
+ t && !o.find((e) => e.name === t.name) && o.push(t);
232
+ });
233
+ });
234
+ }), o;
235
+ };
236
+ static getInstance = (e) => new this(e);
237
+ static addElement = (e, t, n, r = "inside", i = {}) => this.getInstance({ flat: e }).addElement(t, n, r, i);
238
+ static updateElement = (e, t) => this.getInstance({ flat: e }).updateElement(t);
239
+ static moveElement = (e, t, n, r, i = "inside") => this.getInstance({ flat: e }).moveElement(t, n, r, i);
240
+ static getElement = (e, t) => this.getInstance({ flat: e }).getElement(t);
241
+ static cloneElements = (e, t, n = "", r = "", i = !1) => this.getInstance({ flat: e }).cloneElements(t, n, r, i);
242
+ static removeElement = (e, t, n = !1) => this.getInstance({ flat: e }).removeElement(t, n);
243
+ static addVariables = (e, t) => this.getInstance({ variables: e }).addVariables(t);
244
+ static addVariable = (e, t) => this.getInstance({ variables: e }).addVariable(t);
245
+ static updateVariable = (e, t) => this.getInstance({ variables: e }).updateVariable(t);
246
+ static removeVariables = (e, t) => this.getInstance({ variables: e }).removeVariables(t);
247
+ static removeVariable = (e, t) => this.getInstance({ variables: e }).removeVariable(t);
248
+ static parentTree = (e, t) => this.getInstance({ flat: e }).parentTree(t);
249
+ static childTree = (e, t) => this.getInstance({ flat: e }).childTree(t);
250
+ static isValidElement = (e, t) => this.getInstance({ flat: e }).isValidElement(t);
251
+ static flatAsTemplate = (e, t, n, r = !1) => {
252
+ let { flat: i, variables: a } = e;
253
+ return this.getInstance({
254
+ flat: i,
255
+ variables: a
256
+ }).flatAsTemplate(t, n, r);
257
+ };
258
+ static getElementVariables = (e, t, n) => {
259
+ let { flat: r, variables: i } = e;
260
+ return this.getInstance({
261
+ flat: r,
262
+ variables: i
263
+ }).getElementVariables(t, n);
264
+ };
265
+ };
266
+ //#endregion
267
+ export { o as default };
@@ -0,0 +1,5 @@
1
+ import { default as FlatMap } from './helpers/FlatMap';
2
+ import { default as SchemaReducer } from './SchemaReducer';
3
+ export * from './SchemaReducer';
4
+ export * from './helpers/FlatMap';
5
+ export { FlatMap, SchemaReducer };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import e from "./helpers/FlatMap.mjs";
2
+ import t, { SchemaActions as n } from "./SchemaReducer.mjs";
3
+ export { e as FlatMap, n as SchemaActions, t as SchemaReducer };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@plitzi/sdk-schema",
3
+ "version": "0.30.19",
4
+ "license": "AGPL-3.0",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs"
12
+ },
13
+ "./SchemaReducer": {
14
+ "types": "./dist/SchemaReducer.d.ts",
15
+ "import": "./dist/SchemaReducer.mjs"
16
+ },
17
+ "./helpers/FlatMap": {
18
+ "types": "./dist/helpers/FlatMap.d.ts",
19
+ "import": "./dist/helpers/FlatMap.mjs"
20
+ },
21
+ "./index": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.mjs"
24
+ }
25
+ },
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "scripts": {
29
+ "lint": "eslint ./src",
30
+ "typecheck": "tsc -p tsconfig.app.json --noEmit",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest",
33
+ "test:ui": "vitest --ui",
34
+ "build:dev": "vite build --mode development --minify false && node ../sdk-shared/scripts/generate-exports.mjs",
35
+ "build:dev-watch": "vite build --mode development --watch --minify false",
36
+ "build:prod": "vite build && node ../sdk-shared/scripts/generate-exports.mjs"
37
+ },
38
+ "dependencies": {
39
+ "@plitzi/plitzi-ui": "^1.6.2",
40
+ "@plitzi/sdk-shared": "0.30.19",
41
+ "@plitzi/sdk-style": "0.30.19",
42
+ "prop-types": "^15.8.1"
43
+ },
44
+ "devDependencies": {
45
+ "eslint": "^9.39.4",
46
+ "typescript": "^6.0.3",
47
+ "vite": "^8.0.10",
48
+ "vitest": "^4.1.5"
49
+ }
50
+ }