vuewrite 0.0.3 → 0.0.4
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 +2 -0
- package/dist/vuewrite.js +36 -1
- package/package.json +1 -1
package/dist/vuewrite.d.ts
CHANGED
package/dist/vuewrite.js
CHANGED
|
@@ -156,6 +156,18 @@ class TextEditorStore {
|
|
|
156
156
|
return null;
|
|
157
157
|
return this.blocks.find((item) => item.id === this.selection.anchor.blockId) ?? null;
|
|
158
158
|
}));
|
|
159
|
+
__publicField(this, "_selectedText", computed(() => {
|
|
160
|
+
if (this.isCollapsed)
|
|
161
|
+
return "";
|
|
162
|
+
const [start, end, startIndex, endIndex] = this.startAndEnd;
|
|
163
|
+
if (startIndex === endIndex) {
|
|
164
|
+
return this.blocks[startIndex].text.slice(start.offset, end.offset);
|
|
165
|
+
}
|
|
166
|
+
const startText = this.blocks[startIndex].text.slice(start.offset);
|
|
167
|
+
const endText = this.blocks[endIndex].text.slice(0, end.offset);
|
|
168
|
+
const arr = [startText, ...this.blocks.slice(startIndex + 1, endIndex).map((block) => block.text), endText];
|
|
169
|
+
return arr.join("\n");
|
|
170
|
+
}));
|
|
159
171
|
__publicField(this, "_currentStyles", computed(() => {
|
|
160
172
|
const [start, end, startIndex, endIndex] = this.startAndEnd;
|
|
161
173
|
const styles = /* @__PURE__ */ new Map();
|
|
@@ -179,6 +191,9 @@ class TextEditorStore {
|
|
|
179
191
|
get currentBlock() {
|
|
180
192
|
return this._currentBlock.value;
|
|
181
193
|
}
|
|
194
|
+
get selectedText() {
|
|
195
|
+
return this._selectedText.value;
|
|
196
|
+
}
|
|
182
197
|
moveOffset(newOffset) {
|
|
183
198
|
const delta = newOffset - this.selection.anchor.offset;
|
|
184
199
|
if (delta === 0)
|
|
@@ -663,6 +678,23 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
663
678
|
applySelection();
|
|
664
679
|
}
|
|
665
680
|
});
|
|
681
|
+
const onCopy = (e) => {
|
|
682
|
+
e.preventDefault();
|
|
683
|
+
navigator.clipboard.writeText(store.selectedText);
|
|
684
|
+
};
|
|
685
|
+
const onCut = (e) => {
|
|
686
|
+
e.preventDefault();
|
|
687
|
+
navigator.clipboard.writeText(store.selectedText);
|
|
688
|
+
store.deleteSelected();
|
|
689
|
+
};
|
|
690
|
+
const onPaste = (e) => {
|
|
691
|
+
var _a;
|
|
692
|
+
e.preventDefault();
|
|
693
|
+
const text = (_a = e.clipboardData) == null ? void 0 : _a.getData("Text");
|
|
694
|
+
if (!text)
|
|
695
|
+
return;
|
|
696
|
+
store.insertText(text);
|
|
697
|
+
};
|
|
666
698
|
__expose({
|
|
667
699
|
currentStyles: store._currentStyles,
|
|
668
700
|
currentBlock: store._currentBlock,
|
|
@@ -682,7 +714,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
682
714
|
contenteditable: "",
|
|
683
715
|
onInput: _cache[0] || (_cache[0] = //@ts-ignore
|
|
684
716
|
(...args) => unref(store).onInput && unref(store).onInput(...args)),
|
|
685
|
-
onKeydown: onKeyDown
|
|
717
|
+
onKeydown: onKeyDown,
|
|
718
|
+
onCopy,
|
|
719
|
+
onPaste,
|
|
720
|
+
onCut
|
|
686
721
|
}, [
|
|
687
722
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(store).blocks, (block) => {
|
|
688
723
|
return openBlock(), createBlock(_sfc_main$1, {
|