vuewrite 0.0.22 → 0.0.23-b

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.
@@ -97,6 +97,7 @@ offset: number;
97
97
  };
98
98
  };
99
99
  isFocused: Ref<boolean>;
100
+ getCurrentBlocks: () => Generator<Block, any, unknown>;
100
101
  toggleStyle: (style: string) => void;
101
102
  applyStyle: (_style: string, meta?: any) => void;
102
103
  removeStyle: (_style: string) => void;
@@ -150,7 +151,7 @@ declare class TextEditorHistory {
150
151
  redo(): void;
151
152
  }
152
153
 
153
- export declare type TextEditorRef = Pick<TextEditorStore, "currentStyles" | "currentBlock" | "isCollapsed" | "selection" | "toggleStyle" | "applyStyle" | "removeStyle" | "insertText" | "insertBlock" | "addNewLine" | "removeNewLine" | "selectAll" | "removeCurrentBlock"> & {
154
+ export declare type TextEditorRef = Pick<TextEditorStore, "currentStyles" | "currentBlock" | "isCollapsed" | "selection" | "getCurrentBlocks" | "toggleStyle" | "applyStyle" | "removeStyle" | "insertText" | "insertBlock" | "addNewLine" | "removeNewLine" | "selectAll" | "removeCurrentBlock"> & {
154
155
  isFocused: boolean;
155
156
  getClientRects: (selection: TextEditorSelection) => DOMRectList;
156
157
  pushHistory: TextEditorHistory["push"];
@@ -218,6 +219,7 @@ declare class TextEditorStore {
218
219
  }[] | undefined;
219
220
  editable?: boolean | undefined;
220
221
  } | null;
222
+ getCurrentBlocks(): Generator<Block>;
221
223
  _selectedText: ComputedRef<string>;
222
224
  get selectedText(): string;
223
225
  moveOffset(newOffset: number): void;
package/dist/vuewrite.js CHANGED
@@ -281,6 +281,17 @@ class TextEditorStore {
281
281
  get currentBlock() {
282
282
  return this._currentBlock.value;
283
283
  }
284
+ *getCurrentBlocks() {
285
+ const blockAnchorIndex = this.blocks.findIndex((item) => item.id === this.selection.anchor.blockId);
286
+ const focusAnchorIndex = this.blocks.findIndex((item) => item.id === this.selection.focus.blockId);
287
+ if (blockAnchorIndex === -1 || focusAnchorIndex === -1)
288
+ return;
289
+ const start = Math.min(blockAnchorIndex, focusAnchorIndex);
290
+ const end = Math.max(blockAnchorIndex, focusAnchorIndex);
291
+ for (let i = start; i <= end; i++) {
292
+ yield this.blocks[i];
293
+ }
294
+ }
284
295
  get selectedText() {
285
296
  return this._selectedText.value;
286
297
  }
@@ -898,13 +909,11 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
898
909
  return;
899
910
  } else {
900
911
  for (let i = store.blocks.length; i < newValue.length; i++) {
901
- store.blocks.push({ id: uid(), text: "", styles: [] });
912
+ store.blocks.push({ id: uid(), text: "" });
902
913
  }
903
914
  store.blocks.length = newValue.length;
904
915
  for (let i = 0; i < newValue.length; i++) {
905
- store.blocks[i].text = newValue[i].text;
906
- store.blocks[i].type = newValue[i].type;
907
- store.blocks[i].styles = newValue[i].styles;
916
+ store.blocks[i] = { ...newValue[i], id: uid() };
908
917
  }
909
918
  }
910
919
  }, { immediate: true });
@@ -925,6 +934,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
925
934
  emit("update:styles", styles);
926
935
  emit("update:modelValue", modelValue);
927
936
  } else {
937
+ modelValue = store.blocks;
928
938
  emit("update:modelValue", store.blocks);
929
939
  }
930
940
  }, { deep: true });
@@ -1051,6 +1061,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1051
1061
  isCollapsed: store._isCollapsed,
1052
1062
  selection: store.selection,
1053
1063
  isFocused: store.isFocused,
1064
+ getCurrentBlocks: store.getCurrentBlocks.bind(store),
1054
1065
  toggleStyle: store.toggleStyle.bind(store),
1055
1066
  applyStyle: store.applyStyle.bind(store),
1056
1067
  removeStyle: store.removeStyle.bind(store),
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.22",
5
+ "version": "0.0.23-b",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "den59k",
@@ -19,8 +19,7 @@
19
19
  "preview": "vite preview"
20
20
  },
21
21
  "dependencies": {
22
- "vue": "^3",
23
- "vuewrite": "^0.0.19"
22
+ "vue": "^3"
24
23
  },
25
24
  "devDependencies": {
26
25
  "@vitejs/plugin-vue": "^5.0.4",