slate-vue3 0.4.2 → 0.5.1

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/history.js CHANGED
@@ -156,7 +156,7 @@ const withHistory = (editor) => {
156
156
  if (merge == null) {
157
157
  if (lastBatch == null) {
158
158
  merge = false;
159
- } else if (operations.length !== 0) {
159
+ } else if (operations.includes(lastOp)) {
160
160
  merge = true;
161
161
  } else {
162
162
  merge = shouldMerge(op, lastOp);
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SLATE_USE_SELECTED, a as SLATE_STATE_SELECTION } from "./use-focused-De6S1bT0.js";
2
- import { g, D, c, e, f, d, E, b, u, j, h, i } from "./use-focused-De6S1bT0.js";
1
+ import { S as SLATE_USE_SELECTED, a as SLATE_STATE_SELECTION } from "./use-focused-BERGv09e.js";
2
+ import { g, D, c, e, f, d, E, b, u, j, h, i } from "./use-focused-BERGv09e.js";
3
3
  import { inject } from "vue";
4
4
  import { t } from "./batch-dirty-paths-DGoKWQz8.js";
5
5
  const useSelected = () => {
@@ -1,10 +1,4 @@
1
1
  import { VNode } from 'vue';
2
- export declare const PlaceholderComp: import('vue').DefineComponent<{
3
- placeholder?: string | undefined;
4
- onPlaceholderResize: (height?: number) => void;
5
- }, () => false | "" | VNode<import('vue').RendererNode, import('vue').RendererElement, {
2
+ export declare const PlaceholderComp: import('vue').DefineComponent<{}, () => VNode<import('vue').RendererNode, import('vue').RendererElement, {
6
3
  [key: string]: any;
7
- }> | undefined, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{
8
- placeholder?: string | undefined;
9
- onPlaceholderResize: (height?: number) => void;
10
- }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
4
+ }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
@@ -18,7 +18,7 @@ export declare const handleNativeHistoryEvents: (editor: Editor, event: InputEve
18
18
  * A default implement to scroll dom range into view.
19
19
  */
20
20
  export declare const DEFAULT_SCROLL_INTO_VIEW: (editor: DOMEditor, domRange: globalThis.Range) => void;
21
- export declare const DEFAULT_ELEMENT_RENDER: ({ attributes, children, }: RenderElementProps) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
21
+ export declare const DEFAULT_ELEMENT_RENDER: ({ element, attributes, children, editor, }: RenderElementProps) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
22
22
  [key: string]: any;
23
23
  }>;
24
24
  export declare const DEFAULT_LEAF_RENDER: ({ attributes, children, }: RenderLeafProps) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
@@ -10,3 +10,6 @@ export declare const useMarkPlaceholder: () => ComputedRef<{
10
10
  anchor: BasePoint;
11
11
  focus: BasePoint;
12
12
  } | null>;
13
+ export declare const usePlaceholder: () => ComputedRef<string>;
14
+ export declare const usePlaceholderShow: () => ComputedRef<boolean>;
15
+ export declare const usePlaceholderResize: () => (height?: number) => {};
@@ -1,4 +1,4 @@
1
- export type { RenderElementProps, RenderLeafProps, RenderPlaceholderProps, } from './utils/interface';
1
+ export type { RenderElementProps, RenderLeafProps, RenderPlaceholderProps, RenderTextProps, } from './utils/interface';
2
2
  export { Slate } from './components/slate';
3
3
  export { Editable } from './components/editable';
4
4
  export { DEFAULT_ELEMENT_RENDER, DEFAULT_LEAF_RENDER, DEFAULT_TEXT_RENDER, DEFAULT_PLACEHOLDER_RENDER, DEFAULT_SCROLL_INTO_VIEW, DEFAULT_DECORATE_FN, } from './components/utils';
@@ -12,3 +12,6 @@ export declare const SLATE_INNER_RENDER_PLACEHOLDER: unique symbol;
12
12
  export declare const SLATE_INNER_RENDER_TEXT: unique symbol;
13
13
  export declare const SLATE_INNER_CHANGE_EFFECT_INJECT: unique symbol;
14
14
  export declare const SLATE_INNER_MARK_PLACEHOLDER: unique symbol;
15
+ export declare const SLATE_INNER_PLACEHOLDER: unique symbol;
16
+ export declare const SLATE_INNER_PLACEHOLDER_SHOW: unique symbol;
17
+ export declare const SLATE_INNER_PLACEHOLDER_RESIZE: unique symbol;
@@ -1,5 +1,5 @@
1
- import { Text, Element, LeafPosition } from '../../slate/index.ts';
2
- import { HTMLAttributes, VNode, VNodeChild, VNodeProps, VNodeRef } from 'vue';
1
+ import { Text, Element, LeafPosition, Editor } from '../../slate/index.ts';
2
+ import { HTMLAttributes, VNode, VNodeArrayChildren, VNodeChild, VNodeProps, VNodeRef } from 'vue';
3
3
  /**
4
4
  * The props that get passed to renderPlaceholder
5
5
  */
@@ -14,7 +14,7 @@ export interface RenderPlaceholderProps {
14
14
  * `RenderLeafProps` are passed to the `renderLeaf` handler.
15
15
  */
16
16
  export interface RenderLeafProps {
17
- children: VNode;
17
+ children: VNodeArrayChildren;
18
18
  /**
19
19
  * The leaf node with any applied decorations.
20
20
  * If no decorations are applied, it will be identical to the `text` property.
@@ -42,6 +42,7 @@ export interface RenderElementProps {
42
42
  dir?: "rtl";
43
43
  ref: VNodeRef;
44
44
  };
45
+ editor?: Editor;
45
46
  }
46
47
  /**
47
48
  * `RenderTextProps` are passed to the `renderText` handler.
@@ -1,6 +1,6 @@
1
- import { h, defineComponent, provide, ref, computed, onMounted, onUnmounted, renderSlot, inject, watch, renderList, Fragment, useAttrs, reactive, toRaw } from "vue";
1
+ import { h, defineComponent, provide, ref, computed, onMounted, onUnmounted, renderSlot, inject, watch, nextTick, renderList, Fragment, useAttrs, reactive, toRaw } from "vue";
2
2
  import { R as Range, N as Node, S as Scrubber, T as Text, P as Path, E as Editor, a as Element, c as Transforms } from "./batch-dirty-paths-DGoKWQz8.js";
3
- import { I as IS_ANDROID, p as isDOMNode, D as DOMEditor, P as MARK_PLACEHOLDER_SYMBOL, d as EDITOR_TO_ON_CHANGE, 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, 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, r as isPlainTextOnlyPaste, L as IS_COMPOSING, B as Hotkeys, u as IS_CHROME, v as IS_FIREFOX, w as IS_FIREFOX_LEGACY, A as IS_WECHATBROWSER, z as IS_UC_MOBILE, a as EDITOR_TO_USER_MARKS, o as isDOMElement, b as EDITOR_TO_USER_SELECTION } from "./hotkeys-DdYAaAmE.js";
3
+ import { I as IS_ANDROID, p as isDOMNode, D as DOMEditor, P as MARK_PLACEHOLDER_SYMBOL, d as EDITOR_TO_ON_CHANGE, x as IS_IOS, F as EDITOR_TO_ELEMENT, y as IS_WEBKIT, 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, e as applyStringDiff, q as isDOMSelection, n as normalizeStringDiff, O as IS_READ_ONLY, h as getDefaultView, G as EDITOR_TO_WINDOW, H as HAS_BEFORE_INPUT_SUPPORT, C as CAN_USE_DOM, f as getActiveElement, j as getSelection, M as IS_FOCUSED, r as isPlainTextOnlyPaste, L as IS_COMPOSING, B as Hotkeys, u as IS_CHROME, v as IS_FIREFOX, w as IS_FIREFOX_LEGACY, A as IS_WECHATBROWSER, z as IS_UC_MOBILE, a as EDITOR_TO_USER_MARKS, o as isDOMElement, b as EDITOR_TO_USER_SELECTION } from "./hotkeys-DdYAaAmE.js";
4
4
  const SLATE_USE_EDITOR = Symbol("SLATE_USE_EDITOR");
5
5
  const SLATE_USE_DECORATE = Symbol("SLATE_USE_DECORATE");
6
6
  const SLATE_USE_SELECTED = Symbol("SLATE_USE_SELECTED");
@@ -14,6 +14,9 @@ const SLATE_INNER_RENDER_PLACEHOLDER = Symbol("SLATE_INNER_RENDER_PLACEHOLDER");
14
14
  const SLATE_INNER_RENDER_TEXT = Symbol("SLATE_INNER_RENDER_TEXT");
15
15
  const SLATE_INNER_CHANGE_EFFECT_INJECT = Symbol("SLATE_INNER_CHANGE_EFFECT_INJECT");
16
16
  const SLATE_INNER_MARK_PLACEHOLDER = Symbol("SLATE_INNER_MARK_PLACEHOLDER");
17
+ const SLATE_INNER_PLACEHOLDER = Symbol("SLATE_INNER_PLACEHOLDER");
18
+ const SLATE_INNER_PLACEHOLDER_SHOW = Symbol("SLATE_INNER_PLACEHOLDER_SHOW");
19
+ const SLATE_INNER_PLACEHOLDER_RESIZE = Symbol("SLATE_INNER_PLACEHOLDER_RESIZE");
17
20
  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) => {
18
21
  if (t2.clientHeight < t2.scrollHeight || t2.clientWidth < t2.scrollWidth) {
19
22
  const o2 = getComputedStyle(t2, null);
@@ -132,9 +135,23 @@ const DEFAULT_SCROLL_INTO_VIEW = (editor, domRange) => {
132
135
  }
133
136
  };
134
137
  const DEFAULT_ELEMENT_RENDER = ({
138
+ element,
135
139
  attributes,
136
- children
137
- }) => h("p", attributes, children);
140
+ children,
141
+ editor
142
+ }) => {
143
+ const tag = (editor == null ? void 0 : editor.isInline(element)) ? "span" : "div";
144
+ return h(
145
+ tag,
146
+ {
147
+ ...attributes,
148
+ style: {
149
+ position: "relative"
150
+ }
151
+ },
152
+ children
153
+ );
154
+ };
138
155
  const DEFAULT_LEAF_RENDER = ({
139
156
  attributes,
140
157
  children
@@ -299,10 +316,11 @@ const StringComp = defineComponent({
299
316
  }
300
317
  return null;
301
318
  });
302
- return () => zeroStringAttrs.value ? h("span", zeroStringAttrs.value, [
303
- !(IS_ANDROID || IS_IOS) || !isLineBreak.value ? "\uFEFF" : null,
304
- isLineBreak.value ? h("br") : null
305
- ]) : h("span", { "data-slate-string": true }, getTextContent.value);
319
+ return () => zeroStringAttrs.value ? h(
320
+ "span",
321
+ zeroStringAttrs.value,
322
+ (IS_ANDROID || IS_IOS) && isLineBreak.value ? h("br") : "\uFEFF"
323
+ ) : h("span", { "data-slate-string": true }, getTextContent.value);
306
324
  }
307
325
  });
308
326
  const useRenderElement = () => {
@@ -370,6 +388,98 @@ const useMarkPlaceholder = () => {
370
388
  }
371
389
  return MARK_PLACEHOLDER_INJECT;
372
390
  };
391
+ const usePlaceholder = () => {
392
+ const PLACEHOLDER_INJECT = inject(
393
+ SLATE_INNER_PLACEHOLDER
394
+ );
395
+ if (PLACEHOLDER_INJECT === void 0) {
396
+ throw new Error(
397
+ `The \`usePlaceholder\` hook must be used inside the <Slate> component's context.`
398
+ );
399
+ }
400
+ return PLACEHOLDER_INJECT;
401
+ };
402
+ const usePlaceholderShow = () => {
403
+ const PLACEHOLDER_SHOW_INJECT = inject(
404
+ SLATE_INNER_PLACEHOLDER_SHOW
405
+ );
406
+ if (PLACEHOLDER_SHOW_INJECT === void 0) {
407
+ throw new Error(
408
+ `The \`usePlaceholderShow\` hook must be used inside the <Slate> component's context.`
409
+ );
410
+ }
411
+ return PLACEHOLDER_SHOW_INJECT;
412
+ };
413
+ const usePlaceholderResize = () => {
414
+ const PLACEHOLDER_RESIZE_INJECT = inject(
415
+ SLATE_INNER_PLACEHOLDER_RESIZE
416
+ );
417
+ if (PLACEHOLDER_RESIZE_INJECT === void 0) {
418
+ throw new Error(
419
+ `The \`usePlaceholderResize\` hook must be used inside the <Slate> component's context.`
420
+ );
421
+ }
422
+ return PLACEHOLDER_RESIZE_INJECT;
423
+ };
424
+ const style = {
425
+ position: "absolute",
426
+ top: 0,
427
+ pointerEvents: "none",
428
+ width: "100%",
429
+ maxWidth: "100%",
430
+ display: "block",
431
+ opacity: "0.333",
432
+ userSelect: "none",
433
+ textDecoration: "none",
434
+ // Fixes https://github.com/udecode/plate/issues/2315
435
+ WebkitUserModify: IS_WEBKIT ? "inherit" : void 0
436
+ };
437
+ const PlaceholderComp = defineComponent({
438
+ name: "slate-placeholder",
439
+ setup() {
440
+ const placeholder = usePlaceholder();
441
+ const onPlaceholderResize = usePlaceholderResize();
442
+ const placeholderResizeObserver = ref();
443
+ const attributes = computed(() => ({
444
+ "data-slate-placeholder": true,
445
+ style,
446
+ contenteditable: false,
447
+ onVnodeMounted(vNode) {
448
+ if (vNode.el) {
449
+ placeholderResizeObserver.value = new ResizeObserver(() => {
450
+ var _a, _b;
451
+ onPlaceholderResize((_b = (_a = vNode.el) == null ? void 0 : _a.getBoundingClientRect()) == null ? void 0 : _b.height);
452
+ });
453
+ placeholderResizeObserver.value.observe(vNode.el);
454
+ }
455
+ },
456
+ onVnodeUnmounted() {
457
+ var _a;
458
+ (_a = placeholderResizeObserver.value) == null ? void 0 : _a.disconnect();
459
+ placeholderResizeObserver.value = void 0;
460
+ onPlaceholderResize();
461
+ }
462
+ }));
463
+ const renderPlaceholder = useRenderPlaceholder();
464
+ const editor = useEditor();
465
+ onMounted(() => {
466
+ nextTick(() => {
467
+ const element = EDITOR_TO_ELEMENT.get(editor).querySelector(
468
+ "[data-slate-placeholder]"
469
+ );
470
+ for (const node of element.childNodes) {
471
+ if (node.nodeType === 3 && node.textContent === "") {
472
+ element.removeChild(node);
473
+ }
474
+ }
475
+ });
476
+ });
477
+ return () => renderPlaceholder({
478
+ children: placeholder.value,
479
+ attributes: attributes.value
480
+ });
481
+ }
482
+ });
373
483
  const TextComp = defineComponent({
374
484
  name: "slate-text",
375
485
  props: ["text", "element"],
@@ -419,6 +529,7 @@ const TextComp = defineComponent({
419
529
  });
420
530
  const renderLeaf = useRenderLeaf();
421
531
  const renderText = useRenderText();
532
+ const showPlaceholder = usePlaceholderShow();
422
533
  return () => renderText({
423
534
  text,
424
535
  attributes: { "data-slate-node": "text", ref: spanRef },
@@ -429,13 +540,16 @@ const TextComp = defineComponent({
429
540
  leaf: leaf.leaf,
430
541
  leafPosition: leaf.position,
431
542
  attributes: { "data-slate-leaf": true },
432
- children: h(StringComp, {
433
- text,
434
- element,
435
- leaf: leaf.leaf,
436
- isLast: isLastText.value && i === leaves.value.length - 1,
437
- key: `${text.text}-${leaf.leaf.text}-${i}`
438
- })
543
+ children: [
544
+ showPlaceholder.value && h(PlaceholderComp),
545
+ h(StringComp, {
546
+ text,
547
+ element,
548
+ leaf: leaf.leaf,
549
+ isLast: isLastText.value && i === leaves.value.length - 1,
550
+ key: `${text.text}-${leaf.leaf.text}-${i}`
551
+ })
552
+ ]
439
553
  })
440
554
  )
441
555
  });
@@ -527,7 +641,8 @@ const ElementComp = defineComponent({
527
641
  return () => renderElement({
528
642
  attributes: attributes.value,
529
643
  children: children.value,
530
- element
644
+ element,
645
+ editor
531
646
  });
532
647
  }
533
648
  });
@@ -546,61 +661,6 @@ const useComposing = () => {
546
661
  }
547
662
  return isComposing;
548
663
  };
549
- const style = {
550
- position: "absolute",
551
- top: 0,
552
- pointerEvents: "none",
553
- width: "100%",
554
- maxWidth: "100%",
555
- display: "block",
556
- opacity: "0.333",
557
- userSelect: "none",
558
- textDecoration: "none",
559
- // Fixes https://github.com/udecode/plate/issues/2315
560
- WebkitUserModify: IS_WEBKIT ? "inherit" : void 0
561
- };
562
- const PlaceholderComp = defineComponent({
563
- name: "slate-placeholder",
564
- props: ["placeholder", "onPlaceholderResize"],
565
- setup(props) {
566
- const editor = useEditor();
567
- const placeholderResizeObserver = ref();
568
- const isComposing = useComposing();
569
- const showPlaceholder = computed(
570
- () => {
571
- var _a;
572
- return props.placeholder && ((_a = editor.children) == null ? void 0 : _a.length) === 1 && Array.from(Node.texts(editor)).length === 1 && Node.string(editor) === "" && !isComposing.value;
573
- }
574
- );
575
- const attributes = computed(() => ({
576
- "data-slate-placeholder": true,
577
- style,
578
- contenteditable: false,
579
- onVnodeMounted(vNode) {
580
- if (vNode.el) {
581
- placeholderResizeObserver.value = new ResizeObserver(() => {
582
- var _a, _b;
583
- props.onPlaceholderResize(
584
- (_b = (_a = vNode.el) == null ? void 0 : _a.getBoundingClientRect()) == null ? void 0 : _b.height
585
- );
586
- });
587
- placeholderResizeObserver.value.observe(vNode.el);
588
- }
589
- },
590
- onVnodeUnmounted() {
591
- var _a;
592
- (_a = placeholderResizeObserver.value) == null ? void 0 : _a.disconnect();
593
- placeholderResizeObserver.value = void 0;
594
- props.onPlaceholderResize();
595
- }
596
- }));
597
- const renderPlaceholder = useRenderPlaceholder();
598
- return () => showPlaceholder.value && renderPlaceholder({
599
- children: props.placeholder,
600
- attributes: attributes.value
601
- });
602
- }
603
- });
604
664
  const MUTATION_OBSERVER_CONFIG = {
605
665
  subtree: true,
606
666
  childList: true,
@@ -1729,6 +1789,15 @@ const Editable = defineComponent({
1729
1789
  const autocapitalize = computed(
1730
1790
  () => HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM ? attributes.autocapitalize : void 0
1731
1791
  );
1792
+ const showPlaceholder = computed(
1793
+ () => {
1794
+ var _a;
1795
+ return props.placeholder && ((_a = editor.children) == null ? void 0 : _a.length) === 1 && Array.from(Node.texts(editor)).length === 1 && Node.string(editor) === "" && !isComposing.value;
1796
+ }
1797
+ );
1798
+ provide(SLATE_INNER_PLACEHOLDER, computed(() => placeholder));
1799
+ provide(SLATE_INNER_PLACEHOLDER_SHOW, showPlaceholder);
1800
+ provide(SLATE_INNER_PLACEHOLDER_RESIZE, onPlaceholderResize);
1732
1801
  return () => h(
1733
1802
  is,
1734
1803
  {
@@ -1761,13 +1830,7 @@ const Editable = defineComponent({
1761
1830
  onKeydown,
1762
1831
  onPaste
1763
1832
  },
1764
- [
1765
- ChildrenFC(editor, editor),
1766
- h(PlaceholderComp, {
1767
- placeholder,
1768
- onPlaceholderResize
1769
- })
1770
- ]
1833
+ ChildrenFC(editor, editor)
1771
1834
  );
1772
1835
  }
1773
1836
  });
package/dist/yjs.js CHANGED
@@ -2,7 +2,7 @@ import { d as isObject, T as Text, N as Node, P as Path, E as Editor, t as toRaw
2
2
  import { toRaw, ref, onMounted, onUnmounted, watch, onUpdated, computed } from "vue";
3
3
  import { XmlText, YTextEvent, createRelativePositionFromTypeIndex, createAbsolutePositionFromRelativePosition, createRelativePositionFromJSON, decodeRelativePosition, encodeRelativePosition, UndoManager, compareRelativePositions } from "yjs";
4
4
  import { L as Location } from "./location-H02Ot2Mm.js";
5
- import { j as useEditor, h as useFocused } from "./use-focused-De6S1bT0.js";
5
+ import { j as useEditor, h as useFocused } from "./use-focused-BERGv09e.js";
6
6
  import { D as DOMEditor } from "./hotkeys-DdYAaAmE.js";
7
7
  function deepEquals(node, another) {
8
8
  for (const key in node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slate-vue3",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",