@elementor/editor-controls 3.35.0-367 → 3.35.0-369
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/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/inline-editor.tsx +44 -9
package/dist/index.mjs
CHANGED
|
@@ -6235,6 +6235,17 @@ var useOnUpdate = (callback, dependencies) => {
|
|
|
6235
6235
|
}
|
|
6236
6236
|
}, dependencies);
|
|
6237
6237
|
};
|
|
6238
|
+
var calcSelectionCenter = (view, container) => {
|
|
6239
|
+
if (!container) {
|
|
6240
|
+
return null;
|
|
6241
|
+
}
|
|
6242
|
+
const { from, to } = view.state.selection;
|
|
6243
|
+
const start = view.coordsAtPos(from);
|
|
6244
|
+
const end = view.coordsAtPos(to);
|
|
6245
|
+
const left = (start.left + end.left) / 2 - container.left;
|
|
6246
|
+
const top = Math.min(start.top, end.top) - container.top;
|
|
6247
|
+
return { left, top };
|
|
6248
|
+
};
|
|
6238
6249
|
var InlineEditor = React101.forwardRef(
|
|
6239
6250
|
({
|
|
6240
6251
|
value,
|
|
@@ -6251,8 +6262,16 @@ var InlineEditor = React101.forwardRef(
|
|
|
6251
6262
|
const popupState = usePopupState9({ variant: "popover", disableAutoFocus: true });
|
|
6252
6263
|
const [hasSelectedContent, setHasSelectedContent] = React101.useState(false);
|
|
6253
6264
|
const documentContentSettings = !!expectedTag ? "block+" : "inline*";
|
|
6265
|
+
const [selectionRect, setSelectionRect] = React101.useState(null);
|
|
6254
6266
|
const onSelectionEnd = (view) => {
|
|
6255
|
-
|
|
6267
|
+
const hasSelection = !view.state.selection.empty;
|
|
6268
|
+
setHasSelectedContent(hasSelection);
|
|
6269
|
+
if (hasSelection) {
|
|
6270
|
+
const container = containerRef.current?.getBoundingClientRect();
|
|
6271
|
+
setSelectionRect(calcSelectionCenter(view, container));
|
|
6272
|
+
} else {
|
|
6273
|
+
setSelectionRect(null);
|
|
6274
|
+
}
|
|
6256
6275
|
queueMicrotask(() => view.focus());
|
|
6257
6276
|
};
|
|
6258
6277
|
const onKeyDown = (_, event) => {
|
|
@@ -6330,12 +6349,17 @@ var InlineEditor = React101.forwardRef(
|
|
|
6330
6349
|
}
|
|
6331
6350
|
}, [editor, value]);
|
|
6332
6351
|
const computePopupPosition = () => {
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6352
|
+
if (!selectionRect) {
|
|
6353
|
+
return { left: 0, top: 0 };
|
|
6354
|
+
}
|
|
6355
|
+
const container = containerRef.current?.getBoundingClientRect();
|
|
6356
|
+
if (!container) {
|
|
6357
|
+
return { left: 0, top: 0 };
|
|
6358
|
+
}
|
|
6359
|
+
const initial = getInitialPopoverPosition?.() ?? { left: 0, top: 0 };
|
|
6336
6360
|
return {
|
|
6337
|
-
left: left + initial.left,
|
|
6338
|
-
top: top + initial.top
|
|
6361
|
+
left: container.left + selectionRect.left + initial.left,
|
|
6362
|
+
top: container.top + selectionRect.top + initial.top
|
|
6339
6363
|
};
|
|
6340
6364
|
};
|
|
6341
6365
|
const Wrapper = ({ children }) => {
|
|
@@ -6364,11 +6388,11 @@ var InlineEditor = React101.forwardRef(
|
|
|
6364
6388
|
}
|
|
6365
6389
|
},
|
|
6366
6390
|
...bindPopover8(popupState),
|
|
6367
|
-
open: hasSelectedContent,
|
|
6391
|
+
open: hasSelectedContent && selectionRect !== null,
|
|
6368
6392
|
anchorReference: "anchorPosition",
|
|
6369
6393
|
anchorPosition: computePopupPosition(),
|
|
6370
|
-
anchorOrigin: { vertical: "top", horizontal: "
|
|
6371
|
-
transformOrigin: { vertical: "bottom", horizontal: "
|
|
6394
|
+
anchorOrigin: { vertical: "top", horizontal: "center" },
|
|
6395
|
+
transformOrigin: { vertical: "bottom", horizontal: "center" }
|
|
6372
6396
|
},
|
|
6373
6397
|
/* @__PURE__ */ React101.createElement(InlineEditorToolbar, { editor })
|
|
6374
6398
|
));
|