vuewrite 0.0.2 → 0.0.3
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 +10 -1
- package/dist/vuewrite.js +28 -4
- package/package.json +1 -1
package/dist/vuewrite.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ExtractPropTypes } from 'vue';
|
|
|
5
5
|
import { HTMLAttributes } from 'vue';
|
|
6
6
|
import { PropType } from 'vue';
|
|
7
7
|
import { PublicProps } from 'vue';
|
|
8
|
+
import { Ref } from 'vue';
|
|
8
9
|
|
|
9
10
|
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
10
11
|
|
|
@@ -44,6 +45,7 @@ decorator?: Decorator | undefined;
|
|
|
44
45
|
single?: boolean | undefined;
|
|
45
46
|
modelValue?: string | string[] | undefined;
|
|
46
47
|
styles?: Style[] | Style[][] | undefined;
|
|
48
|
+
autofocus?: boolean | undefined;
|
|
47
49
|
}>, {
|
|
48
50
|
currentStyles: ComputedRef<Map<string, Style>>;
|
|
49
51
|
currentBlock: ComputedRef< {
|
|
@@ -68,10 +70,12 @@ blockId: string;
|
|
|
68
70
|
offset: number;
|
|
69
71
|
};
|
|
70
72
|
};
|
|
73
|
+
isFocused: Ref<boolean>;
|
|
71
74
|
toggleStyle: (style: string) => void;
|
|
72
75
|
applyStyle: (_style: string, meta?: any) => void;
|
|
73
76
|
removeStyle: (_style: string) => void;
|
|
74
77
|
insertText: (data: string) => void;
|
|
78
|
+
selectAll: () => void;
|
|
75
79
|
}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
76
80
|
keydown: (...args: any[]) => void;
|
|
77
81
|
"update:modelValue": (...args: any[]) => void;
|
|
@@ -81,6 +85,7 @@ decorator?: Decorator | undefined;
|
|
|
81
85
|
single?: boolean | undefined;
|
|
82
86
|
modelValue?: string | string[] | undefined;
|
|
83
87
|
styles?: Style[] | Style[][] | undefined;
|
|
88
|
+
autofocus?: boolean | undefined;
|
|
84
89
|
}>>> & {
|
|
85
90
|
onKeydown?: ((...args: any[]) => any) | undefined;
|
|
86
91
|
"onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
@@ -89,7 +94,9 @@ onKeydown?: ((...args: any[]) => any) | undefined;
|
|
|
89
94
|
placeholder?(_: {}): any;
|
|
90
95
|
}>;
|
|
91
96
|
|
|
92
|
-
export declare type TextEditorRef = Pick<TextEditorStore, "currentStyles" | "currentBlock" | "isCollapsed" | "selection" | "toggleStyle" | "applyStyle" | "removeStyle" | "insertText"
|
|
97
|
+
export declare type TextEditorRef = Pick<TextEditorStore, "currentStyles" | "currentBlock" | "isCollapsed" | "selection" | "toggleStyle" | "applyStyle" | "removeStyle" | "insertText" | "selectAll"> & {
|
|
98
|
+
isFocused: boolean;
|
|
99
|
+
};
|
|
93
100
|
|
|
94
101
|
declare class TextEditorStore {
|
|
95
102
|
blocks: {
|
|
@@ -115,6 +122,7 @@ declare class TextEditorStore {
|
|
|
115
122
|
};
|
|
116
123
|
_isCollapsed: ComputedRef<boolean>;
|
|
117
124
|
get isCollapsed(): boolean;
|
|
125
|
+
isFocused: Ref<boolean>;
|
|
118
126
|
_currentBlock: ComputedRef< {
|
|
119
127
|
id: string;
|
|
120
128
|
text: string;
|
|
@@ -157,6 +165,7 @@ declare class TextEditorStore {
|
|
|
157
165
|
removeStyle(_style: string): void;
|
|
158
166
|
removeAllStyles(): void;
|
|
159
167
|
toggleStyle(style: string): void;
|
|
168
|
+
selectAll(): void;
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
export { }
|
package/dist/vuewrite.js
CHANGED
|
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
|
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
|
-
import { getCurrentScope, onScopeDispose, unref, watch, reactive, computed, defineComponent, getCurrentInstance, openBlock, createBlock, resolveDynamicComponent, createElementBlock, normalizeProps, mergeProps, h, nextTick, useSlots,
|
|
7
|
+
import { getCurrentScope, onScopeDispose, unref, watch, reactive, computed, ref, defineComponent, getCurrentInstance, openBlock, createBlock, resolveDynamicComponent, createElementBlock, normalizeProps, mergeProps, h, nextTick, useSlots, onMounted, Fragment, renderList, renderSlot, createCommentVNode } from "vue";
|
|
8
8
|
function tryOnScopeDispose(fn) {
|
|
9
9
|
if (getCurrentScope()) {
|
|
10
10
|
onScopeDispose(fn);
|
|
@@ -150,6 +150,7 @@ class TextEditorStore {
|
|
|
150
150
|
__publicField(this, "_isCollapsed", computed(() => {
|
|
151
151
|
return this.selection.anchor.blockId === this.selection.focus.blockId && this.selection.anchor.offset === this.selection.focus.offset;
|
|
152
152
|
}));
|
|
153
|
+
__publicField(this, "isFocused", ref(false));
|
|
153
154
|
__publicField(this, "_currentBlock", computed(() => {
|
|
154
155
|
if (this.selection.anchor.blockId !== this.selection.focus.blockId)
|
|
155
156
|
return null;
|
|
@@ -374,6 +375,11 @@ class TextEditorStore {
|
|
|
374
375
|
this.applyStyle(style);
|
|
375
376
|
}
|
|
376
377
|
}
|
|
378
|
+
selectAll() {
|
|
379
|
+
this.selection.anchor = { blockId: this.blocks[0].id, offset: 0 };
|
|
380
|
+
const lastBlock = this.blocks[this.blocks.length - 1];
|
|
381
|
+
this.selection.focus = { blockId: lastBlock.id, offset: lastBlock.text.length };
|
|
382
|
+
}
|
|
377
383
|
}
|
|
378
384
|
let uidCounter = 0;
|
|
379
385
|
const uid = () => (uidCounter++).toString();
|
|
@@ -521,7 +527,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
521
527
|
decorator: { type: Function },
|
|
522
528
|
single: { type: Boolean },
|
|
523
529
|
modelValue: {},
|
|
524
|
-
styles: {}
|
|
530
|
+
styles: {},
|
|
531
|
+
autofocus: { type: Boolean }
|
|
525
532
|
},
|
|
526
533
|
emits: ["keydown", "update:modelValue", "update:styles"],
|
|
527
534
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
@@ -605,7 +612,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
605
612
|
const offset = anchor === sel.focusNode ? 0 : calcOffsetToNode(focus, sel.focusNode) + sel.focusOffset;
|
|
606
613
|
store.selection.focus = { blockId: focus.getAttribute("data-block-id"), offset };
|
|
607
614
|
}
|
|
608
|
-
|
|
615
|
+
if (store.isFocused.value !== !!focus || !!anchor) {
|
|
616
|
+
store.isFocused.value = !!focus || !!anchor;
|
|
617
|
+
}
|
|
618
|
+
if (!anchor && !focus)
|
|
619
|
+
cachedSelection = JSON.parse(JSON.stringify(store.selection));
|
|
609
620
|
});
|
|
610
621
|
let postRendered = false;
|
|
611
622
|
const onPostRender = () => {
|
|
@@ -619,6 +630,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
619
630
|
});
|
|
620
631
|
};
|
|
621
632
|
const applySelection = () => {
|
|
633
|
+
if (!store.isFocused.value) {
|
|
634
|
+
cachedSelection = JSON.parse(JSON.stringify(store.selection));
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
622
637
|
if (isEqual(store.selection, cachedSelection))
|
|
623
638
|
return;
|
|
624
639
|
const nativeSelection = window.getSelection();
|
|
@@ -641,15 +656,24 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
641
656
|
cachedSelection = JSON.parse(JSON.stringify(store.selection));
|
|
642
657
|
};
|
|
643
658
|
watch(() => store.selection, applySelection, { deep: true, flush: "post" });
|
|
659
|
+
onMounted(() => {
|
|
660
|
+
var _a;
|
|
661
|
+
if (props.autofocus) {
|
|
662
|
+
(_a = textEditorRef.value) == null ? void 0 : _a.focus();
|
|
663
|
+
applySelection();
|
|
664
|
+
}
|
|
665
|
+
});
|
|
644
666
|
__expose({
|
|
645
667
|
currentStyles: store._currentStyles,
|
|
646
668
|
currentBlock: store._currentBlock,
|
|
647
669
|
isCollapsed: store._isCollapsed,
|
|
648
670
|
selection: store.selection,
|
|
671
|
+
isFocused: store.isFocused,
|
|
649
672
|
toggleStyle: store.toggleStyle.bind(store),
|
|
650
673
|
applyStyle: store.applyStyle.bind(store),
|
|
651
674
|
removeStyle: store.removeStyle.bind(store),
|
|
652
|
-
insertText: store.insertText.bind(store)
|
|
675
|
+
insertText: store.insertText.bind(store),
|
|
676
|
+
selectAll: store.selectAll.bind(store)
|
|
653
677
|
});
|
|
654
678
|
return (_ctx, _cache) => {
|
|
655
679
|
return openBlock(), createElementBlock("div", {
|