vuewrite 0.0.18 → 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.
@@ -213,6 +213,11 @@ declare class TextEditorStore {
213
213
  removeNewLine(): void;
214
214
  onInput(_e: Event): void;
215
215
  addNewLine(): void;
216
+ addNewLineAfter(): {
217
+ id: string;
218
+ text: string;
219
+ styles: never[];
220
+ };
216
221
  insertText(data: string): void;
217
222
  insertBlock(blockData: Partial<Block>): void;
218
223
  get startAndEnd(): [{
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.addNewLine();
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
  }
@@ -843,11 +857,15 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
843
857
  store.history.push("setText");
844
858
  });
845
859
  const onCopy = (e) => {
860
+ if (e.defaultPrevented)
861
+ return;
846
862
  e.preventDefault();
847
863
  navigator.clipboard.writeText(store.selectedText);
848
864
  store.history.push("setText");
849
865
  };
850
866
  const onCut = (e) => {
867
+ if (e.defaultPrevented)
868
+ return;
851
869
  e.preventDefault();
852
870
  navigator.clipboard.writeText(store.selectedText);
853
871
  store.deleteSelected();
@@ -855,11 +873,22 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
855
873
  };
856
874
  const onPaste = (e) => {
857
875
  var _a;
876
+ if (e.defaultPrevented)
877
+ return;
858
878
  e.preventDefault();
859
879
  const text = (_a = e.clipboardData) == null ? void 0 : _a.getData("Text");
860
880
  if (!text)
861
881
  return;
862
- store.insertText(text);
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
+ }
863
892
  store.history.push("setText");
864
893
  };
865
894
  const getClientRects = (selection) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vuewrite",
3
3
  "description": "Rich Text Editor based on Vue3 reactivity",
4
4
  "private": false,
5
- "version": "0.0.18",
5
+ "version": "0.0.19",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "den59k",