vuewrite 0.0.23 → 0.0.24-a

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;
@@ -131,7 +132,9 @@ onKeydown?: ((...args: any[]) => any) | undefined;
131
132
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
132
133
  "onUpdate:styles"?: ((...args: any[]) => any) | undefined;
133
134
  }, {}, {}>, {
135
+ _before?(_: {}): any;
134
136
  placeholder?(_: {}): any;
137
+ _after?(_: {}): any;
135
138
  }>;
136
139
 
137
140
  declare class TextEditorHistory {
@@ -150,7 +153,7 @@ declare class TextEditorHistory {
150
153
  redo(): void;
151
154
  }
152
155
 
153
- export declare type TextEditorRef = Pick<TextEditorStore, "currentStyles" | "currentBlock" | "isCollapsed" | "selection" | "toggleStyle" | "applyStyle" | "removeStyle" | "insertText" | "insertBlock" | "addNewLine" | "removeNewLine" | "selectAll" | "removeCurrentBlock"> & {
156
+ export declare type TextEditorRef = Pick<TextEditorStore, "currentStyles" | "currentBlock" | "isCollapsed" | "selection" | "getCurrentBlocks" | "toggleStyle" | "applyStyle" | "removeStyle" | "insertText" | "insertBlock" | "addNewLine" | "removeNewLine" | "selectAll" | "removeCurrentBlock"> & {
154
157
  isFocused: boolean;
155
158
  getClientRects: (selection: TextEditorSelection) => DOMRectList;
156
159
  pushHistory: TextEditorHistory["push"];
@@ -218,6 +221,7 @@ declare class TextEditorStore {
218
221
  }[] | undefined;
219
222
  editable?: boolean | undefined;
220
223
  } | null;
224
+ getCurrentBlocks(): Generator<Block>;
221
225
  _selectedText: ComputedRef<string>;
222
226
  get selectedText(): string;
223
227
  moveOffset(newOffset: number): void;
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, ref, defineComponent, getCurrentInstance, h, nextTick, useSlots, isProxy, toRaw, onMounted, openBlock, createElementBlock, Fragment, renderList, createBlock, renderSlot, createCommentVNode } from "vue";
7
+ import { getCurrentScope, onScopeDispose, unref, watch, reactive, computed, ref, defineComponent, getCurrentInstance, h, nextTick, useSlots, isProxy, toRaw, onMounted, openBlock, createElementBlock, renderSlot, Fragment, renderList, createBlock, createCommentVNode } from "vue";
8
8
  function tryOnScopeDispose(fn) {
9
9
  if (getCurrentScope()) {
10
10
  onScopeDispose(fn);
@@ -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
  }
@@ -1050,6 +1061,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1050
1061
  isCollapsed: store._isCollapsed,
1051
1062
  selection: store.selection,
1052
1063
  isFocused: store.isFocused,
1064
+ getCurrentBlocks: store.getCurrentBlocks.bind(store),
1053
1065
  toggleStyle: store.toggleStyle.bind(store),
1054
1066
  applyStyle: store.applyStyle.bind(store),
1055
1067
  removeStyle: store.removeStyle.bind(store),
@@ -1077,6 +1089,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1077
1089
  onCut: _cache[3] || (_cache[3] = //@ts-ignore
1078
1090
  (...args) => unref(onCut) && unref(onCut)(...args))
1079
1091
  }, [
1092
+ renderSlot(_ctx.$slots, "_before"),
1080
1093
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(store).blocks, (block) => {
1081
1094
  return openBlock(), createBlock(_sfc_main$2, {
1082
1095
  key: block.id,
@@ -1088,7 +1101,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1088
1101
  onPostrender: onPostRender
1089
1102
  }, null, 8, ["block", "slots", "renderer", "decorator", "parser"]);
1090
1103
  }), 128)),
1091
- unref(store).blocks.length === 1 && unref(store).blocks[0].text === "" && !unref(store).blocks[0].type ? renderSlot(_ctx.$slots, "placeholder", { key: 0 }) : createCommentVNode("", true)
1104
+ unref(store).blocks.length === 1 && unref(store).blocks[0].text === "" && !unref(store).blocks[0].type ? renderSlot(_ctx.$slots, "placeholder", { key: 0 }) : createCommentVNode("", true),
1105
+ renderSlot(_ctx.$slots, "_after")
1092
1106
  ], 544);
1093
1107
  };
1094
1108
  }
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.23",
5
+ "version": "0.0.24-a",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "den59k",