vue-editify 0.1.39 → 0.1.40
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/lib/editify.es.js +88 -17
- package/lib/editify.umd.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/plugins/mathformula/index.d.ts +18 -0
- package/lib/plugins/mathformula/insertMathformula/insertMathformula.vue.d.ts +9 -0
- package/lib/plugins/mathformula/insertMathformula/props.d.ts +4 -0
- package/lib/style.css +1 -1
- package/package.json +1 -1
- package/src/editify/editify.less +27 -2
- package/src/index.ts +2 -2
- package/src/plugins/mathformula/index.ts +114 -26
- package/src/plugins/mathformula/insertMathformula/insertMathformula.vue +11 -1
- package/src/plugins/mathformula/insertMathformula/props.ts +5 -0
package/lib/editify.es.js
CHANGED
@@ -40720,6 +40720,11 @@ const InsertMathformulaProps = {
|
|
40720
40720
|
color: {
|
40721
40721
|
type: String,
|
40722
40722
|
default: ""
|
40723
|
+
},
|
40724
|
+
//预置的LaTex文本内容
|
40725
|
+
defaultLaTexContent: {
|
40726
|
+
type: String,
|
40727
|
+
default: ""
|
40723
40728
|
}
|
40724
40729
|
};
|
40725
40730
|
const _hoisted_1 = { class: "editify-mathformula" };
|
@@ -40749,6 +40754,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
40749
40754
|
const insertMathformula = () => {
|
40750
40755
|
emits("insert", latexContent.value);
|
40751
40756
|
};
|
40757
|
+
watch(
|
40758
|
+
() => props.defaultLaTexContent,
|
40759
|
+
(newVal) => {
|
40760
|
+
latexContent.value = newVal;
|
40761
|
+
},
|
40762
|
+
{
|
40763
|
+
immediate: true
|
40764
|
+
}
|
40765
|
+
);
|
40752
40766
|
return (_ctx, _cache) => {
|
40753
40767
|
return openBlock(), createElementBlock("div", _hoisted_1, [
|
40754
40768
|
createElementVNode("div", _hoisted_2, toDisplayString(unref($editTrans)("insertMathformula")), 1),
|
@@ -40776,7 +40790,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
40776
40790
|
};
|
40777
40791
|
}
|
40778
40792
|
});
|
40779
|
-
const InsertMathformula = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
40793
|
+
const InsertMathformula = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ed1761a7"]]);
|
40780
40794
|
const isMathformula = (el) => {
|
40781
40795
|
return el.parsedom == "span" && el.hasMarks() && el.marks["data-editify-mathformula"];
|
40782
40796
|
};
|
@@ -40809,6 +40823,37 @@ const hasMathformulaInRange = (editor, dataRangeCaches) => {
|
|
40809
40823
|
return isUnderMathformula(item.element);
|
40810
40824
|
});
|
40811
40825
|
};
|
40826
|
+
const getMathformulaElementByRange = (editor, dataRangeCaches) => {
|
40827
|
+
if (!editor.range) {
|
40828
|
+
return null;
|
40829
|
+
}
|
40830
|
+
if (editor.range.anchor.element.isEqual(editor.range.focus.element)) {
|
40831
|
+
return getMathformulaElement(editor.range.anchor.element);
|
40832
|
+
}
|
40833
|
+
const arr = dataRangeCaches.list.map((item) => {
|
40834
|
+
return getMathformulaElement(item.element);
|
40835
|
+
});
|
40836
|
+
let hasNull = arr.some((el) => {
|
40837
|
+
return el == null;
|
40838
|
+
});
|
40839
|
+
if (hasNull) {
|
40840
|
+
return null;
|
40841
|
+
}
|
40842
|
+
if (arr.length == 1) {
|
40843
|
+
return arr[0];
|
40844
|
+
}
|
40845
|
+
let flag = true;
|
40846
|
+
for (let i = 1; i < arr.length; i++) {
|
40847
|
+
if (!arr[i].isEqual(arr[0])) {
|
40848
|
+
flag = false;
|
40849
|
+
break;
|
40850
|
+
}
|
40851
|
+
}
|
40852
|
+
if (flag) {
|
40853
|
+
return arr[0];
|
40854
|
+
}
|
40855
|
+
return null;
|
40856
|
+
};
|
40812
40857
|
const mathformula = (options) => {
|
40813
40858
|
if (!common.isObject(options)) {
|
40814
40859
|
options = {};
|
@@ -40816,9 +40861,11 @@ const mathformula = (options) => {
|
|
40816
40861
|
const plugin = (editifyInstance, editTrans) => {
|
40817
40862
|
let isDisabled = false;
|
40818
40863
|
if (editifyInstance.exposed.editor.value) {
|
40819
|
-
isDisabled =
|
40864
|
+
isDisabled = hasPreInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) || hasLinkInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value);
|
40820
40865
|
}
|
40866
|
+
let defaultLaTexContent = "";
|
40821
40867
|
return {
|
40868
|
+
//插件名称
|
40822
40869
|
name: "mathformula",
|
40823
40870
|
//菜单项配置
|
40824
40871
|
menu: {
|
@@ -40835,29 +40882,51 @@ const mathformula = (options) => {
|
|
40835
40882
|
leftBorder: options.leftBorder,
|
40836
40883
|
rightBorder: options.rightBorder,
|
40837
40884
|
hideScroll: true,
|
40838
|
-
active: false,
|
40885
|
+
active: editifyInstance.exposed.editor.value ? hasMathformulaInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) : false,
|
40839
40886
|
disabled: isDisabled || options.disabled,
|
40887
|
+
//浮层展开时触发的事件
|
40888
|
+
onLayerShow() {
|
40889
|
+
const mathformulaElement = getMathformulaElementByRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value);
|
40890
|
+
if (mathformulaElement) {
|
40891
|
+
defaultLaTexContent = mathformulaElement.marks["data-editify-mathformula"] || "";
|
40892
|
+
}
|
40893
|
+
},
|
40840
40894
|
default: () => h(Icon, { value: "mathformula" }),
|
40841
40895
|
layer: (_name, btnInstance) => {
|
40842
40896
|
return h(InsertMathformula, {
|
40843
40897
|
color: editifyInstance.props.color,
|
40898
|
+
defaultLaTexContent,
|
40844
40899
|
onInsert: (content) => {
|
40845
40900
|
if (content) {
|
40846
40901
|
const editor = editifyInstance.exposed.editor.value;
|
40847
|
-
const
|
40848
|
-
|
40902
|
+
const mathformulaElement = getMathformulaElementByRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value);
|
40903
|
+
if (mathformulaElement) {
|
40904
|
+
mathformulaElement.toEmpty();
|
40905
|
+
editor.range.anchor.moveToStart(editor.getNextElement(mathformulaElement));
|
40906
|
+
editor.range.focus.moveToStart(editor.getNextElement(mathformulaElement));
|
40907
|
+
}
|
40908
|
+
let mathml = "";
|
40909
|
+
try {
|
40910
|
+
mathml = katex.renderToString(content, {
|
40849
40911
|
output: "mathml",
|
40850
|
-
throwOnError:
|
40851
|
-
})
|
40852
|
-
)
|
40853
|
-
|
40854
|
-
|
40855
|
-
|
40856
|
-
|
40857
|
-
|
40858
|
-
|
40859
|
-
|
40860
|
-
|
40912
|
+
throwOnError: true
|
40913
|
+
});
|
40914
|
+
} catch (error2) {
|
40915
|
+
mathml = "";
|
40916
|
+
if (typeof options.handleError == "function") {
|
40917
|
+
options.handleError(error2);
|
40918
|
+
}
|
40919
|
+
}
|
40920
|
+
if (mathml) {
|
40921
|
+
const html = `<span data-editify-mathformula="${content}" contenteditable="false">${mathml}</span>`;
|
40922
|
+
const elements = editor.parseHtml(html);
|
40923
|
+
editor.insertElement(elements[0]);
|
40924
|
+
editor.range.anchor.moveToEnd(elements[0]);
|
40925
|
+
editor.range.focus.moveToEnd(elements[0]);
|
40926
|
+
editor.formatElementStack();
|
40927
|
+
editor.domRender();
|
40928
|
+
editor.rangeRender();
|
40929
|
+
}
|
40861
40930
|
}
|
40862
40931
|
btnInstance.show = false;
|
40863
40932
|
}
|
@@ -41076,7 +41145,7 @@ const attachment = (options) => {
|
|
41076
41145
|
const install = (app) => {
|
41077
41146
|
app.component(Editify.name, Editify);
|
41078
41147
|
};
|
41079
|
-
const version = "0.1.
|
41148
|
+
const version = "0.1.40";
|
41080
41149
|
console.log(`%c vue-editify %c v${version} `, "padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060; font-weight: bold;", "padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e; font-weight: bold;");
|
41081
41150
|
export {
|
41082
41151
|
AlexElement,
|
@@ -41087,12 +41156,14 @@ export {
|
|
41087
41156
|
elementIsInTask,
|
41088
41157
|
getCurrentParsedomElement,
|
41089
41158
|
getMathformulaElement,
|
41159
|
+
getMathformulaElementByRange,
|
41090
41160
|
getParsedomElementByElement,
|
41091
41161
|
getRangeText,
|
41092
41162
|
hasAttachmentInRange,
|
41093
41163
|
hasImageInRange,
|
41094
41164
|
hasLinkInRange,
|
41095
41165
|
hasListInRange,
|
41166
|
+
hasMathformulaInRange,
|
41096
41167
|
hasPreInRange,
|
41097
41168
|
hasQuoteInRange,
|
41098
41169
|
hasTableInRange,
|