@elementor/editor-editing-panel 0.4.2 → 0.5.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 +6 -0
- package/dist/index.js +90 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/controls/__tests__/settings-control.test.tsx +16 -10
- package/src/components/controls/control-types/__tests__/select-control.test.tsx +1 -1
- package/src/components/controls/control-types/__tests__/{text-control.test.tsx → text-area-control.test.tsx} +4 -4
- package/src/components/controls/control-types/select-control.tsx +6 -6
- package/src/components/controls/control-types/{text-control.tsx → text-area-control.tsx} +3 -3
- package/src/components/controls/settings-control.tsx +12 -32
- package/src/components/editing-panel.tsx +10 -14
- package/src/contexts/control-context.tsx +45 -0
- package/src/components/controls/control-context.ts +0 -20
- /package/src/{components/controls → contexts}/__tests__/control-context.test.tsx +0 -0
- /package/src/contexts/{settings-controls.tsx → element-context.tsx} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.5.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-editing-panel@0.4.2...@elementor/editor-editing-panel@0.5.0) (2024-07-17)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **editor-editing-panel:** connect controls to element context [EDS-253] ([#203](https://github.com/elementor/elementor-packages/issues/203)) ([12bd853](https://github.com/elementor/elementor-packages/commit/12bd8530713b92aa56716ad3b496f326d7e1b2b9))
|
|
11
|
+
|
|
6
12
|
## [0.4.2](https://github.com/elementor/elementor-packages/compare/@elementor/editor-editing-panel@0.4.1...@elementor/editor-editing-panel@0.4.2) (2024-07-16)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @elementor/editor-editing-panel
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
var import_editor_panels2 = require("@elementor/editor-panels");
|
|
27
27
|
|
|
28
28
|
// src/components/editing-panel.tsx
|
|
29
|
-
var
|
|
29
|
+
var React6 = __toESM(require("react"));
|
|
30
30
|
var import_i18n = require("@wordpress/i18n");
|
|
31
31
|
|
|
32
32
|
// src/hooks/use-selected-elements.ts
|
|
@@ -92,19 +92,85 @@ function useElementType(type) {
|
|
|
92
92
|
var import_editor_panels = require("@elementor/editor-panels");
|
|
93
93
|
|
|
94
94
|
// src/components/controls/control-types/select-control.tsx
|
|
95
|
-
var
|
|
95
|
+
var React3 = __toESM(require("react"));
|
|
96
96
|
var import_ui = require("@elementor/ui");
|
|
97
97
|
|
|
98
|
-
// src/
|
|
98
|
+
// src/contexts/control-context.tsx
|
|
99
|
+
var React2 = __toESM(require("react"));
|
|
100
|
+
var import_react2 = require("react");
|
|
101
|
+
|
|
102
|
+
// src/contexts/element-context.tsx
|
|
103
|
+
var React = __toESM(require("react"));
|
|
99
104
|
var import_react = require("react");
|
|
100
|
-
var
|
|
105
|
+
var Context = (0, import_react.createContext)(null);
|
|
106
|
+
function ElementContext({ children, element }) {
|
|
107
|
+
return /* @__PURE__ */ React.createElement(Context.Provider, { value: { element } }, children);
|
|
108
|
+
}
|
|
109
|
+
function useElementContext() {
|
|
110
|
+
const context = (0, import_react.useContext)(Context);
|
|
111
|
+
if (!context) {
|
|
112
|
+
throw new Error("useElementContext must be used within a ElementContextProvider");
|
|
113
|
+
}
|
|
114
|
+
return context;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/hooks/use-widget-settings.ts
|
|
118
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
119
|
+
|
|
120
|
+
// src/sync/get-container.ts
|
|
121
|
+
function getContainer(id) {
|
|
122
|
+
const extendedWindow = window;
|
|
123
|
+
const container = extendedWindow.elementor?.getContainer?.(id);
|
|
124
|
+
return container ?? null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/hooks/use-widget-settings.ts
|
|
128
|
+
var useWidgetSettings = ({ id, bind }) => {
|
|
129
|
+
return (0, import_editor_v1_adapters3.__privateUseListenTo)(
|
|
130
|
+
(0, import_editor_v1_adapters3.commandEndEvent)("document/elements/settings"),
|
|
131
|
+
() => {
|
|
132
|
+
const container = getContainer(id);
|
|
133
|
+
const value = container?.settings?.get(bind) ?? null;
|
|
134
|
+
return value;
|
|
135
|
+
},
|
|
136
|
+
[]
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/sync/update-settings.ts
|
|
141
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
142
|
+
var updateSettings = ({ id, props }) => {
|
|
143
|
+
const container = getContainer(id);
|
|
144
|
+
(0, import_editor_v1_adapters4.__privateRunCommand)("document/elements/settings", {
|
|
145
|
+
container,
|
|
146
|
+
settings: {
|
|
147
|
+
...props
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/contexts/control-context.tsx
|
|
153
|
+
var ControlContext = (0, import_react2.createContext)(null);
|
|
101
154
|
function useControl(defaultValue) {
|
|
102
|
-
const controlContext = (0,
|
|
155
|
+
const controlContext = (0, import_react2.useContext)(ControlContext);
|
|
103
156
|
if (!controlContext) {
|
|
104
157
|
throw new Error("useControl must be used within a ControlContext");
|
|
105
158
|
}
|
|
106
159
|
return { ...controlContext, value: controlContext.value ?? defaultValue };
|
|
107
160
|
}
|
|
161
|
+
var ControlContextProvider = ({ bind, children }) => {
|
|
162
|
+
const { element } = useElementContext();
|
|
163
|
+
const value = useWidgetSettings({ id: element.id, bind });
|
|
164
|
+
const setValue = (newValue) => {
|
|
165
|
+
updateSettings({
|
|
166
|
+
id: element.id,
|
|
167
|
+
props: {
|
|
168
|
+
[bind]: newValue
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
return /* @__PURE__ */ React2.createElement(ControlContext.Provider, { value: { setValue, value, bind } }, children);
|
|
173
|
+
};
|
|
108
174
|
|
|
109
175
|
// src/components/controls/control-types/select-control.tsx
|
|
110
176
|
var SelectControl = ({ options }) => {
|
|
@@ -112,18 +178,18 @@ var SelectControl = ({ options }) => {
|
|
|
112
178
|
const handleChange = (event) => {
|
|
113
179
|
setValue(event.target.value);
|
|
114
180
|
};
|
|
115
|
-
return /* @__PURE__ */
|
|
181
|
+
return /* @__PURE__ */ React3.createElement(import_ui.Select, { size: "tiny", value: value ?? "", onChange: handleChange }, options.map(({ label, ...props }) => /* @__PURE__ */ React3.createElement(import_ui.MenuItem, { key: props.value, ...props }, label)));
|
|
116
182
|
};
|
|
117
183
|
|
|
118
|
-
// src/components/controls/control-types/text-control.tsx
|
|
119
|
-
var
|
|
184
|
+
// src/components/controls/control-types/text-area-control.tsx
|
|
185
|
+
var React4 = __toESM(require("react"));
|
|
120
186
|
var import_ui2 = require("@elementor/ui");
|
|
121
|
-
var
|
|
187
|
+
var TextAreaControl = ({ placeholder }) => {
|
|
122
188
|
const { value, setValue } = useControl("");
|
|
123
189
|
const handleChange = (event) => {
|
|
124
190
|
setValue(event.target.value);
|
|
125
191
|
};
|
|
126
|
-
return /* @__PURE__ */
|
|
192
|
+
return /* @__PURE__ */ React4.createElement(
|
|
127
193
|
import_ui2.TextareaAutosize,
|
|
128
194
|
{
|
|
129
195
|
size: "tiny",
|
|
@@ -136,61 +202,9 @@ var TextControl = ({ placeholder }) => {
|
|
|
136
202
|
};
|
|
137
203
|
|
|
138
204
|
// src/components/controls/settings-control.tsx
|
|
139
|
-
var
|
|
205
|
+
var React5 = __toESM(require("react"));
|
|
140
206
|
var import_ui3 = require("@elementor/ui");
|
|
141
|
-
|
|
142
|
-
// src/sync/update-settings.ts
|
|
143
|
-
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
144
|
-
|
|
145
|
-
// src/sync/get-container.ts
|
|
146
|
-
function getContainer(id) {
|
|
147
|
-
const extendedWindow = window;
|
|
148
|
-
const container = extendedWindow.elementor?.getContainer?.(id);
|
|
149
|
-
return container ?? null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// src/sync/update-settings.ts
|
|
153
|
-
var updateSettings = ({ id, props }) => {
|
|
154
|
-
const container = getContainer(id);
|
|
155
|
-
(0, import_editor_v1_adapters3.__privateRunCommand)("document/elements/settings", {
|
|
156
|
-
container,
|
|
157
|
-
settings: {
|
|
158
|
-
...props
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
// src/hooks/use-widget-settings.ts
|
|
164
|
-
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
165
|
-
var useWidgetSettings = ({ id, bind }) => {
|
|
166
|
-
return (0, import_editor_v1_adapters4.__privateUseListenTo)(
|
|
167
|
-
(0, import_editor_v1_adapters4.commandEndEvent)("document/elements/settings"),
|
|
168
|
-
() => {
|
|
169
|
-
const container = getContainer(id);
|
|
170
|
-
const value = container?.settings?.get(bind) ?? null;
|
|
171
|
-
return value;
|
|
172
|
-
},
|
|
173
|
-
[]
|
|
174
|
-
);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// src/components/controls/settings-control.tsx
|
|
178
|
-
var SettingsControl = ({ bind, children, elementID }) => {
|
|
179
|
-
const value = useWidgetSettings({ id: elementID, bind });
|
|
180
|
-
const setValue = (newValue) => {
|
|
181
|
-
updateSettings({
|
|
182
|
-
id: elementID,
|
|
183
|
-
props: {
|
|
184
|
-
[bind]: newValue
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
return /* @__PURE__ */ React3.createElement(ControlContext.Provider, { value: { setValue, value, bind } }, children);
|
|
189
|
-
};
|
|
190
|
-
var Label = ({ children }) => {
|
|
191
|
-
return /* @__PURE__ */ React3.createElement(import_ui3.Typography, { component: "label", variant: "caption" }, children);
|
|
192
|
-
};
|
|
193
|
-
var Container = ({ children }) => /* @__PURE__ */ React3.createElement(
|
|
207
|
+
var SettingsControl = ({ children, bind }) => /* @__PURE__ */ React5.createElement(
|
|
194
208
|
import_ui3.Stack,
|
|
195
209
|
{
|
|
196
210
|
spacing: 1,
|
|
@@ -200,50 +214,39 @@ var Container = ({ children }) => /* @__PURE__ */ React3.createElement(
|
|
|
200
214
|
flexWrap: "wrap",
|
|
201
215
|
sx: { px: 2 }
|
|
202
216
|
},
|
|
203
|
-
children
|
|
217
|
+
/* @__PURE__ */ React5.createElement(ControlContextProvider, { bind }, children)
|
|
204
218
|
);
|
|
219
|
+
var Label = ({ children }) => {
|
|
220
|
+
return /* @__PURE__ */ React5.createElement(import_ui3.Typography, { component: "label", variant: "caption" }, children);
|
|
221
|
+
};
|
|
205
222
|
SettingsControl.Label = Label;
|
|
206
|
-
SettingsControl.Container = Container;
|
|
207
223
|
|
|
208
224
|
// src/components/editing-panel.tsx
|
|
209
225
|
var import_ui4 = require("@elementor/ui");
|
|
210
|
-
|
|
211
|
-
// src/contexts/settings-controls.tsx
|
|
212
|
-
var React4 = __toESM(require("react"));
|
|
213
|
-
var import_react2 = require("react");
|
|
214
|
-
var Context = (0, import_react2.createContext)(null);
|
|
215
|
-
function ElementContext({ children, element }) {
|
|
216
|
-
return /* @__PURE__ */ React4.createElement(Context.Provider, { value: { element } }, children);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/components/editing-panel.tsx
|
|
220
226
|
var controlTypes = {
|
|
221
227
|
select: SelectControl,
|
|
222
|
-
|
|
228
|
+
textarea: TextAreaControl
|
|
223
229
|
};
|
|
224
230
|
var EditingPanel = () => {
|
|
225
231
|
const elements = useSelectedElements();
|
|
226
|
-
const selectedElement = elements
|
|
232
|
+
const [selectedElement] = elements;
|
|
227
233
|
const elementType = useElementType(selectedElement?.type);
|
|
228
234
|
if (elements.length !== 1 || !elementType) {
|
|
229
235
|
return null;
|
|
230
236
|
}
|
|
231
237
|
const panelTitle = (0, import_i18n.__)("Edit %s", "elementor").replace("%s", elementType.title);
|
|
232
|
-
return /* @__PURE__ */
|
|
238
|
+
return /* @__PURE__ */ React6.createElement(import_editor_panels.Panel, null, /* @__PURE__ */ React6.createElement(import_editor_panels.PanelHeader, null, /* @__PURE__ */ React6.createElement(import_editor_panels.PanelHeaderTitle, null, panelTitle)), /* @__PURE__ */ React6.createElement(import_editor_panels.PanelBody, null, /* @__PURE__ */ React6.createElement(ElementContext, { element: selectedElement }, /* @__PURE__ */ React6.createElement(import_ui4.Stack, { spacing: 2 }, elementType.controls.map((control) => {
|
|
233
239
|
if (control.type === "control") {
|
|
234
240
|
const ControlComponent = controlTypes[control.value.type];
|
|
235
241
|
if (!ControlComponent) {
|
|
236
242
|
return null;
|
|
237
243
|
}
|
|
238
|
-
return /* @__PURE__ */
|
|
239
|
-
|
|
244
|
+
return /* @__PURE__ */ React6.createElement(SettingsControl, { key: control.value.bind, bind: control.value.bind }, /* @__PURE__ */ React6.createElement(SettingsControl.Label, null, control.value.label), /* @__PURE__ */ React6.createElement(
|
|
245
|
+
ControlComponent,
|
|
240
246
|
{
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
},
|
|
245
|
-
/* @__PURE__ */ React5.createElement(SettingsControl.Container, null, /* @__PURE__ */ React5.createElement(SettingsControl.Label, null, control.value.label), /* @__PURE__ */ React5.createElement(ControlComponent, { ...control.value.props }))
|
|
246
|
-
);
|
|
247
|
+
...control.value.props
|
|
248
|
+
}
|
|
249
|
+
));
|
|
247
250
|
}
|
|
248
251
|
return null;
|
|
249
252
|
})))));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/panel.ts","../src/components/editing-panel.tsx","../src/hooks/use-selected-elements.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/components/controls/control-types/select-control.tsx","../src/components/controls/control-context.ts","../src/components/controls/control-types/text-control.tsx","../src/components/controls/settings-control.tsx","../src/sync/update-settings.ts","../src/sync/get-container.ts","../src/hooks/use-widget-settings.ts","../src/contexts/settings-controls.tsx","../src/init.ts","../src/sync/should-use-v2-panel.ts","../src/hooks/use-open-editor-panel.ts","../src/components/editing-panel-hooks.tsx","../src/index.ts"],"sourcesContent":["import { __createPanel as createPanel } from '@elementor/editor-panels';\nimport { EditingPanel } from './components/editing-panel';\n\nexport const { panel, usePanelActions, usePanelStatus } = createPanel( {\n\tid: 'editing-panel',\n\tcomponent: EditingPanel,\n} );\n","import * as React from 'react';\nimport { __ } from '@wordpress/i18n';\nimport useSelectedElements from '../hooks/use-selected-elements';\nimport useElementType from '../hooks/use-element-type';\nimport { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from '@elementor/editor-panels';\nimport { SelectControl } from './controls/control-types/select-control';\nimport { TextControl } from './controls/control-types/text-control';\nimport { SettingsControl } from '../components/controls/settings-control';\nimport { Stack } from '@elementor/ui';\nimport { ElementContext } from '../contexts/settings-controls';\n\nconst controlTypes = {\n\tselect: SelectControl,\n\ttext: TextControl,\n};\n\nexport const EditingPanel = () => {\n\tconst elements = useSelectedElements();\n\n\tconst selectedElement = elements[ 0 ];\n\n\tconst elementType = useElementType( selectedElement?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn null;\n\t}\n\n\t/* translators: %s: Element type title. */\n\tconst panelTitle = __( 'Edit %s', 'elementor' ).replace( '%s', elementType.title );\n\n\treturn (\n\t\t<Panel>\n\t\t\t<PanelHeader>\n\t\t\t\t<PanelHeaderTitle>{ panelTitle }</PanelHeaderTitle>\n\t\t\t</PanelHeader>\n\t\t\t<PanelBody>\n\t\t\t\t<ElementContext element={ selectedElement }>\n\t\t\t\t\t<Stack spacing={ 2 }>\n\t\t\t\t\t\t{ elementType.controls.map( ( control ) => {\n\t\t\t\t\t\t\tif ( control.type === 'control' ) {\n\t\t\t\t\t\t\t\tconst ControlComponent =\n\t\t\t\t\t\t\t\t\tcontrolTypes[ control.value.type as keyof typeof controlTypes ];\n\n\t\t\t\t\t\t\t\tif ( ! ControlComponent ) {\n\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<SettingsControl\n\t\t\t\t\t\t\t\t\t\tkey={ control.value.bind }\n\t\t\t\t\t\t\t\t\t\tbind={ control.value.bind }\n\t\t\t\t\t\t\t\t\t\telementID={ elements[ 0 ].id }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<SettingsControl.Container>\n\t\t\t\t\t\t\t\t\t\t\t<SettingsControl.Label>{ control.value.label }</SettingsControl.Label>\n\t\t\t\t\t\t\t\t\t\t\t{ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ }\n\t\t\t\t\t\t\t\t\t\t\t<ControlComponent { ...( control.value.props as any ) } />\n\t\t\t\t\t\t\t\t\t\t</SettingsControl.Container>\n\t\t\t\t\t\t\t\t\t</SettingsControl>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</Stack>\n\t\t\t\t</ElementContext>\n\t\t\t</PanelBody>\n\t\t</Panel>\n\t);\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\nimport getSelectedElements from '../sync/get-selected-elements';\n\nexport default function useSelectedElements() {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\t() => getSelectedElements()\n\t);\n}\n","import { ExtendedWindow } from './types';\nimport { Element } from '../types';\n\nexport default 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 default 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\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\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 default function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import * as React from 'react';\nimport { MenuItem, Select, SelectChangeEvent } from '@elementor/ui';\nimport { useControl } from '../control-context';\nimport { PropValue } from '../../../types';\n\nexport type SelectControlProps< T > = {\n\toptions: Array< { label: string; value: T; disabled?: boolean } >;\n};\n\nexport const SelectControl = < T extends PropValue >( { options }: SelectControlProps< T > ) => {\n\tconst { value, setValue } = useControl< T >();\n\n\tconst handleChange = ( event: SelectChangeEvent< T > ) => {\n\t\tsetValue( event.target.value as T );\n\t};\n\n\treturn (\n\t\t<Select size=\"tiny\" value={ value ?? '' } onChange={ handleChange }>\n\t\t\t{ options.map( ( option ) => (\n\t\t\t\t<MenuItem key={ option.value } value={ option.value } disabled={ option.disabled }>\n\t\t\t\t\t{ option.label }\n\t\t\t\t</MenuItem>\n\t\t\t) ) }\n\t\t</Select>\n\t);\n};\n","import { createContext, useContext } from 'react';\nimport { PropKey, PropValue } from '../../types';\n\nexport type ControlContext< T extends PropValue > = null | {\n\tbind: PropKey;\n\tsetValue: ( value: T ) => void;\n\tvalue: T;\n};\n\nexport const ControlContext = createContext< ControlContext< PropValue > >( null );\n\nexport function useControl< T extends PropValue >( defaultValue?: T ) {\n\tconst controlContext = useContext< ControlContext< T > >( ControlContext as never );\n\n\tif ( ! controlContext ) {\n\t\tthrow new Error( 'useControl must be used within a ControlContext' );\n\t}\n\n\treturn { ...controlContext, value: controlContext.value ?? defaultValue };\n}\n","import * as React from 'react';\nimport { TextareaAutosize } from '@elementor/ui';\nimport { useControl } from '../control-context';\n\nexport type TextControlProps = {\n\tplaceholder?: string;\n};\n\nexport const TextControl = ( { placeholder }: TextControlProps ) => {\n\tconst { value, setValue } = useControl< string >( '' );\n\n\tconst handleChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetValue( event.target.value );\n\t};\n\n\treturn (\n\t\t<TextareaAutosize\n\t\t\tsize=\"tiny\"\n\t\t\tminRows={ 3 }\n\t\t\tvalue={ value }\n\t\t\tonChange={ handleChange }\n\t\t\tplaceholder={ placeholder }\n\t\t/>\n\t);\n};\n","import * as React from 'react';\nimport { ControlContext } from './control-context';\nimport { Stack, Typography } from '@elementor/ui';\nimport { updateSettings } from '../../sync/update-settings';\nimport { useWidgetSettings } from '../../hooks/use-widget-settings';\nimport { PropKey, PropValue } from '../../types';\n\ntype Props = {\n\tbind: PropKey;\n\tchildren: React.ReactNode;\n\telementID: Element[ 'id' ];\n};\n\nconst SettingsControl = ( { bind, children, elementID }: Props ) => {\n\tconst value = useWidgetSettings( { id: elementID, bind } );\n\n\tconst setValue = ( newValue: PropValue ) => {\n\t\tupdateSettings( {\n\t\t\tid: elementID,\n\t\t\tprops: {\n\t\t\t\t[ bind ]: newValue,\n\t\t\t},\n\t\t} );\n\t};\n\n\treturn <ControlContext.Provider value={ { setValue, value, bind } }>{ children }</ControlContext.Provider>;\n};\n\nconst Label = ( { children }: { children: React.ReactNode } ) => {\n\treturn (\n\t\t<Typography component=\"label\" variant=\"caption\">\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n};\n\nconst Container = ( { children }: { children: React.ReactNode } ) => (\n\t<Stack\n\t\tspacing={ 1 }\n\t\tflexDirection=\"row\"\n\t\talignItems=\"center\"\n\t\tjustifyContent=\"space-between\"\n\t\tflexWrap=\"wrap\"\n\t\tsx={ { px: 2 } }\n\t>\n\t\t{ children }\n\t</Stack>\n);\n\nSettingsControl.Label = Label;\nSettingsControl.Container = Container;\n\nexport { SettingsControl };\n","import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport { Props } from '../types';\nimport getContainer from './get-container';\n\nexport const updateSettings = ( { id, props }: { id: string; 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 { 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 { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { PropValue } from '../types';\nimport getContainer from '../sync/get-container';\n\nexport const useWidgetSettings = ( { id, bind }: { id: string; bind: string } ): PropValue => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/settings' ),\n\t\t() => {\n\t\t\tconst container = getContainer( id );\n\t\t\tconst value = container?.settings?.get( bind ) ?? null;\n\n\t\t\treturn value;\n\t\t},\n\t\t[]\n\t);\n};\n","import * as React from 'react';\nimport { createContext, ReactNode, useContext } from 'react';\nimport { Element } from '../types';\n\ntype ContextValue = {\n\telement: Element;\n};\n\nconst Context = createContext< ContextValue | null >( null );\n\ntype Props = {\n\telement: Element;\n\tchildren?: ReactNode;\n};\n\nexport function ElementContext( { children, element }: Props ) {\n\treturn <Context.Provider value={ { element } }>{ children }</Context.Provider>;\n}\n\nexport function useElementContext() {\n\tconst context = useContext( Context );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useElementContext must be used within a ElementContextProvider' );\n\t}\n\n\treturn context;\n}\n","import { panel } from './panel';\nimport { injectIntoLogic } from '@elementor/editor';\nimport { shouldUseV2Panel } from './sync/should-use-v2-panel';\nimport { EditingPanelHooks } from './components/editing-panel-hooks';\nimport { __registerPanel as registerPanel } from '@elementor/editor-panels';\nimport { __privateBlockDataCommand as blockDataCommand } from '@elementor/editor-v1-adapters';\n\nexport default function init() {\n\tregisterPanel( panel );\n\tblockV1Panel();\n\n\tinjectIntoLogic( {\n\t\tid: 'editing-panel-hooks',\n\t\tcomponent: EditingPanelHooks,\n\t} );\n}\n\nconst blockV1Panel = () => {\n\tblockDataCommand( {\n\t\tcommand: 'panel/editor/open',\n\t\tcondition: shouldUseV2Panel,\n\t} );\n};\n","import getSelectedElements from './get-selected-elements';\nimport getWidgetsCache from './get-widgets-cache';\n\nexport const shouldUseV2Panel = () => {\n\tconst selectedElements = getSelectedElements();\n\tconst widgetCache = getWidgetsCache();\n\n\tif ( selectedElements.length !== 1 ) {\n\t\treturn false;\n\t}\n\n\t// Check if the selected element has atomic controls, meaning it's a V2 element.\n\treturn !! widgetCache?.[ selectedElements[ 0 ].type ]?.atomic_controls;\n};\n","import { useEffect } from 'react';\nimport { commandStartEvent, __privateListenTo as listenTo } from '@elementor/editor-v1-adapters';\nimport { usePanelActions } from '../panel';\nimport { shouldUseV2Panel } from '../sync/should-use-v2-panel';\n\nexport const useOpenEditorPanel = () => {\n\tconst { open } = usePanelActions();\n\n\tuseEffect( () => {\n\t\treturn listenTo( commandStartEvent( 'panel/editor/open' ), () => {\n\t\t\tif ( shouldUseV2Panel() ) {\n\t\t\t\topen();\n\t\t\t}\n\t\t} );\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n};\n","import { useOpenEditorPanel } from '../hooks/use-open-editor-panel';\n\nexport const EditingPanelHooks = () => {\n\tuseOpenEditorPanel();\n\n\treturn null;\n};\n","import init from './init';\n\ninit();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,wBAA6C;;;ACA7C,IAAAC,SAAuB;AACvB,kBAAmB;;;ACDnB,gCAAqE;;;ACGtD,SAAR,sBAAkD;AACxD,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;;;ADjBe,SAAR,sBAAuC;AAC7C,aAAO,0BAAAC;AAAA,IACN,KAAE,2CAAiB,0BAA2B,OAAG,2CAAiB,4BAA6B,CAAE;AAAA,IACjG,MAAM,oBAAoB;AAAA,EAC3B;AACD;;;AERA,IAAAC,6BAAqE;;;ACEtD,SAAR,kBAAmC;AACzC,QAAM,iBAAiB;AAEvB,SAAO,gBAAgB,WAAW,gBAAgB;AACnD;;;ADFe,SAAR,eAAiC,MAAgB;AACvD,aAAO,2BAAAC;AAAA,QACN,4CAAiB,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,aAAO;AAAA,QACN,K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IAAM,EAAE,OAAO,iBAAiB,eAAe,QAAI,sBAAAC,eAAa;AAAA,EACtE,IAAI;AAAA,EACJ,WAAW;AACZ,CAAE;;;AcLF,oBAAgC;;;ACEzB,IAAM,mBAAmB,MAAM;AACrC,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,cAAc,gBAAgB;AAEpC,MAAK,iBAAiB,WAAW,GAAI;AACpC,WAAO;AAAA,EACR;AAGA,SAAO,CAAC,CAAE,cAAe,iBAAkB,CAAE,EAAE,IAAK,GAAG;AACxD;;;ACbA,IAAAC,gBAA0B;AAC1B,IAAAC,6BAAiE;AAI1D,IAAM,qBAAqB,MAAM;AACvC,QAAM,EAAE,KAAK,IAAI,gBAAgB;AAEjC,+BAAW,MAAM;AAChB,eAAO,2BAAAC,uBAAU,8CAAmB,mBAAoB,GAAG,MAAM;AAChE,UAAK,iBAAiB,GAAI;AACzB,aAAK;AAAA,MACN;AAAA,IACD,CAAE;AAAA,EACH,GAAG,CAAC,CAAE;AACP;;;ACbO,IAAM,oBAAoB,MAAM;AACtC,qBAAmB;AAEnB,SAAO;AACR;;;AHFA,IAAAC,wBAAiD;AACjD,IAAAC,6BAA8D;AAE/C,SAAR,OAAwB;AAC9B,4BAAAC,iBAAe,KAAM;AACrB,eAAa;AAEb,qCAAiB;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;AAEA,IAAM,eAAe,MAAM;AAC1B,iCAAAC,2BAAkB;AAAA,IACjB,SAAS;AAAA,IACT,WAAW;AAAA,EACZ,CAAE;AACH;;;AIpBA,KAAK;","names":["import_editor_panels","React","useListenTo","import_editor_v1_adapters","useListenTo","React","import_ui","React","import_ui","import_editor_v1_adapters","runCommand","import_editor_v1_adapters","useListenTo","import_ui","React","import_react","createPanel","import_react","import_editor_v1_adapters","listenTo","import_editor_panels","import_editor_v1_adapters","registerPanel","blockDataCommand"]}
|
|
1
|
+
{"version":3,"sources":["../src/panel.ts","../src/components/editing-panel.tsx","../src/hooks/use-selected-elements.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/components/controls/control-types/select-control.tsx","../src/contexts/control-context.tsx","../src/contexts/element-context.tsx","../src/hooks/use-widget-settings.ts","../src/sync/get-container.ts","../src/sync/update-settings.ts","../src/components/controls/control-types/text-area-control.tsx","../src/components/controls/settings-control.tsx","../src/init.ts","../src/sync/should-use-v2-panel.ts","../src/hooks/use-open-editor-panel.ts","../src/components/editing-panel-hooks.tsx","../src/index.ts"],"sourcesContent":["import { __createPanel as createPanel } from '@elementor/editor-panels';\nimport { EditingPanel } from './components/editing-panel';\n\nexport const { panel, usePanelActions, usePanelStatus } = createPanel( {\n\tid: 'editing-panel',\n\tcomponent: EditingPanel,\n} );\n","import * as React from 'react';\nimport { __ } from '@wordpress/i18n';\nimport useSelectedElements from '../hooks/use-selected-elements';\nimport useElementType from '../hooks/use-element-type';\nimport { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from '@elementor/editor-panels';\nimport { SelectControl } from './controls/control-types/select-control';\nimport { TextAreaControl } from './controls/control-types/text-area-control';\nimport { SettingsControl } from '../components/controls/settings-control';\nimport { Stack } from '@elementor/ui';\nimport { ElementContext } from '../contexts/element-context';\n\nconst controlTypes = {\n\tselect: SelectControl,\n\ttextarea: TextAreaControl,\n};\n\nexport const EditingPanel = () => {\n\tconst elements = useSelectedElements();\n\n\tconst [ selectedElement ] = elements;\n\n\tconst elementType = useElementType( selectedElement?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn null;\n\t}\n\n\t/* translators: %s: Element type title. */\n\tconst panelTitle = __( 'Edit %s', 'elementor' ).replace( '%s', elementType.title );\n\n\treturn (\n\t\t<Panel>\n\t\t\t<PanelHeader>\n\t\t\t\t<PanelHeaderTitle>{ panelTitle }</PanelHeaderTitle>\n\t\t\t</PanelHeader>\n\t\t\t<PanelBody>\n\t\t\t\t<ElementContext element={ selectedElement }>\n\t\t\t\t\t<Stack spacing={ 2 }>\n\t\t\t\t\t\t{ elementType.controls.map( ( control ) => {\n\t\t\t\t\t\t\tif ( control.type === 'control' ) {\n\t\t\t\t\t\t\t\tconst ControlComponent =\n\t\t\t\t\t\t\t\t\tcontrolTypes[ control.value.type as keyof typeof controlTypes ];\n\n\t\t\t\t\t\t\t\tif ( ! ControlComponent ) {\n\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<SettingsControl key={ control.value.bind } bind={ control.value.bind }>\n\t\t\t\t\t\t\t\t\t\t<SettingsControl.Label>{ control.value.label }</SettingsControl.Label>\n\t\t\t\t\t\t\t\t\t\t<ControlComponent\n\t\t\t\t\t\t\t\t\t\t\t/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n\t\t\t\t\t\t\t\t\t\t\t{ ...( control.value.props as any ) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SettingsControl>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</Stack>\n\t\t\t\t</ElementContext>\n\t\t\t</PanelBody>\n\t\t</Panel>\n\t);\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\nimport getSelectedElements from '../sync/get-selected-elements';\n\nexport default function useSelectedElements() {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\t() => getSelectedElements()\n\t);\n}\n","import { ExtendedWindow } from './types';\nimport { Element } from '../types';\n\nexport default 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 default 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\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\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 default function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import * as React from 'react';\nimport { MenuItem, Select, SelectChangeEvent } from '@elementor/ui';\nimport { useControl } from '../../../contexts/control-context';\nimport { PropValue } from '../../../types';\n\ntype Props< T > = {\n\toptions: Array< { label: string; value: T; disabled?: boolean } >;\n};\n\nexport const SelectControl = < T extends PropValue >( { options }: Props< T > ) => {\n\tconst { value, setValue } = useControl< T >();\n\n\tconst handleChange = ( event: SelectChangeEvent< T > ) => {\n\t\tsetValue( event.target.value as T );\n\t};\n\n\treturn (\n\t\t<Select size=\"tiny\" value={ value ?? '' } onChange={ handleChange }>\n\t\t\t{ options.map( ( { label, ...props } ) => (\n\t\t\t\t<MenuItem key={ props.value } { ...props }>\n\t\t\t\t\t{ label }\n\t\t\t\t</MenuItem>\n\t\t\t) ) }\n\t\t</Select>\n\t);\n};\n","import * as React from 'react';\nimport { createContext, useContext } from 'react';\nimport { PropKey, PropValue } from '../types';\nimport { useElementContext } from './element-context';\nimport { useWidgetSettings } from '../hooks/use-widget-settings';\nimport { updateSettings } from '../sync/update-settings';\n\nexport type ControlContext< T extends PropValue > = null | {\n\tbind: PropKey;\n\tsetValue: ( value: T ) => void;\n\tvalue: T;\n};\n\nexport const ControlContext = createContext< ControlContext< PropValue > >( null );\n\nexport function useControl< T extends PropValue >( defaultValue?: T ) {\n\tconst controlContext = useContext< ControlContext< T > >( ControlContext as never );\n\n\tif ( ! controlContext ) {\n\t\tthrow new Error( 'useControl must be used within a ControlContext' );\n\t}\n\n\treturn { ...controlContext, value: controlContext.value ?? defaultValue };\n}\n\ntype Props = {\n\tbind: PropKey;\n\tchildren: React.ReactNode;\n};\n\nexport const ControlContextProvider = ( { bind, children }: Props ) => {\n\tconst { element } = useElementContext();\n\tconst value = useWidgetSettings( { id: element.id, bind } );\n\n\tconst setValue = ( newValue: PropValue ) => {\n\t\tupdateSettings( {\n\t\t\tid: element.id,\n\t\t\tprops: {\n\t\t\t\t[ bind ]: newValue,\n\t\t\t},\n\t\t} );\n\t};\n\n\treturn <ControlContext.Provider value={ { setValue, value, bind } }>{ children }</ControlContext.Provider>;\n};\n","import * as React from 'react';\nimport { createContext, ReactNode, useContext } from 'react';\nimport { Element } from '../types';\n\ntype ContextValue = {\n\telement: Element;\n};\n\nconst Context = createContext< ContextValue | null >( null );\n\ntype Props = {\n\telement: Element;\n\tchildren?: ReactNode;\n};\n\nexport function ElementContext( { children, element }: Props ) {\n\treturn <Context.Provider value={ { element } }>{ children }</Context.Provider>;\n}\n\nexport function useElementContext() {\n\tconst context = useContext( Context );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useElementContext must be used within a ElementContextProvider' );\n\t}\n\n\treturn context;\n}\n","import { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { PropValue } from '../types';\nimport getContainer from '../sync/get-container';\n\nexport const useWidgetSettings = ( { id, bind }: { id: string; bind: string } ): PropValue => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/settings' ),\n\t\t() => {\n\t\t\tconst container = getContainer( id );\n\t\t\tconst value = container?.settings?.get( bind ) ?? null;\n\n\t\t\treturn value;\n\t\t},\n\t\t[]\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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport { Props } from '../types';\nimport getContainer from './get-container';\n\nexport const updateSettings = ( { id, props }: { id: string; 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 * as React from 'react';\nimport { TextareaAutosize } from '@elementor/ui';\nimport { useControl } from '../../../contexts/control-context';\n\ntype Props = {\n\tplaceholder?: string;\n};\n\nexport const TextAreaControl = ( { placeholder }: Props ) => {\n\tconst { value, setValue } = useControl< string >( '' );\n\n\tconst handleChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetValue( event.target.value );\n\t};\n\n\treturn (\n\t\t<TextareaAutosize\n\t\t\tsize=\"tiny\"\n\t\t\tminRows={ 3 }\n\t\t\tvalue={ value }\n\t\t\tonChange={ handleChange }\n\t\t\tplaceholder={ placeholder }\n\t\t/>\n\t);\n};\n","import * as React from 'react';\nimport { ControlContextProvider } from '../../contexts/control-context';\nimport { Stack, Typography } from '@elementor/ui';\nimport { PropKey } from '../../types';\n\ntype Props = {\n\tbind: PropKey;\n\tchildren: React.ReactNode;\n};\n\nconst SettingsControl = ( { children, bind }: Props ) => (\n\t<Stack\n\t\tspacing={ 1 }\n\t\tflexDirection=\"row\"\n\t\talignItems=\"center\"\n\t\tjustifyContent=\"space-between\"\n\t\tflexWrap=\"wrap\"\n\t\tsx={ { px: 2 } }\n\t>\n\t\t<ControlContextProvider bind={ bind }>{ children }</ControlContextProvider>\n\t</Stack>\n);\n\nconst Label = ( { children }: { children: React.ReactNode } ) => {\n\treturn (\n\t\t<Typography component=\"label\" variant=\"caption\">\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n};\n\nSettingsControl.Label = Label;\nexport { SettingsControl };\n","import { panel } from './panel';\nimport { injectIntoLogic } from '@elementor/editor';\nimport { shouldUseV2Panel } from './sync/should-use-v2-panel';\nimport { EditingPanelHooks } from './components/editing-panel-hooks';\nimport { __registerPanel as registerPanel } from '@elementor/editor-panels';\nimport { __privateBlockDataCommand as blockDataCommand } from '@elementor/editor-v1-adapters';\n\nexport default function init() {\n\tregisterPanel( panel );\n\tblockV1Panel();\n\n\tinjectIntoLogic( {\n\t\tid: 'editing-panel-hooks',\n\t\tcomponent: EditingPanelHooks,\n\t} );\n}\n\nconst blockV1Panel = () => {\n\tblockDataCommand( {\n\t\tcommand: 'panel/editor/open',\n\t\tcondition: shouldUseV2Panel,\n\t} );\n};\n","import getSelectedElements from './get-selected-elements';\nimport getWidgetsCache from './get-widgets-cache';\n\nexport const shouldUseV2Panel = () => {\n\tconst selectedElements = getSelectedElements();\n\tconst widgetCache = getWidgetsCache();\n\n\tif ( selectedElements.length !== 1 ) {\n\t\treturn false;\n\t}\n\n\t// Check if the selected element has atomic controls, meaning it's a V2 element.\n\treturn !! widgetCache?.[ selectedElements[ 0 ].type ]?.atomic_controls;\n};\n","import { useEffect } from 'react';\nimport { commandStartEvent, __privateListenTo as listenTo } from '@elementor/editor-v1-adapters';\nimport { usePanelActions } from '../panel';\nimport { shouldUseV2Panel } from '../sync/should-use-v2-panel';\n\nexport const useOpenEditorPanel = () => {\n\tconst { open } = usePanelActions();\n\n\tuseEffect( () => {\n\t\treturn listenTo( commandStartEvent( 'panel/editor/open' ), () => {\n\t\t\tif ( shouldUseV2Panel() ) {\n\t\t\t\topen();\n\t\t\t}\n\t\t} );\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n};\n","import { useOpenEditorPanel } from '../hooks/use-open-editor-panel';\n\nexport const EditingPanelHooks = () => {\n\tuseOpenEditorPanel();\n\n\treturn null;\n};\n","import init from './init';\n\ninit();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,wBAA6C;;;ACA7C,IAAAC,SAAuB;AACvB,kBAAmB;;;ACDnB,gCAAqE;;;ACGtD,SAAR,sBAAkD;AACxD,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;;;ADjBe,SAAR,sBAAuC;AAC7C,aAAO,0BAAAC;AAAA,IACN,KAAE,2CAAiB,0BAA2B,OAAG,2CAAiB,4BAA6B,CAAE;AAAA,IACjG,MAAM,oBAAoB;AAAA,EAC3B;AACD;;;AERA,IAAAC,6BAAqE;;;ACEtD,SAAR,kBAAmC;AACzC,QAAM,iBAAiB;AAEvB,SAAO,gBAAgB,WAAW,gBAAgB;AACnD;;;ADFe,SAAR,eAAiC,MAAgB;AACvD,aAAO,2BAAAC;AAAA,QACN,4CAAiB,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,a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9C;AAAA,QAAC;AAAA;AAAA,UAEE,GAAK,QAAQ,MAAM;AAAA;AAAA,MACtB,CACD;AAAA,IAEF;AAEA,WAAO;AAAA,EACR,CAAE,CACH,CACD,CACD,CACD;AAEF;;;AD9DO,IAAM,EAAE,OAAO,iBAAiB,eAAe,QAAI,sBAAAC,eAAa;AAAA,EACtE,IAAI;AAAA,EACJ,WAAW;AACZ,CAAE;;;AcLF,oBAAgC;;;ACEzB,IAAM,mBAAmB,MAAM;AACrC,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,cAAc,gBAAgB;AAEpC,MAAK,iBAAiB,WAAW,GAAI;AACpC,WAAO;AAAA,EACR;AAGA,SAAO,CAAC,CAAE,cAAe,iBAAkB,CAAE,EAAE,IAAK,GAAG;AACxD;;;ACbA,IAAAC,gBAA0B;AAC1B,IAAAC,6BAAiE;AAI1D,IAAM,qBAAqB,MAAM;AACvC,QAAM,EAAE,KAAK,IAAI,gBAAgB;AAEjC,+BAAW,MAAM;AAChB,eAAO,2BAAAC,uBAAU,8CAAmB,mBAAoB,GAAG,MAAM;AAChE,UAAK,iBAAiB,GAAI;AACzB,aAAK;AAAA,MACN;AAAA,IACD,CAAE;AAAA,EACH,GAAG,CAAC,CAAE;AACP;;;ACbO,IAAM,oBAAoB,MAAM;AACtC,qBAAmB;AAEnB,SAAO;AACR;;;AHFA,IAAAC,wBAAiD;AACjD,IAAAC,6BAA8D;AAE/C,SAAR,OAAwB;AAC9B,4BAAAC,iBAAe,KAAM;AACrB,eAAa;AAEb,qCAAiB;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;AAEA,IAAM,eAAe,MAAM;AAC1B,iCAAAC,2BAAkB;AAAA,IACjB,SAAS;AAAA,IACT,WAAW;AAAA,EACZ,CAAE;AACH;;;AIpBA,KAAK;","names":["import_editor_panels","React","useListenTo","import_editor_v1_adapters","useListenTo","React","React","import_react","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","runCommand","React","import_ui","React","import_ui","import_ui","createPanel","import_react","import_editor_v1_adapters","listenTo","import_editor_panels","import_editor_v1_adapters","registerPanel","blockDataCommand"]}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { __createPanel as createPanel } from "@elementor/editor-panels";
|
|
3
3
|
|
|
4
4
|
// src/components/editing-panel.tsx
|
|
5
|
-
import * as
|
|
5
|
+
import * as React6 from "react";
|
|
6
6
|
import { __ } from "@wordpress/i18n";
|
|
7
7
|
|
|
8
8
|
// src/hooks/use-selected-elements.ts
|
|
@@ -68,55 +68,30 @@ function useElementType(type) {
|
|
|
68
68
|
import { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from "@elementor/editor-panels";
|
|
69
69
|
|
|
70
70
|
// src/components/controls/control-types/select-control.tsx
|
|
71
|
-
import * as
|
|
71
|
+
import * as React3 from "react";
|
|
72
72
|
import { MenuItem, Select } from "@elementor/ui";
|
|
73
73
|
|
|
74
|
-
// src/
|
|
74
|
+
// src/contexts/control-context.tsx
|
|
75
|
+
import * as React2 from "react";
|
|
76
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
77
|
+
|
|
78
|
+
// src/contexts/element-context.tsx
|
|
79
|
+
import * as React from "react";
|
|
75
80
|
import { createContext, useContext } from "react";
|
|
76
|
-
var
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
var Context = createContext(null);
|
|
82
|
+
function ElementContext({ children, element }) {
|
|
83
|
+
return /* @__PURE__ */ React.createElement(Context.Provider, { value: { element } }, children);
|
|
84
|
+
}
|
|
85
|
+
function useElementContext() {
|
|
86
|
+
const context = useContext(Context);
|
|
87
|
+
if (!context) {
|
|
88
|
+
throw new Error("useElementContext must be used within a ElementContextProvider");
|
|
81
89
|
}
|
|
82
|
-
return
|
|
90
|
+
return context;
|
|
83
91
|
}
|
|
84
92
|
|
|
85
|
-
// src/
|
|
86
|
-
|
|
87
|
-
const { value, setValue } = useControl();
|
|
88
|
-
const handleChange = (event) => {
|
|
89
|
-
setValue(event.target.value);
|
|
90
|
-
};
|
|
91
|
-
return /* @__PURE__ */ React.createElement(Select, { size: "tiny", value: value ?? "", onChange: handleChange }, options.map((option) => /* @__PURE__ */ React.createElement(MenuItem, { key: option.value, value: option.value, disabled: option.disabled }, option.label)));
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// src/components/controls/control-types/text-control.tsx
|
|
95
|
-
import * as React2 from "react";
|
|
96
|
-
import { TextareaAutosize } from "@elementor/ui";
|
|
97
|
-
var TextControl = ({ placeholder }) => {
|
|
98
|
-
const { value, setValue } = useControl("");
|
|
99
|
-
const handleChange = (event) => {
|
|
100
|
-
setValue(event.target.value);
|
|
101
|
-
};
|
|
102
|
-
return /* @__PURE__ */ React2.createElement(
|
|
103
|
-
TextareaAutosize,
|
|
104
|
-
{
|
|
105
|
-
size: "tiny",
|
|
106
|
-
minRows: 3,
|
|
107
|
-
value,
|
|
108
|
-
onChange: handleChange,
|
|
109
|
-
placeholder
|
|
110
|
-
}
|
|
111
|
-
);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// src/components/controls/settings-control.tsx
|
|
115
|
-
import * as React3 from "react";
|
|
116
|
-
import { Stack, Typography } from "@elementor/ui";
|
|
117
|
-
|
|
118
|
-
// src/sync/update-settings.ts
|
|
119
|
-
import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
|
|
93
|
+
// src/hooks/use-widget-settings.ts
|
|
94
|
+
import { commandEndEvent as commandEndEvent3, __privateUseListenTo as useListenTo3 } from "@elementor/editor-v1-adapters";
|
|
120
95
|
|
|
121
96
|
// src/sync/get-container.ts
|
|
122
97
|
function getContainer(id) {
|
|
@@ -125,19 +100,7 @@ function getContainer(id) {
|
|
|
125
100
|
return container ?? null;
|
|
126
101
|
}
|
|
127
102
|
|
|
128
|
-
// src/sync/update-settings.ts
|
|
129
|
-
var updateSettings = ({ id, props }) => {
|
|
130
|
-
const container = getContainer(id);
|
|
131
|
-
runCommand("document/elements/settings", {
|
|
132
|
-
container,
|
|
133
|
-
settings: {
|
|
134
|
-
...props
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
|
|
139
103
|
// src/hooks/use-widget-settings.ts
|
|
140
|
-
import { commandEndEvent as commandEndEvent3, __privateUseListenTo as useListenTo3 } from "@elementor/editor-v1-adapters";
|
|
141
104
|
var useWidgetSettings = ({ id, bind }) => {
|
|
142
105
|
return useListenTo3(
|
|
143
106
|
commandEndEvent3("document/elements/settings"),
|
|
@@ -150,23 +113,74 @@ var useWidgetSettings = ({ id, bind }) => {
|
|
|
150
113
|
);
|
|
151
114
|
};
|
|
152
115
|
|
|
153
|
-
// src/
|
|
154
|
-
|
|
155
|
-
|
|
116
|
+
// src/sync/update-settings.ts
|
|
117
|
+
import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
|
|
118
|
+
var updateSettings = ({ id, props }) => {
|
|
119
|
+
const container = getContainer(id);
|
|
120
|
+
runCommand("document/elements/settings", {
|
|
121
|
+
container,
|
|
122
|
+
settings: {
|
|
123
|
+
...props
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/contexts/control-context.tsx
|
|
129
|
+
var ControlContext = createContext2(null);
|
|
130
|
+
function useControl(defaultValue) {
|
|
131
|
+
const controlContext = useContext2(ControlContext);
|
|
132
|
+
if (!controlContext) {
|
|
133
|
+
throw new Error("useControl must be used within a ControlContext");
|
|
134
|
+
}
|
|
135
|
+
return { ...controlContext, value: controlContext.value ?? defaultValue };
|
|
136
|
+
}
|
|
137
|
+
var ControlContextProvider = ({ bind, children }) => {
|
|
138
|
+
const { element } = useElementContext();
|
|
139
|
+
const value = useWidgetSettings({ id: element.id, bind });
|
|
156
140
|
const setValue = (newValue) => {
|
|
157
141
|
updateSettings({
|
|
158
|
-
id:
|
|
142
|
+
id: element.id,
|
|
159
143
|
props: {
|
|
160
144
|
[bind]: newValue
|
|
161
145
|
}
|
|
162
146
|
});
|
|
163
147
|
};
|
|
164
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ React2.createElement(ControlContext.Provider, { value: { setValue, value, bind } }, children);
|
|
165
149
|
};
|
|
166
|
-
|
|
167
|
-
|
|
150
|
+
|
|
151
|
+
// src/components/controls/control-types/select-control.tsx
|
|
152
|
+
var SelectControl = ({ options }) => {
|
|
153
|
+
const { value, setValue } = useControl();
|
|
154
|
+
const handleChange = (event) => {
|
|
155
|
+
setValue(event.target.value);
|
|
156
|
+
};
|
|
157
|
+
return /* @__PURE__ */ React3.createElement(Select, { size: "tiny", value: value ?? "", onChange: handleChange }, options.map(({ label, ...props }) => /* @__PURE__ */ React3.createElement(MenuItem, { key: props.value, ...props }, label)));
|
|
168
158
|
};
|
|
169
|
-
|
|
159
|
+
|
|
160
|
+
// src/components/controls/control-types/text-area-control.tsx
|
|
161
|
+
import * as React4 from "react";
|
|
162
|
+
import { TextareaAutosize } from "@elementor/ui";
|
|
163
|
+
var TextAreaControl = ({ placeholder }) => {
|
|
164
|
+
const { value, setValue } = useControl("");
|
|
165
|
+
const handleChange = (event) => {
|
|
166
|
+
setValue(event.target.value);
|
|
167
|
+
};
|
|
168
|
+
return /* @__PURE__ */ React4.createElement(
|
|
169
|
+
TextareaAutosize,
|
|
170
|
+
{
|
|
171
|
+
size: "tiny",
|
|
172
|
+
minRows: 3,
|
|
173
|
+
value,
|
|
174
|
+
onChange: handleChange,
|
|
175
|
+
placeholder
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/components/controls/settings-control.tsx
|
|
181
|
+
import * as React5 from "react";
|
|
182
|
+
import { Stack, Typography } from "@elementor/ui";
|
|
183
|
+
var SettingsControl = ({ children, bind }) => /* @__PURE__ */ React5.createElement(
|
|
170
184
|
Stack,
|
|
171
185
|
{
|
|
172
186
|
spacing: 1,
|
|
@@ -176,50 +190,39 @@ var Container = ({ children }) => /* @__PURE__ */ React3.createElement(
|
|
|
176
190
|
flexWrap: "wrap",
|
|
177
191
|
sx: { px: 2 }
|
|
178
192
|
},
|
|
179
|
-
children
|
|
193
|
+
/* @__PURE__ */ React5.createElement(ControlContextProvider, { bind }, children)
|
|
180
194
|
);
|
|
195
|
+
var Label = ({ children }) => {
|
|
196
|
+
return /* @__PURE__ */ React5.createElement(Typography, { component: "label", variant: "caption" }, children);
|
|
197
|
+
};
|
|
181
198
|
SettingsControl.Label = Label;
|
|
182
|
-
SettingsControl.Container = Container;
|
|
183
199
|
|
|
184
200
|
// src/components/editing-panel.tsx
|
|
185
201
|
import { Stack as Stack2 } from "@elementor/ui";
|
|
186
|
-
|
|
187
|
-
// src/contexts/settings-controls.tsx
|
|
188
|
-
import * as React4 from "react";
|
|
189
|
-
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
190
|
-
var Context = createContext2(null);
|
|
191
|
-
function ElementContext({ children, element }) {
|
|
192
|
-
return /* @__PURE__ */ React4.createElement(Context.Provider, { value: { element } }, children);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// src/components/editing-panel.tsx
|
|
196
202
|
var controlTypes = {
|
|
197
203
|
select: SelectControl,
|
|
198
|
-
|
|
204
|
+
textarea: TextAreaControl
|
|
199
205
|
};
|
|
200
206
|
var EditingPanel = () => {
|
|
201
207
|
const elements = useSelectedElements();
|
|
202
|
-
const selectedElement = elements
|
|
208
|
+
const [selectedElement] = elements;
|
|
203
209
|
const elementType = useElementType(selectedElement?.type);
|
|
204
210
|
if (elements.length !== 1 || !elementType) {
|
|
205
211
|
return null;
|
|
206
212
|
}
|
|
207
213
|
const panelTitle = __("Edit %s", "elementor").replace("%s", elementType.title);
|
|
208
|
-
return /* @__PURE__ */
|
|
214
|
+
return /* @__PURE__ */ React6.createElement(Panel, null, /* @__PURE__ */ React6.createElement(PanelHeader, null, /* @__PURE__ */ React6.createElement(PanelHeaderTitle, null, panelTitle)), /* @__PURE__ */ React6.createElement(PanelBody, null, /* @__PURE__ */ React6.createElement(ElementContext, { element: selectedElement }, /* @__PURE__ */ React6.createElement(Stack2, { spacing: 2 }, elementType.controls.map((control) => {
|
|
209
215
|
if (control.type === "control") {
|
|
210
216
|
const ControlComponent = controlTypes[control.value.type];
|
|
211
217
|
if (!ControlComponent) {
|
|
212
218
|
return null;
|
|
213
219
|
}
|
|
214
|
-
return /* @__PURE__ */
|
|
215
|
-
|
|
220
|
+
return /* @__PURE__ */ React6.createElement(SettingsControl, { key: control.value.bind, bind: control.value.bind }, /* @__PURE__ */ React6.createElement(SettingsControl.Label, null, control.value.label), /* @__PURE__ */ React6.createElement(
|
|
221
|
+
ControlComponent,
|
|
216
222
|
{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
},
|
|
221
|
-
/* @__PURE__ */ React5.createElement(SettingsControl.Container, null, /* @__PURE__ */ React5.createElement(SettingsControl.Label, null, control.value.label), /* @__PURE__ */ React5.createElement(ControlComponent, { ...control.value.props }))
|
|
222
|
-
);
|
|
223
|
+
...control.value.props
|
|
224
|
+
}
|
|
225
|
+
));
|
|
223
226
|
}
|
|
224
227
|
return null;
|
|
225
228
|
})))));
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/panel.ts","../src/components/editing-panel.tsx","../src/hooks/use-selected-elements.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/components/controls/control-types/select-control.tsx","../src/components/controls/control-context.ts","../src/components/controls/control-types/text-control.tsx","../src/components/controls/settings-control.tsx","../src/sync/update-settings.ts","../src/sync/get-container.ts","../src/hooks/use-widget-settings.ts","../src/contexts/settings-controls.tsx","../src/init.ts","../src/sync/should-use-v2-panel.ts","../src/hooks/use-open-editor-panel.ts","../src/components/editing-panel-hooks.tsx","../src/index.ts"],"sourcesContent":["import { __createPanel as createPanel } from '@elementor/editor-panels';\nimport { EditingPanel } from './components/editing-panel';\n\nexport const { panel, usePanelActions, usePanelStatus } = createPanel( {\n\tid: 'editing-panel',\n\tcomponent: EditingPanel,\n} );\n","import * as React from 'react';\nimport { __ } from '@wordpress/i18n';\nimport useSelectedElements from '../hooks/use-selected-elements';\nimport useElementType from '../hooks/use-element-type';\nimport { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from '@elementor/editor-panels';\nimport { SelectControl } from './controls/control-types/select-control';\nimport { TextControl } from './controls/control-types/text-control';\nimport { SettingsControl } from '../components/controls/settings-control';\nimport { Stack } from '@elementor/ui';\nimport { ElementContext } from '../contexts/settings-controls';\n\nconst controlTypes = {\n\tselect: SelectControl,\n\ttext: TextControl,\n};\n\nexport const EditingPanel = () => {\n\tconst elements = useSelectedElements();\n\n\tconst selectedElement = elements[ 0 ];\n\n\tconst elementType = useElementType( selectedElement?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn null;\n\t}\n\n\t/* translators: %s: Element type title. */\n\tconst panelTitle = __( 'Edit %s', 'elementor' ).replace( '%s', elementType.title );\n\n\treturn (\n\t\t<Panel>\n\t\t\t<PanelHeader>\n\t\t\t\t<PanelHeaderTitle>{ panelTitle }</PanelHeaderTitle>\n\t\t\t</PanelHeader>\n\t\t\t<PanelBody>\n\t\t\t\t<ElementContext element={ selectedElement }>\n\t\t\t\t\t<Stack spacing={ 2 }>\n\t\t\t\t\t\t{ elementType.controls.map( ( control ) => {\n\t\t\t\t\t\t\tif ( control.type === 'control' ) {\n\t\t\t\t\t\t\t\tconst ControlComponent =\n\t\t\t\t\t\t\t\t\tcontrolTypes[ control.value.type as keyof typeof controlTypes ];\n\n\t\t\t\t\t\t\t\tif ( ! ControlComponent ) {\n\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<SettingsControl\n\t\t\t\t\t\t\t\t\t\tkey={ control.value.bind }\n\t\t\t\t\t\t\t\t\t\tbind={ control.value.bind }\n\t\t\t\t\t\t\t\t\t\telementID={ elements[ 0 ].id }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<SettingsControl.Container>\n\t\t\t\t\t\t\t\t\t\t\t<SettingsControl.Label>{ control.value.label }</SettingsControl.Label>\n\t\t\t\t\t\t\t\t\t\t\t{ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ }\n\t\t\t\t\t\t\t\t\t\t\t<ControlComponent { ...( control.value.props as any ) } />\n\t\t\t\t\t\t\t\t\t\t</SettingsControl.Container>\n\t\t\t\t\t\t\t\t\t</SettingsControl>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</Stack>\n\t\t\t\t</ElementContext>\n\t\t\t</PanelBody>\n\t\t</Panel>\n\t);\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\nimport getSelectedElements from '../sync/get-selected-elements';\n\nexport default function useSelectedElements() {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\t() => getSelectedElements()\n\t);\n}\n","import { ExtendedWindow } from './types';\nimport { Element } from '../types';\n\nexport default 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 default 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\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\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 default function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import * as React from 'react';\nimport { MenuItem, Select, SelectChangeEvent } from '@elementor/ui';\nimport { useControl } from '../control-context';\nimport { PropValue } from '../../../types';\n\nexport type SelectControlProps< T > = {\n\toptions: Array< { label: string; value: T; disabled?: boolean } >;\n};\n\nexport const SelectControl = < T extends PropValue >( { options }: SelectControlProps< T > ) => {\n\tconst { value, setValue } = useControl< T >();\n\n\tconst handleChange = ( event: SelectChangeEvent< T > ) => {\n\t\tsetValue( event.target.value as T );\n\t};\n\n\treturn (\n\t\t<Select size=\"tiny\" value={ value ?? '' } onChange={ handleChange }>\n\t\t\t{ options.map( ( option ) => (\n\t\t\t\t<MenuItem key={ option.value } value={ option.value } disabled={ option.disabled }>\n\t\t\t\t\t{ option.label }\n\t\t\t\t</MenuItem>\n\t\t\t) ) }\n\t\t</Select>\n\t);\n};\n","import { createContext, useContext } from 'react';\nimport { PropKey, PropValue } from '../../types';\n\nexport type ControlContext< T extends PropValue > = null | {\n\tbind: PropKey;\n\tsetValue: ( value: T ) => void;\n\tvalue: T;\n};\n\nexport const ControlContext = createContext< ControlContext< PropValue > >( null );\n\nexport function useControl< T extends PropValue >( defaultValue?: T ) {\n\tconst controlContext = useContext< ControlContext< T > >( ControlContext as never );\n\n\tif ( ! controlContext ) {\n\t\tthrow new Error( 'useControl must be used within a ControlContext' );\n\t}\n\n\treturn { ...controlContext, value: controlContext.value ?? defaultValue };\n}\n","import * as React from 'react';\nimport { TextareaAutosize } from '@elementor/ui';\nimport { useControl } from '../control-context';\n\nexport type TextControlProps = {\n\tplaceholder?: string;\n};\n\nexport const TextControl = ( { placeholder }: TextControlProps ) => {\n\tconst { value, setValue } = useControl< string >( '' );\n\n\tconst handleChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetValue( event.target.value );\n\t};\n\n\treturn (\n\t\t<TextareaAutosize\n\t\t\tsize=\"tiny\"\n\t\t\tminRows={ 3 }\n\t\t\tvalue={ value }\n\t\t\tonChange={ handleChange }\n\t\t\tplaceholder={ placeholder }\n\t\t/>\n\t);\n};\n","import * as React from 'react';\nimport { ControlContext } from './control-context';\nimport { Stack, Typography } from '@elementor/ui';\nimport { updateSettings } from '../../sync/update-settings';\nimport { useWidgetSettings } from '../../hooks/use-widget-settings';\nimport { PropKey, PropValue } from '../../types';\n\ntype Props = {\n\tbind: PropKey;\n\tchildren: React.ReactNode;\n\telementID: Element[ 'id' ];\n};\n\nconst SettingsControl = ( { bind, children, elementID }: Props ) => {\n\tconst value = useWidgetSettings( { id: elementID, bind } );\n\n\tconst setValue = ( newValue: PropValue ) => {\n\t\tupdateSettings( {\n\t\t\tid: elementID,\n\t\t\tprops: {\n\t\t\t\t[ bind ]: newValue,\n\t\t\t},\n\t\t} );\n\t};\n\n\treturn <ControlContext.Provider value={ { setValue, value, bind } }>{ children }</ControlContext.Provider>;\n};\n\nconst Label = ( { children }: { children: React.ReactNode } ) => {\n\treturn (\n\t\t<Typography component=\"label\" variant=\"caption\">\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n};\n\nconst Container = ( { children }: { children: React.ReactNode } ) => (\n\t<Stack\n\t\tspacing={ 1 }\n\t\tflexDirection=\"row\"\n\t\talignItems=\"center\"\n\t\tjustifyContent=\"space-between\"\n\t\tflexWrap=\"wrap\"\n\t\tsx={ { px: 2 } }\n\t>\n\t\t{ children }\n\t</Stack>\n);\n\nSettingsControl.Label = Label;\nSettingsControl.Container = Container;\n\nexport { SettingsControl };\n","import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport { Props } from '../types';\nimport getContainer from './get-container';\n\nexport const updateSettings = ( { id, props }: { id: string; 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 { 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 { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { PropValue } from '../types';\nimport getContainer from '../sync/get-container';\n\nexport const useWidgetSettings = ( { id, bind }: { id: string; bind: string } ): PropValue => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/settings' ),\n\t\t() => {\n\t\t\tconst container = getContainer( id );\n\t\t\tconst value = container?.settings?.get( bind ) ?? null;\n\n\t\t\treturn value;\n\t\t},\n\t\t[]\n\t);\n};\n","import * as React from 'react';\nimport { createContext, ReactNode, useContext } from 'react';\nimport { Element } from '../types';\n\ntype ContextValue = {\n\telement: Element;\n};\n\nconst Context = createContext< ContextValue | null >( null );\n\ntype Props = {\n\telement: Element;\n\tchildren?: ReactNode;\n};\n\nexport function ElementContext( { children, element }: Props ) {\n\treturn <Context.Provider value={ { element } }>{ children }</Context.Provider>;\n}\n\nexport function useElementContext() {\n\tconst context = useContext( Context );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useElementContext must be used within a ElementContextProvider' );\n\t}\n\n\treturn context;\n}\n","import { panel } from './panel';\nimport { injectIntoLogic } from '@elementor/editor';\nimport { shouldUseV2Panel } from './sync/should-use-v2-panel';\nimport { EditingPanelHooks } from './components/editing-panel-hooks';\nimport { __registerPanel as registerPanel } from '@elementor/editor-panels';\nimport { __privateBlockDataCommand as blockDataCommand } from '@elementor/editor-v1-adapters';\n\nexport default function init() {\n\tregisterPanel( panel );\n\tblockV1Panel();\n\n\tinjectIntoLogic( {\n\t\tid: 'editing-panel-hooks',\n\t\tcomponent: EditingPanelHooks,\n\t} );\n}\n\nconst blockV1Panel = () => {\n\tblockDataCommand( {\n\t\tcommand: 'panel/editor/open',\n\t\tcondition: shouldUseV2Panel,\n\t} );\n};\n","import getSelectedElements from './get-selected-elements';\nimport getWidgetsCache from './get-widgets-cache';\n\nexport const shouldUseV2Panel = () => {\n\tconst selectedElements = getSelectedElements();\n\tconst widgetCache = getWidgetsCache();\n\n\tif ( selectedElements.length !== 1 ) {\n\t\treturn false;\n\t}\n\n\t// Check if the selected element has atomic controls, meaning it's a V2 element.\n\treturn !! widgetCache?.[ selectedElements[ 0 ].type ]?.atomic_controls;\n};\n","import { useEffect } from 'react';\nimport { commandStartEvent, __privateListenTo as listenTo } from '@elementor/editor-v1-adapters';\nimport { usePanelActions } from '../panel';\nimport { shouldUseV2Panel } from '../sync/should-use-v2-panel';\n\nexport const useOpenEditorPanel = () => {\n\tconst { open } = usePanelActions();\n\n\tuseEffect( () => {\n\t\treturn listenTo( commandStartEvent( 'panel/editor/open' ), () => {\n\t\t\tif ( shouldUseV2Panel() ) {\n\t\t\t\topen();\n\t\t\t}\n\t\t} );\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n};\n","import { useOpenEditorPanel } from '../hooks/use-open-editor-panel';\n\nexport const EditingPanelHooks = () => {\n\tuseOpenEditorPanel();\n\n\treturn null;\n};\n","import init from './init';\n\ninit();\n"],"mappings":";AAAA,SAAS,iBAAiB,mBAAmB;;;ACA7C,YAAYA,YAAW;AACvB,SAAS,UAAU;;;ACDnB,SAAS,wBAAwB,aAAa,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gBAAgB;AAEpC,MAAK,iBAAiB,WAAW,GAAI;AACpC,WAAO;AAAA,EACR;AAGA,SAAO,CAAC,CAAE,cAAe,iBAAkB,CAAE,EAAE,IAAK,GAAG;AACxD;;;ACbA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB,qBAAqB,gBAAgB;AAI1D,IAAM,qBAAqB,MAAM;AACvC,QAAM,EAAE,KAAK,IAAI,gBAAgB;AAEjC,YAAW,MAAM;AAChB,WAAO,SAAU,kBAAmB,mBAAoB,GAAG,MAAM;AAChE,UAAK,iBAAiB,GAAI;AACzB,aAAK;AAAA,MACN;AAAA,IACD,CAAE;AAAA,EACH,GAAG,CAAC,CAAE;AACP;;;ACbO,IAAM,oBAAoB,MAAM;AACtC,qBAAmB;AAEnB,SAAO;AACR;;;AHFA,SAAS,mBAAmB,qBAAqB;AACjD,SAAS,6BAA6B,wBAAwB;AAE/C,SAAR,OAAwB;AAC9B,gBAAe,KAAM;AACrB,eAAa;AAEb,kBAAiB;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;AAEA,IAAM,eAAe,MAAM;AAC1B,mBAAkB;AAAA,IACjB,SAAS;AAAA,IACT,WAAW;AAAA,EACZ,CAAE;AACH;;;AIpBA,KAAK;","names":["React","useListenTo","commandEndEvent","useListenTo","commandEndEvent","React","React","commandEndEvent","useListenTo","useListenTo","commandEndEvent","Stack","React","createContext","useContext","Stack"]}
|
|
1
|
+
{"version":3,"sources":["../src/panel.ts","../src/components/editing-panel.tsx","../src/hooks/use-selected-elements.ts","../src/sync/get-selected-elements.ts","../src/hooks/use-element-type.ts","../src/sync/get-widgets-cache.ts","../src/components/controls/control-types/select-control.tsx","../src/contexts/control-context.tsx","../src/contexts/element-context.tsx","../src/hooks/use-widget-settings.ts","../src/sync/get-container.ts","../src/sync/update-settings.ts","../src/components/controls/control-types/text-area-control.tsx","../src/components/controls/settings-control.tsx","../src/init.ts","../src/sync/should-use-v2-panel.ts","../src/hooks/use-open-editor-panel.ts","../src/components/editing-panel-hooks.tsx","../src/index.ts"],"sourcesContent":["import { __createPanel as createPanel } from '@elementor/editor-panels';\nimport { EditingPanel } from './components/editing-panel';\n\nexport const { panel, usePanelActions, usePanelStatus } = createPanel( {\n\tid: 'editing-panel',\n\tcomponent: EditingPanel,\n} );\n","import * as React from 'react';\nimport { __ } from '@wordpress/i18n';\nimport useSelectedElements from '../hooks/use-selected-elements';\nimport useElementType from '../hooks/use-element-type';\nimport { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from '@elementor/editor-panels';\nimport { SelectControl } from './controls/control-types/select-control';\nimport { TextAreaControl } from './controls/control-types/text-area-control';\nimport { SettingsControl } from '../components/controls/settings-control';\nimport { Stack } from '@elementor/ui';\nimport { ElementContext } from '../contexts/element-context';\n\nconst controlTypes = {\n\tselect: SelectControl,\n\ttextarea: TextAreaControl,\n};\n\nexport const EditingPanel = () => {\n\tconst elements = useSelectedElements();\n\n\tconst [ selectedElement ] = elements;\n\n\tconst elementType = useElementType( selectedElement?.type );\n\n\tif ( elements.length !== 1 || ! elementType ) {\n\t\treturn null;\n\t}\n\n\t/* translators: %s: Element type title. */\n\tconst panelTitle = __( 'Edit %s', 'elementor' ).replace( '%s', elementType.title );\n\n\treturn (\n\t\t<Panel>\n\t\t\t<PanelHeader>\n\t\t\t\t<PanelHeaderTitle>{ panelTitle }</PanelHeaderTitle>\n\t\t\t</PanelHeader>\n\t\t\t<PanelBody>\n\t\t\t\t<ElementContext element={ selectedElement }>\n\t\t\t\t\t<Stack spacing={ 2 }>\n\t\t\t\t\t\t{ elementType.controls.map( ( control ) => {\n\t\t\t\t\t\t\tif ( control.type === 'control' ) {\n\t\t\t\t\t\t\t\tconst ControlComponent =\n\t\t\t\t\t\t\t\t\tcontrolTypes[ control.value.type as keyof typeof controlTypes ];\n\n\t\t\t\t\t\t\t\tif ( ! ControlComponent ) {\n\t\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<SettingsControl key={ control.value.bind } bind={ control.value.bind }>\n\t\t\t\t\t\t\t\t\t\t<SettingsControl.Label>{ control.value.label }</SettingsControl.Label>\n\t\t\t\t\t\t\t\t\t\t<ControlComponent\n\t\t\t\t\t\t\t\t\t\t\t/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\n\t\t\t\t\t\t\t\t\t\t\t{ ...( control.value.props as any ) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t</SettingsControl>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</Stack>\n\t\t\t\t</ElementContext>\n\t\t\t</PanelBody>\n\t\t</Panel>\n\t);\n};\n","import { __privateUseListenTo as useListenTo, commandEndEvent } from '@elementor/editor-v1-adapters';\nimport getSelectedElements from '../sync/get-selected-elements';\n\nexport default function useSelectedElements() {\n\treturn useListenTo(\n\t\t[ commandEndEvent( 'document/elements/select' ), commandEndEvent( 'document/elements/deselect' ) ],\n\t\t() => getSelectedElements()\n\t);\n}\n","import { ExtendedWindow } from './types';\nimport { Element } from '../types';\n\nexport default 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 default 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\treturn {\n\t\t\t\tkey: type,\n\t\t\t\tcontrols: elementType.atomic_controls,\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 default function getWidgetsCache() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow?.elementor?.widgetsCache || null;\n}\n","import * as React from 'react';\nimport { MenuItem, Select, SelectChangeEvent } from '@elementor/ui';\nimport { useControl } from '../../../contexts/control-context';\nimport { PropValue } from '../../../types';\n\ntype Props< T > = {\n\toptions: Array< { label: string; value: T; disabled?: boolean } >;\n};\n\nexport const SelectControl = < T extends PropValue >( { options }: Props< T > ) => {\n\tconst { value, setValue } = useControl< T >();\n\n\tconst handleChange = ( event: SelectChangeEvent< T > ) => {\n\t\tsetValue( event.target.value as T );\n\t};\n\n\treturn (\n\t\t<Select size=\"tiny\" value={ value ?? '' } onChange={ handleChange }>\n\t\t\t{ options.map( ( { label, ...props } ) => (\n\t\t\t\t<MenuItem key={ props.value } { ...props }>\n\t\t\t\t\t{ label }\n\t\t\t\t</MenuItem>\n\t\t\t) ) }\n\t\t</Select>\n\t);\n};\n","import * as React from 'react';\nimport { createContext, useContext } from 'react';\nimport { PropKey, PropValue } from '../types';\nimport { useElementContext } from './element-context';\nimport { useWidgetSettings } from '../hooks/use-widget-settings';\nimport { updateSettings } from '../sync/update-settings';\n\nexport type ControlContext< T extends PropValue > = null | {\n\tbind: PropKey;\n\tsetValue: ( value: T ) => void;\n\tvalue: T;\n};\n\nexport const ControlContext = createContext< ControlContext< PropValue > >( null );\n\nexport function useControl< T extends PropValue >( defaultValue?: T ) {\n\tconst controlContext = useContext< ControlContext< T > >( ControlContext as never );\n\n\tif ( ! controlContext ) {\n\t\tthrow new Error( 'useControl must be used within a ControlContext' );\n\t}\n\n\treturn { ...controlContext, value: controlContext.value ?? defaultValue };\n}\n\ntype Props = {\n\tbind: PropKey;\n\tchildren: React.ReactNode;\n};\n\nexport const ControlContextProvider = ( { bind, children }: Props ) => {\n\tconst { element } = useElementContext();\n\tconst value = useWidgetSettings( { id: element.id, bind } );\n\n\tconst setValue = ( newValue: PropValue ) => {\n\t\tupdateSettings( {\n\t\t\tid: element.id,\n\t\t\tprops: {\n\t\t\t\t[ bind ]: newValue,\n\t\t\t},\n\t\t} );\n\t};\n\n\treturn <ControlContext.Provider value={ { setValue, value, bind } }>{ children }</ControlContext.Provider>;\n};\n","import * as React from 'react';\nimport { createContext, ReactNode, useContext } from 'react';\nimport { Element } from '../types';\n\ntype ContextValue = {\n\telement: Element;\n};\n\nconst Context = createContext< ContextValue | null >( null );\n\ntype Props = {\n\telement: Element;\n\tchildren?: ReactNode;\n};\n\nexport function ElementContext( { children, element }: Props ) {\n\treturn <Context.Provider value={ { element } }>{ children }</Context.Provider>;\n}\n\nexport function useElementContext() {\n\tconst context = useContext( Context );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useElementContext must be used within a ElementContextProvider' );\n\t}\n\n\treturn context;\n}\n","import { commandEndEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\nimport { PropValue } from '../types';\nimport getContainer from '../sync/get-container';\n\nexport const useWidgetSettings = ( { id, bind }: { id: string; bind: string } ): PropValue => {\n\treturn useListenTo(\n\t\tcommandEndEvent( 'document/elements/settings' ),\n\t\t() => {\n\t\t\tconst container = getContainer( id );\n\t\t\tconst value = container?.settings?.get( bind ) ?? null;\n\n\t\t\treturn value;\n\t\t},\n\t\t[]\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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\nimport { Props } from '../types';\nimport getContainer from './get-container';\n\nexport const updateSettings = ( { id, props }: { id: string; 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 * as React from 'react';\nimport { TextareaAutosize } from '@elementor/ui';\nimport { useControl } from '../../../contexts/control-context';\n\ntype Props = {\n\tplaceholder?: string;\n};\n\nexport const TextAreaControl = ( { placeholder }: Props ) => {\n\tconst { value, setValue } = useControl< string >( '' );\n\n\tconst handleChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetValue( event.target.value );\n\t};\n\n\treturn (\n\t\t<TextareaAutosize\n\t\t\tsize=\"tiny\"\n\t\t\tminRows={ 3 }\n\t\t\tvalue={ value }\n\t\t\tonChange={ handleChange }\n\t\t\tplaceholder={ placeholder }\n\t\t/>\n\t);\n};\n","import * as React from 'react';\nimport { ControlContextProvider } from '../../contexts/control-context';\nimport { Stack, Typography } from '@elementor/ui';\nimport { PropKey } from '../../types';\n\ntype Props = {\n\tbind: PropKey;\n\tchildren: React.ReactNode;\n};\n\nconst SettingsControl = ( { children, bind }: Props ) => (\n\t<Stack\n\t\tspacing={ 1 }\n\t\tflexDirection=\"row\"\n\t\talignItems=\"center\"\n\t\tjustifyContent=\"space-between\"\n\t\tflexWrap=\"wrap\"\n\t\tsx={ { px: 2 } }\n\t>\n\t\t<ControlContextProvider bind={ bind }>{ children }</ControlContextProvider>\n\t</Stack>\n);\n\nconst Label = ( { children }: { children: React.ReactNode } ) => {\n\treturn (\n\t\t<Typography component=\"label\" variant=\"caption\">\n\t\t\t{ children }\n\t\t</Typography>\n\t);\n};\n\nSettingsControl.Label = Label;\nexport { SettingsControl };\n","import { panel } from './panel';\nimport { injectIntoLogic } from '@elementor/editor';\nimport { shouldUseV2Panel } from './sync/should-use-v2-panel';\nimport { EditingPanelHooks } from './components/editing-panel-hooks';\nimport { __registerPanel as registerPanel } from '@elementor/editor-panels';\nimport { __privateBlockDataCommand as blockDataCommand } from '@elementor/editor-v1-adapters';\n\nexport default function init() {\n\tregisterPanel( panel );\n\tblockV1Panel();\n\n\tinjectIntoLogic( {\n\t\tid: 'editing-panel-hooks',\n\t\tcomponent: EditingPanelHooks,\n\t} );\n}\n\nconst blockV1Panel = () => {\n\tblockDataCommand( {\n\t\tcommand: 'panel/editor/open',\n\t\tcondition: shouldUseV2Panel,\n\t} );\n};\n","import getSelectedElements from './get-selected-elements';\nimport getWidgetsCache from './get-widgets-cache';\n\nexport const shouldUseV2Panel = () => {\n\tconst selectedElements = getSelectedElements();\n\tconst widgetCache = getWidgetsCache();\n\n\tif ( selectedElements.length !== 1 ) {\n\t\treturn false;\n\t}\n\n\t// Check if the selected element has atomic controls, meaning it's a V2 element.\n\treturn !! widgetCache?.[ selectedElements[ 0 ].type ]?.atomic_controls;\n};\n","import { useEffect } from 'react';\nimport { commandStartEvent, __privateListenTo as listenTo } from '@elementor/editor-v1-adapters';\nimport { usePanelActions } from '../panel';\nimport { shouldUseV2Panel } from '../sync/should-use-v2-panel';\n\nexport const useOpenEditorPanel = () => {\n\tconst { open } = usePanelActions();\n\n\tuseEffect( () => {\n\t\treturn listenTo( commandStartEvent( 'panel/editor/open' ), () => {\n\t\t\tif ( shouldUseV2Panel() ) {\n\t\t\t\topen();\n\t\t\t}\n\t\t} );\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n};\n","import { useOpenEditorPanel } from '../hooks/use-open-editor-panel';\n\nexport const EditingPanelHooks = () => {\n\tuseOpenEditorPanel();\n\n\treturn null;\n};\n","import init from './init';\n\ninit();\n"],"mappings":";AAAA,SAAS,iBAAiB,mBAAmB;;;ACA7C,YAAYA,YAAW;AACvB,SAAS,UAAU;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e,IAAI,YAAa;AAAA,EACtE,IAAI;AAAA,EACJ,WAAW;AACZ,CAAE;;;AcLF,SAAS,uBAAuB;;;ACEzB,IAAM,mBAAmB,MAAM;AACrC,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,cAAc,gBAAgB;AAEpC,MAAK,iBAAiB,WAAW,GAAI;AACpC,WAAO;AAAA,EACR;AAGA,SAAO,CAAC,CAAE,cAAe,iBAAkB,CAAE,EAAE,IAAK,GAAG;AACxD;;;ACbA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB,qBAAqB,gBAAgB;AAI1D,IAAM,qBAAqB,MAAM;AACvC,QAAM,EAAE,KAAK,IAAI,gBAAgB;AAEjC,YAAW,MAAM;AAChB,WAAO,SAAU,kBAAmB,mBAAoB,GAAG,MAAM;AAChE,UAAK,iBAAiB,GAAI;AACzB,aAAK;AAAA,MACN;AAAA,IACD,CAAE;AAAA,EACH,GAAG,CAAC,CAAE;AACP;;;ACbO,IAAM,oBAAoB,MAAM;AACtC,qBAAmB;AAEnB,SAAO;AACR;;;AHFA,SAAS,mBAAmB,qBAAqB;AACjD,SAAS,6BAA6B,wBAAwB;AAE/C,SAAR,OAAwB;AAC9B,gBAAe,KAAM;AACrB,eAAa;AAEb,kBAAiB;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;AAEA,IAAM,eAAe,MAAM;AAC1B,mBAAkB;AAAA,IACjB,SAAS;AAAA,IACT,WAAW;AAAA,EACZ,CAAE;AACH;;;AIpBA,KAAK;","names":["React","useListenTo","commandEndEvent","useListenTo","commandEndEvent","React","React","createContext","useContext","commandEndEvent","useListenTo","useListenTo","commandEndEvent","createContext","useContext","React","React","Stack","Stack"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-editing-panel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "^18.3.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "7f9c4e85193d2855159a7b3e48f4d8b1f101535e"
|
|
45
45
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
3
|
import { SettingsControl } from '../settings-control';
|
|
4
|
-
import { useControl } from '
|
|
4
|
+
import { useControl } from '../../../contexts/control-context';
|
|
5
5
|
import { updateSettings } from '../../../sync/update-settings';
|
|
6
6
|
import { useWidgetSettings } from '../../../hooks/use-widget-settings';
|
|
7
|
+
import { ElementContext } from '../../../contexts/element-context';
|
|
8
|
+
import { Element } from '../../../types';
|
|
7
9
|
|
|
8
10
|
jest.mock( '../../../sync/update-settings' );
|
|
9
11
|
jest.mock( '../../../hooks/use-widget-settings' );
|
|
@@ -15,14 +17,16 @@ describe( 'SettingsControl', () => {
|
|
|
15
17
|
|
|
16
18
|
it( 'should set the initial value', () => {
|
|
17
19
|
// Arrange.
|
|
18
|
-
const
|
|
20
|
+
const element = { id: '1-heading' } as Element;
|
|
19
21
|
const bind = 'text';
|
|
20
22
|
|
|
21
23
|
// Act.
|
|
22
24
|
render(
|
|
23
|
-
<
|
|
24
|
-
<
|
|
25
|
-
|
|
25
|
+
<ElementContext element={ element }>
|
|
26
|
+
<SettingsControl bind={ bind }>
|
|
27
|
+
<MockControl />
|
|
28
|
+
</SettingsControl>
|
|
29
|
+
</ElementContext>
|
|
26
30
|
);
|
|
27
31
|
|
|
28
32
|
// Assert.
|
|
@@ -31,14 +35,16 @@ describe( 'SettingsControl', () => {
|
|
|
31
35
|
|
|
32
36
|
it( 'should pass the updated payload when input value changes', () => {
|
|
33
37
|
// Arrange.
|
|
34
|
-
const
|
|
38
|
+
const element = { id: '1-heading' } as Element;
|
|
35
39
|
const bind = 'text';
|
|
36
40
|
|
|
37
41
|
// Act.
|
|
38
42
|
render(
|
|
39
|
-
<
|
|
40
|
-
<
|
|
41
|
-
|
|
43
|
+
<ElementContext element={ element }>
|
|
44
|
+
<SettingsControl bind={ bind }>
|
|
45
|
+
<MockControl />
|
|
46
|
+
</SettingsControl>
|
|
47
|
+
</ElementContext>
|
|
42
48
|
);
|
|
43
49
|
|
|
44
50
|
const input = screen.getByRole( 'textbox', { name: bind } );
|
|
@@ -48,7 +54,7 @@ describe( 'SettingsControl', () => {
|
|
|
48
54
|
|
|
49
55
|
// Assert.
|
|
50
56
|
expect( jest.mocked( updateSettings ) ).toHaveBeenCalledWith( {
|
|
51
|
-
id:
|
|
57
|
+
id: element.id,
|
|
52
58
|
props: { [ bind ]: newValue },
|
|
53
59
|
} );
|
|
54
60
|
} );
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import { ControlContext } from '
|
|
3
|
+
import { ControlContext } from '../../../../contexts/control-context';
|
|
4
4
|
import { SelectControl } from '../select-control';
|
|
5
5
|
|
|
6
6
|
describe( 'SelectControl', () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import {
|
|
4
|
-
import { ControlContext } from '
|
|
3
|
+
import { TextAreaControl } from '../text-area-control';
|
|
4
|
+
import { ControlContext } from '../../../../contexts/control-context';
|
|
5
5
|
|
|
6
|
-
describe( '
|
|
6
|
+
describe( 'TextAreaControl', () => {
|
|
7
7
|
it( 'should pass the updated payload when input value changes', () => {
|
|
8
8
|
// Arrange.
|
|
9
9
|
const setValue = jest.fn();
|
|
@@ -11,7 +11,7 @@ describe( 'TextControl', () => {
|
|
|
11
11
|
// Act.
|
|
12
12
|
render(
|
|
13
13
|
<ControlContext.Provider value={ { setValue, value: 'Hi', bind: 'text' } }>
|
|
14
|
-
<
|
|
14
|
+
<TextAreaControl placeholder="type text here" />
|
|
15
15
|
</ControlContext.Provider>
|
|
16
16
|
);
|
|
17
17
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { MenuItem, Select, SelectChangeEvent } from '@elementor/ui';
|
|
3
|
-
import { useControl } from '
|
|
3
|
+
import { useControl } from '../../../contexts/control-context';
|
|
4
4
|
import { PropValue } from '../../../types';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
type Props< T > = {
|
|
7
7
|
options: Array< { label: string; value: T; disabled?: boolean } >;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export const SelectControl = < T extends PropValue >( { options }:
|
|
10
|
+
export const SelectControl = < T extends PropValue >( { options }: Props< T > ) => {
|
|
11
11
|
const { value, setValue } = useControl< T >();
|
|
12
12
|
|
|
13
13
|
const handleChange = ( event: SelectChangeEvent< T > ) => {
|
|
@@ -16,9 +16,9 @@ export const SelectControl = < T extends PropValue >( { options }: SelectControl
|
|
|
16
16
|
|
|
17
17
|
return (
|
|
18
18
|
<Select size="tiny" value={ value ?? '' } onChange={ handleChange }>
|
|
19
|
-
{ options.map( (
|
|
20
|
-
<MenuItem key={
|
|
21
|
-
{
|
|
19
|
+
{ options.map( ( { label, ...props } ) => (
|
|
20
|
+
<MenuItem key={ props.value } { ...props }>
|
|
21
|
+
{ label }
|
|
22
22
|
</MenuItem>
|
|
23
23
|
) ) }
|
|
24
24
|
</Select>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { TextareaAutosize } from '@elementor/ui';
|
|
3
|
-
import { useControl } from '
|
|
3
|
+
import { useControl } from '../../../contexts/control-context';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type Props = {
|
|
6
6
|
placeholder?: string;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export const
|
|
9
|
+
export const TextAreaControl = ( { placeholder }: Props ) => {
|
|
10
10
|
const { value, setValue } = useControl< string >( '' );
|
|
11
11
|
|
|
12
12
|
const handleChange = ( event: React.ChangeEvent< HTMLInputElement > ) => {
|
|
@@ -1,40 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ControlContextProvider } from '../../contexts/control-context';
|
|
3
3
|
import { Stack, Typography } from '@elementor/ui';
|
|
4
|
-
import {
|
|
5
|
-
import { useWidgetSettings } from '../../hooks/use-widget-settings';
|
|
6
|
-
import { PropKey, PropValue } from '../../types';
|
|
4
|
+
import { PropKey } from '../../types';
|
|
7
5
|
|
|
8
6
|
type Props = {
|
|
9
7
|
bind: PropKey;
|
|
10
8
|
children: React.ReactNode;
|
|
11
|
-
elementID: Element[ 'id' ];
|
|
12
9
|
};
|
|
13
10
|
|
|
14
|
-
const SettingsControl = ( {
|
|
15
|
-
const value = useWidgetSettings( { id: elementID, bind } );
|
|
16
|
-
|
|
17
|
-
const setValue = ( newValue: PropValue ) => {
|
|
18
|
-
updateSettings( {
|
|
19
|
-
id: elementID,
|
|
20
|
-
props: {
|
|
21
|
-
[ bind ]: newValue,
|
|
22
|
-
},
|
|
23
|
-
} );
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return <ControlContext.Provider value={ { setValue, value, bind } }>{ children }</ControlContext.Provider>;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const Label = ( { children }: { children: React.ReactNode } ) => {
|
|
30
|
-
return (
|
|
31
|
-
<Typography component="label" variant="caption">
|
|
32
|
-
{ children }
|
|
33
|
-
</Typography>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const Container = ( { children }: { children: React.ReactNode } ) => (
|
|
11
|
+
const SettingsControl = ( { children, bind }: Props ) => (
|
|
38
12
|
<Stack
|
|
39
13
|
spacing={ 1 }
|
|
40
14
|
flexDirection="row"
|
|
@@ -43,11 +17,17 @@ const Container = ( { children }: { children: React.ReactNode } ) => (
|
|
|
43
17
|
flexWrap="wrap"
|
|
44
18
|
sx={ { px: 2 } }
|
|
45
19
|
>
|
|
46
|
-
{ children }
|
|
20
|
+
<ControlContextProvider bind={ bind }>{ children }</ControlContextProvider>
|
|
47
21
|
</Stack>
|
|
48
22
|
);
|
|
49
23
|
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
const Label = ( { children }: { children: React.ReactNode } ) => {
|
|
25
|
+
return (
|
|
26
|
+
<Typography component="label" variant="caption">
|
|
27
|
+
{ children }
|
|
28
|
+
</Typography>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
52
31
|
|
|
32
|
+
SettingsControl.Label = Label;
|
|
53
33
|
export { SettingsControl };
|
|
@@ -4,20 +4,20 @@ import useSelectedElements from '../hooks/use-selected-elements';
|
|
|
4
4
|
import useElementType from '../hooks/use-element-type';
|
|
5
5
|
import { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from '@elementor/editor-panels';
|
|
6
6
|
import { SelectControl } from './controls/control-types/select-control';
|
|
7
|
-
import {
|
|
7
|
+
import { TextAreaControl } from './controls/control-types/text-area-control';
|
|
8
8
|
import { SettingsControl } from '../components/controls/settings-control';
|
|
9
9
|
import { Stack } from '@elementor/ui';
|
|
10
|
-
import { ElementContext } from '../contexts/
|
|
10
|
+
import { ElementContext } from '../contexts/element-context';
|
|
11
11
|
|
|
12
12
|
const controlTypes = {
|
|
13
13
|
select: SelectControl,
|
|
14
|
-
|
|
14
|
+
textarea: TextAreaControl,
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export const EditingPanel = () => {
|
|
18
18
|
const elements = useSelectedElements();
|
|
19
19
|
|
|
20
|
-
const selectedElement = elements
|
|
20
|
+
const [ selectedElement ] = elements;
|
|
21
21
|
|
|
22
22
|
const elementType = useElementType( selectedElement?.type );
|
|
23
23
|
|
|
@@ -46,16 +46,12 @@ export const EditingPanel = () => {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return (
|
|
49
|
-
<SettingsControl
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<SettingsControl.Label>{ control.value.label }</SettingsControl.Label>
|
|
56
|
-
{ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ }
|
|
57
|
-
<ControlComponent { ...( control.value.props as any ) } />
|
|
58
|
-
</SettingsControl.Container>
|
|
49
|
+
<SettingsControl key={ control.value.bind } bind={ control.value.bind }>
|
|
50
|
+
<SettingsControl.Label>{ control.value.label }</SettingsControl.Label>
|
|
51
|
+
<ControlComponent
|
|
52
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
53
|
+
{ ...( control.value.props as any ) }
|
|
54
|
+
/>
|
|
59
55
|
</SettingsControl>
|
|
60
56
|
);
|
|
61
57
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
import { PropKey, PropValue } from '../types';
|
|
4
|
+
import { useElementContext } from './element-context';
|
|
5
|
+
import { useWidgetSettings } from '../hooks/use-widget-settings';
|
|
6
|
+
import { updateSettings } from '../sync/update-settings';
|
|
7
|
+
|
|
8
|
+
export type ControlContext< T extends PropValue > = null | {
|
|
9
|
+
bind: PropKey;
|
|
10
|
+
setValue: ( value: T ) => void;
|
|
11
|
+
value: T;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const ControlContext = createContext< ControlContext< PropValue > >( null );
|
|
15
|
+
|
|
16
|
+
export function useControl< T extends PropValue >( defaultValue?: T ) {
|
|
17
|
+
const controlContext = useContext< ControlContext< T > >( ControlContext as never );
|
|
18
|
+
|
|
19
|
+
if ( ! controlContext ) {
|
|
20
|
+
throw new Error( 'useControl must be used within a ControlContext' );
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { ...controlContext, value: controlContext.value ?? defaultValue };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type Props = {
|
|
27
|
+
bind: PropKey;
|
|
28
|
+
children: React.ReactNode;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const ControlContextProvider = ( { bind, children }: Props ) => {
|
|
32
|
+
const { element } = useElementContext();
|
|
33
|
+
const value = useWidgetSettings( { id: element.id, bind } );
|
|
34
|
+
|
|
35
|
+
const setValue = ( newValue: PropValue ) => {
|
|
36
|
+
updateSettings( {
|
|
37
|
+
id: element.id,
|
|
38
|
+
props: {
|
|
39
|
+
[ bind ]: newValue,
|
|
40
|
+
},
|
|
41
|
+
} );
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return <ControlContext.Provider value={ { setValue, value, bind } }>{ children }</ControlContext.Provider>;
|
|
45
|
+
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react';
|
|
2
|
-
import { PropKey, PropValue } from '../../types';
|
|
3
|
-
|
|
4
|
-
export type ControlContext< T extends PropValue > = null | {
|
|
5
|
-
bind: PropKey;
|
|
6
|
-
setValue: ( value: T ) => void;
|
|
7
|
-
value: T;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const ControlContext = createContext< ControlContext< PropValue > >( null );
|
|
11
|
-
|
|
12
|
-
export function useControl< T extends PropValue >( defaultValue?: T ) {
|
|
13
|
-
const controlContext = useContext< ControlContext< T > >( ControlContext as never );
|
|
14
|
-
|
|
15
|
-
if ( ! controlContext ) {
|
|
16
|
-
throw new Error( 'useControl must be used within a ControlContext' );
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return { ...controlContext, value: controlContext.value ?? defaultValue };
|
|
20
|
-
}
|
|
File without changes
|
|
File without changes
|