vuewrite 0.0.24 → 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.
- package/dist/vuewrite.d.ts +5 -1
- package/dist/vuewrite.js +63 -19
- package/package.json +1 -1
- package/.vscode/extensions.json +0 -3
package/dist/vuewrite.d.ts
CHANGED
|
@@ -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,12 +128,12 @@ 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
138
|
}>;
|
|
138
139
|
|
|
@@ -262,6 +263,7 @@ decorator?: any;
|
|
|
262
263
|
renderer?: any;
|
|
263
264
|
parser?: any;
|
|
264
265
|
modelValue?: any;
|
|
266
|
+
listParser?: any;
|
|
265
267
|
}>, () => VNode<RendererNode, RendererElement, {
|
|
266
268
|
[key: string]: any;
|
|
267
269
|
}>, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<Readonly<{
|
|
@@ -270,12 +272,14 @@ decorator?: any;
|
|
|
270
272
|
renderer?: any;
|
|
271
273
|
parser?: any;
|
|
272
274
|
modelValue?: any;
|
|
275
|
+
listParser?: any;
|
|
273
276
|
}>>>, {
|
|
274
277
|
readonly styles?: any;
|
|
275
278
|
readonly decorator?: any;
|
|
276
279
|
readonly renderer?: any;
|
|
277
280
|
readonly parser?: any;
|
|
278
281
|
readonly modelValue?: any;
|
|
282
|
+
readonly listParser?: any;
|
|
279
283
|
}, {}>;
|
|
280
284
|
|
|
281
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,
|
|
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,
|
|
@@ -1106,24 +1113,61 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
1106
1113
|
};
|
|
1107
1114
|
}
|
|
1108
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
|
+
};
|
|
1109
1139
|
const _sfc_main = defineComponent({
|
|
1110
|
-
props: ["modelValue", "decorator", "parser", "styles", "renderer"],
|
|
1140
|
+
props: ["modelValue", "decorator", "parser", "styles", "renderer", "listParser"],
|
|
1111
1141
|
setup(props, { slots }) {
|
|
1112
1142
|
const blocks = computed(() => {
|
|
1113
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
|
+
}
|
|
1114
1147
|
return props.modelValue;
|
|
1115
1148
|
}
|
|
1116
1149
|
return [{ text: props.modelValue, styles: props.styles ?? [] }];
|
|
1117
1150
|
});
|
|
1118
|
-
return () => h("div", blocks.value.map((block) =>
|
|
1119
|
-
|
|
1120
|
-
block,
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
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
|
+
}));
|
|
1127
1171
|
}
|
|
1128
1172
|
});
|
|
1129
1173
|
export {
|
package/package.json
CHANGED
package/.vscode/extensions.json
DELETED