rme 0.3.0-beta.3 → 0.3.0-beta.5

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";
@@ -3921,12 +3948,69 @@ var ClipboardExtension = class extends PlainExtension2 {
3921
3948
  },
3922
3949
  paste: () => {
3923
3950
  return (params) => {
3924
- if (params.tr.selection.empty) {
3951
+ const { view } = params;
3952
+ 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
+ if (!this.options.clipboardReadFunction) {
3925
3958
  return false;
3926
3959
  }
3927
- if (params.dispatch) {
3928
- document.execCommand("copy");
3929
- }
3960
+ this.options.clipboardReadFunction().then(async (data) => {
3961
+ let { html: html2, text } = data;
3962
+ if (!editable || !html2 || !text) return false;
3963
+ const currentNode = view.state.selection.$from.node();
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));
4013
+ });
3930
4014
  return true;
3931
4015
  };
3932
4016
  },
@@ -10209,7 +10293,8 @@ function extensions(options) {
10209
10293
  handleViewImgSrcUrl,
10210
10294
  imageHostingHandler,
10211
10295
  imageCopyHandler,
10212
- customCopyFunction = defaultCopyFunction
10296
+ customCopyFunction = defaultCopyFunction,
10297
+ clipboardReadFunction = clipboardRead
10213
10298
  } = options;
10214
10299
  const res = [
10215
10300
  ...corePreset({ excludeExtensions: ["paragraph", "text"] }),
@@ -10264,7 +10349,8 @@ function extensions(options) {
10264
10349
  handleViewImgSrcUrl
10265
10350
  }),
10266
10351
  new ClipboardExtension({
10267
- imageCopyHandler
10352
+ imageCopyHandler,
10353
+ clipboardReadFunction
10268
10354
  }),
10269
10355
  new ReactComponentExtension({}),
10270
10356
  new DropCursorExtension({