@elementor/editor-elements 0.2.0 → 0.3.1
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 +27 -0
- package/dist/index.d.mts +53 -26
- package/dist/index.d.ts +53 -26
- package/dist/index.js +146 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/hooks/use-element-setting.ts +9 -7
- package/src/hooks/use-element-style-prop.ts +6 -5
- package/src/hooks/use-element-styles.ts +12 -0
- package/src/hooks/use-element-type.ts +2 -1
- package/src/hooks/use-elements-dom-ref.ts +27 -0
- package/src/hooks/use-selected-element.ts +1 -0
- package/src/index.ts +12 -7
- package/src/sync/get-container.ts +1 -1
- package/src/sync/get-current-document-container.ts +7 -0
- package/src/sync/get-element-setting.ts +4 -4
- package/src/sync/get-element-styles.ts +3 -2
- package/src/sync/get-elements.ts +16 -0
- package/src/sync/get-selected-elements.ts +2 -2
- package/src/sync/get-widgets-cache.ts +1 -1
- package/src/sync/is-element-in-container.ts +14 -0
- package/src/sync/types.ts +17 -4
- package/src/sync/update-settings.ts +3 -2
- package/src/sync/update-styles.ts +4 -3
- package/src/types.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @elementor/editor-elements
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 081bae8: Move the style renderer into editor-canvas and register the elements styles provider in editor-styles-repository
|
|
8
|
+
- Updated dependencies [f584292]
|
|
9
|
+
- @elementor/editor-styles@0.3.0
|
|
10
|
+
|
|
11
|
+
## 0.3.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- e7f4706: save style props to session
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 7781969: Create basic UI for the class selector
|
|
20
|
+
- d21c5c3: Introduce editor canvas to render element overlays for atomic elements
|
|
21
|
+
- 7781969: Update `@elementor/ui` version
|
|
22
|
+
- Updated dependencies [7781969]
|
|
23
|
+
- Updated dependencies [6e240a8]
|
|
24
|
+
- Updated dependencies [7781969]
|
|
25
|
+
- Updated dependencies [0c6bcb6]
|
|
26
|
+
- @elementor/editor-styles@0.2.1
|
|
27
|
+
- @elementor/editor-props@0.3.0
|
|
28
|
+
- @elementor/editor-v1-adapters@0.8.4
|
|
29
|
+
|
|
3
30
|
## 0.2.0
|
|
4
31
|
|
|
5
32
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropType, PropValue, PropKey, Props } from '@elementor/editor-props';
|
|
2
|
-
import
|
|
2
|
+
import * as _elementor_editor_styles from '@elementor/editor-styles';
|
|
3
|
+
import { StyleDefinitionID, StyleDefinition, StyleVariant } from '@elementor/editor-styles';
|
|
3
4
|
|
|
4
5
|
type ElementID = string;
|
|
5
6
|
type Element = {
|
|
@@ -33,20 +34,29 @@ type Control = {
|
|
|
33
34
|
type ControlItem = ControlsSection | Control;
|
|
34
35
|
type PropsSchema = Record<Control['value']['bind'], PropType>;
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
type V1Element = {
|
|
38
|
+
id: string;
|
|
39
|
+
model: V1Model<V1ElementModelProps>;
|
|
40
|
+
settings?: V1Model<V1ElementSettingsProps>;
|
|
41
|
+
children?: V1Element[];
|
|
42
|
+
view?: {
|
|
43
|
+
el: HTMLElement;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
type V1ElementModelProps = {
|
|
47
|
+
widgetType?: string;
|
|
48
|
+
elType: string;
|
|
49
|
+
id: string;
|
|
50
|
+
styles?: Record<StyleDefinitionID, StyleDefinition>;
|
|
51
|
+
};
|
|
52
|
+
type V1ElementSettingsProps = Record<string, PropValue>;
|
|
53
|
+
type V1Model<T> = {
|
|
54
|
+
get: <K extends keyof T>(key: K) => T[K];
|
|
42
55
|
};
|
|
43
56
|
|
|
44
|
-
declare function
|
|
57
|
+
declare function useElementsDomRef(): HTMLElement[];
|
|
45
58
|
|
|
46
|
-
declare const useElementSetting: (
|
|
47
|
-
id: string;
|
|
48
|
-
bind: string;
|
|
49
|
-
}) => PropValue;
|
|
59
|
+
declare const useElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
50
60
|
|
|
51
61
|
type UseElementStylePropArgs = {
|
|
52
62
|
elementID: ElementID;
|
|
@@ -55,20 +65,25 @@ type UseElementStylePropArgs = {
|
|
|
55
65
|
propName: PropKey;
|
|
56
66
|
};
|
|
57
67
|
declare const useElementStyleProp: <T extends PropValue>({ elementID, styleDefID, meta, propName, }: UseElementStylePropArgs) => T | null;
|
|
68
|
+
declare function getVariantByMeta(styleDef: StyleDefinition, meta: StyleVariant['meta']): StyleVariant | undefined;
|
|
58
69
|
|
|
59
|
-
declare
|
|
60
|
-
id: ElementID;
|
|
61
|
-
props: Props;
|
|
62
|
-
}) => void;
|
|
70
|
+
declare function useElementStyles(elementId: ElementID): Record<string, _elementor_editor_styles.StyleDefinition>;
|
|
63
71
|
|
|
64
|
-
type
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
declare function useElementType(type?: string): ElementType | null;
|
|
73
|
+
|
|
74
|
+
declare function useSelectedElement(): {
|
|
75
|
+
element: null;
|
|
76
|
+
elementType: null;
|
|
77
|
+
} | {
|
|
78
|
+
element: Element;
|
|
79
|
+
elementType: ElementType;
|
|
70
80
|
};
|
|
71
|
-
|
|
81
|
+
|
|
82
|
+
declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
83
|
+
|
|
84
|
+
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
85
|
+
|
|
86
|
+
declare function getElements(root?: ElementID): V1Element[];
|
|
72
87
|
|
|
73
88
|
declare function getSelectedElements(): Element[];
|
|
74
89
|
|
|
@@ -79,8 +94,20 @@ declare function getWidgetsCache(): Record<string, {
|
|
|
79
94
|
title: string;
|
|
80
95
|
}> | null;
|
|
81
96
|
|
|
82
|
-
declare const
|
|
97
|
+
declare const isElementInContainer: (element: Element, container: V1Element) => boolean;
|
|
83
98
|
|
|
84
|
-
declare const
|
|
99
|
+
declare const updateSettings: ({ id, props }: {
|
|
100
|
+
id: ElementID;
|
|
101
|
+
props: Props;
|
|
102
|
+
}) => void;
|
|
103
|
+
|
|
104
|
+
type UpdateStyleProps = {
|
|
105
|
+
elementID: ElementID;
|
|
106
|
+
styleDefID?: StyleDefinitionID;
|
|
107
|
+
meta: StyleVariant['meta'];
|
|
108
|
+
props: Props;
|
|
109
|
+
bind: PropKey;
|
|
110
|
+
};
|
|
111
|
+
declare const updateStyle: ({ elementID, styleDefID, meta, props, bind }: UpdateStyleProps) => Promise<void>;
|
|
85
112
|
|
|
86
|
-
export { type Control, type ControlItem, type ControlsSection, type Element, type ElementID, type ElementType, type PropsSchema, getElementSetting, getElementStyles, getSelectedElements, getWidgetsCache, updateSettings, updateStyle, useElementSetting, useElementStyleProp, useElementType, useSelectedElement };
|
|
113
|
+
export { type Control, type ControlItem, type ControlsSection, type Element, type ElementID, type ElementType, type PropsSchema, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, getElementSetting, getElementStyles, getElements, getSelectedElements, getVariantByMeta, getWidgetsCache, isElementInContainer, updateSettings, updateStyle, useElementSetting, useElementStyleProp, useElementStyles, useElementType, useElementsDomRef, useSelectedElement };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropType, PropValue, PropKey, Props } from '@elementor/editor-props';
|
|
2
|
-
import
|
|
2
|
+
import * as _elementor_editor_styles from '@elementor/editor-styles';
|
|
3
|
+
import { StyleDefinitionID, StyleDefinition, StyleVariant } from '@elementor/editor-styles';
|
|
3
4
|
|
|
4
5
|
type ElementID = string;
|
|
5
6
|
type Element = {
|
|
@@ -33,20 +34,29 @@ type Control = {
|
|
|
33
34
|
type ControlItem = ControlsSection | Control;
|
|
34
35
|
type PropsSchema = Record<Control['value']['bind'], PropType>;
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
type V1Element = {
|
|
38
|
+
id: string;
|
|
39
|
+
model: V1Model<V1ElementModelProps>;
|
|
40
|
+
settings?: V1Model<V1ElementSettingsProps>;
|
|
41
|
+
children?: V1Element[];
|
|
42
|
+
view?: {
|
|
43
|
+
el: HTMLElement;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
type V1ElementModelProps = {
|
|
47
|
+
widgetType?: string;
|
|
48
|
+
elType: string;
|
|
49
|
+
id: string;
|
|
50
|
+
styles?: Record<StyleDefinitionID, StyleDefinition>;
|
|
51
|
+
};
|
|
52
|
+
type V1ElementSettingsProps = Record<string, PropValue>;
|
|
53
|
+
type V1Model<T> = {
|
|
54
|
+
get: <K extends keyof T>(key: K) => T[K];
|
|
42
55
|
};
|
|
43
56
|
|
|
44
|
-
declare function
|
|
57
|
+
declare function useElementsDomRef(): HTMLElement[];
|
|
45
58
|
|
|
46
|
-
declare const useElementSetting: (
|
|
47
|
-
id: string;
|
|
48
|
-
bind: string;
|
|
49
|
-
}) => PropValue;
|
|
59
|
+
declare const useElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
50
60
|
|
|
51
61
|
type UseElementStylePropArgs = {
|
|
52
62
|
elementID: ElementID;
|
|
@@ -55,20 +65,25 @@ type UseElementStylePropArgs = {
|
|
|
55
65
|
propName: PropKey;
|
|
56
66
|
};
|
|
57
67
|
declare const useElementStyleProp: <T extends PropValue>({ elementID, styleDefID, meta, propName, }: UseElementStylePropArgs) => T | null;
|
|
68
|
+
declare function getVariantByMeta(styleDef: StyleDefinition, meta: StyleVariant['meta']): StyleVariant | undefined;
|
|
58
69
|
|
|
59
|
-
declare
|
|
60
|
-
id: ElementID;
|
|
61
|
-
props: Props;
|
|
62
|
-
}) => void;
|
|
70
|
+
declare function useElementStyles(elementId: ElementID): Record<string, _elementor_editor_styles.StyleDefinition>;
|
|
63
71
|
|
|
64
|
-
type
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
declare function useElementType(type?: string): ElementType | null;
|
|
73
|
+
|
|
74
|
+
declare function useSelectedElement(): {
|
|
75
|
+
element: null;
|
|
76
|
+
elementType: null;
|
|
77
|
+
} | {
|
|
78
|
+
element: Element;
|
|
79
|
+
elementType: ElementType;
|
|
70
80
|
};
|
|
71
|
-
|
|
81
|
+
|
|
82
|
+
declare const getElementSetting: <TValue>(elementId: ElementID, settingKey: string) => TValue | null;
|
|
83
|
+
|
|
84
|
+
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
85
|
+
|
|
86
|
+
declare function getElements(root?: ElementID): V1Element[];
|
|
72
87
|
|
|
73
88
|
declare function getSelectedElements(): Element[];
|
|
74
89
|
|
|
@@ -79,8 +94,20 @@ declare function getWidgetsCache(): Record<string, {
|
|
|
79
94
|
title: string;
|
|
80
95
|
}> | null;
|
|
81
96
|
|
|
82
|
-
declare const
|
|
97
|
+
declare const isElementInContainer: (element: Element, container: V1Element) => boolean;
|
|
83
98
|
|
|
84
|
-
declare const
|
|
99
|
+
declare const updateSettings: ({ id, props }: {
|
|
100
|
+
id: ElementID;
|
|
101
|
+
props: Props;
|
|
102
|
+
}) => void;
|
|
103
|
+
|
|
104
|
+
type UpdateStyleProps = {
|
|
105
|
+
elementID: ElementID;
|
|
106
|
+
styleDefID?: StyleDefinitionID;
|
|
107
|
+
meta: StyleVariant['meta'];
|
|
108
|
+
props: Props;
|
|
109
|
+
bind: PropKey;
|
|
110
|
+
};
|
|
111
|
+
declare const updateStyle: ({ elementID, styleDefID, meta, props, bind }: UpdateStyleProps) => Promise<void>;
|
|
85
112
|
|
|
86
|
-
export { type Control, type ControlItem, type ControlsSection, type Element, type ElementID, type ElementType, type PropsSchema, getElementSetting, getElementStyles, getSelectedElements, getWidgetsCache, updateSettings, updateStyle, useElementSetting, useElementStyleProp, useElementType, useSelectedElement };
|
|
113
|
+
export { type Control, type ControlItem, type ControlsSection, type Element, type ElementID, type ElementType, type PropsSchema, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, getElementSetting, getElementStyles, getElements, getSelectedElements, getVariantByMeta, getWidgetsCache, isElementInContainer, updateSettings, updateStyle, useElementSetting, useElementStyleProp, useElementStyles, useElementType, useElementsDomRef, useSelectedElement };
|
package/dist/index.js
CHANGED
|
@@ -22,88 +22,54 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
getElementSetting: () => getElementSetting,
|
|
24
24
|
getElementStyles: () => getElementStyles,
|
|
25
|
+
getElements: () => getElements,
|
|
25
26
|
getSelectedElements: () => getSelectedElements,
|
|
27
|
+
getVariantByMeta: () => getVariantByMeta,
|
|
26
28
|
getWidgetsCache: () => getWidgetsCache,
|
|
29
|
+
isElementInContainer: () => isElementInContainer,
|
|
27
30
|
updateSettings: () => updateSettings,
|
|
28
31
|
updateStyle: () => updateStyle,
|
|
29
32
|
useElementSetting: () => useElementSetting,
|
|
30
33
|
useElementStyleProp: () => useElementStyleProp,
|
|
34
|
+
useElementStyles: () => useElementStyles,
|
|
31
35
|
useElementType: () => useElementType,
|
|
36
|
+
useElementsDomRef: () => useElementsDomRef,
|
|
32
37
|
useSelectedElement: () => useSelectedElement
|
|
33
38
|
});
|
|
34
39
|
module.exports = __toCommonJS(src_exports);
|
|
35
40
|
|
|
36
|
-
// src/hooks/use-
|
|
37
|
-
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|
|
38
|
-
|
|
39
|
-
// src/sync/get-selected-elements.ts
|
|
40
|
-
function getSelectedElements() {
|
|
41
|
-
const extendedWindow = window;
|
|
42
|
-
const selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];
|
|
43
|
-
return selectedElements.reduce((acc, el) => {
|
|
44
|
-
const type = el.model.get("widgetType") || el.model.get("elType");
|
|
45
|
-
if (type) {
|
|
46
|
-
acc.push({
|
|
47
|
-
id: el.model.get("id"),
|
|
48
|
-
type
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return acc;
|
|
52
|
-
}, []);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/hooks/use-element-type.ts
|
|
41
|
+
// src/hooks/use-elements-dom-ref.ts
|
|
56
42
|
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
57
43
|
|
|
58
|
-
// src/sync/get-
|
|
59
|
-
function
|
|
44
|
+
// src/sync/get-current-document-container.ts
|
|
45
|
+
function getCurrentDocumentContainer() {
|
|
60
46
|
const extendedWindow = window;
|
|
61
|
-
return extendedWindow
|
|
47
|
+
return extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;
|
|
62
48
|
}
|
|
63
49
|
|
|
64
|
-
// src/hooks/use-
|
|
65
|
-
|
|
50
|
+
// src/hooks/use-elements-dom-ref.ts
|
|
51
|
+
var ELEMENTS_DATA_ATTR = "data-atomic";
|
|
52
|
+
function useElementsDomRef() {
|
|
66
53
|
return (0, import_editor_v1_adapters.__privateUseListenTo)(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!elementType?.atomic_controls) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
if (!elementType?.atomic_props_schema) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
key: type,
|
|
82
|
-
controls: elementType.atomic_controls,
|
|
83
|
-
propsSchema: elementType.atomic_props_schema,
|
|
84
|
-
title: elementType.title
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
[type]
|
|
54
|
+
[
|
|
55
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/preview/atomic-widget/render"),
|
|
56
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/preview/atomic-widget/destroy"),
|
|
57
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/editor/element-rendered"),
|
|
58
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/editor/element-destroyed")
|
|
59
|
+
],
|
|
60
|
+
() => getElementsDom()
|
|
88
61
|
);
|
|
89
62
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
[(0, import_editor_v1_adapters2.commandEndEvent)("document/elements/select"), (0, import_editor_v1_adapters2.commandEndEvent)("document/elements/deselect")],
|
|
95
|
-
getSelectedElements
|
|
96
|
-
);
|
|
97
|
-
const [element] = elements;
|
|
98
|
-
const elementType = useElementType(element?.type);
|
|
99
|
-
if (elements.length !== 1 || !elementType) {
|
|
100
|
-
return { element: null, elementType: null };
|
|
63
|
+
function getElementsDom() {
|
|
64
|
+
const root = getCurrentDocumentContainer();
|
|
65
|
+
if (!root?.view) {
|
|
66
|
+
return [];
|
|
101
67
|
}
|
|
102
|
-
return {
|
|
68
|
+
return [...root.view.el.querySelectorAll(`[${ELEMENTS_DATA_ATTR}]`)];
|
|
103
69
|
}
|
|
104
70
|
|
|
105
71
|
// src/hooks/use-element-setting.ts
|
|
106
|
-
var
|
|
72
|
+
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|
|
107
73
|
|
|
108
74
|
// src/sync/get-container.ts
|
|
109
75
|
function getContainer(id) {
|
|
@@ -113,22 +79,23 @@ function getContainer(id) {
|
|
|
113
79
|
}
|
|
114
80
|
|
|
115
81
|
// src/sync/get-element-setting.ts
|
|
116
|
-
var getElementSetting = (
|
|
117
|
-
const container = getContainer(
|
|
118
|
-
const value = container?.settings?.get(
|
|
82
|
+
var getElementSetting = (elementId, settingKey) => {
|
|
83
|
+
const container = getContainer(elementId);
|
|
84
|
+
const value = container?.settings?.get(settingKey);
|
|
119
85
|
return value ?? null;
|
|
120
86
|
};
|
|
121
87
|
|
|
122
88
|
// src/hooks/use-element-setting.ts
|
|
123
|
-
var useElementSetting = (
|
|
124
|
-
return (0,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
89
|
+
var useElementSetting = (elementId, settingKey) => {
|
|
90
|
+
return (0, import_editor_v1_adapters2.__privateUseListenTo)(
|
|
91
|
+
(0, import_editor_v1_adapters2.commandEndEvent)("document/elements/set-settings"),
|
|
92
|
+
() => getElementSetting(elementId, settingKey),
|
|
93
|
+
[elementId, settingKey]
|
|
94
|
+
);
|
|
128
95
|
};
|
|
129
96
|
|
|
130
97
|
// src/hooks/use-element-style-prop.ts
|
|
131
|
-
var
|
|
98
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
132
99
|
|
|
133
100
|
// src/sync/get-element-styles.ts
|
|
134
101
|
var getElementStyles = (elementID) => {
|
|
@@ -143,8 +110,8 @@ var useElementStyleProp = ({
|
|
|
143
110
|
meta,
|
|
144
111
|
propName
|
|
145
112
|
}) => {
|
|
146
|
-
return (0,
|
|
147
|
-
(0,
|
|
113
|
+
return (0, import_editor_v1_adapters3.__privateUseListenTo)(
|
|
114
|
+
(0, import_editor_v1_adapters3.commandEndEvent)("document/atomic-widgets/styles"),
|
|
148
115
|
() => {
|
|
149
116
|
if (!styleDefID) {
|
|
150
117
|
return null;
|
|
@@ -165,11 +132,111 @@ function getVariantByMeta(styleDef, meta) {
|
|
|
165
132
|
});
|
|
166
133
|
}
|
|
167
134
|
|
|
168
|
-
// src/
|
|
135
|
+
// src/hooks/use-element-styles.ts
|
|
136
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
137
|
+
function useElementStyles(elementId) {
|
|
138
|
+
return (0, import_editor_v1_adapters4.__privateUseListenTo)(
|
|
139
|
+
(0, import_editor_v1_adapters4.commandEndEvent)("document/atomic-widgets/styles"),
|
|
140
|
+
() => getElementStyles(elementId) ?? {},
|
|
141
|
+
[elementId]
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/hooks/use-element-type.ts
|
|
169
146
|
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
147
|
+
|
|
148
|
+
// src/sync/get-widgets-cache.ts
|
|
149
|
+
function getWidgetsCache() {
|
|
150
|
+
const extendedWindow = window;
|
|
151
|
+
return extendedWindow?.elementor?.widgetsCache || null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/hooks/use-element-type.ts
|
|
155
|
+
function useElementType(type) {
|
|
156
|
+
return (0, import_editor_v1_adapters5.__privateUseListenTo)(
|
|
157
|
+
(0, import_editor_v1_adapters5.commandEndEvent)("editor/documents/load"),
|
|
158
|
+
() => {
|
|
159
|
+
if (!type) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
const widgetsCache = getWidgetsCache();
|
|
163
|
+
const elementType = widgetsCache?.[type];
|
|
164
|
+
if (!elementType?.atomic_controls) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
if (!elementType?.atomic_props_schema) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
key: type,
|
|
172
|
+
controls: elementType.atomic_controls,
|
|
173
|
+
propsSchema: elementType.atomic_props_schema,
|
|
174
|
+
title: elementType.title
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
[type]
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/hooks/use-selected-element.ts
|
|
182
|
+
var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
|
|
183
|
+
|
|
184
|
+
// src/sync/get-selected-elements.ts
|
|
185
|
+
function getSelectedElements() {
|
|
186
|
+
const extendedWindow = window;
|
|
187
|
+
const selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];
|
|
188
|
+
return selectedElements.reduce((acc, el) => {
|
|
189
|
+
const type = el.model.get("widgetType") || el.model.get("elType");
|
|
190
|
+
if (type) {
|
|
191
|
+
acc.push({
|
|
192
|
+
id: el.model.get("id"),
|
|
193
|
+
type
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return acc;
|
|
197
|
+
}, []);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/hooks/use-selected-element.ts
|
|
201
|
+
function useSelectedElement() {
|
|
202
|
+
const elements = (0, import_editor_v1_adapters6.__privateUseListenTo)(
|
|
203
|
+
[(0, import_editor_v1_adapters6.commandEndEvent)("document/elements/select"), (0, import_editor_v1_adapters6.commandEndEvent)("document/elements/deselect")],
|
|
204
|
+
getSelectedElements
|
|
205
|
+
);
|
|
206
|
+
const [element] = elements;
|
|
207
|
+
const elementType = useElementType(element?.type);
|
|
208
|
+
if (elements.length !== 1 || !elementType) {
|
|
209
|
+
return { element: null, elementType: null };
|
|
210
|
+
}
|
|
211
|
+
return { element, elementType };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/sync/get-elements.ts
|
|
215
|
+
function getElements(root) {
|
|
216
|
+
const container = root ? getContainer(root) : getCurrentDocumentContainer();
|
|
217
|
+
if (!container) {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
const children = container.children?.flatMap((child) => getElements(child.id)) ?? [];
|
|
221
|
+
return [container, ...children];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/sync/is-element-in-container.ts
|
|
225
|
+
var isElementInContainer = (element, container) => {
|
|
226
|
+
if (container.model.get("id") === element.id && container.model.get("widgetType") === element.type) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
if (container.children && container.children.length > 0) {
|
|
230
|
+
return container.children.some((child) => isElementInContainer(element, child));
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// src/sync/update-settings.ts
|
|
236
|
+
var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
|
|
170
237
|
var updateSettings = ({ id, props }) => {
|
|
171
238
|
const container = getContainer(id);
|
|
172
|
-
(0,
|
|
239
|
+
(0, import_editor_v1_adapters7.__privateRunCommand)("document/elements/settings", {
|
|
173
240
|
container,
|
|
174
241
|
settings: {
|
|
175
242
|
...props
|
|
@@ -178,10 +245,10 @@ var updateSettings = ({ id, props }) => {
|
|
|
178
245
|
};
|
|
179
246
|
|
|
180
247
|
// src/sync/update-styles.ts
|
|
181
|
-
var
|
|
248
|
+
var import_editor_v1_adapters8 = require("@elementor/editor-v1-adapters");
|
|
182
249
|
var updateStyle = async ({ elementID, styleDefID, meta, props, bind }) => {
|
|
183
250
|
const container = getContainer(elementID);
|
|
184
|
-
await (0,
|
|
251
|
+
await (0, import_editor_v1_adapters8.__privateRunCommand)("document/atomic-widgets/styles", {
|
|
185
252
|
container,
|
|
186
253
|
styleDefID,
|
|
187
254
|
bind,
|
|
@@ -193,13 +260,18 @@ var updateStyle = async ({ elementID, styleDefID, meta, props, bind }) => {
|
|
|
193
260
|
0 && (module.exports = {
|
|
194
261
|
getElementSetting,
|
|
195
262
|
getElementStyles,
|
|
263
|
+
getElements,
|
|
196
264
|
getSelectedElements,
|
|
265
|
+
getVariantByMeta,
|
|
197
266
|
getWidgetsCache,
|
|
267
|
+
isElementInContainer,
|
|
198
268
|
updateSettings,
|
|
199
269
|
updateStyle,
|
|
200
270
|
useElementSetting,
|
|
201
271
|
useElementStyleProp,
|
|
272
|
+
useElementStyles,
|
|
202
273
|
useElementType,
|
|
274
|
+
useElementsDomRef,
|
|
203
275
|
useSelectedElement
|
|
204
276
|
});
|
|
205
277
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-element-setting.ts","../src/sync/get-container.ts","../src/sync/get-element-setting.ts","../src/hooks/use-element-style-prop.ts","../src/sync/get-element-styles.ts","../src/sync/update-settings.ts","../src/sync/update-styles.ts"],"sourcesContent":["// types\nexport * from './types';\n\n// hooks\nexport { useSelectedElement } from './hooks/use-selected-element';\nexport { useElementType } from './hooks/use-element-type';\nexport { useElementSetting } from './hooks/use-element-setting';\nexport { useElementStyleProp } from './hooks/use-element-style-prop';\n\n// utils\nexport { updateSettings } from './sync/update-settings';\nexport { updateStyle } from './sync/update-styles';\nexport { getSelectedElements } from './sync/get-selected-elements';\nexport { getWidgetsCache } from './sync/get-widgets-cache';\nexport { getElementStyles } from './sync/get-element-styles';\nexport { getElementSetting } from './sync/get-element-setting';\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\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 { ExtendedWindow } from './types';\nimport { Element } 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';\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { 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 { 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 { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { PropValue } from '@elementor/editor-props';\nimport { getElementSetting } from '../sync/get-element-setting';\n\nexport const useElementSetting = ( { id, bind }: { id: string; bind: string } ): PropValue => {\n\treturn useListenTo( commandEndEvent( 'document/elements/settings' ), () => getElementSetting( id, bind ), [\n\t\tid,\n\t\tbind,\n\t] );\n};\n","import { 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 { ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementSetting = < TValue >( elementID: ElementID, setting: string ): TValue | null => {\n\tconst container = getContainer( elementID );\n\tconst value = container?.settings?.get( setting ) as TValue;\n\n\treturn value ?? null;\n};\n","import { PropKey, PropValue } from '@elementor/editor-props';\nimport { StyleDefinition, StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';\nimport { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { ElementID } from '../types';\n\nexport type UseElementStylePropArgs = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tpropName: PropKey;\n};\n\nexport const useElementStyleProp = < T extends PropValue >( {\n\telementID,\n\tstyleDefID,\n\tmeta,\n\tpropName,\n}: UseElementStylePropArgs ): T | null => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/atomic-widgets/styles' ),\n\t\t() => {\n\t\t\t// TODO: return default value for style prop\n\t\t\tif ( ! styleDefID ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst styleDef = getElementStyles( elementID )?.[ styleDefID ];\n\n\t\t\tif ( ! styleDef ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst variant = getVariantByMeta( styleDef, meta );\n\n\t\t\treturn variant?.props[ propName ] ?? null;\n\t\t},\n\t\t[ elementID, styleDefID, propName, meta ]\n\t) as T;\n};\n\nfunction getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {\n\treturn styleDef.variants.find( ( variant ) => {\n\t\treturn variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;\n\t} );\n}\n","import { StyleDefinition } from '@elementor/editor-styles';\nimport { 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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport { Props } from '@elementor/editor-props';\nimport getContainer from './get-container';\nimport { ElementID } from '../types';\n\nexport const updateSettings = ( { id, props }: { id: ElementID; props: Props } ) => {\n\tconst container = getContainer( id );\n\n\trunCommand( 'document/elements/settings', {\n\t\tcontainer,\n\t\tsettings: {\n\t\t\t...props,\n\t\t},\n\t} );\n};\n","import { PropKey, Props } from '@elementor/editor-props';\nimport { StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';\nimport { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport getContainer from './get-container';\nimport { ElementID } from '../types';\n\nexport type UpdateStyleProps = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tprops: Props;\n\tbind: PropKey;\n};\n\nexport const updateStyle = async ( { elementID, styleDefID, meta, props, bind }: UpdateStyleProps ) => {\n\tconst container = getContainer( elementID );\n\n\tawait runCommand( 'document/atomic-widgets/styles', {\n\t\tcontainer,\n\t\tstyleDefID,\n\t\tbind,\n\t\tmeta,\n\t\tprops,\n\t} );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,6BAAqE;;;ACG9D,SAAS,sBAAiC;AAChD,QAAM,iBAAiB;AAEvB,QAAM,mBAAmB,eAAe,WAAW,WAAW,cAAc,KAAK,CAAC;AAElF,SAAO,iBAAiB,OAAqB,CAAE,KAAK,OAAQ;AAC3D,UAAM,OAAO,GAAG,MAAM,IAAK,YAAa,KAAK,GAAG,MAAM,IAAK,QAAS;AAEpE,QAAK,MAAO;AACX,UAAI,KAAM;AAAA,QACT,IAAI,GAAG,MAAM,IAAK,IAAK;AAAA,QACvB;AAAA,MACD,CAAE;AAAA,IACH;AAEA,WAAO;AAAA,EACR,GAAG,CAAC,CAAE;AACP;;;ACpBA,gCAAqE;;;ACE9D,SAAS,kBAAkB;AACjC,QAAM,iBAAiB;AAEvB,SAAO,gBAAgB,WAAW,gBAAgB;AACnD;;;ADFO,SAAS,eAAgB,MAAgB;AAC/C,aA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or_v1_adapters","useListenTo","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","runCommand","import_editor_v1_adapters","runCommand"]}
|
|
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-style-prop.ts","../src/sync/get-element-styles.ts","../src/hooks/use-element-styles.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/sync/get-elements.ts","../src/sync/is-element-in-container.ts","../src/sync/update-settings.ts","../src/sync/update-styles.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 { useElementStyleProp, getVariantByMeta } from './hooks/use-element-style-prop';\nexport { useElementStyles } from './hooks/use-element-styles';\nexport { useElementType } from './hooks/use-element-type';\nexport { useSelectedElement } from './hooks/use-selected-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 { updateSettings } from './sync/update-settings';\nexport { updateStyle } from './sync/update-styles';\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 { type PropKey, type PropValue } from '@elementor/editor-props';\nimport { type StyleDefinition, type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';\nimport { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport type UseElementStylePropArgs = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tpropName: PropKey;\n};\n\nexport const useElementStyleProp = < T extends PropValue >( {\n\telementID,\n\tstyleDefID,\n\tmeta,\n\tpropName,\n}: UseElementStylePropArgs ): T | null => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/atomic-widgets/styles' ),\n\t\t() => {\n\t\t\t// TODO: return default value for style prop\n\t\t\tif ( ! styleDefID ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst styleDef = getElementStyles( elementID )?.[ styleDefID ];\n\n\t\t\tif ( ! styleDef ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst variant = getVariantByMeta( styleDef, meta );\n\n\t\t\treturn variant?.props[ propName ] ?? null;\n\t\t},\n\t\t[ elementID, styleDefID, propName, meta ]\n\t) as T;\n};\n\nexport function getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {\n\treturn styleDef.variants.find( ( variant ) => {\n\t\treturn variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;\n\t} );\n}\n","import { type StyleDefinition } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {\n\tconst container = getContainer( elementID );\n\n\treturn container?.model.get( 'styles' ) || null;\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport function useElementStyles( elementId: ElementID ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/atomic-widgets/styles' ),\n\t\t() => getElementStyles( elementId ) ?? {},\n\t\t[ elementId ]\n\t);\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementType } from '../types';\n\nexport function useElementType( type?: string ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'editor/documents/load' ),\n\t\t(): ElementType | null => {\n\t\t\tif ( ! type ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst widgetsCache = getWidgetsCache();\n\t\t\tconst elementType = widgetsCache?.[ type ];\n\n\t\t\tif ( ! elementType?.atomic_controls ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif ( ! elementType?.atomic_props_schema ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\n\t\t\t\tpropsSchema: elementType.atomic_props_schema,\n\t\t\t\ttitle: elementType.title,\n\t\t\t};\n\t\t},\n\t\t[ type ]\n\t);\n}\n","import { type ExtendedWindow } from './types';\n\nexport function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getSelectedElements } from '../sync/get-selected-elements';\nimport { useElementType } from './use-element-type';\n\nexport function useSelectedElement() {\n\tconst elements = useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\tgetSelectedElements\n\t);\n\n\tconst [ element ] = elements;\n\n\tconst elementType = useElementType( element?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn { element: null, elementType: null };\n\t}\n\n\treturn { element, elementType };\n}\n","import { type Element } from '../types';\nimport { type ExtendedWindow } from './types';\n\nexport function getSelectedElements(): Element[] {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];\n\n\treturn selectedElements.reduce< Element[] >( ( acc, el ) => {\n\t\tconst type = el.model.get( 'widgetType' ) || el.model.get( 'elType' );\n\n\t\tif ( type ) {\n\t\t\tacc.push( {\n\t\t\t\tid: el.model.get( 'id' ),\n\t\t\t\ttype,\n\t\t\t} );\n\t\t}\n\n\t\treturn acc;\n\t}, [] );\n}\n","import { 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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const updateSettings = ( { id, props }: { id: ElementID; props: Props } ) => {\n\tconst container = getContainer( id );\n\n\trunCommand( 'document/elements/settings', {\n\t\tcontainer,\n\t\tsettings: {\n\t\t\t...props,\n\t\t},\n\t} );\n};\n","import { type PropKey, type Props } from '@elementor/editor-props';\nimport { type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';\nimport { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport type UpdateStyleProps = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tprops: Props;\n\tbind: PropKey;\n};\n\nexport const updateStyle = async ( { elementID, styleDefID, meta, props, bind }: UpdateStyleProps ) => {\n\tconst container = getContainer(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,UAAU,UAAU,QAAS,CAAE,UAAW,YAAa,MAAM,EAAG,CAAE,KAAK,CAAC;AAEzF,SAAO,CAAE,WAAW,GAAG,QAAS;AACjC;;;ACZO,IAAM,uBAAuB,CAAE,SAAkB,cAAmC;AAC1F,MAAK,UAAU,MAAM,IAAK,IAAK,MAAM,QAAQ,MAAM,UAAU,MAAM,IAAK,YAAa,MAAM,QAAQ,MAAO;AACzG,WAAO;AAAA,EACR;AAEA,MAAK,UAAU,YAAY,UAAU,SAAS,SAAS,GAAI;AAC1D,WAAO,UAAU,SAAS,KAAM,CAAE,UAAW,qBAAsB,SAAS,KAAM,CAAE;AAAA,EACrF;AAEA,SAAO;AACR;;;ACZA,IAAAC,6BAAkD;AAK3C,IAAM,iBAAiB,CAAE,EAAE,IAAI,MAAM,MAAwC;AACnF,QAAM,YAAY,aAAc,EAAG;AAEnC,iCAAAC,qBAAY,8BAA8B;AAAA,IACzC;AAAA,IACA,UAAU;AAAA,MACT,GAAG;AAAA,IACJ;AAAA,EACD,CAAE;AACH;;;ACbA,IAAAC,6BAAkD;AAa3C,IAAM,cAAc,OAAQ,EAAE,WAAW,YAAY,MAAM,OAAO,KAAK,MAAyB;AACtG,QAAM,YAAY,aAAc,SAAU;AAE1C,YAAM,2BAAAC,qBAAY,kCAAkC;AAAA,IACnD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AACH;","names":["useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","runCommand","import_editor_v1_adapters","runCommand"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,74 +1,35 @@
|
|
|
1
|
-
// src/hooks/use-
|
|
2
|
-
import { __privateUseListenTo as
|
|
1
|
+
// src/hooks/use-elements-dom-ref.ts
|
|
2
|
+
import { __privateUseListenTo as useListenTo, windowEvent } from "@elementor/editor-v1-adapters";
|
|
3
3
|
|
|
4
|
-
// src/sync/get-
|
|
5
|
-
function
|
|
4
|
+
// src/sync/get-current-document-container.ts
|
|
5
|
+
function getCurrentDocumentContainer() {
|
|
6
6
|
const extendedWindow = window;
|
|
7
|
-
|
|
8
|
-
return selectedElements.reduce((acc, el) => {
|
|
9
|
-
const type = el.model.get("widgetType") || el.model.get("elType");
|
|
10
|
-
if (type) {
|
|
11
|
-
acc.push({
|
|
12
|
-
id: el.model.get("id"),
|
|
13
|
-
type
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return acc;
|
|
17
|
-
}, []);
|
|
7
|
+
return extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;
|
|
18
8
|
}
|
|
19
9
|
|
|
20
|
-
// src/hooks/use-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// src/sync/get-widgets-cache.ts
|
|
24
|
-
function getWidgetsCache() {
|
|
25
|
-
const extendedWindow = window;
|
|
26
|
-
return extendedWindow?.elementor?.widgetsCache || null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/hooks/use-element-type.ts
|
|
30
|
-
function useElementType(type) {
|
|
10
|
+
// src/hooks/use-elements-dom-ref.ts
|
|
11
|
+
var ELEMENTS_DATA_ATTR = "data-atomic";
|
|
12
|
+
function useElementsDomRef() {
|
|
31
13
|
return useListenTo(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!elementType?.atomic_controls) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
if (!elementType?.atomic_props_schema) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
key: type,
|
|
47
|
-
controls: elementType.atomic_controls,
|
|
48
|
-
propsSchema: elementType.atomic_props_schema,
|
|
49
|
-
title: elementType.title
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
[type]
|
|
14
|
+
[
|
|
15
|
+
windowEvent("elementor/preview/atomic-widget/render"),
|
|
16
|
+
windowEvent("elementor/preview/atomic-widget/destroy"),
|
|
17
|
+
windowEvent("elementor/editor/element-rendered"),
|
|
18
|
+
windowEvent("elementor/editor/element-destroyed")
|
|
19
|
+
],
|
|
20
|
+
() => getElementsDom()
|
|
53
21
|
);
|
|
54
22
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
[commandEndEvent2("document/elements/select"), commandEndEvent2("document/elements/deselect")],
|
|
60
|
-
getSelectedElements
|
|
61
|
-
);
|
|
62
|
-
const [element] = elements;
|
|
63
|
-
const elementType = useElementType(element?.type);
|
|
64
|
-
if (elements.length !== 1 || !elementType) {
|
|
65
|
-
return { element: null, elementType: null };
|
|
23
|
+
function getElementsDom() {
|
|
24
|
+
const root = getCurrentDocumentContainer();
|
|
25
|
+
if (!root?.view) {
|
|
26
|
+
return [];
|
|
66
27
|
}
|
|
67
|
-
return {
|
|
28
|
+
return [...root.view.el.querySelectorAll(`[${ELEMENTS_DATA_ATTR}]`)];
|
|
68
29
|
}
|
|
69
30
|
|
|
70
31
|
// src/hooks/use-element-setting.ts
|
|
71
|
-
import {
|
|
32
|
+
import { __privateUseListenTo as useListenTo2, commandEndEvent } from "@elementor/editor-v1-adapters";
|
|
72
33
|
|
|
73
34
|
// src/sync/get-container.ts
|
|
74
35
|
function getContainer(id) {
|
|
@@ -78,22 +39,23 @@ function getContainer(id) {
|
|
|
78
39
|
}
|
|
79
40
|
|
|
80
41
|
// src/sync/get-element-setting.ts
|
|
81
|
-
var getElementSetting = (
|
|
82
|
-
const container = getContainer(
|
|
83
|
-
const value = container?.settings?.get(
|
|
42
|
+
var getElementSetting = (elementId, settingKey) => {
|
|
43
|
+
const container = getContainer(elementId);
|
|
44
|
+
const value = container?.settings?.get(settingKey);
|
|
84
45
|
return value ?? null;
|
|
85
46
|
};
|
|
86
47
|
|
|
87
48
|
// src/hooks/use-element-setting.ts
|
|
88
|
-
var useElementSetting = (
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
49
|
+
var useElementSetting = (elementId, settingKey) => {
|
|
50
|
+
return useListenTo2(
|
|
51
|
+
commandEndEvent("document/elements/set-settings"),
|
|
52
|
+
() => getElementSetting(elementId, settingKey),
|
|
53
|
+
[elementId, settingKey]
|
|
54
|
+
);
|
|
93
55
|
};
|
|
94
56
|
|
|
95
57
|
// src/hooks/use-element-style-prop.ts
|
|
96
|
-
import {
|
|
58
|
+
import { __privateUseListenTo as useListenTo3, commandEndEvent as commandEndEvent2 } from "@elementor/editor-v1-adapters";
|
|
97
59
|
|
|
98
60
|
// src/sync/get-element-styles.ts
|
|
99
61
|
var getElementStyles = (elementID) => {
|
|
@@ -108,8 +70,8 @@ var useElementStyleProp = ({
|
|
|
108
70
|
meta,
|
|
109
71
|
propName
|
|
110
72
|
}) => {
|
|
111
|
-
return
|
|
112
|
-
|
|
73
|
+
return useListenTo3(
|
|
74
|
+
commandEndEvent2("document/atomic-widgets/styles"),
|
|
113
75
|
() => {
|
|
114
76
|
if (!styleDefID) {
|
|
115
77
|
return null;
|
|
@@ -130,6 +92,106 @@ function getVariantByMeta(styleDef, meta) {
|
|
|
130
92
|
});
|
|
131
93
|
}
|
|
132
94
|
|
|
95
|
+
// src/hooks/use-element-styles.ts
|
|
96
|
+
import { __privateUseListenTo as useListenTo4, commandEndEvent as commandEndEvent3 } from "@elementor/editor-v1-adapters";
|
|
97
|
+
function useElementStyles(elementId) {
|
|
98
|
+
return useListenTo4(
|
|
99
|
+
commandEndEvent3("document/atomic-widgets/styles"),
|
|
100
|
+
() => getElementStyles(elementId) ?? {},
|
|
101
|
+
[elementId]
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/hooks/use-element-type.ts
|
|
106
|
+
import { __privateUseListenTo as useListenTo5, commandEndEvent as commandEndEvent4 } from "@elementor/editor-v1-adapters";
|
|
107
|
+
|
|
108
|
+
// src/sync/get-widgets-cache.ts
|
|
109
|
+
function getWidgetsCache() {
|
|
110
|
+
const extendedWindow = window;
|
|
111
|
+
return extendedWindow?.elementor?.widgetsCache || null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/hooks/use-element-type.ts
|
|
115
|
+
function useElementType(type) {
|
|
116
|
+
return useListenTo5(
|
|
117
|
+
commandEndEvent4("editor/documents/load"),
|
|
118
|
+
() => {
|
|
119
|
+
if (!type) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const widgetsCache = getWidgetsCache();
|
|
123
|
+
const elementType = widgetsCache?.[type];
|
|
124
|
+
if (!elementType?.atomic_controls) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
if (!elementType?.atomic_props_schema) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
key: type,
|
|
132
|
+
controls: elementType.atomic_controls,
|
|
133
|
+
propsSchema: elementType.atomic_props_schema,
|
|
134
|
+
title: elementType.title
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
[type]
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/hooks/use-selected-element.ts
|
|
142
|
+
import { __privateUseListenTo as useListenTo6, commandEndEvent as commandEndEvent5 } from "@elementor/editor-v1-adapters";
|
|
143
|
+
|
|
144
|
+
// src/sync/get-selected-elements.ts
|
|
145
|
+
function getSelectedElements() {
|
|
146
|
+
const extendedWindow = window;
|
|
147
|
+
const selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];
|
|
148
|
+
return selectedElements.reduce((acc, el) => {
|
|
149
|
+
const type = el.model.get("widgetType") || el.model.get("elType");
|
|
150
|
+
if (type) {
|
|
151
|
+
acc.push({
|
|
152
|
+
id: el.model.get("id"),
|
|
153
|
+
type
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return acc;
|
|
157
|
+
}, []);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/hooks/use-selected-element.ts
|
|
161
|
+
function useSelectedElement() {
|
|
162
|
+
const elements = useListenTo6(
|
|
163
|
+
[commandEndEvent5("document/elements/select"), commandEndEvent5("document/elements/deselect")],
|
|
164
|
+
getSelectedElements
|
|
165
|
+
);
|
|
166
|
+
const [element] = elements;
|
|
167
|
+
const elementType = useElementType(element?.type);
|
|
168
|
+
if (elements.length !== 1 || !elementType) {
|
|
169
|
+
return { element: null, elementType: null };
|
|
170
|
+
}
|
|
171
|
+
return { element, elementType };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/sync/get-elements.ts
|
|
175
|
+
function getElements(root) {
|
|
176
|
+
const container = root ? getContainer(root) : getCurrentDocumentContainer();
|
|
177
|
+
if (!container) {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
const children = container.children?.flatMap((child) => getElements(child.id)) ?? [];
|
|
181
|
+
return [container, ...children];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/sync/is-element-in-container.ts
|
|
185
|
+
var isElementInContainer = (element, container) => {
|
|
186
|
+
if (container.model.get("id") === element.id && container.model.get("widgetType") === element.type) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
if (container.children && container.children.length > 0) {
|
|
190
|
+
return container.children.some((child) => isElementInContainer(element, child));
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
};
|
|
194
|
+
|
|
133
195
|
// src/sync/update-settings.ts
|
|
134
196
|
import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
|
|
135
197
|
var updateSettings = ({ id, props }) => {
|
|
@@ -157,13 +219,18 @@ var updateStyle = async ({ elementID, styleDefID, meta, props, bind }) => {
|
|
|
157
219
|
export {
|
|
158
220
|
getElementSetting,
|
|
159
221
|
getElementStyles,
|
|
222
|
+
getElements,
|
|
160
223
|
getSelectedElements,
|
|
224
|
+
getVariantByMeta,
|
|
161
225
|
getWidgetsCache,
|
|
226
|
+
isElementInContainer,
|
|
162
227
|
updateSettings,
|
|
163
228
|
updateStyle,
|
|
164
229
|
useElementSetting,
|
|
165
230
|
useElementStyleProp,
|
|
231
|
+
useElementStyles,
|
|
166
232
|
useElementType,
|
|
233
|
+
useElementsDomRef,
|
|
167
234
|
useSelectedElement
|
|
168
235
|
};
|
|
169
236
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-element-setting.ts","../src/sync/get-container.ts","../src/sync/get-element-setting.ts","../src/hooks/use-element-style-prop.ts","../src/sync/get-element-styles.ts","../src/sync/update-settings.ts","../src/sync/update-styles.ts"],"sourcesContent":["import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\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 { ExtendedWindow } from './types';\nimport { Element } 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';\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { 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 { 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 { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { PropValue } from '@elementor/editor-props';\nimport { getElementSetting } from '../sync/get-element-setting';\n\nexport const useElementSetting = ( { id, bind }: { id: string; bind: string } ): PropValue => {\n\treturn useListenTo( commandEndEvent( 'document/elements/settings' ), () => getElementSetting( id, bind ), [\n\t\tid,\n\t\tbind,\n\t] );\n};\n","import { 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 { ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementSetting = < TValue >( elementID: ElementID, setting: string ): TValue | null => {\n\tconst container = getContainer( elementID );\n\tconst value = container?.settings?.get( setting ) as TValue;\n\n\treturn value ?? null;\n};\n","import { PropKey, PropValue } from '@elementor/editor-props';\nimport { StyleDefinition, StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';\nimport { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { ElementID } from '../types';\n\nexport type UseElementStylePropArgs = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tpropName: PropKey;\n};\n\nexport const useElementStyleProp = < T extends PropValue >( {\n\telementID,\n\tstyleDefID,\n\tmeta,\n\tpropName,\n}: UseElementStylePropArgs ): T | null => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/atomic-widgets/styles' ),\n\t\t() => {\n\t\t\t// TODO: return default value for style prop\n\t\t\tif ( ! styleDefID ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst styleDef = getElementStyles( elementID )?.[ styleDefID ];\n\n\t\t\tif ( ! styleDef ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst variant = getVariantByMeta( styleDef, meta );\n\n\t\t\treturn variant?.props[ propName ] ?? null;\n\t\t},\n\t\t[ elementID, styleDefID, propName, meta ]\n\t) as T;\n};\n\nfunction getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {\n\treturn styleDef.variants.find( ( variant ) => {\n\t\treturn variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;\n\t} );\n}\n","import { StyleDefinition } from '@elementor/editor-styles';\nimport { 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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport { Props } from '@elementor/editor-props';\nimport getContainer from './get-container';\nimport { ElementID } from '../types';\n\nexport const updateSettings = ( { id, props }: { id: ElementID; props: Props } ) => {\n\tconst container = getContainer( id );\n\n\trunCommand( 'document/elements/settings', {\n\t\tcontainer,\n\t\tsettings: {\n\t\t\t...props,\n\t\t},\n\t} );\n};\n","import { PropKey, Props } from '@elementor/editor-props';\nimport { StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';\nimport { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport getContainer from './get-container';\nimport { ElementID } from '../types';\n\nexport type UpdateStyleProps = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tprops: Props;\n\tbind: PropKey;\n};\n\nexport const updateStyle = async ( { elementID, styleDefID, meta, props, bind }: UpdateStyleProps ) => {\n\tconst container = getContainer( elementID );\n\n\tawait runCommand( 'document/atomic-widgets/styles', {\n\t\tcontainer,\n\t\tstyleDefID,\n\t\tbind,\n\t\tmeta,\n\t\tprops,\n\t} );\n};\n"],"mappings":";AAAA,SAAS,wBAAwBA,cAAa,mBAAAC,wBAAuB;;;ACG9D,SAAS,sBAAiC;AAChD,QAAM,iBAAiB;AAEvB,QAAM,mBAAmB,eAAe,WAAW,WAAW,cAAc,KAAK,CAAC;AAElF,SAAO,iBAAiB,OAAqB,CAAE,KAAK,OAAQ;AAC3D,UAAM,OAAO,GAAG,MAAM,IAAK,YAAa,KAAK,GAAG,MAAM,IAAK,QAAS;AAEpE,QAAK,MAAO;AACX,UAAI,KAAM;AAAA,QACT,IAAI,GAAG,MAAM,IAAK,IAAK;AAAA,QACvB;AAAA,MACD,CAAE;AAAA,IACH;AAEA,WAAO;AAAA,EACR,GAAG,CAAC,CAAE;AACP;;;ACpBA,SAAS,wBAAwB,aAAa,uBAAuB;;;ACE9D,SAAS,kBAAkB;AACjC,QAAM,iBAAiB;AAEvB,SAAO,gBAAgB,WAAW,gBAAgB;AACnD;;;ADFO,SAAS,eAAgB,MAAgB;AAC/C,SAAO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CAAE;AACH;","names":["useListenTo","commandEndEvent","useListenTo","commandEndEvent","commandEndEvent","useListenTo","useListenTo","commandEndEvent","commandEndEvent","useListenTo","useListenTo","commandEndEvent","runCommand","runCommand"]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-elements-dom-ref.ts","../src/sync/get-current-document-container.ts","../src/hooks/use-element-setting.ts","../src/sync/get-container.ts","../src/sync/get-element-setting.ts","../src/hooks/use-element-style-prop.ts","../src/sync/get-element-styles.ts","../src/hooks/use-element-styles.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/hooks/use-selected-element.ts","../src/sync/get-selected-elements.ts","../src/sync/get-elements.ts","../src/sync/is-element-in-container.ts","../src/sync/update-settings.ts","../src/sync/update-styles.ts"],"sourcesContent":["import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport getCurrentDocumentContainer from '../sync/get-current-document-container';\n\nconst ELEMENTS_DATA_ATTR = 'data-atomic';\n\nexport function useElementsDomRef(): HTMLElement[] {\n\treturn useListenTo(\n\t\t[\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/render' ),\n\t\t\twindowEvent( 'elementor/preview/atomic-widget/destroy' ),\n\t\t\twindowEvent( 'elementor/editor/element-rendered' ),\n\t\t\twindowEvent( 'elementor/editor/element-destroyed' ),\n\t\t],\n\t\t() => getElementsDom()\n\t);\n}\n\nfunction getElementsDom(): HTMLElement[] {\n\tconst root = getCurrentDocumentContainer();\n\n\tif ( ! root?.view ) {\n\t\treturn [];\n\t}\n\n\treturn [ ...root.view.el.querySelectorAll< HTMLElement >( `[${ ELEMENTS_DATA_ATTR }]` ) ];\n}\n","import { type ExtendedWindow } from './types';\n\nexport default function getCurrentDocumentContainer() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementSetting } from '../sync/get-element-setting';\nimport { type ElementID } from '../types';\n\nexport const useElementSetting = < TValue >( elementId: ElementID, settingKey: string ) => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/set-settings' ),\n\t\t() => getElementSetting< TValue >( elementId, settingKey ),\n\t\t[ elementId, settingKey ]\n\t);\n};\n","import { type ExtendedWindow } from './types';\n\nexport default function getContainer( id: string ) {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\tconst container = extendedWindow.elementor?.getContainer?.( id );\n\n\treturn container ?? null;\n}\n","import { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementSetting = < TValue >( elementId: ElementID, settingKey: string ): TValue | null => {\n\tconst container = getContainer( elementId );\n\tconst value = container?.settings?.get( settingKey ) as TValue;\n\n\treturn value ?? null;\n};\n","import { type PropKey, type PropValue } from '@elementor/editor-props';\nimport { type StyleDefinition, type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';\nimport { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport type UseElementStylePropArgs = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tpropName: PropKey;\n};\n\nexport const useElementStyleProp = < T extends PropValue >( {\n\telementID,\n\tstyleDefID,\n\tmeta,\n\tpropName,\n}: UseElementStylePropArgs ): T | null => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/atomic-widgets/styles' ),\n\t\t() => {\n\t\t\t// TODO: return default value for style prop\n\t\t\tif ( ! styleDefID ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst styleDef = getElementStyles( elementID )?.[ styleDefID ];\n\n\t\t\tif ( ! styleDef ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst variant = getVariantByMeta( styleDef, meta );\n\n\t\t\treturn variant?.props[ propName ] ?? null;\n\t\t},\n\t\t[ elementID, styleDefID, propName, meta ]\n\t) as T;\n};\n\nexport function getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {\n\treturn styleDef.variants.find( ( variant ) => {\n\t\treturn variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;\n\t} );\n}\n","import { type StyleDefinition } from '@elementor/editor-styles';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {\n\tconst container = getContainer( elementID );\n\n\treturn container?.model.get( 'styles' ) || null;\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getElementStyles } from '../sync/get-element-styles';\nimport { type ElementID } from '../types';\n\nexport function useElementStyles( elementId: ElementID ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/atomic-widgets/styles' ),\n\t\t() => getElementStyles( elementId ) ?? {},\n\t\t[ elementId ]\n\t);\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getWidgetsCache } from '../sync/get-widgets-cache';\nimport { type ElementType } from '../types';\n\nexport function useElementType( type?: string ) {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'editor/documents/load' ),\n\t\t(): ElementType | null => {\n\t\t\tif ( ! type ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst widgetsCache = getWidgetsCache();\n\t\t\tconst elementType = widgetsCache?.[ type ];\n\n\t\t\tif ( ! elementType?.atomic_controls ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif ( ! elementType?.atomic_props_schema ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\n\t\t\t\tpropsSchema: elementType.atomic_props_schema,\n\t\t\t\ttitle: elementType.title,\n\t\t\t};\n\t\t},\n\t\t[ type ]\n\t);\n}\n","import { type ExtendedWindow } from './types';\n\nexport function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\n\nimport { getSelectedElements } from '../sync/get-selected-elements';\nimport { useElementType } from './use-element-type';\n\nexport function useSelectedElement() {\n\tconst elements = useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\tgetSelectedElements\n\t);\n\n\tconst [ element ] = elements;\n\n\tconst elementType = useElementType( element?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn { element: null, elementType: null };\n\t}\n\n\treturn { element, elementType };\n}\n","import { type Element } from '../types';\nimport { type ExtendedWindow } from './types';\n\nexport function getSelectedElements(): Element[] {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\tconst selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];\n\n\treturn selectedElements.reduce< Element[] >( ( acc, el ) => {\n\t\tconst type = el.model.get( 'widgetType' ) || el.model.get( 'elType' );\n\n\t\tif ( type ) {\n\t\t\tacc.push( {\n\t\t\t\tid: el.model.get( 'id' ),\n\t\t\t\ttype,\n\t\t\t} );\n\t\t}\n\n\t\treturn acc;\n\t}, [] );\n}\n","import { 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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport const updateSettings = ( { id, props }: { id: ElementID; props: Props } ) => {\n\tconst container = getContainer( id );\n\n\trunCommand( 'document/elements/settings', {\n\t\tcontainer,\n\t\tsettings: {\n\t\t\t...props,\n\t\t},\n\t} );\n};\n","import { type PropKey, type Props } from '@elementor/editor-props';\nimport { type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';\nimport { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nimport { type ElementID } from '../types';\nimport getContainer from './get-container';\n\nexport type UpdateStyleProps = {\n\telementID: ElementID;\n\tstyleDefID?: StyleDefinitionID;\n\tmeta: StyleVariant[ 'meta' ];\n\tprops: Props;\n\tbind: PropKey;\n};\n\nexport const updateStyle = async ( { elementID, styleDefID, meta, props, bind }: UpdateStyleProps ) => {\n\tconst container = getContainer( elementID );\n\n\tawait runCommand( 'document/atomic-widgets/styles', {\n\t\tcontainer,\n\t\tstyleDefID,\n\t\tbind,\n\t\tmeta,\n\t\tprops,\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,iBAAg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;AAAA,IACzC;AAAA,IACA,UAAU;AAAA,MACT,GAAG;AAAA,IACJ;AAAA,EACD,CAAE;AACH;;;ACbA,SAAS,uBAAuBC,mBAAkB;AAa3C,IAAM,cAAc,OAAQ,EAAE,WAAW,YAAY,MAAM,OAAO,KAAK,MAAyB;AACtG,QAAM,YAAY,aAAc,SAAU;AAE1C,QAAMC,YAAY,kCAAkC;AAAA,IACnD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AACH;","names":["useListenTo","useListenTo","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","useListenTo","commandEndEvent","runCommand","runCommand"]}
|
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.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-props": "^0.
|
|
44
|
-
"@elementor/editor-styles": "0.
|
|
45
|
-
"@elementor/editor-v1-adapters": "^0.8.
|
|
43
|
+
"@elementor/editor-props": "^0.3.0",
|
|
44
|
+
"@elementor/editor-styles": "0.3.0",
|
|
45
|
+
"@elementor/editor-v1-adapters": "^0.8.4"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": "^18.3.1"
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
|
|
3
3
|
import { getElementSetting } from '../sync/get-element-setting';
|
|
4
|
+
import { type ElementID } from '../types';
|
|
4
5
|
|
|
5
|
-
export const useElementSetting =
|
|
6
|
-
return useListenTo(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export const useElementSetting = < TValue >( elementId: ElementID, settingKey: string ) => {
|
|
7
|
+
return useListenTo(
|
|
8
|
+
commandEndEvent( 'document/elements/set-settings' ),
|
|
9
|
+
() => getElementSetting< TValue >( elementId, settingKey ),
|
|
10
|
+
[ elementId, settingKey ]
|
|
11
|
+
);
|
|
10
12
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { PropKey, PropValue } from '@elementor/editor-props';
|
|
2
|
-
import { StyleDefinition, StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';
|
|
3
|
-
import {
|
|
1
|
+
import { type PropKey, type PropValue } from '@elementor/editor-props';
|
|
2
|
+
import { type StyleDefinition, type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';
|
|
3
|
+
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
4
|
+
|
|
4
5
|
import { getElementStyles } from '../sync/get-element-styles';
|
|
5
|
-
import { ElementID } from '../types';
|
|
6
|
+
import { type ElementID } from '../types';
|
|
6
7
|
|
|
7
8
|
export type UseElementStylePropArgs = {
|
|
8
9
|
elementID: ElementID;
|
|
@@ -39,7 +40,7 @@ export const useElementStyleProp = < T extends PropValue >( {
|
|
|
39
40
|
) as T;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
function getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {
|
|
43
|
+
export function getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {
|
|
43
44
|
return styleDef.variants.find( ( variant ) => {
|
|
44
45
|
return variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;
|
|
45
46
|
} );
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
|
|
3
|
+
import { getElementStyles } from '../sync/get-element-styles';
|
|
4
|
+
import { type ElementID } from '../types';
|
|
5
|
+
|
|
6
|
+
export function useElementStyles( elementId: ElementID ) {
|
|
7
|
+
return useListenTo(
|
|
8
|
+
commandEndEvent( 'document/atomic-widgets/styles' ),
|
|
9
|
+
() => getElementStyles( elementId ) ?? {},
|
|
10
|
+
[ elementId ]
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
|
|
2
3
|
import { getWidgetsCache } from '../sync/get-widgets-cache';
|
|
3
|
-
import { ElementType } from '../types';
|
|
4
|
+
import { type ElementType } from '../types';
|
|
4
5
|
|
|
5
6
|
export function useElementType( type?: string ) {
|
|
6
7
|
return useListenTo(
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
|
|
3
|
+
import getCurrentDocumentContainer from '../sync/get-current-document-container';
|
|
4
|
+
|
|
5
|
+
const ELEMENTS_DATA_ATTR = 'data-atomic';
|
|
6
|
+
|
|
7
|
+
export function useElementsDomRef(): HTMLElement[] {
|
|
8
|
+
return useListenTo(
|
|
9
|
+
[
|
|
10
|
+
windowEvent( 'elementor/preview/atomic-widget/render' ),
|
|
11
|
+
windowEvent( 'elementor/preview/atomic-widget/destroy' ),
|
|
12
|
+
windowEvent( 'elementor/editor/element-rendered' ),
|
|
13
|
+
windowEvent( 'elementor/editor/element-destroyed' ),
|
|
14
|
+
],
|
|
15
|
+
() => getElementsDom()
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getElementsDom(): HTMLElement[] {
|
|
20
|
+
const root = getCurrentDocumentContainer();
|
|
21
|
+
|
|
22
|
+
if ( ! root?.view ) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return [ ...root.view.el.querySelectorAll< HTMLElement >( `[${ ELEMENTS_DATA_ATTR }]` ) ];
|
|
27
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
// types
|
|
2
2
|
export * from './types';
|
|
3
|
+
export type { V1Element, V1ElementModelProps, V1ElementSettingsProps } from './sync/types';
|
|
3
4
|
|
|
4
5
|
// hooks
|
|
5
|
-
export {
|
|
6
|
-
export { useElementType } from './hooks/use-element-type';
|
|
6
|
+
export { useElementsDomRef } from './hooks/use-elements-dom-ref';
|
|
7
7
|
export { useElementSetting } from './hooks/use-element-setting';
|
|
8
|
-
export { useElementStyleProp } from './hooks/use-element-style-prop';
|
|
8
|
+
export { useElementStyleProp, getVariantByMeta } from './hooks/use-element-style-prop';
|
|
9
|
+
export { useElementStyles } from './hooks/use-element-styles';
|
|
10
|
+
export { useElementType } from './hooks/use-element-type';
|
|
11
|
+
export { useSelectedElement } from './hooks/use-selected-element';
|
|
9
12
|
|
|
10
13
|
// utils
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
14
|
+
export { getElementSetting } from './sync/get-element-setting';
|
|
15
|
+
export { getElementStyles } from './sync/get-element-styles';
|
|
16
|
+
export { getElements } from './sync/get-elements';
|
|
13
17
|
export { getSelectedElements } from './sync/get-selected-elements';
|
|
14
18
|
export { getWidgetsCache } from './sync/get-widgets-cache';
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
19
|
+
export { isElementInContainer } from './sync/is-element-in-container';
|
|
20
|
+
export { updateSettings } from './sync/update-settings';
|
|
21
|
+
export { updateStyle } from './sync/update-styles';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ElementID } from '../types';
|
|
1
|
+
import { type ElementID } from '../types';
|
|
2
2
|
import getContainer from './get-container';
|
|
3
3
|
|
|
4
|
-
export const getElementSetting = < TValue >(
|
|
5
|
-
const container = getContainer(
|
|
6
|
-
const value = container?.settings?.get(
|
|
4
|
+
export const getElementSetting = < TValue >( elementId: ElementID, settingKey: string ): TValue | null => {
|
|
5
|
+
const container = getContainer( elementId );
|
|
6
|
+
const value = container?.settings?.get( settingKey ) as TValue;
|
|
7
7
|
|
|
8
8
|
return value ?? null;
|
|
9
9
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StyleDefinition } from '@elementor/editor-styles';
|
|
2
|
-
|
|
1
|
+
import { type StyleDefinition } from '@elementor/editor-styles';
|
|
2
|
+
|
|
3
|
+
import { type ElementID } from '../types';
|
|
3
4
|
import getContainer from './get-container';
|
|
4
5
|
|
|
5
6
|
export const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ElementID } from '../types';
|
|
2
|
+
import getContainer from './get-container';
|
|
3
|
+
import getCurrentDocumentContainer from './get-current-document-container';
|
|
4
|
+
import { type V1Element } from './types';
|
|
5
|
+
|
|
6
|
+
export function getElements( root?: ElementID ): V1Element[] {
|
|
7
|
+
const container = root ? getContainer( root ) : getCurrentDocumentContainer();
|
|
8
|
+
|
|
9
|
+
if ( ! container ) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const children = container.children?.flatMap( ( child ) => getElements( child.id ) ) ?? [];
|
|
14
|
+
|
|
15
|
+
return [ container, ...children ];
|
|
16
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type Element } from '../types';
|
|
2
|
+
import { type ExtendedWindow } from './types';
|
|
3
3
|
|
|
4
4
|
export function getSelectedElements(): Element[] {
|
|
5
5
|
const extendedWindow = window as unknown as ExtendedWindow;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Element } from '../types';
|
|
2
|
+
import { type V1Element } from './types';
|
|
3
|
+
|
|
4
|
+
export const isElementInContainer = ( element: Element, container: V1Element ): boolean => {
|
|
5
|
+
if ( container.model.get( 'id' ) === element.id && container.model.get( 'widgetType' ) === element.type ) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if ( container.children && container.children.length > 0 ) {
|
|
10
|
+
return container.children.some( ( child ) => isElementInContainer( element, child ) );
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return false;
|
|
14
|
+
};
|
package/src/sync/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { PropValue } from '@elementor/editor-props';
|
|
2
|
-
import { StyleDefinition, StyleDefinitionID } from '@elementor/editor-styles';
|
|
3
|
-
|
|
1
|
+
import { type PropValue } from '@elementor/editor-props';
|
|
2
|
+
import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';
|
|
3
|
+
|
|
4
|
+
import { type ControlItem, type PropsSchema } from '../types';
|
|
4
5
|
|
|
5
6
|
export type ExtendedWindow = Window & {
|
|
6
7
|
elementor?: {
|
|
@@ -16,13 +17,25 @@ export type ExtendedWindow = Window & {
|
|
|
16
17
|
title: string;
|
|
17
18
|
}
|
|
18
19
|
>;
|
|
19
|
-
|
|
20
|
+
documents?: {
|
|
21
|
+
getCurrent?: () =>
|
|
22
|
+
| {
|
|
23
|
+
container: V1Element;
|
|
24
|
+
}
|
|
25
|
+
| undefined;
|
|
26
|
+
};
|
|
27
|
+
getContainer?: ( id: string ) => V1Element | undefined;
|
|
20
28
|
};
|
|
21
29
|
};
|
|
22
30
|
|
|
23
31
|
export type V1Element = {
|
|
32
|
+
id: string;
|
|
24
33
|
model: V1Model< V1ElementModelProps >;
|
|
25
34
|
settings?: V1Model< V1ElementSettingsProps >;
|
|
35
|
+
children?: V1Element[];
|
|
36
|
+
view?: {
|
|
37
|
+
el: HTMLElement;
|
|
38
|
+
};
|
|
26
39
|
};
|
|
27
40
|
|
|
28
41
|
export type V1ElementModelProps = {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type Props } from '@elementor/editor-props';
|
|
1
2
|
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
2
|
-
|
|
3
|
+
|
|
4
|
+
import { type ElementID } from '../types';
|
|
3
5
|
import getContainer from './get-container';
|
|
4
|
-
import { ElementID } from '../types';
|
|
5
6
|
|
|
6
7
|
export const updateSettings = ( { id, props }: { id: ElementID; props: Props } ) => {
|
|
7
8
|
const container = getContainer( id );
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { PropKey, Props } from '@elementor/editor-props';
|
|
2
|
-
import { StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';
|
|
1
|
+
import { type PropKey, type Props } from '@elementor/editor-props';
|
|
2
|
+
import { type StyleDefinitionID, type StyleVariant } from '@elementor/editor-styles';
|
|
3
3
|
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
4
|
+
|
|
5
|
+
import { type ElementID } from '../types';
|
|
4
6
|
import getContainer from './get-container';
|
|
5
|
-
import { ElementID } from '../types';
|
|
6
7
|
|
|
7
8
|
export type UpdateStyleProps = {
|
|
8
9
|
elementID: ElementID;
|
package/src/types.ts
CHANGED