@cyberyozh/text-editor 0.2.1 → 0.3.0
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/editor.js +126 -71
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +128 -73
- package/dist/editor.mjs.map +1 -1
- package/dist/render.js +23 -5
- package/dist/render.js.map +1 -1
- package/dist/render.mjs +24 -6
- package/dist/render.mjs.map +1 -1
- package/package.json +5 -2
- package/src/editor/dialogs/image-dialog/image-dialog.tsx +0 -1
- package/src/editor/editor.tsx +9 -6
- package/src/editor/handlers/dialog-handlers.ts +17 -31
- package/src/editor/handlers/insertion-handlers.ts +21 -39
- package/src/editor/handlers/markup-insertion.test.ts +132 -0
- package/src/editor/handlers/markup-insertion.ts +72 -0
- package/src/extensions/base/link.ts +22 -1
- package/src/utils/image-src-resolver.test.ts +54 -0
package/dist/editor.js
CHANGED
|
@@ -37,8 +37,8 @@ module.exports = __toCommonJS(editor_exports);
|
|
|
37
37
|
|
|
38
38
|
// src/editor/editor.tsx
|
|
39
39
|
var import_react37 = require("react");
|
|
40
|
-
var
|
|
41
|
-
var
|
|
40
|
+
var import_state7 = require("@tiptap/pm/state");
|
|
41
|
+
var import_model3 = require("@tiptap/pm/model");
|
|
42
42
|
var import_react38 = require("@tiptap/react");
|
|
43
43
|
var import_menus = require("@tiptap/react/menus");
|
|
44
44
|
var import_github_dark = require("highlight.js/styles/github-dark.css");
|
|
@@ -2058,7 +2058,6 @@ var ImageDialog = ({
|
|
|
2058
2058
|
setIsUploading(true);
|
|
2059
2059
|
try {
|
|
2060
2060
|
const result = await uploadHandler(formState.file);
|
|
2061
|
-
console.log("\u{1F440} ~ handleAddImage ~ result:", result);
|
|
2062
2061
|
onImageAdd({
|
|
2063
2062
|
fileId: result.fileId,
|
|
2064
2063
|
src: result.fileUrl,
|
|
@@ -3138,6 +3137,7 @@ var BaseCustomQuoteSign = import_core3.Node.create({
|
|
|
3138
3137
|
// src/extensions/base/link.ts
|
|
3139
3138
|
var import_extension_link = __toESM(require("@tiptap/extension-link"));
|
|
3140
3139
|
var import_core4 = require("@tiptap/core");
|
|
3140
|
+
var import_state3 = require("@tiptap/pm/state");
|
|
3141
3141
|
|
|
3142
3142
|
// node_modules/linkifyjs/dist/linkify.mjs
|
|
3143
3143
|
var encodedTlds = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5m\xF6gensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2";
|
|
@@ -4316,6 +4316,23 @@ var LinkExtension = import_extension_link.default.extend({
|
|
|
4316
4316
|
}
|
|
4317
4317
|
})
|
|
4318
4318
|
];
|
|
4319
|
+
},
|
|
4320
|
+
addProseMirrorPlugins() {
|
|
4321
|
+
return [
|
|
4322
|
+
...this.parent?.() ?? [],
|
|
4323
|
+
new import_state3.Plugin({
|
|
4324
|
+
props: {
|
|
4325
|
+
handleClick: (view, pos) => {
|
|
4326
|
+
if (!view.editable) return false;
|
|
4327
|
+
const range = (0, import_core4.getMarkRange)(view.state.doc.resolve(pos), this.type);
|
|
4328
|
+
if (!range) return false;
|
|
4329
|
+
const selection = import_state3.TextSelection.create(view.state.doc, range.from, range.to);
|
|
4330
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
4331
|
+
return true;
|
|
4332
|
+
}
|
|
4333
|
+
}
|
|
4334
|
+
})
|
|
4335
|
+
];
|
|
4319
4336
|
}
|
|
4320
4337
|
}).configure({
|
|
4321
4338
|
openOnClick: false,
|
|
@@ -4362,7 +4379,7 @@ var BaseMythReality = import_core5.Node.create({
|
|
|
4362
4379
|
|
|
4363
4380
|
// src/extensions/base/prompt.ts
|
|
4364
4381
|
var import_core6 = require("@tiptap/core");
|
|
4365
|
-
var
|
|
4382
|
+
var import_state4 = require("@tiptap/pm/state");
|
|
4366
4383
|
var BasePrompt = import_core6.Node.create({
|
|
4367
4384
|
name: "prompt",
|
|
4368
4385
|
group: "block",
|
|
@@ -4394,7 +4411,7 @@ var BasePrompt = import_core6.Node.create({
|
|
|
4394
4411
|
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
4395
4412
|
if (!paragraphNode) return false;
|
|
4396
4413
|
tr2.insert(posAfter, paragraphNode);
|
|
4397
|
-
tr2.setSelection(
|
|
4414
|
+
tr2.setSelection(import_state4.TextSelection.create(tr2.doc, posAfter + 1));
|
|
4398
4415
|
view.dispatch(tr2);
|
|
4399
4416
|
return true;
|
|
4400
4417
|
}
|
|
@@ -4636,7 +4653,7 @@ var BaseFigure = import_extension_image.default.extend({
|
|
|
4636
4653
|
|
|
4637
4654
|
// src/extensions/base/compatibility.ts
|
|
4638
4655
|
var import_core9 = require("@tiptap/core");
|
|
4639
|
-
var
|
|
4656
|
+
var import_state5 = require("@tiptap/pm/state");
|
|
4640
4657
|
var import_extension_image2 = __toESM(require("@tiptap/extension-image"));
|
|
4641
4658
|
var BaseLegacyBookAlert = import_core9.Node.create({
|
|
4642
4659
|
name: "calloutAlert",
|
|
@@ -4780,7 +4797,7 @@ var BaseLegacySEQuote = import_core9.Node.create({
|
|
|
4780
4797
|
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
4781
4798
|
if (!paragraphNode) return false;
|
|
4782
4799
|
tr2.insert(posAfter, paragraphNode);
|
|
4783
|
-
tr2.setSelection(
|
|
4800
|
+
tr2.setSelection(import_state5.TextSelection.create(tr2.doc, posAfter + 1));
|
|
4784
4801
|
view.dispatch(tr2);
|
|
4785
4802
|
return true;
|
|
4786
4803
|
}
|
|
@@ -4828,7 +4845,7 @@ var BaseLegacyPromptSE = import_core9.Node.create({
|
|
|
4828
4845
|
const paragraphNode = schema.nodes.paragraph.createAndFill();
|
|
4829
4846
|
if (!paragraphNode) return false;
|
|
4830
4847
|
tr2.insert(posAfter, paragraphNode);
|
|
4831
|
-
tr2.setSelection(
|
|
4848
|
+
tr2.setSelection(import_state5.TextSelection.create(tr2.doc, posAfter + 1));
|
|
4832
4849
|
view.dispatch(tr2);
|
|
4833
4850
|
return true;
|
|
4834
4851
|
}
|
|
@@ -6686,7 +6703,7 @@ function getEditorExtensions(options) {
|
|
|
6686
6703
|
}
|
|
6687
6704
|
|
|
6688
6705
|
// src/editor/handlers/dialog-handlers.ts
|
|
6689
|
-
var
|
|
6706
|
+
var import_state6 = require("@tiptap/pm/state");
|
|
6690
6707
|
var createHandleImageAdd = (editor, closeDialogCommand, savedPos) => {
|
|
6691
6708
|
return (attrs) => {
|
|
6692
6709
|
if (!editor) return;
|
|
@@ -6697,10 +6714,10 @@ var createHandleImageAdd = (editor, closeDialogCommand, savedPos) => {
|
|
|
6697
6714
|
const imageNode = state2.schema.nodes.image.create({ ...attrs });
|
|
6698
6715
|
if ($pos.parent.type.name === "paragraph" && $pos.parent.textContent === "") {
|
|
6699
6716
|
tr2.replaceWith($pos.before(), $pos.after(), imageNode);
|
|
6700
|
-
tr2.setSelection(
|
|
6717
|
+
tr2.setSelection(import_state6.TextSelection.near(tr2.doc.resolve($pos.before())));
|
|
6701
6718
|
} else {
|
|
6702
6719
|
tr2.insert(insertPos, imageNode);
|
|
6703
|
-
tr2.setSelection(
|
|
6720
|
+
tr2.setSelection(import_state6.TextSelection.near(tr2.doc.resolve(insertPos)));
|
|
6704
6721
|
}
|
|
6705
6722
|
return true;
|
|
6706
6723
|
}).run();
|
|
@@ -6724,40 +6741,29 @@ var createHandleVideoAdd = (editor, closeDialogCommand, savedPos) => {
|
|
|
6724
6741
|
const videoNode = state2.schema.nodes.video.create({ src: url });
|
|
6725
6742
|
if ($pos.parent.type.name === "paragraph" && $pos.parent.textContent === "") {
|
|
6726
6743
|
tr2.replaceWith($pos.before(), $pos.after(), videoNode);
|
|
6727
|
-
tr2.setSelection(
|
|
6744
|
+
tr2.setSelection(import_state6.TextSelection.near(tr2.doc.resolve($pos.before())));
|
|
6728
6745
|
} else {
|
|
6729
6746
|
tr2.insert(insertPos, videoNode);
|
|
6730
|
-
tr2.setSelection(
|
|
6747
|
+
tr2.setSelection(import_state6.TextSelection.near(tr2.doc.resolve(insertPos)));
|
|
6731
6748
|
}
|
|
6732
6749
|
return true;
|
|
6733
6750
|
}).run();
|
|
6734
6751
|
closeDialogCommand();
|
|
6735
6752
|
};
|
|
6736
6753
|
};
|
|
6737
|
-
var createHandleLinkAdd = (editor, closeDialogCommand, linkParams,
|
|
6754
|
+
var createHandleLinkAdd = (editor, closeDialogCommand, linkParams, savedRange) => {
|
|
6738
6755
|
if (!editor) return;
|
|
6739
|
-
const
|
|
6740
|
-
const titleLength =
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
}
|
|
6750
|
-
const { state } = editor;
|
|
6751
|
-
const insertPos = savedPos ?? state.selection.from;
|
|
6752
|
-
const titleLength2 = linkParams.title?.length ?? 0;
|
|
6753
|
-
editor.chain().focus().command(({ tr: tr2 }) => {
|
|
6754
|
-
const linkMark = editor.schema.marks.link.create({ ...linkParams });
|
|
6755
|
-
const textNode = editor.schema.text(linkParams.title ?? "", [linkMark]);
|
|
6756
|
-
tr2.insert(insertPos, textNode);
|
|
6757
|
-
tr2.setSelection(import_state5.TextSelection.create(tr2.doc, insertPos, insertPos + titleLength2));
|
|
6758
|
-
return true;
|
|
6759
|
-
}).run();
|
|
6760
|
-
}
|
|
6756
|
+
const title = linkParams.title ?? "";
|
|
6757
|
+
const titleLength = title.length;
|
|
6758
|
+
const from = savedRange?.from ?? editor.state.selection.from;
|
|
6759
|
+
const to = savedRange?.to ?? editor.state.selection.to;
|
|
6760
|
+
editor.chain().focus().command(({ tr: tr2 }) => {
|
|
6761
|
+
tr2.insertText(title, from, to);
|
|
6762
|
+
tr2.removeMark(from, from + titleLength);
|
|
6763
|
+
tr2.addMark(from, from + titleLength, editor.schema.marks.link.create({ ...linkParams }));
|
|
6764
|
+
tr2.setSelection(import_state6.TextSelection.create(tr2.doc, from, from + titleLength));
|
|
6765
|
+
return true;
|
|
6766
|
+
}).run();
|
|
6761
6767
|
closeDialogCommand();
|
|
6762
6768
|
};
|
|
6763
6769
|
var createHandleKatexAdd = (editor, closeDialogCommand, savedPos) => {
|
|
@@ -6771,7 +6777,7 @@ var createHandleKatexAdd = (editor, closeDialogCommand, savedPos) => {
|
|
|
6771
6777
|
editor.chain().focus().command(({ tr: tr2, state: state2 }) => {
|
|
6772
6778
|
const inlineMathNode = state2.schema.nodes.inlineMath.create({ latex });
|
|
6773
6779
|
tr2.insert(insertPos, inlineMathNode);
|
|
6774
|
-
tr2.setSelection(
|
|
6780
|
+
tr2.setSelection(import_state6.TextSelection.near(tr2.doc.resolve(insertPos)));
|
|
6775
6781
|
return true;
|
|
6776
6782
|
}).run();
|
|
6777
6783
|
}
|
|
@@ -6782,6 +6788,9 @@ var createHandleKatexAdd = (editor, closeDialogCommand, savedPos) => {
|
|
|
6782
6788
|
// src/editor/handlers/insertion-handlers.ts
|
|
6783
6789
|
var import_react35 = require("react");
|
|
6784
6790
|
|
|
6791
|
+
// src/editor/handlers/markup-insertion.ts
|
|
6792
|
+
var import_model2 = require("@tiptap/pm/model");
|
|
6793
|
+
|
|
6785
6794
|
// src/utils/prosemirror-iterator.ts
|
|
6786
6795
|
var import_model = require("@tiptap/pm/model");
|
|
6787
6796
|
function prosemirrorIterator(slice, cb) {
|
|
@@ -6808,8 +6817,61 @@ function collectFragmentChildren(fragment, stack) {
|
|
|
6808
6817
|
}
|
|
6809
6818
|
}
|
|
6810
6819
|
|
|
6820
|
+
// src/editor/handlers/markup-insertion.ts
|
|
6821
|
+
function collectRehostableImages(slice) {
|
|
6822
|
+
const imagesToNodes = [];
|
|
6823
|
+
prosemirrorIterator(slice, (node) => {
|
|
6824
|
+
if (node.type.name === "image" && !node.attrs.fileId) {
|
|
6825
|
+
try {
|
|
6826
|
+
const url = new URL(node.attrs.src).toString();
|
|
6827
|
+
imagesToNodes.push([url, node]);
|
|
6828
|
+
} catch {
|
|
6829
|
+
}
|
|
6830
|
+
}
|
|
6831
|
+
});
|
|
6832
|
+
return imagesToNodes;
|
|
6833
|
+
}
|
|
6834
|
+
function removeImagesFromFragment(fragment) {
|
|
6835
|
+
const newNodes = [];
|
|
6836
|
+
fragment.forEach((node) => {
|
|
6837
|
+
if (node.type.name === "image" && !node.attrs.fileId) return;
|
|
6838
|
+
newNodes.push(node.childCount > 0 ? node.copy(removeImagesFromFragment(node.content)) : node);
|
|
6839
|
+
});
|
|
6840
|
+
return import_model2.Fragment.from(newNodes);
|
|
6841
|
+
}
|
|
6842
|
+
function validOpenDepth(fragment, requestedDepth, fromEnd = false) {
|
|
6843
|
+
let depth = 0;
|
|
6844
|
+
let current = fragment;
|
|
6845
|
+
while (depth < requestedDepth) {
|
|
6846
|
+
if (current.childCount === 0) break;
|
|
6847
|
+
const node = fromEnd ? current.lastChild : current.firstChild;
|
|
6848
|
+
if (node.isLeaf) break;
|
|
6849
|
+
current = node.content;
|
|
6850
|
+
depth++;
|
|
6851
|
+
}
|
|
6852
|
+
return depth;
|
|
6853
|
+
}
|
|
6854
|
+
function removeImagesFromSlice(slice) {
|
|
6855
|
+
const newContent = removeImagesFromFragment(slice.content);
|
|
6856
|
+
return new import_model2.Slice(
|
|
6857
|
+
newContent,
|
|
6858
|
+
validOpenDepth(newContent, slice.openStart),
|
|
6859
|
+
validOpenDepth(newContent, slice.openEnd, true)
|
|
6860
|
+
);
|
|
6861
|
+
}
|
|
6862
|
+
function applyUploadResultsToNodes(imagesToNodes, results) {
|
|
6863
|
+
results.forEach((result, index) => {
|
|
6864
|
+
if (!result) return;
|
|
6865
|
+
const node = imagesToNodes[index]?.[1];
|
|
6866
|
+
if (!node) return;
|
|
6867
|
+
node.attrs.src = result.fileUrl ?? null;
|
|
6868
|
+
node.attrs.fileId = result.fileId;
|
|
6869
|
+
node.attrs.storageKey = result.storageKey;
|
|
6870
|
+
});
|
|
6871
|
+
}
|
|
6872
|
+
|
|
6811
6873
|
// src/editor/handlers/insertion-handlers.ts
|
|
6812
|
-
function useInsertionHandlers() {
|
|
6874
|
+
function useInsertionHandlers(imageHandlers) {
|
|
6813
6875
|
const [insertedImage, setInsertedImage] = (0, import_react35.useState)(null);
|
|
6814
6876
|
const { activeDialog, openDialogCommand } = useDialogCommand();
|
|
6815
6877
|
(0, import_react35.useEffect)(() => {
|
|
@@ -6821,6 +6883,7 @@ function useInsertionHandlers() {
|
|
|
6821
6883
|
if (!file || !file.type.startsWith("image/")) return;
|
|
6822
6884
|
event.preventDefault();
|
|
6823
6885
|
event.stopPropagation();
|
|
6886
|
+
if (!imageHandlers?.upload) return;
|
|
6824
6887
|
setInsertedImage(file);
|
|
6825
6888
|
openDialogCommand("image");
|
|
6826
6889
|
}
|
|
@@ -6832,8 +6895,7 @@ function useInsertionHandlers() {
|
|
|
6832
6895
|
const file = event.dataTransfer?.files?.[0];
|
|
6833
6896
|
genericInsertionHandler(file, event);
|
|
6834
6897
|
}
|
|
6835
|
-
function onMarkupInsertion(view, event, slice, setDisabled
|
|
6836
|
-
if (!uploadMultipleByURL) return;
|
|
6898
|
+
function onMarkupInsertion(view, event, slice, setDisabled) {
|
|
6837
6899
|
let hasMarkupInsertion = false;
|
|
6838
6900
|
if ("clipboardData" in event && Array.from(event.clipboardData?.items ?? []).some(
|
|
6839
6901
|
(item) => item.type === "text/html"
|
|
@@ -6846,28 +6908,18 @@ function useInsertionHandlers() {
|
|
|
6846
6908
|
hasMarkupInsertion = true;
|
|
6847
6909
|
}
|
|
6848
6910
|
if (hasMarkupInsertion) {
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
}
|
|
6858
|
-
}
|
|
6859
|
-
});
|
|
6860
|
-
uploadMultipleByURL(imagesToNodes.map(([url]) => url)).then((results) => {
|
|
6861
|
-
results.forEach((result, index) => {
|
|
6862
|
-
const node = imagesToNodes[index][1];
|
|
6863
|
-
node.attrs.src = null;
|
|
6864
|
-
node.attrs.fileId = result?.fileId;
|
|
6865
|
-
node.attrs.storageKey = result?.storageKey;
|
|
6911
|
+
if (imageHandlers?.uploadMultipleByURL) {
|
|
6912
|
+
setDisabled(true);
|
|
6913
|
+
const imagesToNodes = collectRehostableImages(slice);
|
|
6914
|
+
imageHandlers.uploadMultipleByURL(imagesToNodes.map(([url]) => url)).then((results) => {
|
|
6915
|
+
applyUploadResultsToNodes(imagesToNodes, results);
|
|
6916
|
+
view.dispatch(view.state.tr.replaceSelection(slice));
|
|
6917
|
+
}).finally(() => {
|
|
6918
|
+
setDisabled(false);
|
|
6866
6919
|
});
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
});
|
|
6920
|
+
} else {
|
|
6921
|
+
view.dispatch(view.state.tr.replaceSelection(removeImagesFromSlice(slice)));
|
|
6922
|
+
}
|
|
6871
6923
|
return true;
|
|
6872
6924
|
}
|
|
6873
6925
|
}
|
|
@@ -7644,6 +7696,9 @@ function TiptapContent({
|
|
|
7644
7696
|
);
|
|
7645
7697
|
const [editFigureContext, setEditFigureContext] = (0, import_react37.useState)(null);
|
|
7646
7698
|
const [savedDialogCursorPos, setSavedDialogCursorPos] = (0, import_react37.useState)(void 0);
|
|
7699
|
+
const [savedDialogRange, setSavedDialogRange] = (0, import_react37.useState)(
|
|
7700
|
+
void 0
|
|
7701
|
+
);
|
|
7647
7702
|
const { activeDialog, closeDialogCommand, openDialogCommand } = useDialogCommand();
|
|
7648
7703
|
const translations2 = useTiptapTranslations();
|
|
7649
7704
|
const [isDisabledInternal, setIsDisabledInternal] = (0, import_react37.useState)(isDisabled);
|
|
@@ -7659,7 +7714,7 @@ function TiptapContent({
|
|
|
7659
7714
|
onPaste,
|
|
7660
7715
|
onDrop,
|
|
7661
7716
|
onMarkupInsertion
|
|
7662
|
-
} = useInsertionHandlers();
|
|
7717
|
+
} = useInsertionHandlers(imageHandlers);
|
|
7663
7718
|
const editor = (0, import_react38.useEditor)(
|
|
7664
7719
|
{
|
|
7665
7720
|
editable: isEditable && !disabled,
|
|
@@ -7690,8 +7745,7 @@ function TiptapContent({
|
|
|
7690
7745
|
view,
|
|
7691
7746
|
event,
|
|
7692
7747
|
slice,
|
|
7693
|
-
setIsDisabledInternal
|
|
7694
|
-
imageHandlers?.uploadMultipleByURL
|
|
7748
|
+
setIsDisabledInternal
|
|
7695
7749
|
);
|
|
7696
7750
|
if (typeof toReturn === "boolean") return toReturn;
|
|
7697
7751
|
return false;
|
|
@@ -7701,8 +7755,7 @@ function TiptapContent({
|
|
|
7701
7755
|
view,
|
|
7702
7756
|
event,
|
|
7703
7757
|
slice,
|
|
7704
|
-
setIsDisabledInternal
|
|
7705
|
-
imageHandlers?.uploadMultipleByURL
|
|
7758
|
+
setIsDisabledInternal
|
|
7706
7759
|
);
|
|
7707
7760
|
if (typeof toReturn === "boolean") return toReturn;
|
|
7708
7761
|
try {
|
|
@@ -7711,7 +7764,7 @@ function TiptapContent({
|
|
|
7711
7764
|
const json = JSON.parse(text);
|
|
7712
7765
|
if (json.type === "doc" && json.content) {
|
|
7713
7766
|
const node = view.state.schema.nodeFromJSON(json);
|
|
7714
|
-
const newSlice = new
|
|
7767
|
+
const newSlice = new import_model3.Slice(node.content, 0, 0);
|
|
7715
7768
|
view.dispatch(view.state.tr.replaceSelection(newSlice));
|
|
7716
7769
|
return true;
|
|
7717
7770
|
}
|
|
@@ -7728,8 +7781,9 @@ function TiptapContent({
|
|
|
7728
7781
|
);
|
|
7729
7782
|
(0, import_react37.useEffect)(() => {
|
|
7730
7783
|
if (activeDialog && editor && !editor.isDestroyed) {
|
|
7731
|
-
const
|
|
7732
|
-
setSavedDialogCursorPos(
|
|
7784
|
+
const { from, to } = editor.state.selection;
|
|
7785
|
+
setSavedDialogCursorPos(from);
|
|
7786
|
+
setSavedDialogRange({ from, to });
|
|
7733
7787
|
}
|
|
7734
7788
|
}, [activeDialog, editor]);
|
|
7735
7789
|
const handleCloseDialog = () => {
|
|
@@ -7737,6 +7791,7 @@ function TiptapContent({
|
|
|
7737
7791
|
setKatexDialogContext(null);
|
|
7738
7792
|
setEditFigureContext(null);
|
|
7739
7793
|
setSavedDialogCursorPos(void 0);
|
|
7794
|
+
setSavedDialogRange(void 0);
|
|
7740
7795
|
closeDialogCommand();
|
|
7741
7796
|
};
|
|
7742
7797
|
const handleImageAdd = (attrs) => {
|
|
@@ -7747,7 +7802,7 @@ function TiptapContent({
|
|
|
7747
7802
|
createHandleVideoAdd(editor, handleCloseDialog, savedDialogCursorPos)(url);
|
|
7748
7803
|
};
|
|
7749
7804
|
const handleLinkAdd = (params) => {
|
|
7750
|
-
createHandleLinkAdd(editor, handleCloseDialog, params,
|
|
7805
|
+
createHandleLinkAdd(editor, handleCloseDialog, params, savedDialogRange);
|
|
7751
7806
|
};
|
|
7752
7807
|
const handleKatexAdd = (latex) => {
|
|
7753
7808
|
const katexHandler = createHandleKatexAdd(editor, handleCloseDialog, savedDialogCursorPos);
|
|
@@ -7760,7 +7815,7 @@ function TiptapContent({
|
|
|
7760
7815
|
});
|
|
7761
7816
|
}, [content, editor]);
|
|
7762
7817
|
const shouldBubbleMenuShow = ({ state }) => {
|
|
7763
|
-
if (state.selection instanceof
|
|
7818
|
+
if (state.selection instanceof import_state7.NodeSelection) {
|
|
7764
7819
|
return false;
|
|
7765
7820
|
}
|
|
7766
7821
|
if (state.selection.empty) {
|