@elementor/editor-elements 0.6.1 → 0.6.3
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 +23 -0
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +40 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -2
- package/src/styles/consts.ts +3 -1
- package/src/styles/create-element-style.ts +5 -1
- package/src/styles/mutate-element-styles.ts +1 -1
- package/src/sync/get-container.ts +1 -1
- package/src/sync/get-element-label.ts +1 -1
- package/src/sync/get-element-setting.ts +1 -1
- package/src/sync/get-element-styles.ts +1 -1
- package/src/sync/get-elements.ts +4 -2
- package/src/sync/types.ts +2 -0
- package/src/sync/update-element-settings.ts +1 -1
- package/src/hooks/use-element-styles.ts +0 -9
- package/src/sync/is-element-in-container.ts +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @elementor/editor-elements
|
|
2
2
|
|
|
3
|
+
## 0.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8231e7c: Added logic to block adding anchor/link to elements nested in or containing an already an anchored element
|
|
8
|
+
- 19f5dfe: Children elements are not loaded from the right state
|
|
9
|
+
- 51432b9: The editor loader disappears before the styles finish rendering
|
|
10
|
+
- 070b92c: Register legacy views
|
|
11
|
+
- Updated dependencies [e798985]
|
|
12
|
+
- Updated dependencies [4c2935b]
|
|
13
|
+
- Updated dependencies [c002cba]
|
|
14
|
+
- @elementor/editor-v1-adapters@0.11.0
|
|
15
|
+
- @elementor/editor-props@0.11.0
|
|
16
|
+
- @elementor/editor-styles@0.6.3
|
|
17
|
+
|
|
18
|
+
## 0.6.2
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [7d37fc1]
|
|
23
|
+
- @elementor/editor-props@0.10.0
|
|
24
|
+
- @elementor/editor-styles@0.6.2
|
|
25
|
+
|
|
3
26
|
## 0.6.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -50,6 +50,7 @@ type V1ElementModelProps = {
|
|
|
50
50
|
elType: string;
|
|
51
51
|
id: string;
|
|
52
52
|
styles?: Record<StyleDefinitionID, StyleDefinition>;
|
|
53
|
+
elements?: V1Model<V1ElementModelProps>[];
|
|
53
54
|
};
|
|
54
55
|
type V1ElementSettingsProps = Record<string, PropValue>;
|
|
55
56
|
type V1Model<T> = {
|
|
@@ -62,8 +63,6 @@ declare function useElementsDomRef(): HTMLElement[];
|
|
|
62
63
|
|
|
63
64
|
declare const useElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
64
65
|
|
|
65
|
-
declare function useElementStyles(elementId: ElementID): Record<string, _elementor_editor_styles.StyleDefinition>;
|
|
66
|
-
|
|
67
66
|
declare function useElementType(type?: string): ElementType | null;
|
|
68
67
|
|
|
69
68
|
declare function useSelectedElement(): {
|
|
@@ -76,6 +75,8 @@ declare function useSelectedElement(): {
|
|
|
76
75
|
|
|
77
76
|
declare function useParentElement(elementId: string | null): V1Element | null | undefined;
|
|
78
77
|
|
|
78
|
+
declare function getContainer(id: string): V1Element | null;
|
|
79
|
+
|
|
79
80
|
declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
80
81
|
|
|
81
82
|
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
@@ -87,6 +88,7 @@ declare function getElements(root?: ElementID): V1Element[];
|
|
|
87
88
|
declare function getSelectedElements(): Element[];
|
|
88
89
|
|
|
89
90
|
declare function getWidgetsCache(): Record<string, {
|
|
91
|
+
atomic?: boolean;
|
|
90
92
|
atomic_controls?: ControlItem[];
|
|
91
93
|
atomic_props_schema?: _elementor_editor_props.PropsSchema;
|
|
92
94
|
controls: object;
|
|
@@ -94,8 +96,6 @@ declare function getWidgetsCache(): Record<string, {
|
|
|
94
96
|
title: string;
|
|
95
97
|
}> | null;
|
|
96
98
|
|
|
97
|
-
declare const isElementInContainer: (element: Element, container: V1Element) => boolean;
|
|
98
|
-
|
|
99
99
|
type UpdateElementSettingsArgs = {
|
|
100
100
|
id: ElementID;
|
|
101
101
|
props: Props;
|
|
@@ -113,8 +113,9 @@ type CreateElementStyleArgs = {
|
|
|
113
113
|
label: string;
|
|
114
114
|
meta: StyleDefinitionVariant['meta'];
|
|
115
115
|
props: StyleDefinitionVariant['props'];
|
|
116
|
+
additionalVariants?: StyleDefinitionVariant[];
|
|
116
117
|
};
|
|
117
|
-
declare function createElementStyle({ styleId, elementId, classesProp, label, meta, props, }: CreateElementStyleArgs): string;
|
|
118
|
+
declare function createElementStyle({ styleId, elementId, classesProp, label, meta, props, additionalVariants, }: CreateElementStyleArgs): string;
|
|
118
119
|
|
|
119
120
|
type UpdateElementStyleArgs = {
|
|
120
121
|
elementId: ElementID;
|
|
@@ -126,4 +127,4 @@ declare function updateElementStyle(args: UpdateElementStyleArgs): void;
|
|
|
126
127
|
|
|
127
128
|
declare function deleteElementStyle(elementId: ElementID, styleId: StyleDefinitionID): void;
|
|
128
129
|
|
|
129
|
-
export { type Control, type ControlItem, type ControlsSection, type CreateElementStyleArgs, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementID, type ElementType, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, createElementStyle, deleteElementStyle, getElementLabel, getElementSetting, getElementStyles, getElements, getSelectedElements, getWidgetsCache,
|
|
130
|
+
export { type Control, type ControlItem, type ControlsSection, type CreateElementStyleArgs, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementID, type ElementType, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, createElementStyle, deleteElementStyle, getContainer, getElementLabel, getElementSetting, getElementStyles, getElements, getSelectedElements, getWidgetsCache, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementSetting, useElementType, useElementsDomRef, useParentElement, useSelectedElement };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ type V1ElementModelProps = {
|
|
|
50
50
|
elType: string;
|
|
51
51
|
id: string;
|
|
52
52
|
styles?: Record<StyleDefinitionID, StyleDefinition>;
|
|
53
|
+
elements?: V1Model<V1ElementModelProps>[];
|
|
53
54
|
};
|
|
54
55
|
type V1ElementSettingsProps = Record<string, PropValue>;
|
|
55
56
|
type V1Model<T> = {
|
|
@@ -62,8 +63,6 @@ declare function useElementsDomRef(): HTMLElement[];
|
|
|
62
63
|
|
|
63
64
|
declare const useElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
64
65
|
|
|
65
|
-
declare function useElementStyles(elementId: ElementID): Record<string, _elementor_editor_styles.StyleDefinition>;
|
|
66
|
-
|
|
67
66
|
declare function useElementType(type?: string): ElementType | null;
|
|
68
67
|
|
|
69
68
|
declare function useSelectedElement(): {
|
|
@@ -76,6 +75,8 @@ declare function useSelectedElement(): {
|
|
|
76
75
|
|
|
77
76
|
declare function useParentElement(elementId: string | null): V1Element | null | undefined;
|
|
78
77
|
|
|
78
|
+
declare function getContainer(id: string): V1Element | null;
|
|
79
|
+
|
|
79
80
|
declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
80
81
|
|
|
81
82
|
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
@@ -87,6 +88,7 @@ declare function getElements(root?: ElementID): V1Element[];
|
|
|
87
88
|
declare function getSelectedElements(): Element[];
|
|
88
89
|
|
|
89
90
|
declare function getWidgetsCache(): Record<string, {
|
|
91
|
+
atomic?: boolean;
|
|
90
92
|
atomic_controls?: ControlItem[];
|
|
91
93
|
atomic_props_schema?: _elementor_editor_props.PropsSchema;
|
|
92
94
|
controls: object;
|
|
@@ -94,8 +96,6 @@ declare function getWidgetsCache(): Record<string, {
|
|
|
94
96
|
title: string;
|
|
95
97
|
}> | null;
|
|
96
98
|
|
|
97
|
-
declare const isElementInContainer: (element: Element, container: V1Element) => boolean;
|
|
98
|
-
|
|
99
99
|
type UpdateElementSettingsArgs = {
|
|
100
100
|
id: ElementID;
|
|
101
101
|
props: Props;
|
|
@@ -113,8 +113,9 @@ type CreateElementStyleArgs = {
|
|
|
113
113
|
label: string;
|
|
114
114
|
meta: StyleDefinitionVariant['meta'];
|
|
115
115
|
props: StyleDefinitionVariant['props'];
|
|
116
|
+
additionalVariants?: StyleDefinitionVariant[];
|
|
116
117
|
};
|
|
117
|
-
declare function createElementStyle({ styleId, elementId, classesProp, label, meta, props, }: CreateElementStyleArgs): string;
|
|
118
|
+
declare function createElementStyle({ styleId, elementId, classesProp, label, meta, props, additionalVariants, }: CreateElementStyleArgs): string;
|
|
118
119
|
|
|
119
120
|
type UpdateElementStyleArgs = {
|
|
120
121
|
elementId: ElementID;
|
|
@@ -126,4 +127,4 @@ declare function updateElementStyle(args: UpdateElementStyleArgs): void;
|
|
|
126
127
|
|
|
127
128
|
declare function deleteElementStyle(elementId: ElementID, styleId: StyleDefinitionID): void;
|
|
128
129
|
|
|
129
|
-
export { type Control, type ControlItem, type ControlsSection, type CreateElementStyleArgs, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementID, type ElementType, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, createElementStyle, deleteElementStyle, getElementLabel, getElementSetting, getElementStyles, getElements, getSelectedElements, getWidgetsCache,
|
|
130
|
+
export { type Control, type ControlItem, type ControlsSection, type CreateElementStyleArgs, ELEMENT_STYLE_CHANGE_EVENT, type Element, type ElementID, type ElementType, type UpdateElementSettingsArgs, type UpdateElementStyleArgs, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, createElementStyle, deleteElementStyle, getContainer, getElementLabel, getElementSetting, getElementStyles, getElements, getSelectedElements, getWidgetsCache, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementSetting, useElementType, useElementsDomRef, useParentElement, useSelectedElement };
|
package/dist/index.js
CHANGED
|
@@ -23,18 +23,17 @@ __export(index_exports, {
|
|
|
23
23
|
ELEMENT_STYLE_CHANGE_EVENT: () => ELEMENT_STYLE_CHANGE_EVENT,
|
|
24
24
|
createElementStyle: () => createElementStyle,
|
|
25
25
|
deleteElementStyle: () => deleteElementStyle,
|
|
26
|
+
getContainer: () => getContainer,
|
|
26
27
|
getElementLabel: () => getElementLabel,
|
|
27
28
|
getElementSetting: () => getElementSetting,
|
|
28
29
|
getElementStyles: () => getElementStyles,
|
|
29
30
|
getElements: () => getElements,
|
|
30
31
|
getSelectedElements: () => getSelectedElements,
|
|
31
32
|
getWidgetsCache: () => getWidgetsCache,
|
|
32
|
-
isElementInContainer: () => isElementInContainer,
|
|
33
33
|
styleRerenderEvents: () => styleRerenderEvents,
|
|
34
34
|
updateElementSettings: () => updateElementSettings,
|
|
35
35
|
updateElementStyle: () => updateElementStyle,
|
|
36
36
|
useElementSetting: () => useElementSetting,
|
|
37
|
-
useElementStyles: () => useElementStyles,
|
|
38
37
|
useElementType: () => useElementType,
|
|
39
38
|
useElementsDomRef: () => useElementsDomRef,
|
|
40
39
|
useParentElement: () => useParentElement,
|
|
@@ -98,31 +97,8 @@ var useElementSetting = (elementId, settingKey) => {
|
|
|
98
97
|
);
|
|
99
98
|
};
|
|
100
99
|
|
|
101
|
-
// src/hooks/use-element-styles.ts
|
|
102
|
-
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
103
|
-
|
|
104
|
-
// src/styles/consts.ts
|
|
105
|
-
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
106
|
-
var ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/style";
|
|
107
|
-
var styleRerenderEvents = [
|
|
108
|
-
(0, import_editor_v1_adapters3.commandEndEvent)("document/elements/create"),
|
|
109
|
-
(0, import_editor_v1_adapters3.commandEndEvent)("editor/documents/attach-preview"),
|
|
110
|
-
(0, import_editor_v1_adapters3.windowEvent)(ELEMENT_STYLE_CHANGE_EVENT)
|
|
111
|
-
];
|
|
112
|
-
|
|
113
|
-
// src/sync/get-element-styles.ts
|
|
114
|
-
var getElementStyles = (elementID) => {
|
|
115
|
-
const container = getContainer(elementID);
|
|
116
|
-
return container?.model.get("styles") || null;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// src/hooks/use-element-styles.ts
|
|
120
|
-
function useElementStyles(elementId) {
|
|
121
|
-
return (0, import_editor_v1_adapters4.__privateUseListenTo)(styleRerenderEvents, () => getElementStyles(elementId) ?? {}, [elementId]);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
100
|
// src/hooks/use-element-type.ts
|
|
125
|
-
var
|
|
101
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
126
102
|
|
|
127
103
|
// src/sync/get-widgets-cache.ts
|
|
128
104
|
function getWidgetsCache() {
|
|
@@ -132,8 +108,8 @@ function getWidgetsCache() {
|
|
|
132
108
|
|
|
133
109
|
// src/hooks/use-element-type.ts
|
|
134
110
|
function useElementType(type) {
|
|
135
|
-
return (0,
|
|
136
|
-
(0,
|
|
111
|
+
return (0, import_editor_v1_adapters3.__privateUseListenTo)(
|
|
112
|
+
(0, import_editor_v1_adapters3.commandEndEvent)("editor/documents/load"),
|
|
137
113
|
() => {
|
|
138
114
|
if (!type) {
|
|
139
115
|
return null;
|
|
@@ -158,7 +134,7 @@ function useElementType(type) {
|
|
|
158
134
|
}
|
|
159
135
|
|
|
160
136
|
// src/hooks/use-selected-element.ts
|
|
161
|
-
var
|
|
137
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
162
138
|
|
|
163
139
|
// src/sync/get-selected-elements.ts
|
|
164
140
|
function getSelectedElements() {
|
|
@@ -178,8 +154,8 @@ function getSelectedElements() {
|
|
|
178
154
|
|
|
179
155
|
// src/hooks/use-selected-element.ts
|
|
180
156
|
function useSelectedElement() {
|
|
181
|
-
const elements = (0,
|
|
182
|
-
[(0,
|
|
157
|
+
const elements = (0, import_editor_v1_adapters4.__privateUseListenTo)(
|
|
158
|
+
[(0, import_editor_v1_adapters4.commandEndEvent)("document/elements/select"), (0, import_editor_v1_adapters4.commandEndEvent)("document/elements/deselect")],
|
|
183
159
|
getSelectedElements
|
|
184
160
|
);
|
|
185
161
|
const [element] = elements;
|
|
@@ -191,10 +167,10 @@ function useSelectedElement() {
|
|
|
191
167
|
}
|
|
192
168
|
|
|
193
169
|
// src/hooks/use-parent-element.ts
|
|
194
|
-
var
|
|
170
|
+
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
195
171
|
function useParentElement(elementId) {
|
|
196
|
-
return (0,
|
|
197
|
-
[(0,
|
|
172
|
+
return (0, import_editor_v1_adapters5.__privateUseListenTo)(
|
|
173
|
+
[(0, import_editor_v1_adapters5.commandEndEvent)("document/elements/create")],
|
|
198
174
|
() => {
|
|
199
175
|
if (!elementId) {
|
|
200
176
|
return null;
|
|
@@ -210,6 +186,12 @@ function useParentElement(elementId) {
|
|
|
210
186
|
);
|
|
211
187
|
}
|
|
212
188
|
|
|
189
|
+
// src/sync/get-element-styles.ts
|
|
190
|
+
var getElementStyles = (elementID) => {
|
|
191
|
+
const container = getContainer(elementID);
|
|
192
|
+
return container?.model.get("styles") || null;
|
|
193
|
+
};
|
|
194
|
+
|
|
213
195
|
// src/errors.ts
|
|
214
196
|
var import_utils = require("@elementor/utils");
|
|
215
197
|
var ElementNotFoundError = (0, import_utils.createError)({
|
|
@@ -249,23 +231,14 @@ function getElements(root) {
|
|
|
249
231
|
if (!container) {
|
|
250
232
|
return [];
|
|
251
233
|
}
|
|
252
|
-
const children = container.
|
|
234
|
+
const children = [...container.model.get("elements") ?? []].flatMap(
|
|
235
|
+
(childModel) => getElements(childModel.get("id"))
|
|
236
|
+
);
|
|
253
237
|
return [container, ...children];
|
|
254
238
|
}
|
|
255
239
|
|
|
256
|
-
// src/sync/is-element-in-container.ts
|
|
257
|
-
var isElementInContainer = (element, container) => {
|
|
258
|
-
if (container.model.get("id") === element.id && container.model.get("widgetType") === element.type) {
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
if (container.children && container.children.length > 0) {
|
|
262
|
-
return container.children.some((child) => isElementInContainer(element, child));
|
|
263
|
-
}
|
|
264
|
-
return false;
|
|
265
|
-
};
|
|
266
|
-
|
|
267
240
|
// src/sync/update-element-settings.ts
|
|
268
|
-
var
|
|
241
|
+
var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
|
|
269
242
|
var updateElementSettings = ({ id, props, withHistory = true }) => {
|
|
270
243
|
const container = getContainer(id);
|
|
271
244
|
const args = {
|
|
@@ -273,19 +246,30 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
|
|
|
273
246
|
settings: { ...props }
|
|
274
247
|
};
|
|
275
248
|
if (withHistory) {
|
|
276
|
-
(0,
|
|
249
|
+
(0, import_editor_v1_adapters6.__privateRunCommandSync)("document/elements/settings", args);
|
|
277
250
|
} else {
|
|
278
|
-
(0,
|
|
251
|
+
(0, import_editor_v1_adapters6.__privateRunCommandSync)("document/elements/set-settings", args, { internal: true });
|
|
279
252
|
}
|
|
280
253
|
};
|
|
281
254
|
|
|
255
|
+
// src/styles/consts.ts
|
|
256
|
+
var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
|
|
257
|
+
var ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/style";
|
|
258
|
+
var styleRerenderEvents = [
|
|
259
|
+
(0, import_editor_v1_adapters7.commandEndEvent)("document/elements/create"),
|
|
260
|
+
(0, import_editor_v1_adapters7.commandEndEvent)("document/elements/duplicate"),
|
|
261
|
+
(0, import_editor_v1_adapters7.commandEndEvent)("document/elements/import"),
|
|
262
|
+
(0, import_editor_v1_adapters7.commandEndEvent)("document/elements/paste"),
|
|
263
|
+
(0, import_editor_v1_adapters7.windowEvent)(ELEMENT_STYLE_CHANGE_EVENT)
|
|
264
|
+
];
|
|
265
|
+
|
|
282
266
|
// src/styles/create-element-style.ts
|
|
283
267
|
var import_editor_props2 = require("@elementor/editor-props");
|
|
284
268
|
var import_editor_styles = require("@elementor/editor-styles");
|
|
285
269
|
|
|
286
270
|
// src/styles/mutate-element-styles.ts
|
|
287
271
|
var import_editor_props = require("@elementor/editor-props");
|
|
288
|
-
var
|
|
272
|
+
var import_editor_v1_adapters8 = require("@elementor/editor-v1-adapters");
|
|
289
273
|
function mutateElementStyles(elementId, mutator) {
|
|
290
274
|
const container = getContainer(elementId);
|
|
291
275
|
if (!container) {
|
|
@@ -339,7 +323,7 @@ function getClassesProps(container) {
|
|
|
339
323
|
}
|
|
340
324
|
function notifyChanges() {
|
|
341
325
|
dispatchChangeEvent();
|
|
342
|
-
(0,
|
|
326
|
+
(0, import_editor_v1_adapters8.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
|
|
343
327
|
}
|
|
344
328
|
function dispatchChangeEvent() {
|
|
345
329
|
window.dispatchEvent(new CustomEvent(ELEMENT_STYLE_CHANGE_EVENT));
|
|
@@ -352,16 +336,18 @@ function createElementStyle({
|
|
|
352
336
|
classesProp,
|
|
353
337
|
label,
|
|
354
338
|
meta,
|
|
355
|
-
props
|
|
339
|
+
props,
|
|
340
|
+
additionalVariants = []
|
|
356
341
|
}) {
|
|
357
342
|
let id = styleId;
|
|
358
343
|
mutateElementStyles(elementId, (styles) => {
|
|
359
344
|
id ??= (0, import_editor_styles.generateId)(`e-${elementId}-`, Object.keys(styles));
|
|
345
|
+
const variants = [{ meta, props }, ...additionalVariants];
|
|
360
346
|
styles[id] = {
|
|
361
347
|
id,
|
|
362
348
|
label,
|
|
363
349
|
type: "class",
|
|
364
|
-
variants
|
|
350
|
+
variants
|
|
365
351
|
};
|
|
366
352
|
addStyleToClassesProp(elementId, classesProp, id);
|
|
367
353
|
return styles;
|
|
@@ -416,18 +402,17 @@ function deleteElementStyle(elementId, styleId) {
|
|
|
416
402
|
ELEMENT_STYLE_CHANGE_EVENT,
|
|
417
403
|
createElementStyle,
|
|
418
404
|
deleteElementStyle,
|
|
405
|
+
getContainer,
|
|
419
406
|
getElementLabel,
|
|
420
407
|
getElementSetting,
|
|
421
408
|
getElementStyles,
|
|
422
409
|
getElements,
|
|
423
410
|
getSelectedElements,
|
|
424
411
|
getWidgetsCache,
|
|
425
|
-
isElementInContainer,
|
|
426
412
|
styleRerenderEvents,
|
|
427
413
|
updateElementSettings,
|
|
428
414
|
updateElementStyle,
|
|
429
415
|
useElementSetting,
|
|
430
|
-
useElementStyles,
|
|
431
416
|
useElementType,
|
|
432
417
|
useElementsDomRef,
|
|
433
418
|
useParentElement,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/use-elements-dom-ref.ts","../src/sync/get-current-document-container.ts","../src/hooks/use-element-setting.ts","../src/sync/get-container.ts","../src/sync/get-element-setting.ts","../src/hooks/use-element-styles.ts","../src/styles/consts.ts","../src/sync/get-element-styles.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-parent-element.ts","../src/errors.ts","../src/sync/get-element-label.ts","../src/sync/get-elements.ts","../src/sync/is-element-in-container.ts","../src/sync/update-element-settings.ts","../src/styles/create-element-style.ts","../src/styles/mutate-element-styles.ts","../src/styles/update-element-style.ts","../src/styles/delete-element-style.ts"],"sourcesContent":["// types\nexport * from './types';\nexport type { V1Element, V1ElementModelProps, V1ElementSettingsProps } from './sync/types';\n\n// hooks\nexport { useElementsDomRef } from './hooks/use-elements-dom-ref';\nexport { useElementSetting } from './hooks/use-element-setting';\nexport { useElementStyles } from './hooks/use-element-styles';\nexport { useElementType } from './hooks/use-element-type';\nexport { useSelectedElement } from './hooks/use-selected-element';\nexport { useParentElement } from './hooks/use-parent-element';\n\n// utils\nexport { getElementSetting } from './sync/get-element-setting';\nexport { getElementStyles } from './sync/get-element-styles';\nexport { getElementLabel } from './sync/get-element-label';\nexport { getElements } from './sync/get-elements';\nexport { getSelectedElements } from './sync/get-selected-elements';\nexport { getWidgetsCache } from './sync/get-widgets-cache';\nexport { isElementInContainer } from './sync/is-element-in-container';\nexport { updateElementSettings, type UpdateElementSettingsArgs } from './sync/update-element-settings';\n\nexport { ELEMENT_STYLE_CHANGE_EVENT, styleRerenderEvents } from './styles/consts';\nexport { createElementStyle, type CreateElementStyleArgs } from './styles/create-element-style';\nexport { updateElementStyle, type UpdateElementStyleArgs } from './styles/update-element-style';\nexport { deleteElementStyle } from './styles/delete-element-style';\n","import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport getCurrentDocumentContainer from '../sync/get-current-document-container';\n\nconst ELEMENTS_DATA_ATTR = 'data-atomic';\n\nexport function useElementsDomRef(): HTMLElement[] {\n\treturn useListenTo(\n\t\t[\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/render' ),\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/destroy' ),\n\t\t\twindowEvent( 'elementor/editor/element-rendered' ),\n\t\t\twindowEvent( 'elementor/editor/element-destroyed' ),\n\t\t],\n\t\t() => getElementsDom()\n\t);\n}\n\nfunction getElementsDom(): HTMLElement[] {\n\tconst root = getCurrentDocumentContainer();\n\n\tif ( ! root?.view ) {\n\t\treturn [];\n\t}\n\n\treturn [ ...root.view.el.querySelectorAll< HTMLElement >( `[${ ELEMENTS_DATA_ATTR }]` ) ];\n}\n","import { type ExtendedWindow } from './types';\n\nexport default function getCurrentDocumentContainer() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { type ElementID } from '../types';\n\nexport const useElementSetting = < TValue >( elementId: ElementID, settingKey: string ) => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/set-settings' ),\n\t\t() => getElementSetting< TValue >( elementId, settingKey ),\n\t\t[ elementId, settingKey ]\n\t);\n};\n","import { type ExtendedWindow } from './types';\n\nexport default function getContainer( id: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\tconst container = extendedWindow.elementor?.getContainer?.( id );\n\n\treturn container ?? null;\n}\n","import { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementSetting = < TValue >( elementId: ElementID, settingKey: string ): TValue | null => {\n\tconst container = getContainer( elementId );\n\tconst value = container?.settings?.get( settingKey ) as TValue;\n\n\treturn value ?? null;\n};\n","import { __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\n\nimport { styleRerenderEvents } from '../styles/consts';\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport function useElementStyles( elementId: ElementID ) {\n\treturn useListenTo( styleRerenderEvents, () => getElementStyles( elementId ) ?? {}, [ elementId ] );\n}\n","import { commandEndEvent, windowEvent } from '@elementor/editor-v1-adapters';\n\nexport const ELEMENT_STYLE_CHANGE_EVENT = 'elementor/editor-v2/editor-elements/style';\n\nexport const styleRerenderEvents = [\n\tcommandEndEvent( 'document/elements/create' ),\n\tcommandEndEvent( 'editor/documents/attach-preview' ),\n\twindowEvent( ELEMENT_STYLE_CHANGE_EVENT ),\n];\n","import { type StyleDefinition } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {\n\tconst container = getContainer( elementID );\n\n\treturn container?.model.get( 'styles' ) || null;\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementType } from '../types';\n\nexport function useElementType( type?: string ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'editor/documents/load' ),\n\t\t(): ElementType | null => {\n\t\t\tif ( ! type ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst widgetsCache = getWidgetsCache();\n\t\t\tconst elementType = widgetsCache?.[ type ];\n\n\t\t\tif ( ! elementType?.atomic_controls ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif ( ! elementType?.atomic_props_schema ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\n\t\t\t\tpropsSchema: elementType.atomic_props_schema,\n\t\t\t\ttitle: elementType.title,\n\t\t\t};\n\t\t},\n\t\t[ type ]\n\t);\n}\n","import { type ExtendedWindow } from './types';\n\nexport function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getSelectedElements } from '../sync/get-selected-elements';\nimport { useElementType } from './use-element-type';\n\nexport function useSelectedElement() {\n\tconst elements = useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\tgetSelectedElements\n\t);\n\n\tconst [ element ] = elements;\n\n\tconst elementType = useElementType( element?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn { element: null, elementType: null };\n\t}\n\n\treturn { element, elementType };\n}\n","import { type Element } from '../types';\nimport { type ExtendedWindow } from './types';\n\nexport function getSelectedElements(): Element[] {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];\n\n\treturn selectedElements.reduce< Element[] >( ( acc, el ) => {\n\t\tconst type = el.model.get( 'widgetType' ) || el.model.get( 'elType' );\n\n\t\tif ( type ) {\n\t\t\tacc.push( {\n\t\t\t\tid: el.model.get( 'id' ),\n\t\t\t\ttype,\n\t\t\t} );\n\t\t}\n\n\t\treturn acc;\n\t}, [] );\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { type ExtendedWindow } from '../sync/types';\n\nexport function useParentElement( elementId: string | null ) {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/create' ) ],\n\t\t() => {\n\t\t\tif ( ! elementId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst extendedWindow = window as unknown as ExtendedWindow;\n\t\t\tconst element = extendedWindow?.elementor?.getContainer?.( elementId );\n\t\t\tif ( ! element ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn element.parent;\n\t\t},\n\t\t[ elementId ]\n\t);\n}\n","import { createError } from '@elementor/utils';\n\nexport const ElementNotFoundError = createError< { elementId: string } >( {\n\tcode: 'element_not_found',\n\tmessage: 'Element not found.',\n} );\n\nexport const StyleNotFoundError = createError< { styleId: string } >( {\n\tcode: 'style_not_found',\n\tmessage: 'Style not found.',\n} );\n\nexport const ElementTypeNotExistsError = createError< { elementId: string } >( {\n\tcode: 'element_type_not_exists',\n\tmessage: 'Element type does not exist.',\n} );\n\nexport const ElementLabelNotExistsError = createError< { elementType: string } >( {\n\tcode: 'element_label_not_exists',\n\tmessage: 'Element label does not exist.',\n} );\n","import { ElementLabelNotExistsError, ElementTypeNotExistsError } from '../errors';\nimport getContainer from '../sync/get-container';\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementID } from '../types';\n\nexport function getElementLabel( elementId: ElementID ) {\n\tconst container = getContainer( elementId );\n\n\tconst type = container?.model.get( 'widgetType' ) || container?.model.get( 'elType' );\n\n\tif ( ! type ) {\n\t\tthrow new ElementTypeNotExistsError( { context: { elementId } } );\n\t}\n\n\tconst label = getWidgetsCache()?.[ type ]?.title;\n\n\tif ( ! label ) {\n\t\tthrow new ElementLabelNotExistsError( { context: { elementType: type } } );\n\t}\n\n\treturn label;\n}\n","import { type ElementID } from '../types';\nimport getContainer from './get-container';\nimport getCurrentDocumentContainer from './get-current-document-container';\nimport { type V1Element } from './types';\n\nexport function getElements( root?: ElementID ): V1Element[] {\n\tconst container = root ? getContainer( root ) : getCurrentDocumentContainer();\n\n\tif ( ! container ) {\n\t\treturn [];\n\t}\n\n\tconst children = container.children?.flatMap( ( child ) => getElements( child.id ) ) ?? [];\n\n\treturn [ container, ...children ];\n}\n","import { type Element } from '../types';\nimport { type V1Element } from './types';\n\nexport const isElementInContainer = ( element: Element, container: V1Element ): boolean => {\n\tif ( container.model.get( 'id' ) === element.id && container.model.get( 'widgetType' ) === element.type ) {\n\t\treturn true;\n\t}\n\n\tif ( container.children && container.children.length > 0 ) {\n\t\treturn container.children.some( ( child ) => isElementInContainer( element, child ) );\n\t}\n\n\treturn false;\n};\n","import { type Props } from '@elementor/editor-props';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport type UpdateElementSettingsArgs = {\n\tid: ElementID;\n\tprops: Props;\n\twithHistory?: boolean;\n};\n\nexport const updateElementSettings = ( { id, props, withHistory = true }: UpdateElementSettingsArgs ) => {\n\tconst container = getContainer( id );\n\n\tconst args = {\n\t\tcontainer,\n\t\tsettings: { ...props },\n\t};\n\n\tif ( withHistory ) {\n\t\trunCommandSync( 'document/elements/settings', args );\n\t} else {\n\t\trunCommandSync( 'document/elements/set-settings', args, { internal: true } );\n\t}\n};\n","import { classesPropTypeUtil } from '@elementor/editor-props';\nimport {\n\tgenerateId,\n\ttype StyleDefinition,\n\ttype StyleDefinitionID,\n\ttype StyleDefinitionVariant,\n} from '@elementor/editor-styles';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type CreateElementStyleArgs = {\n\tstyleId?: StyleDefinitionID;\n\telementId: ElementID;\n\tclassesProp: string;\n\tlabel: string;\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n};\n\nexport function createElementStyle( {\n\tstyleId,\n\telementId,\n\tclassesProp,\n\tlabel,\n\tmeta,\n\tprops,\n}: CreateElementStyleArgs ): string {\n\tlet id = styleId;\n\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\tid ??= generateId( `e-${ elementId }-`, Object.keys( styles ) );\n\n\t\tstyles[ id ] = {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\ttype: 'class',\n\t\t\tvariants: [ { meta, props } ],\n\t\t} satisfies StyleDefinition;\n\n\t\taddStyleToClassesProp( elementId, classesProp, id );\n\n\t\treturn styles;\n\t} );\n\n\treturn id as string;\n}\n\nfunction addStyleToClassesProp( elementId: ElementID, classesProp: string, styleId: string ) {\n\tconst base = getElementSetting( elementId, classesProp );\n\n\tconst classesPropValue = classesPropTypeUtil.create(\n\t\t( prev ) => {\n\t\t\treturn [ ...( prev ?? [] ), styleId ];\n\t\t},\n\t\t{ base }\n\t);\n\n\tupdateElementSettings( {\n\t\tid: elementId,\n\t\tprops: {\n\t\t\t[ classesProp ]: classesPropValue,\n\t\t},\n\t\twithHistory: false,\n\t} );\n}\n","import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';\nimport { type StyleDefinition, type StyleDefinitionsMap } from '@elementor/editor-styles';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { ElementNotFoundError } from '../errors';\nimport getContainer from '../sync/get-container';\nimport { type V1Element } from '../sync/types';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { ELEMENT_STYLE_CHANGE_EVENT } from './consts';\n\ntype Mutator = ( styles: StyleDefinitionsMap ) => StyleDefinitionsMap;\n\nexport function mutateElementStyles( elementId: ElementID, mutator: Mutator ) {\n\tconst container = getContainer( elementId );\n\n\tif ( ! container ) {\n\t\tthrow new ElementNotFoundError( { context: { elementId } } );\n\t}\n\n\tconst oldIds = Object.keys( container.model.get( 'styles' ) ?? {} );\n\n\tconst styles = mutateStyles( container, mutator );\n\n\tconst newIds = Object.keys( styles );\n\n\tclearRemovedClasses( container, {\n\t\toldIds,\n\t\tnewIds,\n\t} );\n\n\tnotifyChanges();\n\n\treturn styles;\n}\n\nfunction mutateStyles( container: V1Element, mutator: Mutator ) {\n\tconst styles: StyleDefinitionsMap = structuredClone( container.model.get( 'styles' ) ) ?? {};\n\n\tconst entries = Object.entries( mutator( styles ) )\n\t\t.map( ( [ styleId, style ] ) => {\n\t\t\tstyle.variants = removeEmptyVariants( style );\n\n\t\t\treturn [ styleId, style ] as const;\n\t\t} )\n\t\t.filter( ( [ , style ] ) => {\n\t\t\treturn ! isStyleEmpty( style );\n\t\t} );\n\n\tconst mutatedStyles = Object.fromEntries( entries );\n\n\tcontainer.model.set( 'styles', mutatedStyles );\n\n\treturn mutatedStyles;\n}\n\nfunction removeEmptyVariants( style: StyleDefinition ) {\n\treturn style.variants.filter( ( { props } ) => Object.keys( props ).length > 0 );\n}\n\nfunction isStyleEmpty( style: StyleDefinition ) {\n\treturn style.variants.length === 0;\n}\n\nfunction clearRemovedClasses( container: V1Element, { oldIds, newIds }: { oldIds: string[]; newIds: string[] } ) {\n\tconst removedIds = oldIds.filter( ( id ) => ! newIds.includes( id ) );\n\tconst classesProps = structuredClone( getClassesProps( container ) );\n\n\tclassesProps.forEach( ( [ , prop ] ) => {\n\t\tprop.value = prop.value.filter( ( value ) => ! removedIds.includes( value ) );\n\t} );\n\n\tupdateElementSettings( {\n\t\tid: container.id,\n\t\tprops: Object.fromEntries( classesProps ),\n\t\twithHistory: false,\n\t} );\n}\n\nfunction getClassesProps( container: V1Element ) {\n\treturn Object.entries( container.settings.toJSON() ).filter( ( prop ): prop is [ string, ClassesPropValue ] => {\n\t\tconst [ , value ] = prop;\n\n\t\treturn classesPropTypeUtil.isValid( value );\n\t} );\n}\n\nfunction notifyChanges() {\n\tdispatchChangeEvent();\n\trunCommandSync( 'document/save/set-is-modified', { status: true }, { internal: true } );\n}\n\nfunction dispatchChangeEvent() {\n\twindow.dispatchEvent( new CustomEvent( ELEMENT_STYLE_CHANGE_EVENT ) );\n}\n","import { mergeProps } from '@elementor/editor-props';\nimport { getVariantByMeta, type StyleDefinition, type StyleDefinitionVariant } from '@elementor/editor-styles';\n\nimport { StyleNotFoundError } from '../errors';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type UpdateElementStyleArgs = {\n\telementId: ElementID;\n\tstyleId: StyleDefinition[ 'id' ];\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n};\n\nexport function updateElementStyle( args: UpdateElementStyleArgs ) {\n\tmutateElementStyles( args.elementId, ( styles ) => {\n\t\tconst style = styles[ args.styleId ];\n\n\t\tif ( ! style ) {\n\t\t\tthrow new StyleNotFoundError( { context: { styleId: args.styleId } } );\n\t\t}\n\n\t\tconst variant = getVariantByMeta( style, args.meta );\n\n\t\tif ( variant ) {\n\t\t\tvariant.props = mergeProps( variant.props, args.props );\n\t\t} else {\n\t\t\tstyle.variants.push( { meta: args.meta, props: args.props } );\n\t\t}\n\n\t\treturn styles;\n\t} );\n}\n","import { type StyleDefinitionID } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport function deleteElementStyle( elementId: ElementID, styleId: StyleDefinitionID ) {\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\t// The object is deep cloned so mutating it is fine.\n\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\tdelete styles[ styleId ];\n\n\t\treturn styles;\n\t} );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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C,GAAK,OAAQ;AAAA,IACrC;AAAA,IACA,EAAE,KAAK;AAAA,EACR;AAEA,wBAAuB;AAAA,IACtB,IAAI;AAAA,IACJ,OAAO;AAAA,MACN,CAAE,WAAY,GAAG;AAAA,IAClB;AAAA,IACA,aAAa;AAAA,EACd,CAAE;AACH;;;AEnEA,IAAAC,uBAA2B;AAC3B,IAAAC,wBAAoF;AAa7E,SAAS,mBAAoB,MAA+B;AAClE,sBAAqB,KAAK,WAAW,CAAE,WAAY;AAClD,UAAM,QAAQ,OAAQ,KAAK,OAAQ;AAEnC,QAAK,CAAE,OAAQ;AACd,YAAM,IAAI,mBAAoB,EAAE,SAAS,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAE;AAAA,IACtE;AAEA,UAAM,cAAU,wCAAkB,OAAO,KAAK,IAAK;AAEnD,QAAK,SAAU;AACd,cAAQ,YAAQ,iCAAY,QAAQ,OAAO,KAAK,KAAM;AAAA,IACvD,OAAO;AACN,YAAM,SAAS,KAAM,EAAE,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,CAAE;AAAA,IAC7D;AAEA,WAAO;AAAA,EACR,CAAE;AACH;;;AC3BO,SAAS,mBAAoB,WAAsB,SAA6B;AACtF,sBAAqB,WAAW,CAAE,WAAY;AAG7C,WAAO,OAAQ,OAAQ;AAEvB,WAAO;AAAA,EACR,CAAE;AACH;","names":["useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","runCommandSync","import_editor_props","import_editor_v1_adapters","runCommandSync","import_editor_props","import_editor_styles"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/use-elements-dom-ref.ts","../src/sync/get-current-document-container.ts","../src/hooks/use-element-setting.ts","../src/sync/get-container.ts","../src/sync/get-element-setting.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-parent-element.ts","../src/sync/get-element-styles.ts","../src/errors.ts","../src/sync/get-element-label.ts","../src/sync/get-elements.ts","../src/sync/update-element-settings.ts","../src/styles/consts.ts","../src/styles/create-element-style.ts","../src/styles/mutate-element-styles.ts","../src/styles/update-element-style.ts","../src/styles/delete-element-style.ts"],"sourcesContent":["// types\nexport * from './types';\nexport type { V1Element, V1ElementModelProps, V1ElementSettingsProps } from './sync/types';\n\n// hooks\nexport { useElementsDomRef } from './hooks/use-elements-dom-ref';\nexport { useElementSetting } from './hooks/use-element-setting';\nexport { useElementType } from './hooks/use-element-type';\nexport { useSelectedElement } from './hooks/use-selected-element';\nexport { useParentElement } from './hooks/use-parent-element';\n\n// utils\nexport { getContainer } from './sync/get-container';\nexport { getElementSetting } from './sync/get-element-setting';\nexport { getElementStyles } from './sync/get-element-styles';\nexport { getElementLabel } from './sync/get-element-label';\nexport { getElements } from './sync/get-elements';\nexport { getSelectedElements } from './sync/get-selected-elements';\nexport { getWidgetsCache } from './sync/get-widgets-cache';\nexport { updateElementSettings, type UpdateElementSettingsArgs } from './sync/update-element-settings';\n\nexport { ELEMENT_STYLE_CHANGE_EVENT, styleRerenderEvents } from './styles/consts';\nexport { createElementStyle, type CreateElementStyleArgs } from './styles/create-element-style';\nexport { updateElementStyle, type UpdateElementStyleArgs } from './styles/update-element-style';\nexport { deleteElementStyle } from './styles/delete-element-style';\n","import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport getCurrentDocumentContainer from '../sync/get-current-document-container';\n\nconst ELEMENTS_DATA_ATTR = 'data-atomic';\n\nexport function useElementsDomRef(): HTMLElement[] {\n\treturn useListenTo(\n\t\t[\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/render' ),\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/destroy' ),\n\t\t\twindowEvent( 'elementor/editor/element-rendered' ),\n\t\t\twindowEvent( 'elementor/editor/element-destroyed' ),\n\t\t],\n\t\t() => getElementsDom()\n\t);\n}\n\nfunction getElementsDom(): HTMLElement[] {\n\tconst root = getCurrentDocumentContainer();\n\n\tif ( ! root?.view ) {\n\t\treturn [];\n\t}\n\n\treturn [ ...root.view.el.querySelectorAll< HTMLElement >( `[${ ELEMENTS_DATA_ATTR }]` ) ];\n}\n","import { type ExtendedWindow } from './types';\n\nexport default function getCurrentDocumentContainer() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { type ElementID } from '../types';\n\nexport const useElementSetting = < TValue >( elementId: ElementID, settingKey: string ) => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/set-settings' ),\n\t\t() => getElementSetting< TValue >( elementId, settingKey ),\n\t\t[ elementId, settingKey ]\n\t);\n};\n","import { type ExtendedWindow } from './types';\n\nexport function getContainer( id: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\tconst container = extendedWindow.elementor?.getContainer?.( id );\n\n\treturn container ?? null;\n}\n","import { type ElementID } from '../types';\nimport { getContainer } from './get-container';\n\nexport const getElementSetting = < TValue >( elementId: ElementID, settingKey: string ): TValue | null => {\n\tconst container = getContainer( elementId );\n\tconst value = container?.settings?.get( settingKey ) as TValue;\n\n\treturn value ?? null;\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementType } from '../types';\n\nexport function useElementType( type?: string ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'editor/documents/load' ),\n\t\t(): ElementType | null => {\n\t\t\tif ( ! type ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst widgetsCache = getWidgetsCache();\n\t\t\tconst elementType = widgetsCache?.[ type ];\n\n\t\t\tif ( ! elementType?.atomic_controls ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif ( ! elementType?.atomic_props_schema ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\n\t\t\t\tpropsSchema: elementType.atomic_props_schema,\n\t\t\t\ttitle: elementType.title,\n\t\t\t};\n\t\t},\n\t\t[ type ]\n\t);\n}\n","import { type ExtendedWindow } from './types';\n\nexport function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getSelectedElements } from '../sync/get-selected-elements';\nimport { useElementType } from './use-element-type';\n\nexport function useSelectedElement() {\n\tconst elements = useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\tgetSelectedElements\n\t);\n\n\tconst [ element ] = elements;\n\n\tconst elementType = useElementType( element?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn { element: null, elementType: null };\n\t}\n\n\treturn { element, elementType };\n}\n","import { type Element } from '../types';\nimport { type ExtendedWindow } from './types';\n\nexport function getSelectedElements(): Element[] {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];\n\n\treturn selectedElements.reduce< Element[] >( ( acc, el ) => {\n\t\tconst type = el.model.get( 'widgetType' ) || el.model.get( 'elType' );\n\n\t\tif ( type ) {\n\t\t\tacc.push( {\n\t\t\t\tid: el.model.get( 'id' ),\n\t\t\t\ttype,\n\t\t\t} );\n\t\t}\n\n\t\treturn acc;\n\t}, [] );\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { type ExtendedWindow } from '../sync/types';\n\nexport function useParentElement( elementId: string | null ) {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/create' ) ],\n\t\t() => {\n\t\t\tif ( ! elementId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst extendedWindow = window as unknown as ExtendedWindow;\n\t\t\tconst element = extendedWindow?.elementor?.getContainer?.( elementId );\n\t\t\tif ( ! element ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn element.parent;\n\t\t},\n\t\t[ elementId ]\n\t);\n}\n","import { type StyleDefinition } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport { getContainer } from './get-container';\n\nexport const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {\n\tconst container = getContainer( elementID );\n\n\treturn container?.model.get( 'styles' ) || null;\n};\n","import { createError } from '@elementor/utils';\n\nexport const ElementNotFoundError = createError< { elementId: string } >( {\n\tcode: 'element_not_found',\n\tmessage: 'Element not found.',\n} );\n\nexport const StyleNotFoundError = createError< { styleId: string } >( {\n\tcode: 'style_not_found',\n\tmessage: 'Style not found.',\n} );\n\nexport const ElementTypeNotExistsError = createError< { elementId: string } >( {\n\tcode: 'element_type_not_exists',\n\tmessage: 'Element type does not exist.',\n} );\n\nexport const ElementLabelNotExistsError = createError< { elementType: string } >( {\n\tcode: 'element_label_not_exists',\n\tmessage: 'Element label does not exist.',\n} );\n","import { ElementLabelNotExistsError, ElementTypeNotExistsError } from '../errors';\nimport { getContainer } from '../sync/get-container';\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementID } from '../types';\n\nexport function getElementLabel( elementId: ElementID ) {\n\tconst container = getContainer( elementId );\n\n\tconst type = container?.model.get( 'widgetType' ) || container?.model.get( 'elType' );\n\n\tif ( ! type ) {\n\t\tthrow new ElementTypeNotExistsError( { context: { elementId } } );\n\t}\n\n\tconst label = getWidgetsCache()?.[ type ]?.title;\n\n\tif ( ! label ) {\n\t\tthrow new ElementLabelNotExistsError( { context: { elementType: type } } );\n\t}\n\n\treturn label;\n}\n","import { type ElementID } from '../types';\nimport { getContainer } from './get-container';\nimport getCurrentDocumentContainer from './get-current-document-container';\nimport { type V1Element } from './types';\n\nexport function getElements( root?: ElementID ): V1Element[] {\n\tconst container = root ? getContainer( root ) : getCurrentDocumentContainer();\n\n\tif ( ! container ) {\n\t\treturn [];\n\t}\n\n\tconst children = [ ...( container.model.get( 'elements' ) ?? [] ) ].flatMap( ( childModel ) =>\n\t\tgetElements( childModel.get( 'id' ) )\n\t);\n\n\treturn [ container, ...children ];\n}\n","import { type Props } from '@elementor/editor-props';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport { getContainer } from './get-container';\n\nexport type UpdateElementSettingsArgs = {\n\tid: ElementID;\n\tprops: Props;\n\twithHistory?: boolean;\n};\n\nexport const updateElementSettings = ( { id, props, withHistory = true }: UpdateElementSettingsArgs ) => {\n\tconst container = getContainer( id );\n\n\tconst args = {\n\t\tcontainer,\n\t\tsettings: { ...props },\n\t};\n\n\tif ( withHistory ) {\n\t\trunCommandSync( 'document/elements/settings', args );\n\t} else {\n\t\trunCommandSync( 'document/elements/set-settings', args, { internal: true } );\n\t}\n};\n","import { commandEndEvent, windowEvent } from '@elementor/editor-v1-adapters';\n\nexport const ELEMENT_STYLE_CHANGE_EVENT = 'elementor/editor-v2/editor-elements/style';\n\nexport const styleRerenderEvents = [\n\tcommandEndEvent( 'document/elements/create' ),\n\tcommandEndEvent( 'document/elements/duplicate' ),\n\tcommandEndEvent( 'document/elements/import' ),\n\tcommandEndEvent( 'document/elements/paste' ),\n\twindowEvent( ELEMENT_STYLE_CHANGE_EVENT ),\n];\n","import { classesPropTypeUtil } from '@elementor/editor-props';\nimport {\n\tgenerateId,\n\ttype StyleDefinition,\n\ttype StyleDefinitionID,\n\ttype StyleDefinitionVariant,\n} from '@elementor/editor-styles';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type CreateElementStyleArgs = {\n\tstyleId?: StyleDefinitionID;\n\telementId: ElementID;\n\tclassesProp: string;\n\tlabel: string;\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n\tadditionalVariants?: StyleDefinitionVariant[];\n};\n\nexport function createElementStyle( {\n\tstyleId,\n\telementId,\n\tclassesProp,\n\tlabel,\n\tmeta,\n\tprops,\n\tadditionalVariants = [],\n}: CreateElementStyleArgs ): string {\n\tlet id = styleId;\n\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\tid ??= generateId( `e-${ elementId }-`, Object.keys( styles ) );\n\n\t\tconst variants = [ { meta, props }, ...additionalVariants ];\n\n\t\tstyles[ id ] = {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\ttype: 'class',\n\t\t\tvariants,\n\t\t} satisfies StyleDefinition;\n\n\t\taddStyleToClassesProp( elementId, classesProp, id );\n\n\t\treturn styles;\n\t} );\n\n\treturn id as string;\n}\n\nfunction addStyleToClassesProp( elementId: ElementID, classesProp: string, styleId: string ) {\n\tconst base = getElementSetting( elementId, classesProp );\n\n\tconst classesPropValue = classesPropTypeUtil.create(\n\t\t( prev ) => {\n\t\t\treturn [ ...( prev ?? [] ), styleId ];\n\t\t},\n\t\t{ base }\n\t);\n\n\tupdateElementSettings( {\n\t\tid: elementId,\n\t\tprops: {\n\t\t\t[ classesProp ]: classesPropValue,\n\t\t},\n\t\twithHistory: false,\n\t} );\n}\n","import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';\nimport { type StyleDefinition, type StyleDefinitionsMap } from '@elementor/editor-styles';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { ElementNotFoundError } from '../errors';\nimport { getContainer } from '../sync/get-container';\nimport { type V1Element } from '../sync/types';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { ELEMENT_STYLE_CHANGE_EVENT } from './consts';\n\ntype Mutator = ( styles: StyleDefinitionsMap ) => StyleDefinitionsMap;\n\nexport function mutateElementStyles( elementId: ElementID, mutator: Mutator ) {\n\tconst container = getContainer( elementId );\n\n\tif ( ! container ) {\n\t\tthrow new ElementNotFoundError( { context: { elementId } } );\n\t}\n\n\tconst oldIds = Object.keys( container.model.get( 'styles' ) ?? {} );\n\n\tconst styles = mutateStyles( container, mutator );\n\n\tconst newIds = Object.keys( styles );\n\n\tclearRemovedClasses( container, {\n\t\toldIds,\n\t\tnewIds,\n\t} );\n\n\tnotifyChanges();\n\n\treturn styles;\n}\n\nfunction mutateStyles( container: V1Element, mutator: Mutator ) {\n\tconst styles: StyleDefinitionsMap = structuredClone( container.model.get( 'styles' ) ) ?? {};\n\n\tconst entries = Object.entries( mutator( styles ) )\n\t\t.map( ( [ styleId, style ] ) => {\n\t\t\tstyle.variants = removeEmptyVariants( style );\n\n\t\t\treturn [ styleId, style ] as const;\n\t\t} )\n\t\t.filter( ( [ , style ] ) => {\n\t\t\treturn ! isStyleEmpty( style );\n\t\t} );\n\n\tconst mutatedStyles = Object.fromEntries( entries );\n\n\tcontainer.model.set( 'styles', mutatedStyles );\n\n\treturn mutatedStyles;\n}\n\nfunction removeEmptyVariants( style: StyleDefinition ) {\n\treturn style.variants.filter( ( { props } ) => Object.keys( props ).length > 0 );\n}\n\nfunction isStyleEmpty( style: StyleDefinition ) {\n\treturn style.variants.length === 0;\n}\n\nfunction clearRemovedClasses( container: V1Element, { oldIds, newIds }: { oldIds: string[]; newIds: string[] } ) {\n\tconst removedIds = oldIds.filter( ( id ) => ! newIds.includes( id ) );\n\tconst classesProps = structuredClone( getClassesProps( container ) );\n\n\tclassesProps.forEach( ( [ , prop ] ) => {\n\t\tprop.value = prop.value.filter( ( value ) => ! removedIds.includes( value ) );\n\t} );\n\n\tupdateElementSettings( {\n\t\tid: container.id,\n\t\tprops: Object.fromEntries( classesProps ),\n\t\twithHistory: false,\n\t} );\n}\n\nfunction getClassesProps( container: V1Element ) {\n\treturn Object.entries( container.settings.toJSON() ).filter( ( prop ): prop is [ string, ClassesPropValue ] => {\n\t\tconst [ , value ] = prop;\n\n\t\treturn classesPropTypeUtil.isValid( value );\n\t} );\n}\n\nfunction notifyChanges() {\n\tdispatchChangeEvent();\n\trunCommandSync( 'document/save/set-is-modified', { status: true }, { internal: true } );\n}\n\nfunction dispatchChangeEvent() {\n\twindow.dispatchEvent( new CustomEvent( ELEMENT_STYLE_CHANGE_EVENT ) );\n}\n","import { mergeProps } from '@elementor/editor-props';\nimport { getVariantByMeta, type StyleDefinition, type StyleDefinitionVariant } from '@elementor/editor-styles';\n\nimport { StyleNotFoundError } from '../errors';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type UpdateElementStyleArgs = {\n\telementId: ElementID;\n\tstyleId: StyleDefinition[ 'id' ];\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n};\n\nexport function updateElementStyle( args: UpdateElementStyleArgs ) {\n\tmutateElementStyles( args.elementId, ( styles ) => {\n\t\tconst style = styles[ args.styleId ];\n\n\t\tif ( ! style ) {\n\t\t\tthrow new StyleNotFoundError( { context: { styleId: args.styleId } } );\n\t\t}\n\n\t\tconst variant = getVariantByMeta( style, args.meta );\n\n\t\tif ( variant ) {\n\t\t\tvariant.props = mergeProps( variant.props, args.props );\n\t\t} else {\n\t\t\tstyle.variants.push( { meta: args.meta, props: args.props } );\n\t\t}\n\n\t\treturn styles;\n\t} );\n}\n","import { type StyleDefinitionID } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport function deleteElementStyle( elementId: ElementID, styleId: StyleDefinitionID ) {\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\t// The object is deep cloned so mutating it is fine.\n\t\t// eslint-disable-next-line @typescript-eslint/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AAE,WAAY,GAAG;AAAA,IAClB;AAAA,IACA,aAAa;AAAA,EACd,CAAE;AACH;;;AEvEA,IAAAC,uBAA2B;AAC3B,IAAAC,wBAAoF;AAa7E,SAAS,mBAAoB,MAA+B;AAClE,sBAAqB,KAAK,WAAW,CAAE,WAAY;AAClD,UAAM,QAAQ,OAAQ,KAAK,OAAQ;AAEnC,QAAK,CAAE,OAAQ;AACd,YAAM,IAAI,mBAAoB,EAAE,SAAS,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAE;AAAA,IACtE;AAEA,UAAM,cAAU,wCAAkB,OAAO,KAAK,IAAK;AAEnD,QAAK,SAAU;AACd,cAAQ,YAAQ,iCAAY,QAAQ,OAAO,KAAK,KAAM;AAAA,IACvD,OAAO;AACN,YAAM,SAAS,KAAM,EAAE,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,CAAE;AAAA,IAC7D;AAEA,WAAO;AAAA,EACR,CAAE;AACH;;;AC3BO,SAAS,mBAAoB,WAAsB,SAA6B;AACtF,sBAAqB,WAAW,CAAE,WAAY;AAG7C,WAAO,OAAQ,OAAQ;AAEvB,WAAO;AAAA,EACR,CAAE;AACH;","names":["useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","runCommandSync","import_editor_v1_adapters","import_editor_props","import_editor_v1_adapters","runCommandSync","import_editor_props","import_editor_styles"]}
|
package/dist/index.mjs
CHANGED
|
@@ -54,31 +54,8 @@ var useElementSetting = (elementId, settingKey) => {
|
|
|
54
54
|
);
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
// src/hooks/use-element-styles.ts
|
|
58
|
-
import { __privateUseListenTo as useListenTo3 } from "@elementor/editor-v1-adapters";
|
|
59
|
-
|
|
60
|
-
// src/styles/consts.ts
|
|
61
|
-
import { commandEndEvent as commandEndEvent2, windowEvent as windowEvent2 } from "@elementor/editor-v1-adapters";
|
|
62
|
-
var ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/style";
|
|
63
|
-
var styleRerenderEvents = [
|
|
64
|
-
commandEndEvent2("document/elements/create"),
|
|
65
|
-
commandEndEvent2("editor/documents/attach-preview"),
|
|
66
|
-
windowEvent2(ELEMENT_STYLE_CHANGE_EVENT)
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
// src/sync/get-element-styles.ts
|
|
70
|
-
var getElementStyles = (elementID) => {
|
|
71
|
-
const container = getContainer(elementID);
|
|
72
|
-
return container?.model.get("styles") || null;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// src/hooks/use-element-styles.ts
|
|
76
|
-
function useElementStyles(elementId) {
|
|
77
|
-
return useListenTo3(styleRerenderEvents, () => getElementStyles(elementId) ?? {}, [elementId]);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
57
|
// src/hooks/use-element-type.ts
|
|
81
|
-
import { __privateUseListenTo as
|
|
58
|
+
import { __privateUseListenTo as useListenTo3, commandEndEvent as commandEndEvent2 } from "@elementor/editor-v1-adapters";
|
|
82
59
|
|
|
83
60
|
// src/sync/get-widgets-cache.ts
|
|
84
61
|
function getWidgetsCache() {
|
|
@@ -88,8 +65,8 @@ function getWidgetsCache() {
|
|
|
88
65
|
|
|
89
66
|
// src/hooks/use-element-type.ts
|
|
90
67
|
function useElementType(type) {
|
|
91
|
-
return
|
|
92
|
-
|
|
68
|
+
return useListenTo3(
|
|
69
|
+
commandEndEvent2("editor/documents/load"),
|
|
93
70
|
() => {
|
|
94
71
|
if (!type) {
|
|
95
72
|
return null;
|
|
@@ -114,7 +91,7 @@ function useElementType(type) {
|
|
|
114
91
|
}
|
|
115
92
|
|
|
116
93
|
// src/hooks/use-selected-element.ts
|
|
117
|
-
import { __privateUseListenTo as
|
|
94
|
+
import { __privateUseListenTo as useListenTo4, commandEndEvent as commandEndEvent3 } from "@elementor/editor-v1-adapters";
|
|
118
95
|
|
|
119
96
|
// src/sync/get-selected-elements.ts
|
|
120
97
|
function getSelectedElements() {
|
|
@@ -134,8 +111,8 @@ function getSelectedElements() {
|
|
|
134
111
|
|
|
135
112
|
// src/hooks/use-selected-element.ts
|
|
136
113
|
function useSelectedElement() {
|
|
137
|
-
const elements =
|
|
138
|
-
[
|
|
114
|
+
const elements = useListenTo4(
|
|
115
|
+
[commandEndEvent3("document/elements/select"), commandEndEvent3("document/elements/deselect")],
|
|
139
116
|
getSelectedElements
|
|
140
117
|
);
|
|
141
118
|
const [element] = elements;
|
|
@@ -147,10 +124,10 @@ function useSelectedElement() {
|
|
|
147
124
|
}
|
|
148
125
|
|
|
149
126
|
// src/hooks/use-parent-element.ts
|
|
150
|
-
import { __privateUseListenTo as
|
|
127
|
+
import { __privateUseListenTo as useListenTo5, commandEndEvent as commandEndEvent4 } from "@elementor/editor-v1-adapters";
|
|
151
128
|
function useParentElement(elementId) {
|
|
152
|
-
return
|
|
153
|
-
[
|
|
129
|
+
return useListenTo5(
|
|
130
|
+
[commandEndEvent4("document/elements/create")],
|
|
154
131
|
() => {
|
|
155
132
|
if (!elementId) {
|
|
156
133
|
return null;
|
|
@@ -166,6 +143,12 @@ function useParentElement(elementId) {
|
|
|
166
143
|
);
|
|
167
144
|
}
|
|
168
145
|
|
|
146
|
+
// src/sync/get-element-styles.ts
|
|
147
|
+
var getElementStyles = (elementID) => {
|
|
148
|
+
const container = getContainer(elementID);
|
|
149
|
+
return container?.model.get("styles") || null;
|
|
150
|
+
};
|
|
151
|
+
|
|
169
152
|
// src/errors.ts
|
|
170
153
|
import { createError } from "@elementor/utils";
|
|
171
154
|
var ElementNotFoundError = createError({
|
|
@@ -205,21 +188,12 @@ function getElements(root) {
|
|
|
205
188
|
if (!container) {
|
|
206
189
|
return [];
|
|
207
190
|
}
|
|
208
|
-
const children = container.
|
|
191
|
+
const children = [...container.model.get("elements") ?? []].flatMap(
|
|
192
|
+
(childModel) => getElements(childModel.get("id"))
|
|
193
|
+
);
|
|
209
194
|
return [container, ...children];
|
|
210
195
|
}
|
|
211
196
|
|
|
212
|
-
// src/sync/is-element-in-container.ts
|
|
213
|
-
var isElementInContainer = (element, container) => {
|
|
214
|
-
if (container.model.get("id") === element.id && container.model.get("widgetType") === element.type) {
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
if (container.children && container.children.length > 0) {
|
|
218
|
-
return container.children.some((child) => isElementInContainer(element, child));
|
|
219
|
-
}
|
|
220
|
-
return false;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
197
|
// src/sync/update-element-settings.ts
|
|
224
198
|
import { __privateRunCommandSync as runCommandSync } from "@elementor/editor-v1-adapters";
|
|
225
199
|
var updateElementSettings = ({ id, props, withHistory = true }) => {
|
|
@@ -235,6 +209,17 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
|
|
|
235
209
|
}
|
|
236
210
|
};
|
|
237
211
|
|
|
212
|
+
// src/styles/consts.ts
|
|
213
|
+
import { commandEndEvent as commandEndEvent5, windowEvent as windowEvent2 } from "@elementor/editor-v1-adapters";
|
|
214
|
+
var ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/style";
|
|
215
|
+
var styleRerenderEvents = [
|
|
216
|
+
commandEndEvent5("document/elements/create"),
|
|
217
|
+
commandEndEvent5("document/elements/duplicate"),
|
|
218
|
+
commandEndEvent5("document/elements/import"),
|
|
219
|
+
commandEndEvent5("document/elements/paste"),
|
|
220
|
+
windowEvent2(ELEMENT_STYLE_CHANGE_EVENT)
|
|
221
|
+
];
|
|
222
|
+
|
|
238
223
|
// src/styles/create-element-style.ts
|
|
239
224
|
import { classesPropTypeUtil as classesPropTypeUtil2 } from "@elementor/editor-props";
|
|
240
225
|
import {
|
|
@@ -310,16 +295,18 @@ function createElementStyle({
|
|
|
310
295
|
classesProp,
|
|
311
296
|
label,
|
|
312
297
|
meta,
|
|
313
|
-
props
|
|
298
|
+
props,
|
|
299
|
+
additionalVariants = []
|
|
314
300
|
}) {
|
|
315
301
|
let id = styleId;
|
|
316
302
|
mutateElementStyles(elementId, (styles) => {
|
|
317
303
|
id ??= generateId(`e-${elementId}-`, Object.keys(styles));
|
|
304
|
+
const variants = [{ meta, props }, ...additionalVariants];
|
|
318
305
|
styles[id] = {
|
|
319
306
|
id,
|
|
320
307
|
label,
|
|
321
308
|
type: "class",
|
|
322
|
-
variants
|
|
309
|
+
variants
|
|
323
310
|
};
|
|
324
311
|
addStyleToClassesProp(elementId, classesProp, id);
|
|
325
312
|
return styles;
|
|
@@ -373,18 +360,17 @@ export {
|
|
|
373
360
|
ELEMENT_STYLE_CHANGE_EVENT,
|
|
374
361
|
createElementStyle,
|
|
375
362
|
deleteElementStyle,
|
|
363
|
+
getContainer,
|
|
376
364
|
getElementLabel,
|
|
377
365
|
getElementSetting,
|
|
378
366
|
getElementStyles,
|
|
379
367
|
getElements,
|
|
380
368
|
getSelectedElements,
|
|
381
369
|
getWidgetsCache,
|
|
382
|
-
isElementInContainer,
|
|
383
370
|
styleRerenderEvents,
|
|
384
371
|
updateElementSettings,
|
|
385
372
|
updateElementStyle,
|
|
386
373
|
useElementSetting,
|
|
387
|
-
useElementStyles,
|
|
388
374
|
useElementType,
|
|
389
375
|
useElementsDomRef,
|
|
390
376
|
useParentElement,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-elements-dom-ref.ts","../src/sync/get-current-document-container.ts","../src/hooks/use-element-setting.ts","../src/sync/get-container.ts","../src/sync/get-element-setting.ts","../src/hooks/use-element-styles.ts","../src/styles/consts.ts","../src/sync/get-element-styles.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-parent-element.ts","../src/errors.ts","../src/sync/get-element-label.ts","../src/sync/get-elements.ts","../src/sync/is-element-in-container.ts","../src/sync/update-element-settings.ts","../src/styles/create-element-style.ts","../src/styles/mutate-element-styles.ts","../src/styles/update-element-style.ts","../src/styles/delete-element-style.ts"],"sourcesContent":["import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport getCurrentDocumentContainer from '../sync/get-current-document-container';\n\nconst ELEMENTS_DATA_ATTR = 'data-atomic';\n\nexport function useElementsDomRef(): HTMLElement[] {\n\treturn useListenTo(\n\t\t[\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/render' ),\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/destroy' ),\n\t\t\twindowEvent( 'elementor/editor/element-rendered' ),\n\t\t\twindowEvent( 'elementor/editor/element-destroyed' ),\n\t\t],\n\t\t() => getElementsDom()\n\t);\n}\n\nfunction getElementsDom(): HTMLElement[] {\n\tconst root = getCurrentDocumentContainer();\n\n\tif ( ! root?.view ) {\n\t\treturn [];\n\t}\n\n\treturn [ ...root.view.el.querySelectorAll< HTMLElement >( `[${ ELEMENTS_DATA_ATTR }]` ) ];\n}\n","import { type ExtendedWindow } from './types';\n\nexport default function getCurrentDocumentContainer() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { type ElementID } from '../types';\n\nexport const useElementSetting = < TValue >( elementId: ElementID, settingKey: string ) => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/set-settings' ),\n\t\t() => getElementSetting< TValue >( elementId, settingKey ),\n\t\t[ elementId, settingKey ]\n\t);\n};\n","import { type ExtendedWindow } from './types';\n\nexport default function getContainer( id: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\tconst container = extendedWindow.elementor?.getContainer?.( id );\n\n\treturn container ?? null;\n}\n","import { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementSetting = < TValue >( elementId: ElementID, settingKey: string ): TValue | null => {\n\tconst container = getContainer( elementId );\n\tconst value = container?.settings?.get( settingKey ) as TValue;\n\n\treturn value ?? null;\n};\n","import { __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\n\nimport { styleRerenderEvents } from '../styles/consts';\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport function useElementStyles( elementId: ElementID ) {\n\treturn useListenTo( styleRerenderEvents, () => getElementStyles( elementId ) ?? {}, [ elementId ] );\n}\n","import { commandEndEvent, windowEvent } from '@elementor/editor-v1-adapters';\n\nexport const ELEMENT_STYLE_CHANGE_EVENT = 'elementor/editor-v2/editor-elements/style';\n\nexport const styleRerenderEvents = [\n\tcommandEndEvent( 'document/elements/create' ),\n\tcommandEndEvent( 'editor/documents/attach-preview' ),\n\twindowEvent( ELEMENT_STYLE_CHANGE_EVENT ),\n];\n","import { type StyleDefinition } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {\n\tconst container = getContainer( elementID );\n\n\treturn container?.model.get( 'styles' ) || null;\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementType } from '../types';\n\nexport function useElementType( type?: string ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'editor/documents/load' ),\n\t\t(): ElementType | null => {\n\t\t\tif ( ! type ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst widgetsCache = getWidgetsCache();\n\t\t\tconst elementType = widgetsCache?.[ type ];\n\n\t\t\tif ( ! elementType?.atomic_controls ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif ( ! elementType?.atomic_props_schema ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\n\t\t\t\tpropsSchema: elementType.atomic_props_schema,\n\t\t\t\ttitle: elementType.title,\n\t\t\t};\n\t\t},\n\t\t[ type ]\n\t);\n}\n","import { type ExtendedWindow } from './types';\n\nexport function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getSelectedElements } from '../sync/get-selected-elements';\nimport { useElementType } from './use-element-type';\n\nexport function useSelectedElement() {\n\tconst elements = useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\tgetSelectedElements\n\t);\n\n\tconst [ element ] = elements;\n\n\tconst elementType = useElementType( element?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn { element: null, elementType: null };\n\t}\n\n\treturn { element, elementType };\n}\n","import { type Element } from '../types';\nimport { type ExtendedWindow } from './types';\n\nexport function getSelectedElements(): Element[] {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];\n\n\treturn selectedElements.reduce< Element[] >( ( acc, el ) => {\n\t\tconst type = el.model.get( 'widgetType' ) || el.model.get( 'elType' );\n\n\t\tif ( type ) {\n\t\t\tacc.push( {\n\t\t\t\tid: el.model.get( 'id' ),\n\t\t\t\ttype,\n\t\t\t} );\n\t\t}\n\n\t\treturn acc;\n\t}, [] );\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { type ExtendedWindow } from '../sync/types';\n\nexport function useParentElement( elementId: string | null ) {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/create' ) ],\n\t\t() => {\n\t\t\tif ( ! elementId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst extendedWindow = window as unknown as ExtendedWindow;\n\t\t\tconst element = extendedWindow?.elementor?.getContainer?.( elementId );\n\t\t\tif ( ! element ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn element.parent;\n\t\t},\n\t\t[ elementId ]\n\t);\n}\n","import { createError } from '@elementor/utils';\n\nexport const ElementNotFoundError = createError< { elementId: string } >( {\n\tcode: 'element_not_found',\n\tmessage: 'Element not found.',\n} );\n\nexport const StyleNotFoundError = createError< { styleId: string } >( {\n\tcode: 'style_not_found',\n\tmessage: 'Style not found.',\n} );\n\nexport const ElementTypeNotExistsError = createError< { elementId: string } >( {\n\tcode: 'element_type_not_exists',\n\tmessage: 'Element type does not exist.',\n} );\n\nexport const ElementLabelNotExistsError = createError< { elementType: string } >( {\n\tcode: 'element_label_not_exists',\n\tmessage: 'Element label does not exist.',\n} );\n","import { ElementLabelNotExistsError, ElementTypeNotExistsError } from '../errors';\nimport getContainer from '../sync/get-container';\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementID } from '../types';\n\nexport function getElementLabel( elementId: ElementID ) {\n\tconst container = getContainer( elementId );\n\n\tconst type = container?.model.get( 'widgetType' ) || container?.model.get( 'elType' );\n\n\tif ( ! type ) {\n\t\tthrow new ElementTypeNotExistsError( { context: { elementId } } );\n\t}\n\n\tconst label = getWidgetsCache()?.[ type ]?.title;\n\n\tif ( ! label ) {\n\t\tthrow new ElementLabelNotExistsError( { context: { elementType: type } } );\n\t}\n\n\treturn label;\n}\n","import { type ElementID } from '../types';\nimport getContainer from './get-container';\nimport getCurrentDocumentContainer from './get-current-document-container';\nimport { type V1Element } from './types';\n\nexport function getElements( root?: ElementID ): V1Element[] {\n\tconst container = root ? getContainer( root ) : getCurrentDocumentContainer();\n\n\tif ( ! container ) {\n\t\treturn [];\n\t}\n\n\tconst children = container.children?.flatMap( ( child ) => getElements( child.id ) ) ?? [];\n\n\treturn [ container, ...children ];\n}\n","import { type Element } from '../types';\nimport { type V1Element } from './types';\n\nexport const isElementInContainer = ( element: Element, container: V1Element ): boolean => {\n\tif ( container.model.get( 'id' ) === element.id && container.model.get( 'widgetType' ) === element.type ) {\n\t\treturn true;\n\t}\n\n\tif ( container.children && container.children.length > 0 ) {\n\t\treturn container.children.some( ( child ) => isElementInContainer( element, child ) );\n\t}\n\n\treturn false;\n};\n","import { type Props } from '@elementor/editor-props';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport type UpdateElementSettingsArgs = {\n\tid: ElementID;\n\tprops: Props;\n\twithHistory?: boolean;\n};\n\nexport const updateElementSettings = ( { id, props, withHistory = true }: UpdateElementSettingsArgs ) => {\n\tconst container = getContainer( id );\n\n\tconst args = {\n\t\tcontainer,\n\t\tsettings: { ...props },\n\t};\n\n\tif ( withHistory ) {\n\t\trunCommandSync( 'document/elements/settings', args );\n\t} else {\n\t\trunCommandSync( 'document/elements/set-settings', args, { internal: true } );\n\t}\n};\n","import { classesPropTypeUtil } from '@elementor/editor-props';\nimport {\n\tgenerateId,\n\ttype StyleDefinition,\n\ttype StyleDefinitionID,\n\ttype StyleDefinitionVariant,\n} from '@elementor/editor-styles';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type CreateElementStyleArgs = {\n\tstyleId?: StyleDefinitionID;\n\telementId: ElementID;\n\tclassesProp: string;\n\tlabel: string;\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n};\n\nexport function createElementStyle( {\n\tstyleId,\n\telementId,\n\tclassesProp,\n\tlabel,\n\tmeta,\n\tprops,\n}: CreateElementStyleArgs ): string {\n\tlet id = styleId;\n\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\tid ??= generateId( `e-${ elementId }-`, Object.keys( styles ) );\n\n\t\tstyles[ id ] = {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\ttype: 'class',\n\t\t\tvariants: [ { meta, props } ],\n\t\t} satisfies StyleDefinition;\n\n\t\taddStyleToClassesProp( elementId, classesProp, id );\n\n\t\treturn styles;\n\t} );\n\n\treturn id as string;\n}\n\nfunction addStyleToClassesProp( elementId: ElementID, classesProp: string, styleId: string ) {\n\tconst base = getElementSetting( elementId, classesProp );\n\n\tconst classesPropValue = classesPropTypeUtil.create(\n\t\t( prev ) => {\n\t\t\treturn [ ...( prev ?? [] ), styleId ];\n\t\t},\n\t\t{ base }\n\t);\n\n\tupdateElementSettings( {\n\t\tid: elementId,\n\t\tprops: {\n\t\t\t[ classesProp ]: classesPropValue,\n\t\t},\n\t\twithHistory: false,\n\t} );\n}\n","import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';\nimport { type StyleDefinition, type StyleDefinitionsMap } from '@elementor/editor-styles';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { ElementNotFoundError } from '../errors';\nimport getContainer from '../sync/get-container';\nimport { type V1Element } from '../sync/types';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { ELEMENT_STYLE_CHANGE_EVENT } from './consts';\n\ntype Mutator = ( styles: StyleDefinitionsMap ) => StyleDefinitionsMap;\n\nexport function mutateElementStyles( elementId: ElementID, mutator: Mutator ) {\n\tconst container = getContainer( elementId );\n\n\tif ( ! container ) {\n\t\tthrow new ElementNotFoundError( { context: { elementId } } );\n\t}\n\n\tconst oldIds = Object.keys( container.model.get( 'styles' ) ?? {} );\n\n\tconst styles = mutateStyles( container, mutator );\n\n\tconst newIds = Object.keys( styles );\n\n\tclearRemovedClasses( container, {\n\t\toldIds,\n\t\tnewIds,\n\t} );\n\n\tnotifyChanges();\n\n\treturn styles;\n}\n\nfunction mutateStyles( container: V1Element, mutator: Mutator ) {\n\tconst styles: StyleDefinitionsMap = structuredClone( container.model.get( 'styles' ) ) ?? {};\n\n\tconst entries = Object.entries( mutator( styles ) )\n\t\t.map( ( [ styleId, style ] ) => {\n\t\t\tstyle.variants = removeEmptyVariants( style );\n\n\t\t\treturn [ styleId, style ] as const;\n\t\t} )\n\t\t.filter( ( [ , style ] ) => {\n\t\t\treturn ! isStyleEmpty( style );\n\t\t} );\n\n\tconst mutatedStyles = Object.fromEntries( entries );\n\n\tcontainer.model.set( 'styles', mutatedStyles );\n\n\treturn mutatedStyles;\n}\n\nfunction removeEmptyVariants( style: StyleDefinition ) {\n\treturn style.variants.filter( ( { props } ) => Object.keys( props ).length > 0 );\n}\n\nfunction isStyleEmpty( style: StyleDefinition ) {\n\treturn style.variants.length === 0;\n}\n\nfunction clearRemovedClasses( container: V1Element, { oldIds, newIds }: { oldIds: string[]; newIds: string[] } ) {\n\tconst removedIds = oldIds.filter( ( id ) => ! newIds.includes( id ) );\n\tconst classesProps = structuredClone( getClassesProps( container ) );\n\n\tclassesProps.forEach( ( [ , prop ] ) => {\n\t\tprop.value = prop.value.filter( ( value ) => ! removedIds.includes( value ) );\n\t} );\n\n\tupdateElementSettings( {\n\t\tid: container.id,\n\t\tprops: Object.fromEntries( classesProps ),\n\t\twithHistory: false,\n\t} );\n}\n\nfunction getClassesProps( container: V1Element ) {\n\treturn Object.entries( container.settings.toJSON() ).filter( ( prop ): prop is [ string, ClassesPropValue ] => {\n\t\tconst [ , value ] = prop;\n\n\t\treturn classesPropTypeUtil.isValid( value );\n\t} );\n}\n\nfunction notifyChanges() {\n\tdispatchChangeEvent();\n\trunCommandSync( 'document/save/set-is-modified', { status: true }, { internal: true } );\n}\n\nfunction dispatchChangeEvent() {\n\twindow.dispatchEvent( new CustomEvent( ELEMENT_STYLE_CHANGE_EVENT ) );\n}\n","import { mergeProps } from '@elementor/editor-props';\nimport { getVariantByMeta, type StyleDefinition, type StyleDefinitionVariant } from '@elementor/editor-styles';\n\nimport { StyleNotFoundError } from '../errors';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type UpdateElementStyleArgs = {\n\telementId: ElementID;\n\tstyleId: StyleDefinition[ 'id' ];\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n};\n\nexport function updateElementStyle( args: UpdateElementStyleArgs ) {\n\tmutateElementStyles( args.elementId, ( styles ) => {\n\t\tconst style = styles[ args.styleId ];\n\n\t\tif ( ! style ) {\n\t\t\tthrow new StyleNotFoundError( { context: { styleId: args.styleId } } );\n\t\t}\n\n\t\tconst variant = getVariantByMeta( style, args.meta );\n\n\t\tif ( variant ) {\n\t\t\tvariant.props = mergeProps( variant.props, args.props );\n\t\t} else {\n\t\t\tstyle.variants.push( { meta: args.meta, props: args.props } );\n\t\t}\n\n\t\treturn styles;\n\t} );\n}\n","import { type StyleDefinitionID } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport function deleteElementStyle( elementId: ElementID, styleId: StyleDefinitionID ) {\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\t// The object is deep cloned so mutating it is fine.\n\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\tdelete styles[ styleId ];\n\n\t\treturn styles;\n\t} );\n}\n"],"mappings":";AAAA,SAAS,wBAAwB,aAAa,mBAAmB;;;ACElD,SAAR,8BAA+C;AACrD,QAAM,iBAAiB;AAEvB,SAAO,eAAe,WAAW,WAAW,aAAa,GAAG,aAAa;AAC1E;;;ADFA,IAAM,qBAAqB;AAEpB,SAAS,oBAAmC;AAClD,SAAO;AAAA,IACN;AAAA,MACC,YAAa,wCAAyC;AAAA,MACtD,YAAa,yCAA0C;AAAA,MACvD,YAAa,mCAAoC;AAAA,MACjD,YAAa,oCAAqC;AAAA,IACnD;AAAA,IACA,MAAM,eAAe;AAAA,EACtB;AACD;AAEA,SAAS,iBAAgC;AACxC,QAAM,OAAO,4BAA4B;AAEzC,MAAK,CAAE,MAAM,MAAO;AACnB,WAAO,CAAC;AAAA,EACT;AAEA,SAAO,CAAE,GAAG,KAAK,KAAK,GAAG,iBAAiC,IAAK,kBAAmB,GA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,iBAAkB,OAAO,KAAK,IAAK;AAEnD,QAAK,SAAU;AACd,cAAQ,QAAQ,WAAY,QAAQ,OAAO,KAAK,KAAM;AAAA,IACvD,OAAO;AACN,YAAM,SAAS,KAAM,EAAE,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,CAAE;AAAA,IAC7D;AAEA,WAAO;AAAA,EACR,CAAE;AACH;;;AC3BO,SAAS,mBAAoB,WAAsB,SAA6B;AACtF,sBAAqB,WAAW,CAAE,WAAY;AAG7C,WAAO,OAAQ,OAAQ;AAEvB,WAAO;AAAA,EACR,CAAE;AACH;","names":["useListenTo","useListenTo","useListenTo","commandEndEvent","windowEvent","useListenTo","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","classesPropTypeUtil","runCommandSync","runCommandSync","classesPropTypeUtil"]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-elements-dom-ref.ts","../src/sync/get-current-document-container.ts","../src/hooks/use-element-setting.ts","../src/sync/get-container.ts","../src/sync/get-element-setting.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-parent-element.ts","../src/sync/get-element-styles.ts","../src/errors.ts","../src/sync/get-element-label.ts","../src/sync/get-elements.ts","../src/sync/update-element-settings.ts","../src/styles/consts.ts","../src/styles/create-element-style.ts","../src/styles/mutate-element-styles.ts","../src/styles/update-element-style.ts","../src/styles/delete-element-style.ts"],"sourcesContent":["import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport getCurrentDocumentContainer from '../sync/get-current-document-container';\n\nconst ELEMENTS_DATA_ATTR = 'data-atomic';\n\nexport function useElementsDomRef(): HTMLElement[] {\n\treturn useListenTo(\n\t\t[\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/render' ),\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/destroy' ),\n\t\t\twindowEvent( 'elementor/editor/element-rendered' ),\n\t\t\twindowEvent( 'elementor/editor/element-destroyed' ),\n\t\t],\n\t\t() => getElementsDom()\n\t);\n}\n\nfunction getElementsDom(): HTMLElement[] {\n\tconst root = getCurrentDocumentContainer();\n\n\tif ( ! root?.view ) {\n\t\treturn [];\n\t}\n\n\treturn [ ...root.view.el.querySelectorAll< HTMLElement >( `[${ ELEMENTS_DATA_ATTR }]` ) ];\n}\n","import { type ExtendedWindow } from './types';\n\nexport default function getCurrentDocumentContainer() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { type ElementID } from '../types';\n\nexport const useElementSetting = < TValue >( elementId: ElementID, settingKey: string ) => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/set-settings' ),\n\t\t() => getElementSetting< TValue >( elementId, settingKey ),\n\t\t[ elementId, settingKey ]\n\t);\n};\n","import { type ExtendedWindow } from './types';\n\nexport function getContainer( id: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\tconst container = extendedWindow.elementor?.getContainer?.( id );\n\n\treturn container ?? null;\n}\n","import { type ElementID } from '../types';\nimport { getContainer } from './get-container';\n\nexport const getElementSetting = < TValue >( elementId: ElementID, settingKey: string ): TValue | null => {\n\tconst container = getContainer( elementId );\n\tconst value = container?.settings?.get( settingKey ) as TValue;\n\n\treturn value ?? null;\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementType } from '../types';\n\nexport function useElementType( type?: string ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'editor/documents/load' ),\n\t\t(): ElementType | null => {\n\t\t\tif ( ! type ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst widgetsCache = getWidgetsCache();\n\t\t\tconst elementType = widgetsCache?.[ type ];\n\n\t\t\tif ( ! elementType?.atomic_controls ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif ( ! elementType?.atomic_props_schema ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\n\t\t\t\tpropsSchema: elementType.atomic_props_schema,\n\t\t\t\ttitle: elementType.title,\n\t\t\t};\n\t\t},\n\t\t[ type ]\n\t);\n}\n","import { type ExtendedWindow } from './types';\n\nexport function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getSelectedElements } from '../sync/get-selected-elements';\nimport { useElementType } from './use-element-type';\n\nexport function useSelectedElement() {\n\tconst elements = useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\tgetSelectedElements\n\t);\n\n\tconst [ element ] = elements;\n\n\tconst elementType = useElementType( element?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn { element: null, elementType: null };\n\t}\n\n\treturn { element, elementType };\n}\n","import { type Element } from '../types';\nimport { type ExtendedWindow } from './types';\n\nexport function getSelectedElements(): Element[] {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];\n\n\treturn selectedElements.reduce< Element[] >( ( acc, el ) => {\n\t\tconst type = el.model.get( 'widgetType' ) || el.model.get( 'elType' );\n\n\t\tif ( type ) {\n\t\t\tacc.push( {\n\t\t\t\tid: el.model.get( 'id' ),\n\t\t\t\ttype,\n\t\t\t} );\n\t\t}\n\n\t\treturn acc;\n\t}, [] );\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { type ExtendedWindow } from '../sync/types';\n\nexport function useParentElement( elementId: string | null ) {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/create' ) ],\n\t\t() => {\n\t\t\tif ( ! elementId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst extendedWindow = window as unknown as ExtendedWindow;\n\t\t\tconst element = extendedWindow?.elementor?.getContainer?.( elementId );\n\t\t\tif ( ! element ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn element.parent;\n\t\t},\n\t\t[ elementId ]\n\t);\n}\n","import { type StyleDefinition } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport { getContainer } from './get-container';\n\nexport const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {\n\tconst container = getContainer( elementID );\n\n\treturn container?.model.get( 'styles' ) || null;\n};\n","import { createError } from '@elementor/utils';\n\nexport const ElementNotFoundError = createError< { elementId: string } >( {\n\tcode: 'element_not_found',\n\tmessage: 'Element not found.',\n} );\n\nexport const StyleNotFoundError = createError< { styleId: string } >( {\n\tcode: 'style_not_found',\n\tmessage: 'Style not found.',\n} );\n\nexport const ElementTypeNotExistsError = createError< { elementId: string } >( {\n\tcode: 'element_type_not_exists',\n\tmessage: 'Element type does not exist.',\n} );\n\nexport const ElementLabelNotExistsError = createError< { elementType: string } >( {\n\tcode: 'element_label_not_exists',\n\tmessage: 'Element label does not exist.',\n} );\n","import { ElementLabelNotExistsError, ElementTypeNotExistsError } from '../errors';\nimport { getContainer } from '../sync/get-container';\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementID } from '../types';\n\nexport function getElementLabel( elementId: ElementID ) {\n\tconst container = getContainer( elementId );\n\n\tconst type = container?.model.get( 'widgetType' ) || container?.model.get( 'elType' );\n\n\tif ( ! type ) {\n\t\tthrow new ElementTypeNotExistsError( { context: { elementId } } );\n\t}\n\n\tconst label = getWidgetsCache()?.[ type ]?.title;\n\n\tif ( ! label ) {\n\t\tthrow new ElementLabelNotExistsError( { context: { elementType: type } } );\n\t}\n\n\treturn label;\n}\n","import { type ElementID } from '../types';\nimport { getContainer } from './get-container';\nimport getCurrentDocumentContainer from './get-current-document-container';\nimport { type V1Element } from './types';\n\nexport function getElements( root?: ElementID ): V1Element[] {\n\tconst container = root ? getContainer( root ) : getCurrentDocumentContainer();\n\n\tif ( ! container ) {\n\t\treturn [];\n\t}\n\n\tconst children = [ ...( container.model.get( 'elements' ) ?? [] ) ].flatMap( ( childModel ) =>\n\t\tgetElements( childModel.get( 'id' ) )\n\t);\n\n\treturn [ container, ...children ];\n}\n","import { type Props } from '@elementor/editor-props';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport { getContainer } from './get-container';\n\nexport type UpdateElementSettingsArgs = {\n\tid: ElementID;\n\tprops: Props;\n\twithHistory?: boolean;\n};\n\nexport const updateElementSettings = ( { id, props, withHistory = true }: UpdateElementSettingsArgs ) => {\n\tconst container = getContainer( id );\n\n\tconst args = {\n\t\tcontainer,\n\t\tsettings: { ...props },\n\t};\n\n\tif ( withHistory ) {\n\t\trunCommandSync( 'document/elements/settings', args );\n\t} else {\n\t\trunCommandSync( 'document/elements/set-settings', args, { internal: true } );\n\t}\n};\n","import { commandEndEvent, windowEvent } from '@elementor/editor-v1-adapters';\n\nexport const ELEMENT_STYLE_CHANGE_EVENT = 'elementor/editor-v2/editor-elements/style';\n\nexport const styleRerenderEvents = [\n\tcommandEndEvent( 'document/elements/create' ),\n\tcommandEndEvent( 'document/elements/duplicate' ),\n\tcommandEndEvent( 'document/elements/import' ),\n\tcommandEndEvent( 'document/elements/paste' ),\n\twindowEvent( ELEMENT_STYLE_CHANGE_EVENT ),\n];\n","import { classesPropTypeUtil } from '@elementor/editor-props';\nimport {\n\tgenerateId,\n\ttype StyleDefinition,\n\ttype StyleDefinitionID,\n\ttype StyleDefinitionVariant,\n} from '@elementor/editor-styles';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type CreateElementStyleArgs = {\n\tstyleId?: StyleDefinitionID;\n\telementId: ElementID;\n\tclassesProp: string;\n\tlabel: string;\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n\tadditionalVariants?: StyleDefinitionVariant[];\n};\n\nexport function createElementStyle( {\n\tstyleId,\n\telementId,\n\tclassesProp,\n\tlabel,\n\tmeta,\n\tprops,\n\tadditionalVariants = [],\n}: CreateElementStyleArgs ): string {\n\tlet id = styleId;\n\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\tid ??= generateId( `e-${ elementId }-`, Object.keys( styles ) );\n\n\t\tconst variants = [ { meta, props }, ...additionalVariants ];\n\n\t\tstyles[ id ] = {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\ttype: 'class',\n\t\t\tvariants,\n\t\t} satisfies StyleDefinition;\n\n\t\taddStyleToClassesProp( elementId, classesProp, id );\n\n\t\treturn styles;\n\t} );\n\n\treturn id as string;\n}\n\nfunction addStyleToClassesProp( elementId: ElementID, classesProp: string, styleId: string ) {\n\tconst base = getElementSetting( elementId, classesProp );\n\n\tconst classesPropValue = classesPropTypeUtil.create(\n\t\t( prev ) => {\n\t\t\treturn [ ...( prev ?? [] ), styleId ];\n\t\t},\n\t\t{ base }\n\t);\n\n\tupdateElementSettings( {\n\t\tid: elementId,\n\t\tprops: {\n\t\t\t[ classesProp ]: classesPropValue,\n\t\t},\n\t\twithHistory: false,\n\t} );\n}\n","import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';\nimport { type StyleDefinition, type StyleDefinitionsMap } from '@elementor/editor-styles';\nimport { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';\n\nimport { ElementNotFoundError } from '../errors';\nimport { getContainer } from '../sync/get-container';\nimport { type V1Element } from '../sync/types';\nimport { updateElementSettings } from '../sync/update-element-settings';\nimport { type ElementID } from '../types';\nimport { ELEMENT_STYLE_CHANGE_EVENT } from './consts';\n\ntype Mutator = ( styles: StyleDefinitionsMap ) => StyleDefinitionsMap;\n\nexport function mutateElementStyles( elementId: ElementID, mutator: Mutator ) {\n\tconst container = getContainer( elementId );\n\n\tif ( ! container ) {\n\t\tthrow new ElementNotFoundError( { context: { elementId } } );\n\t}\n\n\tconst oldIds = Object.keys( container.model.get( 'styles' ) ?? {} );\n\n\tconst styles = mutateStyles( container, mutator );\n\n\tconst newIds = Object.keys( styles );\n\n\tclearRemovedClasses( container, {\n\t\toldIds,\n\t\tnewIds,\n\t} );\n\n\tnotifyChanges();\n\n\treturn styles;\n}\n\nfunction mutateStyles( container: V1Element, mutator: Mutator ) {\n\tconst styles: StyleDefinitionsMap = structuredClone( container.model.get( 'styles' ) ) ?? {};\n\n\tconst entries = Object.entries( mutator( styles ) )\n\t\t.map( ( [ styleId, style ] ) => {\n\t\t\tstyle.variants = removeEmptyVariants( style );\n\n\t\t\treturn [ styleId, style ] as const;\n\t\t} )\n\t\t.filter( ( [ , style ] ) => {\n\t\t\treturn ! isStyleEmpty( style );\n\t\t} );\n\n\tconst mutatedStyles = Object.fromEntries( entries );\n\n\tcontainer.model.set( 'styles', mutatedStyles );\n\n\treturn mutatedStyles;\n}\n\nfunction removeEmptyVariants( style: StyleDefinition ) {\n\treturn style.variants.filter( ( { props } ) => Object.keys( props ).length > 0 );\n}\n\nfunction isStyleEmpty( style: StyleDefinition ) {\n\treturn style.variants.length === 0;\n}\n\nfunction clearRemovedClasses( container: V1Element, { oldIds, newIds }: { oldIds: string[]; newIds: string[] } ) {\n\tconst removedIds = oldIds.filter( ( id ) => ! newIds.includes( id ) );\n\tconst classesProps = structuredClone( getClassesProps( container ) );\n\n\tclassesProps.forEach( ( [ , prop ] ) => {\n\t\tprop.value = prop.value.filter( ( value ) => ! removedIds.includes( value ) );\n\t} );\n\n\tupdateElementSettings( {\n\t\tid: container.id,\n\t\tprops: Object.fromEntries( classesProps ),\n\t\twithHistory: false,\n\t} );\n}\n\nfunction getClassesProps( container: V1Element ) {\n\treturn Object.entries( container.settings.toJSON() ).filter( ( prop ): prop is [ string, ClassesPropValue ] => {\n\t\tconst [ , value ] = prop;\n\n\t\treturn classesPropTypeUtil.isValid( value );\n\t} );\n}\n\nfunction notifyChanges() {\n\tdispatchChangeEvent();\n\trunCommandSync( 'document/save/set-is-modified', { status: true }, { internal: true } );\n}\n\nfunction dispatchChangeEvent() {\n\twindow.dispatchEvent( new CustomEvent( ELEMENT_STYLE_CHANGE_EVENT ) );\n}\n","import { mergeProps } from '@elementor/editor-props';\nimport { getVariantByMeta, type StyleDefinition, type StyleDefinitionVariant } from '@elementor/editor-styles';\n\nimport { StyleNotFoundError } from '../errors';\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport type UpdateElementStyleArgs = {\n\telementId: ElementID;\n\tstyleId: StyleDefinition[ 'id' ];\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n};\n\nexport function updateElementStyle( args: UpdateElementStyleArgs ) {\n\tmutateElementStyles( args.elementId, ( styles ) => {\n\t\tconst style = styles[ args.styleId ];\n\n\t\tif ( ! style ) {\n\t\t\tthrow new StyleNotFoundError( { context: { styleId: args.styleId } } );\n\t\t}\n\n\t\tconst variant = getVariantByMeta( style, args.meta );\n\n\t\tif ( variant ) {\n\t\t\tvariant.props = mergeProps( variant.props, args.props );\n\t\t} else {\n\t\t\tstyle.variants.push( { meta: args.meta, props: args.props } );\n\t\t}\n\n\t\treturn styles;\n\t} );\n}\n","import { type StyleDefinitionID } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport { mutateElementStyles } from './mutate-element-styles';\n\nexport function deleteElementStyle( elementId: ElementID, styleId: StyleDefinitionID ) {\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\t// The object is deep cloned so mutating it is fine.\n\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\tdelete styles[ styleId ];\n\n\t\treturn styles;\n\t} );\n}\n"],"mappings":";AAAA,SAAS,wBAAwB,aAAa,mBAAmB;;;ACElD,SAAR,8BAA+C;AACrD,QAAM,iBAAiB;AAEvB,SAAO,eAAe,WAAW,WAAW,aAAa,GAAG,aAAa;AAC1E;;;ADFA,IAAM,qBAAqB;AAEpB,SAAS,oBAAmC;AAClD,SAAO;AAAA,IACN;AAAA,MACC,YAAa,wCAAyC;AAAA,MACtD,YAAa,yCAA0C;AAAA,MACvD,YAAa,mCAAoC;AAAA,MACjD,YAAa,oCAAqC;AAAA,IACnD;AAAA,IACA,MAAM,eAAe;AAAA,EACtB;AACD;AAEA,SAAS,iBAAgC;AACxC,QAAM,OAAO,4BAA4B;AAEzC,MAAK,CAAE,MAAM,MAAO;AACnB,WAAO,CAAC;AAAA,EACT;AAEA,SAAO,CAAE,GAAG,KAAK,KAAK,GAAG,iBAAiC,IAAK,kBAAmB,GAAI,CAAE;AACzF;;;AE1BA,SAAS,wBAAwBA,cAAa,uBAAuB;;;ACE9D,SAAS,aAAc,IAAa;AAC1C,QAAM,iBAAiB;AACvB,QAAM,YAAY,eAAe,WAAW,eAAgB,EAAG;AAE/D,SAAO,aAAa;AACrB;;;ACJO,IAAM,oBAAoB,CAAY,WAAsB,eAAuC;AACzG,QAAM,YAAY,aAAc,SAAU;AAC1C,QAAM,QAAQ,WAAW,UAAU,IAAK,UAAW;AAEnD,SAAO,SAAS;AACjB;;;AFHO,IAAM,oBAAoB,CAAY,WAAsB,eAAwB;AAC1F,SAAOC;AAAA,IACN,gBAAiB,gCAAiC;AAAA,IAClD,MAAM,kBAA6B,WAAW,UAAW;AAAA,IACzD,CAAE,WAAW,UAAW;AAAA,EACzB;AACD;;;AGXA,SAAS,wBAAwBC,cAAa,mBAAAC,wBAAuB;;;ACE9D,SAAS,kBAAkB;AACjC,QAAM,i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,OAAO;AAAA,MACN,CAAE,WAAY,GAAG;AAAA,IAClB;AAAA,IACA,aAAa;AAAA,EACd,CAAE;AACH;;;AEvEA,SAAS,kBAAkB;AAC3B,SAAS,wBAA2E;AAa7E,SAAS,mBAAoB,MAA+B;AAClE,sBAAqB,KAAK,WAAW,CAAE,WAAY;AAClD,UAAM,QAAQ,OAAQ,KAAK,OAAQ;AAEnC,QAAK,CAAE,OAAQ;AACd,YAAM,IAAI,mBAAoB,EAAE,SAAS,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAE;AAAA,IACtE;AAEA,UAAM,UAAU,iBAAkB,OAAO,KAAK,IAAK;AAEnD,QAAK,SAAU;AACd,cAAQ,QAAQ,WAAY,QAAQ,OAAO,KAAK,KAAM;AAAA,IACvD,OAAO;AACN,YAAM,SAAS,KAAM,EAAE,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,CAAE;AAAA,IAC7D;AAEA,WAAO;AAAA,EACR,CAAE;AACH;;;AC3BO,SAAS,mBAAoB,WAAsB,SAA6B;AACtF,sBAAqB,WAAW,CAAE,WAAY;AAG7C,WAAO,OAAQ,OAAQ;AAEvB,WAAO;AAAA,EACR,CAAE;AACH;","names":["useListenTo","useListenTo","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","commandEndEvent","windowEvent","classesPropTypeUtil","runCommandSync","runCommandSync","classesPropTypeUtil"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-elements",
|
|
3
3
|
"description": "This package contains the elements model for the Elementor editor",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-props": "0.
|
|
44
|
-
"@elementor/editor-styles": "0.6.
|
|
45
|
-
"@elementor/editor-v1-adapters": "0.
|
|
43
|
+
"@elementor/editor-props": "0.11.0",
|
|
44
|
+
"@elementor/editor-styles": "0.6.3",
|
|
45
|
+
"@elementor/editor-v1-adapters": "0.11.0",
|
|
46
46
|
"@elementor/utils": "0.4.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -5,19 +5,18 @@ export type { V1Element, V1ElementModelProps, V1ElementSettingsProps } from './s
|
|
|
5
5
|
// hooks
|
|
6
6
|
export { useElementsDomRef } from './hooks/use-elements-dom-ref';
|
|
7
7
|
export { useElementSetting } from './hooks/use-element-setting';
|
|
8
|
-
export { useElementStyles } from './hooks/use-element-styles';
|
|
9
8
|
export { useElementType } from './hooks/use-element-type';
|
|
10
9
|
export { useSelectedElement } from './hooks/use-selected-element';
|
|
11
10
|
export { useParentElement } from './hooks/use-parent-element';
|
|
12
11
|
|
|
13
12
|
// utils
|
|
13
|
+
export { getContainer } from './sync/get-container';
|
|
14
14
|
export { getElementSetting } from './sync/get-element-setting';
|
|
15
15
|
export { getElementStyles } from './sync/get-element-styles';
|
|
16
16
|
export { getElementLabel } from './sync/get-element-label';
|
|
17
17
|
export { getElements } from './sync/get-elements';
|
|
18
18
|
export { getSelectedElements } from './sync/get-selected-elements';
|
|
19
19
|
export { getWidgetsCache } from './sync/get-widgets-cache';
|
|
20
|
-
export { isElementInContainer } from './sync/is-element-in-container';
|
|
21
20
|
export { updateElementSettings, type UpdateElementSettingsArgs } from './sync/update-element-settings';
|
|
22
21
|
|
|
23
22
|
export { ELEMENT_STYLE_CHANGE_EVENT, styleRerenderEvents } from './styles/consts';
|
package/src/styles/consts.ts
CHANGED
|
@@ -4,6 +4,8 @@ export const ELEMENT_STYLE_CHANGE_EVENT = 'elementor/editor-v2/editor-elements/s
|
|
|
4
4
|
|
|
5
5
|
export const styleRerenderEvents = [
|
|
6
6
|
commandEndEvent( 'document/elements/create' ),
|
|
7
|
-
commandEndEvent( '
|
|
7
|
+
commandEndEvent( 'document/elements/duplicate' ),
|
|
8
|
+
commandEndEvent( 'document/elements/import' ),
|
|
9
|
+
commandEndEvent( 'document/elements/paste' ),
|
|
8
10
|
windowEvent( ELEMENT_STYLE_CHANGE_EVENT ),
|
|
9
11
|
];
|
|
@@ -18,6 +18,7 @@ export type CreateElementStyleArgs = {
|
|
|
18
18
|
label: string;
|
|
19
19
|
meta: StyleDefinitionVariant[ 'meta' ];
|
|
20
20
|
props: StyleDefinitionVariant[ 'props' ];
|
|
21
|
+
additionalVariants?: StyleDefinitionVariant[];
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export function createElementStyle( {
|
|
@@ -27,17 +28,20 @@ export function createElementStyle( {
|
|
|
27
28
|
label,
|
|
28
29
|
meta,
|
|
29
30
|
props,
|
|
31
|
+
additionalVariants = [],
|
|
30
32
|
}: CreateElementStyleArgs ): string {
|
|
31
33
|
let id = styleId;
|
|
32
34
|
|
|
33
35
|
mutateElementStyles( elementId, ( styles ) => {
|
|
34
36
|
id ??= generateId( `e-${ elementId }-`, Object.keys( styles ) );
|
|
35
37
|
|
|
38
|
+
const variants = [ { meta, props }, ...additionalVariants ];
|
|
39
|
+
|
|
36
40
|
styles[ id ] = {
|
|
37
41
|
id,
|
|
38
42
|
label,
|
|
39
43
|
type: 'class',
|
|
40
|
-
variants
|
|
44
|
+
variants,
|
|
41
45
|
} satisfies StyleDefinition;
|
|
42
46
|
|
|
43
47
|
addStyleToClassesProp( elementId, classesProp, id );
|
|
@@ -3,7 +3,7 @@ import { type StyleDefinition, type StyleDefinitionsMap } from '@elementor/edito
|
|
|
3
3
|
import { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';
|
|
4
4
|
|
|
5
5
|
import { ElementNotFoundError } from '../errors';
|
|
6
|
-
import getContainer from '../sync/get-container';
|
|
6
|
+
import { getContainer } from '../sync/get-container';
|
|
7
7
|
import { type V1Element } from '../sync/types';
|
|
8
8
|
import { updateElementSettings } from '../sync/update-element-settings';
|
|
9
9
|
import { type ElementID } from '../types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ExtendedWindow } from './types';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function getContainer( id: string ) {
|
|
4
4
|
const extendedWindow = window as unknown as ExtendedWindow;
|
|
5
5
|
const container = extendedWindow.elementor?.getContainer?.( id );
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ElementLabelNotExistsError, ElementTypeNotExistsError } from '../errors';
|
|
2
|
-
import getContainer from '../sync/get-container';
|
|
2
|
+
import { getContainer } from '../sync/get-container';
|
|
3
3
|
import { getWidgetsCache } from '../sync/get-widgets-cache';
|
|
4
4
|
import { type ElementID } from '../types';
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ElementID } from '../types';
|
|
2
|
-
import getContainer from './get-container';
|
|
2
|
+
import { getContainer } from './get-container';
|
|
3
3
|
|
|
4
4
|
export const getElementSetting = < TValue >( elementId: ElementID, settingKey: string ): TValue | null => {
|
|
5
5
|
const container = getContainer( elementId );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type StyleDefinition } from '@elementor/editor-styles';
|
|
2
2
|
|
|
3
3
|
import { type ElementID } from '../types';
|
|
4
|
-
import getContainer from './get-container';
|
|
4
|
+
import { getContainer } from './get-container';
|
|
5
5
|
|
|
6
6
|
export const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {
|
|
7
7
|
const container = getContainer( elementID );
|
package/src/sync/get-elements.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ElementID } from '../types';
|
|
2
|
-
import getContainer from './get-container';
|
|
2
|
+
import { getContainer } from './get-container';
|
|
3
3
|
import getCurrentDocumentContainer from './get-current-document-container';
|
|
4
4
|
import { type V1Element } from './types';
|
|
5
5
|
|
|
@@ -10,7 +10,9 @@ export function getElements( root?: ElementID ): V1Element[] {
|
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const children = container.
|
|
13
|
+
const children = [ ...( container.model.get( 'elements' ) ?? [] ) ].flatMap( ( childModel ) =>
|
|
14
|
+
getElements( childModel.get( 'id' ) )
|
|
15
|
+
);
|
|
14
16
|
|
|
15
17
|
return [ container, ...children ];
|
|
16
18
|
}
|
package/src/sync/types.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type ExtendedWindow = Window & {
|
|
|
11
11
|
widgetsCache?: Record<
|
|
12
12
|
string,
|
|
13
13
|
{
|
|
14
|
+
atomic?: boolean;
|
|
14
15
|
atomic_controls?: ControlItem[];
|
|
15
16
|
atomic_props_schema?: PropsSchema;
|
|
16
17
|
controls: object;
|
|
@@ -45,6 +46,7 @@ export type V1ElementModelProps = {
|
|
|
45
46
|
elType: string;
|
|
46
47
|
id: string;
|
|
47
48
|
styles?: Record< StyleDefinitionID, StyleDefinition >;
|
|
49
|
+
elements?: V1Model< V1ElementModelProps >[];
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
export type V1ElementSettingsProps = Record< string, PropValue >;
|
|
@@ -2,7 +2,7 @@ import { type Props } from '@elementor/editor-props';
|
|
|
2
2
|
import { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';
|
|
3
3
|
|
|
4
4
|
import { type ElementID } from '../types';
|
|
5
|
-
import getContainer from './get-container';
|
|
5
|
+
import { getContainer } from './get-container';
|
|
6
6
|
|
|
7
7
|
export type UpdateElementSettingsArgs = {
|
|
8
8
|
id: ElementID;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';
|
|
2
|
-
|
|
3
|
-
import { styleRerenderEvents } from '../styles/consts';
|
|
4
|
-
import { getElementStyles } from '../sync/get-element-styles';
|
|
5
|
-
import { type ElementID } from '../types';
|
|
6
|
-
|
|
7
|
-
export function useElementStyles( elementId: ElementID ) {
|
|
8
|
-
return useListenTo( styleRerenderEvents, () => getElementStyles( elementId ) ?? {}, [ elementId ] );
|
|
9
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type Element } from '../types';
|
|
2
|
-
import { type V1Element } from './types';
|
|
3
|
-
|
|
4
|
-
export const isElementInContainer = ( element: Element, container: V1Element ): boolean => {
|
|
5
|
-
if ( container.model.get( 'id' ) === element.id && container.model.get( 'widgetType' ) === element.type ) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if ( container.children && container.children.length > 0 ) {
|
|
10
|
-
return container.children.some( ( child ) => isElementInContainer( element, child ) );
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return false;
|
|
14
|
-
};
|