@edifice.io/tiptap-extensions 1.5.16-develop-rc.3 → 1.7.4-develop-pedago.20241211162226

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 (109) hide show
  1. package/README.md +8 -5
  2. package/dist/abbr/abbr.cjs +1 -32
  3. package/dist/abbr/abbr.cjs.map +1 -1
  4. package/dist/abbr/abbr.d.ts +12 -12
  5. package/dist/abbr/abbr.js +13 -17
  6. package/dist/abbr/abbr.js.map +1 -1
  7. package/dist/alert/alert.cjs +1 -32
  8. package/dist/alert/alert.cjs.map +1 -1
  9. package/dist/alert/alert.js +22 -20
  10. package/dist/alert/alert.js.map +1 -1
  11. package/dist/attachment/attachment-transformer.cjs +2 -0
  12. package/dist/attachment/attachment-transformer.cjs.map +1 -0
  13. package/dist/attachment/attachment-transformer.d.ts +12 -0
  14. package/dist/attachment/attachment-transformer.js +76 -0
  15. package/dist/attachment/attachment-transformer.js.map +1 -0
  16. package/dist/attachment/attachment.cjs +1 -73
  17. package/dist/attachment/attachment.cjs.map +1 -1
  18. package/dist/attachment/attachment.d.ts +6 -6
  19. package/dist/attachment/attachment.js +29 -40
  20. package/dist/attachment/attachment.js.map +1 -1
  21. package/dist/attachment/index.d.ts +1 -0
  22. package/dist/audio/audio.cjs +2 -52
  23. package/dist/audio/audio.cjs.map +1 -1
  24. package/dist/audio/audio.d.ts +13 -17
  25. package/dist/audio/audio.js +25 -28
  26. package/dist/audio/audio.js.map +1 -1
  27. package/dist/font-size/font-size.cjs +1 -48
  28. package/dist/font-size/font-size.cjs.map +1 -1
  29. package/dist/font-size/font-size.d.ts +13 -13
  30. package/dist/font-size/font-size.js +17 -29
  31. package/dist/font-size/font-size.js.map +1 -1
  32. package/dist/heading/heading.cjs +1 -61
  33. package/dist/heading/heading.cjs.map +1 -1
  34. package/dist/heading/heading.d.ts +12 -10
  35. package/dist/heading/heading.js +25 -39
  36. package/dist/heading/heading.js.map +1 -1
  37. package/dist/highlight/highlight.cjs +1 -25
  38. package/dist/highlight/highlight.cjs.map +1 -1
  39. package/dist/highlight/highlight.d.ts +1 -4
  40. package/dist/highlight/highlight.js +13 -11
  41. package/dist/highlight/highlight.js.map +1 -1
  42. package/dist/hyperlink/hyperlink.cjs +1 -47
  43. package/dist/hyperlink/hyperlink.cjs.map +1 -1
  44. package/dist/hyperlink/hyperlink.d.ts +24 -27
  45. package/dist/hyperlink/hyperlink.js +19 -21
  46. package/dist/hyperlink/hyperlink.js.map +1 -1
  47. package/dist/iframe/iframe.cjs +1 -69
  48. package/dist/iframe/iframe.cjs.map +1 -1
  49. package/dist/iframe/iframe.d.ts +14 -12
  50. package/dist/iframe/iframe.js +32 -48
  51. package/dist/iframe/iframe.js.map +1 -1
  52. package/dist/image/image.cjs +2 -0
  53. package/dist/image/image.cjs.map +1 -0
  54. package/dist/image/image.d.ts +26 -0
  55. package/dist/image/image.js +178 -0
  56. package/dist/image/image.js.map +1 -0
  57. package/dist/image/index.d.ts +3 -3
  58. package/dist/index.cjs +1 -43
  59. package/dist/index.js +24 -22
  60. package/dist/index.js.map +1 -1
  61. package/dist/line-height/line-height.cjs +1 -33
  62. package/dist/line-height/line-height.cjs.map +1 -1
  63. package/dist/line-height/line-height.js +15 -18
  64. package/dist/line-height/line-height.js.map +1 -1
  65. package/dist/linker/linker.cjs +1 -95
  66. package/dist/linker/linker.cjs.map +1 -1
  67. package/dist/linker/linker.d.ts +17 -17
  68. package/dist/linker/linker.js +49 -57
  69. package/dist/linker/linker.js.map +1 -1
  70. package/dist/mathjax/mathjax.cjs +1 -47
  71. package/dist/mathjax/mathjax.cjs.map +1 -1
  72. package/dist/mathjax/mathjax.js +20 -30
  73. package/dist/mathjax/mathjax.js.map +1 -1
  74. package/dist/paragraph/paragraph.cjs +1 -13
  75. package/dist/paragraph/paragraph.cjs.map +1 -1
  76. package/dist/paragraph/paragraph.d.ts +1 -4
  77. package/dist/paragraph/paragraph.js +8 -6
  78. package/dist/paragraph/paragraph.js.map +1 -1
  79. package/dist/speech-recognition/speech-recognition.cjs +1 -76
  80. package/dist/speech-recognition/speech-recognition.cjs.map +1 -1
  81. package/dist/speech-recognition/speech-recognition.d.ts +12 -12
  82. package/dist/speech-recognition/speech-recognition.js +36 -57
  83. package/dist/speech-recognition/speech-recognition.js.map +1 -1
  84. package/dist/speech-synthesis/speech-synthesis.cjs +1 -32
  85. package/dist/speech-synthesis/speech-synthesis.cjs.map +1 -1
  86. package/dist/speech-synthesis/speech-synthesis.d.ts +9 -9
  87. package/dist/speech-synthesis/speech-synthesis.js +10 -19
  88. package/dist/speech-synthesis/speech-synthesis.js.map +1 -1
  89. package/dist/table-cell/table-cell.cjs +1 -27
  90. package/dist/table-cell/table-cell.cjs.map +1 -1
  91. package/dist/table-cell/table-cell.d.ts +1 -4
  92. package/dist/table-cell/table-cell.js +12 -17
  93. package/dist/table-cell/table-cell.js.map +1 -1
  94. package/dist/transform/html-to-json/html-to-json.cjs +1 -4
  95. package/dist/transform/html-to-json/html-to-json.d.ts +1 -4
  96. package/dist/transform/html-to-json/html-to-json.js +4 -2
  97. package/dist/transform/json-to-html/json-to-html.cjs +1 -4
  98. package/dist/transform/json-to-html/json-to-html.js +4 -2
  99. package/dist/video/video.cjs +2 -111
  100. package/dist/video/video.cjs.map +1 -1
  101. package/dist/video/video.d.ts +19 -28
  102. package/dist/video/video.js +90 -114
  103. package/dist/video/video.js.map +1 -1
  104. package/package.json +24 -16
  105. package/dist/image/custom-image.cjs +0 -163
  106. package/dist/image/custom-image.cjs.map +0 -1
  107. package/dist/image/custom-image.d.ts +0 -27
  108. package/dist/image/custom-image.js +0 -181
  109. package/dist/image/custom-image.js.map +0 -1
@@ -0,0 +1 @@
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: (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 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,QACJ,MAAA,CACL,IAAG,QAAK,SAAL,0BACH,OAAQ,GACR,QAAS,UACT,MAAO,CAAC,QAAS,SAAU,OAAO,EAClC,eAAgB,CACd,MAAO,cACT,EACA,WAAY,IACH,QAAQ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S,GAY3B,OANM,KAAK,KAAK,OAAO,CAC5B,IAAK,SACL,IAAK,MAAM,IACX,MAAO,MAAM,KAAA,CACd,CAGH,EAEM,iBAAoB,OACjB,MAAM,KAAK,KAAK,EAAE,OAAQ,MAC/B,2CAA2C,KAAK,KAAK,IAAI,CAC3D,EAGI,kBAAoB,MACxB,OACA,KACA,WACG,CACG,MAAA,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,EAEO,MAAA,CACL,IAAIC,wBAAO,CACT,MAAO,CACL,YAAa,CAAC,OAAQ,IAAM,QAC1B,MAAM,MAAQ,kBAAiB,KAAE,gBAAF,eAAiB,KAAK,EACjD,GAAA,MAAM,SAAW,EAAU,MAAA,GAE/B,UAAW,QAAQ,MACjB,kBAAkB,OAAQ,IAAI,EAGzB,MAAA,EACT,EACA,WAAY,CAAC,OAAQ,EAAG,GAAI,QAAU,CACpC,GAAI,MAAc,MAAA,GAElB,MAAM,MAAQ,iBAAiB,EAAE,aAAa,KAAK,EAC/C,GAAA,MAAM,SAAW,EAAU,MAAA,GAE/B,KAAM,CAAE,IAAK,UAAa,OAAO,YAAY,CAC3C,KAAM,EAAE,QACR,IAAK,EAAE,OAAA,CACR,EAED,UAAW,QAAQ,MACC,kBAAA,OAAQ,KAAM,QAAQ,EAEnC,MAAA,EAAA,CACT,CAEH,CAAA,CACH,CAAA,CAEJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { WorkspaceElement } from '@edifice.io/client';
2
+ export declare const IMAGE_INPUT_REGEX: RegExp;
3
+ export interface CustomImageOptions {
4
+ HTMLAttributes: Record<string, string>;
5
+ sizes: string[];
6
+ uploadFile?: (file: File) => Promise<WorkspaceElement | null>;
7
+ }
8
+ interface AttributesProps {
9
+ width: number | string;
10
+ height: number | string;
11
+ size: string;
12
+ }
13
+ declare module '@tiptap/core' {
14
+ interface Commands<ReturnType> {
15
+ customImage: {
16
+ setAttributes: (options: AttributesProps) => ReturnType;
17
+ setNewImage: (options: {
18
+ src: string;
19
+ alt?: string;
20
+ title?: string;
21
+ }) => ReturnType;
22
+ };
23
+ }
24
+ }
25
+ export declare const Image: import('@tiptap/core').Node<CustomImageOptions, any>;
26
+ export {};
@@ -0,0 +1,178 @@
1
+ import { ImageResizer } from "@edifice.io/utilities";
2
+ import { mergeAttributes, nodeInputRule } 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: (element) => {
60
+ const style = element.getAttribute("style");
61
+ return style && typeof style == "string" && style.length > 0 ? {} : null;
62
+ }
63
+ }
64
+ };
65
+ },
66
+ parseHTML() {
67
+ return [
68
+ {
69
+ tag: 'img[src]:not([src^="data:"])',
70
+ getAttrs: (el) => {
71
+ var _a, _b, _c, _d, _e;
72
+ const attr = { src: el.getAttribute("src") };
73
+ 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), [
74
+ "happy",
75
+ "proud",
76
+ "dreamy",
77
+ "love",
78
+ "tired",
79
+ "angry",
80
+ "worried",
81
+ "sick",
82
+ "joker",
83
+ "sad"
84
+ ].filter((smiley) => attr.src.includes(smiley + ".png")).length > 0 && (attr.style = {
85
+ width: "1.5em",
86
+ height: "1.5em",
87
+ fontSize: (_e = (_d = el.parentElement) == null ? void 0 : _d.style) == null ? void 0 : _e.fontSize
88
+ }, attr.width = "null", attr.height = "null"), attr;
89
+ }
90
+ }
91
+ ];
92
+ },
93
+ renderHTML({ HTMLAttributes }) {
94
+ return [
95
+ "img",
96
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)
97
+ ];
98
+ },
99
+ addInputRules() {
100
+ return [
101
+ nodeInputRule({
102
+ find: IMAGE_INPUT_REGEX,
103
+ type: this.type,
104
+ getAttributes: (match) => {
105
+ const [, , alt, src, title] = match;
106
+ return {
107
+ src,
108
+ alt,
109
+ title
110
+ };
111
+ }
112
+ })
113
+ ];
114
+ },
115
+ addCommands() {
116
+ return {
117
+ setNewImage: (attrs) => ({ tr, dispatch }) => {
118
+ const { selection } = tr, node = this.type.create(attrs);
119
+ return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
120
+ },
121
+ setAttributes: (attributes) => ({ tr, dispatch }) => {
122
+ const { selection } = tr, options = {
123
+ ...tr.doc.nodeAt(tr.selection.from).attrs,
124
+ ...attributes
125
+ }, node = this.type.create(options);
126
+ return dispatch && tr.replaceRangeWith(selection.from, selection.to, node), !0;
127
+ }
128
+ };
129
+ },
130
+ addProseMirrorPlugins() {
131
+ const uploadNode = async (file) => {
132
+ 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()}`;
133
+ return this.type.create({
134
+ src: imageUrl,
135
+ alt: image.alt,
136
+ title: image.title
137
+ });
138
+ }, getFilteredFiles = (files) => Array.from(files).filter(
139
+ (file) => /image\/(png|jpeg|jpg|gif|webp|heic|avif)/.test(file.type)
140
+ ), handleImageInsert = async (editor, file, position) => {
141
+ const node = await uploadNode(file);
142
+ if (!node) return;
143
+ const transaction = position !== void 0 ? editor.state.tr.insert(position, node) : editor.state.tr.replaceSelectionWith(node);
144
+ editor.dispatch(transaction);
145
+ };
146
+ return [
147
+ new Plugin({
148
+ props: {
149
+ handlePaste: (editor, e) => {
150
+ var _a;
151
+ const files = getFilteredFiles((_a = e.clipboardData) == null ? void 0 : _a.files);
152
+ if (files.length === 0) return !1;
153
+ for (const file of files)
154
+ handleImageInsert(editor, file);
155
+ return !0;
156
+ },
157
+ handleDrop: (editor, e, _s, moved) => {
158
+ if (moved) return !1;
159
+ const files = getFilteredFiles(e.dataTransfer.files);
160
+ if (files.length === 0) return !1;
161
+ const { pos: position } = editor.posAtCoords({
162
+ left: e.clientX,
163
+ top: e.clientY
164
+ });
165
+ for (const file of files)
166
+ handleImageInsert(editor, file, position);
167
+ return !0;
168
+ }
169
+ }
170
+ })
171
+ ];
172
+ }
173
+ });
174
+ export {
175
+ IMAGE_INPUT_REGEX,
176
+ Image
177
+ };
178
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
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: (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 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":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oB,OACxB,QACA,MACA,aACG;AACG,YAAA,OAAO,MAAM,WAAW,IAAI;AAClC,UAAI,CAAC,KAAM;AAEX,YAAM,cACJ,aAAa,SACT,OAAO,MAAM,GAAG,OAAO,UAAU,IAAI,IACrC,OAAO,MAAM,GAAG,qBAAqB,IAAI;AAE/C,aAAO,SAAS,WAAW;AAAA,IAC7B;AAEO,WAAA;AAAA,MACL,IAAI,OAAO;AAAA,QACT,OAAO;AAAA,UACL,aAAa,CAAC,QAAQ,MAAM;;AAC1B,kBAAM,QAAQ,kBAAiB,OAAE,kBAAF,mBAAiB,KAAK;AACjD,gBAAA,MAAM,WAAW,EAAU,QAAA;AAE/B,uBAAW,QAAQ;AACjB,gCAAkB,QAAQ,IAAI;AAGzB,mBAAA;AAAA,UACT;AAAA,UACA,YAAY,CAAC,QAAQ,GAAG,IAAI,UAAU;AACpC,gBAAI,MAAc,QAAA;AAElB,kBAAM,QAAQ,iBAAiB,EAAE,aAAa,KAAK;AAC/C,gBAAA,MAAM,WAAW,EAAU,QAAA;AAE/B,kBAAM,EAAE,KAAK,aAAa,OAAO,YAAY;AAAA,cAC3C,MAAM,EAAE;AAAA,cACR,KAAK,EAAE;AAAA,YAAA,CACR;AAED,uBAAW,QAAQ;AACC,gCAAA,QAAQ,MAAM,QAAQ;AAEnC,mBAAA;AAAA,UAAA;AAAA,QACT;AAAA,MAEH,CAAA;AAAA,IACH;AAAA,EAAA;AAEJ,CAAC;"}
@@ -1,3 +1,3 @@
1
- import { CustomImage } from './custom-image';
2
- export * from './custom-image';
3
- export default CustomImage;
1
+ import { Image } from './image';
2
+ export * from './image';
3
+ export default Image;
package/dist/index.cjs CHANGED
@@ -1,44 +1,2 @@
1
- 'use strict';
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const abbr = require('./abbr/abbr.cjs'),
4
- alert = require('./alert/alert.cjs'),
5
- attachment = require('./attachment/attachment.cjs'),
6
- audio = require('./audio/audio.cjs'),
7
- fontSize = require('./font-size/font-size.cjs'),
8
- heading = require('./heading/heading.cjs'),
9
- highlight = require('./highlight/highlight.cjs'),
10
- hyperlink = require('./hyperlink/hyperlink.cjs'),
11
- iframe = require('./iframe/iframe.cjs'),
12
- customImage = require('./image/custom-image.cjs'),
13
- lineHeight = require('./line-height/line-height.cjs'),
14
- linker = require('./linker/linker.cjs'),
15
- mathjax = require('./mathjax/mathjax.cjs'),
16
- paragraph = require('./paragraph/paragraph.cjs'),
17
- speechRecognition = require('./speech-recognition/speech-recognition.cjs'),
18
- speechSynthesis = require('./speech-synthesis/speech-synthesis.cjs'),
19
- tableCell = require('./table-cell/table-cell.cjs'),
20
- htmlToJson = require('./transform/html-to-json/html-to-json.cjs'),
21
- jsonToHtml = require('./transform/json-to-html/json-to-html.cjs'),
22
- video = require('./video/video.cjs');
23
- exports.Abbr = abbr.Abbr;
24
- exports.Alert = alert.Alert;
25
- exports.Attachment = attachment.Attachment;
26
- exports.Audio = audio.Audio;
27
- exports.FontSize = fontSize.FontSize;
28
- exports.CustomHeading = heading.CustomHeading;
29
- exports.CustomHighlight = highlight.CustomHighlight;
30
- exports.Hyperlink = hyperlink.Hyperlink;
31
- exports.Iframe = iframe.Iframe;
32
- exports.CustomImage = customImage.CustomImage;
33
- exports.IMAGE_INPUT_REGEX = customImage.IMAGE_INPUT_REGEX;
34
- exports.LineHeight = lineHeight.LineHeight;
35
- exports.Linker = linker.Linker;
36
- exports.MathJax = mathjax.MathJax;
37
- exports.Paragraph = paragraph.Paragraph;
38
- exports.SpeechRecognition = speechRecognition.SpeechRecognition;
39
- exports.SpeechSynthesis = speechSynthesis.SpeechSynthesis;
40
- exports.TableCell = tableCell.TableCell;
41
- exports.htmlToJson = htmlToJson;
42
- exports.jsonToHtml = jsonToHtml;
43
- exports.Video = video.Video;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const abbr=require("./abbr/abbr.cjs"),alert=require("./alert/alert.cjs"),attachmentTransformer=require("./attachment/attachment-transformer.cjs"),attachment=require("./attachment/attachment.cjs"),audio=require("./audio/audio.cjs"),fontSize=require("./font-size/font-size.cjs"),heading=require("./heading/heading.cjs"),highlight=require("./highlight/highlight.cjs"),hyperlink=require("./hyperlink/hyperlink.cjs"),iframe=require("./iframe/iframe.cjs"),image=require("./image/image.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"),htmlToJson=require("./transform/html-to-json/html-to-json.cjs"),jsonToHtml=require("./transform/json-to-html/json-to-html.cjs"),video=require("./video/video.cjs");exports.Abbr=abbr.Abbr;exports.Alert=alert.Alert;exports.AttachmentTransformer=attachmentTransformer.AttachmentTransformer;exports.Attachment=attachment.Attachment;exports.Audio=audio.Audio;exports.FontSize=fontSize.FontSize;exports.CustomHeading=heading.CustomHeading;exports.CustomHighlight=highlight.CustomHighlight;exports.Hyperlink=hyperlink.Hyperlink;exports.Iframe=iframe.Iframe;exports.IMAGE_INPUT_REGEX=image.IMAGE_INPUT_REGEX;exports.Image=image.Image;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.htmlToJson=htmlToJson;exports.jsonToHtml=jsonToHtml;exports.Video=video.Video;
44
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,35 +1,37 @@
1
- import { Abbr } from './abbr/abbr.js';
2
- import { Alert } from './alert/alert.js';
3
- import { Attachment } from './attachment/attachment.js';
4
- import { Audio } from './audio/audio.js';
5
- import { FontSize } from './font-size/font-size.js';
6
- import { CustomHeading } from './heading/heading.js';
7
- import { CustomHighlight } from './highlight/highlight.js';
8
- import { Hyperlink } from './hyperlink/hyperlink.js';
9
- import { Iframe } from './iframe/iframe.js';
10
- import { CustomImage, IMAGE_INPUT_REGEX } from './image/custom-image.js';
11
- import { LineHeight } from './line-height/line-height.js';
12
- import { Linker } from './linker/linker.js';
13
- import { MathJax } from './mathjax/mathjax.js';
14
- import { Paragraph } from './paragraph/paragraph.js';
15
- import { SpeechRecognition } from './speech-recognition/speech-recognition.js';
16
- import { SpeechSynthesis } from './speech-synthesis/speech-synthesis.js';
17
- import { TableCell } from './table-cell/table-cell.js';
18
- import { default as default2 } from './transform/html-to-json/html-to-json.js';
19
- import { default as default3 } from './transform/json-to-html/json-to-html.js';
20
- import { Video } from './video/video.js';
1
+ import { Abbr } from "./abbr/abbr.js";
2
+ import { Alert } from "./alert/alert.js";
3
+ import { AttachmentTransformer } from "./attachment/attachment-transformer.js";
4
+ import { Attachment } from "./attachment/attachment.js";
5
+ import { Audio } from "./audio/audio.js";
6
+ import { FontSize } from "./font-size/font-size.js";
7
+ import { CustomHeading } from "./heading/heading.js";
8
+ import { CustomHighlight } from "./highlight/highlight.js";
9
+ import { Hyperlink } from "./hyperlink/hyperlink.js";
10
+ import { Iframe } from "./iframe/iframe.js";
11
+ import { IMAGE_INPUT_REGEX, Image } from "./image/image.js";
12
+ import { LineHeight } from "./line-height/line-height.js";
13
+ import { Linker } from "./linker/linker.js";
14
+ import { MathJax } from "./mathjax/mathjax.js";
15
+ import { Paragraph } from "./paragraph/paragraph.js";
16
+ import { SpeechRecognition } from "./speech-recognition/speech-recognition.js";
17
+ import { SpeechSynthesis } from "./speech-synthesis/speech-synthesis.js";
18
+ import { TableCell } from "./table-cell/table-cell.js";
19
+ import { default as default2 } from "./transform/html-to-json/html-to-json.js";
20
+ import { default as default3 } from "./transform/json-to-html/json-to-html.js";
21
+ import { Video } from "./video/video.js";
21
22
  export {
22
23
  Abbr,
23
24
  Alert,
24
25
  Attachment,
26
+ AttachmentTransformer,
25
27
  Audio,
26
28
  CustomHeading,
27
29
  CustomHighlight,
28
- CustomImage,
29
30
  FontSize,
30
31
  Hyperlink,
31
32
  IMAGE_INPUT_REGEX,
32
33
  Iframe,
34
+ Image,
33
35
  LineHeight,
34
36
  Linker,
35
37
  MathJax,
@@ -39,6 +41,6 @@ export {
39
41
  TableCell,
40
42
  Video,
41
43
  default2 as htmlToJson,
42
- default3 as jsonToHtml,
44
+ default3 as jsonToHtml
43
45
  };
44
46
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
@@ -1,34 +1,2 @@
1
- 'use strict';
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- require('@tiptap/extension-text-style');
4
- const core = require('@tiptap/core'),
5
- LineHeight = core.Extension.create({
6
- name: 'lineHeight',
7
- addOptions() {
8
- return { types: ['textStyle'] };
9
- },
10
- addGlobalAttributes() {
11
- return [
12
- {
13
- types: this.options.types,
14
- attributes: {
15
- lineHeight: {
16
- default: null,
17
- parseHTML: (element) => {
18
- var _a;
19
- return (_a = element.style.lineHeight) == null
20
- ? void 0
21
- : _a.replace(/['"]+/g, '');
22
- },
23
- renderHTML: (attributes) =>
24
- attributes.lineHeight
25
- ? { style: `line-height: ${attributes.lineHeight}` }
26
- : {},
27
- },
28
- },
29
- },
30
- ];
31
- },
32
- });
33
- exports.LineHeight = LineHeight;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@tiptap/extension-text-style");const core=require("@tiptap/core"),LineHeight=core.Extension.create({name:"lineHeight",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:element=>{var _a;return(_a=element.style.lineHeight)==null?void 0:_a.replace(/['"]+/g,"")},renderHTML:attributes=>attributes.lineHeight?{style:`line-height: ${attributes.lineHeight}`}:{}}}}]}});exports.LineHeight=LineHeight;
34
2
  //# sourceMappingURL=line-height.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-height.cjs","sources":["../../src/line-height/line-height.ts"],"sourcesContent":["import '@tiptap/extension-text-style';\n\nimport { Extension } from '@tiptap/core';\n\nexport const LineHeight = Extension.create({\n name: 'lineHeight',\n\n addOptions() {\n return {\n types: ['textStyle'],\n };\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n lineHeight: {\n default: null,\n parseHTML: (element) =>\n element.style.lineHeight?.replace(/['\"]+/g, ''),\n renderHTML: (attributes) => {\n if (!attributes.lineHeight) {\n return {};\n }\n\n return {\n style: `line-height: ${attributes.lineHeight}`,\n };\n },\n },\n },\n },\n ];\n },\n});\n"],"names":["Extension"],"mappings":"2JAIa,WAAaA,eAAU,OAAO,CACzC,KAAM,aAEN,YAAa,CACJ,MAAA,CACL,MAAO,CAAC,WAAW,CAAA,CAEvB,EAEA,qBAAsB,CACb,MAAA,CACL,CACE,MAAO,KAAK,QAAQ,MACpB,WAAY,CACV,WAAY,CACV,QAAS,KACT,UAAY,SACV,QAAA,kBAAQ,MAAM,aAAd,eAA0B,QAAQ,SAAU,KAC9C,WAAa,YACN,WAAW,WAIT,CACL,MAAO,gBAAgB,WAAW,UAAU,EAAA,EAJrC,EAOb,CACF,CACF,CAAA,CAEJ,CACF,CAAC"}
1
+ {"version":3,"file":"line-height.cjs","sources":["../../src/line-height/line-height.ts"],"sourcesContent":["import '@tiptap/extension-text-style';\n\nimport { Extension } from '@tiptap/core';\n\nexport const LineHeight = Extension.create({\n name: 'lineHeight',\n\n addOptions() {\n return {\n types: ['textStyle'],\n };\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n lineHeight: {\n default: null,\n parseHTML: (element) =>\n element.style.lineHeight?.replace(/['\"]+/g, ''),\n renderHTML: (attributes) => {\n if (!attributes.lineHeight) {\n return {};\n }\n\n return {\n style: `line-height: ${attributes.lineHeight}`,\n };\n },\n },\n },\n },\n ];\n },\n});\n"],"names":["Extension"],"mappings":"2JAIa,WAAaA,eAAU,OAAO,CACzC,KAAM,aAEN,YAAa,CACJ,MAAA,CACL,MAAO,CAAC,WAAW,CACrB,CACF,EAEA,qBAAsB,CACb,MAAA,CACL,CACE,MAAO,KAAK,QAAQ,MACpB,WAAY,CACV,WAAY,CACV,QAAS,KACT,UAAY,SACV,QAAA,kBAAQ,MAAM,aAAd,eAA0B,QAAQ,SAAU,KAC9C,WAAa,YACN,WAAW,WAIT,CACL,MAAO,gBAAgB,WAAW,UAAU,EAC9C,EALS,CAAC,CAMZ,CACF,CACF,CAEJ,CAAA,CAEJ,CAAC"}
@@ -1,10 +1,10 @@
1
- import '@tiptap/extension-text-style';
2
- import { Extension } from '@tiptap/core';
1
+ import "@tiptap/extension-text-style";
2
+ import { Extension } from "@tiptap/core";
3
3
  const LineHeight = Extension.create({
4
- name: 'lineHeight',
4
+ name: "lineHeight",
5
5
  addOptions() {
6
6
  return {
7
- types: ['textStyle'],
7
+ types: ["textStyle"]
8
8
  };
9
9
  },
10
10
  addGlobalAttributes() {
@@ -16,21 +16,18 @@ const LineHeight = Extension.create({
16
16
  default: null,
17
17
  parseHTML: (element) => {
18
18
  var _a;
19
- return (_a = element.style.lineHeight) == null
20
- ? void 0
21
- : _a.replace(/['"]+/g, '');
19
+ return (_a = element.style.lineHeight) == null ? void 0 : _a.replace(/['"]+/g, "");
22
20
  },
23
- renderHTML: (attributes) =>
24
- attributes.lineHeight
25
- ? {
26
- style: `line-height: ${attributes.lineHeight}`,
27
- }
28
- : {},
29
- },
30
- },
31
- },
21
+ renderHTML: (attributes) => attributes.lineHeight ? {
22
+ style: `line-height: ${attributes.lineHeight}`
23
+ } : {}
24
+ }
25
+ }
26
+ }
32
27
  ];
33
- },
28
+ }
34
29
  });
35
- export { LineHeight };
30
+ export {
31
+ LineHeight
32
+ };
36
33
  //# sourceMappingURL=line-height.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-height.js","sources":["../../src/line-height/line-height.ts"],"sourcesContent":["import '@tiptap/extension-text-style';\n\nimport { Extension } from '@tiptap/core';\n\nexport const LineHeight = Extension.create({\n name: 'lineHeight',\n\n addOptions() {\n return {\n types: ['textStyle'],\n };\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n lineHeight: {\n default: null,\n parseHTML: (element) =>\n element.style.lineHeight?.replace(/['\"]+/g, ''),\n renderHTML: (attributes) => {\n if (!attributes.lineHeight) {\n return {};\n }\n\n return {\n style: `line-height: ${attributes.lineHeight}`,\n };\n },\n },\n },\n },\n ];\n },\n});\n"],"names":[],"mappings":";;AAIa,MAAA,aAAa,UAAU,OAAO;AAAA,EACzC,MAAM;AAAA,EAEN,aAAa;AACJ,WAAA;AAAA,MACL,OAAO,CAAC,WAAW;AAAA,IAAA;AAAA,EAEvB;AAAA,EAEA,sBAAsB;AACb,WAAA;AAAA,MACL;AAAA,QACE,OAAO,KAAK,QAAQ;AAAA,QACpB,YAAY;AAAA,UACV,YAAY;AAAA,YACV,SAAS;AAAA,YACT,WAAW,CAAC,YACV;;AAAA,mCAAQ,MAAM,eAAd,mBAA0B,QAAQ,UAAU;AAAA;AAAA,YAC9C,YAAY,CAAC,eACN,WAAW,aAIT;AAAA,cACL,OAAO,gBAAgB,WAAW,UAAU;AAAA,YAAA,IAJrC;UAOb;AAAA,QACF;AAAA,MACF;AAAA,IAAA;AAAA,EAEJ;AACF,CAAC;"}
1
+ {"version":3,"file":"line-height.js","sources":["../../src/line-height/line-height.ts"],"sourcesContent":["import '@tiptap/extension-text-style';\n\nimport { Extension } from '@tiptap/core';\n\nexport const LineHeight = Extension.create({\n name: 'lineHeight',\n\n addOptions() {\n return {\n types: ['textStyle'],\n };\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n lineHeight: {\n default: null,\n parseHTML: (element) =>\n element.style.lineHeight?.replace(/['\"]+/g, ''),\n renderHTML: (attributes) => {\n if (!attributes.lineHeight) {\n return {};\n }\n\n return {\n style: `line-height: ${attributes.lineHeight}`,\n };\n },\n },\n },\n },\n ];\n },\n});\n"],"names":[],"mappings":";;AAIa,MAAA,aAAa,UAAU,OAAO;AAAA,EACzC,MAAM;AAAA,EAEN,aAAa;AACJ,WAAA;AAAA,MACL,OAAO,CAAC,WAAW;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,sBAAsB;AACb,WAAA;AAAA,MACL;AAAA,QACE,OAAO,KAAK,QAAQ;AAAA,QACpB,YAAY;AAAA,UACV,YAAY;AAAA,YACV,SAAS;AAAA,YACT,WAAW,CAAC,YACV;;AAAA,mCAAQ,MAAM,eAAd,mBAA0B,QAAQ,UAAU;AAAA;AAAA,YAC9C,YAAY,CAAC,eACN,WAAW,aAIT;AAAA,cACL,OAAO,gBAAgB,WAAW,UAAU;AAAA,YAC9C,IALS,CAAC;AAAA,UAMZ;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAAA,EAAA;AAEJ,CAAC;"}
@@ -1,96 +1,2 @@
1
- 'use strict';
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const core = require('@tiptap/core'),
4
- Linker = core.Node.create({
5
- name: 'linker',
6
- content: 'text*',
7
- marks: '',
8
- group: 'inline',
9
- inline: !0,
10
- selectable: !0,
11
- atom: !0,
12
- draggable: !0,
13
- isolating: !0,
14
- allowGapCursor: !1,
15
- priority: 1100,
16
- keepOnSplit: !1,
17
- addOptions() {
18
- return {
19
- openOnClick: !0,
20
- HTMLAttributes: {
21
- target: null,
22
- title: null,
23
- class: null,
24
- 'data-id': null,
25
- 'data-app-prefix': null,
26
- },
27
- validate: void 0,
28
- };
29
- },
30
- addAttributes() {
31
- return {
32
- href: { default: null },
33
- class: { default: this.options.HTMLAttributes.class },
34
- target: {
35
- default: this.options.HTMLAttributes.target,
36
- parseHTML: (element) =>
37
- element.getAttribute('target') !== '_blank' ? null : '_blank',
38
- },
39
- title: { default: this.options.HTMLAttributes.title },
40
- 'data-id': { default: this.options.HTMLAttributes['data-id'] },
41
- 'data-app-prefix': {
42
- default: this.options.HTMLAttributes['data-app-prefix'],
43
- },
44
- };
45
- },
46
- parseHTML() {
47
- return [
48
- {
49
- tag: 'a[href]:not([href *= "javascript:" i])[data-id][data-app-prefix]',
50
- },
51
- ];
52
- },
53
- renderHTML({ HTMLAttributes }) {
54
- var _a;
55
- return (_a = HTMLAttributes.href) != null && _a.startsWith('javascript:')
56
- ? [
57
- 'a',
58
- core.mergeAttributes(this.options.HTMLAttributes, {
59
- ...HTMLAttributes,
60
- href: '',
61
- }),
62
- 0,
63
- ]
64
- : [
65
- 'a',
66
- core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
67
- 0,
68
- ];
69
- },
70
- addCommands() {
71
- return {
72
- setLinker:
73
- (attrs) =>
74
- ({ commands }) => (
75
- commands.insertContent({
76
- type: this.name,
77
- attrs,
78
- content: [{ type: 'text', text: attrs.title }],
79
- }),
80
- !0
81
- ),
82
- unsetLinker:
83
- () =>
84
- ({ state, tr }) => {
85
- const { node, from, to } = state.selection;
86
- return (
87
- (node == null ? void 0 : node.type.name) === 'linker' &&
88
- tr.delete(from, to).scrollIntoView(),
89
- !0
90
- );
91
- },
92
- };
93
- },
94
- });
95
- exports.Linker = Linker;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@tiptap/core"),Linker=core.Node.create({name:"linker",content:"text*",marks:"",group:"inline",inline:!0,selectable:!0,atom:!0,draggable:!0,isolating:!0,allowGapCursor:!1,priority:1100,keepOnSplit:!1,addOptions(){return{openOnClick:!0,HTMLAttributes:{target:null,title:null,class:null,"data-id":null,"data-app-prefix":null},validate:void 0}},addAttributes(){return{href:{default:null},class:{default:this.options.HTMLAttributes.class},target:{default:this.options.HTMLAttributes.target,parseHTML:element=>element.getAttribute("target")!=="_blank"?null:"_blank"},title:{default:this.options.HTMLAttributes.title},"data-id":{default:this.options.HTMLAttributes["data-id"]},"data-app-prefix":{default:this.options.HTMLAttributes["data-app-prefix"]}}},parseHTML(){return[{tag:'a[href]:not([href *= "javascript:" i])[data-id][data-app-prefix]'}]},renderHTML({HTMLAttributes}){var _a;return(_a=HTMLAttributes.href)!=null&&_a.startsWith("javascript:")?["a",core.mergeAttributes(this.options.HTMLAttributes,{...HTMLAttributes,href:""}),0]:["a",core.mergeAttributes(this.options.HTMLAttributes,HTMLAttributes),0]},addCommands(){return{setLinker:attrs=>({commands})=>(commands.insertContent({type:this.name,attrs,content:[{type:"text",text:attrs.title}]}),!0),unsetLinker:()=>({state,tr})=>{const{node,from,to}=state.selection;return(node==null?void 0:node.type.name)==="linker"&&tr.delete(from,to).scrollIntoView(),!0}}}});exports.Linker=Linker;
96
2
  //# sourceMappingURL=linker.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"linker.cjs","sources":["../../src/linker/linker.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core';\nimport { NodeSelection } from '@tiptap/pm/state';\n\n/* Our own model of a link in a rich document. */\nexport type LinkerAttributes = {\n href: string | null;\n target: '_blank' | null;\n title: string | null;\n 'data-id': string | null;\n 'data-app-prefix': string | null;\n};\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n linker: {\n /**\n * Set a linker node\n */\n setLinker: (attributes: LinkerAttributes) => ReturnType;\n /**\n * Unset a linker node\n */\n unsetLinker: () => ReturnType;\n };\n }\n}\n\n/**\n * Internal links extension.\n * Reproduces the legacy angularJs \"linker\" directive.\n *\n * Links to internal resources MAY have a `title` and MUST HAVE `data-id` and `data-app-prefix` attributes :\n * `<a href=\"/blog#/view/35fa4198-blog_id/5e654c71-article_id\" data-app-prefix=\"blog\" data-id=\"35fa4198-blog_id\" target=\"_blank\" title=\"Voir ce billet de blog\" class=\"ng-scope\">/blog#/view/35fa4198-57fe-45eb-94f4-a5e4defff305/5e654c71-1e61-4f84-86dc-6fcfaf33f513</a>`\n */\nexport const Linker = Node.create({\n name: 'linker',\n content: 'text*',\n marks: '',\n group: 'inline',\n\n inline: true,\n selectable: true,\n atom: true,\n draggable: true,\n isolating: true,\n allowGapCursor: false,\n\n priority: 1100,\n keepOnSplit: false,\n\n addOptions() {\n return {\n openOnClick: true,\n HTMLAttributes: {\n target: null,\n title: null,\n class: null,\n 'data-id': null,\n 'data-app-prefix': null,\n },\n validate: undefined,\n };\n },\n\n addAttributes() {\n return {\n href: {\n default: null,\n },\n class: {\n default: this.options.HTMLAttributes.class,\n },\n target: {\n default: this.options.HTMLAttributes.target,\n // Sanitize target value\n parseHTML: (element) =>\n element.getAttribute('target') !== '_blank' ? null : '_blank',\n },\n title: {\n default: this.options.HTMLAttributes.title,\n },\n 'data-id': {\n default: this.options.HTMLAttributes['data-id'],\n },\n 'data-app-prefix': {\n default: this.options.HTMLAttributes['data-app-prefix'],\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'a[href]:not([href *= \"javascript:\" i])[data-id][data-app-prefix]',\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n if (HTMLAttributes.href?.startsWith('javascript:')) {\n return [\n 'a',\n mergeAttributes(this.options.HTMLAttributes, {\n ...HTMLAttributes,\n href: '',\n }),\n 0,\n ];\n }\n return [\n 'a',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n 0,\n ];\n },\n\n addCommands() {\n return {\n setLinker:\n (attrs) =>\n ({ commands }) => {\n // Insert a Linker node with inner text node\n commands.insertContent({\n type: this.name,\n attrs,\n content: [\n {\n type: 'text',\n text: attrs.title,\n },\n ],\n });\n return true;\n },\n\n unsetLinker:\n () =>\n ({ state, tr }) => {\n // Which Linker node is actually selected ?\n const { node, from, to } = state.selection as NodeSelection;\n // Delete any selected Linker node\n if (node?.type.name === 'linker') {\n /* The following does not work as one would expected.\n commands.deleteNode(this.name);\n commands.deleteCurrentNode();\n * Replaced by : */\n tr.delete(from, to).scrollIntoView();\n }\n return true;\n },\n };\n },\n});\n"],"names":["Node","mergeAttributes"],"mappings":"mHAkCa,OAASA,UAAK,OAAO,CAChC,KAAM,SACN,QAAS,QACT,MAAO,GACP,MAAO,SAEP,OAAQ,GACR,WAAY,GACZ,KAAM,GACN,UAAW,GACX,UAAW,GACX,eAAgB,GAEhB,SAAU,KACV,YAAa,GAEb,YAAa,CACJ,MAAA,CACL,YAAa,GACb,eAAgB,CACd,OAAQ,KACR,MAAO,KACP,MAAO,KACP,UAAW,KACX,kBAAmB,IACrB,EACA,SAAU,MAAA,CAEd,EAEA,eAAgB,CACP,MAAA,CACL,KAAM,CACJ,QAAS,IACX,EACA,MAAO,CACL,QAAS,KAAK,QAAQ,eAAe,KACvC,EACA,OAAQ,CACN,QAAS,KAAK,QAAQ,eAAe,OAErC,UAAY,SACV,QAAQ,aAAa,QAAQ,IAAM,SAAW,KAAO,QACzD,EACA,MAAO,CACL,QAAS,KAAK,QAAQ,eAAe,KACvC,EACA,UAAW,CACT,QAAS,KAAK,QAAQ,eAAe,SAAS,CAChD,EACA,kBAAmB,CACjB,QAAS,KAAK,QAAQ,eAAe,iBAAiB,CACxD,CAAA,CAEJ,EAEA,WAAY,CACH,MAAA,CACL,CACE,IAAK,kEACP,CAAA,CAEJ,EAEA,WAAW,CAAE,gBAAkB,QAC7B,OAAI,kBAAe,OAAf,SAAqB,WAAW,eAC3B,CACL,IACAC,qBAAgB,KAAK,QAAQ,eAAgB,CAC3C,GAAG,eACH,KAAM,EAAA,CACP,EACD,CAAA,EAGG,CACL,IACAA,KAAAA,gBAAgB,KAAK,QAAQ,eAAgB,cAAc,EAC3D,CAAA,CAEJ,EAEA,aAAc,CACL,MAAA,CACL,UACG,OACD,CAAC,CAAE,aAED,SAAS,cAAc,CACrB,KAAM,KAAK,KACX,MACA,QAAS,CACP,CACE,KAAM,OACN,KAAM,MAAM,KACd,CACF,CAAA,CACD,EACM,IAGX,YACE,IACA,CAAC,CAAE,MAAO,MAAS,CAEjB,KAAM,CAAE,KAAM,KAAM,EAAA,EAAO,MAAM,UAE7B,OAAA,uBAAM,KAAK,QAAS,UAKtB,GAAG,OAAO,KAAM,EAAE,EAAE,eAAe,EAE9B,EACT,CAAA,CAEN,CACF,CAAC"}
1
+ {"version":3,"file":"linker.cjs","sources":["../../src/linker/linker.ts"],"sourcesContent":["import { Node, mergeAttributes } from '@tiptap/core';\nimport { NodeSelection } from '@tiptap/pm/state';\n\n/* Our own model of a link in a rich document. */\nexport type LinkerAttributes = {\n 'href': string | null;\n 'target': '_blank' | null;\n 'title': string | null;\n 'data-id': string | null;\n 'data-app-prefix': string | null;\n};\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n linker: {\n /**\n * Set a linker node\n */\n setLinker: (attributes: LinkerAttributes) => ReturnType;\n /**\n * Unset a linker node\n */\n unsetLinker: () => ReturnType;\n };\n }\n}\n\n/**\n * Internal links extension.\n * Reproduces the legacy angularJs \"linker\" directive.\n *\n * Links to internal resources MAY have a `title` and MUST HAVE `data-id` and `data-app-prefix` attributes :\n * `<a href=\"/blog#/view/35fa4198-blog_id/5e654c71-article_id\" data-app-prefix=\"blog\" data-id=\"35fa4198-blog_id\" target=\"_blank\" title=\"Voir ce billet de blog\" class=\"ng-scope\">/blog#/view/35fa4198-57fe-45eb-94f4-a5e4defff305/5e654c71-1e61-4f84-86dc-6fcfaf33f513</a>`\n */\nexport const Linker = Node.create({\n name: 'linker',\n content: 'text*',\n marks: '',\n group: 'inline',\n\n inline: true,\n selectable: true,\n atom: true,\n draggable: true,\n isolating: true,\n allowGapCursor: false,\n\n priority: 1100,\n keepOnSplit: false,\n\n addOptions() {\n return {\n openOnClick: true,\n HTMLAttributes: {\n 'target': null,\n 'title': null,\n 'class': null,\n 'data-id': null,\n 'data-app-prefix': null,\n },\n validate: undefined,\n };\n },\n\n addAttributes() {\n return {\n 'href': {\n default: null,\n },\n 'class': {\n default: this.options.HTMLAttributes.class,\n },\n 'target': {\n default: this.options.HTMLAttributes.target,\n // Sanitize target value\n parseHTML: (element) =>\n element.getAttribute('target') !== '_blank' ? null : '_blank',\n },\n 'title': {\n default: this.options.HTMLAttributes.title,\n },\n 'data-id': {\n default: this.options.HTMLAttributes['data-id'],\n },\n 'data-app-prefix': {\n default: this.options.HTMLAttributes['data-app-prefix'],\n },\n };\n },\n\n parseHTML() {\n return [\n {\n tag: 'a[href]:not([href *= \"javascript:\" i])[data-id][data-app-prefix]',\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n if (HTMLAttributes.href?.startsWith('javascript:')) {\n return [\n 'a',\n mergeAttributes(this.options.HTMLAttributes, {\n ...HTMLAttributes,\n href: '',\n }),\n 0,\n ];\n }\n return [\n 'a',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n 0,\n ];\n },\n\n addCommands() {\n return {\n setLinker:\n (attrs) =>\n ({ commands }) => {\n // Insert a Linker node with inner text node\n commands.insertContent({\n type: this.name,\n attrs,\n content: [\n {\n type: 'text',\n text: attrs.title,\n },\n ],\n });\n return true;\n },\n\n unsetLinker:\n () =>\n ({ state, tr }) => {\n // Which Linker node is actually selected ?\n const { node, from, to } = state.selection as NodeSelection;\n // Delete any selected Linker node\n if (node?.type.name === 'linker') {\n /* The following does not work as one would expected.\n commands.deleteNode(this.name);\n commands.deleteCurrentNode();\n * Replaced by : */\n tr.delete(from, to).scrollIntoView();\n }\n return true;\n },\n };\n },\n});\n"],"names":["Node","mergeAttributes"],"mappings":"mHAkCa,OAASA,UAAK,OAAO,CAChC,KAAM,SACN,QAAS,QACT,MAAO,GACP,MAAO,SAEP,OAAQ,GACR,WAAY,GACZ,KAAM,GACN,UAAW,GACX,UAAW,GACX,eAAgB,GAEhB,SAAU,KACV,YAAa,GAEb,YAAa,CACJ,MAAA,CACL,YAAa,GACb,eAAgB,CACd,OAAU,KACV,MAAS,KACT,MAAS,KACT,UAAW,KACX,kBAAmB,IACrB,EACA,SAAU,MACZ,CACF,E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