@elementor/editor-elements 0.2.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/README.md +4 -0
- package/dist/index.d.mts +86 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +205 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +169 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
- package/src/hooks/use-element-setting.ts +10 -0
- package/src/hooks/use-element-style-prop.ts +46 -0
- package/src/hooks/use-element-type.ts +33 -0
- package/src/hooks/use-selected-element.ts +20 -0
- package/src/index.ts +16 -0
- package/src/sync/get-container.ts +8 -0
- package/src/sync/get-element-setting.ts +9 -0
- package/src/sync/get-element-styles.ts +9 -0
- package/src/sync/get-selected-elements.ts +21 -0
- package/src/sync/get-widgets-cache.ts +7 -0
- package/src/sync/types.ts +39 -0
- package/src/sync/update-settings.ts +15 -0
- package/src/sync/update-styles.ts +25 -0
- package/src/types.ts +39 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @elementor/editor-elements
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a46ac3a: Created the `editor-elements` packages.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [9abdfaf]
|
|
12
|
+
- Updated dependencies [2b28089]
|
|
13
|
+
- Updated dependencies [036b439]
|
|
14
|
+
- Updated dependencies [6cf7ba1]
|
|
15
|
+
- Updated dependencies [e69bdae]
|
|
16
|
+
- Updated dependencies [bf12c4d]
|
|
17
|
+
- @elementor/editor-v1-adapters@0.8.3
|
|
18
|
+
- @elementor/editor-styles@0.2.0
|
|
19
|
+
- @elementor/editor-props@0.2.0
|
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PropType, PropValue, PropKey, Props } from '@elementor/editor-props';
|
|
2
|
+
import { StyleDefinitionID, StyleVariant, StyleDefinition } from '@elementor/editor-styles';
|
|
3
|
+
|
|
4
|
+
type ElementID = string;
|
|
5
|
+
type Element = {
|
|
6
|
+
id: ElementID;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
type ElementType = {
|
|
10
|
+
key: string;
|
|
11
|
+
controls: ControlItem[];
|
|
12
|
+
propsSchema: PropsSchema;
|
|
13
|
+
title: string;
|
|
14
|
+
};
|
|
15
|
+
type ControlsSection = {
|
|
16
|
+
type: 'section';
|
|
17
|
+
value: {
|
|
18
|
+
description?: string;
|
|
19
|
+
label: string;
|
|
20
|
+
items: ControlItem[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type Control = {
|
|
24
|
+
type: 'control';
|
|
25
|
+
value: {
|
|
26
|
+
bind: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
type: string;
|
|
30
|
+
props: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type ControlItem = ControlsSection | Control;
|
|
34
|
+
type PropsSchema = Record<Control['value']['bind'], PropType>;
|
|
35
|
+
|
|
36
|
+
declare function useSelectedElement(): {
|
|
37
|
+
element: null;
|
|
38
|
+
elementType: null;
|
|
39
|
+
} | {
|
|
40
|
+
element: Element;
|
|
41
|
+
elementType: ElementType;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
declare function useElementType(type?: string): ElementType | null;
|
|
45
|
+
|
|
46
|
+
declare const useElementSetting: ({ id, bind }: {
|
|
47
|
+
id: string;
|
|
48
|
+
bind: string;
|
|
49
|
+
}) => PropValue;
|
|
50
|
+
|
|
51
|
+
type UseElementStylePropArgs = {
|
|
52
|
+
elementID: ElementID;
|
|
53
|
+
styleDefID?: StyleDefinitionID;
|
|
54
|
+
meta: StyleVariant['meta'];
|
|
55
|
+
propName: PropKey;
|
|
56
|
+
};
|
|
57
|
+
declare const useElementStyleProp: <T extends PropValue>({ elementID, styleDefID, meta, propName, }: UseElementStylePropArgs) => T | null;
|
|
58
|
+
|
|
59
|
+
declare const updateSettings: ({ id, props }: {
|
|
60
|
+
id: ElementID;
|
|
61
|
+
props: Props;
|
|
62
|
+
}) => void;
|
|
63
|
+
|
|
64
|
+
type UpdateStyleProps = {
|
|
65
|
+
elementID: ElementID;
|
|
66
|
+
styleDefID?: StyleDefinitionID;
|
|
67
|
+
meta: StyleVariant['meta'];
|
|
68
|
+
props: Props;
|
|
69
|
+
bind: PropKey;
|
|
70
|
+
};
|
|
71
|
+
declare const updateStyle: ({ elementID, styleDefID, meta, props, bind }: UpdateStyleProps) => Promise<void>;
|
|
72
|
+
|
|
73
|
+
declare function getSelectedElements(): Element[];
|
|
74
|
+
|
|
75
|
+
declare function getWidgetsCache(): Record<string, {
|
|
76
|
+
atomic_controls?: ControlItem[];
|
|
77
|
+
atomic_props_schema?: PropsSchema;
|
|
78
|
+
controls: object;
|
|
79
|
+
title: string;
|
|
80
|
+
}> | null;
|
|
81
|
+
|
|
82
|
+
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
83
|
+
|
|
84
|
+
declare const getElementSetting: <TValue>(elementID: ElementID, setting: string) => TValue | null;
|
|
85
|
+
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PropType, PropValue, PropKey, Props } from '@elementor/editor-props';
|
|
2
|
+
import { StyleDefinitionID, StyleVariant, StyleDefinition } from '@elementor/editor-styles';
|
|
3
|
+
|
|
4
|
+
type ElementID = string;
|
|
5
|
+
type Element = {
|
|
6
|
+
id: ElementID;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
type ElementType = {
|
|
10
|
+
key: string;
|
|
11
|
+
controls: ControlItem[];
|
|
12
|
+
propsSchema: PropsSchema;
|
|
13
|
+
title: string;
|
|
14
|
+
};
|
|
15
|
+
type ControlsSection = {
|
|
16
|
+
type: 'section';
|
|
17
|
+
value: {
|
|
18
|
+
description?: string;
|
|
19
|
+
label: string;
|
|
20
|
+
items: ControlItem[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type Control = {
|
|
24
|
+
type: 'control';
|
|
25
|
+
value: {
|
|
26
|
+
bind: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
type: string;
|
|
30
|
+
props: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type ControlItem = ControlsSection | Control;
|
|
34
|
+
type PropsSchema = Record<Control['value']['bind'], PropType>;
|
|
35
|
+
|
|
36
|
+
declare function useSelectedElement(): {
|
|
37
|
+
element: null;
|
|
38
|
+
elementType: null;
|
|
39
|
+
} | {
|
|
40
|
+
element: Element;
|
|
41
|
+
elementType: ElementType;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
declare function useElementType(type?: string): ElementType | null;
|
|
45
|
+
|
|
46
|
+
declare const useElementSetting: ({ id, bind }: {
|
|
47
|
+
id: string;
|
|
48
|
+
bind: string;
|
|
49
|
+
}) => PropValue;
|
|
50
|
+
|
|
51
|
+
type UseElementStylePropArgs = {
|
|
52
|
+
elementID: ElementID;
|
|
53
|
+
styleDefID?: StyleDefinitionID;
|
|
54
|
+
meta: StyleVariant['meta'];
|
|
55
|
+
propName: PropKey;
|
|
56
|
+
};
|
|
57
|
+
declare const useElementStyleProp: <T extends PropValue>({ elementID, styleDefID, meta, propName, }: UseElementStylePropArgs) => T | null;
|
|
58
|
+
|
|
59
|
+
declare const updateSettings: ({ id, props }: {
|
|
60
|
+
id: ElementID;
|
|
61
|
+
props: Props;
|
|
62
|
+
}) => void;
|
|
63
|
+
|
|
64
|
+
type UpdateStyleProps = {
|
|
65
|
+
elementID: ElementID;
|
|
66
|
+
styleDefID?: StyleDefinitionID;
|
|
67
|
+
meta: StyleVariant['meta'];
|
|
68
|
+
props: Props;
|
|
69
|
+
bind: PropKey;
|
|
70
|
+
};
|
|
71
|
+
declare const updateStyle: ({ elementID, styleDefID, meta, props, bind }: UpdateStyleProps) => Promise<void>;
|
|
72
|
+
|
|
73
|
+
declare function getSelectedElements(): Element[];
|
|
74
|
+
|
|
75
|
+
declare function getWidgetsCache(): Record<string, {
|
|
76
|
+
atomic_controls?: ControlItem[];
|
|
77
|
+
atomic_props_schema?: PropsSchema;
|
|
78
|
+
controls: object;
|
|
79
|
+
title: string;
|
|
80
|
+
}> | null;
|
|
81
|
+
|
|
82
|
+
declare const getElementStyles: (elementID: ElementID) => Record<string, StyleDefinition> | null;
|
|
83
|
+
|
|
84
|
+
declare const getElementSetting: <TValue>(elementID: ElementID, setting: string) => TValue | null;
|
|
85
|
+
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
getElementSetting: () => getElementSetting,
|
|
24
|
+
getElementStyles: () => getElementStyles,
|
|
25
|
+
getSelectedElements: () => getSelectedElements,
|
|
26
|
+
getWidgetsCache: () => getWidgetsCache,
|
|
27
|
+
updateSettings: () => updateSettings,
|
|
28
|
+
updateStyle: () => updateStyle,
|
|
29
|
+
useElementSetting: () => useElementSetting,
|
|
30
|
+
useElementStyleProp: () => useElementStyleProp,
|
|
31
|
+
useElementType: () => useElementType,
|
|
32
|
+
useSelectedElement: () => useSelectedElement
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
|
|
36
|
+
// src/hooks/use-selected-element.ts
|
|
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
|
|
56
|
+
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
57
|
+
|
|
58
|
+
// src/sync/get-widgets-cache.ts
|
|
59
|
+
function getWidgetsCache() {
|
|
60
|
+
const extendedWindow = window;
|
|
61
|
+
return extendedWindow?.elementor?.widgetsCache || null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/hooks/use-element-type.ts
|
|
65
|
+
function useElementType(type) {
|
|
66
|
+
return (0, import_editor_v1_adapters.__privateUseListenTo)(
|
|
67
|
+
(0, import_editor_v1_adapters.commandEndEvent)("editor/documents/load"),
|
|
68
|
+
() => {
|
|
69
|
+
if (!type) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const widgetsCache = getWidgetsCache();
|
|
73
|
+
const elementType = widgetsCache?.[type];
|
|
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]
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/hooks/use-selected-element.ts
|
|
92
|
+
function useSelectedElement() {
|
|
93
|
+
const elements = (0, import_editor_v1_adapters2.__privateUseListenTo)(
|
|
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 };
|
|
101
|
+
}
|
|
102
|
+
return { element, elementType };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/hooks/use-element-setting.ts
|
|
106
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
107
|
+
|
|
108
|
+
// src/sync/get-container.ts
|
|
109
|
+
function getContainer(id) {
|
|
110
|
+
const extendedWindow = window;
|
|
111
|
+
const container = extendedWindow.elementor?.getContainer?.(id);
|
|
112
|
+
return container ?? null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/sync/get-element-setting.ts
|
|
116
|
+
var getElementSetting = (elementID, setting) => {
|
|
117
|
+
const container = getContainer(elementID);
|
|
118
|
+
const value = container?.settings?.get(setting);
|
|
119
|
+
return value ?? null;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/hooks/use-element-setting.ts
|
|
123
|
+
var useElementSetting = ({ id, bind }) => {
|
|
124
|
+
return (0, import_editor_v1_adapters3.__privateUseListenTo)((0, import_editor_v1_adapters3.commandEndEvent)("document/elements/settings"), () => getElementSetting(id, bind), [
|
|
125
|
+
id,
|
|
126
|
+
bind
|
|
127
|
+
]);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/hooks/use-element-style-prop.ts
|
|
131
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
132
|
+
|
|
133
|
+
// src/sync/get-element-styles.ts
|
|
134
|
+
var getElementStyles = (elementID) => {
|
|
135
|
+
const container = getContainer(elementID);
|
|
136
|
+
return container?.model.get("styles") || null;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// src/hooks/use-element-style-prop.ts
|
|
140
|
+
var useElementStyleProp = ({
|
|
141
|
+
elementID,
|
|
142
|
+
styleDefID,
|
|
143
|
+
meta,
|
|
144
|
+
propName
|
|
145
|
+
}) => {
|
|
146
|
+
return (0, import_editor_v1_adapters4.__privateUseListenTo)(
|
|
147
|
+
(0, import_editor_v1_adapters4.commandEndEvent)("document/atomic-widgets/styles"),
|
|
148
|
+
() => {
|
|
149
|
+
if (!styleDefID) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
const styleDef = getElementStyles(elementID)?.[styleDefID];
|
|
153
|
+
if (!styleDef) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const variant = getVariantByMeta(styleDef, meta);
|
|
157
|
+
return variant?.props[propName] ?? null;
|
|
158
|
+
},
|
|
159
|
+
[elementID, styleDefID, propName, meta]
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
function getVariantByMeta(styleDef, meta) {
|
|
163
|
+
return styleDef.variants.find((variant) => {
|
|
164
|
+
return variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/sync/update-settings.ts
|
|
169
|
+
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
170
|
+
var updateSettings = ({ id, props }) => {
|
|
171
|
+
const container = getContainer(id);
|
|
172
|
+
(0, import_editor_v1_adapters5.__privateRunCommand)("document/elements/settings", {
|
|
173
|
+
container,
|
|
174
|
+
settings: {
|
|
175
|
+
...props
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/sync/update-styles.ts
|
|
181
|
+
var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
|
|
182
|
+
var updateStyle = async ({ elementID, styleDefID, meta, props, bind }) => {
|
|
183
|
+
const container = getContainer(elementID);
|
|
184
|
+
await (0, import_editor_v1_adapters6.__privateRunCommand)("document/atomic-widgets/styles", {
|
|
185
|
+
container,
|
|
186
|
+
styleDefID,
|
|
187
|
+
bind,
|
|
188
|
+
meta,
|
|
189
|
+
props
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
193
|
+
0 && (module.exports = {
|
|
194
|
+
getElementSetting,
|
|
195
|
+
getElementStyles,
|
|
196
|
+
getSelectedElements,
|
|
197
|
+
getWidgetsCache,
|
|
198
|
+
updateSettings,
|
|
199
|
+
updateStyle,
|
|
200
|
+
useElementSetting,
|
|
201
|
+
useElementStyleProp,
|
|
202
|
+
useElementType,
|
|
203
|
+
useSelectedElement
|
|
204
|
+
});
|
|
205
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AAE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AAU;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"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/hooks/use-selected-element.ts
|
|
2
|
+
import { __privateUseListenTo as useListenTo2, commandEndEvent as commandEndEvent2 } from "@elementor/editor-v1-adapters";
|
|
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";
|
|
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) {
|
|
31
|
+
return useListenTo(
|
|
32
|
+
commandEndEvent("editor/documents/load"),
|
|
33
|
+
() => {
|
|
34
|
+
if (!type) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const widgetsCache = getWidgetsCache();
|
|
38
|
+
const elementType = widgetsCache?.[type];
|
|
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]
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/hooks/use-selected-element.ts
|
|
57
|
+
function useSelectedElement() {
|
|
58
|
+
const elements = useListenTo2(
|
|
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 };
|
|
66
|
+
}
|
|
67
|
+
return { element, elementType };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/hooks/use-element-setting.ts
|
|
71
|
+
import { commandEndEvent as commandEndEvent3, __privateUseListenTo as useListenTo3 } from "@elementor/editor-v1-adapters";
|
|
72
|
+
|
|
73
|
+
// src/sync/get-container.ts
|
|
74
|
+
function getContainer(id) {
|
|
75
|
+
const extendedWindow = window;
|
|
76
|
+
const container = extendedWindow.elementor?.getContainer?.(id);
|
|
77
|
+
return container ?? null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/sync/get-element-setting.ts
|
|
81
|
+
var getElementSetting = (elementID, setting) => {
|
|
82
|
+
const container = getContainer(elementID);
|
|
83
|
+
const value = container?.settings?.get(setting);
|
|
84
|
+
return value ?? null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/hooks/use-element-setting.ts
|
|
88
|
+
var useElementSetting = ({ id, bind }) => {
|
|
89
|
+
return useListenTo3(commandEndEvent3("document/elements/settings"), () => getElementSetting(id, bind), [
|
|
90
|
+
id,
|
|
91
|
+
bind
|
|
92
|
+
]);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/hooks/use-element-style-prop.ts
|
|
96
|
+
import { commandEndEvent as commandEndEvent4, __privateUseListenTo as useListenTo4 } from "@elementor/editor-v1-adapters";
|
|
97
|
+
|
|
98
|
+
// src/sync/get-element-styles.ts
|
|
99
|
+
var getElementStyles = (elementID) => {
|
|
100
|
+
const container = getContainer(elementID);
|
|
101
|
+
return container?.model.get("styles") || null;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/hooks/use-element-style-prop.ts
|
|
105
|
+
var useElementStyleProp = ({
|
|
106
|
+
elementID,
|
|
107
|
+
styleDefID,
|
|
108
|
+
meta,
|
|
109
|
+
propName
|
|
110
|
+
}) => {
|
|
111
|
+
return useListenTo4(
|
|
112
|
+
commandEndEvent4("document/atomic-widgets/styles"),
|
|
113
|
+
() => {
|
|
114
|
+
if (!styleDefID) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const styleDef = getElementStyles(elementID)?.[styleDefID];
|
|
118
|
+
if (!styleDef) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const variant = getVariantByMeta(styleDef, meta);
|
|
122
|
+
return variant?.props[propName] ?? null;
|
|
123
|
+
},
|
|
124
|
+
[elementID, styleDefID, propName, meta]
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
function getVariantByMeta(styleDef, meta) {
|
|
128
|
+
return styleDef.variants.find((variant) => {
|
|
129
|
+
return variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/sync/update-settings.ts
|
|
134
|
+
import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
|
|
135
|
+
var updateSettings = ({ id, props }) => {
|
|
136
|
+
const container = getContainer(id);
|
|
137
|
+
runCommand("document/elements/settings", {
|
|
138
|
+
container,
|
|
139
|
+
settings: {
|
|
140
|
+
...props
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/sync/update-styles.ts
|
|
146
|
+
import { __privateRunCommand as runCommand2 } from "@elementor/editor-v1-adapters";
|
|
147
|
+
var updateStyle = async ({ elementID, styleDefID, meta, props, bind }) => {
|
|
148
|
+
const container = getContainer(elementID);
|
|
149
|
+
await runCommand2("document/atomic-widgets/styles", {
|
|
150
|
+
container,
|
|
151
|
+
styleDefID,
|
|
152
|
+
bind,
|
|
153
|
+
meta,
|
|
154
|
+
props
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
export {
|
|
158
|
+
getElementSetting,
|
|
159
|
+
getElementStyles,
|
|
160
|
+
getSelectedElements,
|
|
161
|
+
getWidgetsCache,
|
|
162
|
+
updateSettings,
|
|
163
|
+
updateStyle,
|
|
164
|
+
useElementSetting,
|
|
165
|
+
useElementStyleProp,
|
|
166
|
+
useElementType,
|
|
167
|
+
useSelectedElement
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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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;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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elementor/editor-elements",
|
|
3
|
+
"description": "This package contains the elements model for the Elementor editor",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"private": false,
|
|
6
|
+
"author": "Elementor Team",
|
|
7
|
+
"homepage": "https://elementor.com/",
|
|
8
|
+
"license": "GPL-3.0-or-later",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"module": "dist/index.mjs",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/elementor/elementor-packages.git",
|
|
23
|
+
"directory": "packages/libs/editor-elements"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/elementor/elementor-packages/issues"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"README.md",
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"/dist",
|
|
35
|
+
"/src",
|
|
36
|
+
"!**/__tests__"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup --config=../../tsup.build.ts",
|
|
40
|
+
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@elementor/editor-props": "^0.2.0",
|
|
44
|
+
"@elementor/editor-styles": "0.2.0",
|
|
45
|
+
"@elementor/editor-v1-adapters": "^0.8.3"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"react": "^18.3.1"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';
|
|
2
|
+
import { PropValue } from '@elementor/editor-props';
|
|
3
|
+
import { getElementSetting } from '../sync/get-element-setting';
|
|
4
|
+
|
|
5
|
+
export const useElementSetting = ( { id, bind }: { id: string; bind: string } ): PropValue => {
|
|
6
|
+
return useListenTo( commandEndEvent( 'document/elements/settings' ), () => getElementSetting( id, bind ), [
|
|
7
|
+
id,
|
|
8
|
+
bind,
|
|
9
|
+
] );
|
|
10
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { PropKey, PropValue } from '@elementor/editor-props';
|
|
2
|
+
import { StyleDefinition, StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';
|
|
3
|
+
import { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';
|
|
4
|
+
import { getElementStyles } from '../sync/get-element-styles';
|
|
5
|
+
import { ElementID } from '../types';
|
|
6
|
+
|
|
7
|
+
export type UseElementStylePropArgs = {
|
|
8
|
+
elementID: ElementID;
|
|
9
|
+
styleDefID?: StyleDefinitionID;
|
|
10
|
+
meta: StyleVariant[ 'meta' ];
|
|
11
|
+
propName: PropKey;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const useElementStyleProp = < T extends PropValue >( {
|
|
15
|
+
elementID,
|
|
16
|
+
styleDefID,
|
|
17
|
+
meta,
|
|
18
|
+
propName,
|
|
19
|
+
}: UseElementStylePropArgs ): T | null => {
|
|
20
|
+
return useListenTo(
|
|
21
|
+
commandEndEvent( 'document/atomic-widgets/styles' ),
|
|
22
|
+
() => {
|
|
23
|
+
// TODO: return default value for style prop
|
|
24
|
+
if ( ! styleDefID ) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const styleDef = getElementStyles( elementID )?.[ styleDefID ];
|
|
29
|
+
|
|
30
|
+
if ( ! styleDef ) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const variant = getVariantByMeta( styleDef, meta );
|
|
35
|
+
|
|
36
|
+
return variant?.props[ propName ] ?? null;
|
|
37
|
+
},
|
|
38
|
+
[ elementID, styleDefID, propName, meta ]
|
|
39
|
+
) as T;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function getVariantByMeta( styleDef: StyleDefinition, meta: StyleVariant[ 'meta' ] ) {
|
|
43
|
+
return styleDef.variants.find( ( variant ) => {
|
|
44
|
+
return variant.meta.breakpoint === meta.breakpoint && variant.meta.state === meta.state;
|
|
45
|
+
} );
|
|
46
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
import { getWidgetsCache } from '../sync/get-widgets-cache';
|
|
3
|
+
import { ElementType } from '../types';
|
|
4
|
+
|
|
5
|
+
export function useElementType( type?: string ) {
|
|
6
|
+
return useListenTo(
|
|
7
|
+
commandEndEvent( 'editor/documents/load' ),
|
|
8
|
+
(): ElementType | null => {
|
|
9
|
+
if ( ! type ) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const widgetsCache = getWidgetsCache();
|
|
14
|
+
const elementType = widgetsCache?.[ type ];
|
|
15
|
+
|
|
16
|
+
if ( ! elementType?.atomic_controls ) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if ( ! elementType?.atomic_props_schema ) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
key: type,
|
|
26
|
+
controls: elementType.atomic_controls,
|
|
27
|
+
propsSchema: elementType.atomic_props_schema,
|
|
28
|
+
title: elementType.title,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
[ type ]
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
import { getSelectedElements } from '../sync/get-selected-elements';
|
|
3
|
+
import { useElementType } from './use-element-type';
|
|
4
|
+
|
|
5
|
+
export function useSelectedElement() {
|
|
6
|
+
const elements = useListenTo(
|
|
7
|
+
[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],
|
|
8
|
+
getSelectedElements
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const [ element ] = elements;
|
|
12
|
+
|
|
13
|
+
const elementType = useElementType( element?.type );
|
|
14
|
+
|
|
15
|
+
if ( elements.length !== 1 || ! elementType ) {
|
|
16
|
+
return { element: null, elementType: null };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return { element, elementType };
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// types
|
|
2
|
+
export * from './types';
|
|
3
|
+
|
|
4
|
+
// hooks
|
|
5
|
+
export { useSelectedElement } from './hooks/use-selected-element';
|
|
6
|
+
export { useElementType } from './hooks/use-element-type';
|
|
7
|
+
export { useElementSetting } from './hooks/use-element-setting';
|
|
8
|
+
export { useElementStyleProp } from './hooks/use-element-style-prop';
|
|
9
|
+
|
|
10
|
+
// utils
|
|
11
|
+
export { updateSettings } from './sync/update-settings';
|
|
12
|
+
export { updateStyle } from './sync/update-styles';
|
|
13
|
+
export { getSelectedElements } from './sync/get-selected-elements';
|
|
14
|
+
export { getWidgetsCache } from './sync/get-widgets-cache';
|
|
15
|
+
export { getElementStyles } from './sync/get-element-styles';
|
|
16
|
+
export { getElementSetting } from './sync/get-element-setting';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ElementID } from '../types';
|
|
2
|
+
import getContainer from './get-container';
|
|
3
|
+
|
|
4
|
+
export const getElementSetting = < TValue >( elementID: ElementID, setting: string ): TValue | null => {
|
|
5
|
+
const container = getContainer( elementID );
|
|
6
|
+
const value = container?.settings?.get( setting ) as TValue;
|
|
7
|
+
|
|
8
|
+
return value ?? null;
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StyleDefinition } from '@elementor/editor-styles';
|
|
2
|
+
import { ElementID } from '../types';
|
|
3
|
+
import getContainer from './get-container';
|
|
4
|
+
|
|
5
|
+
export const getElementStyles = ( elementID: ElementID ): Record< string, StyleDefinition > | null => {
|
|
6
|
+
const container = getContainer( elementID );
|
|
7
|
+
|
|
8
|
+
return container?.model.get( 'styles' ) || null;
|
|
9
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ExtendedWindow } from './types';
|
|
2
|
+
import { Element } from '../types';
|
|
3
|
+
|
|
4
|
+
export function getSelectedElements(): Element[] {
|
|
5
|
+
const extendedWindow = window as unknown as ExtendedWindow;
|
|
6
|
+
|
|
7
|
+
const selectedElements = extendedWindow.elementor?.selection?.getElements?.() ?? [];
|
|
8
|
+
|
|
9
|
+
return selectedElements.reduce< Element[] >( ( acc, el ) => {
|
|
10
|
+
const type = el.model.get( 'widgetType' ) || el.model.get( 'elType' );
|
|
11
|
+
|
|
12
|
+
if ( type ) {
|
|
13
|
+
acc.push( {
|
|
14
|
+
id: el.model.get( 'id' ),
|
|
15
|
+
type,
|
|
16
|
+
} );
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return acc;
|
|
20
|
+
}, [] );
|
|
21
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PropValue } from '@elementor/editor-props';
|
|
2
|
+
import { StyleDefinition, StyleDefinitionID } from '@elementor/editor-styles';
|
|
3
|
+
import { ControlItem, PropsSchema } from '../types';
|
|
4
|
+
|
|
5
|
+
export type ExtendedWindow = Window & {
|
|
6
|
+
elementor?: {
|
|
7
|
+
selection?: {
|
|
8
|
+
getElements: () => V1Element[];
|
|
9
|
+
};
|
|
10
|
+
widgetsCache?: Record<
|
|
11
|
+
string,
|
|
12
|
+
{
|
|
13
|
+
atomic_controls?: ControlItem[];
|
|
14
|
+
atomic_props_schema?: PropsSchema;
|
|
15
|
+
controls: object;
|
|
16
|
+
title: string;
|
|
17
|
+
}
|
|
18
|
+
>;
|
|
19
|
+
getContainer?: ( id: string ) => V1Element;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type V1Element = {
|
|
24
|
+
model: V1Model< V1ElementModelProps >;
|
|
25
|
+
settings?: V1Model< V1ElementSettingsProps >;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type V1ElementModelProps = {
|
|
29
|
+
widgetType?: string;
|
|
30
|
+
elType: string;
|
|
31
|
+
id: string;
|
|
32
|
+
styles?: Record< StyleDefinitionID, StyleDefinition >;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type V1ElementSettingsProps = Record< string, PropValue >;
|
|
36
|
+
|
|
37
|
+
type V1Model< T > = {
|
|
38
|
+
get: < K extends keyof T >( key: K ) => T[ K ];
|
|
39
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
2
|
+
import { Props } from '@elementor/editor-props';
|
|
3
|
+
import getContainer from './get-container';
|
|
4
|
+
import { ElementID } from '../types';
|
|
5
|
+
|
|
6
|
+
export const updateSettings = ( { id, props }: { id: ElementID; props: Props } ) => {
|
|
7
|
+
const container = getContainer( id );
|
|
8
|
+
|
|
9
|
+
runCommand( 'document/elements/settings', {
|
|
10
|
+
container,
|
|
11
|
+
settings: {
|
|
12
|
+
...props,
|
|
13
|
+
},
|
|
14
|
+
} );
|
|
15
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PropKey, Props } from '@elementor/editor-props';
|
|
2
|
+
import { StyleDefinitionID, StyleVariant } from '@elementor/editor-styles';
|
|
3
|
+
import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
|
|
4
|
+
import getContainer from './get-container';
|
|
5
|
+
import { ElementID } from '../types';
|
|
6
|
+
|
|
7
|
+
export type UpdateStyleProps = {
|
|
8
|
+
elementID: ElementID;
|
|
9
|
+
styleDefID?: StyleDefinitionID;
|
|
10
|
+
meta: StyleVariant[ 'meta' ];
|
|
11
|
+
props: Props;
|
|
12
|
+
bind: PropKey;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const updateStyle = async ( { elementID, styleDefID, meta, props, bind }: UpdateStyleProps ) => {
|
|
16
|
+
const container = getContainer( elementID );
|
|
17
|
+
|
|
18
|
+
await runCommand( 'document/atomic-widgets/styles', {
|
|
19
|
+
container,
|
|
20
|
+
styleDefID,
|
|
21
|
+
bind,
|
|
22
|
+
meta,
|
|
23
|
+
props,
|
|
24
|
+
} );
|
|
25
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { PropType } from '@elementor/editor-props';
|
|
2
|
+
|
|
3
|
+
export type ElementID = string;
|
|
4
|
+
|
|
5
|
+
export type Element = {
|
|
6
|
+
id: ElementID;
|
|
7
|
+
type: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ElementType = {
|
|
11
|
+
key: string;
|
|
12
|
+
controls: ControlItem[];
|
|
13
|
+
propsSchema: PropsSchema;
|
|
14
|
+
title: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ControlsSection = {
|
|
18
|
+
type: 'section';
|
|
19
|
+
value: {
|
|
20
|
+
description?: string;
|
|
21
|
+
label: string;
|
|
22
|
+
items: ControlItem[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type Control = {
|
|
27
|
+
type: 'control';
|
|
28
|
+
value: {
|
|
29
|
+
bind: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
type: string;
|
|
33
|
+
props: Record< string, unknown >;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ControlItem = ControlsSection | Control;
|
|
38
|
+
|
|
39
|
+
export type PropsSchema = Record< Control[ 'value' ][ 'bind' ], PropType >;
|