rme 0.3.0-beta.4 → 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.d.ts CHANGED
@@ -237,6 +237,12 @@ declare const createSourceCodeDelegate: (options?: CreateSourceCodeManagerOption
237
237
 
238
238
  declare const _default$1: react__default.NamedExoticComponent<EditorProps>;
239
239
 
240
+ type ClipboardReadFunction = typeof clipboardRead;
241
+ declare function clipboardRead(): Promise<{
242
+ html: string;
243
+ text: string;
244
+ }>;
245
+
240
246
  interface AIOptions {
241
247
  defaultSelectProvider?: string;
242
248
  supportProviderInfosMap: Record<string, {
@@ -389,6 +395,7 @@ type ExtensionsOptions = {
389
395
  ai?: AIOptions;
390
396
  customCopyFunction?: CustomCopyFunction;
391
397
  overrideShortcutMap?: Record<string, string>;
398
+ clipboardReadFunction?: ClipboardReadFunction;
392
399
  };
393
400
  declare function extensions(options: ExtensionsOptions): any[];
394
401
 
package/dist/index.mjs CHANGED
@@ -3433,6 +3433,33 @@ import { CountExtension } from "@rme-sdk/extension-count";
3433
3433
  import { corePreset } from "@rme-sdk/preset-core";
3434
3434
  import { ReactComponentExtension } from "@rme-sdk/react";
3435
3435
 
3436
+ // src/editor/utils/clipboard-read.ts
3437
+ function clipboardRead() {
3438
+ return navigator.clipboard.read().then(async (data) => {
3439
+ let html2 = "";
3440
+ let text = "";
3441
+ const htmlData = data.find((item) => item.types.includes("text/html"));
3442
+ const textData = data.find((item) => item.types.includes("text/plain"));
3443
+ const getHtml = async () => {
3444
+ if (htmlData) {
3445
+ const blob = await htmlData.getType("text/html");
3446
+ html2 = await blob.text();
3447
+ }
3448
+ };
3449
+ const getText = async () => {
3450
+ if (textData) {
3451
+ const blob = await textData.getType("text/plain");
3452
+ text = await blob.text();
3453
+ }
3454
+ };
3455
+ await Promise.all([getHtml(), getText()]);
3456
+ return {
3457
+ html: html2,
3458
+ text
3459
+ };
3460
+ });
3461
+ }
3462
+
3436
3463
  // src/editor/extensions/Ai/ai-extension.tsx
3437
3464
  import { extension, ExtensionTag, NodeExtension } from "@rme-sdk/core";
3438
3465
  import { TextSelection as TextSelection3 } from "@rme-sdk/pm/state";
@@ -3827,6 +3854,71 @@ function isTextOnlySlice(slice) {
3827
3854
  return false;
3828
3855
  }
3829
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
+ }
3830
3922
  get name() {
3831
3923
  return "clipboard";
3832
3924
  }
@@ -3834,62 +3926,13 @@ var ClipboardExtension = class extends PlainExtension2 {
3834
3926
  return {
3835
3927
  props: {
3836
3928
  handlePaste: (view, event) => {
3837
- console.log("handlePaste", event);
3838
- const transformer = getTransformerByView(view);
3839
- const parser = transformer.stringToDoc;
3840
- const schema = view.state.schema;
3841
- const editable = view.props.editable?.(view.state);
3842
3929
  const { clipboardData } = event;
3843
- if (!editable || !clipboardData) return false;
3930
+ if (!clipboardData) return false;
3844
3931
  const currentNode = view.state.selection.$from.node();
3845
3932
  if (currentNode.type.spec.code) return false;
3846
3933
  const text = clipboardData.getData("text/plain");
3847
3934
  const html2 = clipboardData.getData("text/html");
3848
- if (html2.length === 0 && text.length === 0) return false;
3849
- const domParser = DOMParser2.fromSchema(schema);
3850
- let dom;
3851
- if (html2.length === 0) {
3852
- const slice2 = parser?.(text);
3853
- if (!slice2 || typeof slice2 === "string") return false;
3854
- const res = [];
3855
- slice2.content.forEach((node2, index) => {
3856
- if (node2.type.name === "paragraph" && index === 0) {
3857
- node2.content.forEach((child) => {
3858
- res.push(child);
3859
- });
3860
- } else {
3861
- res.push(node2);
3862
- }
3863
- });
3864
- this.processImagesInNodesAsync(res, view);
3865
- if (res.length === 1) {
3866
- view.dispatch(view.state.tr.replaceSelectionWith(res[0], false));
3867
- } else {
3868
- const fragment = Fragment3.from(res);
3869
- view.dispatch(view.state.tr.replaceSelection(new Slice(fragment, 0, 0)));
3870
- }
3871
- return true;
3872
- } else {
3873
- const template = document.createElement("template");
3874
- template.innerHTML = html2;
3875
- dom = template.content.cloneNode(true);
3876
- template.remove();
3877
- }
3878
- const slice = domParser.parseSlice(dom);
3879
- const node = isTextOnlySlice(slice);
3880
- if (node) {
3881
- if ((node.type.name === "html_image" || node.type.name === "md_image") && node.attrs.src) {
3882
- this.processImageNode(node, view);
3883
- view.dispatch(view.state.tr.replaceSelectionWith(node, true));
3884
- } else {
3885
- this.processMarkdownImageSyntax(node, view).then(() => {
3886
- view.dispatch(view.state.tr.replaceSelectionWith(node, true));
3887
- });
3888
- }
3889
- return true;
3890
- }
3891
- this.processImagesInSliceAsync(slice, view);
3892
- view.dispatch(view.state.tr.replaceSelection(slice));
3935
+ this.handleClipboardData({ text, html: html2, view });
3893
3936
  return true;
3894
3937
  },
3895
3938
  clipboardTextSerializer: (slice, view) => {
@@ -3922,13 +3965,16 @@ var ClipboardExtension = class extends PlainExtension2 {
3922
3965
  },
3923
3966
  paste: () => {
3924
3967
  return (params) => {
3925
- if (params.tr.selection.empty) {
3968
+ const { view } = params;
3969
+ if (!view) return false;
3970
+ if (!this.options.clipboardReadFunction) {
3926
3971
  return false;
3927
3972
  }
3928
- if (params.dispatch) {
3929
- console.log("execCommand paste");
3930
- document.execCommand("paste");
3931
- }
3973
+ this.options.clipboardReadFunction().then(async (data) => {
3974
+ let { html: html2, text } = data;
3975
+ if (!html2 || !text) return false;
3976
+ return await this.handleClipboardData({ html: html2, text, view });
3977
+ });
3932
3978
  return true;
3933
3979
  };
3934
3980
  },
@@ -3984,13 +4030,13 @@ var ClipboardExtension = class extends PlainExtension2 {
3984
4030
  imageCopyHandler(node.attrs.src).then((newSrc) => {
3985
4031
  if (newSrc && newSrc !== node.attrs.src) {
3986
4032
  this.updateImageNodeSrc(view, node, newSrc);
3987
- } else {
3988
- const { state, dispatch } = view;
3989
- node.attrs["data-rme-loading"] = null;
3990
- dispatch(state.tr);
3991
4033
  }
3992
4034
  }).catch((error) => {
3993
4035
  console.warn("imageCopyHandler failed:", error);
4036
+ }).finally(() => {
4037
+ const { state, dispatch } = view;
4038
+ node.attrs["data-rme-loading"] = null;
4039
+ dispatch(state.tr);
3994
4040
  });
3995
4041
  }
3996
4042
  /**
@@ -6771,8 +6817,8 @@ import { jsx as jsx14 } from "react/jsx-runtime";
6771
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=";
6772
6818
  function ImageNodeView(props) {
6773
6819
  const { node, selected, updateAttributes, handleViewImgSrcUrl, imageHostingHandler } = props;
6774
- const initRef = useRef7();
6775
- const popoverStore = useRef7();
6820
+ const initRef = useRef7(null);
6821
+ const popoverStore = useRef7(null);
6776
6822
  const popoverRef = useRef7(null);
6777
6823
  const handleStoreChange = (store) => {
6778
6824
  popoverStore.current = store;
@@ -6831,10 +6877,10 @@ function ImageNodeView(props) {
6831
6877
  });
6832
6878
  },
6833
6879
  ...node.attrs
6834
- }
6880
+ },
6881
+ `${node.attrs.src}_${node.attrs["data-rme-loading"]}`
6835
6882
  )
6836
- },
6837
- `${node.attrs.src}_${node.attrs["data-rme-loading"]}`
6883
+ }
6838
6884
  );
6839
6885
  return /* @__PURE__ */ jsx14("div", { ref: popoverRef, style: { position: "relative", zIndex: selected ? 10 : "auto" }, children: /* @__PURE__ */ jsx14(
6840
6886
  Popover2,
@@ -8956,7 +9002,6 @@ var MathInlineView = class {
8956
9002
  }
8957
9003
  this._renderElt.replaceWith(newRenderEl);
8958
9004
  this._renderElt = newRenderEl;
8959
- console.log("this.renderElt", this._renderElt.outerHTML);
8960
9005
  this.dom.appendChild(this._renderElt);
8961
9006
  if (preview) {
8962
9007
  this._renderElt.classList.add("inline-input-preview");
@@ -10211,7 +10256,8 @@ function extensions(options) {
10211
10256
  handleViewImgSrcUrl,
10212
10257
  imageHostingHandler,
10213
10258
  imageCopyHandler,
10214
- customCopyFunction = defaultCopyFunction
10259
+ customCopyFunction = defaultCopyFunction,
10260
+ clipboardReadFunction = clipboardRead
10215
10261
  } = options;
10216
10262
  const res = [
10217
10263
  ...corePreset({ excludeExtensions: ["paragraph", "text"] }),
@@ -10266,7 +10312,8 @@ function extensions(options) {
10266
10312
  handleViewImgSrcUrl
10267
10313
  }),
10268
10314
  new ClipboardExtension({
10269
- imageCopyHandler
10315
+ imageCopyHandler,
10316
+ clipboardReadFunction
10270
10317
  }),
10271
10318
  new ReactComponentExtension({}),
10272
10319
  new DropCursorExtension({