slate-vue3 0.1.6 → 0.2.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.
package/dist/index.js
CHANGED
|
@@ -12,7 +12,6 @@ const SLATE_INNER_RENDER_ELEMENT = Symbol("SLATE_INNER_RENDER_ELEMENT");
|
|
|
12
12
|
const SLATE_INNER_RENDER_LEAF = Symbol("SLATE_INNER_RENDER_LEAF");
|
|
13
13
|
const SLATE_INNER_RENDER_PLACEHOLDER = Symbol("SLATE_INNER_RENDER_PLACEHOLDER");
|
|
14
14
|
const SLATE_INNER_CHANGE_EFFECT_INJECT = Symbol("SLATE_INNER_CHANGE_EFFECT_INJECT");
|
|
15
|
-
const SLATE_INNER_DESCORATION = Symbol("SLATE_INNER_DESCORATION");
|
|
16
15
|
const Slate = defineComponent({
|
|
17
16
|
name: "slate-editor",
|
|
18
17
|
emits: ["change", "selectionchange", "valuechange"],
|
|
@@ -189,17 +188,6 @@ const useChangeEffect = (fn) => {
|
|
|
189
188
|
watch(() => CHANGE_EFFECT_INJECT.value, fn);
|
|
190
189
|
return CHANGE_EFFECT_INJECT;
|
|
191
190
|
};
|
|
192
|
-
const useParentDescoration = () => {
|
|
193
|
-
const PARENT_DESCORATION = inject(
|
|
194
|
-
SLATE_INNER_DESCORATION
|
|
195
|
-
);
|
|
196
|
-
if (PARENT_DESCORATION === void 0) {
|
|
197
|
-
throw new Error(
|
|
198
|
-
`The \`useParentDescoration\` hook must be used inside the <Slate> component's context.`
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
return PARENT_DESCORATION;
|
|
202
|
-
};
|
|
203
191
|
const TextComp = defineComponent({
|
|
204
192
|
name: "slate-text",
|
|
205
193
|
props: ["text", "element"],
|
|
@@ -208,9 +196,9 @@ const TextComp = defineComponent({
|
|
|
208
196
|
const editor = useEditor();
|
|
209
197
|
const spanRef = ref();
|
|
210
198
|
const decorate = useDecorate();
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
const
|
|
199
|
+
const leaves = computed(() => {
|
|
200
|
+
const elemPath = DOMEditor.findPath(editor, element);
|
|
201
|
+
const elemDs = decorate([element, elemPath]);
|
|
214
202
|
if (editor.selection && Range.isCollapsed(editor.selection) && editor.marks) {
|
|
215
203
|
const anchor = editor.selection.anchor;
|
|
216
204
|
const leaf = Node.leaf(editor, anchor.path);
|
|
@@ -219,7 +207,7 @@ const TextComp = defineComponent({
|
|
|
219
207
|
const unset = Object.fromEntries(
|
|
220
208
|
Object.keys(rest).map((mark) => [mark, null])
|
|
221
209
|
);
|
|
222
|
-
|
|
210
|
+
elemDs.push({
|
|
223
211
|
[MARK_PLACEHOLDER_SYMBOL]: true,
|
|
224
212
|
...unset,
|
|
225
213
|
...editor.marks,
|
|
@@ -228,16 +216,13 @@ const TextComp = defineComponent({
|
|
|
228
216
|
});
|
|
229
217
|
}
|
|
230
218
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const ds = decorate([text, path]);
|
|
237
|
-
decorations.value.forEach((dec) => {
|
|
238
|
-
ds.push(Range.intersection(dec, range));
|
|
219
|
+
const textPath = DOMEditor.findPath(editor, text);
|
|
220
|
+
const range = Editor.range(editor, textPath);
|
|
221
|
+
const textDs = decorate([text, textPath]);
|
|
222
|
+
elemDs.forEach((dec) => {
|
|
223
|
+
textDs.push(Range.intersection(dec, range));
|
|
239
224
|
});
|
|
240
|
-
const filterDs =
|
|
225
|
+
const filterDs = textDs.filter(Boolean);
|
|
241
226
|
return Text.decorations(text, filterDs.length ? filterDs : []);
|
|
242
227
|
});
|
|
243
228
|
onMounted(() => {
|
|
@@ -364,18 +349,6 @@ const ElementComp = defineComponent({
|
|
|
364
349
|
const tag = isInline.value ? "span" : "div";
|
|
365
350
|
return h(tag, VOID_CHILDREN_ATTRS, h(TextComp, { element, text }));
|
|
366
351
|
});
|
|
367
|
-
const decorate = useDecorate();
|
|
368
|
-
const parentDs = useParentDescoration();
|
|
369
|
-
const provideDs = computed(() => {
|
|
370
|
-
const path = DOMEditor.findPath(editor, element);
|
|
371
|
-
const ds = decorate([props.element, path]);
|
|
372
|
-
const range = Editor.range(editor, path);
|
|
373
|
-
parentDs.value.forEach((dec) => {
|
|
374
|
-
ds.push(Range.intersection(dec, range));
|
|
375
|
-
});
|
|
376
|
-
return ds;
|
|
377
|
-
});
|
|
378
|
-
provide(SLATE_INNER_DESCORATION, provideDs);
|
|
379
352
|
const renderElement = useRenderElement();
|
|
380
353
|
return () => renderElement({
|
|
381
354
|
attributes: attributes.value,
|
|
@@ -1713,9 +1686,6 @@ const Editable = defineComponent({
|
|
|
1713
1686
|
const autocapitalize = computed(
|
|
1714
1687
|
() => HAS_BEFORE_INPUT_SUPPORT || !CAN_USE_DOM ? attributes.autocapitalize : void 0
|
|
1715
1688
|
);
|
|
1716
|
-
const decorate = useDecorate();
|
|
1717
|
-
const descProvide = computed(() => decorate([editor, []]));
|
|
1718
|
-
provide(SLATE_INNER_DESCORATION, descProvide);
|
|
1719
1689
|
return () => h(
|
|
1720
1690
|
is,
|
|
1721
1691
|
{
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ref, VNode } from 'vue';
|
|
2
2
|
import { RenderElementProps, RenderPlaceholderProps, RenderLeafProps } from '../utils/interface';
|
|
3
|
-
import { DecoratedRange } from '../../slate/index.ts';
|
|
4
3
|
export declare const useRenderElement: () => (props: RenderElementProps) => VNode;
|
|
5
4
|
export declare const useRenderLeaf: () => (props: RenderLeafProps) => VNode;
|
|
6
5
|
export declare const useRenderPlaceholder: () => (props: RenderPlaceholderProps) => VNode;
|
|
7
6
|
export declare const useChangeEffect: (fn: () => void) => Ref<number, number>;
|
|
8
|
-
export declare const useParentDescoration: () => ComputedRef<DecoratedRange[]>;
|
|
@@ -10,4 +10,3 @@ export declare const SLATE_INNER_RENDER_ELEMENT: unique symbol;
|
|
|
10
10
|
export declare const SLATE_INNER_RENDER_LEAF: unique symbol;
|
|
11
11
|
export declare const SLATE_INNER_RENDER_PLACEHOLDER: unique symbol;
|
|
12
12
|
export declare const SLATE_INNER_CHANGE_EFFECT_INJECT: unique symbol;
|
|
13
|
-
export declare const SLATE_INNER_DESCORATION: unique symbol;
|