vuewrite 0.0.9 → 0.0.11
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 +31 -0
- package/dist/vuewrite.js +54 -13
- package/package.json +1 -1
package/dist/vuewrite.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { Ref } from 'vue';
|
|
|
9
9
|
|
|
10
10
|
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
11
11
|
|
|
12
|
+
declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
|
|
13
|
+
|
|
12
14
|
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
13
15
|
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
14
16
|
type: PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
@@ -18,6 +20,15 @@ declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
|
18
20
|
};
|
|
19
21
|
};
|
|
20
22
|
|
|
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
|
+
|
|
21
32
|
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
22
33
|
new (): {
|
|
23
34
|
$slots: S;
|
|
@@ -229,6 +240,26 @@ declare class TextEditorStore {
|
|
|
229
240
|
selectAll(): void;
|
|
230
241
|
}
|
|
231
242
|
|
|
243
|
+
export declare const TextEditorView: DefineComponent<__VLS_TypePropsToRuntimeProps_2<{
|
|
244
|
+
modelValue: {
|
|
245
|
+
text: string;
|
|
246
|
+
styles?: Style[];
|
|
247
|
+
type?: string;
|
|
248
|
+
}[] | string;
|
|
249
|
+
decorator?: Decorator | undefined;
|
|
250
|
+
parser?: TextParser | undefined;
|
|
251
|
+
styles?: Style[] | undefined;
|
|
252
|
+
}>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps_2<{
|
|
253
|
+
modelValue: {
|
|
254
|
+
text: string;
|
|
255
|
+
styles?: Style[];
|
|
256
|
+
type?: string;
|
|
257
|
+
}[] | string;
|
|
258
|
+
decorator?: Decorator | undefined;
|
|
259
|
+
parser?: TextParser | undefined;
|
|
260
|
+
styles?: Style[] | undefined;
|
|
261
|
+
}>>>, {}, {}>;
|
|
262
|
+
|
|
232
263
|
declare type TextParser = (text: string) => Style[];
|
|
233
264
|
|
|
234
265
|
export { }
|
package/dist/vuewrite.js
CHANGED
|
@@ -291,16 +291,16 @@ class TextEditorStore {
|
|
|
291
291
|
const blockIndex = this.blocks.findIndex((item) => item.id === this.selection.anchor.blockId);
|
|
292
292
|
if (blockIndex < 1)
|
|
293
293
|
return;
|
|
294
|
+
this.selection.anchor.blockId = this.blocks[blockIndex - 1].id;
|
|
295
|
+
this.selection.focus.blockId = this.blocks[blockIndex - 1].id;
|
|
296
|
+
this.selection.anchor.offset = this.blocks[blockIndex - 1].text.length;
|
|
297
|
+
this.selection.focus.offset = this.blocks[blockIndex - 1].text.length;
|
|
294
298
|
if (this.blocks[blockIndex - 1].editable === false) {
|
|
295
299
|
this.blocks.splice(blockIndex - 1, 1);
|
|
296
300
|
} else {
|
|
297
301
|
this.concatBlocks(this.blocks[blockIndex - 1], this.blocks[blockIndex]);
|
|
298
302
|
this.blocks.splice(blockIndex, 1);
|
|
299
303
|
}
|
|
300
|
-
this.selection.anchor.blockId = this.blocks[blockIndex - 1].id;
|
|
301
|
-
this.selection.focus.blockId = this.blocks[blockIndex - 1].id;
|
|
302
|
-
this.selection.anchor.offset = this.blocks[blockIndex - 1].text.length;
|
|
303
|
-
this.selection.focus.offset = this.blocks[blockIndex - 1].text.length;
|
|
304
304
|
this.history.push("setText");
|
|
305
305
|
}
|
|
306
306
|
onInput(_e) {
|
|
@@ -348,6 +348,12 @@ class TextEditorStore {
|
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
addNewLine() {
|
|
351
|
+
if (this.isCollapsed && this.selection.anchor.offset === 0) {
|
|
352
|
+
const index2 = this.blocks.findIndex((item) => item.id === this.selection.anchor.blockId);
|
|
353
|
+
const block2 = { id: uid(), text: "", styles: [] };
|
|
354
|
+
this.blocks.splice(index2, 0, block2);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
351
357
|
this.deleteSelected();
|
|
352
358
|
if (!this.currentBlock)
|
|
353
359
|
return;
|
|
@@ -524,7 +530,7 @@ class TextEditorStore {
|
|
|
524
530
|
}
|
|
525
531
|
let uidCounter = 0;
|
|
526
532
|
const uid = () => (uidCounter++).toString();
|
|
527
|
-
const _sfc_main$
|
|
533
|
+
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
528
534
|
__name: "TextEditorBlock",
|
|
529
535
|
props: {
|
|
530
536
|
block: {},
|
|
@@ -538,7 +544,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
538
544
|
const emit = __emit;
|
|
539
545
|
const slot = computed(() => {
|
|
540
546
|
if (!props.block.type)
|
|
541
|
-
return null;
|
|
547
|
+
return props.slots["default"] ?? null;
|
|
542
548
|
return props.slots[props.block.type] ?? null;
|
|
543
549
|
});
|
|
544
550
|
const blockProps = {
|
|
@@ -625,9 +631,11 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
625
631
|
text = text + "\n";
|
|
626
632
|
}
|
|
627
633
|
const markers = [];
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
634
|
+
if (block.styles) {
|
|
635
|
+
for (let style of block.styles) {
|
|
636
|
+
markers.push([style.start, style]);
|
|
637
|
+
markers.push([style.end, style]);
|
|
638
|
+
}
|
|
631
639
|
}
|
|
632
640
|
if (props.parser) {
|
|
633
641
|
for (let style of props.parser(text)) {
|
|
@@ -671,7 +679,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
671
679
|
};
|
|
672
680
|
}
|
|
673
681
|
});
|
|
674
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
682
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
675
683
|
__name: "TextEditor",
|
|
676
684
|
props: {
|
|
677
685
|
decorator: { type: Function },
|
|
@@ -705,7 +713,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
705
713
|
for (let i = 0; i < newValue.length; i++) {
|
|
706
714
|
store.blocks[i].text = newValue[i].text;
|
|
707
715
|
store.blocks[i].type = newValue[i].type;
|
|
708
|
-
store.blocks[i].
|
|
716
|
+
store.blocks[i].styles = newValue[i].styles ?? [];
|
|
709
717
|
}
|
|
710
718
|
}
|
|
711
719
|
}, { immediate: true });
|
|
@@ -896,7 +904,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
896
904
|
onCut
|
|
897
905
|
}, [
|
|
898
906
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(store).blocks, (block) => {
|
|
899
|
-
return openBlock(), createBlock(_sfc_main$
|
|
907
|
+
return openBlock(), createBlock(_sfc_main$2, {
|
|
900
908
|
key: block.id,
|
|
901
909
|
block,
|
|
902
910
|
slots: unref(slots),
|
|
@@ -910,6 +918,39 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
910
918
|
};
|
|
911
919
|
}
|
|
912
920
|
});
|
|
921
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
922
|
+
__name: "TextEditorView",
|
|
923
|
+
props: {
|
|
924
|
+
modelValue: {},
|
|
925
|
+
decorator: { type: Function },
|
|
926
|
+
parser: {},
|
|
927
|
+
styles: {}
|
|
928
|
+
},
|
|
929
|
+
setup(__props) {
|
|
930
|
+
const props = __props;
|
|
931
|
+
const slots = useSlots();
|
|
932
|
+
const blocks = computed(() => {
|
|
933
|
+
if (Array.isArray(props.modelValue)) {
|
|
934
|
+
return props.modelValue;
|
|
935
|
+
}
|
|
936
|
+
return [{ text: props.modelValue, styles: props.styles ?? [] }];
|
|
937
|
+
});
|
|
938
|
+
return (_ctx, _cache) => {
|
|
939
|
+
return openBlock(), createElementBlock("div", null, [
|
|
940
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(blocks.value, (block) => {
|
|
941
|
+
return openBlock(), createBlock(_sfc_main$2, {
|
|
942
|
+
key: block.id,
|
|
943
|
+
block,
|
|
944
|
+
slots: unref(slots),
|
|
945
|
+
decorator: props.decorator,
|
|
946
|
+
parser: props.parser
|
|
947
|
+
}, null, 8, ["block", "slots", "decorator", "parser"]);
|
|
948
|
+
}), 128))
|
|
949
|
+
]);
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
});
|
|
913
953
|
export {
|
|
914
|
-
_sfc_main as TextEditor
|
|
954
|
+
_sfc_main$1 as TextEditor,
|
|
955
|
+
_sfc_main as TextEditorView
|
|
915
956
|
};
|