vuewrite 0.0.24-a → 0.0.25

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.
@@ -71,6 +71,7 @@ styles?: Style[] | undefined;
71
71
  autofocus?: boolean | undefined;
72
72
  autoselect?: boolean | undefined;
73
73
  preventMultiline?: boolean | undefined;
74
+ htmlParser?: ((el: Element) => string | null | void) | undefined;
74
75
  }>, {
75
76
  currentStyles: ComputedRef<Map<string, Style>>;
76
77
  currentBlock: ComputedRef< {
@@ -127,14 +128,13 @@ styles?: Style[] | undefined;
127
128
  autofocus?: boolean | undefined;
128
129
  autoselect?: boolean | undefined;
129
130
  preventMultiline?: boolean | undefined;
131
+ htmlParser?: ((el: Element) => string | null | void) | undefined;
130
132
  }>>> & {
131
133
  onKeydown?: ((...args: any[]) => any) | undefined;
132
134
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
133
135
  "onUpdate:styles"?: ((...args: any[]) => any) | undefined;
134
136
  }, {}, {}>, {
135
- _before?(_: {}): any;
136
137
  placeholder?(_: {}): any;
137
- _after?(_: {}): any;
138
138
  }>;
139
139
 
140
140
  declare class TextEditorHistory {
@@ -263,6 +263,7 @@ decorator?: any;
263
263
  renderer?: any;
264
264
  parser?: any;
265
265
  modelValue?: any;
266
+ listParser?: any;
266
267
  }>, () => VNode<RendererNode, RendererElement, {
267
268
  [key: string]: any;
268
269
  }>, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<Readonly<{
@@ -271,12 +272,14 @@ decorator?: any;
271
272
  renderer?: any;
272
273
  parser?: any;
273
274
  modelValue?: any;
275
+ listParser?: any;
274
276
  }>>>, {
275
277
  readonly styles?: any;
276
278
  readonly decorator?: any;
277
279
  readonly renderer?: any;
278
280
  readonly parser?: any;
279
281
  readonly modelValue?: any;
282
+ readonly listParser?: any;
280
283
  }, {}>;
281
284
 
282
285
  declare type TextParser = (text: string) => Style[];
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, renderSlot, Fragment, renderList, createBlock, createCommentVNode } from "vue";
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";
8
8
  function tryOnScopeDispose(fn) {
9
9
  if (getCurrentScope()) {
10
10
  onScopeDispose(fn);
@@ -814,7 +814,7 @@ const createClipboardEvents = (store, props) => {
814
814
  store.deleteSelected();
815
815
  store.history.push("setText");
816
816
  };
817
- const insertText = (text) => {
817
+ const insertText = (text, type) => {
818
818
  if (props.preventMultiline) {
819
819
  const blocks = text.split("\n");
820
820
  store.insertText(blocks[0]);
@@ -823,11 +823,14 @@ const createClipboardEvents = (store, props) => {
823
823
  store.insertText(blocks[i]);
824
824
  }
825
825
  } else {
826
+ if (type && store.currentBlock) {
827
+ store.currentBlock.type = type;
828
+ }
826
829
  store.insertText(text);
827
830
  }
828
831
  };
829
- const parseHtml = (node) => {
830
- var _a;
832
+ const parseHtml = (node, type) => {
833
+ var _a, _b, _c, _d;
831
834
  let isTextNode = false;
832
835
  for (let _node of node.childNodes) {
833
836
  if (_node.nodeType === Node.TEXT_NODE && ((_a = _node.textContent) == null ? void 0 : _a.trim()) || _node.nodeType == Node.ELEMENT_NODE && _node.tagName === "SPAN") {
@@ -839,15 +842,19 @@ const createClipboardEvents = (store, props) => {
839
842
  const text = node.textContent;
840
843
  if (!text)
841
844
  return;
842
- insertText(text);
845
+ insertText(text, type ?? ((_b = props.htmlParser) == null ? void 0 : _b.call(props, node)) ?? void 0);
843
846
  store.addNewLine();
844
847
  return;
845
848
  }
846
849
  for (let child of node.children) {
847
850
  if (child.tagName === "DIV") {
848
- parseHtml(child);
851
+ parseHtml(child, type);
852
+ } else if (child.tagName === "UL") {
853
+ for (let li of child.children) {
854
+ parseHtml(li, ((_c = props.htmlParser) == null ? void 0 : _c.call(props, li)) ?? void 0);
855
+ }
849
856
  } else {
850
- insertText(child.textContent ?? "");
857
+ insertText(child.textContent ?? "", type ?? ((_d = props.htmlParser) == null ? void 0 : _d.call(props, child)) ?? void 0);
851
858
  store.addNewLine();
852
859
  }
853
860
  }
@@ -889,7 +896,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
889
896
  styles: {},
890
897
  autofocus: { type: Boolean },
891
898
  autoselect: { type: Boolean },
892
- preventMultiline: { type: Boolean }
899
+ preventMultiline: { type: Boolean },
900
+ htmlParser: { type: Function }
893
901
  },
894
902
  emits: ["keydown", "update:modelValue", "update:styles"],
895
903
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -1089,7 +1097,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1089
1097
  onCut: _cache[3] || (_cache[3] = //@ts-ignore
1090
1098
  (...args) => unref(onCut) && unref(onCut)(...args))
1091
1099
  }, [
1092
- renderSlot(_ctx.$slots, "_before"),
1093
1100
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(store).blocks, (block) => {
1094
1101
  return openBlock(), createBlock(_sfc_main$2, {
1095
1102
  key: block.id,
@@ -1101,30 +1108,66 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1101
1108
  onPostrender: onPostRender
1102
1109
  }, null, 8, ["block", "slots", "renderer", "decorator", "parser"]);
1103
1110
  }), 128)),
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")
1111
+ unref(store).blocks.length === 1 && unref(store).blocks[0].text === "" && !unref(store).blocks[0].type ? renderSlot(_ctx.$slots, "placeholder", { key: 0 }) : createCommentVNode("", true)
1106
1112
  ], 544);
1107
1113
  };
1108
1114
  }
1109
1115
  });
1116
+ const wrapLists = (blocks, creator) => {
1117
+ if (!blocks.some((i) => !!creator(i))) {
1118
+ return blocks;
1119
+ }
1120
+ const arr = [];
1121
+ let liArray = [];
1122
+ let currentListTag = null;
1123
+ for (let i of blocks) {
1124
+ let listTag = creator(i);
1125
+ if (listTag) {
1126
+ if (currentListTag == null || listTag !== currentListTag) {
1127
+ liArray = [];
1128
+ arr.push(liArray);
1129
+ currentListTag = listTag;
1130
+ }
1131
+ liArray.push(i);
1132
+ } else {
1133
+ arr.push(i);
1134
+ currentListTag = null;
1135
+ }
1136
+ }
1137
+ return arr;
1138
+ };
1110
1139
  const _sfc_main = defineComponent({
1111
- props: ["modelValue", "decorator", "parser", "styles", "renderer"],
1140
+ props: ["modelValue", "decorator", "parser", "styles", "renderer", "listParser"],
1112
1141
  setup(props, { slots }) {
1113
1142
  const blocks = computed(() => {
1114
1143
  if (Array.isArray(props.modelValue)) {
1144
+ if (props.listParser && props.modelValue.some((i) => props.listParser(i))) {
1145
+ return wrapLists(props.modelValue, props.listParser);
1146
+ }
1115
1147
  return props.modelValue;
1116
1148
  }
1117
1149
  return [{ text: props.modelValue, styles: props.styles ?? [] }];
1118
1150
  });
1119
- return () => h("div", blocks.value.map((block) => h(_sfc_main$2, {
1120
- key: block.id,
1121
- block,
1122
- slots,
1123
- decorator: props.decorator,
1124
- renderer: props.renderer,
1125
- parser: props.parser,
1126
- static: true
1127
- })));
1151
+ return () => h("div", blocks.value.map((block) => {
1152
+ var _a;
1153
+ return Array.isArray(block) ? h(((_a = props.listParser) == null ? void 0 : _a.call(props, block[0])) ?? "ul", { key: block[0].id }, block.map((block2) => h(_sfc_main$2, {
1154
+ key: block2.id,
1155
+ block: block2,
1156
+ slots,
1157
+ decorator: props.decorator,
1158
+ renderer: props.renderer,
1159
+ parser: props.parser,
1160
+ static: true
1161
+ }))) : h(_sfc_main$2, {
1162
+ key: block.id,
1163
+ block,
1164
+ slots,
1165
+ decorator: props.decorator,
1166
+ renderer: props.renderer,
1167
+ parser: props.parser,
1168
+ static: true
1169
+ });
1170
+ }));
1128
1171
  }
1129
1172
  });
1130
1173
  export {
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.24-a",
5
+ "version": "0.0.25",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "den59k",
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["Vue.volar"]
3
- }