vuewrite 0.0.17 → 0.0.19
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/vuewrite.d.ts +26 -32
- package/dist/vuewrite.js +48 -30
- package/package.json +1 -1
package/dist/vuewrite.d.ts
CHANGED
|
@@ -6,11 +6,12 @@ import { HTMLAttributes } from 'vue';
|
|
|
6
6
|
import { PropType } from 'vue';
|
|
7
7
|
import { PublicProps } from 'vue';
|
|
8
8
|
import { Ref } from 'vue';
|
|
9
|
+
import { RendererElement } from 'vue';
|
|
10
|
+
import { RendererNode } from 'vue';
|
|
11
|
+
import { VNode } from 'vue';
|
|
9
12
|
|
|
10
13
|
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
11
14
|
|
|
12
|
-
declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
|
|
13
|
-
|
|
14
15
|
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
15
16
|
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
16
17
|
type: PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
@@ -20,15 +21,6 @@ declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
|
20
21
|
};
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
declare type __VLS_TypePropsToRuntimeProps_2<T> = {
|
|
24
|
-
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
25
|
-
type: PropType<__VLS_NonUndefinedable_2<T[K]>>;
|
|
26
|
-
} : {
|
|
27
|
-
type: PropType<T[K]>;
|
|
28
|
-
required: true;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
24
|
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
33
25
|
new (): {
|
|
34
26
|
$slots: S;
|
|
@@ -221,6 +213,11 @@ declare class TextEditorStore {
|
|
|
221
213
|
removeNewLine(): void;
|
|
222
214
|
onInput(_e: Event): void;
|
|
223
215
|
addNewLine(): void;
|
|
216
|
+
addNewLineAfter(): {
|
|
217
|
+
id: string;
|
|
218
|
+
text: string;
|
|
219
|
+
styles: never[];
|
|
220
|
+
};
|
|
224
221
|
insertText(data: string): void;
|
|
225
222
|
insertBlock(blockData: Partial<Block>): void;
|
|
226
223
|
get startAndEnd(): [{
|
|
@@ -242,27 +239,24 @@ declare class TextEditorStore {
|
|
|
242
239
|
selectAll(): void;
|
|
243
240
|
}
|
|
244
241
|
|
|
245
|
-
export declare const TextEditorView: DefineComponent<
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
styles?:
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
modelValue
|
|
257
|
-
|
|
258
|
-
styles?:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
styles?: Style[] | undefined;
|
|
264
|
-
preventMultiline?: boolean | undefined;
|
|
265
|
-
}>>>, {}, {}>;
|
|
242
|
+
export declare const TextEditorView: DefineComponent<Readonly<{
|
|
243
|
+
styles?: any;
|
|
244
|
+
decorator?: any;
|
|
245
|
+
parser?: any;
|
|
246
|
+
modelValue?: any;
|
|
247
|
+
}>, () => VNode<RendererNode, RendererElement, {
|
|
248
|
+
[key: string]: any;
|
|
249
|
+
}>, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<Readonly<{
|
|
250
|
+
styles?: any;
|
|
251
|
+
decorator?: any;
|
|
252
|
+
parser?: any;
|
|
253
|
+
modelValue?: any;
|
|
254
|
+
}>>>, {
|
|
255
|
+
readonly styles?: any;
|
|
256
|
+
readonly decorator?: any;
|
|
257
|
+
readonly parser?: any;
|
|
258
|
+
readonly modelValue?: any;
|
|
259
|
+
}, {}>;
|
|
266
260
|
|
|
267
261
|
declare type TextParser = (text: string) => Style[];
|
|
268
262
|
|
package/dist/vuewrite.js
CHANGED
|
@@ -366,6 +366,12 @@ class TextEditorStore {
|
|
|
366
366
|
this.selection.focus = { blockId: block.id, offset: 0 };
|
|
367
367
|
this.history.push("setText");
|
|
368
368
|
}
|
|
369
|
+
addNewLineAfter() {
|
|
370
|
+
const index = this.blocks.findIndex((item) => item.id === this.selection.anchor.blockId);
|
|
371
|
+
const block = { id: uid(), text: "", styles: [] };
|
|
372
|
+
this.blocks.splice(index + 1, 0, block);
|
|
373
|
+
return block;
|
|
374
|
+
}
|
|
369
375
|
insertText(data) {
|
|
370
376
|
const block = this.currentBlock;
|
|
371
377
|
if (!block)
|
|
@@ -388,7 +394,11 @@ class TextEditorStore {
|
|
|
388
394
|
}
|
|
389
395
|
Object.assign(this.currentBlock, blockData);
|
|
390
396
|
if (blockData.editable === false && this.currentBlock === this.blocks[this.blocks.length - 1]) {
|
|
391
|
-
this.
|
|
397
|
+
const newLine = this.addNewLineAfter();
|
|
398
|
+
this.selection.focus.blockId = newLine.id;
|
|
399
|
+
this.selection.focus.offset = 0;
|
|
400
|
+
this.selection.anchor.blockId = newLine.id;
|
|
401
|
+
this.selection.anchor.offset = 0;
|
|
392
402
|
}
|
|
393
403
|
this.history.push("setText");
|
|
394
404
|
}
|
|
@@ -606,12 +616,16 @@ const _sfc_main$2 = defineComponent({
|
|
|
606
616
|
const markers = [];
|
|
607
617
|
if (block.styles) {
|
|
608
618
|
for (let style of block.styles) {
|
|
619
|
+
if (style.end <= style.start)
|
|
620
|
+
continue;
|
|
609
621
|
markers.push([style.start, style]);
|
|
610
622
|
markers.push([style.end, style]);
|
|
611
623
|
}
|
|
612
624
|
}
|
|
613
625
|
if (props.parser) {
|
|
614
626
|
for (let style of props.parser(text)) {
|
|
627
|
+
if (style.end <= style.start)
|
|
628
|
+
continue;
|
|
615
629
|
markers.push([style.start, style]);
|
|
616
630
|
markers.push([style.end, style]);
|
|
617
631
|
}
|
|
@@ -666,8 +680,12 @@ const _sfc_main$2 = defineComponent({
|
|
|
666
680
|
return h(elementTag, attrs, text);
|
|
667
681
|
};
|
|
668
682
|
return () => {
|
|
669
|
-
if (slot.value)
|
|
670
|
-
|
|
683
|
+
if (slot.value) {
|
|
684
|
+
const component = slot.value({ content, props: blockProps, block: props.block });
|
|
685
|
+
if (Array.isArray(component) && component.length === 1)
|
|
686
|
+
return component[0];
|
|
687
|
+
return component;
|
|
688
|
+
}
|
|
671
689
|
return h("div", blockProps, content());
|
|
672
690
|
};
|
|
673
691
|
}
|
|
@@ -839,11 +857,15 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
839
857
|
store.history.push("setText");
|
|
840
858
|
});
|
|
841
859
|
const onCopy = (e) => {
|
|
860
|
+
if (e.defaultPrevented)
|
|
861
|
+
return;
|
|
842
862
|
e.preventDefault();
|
|
843
863
|
navigator.clipboard.writeText(store.selectedText);
|
|
844
864
|
store.history.push("setText");
|
|
845
865
|
};
|
|
846
866
|
const onCut = (e) => {
|
|
867
|
+
if (e.defaultPrevented)
|
|
868
|
+
return;
|
|
847
869
|
e.preventDefault();
|
|
848
870
|
navigator.clipboard.writeText(store.selectedText);
|
|
849
871
|
store.deleteSelected();
|
|
@@ -851,11 +873,22 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
851
873
|
};
|
|
852
874
|
const onPaste = (e) => {
|
|
853
875
|
var _a;
|
|
876
|
+
if (e.defaultPrevented)
|
|
877
|
+
return;
|
|
854
878
|
e.preventDefault();
|
|
855
879
|
const text = (_a = e.clipboardData) == null ? void 0 : _a.getData("Text");
|
|
856
880
|
if (!text)
|
|
857
881
|
return;
|
|
858
|
-
|
|
882
|
+
if (props.preventMultiline) {
|
|
883
|
+
const blocks = text.split("\n");
|
|
884
|
+
store.insertText(blocks[0]);
|
|
885
|
+
for (let i = 1; i < blocks.length; i++) {
|
|
886
|
+
store.addNewLine();
|
|
887
|
+
store.insertText(blocks[i]);
|
|
888
|
+
}
|
|
889
|
+
} else {
|
|
890
|
+
store.insertText(text);
|
|
891
|
+
}
|
|
859
892
|
store.history.push("setText");
|
|
860
893
|
};
|
|
861
894
|
const getClientRects = (selection) => {
|
|
@@ -913,38 +946,23 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
913
946
|
};
|
|
914
947
|
}
|
|
915
948
|
});
|
|
916
|
-
const _sfc_main =
|
|
917
|
-
|
|
918
|
-
props
|
|
919
|
-
modelValue: {},
|
|
920
|
-
decorator: { type: Function },
|
|
921
|
-
parser: {},
|
|
922
|
-
styles: {},
|
|
923
|
-
preventMultiline: { type: Boolean }
|
|
924
|
-
},
|
|
925
|
-
setup(__props) {
|
|
926
|
-
const props = __props;
|
|
927
|
-
const slots = useSlots();
|
|
949
|
+
const _sfc_main = defineComponent({
|
|
950
|
+
props: ["modelValue", "decorator", "parser", "styles"],
|
|
951
|
+
setup(props, { slots }) {
|
|
928
952
|
const blocks = computed(() => {
|
|
929
953
|
if (Array.isArray(props.modelValue)) {
|
|
930
954
|
return props.modelValue;
|
|
931
955
|
}
|
|
932
956
|
return [{ text: props.modelValue, styles: props.styles ?? [] }];
|
|
933
957
|
});
|
|
934
|
-
return (
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
parser: props.parser,
|
|
943
|
-
static: ""
|
|
944
|
-
}, null, 8, ["block", "slots", "decorator", "parser"]);
|
|
945
|
-
}), 128))
|
|
946
|
-
]);
|
|
947
|
-
};
|
|
958
|
+
return () => h("div", blocks.value.map((block) => h(_sfc_main$2, {
|
|
959
|
+
key: block.id,
|
|
960
|
+
block,
|
|
961
|
+
slots,
|
|
962
|
+
decorator: props.decorator,
|
|
963
|
+
parser: props.parser,
|
|
964
|
+
static: true
|
|
965
|
+
})));
|
|
948
966
|
}
|
|
949
967
|
});
|
|
950
968
|
export {
|