slate-vue3 0.0.28 → 0.0.30

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.
Files changed (2) hide show
  1. package/dist/index.js +36 -22
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -5761,7 +5761,7 @@ const DOMEditor = {
5761
5761
  return { path: path2, offset };
5762
5762
  },
5763
5763
  toSlateRange: (editor, domRange, options) => {
5764
- var _a2;
5764
+ var _a2, _b2;
5765
5765
  const { exactMatch, suppressThrow } = options;
5766
5766
  const el = isDOMSelection(domRange) ? domRange.anchorNode : domRange.startContainer;
5767
5767
  let anchorNode;
@@ -5776,18 +5776,18 @@ const DOMEditor = {
5776
5776
  focusNode = domRange.focusNode;
5777
5777
  focusOffset = domRange.focusOffset;
5778
5778
  if (IS_FIREFOX) {
5779
- const attributes = anchorNode instanceof HTMLElement ? anchorNode.attributes : null;
5780
- if (attributes && attributes.getNamedItem("data-slate-editor")) {
5781
- while (anchorNode == null ? void 0 : anchorNode.firstElementChild) {
5779
+ const anchorAttr = anchorNode instanceof HTMLElement ? anchorNode.attributes : null;
5780
+ if (anchorAttr == null ? void 0 : anchorAttr.getNamedItem("data-slate-editor")) {
5781
+ while (anchorNode instanceof HTMLElement && anchorNode.firstElementChild) {
5782
5782
  anchorNode = anchorNode.firstElementChild;
5783
5783
  }
5784
- while (focusNode == null ? void 0 : focusNode.lastElementChild) {
5784
+ while (focusNode instanceof HTMLElement && focusNode.lastElementChild) {
5785
5785
  focusNode = focusNode.lastElementChild;
5786
5786
  }
5787
- anchorNode = anchorNode.firstChild;
5787
+ anchorNode = anchorNode == null ? void 0 : anchorNode.firstChild;
5788
5788
  anchorOffset = 0;
5789
- focusNode = focusNode.lastChild;
5790
- focusOffset = focusNode.length;
5789
+ focusNode = focusNode == null ? void 0 : focusNode.lastChild;
5790
+ focusOffset = ((_a2 = focusNode == null ? void 0 : focusNode.textContent) == null ? void 0 : _a2.length) || 0;
5791
5791
  } else {
5792
5792
  if (anchorNode) {
5793
5793
  const [el2, offset] = getFirefoxNodeEl(anchorNode, anchorOffset);
@@ -5834,7 +5834,7 @@ const DOMEditor = {
5834
5834
  `Cannot resolve a Slate range from DOM range: ${domRange}`
5835
5835
  );
5836
5836
  }
5837
- if (IS_FIREFOX && ((_a2 = focusNode.textContent) == null ? void 0 : _a2.endsWith("\n\n")) && focusOffset === focusNode.textContent.length) {
5837
+ if (IS_FIREFOX && ((_b2 = focusNode.textContent) == null ? void 0 : _b2.endsWith("\n\n")) && focusOffset === focusNode.textContent.length) {
5838
5838
  focusOffset--;
5839
5839
  }
5840
5840
  const anchor = DOMEditor.toSlatePoint(editor, [anchorNode, anchorOffset], {
@@ -7325,6 +7325,15 @@ function createAndroidInputManager({
7325
7325
  handleInput
7326
7326
  };
7327
7327
  }
7328
+ const useEditor = () => {
7329
+ const editor = inject(SLATE_USE_EDITOR);
7330
+ if (editor === void 0) {
7331
+ throw new Error(
7332
+ `The \`useEditor\` hook must be used inside the <Slate> component's context.`
7333
+ );
7334
+ }
7335
+ return editor;
7336
+ };
7328
7337
  const MUTATION_OBSERVER_CONFIG$1 = {
7329
7338
  subtree: true,
7330
7339
  childList: true,
@@ -7334,7 +7343,7 @@ const useAndroidInputManager = !IS_ANDROID ? () => null : ({ node: node2, ...opt
7334
7343
  if (!IS_ANDROID) {
7335
7344
  return null;
7336
7345
  }
7337
- const editor = inject("editorRef");
7346
+ const editor = useEditor();
7338
7347
  const isMounted = ref(false);
7339
7348
  onMounted(() => isMounted.value = true);
7340
7349
  onUnmounted(() => isMounted.value = false);
@@ -7374,15 +7383,6 @@ const useDecorate = () => {
7374
7383
  }
7375
7384
  return decorate;
7376
7385
  };
7377
- const useEditor = () => {
7378
- const editor = inject(SLATE_USE_EDITOR);
7379
- if (editor === void 0) {
7380
- throw new Error(
7381
- `The \`useEditor\` hook must be used inside the <Slate> component's context.`
7382
- );
7383
- }
7384
- return editor;
7385
- };
7386
7386
  const StringComp = defineComponent({
7387
7387
  name: "slate-string",
7388
7388
  props: ["isLast", "leaf", "element", "text"],
@@ -8009,6 +8009,7 @@ const Editable = defineComponent({
8009
8009
  const placeholderHeight = ref();
8010
8010
  const onPlaceholderResize = (h2) => placeholderHeight.value = h2;
8011
8011
  const androidInputManagerRef = ref(null);
8012
+ const processing = ref(false);
8012
8013
  const onDOMSelectionChange = (event) => {
8013
8014
  const target = event == null ? void 0 : event.target;
8014
8015
  const targetElement = target instanceof HTMLElement ? target : null;
@@ -8018,7 +8019,8 @@ const Editable = defineComponent({
8018
8019
  }
8019
8020
  const el = DOMEditor.toDOMNode(editor, editor);
8020
8021
  const root2 = el.getRootNode();
8021
- if (IS_WEBKIT && root2 instanceof ShadowRoot) {
8022
+ if (!processing.value && IS_WEBKIT && root2 instanceof ShadowRoot) {
8023
+ processing.value = true;
8022
8024
  const active = getActiveElement();
8023
8025
  if (active) {
8024
8026
  document.execCommand("indent");
@@ -8216,17 +8218,29 @@ const Editable = defineComponent({
8216
8218
  if (HAS_BEFORE_INPUT_SUPPORT) {
8217
8219
  const el = DOMEditor.toDOMNode(editor, editor);
8218
8220
  const root2 = el.getRootNode();
8219
- if (IS_WEBKIT && root2 instanceof ShadowRoot) {
8221
+ if (processing.value && IS_WEBKIT && root2 instanceof ShadowRoot) {
8220
8222
  const ranges = event.getTargetRanges();
8221
8223
  const range2 = ranges[0];
8222
8224
  const newRange = new window.Range();
8225
+ let endContainer = range2.endContainer;
8226
+ let endOffset = range2.endOffset;
8227
+ if (endContainer.nodeType === 3 && endContainer.textContent === "" && endContainer.previousSibling) {
8228
+ endContainer = endContainer.previousSibling;
8229
+ }
8230
+ while (endContainer instanceof HTMLElement && !endContainer.attributes.getNamedItem("data-slate-string") && endContainer.lastElementChild) {
8231
+ endContainer = endContainer.lastElementChild;
8232
+ }
8233
+ if (endContainer instanceof HTMLElement && endContainer.attributes.getNamedItem("data-slate-string") && endContainer.lastChild) {
8234
+ endContainer = endContainer.lastChild;
8235
+ }
8223
8236
  newRange.setStart(range2.startContainer, range2.startOffset);
8224
- newRange.setEnd(range2.endContainer, range2.endOffset);
8237
+ newRange.setEnd(endContainer, endOffset);
8225
8238
  const slateRange = DOMEditor.toSlateRange(editor, newRange, {
8226
8239
  exactMatch: false,
8227
8240
  suppressThrow: false
8228
8241
  });
8229
8242
  Transforms.select(editor, slateRange);
8243
+ processing.value = false;
8230
8244
  event.preventDefault();
8231
8245
  event.stopImmediatePropagation();
8232
8246
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slate-vue3",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "build": "vite build",
16
16
  "preview": "vite preview",
17
17
  "build-all": "vite build --mode=lib",
18
- "e2e": "playwright test",
18
+ "e2e": "node --no-experimental-strip-types node_modules/@playwright/test/cli.js test",
19
19
  "e2e-ui": "playwright test --ui",
20
20
  "test": "vitest"
21
21
  },