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