rme 0.3.0-beta.5 → 0.3.0-beta.7
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 +218 -261
- package/dist/index.mjs.map +3 -3
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -890,9 +890,21 @@ var WysiwygThemeWrapper = styled.div.attrs((p) => ({
|
|
|
890
890
|
color: ${(props) => props.theme.labelFontColor};
|
|
891
891
|
}
|
|
892
892
|
|
|
893
|
-
.
|
|
894
|
-
|
|
895
|
-
|
|
893
|
+
& .inline-loading {
|
|
894
|
+
width: min-content;
|
|
895
|
+
height: min-content;
|
|
896
|
+
display: inline-block;
|
|
897
|
+
font-size: 16px;
|
|
898
|
+
animation: loading-icon-spin 1s linear infinite;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
@keyframes loading-icon-spin {
|
|
902
|
+
0% {
|
|
903
|
+
transform: rotate(0deg);
|
|
904
|
+
}
|
|
905
|
+
100% {
|
|
906
|
+
transform: rotate(360deg);
|
|
907
|
+
}
|
|
896
908
|
}
|
|
897
909
|
|
|
898
910
|
.html_tag {
|
|
@@ -3798,40 +3810,6 @@ var LineBlockquoteExtension = class extends BlockquoteExtension {
|
|
|
3798
3810
|
// src/editor/extensions/Clipboard/clipboard-extension.ts
|
|
3799
3811
|
import { extension as extension2, PlainExtension as PlainExtension2 } from "@rme-sdk/core";
|
|
3800
3812
|
import { DOMParser as DOMParser2, Fragment as Fragment3, Slice } from "@rme-sdk/pm/model";
|
|
3801
|
-
|
|
3802
|
-
// src/editor/inline-input-regex/index.ts
|
|
3803
|
-
var getMdImageInputRule = (nodeType) => [
|
|
3804
|
-
{
|
|
3805
|
-
regexp: /!\[([^\]]*)\]\(([^\s"]+(?:\s+[^\s"]+)*)?(?:\s+"(.*?)")?\)/,
|
|
3806
|
-
type: nodeType,
|
|
3807
|
-
getAttributes: (match) => {
|
|
3808
|
-
const [, alt, src, title] = match;
|
|
3809
|
-
return { alt, src, title };
|
|
3810
|
-
}
|
|
3811
|
-
}
|
|
3812
|
-
];
|
|
3813
|
-
var getInlineMathInputRule = (nodeType) => [
|
|
3814
|
-
// Typed inline math trigger: $$ -> insert empty inline math and focus inside
|
|
3815
|
-
{
|
|
3816
|
-
regexp: /\$\$(?!\$)/,
|
|
3817
|
-
type: nodeType,
|
|
3818
|
-
getAttributes: () => ({ tex: "", fromInput: true })
|
|
3819
|
-
},
|
|
3820
|
-
{
|
|
3821
|
-
regexp: /<span[^>]*data-type=["']math-inline["'][^>]*><\/span>/,
|
|
3822
|
-
type: nodeType,
|
|
3823
|
-
getAttributes: () => ({ fromInput: false })
|
|
3824
|
-
},
|
|
3825
|
-
{
|
|
3826
|
-
regexp: /\$([^$\n]+?)\$/,
|
|
3827
|
-
type: nodeType,
|
|
3828
|
-
getAttributes: (match) => {
|
|
3829
|
-
return { tex: match[1] ?? "", fromInput: true };
|
|
3830
|
-
}
|
|
3831
|
-
}
|
|
3832
|
-
];
|
|
3833
|
-
|
|
3834
|
-
// src/editor/extensions/Clipboard/clipboard-extension.ts
|
|
3835
3813
|
function isPureText(content) {
|
|
3836
3814
|
if (!content) return false;
|
|
3837
3815
|
if (Array.isArray(content)) {
|
|
@@ -3854,6 +3832,64 @@ function isTextOnlySlice(slice) {
|
|
|
3854
3832
|
return false;
|
|
3855
3833
|
}
|
|
3856
3834
|
var ClipboardExtension = class extends PlainExtension2 {
|
|
3835
|
+
constructor() {
|
|
3836
|
+
super(...arguments);
|
|
3837
|
+
this.handleClipboardData = async ({
|
|
3838
|
+
html: html2 = "",
|
|
3839
|
+
text = "",
|
|
3840
|
+
view
|
|
3841
|
+
}) => {
|
|
3842
|
+
const editable = view.props.editable?.(view.state);
|
|
3843
|
+
if (!editable) return false;
|
|
3844
|
+
const currentNode = view.state.selection.$from.node();
|
|
3845
|
+
if (currentNode.type.spec.code) return false;
|
|
3846
|
+
if (html2.length === 0 && text.length === 0) return false;
|
|
3847
|
+
console.log("html", html2);
|
|
3848
|
+
console.log("text", text);
|
|
3849
|
+
const transformer = getTransformerByView(view);
|
|
3850
|
+
const parser = transformer.stringToDoc;
|
|
3851
|
+
const schema = view.state.schema;
|
|
3852
|
+
const domParser = DOMParser2.fromSchema(schema);
|
|
3853
|
+
let dom;
|
|
3854
|
+
if (html2.length === 0) {
|
|
3855
|
+
const slice2 = parser?.(text);
|
|
3856
|
+
if (!slice2 || typeof slice2 === "string") return false;
|
|
3857
|
+
const nodes = [];
|
|
3858
|
+
slice2.content.forEach((node2, index) => {
|
|
3859
|
+
if (node2.type.name === "paragraph" && index === 0) {
|
|
3860
|
+
node2.content.forEach((child) => {
|
|
3861
|
+
nodes.push(child);
|
|
3862
|
+
});
|
|
3863
|
+
} else {
|
|
3864
|
+
nodes.push(node2);
|
|
3865
|
+
}
|
|
3866
|
+
});
|
|
3867
|
+
this.processImagesInNodesSync(nodes, view);
|
|
3868
|
+
if (nodes.length === 1) {
|
|
3869
|
+
view.dispatch(view.state.tr.replaceSelectionWith(nodes[0], false));
|
|
3870
|
+
} else {
|
|
3871
|
+
const fragment = Fragment3.from(nodes);
|
|
3872
|
+
view.dispatch(view.state.tr.replaceSelection(new Slice(fragment, 0, 0)));
|
|
3873
|
+
}
|
|
3874
|
+
return true;
|
|
3875
|
+
} else {
|
|
3876
|
+
const template = document.createElement("template");
|
|
3877
|
+
template.innerHTML = html2;
|
|
3878
|
+
dom = template.content.cloneNode(true);
|
|
3879
|
+
template.remove();
|
|
3880
|
+
}
|
|
3881
|
+
const slice = domParser.parseSlice(dom);
|
|
3882
|
+
const node = isTextOnlySlice(slice);
|
|
3883
|
+
if (node) {
|
|
3884
|
+
node.attrs["data-rme-from-paste"] = "true";
|
|
3885
|
+
view.dispatch(view.state.tr.replaceSelectionWith(node, true));
|
|
3886
|
+
return true;
|
|
3887
|
+
}
|
|
3888
|
+
this.processImagesInSliceAsync(slice, view);
|
|
3889
|
+
view.dispatch(view.state.tr.replaceSelection(slice));
|
|
3890
|
+
return true;
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3857
3893
|
get name() {
|
|
3858
3894
|
return "clipboard";
|
|
3859
3895
|
}
|
|
@@ -3861,61 +3897,13 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
3861
3897
|
return {
|
|
3862
3898
|
props: {
|
|
3863
3899
|
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
3900
|
const { clipboardData } = event;
|
|
3869
|
-
if (!
|
|
3901
|
+
if (!clipboardData) return false;
|
|
3870
3902
|
const currentNode = view.state.selection.$from.node();
|
|
3871
3903
|
if (currentNode.type.spec.code) return false;
|
|
3872
3904
|
const text = clipboardData.getData("text/plain");
|
|
3873
3905
|
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));
|
|
3906
|
+
this.handleClipboardData({ text, html: html2, view });
|
|
3919
3907
|
return true;
|
|
3920
3908
|
},
|
|
3921
3909
|
clipboardTextSerializer: (slice, view) => {
|
|
@@ -3950,66 +3938,13 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
3950
3938
|
return (params) => {
|
|
3951
3939
|
const { view } = params;
|
|
3952
3940
|
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
3941
|
if (!this.options.clipboardReadFunction) {
|
|
3958
3942
|
return false;
|
|
3959
3943
|
}
|
|
3960
3944
|
this.options.clipboardReadFunction().then(async (data) => {
|
|
3961
3945
|
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));
|
|
3946
|
+
if (!html2 || !text) return false;
|
|
3947
|
+
return await this.handleClipboardData({ html: html2, text, view });
|
|
4013
3948
|
});
|
|
4014
3949
|
return true;
|
|
4015
3950
|
};
|
|
@@ -4027,60 +3962,16 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
4027
3962
|
}
|
|
4028
3963
|
};
|
|
4029
3964
|
}
|
|
4030
|
-
/**
|
|
4031
|
-
* Process markdown image syntax in text nodes and update their src attributes using imageCopyHandler
|
|
4032
|
-
*/
|
|
4033
|
-
async processMarkdownImageSyntax(node, view) {
|
|
4034
|
-
const { imageCopyHandler } = this.options;
|
|
4035
|
-
if (!imageCopyHandler) return;
|
|
4036
|
-
const imageRegex = new RegExp(getMdImageInputRule("md_image")[0]?.regexp, "g");
|
|
4037
|
-
const processTextNode = async (n) => {
|
|
4038
|
-
if (n.isText && n.text) {
|
|
4039
|
-
let match;
|
|
4040
|
-
imageRegex.lastIndex = 0;
|
|
4041
|
-
while ((match = imageRegex.exec(n.text)) !== null) {
|
|
4042
|
-
const [, , src] = match;
|
|
4043
|
-
if (src) {
|
|
4044
|
-
const newSrc = await imageCopyHandler(src);
|
|
4045
|
-
if (newSrc && newSrc !== src) {
|
|
4046
|
-
n.text = n.text.replace(src, newSrc);
|
|
4047
|
-
}
|
|
4048
|
-
}
|
|
4049
|
-
}
|
|
4050
|
-
}
|
|
4051
|
-
if (n.content && n.content.size > 0) {
|
|
4052
|
-
n.content.forEach((child) => {
|
|
4053
|
-
processTextNode(child);
|
|
4054
|
-
});
|
|
4055
|
-
}
|
|
4056
|
-
};
|
|
4057
|
-
await processTextNode(node);
|
|
4058
|
-
}
|
|
4059
3965
|
/**
|
|
4060
3966
|
* Process a single image node asynchronously and update its src attribute using imageCopyHandler
|
|
4061
3967
|
*/
|
|
4062
3968
|
processImageNode(node, view) {
|
|
4063
|
-
|
|
4064
|
-
if (!imageCopyHandler || !node.attrs.src) return;
|
|
4065
|
-
node.attrs["data-rme-loading"] = "true";
|
|
4066
|
-
imageCopyHandler(node.attrs.src).then((newSrc) => {
|
|
4067
|
-
if (newSrc && newSrc !== node.attrs.src) {
|
|
4068
|
-
this.updateImageNodeSrc(view, node, newSrc);
|
|
4069
|
-
} else {
|
|
4070
|
-
const { state, dispatch } = view;
|
|
4071
|
-
node.attrs["data-rme-loading"] = null;
|
|
4072
|
-
dispatch(state.tr);
|
|
4073
|
-
}
|
|
4074
|
-
}).catch((error) => {
|
|
4075
|
-
console.warn("imageCopyHandler failed:", error);
|
|
4076
|
-
});
|
|
3969
|
+
node.attrs["data-rme-from-paste"] = "true";
|
|
4077
3970
|
}
|
|
4078
3971
|
/**
|
|
4079
3972
|
* Process images in a slice asynchronously and update their src attributes using imageCopyHandler
|
|
4080
3973
|
*/
|
|
4081
3974
|
processImagesInSliceAsync(slice, view) {
|
|
4082
|
-
const { imageCopyHandler } = this.options;
|
|
4083
|
-
if (!imageCopyHandler) return;
|
|
4084
3975
|
const imageNodes = [];
|
|
4085
3976
|
let currentPos = 0;
|
|
4086
3977
|
const findImageNodes = (node, pos) => {
|
|
@@ -4096,18 +3987,16 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
4096
3987
|
slice.content.forEach((node, offset) => {
|
|
4097
3988
|
findImageNodes(node, currentPos + offset);
|
|
4098
3989
|
});
|
|
4099
|
-
imageNodes.
|
|
3990
|
+
imageNodes.map(({ node, pos }) => {
|
|
4100
3991
|
if (node.attrs.src) {
|
|
4101
|
-
this.processImageNode(node, view);
|
|
3992
|
+
return this.processImageNode(node, view);
|
|
4102
3993
|
}
|
|
4103
3994
|
});
|
|
4104
3995
|
}
|
|
4105
3996
|
/**
|
|
4106
3997
|
* Process images in an array of nodes asynchronously and update their src attributes using imageCopyHandler
|
|
4107
3998
|
*/
|
|
4108
|
-
|
|
4109
|
-
const { imageCopyHandler } = this.options;
|
|
4110
|
-
if (!imageCopyHandler) return;
|
|
3999
|
+
processImagesInNodesSync(nodes, view) {
|
|
4111
4000
|
const processNode = (node) => {
|
|
4112
4001
|
if ((node.type.name === "html_image" || node.type.name === "md_image") && node.attrs.src) {
|
|
4113
4002
|
this.processImageNode(node, view);
|
|
@@ -4120,16 +4009,6 @@ var ClipboardExtension = class extends PlainExtension2 {
|
|
|
4120
4009
|
};
|
|
4121
4010
|
nodes.forEach(processNode);
|
|
4122
4011
|
}
|
|
4123
|
-
/**
|
|
4124
|
-
* Update image node src attribute in the document
|
|
4125
|
-
*/
|
|
4126
|
-
updateImageNodeSrc(view, node, newSrc) {
|
|
4127
|
-
const { state, dispatch } = view;
|
|
4128
|
-
let tr = state.tr;
|
|
4129
|
-
node.attrs.src = newSrc;
|
|
4130
|
-
node.attrs["data-rme-loading"] = null;
|
|
4131
|
-
dispatch(tr);
|
|
4132
|
-
}
|
|
4133
4012
|
};
|
|
4134
4013
|
ClipboardExtension = __decorateClass([
|
|
4135
4014
|
extension2({
|
|
@@ -4461,13 +4340,57 @@ FindExtension = __decorateClass([
|
|
|
4461
4340
|
|
|
4462
4341
|
// src/editor/extensions/HandleInput/handle-input-extension.ts
|
|
4463
4342
|
import { PlainExtension as PlainExtension4 } from "@rme-sdk/core";
|
|
4343
|
+
|
|
4344
|
+
// src/editor/inline-input-regex/index.ts
|
|
4345
|
+
var getMdImageInputRule = (nodeType) => [
|
|
4346
|
+
{
|
|
4347
|
+
regexp: /!\[([^\]]*)\]\(([^\s"]+(?:\s+[^\s"]+)*)?(?:\s+"(.*?)")?\)/,
|
|
4348
|
+
type: nodeType,
|
|
4349
|
+
getAttributes: (match) => {
|
|
4350
|
+
const [, alt, src, title] = match;
|
|
4351
|
+
return { alt, src, title };
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
];
|
|
4355
|
+
var getHtmlImageInputRule = (nodeType) => [
|
|
4356
|
+
{
|
|
4357
|
+
regexp: new RegExp("<img[^>]*>"),
|
|
4358
|
+
type: nodeType,
|
|
4359
|
+
getAttributes: (match) => {
|
|
4360
|
+
return getAttrsBySignalHtmlContent(match[0]);
|
|
4361
|
+
}
|
|
4362
|
+
}
|
|
4363
|
+
];
|
|
4364
|
+
var getInlineMathInputRule = (nodeType) => [
|
|
4365
|
+
// Typed inline math trigger: $$ -> insert empty inline math and focus inside
|
|
4366
|
+
{
|
|
4367
|
+
regexp: /\$\$(?!\$)/,
|
|
4368
|
+
type: nodeType,
|
|
4369
|
+
getAttributes: () => ({ tex: "", fromInput: true })
|
|
4370
|
+
},
|
|
4371
|
+
{
|
|
4372
|
+
regexp: /<span[^>]*data-type=["']math-inline["'][^>]*><\/span>/,
|
|
4373
|
+
type: nodeType,
|
|
4374
|
+
getAttributes: () => ({ fromInput: false })
|
|
4375
|
+
},
|
|
4376
|
+
{
|
|
4377
|
+
regexp: /\$([^$\n]+?)\$/,
|
|
4378
|
+
type: nodeType,
|
|
4379
|
+
getAttributes: (match) => {
|
|
4380
|
+
return { tex: match[1] ?? "", fromInput: true };
|
|
4381
|
+
}
|
|
4382
|
+
}
|
|
4383
|
+
];
|
|
4384
|
+
|
|
4385
|
+
// src/editor/extensions/HandleInput/handle-input-extension.ts
|
|
4464
4386
|
var excludeNodeName = ["math_block", "codeMirror"];
|
|
4465
4387
|
var HandleInputExtension = class extends PlainExtension4 {
|
|
4466
4388
|
constructor(options) {
|
|
4467
4389
|
super();
|
|
4468
4390
|
this.inputRules = [
|
|
4469
4391
|
...getMdImageInputRule("md_image"),
|
|
4470
|
-
...getInlineMathInputRule("math_inline")
|
|
4392
|
+
...getInlineMathInputRule("math_inline"),
|
|
4393
|
+
...getHtmlImageInputRule("html_image")
|
|
4471
4394
|
];
|
|
4472
4395
|
if (options?.rules) {
|
|
4473
4396
|
this.inputRules = [...this.inputRules, ...options.rules];
|
|
@@ -4527,7 +4450,11 @@ var HandleInputExtension = class extends PlainExtension4 {
|
|
|
4527
4450
|
const start = pos + matchIndex;
|
|
4528
4451
|
const end = start + match[0].length;
|
|
4529
4452
|
if (start >= 0 && end <= newState.doc.content.size) {
|
|
4453
|
+
console.log("nodenode", node);
|
|
4530
4454
|
const attrs = rule6.getAttributes ? rule6.getAttributes(match) : null;
|
|
4455
|
+
if (node.attrs["data-rme-from-paste"] === "true" && attrs) {
|
|
4456
|
+
attrs["data-rme-from-paste"] = "true";
|
|
4457
|
+
}
|
|
4531
4458
|
const nodeType = schema.nodes[rule6.type];
|
|
4532
4459
|
if (!nodeType) {
|
|
4533
4460
|
console.warn(`Node type '${rule6.type}' not found in schema`);
|
|
@@ -6852,10 +6779,43 @@ var ImageToolTips = (props) => {
|
|
|
6852
6779
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
6853
6780
|
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
6781
|
function ImageNodeView(props) {
|
|
6855
|
-
const {
|
|
6856
|
-
|
|
6857
|
-
|
|
6782
|
+
const {
|
|
6783
|
+
node,
|
|
6784
|
+
selected,
|
|
6785
|
+
updateAttributes,
|
|
6786
|
+
handleViewImgSrcUrl,
|
|
6787
|
+
imageCopyHandler,
|
|
6788
|
+
imageHostingHandler
|
|
6789
|
+
} = props;
|
|
6790
|
+
const initRef = useRef7(null);
|
|
6791
|
+
const popoverStore = useRef7(null);
|
|
6858
6792
|
const popoverRef = useRef7(null);
|
|
6793
|
+
const fromPaste = node.attrs["data-rme-from-paste"] === "true";
|
|
6794
|
+
console.log("fromPaste", fromPaste, node);
|
|
6795
|
+
useEffect6(() => {
|
|
6796
|
+
if (fromPaste) {
|
|
6797
|
+
const handlePasteEvent = async () => {
|
|
6798
|
+
let src = node.attrs.src || "";
|
|
6799
|
+
if (imageCopyHandler) {
|
|
6800
|
+
try {
|
|
6801
|
+
src = await imageCopyHandler(node.attrs.src);
|
|
6802
|
+
} catch (error) {
|
|
6803
|
+
}
|
|
6804
|
+
}
|
|
6805
|
+
if (handleViewImgSrcUrl) {
|
|
6806
|
+
try {
|
|
6807
|
+
src = await handleViewImgSrcUrl(src);
|
|
6808
|
+
} catch (error) {
|
|
6809
|
+
}
|
|
6810
|
+
}
|
|
6811
|
+
updateAttributes({
|
|
6812
|
+
"data-rme-from-paste": null,
|
|
6813
|
+
src
|
|
6814
|
+
});
|
|
6815
|
+
};
|
|
6816
|
+
handlePasteEvent();
|
|
6817
|
+
}
|
|
6818
|
+
}, [fromPaste, node.attrs.src]);
|
|
6859
6819
|
const handleStoreChange = (store) => {
|
|
6860
6820
|
popoverStore.current = store;
|
|
6861
6821
|
};
|
|
@@ -6877,47 +6837,41 @@ function ImageNodeView(props) {
|
|
|
6877
6837
|
["data-rme-type"]: "html"
|
|
6878
6838
|
});
|
|
6879
6839
|
}, [updateAttributes]);
|
|
6880
|
-
const
|
|
6881
|
-
|
|
6840
|
+
const Loading = /* @__PURE__ */ jsx14("span", { className: "inline-loading", children: /* @__PURE__ */ jsx14("i", { className: "inline-loading-icon ri-loader-4-line" }) });
|
|
6841
|
+
if (fromPaste) {
|
|
6842
|
+
return Loading;
|
|
6843
|
+
}
|
|
6844
|
+
const Main = /* @__PURE__ */ jsx14(Resizable, { controlInit: (init) => initRef.current = init, onResize: handleResize, ...props, children: /* @__PURE__ */ jsx14(
|
|
6845
|
+
ZensImage,
|
|
6882
6846
|
{
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
};
|
|
6902
|
-
img.onerror = () => {
|
|
6903
|
-
reject(warningFallBack);
|
|
6904
|
-
};
|
|
6905
|
-
};
|
|
6906
|
-
if (handleViewImgSrcUrl) {
|
|
6907
|
-
handleViewImgSrcUrl(node.attrs.src).then((newSrc) => {
|
|
6908
|
-
makeImageLoad(newSrc);
|
|
6909
|
-
});
|
|
6910
|
-
} else {
|
|
6911
|
-
makeImageLoad(node.attrs.src);
|
|
6912
|
-
}
|
|
6847
|
+
onLoad: () => initRef.current?.(),
|
|
6848
|
+
src: node.attrs.src,
|
|
6849
|
+
loader: Loading,
|
|
6850
|
+
imgPromise: (src) => {
|
|
6851
|
+
return new Promise((resolve, reject) => {
|
|
6852
|
+
const makeImageLoad = (targetSrc) => {
|
|
6853
|
+
const img = new Image();
|
|
6854
|
+
img.src = targetSrc;
|
|
6855
|
+
img.onload = () => {
|
|
6856
|
+
resolve(targetSrc);
|
|
6857
|
+
};
|
|
6858
|
+
img.onerror = () => {
|
|
6859
|
+
reject(warningFallBack);
|
|
6860
|
+
};
|
|
6861
|
+
};
|
|
6862
|
+
if (handleViewImgSrcUrl) {
|
|
6863
|
+
handleViewImgSrcUrl(node.attrs.src).then((newSrc) => {
|
|
6864
|
+
makeImageLoad(newSrc);
|
|
6913
6865
|
});
|
|
6914
|
-
}
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6866
|
+
} else {
|
|
6867
|
+
makeImageLoad(node.attrs.src);
|
|
6868
|
+
}
|
|
6869
|
+
});
|
|
6870
|
+
},
|
|
6871
|
+
...node.attrs
|
|
6918
6872
|
},
|
|
6919
6873
|
`${node.attrs.src}_${node.attrs["data-rme-loading"]}`
|
|
6920
|
-
);
|
|
6874
|
+
) });
|
|
6921
6875
|
return /* @__PURE__ */ jsx14("div", { ref: popoverRef, style: { position: "relative", zIndex: selected ? 10 : "auto" }, children: /* @__PURE__ */ jsx14(
|
|
6922
6876
|
Popover2,
|
|
6923
6877
|
{
|
|
@@ -6948,8 +6902,16 @@ var HtmlImageExtension = class extends NodeExtension6 {
|
|
|
6948
6902
|
constructor() {
|
|
6949
6903
|
super(...arguments);
|
|
6950
6904
|
this.ReactComponent = (props) => {
|
|
6951
|
-
const { handleViewImgSrcUrl, imageHostingHandler } = this.options;
|
|
6952
|
-
return /* @__PURE__ */ jsx15(
|
|
6905
|
+
const { handleViewImgSrcUrl, imageHostingHandler, imageCopyHandler } = this.options;
|
|
6906
|
+
return /* @__PURE__ */ jsx15(
|
|
6907
|
+
ImageNodeView,
|
|
6908
|
+
{
|
|
6909
|
+
handleViewImgSrcUrl,
|
|
6910
|
+
imageCopyHandler,
|
|
6911
|
+
imageHostingHandler,
|
|
6912
|
+
...props
|
|
6913
|
+
}
|
|
6914
|
+
);
|
|
6953
6915
|
};
|
|
6954
6916
|
}
|
|
6955
6917
|
get name() {
|
|
@@ -6975,7 +6937,8 @@ var HtmlImageExtension = class extends NodeExtension6 {
|
|
|
6975
6937
|
src: { default: null },
|
|
6976
6938
|
title: { default: "" },
|
|
6977
6939
|
"data-file-name": { default: null },
|
|
6978
|
-
"data-rme-loading": { default: null }
|
|
6940
|
+
"data-rme-loading": { default: null },
|
|
6941
|
+
"data-rme-from-paste": { default: null }
|
|
6979
6942
|
},
|
|
6980
6943
|
parseDOM: [
|
|
6981
6944
|
{
|
|
@@ -7083,16 +7046,7 @@ var HtmlImageExtension = class extends NodeExtension6 {
|
|
|
7083
7046
|
];
|
|
7084
7047
|
}
|
|
7085
7048
|
createInputRules() {
|
|
7086
|
-
|
|
7087
|
-
nodeInputRule5({
|
|
7088
|
-
regexp: new RegExp("<img[^>]*>"),
|
|
7089
|
-
type: this.type,
|
|
7090
|
-
getAttributes: (match) => {
|
|
7091
|
-
return getAttrsBySignalHtmlContent(match[0]);
|
|
7092
|
-
}
|
|
7093
|
-
})
|
|
7094
|
-
];
|
|
7095
|
-
return rules;
|
|
7049
|
+
return getHtmlImageInputRule(this.type).map(nodeInputRule5);
|
|
7096
7050
|
}
|
|
7097
7051
|
fromMarkdown() {
|
|
7098
7052
|
return [
|
|
@@ -7206,12 +7160,13 @@ var MdImgUriExtension = class extends NodeExtension7 {
|
|
|
7206
7160
|
constructor() {
|
|
7207
7161
|
super(...arguments);
|
|
7208
7162
|
this.ReactComponent = (props) => {
|
|
7209
|
-
const { handleViewImgSrcUrl, imageHostingHandler } = this.options;
|
|
7163
|
+
const { handleViewImgSrcUrl, imageHostingHandler, imageCopyHandler } = this.options;
|
|
7210
7164
|
return /* @__PURE__ */ jsx16(
|
|
7211
7165
|
ImageNodeView,
|
|
7212
7166
|
{
|
|
7213
7167
|
handleViewImgSrcUrl,
|
|
7214
7168
|
imageHostingHandler,
|
|
7169
|
+
imageCopyHandler,
|
|
7215
7170
|
...props
|
|
7216
7171
|
}
|
|
7217
7172
|
);
|
|
@@ -7240,7 +7195,8 @@ var MdImgUriExtension = class extends NodeExtension7 {
|
|
|
7240
7195
|
rotate: { default: null },
|
|
7241
7196
|
src: { default: null },
|
|
7242
7197
|
title: { default: "" },
|
|
7243
|
-
"data-file-name": { default: null }
|
|
7198
|
+
"data-file-name": { default: null },
|
|
7199
|
+
"data-rme-from-paste": { default: null }
|
|
7244
7200
|
},
|
|
7245
7201
|
parseDOM: [
|
|
7246
7202
|
{
|
|
@@ -9038,7 +8994,6 @@ var MathInlineView = class {
|
|
|
9038
8994
|
}
|
|
9039
8995
|
this._renderElt.replaceWith(newRenderEl);
|
|
9040
8996
|
this._renderElt = newRenderEl;
|
|
9041
|
-
console.log("this.renderElt", this._renderElt.outerHTML);
|
|
9042
8997
|
this.dom.appendChild(this._renderElt);
|
|
9043
8998
|
if (preview) {
|
|
9044
8999
|
this._renderElt.classList.add("inline-input-preview");
|
|
@@ -10304,11 +10259,13 @@ function extensions(options) {
|
|
|
10304
10259
|
new CountExtension({}),
|
|
10305
10260
|
new HtmlImageExtension({
|
|
10306
10261
|
handleViewImgSrcUrl,
|
|
10307
|
-
imageHostingHandler
|
|
10262
|
+
imageHostingHandler,
|
|
10263
|
+
imageCopyHandler
|
|
10308
10264
|
}),
|
|
10309
10265
|
new MdImgUriExtension({
|
|
10310
10266
|
handleViewImgSrcUrl,
|
|
10311
|
-
imageHostingHandler
|
|
10267
|
+
imageHostingHandler,
|
|
10268
|
+
imageCopyHandler
|
|
10312
10269
|
}),
|
|
10313
10270
|
new HandleInputExtension(),
|
|
10314
10271
|
new HtmlBrExtension(),
|