frappe-ui 1.0.2 → 1.2.0

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 (194) hide show
  1. package/experimental/Calendar/CalendarEventRow.vue +0 -4
  2. package/experimental/Calendar/calendarUtils.ts +33 -21
  3. package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
  4. package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
  5. package/experimental/MultiEmailInput/types.ts +12 -3
  6. package/experimental/SpriteIcons/IconPicker.vue +2 -1
  7. package/experimental/Stepper/StepIndicator.vue +129 -0
  8. package/experimental/Stepper/Stepper.api.md +117 -0
  9. package/experimental/Stepper/Stepper.md +95 -0
  10. package/experimental/Stepper/Stepper.vue +82 -0
  11. package/experimental/Stepper/StepperHorizontal.vue +93 -0
  12. package/experimental/Stepper/StepperVertical.vue +291 -0
  13. package/experimental/Stepper/index.ts +11 -0
  14. package/experimental/Stepper/resolve.ts +87 -0
  15. package/experimental/Stepper/types.ts +89 -0
  16. package/experimental.ts +2 -21
  17. package/package.json +1 -3
  18. package/src/charts/CalendarHeatmapChart.vue +353 -0
  19. package/src/charts/DonutChart.vue +34 -58
  20. package/src/charts/HeatmapChart.vue +26 -64
  21. package/src/charts/NumberCard.vue +62 -7
  22. package/src/charts/PercentageBarChart.vue +243 -0
  23. package/src/charts/SankeyChart.vue +14 -11
  24. package/src/charts/ScatterChart.vue +24 -20
  25. package/src/charts/axisChartCommon.ts +182 -18
  26. package/src/charts/axisFormat.ts +8 -3
  27. package/src/charts/calendarHeatmapOptions.ts +604 -0
  28. package/src/charts/colorMath.ts +26 -0
  29. package/src/charts/components/ChartContainer.vue +63 -53
  30. package/src/charts/components/ChartLegend.vue +216 -24
  31. package/src/charts/components/ChartScale.vue +85 -0
  32. package/src/charts/core/dataLabelFit.ts +45 -6
  33. package/src/charts/core/useAxisChart.ts +36 -19
  34. package/src/charts/core/useChart.ts +6 -1
  35. package/src/charts/core/usePlotKeyboard.ts +13 -2
  36. package/src/charts/docs/BarChart.md +11 -3
  37. package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
  38. package/src/charts/docs/CalendarHeatmapChart.md +33 -0
  39. package/src/charts/docs/ChartContainer.api.md +6 -0
  40. package/src/charts/docs/ChartLegend.api.md +1 -1
  41. package/src/charts/docs/ChartLegend.md +25 -3
  42. package/src/charts/docs/DonutChart.api.md +12 -0
  43. package/src/charts/docs/DonutChart.md +17 -0
  44. package/src/charts/docs/HeatmapChart.api.md +1 -1
  45. package/src/charts/docs/LineChart.md +5 -3
  46. package/src/charts/docs/NumberCard.api.md +6 -0
  47. package/src/charts/docs/NumberCard.md +6 -0
  48. package/src/charts/docs/Overview.md +13 -6
  49. package/src/charts/docs/PercentageBarChart.api.md +148 -0
  50. package/src/charts/docs/PercentageBarChart.md +42 -0
  51. package/src/charts/docs/ScatterChart.md +2 -3
  52. package/src/charts/donutChartOptions.ts +22 -130
  53. package/src/charts/format.ts +4 -1
  54. package/src/charts/heatmapOptions.ts +17 -12
  55. package/src/charts/hiddenSeries.ts +8 -3
  56. package/src/charts/index.ts +12 -0
  57. package/src/charts/legendOverflow.ts +40 -0
  58. package/src/charts/numberCardFormat.ts +19 -13
  59. package/src/charts/referenceLines.ts +2 -1
  60. package/src/charts/scatterOptions.ts +16 -3
  61. package/src/charts/seriesData.ts +8 -3
  62. package/src/charts/slices.ts +228 -0
  63. package/src/charts/tokens.ts +99 -0
  64. package/src/charts/types.ts +318 -9
  65. package/src/components/Avatar/Avatar.md +27 -2
  66. package/src/components/Avatar/Avatar.vue +29 -12
  67. package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
  68. package/src/components/Combobox/Combobox.vue +9 -2
  69. package/src/components/Combobox/ComboboxResults.vue +6 -1
  70. package/src/components/Combobox/utils.ts +2 -1
  71. package/src/components/DatePicker/DatePicker.md +7 -0
  72. package/src/components/DatePicker/DatePicker.vue +6 -0
  73. package/src/components/DatePicker/DateTimePicker.vue +6 -0
  74. package/src/components/DatePicker/composables.ts +18 -1
  75. package/src/components/DatePicker/utils.ts +53 -0
  76. package/src/components/Dialog/Dialog.md +3 -1
  77. package/src/components/Duration/Duration.api.md +16 -3
  78. package/src/components/Duration/Duration.md +21 -0
  79. package/src/components/Duration/Duration.vue +29 -8
  80. package/src/components/Duration/duration.ts +105 -44
  81. package/src/components/Duration/index.ts +1 -0
  82. package/src/components/Duration/types.ts +30 -1
  83. package/src/components/HoverCard/HoverCard.vue +21 -5
  84. package/src/components/Menu/utils.ts +3 -2
  85. package/src/components/MobileNav/MobileNavItem.vue +3 -22
  86. package/src/components/MultiSelect/MultiSelect.api.md +5 -0
  87. package/src/components/MultiSelect/MultiSelect.vue +34 -0
  88. package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
  89. package/src/components/MultiSelect/types.ts +6 -0
  90. package/src/components/Select/Select.vue +4 -4
  91. package/src/components/Select/utils.ts +1 -0
  92. package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
  93. package/src/components/SettingsDialog/SettingsDialog.md +2 -1
  94. package/src/components/SettingsDialog/SettingsRow.vue +12 -2
  95. package/src/components/Sidebar/SidebarItem.vue +3 -33
  96. package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
  97. package/src/components/Switch/Switch.vue +3 -3
  98. package/src/components/Tooltip/Tooltip.vue +8 -0
  99. package/src/components/shared/deferredTrigger.ts +174 -0
  100. package/src/components/shared/navLink.ts +45 -0
  101. package/src/components/shared/selection/utils.ts +8 -1
  102. package/src/data-fetching/useCall/useCall.ts +25 -26
  103. package/src/data-fetching/useFrappeFetch.ts +48 -2
  104. package/src/data-fetching/useList/useList.ts +11 -3
  105. package/src/data-fetching/utils.ts +15 -1
  106. package/src/molecules/editor/components/MediaNodeView.vue +10 -1
  107. package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
  108. package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
  109. package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
  110. package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
  111. package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
  112. package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
  113. package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
  114. package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
  115. package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
  116. package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
  117. package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
  118. package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
  119. package/src/molecules/editor/useEditor.ts +12 -6
  120. package/src/molecules/list/ListRow.vue +8 -1
  121. package/src/utils/dialog.ts +57 -16
  122. package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
  123. package/tailwind/content.js +1 -1
  124. package/tailwind/plugin.js +22 -0
  125. package/vite/README.md +5 -3
  126. package/vite/codeLanguages.js +41 -17
  127. package/vite/doctypeInterfaceGenerator.js +52 -39
  128. package/vitepress/index.node.ts +0 -2
  129. package/experimental/TextEditor/TextEditor.api.md +0 -161
  130. package/experimental/TextEditor/TextEditor.vue +0 -298
  131. package/experimental/TextEditor/classIcon.ts +0 -21
  132. package/experimental/TextEditor/commands.js +0 -344
  133. package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
  134. package/experimental/TextEditor/components/FontColor.vue +0 -153
  135. package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
  136. package/experimental/TextEditor/components/InsertImage.vue +0 -54
  137. package/experimental/TextEditor/components/InsertLink.vue +0 -13
  138. package/experimental/TextEditor/components/InsertVideo.vue +0 -14
  139. package/experimental/TextEditor/components/LinkPopup.vue +0 -99
  140. package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
  141. package/experimental/TextEditor/components/MentionList.vue +0 -95
  142. package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
  143. package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
  144. package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
  145. package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
  146. package/experimental/TextEditor/components/index.js +0 -0
  147. package/experimental/TextEditor/extensions/code-block.ts +0 -119
  148. package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
  149. package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
  150. package/experimental/TextEditor/extensions/color/index.ts +0 -2
  151. package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
  152. package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
  153. package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
  154. package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
  155. package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
  156. package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
  157. package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
  158. package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
  159. package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
  160. package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
  161. package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
  162. package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
  163. package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
  164. package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
  165. package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
  166. package/experimental/TextEditor/extensions/image/index.ts +0 -5
  167. package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
  168. package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
  169. package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
  170. package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
  171. package/experimental/TextEditor/extensions/link/index.ts +0 -1
  172. package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
  173. package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
  174. package/experimental/TextEditor/extensions/mention/index.ts +0 -1
  175. package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
  176. package/experimental/TextEditor/extensions/mention/style.css +0 -11
  177. package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
  178. package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
  179. package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
  180. package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
  181. package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
  182. package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
  183. package/experimental/TextEditor/extensions/tag/index.ts +0 -1
  184. package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
  185. package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
  186. package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
  187. package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
  188. package/experimental/TextEditor/extensions/video-extension.ts +0 -653
  189. package/experimental/TextEditor/hljs-github.css +0 -197
  190. package/experimental/TextEditor/index.ts +0 -21
  191. package/experimental/TextEditor/style.css +0 -190
  192. package/experimental/TextEditor/types.ts +0 -72
  193. package/experimental/TextEditor/utils.js +0 -11
  194. package/src/utils/url-validation.ts +0 -39
@@ -1,209 +0,0 @@
1
- <template>
2
- <div>
3
- <slot v-bind="{ onClick: openIframeDialog }"></slot>
4
-
5
- <!-- Iframe URL Input Dialog -->
6
- <Dialog v-model="showDialog" title="Insert Embed" size="md">
7
- <template #default>
8
- <div class="space-y-4">
9
- <div>
10
- <label class="mb-2 block text-base text-ink-gray-5">
11
- URL or Embed Code
12
- </label>
13
- <Textarea
14
- ref="urlInput"
15
- v-model="embedUrl"
16
- placeholder="https://youtube.com/watch?v=... or <iframe src=...>"
17
- @keydown.enter="insertIframe"
18
- @input="validateUrl"
19
- />
20
- <p v-if="urlError" class="text-red-500 text-sm mt-1">
21
- {{ urlError }}
22
- </p>
23
- <p
24
- v-else-if="embedUrl && isValidUrl"
25
- class="text-ink-green-5 text-sm mt-1"
26
- >
27
- ✓ Valid {{ platformInfo.platform }} URL
28
- </p>
29
- </div>
30
- </div>
31
- </template>
32
-
33
- <template #actions>
34
- <div class="flex justify-end space-x-2">
35
- <Button variant="subtle" @click="showDialog = false">Cancel</Button>
36
- <Button
37
- variant="solid"
38
- :disabled="!embedUrl || !isValidUrl"
39
- @click="insertIframe"
40
- >
41
- Insert Embed
42
- </Button>
43
- </div>
44
- </template>
45
- </Dialog>
46
- </div>
47
- </template>
48
-
49
- <script setup lang="ts">
50
- import { ref, computed, nextTick, onMounted, onUnmounted } from 'vue'
51
- import { Editor } from '@tiptap/vue-3'
52
- import { Dialog } from '#components/Dialog'
53
- import { Button } from '#components/Button'
54
- import { TextInput } from '#components/TextInput'
55
- import { Textarea } from '#components/Textarea'
56
-
57
- import {
58
- validateURL,
59
- processURL,
60
- detectPlatform,
61
- calculateAspectRatio,
62
- getOptimalDimensions,
63
- ALLOWED_DOMAINS
64
- } from './utils'
65
-
66
-
67
- const props = defineProps<{
68
- editor: Editor
69
- }>()
70
-
71
- const showDialog = ref(false)
72
- const embedUrl = ref('')
73
- const urlError = ref('')
74
- const title = ref('')
75
- const alignment = ref<'left' | 'center' | 'right'>('center')
76
- const customWidth = ref<number>(640)
77
- const customHeight = ref<number>(360)
78
-
79
- const urlInput = ref<InstanceType<typeof Textarea>>()
80
-
81
- const isValidUrl = computed(() => {
82
- if (!embedUrl.value) return false
83
-
84
- try {
85
- // Handle iframe embed code
86
- if (embedUrl.value.trim().startsWith('<iframe')) {
87
- const srcMatch = embedUrl.value.match(/src=["']([^"']+)["']/)
88
- if (srcMatch?.[1]) {
89
- return validateURL(srcMatch[1], {
90
- allowedDomains: ALLOWED_DOMAINS,
91
- HTMLAttributes: {}
92
- })
93
- }
94
- return false
95
- }
96
-
97
- // Handle direct URLs
98
- return validateURL(embedUrl.value, {
99
- allowedDomains: ALLOWED_DOMAINS,
100
- HTMLAttributes: {}
101
- })
102
- } catch {
103
- return false
104
- }
105
- })
106
-
107
- const processedUrl = computed(() => {
108
- if (!embedUrl.value) return ''
109
-
110
- // Extract URL from iframe code if needed
111
- if (embedUrl.value.trim().startsWith('<iframe')) {
112
- const srcMatch = embedUrl.value.match(/src=["']([^"']+)["']/)
113
- if (srcMatch?.[1]) {
114
- return processURL(srcMatch[1])
115
- }
116
- return embedUrl.value
117
- }
118
-
119
- return processURL(embedUrl.value)
120
- })
121
-
122
- const platformInfo = computed(() => {
123
- if (!embedUrl.value || !isValidUrl.value) return { platform: 'Generic', aspectRatio: 9/16 }
124
-
125
- const platform = detectPlatform(processedUrl.value)
126
- const aspectInfo = calculateAspectRatio(processedUrl.value)
127
-
128
- return {
129
- platform: platform?.name || 'Generic',
130
- aspectRatio: aspectInfo.ratio
131
- }
132
- })
133
-
134
- const optimalDimensions = computed(() => {
135
- if (!embedUrl.value || !isValidUrl.value) return { width: 640, height: 360 }
136
-
137
- return getOptimalDimensions(processedUrl.value, 800) // Assume 800px editor width
138
- })
139
-
140
- function validateUrl() {
141
- urlError.value = ''
142
-
143
- if (!embedUrl.value) return
144
-
145
- if (!isValidUrl.value) {
146
- urlError.value = 'Please enter a supported URL or iframe embed code'
147
- }
148
- }
149
-
150
- function openIframeDialog() {
151
- showDialog.value = true
152
- embedUrl.value = ''
153
- urlError.value = ''
154
- title.value = ''
155
- alignment.value = 'center'
156
-
157
- // Set initial dimensions
158
- customWidth.value = 640
159
- customHeight.value = 360
160
-
161
- nextTick(() => {
162
- urlInput.value?.focus()
163
- })
164
- }
165
-
166
- // Update custom dimensions when URL changes
167
- computed(() => {
168
- if (embedUrl.value && isValidUrl.value) {
169
- const dimensions = optimalDimensions.value
170
- customWidth.value = dimensions.width
171
- customHeight.value = dimensions.height
172
- }
173
- })
174
-
175
- function insertIframe() {
176
- if (!embedUrl.value || !isValidUrl.value) return
177
-
178
- const success = props.editor.commands.setIframe({
179
- src: processedUrl.value,
180
- width: customWidth.value,
181
- height: customHeight.value,
182
- title: title.value,
183
- align: alignment.value
184
- })
185
-
186
- if (success) {
187
- showDialog.value = false
188
- props.editor.commands.focus()
189
- } else {
190
- urlError.value = 'Failed to insert embed. Please check the URL and try again.'
191
- }
192
- }
193
-
194
- function handleSlashCommandInsert(event: CustomEvent) {
195
- if (event.detail?.editor === props.editor) {
196
- openIframeDialog()
197
- }
198
- }
199
-
200
- onMounted(() => {
201
- props.editor.view.dom.addEventListener('iframe:open-dialog', handleSlashCommandInsert as EventListener)
202
- })
203
-
204
- onUnmounted(() => {
205
- try {
206
- props.editor.view.dom.removeEventListener('iframe:open-dialog', handleSlashCommandInsert as EventListener)
207
- } catch {}
208
- })
209
- </script>
@@ -1,404 +0,0 @@
1
- import { Node, mergeAttributes } from '@tiptap/core'
2
- import { VueNodeViewRenderer } from '@tiptap/vue-3'
3
- import { Plugin, PluginKey } from '@tiptap/pm/state'
4
- import IframeNodeView from './IframeNodeView.vue'
5
- import {
6
- validateURL,
7
- processURL,
8
- getOptimalDimensions,
9
- ALLOWED_DOMAINS,
10
- } from './utils'
11
-
12
- // Constants for iframe constraints
13
- const MIN_IFRAME_WIDTH = 200
14
- const EDITOR_PADDING = 40
15
- const DEFAULT_EMBED_HOST = 'gameplan'
16
-
17
- export interface IframeOptions {
18
- allowedDomains?: string[]
19
- blockedDomains?: string[]
20
- HTMLAttributes: Record<string, any>
21
- }
22
-
23
- export interface SetIframeOptions {
24
- src: string
25
- width?: number
26
- height?: number
27
- title?: string
28
- interactive?: boolean
29
- align?: 'left' | 'center' | 'right'
30
- }
31
-
32
- declare module '@tiptap/core' {
33
- interface Commands<ReturnType> {
34
- iframe: {
35
- setIframe: (options: SetIframeOptions) => ReturnType
36
- insertIframeURL: (url: string) => ReturnType
37
- setIframeAlign: (align: 'left' | 'center' | 'right') => ReturnType
38
- // `platform` is consumed by the molecules editor's implementation; this
39
- // legacy one ignores it. The signature must match — both editors augment
40
- // the same `Commands.iframe` group, and divergence is a TS2717 error.
41
- openIframeDialog: (platform?: string) => ReturnType
42
- }
43
- }
44
- }
45
-
46
- export const IframeExtension = Node.create<IframeOptions>({
47
- name: 'iframe',
48
- group: 'block',
49
- selectable: true,
50
- draggable: true,
51
- atom: true,
52
-
53
- addOptions() {
54
- return {
55
- allowedDomains: ALLOWED_DOMAINS,
56
- blockedDomains: [],
57
- HTMLAttributes: {},
58
- }
59
- },
60
-
61
- addAttributes() {
62
- return {
63
- src: {
64
- default: null,
65
- parseHTML: (element) => element.getAttribute('src'),
66
- renderHTML: (attributes) => ({
67
- src: attributes.src,
68
- }),
69
- },
70
- width: {
71
- default: null,
72
- parseHTML: (element) => {
73
- const width = element.getAttribute('width')
74
- return width ? parseInt(width, 10) : null
75
- },
76
- renderHTML: (attributes) => ({
77
- width: attributes.width ? String(attributes.width) : null,
78
- }),
79
- },
80
- height: {
81
- default: null,
82
- parseHTML: (element) => {
83
- const height = element.getAttribute('height')
84
- return height ? parseInt(height, 10) : null
85
- },
86
- renderHTML: (attributes) => ({
87
- height: attributes.height ? String(attributes.height) : null,
88
- }),
89
- },
90
- aspectRatio: {
91
- default: 9 / 16, // Default 16:9 aspect ratio
92
- parseHTML: () => null, // Don't parse from HTML
93
- renderHTML: () => ({}), // Don't render to HTML
94
- },
95
- align: {
96
- default: 'center',
97
- parseHTML: (element) => {
98
- const align = (
99
- element.getAttribute('data-align') ||
100
- element.getAttribute('align') ||
101
- 'left'
102
- ).toLowerCase()
103
-
104
- if (['left', 'center', 'right'].includes(align)) {
105
- return align as 'left' | 'center' | 'right'
106
- }
107
- return 'left'
108
- },
109
- renderHTML: (attributes) => {
110
- return {
111
- 'data-align': attributes.align || 'center',
112
- }
113
- },
114
- },
115
- title: {
116
- default: null,
117
- parseHTML: (element) => element.getAttribute('title'),
118
- renderHTML: (attributes) => ({
119
- title: attributes.title,
120
- }),
121
- },
122
- frameborder: {
123
- default: '0',
124
- renderHTML: () => ({
125
- frameborder: '0',
126
- }),
127
- },
128
- allowfullscreen: {
129
- default: 'true',
130
- renderHTML: () => ({
131
- allowfullscreen: 'true',
132
- }),
133
- },
134
- sandbox: {
135
- default: 'allow-scripts allow-same-origin allow-popups allow-forms',
136
- renderHTML: (attributes) => ({
137
- sandbox: attributes.sandbox,
138
- }),
139
- },
140
- interactive: {
141
- default: false,
142
- parseHTML: (el) => el.getAttribute('data-interactive') === 'true',
143
- renderHTML: (attrs) => ({
144
- 'data-interactive': attrs.interactive ? 'true' : 'false',
145
- }),
146
- },
147
- }
148
- },
149
-
150
- parseHTML() {
151
- return [
152
- {
153
- tag: 'iframe[src]',
154
- getAttrs: (element) => {
155
- const src = (element as HTMLElement).getAttribute('src')
156
- const width = (element as HTMLElement).getAttribute('width')
157
- const height = (element as HTMLElement).getAttribute('height')
158
- const title = (element as HTMLElement).getAttribute('title')
159
- const align = (element as HTMLElement).getAttribute('data-align')
160
-
161
- return {
162
- src,
163
- width: width ? parseInt(width, 10) : null,
164
- height: height ? parseInt(height, 10) : null,
165
- title: title || null,
166
- align: align || 'center',
167
- }
168
- },
169
- },
170
- ]
171
- },
172
-
173
- renderHTML({ HTMLAttributes }) {
174
- return [
175
- 'iframe',
176
- mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
177
- loading: 'lazy',
178
- referrerpolicy: 'no-referrer-when-downgrade',
179
- }),
180
- ]
181
- },
182
-
183
- addNodeView() {
184
- return VueNodeViewRenderer(IframeNodeView)
185
- },
186
-
187
- addCommands() {
188
- return {
189
- setIframeAlign:
190
- (align: 'left' | 'center' | 'right') =>
191
- ({ commands }) => {
192
- return commands.updateAttributes(this.name, { align })
193
- },
194
-
195
- setIframe:
196
- (options: SetIframeOptions) =>
197
- ({ commands, editor }) => {
198
- if (!validateURL(options.src, this.options)) {
199
- return false
200
- }
201
-
202
- const processedSrc = processURL(options.src)
203
-
204
- // Calculate optimal dimensions if not provided
205
- const editorElement = editor.view.dom
206
- const editorWidth = editorElement?.clientWidth || 800
207
- const optimalDimensions = getOptimalDimensions(
208
- processedSrc,
209
- editorWidth,
210
- )
211
-
212
- const attrs = {
213
- src: processedSrc,
214
- width: options.width || optimalDimensions.width,
215
- height: options.height || optimalDimensions.height,
216
- title: options.title,
217
- align: options.align || 'center',
218
- aspectRatio: optimalDimensions.height / optimalDimensions.width,
219
- interactive: options.interactive,
220
- }
221
-
222
- return commands.insertContent({
223
- type: this.name,
224
- attrs,
225
- })
226
- },
227
-
228
- insertIframeURL:
229
- (url: string) =>
230
- ({ commands }) => {
231
- const processedUrl = processURL(url)
232
- return commands.setIframe({ src: processedUrl })
233
- },
234
-
235
- openIframeDialog:
236
- () =>
237
- ({ editor }) => {
238
- // Emit a custom event on the editor's view DOM element
239
- // This is more localized than document.dispatchEvent
240
- const event = new CustomEvent('iframe:open-dialog', {
241
- detail: { editor },
242
- })
243
- editor.view.dom.dispatchEvent(event)
244
- return true
245
- },
246
- }
247
- },
248
-
249
- // Add ProseMirror plugin for paste handling
250
- addProseMirrorPlugins() {
251
- const extensionThis = this
252
-
253
- return [
254
- new Plugin({
255
- key: new PluginKey('iframe-paste-handler'),
256
- props: {
257
- handlePaste: (view, event, slice) => {
258
- const text = event.clipboardData?.getData('text/plain')
259
- const html = event.clipboardData?.getData('text/html')
260
-
261
- // First, check for iframe embed codes in HTML content
262
- if (html) {
263
- const iframeData = parseIframeFromHTML(html)
264
- if (iframeData) {
265
- return createIframeNode(
266
- view,
267
- extensionThis,
268
- iframeData.src,
269
- iframeData.width,
270
- iframeData.height,
271
- iframeData.title,
272
- )
273
- }
274
- }
275
-
276
- // Check if plain text contains iframe embed code
277
- if (text && text.includes('<iframe')) {
278
- const iframeData = parseIframeFromHTML(text)
279
- if (iframeData) {
280
- return createIframeNode(
281
- view,
282
- extensionThis,
283
- iframeData.src,
284
- iframeData.width,
285
- iframeData.height,
286
- iframeData.title,
287
- )
288
- }
289
- }
290
-
291
- // Fallback to URL detection for plain text
292
- if (text) {
293
- // Check if pasted text is a supported embed URL
294
- const urlPattern =
295
- /^https?:\/\/(?:www\.)?(?:youtube\.com\/watch\?v=[\w-]+|youtu\.be\/[\w-]+|youtube\.com\/embed\/[\w-]+|vimeo\.com\/\d+|player\.vimeo\.com\/video\/\d+|codepen\.io\/[\w-]+\/pen\/[\w-]+|codesandbox\.io\/[\w\/.-]+|figma\.com\/[\w\/.-]+|embed\.figma\.com\/[\w\/.-]+)$/
296
-
297
- if (urlPattern.test(text.trim())) {
298
- return createIframeNode(view, extensionThis, text.trim())
299
- }
300
- }
301
-
302
- return false // Allow default paste behavior
303
- },
304
- },
305
- }),
306
- ]
307
- },
308
- })
309
-
310
- // Helper function to parse iframe embed codes from pasted HTML content
311
- function parseIframeFromHTML(
312
- html: string,
313
- ): { src: string; width?: number; height?: number; title?: string } | null {
314
- try {
315
- const parser = new DOMParser()
316
- const doc = parser.parseFromString(html, 'text/html')
317
- const iframe = doc.querySelector('iframe')
318
-
319
- if (!iframe) {
320
- // Fallback: try to parse iframe tag using regex
321
- const iframeMatch = html.match(/<iframe[^>]*src=["']([^"']+)["'][^>]*>/i)
322
- if (iframeMatch) {
323
- const src = iframeMatch[1]
324
- const widthMatch = html.match(/width=["'](\d+)["']/i)
325
- const heightMatch = html.match(/height=["'](\d+)["']/i)
326
- const titleMatch = html.match(/title=["']([^"']+)["']/i)
327
-
328
- return {
329
- src,
330
- width: widthMatch ? parseInt(widthMatch[1], 10) : undefined,
331
- height: heightMatch ? parseInt(heightMatch[1], 10) : undefined,
332
- title: titleMatch ? titleMatch[1] : undefined,
333
- }
334
- }
335
- return null
336
- }
337
-
338
- const src = iframe.getAttribute('src')
339
- if (!src) return null
340
-
341
- const width = iframe.getAttribute('width')
342
- ? parseInt(iframe.getAttribute('width')!, 10)
343
- : undefined
344
- const height = iframe.getAttribute('height')
345
- ? parseInt(iframe.getAttribute('height')!, 10)
346
- : undefined
347
- const title = iframe.getAttribute('title') || undefined
348
-
349
- return { src, width, height, title }
350
- } catch (error) {
351
- return null
352
- }
353
- }
354
-
355
- // Helper function to create iframe node from parsed data
356
- function createIframeNode(
357
- view: any,
358
- extensionThis: any,
359
- src: string,
360
- width?: number,
361
- height?: number,
362
- title?: string,
363
- ) {
364
- // Ask user for confirmation before creating iframe
365
- const shouldCreateEmbed = confirm(
366
- `Do you want to embed this content?\n\nURL: ${src}\n\nClick "OK" to create an embed, or "Cancel" to paste as plain text.`,
367
- )
368
-
369
- if (!shouldCreateEmbed) {
370
- return false // Allow default paste behavior (paste as text)
371
- }
372
-
373
- if (!validateURL(src, extensionThis.options)) {
374
- return false
375
- }
376
-
377
- console.log('URL validated, creating iframe node')
378
- const processedUrl = processURL(src)
379
- const editorElement = extensionThis.editor.view.dom
380
- const editorWidth = editorElement?.clientWidth || 800
381
-
382
- // Use provided dimensions or calculate optimal ones
383
- const finalWidth =
384
- width || getOptimalDimensions(processedUrl, editorWidth).width
385
- const finalHeight =
386
- height || getOptimalDimensions(processedUrl, editorWidth).height
387
-
388
- const attrs = {
389
- src: processedUrl,
390
- width: finalWidth,
391
- height: finalHeight,
392
- title: title,
393
- align: 'center' as const,
394
- aspectRatio: finalHeight / finalWidth,
395
- }
396
-
397
- const node = view.state.schema.nodes.iframe.create(attrs)
398
- const tr = view.state.tr.replaceSelectionWith(node)
399
- view.dispatch(tr)
400
-
401
- return true // Prevent default paste behavior
402
- }
403
-
404
- export default IframeExtension
@@ -1,11 +0,0 @@
1
- export { IframeExtension, default } from './iframe-extension'
2
- export type { IframeOptions, SetIframeOptions } from './iframe-extension'
3
- export {
4
- detectPlatform,
5
- calculateAspectRatio,
6
- getOptimalDimensions,
7
- validateURL,
8
- processURL,
9
- ALLOWED_DOMAINS
10
- } from './utils'
11
- export type { AspectRatioInfo, PlatformConfig } from './utils'