@edifice.io/tiptap-extensions 2.0.0-develop-rc.8 → 2.0.0-develop-rc.13

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 (100) hide show
  1. package/README.md +1 -1
  2. package/dist/abbr/abbr.cjs +32 -1
  3. package/dist/abbr/abbr.cjs.map +1 -1
  4. package/dist/abbr/abbr.d.ts +12 -12
  5. package/dist/abbr/abbr.js +20 -16
  6. package/dist/abbr/abbr.js.map +1 -1
  7. package/dist/alert/alert.cjs +32 -1
  8. package/dist/alert/alert.cjs.map +1 -1
  9. package/dist/alert/alert.js +22 -24
  10. package/dist/alert/alert.js.map +1 -1
  11. package/dist/attachment/attachment.cjs +73 -1
  12. package/dist/attachment/attachment.cjs.map +1 -1
  13. package/dist/attachment/attachment.d.ts +6 -6
  14. package/dist/attachment/attachment.js +58 -47
  15. package/dist/attachment/attachment.js.map +1 -1
  16. package/dist/audio/audio.cjs +53 -3
  17. package/dist/audio/audio.cjs.map +1 -1
  18. package/dist/audio/audio.d.ts +17 -13
  19. package/dist/audio/audio.js +33 -30
  20. package/dist/audio/audio.js.map +1 -1
  21. package/dist/font-size/font-size.cjs +48 -1
  22. package/dist/font-size/font-size.cjs.map +1 -1
  23. package/dist/font-size/font-size.d.ts +13 -13
  24. package/dist/font-size/font-size.js +32 -20
  25. package/dist/font-size/font-size.js.map +1 -1
  26. package/dist/heading/heading.cjs +61 -1
  27. package/dist/heading/heading.cjs.map +1 -1
  28. package/dist/heading/heading.d.ts +10 -12
  29. package/dist/heading/heading.js +45 -31
  30. package/dist/heading/heading.js.map +1 -1
  31. package/dist/highlight/highlight.cjs +25 -1
  32. package/dist/highlight/highlight.cjs.map +1 -1
  33. package/dist/highlight/highlight.d.ts +4 -1
  34. package/dist/highlight/highlight.js +15 -17
  35. package/dist/highlight/highlight.js.map +1 -1
  36. package/dist/hyperlink/hyperlink.cjs +47 -1
  37. package/dist/hyperlink/hyperlink.cjs.map +1 -1
  38. package/dist/hyperlink/hyperlink.d.ts +27 -24
  39. package/dist/hyperlink/hyperlink.js +26 -24
  40. package/dist/hyperlink/hyperlink.js.map +1 -1
  41. package/dist/iframe/iframe.cjs +69 -1
  42. package/dist/iframe/iframe.cjs.map +1 -1
  43. package/dist/iframe/iframe.d.ts +12 -14
  44. package/dist/iframe/iframe.js +50 -34
  45. package/dist/iframe/iframe.js.map +1 -1
  46. package/dist/image/custom-image.cjs +162 -1
  47. package/dist/image/custom-image.cjs.map +1 -1
  48. package/dist/image/custom-image.d.ts +19 -16
  49. package/dist/image/custom-image.js +179 -130
  50. package/dist/image/custom-image.js.map +1 -1
  51. package/dist/index.cjs +43 -1
  52. package/dist/index.js +41 -41
  53. package/dist/line-height/line-height.cjs +33 -1
  54. package/dist/line-height/line-height.cjs.map +1 -1
  55. package/dist/line-height/line-height.js +21 -18
  56. package/dist/line-height/line-height.js.map +1 -1
  57. package/dist/linker/linker.cjs +95 -1
  58. package/dist/linker/linker.cjs.map +1 -1
  59. package/dist/linker/linker.d.ts +17 -17
  60. package/dist/linker/linker.js +60 -52
  61. package/dist/linker/linker.js.map +1 -1
  62. package/dist/mathjax/mathjax.cjs +47 -1
  63. package/dist/mathjax/mathjax.cjs.map +1 -1
  64. package/dist/mathjax/mathjax.js +33 -23
  65. package/dist/mathjax/mathjax.js.map +1 -1
  66. package/dist/paragraph/paragraph.cjs +13 -1
  67. package/dist/paragraph/paragraph.cjs.map +1 -1
  68. package/dist/paragraph/paragraph.d.ts +4 -1
  69. package/dist/paragraph/paragraph.js +8 -10
  70. package/dist/paragraph/paragraph.js.map +1 -1
  71. package/dist/speech-recognition/speech-recognition.cjs +76 -1
  72. package/dist/speech-recognition/speech-recognition.cjs.map +1 -1
  73. package/dist/speech-recognition/speech-recognition.d.ts +12 -12
  74. package/dist/speech-recognition/speech-recognition.js +61 -45
  75. package/dist/speech-recognition/speech-recognition.js.map +1 -1
  76. package/dist/speech-synthesis/speech-synthesis.cjs +32 -1
  77. package/dist/speech-synthesis/speech-synthesis.cjs.map +1 -1
  78. package/dist/speech-synthesis/speech-synthesis.d.ts +9 -9
  79. package/dist/speech-synthesis/speech-synthesis.js +23 -14
  80. package/dist/speech-synthesis/speech-synthesis.js.map +1 -1
  81. package/dist/table-cell/table-cell.cjs +27 -1
  82. package/dist/table-cell/table-cell.cjs.map +1 -1
  83. package/dist/table-cell/table-cell.d.ts +4 -1
  84. package/dist/table-cell/table-cell.js +21 -16
  85. package/dist/table-cell/table-cell.js.map +1 -1
  86. package/dist/transform/html-to-json/html-to-json.cjs +4 -1
  87. package/dist/transform/html-to-json/html-to-json.cjs.map +1 -1
  88. package/dist/transform/html-to-json/html-to-json.d.ts +4 -1
  89. package/dist/transform/html-to-json/html-to-json.js +3 -5
  90. package/dist/transform/html-to-json/html-to-json.js.map +1 -1
  91. package/dist/transform/json-to-html/json-to-html.cjs +4 -1
  92. package/dist/transform/json-to-html/json-to-html.cjs.map +1 -1
  93. package/dist/transform/json-to-html/json-to-html.js +3 -5
  94. package/dist/transform/json-to-html/json-to-html.js.map +1 -1
  95. package/dist/video/video.cjs +118 -9
  96. package/dist/video/video.cjs.map +1 -1
  97. package/dist/video/video.d.ts +28 -19
  98. package/dist/video/video.js +121 -97
  99. package/dist/video/video.js.map +1 -1
  100. package/package.json +36 -47
@@ -1,2 +1,163 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@tiptap/core"),h=require("@tiptap/extension-image"),a=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,c=h.extend({name:"custom-image",draggable:!0,selectable:!0,addOptions(){var e;return{...(e=this.parent)==null?void 0:e.call(this),inline:!0,content:"inline*",sizes:["small","medium","large"],HTMLAttributes:{class:"custom-image"}}},addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),size:{default:"medium",rendered:!1},alt:{renderHTML:t=>({alt:t.alt}),parseHTML:t=>t.getAttribute("alt")},title:{renderHTML:t=>({title:t.title}),parseHTML:t=>t.getAttribute("title")},width:{default:"350",renderHTML:t=>t.width!==null&&t.width!==void 0&&!Number.isNaN(t.width)?{width:parseInt(t.width)}:{},parseHTML:t=>t.getAttribute("width")},height:{renderHTML:t=>t.height!==null&&t.height!==void 0&&!Number.isNaN(t.height)?{height:parseInt(t.height)}:{},parseHTML:t=>t.getAttribute("height")},style:{renderHTML:t=>t.style?{style:t.style}:{},parseHTML:t=>{const r=t.getAttribute("style");return r&&typeof r=="string"&&r.length>0?{}:null}}}},parseHTML(){return[{tag:'img[src]:not([src^="data:"])',getAttrs:e=>{var n,i,s,l,d;const t={src:e.getAttribute("src")};return(n=e.parentElement)!=null&&n.className.includes("image-container")&&(i=e.parentElement.style)!=null&&i.width&&(t.width=e.parentElement.style.width),(s=e.style)!=null&&s.width&&(t.width=e.style.width),["happy","proud","dreamy","love","tired","angry","worried","sick","joker","sad"].filter(u=>t.src.includes(u+".png")).length>0&&(t.style={width:"1.5em",height:"1.5em",fontSize:(d=(l=e.parentElement)==null?void 0:l.style)==null?void 0:d.fontSize},t.width="null",t.height="null"),t}}]},renderHTML({HTMLAttributes:e}){return["img",o.mergeAttributes(this.options.HTMLAttributes,e)]},addInputRules(){return[o.nodeInputRule({find:a,type:this.type,getAttributes:e=>{const[,,t,r,n]=e;return{src:r,alt:t,title:n}}})]},addCommands(){return{setNewImage:e=>({tr:t,dispatch:r})=>{const{selection:n}=t,i=this.type.create(e);return r&&t.replaceRangeWith(n.from,n.to,i),!0},setAttributes:e=>({tr:t,dispatch:r})=>{const{selection:n}=t,s={...t.doc.nodeAt(t.selection.from).attrs,...e},l=this.type.create(s);return r&&t.replaceRangeWith(n.from,n.to,l),!0}}}});exports.CustomImage=c;exports.IMAGE_INPUT_REGEX=a;
1
+ 'use strict';
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
+ const core = require('@tiptap/core'),
4
+ Image = require('@tiptap/extension-image'),
5
+ IMAGE_INPUT_REGEX =
6
+ /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,
7
+ CustomImage = Image.extend({
8
+ name: 'custom-image',
9
+ draggable: !0,
10
+ selectable: !0,
11
+ addOptions() {
12
+ var _a;
13
+ return {
14
+ ...((_a = this.parent) == null ? void 0 : _a.call(this)),
15
+ inline: !0,
16
+ content: 'inline*',
17
+ sizes: ['small', 'medium', 'large'],
18
+ HTMLAttributes: { class: 'custom-image' },
19
+ };
20
+ },
21
+ addAttributes() {
22
+ var _a;
23
+ return {
24
+ ...((_a = this.parent) == null ? void 0 : _a.call(this)),
25
+ size: { default: 'medium', rendered: !1 },
26
+ alt: {
27
+ renderHTML: (attributes) => ({ alt: attributes.alt }),
28
+ parseHTML: (element) => element.getAttribute('alt'),
29
+ },
30
+ title: {
31
+ renderHTML: (attributes) => ({ title: attributes.title }),
32
+ parseHTML: (element) => element.getAttribute('title'),
33
+ },
34
+ width: {
35
+ default: '350',
36
+ renderHTML: (attributes) =>
37
+ attributes.width !== null &&
38
+ attributes.width !== void 0 &&
39
+ !Number.isNaN(attributes.width)
40
+ ? { width: parseInt(attributes.width) }
41
+ : {},
42
+ parseHTML: (element) => element.getAttribute('width'),
43
+ },
44
+ height: {
45
+ renderHTML: (attributes) =>
46
+ attributes.height !== null &&
47
+ attributes.height !== void 0 &&
48
+ !Number.isNaN(attributes.height)
49
+ ? { height: parseInt(attributes.height) }
50
+ : {},
51
+ parseHTML: (element) => element.getAttribute('height'),
52
+ },
53
+ style: {
54
+ renderHTML: (attributes) =>
55
+ attributes.style ? { style: attributes.style } : {},
56
+ parseHTML: (element) => {
57
+ const style = element.getAttribute('style');
58
+ return style && typeof style == 'string' && style.length > 0
59
+ ? {}
60
+ : null;
61
+ },
62
+ },
63
+ };
64
+ },
65
+ parseHTML() {
66
+ return [
67
+ {
68
+ tag: 'img[src]:not([src^="data:"])',
69
+ getAttrs: (el) => {
70
+ var _a, _b, _c, _d, _e;
71
+ const attr = { src: el.getAttribute('src') };
72
+ return (
73
+ (_a = el.parentElement) != null &&
74
+ _a.className.includes('image-container') &&
75
+ (_b = el.parentElement.style) != null &&
76
+ _b.width &&
77
+ (attr.width = el.parentElement.style.width),
78
+ (_c = el.style) != null &&
79
+ _c.width &&
80
+ (attr.width = el.style.width),
81
+ [
82
+ 'happy',
83
+ 'proud',
84
+ 'dreamy',
85
+ 'love',
86
+ 'tired',
87
+ 'angry',
88
+ 'worried',
89
+ 'sick',
90
+ 'joker',
91
+ 'sad',
92
+ ].filter((smiley) => attr.src.includes(smiley + '.png')).length >
93
+ 0 &&
94
+ ((attr.style = {
95
+ width: '1.5em',
96
+ height: '1.5em',
97
+ fontSize:
98
+ (_e =
99
+ (_d = el.parentElement) == null ? void 0 : _d.style) ==
100
+ null
101
+ ? void 0
102
+ : _e.fontSize,
103
+ }),
104
+ (attr.width = 'null'),
105
+ (attr.height = 'null')),
106
+ attr
107
+ );
108
+ },
109
+ },
110
+ ];
111
+ },
112
+ renderHTML({ HTMLAttributes }) {
113
+ return [
114
+ 'img',
115
+ core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
116
+ ];
117
+ },
118
+ addInputRules() {
119
+ return [
120
+ core.nodeInputRule({
121
+ find: IMAGE_INPUT_REGEX,
122
+ type: this.type,
123
+ getAttributes: (match) => {
124
+ const [, , alt, src, title] = match;
125
+ return { src, alt, title };
126
+ },
127
+ }),
128
+ ];
129
+ },
130
+ addCommands() {
131
+ return {
132
+ setNewImage:
133
+ (attrs) =>
134
+ ({ tr, dispatch }) => {
135
+ const { selection } = tr,
136
+ node = this.type.create(attrs);
137
+ return (
138
+ dispatch &&
139
+ tr.replaceRangeWith(selection.from, selection.to, node),
140
+ !0
141
+ );
142
+ },
143
+ setAttributes:
144
+ (attributes) =>
145
+ ({ tr, dispatch }) => {
146
+ const { selection } = tr,
147
+ options = {
148
+ ...tr.doc.nodeAt(tr.selection.from).attrs,
149
+ ...attributes,
150
+ },
151
+ node = this.type.create(options);
152
+ return (
153
+ dispatch &&
154
+ tr.replaceRangeWith(selection.from, selection.to, node),
155
+ !0
156
+ );
157
+ },
158
+ };
159
+ },
160
+ });
161
+ exports.CustomImage = CustomImage;
162
+ exports.IMAGE_INPUT_REGEX = IMAGE_INPUT_REGEX;
2
163
  //# sourceMappingURL=custom-image.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-image.cjs","sources":["../../src/image/custom-image.ts"],"sourcesContent":["import { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport Image from '@tiptap/extension-image';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\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 CustomImage = Image.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 };\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: (element) => {\n const style = element.getAttribute('style');\n return style && typeof style === 'string' && style.length > 0\n ? {}\n : 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: el.parentElement?.style?.fontSize,\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\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"],"names":["IMAGE_INPUT_REGEX","CustomImage","Image","_a","attributes","element","style","el","attr","_b","_c","smiley","_e","_d","HTMLAttributes","mergeAttributes","nodeInputRule","match","alt","src","title","attrs","tr","dispatch","selection","node","options"],"mappings":"qJAGaA,EACX,2DA0BWC,EAAcC,EAAM,OAA2B,CAC1D,KAAM,eACN,UAAW,GACX,WAAY,GAEZ,YAAa,OACJ,MAAA,CACL,IAAGC,EAAA,KAAK,SAAL,YAAAA,EAAA,WACH,OAAQ,GACR,QAAS,UACT,MAAO,CAAC,QAAS,SAAU,OAAO,EAClC,eAAgB,CACd,MAAO,cACT,CAAA,CAEJ,EAEA,eAAgB,OACP,MAAA,CACL,IAAGA,EAAA,KAAK,SAAL,YAAAA,EAAA,WACH,KAAM,CACJ,QAAS,SACT,SAAU,EACZ,EACA,IAAK,CACH,WAAaC,IACJ,CACL,IAAKA,EAAW,GAAA,GAGpB,UAAYC,GAAYA,EAAQ,aAAa,KAAK,CACpD,EACA,MAAO,CACL,WAAaD,IACJ,CACL,MAAOA,EAAW,KAAA,GAGtB,UAAYC,GAAYA,EAAQ,aAAa,OAAO,CACtD,EACA,MAAO,CACL,QAAS,MACT,WAAaD,GAETA,EAAW,QAAU,MACrBA,EAAW,QAAU,QACrB,CAAC,OAAO,MAAMA,EAAW,KAAK,EAEvB,CACL,MAAO,SAASA,EAAW,KAAK,CAAA,EAG7B,GAET,UAAYC,GAAYA,EAAQ,aAAa,OAAO,CACtD,EACA,OAAQ,CACN,WAAaD,GAETA,EAAW,SAAW,MACtBA,EAAW,SAAW,QACtB,CAAC,OAAO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KC,CAAK,EAAIH,EAEvB,MAAA,CACL,IAAAE,EACA,IAAAD,EACA,MAAAE,CAAA,CAEJ,CAAA,CACD,CAAA,CAEL,EAEA,aAAc,CACL,MAAA,CACL,YACGC,GACD,CAAC,CAAE,GAAAC,EAAI,SAAAC,KAAe,CACd,KAAA,CAAE,UAAAC,CAAc,EAAAF,EAChBG,EAAO,KAAK,KAAK,OAAOJ,CAAK,EAEnC,OAAIE,GACFD,EAAG,iBAAiBE,EAAU,KAAMA,EAAU,GAAIC,CAAI,EAGjD,EACT,EACF,cACGrB,GACD,CAAC,CAAE,GAAAkB,EAAI,SAAAC,KAAe,CACd,KAAA,CAAE,UAAAC,CAAc,EAAAF,EAGhBI,EAAU,CACd,GAFgBJ,EAAG,IAAI,OAAOA,EAAG,UAAU,IAAI,EAElC,MACb,GAAGlB,CAAA,EAECqB,EAAO,KAAK,KAAK,OAAOC,CAAO,EAErC,OAAIH,GACFD,EAAG,iBAAiBE,EAAU,KAAMA,EAAU,GAAIC,CAAI,EAGjD,EACT,CAAA,CAEN,CACF,CAAC"}
1
+ {"version":3,"file":"custom-image.cjs","sources":["../../src/image/custom-image.ts"],"sourcesContent":["import { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport Image from '@tiptap/extension-image';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\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 CustomImage = Image.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 };\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: (element) => {\n const style = element.getAttribute('style');\n return style && typeof style === 'string' && style.length > 0\n ? {}\n : 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: el.parentElement?.style?.fontSize,\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\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"],"names":["mergeAttributes","nodeInputRule"],"mappings":"4JAGa,kBACX,2DA0BW,YAAc,MAAM,OAA2B,CAC1D,KAAM,eACN,UAAW,GACX,WAAY,GAEZ,YAAa,QACJ,MAAA,CACL,IAAG,QAAK,SAAL,0BACH,OAAQ,GACR,QAAS,UACT,MAAO,CAAC,QAAS,SAAU,OAAO,EAClC,eAAgB,CACd,MAAO,cACT,CAAA,CAEJ,EAEA,eAAgB,QACP,MAAA,CACL,IAAG,QAAK,SAAL,0BACH,KAAM,CACJ,QAAS,SACT,SAAU,EACZ,EACA,IAAK,CACH,WAAa,aACJ,CACL,IAAK,WAAW,GAAA,GAGpB,UAAY,SAAY,QAAQ,aAAa,KAAK,CACpD,EACA,MAAO,CACL,WAAa,aACJ,CACL,MAAO,WAAW,KAAA,GAGtB,UAAY,SAAY,QAAQ,aAAa,OAAO,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QAAQ,eAAgB,cAAc,CAAA,CAE/D,EAEA,eAAgB,CACP,MAAA,CACLC,mBAAc,CACZ,KAAM,kBACN,KAAM,KAAK,KACX,cAAgB,OAAU,CACxB,KAAM,CAAK,CAAA,CAAA,IAAK,IAAK,KAAK,EAAI,MAEvB,MAAA,CACL,IACA,IACA,KAAA,CAEJ,CAAA,CACD,CAAA,CAEL,EAEA,aAAc,CACL,MAAA,CACL,YACG,OACD,CAAC,CAAE,GAAI,YAAe,CACd,KAAA,CAAE,SAAc,EAAA,GAChB,KAAO,KAAK,KAAK,OAAO,KAAK,EAEnC,OAAI,UACF,GAAG,iBAAiB,UAAU,KAAM,UAAU,GAAI,IAAI,EAGjD,EACT,EACF,cACG,YACD,CAAC,CAAE,GAAI,YAAe,CACd,KAAA,CAAE,SAAc,EAAA,GAGhB,QAAU,CACd,GAFgB,GAAG,IAAI,OAAO,GAAG,UAAU,IAAI,EAElC,MACb,GAAG,UAAA,EAEC,KAAO,KAAK,KAAK,OAAO,OAAO,EAErC,OAAI,UACF,GAAG,iBAAiB,UAAU,KAAM,UAAU,GAAI,IAAI,EAGjD,EACT,CAAA,CAEN,CACF,CAAC"}
@@ -1,24 +1,27 @@
1
1
  export declare const IMAGE_INPUT_REGEX: RegExp;
2
2
  export interface CustomImageOptions {
3
- HTMLAttributes: Record<string, string>;
4
- sizes: string[];
3
+ HTMLAttributes: Record<string, string>;
4
+ sizes: string[];
5
5
  }
6
6
  interface AttributesProps {
7
- width: number | string;
8
- height: number | string;
9
- size: string;
7
+ width: number | string;
8
+ height: number | string;
9
+ size: string;
10
10
  }
11
11
  declare module '@tiptap/core' {
12
- interface Commands<ReturnType> {
13
- customImage: {
14
- setAttributes: (options: AttributesProps) => ReturnType;
15
- setNewImage: (options: {
16
- src: string;
17
- alt?: string;
18
- title?: string;
19
- }) => ReturnType;
20
- };
21
- }
12
+ interface Commands<ReturnType> {
13
+ customImage: {
14
+ setAttributes: (options: AttributesProps) => ReturnType;
15
+ setNewImage: (options: {
16
+ src: string;
17
+ alt?: string;
18
+ title?: string;
19
+ }) => ReturnType;
20
+ };
21
+ }
22
22
  }
23
- export declare const CustomImage: import('@tiptap/core').Node<CustomImageOptions, any>;
23
+ export declare const CustomImage: import('@tiptap/core').Node<
24
+ CustomImageOptions,
25
+ any
26
+ >;
24
27
  export {};
@@ -1,132 +1,181 @@
1
- import { mergeAttributes as a, nodeInputRule as u } from "@tiptap/core";
2
- import h from "@tiptap/extension-image";
3
- const m = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, p = h.extend({
4
- name: "custom-image",
5
- draggable: !0,
6
- selectable: !0,
7
- addOptions() {
8
- var e;
9
- return {
10
- ...(e = this.parent) == null ? void 0 : e.call(this),
11
- inline: !0,
12
- content: "inline*",
13
- sizes: ["small", "medium", "large"],
14
- HTMLAttributes: {
15
- class: "custom-image"
16
- }
17
- };
18
- },
19
- addAttributes() {
20
- var e;
21
- return {
22
- ...(e = this.parent) == null ? void 0 : e.call(this),
23
- size: {
24
- default: "medium",
25
- rendered: !1
26
- },
27
- alt: {
28
- renderHTML: (t) => ({
29
- alt: t.alt
1
+ import { mergeAttributes, nodeInputRule } from '@tiptap/core';
2
+ import Image from '@tiptap/extension-image';
3
+ const IMAGE_INPUT_REGEX =
4
+ /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,
5
+ CustomImage = Image.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
+ };
20
+ },
21
+ addAttributes() {
22
+ var _a;
23
+ return {
24
+ ...((_a = this.parent) == null ? void 0 : _a.call(this)),
25
+ size: {
26
+ default: 'medium',
27
+ rendered: !1,
28
+ },
29
+ alt: {
30
+ renderHTML: (attributes) => ({
31
+ alt: attributes.alt,
32
+ }),
33
+ parseHTML: (element) => element.getAttribute('alt'),
34
+ },
35
+ title: {
36
+ renderHTML: (attributes) => ({
37
+ title: attributes.title,
38
+ }),
39
+ parseHTML: (element) => element.getAttribute('title'),
40
+ },
41
+ width: {
42
+ default: '350',
43
+ renderHTML: (attributes) =>
44
+ attributes.width !== null &&
45
+ attributes.width !== void 0 &&
46
+ !Number.isNaN(attributes.width)
47
+ ? {
48
+ width: parseInt(attributes.width),
49
+ }
50
+ : {},
51
+ parseHTML: (element) => element.getAttribute('width'),
52
+ },
53
+ height: {
54
+ renderHTML: (attributes) =>
55
+ attributes.height !== null &&
56
+ attributes.height !== void 0 &&
57
+ !Number.isNaN(attributes.height)
58
+ ? {
59
+ height: parseInt(attributes.height),
60
+ }
61
+ : {},
62
+ parseHTML: (element) => element.getAttribute('height'),
63
+ },
64
+ style: {
65
+ renderHTML: (attributes) =>
66
+ attributes.style
67
+ ? {
68
+ style: attributes.style,
69
+ }
70
+ : {},
71
+ parseHTML: (element) => {
72
+ const style = element.getAttribute('style');
73
+ return style && typeof style == 'string' && style.length > 0
74
+ ? {}
75
+ : null;
76
+ },
77
+ },
78
+ };
79
+ },
80
+ parseHTML() {
81
+ return [
82
+ {
83
+ tag: 'img[src]:not([src^="data:"])',
84
+ getAttrs: (el) => {
85
+ var _a, _b, _c, _d, _e;
86
+ const attr = { src: el.getAttribute('src') };
87
+ return (
88
+ (_a = el.parentElement) != null &&
89
+ _a.className.includes('image-container') &&
90
+ (_b = el.parentElement.style) != null &&
91
+ _b.width &&
92
+ (attr.width = el.parentElement.style.width),
93
+ (_c = el.style) != null &&
94
+ _c.width &&
95
+ (attr.width = el.style.width),
96
+ [
97
+ 'happy',
98
+ 'proud',
99
+ 'dreamy',
100
+ 'love',
101
+ 'tired',
102
+ 'angry',
103
+ 'worried',
104
+ 'sick',
105
+ 'joker',
106
+ 'sad',
107
+ ].filter((smiley) => attr.src.includes(smiley + '.png')).length >
108
+ 0 &&
109
+ ((attr.style = {
110
+ width: '1.5em',
111
+ height: '1.5em',
112
+ fontSize:
113
+ (_e =
114
+ (_d = el.parentElement) == null ? void 0 : _d.style) ==
115
+ null
116
+ ? void 0
117
+ : _e.fontSize,
118
+ }),
119
+ (attr.width = 'null'),
120
+ (attr.height = 'null')),
121
+ attr
122
+ );
123
+ },
124
+ },
125
+ ];
126
+ },
127
+ renderHTML({ HTMLAttributes }) {
128
+ return [
129
+ 'img',
130
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
131
+ ];
132
+ },
133
+ addInputRules() {
134
+ return [
135
+ nodeInputRule({
136
+ find: IMAGE_INPUT_REGEX,
137
+ type: this.type,
138
+ getAttributes: (match) => {
139
+ const [, , alt, src, title] = match;
140
+ return {
141
+ src,
142
+ alt,
143
+ title,
144
+ };
145
+ },
30
146
  }),
31
- parseHTML: (t) => t.getAttribute("alt")
32
- },
33
- title: {
34
- renderHTML: (t) => ({
35
- title: t.title
36
- }),
37
- parseHTML: (t) => t.getAttribute("title")
38
- },
39
- width: {
40
- default: "350",
41
- renderHTML: (t) => t.width !== null && t.width !== void 0 && !Number.isNaN(t.width) ? {
42
- width: parseInt(t.width)
43
- } : {},
44
- parseHTML: (t) => t.getAttribute("width")
45
- },
46
- height: {
47
- renderHTML: (t) => t.height !== null && t.height !== void 0 && !Number.isNaN(t.height) ? {
48
- height: parseInt(t.height)
49
- } : {},
50
- parseHTML: (t) => t.getAttribute("height")
51
- },
52
- style: {
53
- renderHTML: (t) => t.style ? {
54
- style: t.style
55
- } : {},
56
- parseHTML: (t) => {
57
- const r = t.getAttribute("style");
58
- return r && typeof r == "string" && r.length > 0 ? {} : null;
59
- }
60
- }
61
- };
62
- },
63
- parseHTML() {
64
- return [
65
- {
66
- tag: 'img[src]:not([src^="data:"])',
67
- getAttrs: (e) => {
68
- var n, i, s, l, d;
69
- const t = { src: e.getAttribute("src") };
70
- return (n = e.parentElement) != null && n.className.includes("image-container") && (i = e.parentElement.style) != null && i.width && (t.width = e.parentElement.style.width), (s = e.style) != null && s.width && (t.width = e.style.width), [
71
- "happy",
72
- "proud",
73
- "dreamy",
74
- "love",
75
- "tired",
76
- "angry",
77
- "worried",
78
- "sick",
79
- "joker",
80
- "sad"
81
- ].filter((o) => t.src.includes(o + ".png")).length > 0 && (t.style = {
82
- width: "1.5em",
83
- height: "1.5em",
84
- fontSize: (d = (l = e.parentElement) == null ? void 0 : l.style) == null ? void 0 : d.fontSize
85
- }, t.width = "null", t.height = "null"), t;
86
- }
87
- }
88
- ];
89
- },
90
- renderHTML({ HTMLAttributes: e }) {
91
- return [
92
- "img",
93
- a(this.options.HTMLAttributes, e)
94
- ];
95
- },
96
- addInputRules() {
97
- return [
98
- u({
99
- find: m,
100
- type: this.type,
101
- getAttributes: (e) => {
102
- const [, , t, r, n] = e;
103
- return {
104
- src: r,
105
- alt: t,
106
- title: n
107
- };
108
- }
109
- })
110
- ];
111
- },
112
- addCommands() {
113
- return {
114
- setNewImage: (e) => ({ tr: t, dispatch: r }) => {
115
- const { selection: n } = t, i = this.type.create(e);
116
- return r && t.replaceRangeWith(n.from, n.to, i), !0;
117
- },
118
- setAttributes: (e) => ({ tr: t, dispatch: r }) => {
119
- const { selection: n } = t, s = {
120
- ...t.doc.nodeAt(t.selection.from).attrs,
121
- ...e
122
- }, l = this.type.create(s);
123
- return r && t.replaceRangeWith(n.from, n.to, l), !0;
124
- }
125
- };
126
- }
127
- });
128
- export {
129
- p as CustomImage,
130
- m as IMAGE_INPUT_REGEX
131
- };
147
+ ];
148
+ },
149
+ addCommands() {
150
+ return {
151
+ setNewImage:
152
+ (attrs) =>
153
+ ({ tr, dispatch }) => {
154
+ const { selection } = tr,
155
+ node = this.type.create(attrs);
156
+ return (
157
+ dispatch &&
158
+ tr.replaceRangeWith(selection.from, selection.to, node),
159
+ !0
160
+ );
161
+ },
162
+ setAttributes:
163
+ (attributes) =>
164
+ ({ tr, dispatch }) => {
165
+ const { selection } = tr,
166
+ options = {
167
+ ...tr.doc.nodeAt(tr.selection.from).attrs,
168
+ ...attributes,
169
+ },
170
+ node = this.type.create(options);
171
+ return (
172
+ dispatch &&
173
+ tr.replaceRangeWith(selection.from, selection.to, node),
174
+ !0
175
+ );
176
+ },
177
+ };
178
+ },
179
+ });
180
+ export { CustomImage, IMAGE_INPUT_REGEX };
132
181
  //# sourceMappingURL=custom-image.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-image.js","sources":["../../src/image/custom-image.ts"],"sourcesContent":["import { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport Image from '@tiptap/extension-image';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\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 CustomImage = Image.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 };\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: (element) => {\n const style = element.getAttribute('style');\n return style && typeof style === 'string' && style.length > 0\n ? {}\n : 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: el.parentElement?.style?.fontSize,\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\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"],"names":["IMAGE_INPUT_REGEX","CustomImage","Image","_a","attributes","element","style","el","attr","_b","_c","smiley","_e","_d","HTMLAttributes","mergeAttributes","nodeInputRule","match","alt","src","title","attrs","tr","dispatch","selection","node","options"],"mappings":";;AAGO,MAAMA,IACX,4DA0BWC,IAAcC,EAAM,OAA2B;AAAA,EAC1D,MAAM;AAAA,EACN,WAAW;AAAA,EACX,YAAY;AAAA,EAEZ,aAAa;;AACJ,WAAA;AAAA,MACL,IAAGC,IAAA,KAAK,WAAL,gBAAAA,EAAA;AAAA,MACH,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,OAAO,CAAC,SAAS,UAAU,OAAO;AAAA,MAClC,gBAAgB;AAAA,QACd,OAAO;AAAA,MACT;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEA,gBAAgB;;AACP,WAAA;AAAA,MACL,IAAGA,IAAA,KAAK,WAAL,gBAAAA,EAAA;AAAA,MACH,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,UAAU;AAAA,MACZ;AAAA,MACA,KAAK;AAAA,QACH,YAAY,CAACC,OACJ;AAAA,UACL,KAAKA,EAAW;AAAA,QAAA;AAAA,QAGpB,WAAW,CAACC,MAAYA,EAAQ,aAAa,KAAK;AAAA,MACpD;AAAA,MACA,OAAO;AAAA,QACL,YAAY,CAACD,OACJ;AAAA,UACL,OAAOA,EAAW;AAAA,QAAA;AAAA,QAGtB,WAAW,CAACC,MAAYA,EAAQ,aAAa,OAAO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AAI,EAElC;AAAA,UACb,GAAGlB;AAAA,QAAA,GAECqB,IAAO,KAAK,KAAK,OAAOC,CAAO;AAErC,eAAIH,KACFD,EAAG,iBAAiBE,EAAU,MAAMA,EAAU,IAAIC,CAAI,GAGjD;AAAA,MACT;AAAA,IAAA;AAAA,EAEN;AACF,CAAC;"}
1
+ {"version":3,"file":"custom-image.js","sources":["../../src/image/custom-image.ts"],"sourcesContent":["import { mergeAttributes, nodeInputRule } from '@tiptap/core';\nimport Image from '@tiptap/extension-image';\n\nexport const IMAGE_INPUT_REGEX =\n /(?:^|\\s)(!\\[(.+|:?)]\\((\\S+)(?:(?:\\s+)[\"'](\\S+)[\"'])?\\))$/;\n\nexport interface CustomImageOptions {\n HTMLAttributes: Record<string, string>;\n sizes: string[];\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 CustomImage = Image.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 };\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: (element) => {\n const style = element.getAttribute('style');\n return style && typeof style === 'string' && style.length > 0\n ? {}\n : 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: el.parentElement?.style?.fontSize,\n };\n attr['width'] = 'null';\n attr['height'] = 'null';\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"],"names":[],"mappings":";;AAGO,MAAM,oBACX,4DA0BW,cAAc,MAAM,OAA2B;AAAA,EAC1D,MAAM;AAAA,EACN,WAAW;AAAA,EACX,YAAY;AAAA,EAEZ,aAAa;;AACJ,WAAA;AAAA,MACL,IAAG,UAAK,WAAL;AAAA,MACH,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,OAAO,CAAC,SAAS,UAAU,OAAO;AAAA,MAClC,gBAAgB;AAAA,QACd,OAAO;AAAA,MACT;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEA,gBAAgB;;AACP,WAAA;AAAA,MACL,IAAG,UAAK,WAAL;AAAA,MACH,MAAM;AAAA,QACJ,SAAS;AAAA,QACT,UAAU;AAAA,MACZ;AAAA,MACA,KAAK;AAAA,QACH,YAAY,CAAC,gBACJ;AAAA,UACL,KAAK,WAAW;AAAA,QAAA;AAAA,QAGpB,WAAW,CAAC,YAAY,QAAQ,aAAa,KAAK;AAAA,MACpD;AAAA,MACA,OAAO;AAAA,QACL,YAAY,CAAC,gBACJ;AAAA,UACL,OAAO,WAAW;AAAA,QAAA;AAAA,QAGtB,WAAW,CAAC,YAAY,QAAQ,aAAa,OAAO;AAAA,MACtD;AAAA,MACA,OAAO;AAAA,QACL,SAAS;AAAA,QACT,YAAY,CAAC,eAET,WAAW,UAAU,QACrB,WAAW,UAAU,UACrB,CAAC,OAAO,MAAM,WAAW,KAAK,IAEvB;AAAA,UACL,OAAO,SAAS,WAAW,KAAK;AAAA,QAAA,IAG7B;QAET,WAAW,CAAC,YAAY,QAAQ,aAAa,OAAO;AAAA,MACtD;AAAA,MACA,Q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