@haklex/rich-editor 0.65.1 → 0.65.3
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.
|
@@ -2591,14 +2591,15 @@ function getTopLevelBlockById(blockId) {
|
|
|
2591
2591
|
for (const child of $getRoot().getChildren()) if ($getState(child, blockIdState) === blockId && $isElementNode(child)) return child;
|
|
2592
2592
|
return null;
|
|
2593
2593
|
}
|
|
2594
|
-
function
|
|
2595
|
-
|
|
2594
|
+
function holdsNoLexicalText(element) {
|
|
2595
|
+
if (element.tagName === "SUMMARY" && element.parentElement?.tagName === "DETAILS") return true;
|
|
2596
|
+
return element.getAttribute("contenteditable") === "false";
|
|
2596
2597
|
}
|
|
2597
2598
|
function getTextLengthOfDomNode(node) {
|
|
2598
2599
|
if (node.nodeType === Node.TEXT_NODE) return node.textContent?.length ?? 0;
|
|
2599
2600
|
if (node.nodeType !== Node.ELEMENT_NODE) return 0;
|
|
2600
2601
|
const element = node;
|
|
2601
|
-
if (
|
|
2602
|
+
if (holdsNoLexicalText(element)) return 0;
|
|
2602
2603
|
if (element.tagName === "BR") return 1;
|
|
2603
2604
|
let length = 0;
|
|
2604
2605
|
for (const child of node.childNodes) length += getTextLengthOfDomNode(child);
|
|
@@ -2746,7 +2747,7 @@ function getTextOffsetFromDOMPoint(container, targetNode, targetOffset) {
|
|
|
2746
2747
|
}
|
|
2747
2748
|
if (node.nodeType !== Node.ELEMENT_NODE) return false;
|
|
2748
2749
|
const element = node;
|
|
2749
|
-
if (
|
|
2750
|
+
if (holdsNoLexicalText(element)) return false;
|
|
2750
2751
|
if (element.tagName === "BR") {
|
|
2751
2752
|
offset += 1;
|
|
2752
2753
|
return false;
|
|
@@ -2757,13 +2758,13 @@ function getTextOffsetFromDOMPoint(container, targetNode, targetOffset) {
|
|
|
2757
2758
|
walk(container);
|
|
2758
2759
|
return offset;
|
|
2759
2760
|
}
|
|
2760
|
-
function findDOMPointByTextOffset(container, requestedOffset) {
|
|
2761
|
+
function findDOMPointByTextOffset(container, requestedOffset, affinity = "backward") {
|
|
2761
2762
|
const targetOffset = clampOffset(requestedOffset, getTextLengthOfDomNode(container));
|
|
2762
2763
|
let consumed = 0;
|
|
2763
2764
|
function walk(node) {
|
|
2764
2765
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
2765
2766
|
const length = node.textContent?.length ?? 0;
|
|
2766
|
-
if (targetOffset <= consumed + length) return {
|
|
2767
|
+
if (affinity === "forward" ? targetOffset < consumed + length : targetOffset <= consumed + length) return {
|
|
2767
2768
|
node,
|
|
2768
2769
|
offset: targetOffset - consumed
|
|
2769
2770
|
};
|
|
@@ -2772,7 +2773,7 @@ function findDOMPointByTextOffset(container, requestedOffset) {
|
|
|
2772
2773
|
}
|
|
2773
2774
|
if (node.nodeType !== Node.ELEMENT_NODE) return null;
|
|
2774
2775
|
const element = node;
|
|
2775
|
-
if (
|
|
2776
|
+
if (holdsNoLexicalText(element)) return null;
|
|
2776
2777
|
if (element.tagName === "BR") {
|
|
2777
2778
|
const parent = element.parentNode;
|
|
2778
2779
|
if (!parent) return null;
|
|
@@ -2806,12 +2807,10 @@ function createDOMRangeFromTextSelection(rootElement, snapshot) {
|
|
|
2806
2807
|
const anchorBlock = getBlockElementById(rootElement, snapshot.anchorBlockId);
|
|
2807
2808
|
const focusBlock = getBlockElementById(rootElement, snapshot.focusBlockId);
|
|
2808
2809
|
if (!anchorBlock || !focusBlock) return null;
|
|
2809
|
-
const anchor = findDOMPointByTextOffset(anchorBlock, snapshot.anchorOffset);
|
|
2810
|
-
const focus = findDOMPointByTextOffset(focusBlock, snapshot.focusOffset);
|
|
2811
|
-
if (!anchor || !focus) return null;
|
|
2812
2810
|
const anchorComesFirst = anchorBlock === focusBlock ? snapshot.anchorOffset <= snapshot.focusOffset : compareBlockElements(anchorBlock, focusBlock) <= 0;
|
|
2813
|
-
const start = anchorComesFirst ?
|
|
2814
|
-
const end = anchorComesFirst ?
|
|
2811
|
+
const start = anchorComesFirst ? findDOMPointByTextOffset(anchorBlock, snapshot.anchorOffset, "forward") : findDOMPointByTextOffset(focusBlock, snapshot.focusOffset, "forward");
|
|
2812
|
+
const end = anchorComesFirst ? findDOMPointByTextOffset(focusBlock, snapshot.focusOffset) : findDOMPointByTextOffset(anchorBlock, snapshot.anchorOffset);
|
|
2813
|
+
if (!start || !end) return null;
|
|
2815
2814
|
try {
|
|
2816
2815
|
const range = document.createRange();
|
|
2817
2816
|
range.setStart(start.node, start.offset);
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as VideoUploadProvider, C as createTextSelectionStore, D as ImageUploadPlugin, E as LinkFaviconPlugin, H as ImageUploadProvider, J as CorePlugins, K as FileUploadProvider, L as FileUploadPlugin, O as defaultImageUpload, S as TextSelectionStoreProvider, T as useTextSelectionStore, W as ImagePreprocessProvider, _ as $getRootBlock, a as EditorRefPlugin, b as buildBlockAnchor, c as $captureTextSelection, d as createDOMRangeFromTextSelection, f as findDOMPointByTextOffset, g as TEXT_SELECTION_HIGHLIGHT_NAME, h as getTextOffsetFromDOMPoint, i as FootnotePlugin, l as $captureTextSelectionFromRangeSelection, m as getDOMRectFromTextSelection, n as SubmitShortcutPlugin, o as VideoUploadPlugin, p as getBlockElementById, r as OnChangePlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, u as $restoreTextSelection, v as $getTextOffsetInBlock, w as useTextSelectionSnapshot, x as buildRangeAnchor, y as $resolveSelectionPoint } from "./VirtualizationPlugin-
|
|
1
|
+
import { B as VideoUploadProvider, C as createTextSelectionStore, D as ImageUploadPlugin, E as LinkFaviconPlugin, H as ImageUploadProvider, J as CorePlugins, K as FileUploadProvider, L as FileUploadPlugin, O as defaultImageUpload, S as TextSelectionStoreProvider, T as useTextSelectionStore, W as ImagePreprocessProvider, _ as $getRootBlock, a as EditorRefPlugin, b as buildBlockAnchor, c as $captureTextSelection, d as createDOMRangeFromTextSelection, f as findDOMPointByTextOffset, g as TEXT_SELECTION_HIGHLIGHT_NAME, h as getTextOffsetFromDOMPoint, i as FootnotePlugin, l as $captureTextSelectionFromRangeSelection, m as getDOMRectFromTextSelection, n as SubmitShortcutPlugin, o as VideoUploadPlugin, p as getBlockElementById, r as OnChangePlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, u as $restoreTextSelection, v as $getTextOffsetInBlock, w as useTextSelectionSnapshot, x as buildRangeAnchor, y as $resolveSelectionPoint } from "./VirtualizationPlugin-DNCoEU-6.js";
|
|
2
2
|
import { n as setResolvedEditNodes, r as allEditNodes } from "./node-registry-8OWu2S8i.js";
|
|
3
3
|
import { n as useEditorBlock } from "./EditorBlockContext-DytAx9Tg.js";
|
|
4
4
|
import { J as NestedContentRendererProvider, X as useOptionalNestedContentRenderer, Y as useNestedContentRenderer, t as editorTheme } from "./theme-DH4xzxU-.js";
|
package/dist/plugins-entry.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as HorizontalRulePlugin, A as presentImageDialog, B as VideoUploadProvider, D as ImageUploadPlugin, E as LinkFaviconPlugin, F as registerImageEditor, G as useImagePreprocess, H as ImageUploadProvider, I as resolvePreprocessTargets, J as CorePlugins, K as FileUploadProvider, L as FileUploadPlugin, M as getImageEditor, N as keepsOriginal, O as defaultImageUpload, P as markKeepOriginal, Q as InlineDndPlugin, R as setFileUploadEntry, U as useImageUpload, V as useVideoUpload, W as ImagePreprocessProvider, X as MarkdownPastePlugin, Y as MarkdownShortcutsPlugin, Z as ALL_TRANSFORMERS, a as EditorRefPlugin, et as ClickBelowPlugin, i as FootnotePlugin, j as ImageDialog, k as uploadImageFile, n as SubmitShortcutPlugin, nt as BlockExitPlugin, o as VideoUploadPlugin, q as useFileUpload, r as OnChangePlugin, rt as AutoLinkPlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, tt as registerClickBelowCommand, z as useFileUploadEntry } from "./VirtualizationPlugin-
|
|
1
|
+
import { $ as HorizontalRulePlugin, A as presentImageDialog, B as VideoUploadProvider, D as ImageUploadPlugin, E as LinkFaviconPlugin, F as registerImageEditor, G as useImagePreprocess, H as ImageUploadProvider, I as resolvePreprocessTargets, J as CorePlugins, K as FileUploadProvider, L as FileUploadPlugin, M as getImageEditor, N as keepsOriginal, O as defaultImageUpload, P as markKeepOriginal, Q as InlineDndPlugin, R as setFileUploadEntry, U as useImageUpload, V as useVideoUpload, W as ImagePreprocessProvider, X as MarkdownPastePlugin, Y as MarkdownShortcutsPlugin, Z as ALL_TRANSFORMERS, a as EditorRefPlugin, et as ClickBelowPlugin, i as FootnotePlugin, j as ImageDialog, k as uploadImageFile, n as SubmitShortcutPlugin, nt as BlockExitPlugin, o as VideoUploadPlugin, q as useFileUpload, r as OnChangePlugin, rt as AutoLinkPlugin, s as TextSelectionPlugin, t as AutoFocusPlugin, tt as registerClickBelowCommand, z as useFileUploadEntry } from "./VirtualizationPlugin-DNCoEU-6.js";
|
|
2
2
|
import { $ as markInlineDraggable, Z as INLINE_DRAG_ATTR } from "./theme-DH4xzxU-.js";
|
|
3
3
|
import { c as PasteLinkPlugin } from "./AlertQuoteEditNode-Ck4v29Wg.js";
|
|
4
4
|
import { i as EditorSurfacePlugins, n as ActiveEditorScope, o as useActiveEditor, r as EditorSurfacePlugin, t as VirtualizationPlugin } from "./VirtualizationPlugin-nD_x-4yR.js";
|
|
@@ -15,7 +15,7 @@ export declare function $captureTextSelectionFromRangeSelection(selection: Range
|
|
|
15
15
|
export declare function $captureTextSelection(): TextSelectionSnapshot | null;
|
|
16
16
|
export declare function $restoreTextSelection(snapshot: TextSelectionSnapshot): boolean;
|
|
17
17
|
export declare function getTextOffsetFromDOMPoint(container: Element, targetNode: Node, targetOffset: number): number;
|
|
18
|
-
export declare function findDOMPointByTextOffset(container: Element, requestedOffset: number): DOMSelectionTarget | null;
|
|
18
|
+
export declare function findDOMPointByTextOffset(container: Element, requestedOffset: number, affinity?: 'backward' | 'forward'): DOMSelectionTarget | null;
|
|
19
19
|
export declare function getBlockElementById(rootElement: HTMLElement, blockId: string): HTMLElement | null;
|
|
20
20
|
export declare function createDOMRangeFromTextSelection(rootElement: HTMLElement, snapshot: TextSelectionSnapshot): Range | null;
|
|
21
21
|
export declare function getDOMRectFromTextSelection(rootElement: HTMLElement, snapshot: TextSelectionSnapshot): DOMRect | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-selection.d.ts","sourceRoot":"","sources":["../../src/utils/text-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,cAAc,EAAE,MAAM,SAAS,CAAC;AAgBxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAQD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB;
|
|
1
|
+
{"version":3,"file":"text-selection.d.ts","sourceRoot":"","sources":["../../src/utils/text-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,cAAc,EAAE,MAAM,SAAS,CAAC;AAgBxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE3E,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAQD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB;AAiJD,wBAAgB,uCAAuC,CACrD,SAAS,EAAE,cAAc,GACxB,qBAAqB,GAAG,IAAI,CA2B9B;AAED,wBAAgB,qBAAqB,IAAI,qBAAqB,GAAG,IAAI,CAOpE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAe9E;AAED,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,IAAI,EAChB,YAAY,EAAE,MAAM,GACnB,MAAM,CA+CR;AAED,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,OAAO,EAClB,eAAe,EAAE,MAAM,EACvB,QAAQ,GAAE,UAAU,GAAG,SAAsB,GAC5C,kBAAkB,GAAG,IAAI,CA0D3B;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAEjG;AAED,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,qBAAqB,GAC9B,KAAK,GAAG,IAAI,CA8Bd;AAED,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,qBAAqB,GAC9B,OAAO,GAAG,IAAI,CAYhB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haklex/rich-editor",
|
|
3
|
-
"version": "0.65.
|
|
3
|
+
"version": "0.65.3",
|
|
4
4
|
"description": "Core rich text editor based on Lexical",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"dist"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@haklex/rich-editor-ui": "0.65.
|
|
61
|
-
"@haklex/rich-headless": "0.65.
|
|
62
|
-
"@haklex/rich-style-token": "0.65.
|
|
60
|
+
"@haklex/rich-editor-ui": "0.65.3",
|
|
61
|
+
"@haklex/rich-headless": "0.65.3",
|
|
62
|
+
"@haklex/rich-style-token": "0.65.3",
|
|
63
63
|
"@lexical/code-core": "^0.53.0",
|
|
64
64
|
"nanoid": "^6.0.2",
|
|
65
65
|
"thumbhash": "^0.1.1"
|