@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.js
CHANGED
|
@@ -6224,6 +6224,17 @@ var useOnUpdate = (callback, dependencies) => {
|
|
|
6224
6224
|
}
|
|
6225
6225
|
}, dependencies);
|
|
6226
6226
|
};
|
|
6227
|
+
var calcSelectionCenter = (view, container) => {
|
|
6228
|
+
if (!container) {
|
|
6229
|
+
return null;
|
|
6230
|
+
}
|
|
6231
|
+
const { from, to } = view.state.selection;
|
|
6232
|
+
const start = view.coordsAtPos(from);
|
|
6233
|
+
const end = view.coordsAtPos(to);
|
|
6234
|
+
const left = (start.left + end.left) / 2 - container.left;
|
|
6235
|
+
const top = Math.min(start.top, end.top) - container.top;
|
|
6236
|
+
return { left, top };
|
|
6237
|
+
};
|
|
6227
6238
|
var InlineEditor = React101.forwardRef(
|
|
6228
6239
|
({
|
|
6229
6240
|
value,
|
|
@@ -6240,8 +6251,16 @@ var InlineEditor = React101.forwardRef(
|
|
|
6240
6251
|
const popupState = (0, import_ui87.usePopupState)({ variant: "popover", disableAutoFocus: true });
|
|
6241
6252
|
const [hasSelectedContent, setHasSelectedContent] = React101.useState(false);
|
|
6242
6253
|
const documentContentSettings = !!expectedTag ? "block+" : "inline*";
|
|
6254
|
+
const [selectionRect, setSelectionRect] = React101.useState(null);
|
|
6243
6255
|
const onSelectionEnd = (view) => {
|
|
6244
|
-
|
|
6256
|
+
const hasSelection = !view.state.selection.empty;
|
|
6257
|
+
setHasSelectedContent(hasSelection);
|
|
6258
|
+
if (hasSelection) {
|
|
6259
|
+
const container = containerRef.current?.getBoundingClientRect();
|
|
6260
|
+
setSelectionRect(calcSelectionCenter(view, container));
|
|
6261
|
+
} else {
|
|
6262
|
+
setSelectionRect(null);
|
|
6263
|
+
}
|
|
6245
6264
|
queueMicrotask(() => view.focus());
|
|
6246
6265
|
};
|
|
6247
6266
|
const onKeyDown = (_, event) => {
|
|
@@ -6319,12 +6338,17 @@ var InlineEditor = React101.forwardRef(
|
|
|
6319
6338
|
}
|
|
6320
6339
|
}, [editor, value]);
|
|
6321
6340
|
const computePopupPosition = () => {
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6341
|
+
if (!selectionRect) {
|
|
6342
|
+
return { left: 0, top: 0 };
|
|
6343
|
+
}
|
|
6344
|
+
const container = containerRef.current?.getBoundingClientRect();
|
|
6345
|
+
if (!container) {
|
|
6346
|
+
return { left: 0, top: 0 };
|
|
6347
|
+
}
|
|
6348
|
+
const initial = getInitialPopoverPosition?.() ?? { left: 0, top: 0 };
|
|
6325
6349
|
return {
|
|
6326
|
-
left: left + initial.left,
|
|
6327
|
-
top: top + initial.top
|
|
6350
|
+
left: container.left + selectionRect.left + initial.left,
|
|
6351
|
+
top: container.top + selectionRect.top + initial.top
|
|
6328
6352
|
};
|
|
6329
6353
|
};
|
|
6330
6354
|
const Wrapper = ({ children }) => {
|
|
@@ -6353,11 +6377,11 @@ var InlineEditor = React101.forwardRef(
|
|
|
6353
6377
|
}
|
|
6354
6378
|
},
|
|
6355
6379
|
...(0, import_ui87.bindPopover)(popupState),
|
|
6356
|
-
open: hasSelectedContent,
|
|
6380
|
+
open: hasSelectedContent && selectionRect !== null,
|
|
6357
6381
|
anchorReference: "anchorPosition",
|
|
6358
6382
|
anchorPosition: computePopupPosition(),
|
|
6359
|
-
anchorOrigin: { vertical: "top", horizontal: "
|
|
6360
|
-
transformOrigin: { vertical: "bottom", horizontal: "
|
|
6383
|
+
anchorOrigin: { vertical: "top", horizontal: "center" },
|
|
6384
|
+
transformOrigin: { vertical: "bottom", horizontal: "center" }
|
|
6361
6385
|
},
|
|
6362
6386
|
/* @__PURE__ */ React101.createElement(InlineEditorToolbar, { editor })
|
|
6363
6387
|
));
|