@edifice.io/tiptap-extensions 2.6.9-develop-enabling.20261013152718 → 2.6.9-develop-integration.20261014184332

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.
Files changed (110) hide show
  1. package/dist/abbr/abbr.cjs +2 -2
  2. package/dist/abbr/abbr.cjs.map +1 -1
  3. package/dist/abbr/abbr.js +33 -2
  4. package/dist/abbr/abbr.js.map +1 -1
  5. package/dist/alert/alert.cjs +2 -2
  6. package/dist/alert/alert.cjs.map +1 -1
  7. package/dist/alert/alert.js +45 -2
  8. package/dist/alert/alert.js.map +1 -1
  9. package/dist/attachment/attachment-transformer.cjs +2 -2
  10. package/dist/attachment/attachment-transformer.cjs.map +1 -1
  11. package/dist/attachment/attachment-transformer.js +76 -2
  12. package/dist/attachment/attachment-transformer.js.map +1 -1
  13. package/dist/attachment/attachment.cjs +2 -2
  14. package/dist/attachment/attachment.cjs.map +1 -1
  15. package/dist/attachment/attachment.js +98 -2
  16. package/dist/attachment/attachment.js.map +1 -1
  17. package/dist/audio/audio.cjs +2 -2
  18. package/dist/audio/audio.cjs.map +1 -1
  19. package/dist/audio/audio.js +52 -3
  20. package/dist/audio/audio.js.map +1 -1
  21. package/dist/conversation-history/conversation-history.cjs +2 -2
  22. package/dist/conversation-history/conversation-history.cjs.map +1 -1
  23. package/dist/conversation-history/conversation-history.js +63 -2
  24. package/dist/conversation-history/conversation-history.js.map +1 -1
  25. package/dist/conversation-history-body/conversation-history-body.cjs +2 -2
  26. package/dist/conversation-history-body/conversation-history-body.cjs.map +1 -1
  27. package/dist/conversation-history-body/conversation-history-body.js +24 -2
  28. package/dist/conversation-history-body/conversation-history-body.js.map +1 -1
  29. package/dist/font-size/font-size.cjs +2 -2
  30. package/dist/font-size/font-size.cjs.map +1 -1
  31. package/dist/font-size/font-size.js +39 -2
  32. package/dist/font-size/font-size.js.map +1 -1
  33. package/dist/heading/heading.cjs +2 -2
  34. package/dist/heading/heading.cjs.map +1 -1
  35. package/dist/heading/heading.js +46 -2
  36. package/dist/heading/heading.js.map +1 -1
  37. package/dist/highlight/highlight.cjs +2 -2
  38. package/dist/highlight/highlight.cjs.map +1 -1
  39. package/dist/highlight/highlight.js +28 -2
  40. package/dist/highlight/highlight.js.map +1 -1
  41. package/dist/hyperlink/hyperlink.cjs +2 -2
  42. package/dist/hyperlink/hyperlink.cjs.map +1 -1
  43. package/dist/hyperlink/hyperlink.js +53 -2
  44. package/dist/hyperlink/hyperlink.js.map +1 -1
  45. package/dist/iframe/iframe.cjs +2 -2
  46. package/dist/iframe/iframe.cjs.map +1 -1
  47. package/dist/iframe/iframe.js +70 -2
  48. package/dist/iframe/iframe.js.map +1 -1
  49. package/dist/iframe/transformers/index.cjs +2 -2
  50. package/dist/iframe/transformers/index.cjs.map +1 -1
  51. package/dist/iframe/transformers/index.js +22 -2
  52. package/dist/iframe/transformers/index.js.map +1 -1
  53. package/dist/iframe/transformers/pad-transformer.cjs +2 -2
  54. package/dist/iframe/transformers/pad-transformer.cjs.map +1 -1
  55. package/dist/iframe/transformers/pad-transformer.js +24 -2
  56. package/dist/iframe/transformers/pad-transformer.js.map +1 -1
  57. package/dist/image/image.cjs +2 -2
  58. package/dist/image/image.cjs.map +1 -1
  59. package/dist/image/image.js +175 -2
  60. package/dist/image/image.js.map +1 -1
  61. package/dist/index.cjs +2 -1
  62. package/dist/index.cjs.map +1 -0
  63. package/dist/index.js +52 -1
  64. package/dist/index.js.map +1 -0
  65. package/dist/information-pane/information-pane.cjs +2 -2
  66. package/dist/information-pane/information-pane.cjs.map +1 -1
  67. package/dist/information-pane/information-pane.js +57 -2
  68. package/dist/information-pane/information-pane.js.map +1 -1
  69. package/dist/line-height/line-height.cjs +2 -2
  70. package/dist/line-height/line-height.cjs.map +1 -1
  71. package/dist/line-height/line-height.js +33 -2
  72. package/dist/line-height/line-height.js.map +1 -1
  73. package/dist/linker/linker.cjs +2 -2
  74. package/dist/linker/linker.cjs.map +1 -1
  75. package/dist/linker/linker.js +96 -2
  76. package/dist/linker/linker.js.map +1 -1
  77. package/dist/mathjax/mathjax.cjs +2 -2
  78. package/dist/mathjax/mathjax.cjs.map +1 -1
  79. package/dist/mathjax/mathjax.js +40 -2
  80. package/dist/mathjax/mathjax.js.map +1 -1
  81. package/dist/paragraph/paragraph.cjs +2 -2
  82. package/dist/paragraph/paragraph.cjs.map +1 -1
  83. package/dist/paragraph/paragraph.js +16 -2
  84. package/dist/paragraph/paragraph.js.map +1 -1
  85. package/dist/speech-recognition/speech-recognition.cjs +2 -2
  86. package/dist/speech-recognition/speech-recognition.cjs.map +1 -1
  87. package/dist/speech-recognition/speech-recognition.js +56 -2
  88. package/dist/speech-recognition/speech-recognition.js.map +1 -1
  89. package/dist/speech-synthesis/speech-synthesis.cjs +2 -2
  90. package/dist/speech-synthesis/speech-synthesis.cjs.map +1 -1
  91. package/dist/speech-synthesis/speech-synthesis.js +25 -2
  92. package/dist/speech-synthesis/speech-synthesis.js.map +1 -1
  93. package/dist/table-cell/table-cell.cjs +2 -2
  94. package/dist/table-cell/table-cell.cjs.map +1 -1
  95. package/dist/table-cell/table-cell.js +23 -2
  96. package/dist/table-cell/table-cell.js.map +1 -1
  97. package/dist/transform/html-to-json/html-to-json.cjs +2 -2
  98. package/dist/transform/html-to-json/html-to-json.cjs.map +1 -1
  99. package/dist/transform/html-to-json/html-to-json.js +6 -2
  100. package/dist/transform/html-to-json/html-to-json.js.map +1 -1
  101. package/dist/transform/json-to-html/json-to-html.cjs +2 -2
  102. package/dist/transform/json-to-html/json-to-html.cjs.map +1 -1
  103. package/dist/transform/json-to-html/json-to-html.js +6 -2
  104. package/dist/transform/json-to-html/json-to-html.js.map +1 -1
  105. package/dist/video/video.cjs +3 -3
  106. package/dist/video/video.cjs.map +1 -1
  107. package/dist/video/video.js +92 -3
  108. package/dist/video/video.js.map +1 -1
  109. package/package.json +5 -5
  110. package/dist/_virtual/_rolldown/runtime.cjs +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.cjs","names":[],"sources":["../../src/iframe/iframe.ts"],"sourcesContent":["import { Node } from '@tiptap/core';\nimport { iframeTransformer } from './transformers';\n\nexport interface IframeOptions {\n allowFullscreen: boolean;\n HTMLAttributes: {\n [key: string]: any;\n };\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n iframe: {\n /**\n * Add an iframe\n */\n setIframe: (options: { src: string }) => ReturnType;\n };\n }\n}\n\nexport const Iframe = Node.create<IframeOptions>({\n name: 'iframe',\n group: 'block',\n atom: true,\n draggable: true,\n\n addOptions() {\n return {\n allowFullscreen: true,\n HTMLAttributes: {\n class: 'iframe-wrapper',\n },\n };\n },\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n frameborder: {\n default: 0,\n },\n allowfullscreen: {\n default: this.options.allowFullscreen,\n parseHTML: () => this.options.allowFullscreen,\n },\n width: {\n renderHTML: (attributes) => {\n return attributes.width\n ? {\n width:\n attributes.width === '100%'\n ? '100%'\n : parseInt(attributes.width),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n return attributes.height\n ? {\n height: parseInt(attributes.height),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('style'),\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'iframe',\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n // Call the onRenderHTML method from the iframeTransformer before rendering the iframe\n iframeTransformer.onRenderHTML({ HTMLAttributes });\n return ['div', this.options.HTMLAttributes, ['iframe', HTMLAttributes]];\n },\n\n addCommands() {\n return {\n setIframe:\n (options: { src: string }) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n});\n"],"mappings":"wDAqBA,IAAa,6BAAS,EAAA,KAAK,OAAsB,CAC/C,KAAM,SACN,MAAO,QACP,KAAM,GACN,UAAW,GAEX,YAAa,CACX,MAAO,CACL,gBAAiB,GACjB,eAAgB,CACd,MAAO,gBACT,CACF,CACF,EAEA,eAAgB,CACd,MAAO,CACL,IAAK,CACH,QAAS,IACX,EACA,YAAa,CACX,QAAS,CACX,EACA,gBAAiB,CACf,QAAS,KAAK,QAAQ,gBACtB,cAAiB,KAAK,QAAQ,eAChC,EACA,MAAO,CACL,WAAa,YACJ,WAAW,MACd,CACE,MACE,WAAW,QAAU,OACjB,OACA,SAAS,WAAW,KAAK,CACjC,EACA,CAAC,EAEP,UAAY,SAAY,QAAQ,aAAa,OAAO,CACtD,EACA,OAAQ,CACN,WAAa,YACJ,WAAW,OACd,CACE,OAAQ,SAAS,WAAW,MAAM,CACpC,EACA,CAAC,EAEP,UAAY,SAAY,QAAQ,aAAa,QAAQ,CACvD,EACA,MAAO,CACL,WAAa,YACJ,WAAW,MACd,CACE,MAAO,WAAW,KACpB,EACA,CAAC,EAEP,UAAY,SAAY,QAAQ,aAAa,OAAO,CACtD,CACF,CACF,EAEA,WAAY,CACV,MAAO,CACL,CACE,IAAK,QACP,CACF,CACF,EAEA,WAAW,CAAE,gBAAkB,CAG7B,OADA,cAAA,kBAAkB,aAAa,CAAE,cAAe,CAAC,EAC1C,CAAC,MAAO,KAAK,QAAQ,eAAgB,CAAC,SAAU,cAAc,CAAC,CACxE,EAEA,aAAc,CACZ,MAAO,CACL,UACG,UACA,CAAE,GAAI,YAAe,CACpB,GAAM,CAAE,WAAc,GAChB,KAAO,KAAK,KAAK,OAAO,OAAO,EAMrC,OAJI,UACF,GAAG,iBAAiB,UAAU,KAAM,UAAU,GAAI,IAAI,EAGjD,EACT,CACJ,CACF,CACF,CAAC"}
1
+ {"version":3,"file":"iframe.cjs","sources":["../../src/iframe/iframe.ts"],"sourcesContent":["import { Node } from '@tiptap/core';\nimport { iframeTransformer } from './transformers';\n\nexport interface IframeOptions {\n allowFullscreen: boolean;\n HTMLAttributes: {\n [key: string]: any;\n };\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n iframe: {\n /**\n * Add an iframe\n */\n setIframe: (options: { src: string }) => ReturnType;\n };\n }\n}\n\nexport const Iframe = Node.create<IframeOptions>({\n name: 'iframe',\n group: 'block',\n atom: true,\n draggable: true,\n\n addOptions() {\n return {\n allowFullscreen: true,\n HTMLAttributes: {\n class: 'iframe-wrapper',\n },\n };\n },\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n frameborder: {\n default: 0,\n },\n allowfullscreen: {\n default: this.options.allowFullscreen,\n parseHTML: () => this.options.allowFullscreen,\n },\n width: {\n renderHTML: (attributes) => {\n return attributes.width\n ? {\n width:\n attributes.width === '100%'\n ? '100%'\n : parseInt(attributes.width),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n return attributes.height\n ? {\n height: parseInt(attributes.height),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('style'),\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'iframe',\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n // Call the onRenderHTML method from the iframeTransformer before rendering the iframe\n iframeTransformer.onRenderHTML({ HTMLAttributes });\n return ['div', this.options.HTMLAttributes, ['iframe', HTMLAttributes]];\n },\n\n addCommands() {\n return {\n setIframe:\n (options: { src: string }) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n});\n"],"names":["Node","iframeTransformer"],"mappings":"6JAqBa,OAASA,KAAAA,KAAK,OAAsB,CAC/C,KAAM,SACN,MAAO,QACP,KAAM,GACN,UAAW,GAEX,YAAa,CACX,MAAO,CACL,gBAAiB,GACjB,eAAgB,CACd,MAAO,gBAAA,CACT,CAEJ,EAEA,eAAgB,CACd,MAAO,CACL,IAAK,CACH,QAAS,IAAA,EAEX,YAAa,CACX,QAAS,CAAA,EAEX,gBAAiB,CACf,QAAS,KAAK,QAAQ,gBACtB,UAAW,IAAM,KAAK,QAAQ,eAAA,EAEhC,MAAO,CACL,WAAa,YACJ,WAAW,MACd,CACE,MACE,WAAW,QAAU,OACjB,OACA,SAAS,WAAW,KAAK,CAAA,EAEjC,CAAA,EAEN,UAAY,SAAY,QAAQ,aAAa,OAAO,CAAA,EAEtD,OAAQ,CACN,WAAa,YACJ,WAAW,OACd,CACE,OAAQ,SAAS,WAAW,MAAM,CAAA,EAEpC,CAAA,EAEN,UAAY,SAAY,QAAQ,aAAa,QAAQ,CAAA,EAEvD,MAAO,CACL,WAAa,YACJ,WAAW,MACd,CACE,MAAO,WAAW,KAAA,EAEpB,CAAA,EAEN,UAAY,SAAY,QAAQ,aAAa,OAAO,CAAA,CACtD,CAEJ,EAEA,WAAY,CACV,MAAO,CACL,CACE,IAAK,QAAA,CACP,CAEJ,EAEA,WAAW,CAAE,gBAAkB,CAE7BC,+BAAkB,aAAa,CAAE,eAAgB,EAC1C,CAAC,MAAO,KAAK,QAAQ,eAAgB,CAAC,SAAU,cAAc,CAAC,CACxE,EAEA,aAAc,CACZ,MAAO,CACL,UACG,SACD,CAAC,CAAE,GAAI,YAAe,CACpB,KAAM,CAAE,WAAc,GAChB,KAAO,KAAK,KAAK,OAAO,OAAO,EAErC,OAAI,UACF,GAAG,iBAAiB,UAAU,KAAM,UAAU,GAAI,IAAI,EAGjD,EACT,CAAA,CAEN,CACF,CAAC"}
@@ -1,2 +1,70 @@
1
- import{iframeTransformer}from"./transformers/index.js";import{Node}from"@tiptap/core";var Iframe=Node.create({name:`iframe`,group:`block`,atom:!0,draggable:!0,addOptions(){return{allowFullscreen:!0,HTMLAttributes:{class:`iframe-wrapper`}}},addAttributes(){return{src:{default:null},frameborder:{default:0},allowfullscreen:{default:this.options.allowFullscreen,parseHTML:()=>this.options.allowFullscreen},width:{renderHTML:attributes=>attributes.width?{width:attributes.width===`100%`?`100%`:parseInt(attributes.width)}:{},parseHTML:element=>element.getAttribute(`width`)},height:{renderHTML:attributes=>attributes.height?{height:parseInt(attributes.height)}:{},parseHTML:element=>element.getAttribute(`height`)},style:{renderHTML:attributes=>attributes.style?{style:attributes.style}:{},parseHTML:element=>element.getAttribute(`style`)}}},parseHTML(){return[{tag:`iframe`}]},renderHTML({HTMLAttributes}){return iframeTransformer.onRenderHTML({HTMLAttributes}),[`div`,this.options.HTMLAttributes,[`iframe`,HTMLAttributes]]},addCommands(){return{setIframe:options=>({tr,dispatch})=>{let{selection}=tr,node=this.type.create(options);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0}}}});export{Iframe};
2
- //# sourceMappingURL=iframe.js.map
1
+ import { Node } from "@tiptap/core";
2
+ import { iframeTransformer } from "./transformers/index.js";
3
+ const Iframe = Node.create({
4
+ name: "iframe",
5
+ group: "block",
6
+ atom: !0,
7
+ draggable: !0,
8
+ addOptions() {
9
+ return {
10
+ allowFullscreen: !0,
11
+ HTMLAttributes: {
12
+ class: "iframe-wrapper"
13
+ }
14
+ };
15
+ },
16
+ addAttributes() {
17
+ return {
18
+ src: {
19
+ default: null
20
+ },
21
+ frameborder: {
22
+ default: 0
23
+ },
24
+ allowfullscreen: {
25
+ default: this.options.allowFullscreen,
26
+ parseHTML: () => this.options.allowFullscreen
27
+ },
28
+ width: {
29
+ renderHTML: (attributes) => attributes.width ? {
30
+ width: attributes.width === "100%" ? "100%" : parseInt(attributes.width)
31
+ } : {},
32
+ parseHTML: (element) => element.getAttribute("width")
33
+ },
34
+ height: {
35
+ renderHTML: (attributes) => attributes.height ? {
36
+ height: parseInt(attributes.height)
37
+ } : {},
38
+ parseHTML: (element) => element.getAttribute("height")
39
+ },
40
+ style: {
41
+ renderHTML: (attributes) => attributes.style ? {
42
+ style: attributes.style
43
+ } : {},
44
+ parseHTML: (element) => element.getAttribute("style")
45
+ }
46
+ };
47
+ },
48
+ parseHTML() {
49
+ return [
50
+ {
51
+ tag: "iframe"
52
+ }
53
+ ];
54
+ },
55
+ renderHTML({ HTMLAttributes }) {
56
+ return iframeTransformer.onRenderHTML({ HTMLAttributes }), ["div", this.options.HTMLAttributes, ["iframe", HTMLAttributes]];
57
+ },
58
+ addCommands() {
59
+ return {
60
+ setIframe: (options) => ({ tr, dispatch }) => {
61
+ const { selection } = tr, node = this.type.create(options);
62
+ return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
63
+ }
64
+ };
65
+ }
66
+ });
67
+ export {
68
+ Iframe
69
+ };
70
+ //# sourceMappingURL=iframe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.js","names":[],"sources":["../../src/iframe/iframe.ts"],"sourcesContent":["import { Node } from '@tiptap/core';\nimport { iframeTransformer } from './transformers';\n\nexport interface IframeOptions {\n allowFullscreen: boolean;\n HTMLAttributes: {\n [key: string]: any;\n };\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n iframe: {\n /**\n * Add an iframe\n */\n setIframe: (options: { src: string }) => ReturnType;\n };\n }\n}\n\nexport const Iframe = Node.create<IframeOptions>({\n name: 'iframe',\n group: 'block',\n atom: true,\n draggable: true,\n\n addOptions() {\n return {\n allowFullscreen: true,\n HTMLAttributes: {\n class: 'iframe-wrapper',\n },\n };\n },\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n frameborder: {\n default: 0,\n },\n allowfullscreen: {\n default: this.options.allowFullscreen,\n parseHTML: () => this.options.allowFullscreen,\n },\n width: {\n renderHTML: (attributes) => {\n return attributes.width\n ? {\n width:\n attributes.width === '100%'\n ? '100%'\n : parseInt(attributes.width),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n return attributes.height\n ? {\n height: parseInt(attributes.height),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('style'),\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'iframe',\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n // Call the onRenderHTML method from the iframeTransformer before rendering the iframe\n iframeTransformer.onRenderHTML({ HTMLAttributes });\n return ['div', this.options.HTMLAttributes, ['iframe', HTMLAttributes]];\n },\n\n addCommands() {\n return {\n setIframe:\n (options: { src: string }) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n});\n"],"mappings":"sFAqBA,IAAa,OAAS,KAAK,OAAsB,CAC/C,KAAM,SACN,MAAO,QACP,KAAM,GACN,UAAW,GAEX,YAAa,CACX,MAAO,CACL,gBAAiB,GACjB,eAAgB,CACd,MAAO,gBACT,CACF,CACF,EAEA,eAAgB,CACd,MAAO,CACL,IAAK,CACH,QAAS,IACX,EACA,YAAa,CACX,QAAS,CACX,EACA,gBAAiB,CACf,QAAS,KAAK,QAAQ,gBACtB,cAAiB,KAAK,QAAQ,eAChC,EACA,MAAO,CACL,WAAa,YACJ,WAAW,MACd,CACE,MACE,WAAW,QAAU,OACjB,OACA,SAAS,WAAW,KAAK,CACjC,EACA,CAAC,EAEP,UAAY,SAAY,QAAQ,aAAa,OAAO,CACtD,EACA,OAAQ,CACN,WAAa,YACJ,WAAW,OACd,CACE,OAAQ,SAAS,WAAW,MAAM,CACpC,EACA,CAAC,EAEP,UAAY,SAAY,QAAQ,aAAa,QAAQ,CACvD,EACA,MAAO,CACL,WAAa,YACJ,WAAW,MACd,CACE,MAAO,WAAW,KACpB,EACA,CAAC,EAEP,UAAY,SAAY,QAAQ,aAAa,OAAO,CACtD,CACF,CACF,EAEA,WAAY,CACV,MAAO,CACL,CACE,IAAK,QACP,CACF,CACF,EAEA,WAAW,CAAE,gBAAkB,CAG7B,OADA,kBAAkB,aAAa,CAAE,cAAe,CAAC,EAC1C,CAAC,MAAO,KAAK,QAAQ,eAAgB,CAAC,SAAU,cAAc,CAAC,CACxE,EAEA,aAAc,CACZ,MAAO,CACL,UACG,UACA,CAAE,GAAI,YAAe,CACpB,GAAM,CAAE,WAAc,GAChB,KAAO,KAAK,KAAK,OAAO,OAAO,EAMrC,OAJI,UACF,GAAG,iBAAiB,UAAU,KAAM,UAAU,GAAI,IAAI,EAGjD,EACT,CACJ,CACF,CACF,CAAC"}
1
+ {"version":3,"file":"iframe.js","sources":["../../src/iframe/iframe.ts"],"sourcesContent":["import { Node } from '@tiptap/core';\nimport { iframeTransformer } from './transformers';\n\nexport interface IframeOptions {\n allowFullscreen: boolean;\n HTMLAttributes: {\n [key: string]: any;\n };\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n iframe: {\n /**\n * Add an iframe\n */\n setIframe: (options: { src: string }) => ReturnType;\n };\n }\n}\n\nexport const Iframe = Node.create<IframeOptions>({\n name: 'iframe',\n group: 'block',\n atom: true,\n draggable: true,\n\n addOptions() {\n return {\n allowFullscreen: true,\n HTMLAttributes: {\n class: 'iframe-wrapper',\n },\n };\n },\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n frameborder: {\n default: 0,\n },\n allowfullscreen: {\n default: this.options.allowFullscreen,\n parseHTML: () => this.options.allowFullscreen,\n },\n width: {\n renderHTML: (attributes) => {\n return attributes.width\n ? {\n width:\n attributes.width === '100%'\n ? '100%'\n : parseInt(attributes.width),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n return attributes.height\n ? {\n height: parseInt(attributes.height),\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: (element) => element.getAttribute('style'),\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'iframe',\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n // Call the onRenderHTML method from the iframeTransformer before rendering the iframe\n iframeTransformer.onRenderHTML({ HTMLAttributes });\n return ['div', this.options.HTMLAttributes, ['iframe', HTMLAttributes]];\n },\n\n addCommands() {\n return {\n setIframe:\n (options: { src: string }) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n});\n"],"names":[],"mappings":";;AAqBO,MAAM,SAAS,KAAK,OAAsB;AAAA,EAC/C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EAEX,aAAa;AACX,WAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,QACd,OAAO;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AAAA,EAEA,gBAAgB;AACd,WAAO;AAAA,MACL,KAAK;AAAA,QACH,SAAS;AAAA,MAAA;AAAA,MAEX,aAAa;AAAA,QACX,SAAS;AAAA,MAAA;AAAA,MAEX,iBAAiB;AAAA,QACf,SAAS,KAAK,QAAQ;AAAA,QACtB,WAAW,MAAM,KAAK,QAAQ;AAAA,MAAA;AAAA,MAEhC,OAAO;AAAA,QACL,YAAY,CAAC,eACJ,WAAW,QACd;AAAA,UACE,OACE,WAAW,UAAU,SACjB,SACA,SAAS,WAAW,KAAK;AAAA,QAAA,IAEjC,CAAA;AAAA,QAEN,WAAW,CAAC,YAAY,QAAQ,aAAa,OAAO;AAAA,MAAA;AAAA,MAEtD,QAAQ;AAAA,QACN,YAAY,CAAC,eACJ,WAAW,SACd;AAAA,UACE,QAAQ,SAAS,WAAW,MAAM;AAAA,QAAA,IAEpC,CAAA;AAAA,QAEN,WAAW,CAAC,YAAY,QAAQ,aAAa,QAAQ;AAAA,MAAA;AAAA,MAEvD,OAAO;AAAA,QACL,YAAY,CAAC,eACJ,WAAW,QACd;AAAA,UACE,OAAO,WAAW;AAAA,QAAA,IAEpB,CAAA;AAAA,QAEN,WAAW,CAAC,YAAY,QAAQ,aAAa,OAAO;AAAA,MAAA;AAAA,IACtD;AAAA,EAEJ;AAAA,EAEA,YAAY;AACV,WAAO;AAAA,MACL;AAAA,QACE,KAAK;AAAA,MAAA;AAAA,IACP;AAAA,EAEJ;AAAA,EAEA,WAAW,EAAE,kBAAkB;AAE7B,6BAAkB,aAAa,EAAE,gBAAgB,GAC1C,CAAC,OAAO,KAAK,QAAQ,gBAAgB,CAAC,UAAU,cAAc,CAAC;AAAA,EACxE;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,WACE,CAAC,YACD,CAAC,EAAE,IAAI,eAAe;AACpB,cAAM,EAAE,cAAc,IAChB,OAAO,KAAK,KAAK,OAAO,OAAO;AAErC,eAAI,YACF,GAAG,iBAAiB,UAAU,MAAM,UAAU,IAAI,IAAI,GAGjD;AAAA,MACT;AAAA,IAAA;AAAA,EAEN;AACF,CAAC;"}
@@ -1,2 +1,2 @@
1
- const require_pad_transformer=require("./pad-transformer.cjs");var iframeTransformer=new class{#transformers=[new require_pad_transformer.PadIframeTransformer];onRenderHTML({HTMLAttributes}){for(let transformer of this.#transformers)transformer.onRenderHTML({HTMLAttributes})}};exports.iframeTransformer=iframeTransformer;
2
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";var __typeError=msg=>{throw TypeError(msg)};var __accessCheck=(obj,member,msg)=>member.has(obj)||__typeError("Cannot "+msg);var __privateGet=(obj,member,getter)=>(__accessCheck(obj,member,"read from private field"),getter?getter.call(obj):member.get(obj)),__privateAdd=(obj,member,value)=>member.has(obj)?__typeError("Cannot add the same private member more than once"):member instanceof WeakSet?member.add(obj):member.set(obj,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const padTransformer=require("./pad-transformer.cjs");var _transformers;class DefaultIframeTransformer{constructor(){__privateAdd(this,_transformers,[new padTransformer.PadIframeTransformer])}onRenderHTML({HTMLAttributes}){for(const transformer of __privateGet(this,_transformers))transformer.onRenderHTML({HTMLAttributes})}}_transformers=new WeakMap;const iframeTransformer=new DefaultIframeTransformer;exports.iframeTransformer=iframeTransformer;
2
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["#transformers"],"sources":["../../../src/iframe/transformers/index.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\nimport { PadIframeTransformer } from './pad-transformer';\n/**\n * Default iframe transformer\n * This transformer is used to call all the transformers\n */\nclass DefaultIframeTransformer implements IframeTransformer {\n #transformers = [new PadIframeTransformer()];\n onRenderHTML({ HTMLAttributes }) {\n for (const transformer of this.#transformers) {\n transformer.onRenderHTML({ HTMLAttributes });\n }\n }\n}\n\nexport const iframeTransformer: IframeTransformer =\n new DefaultIframeTransformer();\n"],"mappings":"+DAeA,IAAa,kBACX,IAAI,KAVsD,CAC1D,cAAgB,CAAC,IAAI,wBAAA,oBAAsB,EAC3C,aAAa,CAAE,gBAAkB,CAC/B,IAAK,IAAM,eAAe,KAAKA,cAC7B,YAAY,aAAa,CAAE,cAAe,CAAC,CAE/C,CACF"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/iframe/transformers/index.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\nimport { PadIframeTransformer } from './pad-transformer';\n/**\n * Default iframe transformer\n * This transformer is used to call all the transformers\n */\nclass DefaultIframeTransformer implements IframeTransformer {\n #transformers = [new PadIframeTransformer()];\n onRenderHTML({ HTMLAttributes }) {\n for (const transformer of this.#transformers) {\n transformer.onRenderHTML({ HTMLAttributes });\n }\n }\n}\n\nexport const iframeTransformer: IframeTransformer =\n new DefaultIframeTransformer();\n"],"names":["PadIframeTransformer"],"mappings":"0kBAMA,MAAM,wBAAsD,CAA5D,cACE,gCAAgB,CAAC,IAAIA,eAAAA,oBAAsB,GAC3C,aAAa,CAAE,gBAAkB,CAC/B,UAAW,eAAe,kBAAK,eAC7B,YAAY,aAAa,CAAE,eAAgB,CAE/C,CACF,CANE,0BAQK,MAAM,kBACX,IAAI"}
@@ -1,2 +1,22 @@
1
- import{PadIframeTransformer}from"./pad-transformer.js";var iframeTransformer=new class{#transformers=[new PadIframeTransformer];onRenderHTML({HTMLAttributes}){for(let transformer of this.#transformers)transformer.onRenderHTML({HTMLAttributes})}};export{iframeTransformer};
2
- //# sourceMappingURL=index.js.map
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
6
+ import { PadIframeTransformer } from "./pad-transformer.js";
7
+ var _transformers;
8
+ class DefaultIframeTransformer {
9
+ constructor() {
10
+ __privateAdd(this, _transformers, [new PadIframeTransformer()]);
11
+ }
12
+ onRenderHTML({ HTMLAttributes }) {
13
+ for (const transformer of __privateGet(this, _transformers))
14
+ transformer.onRenderHTML({ HTMLAttributes });
15
+ }
16
+ }
17
+ _transformers = new WeakMap();
18
+ const iframeTransformer = new DefaultIframeTransformer();
19
+ export {
20
+ iframeTransformer
21
+ };
22
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["#transformers"],"sources":["../../../src/iframe/transformers/index.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\nimport { PadIframeTransformer } from './pad-transformer';\n/**\n * Default iframe transformer\n * This transformer is used to call all the transformers\n */\nclass DefaultIframeTransformer implements IframeTransformer {\n #transformers = [new PadIframeTransformer()];\n onRenderHTML({ HTMLAttributes }) {\n for (const transformer of this.#transformers) {\n transformer.onRenderHTML({ HTMLAttributes });\n }\n }\n}\n\nexport const iframeTransformer: IframeTransformer =\n new DefaultIframeTransformer();\n"],"mappings":"uDAeA,IAAa,kBACX,IAAI,KAVsD,CAC1D,cAAgB,CAAC,IAAI,oBAAsB,EAC3C,aAAa,CAAE,gBAAkB,CAC/B,IAAK,IAAM,eAAe,KAAKA,cAC7B,YAAY,aAAa,CAAE,cAAe,CAAC,CAE/C,CACF"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/iframe/transformers/index.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\nimport { PadIframeTransformer } from './pad-transformer';\n/**\n * Default iframe transformer\n * This transformer is used to call all the transformers\n */\nclass DefaultIframeTransformer implements IframeTransformer {\n #transformers = [new PadIframeTransformer()];\n onRenderHTML({ HTMLAttributes }) {\n for (const transformer of this.#transformers) {\n transformer.onRenderHTML({ HTMLAttributes });\n }\n }\n}\n\nexport const iframeTransformer: IframeTransformer =\n new DefaultIframeTransformer();\n"],"names":[],"mappings":";;;;;;;AAMA,MAAM,yBAAsD;AAAA,EAA5D;AACE,sCAAgB,CAAC,IAAI,sBAAsB;AAAA;AAAA,EAC3C,aAAa,EAAE,kBAAkB;AAC/B,eAAW,eAAe,mBAAK;AAC7B,kBAAY,aAAa,EAAE,gBAAgB;AAAA,EAE/C;AACF;AANE;AAQK,MAAM,oBACX,IAAI,yBAAA;"}
@@ -1,2 +1,2 @@
1
- var PadIframeTransformer=class{constructor(){this.padPath=`/pad/`,this.embedPath=`/collaborativeeditor/embed/`}onRenderHTML({HTMLAttributes}){try{let currentUrl=window.location.href.split(`?`)[0],baseUrl=new URL(currentUrl).origin,srcUrl=new URL(HTMLAttributes.src),pathMatch=srcUrl.pathname.match(RegExp(`^${this.padPath}(.+)$`));if(srcUrl.origin===baseUrl&&pathMatch&&pathMatch[1]){let padId=pathMatch[1].replace(/^p\//i,``),newUrl=new URL(`${baseUrl}${this.embedPath}${padId}`);srcUrl.searchParams.forEach((value,key)=>{newUrl.searchParams.set(key,value)}),HTMLAttributes.src=newUrl.toString()}}catch(e){console.error(`Error transforming pad URL:`,e)}}};exports.PadIframeTransformer=PadIframeTransformer;
2
- //# sourceMappingURL=pad-transformer.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class PadIframeTransformer{constructor(){this.padPath="/pad/",this.embedPath="/collaborativeeditor/embed/"}onRenderHTML({HTMLAttributes}){try{const currentUrl=window.location.href.split("?")[0],baseUrl=new URL(currentUrl).origin,srcUrl=new URL(HTMLAttributes.src),pathMatch=srcUrl.pathname.match(new RegExp(`^${this.padPath}(.+)$`));if(srcUrl.origin===baseUrl&&pathMatch&&pathMatch[1]){const padId=pathMatch[1].replace(/^p\//i,""),newUrl=new URL(`${baseUrl}${this.embedPath}${padId}`);srcUrl.searchParams.forEach((value,key)=>{newUrl.searchParams.set(key,value)}),HTMLAttributes.src=newUrl.toString()}}catch(e){console.error("Error transforming pad URL:",e)}}}exports.PadIframeTransformer=PadIframeTransformer;
2
+ //# sourceMappingURL=pad-transformer.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"pad-transformer.cjs","names":[],"sources":["../../../src/iframe/transformers/pad-transformer.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\n\n/**\n * This transformer is used to transform the pad URL to the embed URL inside the iframe\n * The embed URL is used to create a session for the pad before redirecting to the pad url\n */\nexport class PadIframeTransformer implements IframeTransformer {\n // Define the pad path\n private padPath = '/pad/';\n // Define the embed path\n private embedPath = '/collaborativeeditor/embed/';\n onRenderHTML({ HTMLAttributes }) {\n try {\n // Get host URL from the current window\n const currentUrl = window.location.href.split('?')[0];\n const baseUrl = new URL(currentUrl).origin;\n // Get Iframe src URL\n const srcUrl = new URL(HTMLAttributes.src);\n const pathMatch = srcUrl.pathname.match(\n new RegExp(`^${this.padPath}(.+)$`),\n );\n // Check if the src URL is from the same origin and matches the pad path\n if (srcUrl.origin === baseUrl && pathMatch && pathMatch[1]) {\n // Extract pad ID from the URL\n const padId = pathMatch[1].replace(/^p\\//i, '');\n // Create a new URL with the embed path\n const newUrl = new URL(`${baseUrl}${this.embedPath}${padId}`);\n // Copy search params from the src URL to the new URL\n srcUrl.searchParams.forEach((value, key) => {\n newUrl.searchParams.set(key, value);\n });\n // Set the new URL\n HTMLAttributes.src = newUrl.toString();\n }\n } catch (e) {\n console.error('Error transforming pad URL:', e);\n }\n }\n}\n"],"mappings":"AAMA,IAAa,qBAAb,KAA+D,4BAE3C,uBAEE,8BACpB,aAAa,CAAE,gBAAkB,CAC/B,GAAI,CAEF,IAAM,WAAa,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,GAC7C,QAAU,IAAI,IAAI,UAAU,EAAE,OAE9B,OAAS,IAAI,IAAI,eAAe,GAAG,EACnC,UAAY,OAAO,SAAS,MAC5B,OAAO,IAAI,KAAK,QAAQ,MAAM,CACpC,EAEA,GAAI,OAAO,SAAW,SAAW,WAAa,UAAU,GAAI,CAE1D,IAAM,MAAQ,UAAU,GAAG,QAAQ,QAAS,EAAE,EAExC,OAAS,IAAI,IAAI,GAAG,UAAU,KAAK,YAAY,OAAO,EAE5D,OAAO,aAAa,SAAS,MAAO,MAAQ,CAC1C,OAAO,aAAa,IAAI,IAAK,KAAK,CACpC,CAAC,EAED,eAAe,IAAM,OAAO,SAAS,CACvC,CACF,OAAS,EAAG,CACV,QAAQ,MAAM,8BAA+B,CAAC,CAChD,CACF,CACF"}
1
+ {"version":3,"file":"pad-transformer.cjs","sources":["../../../src/iframe/transformers/pad-transformer.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\n\n/**\n * This transformer is used to transform the pad URL to the embed URL inside the iframe\n * The embed URL is used to create a session for the pad before redirecting to the pad url\n */\nexport class PadIframeTransformer implements IframeTransformer {\n // Define the pad path\n private padPath = '/pad/';\n // Define the embed path\n private embedPath = '/collaborativeeditor/embed/';\n onRenderHTML({ HTMLAttributes }) {\n try {\n // Get host URL from the current window\n const currentUrl = window.location.href.split('?')[0];\n const baseUrl = new URL(currentUrl).origin;\n // Get Iframe src URL\n const srcUrl = new URL(HTMLAttributes.src);\n const pathMatch = srcUrl.pathname.match(\n new RegExp(`^${this.padPath}(.+)$`),\n );\n // Check if the src URL is from the same origin and matches the pad path\n if (srcUrl.origin === baseUrl && pathMatch && pathMatch[1]) {\n // Extract pad ID from the URL\n const padId = pathMatch[1].replace(/^p\\//i, '');\n // Create a new URL with the embed path\n const newUrl = new URL(`${baseUrl}${this.embedPath}${padId}`);\n // Copy search params from the src URL to the new URL\n srcUrl.searchParams.forEach((value, key) => {\n newUrl.searchParams.set(key, value);\n });\n // Set the new URL\n HTMLAttributes.src = newUrl.toString();\n }\n } catch (e) {\n console.error('Error transforming pad URL:', e);\n }\n }\n}\n"],"names":[],"mappings":"gFAMO,MAAM,oBAAkD,CAAxD,aAAA,CAEL,KAAQ,QAAU,QAElB,KAAQ,UAAY,6BAAA,CACpB,aAAa,CAAE,gBAAkB,CAC/B,GAAI,CAEF,MAAM,WAAa,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC,EAC9C,QAAU,IAAI,IAAI,UAAU,EAAE,OAE9B,OAAS,IAAI,IAAI,eAAe,GAAG,EACnC,UAAY,OAAO,SAAS,MAChC,IAAI,OAAO,IAAI,KAAK,OAAO,OAAO,CAAA,EAGpC,GAAI,OAAO,SAAW,SAAW,WAAa,UAAU,CAAC,EAAG,CAE1D,MAAM,MAAQ,UAAU,CAAC,EAAE,QAAQ,QAAS,EAAE,EAExC,OAAS,IAAI,IAAI,GAAG,OAAO,GAAG,KAAK,SAAS,GAAG,KAAK,EAAE,EAE5D,OAAO,aAAa,QAAQ,CAAC,MAAO,MAAQ,CAC1C,OAAO,aAAa,IAAI,IAAK,KAAK,CACpC,CAAC,EAED,eAAe,IAAM,OAAO,SAAA,CAC9B,CACF,OAAS,EAAG,CACV,QAAQ,MAAM,8BAA+B,CAAC,CAChD,CACF,CACF"}
@@ -1,2 +1,24 @@
1
- var PadIframeTransformer=class{constructor(){this.padPath=`/pad/`,this.embedPath=`/collaborativeeditor/embed/`}onRenderHTML({HTMLAttributes}){try{let currentUrl=window.location.href.split(`?`)[0],baseUrl=new URL(currentUrl).origin,srcUrl=new URL(HTMLAttributes.src),pathMatch=srcUrl.pathname.match(RegExp(`^${this.padPath}(.+)$`));if(srcUrl.origin===baseUrl&&pathMatch&&pathMatch[1]){let padId=pathMatch[1].replace(/^p\//i,``),newUrl=new URL(`${baseUrl}${this.embedPath}${padId}`);srcUrl.searchParams.forEach((value,key)=>{newUrl.searchParams.set(key,value)}),HTMLAttributes.src=newUrl.toString()}}catch(e){console.error(`Error transforming pad URL:`,e)}}};export{PadIframeTransformer};
2
- //# sourceMappingURL=pad-transformer.js.map
1
+ class PadIframeTransformer {
2
+ constructor() {
3
+ this.padPath = "/pad/", this.embedPath = "/collaborativeeditor/embed/";
4
+ }
5
+ onRenderHTML({ HTMLAttributes }) {
6
+ try {
7
+ const currentUrl = window.location.href.split("?")[0], baseUrl = new URL(currentUrl).origin, srcUrl = new URL(HTMLAttributes.src), pathMatch = srcUrl.pathname.match(
8
+ new RegExp(`^${this.padPath}(.+)$`)
9
+ );
10
+ if (srcUrl.origin === baseUrl && pathMatch && pathMatch[1]) {
11
+ const padId = pathMatch[1].replace(/^p\//i, ""), newUrl = new URL(`${baseUrl}${this.embedPath}${padId}`);
12
+ srcUrl.searchParams.forEach((value, key) => {
13
+ newUrl.searchParams.set(key, value);
14
+ }), HTMLAttributes.src = newUrl.toString();
15
+ }
16
+ } catch (e) {
17
+ console.error("Error transforming pad URL:", e);
18
+ }
19
+ }
20
+ }
21
+ export {
22
+ PadIframeTransformer
23
+ };
24
+ //# sourceMappingURL=pad-transformer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pad-transformer.js","names":[],"sources":["../../../src/iframe/transformers/pad-transformer.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\n\n/**\n * This transformer is used to transform the pad URL to the embed URL inside the iframe\n * The embed URL is used to create a session for the pad before redirecting to the pad url\n */\nexport class PadIframeTransformer implements IframeTransformer {\n // Define the pad path\n private padPath = '/pad/';\n // Define the embed path\n private embedPath = '/collaborativeeditor/embed/';\n onRenderHTML({ HTMLAttributes }) {\n try {\n // Get host URL from the current window\n const currentUrl = window.location.href.split('?')[0];\n const baseUrl = new URL(currentUrl).origin;\n // Get Iframe src URL\n const srcUrl = new URL(HTMLAttributes.src);\n const pathMatch = srcUrl.pathname.match(\n new RegExp(`^${this.padPath}(.+)$`),\n );\n // Check if the src URL is from the same origin and matches the pad path\n if (srcUrl.origin === baseUrl && pathMatch && pathMatch[1]) {\n // Extract pad ID from the URL\n const padId = pathMatch[1].replace(/^p\\//i, '');\n // Create a new URL with the embed path\n const newUrl = new URL(`${baseUrl}${this.embedPath}${padId}`);\n // Copy search params from the src URL to the new URL\n srcUrl.searchParams.forEach((value, key) => {\n newUrl.searchParams.set(key, value);\n });\n // Set the new URL\n HTMLAttributes.src = newUrl.toString();\n }\n } catch (e) {\n console.error('Error transforming pad URL:', e);\n }\n }\n}\n"],"mappings":"AAMA,IAAa,qBAAb,KAA+D,4BAE3C,uBAEE,8BACpB,aAAa,CAAE,gBAAkB,CAC/B,GAAI,CAEF,IAAM,WAAa,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,GAC7C,QAAU,IAAI,IAAI,UAAU,EAAE,OAE9B,OAAS,IAAI,IAAI,eAAe,GAAG,EACnC,UAAY,OAAO,SAAS,MAC5B,OAAO,IAAI,KAAK,QAAQ,MAAM,CACpC,EAEA,GAAI,OAAO,SAAW,SAAW,WAAa,UAAU,GAAI,CAE1D,IAAM,MAAQ,UAAU,GAAG,QAAQ,QAAS,EAAE,EAExC,OAAS,IAAI,IAAI,GAAG,UAAU,KAAK,YAAY,OAAO,EAE5D,OAAO,aAAa,SAAS,MAAO,MAAQ,CAC1C,OAAO,aAAa,IAAI,IAAK,KAAK,CACpC,CAAC,EAED,eAAe,IAAM,OAAO,SAAS,CACvC,CACF,OAAS,EAAG,CACV,QAAQ,MAAM,8BAA+B,CAAC,CAChD,CACF,CACF"}
1
+ {"version":3,"file":"pad-transformer.js","sources":["../../../src/iframe/transformers/pad-transformer.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\n\n/**\n * This transformer is used to transform the pad URL to the embed URL inside the iframe\n * The embed URL is used to create a session for the pad before redirecting to the pad url\n */\nexport class PadIframeTransformer implements IframeTransformer {\n // Define the pad path\n private padPath = '/pad/';\n // Define the embed path\n private embedPath = '/collaborativeeditor/embed/';\n onRenderHTML({ HTMLAttributes }) {\n try {\n // Get host URL from the current window\n const currentUrl = window.location.href.split('?')[0];\n const baseUrl = new URL(currentUrl).origin;\n // Get Iframe src URL\n const srcUrl = new URL(HTMLAttributes.src);\n const pathMatch = srcUrl.pathname.match(\n new RegExp(`^${this.padPath}(.+)$`),\n );\n // Check if the src URL is from the same origin and matches the pad path\n if (srcUrl.origin === baseUrl && pathMatch && pathMatch[1]) {\n // Extract pad ID from the URL\n const padId = pathMatch[1].replace(/^p\\//i, '');\n // Create a new URL with the embed path\n const newUrl = new URL(`${baseUrl}${this.embedPath}${padId}`);\n // Copy search params from the src URL to the new URL\n srcUrl.searchParams.forEach((value, key) => {\n newUrl.searchParams.set(key, value);\n });\n // Set the new URL\n HTMLAttributes.src = newUrl.toString();\n }\n } catch (e) {\n console.error('Error transforming pad URL:', e);\n }\n }\n}\n"],"names":[],"mappings":"AAMO,MAAM,qBAAkD;AAAA,EAAxD,cAAA;AAEL,SAAQ,UAAU,SAElB,KAAQ,YAAY;AAAA,EAAA;AAAA,EACpB,aAAa,EAAE,kBAAkB;AAC/B,QAAI;AAEF,YAAM,aAAa,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC,GAC9C,UAAU,IAAI,IAAI,UAAU,EAAE,QAE9B,SAAS,IAAI,IAAI,eAAe,GAAG,GACnC,YAAY,OAAO,SAAS;AAAA,QAChC,IAAI,OAAO,IAAI,KAAK,OAAO,OAAO;AAAA,MAAA;AAGpC,UAAI,OAAO,WAAW,WAAW,aAAa,UAAU,CAAC,GAAG;AAE1D,cAAM,QAAQ,UAAU,CAAC,EAAE,QAAQ,SAAS,EAAE,GAExC,SAAS,IAAI,IAAI,GAAG,OAAO,GAAG,KAAK,SAAS,GAAG,KAAK,EAAE;AAE5D,eAAO,aAAa,QAAQ,CAAC,OAAO,QAAQ;AAC1C,iBAAO,aAAa,IAAI,KAAK,KAAK;AAAA,QACpC,CAAC,GAED,eAAe,MAAM,OAAO,SAAA;AAAA,MAC9B;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,+BAA+B,CAAC;AAAA,IAChD;AAAA,EACF;AACF;"}
@@ -1,2 +1,2 @@
1
- const require_runtime=require("../_virtual/_rolldown/runtime.cjs");let _tiptap_core=require("@tiptap/core"),prosemirror_state=require("prosemirror-state"),_edifice_io_utilities=require("@edifice.io/utilities"),_tiptap_extension_image=require("@tiptap/extension-image");_tiptap_extension_image=require_runtime.__toESM(_tiptap_extension_image,1);var IMAGE_INPUT_REGEX=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,Image=_tiptap_extension_image.default.extend({name:`custom-image`,draggable:!0,selectable:!0,addOptions(){return{...this.parent?.(),inline:!0,content:`inline*`,sizes:[`small`,`medium`,`large`],HTMLAttributes:{class:`custom-image`},uploadFile:()=>Promise.resolve(null)}},addAttributes(){return{...this.parent?.(),size:{default:`medium`,rendered:!1},alt:{renderHTML:attributes=>({alt:attributes.alt}),parseHTML:element=>element.getAttribute(`alt`)},title:{renderHTML:attributes=>({title:attributes.title}),parseHTML:element=>element.getAttribute(`title`)},width:{default:`350`,renderHTML:attributes=>attributes.width!==null&&attributes.width!==void 0&&!Number.isNaN(attributes.width)?{width:parseInt(attributes.width)}:{},parseHTML:element=>element.getAttribute(`width`)},height:{renderHTML:attributes=>attributes.height!==null&&attributes.height!==void 0&&!Number.isNaN(attributes.height)?{height:parseInt(attributes.height)}:{},parseHTML:element=>element.getAttribute(`height`)},style:{renderHTML:attributes=>attributes.style?{style:attributes.style}:{},parseHTML:()=>null}}},parseHTML(){return[{tag:`img[src]:not([src^="data:"])`,getAttrs:el=>{let attr={src:el.getAttribute(`src`)};return el.parentElement?.className.includes(`image-container`)&&el.parentElement.style?.width&&(attr.width=el.parentElement.style.width),el.style?.width&&(attr.width=el.style.width),[`happy`,`proud`,`dreamy`,`love`,`tired`,`angry`,`worried`,`sick`,`joker`,`sad`].filter(smiley=>attr.src.includes(smiley+`.png`)).length>0&&(attr.style={width:`1.5em`,height:`1.5em`,fontSize:`16px`},attr.width=`null`,attr.height=`null`),attr}}]},renderHTML({HTMLAttributes}){return[`img`,(0,_tiptap_core.mergeAttributes)(this.options.HTMLAttributes,HTMLAttributes)]},addInputRules(){return[(0,_tiptap_core.nodeInputRule)({find:IMAGE_INPUT_REGEX,type:this.type,getAttributes:match=>{let[,,alt,src,title]=match;return{src,alt,title}}})]},addCommands(){return{setNewImage:attrs=>({tr,dispatch})=>{let{selection}=tr,node=this.type.create(attrs);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0},setAttributes:attributes=>({tr,dispatch})=>{let{selection}=tr,options={...tr.doc.nodeAt(tr.selection.from).attrs,...attributes},node=this.type.create(options);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0}}},addProseMirrorPlugins(){let uploadNode=async file=>{let resizedImage=await _edifice_io_utilities.ImageResizer.resizeImageFile(file),image=await this.options.uploadFile(resizedImage),imageUrl=`/workspace/${image.public?`pub/`:``}document/${image._id}?timestamp=${new Date().getTime()}`;return this.type.create({src:imageUrl,alt:image.alt,title:image.title})},getFilteredFiles=files=>Array.from(files).filter(file=>/image\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type)),handleImageInsert=async(editor,file,position)=>{let node=await uploadNode(file);if(!node)return;let transaction=position===void 0?editor.state.tr.replaceSelectionWith(node):editor.state.tr.insert(position,node);editor.dispatch(transaction)};return[new prosemirror_state.Plugin({props:{handlePaste:(editor,e)=>{let files=getFilteredFiles(e.clipboardData?.files);if(files.length===0)return!1;for(let file of files)handleImageInsert(editor,file);return!0},handleDrop:(editor,e,_s,moved)=>{if(moved)return!1;let files=getFilteredFiles(e.dataTransfer.files);if(files.length===0)return!1;let{pos:position}=editor.posAtCoords({left:e.clientX,top:e.clientY});for(let file of files)handleImageInsert(editor,file,position);return!0}}})]}});exports.IMAGE_INPUT_REGEX=IMAGE_INPUT_REGEX,exports.Image=Image;
2
- //# sourceMappingURL=image.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const utilities=require("@edifice.io/utilities"),core=require("@tiptap/core"),TiptapImage=require("@tiptap/extension-image"),prosemirrorState=require("prosemirror-state"),IMAGE_INPUT_REGEX=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,Image=TiptapImage.extend({name:"custom-image",draggable:!0,selectable:!0,addOptions(){var _a;return{...(_a=this.parent)==null?void 0:_a.call(this),inline:!0,content:"inline*",sizes:["small","medium","large"],HTMLAttributes:{class:"custom-image"},uploadFile:()=>Promise.resolve(null)}},addAttributes(){var _a;return{...(_a=this.parent)==null?void 0:_a.call(this),size:{default:"medium",rendered:!1},alt:{renderHTML:attributes=>({alt:attributes.alt}),parseHTML:element=>element.getAttribute("alt")},title:{renderHTML:attributes=>({title:attributes.title}),parseHTML:element=>element.getAttribute("title")},width:{default:"350",renderHTML:attributes=>attributes.width!==null&&attributes.width!==void 0&&!Number.isNaN(attributes.width)?{width:parseInt(attributes.width)}:{},parseHTML:element=>element.getAttribute("width")},height:{renderHTML:attributes=>attributes.height!==null&&attributes.height!==void 0&&!Number.isNaN(attributes.height)?{height:parseInt(attributes.height)}:{},parseHTML:element=>element.getAttribute("height")},style:{renderHTML:attributes=>attributes.style?{style:attributes.style}:{},parseHTML:()=>null}}},parseHTML(){return[{tag:'img[src]:not([src^="data:"])',getAttrs:el=>{var _a,_b,_c;const attr={src:el.getAttribute("src")};return(_a=el.parentElement)!=null&&_a.className.includes("image-container")&&(_b=el.parentElement.style)!=null&&_b.width&&(attr.width=el.parentElement.style.width),(_c=el.style)!=null&&_c.width&&(attr.width=el.style.width),["happy","proud","dreamy","love","tired","angry","worried","sick","joker","sad"].filter(smiley=>attr.src.includes(smiley+".png")).length>0&&(attr.style={width:"1.5em",height:"1.5em",fontSize:"16px"},attr.width="null",attr.height="null"),attr}}]},renderHTML({HTMLAttributes}){return["img",core.mergeAttributes(this.options.HTMLAttributes,HTMLAttributes)]},addInputRules(){return[core.nodeInputRule({find:IMAGE_INPUT_REGEX,type:this.type,getAttributes:match=>{const[,,alt,src,title]=match;return{src,alt,title}}})]},addCommands(){return{setNewImage:attrs=>({tr,dispatch})=>{const{selection}=tr,node=this.type.create(attrs);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0},setAttributes:attributes=>({tr,dispatch})=>{const{selection}=tr,options={...tr.doc.nodeAt(tr.selection.from).attrs,...attributes},node=this.type.create(options);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0}}},addProseMirrorPlugins(){const uploadNode=async file=>{const resizedImage=await utilities.ImageResizer.resizeImageFile(file),image=await this.options.uploadFile(resizedImage),imageUrl=`/workspace/${image.public?"pub/":""}document/${image._id}?timestamp=${new Date().getTime()}`;return this.type.create({src:imageUrl,alt:image.alt,title:image.title})},getFilteredFiles=files=>Array.from(files).filter(file=>/image\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type)),handleImageInsert=async(editor,file,position)=>{const node=await uploadNode(file);if(!node)return;const transaction=position!==void 0?editor.state.tr.insert(position,node):editor.state.tr.replaceSelectionWith(node);editor.dispatch(transaction)};return[new prosemirrorState.Plugin({props:{handlePaste:(editor,e)=>{var _a;const files=getFilteredFiles((_a=e.clipboardData)==null?void 0:_a.files);if(files.length===0)return!1;for(const file of files)handleImageInsert(editor,file);return!0},handleDrop:(editor,e,_s,moved)=>{if(moved)return!1;const files=getFilteredFiles(e.dataTransfer.files);if(files.length===0)return!1;const{pos:position}=editor.posAtCoords({left:e.clientX,top:e.clientY});for(const file of files)handleImageInsert(editor,file,position);return!0}}})]}});exports.IMAGE_INPUT_REGEX=IMAGE_INPUT_REGEX;exports.Image=Image;
2
+ //# sourceMappingURL=image.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"image.cjs","names":[],"sources":["../../src/image/image.ts"],"sourcesContent":["import { WorkspaceElement } from '@edifice.io/client';\nimport { ImageResizer } from '@edifice.io/utilities';\nimport { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport TiptapImage from '@tiptap/extension-image';\nimport { Plugin } from 'prosemirror-state';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\n uploadFile?: (file: File) => Promise<WorkspaceElement | null>;\n}\n\ninterface AttributesProps {\n width: number | string;\n height: number | string;\n size: string;\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n customImage: {\n setAttributes: (options: AttributesProps) => ReturnType;\n setNewImage: (options: {\n src: string;\n alt?: string;\n title?: string;\n }) => ReturnType;\n };\n }\n}\n\nexport const Image = TiptapImage.extend<CustomImageOptions>({\n name: 'custom-image',\n draggable: true,\n selectable: true,\n\n addOptions() {\n return {\n ...this.parent?.(),\n inline: true,\n content: 'inline*',\n sizes: ['small', 'medium', 'large'],\n HTMLAttributes: {\n class: 'custom-image',\n },\n uploadFile: () => {\n return Promise.resolve(null);\n },\n };\n },\n\n addAttributes() {\n return {\n ...this.parent?.(),\n size: {\n default: 'medium',\n rendered: false,\n },\n alt: {\n renderHTML: (attributes) => {\n return {\n alt: attributes.alt,\n };\n },\n parseHTML: (element) => element.getAttribute('alt'),\n },\n title: {\n renderHTML: (attributes) => {\n return {\n title: attributes.title,\n };\n },\n parseHTML: (element) => element.getAttribute('title'),\n },\n width: {\n default: '350',\n renderHTML: (attributes) => {\n if (\n attributes.width !== null &&\n attributes.width !== undefined &&\n !Number.isNaN(attributes.width)\n ) {\n return {\n width: parseInt(attributes.width),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n if (\n attributes.height !== null &&\n attributes.height !== undefined &&\n !Number.isNaN(attributes.height)\n ) {\n return {\n height: parseInt(attributes.height),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: () => {\n return null;\n },\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]:not([src^=\"data:\"])',\n getAttrs: (el: HTMLImageElement) => {\n const attr = { src: el.getAttribute('src') };\n // Check old content format and get the width from the parent element\n if (el.parentElement?.className.includes('image-container')) {\n if (el.parentElement.style?.width) {\n attr['width'] = el.parentElement.style.width;\n }\n }\n if (el.style?.width) {\n attr['width'] = el.style.width;\n }\n\n // Check old content smiley\n const oldSmileyList = [\n 'happy',\n 'proud',\n 'dreamy',\n 'love',\n 'tired',\n 'angry',\n 'worried',\n 'sick',\n 'joker',\n 'sad',\n ];\n if (\n oldSmileyList.filter((smiley) => attr.src.includes(smiley + '.png'))\n .length > 0\n ) {\n attr['style'] = {\n width: '1.5em',\n height: '1.5em',\n fontSize: '16px',\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\n }\n\n return attr;\n },\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'img',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n ];\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: IMAGE_INPUT_REGEX,\n type: this.type,\n getAttributes: (match) => {\n const [, , alt, src, title] = match;\n\n return {\n src,\n alt,\n title,\n };\n },\n }),\n ];\n },\n\n addCommands() {\n return {\n setNewImage:\n (attrs) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(attrs);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n setAttributes:\n (attributes) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n\n const nodeAttrs = tr.doc.nodeAt(tr.selection.from);\n const options = {\n ...nodeAttrs.attrs,\n ...attributes,\n };\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n\n addProseMirrorPlugins() {\n const uploadNode = async (file: File) => {\n /**\n * Resize the image\n */\n const resizedImage = await ImageResizer.resizeImageFile(file);\n\n /**\n * Upload the image\n */\n const image = await this.options.uploadFile(resizedImage);\n\n /**\n * Get the image url\n */\n const imageUrl = `/workspace/${image.public ? 'pub/' : ''}document/${\n image._id\n }?timestamp=${new Date().getTime()}`;\n\n /**\n * Create the image node\n */\n\n const node = this.type.create({\n src: imageUrl,\n alt: image.alt,\n title: image.title,\n });\n\n return node;\n };\n\n const getFilteredFiles = (files: FileList) => {\n return Array.from(files).filter((file) =>\n /image\\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type),\n );\n };\n\n const handleImageInsert = async (\n editor: any,\n file: File,\n position?: number,\n ) => {\n const node = await uploadNode(file);\n if (!node) return;\n\n const transaction =\n position !== undefined\n ? editor.state.tr.insert(position, node)\n : editor.state.tr.replaceSelectionWith(node);\n\n editor.dispatch(transaction);\n };\n\n return [\n new Plugin({\n props: {\n handlePaste: (editor, e) => {\n const files = getFilteredFiles(e.clipboardData?.files);\n if (files.length === 0) return false;\n\n for (const file of files) {\n handleImageInsert(editor, file);\n }\n\n return true;\n },\n handleDrop: (editor, e, _s, moved) => {\n if (moved) return false;\n\n const files = getFilteredFiles(e.dataTransfer.files);\n if (files.length === 0) return false;\n\n const { pos: position } = editor.posAtCoords({\n left: e.clientX,\n top: e.clientY,\n });\n\n for (const file of files) {\n handleImageInsert(editor, file, position);\n }\n return true;\n },\n },\n }),\n ];\n },\n});\n"],"mappings":"wVAMA,IAA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AAc,MAAM,OAAS,OAAS,GAAG,WACxD,MAAM,IACP,aAAa,IAAI,KAAK,EAAE,QAAQ,IAYjC,OANa,KAAK,KAAK,OAAO,CAC5B,IAAK,SACL,IAAK,MAAM,IACX,MAAO,MAAM,KACf,CAEO,CACT,EAEM,iBAAoB,OACjB,MAAM,KAAK,KAAK,EAAE,OAAQ,MAC/B,2CAA2C,KAAK,KAAK,IAAI,CAC3D,EAGI,kBAAoB,MACxB,OACA,KACA,WACG,CACH,IAAM,KAAO,MAAM,WAAW,IAAI,EAClC,GAAI,CAAC,KAAM,OAEX,IAAM,YACJ,WAAa,IAAA,GAET,OAAO,MAAM,GAAG,qBAAqB,IAAI,EADzC,OAAO,MAAM,GAAG,OAAO,SAAU,IAAI,EAG3C,OAAO,SAAS,WAAW,CAC7B,EAEA,MAAO,CACL,IAAI,kBAAA,OAAO,CACT,MAAO,CACL,aAAc,OAAQ,IAAM,CAC1B,IAAM,MAAQ,iBAAiB,EAAE,eAAe,KAAK,EACrD,GAAI,MAAM,SAAW,EAAG,MAAO,GAE/B,IAAK,IAAM,QAAQ,MACjB,kBAAkB,OAAQ,IAAI,EAGhC,MAAO,EACT,EACA,YAAa,OAAQ,EAAG,GAAI,QAAU,CACpC,GAAI,MAAO,MAAO,GAElB,IAAM,MAAQ,iBAAiB,EAAE,aAAa,KAAK,EACnD,GAAI,MAAM,SAAW,EAAG,MAAO,GAE/B,GAAM,CAAE,IAAK,UAAa,OAAO,YAAY,CAC3C,KAAM,EAAE,QACR,IAAK,EAAE,OACT,CAAC,EAED,IAAK,IAAM,QAAQ,MACjB,kBAAkB,OAAQ,KAAM,QAAQ,EAE1C,MAAO,EACT,CACF,CACF,CAAC,CACH,CACF,CACF,CAAC"}
1
+ {"version":3,"file":"image.cjs","sources":["../../src/image/image.ts"],"sourcesContent":["import { WorkspaceElement } from '@edifice.io/client';\nimport { ImageResizer } from '@edifice.io/utilities';\nimport { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport TiptapImage from '@tiptap/extension-image';\nimport { Plugin } from 'prosemirror-state';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\n uploadFile?: (file: File) => Promise<WorkspaceElement | null>;\n}\n\ninterface AttributesProps {\n width: number | string;\n height: number | string;\n size: string;\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n customImage: {\n setAttributes: (options: AttributesProps) => ReturnType;\n setNewImage: (options: {\n src: string;\n alt?: string;\n title?: string;\n }) => ReturnType;\n };\n }\n}\n\nexport const Image = TiptapImage.extend<CustomImageOptions>({\n name: 'custom-image',\n draggable: true,\n selectable: true,\n\n addOptions() {\n return {\n ...this.parent?.(),\n inline: true,\n content: 'inline*',\n sizes: ['small', 'medium', 'large'],\n HTMLAttributes: {\n class: 'custom-image',\n },\n uploadFile: () => {\n return Promise.resolve(null);\n },\n };\n },\n\n addAttributes() {\n return {\n ...this.parent?.(),\n size: {\n default: 'medium',\n rendered: false,\n },\n alt: {\n renderHTML: (attributes) => {\n return {\n alt: attributes.alt,\n };\n },\n parseHTML: (element) => element.getAttribute('alt'),\n },\n title: {\n renderHTML: (attributes) => {\n return {\n title: attributes.title,\n };\n },\n parseHTML: (element) => element.getAttribute('title'),\n },\n width: {\n default: '350',\n renderHTML: (attributes) => {\n if (\n attributes.width !== null &&\n attributes.width !== undefined &&\n !Number.isNaN(attributes.width)\n ) {\n return {\n width: parseInt(attributes.width),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n if (\n attributes.height !== null &&\n attributes.height !== undefined &&\n !Number.isNaN(attributes.height)\n ) {\n return {\n height: parseInt(attributes.height),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: () => {\n return null;\n },\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]:not([src^=\"data:\"])',\n getAttrs: (el: HTMLImageElement) => {\n const attr = { src: el.getAttribute('src') };\n // Check old content format and get the width from the parent element\n if (el.parentElement?.className.includes('image-container')) {\n if (el.parentElement.style?.width) {\n attr['width'] = el.parentElement.style.width;\n }\n }\n if (el.style?.width) {\n attr['width'] = el.style.width;\n }\n\n // Check old content smiley\n const oldSmileyList = [\n 'happy',\n 'proud',\n 'dreamy',\n 'love',\n 'tired',\n 'angry',\n 'worried',\n 'sick',\n 'joker',\n 'sad',\n ];\n if (\n oldSmileyList.filter((smiley) => attr.src.includes(smiley + '.png'))\n .length > 0\n ) {\n attr['style'] = {\n width: '1.5em',\n height: '1.5em',\n fontSize: '16px',\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\n }\n\n return attr;\n },\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'img',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n ];\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: IMAGE_INPUT_REGEX,\n type: this.type,\n getAttributes: (match) => {\n const [, , alt, src, title] = match;\n\n return {\n src,\n alt,\n title,\n };\n },\n }),\n ];\n },\n\n addCommands() {\n return {\n setNewImage:\n (attrs) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(attrs);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n setAttributes:\n (attributes) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n\n const nodeAttrs = tr.doc.nodeAt(tr.selection.from);\n const options = {\n ...nodeAttrs.attrs,\n ...attributes,\n };\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n\n addProseMirrorPlugins() {\n const uploadNode = async (file: File) => {\n /**\n * Resize the image\n */\n const resizedImage = await ImageResizer.resizeImageFile(file);\n\n /**\n * Upload the image\n */\n const image = await this.options.uploadFile(resizedImage);\n\n /**\n * Get the image url\n */\n const imageUrl = `/workspace/${image.public ? 'pub/' : ''}document/${\n image._id\n }?timestamp=${new Date().getTime()}`;\n\n /**\n * Create the image node\n */\n\n const node = this.type.create({\n src: imageUrl,\n alt: image.alt,\n title: image.title,\n });\n\n return node;\n };\n\n const getFilteredFiles = (files: FileList) => {\n return Array.from(files).filter((file) =>\n /image\\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type),\n );\n };\n\n const handleImageInsert = async (\n editor: any,\n file: File,\n position?: number,\n ) => {\n const node = await uploadNode(file);\n if (!node) return;\n\n const transaction =\n position !== undefined\n ? editor.state.tr.insert(position, node)\n : editor.state.tr.replaceSelectionWith(node);\n\n editor.dispatch(transaction);\n };\n\n return [\n new Plugin({\n props: {\n handlePaste: (editor, e) => {\n const files = getFilteredFiles(e.clipboardData?.files);\n if (files.length === 0) return false;\n\n for (const file of files) {\n handleImageInsert(editor, file);\n }\n\n return true;\n },\n handleDrop: (editor, e, _s, moved) => {\n if (moved) return false;\n\n const files = getFilteredFiles(e.dataTransfer.files);\n if (files.length === 0) return false;\n\n const { pos: position } = editor.posAtCoords({\n left: e.clientX,\n top: e.clientY,\n });\n\n for (const file of files) {\n handleImageInsert(editor, file, position);\n }\n return true;\n },\n },\n }),\n ];\n },\n});\n"],"names":["mergeAttributes","nodeInputRule","ImageResizer","Plugin"],"mappings":"2PAMa,kBACX,2DA2BW,MAAQ,YAAY,OAA2B,CAC1D,KAAM,eACN,UAAW,GACX,WAAY,GAEZ,YAAa,QACX,MAAO,CACL,IAAG,QAAK,SAAL,0BACH,OAAQ,GACR,QAAS,UACT,MAAO,CAAC,QAAS,SAAU,OAAO,EAClC,eAAgB,CACd,MAAO,cAAA,EAET,WAAY,IACH,QAAQ,QAAQ,IAAI,CAC7B,CAEJ,EAEA,eAAgB,QACd,MAA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AK,KAAK,IAAI,CAAA,EAIvD,kBAAoB,MACxB,OACA,KACA,WACG,CACH,MAAM,KAAO,MAAM,WAAW,IAAI,EAClC,GAAI,CAAC,KAAM,OAEX,MAAM,YACJ,WAAa,OACT,OAAO,MAAM,GAAG,OAAO,SAAU,IAAI,EACrC,OAAO,MAAM,GAAG,qBAAqB,IAAI,EAE/C,OAAO,SAAS,WAAW,CAC7B,EAEA,MAAO,CACL,IAAIC,wBAAO,CACT,MAAO,CACL,YAAa,CAAC,OAAQ,IAAM,QAC1B,MAAM,MAAQ,kBAAiB,KAAE,gBAAF,eAAiB,KAAK,EACrD,GAAI,MAAM,SAAW,EAAG,MAAO,GAE/B,UAAW,QAAQ,MACjB,kBAAkB,OAAQ,IAAI,EAGhC,MAAO,EACT,EACA,WAAY,CAAC,OAAQ,EAAG,GAAI,QAAU,CACpC,GAAI,MAAO,MAAO,GAElB,MAAM,MAAQ,iBAAiB,EAAE,aAAa,KAAK,EACnD,GAAI,MAAM,SAAW,EAAG,MAAO,GAE/B,KAAM,CAAE,IAAK,UAAa,OAAO,YAAY,CAC3C,KAAM,EAAE,QACR,IAAK,EAAE,OAAA,CACR,EAED,UAAW,QAAQ,MACjB,kBAAkB,OAAQ,KAAM,QAAQ,EAE1C,MAAO,EACT,CAAA,CACF,CACD,CAAA,CAEL,CACF,CAAC"}
@@ -1,2 +1,175 @@
1
- import{mergeAttributes,nodeInputRule}from"@tiptap/core";import{Plugin}from"prosemirror-state";import{ImageResizer}from"@edifice.io/utilities";import TiptapImage from"@tiptap/extension-image";var IMAGE_INPUT_REGEX=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,Image=TiptapImage.extend({name:`custom-image`,draggable:!0,selectable:!0,addOptions(){return{...this.parent?.(),inline:!0,content:`inline*`,sizes:[`small`,`medium`,`large`],HTMLAttributes:{class:`custom-image`},uploadFile:()=>Promise.resolve(null)}},addAttributes(){return{...this.parent?.(),size:{default:`medium`,rendered:!1},alt:{renderHTML:attributes=>({alt:attributes.alt}),parseHTML:element=>element.getAttribute(`alt`)},title:{renderHTML:attributes=>({title:attributes.title}),parseHTML:element=>element.getAttribute(`title`)},width:{default:`350`,renderHTML:attributes=>attributes.width!==null&&attributes.width!==void 0&&!Number.isNaN(attributes.width)?{width:parseInt(attributes.width)}:{},parseHTML:element=>element.getAttribute(`width`)},height:{renderHTML:attributes=>attributes.height!==null&&attributes.height!==void 0&&!Number.isNaN(attributes.height)?{height:parseInt(attributes.height)}:{},parseHTML:element=>element.getAttribute(`height`)},style:{renderHTML:attributes=>attributes.style?{style:attributes.style}:{},parseHTML:()=>null}}},parseHTML(){return[{tag:`img[src]:not([src^="data:"])`,getAttrs:el=>{let attr={src:el.getAttribute(`src`)};return el.parentElement?.className.includes(`image-container`)&&el.parentElement.style?.width&&(attr.width=el.parentElement.style.width),el.style?.width&&(attr.width=el.style.width),[`happy`,`proud`,`dreamy`,`love`,`tired`,`angry`,`worried`,`sick`,`joker`,`sad`].filter(smiley=>attr.src.includes(smiley+`.png`)).length>0&&(attr.style={width:`1.5em`,height:`1.5em`,fontSize:`16px`},attr.width=`null`,attr.height=`null`),attr}}]},renderHTML({HTMLAttributes}){return[`img`,mergeAttributes(this.options.HTMLAttributes,HTMLAttributes)]},addInputRules(){return[nodeInputRule({find:IMAGE_INPUT_REGEX,type:this.type,getAttributes:match=>{let[,,alt,src,title]=match;return{src,alt,title}}})]},addCommands(){return{setNewImage:attrs=>({tr,dispatch})=>{let{selection}=tr,node=this.type.create(attrs);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0},setAttributes:attributes=>({tr,dispatch})=>{let{selection}=tr,options={...tr.doc.nodeAt(tr.selection.from).attrs,...attributes},node=this.type.create(options);return dispatch&&tr.replaceRangeWith(selection.from,selection.to,node),!0}}},addProseMirrorPlugins(){let uploadNode=async file=>{let resizedImage=await ImageResizer.resizeImageFile(file),image=await this.options.uploadFile(resizedImage),imageUrl=`/workspace/${image.public?`pub/`:``}document/${image._id}?timestamp=${new Date().getTime()}`;return this.type.create({src:imageUrl,alt:image.alt,title:image.title})},getFilteredFiles=files=>Array.from(files).filter(file=>/image\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type)),handleImageInsert=async(editor,file,position)=>{let node=await uploadNode(file);if(!node)return;let transaction=position===void 0?editor.state.tr.replaceSelectionWith(node):editor.state.tr.insert(position,node);editor.dispatch(transaction)};return[new Plugin({props:{handlePaste:(editor,e)=>{let files=getFilteredFiles(e.clipboardData?.files);if(files.length===0)return!1;for(let file of files)handleImageInsert(editor,file);return!0},handleDrop:(editor,e,_s,moved)=>{if(moved)return!1;let files=getFilteredFiles(e.dataTransfer.files);if(files.length===0)return!1;let{pos:position}=editor.posAtCoords({left:e.clientX,top:e.clientY});for(let file of files)handleImageInsert(editor,file,position);return!0}}})]}});export{IMAGE_INPUT_REGEX,Image};
2
- //# sourceMappingURL=image.js.map
1
+ import { ImageResizer } from "@edifice.io/utilities";
2
+ import { nodeInputRule, mergeAttributes } from "@tiptap/core";
3
+ import TiptapImage from "@tiptap/extension-image";
4
+ import { Plugin } from "prosemirror-state";
5
+ const IMAGE_INPUT_REGEX = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, Image = TiptapImage.extend({
6
+ name: "custom-image",
7
+ draggable: !0,
8
+ selectable: !0,
9
+ addOptions() {
10
+ var _a;
11
+ return {
12
+ ...(_a = this.parent) == null ? void 0 : _a.call(this),
13
+ inline: !0,
14
+ content: "inline*",
15
+ sizes: ["small", "medium", "large"],
16
+ HTMLAttributes: {
17
+ class: "custom-image"
18
+ },
19
+ uploadFile: () => Promise.resolve(null)
20
+ };
21
+ },
22
+ addAttributes() {
23
+ var _a;
24
+ return {
25
+ ...(_a = this.parent) == null ? void 0 : _a.call(this),
26
+ size: {
27
+ default: "medium",
28
+ rendered: !1
29
+ },
30
+ alt: {
31
+ renderHTML: (attributes) => ({
32
+ alt: attributes.alt
33
+ }),
34
+ parseHTML: (element) => element.getAttribute("alt")
35
+ },
36
+ title: {
37
+ renderHTML: (attributes) => ({
38
+ title: attributes.title
39
+ }),
40
+ parseHTML: (element) => element.getAttribute("title")
41
+ },
42
+ width: {
43
+ default: "350",
44
+ renderHTML: (attributes) => attributes.width !== null && attributes.width !== void 0 && !Number.isNaN(attributes.width) ? {
45
+ width: parseInt(attributes.width)
46
+ } : {},
47
+ parseHTML: (element) => element.getAttribute("width")
48
+ },
49
+ height: {
50
+ renderHTML: (attributes) => attributes.height !== null && attributes.height !== void 0 && !Number.isNaN(attributes.height) ? {
51
+ height: parseInt(attributes.height)
52
+ } : {},
53
+ parseHTML: (element) => element.getAttribute("height")
54
+ },
55
+ style: {
56
+ renderHTML: (attributes) => attributes.style ? {
57
+ style: attributes.style
58
+ } : {},
59
+ parseHTML: () => null
60
+ }
61
+ };
62
+ },
63
+ parseHTML() {
64
+ return [
65
+ {
66
+ tag: 'img[src]:not([src^="data:"])',
67
+ getAttrs: (el) => {
68
+ var _a, _b, _c;
69
+ const attr = { src: el.getAttribute("src") };
70
+ return (_a = el.parentElement) != null && _a.className.includes("image-container") && (_b = el.parentElement.style) != null && _b.width && (attr.width = el.parentElement.style.width), (_c = el.style) != null && _c.width && (attr.width = el.style.width), [
71
+ "happy",
72
+ "proud",
73
+ "dreamy",
74
+ "love",
75
+ "tired",
76
+ "angry",
77
+ "worried",
78
+ "sick",
79
+ "joker",
80
+ "sad"
81
+ ].filter((smiley) => attr.src.includes(smiley + ".png")).length > 0 && (attr.style = {
82
+ width: "1.5em",
83
+ height: "1.5em",
84
+ fontSize: "16px"
85
+ }, attr.width = "null", attr.height = "null"), attr;
86
+ }
87
+ }
88
+ ];
89
+ },
90
+ renderHTML({ HTMLAttributes }) {
91
+ return [
92
+ "img",
93
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)
94
+ ];
95
+ },
96
+ addInputRules() {
97
+ return [
98
+ nodeInputRule({
99
+ find: IMAGE_INPUT_REGEX,
100
+ type: this.type,
101
+ getAttributes: (match) => {
102
+ const [, , alt, src, title] = match;
103
+ return {
104
+ src,
105
+ alt,
106
+ title
107
+ };
108
+ }
109
+ })
110
+ ];
111
+ },
112
+ addCommands() {
113
+ return {
114
+ setNewImage: (attrs) => ({ tr, dispatch }) => {
115
+ const { selection } = tr, node = this.type.create(attrs);
116
+ return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
117
+ },
118
+ setAttributes: (attributes) => ({ tr, dispatch }) => {
119
+ const { selection } = tr, options = {
120
+ ...tr.doc.nodeAt(tr.selection.from).attrs,
121
+ ...attributes
122
+ }, node = this.type.create(options);
123
+ return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
124
+ }
125
+ };
126
+ },
127
+ addProseMirrorPlugins() {
128
+ const uploadNode = async (file) => {
129
+ const resizedImage = await ImageResizer.resizeImageFile(file), image = await this.options.uploadFile(resizedImage), imageUrl = `/workspace/${image.public ? "pub/" : ""}document/${image._id}?timestamp=${(/* @__PURE__ */ new Date()).getTime()}`;
130
+ return this.type.create({
131
+ src: imageUrl,
132
+ alt: image.alt,
133
+ title: image.title
134
+ });
135
+ }, getFilteredFiles = (files) => Array.from(files).filter(
136
+ (file) => /image\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type)
137
+ ), handleImageInsert = async (editor, file, position) => {
138
+ const node = await uploadNode(file);
139
+ if (!node) return;
140
+ const transaction = position !== void 0 ? editor.state.tr.insert(position, node) : editor.state.tr.replaceSelectionWith(node);
141
+ editor.dispatch(transaction);
142
+ };
143
+ return [
144
+ new Plugin({
145
+ props: {
146
+ handlePaste: (editor, e) => {
147
+ var _a;
148
+ const files = getFilteredFiles((_a = e.clipboardData) == null ? void 0 : _a.files);
149
+ if (files.length === 0) return !1;
150
+ for (const file of files)
151
+ handleImageInsert(editor, file);
152
+ return !0;
153
+ },
154
+ handleDrop: (editor, e, _s, moved) => {
155
+ if (moved) return !1;
156
+ const files = getFilteredFiles(e.dataTransfer.files);
157
+ if (files.length === 0) return !1;
158
+ const { pos: position } = editor.posAtCoords({
159
+ left: e.clientX,
160
+ top: e.clientY
161
+ });
162
+ for (const file of files)
163
+ handleImageInsert(editor, file, position);
164
+ return !0;
165
+ }
166
+ }
167
+ })
168
+ ];
169
+ }
170
+ });
171
+ export {
172
+ IMAGE_INPUT_REGEX,
173
+ Image
174
+ };
175
+ //# sourceMappingURL=image.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","names":[],"sources":["../../src/image/image.ts"],"sourcesContent":["import { WorkspaceElement } from '@edifice.io/client';\nimport { ImageResizer } from '@edifice.io/utilities';\nimport { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport TiptapImage from '@tiptap/extension-image';\nimport { Plugin } from 'prosemirror-state';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\n uploadFile?: (file: File) => Promise<WorkspaceElement | null>;\n}\n\ninterface AttributesProps {\n width: number | string;\n height: number | string;\n size: string;\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n customImage: {\n setAttributes: (options: AttributesProps) => ReturnType;\n setNewImage: (options: {\n src: string;\n alt?: string;\n title?: string;\n }) => ReturnType;\n };\n }\n}\n\nexport const Image = TiptapImage.extend<CustomImageOptions>({\n name: 'custom-image',\n draggable: true,\n selectable: true,\n\n addOptions() {\n return {\n ...this.parent?.(),\n inline: true,\n content: 'inline*',\n sizes: ['small', 'medium', 'large'],\n HTMLAttributes: {\n class: 'custom-image',\n },\n uploadFile: () => {\n return Promise.resolve(null);\n },\n };\n },\n\n addAttributes() {\n return {\n ...this.parent?.(),\n size: {\n default: 'medium',\n rendered: false,\n },\n alt: {\n renderHTML: (attributes) => {\n return {\n alt: attributes.alt,\n };\n },\n parseHTML: (element) => element.getAttribute('alt'),\n },\n title: {\n renderHTML: (attributes) => {\n return {\n title: attributes.title,\n };\n },\n parseHTML: (element) => element.getAttribute('title'),\n },\n width: {\n default: '350',\n renderHTML: (attributes) => {\n if (\n attributes.width !== null &&\n attributes.width !== undefined &&\n !Number.isNaN(attributes.width)\n ) {\n return {\n width: parseInt(attributes.width),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n if (\n attributes.height !== null &&\n attributes.height !== undefined &&\n !Number.isNaN(attributes.height)\n ) {\n return {\n height: parseInt(attributes.height),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: () => {\n return null;\n },\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]:not([src^=\"data:\"])',\n getAttrs: (el: HTMLImageElement) => {\n const attr = { src: el.getAttribute('src') };\n // Check old content format and get the width from the parent element\n if (el.parentElement?.className.includes('image-container')) {\n if (el.parentElement.style?.width) {\n attr['width'] = el.parentElement.style.width;\n }\n }\n if (el.style?.width) {\n attr['width'] = el.style.width;\n }\n\n // Check old content smiley\n const oldSmileyList = [\n 'happy',\n 'proud',\n 'dreamy',\n 'love',\n 'tired',\n 'angry',\n 'worried',\n 'sick',\n 'joker',\n 'sad',\n ];\n if (\n oldSmileyList.filter((smiley) => attr.src.includes(smiley + '.png'))\n .length > 0\n ) {\n attr['style'] = {\n width: '1.5em',\n height: '1.5em',\n fontSize: '16px',\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\n }\n\n return attr;\n },\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'img',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n ];\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: IMAGE_INPUT_REGEX,\n type: this.type,\n getAttributes: (match) => {\n const [, , alt, src, title] = match;\n\n return {\n src,\n alt,\n title,\n };\n },\n }),\n ];\n },\n\n addCommands() {\n return {\n setNewImage:\n (attrs) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(attrs);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n setAttributes:\n (attributes) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n\n const nodeAttrs = tr.doc.nodeAt(tr.selection.from);\n const options = {\n ...nodeAttrs.attrs,\n ...attributes,\n };\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n\n addProseMirrorPlugins() {\n const uploadNode = async (file: File) => {\n /**\n * Resize the image\n */\n const resizedImage = await ImageResizer.resizeImageFile(file);\n\n /**\n * Upload the image\n */\n const image = await this.options.uploadFile(resizedImage);\n\n /**\n * Get the image url\n */\n const imageUrl = `/workspace/${image.public ? 'pub/' : ''}document/${\n image._id\n }?timestamp=${new Date().getTime()}`;\n\n /**\n * Create the image node\n */\n\n const node = this.type.create({\n src: imageUrl,\n alt: image.alt,\n title: image.title,\n });\n\n return node;\n };\n\n const getFilteredFiles = (files: FileList) => {\n return Array.from(files).filter((file) =>\n /image\\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type),\n );\n };\n\n const handleImageInsert = async (\n editor: any,\n file: File,\n position?: number,\n ) => {\n const node = await uploadNode(file);\n if (!node) return;\n\n const transaction =\n position !== undefined\n ? editor.state.tr.insert(position, node)\n : editor.state.tr.replaceSelectionWith(node);\n\n editor.dispatch(transaction);\n };\n\n return [\n new Plugin({\n props: {\n handlePaste: (editor, e) => {\n const files = getFilteredFiles(e.clipboardData?.files);\n if (files.length === 0) return false;\n\n for (const file of files) {\n handleImageInsert(editor, file);\n }\n\n return true;\n },\n handleDrop: (editor, e, _s, moved) => {\n if (moved) return false;\n\n const files = getFilteredFiles(e.dataTransfer.files);\n if (files.length === 0) return false;\n\n const { pos: position } = editor.posAtCoords({\n left: e.clientX,\n top: e.clientY,\n });\n\n for (const file of files) {\n handleImageInsert(editor, file, position);\n }\n return true;\n },\n },\n }),\n ];\n },\n});\n"],"mappings":"+LAMA,IAAa,kBACX,2DA2BW,MAAQ,YAAY,OAA2B,CAC1D,KAAM,eACN,UAAW,GACX,WAAY,GAEZ,YAAa,CACX,MAAO,CACL,GAAG,KAAK,SAAS,EACjB,OAAQ,GACR,QAAS,UACT,MAAO,CAAC,QAAS,SAAU,OAAO,EAClC,eAAgB,CACd,MAAO,cACT,EACA,eACS,QAAQ,QAAQ,IAAI,CAE/B,CACF,EAEA,eAAgB,CACd,MAAO,CACL,GAAG,KAAK,SAAS,EACjB,KAAM,CACJ,QAAS,SACT,SAAU,EACZ,EACA,IAAK,CACH,WAAa,aACJ,CACL,IAAK,WAAW,GAClB,GAEF,UAAY,SAAY,QAAQ,aAAa,KAAK,CACpD,EACA,MAAO,CACL,WAAa,aACJ,CACL,MAAO,WAAW,KACpB,GAEF,UAAY,SAAY,QAAQ,aAAa,OAAO,CACtD,EACA,MAAO,CACL,QAAS,MACT,WAAa,YAET,WAAW,QAAU,MACrB,WAAW,QAAU,IAAA,IACrB,CAAC,OAAO,MAAM,WAAW,KAAK,EAEvB,CACL,MAAO,SAAS,WAAW,KAAK,CAClC,EAEK,CAAC,EAEV,UAAY,SAAY,QAAQ,aAAa,OAAO,CACtD,EACA,OAAQ,CACN,WAAa,YAET,WAAW,SAAW,MACtB,WAAW,SAAW,IAAA,IACtB,CAAC,OAAO,MAAM,WAAW,MAAM,EAExB,CACL,OAAQ,SAAS,WAAW,MAAM,CACpC,EAEK,CAAC,EAEV,UAAY,SAAY,QAAQ,aAAa,QAAQ,CACvD,EACA,MAAO,CACL,WAAa,YACJ,WAAW,MACd,CACE,MAAO,WAAW,KACpB,EACA,CAAC,EAEP,cACS,IAEX,CACF,CACF,EAEA,WAAY,CACV,MAAO,CACL,CACE,IAAK,+BACL,SAAW,IAAyB,CAClC,IAAM,KAAO,CAAE,IAA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AAa,gBAAgB,IAAI,EAKtD,MAAQ,MAAM,KAAK,QAAQ,WAAW,YAAY,EAKlD,SAAW,cAAc,MAAM,OAAS,OAAS,GAAG,WACxD,MAAM,IACP,aAAa,IAAI,KAAK,EAAE,QAAQ,IAYjC,OANa,KAAK,KAAK,OAAO,CAC5B,IAAK,SACL,IAAK,MAAM,IACX,MAAO,MAAM,KACf,CAEO,CACT,EAEM,iBAAoB,OACjB,MAAM,KAAK,KAAK,EAAE,OAAQ,MAC/B,2CAA2C,KAAK,KAAK,IAAI,CAC3D,EAGI,kBAAoB,MACxB,OACA,KACA,WACG,CACH,IAAM,KAAO,MAAM,WAAW,IAAI,EAClC,GAAI,CAAC,KAAM,OAEX,IAAM,YACJ,WAAa,IAAA,GAET,OAAO,MAAM,GAAG,qBAAqB,IAAI,EADzC,OAAO,MAAM,GAAG,OAAO,SAAU,IAAI,EAG3C,OAAO,SAAS,WAAW,CAC7B,EAEA,MAAO,CACL,IAAI,OAAO,CACT,MAAO,CACL,aAAc,OAAQ,IAAM,CAC1B,IAAM,MAAQ,iBAAiB,EAAE,eAAe,KAAK,EACrD,GAAI,MAAM,SAAW,EAAG,MAAO,GAE/B,IAAK,IAAM,QAAQ,MACjB,kBAAkB,OAAQ,IAAI,EAGhC,MAAO,EACT,EACA,YAAa,OAAQ,EAAG,GAAI,QAAU,CACpC,GAAI,MAAO,MAAO,GAElB,IAAM,MAAQ,iBAAiB,EAAE,aAAa,KAAK,EACnD,GAAI,MAAM,SAAW,EAAG,MAAO,GAE/B,GAAM,CAAE,IAAK,UAAa,OAAO,YAAY,CAC3C,KAAM,EAAE,QACR,IAAK,EAAE,OACT,CAAC,EAED,IAAK,IAAM,QAAQ,MACjB,kBAAkB,OAAQ,KAAM,QAAQ,EAE1C,MAAO,EACT,CACF,CACF,CAAC,CACH,CACF,CACF,CAAC"}
1
+ {"version":3,"file":"image.js","sources":["../../src/image/image.ts"],"sourcesContent":["import { WorkspaceElement } from '@edifice.io/client';\nimport { ImageResizer } from '@edifice.io/utilities';\nimport { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport TiptapImage from '@tiptap/extension-image';\nimport { Plugin } from 'prosemirror-state';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\n uploadFile?: (file: File) => Promise<WorkspaceElement | null>;\n}\n\ninterface AttributesProps {\n width: number | string;\n height: number | string;\n size: string;\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n customImage: {\n setAttributes: (options: AttributesProps) => ReturnType;\n setNewImage: (options: {\n src: string;\n alt?: string;\n title?: string;\n }) => ReturnType;\n };\n }\n}\n\nexport const Image = TiptapImage.extend<CustomImageOptions>({\n name: 'custom-image',\n draggable: true,\n selectable: true,\n\n addOptions() {\n return {\n ...this.parent?.(),\n inline: true,\n content: 'inline*',\n sizes: ['small', 'medium', 'large'],\n HTMLAttributes: {\n class: 'custom-image',\n },\n uploadFile: () => {\n return Promise.resolve(null);\n },\n };\n },\n\n addAttributes() {\n return {\n ...this.parent?.(),\n size: {\n default: 'medium',\n rendered: false,\n },\n alt: {\n renderHTML: (attributes) => {\n return {\n alt: attributes.alt,\n };\n },\n parseHTML: (element) => element.getAttribute('alt'),\n },\n title: {\n renderHTML: (attributes) => {\n return {\n title: attributes.title,\n };\n },\n parseHTML: (element) => element.getAttribute('title'),\n },\n width: {\n default: '350',\n renderHTML: (attributes) => {\n if (\n attributes.width !== null &&\n attributes.width !== undefined &&\n !Number.isNaN(attributes.width)\n ) {\n return {\n width: parseInt(attributes.width),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('width'),\n },\n height: {\n renderHTML: (attributes) => {\n if (\n attributes.height !== null &&\n attributes.height !== undefined &&\n !Number.isNaN(attributes.height)\n ) {\n return {\n height: parseInt(attributes.height),\n };\n }\n return {};\n },\n parseHTML: (element) => element.getAttribute('height'),\n },\n style: {\n renderHTML: (attributes) => {\n return attributes.style\n ? {\n style: attributes.style,\n }\n : {};\n },\n parseHTML: () => {\n return null;\n },\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'img[src]:not([src^=\"data:\"])',\n getAttrs: (el: HTMLImageElement) => {\n const attr = { src: el.getAttribute('src') };\n // Check old content format and get the width from the parent element\n if (el.parentElement?.className.includes('image-container')) {\n if (el.parentElement.style?.width) {\n attr['width'] = el.parentElement.style.width;\n }\n }\n if (el.style?.width) {\n attr['width'] = el.style.width;\n }\n\n // Check old content smiley\n const oldSmileyList = [\n 'happy',\n 'proud',\n 'dreamy',\n 'love',\n 'tired',\n 'angry',\n 'worried',\n 'sick',\n 'joker',\n 'sad',\n ];\n if (\n oldSmileyList.filter((smiley) => attr.src.includes(smiley + '.png'))\n .length > 0\n ) {\n attr['style'] = {\n width: '1.5em',\n height: '1.5em',\n fontSize: '16px',\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\n }\n\n return attr;\n },\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'img',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n ];\n },\n\n addInputRules() {\n return [\n nodeInputRule({\n find: IMAGE_INPUT_REGEX,\n type: this.type,\n getAttributes: (match) => {\n const [, , alt, src, title] = match;\n\n return {\n src,\n alt,\n title,\n };\n },\n }),\n ];\n },\n\n addCommands() {\n return {\n setNewImage:\n (attrs) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n const node = this.type.create(attrs);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n setAttributes:\n (attributes) =>\n ({ tr, dispatch }) => {\n const { selection } = tr;\n\n const nodeAttrs = tr.doc.nodeAt(tr.selection.from);\n const options = {\n ...nodeAttrs.attrs,\n ...attributes,\n };\n const node = this.type.create(options);\n\n if (dispatch) {\n tr.replaceRangeWith(selection.from, selection.to, node);\n }\n\n return true;\n },\n };\n },\n\n addProseMirrorPlugins() {\n const uploadNode = async (file: File) => {\n /**\n * Resize the image\n */\n const resizedImage = await ImageResizer.resizeImageFile(file);\n\n /**\n * Upload the image\n */\n const image = await this.options.uploadFile(resizedImage);\n\n /**\n * Get the image url\n */\n const imageUrl = `/workspace/${image.public ? 'pub/' : ''}document/${\n image._id\n }?timestamp=${new Date().getTime()}`;\n\n /**\n * Create the image node\n */\n\n const node = this.type.create({\n src: imageUrl,\n alt: image.alt,\n title: image.title,\n });\n\n return node;\n };\n\n const getFilteredFiles = (files: FileList) => {\n return Array.from(files).filter((file) =>\n /image\\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type),\n );\n };\n\n const handleImageInsert = async (\n editor: any,\n file: File,\n position?: number,\n ) => {\n const node = await uploadNode(file);\n if (!node) return;\n\n const transaction =\n position !== undefined\n ? editor.state.tr.insert(position, node)\n : editor.state.tr.replaceSelectionWith(node);\n\n editor.dispatch(transaction);\n };\n\n return [\n new Plugin({\n props: {\n handlePaste: (editor, e) => {\n const files = getFilteredFiles(e.clipboardData?.files);\n if (files.length === 0) return false;\n\n for (const file of files) {\n handleImageInsert(editor, file);\n }\n\n return true;\n },\n handleDrop: (editor, e, _s, moved) => {\n if (moved) return false;\n\n const files = getFilteredFiles(e.dataTransfer.files);\n if (files.length === 0) return false;\n\n const { pos: position } = editor.posAtCoords({\n left: e.clientX,\n top: e.clientY,\n });\n\n for (const file of files) {\n handleImageInsert(editor, file, position);\n }\n return true;\n },\n },\n }),\n ];\n },\n});\n"],"names":[],"mappings":";;;;AAMO,MAAM,oBACX,4DA2BW,QAAQ,YAAY,OAA2B;AAAA,EAC1D,MAAM;AAAA,EACN,WAAW;AAAA,EACX,YAAY;AAAA,EAEZ,aAAa;;AACX,WAAO;AAAA,MACL,IAAG,UAAK,WAAL;AAAA,MACH,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,OAAO,CAAC,SAAS,UAAU,OAAO;AAAA,MACl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M,WAAW,EAAG,QAAO;AAE/B,uBAAW,QAAQ;AACjB,gCAAkB,QAAQ,IAAI;AAGhC,mBAAO;AAAA,UACT;AAAA,UACA,YAAY,CAAC,QAAQ,GAAG,IAAI,UAAU;AACpC,gBAAI,MAAO,QAAO;AAElB,kBAAM,QAAQ,iBAAiB,EAAE,aAAa,KAAK;AACnD,gBAAI,MAAM,WAAW,EAAG,QAAO;AAE/B,kBAAM,EAAE,KAAK,aAAa,OAAO,YAAY;AAAA,cAC3C,MAAM,EAAE;AAAA,cACR,KAAK,EAAE;AAAA,YAAA,CACR;AAED,uBAAW,QAAQ;AACjB,gCAAkB,QAAQ,MAAM,QAAQ;AAE1C,mBAAO;AAAA,UACT;AAAA,QAAA;AAAA,MACF,CACD;AAAA,IAAA;AAAA,EAEL;AACF,CAAC;"}
package/dist/index.cjs CHANGED
@@ -1 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require_abbr=require("./abbr/abbr.cjs"),require_alert=require("./alert/alert.cjs"),require_attachment=require("./attachment/attachment.cjs"),require_attachment_transformer=require("./attachment/attachment-transformer.cjs"),require_audio=require("./audio/audio.cjs"),require_conversation_history=require("./conversation-history/conversation-history.cjs"),require_conversation_history_body=require("./conversation-history-body/conversation-history-body.cjs"),require_font_size=require("./font-size/font-size.cjs"),require_heading=require("./heading/heading.cjs"),require_highlight=require("./highlight/highlight.cjs"),require_hyperlink=require("./hyperlink/hyperlink.cjs"),require_iframe=require("./iframe/iframe.cjs"),require_image=require("./image/image.cjs"),require_information_pane=require("./information-pane/information-pane.cjs"),require_line_height=require("./line-height/line-height.cjs"),require_linker=require("./linker/linker.cjs"),require_mathjax=require("./mathjax/mathjax.cjs"),require_paragraph=require("./paragraph/paragraph.cjs"),require_speech_recognition=require("./speech-recognition/speech-recognition.cjs"),require_speech_synthesis=require("./speech-synthesis/speech-synthesis.cjs"),require_table_cell=require("./table-cell/table-cell.cjs"),require_html_to_json=require("./transform/html-to-json/html-to-json.cjs"),require_json_to_html=require("./transform/json-to-html/json-to-html.cjs"),require_video=require("./video/video.cjs");exports.Abbr=require_abbr.Abbr,exports.Alert=require_alert.Alert,exports.Attachment=require_attachment.Attachment,exports.AttachmentTransformer=require_attachment_transformer.AttachmentTransformer,exports.Audio=require_audio.Audio,exports.ConversationHistory=require_conversation_history.ConversationHistory,exports.ConversationHistoryBody=require_conversation_history_body.ConversationHistoryBody,exports.CustomHeading=require_heading.CustomHeading,exports.CustomHighlight=require_highlight.CustomHighlight,exports.FontSize=require_font_size.FontSize,exports.Hyperlink=require_hyperlink.Hyperlink,exports.IMAGE_INPUT_REGEX=require_image.IMAGE_INPUT_REGEX,exports.Iframe=require_iframe.Iframe,exports.Image=require_image.Image,exports.InformationPane=require_information_pane.InformationPane,exports.LineHeight=require_line_height.LineHeight,exports.Linker=require_linker.Linker,exports.MathJax=require_mathjax.MathJax,exports.Paragraph=require_paragraph.Paragraph,exports.SpeechRecognition=require_speech_recognition.SpeechRecognition,exports.SpeechSynthesis=require_speech_synthesis.SpeechSynthesis,exports.TableCell=require_table_cell.TableCell,exports.Video=require_video.Video,exports.htmlToJson=require_html_to_json,exports.jsonToHtml=require_json_to_html;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const abbr=require("./abbr/abbr.cjs"),alert=require("./alert/alert.cjs"),attachment=require("./attachment/attachment.cjs"),attachmentTransformer=require("./attachment/attachment-transformer.cjs"),audio=require("./audio/audio.cjs"),conversationHistory=require("./conversation-history/conversation-history.cjs"),conversationHistoryBody=require("./conversation-history-body/conversation-history-body.cjs"),heading=require("./heading/heading.cjs"),highlight=require("./highlight/highlight.cjs"),fontSize=require("./font-size/font-size.cjs"),hyperlink=require("./hyperlink/hyperlink.cjs"),image=require("./image/image.cjs"),iframe=require("./iframe/iframe.cjs"),informationPane=require("./information-pane/information-pane.cjs"),lineHeight=require("./line-height/line-height.cjs"),linker=require("./linker/linker.cjs"),mathjax=require("./mathjax/mathjax.cjs"),paragraph=require("./paragraph/paragraph.cjs"),speechRecognition=require("./speech-recognition/speech-recognition.cjs"),speechSynthesis=require("./speech-synthesis/speech-synthesis.cjs"),tableCell=require("./table-cell/table-cell.cjs"),video=require("./video/video.cjs"),htmlToJson=require("./transform/html-to-json/html-to-json.cjs"),jsonToHtml=require("./transform/json-to-html/json-to-html.cjs");exports.Abbr=abbr.Abbr;exports.Alert=alert.Alert;exports.Attachment=attachment.Attachment;exports.AttachmentTransformer=attachmentTransformer.AttachmentTransformer;exports.Audio=audio.Audio;exports.ConversationHistory=conversationHistory.ConversationHistory;exports.ConversationHistoryBody=conversationHistoryBody.ConversationHistoryBody;exports.CustomHeading=heading.CustomHeading;exports.CustomHighlight=highlight.CustomHighlight;exports.FontSize=fontSize.FontSize;exports.Hyperlink=hyperlink.Hyperlink;exports.IMAGE_INPUT_REGEX=image.IMAGE_INPUT_REGEX;exports.Image=image.Image;exports.Iframe=iframe.Iframe;exports.InformationPane=informationPane.InformationPane;exports.LineHeight=lineHeight.LineHeight;exports.Linker=linker.Linker;exports.MathJax=mathjax.MathJax;exports.Paragraph=paragraph.Paragraph;exports.SpeechRecognition=speechRecognition.SpeechRecognition;exports.SpeechSynthesis=speechSynthesis.SpeechSynthesis;exports.TableCell=tableCell.TableCell;exports.Video=video.Video;exports.htmlToJson=htmlToJson;exports.jsonToHtml=jsonToHtml;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}