@elementor/editor-elements 0.2.0 → 0.3.0
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 +51 -26
- package/dist/index.d.ts +51 -26
- package/dist/index.js +134 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -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 +11 -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-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,24 @@
|
|
|
1
1
|
# @elementor/editor-elements
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e7f4706: save style props to session
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 7781969: Create basic UI for the class selector
|
|
12
|
+
- d21c5c3: Introduce editor canvas to render element overlays for atomic elements
|
|
13
|
+
- 7781969: Update `@elementor/ui` version
|
|
14
|
+
- Updated dependencies [7781969]
|
|
15
|
+
- Updated dependencies [6e240a8]
|
|
16
|
+
- Updated dependencies [7781969]
|
|
17
|
+
- Updated dependencies [0c6bcb6]
|
|
18
|
+
- @elementor/editor-styles@0.2.1
|
|
19
|
+
- @elementor/editor-props@0.3.0
|
|
20
|
+
- @elementor/editor-v1-adapters@0.8.4
|
|
21
|
+
|
|
3
22
|
## 0.2.0
|
|
4
23
|
|
|
5
24
|
### 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,23 @@ 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;
|
|
72
85
|
|
|
73
86
|
declare function getSelectedElements(): Element[];
|
|
74
87
|
|
|
@@ -79,8 +92,20 @@ declare function getWidgetsCache(): Record<string, {
|
|
|
79
92
|
title: string;
|
|
80
93
|
}> | null;
|
|
81
94
|
|
|
82
|
-
declare const
|
|
95
|
+
declare const isElementInContainer: (element: Element, container: V1Element) => boolean;
|
|
96
|
+
|
|
97
|
+
declare const updateSettings: ({ id, props }: {
|
|
98
|
+
id: ElementID;
|
|
99
|
+
props: Props;
|
|
100
|
+
}) => void;
|
|
83
101
|
|
|
84
|
-
|
|
102
|
+
type UpdateStyleProps = {
|
|
103
|
+
elementID: ElementID;
|
|
104
|
+
styleDefID?: StyleDefinitionID;
|
|
105
|
+
meta: StyleVariant['meta'];
|
|
106
|
+
props: Props;
|
|
107
|
+
bind: PropKey;
|
|
108
|
+
};
|
|
109
|
+
declare const updateStyle: ({ elementID, styleDefID, meta, props, bind }: UpdateStyleProps) => Promise<void>;
|
|
85
110
|
|
|
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 };
|
|
111
|
+
export { type Control, type ControlItem, type ControlsSection, type Element, type ElementID, type ElementType, type PropsSchema, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, getElementSetting, getElementStyles, 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,23 @@ 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;
|
|
72
85
|
|
|
73
86
|
declare function getSelectedElements(): Element[];
|
|
74
87
|
|
|
@@ -79,8 +92,20 @@ declare function getWidgetsCache(): Record<string, {
|
|
|
79
92
|
title: string;
|
|
80
93
|
}> | null;
|
|
81
94
|
|
|
82
|
-
declare const
|
|
95
|
+
declare const isElementInContainer: (element: Element, container: V1Element) => boolean;
|
|
96
|
+
|
|
97
|
+
declare const updateSettings: ({ id, props }: {
|
|
98
|
+
id: ElementID;
|
|
99
|
+
props: Props;
|
|
100
|
+
}) => void;
|
|
83
101
|
|
|
84
|
-
|
|
102
|
+
type UpdateStyleProps = {
|
|
103
|
+
elementID: ElementID;
|
|
104
|
+
styleDefID?: StyleDefinitionID;
|
|
105
|
+
meta: StyleVariant['meta'];
|
|
106
|
+
props: Props;
|
|
107
|
+
bind: PropKey;
|
|
108
|
+
};
|
|
109
|
+
declare const updateStyle: ({ elementID, styleDefID, meta, props, bind }: UpdateStyleProps) => Promise<void>;
|
|
85
110
|
|
|
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 };
|
|
111
|
+
export { type Control, type ControlItem, type ControlsSection, type Element, type ElementID, type ElementType, type PropsSchema, type V1Element, type V1ElementModelProps, type V1ElementSettingsProps, getElementSetting, getElementStyles, getSelectedElements, getVariantByMeta, getWidgetsCache, isElementInContainer, updateSettings, updateStyle, useElementSetting, useElementStyleProp, useElementStyles, useElementType, useElementsDomRef, useSelectedElement };
|
package/dist/index.js
CHANGED
|
@@ -23,87 +23,52 @@ __export(src_exports, {
|
|
|
23
23
|
getElementSetting: () => getElementSetting,
|
|
24
24
|
getElementStyles: () => getElementStyles,
|
|
25
25
|
getSelectedElements: () => getSelectedElements,
|
|
26
|
+
getVariantByMeta: () => getVariantByMeta,
|
|
26
27
|
getWidgetsCache: () => getWidgetsCache,
|
|
28
|
+
isElementInContainer: () => isElementInContainer,
|
|
27
29
|
updateSettings: () => updateSettings,
|
|
28
30
|
updateStyle: () => updateStyle,
|
|
29
31
|
useElementSetting: () => useElementSetting,
|
|
30
32
|
useElementStyleProp: () => useElementStyleProp,
|
|
33
|
+
useElementStyles: () => useElementStyles,
|
|
31
34
|
useElementType: () => useElementType,
|
|
35
|
+
useElementsDomRef: () => useElementsDomRef,
|
|
32
36
|
useSelectedElement: () => useSelectedElement
|
|
33
37
|
});
|
|
34
38
|
module.exports = __toCommonJS(src_exports);
|
|
35
39
|
|
|
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
|
|
40
|
+
// src/hooks/use-elements-dom-ref.ts
|
|
56
41
|
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
57
42
|
|
|
58
|
-
// src/sync/get-
|
|
59
|
-
function
|
|
43
|
+
// src/sync/get-current-document-container.ts
|
|
44
|
+
function getCurrentDocumentContainer() {
|
|
60
45
|
const extendedWindow = window;
|
|
61
|
-
return extendedWindow
|
|
46
|
+
return extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;
|
|
62
47
|
}
|
|
63
48
|
|
|
64
|
-
// src/hooks/use-
|
|
65
|
-
|
|
49
|
+
// src/hooks/use-elements-dom-ref.ts
|
|
50
|
+
var ELEMENTS_DATA_ATTR = "data-atomic";
|
|
51
|
+
function useElementsDomRef() {
|
|
66
52
|
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]
|
|
53
|
+
[
|
|
54
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/preview/atomic-widget/render"),
|
|
55
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/preview/atomic-widget/destroy"),
|
|
56
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/editor/element-rendered"),
|
|
57
|
+
(0, import_editor_v1_adapters.windowEvent)("elementor/editor/element-destroyed")
|
|
58
|
+
],
|
|
59
|
+
() => getElementsDom()
|
|
88
60
|
);
|
|
89
61
|
}
|
|
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 };
|
|
62
|
+
function getElementsDom() {
|
|
63
|
+
const root = getCurrentDocumentContainer();
|
|
64
|
+
if (!root?.view) {
|
|
65
|
+
return [];
|
|
101
66
|
}
|
|
102
|
-
return {
|
|
67
|
+
return [...root.view.el.querySelectorAll(`[${ELEMENTS_DATA_ATTR}]`)];
|
|
103
68
|
}
|
|
104
69
|
|
|
105
70
|
// src/hooks/use-element-setting.ts
|
|
106
|
-
var
|
|
71
|
+
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|
|
107
72
|
|
|
108
73
|
// src/sync/get-container.ts
|
|
109
74
|
function getContainer(id) {
|
|
@@ -113,22 +78,23 @@ function getContainer(id) {
|
|
|
113
78
|
}
|
|
114
79
|
|
|
115
80
|
// src/sync/get-element-setting.ts
|
|
116
|
-
var getElementSetting = (
|
|
117
|
-
const container = getContainer(
|
|
118
|
-
const value = container?.settings?.get(
|
|
81
|
+
var getElementSetting = (elementId, settingKey) => {
|
|
82
|
+
const container = getContainer(elementId);
|
|
83
|
+
const value = container?.settings?.get(settingKey);
|
|
119
84
|
return value ?? null;
|
|
120
85
|
};
|
|
121
86
|
|
|
122
87
|
// src/hooks/use-element-setting.ts
|
|
123
|
-
var useElementSetting = (
|
|
124
|
-
return (0,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
88
|
+
var useElementSetting = (elementId, settingKey) => {
|
|
89
|
+
return (0, import_editor_v1_adapters2.__privateUseListenTo)(
|
|
90
|
+
(0, import_editor_v1_adapters2.commandEndEvent)("document/elements/set-settings"),
|
|
91
|
+
() => getElementSetting(elementId, settingKey),
|
|
92
|
+
[elementId, settingKey]
|
|
93
|
+
);
|
|
128
94
|
};
|
|
129
95
|
|
|
130
96
|
// src/hooks/use-element-style-prop.ts
|
|
131
|
-
var
|
|
97
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
132
98
|
|
|
133
99
|
// src/sync/get-element-styles.ts
|
|
134
100
|
var getElementStyles = (elementID) => {
|
|
@@ -143,8 +109,8 @@ var useElementStyleProp = ({
|
|
|
143
109
|
meta,
|
|
144
110
|
propName
|
|
145
111
|
}) => {
|
|
146
|
-
return (0,
|
|
147
|
-
(0,
|
|
112
|
+
return (0, import_editor_v1_adapters3.__privateUseListenTo)(
|
|
113
|
+
(0, import_editor_v1_adapters3.commandEndEvent)("document/atomic-widgets/styles"),
|
|
148
114
|
() => {
|
|
149
115
|
if (!styleDefID) {
|
|
150
116
|
return null;
|
|
@@ -165,11 +131,101 @@ function getVariantByMeta(styleDef, meta) {
|
|
|
165
131
|
});
|
|
166
132
|
}
|
|
167
133
|
|
|
168
|
-
// src/
|
|
134
|
+
// src/hooks/use-element-styles.ts
|
|
135
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
136
|
+
function useElementStyles(elementId) {
|
|
137
|
+
return (0, import_editor_v1_adapters4.__privateUseListenTo)(
|
|
138
|
+
(0, import_editor_v1_adapters4.commandEndEvent)("document/atomic-widgets/styles"),
|
|
139
|
+
() => getElementStyles(elementId) ?? {},
|
|
140
|
+
[elementId]
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/hooks/use-element-type.ts
|
|
169
145
|
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
146
|
+
|
|
147
|
+
// src/sync/get-widgets-cache.ts
|
|
148
|
+
function getWidgetsCache() {
|
|
149
|
+
const extendedWindow = window;
|
|
150
|
+
return extendedWindow?.elementor?.widgetsCache || null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/hooks/use-element-type.ts
|
|
154
|
+
function useElementType(type) {
|
|
155
|
+
return (0, import_editor_v1_adapters5.__privateUseListenTo)(
|
|
156
|
+
(0, import_editor_v1_adapters5.commandEndEvent)("editor/documents/load"),
|
|
157
|
+
() => {
|
|
158
|
+
if (!type) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const widgetsCache = getWidgetsCache();
|
|
162
|
+
const elementType = widgetsCache?.[type];
|
|
163
|
+
if (!elementType?.atomic_controls) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (!elementType?.atomic_props_schema) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
key: type,
|
|
171
|
+
controls: elementType.atomic_controls,
|
|
172
|
+
propsSchema: elementType.atomic_props_schema,
|
|
173
|
+
title: elementType.title
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
[type]
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/hooks/use-selected-element.ts
|
|
181
|
+
var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
|
|
182
|
+
|
|
183
|
+
// src/sync/get-selected-elements.ts
|
|
184
|
+
function getSelectedElements() {
|
|
185
|
+
const extendedWindow = window;
|
|
186
|
+
const selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];
|
|
187
|
+
return selectedElements.reduce((acc, el) => {
|
|
188
|
+
const type = el.model.get("widgetType") || el.model.get("elType");
|
|
189
|
+
if (type) {
|
|
190
|
+
acc.push({
|
|
191
|
+
id: el.model.get("id"),
|
|
192
|
+
type
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return acc;
|
|
196
|
+
}, []);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/hooks/use-selected-element.ts
|
|
200
|
+
function useSelectedElement() {
|
|
201
|
+
const elements = (0, import_editor_v1_adapters6.__privateUseListenTo)(
|
|
202
|
+
[(0, import_editor_v1_adapters6.commandEndEvent)("document/elements/select"), (0, import_editor_v1_adapters6.commandEndEvent)("document/elements/deselect")],
|
|
203
|
+
getSelectedElements
|
|
204
|
+
);
|
|
205
|
+
const [element] = elements;
|
|
206
|
+
const elementType = useElementType(element?.type);
|
|
207
|
+
if (elements.length !== 1 || !elementType) {
|
|
208
|
+
return { element: null, elementType: null };
|
|
209
|
+
}
|
|
210
|
+
return { element, elementType };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/sync/is-element-in-container.ts
|
|
214
|
+
var isElementInContainer = (element, container) => {
|
|
215
|
+
if (container.model.get("id") === element.id && container.model.get("widgetType") === element.type) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
if (container.children && container.children.length > 0) {
|
|
219
|
+
return container.children.some((child) => isElementInContainer(element, child));
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/sync/update-settings.ts
|
|
225
|
+
var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
|
|
170
226
|
var updateSettings = ({ id, props }) => {
|
|
171
227
|
const container = getContainer(id);
|
|
172
|
-
(0,
|
|
228
|
+
(0, import_editor_v1_adapters7.__privateRunCommand)("document/elements/settings", {
|
|
173
229
|
container,
|
|
174
230
|
settings: {
|
|
175
231
|
...props
|
|
@@ -178,10 +234,10 @@ var updateSettings = ({ id, props }) => {
|
|
|
178
234
|
};
|
|
179
235
|
|
|
180
236
|
// src/sync/update-styles.ts
|
|
181
|
-
var
|
|
237
|
+
var import_editor_v1_adapters8 = require("@elementor/editor-v1-adapters");
|
|
182
238
|
var updateStyle = async ({ elementID, styleDefID, meta, props, bind }) => {
|
|
183
239
|
const container = getContainer(elementID);
|
|
184
|
-
await (0,
|
|
240
|
+
await (0, import_editor_v1_adapters8.__privateRunCommand)("document/atomic-widgets/styles", {
|
|
185
241
|
container,
|
|
186
242
|
styleDefID,
|
|
187
243
|
bind,
|
|
@@ -194,12 +250,16 @@ var updateStyle = async ({ elementID, styleDefID, meta, props, bind }) => {
|
|
|
194
250
|
getElementSetting,
|
|
195
251
|
getElementStyles,
|
|
196
252
|
getSelectedElements,
|
|
253
|
+
getVariantByMeta,
|
|
197
254
|
getWidgetsCache,
|
|
255
|
+
isElementInContainer,
|
|
198
256
|
updateSettings,
|
|
199
257
|
updateStyle,
|
|
200
258
|
useElementSetting,
|
|
201
259
|
useElementStyleProp,
|
|
260
|
+
useElementStyles,
|
|
202
261
|
useElementType,
|
|
262
|
+
useElementsDomRef,
|
|
203
263
|
useSelectedElement
|
|
204
264
|
});
|
|
205
265
|
//# 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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QAAQ,KAAK,eAAe,KAAK,cAAc,QAAQ,KAAK,UAAU,KAAK;AAAA,EACnF,CAAE;AACH;;;AE7CA,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;;;ACZA,IAAAC,6BAAkD;AAY3C,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":["import_editor_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/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 { 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 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;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,QA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EAAE,SAAS,MAAM,aAAa,KAAK;AAAA,EAC3C;AAEA,SAAO,EAAE,SAAS,YAAY;AAC/B;;;AEjBO,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
|
|
3
|
-
|
|
4
|
-
// src/sync/get-selected-elements.ts
|
|
5
|
-
function getSelectedElements() {
|
|
6
|
-
const extendedWindow = window;
|
|
7
|
-
const selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];
|
|
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
|
-
}, []);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// src/hooks/use-element-type.ts
|
|
21
|
-
import { __privateUseListenTo as useListenTo, commandEndEvent } from "@elementor/editor-v1-adapters";
|
|
1
|
+
// src/hooks/use-elements-dom-ref.ts
|
|
2
|
+
import { __privateUseListenTo as useListenTo, windowEvent } from "@elementor/editor-v1-adapters";
|
|
22
3
|
|
|
23
|
-
// src/sync/get-
|
|
24
|
-
function
|
|
4
|
+
// src/sync/get-current-document-container.ts
|
|
5
|
+
function getCurrentDocumentContainer() {
|
|
25
6
|
const extendedWindow = window;
|
|
26
|
-
return extendedWindow
|
|
7
|
+
return extendedWindow.elementor?.documents?.getCurrent?.()?.container ?? null;
|
|
27
8
|
}
|
|
28
9
|
|
|
29
|
-
// src/hooks/use-
|
|
30
|
-
|
|
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,96 @@ 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/is-element-in-container.ts
|
|
175
|
+
var isElementInContainer = (element, container) => {
|
|
176
|
+
if (container.model.get("id") === element.id && container.model.get("widgetType") === element.type) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
if (container.children && container.children.length > 0) {
|
|
180
|
+
return container.children.some((child) => isElementInContainer(element, child));
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
};
|
|
184
|
+
|
|
133
185
|
// src/sync/update-settings.ts
|
|
134
186
|
import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
|
|
135
187
|
var updateSettings = ({ id, props }) => {
|
|
@@ -158,12 +210,16 @@ export {
|
|
|
158
210
|
getElementSetting,
|
|
159
211
|
getElementStyles,
|
|
160
212
|
getSelectedElements,
|
|
213
|
+
getVariantByMeta,
|
|
161
214
|
getWidgetsCache,
|
|
215
|
+
isElementInContainer,
|
|
162
216
|
updateSettings,
|
|
163
217
|
updateStyle,
|
|
164
218
|
useElementSetting,
|
|
165
219
|
useElementStyleProp,
|
|
220
|
+
useElementStyles,
|
|
166
221
|
useElementType,
|
|
222
|
+
useElementsDomRef,
|
|
167
223
|
useSelectedElement
|
|
168
224
|
};
|
|
169
225
|
//# 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;AAAA,IACN,gBAAiB,uBAAwB;AAAA,IACzC,MAA0B;AACzB,UAAK,CAAE,MAAO;AACb,eAAO;AAAA,MACR;AAEA,YAAM,eAAe,gBAAgB;AACrC,YAAM,cAAc,eAAgB,IAAK;AAEzC,UAAK,CAAE,aAAa,iBAAkB;AACrC,eAAO;AAAA,MACR;AAEA,UAAK,CAAE,aAAa,qBAAsB;AACzC,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,QACN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;AAAA,IACNC,iBAAiB,gCAAiC;AAAA,IAClD,MAAM;AAEL,UAAK,CAAE,YAAa;AACnB,eAAO;AAAA,MACR;AAEA,YAAM,WAAW,iBAAkB,SAAU,IAAK,UAAW;AAE7D,UAAK,CAAE,UAAW;AACjB,eAAO;AAAA,MACR;AAEA,YAAM,UAAU,iBAAkB,UAAU,IAAK;AAEjD,aAAO,SAAS,MAAO,QAAS,KAAK;AAAA,IACtC;AAAA,IACA,CAAE,WAAW,YAAY,UAAU,IAAK;AAAA,EACzC;AACD;AAEA,SAAS,iBAAkB,UAA2B,MAA+B;AACpF,SAAO,SAAS,SAAS,KAAM,CAAE,YAAa;AAC7C,WAAO,QAAQ,KAAK,eAAe,KAAK,cAAc,QAAQ,KAAK,UAAU,KAAK;AAAA,EACnF,CAAE;AACH;;;AE7CA,SAAS,uBAAuB,kBAAkB;AAK3C,IAAM,iBAAiB,CAAE,EAAE,IAAI,MAAM,MAAwC;AACnF,QAAM,YAAY,aAAc,EAAG;AAEnC,aAAY,8BAA8B;AAAA,IACzC;AAAA,IACA,UAAU;AAAA,MACT,GAAG;AAAA,IACJ;AAAA,EACD,CAAE;AACH;;;ACZA,SAAS,uBAAuBC,mBAAkB;AAY3C,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","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/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 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,iBAAgC;AACxC,QAAM,OAAO,4BAA4B;AAEzC,MAAK,CAAE,MAAM,MAAO;AACnB,WAAO,CAAC;AAAA,EACT;AAEA,SAAO,CAAE,GAAG,KAAK,KAAK,GAAG,iBAAiC,IAAK,kBAAmB,GAAI,CAAE;AACzF;;;AE1BA,SAAS,wBAAwBA,cAAa,uBAAuB;;;ACEtD,SAAR,aAA+B,IAAa;AAClD,QAAM,iBAAiB;AACvB,QAAM,YAAY,eAAe,WAAW,eAAgB,EAAG;AAE/D,SAAO,aAAa;AACrB;;;ACJO,IAAM,oBAAoB,CAAY,WAAsB,eAAuC;AACzG,QAAM,YAAY,aAAc,SAAU;AAC1C,QAAM,QAAQ,WAAW,UAAU,IAAK,UAAW;AAEnD,SAAO,SAAS;AACjB;;;AFHO,IAAM,oBAAoB,CAAY,WAAsB,eAAwB;AAC1F,SAAOC;AAAA,IACN,gBAAiB,gCAAiC;AAAA,IAClD,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C1F,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,SAAS,uBAAuB,kBAAkB;AAK3C,IAAM,iBAAiB,CAAE,EAAE,IAAI,MAAM,MAAwC;AACnF,QAAM,YAAY,aAAc,EAAG;AAEnC,aAAY,8BAA8B;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.0",
|
|
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.2.
|
|
45
|
-
"@elementor/editor-v1-adapters": "^0.8.
|
|
43
|
+
"@elementor/editor-props": "^0.3.0",
|
|
44
|
+
"@elementor/editor-styles": "0.2.1",
|
|
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,20 @@
|
|
|
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';
|
|
13
16
|
export { getSelectedElements } from './sync/get-selected-elements';
|
|
14
17
|
export { getWidgetsCache } from './sync/get-widgets-cache';
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
18
|
+
export { isElementInContainer } from './sync/is-element-in-container';
|
|
19
|
+
export { updateSettings } from './sync/update-settings';
|
|
20
|
+
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 => {
|
|
@@ -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