@elementor/editor-elements 0.5.0 → 0.5.2
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 +30 -0
- package/dist/index.d.mts +13 -17
- package/dist/index.d.ts +13 -17
- package/dist/index.js +88 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -80
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -5
- package/src/errors.ts +21 -0
- package/src/hooks/use-element-styles.ts +3 -5
- package/src/index.ts +3 -2
- package/src/styles/consts.ts +8 -0
- package/src/styles/create-element-style.ts +20 -3
- package/src/styles/delete-element-style.ts +14 -0
- package/src/styles/mutate-element-styles.ts +20 -7
- package/src/styles/update-element-style.ts +7 -24
- package/src/sync/get-element-label.ts +22 -0
- package/src/sync/types.ts +3 -3
- package/src/types.ts +1 -3
- package/src/hooks/use-element-style-props.ts +0 -49
- package/src/styles/errors.ts +0 -11
package/dist/index.mjs
CHANGED
|
@@ -54,12 +54,17 @@ var useElementSetting = (elementId, settingKey) => {
|
|
|
54
54
|
);
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
// src/hooks/use-element-
|
|
58
|
-
import {
|
|
59
|
-
import { __privateUseListenTo as useListenTo3, windowEvent as windowEvent2 } from "@elementor/editor-v1-adapters";
|
|
57
|
+
// src/hooks/use-element-styles.ts
|
|
58
|
+
import { __privateUseListenTo as useListenTo3 } from "@elementor/editor-v1-adapters";
|
|
60
59
|
|
|
61
60
|
// src/styles/consts.ts
|
|
61
|
+
import { commandEndEvent as commandEndEvent2, windowEvent as windowEvent2 } from "@elementor/editor-v1-adapters";
|
|
62
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
|
+
];
|
|
63
68
|
|
|
64
69
|
// src/sync/get-element-styles.ts
|
|
65
70
|
var getElementStyles = (elementID) => {
|
|
@@ -67,43 +72,13 @@ var getElementStyles = (elementID) => {
|
|
|
67
72
|
return container?.model.get("styles") || null;
|
|
68
73
|
};
|
|
69
74
|
|
|
70
|
-
// src/hooks/use-element-style-props.ts
|
|
71
|
-
function useElementStyleProps({
|
|
72
|
-
elementID,
|
|
73
|
-
styleDefID,
|
|
74
|
-
meta,
|
|
75
|
-
propNames
|
|
76
|
-
}) {
|
|
77
|
-
return useListenTo3(
|
|
78
|
-
windowEvent2(ELEMENT_STYLE_CHANGE_EVENT),
|
|
79
|
-
() => {
|
|
80
|
-
if (!styleDefID) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
const styleDef = getElementStyles(elementID)?.[styleDefID];
|
|
84
|
-
if (!styleDef) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
const variant = getVariantByMeta(styleDef, meta);
|
|
88
|
-
return propNames.reduce((acc, key) => {
|
|
89
|
-
acc[key] = variant?.props[key] ?? null;
|
|
90
|
-
return acc;
|
|
91
|
-
}, {});
|
|
92
|
-
},
|
|
93
|
-
[elementID, styleDefID, JSON.stringify(propNames), meta]
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
75
|
// src/hooks/use-element-styles.ts
|
|
98
|
-
import { __privateUseListenTo as useListenTo4, windowEvent as windowEvent3 } from "@elementor/editor-v1-adapters";
|
|
99
76
|
function useElementStyles(elementId) {
|
|
100
|
-
return
|
|
101
|
-
elementId
|
|
102
|
-
]);
|
|
77
|
+
return useListenTo3(styleRerenderEvents, () => getElementStyles(elementId) ?? {}, [elementId]);
|
|
103
78
|
}
|
|
104
79
|
|
|
105
80
|
// src/hooks/use-element-type.ts
|
|
106
|
-
import { __privateUseListenTo as
|
|
81
|
+
import { __privateUseListenTo as useListenTo4, commandEndEvent as commandEndEvent3 } from "@elementor/editor-v1-adapters";
|
|
107
82
|
|
|
108
83
|
// src/sync/get-widgets-cache.ts
|
|
109
84
|
function getWidgetsCache() {
|
|
@@ -113,8 +88,8 @@ function getWidgetsCache() {
|
|
|
113
88
|
|
|
114
89
|
// src/hooks/use-element-type.ts
|
|
115
90
|
function useElementType(type) {
|
|
116
|
-
return
|
|
117
|
-
|
|
91
|
+
return useListenTo4(
|
|
92
|
+
commandEndEvent3("editor/documents/load"),
|
|
118
93
|
() => {
|
|
119
94
|
if (!type) {
|
|
120
95
|
return null;
|
|
@@ -139,7 +114,7 @@ function useElementType(type) {
|
|
|
139
114
|
}
|
|
140
115
|
|
|
141
116
|
// src/hooks/use-selected-element.ts
|
|
142
|
-
import { __privateUseListenTo as
|
|
117
|
+
import { __privateUseListenTo as useListenTo5, commandEndEvent as commandEndEvent4 } from "@elementor/editor-v1-adapters";
|
|
143
118
|
|
|
144
119
|
// src/sync/get-selected-elements.ts
|
|
145
120
|
function getSelectedElements() {
|
|
@@ -159,8 +134,8 @@ function getSelectedElements() {
|
|
|
159
134
|
|
|
160
135
|
// src/hooks/use-selected-element.ts
|
|
161
136
|
function useSelectedElement() {
|
|
162
|
-
const elements =
|
|
163
|
-
[
|
|
137
|
+
const elements = useListenTo5(
|
|
138
|
+
[commandEndEvent4("document/elements/select"), commandEndEvent4("document/elements/deselect")],
|
|
164
139
|
getSelectedElements
|
|
165
140
|
);
|
|
166
141
|
const [element] = elements;
|
|
@@ -172,10 +147,10 @@ function useSelectedElement() {
|
|
|
172
147
|
}
|
|
173
148
|
|
|
174
149
|
// src/hooks/use-parent-element.ts
|
|
175
|
-
import { __privateUseListenTo as
|
|
150
|
+
import { __privateUseListenTo as useListenTo6, commandEndEvent as commandEndEvent5 } from "@elementor/editor-v1-adapters";
|
|
176
151
|
function useParentElement(elementId) {
|
|
177
|
-
return
|
|
178
|
-
[
|
|
152
|
+
return useListenTo6(
|
|
153
|
+
[commandEndEvent5("document/elements/create")],
|
|
179
154
|
() => {
|
|
180
155
|
if (!elementId) {
|
|
181
156
|
return null;
|
|
@@ -191,6 +166,39 @@ function useParentElement(elementId) {
|
|
|
191
166
|
);
|
|
192
167
|
}
|
|
193
168
|
|
|
169
|
+
// src/errors.ts
|
|
170
|
+
import { createError } from "@elementor/utils";
|
|
171
|
+
var ElementNotFoundError = createError({
|
|
172
|
+
code: "element_not_found",
|
|
173
|
+
message: "Element not found."
|
|
174
|
+
});
|
|
175
|
+
var StyleNotFoundError = createError({
|
|
176
|
+
code: "style_not_found",
|
|
177
|
+
message: "Style not found."
|
|
178
|
+
});
|
|
179
|
+
var ElementTypeNotExistsError = createError({
|
|
180
|
+
code: "element_type_not_exists",
|
|
181
|
+
message: "Element type does not exist."
|
|
182
|
+
});
|
|
183
|
+
var ElementLabelNotExistsError = createError({
|
|
184
|
+
code: "element_label_not_exists",
|
|
185
|
+
message: "Element label does not exist."
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// src/sync/get-element-label.ts
|
|
189
|
+
function getElementLabel(elementId) {
|
|
190
|
+
const container = getContainer(elementId);
|
|
191
|
+
const type = container?.model.get("widgetType") || container?.model.get("elType");
|
|
192
|
+
if (!type) {
|
|
193
|
+
throw new ElementTypeNotExistsError({ context: { elementId } });
|
|
194
|
+
}
|
|
195
|
+
const label = getWidgetsCache()?.[type]?.title;
|
|
196
|
+
if (!label) {
|
|
197
|
+
throw new ElementLabelNotExistsError({ context: { elementType: type } });
|
|
198
|
+
}
|
|
199
|
+
return label;
|
|
200
|
+
}
|
|
201
|
+
|
|
194
202
|
// src/sync/get-elements.ts
|
|
195
203
|
function getElements(root) {
|
|
196
204
|
const container = root ? getContainer(root) : getCurrentDocumentContainer();
|
|
@@ -229,31 +237,26 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
|
|
|
229
237
|
|
|
230
238
|
// src/styles/create-element-style.ts
|
|
231
239
|
import { classesPropTypeUtil as classesPropTypeUtil2 } from "@elementor/editor-props";
|
|
232
|
-
import {
|
|
240
|
+
import {
|
|
241
|
+
generateId
|
|
242
|
+
} from "@elementor/editor-styles";
|
|
233
243
|
|
|
234
244
|
// src/styles/mutate-element-styles.ts
|
|
235
245
|
import { classesPropTypeUtil } from "@elementor/editor-props";
|
|
236
|
-
|
|
237
|
-
// src/styles/errors.ts
|
|
238
|
-
import { createError } from "@elementor/utils";
|
|
239
|
-
var ElementNotFoundError = createError({
|
|
240
|
-
code: "element_not_found",
|
|
241
|
-
message: "Element not found."
|
|
242
|
-
});
|
|
243
|
-
var StyleNotFoundError = createError({
|
|
244
|
-
code: "style_not_found",
|
|
245
|
-
message: "Style not found."
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
// src/styles/mutate-element-styles.ts
|
|
246
|
+
import { __privateRunCommandSync as runCommandSync2 } from "@elementor/editor-v1-adapters";
|
|
249
247
|
function mutateElementStyles(elementId, mutator) {
|
|
250
248
|
const container = getContainer(elementId);
|
|
251
249
|
if (!container) {
|
|
252
250
|
throw new ElementNotFoundError({ context: { elementId } });
|
|
253
251
|
}
|
|
252
|
+
const oldIds = Object.keys(container.model.get("styles") ?? {});
|
|
254
253
|
const styles = mutateStyles(container, mutator);
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
const newIds = Object.keys(styles);
|
|
255
|
+
clearRemovedClasses(container, {
|
|
256
|
+
oldIds,
|
|
257
|
+
newIds
|
|
258
|
+
});
|
|
259
|
+
notifyChanges();
|
|
257
260
|
return styles;
|
|
258
261
|
}
|
|
259
262
|
function mutateStyles(container, mutator) {
|
|
@@ -274,11 +277,11 @@ function removeEmptyVariants(style) {
|
|
|
274
277
|
function isStyleEmpty(style) {
|
|
275
278
|
return style.variants.length === 0;
|
|
276
279
|
}
|
|
277
|
-
function
|
|
278
|
-
const
|
|
280
|
+
function clearRemovedClasses(container, { oldIds, newIds }) {
|
|
281
|
+
const removedIds = oldIds.filter((id) => !newIds.includes(id));
|
|
279
282
|
const classesProps = structuredClone(getClassesProps(container));
|
|
280
283
|
classesProps.forEach(([, prop]) => {
|
|
281
|
-
prop.value = prop.value.filter((value) =>
|
|
284
|
+
prop.value = prop.value.filter((value) => !removedIds.includes(value));
|
|
282
285
|
});
|
|
283
286
|
updateElementSettings({
|
|
284
287
|
id: container.id,
|
|
@@ -292,14 +295,26 @@ function getClassesProps(container) {
|
|
|
292
295
|
return classesPropTypeUtil.isValid(value);
|
|
293
296
|
});
|
|
294
297
|
}
|
|
298
|
+
function notifyChanges() {
|
|
299
|
+
dispatchChangeEvent();
|
|
300
|
+
runCommandSync2("document/save/set-is-modified", { status: true }, { internal: true });
|
|
301
|
+
}
|
|
295
302
|
function dispatchChangeEvent() {
|
|
296
303
|
window.dispatchEvent(new CustomEvent(ELEMENT_STYLE_CHANGE_EVENT));
|
|
297
304
|
}
|
|
298
305
|
|
|
299
306
|
// src/styles/create-element-style.ts
|
|
300
|
-
function createElementStyle({
|
|
307
|
+
function createElementStyle({
|
|
308
|
+
styleId,
|
|
309
|
+
elementId,
|
|
310
|
+
classesProp,
|
|
311
|
+
label,
|
|
312
|
+
meta,
|
|
313
|
+
props
|
|
314
|
+
}) {
|
|
315
|
+
let id = styleId;
|
|
301
316
|
mutateElementStyles(elementId, (styles) => {
|
|
302
|
-
|
|
317
|
+
id ??= generateId(`e-${elementId}-`, Object.keys(styles));
|
|
303
318
|
styles[id] = {
|
|
304
319
|
id,
|
|
305
320
|
label,
|
|
@@ -309,6 +324,7 @@ function createElementStyle({ elementId, classesProp, label, meta, props }) {
|
|
|
309
324
|
addStyleToClassesProp(elementId, classesProp, id);
|
|
310
325
|
return styles;
|
|
311
326
|
});
|
|
327
|
+
return id;
|
|
312
328
|
}
|
|
313
329
|
function addStyleToClassesProp(elementId, classesProp, styleId) {
|
|
314
330
|
const base = getElementSetting(elementId, classesProp);
|
|
@@ -328,46 +344,46 @@ function addStyleToClassesProp(elementId, classesProp, styleId) {
|
|
|
328
344
|
}
|
|
329
345
|
|
|
330
346
|
// src/styles/update-element-style.ts
|
|
331
|
-
import {
|
|
347
|
+
import { mergeProps } from "@elementor/editor-props";
|
|
348
|
+
import { getVariantByMeta } from "@elementor/editor-styles";
|
|
332
349
|
function updateElementStyle(args) {
|
|
333
350
|
mutateElementStyles(args.elementId, (styles) => {
|
|
334
351
|
const style = styles[args.styleId];
|
|
335
352
|
if (!style) {
|
|
336
353
|
throw new StyleNotFoundError({ context: { styleId: args.styleId } });
|
|
337
354
|
}
|
|
338
|
-
|
|
339
|
-
if (
|
|
340
|
-
variant =
|
|
341
|
-
|
|
355
|
+
const variant = getVariantByMeta(style, args.meta);
|
|
356
|
+
if (variant) {
|
|
357
|
+
variant.props = mergeProps(variant.props, args.props);
|
|
358
|
+
} else {
|
|
359
|
+
style.variants.push({ meta: args.meta, props: args.props });
|
|
342
360
|
}
|
|
343
|
-
variant.props = mergeVariantProps(variant, args.props);
|
|
344
361
|
return styles;
|
|
345
362
|
});
|
|
346
363
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
finalProps[key] = value;
|
|
354
|
-
}
|
|
364
|
+
|
|
365
|
+
// src/styles/delete-element-style.ts
|
|
366
|
+
function deleteElementStyle(elementId, styleId) {
|
|
367
|
+
mutateElementStyles(elementId, (styles) => {
|
|
368
|
+
delete styles[styleId];
|
|
369
|
+
return styles;
|
|
355
370
|
});
|
|
356
|
-
return finalProps;
|
|
357
371
|
}
|
|
358
372
|
export {
|
|
359
373
|
ELEMENT_STYLE_CHANGE_EVENT,
|
|
360
374
|
createElementStyle,
|
|
375
|
+
deleteElementStyle,
|
|
376
|
+
getElementLabel,
|
|
361
377
|
getElementSetting,
|
|
362
378
|
getElementStyles,
|
|
363
379
|
getElements,
|
|
364
380
|
getSelectedElements,
|
|
365
381
|
getWidgetsCache,
|
|
366
382
|
isElementInContainer,
|
|
383
|
+
styleRerenderEvents,
|
|
367
384
|
updateElementSettings,
|
|
368
385
|
updateElementStyle,
|
|
369
386
|
useElementSetting,
|
|
370
|
-
useElementStyleProps,
|
|
371
387
|
useElementStyles,
|
|
372
388
|
useElementType,
|
|
373
389
|
useElementsDomRef,
|
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-style-props.ts","../src/styles/consts.ts","../src/sync/get-element-styles.ts","../src/hooks/use-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/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/errors.ts","../src/styles/update-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 { type Props } from '@elementor/editor-props';\nimport { getVariantByMeta, type StyleDefinitionID, type StyleDefinitionVariant } from '@elementor/editor-styles';\nimport { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport { ELEMENT_STYLE_CHANGE_EVENT } from '../styles/consts';\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport type UseElementStylePropsArgs< T extends Props > = {\n\telementID: ElementID;\n\tstyleDefID: StyleDefinitionID | null;\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tpropNames: Array< keyof T & string >;\n};\n\ntype NullableObjectValues< T extends Props > = {\n\t[ K in keyof T ]: T[ K ] | null;\n};\n\nexport function useElementStyleProps< T extends Props >( {\n\telementID,\n\tstyleDefID,\n\tmeta,\n\tpropNames,\n}: UseElementStylePropsArgs< T > ): NullableObjectValues< T > | null {\n\treturn useListenTo(\n\t\twindowEvent( ELEMENT_STYLE_CHANGE_EVENT ),\n\t\t() => {\n\t\t\tif ( ! styleDefID ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst styleDef = getElementStyles( elementID )?.[ styleDefID ];\n\n\t\t\tif ( ! styleDef ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst variant = getVariantByMeta( styleDef, meta );\n\n\t\t\treturn propNames.reduce< Record< string, unknown > >( ( acc, key ) => {\n\t\t\t\tacc[ key ] = variant?.props[ key ] ?? null;\n\n\t\t\t\treturn acc;\n\t\t\t}, {} ) as NullableObjectValues< T >;\n\t\t},\n\t\t[ elementID, styleDefID, JSON.stringify( propNames ), meta ]\n\t);\n}\n","export const ELEMENT_STYLE_CHANGE_EVENT = 'elementor/editor-v2/editor-elements/style';\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, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport { ELEMENT_STYLE_CHANGE_EVENT } from '../styles/consts';\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport function useElementStyles( elementId: ElementID ) {\n\treturn useListenTo( windowEvent( ELEMENT_STYLE_CHANGE_EVENT ), () => getElementStyles( elementId ) ?? {}, [\n\t\telementId,\n\t] );\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 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 { generateId, type StyleDefinition, type StyleDefinitionVariant } 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\telementId: ElementID;\n\tclassesProp: string;\n\tlabel: string;\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: StyleDefinitionVariant[ 'props' ];\n};\n\nexport function createElementStyle( { elementId, classesProp, label, meta, props }: CreateElementStyleArgs ) {\n\tmutateElementStyles( elementId, ( styles ) => {\n\t\tconst id = 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\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';\n\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';\nimport { ElementNotFoundError } from './errors';\n\nexport type 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 styles = mutateStyles( container, mutator );\n\n\tremoveNonExistingClasses( container, styles );\n\n\tdispatchChangeEvent();\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 removeNonExistingClasses( container: V1Element, styles: StyleDefinitionsMap ) {\n\tconst existingStylesIds = Object.keys( styles );\n\tconst classesProps = structuredClone( getClassesProps( container ) );\n\n\tclassesProps.forEach( ( [ , prop ] ) => {\n\t\tprop.value = prop.value.filter( ( value ) => existingStylesIds.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 dispatchChangeEvent() {\n\twindow.dispatchEvent( new CustomEvent( ELEMENT_STYLE_CHANGE_EVENT ) );\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","import { type Props } from '@elementor/editor-props';\nimport { getVariantByMeta, type StyleDefinition, type StyleDefinitionVariant } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport { StyleNotFoundError } from './errors';\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\tlet variant = getVariantByMeta( style, args.meta );\n\n\t\tif ( ! variant ) {\n\t\t\tvariant = { meta: args.meta, props: {} };\n\n\t\t\tstyle.variants.push( variant );\n\t\t}\n\n\t\tvariant.props = mergeVariantProps( variant, args.props );\n\n\t\treturn styles;\n\t} );\n}\n\nfunction mergeVariantProps( variant: StyleDefinitionVariant, props: Props ) {\n\tconst finalProps = { ...variant.props };\n\n\tObject.entries( props ).forEach( ( [ key, value ] ) => {\n\t\tif ( value === null || value === undefined ) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\tdelete finalProps[ key ];\n\t\t} else {\n\t\t\tfinalProps[ key ] = value;\n\t\t}\n\t} );\n\n\treturn finalProps;\n}\n"],"mappings":";AAAA,SAAS,wBAAwB,aAAa,mBAAmB;;;ACElD,SAAR,8BAA+C;AACrD,QAAM,iBAAiB;AAEvB,SAAO,eAAe,WAAW,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AAE,MAAM,KAAK,MAAM,OAAO,CAAC,EAAE;AAEvC,YAAM,SAAS,KAAM,OAAQ;AAAA,IAC9B;AAEA,YAAQ,QAAQ,kBAAmB,SAAS,KAAK,KAAM;AAEvD,WAAO;AAAA,EACR,CAAE;AACH;AAEA,SAAS,kBAAmB,SAAiC,OAAe;AAC3E,QAAM,aAAa,EAAE,GAAG,QAAQ,MAAM;AAEtC,SAAO,QAAS,KAAM,EAAE,QAAS,CAAE,CAAE,KAAK,KAAM,MAAO;AACtD,QAAK,UAAU,QAAQ,UAAU,QAAY;AAE5C,aAAO,WAAY,GAAI;AAAA,IACxB,OAAO;AACN,iBAAY,GAAI,IAAI;AAAA,IACrB;AAAA,EACD,CAAE;AAEF,SAAO;AACR;","names":["useListenTo","useListenTo","useListenTo","windowEvent","useListenTo","windowEvent","useListenTo","windowEvent","useListenTo","windowEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","classesPropTypeUtil","classesPropTypeUtil","getVariantByMeta","getVariantByMeta"]}
|
|
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,GAAI,CAAE;AACzF;;;AE1BA,SAAS,wBAAwBA,cAAa,uBAAuB;;;ACEtD,SAAR,aAA+B,IAAa;AAClD,QAAM,iBAAiB;AACvB,QAAM,YAAY,eAAe,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AS,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"]}
|
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.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,12 +40,15 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-props": "0.
|
|
44
|
-
"@elementor/editor-styles": "0.5.
|
|
45
|
-
"@elementor/editor-v1-adapters": "0.
|
|
46
|
-
"@elementor/utils": "0.3.
|
|
43
|
+
"@elementor/editor-props": "0.9.0",
|
|
44
|
+
"@elementor/editor-styles": "0.5.5",
|
|
45
|
+
"@elementor/editor-v1-adapters": "0.10.0",
|
|
46
|
+
"@elementor/utils": "0.3.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"react": "^18.3.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"tsup": "^8.3.5"
|
|
50
53
|
}
|
|
51
54
|
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createError } from '@elementor/utils';
|
|
2
|
+
|
|
3
|
+
export const ElementNotFoundError = createError< { elementId: string } >( {
|
|
4
|
+
code: 'element_not_found',
|
|
5
|
+
message: 'Element not found.',
|
|
6
|
+
} );
|
|
7
|
+
|
|
8
|
+
export const StyleNotFoundError = createError< { styleId: string } >( {
|
|
9
|
+
code: 'style_not_found',
|
|
10
|
+
message: 'Style not found.',
|
|
11
|
+
} );
|
|
12
|
+
|
|
13
|
+
export const ElementTypeNotExistsError = createError< { elementId: string } >( {
|
|
14
|
+
code: 'element_type_not_exists',
|
|
15
|
+
message: 'Element type does not exist.',
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
export const ElementLabelNotExistsError = createError< { elementType: string } >( {
|
|
19
|
+
code: 'element_label_not_exists',
|
|
20
|
+
message: 'Element label does not exist.',
|
|
21
|
+
} );
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { __privateUseListenTo as useListenTo
|
|
1
|
+
import { __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { styleRerenderEvents } from '../styles/consts';
|
|
4
4
|
import { getElementStyles } from '../sync/get-element-styles';
|
|
5
5
|
import { type ElementID } from '../types';
|
|
6
6
|
|
|
7
7
|
export function useElementStyles( elementId: ElementID ) {
|
|
8
|
-
return useListenTo(
|
|
9
|
-
elementId,
|
|
10
|
-
] );
|
|
8
|
+
return useListenTo( styleRerenderEvents, () => getElementStyles( elementId ) ?? {}, [ elementId ] );
|
|
11
9
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ 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 { useElementStyleProps } from './hooks/use-element-style-props';
|
|
9
8
|
export { useElementStyles } from './hooks/use-element-styles';
|
|
10
9
|
export { useElementType } from './hooks/use-element-type';
|
|
11
10
|
export { useSelectedElement } from './hooks/use-selected-element';
|
|
@@ -14,12 +13,14 @@ export { useParentElement } from './hooks/use-parent-element';
|
|
|
14
13
|
// utils
|
|
15
14
|
export { getElementSetting } from './sync/get-element-setting';
|
|
16
15
|
export { getElementStyles } from './sync/get-element-styles';
|
|
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
20
|
export { isElementInContainer } from './sync/is-element-in-container';
|
|
21
21
|
export { updateElementSettings, type UpdateElementSettingsArgs } from './sync/update-element-settings';
|
|
22
22
|
|
|
23
|
-
export { ELEMENT_STYLE_CHANGE_EVENT } from './styles/consts';
|
|
23
|
+
export { ELEMENT_STYLE_CHANGE_EVENT, styleRerenderEvents } from './styles/consts';
|
|
24
24
|
export { createElementStyle, type CreateElementStyleArgs } from './styles/create-element-style';
|
|
25
25
|
export { updateElementStyle, type UpdateElementStyleArgs } from './styles/update-element-style';
|
|
26
|
+
export { deleteElementStyle } from './styles/delete-element-style';
|
package/src/styles/consts.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
import { commandEndEvent, windowEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
|
|
1
3
|
export const ELEMENT_STYLE_CHANGE_EVENT = 'elementor/editor-v2/editor-elements/style';
|
|
4
|
+
|
|
5
|
+
export const styleRerenderEvents = [
|
|
6
|
+
commandEndEvent( 'document/elements/create' ),
|
|
7
|
+
commandEndEvent( 'editor/documents/attach-preview' ),
|
|
8
|
+
windowEvent( ELEMENT_STYLE_CHANGE_EVENT ),
|
|
9
|
+
];
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { classesPropTypeUtil } from '@elementor/editor-props';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
generateId,
|
|
4
|
+
type StyleDefinition,
|
|
5
|
+
type StyleDefinitionID,
|
|
6
|
+
type StyleDefinitionVariant,
|
|
7
|
+
} from '@elementor/editor-styles';
|
|
3
8
|
|
|
4
9
|
import { getElementSetting } from '../sync/get-element-setting';
|
|
5
10
|
import { updateElementSettings } from '../sync/update-element-settings';
|
|
@@ -7,6 +12,7 @@ import { type ElementID } from '../types';
|
|
|
7
12
|
import { mutateElementStyles } from './mutate-element-styles';
|
|
8
13
|
|
|
9
14
|
export type CreateElementStyleArgs = {
|
|
15
|
+
styleId?: StyleDefinitionID;
|
|
10
16
|
elementId: ElementID;
|
|
11
17
|
classesProp: string;
|
|
12
18
|
label: string;
|
|
@@ -14,9 +20,18 @@ export type CreateElementStyleArgs = {
|
|
|
14
20
|
props: StyleDefinitionVariant[ 'props' ];
|
|
15
21
|
};
|
|
16
22
|
|
|
17
|
-
export function createElementStyle( {
|
|
23
|
+
export function createElementStyle( {
|
|
24
|
+
styleId,
|
|
25
|
+
elementId,
|
|
26
|
+
classesProp,
|
|
27
|
+
label,
|
|
28
|
+
meta,
|
|
29
|
+
props,
|
|
30
|
+
}: CreateElementStyleArgs ): string {
|
|
31
|
+
let id = styleId;
|
|
32
|
+
|
|
18
33
|
mutateElementStyles( elementId, ( styles ) => {
|
|
19
|
-
|
|
34
|
+
id ??= generateId( `e-${ elementId }-`, Object.keys( styles ) );
|
|
20
35
|
|
|
21
36
|
styles[ id ] = {
|
|
22
37
|
id,
|
|
@@ -29,6 +44,8 @@ export function createElementStyle( { elementId, classesProp, label, meta, props
|
|
|
29
44
|
|
|
30
45
|
return styles;
|
|
31
46
|
} );
|
|
47
|
+
|
|
48
|
+
return id as string;
|
|
32
49
|
}
|
|
33
50
|
|
|
34
51
|
function addStyleToClassesProp( elementId: ElementID, classesProp: string, styleId: string ) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type StyleDefinitionID } from '@elementor/editor-styles';
|
|
2
|
+
|
|
3
|
+
import { type ElementID } from '../types';
|
|
4
|
+
import { mutateElementStyles } from './mutate-element-styles';
|
|
5
|
+
|
|
6
|
+
export function deleteElementStyle( elementId: ElementID, styleId: StyleDefinitionID ) {
|
|
7
|
+
mutateElementStyles( elementId, ( styles ) => {
|
|
8
|
+
// The object is deep cloned so mutating it is fine.
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
10
|
+
delete styles[ styleId ];
|
|
11
|
+
|
|
12
|
+
return styles;
|
|
13
|
+
} );
|
|
14
|
+
}
|