slate-vue3 0.2.0 → 0.2.2

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/README.md CHANGED
@@ -20,8 +20,8 @@
20
20
  # Why use it?
21
21
 
22
22
  1. :sparkles: Highly customizable features, use slate core at the bottom level
23
- 2. :zap: The latest version of the core, use vue to reduce the number of re-renderings
24
- 3. :coffee: This library provides the same usage as slate-react, design tends to be stable
23
+ 2. :zap: Use vue3 for high-performance rendering, and later connect to vapor mode
24
+ 3. :coffee: The latest version of the core, design tends to be stable
25
25
  4. :point_right: Check out the [**live demo**](https://guan-erjia.github.io/slate-vue3/examples) of all of the examples
26
26
 
27
27
  # How to use?
@@ -84,24 +84,3 @@ Of coures yes, but we do not recommend it unless you have already configured jsx
84
84
  ### 3. Why do rendering functions not use Vue components ?
85
85
 
86
86
  Vue uses lazy updates, rendering with components generates additional state, which can cause unexpected results during updates, it would be better to use functions as branches directly
87
-
88
- # Compact Slate
89
-
90
- **reactive implement**
91
-
92
- 1. packages/slate/src/interfaces/text.ts 115:115
93
- 2. packages/slate/src/create-editor.ts 94:94
94
- 3. packages/slate/src/transforms-node/set-nodes.ts 18:18
95
- 4. packages/slate/src/interfaces/text.ts 116:116
96
-
97
- **remove immer**
98
-
99
- 1. packages/slate/src/interfaces/node.ts 365:365
100
- 2. packages/slate/src/interfaces/point.ts 103:103
101
- 3. packages/slate/src/interfaces/range.ts 224:224
102
- 4. packages/slate/src/interfaces/transforms/general.ts 322:333
103
-
104
- **other compact**
105
-
106
- 1. packages/slate/src/core/normalize-node.ts
107
- 2. packages/slate-dom/src/plugin/dom-editor.ts 421:441
package/dist/dom.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DOMEditor, E as EDITOR_TO_KEY_TO_ELEMENT, a as EDITOR_TO_USER_MARKS, b as EDITOR_TO_USER_SELECTION, N as NODE_TO_KEY, i as isDOMText, g as getPlainText, c as getSlateFragmentAttribute, d as EDITOR_TO_ON_CHANGE } from "./hotkeys-u-dgagSM.js";
2
- import { C, F, G, J, H, B, I, u, L, v, w, M, x, O, z, y, A, K, P, Q, R, S, e, f, h, j, k, l, m, o, p, q, r, s, t, n } from "./hotkeys-u-dgagSM.js";
1
+ import { D as DOMEditor, E as EDITOR_TO_KEY_TO_ELEMENT, a as EDITOR_TO_USER_MARKS, b as EDITOR_TO_USER_SELECTION, N as NODE_TO_KEY, i as isDOMText, g as getPlainText, c as getSlateFragmentAttribute, d as EDITOR_TO_ON_CHANGE } from "./hotkeys-BwRBmDaN.js";
2
+ import { C, F, G, J, H, B, I, u, L, v, w, M, x, O, z, y, A, K, P, Q, R, S, e, f, h, j, k, l, m, o, p, q, r, s, t, n } from "./hotkeys-BwRBmDaN.js";
3
3
  import { E as Editor, R as Range, a as Element, c as Transforms, P as Path, N as Node } from "./batch-dirty-paths-X-eP3GRL.js";
4
4
  import "vue";
5
5
  const doRectsIntersect = (rect, compareRect) => {
@@ -199,7 +199,7 @@ const EDITOR_TO_USER_MARKS = new toRawWeakMap();
199
199
  const MARK_PLACEHOLDER_SYMBOL = Symbol(
200
200
  "mark-placeholder"
201
201
  );
202
- function getFirefoxNodeEl(node, offset) {
202
+ function getFirefoxNodeEl([node, offset]) {
203
203
  var _a2;
204
204
  if (node.nodeType !== 3 || node.textContent !== "") {
205
205
  return [node, offset];
@@ -648,12 +648,12 @@ const DOMEditor = {
648
648
  focusOffset = ((_a2 = focusNode == null ? void 0 : focusNode.textContent) == null ? void 0 : _a2.length) || 0;
649
649
  } else {
650
650
  if (anchorNode) {
651
- const [el2, offset] = getFirefoxNodeEl(anchorNode, anchorOffset);
651
+ const [el2, offset] = getFirefoxNodeEl([anchorNode, anchorOffset]);
652
652
  anchorNode = el2;
653
653
  anchorOffset = offset;
654
654
  }
655
655
  if (focusNode) {
656
- const [el2, offset] = getFirefoxNodeEl(focusNode, focusOffset);
656
+ const [el2, offset] = getFirefoxNodeEl([focusNode, focusOffset]);
657
657
  focusNode = el2;
658
658
  focusOffset = offset;
659
659
  }
@@ -675,12 +675,12 @@ const DOMEditor = {
675
675
  isCollapsed = domRange.collapsed;
676
676
  if (IS_FIREFOX) {
677
677
  if (anchorNode) {
678
- const [el2, offset] = getFirefoxNodeEl(anchorNode, anchorOffset);
678
+ const [el2, offset] = getFirefoxNodeEl([anchorNode, anchorOffset]);
679
679
  anchorNode = el2;
680
680
  anchorOffset = offset;
681
681
  }
682
682
  if (focusNode) {
683
- const [el2, offset] = getFirefoxNodeEl(focusNode, focusOffset);
683
+ const [el2, offset] = getFirefoxNodeEl([focusNode, focusOffset]);
684
684
  focusNode = el2;
685
685
  focusOffset = offset;
686
686
  }
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { defineComponent, provide, ref, computed, onMounted, onUnmounted, renderSlot, inject, h, watch, renderList, Fragment, useAttrs, reactive } from "vue";
2
2
  import { N as Node, S as Scrubber, P as Path, E as Editor, R as Range, T as Text, a as Element, c as Transforms } from "./batch-dirty-paths-X-eP3GRL.js";
3
- import { D as DOMEditor, d as EDITOR_TO_ON_CHANGE, P as MARK_PLACEHOLDER_SYMBOL, I as IS_ANDROID, x as IS_IOS, E as EDITOR_TO_KEY_TO_ELEMENT, J as ELEMENT_TO_NODE, Q as NODE_TO_ELEMENT, R as NODE_TO_INDEX, S as NODE_TO_PARENT, p as isDOMNode, y as IS_WEBKIT, e as applyStringDiff, q as isDOMSelection, n as normalizeStringDiff, O as IS_READ_ONLY, h as getDefaultView, G as EDITOR_TO_WINDOW, F as EDITOR_TO_ELEMENT, H as HAS_BEFORE_INPUT_SUPPORT, C as CAN_USE_DOM, f as getActiveElement, j as getSelection, M as IS_FOCUSED, b as EDITOR_TO_USER_SELECTION, L as IS_COMPOSING, o as isDOMElement, w as IS_FIREFOX_LEGACY, A as IS_WECHATBROWSER, z as IS_UC_MOBILE, a as EDITOR_TO_USER_MARKS, v as IS_FIREFOX, B as Hotkeys, u as IS_CHROME, r as isPlainTextOnlyPaste } from "./hotkeys-u-dgagSM.js";
3
+ import { t } from "./batch-dirty-paths-X-eP3GRL.js";
4
+ import { D as DOMEditor, d as EDITOR_TO_ON_CHANGE, P as MARK_PLACEHOLDER_SYMBOL, I as IS_ANDROID, x as IS_IOS, E as EDITOR_TO_KEY_TO_ELEMENT, J as ELEMENT_TO_NODE, Q as NODE_TO_ELEMENT, R as NODE_TO_INDEX, S as NODE_TO_PARENT, p as isDOMNode, y as IS_WEBKIT, e as applyStringDiff, q as isDOMSelection, n as normalizeStringDiff, O as IS_READ_ONLY, h as getDefaultView, G as EDITOR_TO_WINDOW, F as EDITOR_TO_ELEMENT, H as HAS_BEFORE_INPUT_SUPPORT, C as CAN_USE_DOM, f as getActiveElement, j as getSelection, M as IS_FOCUSED, b as EDITOR_TO_USER_SELECTION, L as IS_COMPOSING, o as isDOMElement, w as IS_FIREFOX_LEGACY, A as IS_WECHATBROWSER, z as IS_UC_MOBILE, a as EDITOR_TO_USER_MARKS, v as IS_FIREFOX, B as Hotkeys, u as IS_CHROME, r as isPlainTextOnlyPaste } from "./hotkeys-BwRBmDaN.js";
4
5
  const SLATE_USE_EDITOR = Symbol("SLATE_USE_EDITOR");
5
6
  const SLATE_USE_DECORATE = Symbol("SLATE_USE_DECORATE");
6
7
  const SLATE_USE_SELECTED = Symbol("SLATE_USE_SELECTED");
@@ -363,47 +364,47 @@ const ChildrenFC = (element, editor) => renderList(element.children, (child, i)
363
364
  NODE_TO_PARENT.set(child, element);
364
365
  return Element.isElement(child) ? h(ElementComp, { element: child, key: key.id }) : h(TextComp, { text: child, element, key: key.id });
365
366
  });
366
- const t = (t2) => "object" == typeof t2 && null != t2 && 1 === t2.nodeType, e$1 = (t2, e2) => (!e2 || "hidden" !== t2) && ("visible" !== t2 && "clip" !== t2), n = (t2, n2) => {
367
- if (t2.clientHeight < t2.scrollHeight || t2.clientWidth < t2.scrollWidth) {
368
- const o2 = getComputedStyle(t2, null);
369
- return e$1(o2.overflowY, n2) || e$1(o2.overflowX, n2) || ((t3) => {
370
- const e2 = ((t4) => {
371
- if (!t4.ownerDocument || !t4.ownerDocument.defaultView) return null;
367
+ const t2 = (t3) => "object" == typeof t3 && null != t3 && 1 === t3.nodeType, e$1 = (t3, e2) => (!e2 || "hidden" !== t3) && ("visible" !== t3 && "clip" !== t3), n = (t3, n2) => {
368
+ if (t3.clientHeight < t3.scrollHeight || t3.clientWidth < t3.scrollWidth) {
369
+ const o2 = getComputedStyle(t3, null);
370
+ return e$1(o2.overflowY, n2) || e$1(o2.overflowX, n2) || ((t4) => {
371
+ const e2 = ((t5) => {
372
+ if (!t5.ownerDocument || !t5.ownerDocument.defaultView) return null;
372
373
  try {
373
- return t4.ownerDocument.defaultView.frameElement;
374
- } catch (t5) {
374
+ return t5.ownerDocument.defaultView.frameElement;
375
+ } catch (t6) {
375
376
  return null;
376
377
  }
377
- })(t3);
378
- return !!e2 && (e2.clientHeight < t3.scrollHeight || e2.clientWidth < t3.scrollWidth);
379
- })(t2);
378
+ })(t4);
379
+ return !!e2 && (e2.clientHeight < t4.scrollHeight || e2.clientWidth < t4.scrollWidth);
380
+ })(t3);
380
381
  }
381
382
  return false;
382
- }, o$1 = (t2, e2, n2, o2, l2, r2, i, s) => r2 < t2 && i > e2 || r2 > t2 && i < e2 ? 0 : r2 <= t2 && s <= n2 || i >= e2 && s >= n2 ? r2 - t2 - o2 : i > e2 && s < n2 || r2 < t2 && s > n2 ? i - e2 + l2 : 0, l = (t2) => {
383
- const e2 = t2.parentElement;
384
- return null == e2 ? t2.getRootNode().host || null : e2;
383
+ }, o$1 = (t3, e2, n2, o2, l2, r2, i, s) => r2 < t3 && i > e2 || r2 > t3 && i < e2 ? 0 : r2 <= t3 && s <= n2 || i >= e2 && s >= n2 ? r2 - t3 - o2 : i > e2 && s < n2 || r2 < t3 && s > n2 ? i - e2 + l2 : 0, l = (t3) => {
384
+ const e2 = t3.parentElement;
385
+ return null == e2 ? t3.getRootNode().host || null : e2;
385
386
  }, r = (e2, r2) => {
386
387
  var i, s, d, h2;
387
388
  if ("undefined" == typeof document) return [];
388
- const { scrollMode: c, block: f, inline: u, boundary: a, skipOverflowHiddenElements: g } = r2, p = "function" == typeof a ? a : (t2) => t2 !== a;
389
- if (!t(e2)) throw new TypeError("Invalid target");
389
+ const { scrollMode: c, block: f, inline: u, boundary: a, skipOverflowHiddenElements: g } = r2, p = "function" == typeof a ? a : (t3) => t3 !== a;
390
+ if (!t2(e2)) throw new TypeError("Invalid target");
390
391
  const m = document.scrollingElement || document.documentElement, w = [];
391
392
  let W = e2;
392
- for (; t(W) && p(W); ) {
393
+ for (; t2(W) && p(W); ) {
393
394
  if (W = l(W), W === m) {
394
395
  w.push(W);
395
396
  break;
396
397
  }
397
398
  null != W && W === document.body && n(W) && !n(document.documentElement) || null != W && n(W, g) && w.push(W);
398
399
  }
399
- const b = null != (s = null == (i = window.visualViewport) ? void 0 : i.width) ? s : innerWidth, H = null != (h2 = null == (d = window.visualViewport) ? void 0 : d.height) ? h2 : innerHeight, { scrollX: y, scrollY: M } = window, { height: v, width: E, top: x, right: C, bottom: I, left: R } = e2.getBoundingClientRect(), { top: T, right: B, bottom: F, left: V } = ((t2) => {
400
- const e3 = window.getComputedStyle(t2);
400
+ const b = null != (s = null == (i = window.visualViewport) ? void 0 : i.width) ? s : innerWidth, H = null != (h2 = null == (d = window.visualViewport) ? void 0 : d.height) ? h2 : innerHeight, { scrollX: y, scrollY: M } = window, { height: v, width: E, top: x, right: C, bottom: I, left: R } = e2.getBoundingClientRect(), { top: T, right: B, bottom: F, left: V } = ((t3) => {
401
+ const e3 = window.getComputedStyle(t3);
401
402
  return { top: parseFloat(e3.scrollMarginTop) || 0, right: parseFloat(e3.scrollMarginRight) || 0, bottom: parseFloat(e3.scrollMarginBottom) || 0, left: parseFloat(e3.scrollMarginLeft) || 0 };
402
403
  })(e2);
403
404
  let k = "start" === f || "nearest" === f ? x - T : "end" === f ? I + F : x + v / 2 - T + F, D = "center" === u ? R + E / 2 - V + B : "end" === u ? C + B : R - V;
404
405
  const L = [];
405
- for (let t2 = 0; t2 < w.length; t2++) {
406
- const e3 = w[t2], { height: n2, width: l2, top: r3, right: i2, bottom: s2, left: d2 } = e3.getBoundingClientRect();
406
+ for (let t3 = 0; t3 < w.length; t3++) {
407
+ const e3 = w[t3], { height: n2, width: l2, top: r3, right: i2, bottom: s2, left: d2 } = e3.getBoundingClientRect();
407
408
  if ("if-needed" === c && x >= 0 && R >= 0 && I <= H && C <= b && x >= r3 && I <= s2 && R >= d2 && C <= i2) return L;
408
409
  const h3 = getComputedStyle(e3), a2 = parseInt(h3.borderLeftWidth, 10), g2 = parseInt(h3.borderTopWidth, 10), p2 = parseInt(h3.borderRightWidth, 10), W2 = parseInt(h3.borderBottomWidth, 10);
409
410
  let T2 = 0, B2 = 0;
@@ -411,32 +412,32 @@ const t = (t2) => "object" == typeof t2 && null != t2 && 1 === t2.nodeType, e$1
411
412
  if (m === e3) T2 = "start" === f ? k : "end" === f ? k - H : "nearest" === f ? o$1(M, M + H, H, g2, W2, M + k, M + k + v, v) : k - H / 2, B2 = "start" === u ? D : "center" === u ? D - b / 2 : "end" === u ? D - b : o$1(y, y + b, b, a2, p2, y + D, y + D + E, E), T2 = Math.max(0, T2 + M), B2 = Math.max(0, B2 + y);
412
413
  else {
413
414
  T2 = "start" === f ? k - r3 - g2 : "end" === f ? k - s2 + W2 + V2 : "nearest" === f ? o$1(r3, s2, n2, g2, W2 + V2, k, k + v, v) : k - (r3 + n2 / 2) + V2 / 2, B2 = "start" === u ? D - d2 - a2 : "center" === u ? D - (d2 + l2 / 2) + F2 / 2 : "end" === u ? D - i2 + p2 + F2 : o$1(d2, i2, l2, a2, p2 + F2, D, D + E, E);
414
- const { scrollLeft: t3, scrollTop: h4 } = e3;
415
- T2 = 0 === X ? 0 : Math.max(0, Math.min(h4 + T2 / X, e3.scrollHeight - n2 / X + V2)), B2 = 0 === S ? 0 : Math.max(0, Math.min(t3 + B2 / S, e3.scrollWidth - l2 / S + F2)), k += h4 - T2, D += t3 - B2;
415
+ const { scrollLeft: t4, scrollTop: h4 } = e3;
416
+ T2 = 0 === X ? 0 : Math.max(0, Math.min(h4 + T2 / X, e3.scrollHeight - n2 / X + V2)), B2 = 0 === S ? 0 : Math.max(0, Math.min(t4 + B2 / S, e3.scrollWidth - l2 / S + F2)), k += h4 - T2, D += t4 - B2;
416
417
  }
417
418
  L.push({ el: e3, top: T2, left: B2 });
418
419
  }
419
420
  return L;
420
421
  };
421
- const o = (t2) => false === t2 ? { block: "end", inline: "nearest" } : ((t3) => t3 === Object(t3) && 0 !== Object.keys(t3).length)(t2) ? t2 : { block: "start", inline: "nearest" };
422
+ const o = (t3) => false === t3 ? { block: "end", inline: "nearest" } : ((t4) => t4 === Object(t4) && 0 !== Object.keys(t4).length)(t3) ? t3 : { block: "start", inline: "nearest" };
422
423
  function e(e2, r$1) {
423
- if (!e2.isConnected || !((t2) => {
424
- let o2 = t2;
424
+ if (!e2.isConnected || !((t3) => {
425
+ let o2 = t3;
425
426
  for (; o2 && o2.parentNode; ) {
426
427
  if (o2.parentNode === document) return true;
427
428
  o2 = o2.parentNode instanceof ShadowRoot ? o2.parentNode.host : o2.parentNode;
428
429
  }
429
430
  return false;
430
431
  })(e2)) return;
431
- const n2 = ((t2) => {
432
- const o2 = window.getComputedStyle(t2);
432
+ const n2 = ((t3) => {
433
+ const o2 = window.getComputedStyle(t3);
433
434
  return { top: parseFloat(o2.scrollMarginTop) || 0, right: parseFloat(o2.scrollMarginRight) || 0, bottom: parseFloat(o2.scrollMarginBottom) || 0, left: parseFloat(o2.scrollMarginLeft) || 0 };
434
435
  })(e2);
435
- if (((t2) => "object" == typeof t2 && "function" == typeof t2.behavior)(r$1)) return r$1.behavior(r(e2, r$1));
436
+ if (((t3) => "object" == typeof t3 && "function" == typeof t3.behavior)(r$1)) return r$1.behavior(r(e2, r$1));
436
437
  const l2 = "boolean" == typeof r$1 || null == r$1 ? void 0 : r$1.behavior;
437
438
  for (const { el: a, top: i, left: s } of r(e2, o(r$1))) {
438
- const t2 = i - n2.top + n2.bottom, o2 = s - n2.left + n2.right;
439
- a.scroll({ top: t2, left: o2, behavior: l2 });
439
+ const t3 = i - n2.top + n2.bottom, o2 = s - n2.left + n2.right;
440
+ a.scroll({ top: t3, left: o2, behavior: l2 });
440
441
  }
441
442
  }
442
443
  const isEventHandled = (event, handler) => {
@@ -1773,6 +1774,7 @@ export {
1773
1774
  Slate,
1774
1775
  defaultRenderLeaf,
1775
1776
  defaultRenderPlaceHolder,
1777
+ t as toRawWeakMap,
1776
1778
  useComposing,
1777
1779
  useEditor,
1778
1780
  useFocused,
@@ -3,7 +3,6 @@ export { withDOM } from './plugin/with-dom';
3
3
  export { applyStringDiff, normalizeStringDiff } from './utils/diff-text';
4
4
  export type { StringDiff, TextDiff } from './utils/diff-text';
5
5
  export { getActiveElement, getDefaultView, getSelection, hasShadowRoot, isAfter, isBefore, isDOMElement, isDOMNode, isDOMSelection, isPlainTextOnlyPaste, isTrackedMutation, normalizeDOMPoint, } from './utils/dom';
6
- export type { DOMPoint } from './utils/dom';
7
6
  export { CAN_USE_DOM, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_CHROME, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_IOS, IS_WEBKIT, IS_UC_MOBILE, IS_WECHATBROWSER, } from './utils/environment';
8
7
  export { Hotkeys } from './utils/hotkeys';
9
8
  export { Key } from './utils/key';
@@ -1,10 +1,13 @@
1
1
  import { BaseEditor, Node, Path, Point, Range } from '../../slate/index.ts';
2
- import { DOMPoint } from '../utils/dom';
3
2
  import { Key } from '../utils/key';
4
3
  type DOMNode = globalThis.Node;
5
4
  type DOMRange = globalThis.Range;
6
5
  type DOMSelection = globalThis.Selection;
7
6
  type DOMStaticRange = globalThis.StaticRange;
7
+ type DOMPoint = [globalThis.Node, number];
8
+ /**
9
+ * A DOM-specific version of the `Editor` interface.
10
+ */
8
11
  export interface DOMEditor extends BaseEditor {
9
12
  hasEditableTarget: (editor: DOMEditor, target: EventTarget | null) => target is DOMNode;
10
13
  hasRange: (editor: DOMEditor, range: Range) => boolean;
@@ -11,7 +11,6 @@ declare global {
11
11
  Node: (typeof Node)['constructor'];
12
12
  }
13
13
  }
14
- export type DOMPoint = [Node, number];
15
14
  /**
16
15
  * Returns the host window of a DOM node
17
16
  */
@@ -43,6 +42,7 @@ export declare const isPlainTextOnlyPaste: (event: ClipboardEvent) => boolean |
43
42
  /**
44
43
  * Normalize a DOM point so that it always refers to a text node.
45
44
  */
45
+ type DOMPoint = [DOMNode, number];
46
46
  export declare const normalizeDOMPoint: (domPoint: DOMPoint) => DOMPoint;
47
47
  /**
48
48
  * Determines whether the active element is nested within a shadowRoot
@@ -10,3 +10,4 @@ export { useSelected } from './hooks/use-selected';
10
10
  export { useEditor } from './hooks/use-editor';
11
11
  export { useSelection } from './hooks/use-selection';
12
12
  export { useInheritRef } from './hooks/use-inherit-ref';
13
+ export { toRawWeakMap } from '../share-tools/index.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slate-vue3",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -87,7 +87,7 @@
87
87
  "remark-slate-transformer": "^0.9.0",
88
88
  "typescript": "~5.8.2",
89
89
  "unified": "^11.0.5",
90
- "vite": "^6.2.3",
90
+ "vite": "^6.2.5",
91
91
  "vite-plugin-dts": "^4.5.0",
92
92
  "vitest": "^3.0.5",
93
93
  "vue-router": "^4.5.0",