rme 0.3.0-beta.5 → 0.3.0-beta.6
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/index.mjs +78 -115
- package/dist/index.mjs.map +2 -2
- package/package.json +9 -9
package/dist/index.mjs
CHANGED
|
@@ -3854,6 +3854,71 @@ function isTextOnlySlice(slice) {
|
|
|
3854
3854
|
return false;
|
|
3855
3855
|
}
|
|
3856
3856
|
var ClipboardExtension = class extends PlainExtension2 {
|
|
3857
|
+
constructor() {
|
|
3858
|
+
super(...arguments);
|
|
3859
|
+
this.handleClipboardData = async ({
|
|
3860
|
+
html: html2 = "",
|
|
3861
|
+
text = "",
|
|
3862
|
+
view
|
|
3863
|
+
}) => {
|
|
3864
|
+
const editable = view.props.editable?.(view.state);
|
|
3865
|
+
if (!editable) return false;
|
|
3866
|
+
const currentNode = view.state.selection.$from.node();
|
|
3867
|
+
if (currentNode.type.spec.code) return false;
|
|
3868
|
+
if (html2.length === 0 && text.length === 0) return false;
|
|
3869
|
+
console.log("html", html2);
|
|
3870
|
+
console.log("text", text);
|
|
3871
|
+
const transformer = getTransformerByView(view);
|
|
3872
|
+
const parser = transformer.stringToDoc;
|
|
3873
|
+
const schema = view.state.schema;
|
|
3874
|
+
const domParser = DOMParser2.fromSchema(schema);
|
|
3875
|
+
let dom;
|
|
3876
|
+
if (html2.length === 0) {
|
|
3877
|
+
const slice2 = parser?.(text);
|
|
3878
|
+
if (!slice2 || typeof slice2 === "string") return false;
|
|
3879
|
+
const res = [];
|
|
3880
|
+
slice2.content.forEach((node2, index) => {
|
|
3881
|
+
if (node2.type.name === "paragraph" && index === 0) {
|
|
3882
|
+
node2.content.forEach((child) => {
|
|
3883
|
+
res.push(child);
|
|
3884
|
+
});
|
|
3885
|
+
} else {
|
|
3886
|
+
res.push(node2);
|
|
3887
|
+
}
|
|
3888
|
+
});
|
|
3889
|
+
this.processImagesInNodesAsync(res, view);
|
|
3890
|
+
if (res.length === 1) {
|
|
3891
|
+
view.dispatch(view.state.tr.replaceSelectionWith(res[0], false));
|
|
3892
|
+
} else {
|
|
3893
|
+
const fragment = Fragment3.from(res);
|
|
3894
|
+
view.dispatch(view.state.tr.replaceSelection(new Slice(fragment, 0, 0)));
|
|
3895
|
+
}
|
|
3896
|
+
return true;
|
|
3897
|
+
} else {
|
|
3898
|
+
const template = document.createElement("template");
|
|
3899
|
+
template.innerHTML = html2;
|
|
3900
|
+
dom = template.content.cloneNode(true);
|
|
3901
|
+
template.remove();
|
|
3902
|
+
}
|
|
3903
|
+
const slice = domParser.parseSlice(dom);
|
|
3904
|
+
const node = isTextOnlySlice(slice);
|
|
3905
|
+
console.log("slice", slice, node);
|
|
3906
|
+
if (node) {
|
|
3907
|
+
if ((node.type.name === "html_image" || node.type.name === "md_image") && node.attrs.src) {
|
|
3908
|
+
this.processImageNode(node, view);
|
|
3909
|
+
view.dispatch(view.state.tr.replaceSelectionWith(node, true));
|
|
3910
|
+
} else {
|
|
3911
|
+
this.processMarkdownImageSyntax(node, view).then(() => {
|
|
3912
|
+
view.dispatch(view.state.tr.replaceSelectionWith(node, true));
|
|
3913
|
+
});
|
|
3914
|
+
}
|
|
3915
|
+
return true;
|
|
3916
|
+
}
|
|
3917
|
+
this.processImagesInSliceAsync(slice, view);
|
|
3918
|
+
view.dispatch(view.state.tr.replaceSelection(slice));
|
|
3919
|
+
return true;
|
|
3920
|
+
};
|
|
3921
|
+
}
|
|
3857
3922
|
get name() {
|
|
3858
3923
|
return "clipboard";
|
|
3859
3924
|
}
|
|
@@ -3861,61 +3926,13 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
3861
3926
|
return {
|
|
3862
3927
|
props: {
|
|
3863
3928
|
handlePaste: (view, event) => {
|
|
3864
|
-
const transformer = getTransformerByView(view);
|
|
3865
|
-
const parser = transformer.stringToDoc;
|
|
3866
|
-
const schema = view.state.schema;
|
|
3867
|
-
const editable = view.props.editable?.(view.state);
|
|
3868
3929
|
const { clipboardData } = event;
|
|
3869
|
-
if (!
|
|
3930
|
+
if (!clipboardData) return false;
|
|
3870
3931
|
const currentNode = view.state.selection.$from.node();
|
|
3871
3932
|
if (currentNode.type.spec.code) return false;
|
|
3872
3933
|
const text = clipboardData.getData("text/plain");
|
|
3873
3934
|
const html2 = clipboardData.getData("text/html");
|
|
3874
|
-
|
|
3875
|
-
const domParser = DOMParser2.fromSchema(schema);
|
|
3876
|
-
let dom;
|
|
3877
|
-
if (html2.length === 0) {
|
|
3878
|
-
const slice2 = parser?.(text);
|
|
3879
|
-
if (!slice2 || typeof slice2 === "string") return false;
|
|
3880
|
-
const res = [];
|
|
3881
|
-
slice2.content.forEach((node2, index) => {
|
|
3882
|
-
if (node2.type.name === "paragraph" && index === 0) {
|
|
3883
|
-
node2.content.forEach((child) => {
|
|
3884
|
-
res.push(child);
|
|
3885
|
-
});
|
|
3886
|
-
} else {
|
|
3887
|
-
res.push(node2);
|
|
3888
|
-
}
|
|
3889
|
-
});
|
|
3890
|
-
this.processImagesInNodesAsync(res, view);
|
|
3891
|
-
if (res.length === 1) {
|
|
3892
|
-
view.dispatch(view.state.tr.replaceSelectionWith(res[0], false));
|
|
3893
|
-
} else {
|
|
3894
|
-
const fragment = Fragment3.from(res);
|
|
3895
|
-
view.dispatch(view.state.tr.replaceSelection(new Slice(fragment, 0, 0)));
|
|
3896
|
-
}
|
|
3897
|
-
return true;
|
|
3898
|
-
} else {
|
|
3899
|
-
const template = document.createElement("template");
|
|
3900
|
-
template.innerHTML = html2;
|
|
3901
|
-
dom = template.content.cloneNode(true);
|
|
3902
|
-
template.remove();
|
|
3903
|
-
}
|
|
3904
|
-
const slice = domParser.parseSlice(dom);
|
|
3905
|
-
const node = isTextOnlySlice(slice);
|
|
3906
|
-
if (node) {
|
|
3907
|
-
if ((node.type.name === "html_image" || node.type.name === "md_image") && node.attrs.src) {
|
|
3908
|
-
this.processImageNode(node, view);
|
|
3909
|
-
view.dispatch(view.state.tr.replaceSelectionWith(node, true));
|
|
3910
|
-
} else {
|
|
3911
|
-
this.processMarkdownImageSyntax(node, view).then(() => {
|
|
3912
|
-
view.dispatch(view.state.tr.replaceSelectionWith(node, true));
|
|
3913
|
-
});
|
|
3914
|
-
}
|
|
3915
|
-
return true;
|
|
3916
|
-
}
|
|
3917
|
-
this.processImagesInSliceAsync(slice, view);
|
|
3918
|
-
view.dispatch(view.state.tr.replaceSelection(slice));
|
|
3935
|
+
this.handleClipboardData({ text, html: html2, view });
|
|
3919
3936
|
return true;
|
|
3920
3937
|
},
|
|
3921
3938
|
clipboardTextSerializer: (slice, view) => {
|
|
@@ -3950,66 +3967,13 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
3950
3967
|
return (params) => {
|
|
3951
3968
|
const { view } = params;
|
|
3952
3969
|
if (!view) return false;
|
|
3953
|
-
const transformer = getTransformerByView(view);
|
|
3954
|
-
const parser = transformer.stringToDoc;
|
|
3955
|
-
const schema = view.state.schema;
|
|
3956
|
-
const editable = view.props.editable?.(view.state);
|
|
3957
3970
|
if (!this.options.clipboardReadFunction) {
|
|
3958
3971
|
return false;
|
|
3959
3972
|
}
|
|
3960
3973
|
this.options.clipboardReadFunction().then(async (data) => {
|
|
3961
3974
|
let { html: html2, text } = data;
|
|
3962
|
-
if (!
|
|
3963
|
-
|
|
3964
|
-
if (currentNode.type.spec.code) return false;
|
|
3965
|
-
if (html2.length === 0 && text.length === 0) return false;
|
|
3966
|
-
console.log("html", html2);
|
|
3967
|
-
console.log("text", text);
|
|
3968
|
-
const domParser = DOMParser2.fromSchema(schema);
|
|
3969
|
-
let dom;
|
|
3970
|
-
if (html2.length === 0) {
|
|
3971
|
-
const slice2 = parser?.(text);
|
|
3972
|
-
if (!slice2 || typeof slice2 === "string") return false;
|
|
3973
|
-
const res = [];
|
|
3974
|
-
slice2.content.forEach((node2, index) => {
|
|
3975
|
-
if (node2.type.name === "paragraph" && index === 0) {
|
|
3976
|
-
node2.content.forEach((child) => {
|
|
3977
|
-
res.push(child);
|
|
3978
|
-
});
|
|
3979
|
-
} else {
|
|
3980
|
-
res.push(node2);
|
|
3981
|
-
}
|
|
3982
|
-
});
|
|
3983
|
-
this.processImagesInNodesAsync(res, view);
|
|
3984
|
-
if (res.length === 1) {
|
|
3985
|
-
view.dispatch(view.state.tr.replaceSelectionWith(res[0], false));
|
|
3986
|
-
} else {
|
|
3987
|
-
const fragment = Fragment3.from(res);
|
|
3988
|
-
view.dispatch(view.state.tr.replaceSelection(new Slice(fragment, 0, 0)));
|
|
3989
|
-
}
|
|
3990
|
-
return true;
|
|
3991
|
-
} else {
|
|
3992
|
-
const template = document.createElement("template");
|
|
3993
|
-
template.innerHTML = html2;
|
|
3994
|
-
dom = template.content.cloneNode(true);
|
|
3995
|
-
template.remove();
|
|
3996
|
-
}
|
|
3997
|
-
const slice = domParser.parseSlice(dom);
|
|
3998
|
-
const node = isTextOnlySlice(slice);
|
|
3999
|
-
console.log("slice", slice, node);
|
|
4000
|
-
if (node) {
|
|
4001
|
-
if ((node.type.name === "html_image" || node.type.name === "md_image") && node.attrs.src) {
|
|
4002
|
-
this.processImageNode(node, view);
|
|
4003
|
-
view.dispatch(view.state.tr.replaceSelectionWith(node, true));
|
|
4004
|
-
} else {
|
|
4005
|
-
this.processMarkdownImageSyntax(node, view).then(() => {
|
|
4006
|
-
view.dispatch(view.state.tr.replaceSelectionWith(node, true));
|
|
4007
|
-
});
|
|
4008
|
-
}
|
|
4009
|
-
return true;
|
|
4010
|
-
}
|
|
4011
|
-
this.processImagesInSliceAsync(slice, view);
|
|
4012
|
-
view.dispatch(view.state.tr.replaceSelection(slice));
|
|
3975
|
+
if (!html2 || !text) return false;
|
|
3976
|
+
return await this.handleClipboardData({ html: html2, text, view });
|
|
4013
3977
|
});
|
|
4014
3978
|
return true;
|
|
4015
3979
|
};
|
|
@@ -4066,13 +4030,13 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
4066
4030
|
imageCopyHandler(node.attrs.src).then((newSrc) => {
|
|
4067
4031
|
if (newSrc && newSrc !== node.attrs.src) {
|
|
4068
4032
|
this.updateImageNodeSrc(view, node, newSrc);
|
|
4069
|
-
} else {
|
|
4070
|
-
const { state, dispatch } = view;
|
|
4071
|
-
node.attrs["data-rme-loading"] = null;
|
|
4072
|
-
dispatch(state.tr);
|
|
4073
4033
|
}
|
|
4074
4034
|
}).catch((error) => {
|
|
4075
4035
|
console.warn("imageCopyHandler failed:", error);
|
|
4036
|
+
}).finally(() => {
|
|
4037
|
+
const { state, dispatch } = view;
|
|
4038
|
+
node.attrs["data-rme-loading"] = null;
|
|
4039
|
+
dispatch(state.tr);
|
|
4076
4040
|
});
|
|
4077
4041
|
}
|
|
4078
4042
|
/**
|
|
@@ -6853,8 +6817,8 @@ import { jsx as jsx14 } from "react/jsx-runtime";
|
|
|
6853
6817
|
var warningFallBack = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAAAAACIM/FCAAAChElEQVR4Ae3aMW/TQBxAcb70k91AAiGuGlZAtOlQApWaDiSdklZq2RPUTm1xUWL3PgqSpygkXlh88N54nn7S2Trd3y/CP5IQIUKECBEiRIgQIUKECBEiRIgQIUKECBEiRIgQIUKECBEiRIgQIUKECBEiRIgQIUKECBEiRIgQIUKECPmPIEKECBEiRIgQIeX82+FBO0naB4eTRRkt5P7sNWt1Rw9RQvKThI2SYR4f5OoVW2rfRAYpT6hqHc8WeVHki9mgRdWwiAmyfA9AdrlaW5tlAHxcxQMpK8feRbGxPEkrSREN5ARg/y780V0GMIwFcgXwLg9byvsAN3FA8lfAfr7jYQZ0nqKAfAb21vYVwNruSoEvMUDuE+Ai7IKECZA+RAA5A7JiN6TMgFHzIeUb4DLshoQZ0H1uPGQOvFzVQZYtYNF4yBg4DnWQMAAmjYccArN6yBQ4ajzkAFjUQ+ZAv/GQNpDXQ3Kg03hIAhT1kAJIhLi1/vJl39Ic6Mf3+a2K8PM7BgahtgEwjuKI0lqGjSI8opRdYFb3sk/jODSGEZCVuyFFDzgPzYc8JMBkN2QMpI8RQMIQ2LvdBblNgdM4Lh/aQJaHrf3sAe2nKCDhGqCfb3VEcx1UNQTItlzQ3fYAvoZYIMUHgHRSbiyPU4BPZUSX2JWEbLZcW5v2qByrmMYKxZCq1mA6z4sin08HLapOy8gGPddtttT5HuHobZiwUXr6K85h6KjLWm/PH+MdTy/GR/12knb6g8mPZ38YECJEiBAhQoQIESJEiBAhQoQIESJEiBAhQoQIESJEiBAhQoQIESJEiBAhQoQIESJEiBAhQoQIESJEiBAhQoQIESJEiBAh0fUb5q7oCGreEVEAAAAASUVORK5CYII=";
|
|
6854
6818
|
function ImageNodeView(props) {
|
|
6855
6819
|
const { node, selected, updateAttributes, handleViewImgSrcUrl, imageHostingHandler } = props;
|
|
6856
|
-
const initRef = useRef7();
|
|
6857
|
-
const popoverStore = useRef7();
|
|
6820
|
+
const initRef = useRef7(null);
|
|
6821
|
+
const popoverStore = useRef7(null);
|
|
6858
6822
|
const popoverRef = useRef7(null);
|
|
6859
6823
|
const handleStoreChange = (store) => {
|
|
6860
6824
|
popoverStore.current = store;
|
|
@@ -6913,10 +6877,10 @@ function ImageNodeView(props) {
|
|
|
6913
6877
|
});
|
|
6914
6878
|
},
|
|
6915
6879
|
...node.attrs
|
|
6916
|
-
}
|
|
6880
|
+
},
|
|
6881
|
+
`${node.attrs.src}_${node.attrs["data-rme-loading"]}`
|
|
6917
6882
|
)
|
|
6918
|
-
}
|
|
6919
|
-
`${node.attrs.src}_${node.attrs["data-rme-loading"]}`
|
|
6883
|
+
}
|
|
6920
6884
|
);
|
|
6921
6885
|
return /* @__PURE__ */ jsx14("div", { ref: popoverRef, style: { position: "relative", zIndex: selected ? 10 : "auto" }, children: /* @__PURE__ */ jsx14(
|
|
6922
6886
|
Popover2,
|
|
@@ -9038,7 +9002,6 @@ var MathInlineView = class {
|
|
|
9038
9002
|
}
|
|
9039
9003
|
this._renderElt.replaceWith(newRenderEl);
|
|
9040
9004
|
this._renderElt = newRenderEl;
|
|
9041
|
-
console.log("this.renderElt", this._renderElt.outerHTML);
|
|
9042
9005
|
this.dom.appendChild(this._renderElt);
|
|
9043
9006
|
if (preview) {
|
|
9044
9007
|
this._renderElt.classList.add("inline-input-preview");
|