@elementor/editor-floating-panels 4.3.0-970
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 +5 -0
- package/README.md +117 -0
- package/dist/index.d.mts +159 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.js +1108 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1062 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
- package/src/api.ts +36 -0
- package/src/components/external/floating-panel-body.tsx +15 -0
- package/src/components/external/floating-panel-footer.tsx +22 -0
- package/src/components/external/floating-panel-header.tsx +100 -0
- package/src/components/external/floating-panel.tsx +10 -0
- package/src/components/external/index.ts +4 -0
- package/src/components/internal/corner-resize-handle.tsx +69 -0
- package/src/components/internal/drag-handle.tsx +29 -0
- package/src/components/internal/host.tsx +86 -0
- package/src/components/internal/panel-window.tsx +100 -0
- package/src/components/internal/resize-handle.tsx +60 -0
- package/src/constants.ts +1 -0
- package/src/hooks/use-floating-panel-actions.ts +26 -0
- package/src/hooks/use-floating-panel-drag.ts +85 -0
- package/src/hooks/use-floating-panel-resize.ts +166 -0
- package/src/hooks/use-floating-panel-status.ts +17 -0
- package/src/hooks/use-floating-panel-z-index.ts +7 -0
- package/src/index.ts +15 -0
- package/src/init.ts +14 -0
- package/src/location.ts +3 -0
- package/src/persistence.ts +76 -0
- package/src/store/index.ts +2 -0
- package/src/store/selectors.ts +61 -0
- package/src/store/slice.ts +113 -0
- package/src/sync.ts +104 -0
- package/src/types.ts +64 -0
- package/src/utils/clamp.ts +3 -0
- package/src/utils/corner-position.ts +149 -0
- package/src/utils/direction.ts +3 -0
- package/src/utils/drag-math.ts +49 -0
- package/src/utils/resize-math.ts +107 -0
- package/src/utils/viewport-bounds.ts +7 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
FloatingPanel: () => FloatingPanel,
|
|
34
|
+
FloatingPanelBody: () => FloatingPanelBody,
|
|
35
|
+
FloatingPanelFooter: () => FloatingPanelFooter,
|
|
36
|
+
FloatingPanelHeader: () => FloatingPanelHeader,
|
|
37
|
+
createFloatingPanel: () => createFloatingPanel,
|
|
38
|
+
init: () => init,
|
|
39
|
+
registerFloatingPanel: () => registerFloatingPanel,
|
|
40
|
+
useFloatingPanelActions: () => useFloatingPanelActions,
|
|
41
|
+
useFloatingPanelStatus: () => useFloatingPanelStatus,
|
|
42
|
+
useFloatingPanelZIndex: () => useFloatingPanelZIndex
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
45
|
+
|
|
46
|
+
// src/api.ts
|
|
47
|
+
var import_store6 = require("@elementor/store");
|
|
48
|
+
|
|
49
|
+
// src/hooks/use-floating-panel-actions.ts
|
|
50
|
+
var import_store3 = require("@elementor/store");
|
|
51
|
+
|
|
52
|
+
// src/store/selectors.ts
|
|
53
|
+
var import_store = require("@elementor/store");
|
|
54
|
+
|
|
55
|
+
// src/constants.ts
|
|
56
|
+
var FLOATING_PANEL_Z_INDEX_BASE = 1e3;
|
|
57
|
+
|
|
58
|
+
// src/store/selectors.ts
|
|
59
|
+
function selectPanelState(state, id) {
|
|
60
|
+
return state.floatingPanels.byId[id];
|
|
61
|
+
}
|
|
62
|
+
function resolvePanelZIndex(state, id) {
|
|
63
|
+
return FLOATING_PANEL_Z_INDEX_BASE + (state.floatingPanels.byId[id]?.zIndex ?? 0);
|
|
64
|
+
}
|
|
65
|
+
function resolveOverlayZIndex(state, id) {
|
|
66
|
+
return resolvePanelZIndex(state, id) + 1;
|
|
67
|
+
}
|
|
68
|
+
function selectIsOpen(state, id) {
|
|
69
|
+
return state.floatingPanels.byId[id]?.isOpen ?? false;
|
|
70
|
+
}
|
|
71
|
+
function selectCorner(state, id) {
|
|
72
|
+
return state.floatingPanels.byId[id]?.corner;
|
|
73
|
+
}
|
|
74
|
+
function selectPosition(state, id) {
|
|
75
|
+
return state.floatingPanels.byId[id]?.position;
|
|
76
|
+
}
|
|
77
|
+
function selectSize(state, id) {
|
|
78
|
+
return state.floatingPanels.byId[id]?.size;
|
|
79
|
+
}
|
|
80
|
+
function selectMinSize(state, id) {
|
|
81
|
+
return state.floatingPanels.minSizeById[id];
|
|
82
|
+
}
|
|
83
|
+
function selectIsDraggable(state, id) {
|
|
84
|
+
return state.floatingPanels.isDraggableById[id] ?? false;
|
|
85
|
+
}
|
|
86
|
+
function selectIsResizable(state, id) {
|
|
87
|
+
return state.floatingPanels.isResizableById[id] ?? false;
|
|
88
|
+
}
|
|
89
|
+
function selectPanelTitle(state, id) {
|
|
90
|
+
return state.floatingPanels.titlesById[id];
|
|
91
|
+
}
|
|
92
|
+
var selectOpenPanelIds = (0, import_store.__createSelector)(
|
|
93
|
+
[(state) => state.floatingPanels.byId],
|
|
94
|
+
(byId) => Object.entries(byId).filter(([, panel]) => panel.isOpen).sort(([, a], [, b]) => a.zIndex - b.zIndex).map(([id]) => id)
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// src/store/slice.ts
|
|
98
|
+
var import_store2 = require("@elementor/store");
|
|
99
|
+
|
|
100
|
+
// src/utils/corner-position.ts
|
|
101
|
+
var DEFAULT_INSET_BLOCK_PX = 80;
|
|
102
|
+
var DEFAULT_INSET_INLINE_PX = 24;
|
|
103
|
+
var ACTIVE_INSETS = {
|
|
104
|
+
"block-start-inline-start": ["insetInlineStart", "insetBlockStart"],
|
|
105
|
+
"block-start-inline-end": ["insetInlineEnd", "insetBlockStart"],
|
|
106
|
+
"block-end-inline-start": ["insetInlineStart", "insetBlockEnd"],
|
|
107
|
+
"block-end-inline-end": ["insetInlineEnd", "insetBlockEnd"]
|
|
108
|
+
};
|
|
109
|
+
var CORNER_DEFAULTS = {
|
|
110
|
+
"block-start-inline-start": { insetInlineStart: DEFAULT_INSET_INLINE_PX, insetBlockStart: DEFAULT_INSET_BLOCK_PX },
|
|
111
|
+
"block-start-inline-end": { insetInlineEnd: DEFAULT_INSET_INLINE_PX, insetBlockStart: DEFAULT_INSET_BLOCK_PX },
|
|
112
|
+
"block-end-inline-start": { insetInlineStart: DEFAULT_INSET_INLINE_PX, insetBlockEnd: DEFAULT_INSET_BLOCK_PX },
|
|
113
|
+
"block-end-inline-end": { insetInlineEnd: DEFAULT_INSET_INLINE_PX, insetBlockEnd: DEFAULT_INSET_BLOCK_PX }
|
|
114
|
+
};
|
|
115
|
+
var EMPTY_POSITION = {
|
|
116
|
+
insetBlockStart: 0,
|
|
117
|
+
insetBlockEnd: 0,
|
|
118
|
+
insetInlineStart: 0,
|
|
119
|
+
insetInlineEnd: 0
|
|
120
|
+
};
|
|
121
|
+
function getActiveInsetKeys(corner) {
|
|
122
|
+
return ACTIVE_INSETS[corner];
|
|
123
|
+
}
|
|
124
|
+
function usesInlineStart(corner) {
|
|
125
|
+
return corner.endsWith("inline-start");
|
|
126
|
+
}
|
|
127
|
+
function usesBlockStart(corner) {
|
|
128
|
+
return corner.startsWith("block-start");
|
|
129
|
+
}
|
|
130
|
+
function buildInitialPosition(corner, overrides) {
|
|
131
|
+
const [inlineKey, blockKey] = getActiveInsetKeys(corner);
|
|
132
|
+
const defaults = CORNER_DEFAULTS[corner];
|
|
133
|
+
return {
|
|
134
|
+
...EMPTY_POSITION,
|
|
135
|
+
[inlineKey]: overrides?.[inlineKey] ?? defaults[inlineKey] ?? 0,
|
|
136
|
+
[blockKey]: overrides?.[blockKey] ?? defaults[blockKey] ?? 0
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function positionToCssInsets(corner, position) {
|
|
140
|
+
const [inlineKey, blockKey] = getActiveInsetKeys(corner);
|
|
141
|
+
return {
|
|
142
|
+
[inlineKey]: `${position[inlineKey]}px`,
|
|
143
|
+
[blockKey]: `${position[blockKey]}px`
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function toStartAnchoredPosition(corner, position, size, viewport) {
|
|
147
|
+
return {
|
|
148
|
+
insetInlineStart: usesInlineStart(corner) ? position.insetInlineStart : viewport.width - position.insetInlineEnd - size.inlineSize,
|
|
149
|
+
insetBlockStart: usesBlockStart(corner) ? position.insetBlockStart : viewport.height - position.insetBlockEnd - size.blockSize
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function fromStartAnchoredPosition(corner, startAnchored, size, viewport) {
|
|
153
|
+
if (usesInlineStart(corner) && usesBlockStart(corner)) {
|
|
154
|
+
return {
|
|
155
|
+
...EMPTY_POSITION,
|
|
156
|
+
insetInlineStart: startAnchored.insetInlineStart,
|
|
157
|
+
insetBlockStart: startAnchored.insetBlockStart
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const position = { ...EMPTY_POSITION };
|
|
161
|
+
if (usesInlineStart(corner)) {
|
|
162
|
+
position.insetInlineStart = startAnchored.insetInlineStart;
|
|
163
|
+
position.insetBlockEnd = viewport.height - startAnchored.insetBlockStart - size.blockSize;
|
|
164
|
+
} else if (usesBlockStart(corner)) {
|
|
165
|
+
position.insetInlineEnd = viewport.width - startAnchored.insetInlineStart - size.inlineSize;
|
|
166
|
+
position.insetBlockStart = startAnchored.insetBlockStart;
|
|
167
|
+
} else {
|
|
168
|
+
position.insetInlineEnd = viewport.width - startAnchored.insetInlineStart - size.inlineSize;
|
|
169
|
+
position.insetBlockEnd = viewport.height - startAnchored.insetBlockStart - size.blockSize;
|
|
170
|
+
}
|
|
171
|
+
return position;
|
|
172
|
+
}
|
|
173
|
+
function activePositionChanged(corner, before, after) {
|
|
174
|
+
const [inlineKey, blockKey] = getActiveInsetKeys(corner);
|
|
175
|
+
return before[inlineKey] !== after[inlineKey] || before[blockKey] !== after[blockKey];
|
|
176
|
+
}
|
|
177
|
+
function getDragBounds(size, viewport, sidePanelInlineSize, appBarHeight) {
|
|
178
|
+
return {
|
|
179
|
+
minInlineStart: sidePanelInlineSize,
|
|
180
|
+
maxInlineStart: viewport.width - size.inlineSize,
|
|
181
|
+
minInlineEnd: 0,
|
|
182
|
+
maxInlineEnd: viewport.width - sidePanelInlineSize - size.inlineSize,
|
|
183
|
+
minBlockStart: appBarHeight,
|
|
184
|
+
maxBlockStart: viewport.height - size.blockSize,
|
|
185
|
+
minBlockEnd: 0,
|
|
186
|
+
maxBlockEnd: viewport.height - appBarHeight - size.blockSize
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/store/slice.ts
|
|
191
|
+
var DEFAULT_CORNER = "block-start-inline-start";
|
|
192
|
+
var initialState = {
|
|
193
|
+
byId: {},
|
|
194
|
+
minSizeById: {},
|
|
195
|
+
titlesById: {},
|
|
196
|
+
isDraggableById: {},
|
|
197
|
+
isResizableById: {},
|
|
198
|
+
topZIndex: 0
|
|
199
|
+
};
|
|
200
|
+
var slice = (0, import_store2.__createSlice)({
|
|
201
|
+
name: "floatingPanels",
|
|
202
|
+
initialState,
|
|
203
|
+
reducers: {
|
|
204
|
+
register(state, action) {
|
|
205
|
+
const { id, defaults, title, isDraggable, isResizable, persisted } = action.payload;
|
|
206
|
+
state.minSizeById[id] = { inlineSize: defaults.minWidth, blockSize: defaults.minHeight };
|
|
207
|
+
state.isDraggableById[id] = isDraggable ?? false;
|
|
208
|
+
state.isResizableById[id] = isResizable ?? false;
|
|
209
|
+
if (title !== void 0) {
|
|
210
|
+
state.titlesById[id] = title;
|
|
211
|
+
}
|
|
212
|
+
if (state.byId[id]) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const corner = defaults.corner ?? DEFAULT_CORNER;
|
|
216
|
+
const canReusePersisted = persisted && persisted.corner === corner;
|
|
217
|
+
state.byId[id] = canReusePersisted ? persisted : {
|
|
218
|
+
isOpen: false,
|
|
219
|
+
corner,
|
|
220
|
+
position: buildInitialPosition(corner, defaults.initialPosition),
|
|
221
|
+
size: { inlineSize: defaults.width, blockSize: defaults.height },
|
|
222
|
+
zIndex: 0
|
|
223
|
+
};
|
|
224
|
+
if (persisted && persisted.zIndex > state.topZIndex) {
|
|
225
|
+
state.topZIndex = persisted.zIndex;
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
open(state, action) {
|
|
229
|
+
const panel = state.byId[action.payload];
|
|
230
|
+
if (panel) {
|
|
231
|
+
panel.isOpen = true;
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
close(state, action) {
|
|
235
|
+
const panel = state.byId[action.payload];
|
|
236
|
+
if (panel) {
|
|
237
|
+
panel.isOpen = false;
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
setPosition(state, action) {
|
|
241
|
+
const panel = state.byId[action.payload.id];
|
|
242
|
+
if (panel) {
|
|
243
|
+
panel.position = action.payload.position;
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
setSize(state, action) {
|
|
247
|
+
const panel = state.byId[action.payload.id];
|
|
248
|
+
if (panel) {
|
|
249
|
+
panel.size = action.payload.size;
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
bringToFront(state, action) {
|
|
253
|
+
const panel = state.byId[action.payload];
|
|
254
|
+
if (!panel) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
state.topZIndex += 1;
|
|
258
|
+
panel.zIndex = state.topZIndex;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// src/hooks/use-floating-panel-actions.ts
|
|
264
|
+
function useFloatingPanelActions(id) {
|
|
265
|
+
const dispatch2 = (0, import_store3.__useDispatch)();
|
|
266
|
+
const isOpen = (0, import_store3.__useSelector)((state) => selectIsOpen(state, id));
|
|
267
|
+
const open = () => {
|
|
268
|
+
dispatch2(slice.actions.open(id));
|
|
269
|
+
dispatch2(slice.actions.bringToFront(id));
|
|
270
|
+
};
|
|
271
|
+
const close = () => dispatch2(slice.actions.close(id));
|
|
272
|
+
return {
|
|
273
|
+
open,
|
|
274
|
+
close,
|
|
275
|
+
toggle: () => isOpen ? close() : open(),
|
|
276
|
+
setPosition: (position) => dispatch2(slice.actions.setPosition({ id, position })),
|
|
277
|
+
setSize: (size) => dispatch2(slice.actions.setSize({ id, size })),
|
|
278
|
+
focus: () => dispatch2(slice.actions.bringToFront(id))
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// src/hooks/use-floating-panel-status.ts
|
|
283
|
+
var import_store4 = require("@elementor/store");
|
|
284
|
+
var selectStatus = (0, import_store4.__createSelector)(
|
|
285
|
+
[
|
|
286
|
+
(state, id) => selectIsOpen(state, id),
|
|
287
|
+
(state, id) => selectCorner(state, id),
|
|
288
|
+
(state, id) => selectPosition(state, id),
|
|
289
|
+
(state, id) => selectSize(state, id)
|
|
290
|
+
],
|
|
291
|
+
(isOpen, corner, position, size) => ({ isOpen, corner, position, size })
|
|
292
|
+
);
|
|
293
|
+
function useFloatingPanelStatus(id) {
|
|
294
|
+
return (0, import_store4.__useSelector)((state) => selectStatus(state, id));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/location.ts
|
|
298
|
+
var import_locations = require("@elementor/locations");
|
|
299
|
+
var { inject: injectIntoFloatingPanels, useInjections: useFloatingPanelsInjections } = (0, import_locations.createLocation)();
|
|
300
|
+
|
|
301
|
+
// src/persistence.ts
|
|
302
|
+
var PERSISTENCE_STORAGE_KEY = "elementor_floating_panels_state";
|
|
303
|
+
var VALID_PANEL_CORNERS = /* @__PURE__ */ new Set([
|
|
304
|
+
"block-start-inline-start",
|
|
305
|
+
"block-start-inline-end",
|
|
306
|
+
"block-end-inline-start",
|
|
307
|
+
"block-end-inline-end"
|
|
308
|
+
]);
|
|
309
|
+
function encodePersistedState(state) {
|
|
310
|
+
return JSON.stringify(state);
|
|
311
|
+
}
|
|
312
|
+
function decodePersistedState(raw) {
|
|
313
|
+
if (!raw) {
|
|
314
|
+
return {};
|
|
315
|
+
}
|
|
316
|
+
let parsed;
|
|
317
|
+
try {
|
|
318
|
+
parsed = JSON.parse(raw);
|
|
319
|
+
} catch {
|
|
320
|
+
return {};
|
|
321
|
+
}
|
|
322
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
323
|
+
return {};
|
|
324
|
+
}
|
|
325
|
+
const result = {};
|
|
326
|
+
for (const [id, value] of Object.entries(parsed)) {
|
|
327
|
+
if (isPanelState(value)) {
|
|
328
|
+
result[id] = value;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
function isPanelState(value) {
|
|
334
|
+
if (typeof value !== "object" || value === null) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
const v = value;
|
|
338
|
+
if (typeof v.size !== "object" || v.size === null) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
if (typeof v.position !== "object" || v.position === null) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
const size = v.size;
|
|
345
|
+
const position = v.position;
|
|
346
|
+
return typeof v.isOpen === "boolean" && typeof v.zIndex === "number" && typeof v.corner === "string" && VALID_PANEL_CORNERS.has(v.corner) && typeof size.inlineSize === "number" && typeof size.blockSize === "number" && typeof position.insetInlineStart === "number" && typeof position.insetInlineEnd === "number" && typeof position.insetBlockStart === "number" && typeof position.insetBlockEnd === "number";
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/sync.ts
|
|
350
|
+
var import_store5 = require("@elementor/store");
|
|
351
|
+
var PERSIST_DEBOUNCE_MS = 250;
|
|
352
|
+
var localStorageAdapter = {
|
|
353
|
+
read: () => {
|
|
354
|
+
try {
|
|
355
|
+
return globalThis.localStorage?.getItem(PERSISTENCE_STORAGE_KEY) ?? null;
|
|
356
|
+
} catch {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
write: (value) => {
|
|
361
|
+
try {
|
|
362
|
+
globalThis.localStorage?.setItem(PERSISTENCE_STORAGE_KEY, value);
|
|
363
|
+
} catch {
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var cachedPersistedState = {};
|
|
368
|
+
var isSyncInitialized = false;
|
|
369
|
+
var persistenceTimer = null;
|
|
370
|
+
var persistenceUnsubscribe = null;
|
|
371
|
+
var persistenceSession = 0;
|
|
372
|
+
function isFloatingPanelsSyncInitialized() {
|
|
373
|
+
return isSyncInitialized;
|
|
374
|
+
}
|
|
375
|
+
function sync(storage = localStorageAdapter) {
|
|
376
|
+
isSyncInitialized = true;
|
|
377
|
+
cachedPersistedState = decodePersistedState(storage.read());
|
|
378
|
+
schedulePersistence(storage);
|
|
379
|
+
}
|
|
380
|
+
function getPersistedState(id) {
|
|
381
|
+
return cachedPersistedState[id];
|
|
382
|
+
}
|
|
383
|
+
var STORE_READY_POLL_MS = 16;
|
|
384
|
+
function clearPersistenceTimer() {
|
|
385
|
+
if (persistenceTimer) {
|
|
386
|
+
clearTimeout(persistenceTimer);
|
|
387
|
+
persistenceTimer = null;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function schedulePersistence(storage) {
|
|
391
|
+
clearPersistenceTimer();
|
|
392
|
+
persistenceUnsubscribe?.();
|
|
393
|
+
persistenceUnsubscribe = null;
|
|
394
|
+
const session = ++persistenceSession;
|
|
395
|
+
const subscribe = () => {
|
|
396
|
+
if (session !== persistenceSession) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
persistenceUnsubscribe = (0, import_store5.__subscribeWithSelector)(
|
|
400
|
+
(state) => state.floatingPanels.byId,
|
|
401
|
+
(byId) => {
|
|
402
|
+
clearPersistenceTimer();
|
|
403
|
+
persistenceTimer = setTimeout(() => {
|
|
404
|
+
if (session !== persistenceSession) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
cachedPersistedState = { ...cachedPersistedState, ...byId };
|
|
408
|
+
storage.write(encodePersistedState(cachedPersistedState));
|
|
409
|
+
}, PERSIST_DEBOUNCE_MS);
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
};
|
|
413
|
+
const waitForStore = () => {
|
|
414
|
+
if (session !== persistenceSession) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if ((0, import_store5.__getStore)()) {
|
|
418
|
+
subscribe();
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
setTimeout(waitForStore, STORE_READY_POLL_MS);
|
|
422
|
+
};
|
|
423
|
+
waitForStore();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/api.ts
|
|
427
|
+
function createFloatingPanel(declaration) {
|
|
428
|
+
const persisted = isFloatingPanelsSyncInitialized() ? getPersistedState(declaration.id) : decodePersistedState(localStorageAdapter.read())[declaration.id];
|
|
429
|
+
(0, import_store6.__dispatch)(
|
|
430
|
+
slice.actions.register({
|
|
431
|
+
id: declaration.id,
|
|
432
|
+
title: declaration.title,
|
|
433
|
+
isDraggable: declaration.isDraggable,
|
|
434
|
+
isResizable: declaration.isResizable,
|
|
435
|
+
defaults: declaration.defaults,
|
|
436
|
+
persisted
|
|
437
|
+
})
|
|
438
|
+
);
|
|
439
|
+
return {
|
|
440
|
+
panel: declaration,
|
|
441
|
+
useFloatingPanelStatus: () => useFloatingPanelStatus(declaration.id),
|
|
442
|
+
useFloatingPanelActions: () => useFloatingPanelActions(declaration.id)
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function registerFloatingPanel(declaration) {
|
|
446
|
+
injectIntoFloatingPanels({ id: declaration.id, component: declaration.component });
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/components/external/floating-panel.tsx
|
|
450
|
+
var React = __toESM(require("react"));
|
|
451
|
+
function FloatingPanel({ children }) {
|
|
452
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// src/components/external/floating-panel-body.tsx
|
|
456
|
+
var React2 = __toESM(require("react"));
|
|
457
|
+
var import_ui = require("@elementor/ui");
|
|
458
|
+
function FloatingPanelBody(props) {
|
|
459
|
+
return /* @__PURE__ */ React2.createElement(
|
|
460
|
+
import_ui.Box,
|
|
461
|
+
{
|
|
462
|
+
...props,
|
|
463
|
+
sx: {
|
|
464
|
+
flex: 1,
|
|
465
|
+
overflowY: "auto",
|
|
466
|
+
...props.sx ?? {}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/components/external/floating-panel-footer.tsx
|
|
473
|
+
var React3 = __toESM(require("react"));
|
|
474
|
+
var import_ui2 = require("@elementor/ui");
|
|
475
|
+
function FloatingPanelFooter({ children, sx, ...props }) {
|
|
476
|
+
return /* @__PURE__ */ React3.createElement(
|
|
477
|
+
import_ui2.Box,
|
|
478
|
+
{
|
|
479
|
+
...props,
|
|
480
|
+
sx: {
|
|
481
|
+
px: 2,
|
|
482
|
+
py: 1.5,
|
|
483
|
+
borderTop: 1,
|
|
484
|
+
borderColor: "var(--e-a-border-color)",
|
|
485
|
+
display: "flex",
|
|
486
|
+
alignItems: "center",
|
|
487
|
+
gap: 1,
|
|
488
|
+
...sx ?? {}
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
children
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/components/external/floating-panel-header.tsx
|
|
496
|
+
var React5 = __toESM(require("react"));
|
|
497
|
+
var import_icons = require("@elementor/icons");
|
|
498
|
+
var import_store8 = require("@elementor/store");
|
|
499
|
+
var import_ui4 = require("@elementor/ui");
|
|
500
|
+
var import_i18n2 = require("@wordpress/i18n");
|
|
501
|
+
|
|
502
|
+
// src/hooks/use-floating-panel-z-index.ts
|
|
503
|
+
var import_store7 = require("@elementor/store");
|
|
504
|
+
function useFloatingPanelZIndex(panelId) {
|
|
505
|
+
return (0, import_store7.__useSelector)((state) => resolveOverlayZIndex(state, panelId));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// src/components/internal/drag-handle.tsx
|
|
509
|
+
var React4 = __toESM(require("react"));
|
|
510
|
+
var import_ui3 = require("@elementor/ui");
|
|
511
|
+
var import_i18n = require("@wordpress/i18n");
|
|
512
|
+
|
|
513
|
+
// src/hooks/use-floating-panel-drag.ts
|
|
514
|
+
var import_react = require("react");
|
|
515
|
+
|
|
516
|
+
// src/utils/direction.ts
|
|
517
|
+
function isRtl() {
|
|
518
|
+
return (document?.documentElement?.dir ?? "").toLowerCase() === "rtl";
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/utils/clamp.ts
|
|
522
|
+
function clamp(value, min, max) {
|
|
523
|
+
return Math.min(Math.max(min, value), Math.max(min, max));
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// src/utils/drag-math.ts
|
|
527
|
+
function physicalToLogicalDelta(delta, isRtl2) {
|
|
528
|
+
return {
|
|
529
|
+
inlineDelta: isRtl2 ? -delta.dx : delta.dx,
|
|
530
|
+
blockDelta: delta.dy
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
function applyDragDelta(corner, position, delta, bounds) {
|
|
534
|
+
const [inlineKey, blockKey] = getActiveInsetKeys(corner);
|
|
535
|
+
const inlineDelta = usesInlineStart(corner) ? delta.inlineDelta : -delta.inlineDelta;
|
|
536
|
+
const blockDelta = usesBlockStart(corner) ? delta.blockDelta : -delta.blockDelta;
|
|
537
|
+
const inlineBounds = inlineKey === "insetInlineStart" ? { min: bounds.minInlineStart, max: bounds.maxInlineStart } : { min: bounds.minInlineEnd, max: bounds.maxInlineEnd };
|
|
538
|
+
const blockBounds = blockKey === "insetBlockStart" ? { min: bounds.minBlockStart, max: bounds.maxBlockStart } : { min: bounds.minBlockEnd, max: bounds.maxBlockEnd };
|
|
539
|
+
return {
|
|
540
|
+
...position,
|
|
541
|
+
[inlineKey]: clamp(position[inlineKey] + inlineDelta, inlineBounds.min, inlineBounds.max),
|
|
542
|
+
[blockKey]: clamp(position[blockKey] + blockDelta, blockBounds.min, blockBounds.max)
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/utils/viewport-bounds.ts
|
|
547
|
+
var APP_BAR_HEIGHT_PX = 48;
|
|
548
|
+
var SIDE_PANEL_SELECTOR = "#elementor-panel";
|
|
549
|
+
function getSidePanelInlineSize() {
|
|
550
|
+
return document.querySelector(SIDE_PANEL_SELECTOR)?.getBoundingClientRect().width ?? 0;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/hooks/use-floating-panel-drag.ts
|
|
554
|
+
function useFloatingPanelDrag(id) {
|
|
555
|
+
const sessionRef = (0, import_react.useRef)(null);
|
|
556
|
+
const { corner, position, size } = useFloatingPanelStatus(id);
|
|
557
|
+
const { setPosition } = useFloatingPanelActions(id);
|
|
558
|
+
const onPointerDown = (0, import_react.useCallback)(
|
|
559
|
+
(event) => {
|
|
560
|
+
if (!corner || !position || !size) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
564
|
+
sessionRef.current = {
|
|
565
|
+
pointerId: event.pointerId,
|
|
566
|
+
startClientX: event.clientX,
|
|
567
|
+
startClientY: event.clientY,
|
|
568
|
+
startPosition: position,
|
|
569
|
+
lastDispatchedPosition: position,
|
|
570
|
+
bounds: getDragBounds(
|
|
571
|
+
size,
|
|
572
|
+
{ width: window.innerWidth, height: window.innerHeight },
|
|
573
|
+
getSidePanelInlineSize(),
|
|
574
|
+
APP_BAR_HEIGHT_PX
|
|
575
|
+
),
|
|
576
|
+
corner,
|
|
577
|
+
isRtl: isRtl()
|
|
578
|
+
};
|
|
579
|
+
},
|
|
580
|
+
[corner, position, size]
|
|
581
|
+
);
|
|
582
|
+
const onPointerMove = (0, import_react.useCallback)(
|
|
583
|
+
(event) => {
|
|
584
|
+
const session = sessionRef.current;
|
|
585
|
+
if (!session || session.pointerId !== event.pointerId) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const physical = { dx: event.clientX - session.startClientX, dy: event.clientY - session.startClientY };
|
|
589
|
+
const logical = physicalToLogicalDelta(physical, session.isRtl);
|
|
590
|
+
const nextPosition = applyDragDelta(session.corner, session.startPosition, logical, session.bounds);
|
|
591
|
+
if (activePositionChanged(session.corner, session.lastDispatchedPosition, nextPosition)) {
|
|
592
|
+
setPosition(nextPosition);
|
|
593
|
+
session.lastDispatchedPosition = nextPosition;
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
[setPosition]
|
|
597
|
+
);
|
|
598
|
+
const clearSession = (0, import_react.useCallback)((event) => {
|
|
599
|
+
const session = sessionRef.current;
|
|
600
|
+
if (!session || session.pointerId !== event.pointerId) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
sessionRef.current = null;
|
|
604
|
+
}, []);
|
|
605
|
+
return { onPointerDown, onPointerMove, onPointerUp: clearSession, onPointerCancel: clearSession };
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// src/components/internal/drag-handle.tsx
|
|
609
|
+
function DragHandle({ panelId, children }) {
|
|
610
|
+
const { onPointerDown, onPointerMove, onPointerUp, onPointerCancel } = useFloatingPanelDrag(panelId);
|
|
611
|
+
return /* @__PURE__ */ React4.createElement(
|
|
612
|
+
import_ui3.Box,
|
|
613
|
+
{
|
|
614
|
+
role: "button",
|
|
615
|
+
"aria-label": (0, import_i18n.__)("Drag to reposition", "elementor"),
|
|
616
|
+
onPointerDown,
|
|
617
|
+
onPointerMove,
|
|
618
|
+
onPointerUp,
|
|
619
|
+
onPointerCancel,
|
|
620
|
+
sx: { cursor: "move", touchAction: "none", flex: 1 }
|
|
621
|
+
},
|
|
622
|
+
children
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// src/components/external/floating-panel-header.tsx
|
|
627
|
+
function HeaderAction({
|
|
628
|
+
icon: Icon,
|
|
629
|
+
label,
|
|
630
|
+
onClick,
|
|
631
|
+
panelZIndex,
|
|
632
|
+
disabled = false
|
|
633
|
+
}) {
|
|
634
|
+
return /* @__PURE__ */ React5.createElement(
|
|
635
|
+
import_ui4.Tooltip,
|
|
636
|
+
{
|
|
637
|
+
title: label,
|
|
638
|
+
placement: "top",
|
|
639
|
+
PopperProps: {
|
|
640
|
+
sx: { zIndex: panelZIndex }
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
/* @__PURE__ */ React5.createElement(import_ui4.Box, { component: "span", "aria-label": void 0 }, /* @__PURE__ */ React5.createElement(
|
|
644
|
+
import_ui4.IconButton,
|
|
645
|
+
{
|
|
646
|
+
size: "small",
|
|
647
|
+
color: "inherit",
|
|
648
|
+
"aria-label": label,
|
|
649
|
+
disabled,
|
|
650
|
+
onClick: disabled ? void 0 : onClick,
|
|
651
|
+
sx: { borderRadius: 0, p: 1 }
|
|
652
|
+
},
|
|
653
|
+
/* @__PURE__ */ React5.createElement(Icon, null)
|
|
654
|
+
))
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
function FloatingPanelHeader({ panelId, title, icon: Icon, actions }) {
|
|
658
|
+
const { close } = useFloatingPanelActions(panelId);
|
|
659
|
+
const isDraggable = (0, import_store8.__useSelector)((state) => selectIsDraggable(state, panelId));
|
|
660
|
+
const hasActions = Boolean(actions?.length);
|
|
661
|
+
const panelZIndex = useFloatingPanelZIndex(panelId);
|
|
662
|
+
const titleContent = /* @__PURE__ */ React5.createElement(import_ui4.Box, { sx: { display: "flex", alignItems: "center", justifyContent: "center", gap: 1, height: "100%" } }, Icon ? /* @__PURE__ */ React5.createElement(Icon, null) : null, /* @__PURE__ */ React5.createElement(import_ui4.Typography, { component: "h2", sx: { textAlign: "center", fontSize: "13px", fontWeight: 400 } }, title));
|
|
663
|
+
return /* @__PURE__ */ React5.createElement(
|
|
664
|
+
import_ui4.Box,
|
|
665
|
+
{
|
|
666
|
+
sx: {
|
|
667
|
+
display: "flex",
|
|
668
|
+
alignItems: "stretch",
|
|
669
|
+
borderBottom: 1,
|
|
670
|
+
borderColor: "var(--e-a-border-color)",
|
|
671
|
+
overflow: "visible"
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
hasActions ? /* @__PURE__ */ React5.createElement(import_ui4.Stack, { direction: "row", alignItems: "center", sx: { flexShrink: 0, overflow: "visible" } }, actions?.map((action) => /* @__PURE__ */ React5.createElement(HeaderAction, { key: action.id, panelZIndex, ...action }))) : null,
|
|
675
|
+
isDraggable ? /* @__PURE__ */ React5.createElement(DragHandle, { panelId }, titleContent) : /* @__PURE__ */ React5.createElement(import_ui4.Box, { sx: { flex: 1 } }, titleContent),
|
|
676
|
+
/* @__PURE__ */ React5.createElement(
|
|
677
|
+
import_ui4.IconButton,
|
|
678
|
+
{
|
|
679
|
+
size: "small",
|
|
680
|
+
color: "inherit",
|
|
681
|
+
"aria-label": (0, import_i18n2.__)("Close panel", "elementor"),
|
|
682
|
+
onClick: close,
|
|
683
|
+
sx: { borderRadius: 0, p: 1 }
|
|
684
|
+
},
|
|
685
|
+
/* @__PURE__ */ React5.createElement(import_icons.XIcon, { fontSize: "small" })
|
|
686
|
+
)
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// src/init.ts
|
|
691
|
+
var import_editor = require("@elementor/editor");
|
|
692
|
+
var import_store12 = require("@elementor/store");
|
|
693
|
+
|
|
694
|
+
// src/components/internal/host.tsx
|
|
695
|
+
var React9 = __toESM(require("react"));
|
|
696
|
+
var import_react3 = require("react");
|
|
697
|
+
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
698
|
+
var import_store11 = require("@elementor/store");
|
|
699
|
+
|
|
700
|
+
// src/components/internal/panel-window.tsx
|
|
701
|
+
var React8 = __toESM(require("react"));
|
|
702
|
+
var import_editor_ui = require("@elementor/editor-ui");
|
|
703
|
+
var import_store10 = require("@elementor/store");
|
|
704
|
+
var import_ui7 = require("@elementor/ui");
|
|
705
|
+
|
|
706
|
+
// src/hooks/use-floating-panel-resize.ts
|
|
707
|
+
var import_react2 = require("react");
|
|
708
|
+
var import_store9 = require("@elementor/store");
|
|
709
|
+
|
|
710
|
+
// src/utils/resize-math.ts
|
|
711
|
+
function applyInlineEndResize(size, inlineDelta, bounds) {
|
|
712
|
+
return {
|
|
713
|
+
inlineSize: clamp(size.inlineSize + inlineDelta, bounds.minInlineSize, bounds.maxInlineSize),
|
|
714
|
+
blockSize: size.blockSize
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
function applyBlockEndResize(size, blockDelta, bounds) {
|
|
718
|
+
return {
|
|
719
|
+
inlineSize: size.inlineSize,
|
|
720
|
+
blockSize: clamp(size.blockSize + blockDelta, bounds.minBlockSize, bounds.maxBlockSize)
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
function applyInlineStartResize(position, size, inlineDelta, bounds) {
|
|
724
|
+
const anchorInlineEnd = position.insetInlineStart + size.inlineSize;
|
|
725
|
+
const lowBound = Math.max(bounds.minInlineStart, anchorInlineEnd - bounds.maxInlineSize);
|
|
726
|
+
const highBound = anchorInlineEnd - bounds.minInlineSize;
|
|
727
|
+
const nextInlineStart = clamp(position.insetInlineStart + inlineDelta, lowBound, highBound);
|
|
728
|
+
return {
|
|
729
|
+
position: { ...position, insetInlineStart: nextInlineStart },
|
|
730
|
+
size: { ...size, inlineSize: anchorInlineEnd - nextInlineStart }
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function applyBlockStartResize(position, size, blockDelta, bounds) {
|
|
734
|
+
const anchorBlockEnd = position.insetBlockStart + size.blockSize;
|
|
735
|
+
const lowBound = Math.max(bounds.minBlockStart, anchorBlockEnd - bounds.maxBlockSize);
|
|
736
|
+
const highBound = anchorBlockEnd - bounds.minBlockSize;
|
|
737
|
+
const nextBlockStart = clamp(position.insetBlockStart + blockDelta, lowBound, highBound);
|
|
738
|
+
return {
|
|
739
|
+
position: { ...position, insetBlockStart: nextBlockStart },
|
|
740
|
+
size: { ...size, blockSize: anchorBlockEnd - nextBlockStart }
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function applyResize(direction, position, size, inlineDelta, blockDelta, bounds) {
|
|
744
|
+
if (direction === "inline-end") {
|
|
745
|
+
return { position, size: applyInlineEndResize(size, inlineDelta, bounds) };
|
|
746
|
+
}
|
|
747
|
+
if (direction === "block-end") {
|
|
748
|
+
return { position, size: applyBlockEndResize(size, blockDelta, bounds) };
|
|
749
|
+
}
|
|
750
|
+
if (direction === "inline-start") {
|
|
751
|
+
return applyInlineStartResize(position, size, inlineDelta, bounds);
|
|
752
|
+
}
|
|
753
|
+
if (direction === "block-start") {
|
|
754
|
+
return applyBlockStartResize(position, size, blockDelta, bounds);
|
|
755
|
+
}
|
|
756
|
+
let next = { position, size };
|
|
757
|
+
if (direction.includes("inline-start")) {
|
|
758
|
+
next = applyInlineStartResize(next.position, next.size, inlineDelta, bounds);
|
|
759
|
+
} else {
|
|
760
|
+
next = { position: next.position, size: applyInlineEndResize(next.size, inlineDelta, bounds) };
|
|
761
|
+
}
|
|
762
|
+
if (direction.includes("block-start")) {
|
|
763
|
+
next = applyBlockStartResize(next.position, next.size, blockDelta, bounds);
|
|
764
|
+
} else {
|
|
765
|
+
next = { position: next.position, size: applyBlockEndResize(next.size, blockDelta, bounds) };
|
|
766
|
+
}
|
|
767
|
+
return next;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// src/hooks/use-floating-panel-resize.ts
|
|
771
|
+
function getResizeBounds(corner, position, currentSize, minSize) {
|
|
772
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
773
|
+
const startAnchored = toStartAnchoredPosition(corner, position, currentSize, viewport);
|
|
774
|
+
return {
|
|
775
|
+
minBlockSize: minSize.blockSize,
|
|
776
|
+
maxBlockSize: window.innerHeight - startAnchored.insetBlockStart,
|
|
777
|
+
minInlineSize: minSize.inlineSize,
|
|
778
|
+
maxInlineSize: window.innerWidth - startAnchored.insetInlineStart,
|
|
779
|
+
minInlineStart: getSidePanelInlineSize(),
|
|
780
|
+
minBlockStart: APP_BAR_HEIGHT_PX
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
function usePanelResizeInteraction(id) {
|
|
784
|
+
const sessionRef = (0, import_react2.useRef)(null);
|
|
785
|
+
const { corner, position, size } = useFloatingPanelStatus(id);
|
|
786
|
+
const minSize = (0, import_store9.__useSelector)((state) => selectMinSize(state, id));
|
|
787
|
+
const { setPosition, setSize } = useFloatingPanelActions(id);
|
|
788
|
+
const onPointerDown = (0, import_react2.useCallback)(
|
|
789
|
+
(direction, event) => {
|
|
790
|
+
if (!corner || !position || !size || !minSize) {
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
794
|
+
sessionRef.current = {
|
|
795
|
+
pointerId: event.pointerId,
|
|
796
|
+
direction,
|
|
797
|
+
startClientX: event.clientX,
|
|
798
|
+
startClientY: event.clientY,
|
|
799
|
+
startPosition: position,
|
|
800
|
+
startSize: size,
|
|
801
|
+
lastPosition: position,
|
|
802
|
+
lastSize: size,
|
|
803
|
+
bounds: getResizeBounds(corner, position, size, minSize),
|
|
804
|
+
corner,
|
|
805
|
+
isRtl: isRtl()
|
|
806
|
+
};
|
|
807
|
+
},
|
|
808
|
+
[corner, position, size, minSize]
|
|
809
|
+
);
|
|
810
|
+
const onPointerMove = (0, import_react2.useCallback)(
|
|
811
|
+
(event) => {
|
|
812
|
+
const session = sessionRef.current;
|
|
813
|
+
if (!session || session.pointerId !== event.pointerId) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
const physical = { dx: event.clientX - session.startClientX, dy: event.clientY - session.startClientY };
|
|
817
|
+
const logical = physicalToLogicalDelta(physical, session.isRtl);
|
|
818
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
819
|
+
const startAnchoredPosition = toStartAnchoredPosition(
|
|
820
|
+
session.corner,
|
|
821
|
+
session.startPosition,
|
|
822
|
+
session.startSize,
|
|
823
|
+
viewport
|
|
824
|
+
);
|
|
825
|
+
const resizeInput = { ...session.startPosition, ...startAnchoredPosition };
|
|
826
|
+
const next = applyResize(
|
|
827
|
+
session.direction,
|
|
828
|
+
resizeInput,
|
|
829
|
+
session.startSize,
|
|
830
|
+
logical.inlineDelta,
|
|
831
|
+
logical.blockDelta,
|
|
832
|
+
session.bounds
|
|
833
|
+
);
|
|
834
|
+
const nextPosition = fromStartAnchoredPosition(
|
|
835
|
+
session.corner,
|
|
836
|
+
{
|
|
837
|
+
insetBlockStart: next.position.insetBlockStart,
|
|
838
|
+
insetInlineStart: next.position.insetInlineStart
|
|
839
|
+
},
|
|
840
|
+
next.size,
|
|
841
|
+
viewport
|
|
842
|
+
);
|
|
843
|
+
if (activePositionChanged(session.corner, session.lastPosition, nextPosition)) {
|
|
844
|
+
setPosition(nextPosition);
|
|
845
|
+
session.lastPosition = nextPosition;
|
|
846
|
+
}
|
|
847
|
+
const sizeChanged = next.size.inlineSize !== session.lastSize.inlineSize || next.size.blockSize !== session.lastSize.blockSize;
|
|
848
|
+
if (sizeChanged) {
|
|
849
|
+
setSize(next.size);
|
|
850
|
+
session.lastSize = next.size;
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
[setPosition, setSize]
|
|
854
|
+
);
|
|
855
|
+
const clearSession = (0, import_react2.useCallback)((event) => {
|
|
856
|
+
const session = sessionRef.current;
|
|
857
|
+
if (!session || session.pointerId !== event.pointerId) {
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
sessionRef.current = null;
|
|
861
|
+
}, []);
|
|
862
|
+
const getResizeHandleProps = (0, import_react2.useCallback)(
|
|
863
|
+
(direction) => {
|
|
864
|
+
return {
|
|
865
|
+
onPointerDown: (event) => onPointerDown(direction, event),
|
|
866
|
+
onPointerMove,
|
|
867
|
+
onPointerUp: clearSession,
|
|
868
|
+
onPointerCancel: clearSession
|
|
869
|
+
};
|
|
870
|
+
},
|
|
871
|
+
[onPointerDown, onPointerMove, clearSession]
|
|
872
|
+
);
|
|
873
|
+
return { getResizeHandleProps };
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// src/components/internal/corner-resize-handle.tsx
|
|
877
|
+
var React6 = __toESM(require("react"));
|
|
878
|
+
var import_ui5 = require("@elementor/ui");
|
|
879
|
+
var HANDLE_SIZE_PX = 8;
|
|
880
|
+
var CORNER_POSITION = {
|
|
881
|
+
"block-start-inline-start": { insetBlockStart: 0, insetInlineStart: 0 },
|
|
882
|
+
"block-start-inline-end": { insetBlockStart: 0, insetInlineEnd: 0 },
|
|
883
|
+
"block-end-inline-start": { insetBlockEnd: 0, insetInlineStart: 0 },
|
|
884
|
+
"block-end-inline-end": { insetBlockEnd: 0, insetInlineEnd: 0 }
|
|
885
|
+
};
|
|
886
|
+
var LTR_CURSORS = {
|
|
887
|
+
"block-start-inline-start": "nwse-resize",
|
|
888
|
+
"block-start-inline-end": "nesw-resize",
|
|
889
|
+
"block-end-inline-start": "nesw-resize",
|
|
890
|
+
"block-end-inline-end": "nwse-resize"
|
|
891
|
+
};
|
|
892
|
+
var RTL_CURSORS = {
|
|
893
|
+
"block-start-inline-start": "nesw-resize",
|
|
894
|
+
"block-start-inline-end": "nwse-resize",
|
|
895
|
+
"block-end-inline-start": "nwse-resize",
|
|
896
|
+
"block-end-inline-end": "nesw-resize"
|
|
897
|
+
};
|
|
898
|
+
function CornerResizeHandle({
|
|
899
|
+
corner,
|
|
900
|
+
onPointerDown,
|
|
901
|
+
onPointerMove,
|
|
902
|
+
onPointerUp,
|
|
903
|
+
onPointerCancel
|
|
904
|
+
}) {
|
|
905
|
+
const cursor = isRtl() ? RTL_CURSORS[corner] : LTR_CURSORS[corner];
|
|
906
|
+
return /* @__PURE__ */ React6.createElement(
|
|
907
|
+
import_ui5.Box,
|
|
908
|
+
{
|
|
909
|
+
"data-resize-corner": corner,
|
|
910
|
+
"aria-hidden": "true",
|
|
911
|
+
onPointerDown,
|
|
912
|
+
onPointerMove,
|
|
913
|
+
onPointerUp,
|
|
914
|
+
onPointerCancel,
|
|
915
|
+
sx: {
|
|
916
|
+
position: "absolute",
|
|
917
|
+
touchAction: "none",
|
|
918
|
+
zIndex: 2,
|
|
919
|
+
inlineSize: `${HANDLE_SIZE_PX}px`,
|
|
920
|
+
blockSize: `${HANDLE_SIZE_PX}px`,
|
|
921
|
+
cursor,
|
|
922
|
+
...CORNER_POSITION[corner]
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/components/internal/resize-handle.tsx
|
|
929
|
+
var React7 = __toESM(require("react"));
|
|
930
|
+
var import_ui6 = require("@elementor/ui");
|
|
931
|
+
var HANDLE_THICKNESS_PX = 8;
|
|
932
|
+
var EDGE_SX = {
|
|
933
|
+
"inline-start": {
|
|
934
|
+
insetBlockStart: 0,
|
|
935
|
+
insetBlockEnd: 0,
|
|
936
|
+
insetInlineStart: 0,
|
|
937
|
+
inlineSize: `${HANDLE_THICKNESS_PX}px`,
|
|
938
|
+
cursor: "ew-resize"
|
|
939
|
+
},
|
|
940
|
+
"inline-end": {
|
|
941
|
+
insetBlockStart: 0,
|
|
942
|
+
insetBlockEnd: 0,
|
|
943
|
+
insetInlineEnd: 0,
|
|
944
|
+
inlineSize: `${HANDLE_THICKNESS_PX}px`,
|
|
945
|
+
cursor: "ew-resize"
|
|
946
|
+
},
|
|
947
|
+
"block-start": {
|
|
948
|
+
insetInlineStart: 0,
|
|
949
|
+
insetInlineEnd: 0,
|
|
950
|
+
insetBlockStart: 0,
|
|
951
|
+
blockSize: `${HANDLE_THICKNESS_PX}px`,
|
|
952
|
+
cursor: "ns-resize"
|
|
953
|
+
},
|
|
954
|
+
"block-end": {
|
|
955
|
+
insetInlineStart: 0,
|
|
956
|
+
insetInlineEnd: 0,
|
|
957
|
+
insetBlockEnd: 0,
|
|
958
|
+
blockSize: `${HANDLE_THICKNESS_PX}px`,
|
|
959
|
+
cursor: "ns-resize"
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
function ResizeHandle({ edge, onPointerDown, onPointerMove, onPointerUp, onPointerCancel }) {
|
|
963
|
+
return /* @__PURE__ */ React7.createElement(
|
|
964
|
+
import_ui6.Box,
|
|
965
|
+
{
|
|
966
|
+
"data-resize-edge": edge,
|
|
967
|
+
"aria-hidden": "true",
|
|
968
|
+
onPointerDown,
|
|
969
|
+
onPointerMove,
|
|
970
|
+
onPointerUp,
|
|
971
|
+
onPointerCancel,
|
|
972
|
+
sx: { position: "absolute", touchAction: "none", zIndex: 1, ...EDGE_SX[edge] }
|
|
973
|
+
}
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
// src/components/internal/panel-window.tsx
|
|
978
|
+
var FADE_ENTER_MS = 225;
|
|
979
|
+
var FADE_EXIT_MS = 195;
|
|
980
|
+
var RESIZE_EDGES = ["inline-start", "inline-end", "block-start", "block-end"];
|
|
981
|
+
var RESIZE_CORNERS = [
|
|
982
|
+
"block-start-inline-start",
|
|
983
|
+
"block-start-inline-end",
|
|
984
|
+
"block-end-inline-start",
|
|
985
|
+
"block-end-inline-end"
|
|
986
|
+
];
|
|
987
|
+
function PanelResizeHandles({ panelId }) {
|
|
988
|
+
const { getResizeHandleProps } = usePanelResizeInteraction(panelId);
|
|
989
|
+
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, RESIZE_EDGES.map((edge) => /* @__PURE__ */ React8.createElement(ResizeHandle, { key: edge, edge, ...getResizeHandleProps(edge) })), RESIZE_CORNERS.map((corner) => /* @__PURE__ */ React8.createElement(CornerResizeHandle, { key: corner, corner, ...getResizeHandleProps(corner) })));
|
|
990
|
+
}
|
|
991
|
+
function PanelWindow({
|
|
992
|
+
panelId,
|
|
993
|
+
corner,
|
|
994
|
+
position,
|
|
995
|
+
size,
|
|
996
|
+
title,
|
|
997
|
+
zIndex,
|
|
998
|
+
visible,
|
|
999
|
+
onFocus,
|
|
1000
|
+
children
|
|
1001
|
+
}) {
|
|
1002
|
+
const isResizable = (0, import_store10.__useSelector)((state) => selectIsResizable(state, panelId));
|
|
1003
|
+
return /* @__PURE__ */ React8.createElement(import_ui7.Fade, { in: visible, timeout: { enter: FADE_ENTER_MS, exit: FADE_EXIT_MS } }, /* @__PURE__ */ React8.createElement(
|
|
1004
|
+
import_ui7.Paper,
|
|
1005
|
+
{
|
|
1006
|
+
component: "aside",
|
|
1007
|
+
"data-floating-panel": panelId,
|
|
1008
|
+
elevation: 0,
|
|
1009
|
+
"aria-label": title || panelId,
|
|
1010
|
+
"aria-hidden": !visible,
|
|
1011
|
+
inert: !visible ? "" : void 0,
|
|
1012
|
+
onMouseDown: onFocus,
|
|
1013
|
+
onFocusCapture: onFocus,
|
|
1014
|
+
sx: {
|
|
1015
|
+
position: "fixed",
|
|
1016
|
+
...positionToCssInsets(corner, position),
|
|
1017
|
+
inlineSize: `${size.inlineSize}px`,
|
|
1018
|
+
blockSize: `${size.blockSize}px`,
|
|
1019
|
+
zIndex,
|
|
1020
|
+
display: "flex",
|
|
1021
|
+
flexDirection: "column",
|
|
1022
|
+
pointerEvents: visible ? "auto" : "none",
|
|
1023
|
+
bgcolor: "var(--e-a-bg-default)",
|
|
1024
|
+
color: "var(--e-a-color-txt)",
|
|
1025
|
+
border: "var(--e-a-border)",
|
|
1026
|
+
boxShadow: `0 2px 20px 0 rgba(0, 0, 0, 0.1)`
|
|
1027
|
+
}
|
|
1028
|
+
},
|
|
1029
|
+
/* @__PURE__ */ React8.createElement(import_editor_ui.ThemeProvider, null, /* @__PURE__ */ React8.createElement(import_ui7.Box, { sx: { display: "flex", flexDirection: "column", height: "100%" } }, children)),
|
|
1030
|
+
isResizable && /* @__PURE__ */ React8.createElement(PanelResizeHandles, { panelId })
|
|
1031
|
+
));
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// src/components/internal/host.tsx
|
|
1035
|
+
function FloatingPanelsHost() {
|
|
1036
|
+
const openIds = (0, import_store11.__useSelector)(selectOpenPanelIds);
|
|
1037
|
+
const injections = useFloatingPanelsInjections();
|
|
1038
|
+
const dispatch2 = (0, import_store11.__useDispatch)();
|
|
1039
|
+
const isPreviewMode = (0, import_editor_v1_adapters.useEditMode)() === "preview";
|
|
1040
|
+
const declarationById = (0, import_react3.useMemo)(() => {
|
|
1041
|
+
return Object.fromEntries(injections.map((inj) => [inj.id, inj]));
|
|
1042
|
+
}, [injections]);
|
|
1043
|
+
return /* @__PURE__ */ React9.createElement(React9.Fragment, null, openIds.map((id) => {
|
|
1044
|
+
const declaration = declarationById[id];
|
|
1045
|
+
if (!declaration) {
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
const Component = declaration.component;
|
|
1049
|
+
return /* @__PURE__ */ React9.createElement(
|
|
1050
|
+
HostedPanel,
|
|
1051
|
+
{
|
|
1052
|
+
key: id,
|
|
1053
|
+
id,
|
|
1054
|
+
visible: !isPreviewMode,
|
|
1055
|
+
onFocus: () => dispatch2(slice.actions.bringToFront(id))
|
|
1056
|
+
},
|
|
1057
|
+
/* @__PURE__ */ React9.createElement(Component, null)
|
|
1058
|
+
);
|
|
1059
|
+
}));
|
|
1060
|
+
}
|
|
1061
|
+
function HostedPanel({
|
|
1062
|
+
id,
|
|
1063
|
+
children,
|
|
1064
|
+
onFocus,
|
|
1065
|
+
visible
|
|
1066
|
+
}) {
|
|
1067
|
+
const panel = (0, import_store11.__useSelector)((state) => selectPanelState(state, id));
|
|
1068
|
+
const title = (0, import_store11.__useSelector)((state) => selectPanelTitle(state, id));
|
|
1069
|
+
const zIndex = (0, import_store11.__useSelector)((state) => resolvePanelZIndex(state, id));
|
|
1070
|
+
if (!panel) {
|
|
1071
|
+
return null;
|
|
1072
|
+
}
|
|
1073
|
+
return /* @__PURE__ */ React9.createElement(
|
|
1074
|
+
PanelWindow,
|
|
1075
|
+
{
|
|
1076
|
+
panelId: id,
|
|
1077
|
+
corner: panel.corner,
|
|
1078
|
+
position: panel.position,
|
|
1079
|
+
size: panel.size,
|
|
1080
|
+
zIndex,
|
|
1081
|
+
visible,
|
|
1082
|
+
onFocus,
|
|
1083
|
+
title
|
|
1084
|
+
},
|
|
1085
|
+
children
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// src/init.ts
|
|
1090
|
+
function init() {
|
|
1091
|
+
sync();
|
|
1092
|
+
(0, import_store12.__registerSlice)(slice);
|
|
1093
|
+
(0, import_editor.injectIntoTop)({ id: "floating-panels", component: FloatingPanelsHost });
|
|
1094
|
+
}
|
|
1095
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1096
|
+
0 && (module.exports = {
|
|
1097
|
+
FloatingPanel,
|
|
1098
|
+
FloatingPanelBody,
|
|
1099
|
+
FloatingPanelFooter,
|
|
1100
|
+
FloatingPanelHeader,
|
|
1101
|
+
createFloatingPanel,
|
|
1102
|
+
init,
|
|
1103
|
+
registerFloatingPanel,
|
|
1104
|
+
useFloatingPanelActions,
|
|
1105
|
+
useFloatingPanelStatus,
|
|
1106
|
+
useFloatingPanelZIndex
|
|
1107
|
+
});
|
|
1108
|
+
//# sourceMappingURL=index.js.map
|