@elementor/editor-elements 0.5.1 → 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 +19 -0
- package/dist/index.d.mts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +62 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -5
- package/src/errors.ts +21 -0
- package/src/index.ts +2 -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 +9 -3
- package/src/styles/update-element-style.ts +1 -1
- package/src/sync/get-element-label.ts +22 -0
- package/src/sync/types.ts +3 -3
- package/src/types.ts +1 -3
- package/src/styles/errors.ts +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @elementor/editor-elements
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e441663: Fix disabled publish button on style change.
|
|
8
|
+
- da38fa9: Remove unused exports and add missing dependencies.
|
|
9
|
+
- ad6fde0: Support history actions in style changes
|
|
10
|
+
- Updated dependencies [c9133d7]
|
|
11
|
+
- Updated dependencies [86863c1]
|
|
12
|
+
- Updated dependencies [da38fa9]
|
|
13
|
+
- Updated dependencies [9ca4eab]
|
|
14
|
+
- Updated dependencies [15c964f]
|
|
15
|
+
- Updated dependencies [ad6fde0]
|
|
16
|
+
- Updated dependencies [b8e2a85]
|
|
17
|
+
- @elementor/editor-props@0.9.0
|
|
18
|
+
- @elementor/editor-v1-adapters@0.10.0
|
|
19
|
+
- @elementor/utils@0.3.1
|
|
20
|
+
- @elementor/editor-styles@0.5.5
|
|
21
|
+
|
|
3
22
|
## 0.5.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _elementor_editor_props from '@elementor/editor-props';
|
|
2
|
+
import { PropsSchema, PropValue, Props } from '@elementor/editor-props';
|
|
2
3
|
import * as _elementor_editor_styles from '@elementor/editor-styles';
|
|
3
4
|
import { StyleDefinitionID, StyleDefinition, StyleDefinitionVariant } from '@elementor/editor-styles';
|
|
4
5
|
import * as _elementor_editor_v1_adapters from '@elementor/editor-v1-adapters';
|
|
@@ -33,7 +34,6 @@ type Control = {
|
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
36
|
type ControlItem = ControlsSection | Control;
|
|
36
|
-
type PropsSchema = Record<Control['value']['bind'], PropType>;
|
|
37
37
|
|
|
38
38
|
type V1Element = {
|
|
39
39
|
id: string;
|
|
@@ -80,15 +80,17 @@ declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: stri
|
|
|
80
80
|
|
|
81
81
|
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
82
82
|
|
|
83
|
+
declare function getElementLabel(elementId: ElementID): string;
|
|
84
|
+
|
|
83
85
|
declare function getElements(root?: ElementID): V1Element[];
|
|
84
86
|
|
|
85
87
|
declare function getSelectedElements(): Element[];
|
|
86
88
|
|
|
87
89
|
declare function getWidgetsCache(): Record<string, {
|
|
88
90
|
atomic_controls?: ControlItem[];
|
|
89
|
-
atomic_props_schema?: PropsSchema;
|
|
91
|
+
atomic_props_schema?: _elementor_editor_props.PropsSchema;
|
|
90
92
|
controls: object;
|
|
91
|
-
base_styles?: _elementor_editor_styles.StyleDefinition
|
|
93
|
+
base_styles?: Record<string, _elementor_editor_styles.StyleDefinition>;
|
|
92
94
|
title: string;
|
|
93
95
|
}> | null;
|
|
94
96
|
|
|
@@ -105,13 +107,14 @@ declare const ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/
|
|
|
105
107
|
declare const styleRerenderEvents: (_elementor_editor_v1_adapters.CommandEventDescriptor | _elementor_editor_v1_adapters.WindowEventDescriptor)[];
|
|
106
108
|
|
|
107
109
|
type CreateElementStyleArgs = {
|
|
110
|
+
styleId?: StyleDefinitionID;
|
|
108
111
|
elementId: ElementID;
|
|
109
112
|
classesProp: string;
|
|
110
113
|
label: string;
|
|
111
114
|
meta: StyleDefinitionVariant['meta'];
|
|
112
115
|
props: StyleDefinitionVariant['props'];
|
|
113
116
|
};
|
|
114
|
-
declare function createElementStyle({ elementId, classesProp, label, meta, props }: CreateElementStyleArgs):
|
|
117
|
+
declare function createElementStyle({ styleId, elementId, classesProp, label, meta, props, }: CreateElementStyleArgs): string;
|
|
115
118
|
|
|
116
119
|
type UpdateElementStyleArgs = {
|
|
117
120
|
elementId: ElementID;
|
|
@@ -121,4 +124,6 @@ type UpdateElementStyleArgs = {
|
|
|
121
124
|
};
|
|
122
125
|
declare function updateElementStyle(args: UpdateElementStyleArgs): void;
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
declare function deleteElementStyle(elementId: ElementID, styleId: StyleDefinitionID): void;
|
|
128
|
+
|
|
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, isElementInContainer, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementSetting, useElementStyles, useElementType, useElementsDomRef, useParentElement, useSelectedElement };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _elementor_editor_props from '@elementor/editor-props';
|
|
2
|
+
import { PropsSchema, PropValue, Props } from '@elementor/editor-props';
|
|
2
3
|
import * as _elementor_editor_styles from '@elementor/editor-styles';
|
|
3
4
|
import { StyleDefinitionID, StyleDefinition, StyleDefinitionVariant } from '@elementor/editor-styles';
|
|
4
5
|
import * as _elementor_editor_v1_adapters from '@elementor/editor-v1-adapters';
|
|
@@ -33,7 +34,6 @@ type Control = {
|
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
36
|
type ControlItem = ControlsSection | Control;
|
|
36
|
-
type PropsSchema = Record<Control['value']['bind'], PropType>;
|
|
37
37
|
|
|
38
38
|
type V1Element = {
|
|
39
39
|
id: string;
|
|
@@ -80,15 +80,17 @@ declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: stri
|
|
|
80
80
|
|
|
81
81
|
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
82
82
|
|
|
83
|
+
declare function getElementLabel(elementId: ElementID): string;
|
|
84
|
+
|
|
83
85
|
declare function getElements(root?: ElementID): V1Element[];
|
|
84
86
|
|
|
85
87
|
declare function getSelectedElements(): Element[];
|
|
86
88
|
|
|
87
89
|
declare function getWidgetsCache(): Record<string, {
|
|
88
90
|
atomic_controls?: ControlItem[];
|
|
89
|
-
atomic_props_schema?: PropsSchema;
|
|
91
|
+
atomic_props_schema?: _elementor_editor_props.PropsSchema;
|
|
90
92
|
controls: object;
|
|
91
|
-
base_styles?: _elementor_editor_styles.StyleDefinition
|
|
93
|
+
base_styles?: Record<string, _elementor_editor_styles.StyleDefinition>;
|
|
92
94
|
title: string;
|
|
93
95
|
}> | null;
|
|
94
96
|
|
|
@@ -105,13 +107,14 @@ declare const ELEMENT_STYLE_CHANGE_EVENT = "elementor/editor-v2/editor-elements/
|
|
|
105
107
|
declare const styleRerenderEvents: (_elementor_editor_v1_adapters.CommandEventDescriptor | _elementor_editor_v1_adapters.WindowEventDescriptor)[];
|
|
106
108
|
|
|
107
109
|
type CreateElementStyleArgs = {
|
|
110
|
+
styleId?: StyleDefinitionID;
|
|
108
111
|
elementId: ElementID;
|
|
109
112
|
classesProp: string;
|
|
110
113
|
label: string;
|
|
111
114
|
meta: StyleDefinitionVariant['meta'];
|
|
112
115
|
props: StyleDefinitionVariant['props'];
|
|
113
116
|
};
|
|
114
|
-
declare function createElementStyle({ elementId, classesProp, label, meta, props }: CreateElementStyleArgs):
|
|
117
|
+
declare function createElementStyle({ styleId, elementId, classesProp, label, meta, props, }: CreateElementStyleArgs): string;
|
|
115
118
|
|
|
116
119
|
type UpdateElementStyleArgs = {
|
|
117
120
|
elementId: ElementID;
|
|
@@ -121,4 +124,6 @@ type UpdateElementStyleArgs = {
|
|
|
121
124
|
};
|
|
122
125
|
declare function updateElementStyle(args: UpdateElementStyleArgs): void;
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
declare function deleteElementStyle(elementId: ElementID, styleId: StyleDefinitionID): void;
|
|
128
|
+
|
|
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, isElementInContainer, styleRerenderEvents, updateElementSettings, updateElementStyle, useElementSetting, useElementStyles, useElementType, useElementsDomRef, useParentElement, useSelectedElement };
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ELEMENT_STYLE_CHANGE_EVENT: () => ELEMENT_STYLE_CHANGE_EVENT,
|
|
24
24
|
createElementStyle: () => createElementStyle,
|
|
25
|
+
deleteElementStyle: () => deleteElementStyle,
|
|
26
|
+
getElementLabel: () => getElementLabel,
|
|
25
27
|
getElementSetting: () => getElementSetting,
|
|
26
28
|
getElementStyles: () => getElementStyles,
|
|
27
29
|
getElements: () => getElements,
|
|
@@ -208,6 +210,39 @@ function useParentElement(elementId) {
|
|
|
208
210
|
);
|
|
209
211
|
}
|
|
210
212
|
|
|
213
|
+
// src/errors.ts
|
|
214
|
+
var import_utils = require("@elementor/utils");
|
|
215
|
+
var ElementNotFoundError = (0, import_utils.createError)({
|
|
216
|
+
code: "element_not_found",
|
|
217
|
+
message: "Element not found."
|
|
218
|
+
});
|
|
219
|
+
var StyleNotFoundError = (0, import_utils.createError)({
|
|
220
|
+
code: "style_not_found",
|
|
221
|
+
message: "Style not found."
|
|
222
|
+
});
|
|
223
|
+
var ElementTypeNotExistsError = (0, import_utils.createError)({
|
|
224
|
+
code: "element_type_not_exists",
|
|
225
|
+
message: "Element type does not exist."
|
|
226
|
+
});
|
|
227
|
+
var ElementLabelNotExistsError = (0, import_utils.createError)({
|
|
228
|
+
code: "element_label_not_exists",
|
|
229
|
+
message: "Element label does not exist."
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// src/sync/get-element-label.ts
|
|
233
|
+
function getElementLabel(elementId) {
|
|
234
|
+
const container = getContainer(elementId);
|
|
235
|
+
const type = container?.model.get("widgetType") || container?.model.get("elType");
|
|
236
|
+
if (!type) {
|
|
237
|
+
throw new ElementTypeNotExistsError({ context: { elementId } });
|
|
238
|
+
}
|
|
239
|
+
const label = getWidgetsCache()?.[type]?.title;
|
|
240
|
+
if (!label) {
|
|
241
|
+
throw new ElementLabelNotExistsError({ context: { elementType: type } });
|
|
242
|
+
}
|
|
243
|
+
return label;
|
|
244
|
+
}
|
|
245
|
+
|
|
211
246
|
// src/sync/get-elements.ts
|
|
212
247
|
function getElements(root) {
|
|
213
248
|
const container = root ? getContainer(root) : getCurrentDocumentContainer();
|
|
@@ -250,19 +285,7 @@ var import_editor_styles = require("@elementor/editor-styles");
|
|
|
250
285
|
|
|
251
286
|
// src/styles/mutate-element-styles.ts
|
|
252
287
|
var import_editor_props = require("@elementor/editor-props");
|
|
253
|
-
|
|
254
|
-
// src/styles/errors.ts
|
|
255
|
-
var import_utils = require("@elementor/utils");
|
|
256
|
-
var ElementNotFoundError = (0, import_utils.createError)({
|
|
257
|
-
code: "element_not_found",
|
|
258
|
-
message: "Element not found."
|
|
259
|
-
});
|
|
260
|
-
var StyleNotFoundError = (0, import_utils.createError)({
|
|
261
|
-
code: "style_not_found",
|
|
262
|
-
message: "Style not found."
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// src/styles/mutate-element-styles.ts
|
|
288
|
+
var import_editor_v1_adapters9 = require("@elementor/editor-v1-adapters");
|
|
266
289
|
function mutateElementStyles(elementId, mutator) {
|
|
267
290
|
const container = getContainer(elementId);
|
|
268
291
|
if (!container) {
|
|
@@ -275,7 +298,7 @@ function mutateElementStyles(elementId, mutator) {
|
|
|
275
298
|
oldIds,
|
|
276
299
|
newIds
|
|
277
300
|
});
|
|
278
|
-
|
|
301
|
+
notifyChanges();
|
|
279
302
|
return styles;
|
|
280
303
|
}
|
|
281
304
|
function mutateStyles(container, mutator) {
|
|
@@ -314,14 +337,26 @@ function getClassesProps(container) {
|
|
|
314
337
|
return import_editor_props.classesPropTypeUtil.isValid(value);
|
|
315
338
|
});
|
|
316
339
|
}
|
|
340
|
+
function notifyChanges() {
|
|
341
|
+
dispatchChangeEvent();
|
|
342
|
+
(0, import_editor_v1_adapters9.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
|
|
343
|
+
}
|
|
317
344
|
function dispatchChangeEvent() {
|
|
318
345
|
window.dispatchEvent(new CustomEvent(ELEMENT_STYLE_CHANGE_EVENT));
|
|
319
346
|
}
|
|
320
347
|
|
|
321
348
|
// src/styles/create-element-style.ts
|
|
322
|
-
function createElementStyle({
|
|
349
|
+
function createElementStyle({
|
|
350
|
+
styleId,
|
|
351
|
+
elementId,
|
|
352
|
+
classesProp,
|
|
353
|
+
label,
|
|
354
|
+
meta,
|
|
355
|
+
props
|
|
356
|
+
}) {
|
|
357
|
+
let id = styleId;
|
|
323
358
|
mutateElementStyles(elementId, (styles) => {
|
|
324
|
-
|
|
359
|
+
id ??= (0, import_editor_styles.generateId)(`e-${elementId}-`, Object.keys(styles));
|
|
325
360
|
styles[id] = {
|
|
326
361
|
id,
|
|
327
362
|
label,
|
|
@@ -331,6 +366,7 @@ function createElementStyle({ elementId, classesProp, label, meta, props }) {
|
|
|
331
366
|
addStyleToClassesProp(elementId, classesProp, id);
|
|
332
367
|
return styles;
|
|
333
368
|
});
|
|
369
|
+
return id;
|
|
334
370
|
}
|
|
335
371
|
function addStyleToClassesProp(elementId, classesProp, styleId) {
|
|
336
372
|
const base = getElementSetting(elementId, classesProp);
|
|
@@ -367,10 +403,20 @@ function updateElementStyle(args) {
|
|
|
367
403
|
return styles;
|
|
368
404
|
});
|
|
369
405
|
}
|
|
406
|
+
|
|
407
|
+
// src/styles/delete-element-style.ts
|
|
408
|
+
function deleteElementStyle(elementId, styleId) {
|
|
409
|
+
mutateElementStyles(elementId, (styles) => {
|
|
410
|
+
delete styles[styleId];
|
|
411
|
+
return styles;
|
|
412
|
+
});
|
|
413
|
+
}
|
|
370
414
|
// Annotate the CommonJS export names for ESM import in node:
|
|
371
415
|
0 && (module.exports = {
|
|
372
416
|
ELEMENT_STYLE_CHANGE_EVENT,
|
|
373
417
|
createElementStyle,
|
|
418
|
+
deleteElementStyle,
|
|
419
|
+
getElementLabel,
|
|
374
420
|
getElementSetting,
|
|
375
421
|
getElementStyles,
|
|
376
422
|
getElements,
|
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/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":["// 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 { 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';\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 { 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 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\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 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 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 { mergeProps } 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\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAiE;;;ACElD,SAAR,8BAA+C;AACrD,QAAM,iBAAiB;AAEvB,SAAO,eAAe,WAAW,WAAW,aAAa,GAAG,aAAa;AAC1E;;;ADFA,IAAM,qBAAqB;AAEpB,SAAS,oBAAmC;AAClD,aAAO,0BAAAA;AAAA,IACN;AAAA,UACC,uCAAa,wCAAyC;AAAA,UACtD,uCAAa,yCAA0C;AAAA,UACvD,uCAAa,mCAAoC;AAAA,UACjD,uCAAa,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,IAAAC,6BAAqE;;;ACEtD,SAAR,aAA+B,IAAa;AAClD,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,aAAO,2BAAAC;AAAA,QACN,4CAAiB,gCAAiC;AAA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AAK;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;","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_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-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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAiE;;;ACElD,SAAR,8BAA+C;AACrD,QAAM,iBAAiB;AAEvB,SAA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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"]}
|
package/dist/index.mjs
CHANGED
|
@@ -166,6 +166,39 @@ function useParentElement(elementId) {
|
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
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
|
+
|
|
169
202
|
// src/sync/get-elements.ts
|
|
170
203
|
function getElements(root) {
|
|
171
204
|
const container = root ? getContainer(root) : getCurrentDocumentContainer();
|
|
@@ -204,23 +237,13 @@ var updateElementSettings = ({ id, props, withHistory = true }) => {
|
|
|
204
237
|
|
|
205
238
|
// src/styles/create-element-style.ts
|
|
206
239
|
import { classesPropTypeUtil as classesPropTypeUtil2 } from "@elementor/editor-props";
|
|
207
|
-
import {
|
|
240
|
+
import {
|
|
241
|
+
generateId
|
|
242
|
+
} from "@elementor/editor-styles";
|
|
208
243
|
|
|
209
244
|
// src/styles/mutate-element-styles.ts
|
|
210
245
|
import { classesPropTypeUtil } from "@elementor/editor-props";
|
|
211
|
-
|
|
212
|
-
// src/styles/errors.ts
|
|
213
|
-
import { createError } from "@elementor/utils";
|
|
214
|
-
var ElementNotFoundError = createError({
|
|
215
|
-
code: "element_not_found",
|
|
216
|
-
message: "Element not found."
|
|
217
|
-
});
|
|
218
|
-
var StyleNotFoundError = createError({
|
|
219
|
-
code: "style_not_found",
|
|
220
|
-
message: "Style not found."
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// src/styles/mutate-element-styles.ts
|
|
246
|
+
import { __privateRunCommandSync as runCommandSync2 } from "@elementor/editor-v1-adapters";
|
|
224
247
|
function mutateElementStyles(elementId, mutator) {
|
|
225
248
|
const container = getContainer(elementId);
|
|
226
249
|
if (!container) {
|
|
@@ -233,7 +256,7 @@ function mutateElementStyles(elementId, mutator) {
|
|
|
233
256
|
oldIds,
|
|
234
257
|
newIds
|
|
235
258
|
});
|
|
236
|
-
|
|
259
|
+
notifyChanges();
|
|
237
260
|
return styles;
|
|
238
261
|
}
|
|
239
262
|
function mutateStyles(container, mutator) {
|
|
@@ -272,14 +295,26 @@ function getClassesProps(container) {
|
|
|
272
295
|
return classesPropTypeUtil.isValid(value);
|
|
273
296
|
});
|
|
274
297
|
}
|
|
298
|
+
function notifyChanges() {
|
|
299
|
+
dispatchChangeEvent();
|
|
300
|
+
runCommandSync2("document/save/set-is-modified", { status: true }, { internal: true });
|
|
301
|
+
}
|
|
275
302
|
function dispatchChangeEvent() {
|
|
276
303
|
window.dispatchEvent(new CustomEvent(ELEMENT_STYLE_CHANGE_EVENT));
|
|
277
304
|
}
|
|
278
305
|
|
|
279
306
|
// src/styles/create-element-style.ts
|
|
280
|
-
function createElementStyle({
|
|
307
|
+
function createElementStyle({
|
|
308
|
+
styleId,
|
|
309
|
+
elementId,
|
|
310
|
+
classesProp,
|
|
311
|
+
label,
|
|
312
|
+
meta,
|
|
313
|
+
props
|
|
314
|
+
}) {
|
|
315
|
+
let id = styleId;
|
|
281
316
|
mutateElementStyles(elementId, (styles) => {
|
|
282
|
-
|
|
317
|
+
id ??= generateId(`e-${elementId}-`, Object.keys(styles));
|
|
283
318
|
styles[id] = {
|
|
284
319
|
id,
|
|
285
320
|
label,
|
|
@@ -289,6 +324,7 @@ function createElementStyle({ elementId, classesProp, label, meta, props }) {
|
|
|
289
324
|
addStyleToClassesProp(elementId, classesProp, id);
|
|
290
325
|
return styles;
|
|
291
326
|
});
|
|
327
|
+
return id;
|
|
292
328
|
}
|
|
293
329
|
function addStyleToClassesProp(elementId, classesProp, styleId) {
|
|
294
330
|
const base = getElementSetting(elementId, classesProp);
|
|
@@ -325,9 +361,19 @@ function updateElementStyle(args) {
|
|
|
325
361
|
return styles;
|
|
326
362
|
});
|
|
327
363
|
}
|
|
364
|
+
|
|
365
|
+
// src/styles/delete-element-style.ts
|
|
366
|
+
function deleteElementStyle(elementId, styleId) {
|
|
367
|
+
mutateElementStyles(elementId, (styles) => {
|
|
368
|
+
delete styles[styleId];
|
|
369
|
+
return styles;
|
|
370
|
+
});
|
|
371
|
+
}
|
|
328
372
|
export {
|
|
329
373
|
ELEMENT_STYLE_CHANGE_EVENT,
|
|
330
374
|
createElementStyle,
|
|
375
|
+
deleteElementStyle,
|
|
376
|
+
getElementLabel,
|
|
331
377
|
getElementSetting,
|
|
332
378
|
getElementStyles,
|
|
333
379
|
getElements,
|
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/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 { __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 { 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 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\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 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 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 { mergeProps } 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\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"],"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,S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AAuB;AAAA,IACtB,IAAI;AAAA,IACJ,OAAO;AAAA,MACN,CAAE,WAAY,GAAG;AAAA,IAClB;AAAA,IACA,aAAa;AAAA,EACd,CAAE;AACH;;;AGlDA,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;","names":["useListenTo","useListenTo","useListenTo","commandEndEvent","windowEvent","useListenTo","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","classesPropTypeUtil","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-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,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AAkB,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"]}
|
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
|
+
} );
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { useParentElement } from './hooks/use-parent-element';
|
|
|
13
13
|
// utils
|
|
14
14
|
export { getElementSetting } from './sync/get-element-setting';
|
|
15
15
|
export { getElementStyles } from './sync/get-element-styles';
|
|
16
|
+
export { getElementLabel } from './sync/get-element-label';
|
|
16
17
|
export { getElements } from './sync/get-elements';
|
|
17
18
|
export { getSelectedElements } from './sync/get-selected-elements';
|
|
18
19
|
export { getWidgetsCache } from './sync/get-widgets-cache';
|
|
@@ -22,3 +23,4 @@ export { updateElementSettings, type UpdateElementSettingsArgs } from './sync/up
|
|
|
22
23
|
export { ELEMENT_STYLE_CHANGE_EVENT, styleRerenderEvents } from './styles/consts';
|
|
23
24
|
export { createElementStyle, type CreateElementStyleArgs } from './styles/create-element-style';
|
|
24
25
|
export { updateElementStyle, type UpdateElementStyleArgs } from './styles/update-element-style';
|
|
26
|
+
export { deleteElementStyle } from './styles/delete-element-style';
|
|
@@ -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
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';
|
|
2
2
|
import { type StyleDefinition, type StyleDefinitionsMap } from '@elementor/editor-styles';
|
|
3
|
+
import { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';
|
|
3
4
|
|
|
5
|
+
import { ElementNotFoundError } from '../errors';
|
|
4
6
|
import getContainer from '../sync/get-container';
|
|
5
7
|
import { type V1Element } from '../sync/types';
|
|
6
8
|
import { updateElementSettings } from '../sync/update-element-settings';
|
|
7
9
|
import { type ElementID } from '../types';
|
|
8
10
|
import { ELEMENT_STYLE_CHANGE_EVENT } from './consts';
|
|
9
|
-
import { ElementNotFoundError } from './errors';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
type Mutator = ( styles: StyleDefinitionsMap ) => StyleDefinitionsMap;
|
|
12
13
|
|
|
13
14
|
export function mutateElementStyles( elementId: ElementID, mutator: Mutator ) {
|
|
14
15
|
const container = getContainer( elementId );
|
|
@@ -28,7 +29,7 @@ export function mutateElementStyles( elementId: ElementID, mutator: Mutator ) {
|
|
|
28
29
|
newIds,
|
|
29
30
|
} );
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
notifyChanges();
|
|
32
33
|
|
|
33
34
|
return styles;
|
|
34
35
|
}
|
|
@@ -84,6 +85,11 @@ function getClassesProps( container: V1Element ) {
|
|
|
84
85
|
} );
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
function notifyChanges() {
|
|
89
|
+
dispatchChangeEvent();
|
|
90
|
+
runCommandSync( 'document/save/set-is-modified', { status: true }, { internal: true } );
|
|
91
|
+
}
|
|
92
|
+
|
|
87
93
|
function dispatchChangeEvent() {
|
|
88
94
|
window.dispatchEvent( new CustomEvent( ELEMENT_STYLE_CHANGE_EVENT ) );
|
|
89
95
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { mergeProps } from '@elementor/editor-props';
|
|
2
2
|
import { getVariantByMeta, type StyleDefinition, type StyleDefinitionVariant } from '@elementor/editor-styles';
|
|
3
3
|
|
|
4
|
+
import { StyleNotFoundError } from '../errors';
|
|
4
5
|
import { type ElementID } from '../types';
|
|
5
|
-
import { StyleNotFoundError } from './errors';
|
|
6
6
|
import { mutateElementStyles } from './mutate-element-styles';
|
|
7
7
|
|
|
8
8
|
export type UpdateElementStyleArgs = {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ElementLabelNotExistsError, ElementTypeNotExistsError } from '../errors';
|
|
2
|
+
import getContainer from '../sync/get-container';
|
|
3
|
+
import { getWidgetsCache } from '../sync/get-widgets-cache';
|
|
4
|
+
import { type ElementID } from '../types';
|
|
5
|
+
|
|
6
|
+
export function getElementLabel( elementId: ElementID ) {
|
|
7
|
+
const container = getContainer( elementId );
|
|
8
|
+
|
|
9
|
+
const type = container?.model.get( 'widgetType' ) || container?.model.get( 'elType' );
|
|
10
|
+
|
|
11
|
+
if ( ! type ) {
|
|
12
|
+
throw new ElementTypeNotExistsError( { context: { elementId } } );
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const label = getWidgetsCache()?.[ type ]?.title;
|
|
16
|
+
|
|
17
|
+
if ( ! label ) {
|
|
18
|
+
throw new ElementLabelNotExistsError( { context: { elementType: type } } );
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return label;
|
|
22
|
+
}
|
package/src/sync/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type PropValue } from '@elementor/editor-props';
|
|
1
|
+
import { type PropsSchema, type PropValue } from '@elementor/editor-props';
|
|
2
2
|
import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';
|
|
3
3
|
|
|
4
|
-
import { type ControlItem
|
|
4
|
+
import { type ControlItem } from '../types';
|
|
5
5
|
|
|
6
6
|
export type ExtendedWindow = Window & {
|
|
7
7
|
elementor?: {
|
|
@@ -14,7 +14,7 @@ export type ExtendedWindow = Window & {
|
|
|
14
14
|
atomic_controls?: ControlItem[];
|
|
15
15
|
atomic_props_schema?: PropsSchema;
|
|
16
16
|
controls: object;
|
|
17
|
-
base_styles?: StyleDefinition
|
|
17
|
+
base_styles?: Record< string, StyleDefinition >;
|
|
18
18
|
title: string;
|
|
19
19
|
}
|
|
20
20
|
>;
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PropsSchema } from '@elementor/editor-props';
|
|
2
2
|
|
|
3
3
|
export type ElementID = string;
|
|
4
4
|
|
|
@@ -35,5 +35,3 @@ export type Control = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
export type ControlItem = ControlsSection | Control;
|
|
38
|
-
|
|
39
|
-
export type PropsSchema = Record< Control[ 'value' ][ 'bind' ], PropType >;
|
package/src/styles/errors.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
} );
|