@haklex/rich-plugin-block-handle 0.69.2 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"BlockHandlePlugin.d.ts","sources":["../src/BlockHandlePlugin.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAiC,YAAY,EAAE,MAAM,OAAO,CAAC;AAwsBzE,wBAAgB,iBAAiB,IAAI,YAAY,CAGhD"}
1
+ {"version":3,"file":"BlockHandlePlugin.d.ts","sources":["../src/BlockHandlePlugin.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAiC,YAAY,EAAE,MAAM,OAAO,CAAC;AAooBzE,wBAAgB,iBAAiB,IAAI,YAAY,CAGhD"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useEditorBlock } from "@haklex/rich-editor";
1
+ import { getBlockElement, getDropTargetBlock, getNearestBlockByY, useEditorBlock } from "@haklex/rich-editor";
2
2
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuTrigger, detectPlatform } from "@haklex/rich-editor-ui";
3
3
  import { usePortalTheme } from "@haklex/rich-style-token";
4
4
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
@@ -1210,59 +1210,6 @@ var DRAG_DATA_KEY = "application/x-rich-editor-drag";
1210
1210
  var HIDE_DELAY = 300;
1211
1211
  var GUTTER_INSET = 26;
1212
1212
  var GRIP_HEIGHT = 24;
1213
- function getBlockElement(editor, target) {
1214
- const rootElement = editor.getRootElement();
1215
- if (!rootElement) return null;
1216
- let current = target;
1217
- while (current && current !== rootElement) {
1218
- if (current.parentElement === rootElement) return current;
1219
- current = current.parentElement;
1220
- }
1221
- return null;
1222
- }
1223
- function getNearestBlockByY(rootElement, clientY) {
1224
- const blocks = [...rootElement.children].filter((child) => child instanceof HTMLElement);
1225
- if (!blocks.length) return null;
1226
- let nearestBlock = null;
1227
- let nearestDistance = Number.POSITIVE_INFINITY;
1228
- for (const block of blocks) {
1229
- const rect = block.getBoundingClientRect();
1230
- if (rect.height <= 0) continue;
1231
- if (clientY >= rect.top && clientY <= rect.bottom) return block;
1232
- const distance = clientY < rect.top ? rect.top - clientY : clientY - rect.bottom;
1233
- if (distance < nearestDistance) {
1234
- nearestDistance = distance;
1235
- nearestBlock = block;
1236
- }
1237
- }
1238
- return nearestBlock;
1239
- }
1240
- function getDropTargetBlock(editor, rootElement, event) {
1241
- const rootRect = rootElement.getBoundingClientRect();
1242
- if (rootRect.width <= 0 || rootRect.height <= 0) return null;
1243
- if (event.clientY < rootRect.top || event.clientY > rootRect.bottom) return null;
1244
- const points = [{
1245
- x: event.clientX,
1246
- y: event.clientY
1247
- }];
1248
- const clampedX = Math.min(rootRect.right - 1, Math.max(rootRect.left + 1, event.clientX));
1249
- if (clampedX !== event.clientX) points.unshift({
1250
- x: clampedX,
1251
- y: event.clientY
1252
- });
1253
- for (const point of points) {
1254
- const element = document.elementFromPoint(point.x, point.y);
1255
- if (!(element instanceof HTMLElement)) continue;
1256
- const block = getBlockElement(editor, element);
1257
- if (block) return block;
1258
- }
1259
- const { target } = event;
1260
- if (target instanceof HTMLElement) {
1261
- const block = getBlockElement(editor, target);
1262
- if (block) return block;
1263
- }
1264
- return getNearestBlockByY(rootElement, event.clientY);
1265
- }
1266
1213
  function toPagePosition(rect) {
1267
1214
  return {
1268
1215
  top: rect.top + window.scrollY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-plugin-block-handle",
3
- "version": "0.69.2",
3
+ "version": "0.70.0",
4
4
  "description": "Block handle plugin with add button and context menu",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,9 +40,9 @@
40
40
  "vite": "^8.3.5"
41
41
  },
42
42
  "peerDependencies": {
43
- "@haklex/rich-editor": "^0.69.2",
44
- "@haklex/rich-editor-ui": "^0.69.2",
45
- "@haklex/rich-style-token": "^0.69.2",
43
+ "@haklex/rich-editor": "^0.70.0",
44
+ "@haklex/rich-editor-ui": "^0.70.0",
45
+ "@haklex/rich-style-token": "^0.70.0",
46
46
  "@lexical/html": "^0.53.0",
47
47
  "@lexical/list": "^0.53.0",
48
48
  "@lexical/react": "^0.53.0",