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,20 +0,0 @@
1
- import TiptapHeading from '@tiptap/extension-heading'
2
- import { textblockTypeInputRule } from '@tiptap/core'
3
-
4
- // This custom Heading extension modifies the default input rule behavior.
5
- // The default Tiptap heading input rule converts text to a heading when '#' is followed by any whitespace (including Enter).
6
- // This customization ensures that headings are only created when '#' is followed by a literal space.
7
- // This change is necessary to prevent conflicts with other extensions, such as a tags extension,
8
- // which uses '#' followed by Enter to add a tag.
9
- export const Heading = TiptapHeading.extend({
10
- addInputRules() {
11
- return this.options.levels.map((level) => {
12
- let regexp = new RegExp(`^(#{${level}})( |\\u00A0)$`)
13
- return textblockTypeInputRule({
14
- find: regexp,
15
- type: this.type,
16
- getAttributes: { level },
17
- })
18
- })
19
- },
20
- })
@@ -1,241 +0,0 @@
1
- import { Mark, mergeAttributes } from '@tiptap/core'
2
- import {
3
- getClosestNamedColor,
4
- highlightColorHexMap,
5
- legacyHighlightColorMap,
6
- extractHighlightColorFromStyle,
7
- } from '../shared/color-utils'
8
-
9
- export interface HighlightOptions {
10
- /**
11
- * HTML tag to wrap the highlighted text
12
- * @default 'mark'
13
- */
14
- HTMLAttributes: Record<string, any>
15
-
16
- /**
17
- * Available highlight color names that can be used
18
- * @default ['yellow', 'blue', 'green', 'red', 'orange', 'purple', 'pink', 'gray']
19
- */
20
- colors: string[]
21
-
22
- /**
23
- * Enable multiple highlight colors
24
- * @default true
25
- */
26
- multicolor: boolean
27
- }
28
-
29
- declare module '@tiptap/core' {
30
- interface Commands<ReturnType> {
31
- namedHighlight: {
32
- /**
33
- * Set a highlight by color name
34
- * @param colorName The named color to set (e.g., 'yellow', 'blue')
35
- * @example editor.commands.setHighlightByName('yellow')
36
- */
37
- setHighlightByName: (colorName: string) => ReturnType
38
- /**
39
- * Toggle a highlight by color name
40
- * @param colorName The named color to toggle (e.g., 'yellow', 'blue')
41
- * @example editor.commands.toggleHighlightByName('yellow')
42
- */
43
- toggleHighlightByName: (colorName: string) => ReturnType
44
- /**
45
- * Unset the highlight
46
- * @example editor.commands.unsetHighlight()
47
- */
48
- unsetHighlight: () => ReturnType
49
- }
50
- }
51
- }
52
-
53
- /**
54
- * This extension allows you to highlight your text using named colors instead of hex/rgb values.
55
- * Highlights are applied as data attributes that can be styled with CSS for light/dark mode support.
56
- */
57
- export const NamedHighlightExtension = Mark.create<HighlightOptions>({
58
- name: 'namedHighlight',
59
-
60
- addOptions() {
61
- return {
62
- HTMLAttributes: {},
63
- multicolor: true,
64
- colors: [
65
- 'yellow',
66
- 'blue',
67
- 'green',
68
- 'red',
69
- 'orange',
70
- 'purple',
71
- 'pink',
72
- 'gray',
73
- 'teal',
74
- 'cyan',
75
- ],
76
- }
77
- },
78
-
79
- addAttributes() {
80
- if (!this.options.multicolor) {
81
- return {}
82
- }
83
-
84
- return {
85
- color: {
86
- default: null,
87
- parseHTML: (element) => {
88
- // Check for CSS custom property format in style attribute
89
- const style = element.getAttribute('style')
90
- if (style) {
91
- const highlightMatch = style.match(
92
- /background-color:\s*var\(--prose-highlight-(\w+)\)/,
93
- )
94
- if (
95
- highlightMatch &&
96
- this.options.colors.includes(highlightMatch[1])
97
- ) {
98
- return highlightMatch[1]
99
- }
100
- }
101
-
102
- // Check for legacy format with data-color attribute (hex value)
103
- const legacyColorAttr = element.getAttribute('data-color')
104
- if (legacyColorAttr) {
105
- const closestColor = getClosestNamedColor(
106
- legacyColorAttr,
107
- this.options.colors,
108
- highlightColorHexMap,
109
- legacyHighlightColorMap,
110
- )
111
- if (closestColor) {
112
- return closestColor
113
- }
114
- }
115
-
116
- // Try extracting from style attribute as fallback
117
- if (style) {
118
- const extractedColor = extractHighlightColorFromStyle(
119
- style,
120
- this.options.colors,
121
- )
122
- if (extractedColor) {
123
- return extractedColor
124
- }
125
- }
126
-
127
- return null
128
- },
129
- renderHTML: (attributes) => {
130
- if (
131
- !attributes.color ||
132
- !this.options.colors.includes(attributes.color)
133
- ) {
134
- return {}
135
- }
136
-
137
- return {
138
- style: `background-color: var(--prose-highlight-${attributes.color})`,
139
- }
140
- },
141
- },
142
- }
143
- },
144
-
145
- parseHTML() {
146
- return [
147
- {
148
- tag: 'mark',
149
- },
150
- ]
151
- },
152
-
153
- renderHTML({ HTMLAttributes }) {
154
- return [
155
- 'mark',
156
- mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
157
- 0,
158
- ]
159
- },
160
-
161
- addCommands() {
162
- return {
163
- setHighlightByName:
164
- (colorName) =>
165
- ({ chain, commands, editor, state }) => {
166
- // Validate that the color name is allowed
167
- if (!this.options.colors.includes(colorName)) {
168
- console.warn(
169
- `Highlight color "${colorName}" is not in the allowed colors list`,
170
- )
171
- return false
172
- }
173
-
174
- const { from, to, empty } = state.selection // Get original selection details
175
-
176
- let commandChain = chain()
177
- if (this.options.multicolor) {
178
- commandChain = commandChain.setMark(this.name, { color: colorName })
179
- } else {
180
- commandChain = commandChain.setMark(this.name)
181
- }
182
-
183
- if (!empty) {
184
- commandChain = commandChain
185
- .setTextSelection(to)
186
- .command(({ tr }) => {
187
- tr.setStoredMarks([])
188
- return true
189
- })
190
- }
191
-
192
- return commandChain.focus().run()
193
- },
194
- toggleHighlightByName:
195
- (colorName) =>
196
- ({ chain, commands, editor, state }) => {
197
- // Validate that the color name is allowed
198
- if (!this.options.colors.includes(colorName)) {
199
- console.warn(
200
- `Highlight color "${colorName}" is not in the allowed colors list`,
201
- )
202
- return false
203
- }
204
-
205
- const { to, empty } = state.selection // Get original selection details
206
- const highlightAttributes = this.options.multicolor
207
- ? { color: colorName }
208
- : undefined
209
-
210
- // Check if the mark is currently active with the given attributes *before* toggling
211
- // This helps determine if the toggle action will be setting or unsetting the mark.
212
- const isCurrentlyActive = editor.isActive(
213
- this.name,
214
- highlightAttributes,
215
- )
216
-
217
- let commandChain = chain().toggleMark(this.name, highlightAttributes)
218
-
219
- // If the selection was not empty AND the toggle action is about to *set* the mark
220
- // (i.e., it wasn't active before)
221
- if (!empty && !isCurrentlyActive) {
222
- commandChain = commandChain
223
- .setTextSelection(to)
224
- .command(({ tr }) => {
225
- tr.setStoredMarks([])
226
- return true
227
- })
228
- }
229
-
230
- return commandChain.focus().run()
231
- },
232
- unsetHighlight:
233
- () =>
234
- ({ commands }) => {
235
- return commands.unsetMark(this.name)
236
- },
237
- }
238
- },
239
- })
240
-
241
- export { NamedHighlightExtension as default }
@@ -1,31 +0,0 @@
1
- .ProseMirror {
2
- --prose-highlight-red: var(--red-100);
3
- --prose-highlight-blue: var(--blue-100);
4
- --prose-highlight-green: var(--green-100);
5
- --prose-highlight-yellow: var(--yellow-100);
6
- --prose-highlight-orange: var(--orange-100);
7
- --prose-highlight-purple: var(--purple-100);
8
- --prose-highlight-pink: var(--pink-100);
9
- --prose-highlight-gray: var(--gray-100);
10
- --prose-highlight-teal: var(--teal-100);
11
- --prose-highlight-cyan: var(--cyan-100);
12
- }
13
-
14
- [data-theme='dark'] .ProseMirror {
15
- --prose-highlight-red: var(--dark-red-800);
16
- --prose-highlight-blue: var(--dark-blue-800);
17
- --prose-highlight-green: var(--dark-green-800);
18
- --prose-highlight-yellow: var(--dark-yellow-800);
19
- --prose-highlight-orange: var(--dark-orange-800);
20
- --prose-highlight-purple: var(--dark-purple-800);
21
- --prose-highlight-pink: var(--dark-pink-800);
22
- --prose-highlight-gray: var(--dark-gray-800);
23
- --prose-highlight-teal: var(--dark-teal-800);
24
- --prose-highlight-cyan: var(--dark-cyan-800);
25
- }
26
-
27
- .ProseMirror mark {
28
- border-radius: 3px;
29
- padding: 0 2px;
30
- color: inherit;
31
- }
@@ -1,2 +0,0 @@
1
- export { NamedHighlightExtension, default } from './highlight-extension'
2
- export type { HighlightOptions } from './highlight-extension'
@@ -1,308 +0,0 @@
1
- <script setup lang="ts">
2
- // @ts-nocheck -- frozen v0 code, kept out of type-check (see tsconfig.app.json)
3
- import { ref, onMounted, computed, nextTick } from 'vue'
4
- import { NodeViewWrapper, nodeViewProps } from '@tiptap/vue-3'
5
- import { detectPlatform, calculateAspectRatio } from './utils'
6
- import { classIcon } from '../../classIcon'
7
- const LucideMoveDiagonal2 = classIcon('lucide-move-diagonal-2')
8
- const LucideAlignLeft = classIcon('lucide-align-left')
9
- const LucideAlignCenter = classIcon('lucide-align-center')
10
- const LucideAlignRight = classIcon('lucide-align-right')
11
- const props = defineProps(nodeViewProps)
12
-
13
- const iframeRef = ref<HTMLIFrameElement | null>(null)
14
- const containerRef = ref<HTMLDivElement | null>(null)
15
- const isResizing = ref(false)
16
- const startDragX = ref(0)
17
- const startWidth = ref(0)
18
- const originalAspectRatio = ref(9/16) // Default 16:9
19
- const isEditable = ref(false)
20
-
21
- function selectIframe() {
22
- props.editor.commands.setNodeSelection(props.getPos())
23
- }
24
-
25
- // Computed properties for styling and info
26
- const platformInfo = computed(() => {
27
- if (props.node.attrs.src) {
28
- const platform = detectPlatform(props.node.attrs.src)
29
- const aspectInfo = calculateAspectRatio(props.node.attrs.src)
30
- return {
31
- platform: platform?.name || 'Generic',
32
- aspectRatio: aspectInfo.ratio
33
- }
34
- }
35
- return { platform: 'Generic', aspectRatio: 9/16 }
36
- })
37
-
38
- const iframeStyles = computed(() => {
39
- const width = props.node.attrs.width || 640
40
- const height = props.node.attrs.height || (width * originalAspectRatio.value)
41
-
42
- return {
43
- width: `${width}px`,
44
- height: `${height}px`
45
- }
46
- })
47
-
48
- onMounted(() => {
49
- isEditable.value = props.editor.isEditable
50
-
51
- // Calculate aspect ratio from node attributes or URL
52
- if (props.node.attrs.aspectRatio) {
53
- originalAspectRatio.value = props.node.attrs.aspectRatio
54
- } else if (props.node.attrs.src) {
55
- const aspectInfo = calculateAspectRatio(props.node.attrs.src)
56
- originalAspectRatio.value = aspectInfo.ratio
57
-
58
- // Update node with calculated aspect ratio
59
- props.updateAttributes({ aspectRatio: aspectInfo.ratio })
60
- }
61
- })
62
-
63
- props.editor.on('update', () => {
64
- isEditable.value = props.editor.isEditable
65
- })
66
-
67
- function startResize(event: MouseEvent) {
68
- if (!isEditable.value) return
69
- selectIframe()
70
- isResizing.value = true
71
- startDragX.value = event.clientX
72
- startWidth.value = containerRef.value?.offsetWidth || props.node.attrs.width || 640
73
-
74
- // Use stored aspect ratio or calculate from current dimensions
75
- if (props.node.attrs.aspectRatio) {
76
- originalAspectRatio.value = props.node.attrs.aspectRatio
77
- } else {
78
- const width = props.node.attrs.width || startWidth.value
79
- const height = props.node.attrs.height || (width * originalAspectRatio.value)
80
- if (width && height) {
81
- originalAspectRatio.value = height / width
82
- }
83
- }
84
-
85
- window.addEventListener('mousemove', handleResize)
86
- window.addEventListener('mouseup', stopResize)
87
- document.body.style.cursor = 'ew-resize'
88
- }
89
-
90
- function handleResize(event: MouseEvent) {
91
- if (!isResizing.value || !iframeRef.value || !containerRef.value) return
92
-
93
- const editorElement = props.editor.view.dom
94
- const editorWidth = editorElement.clientWidth
95
-
96
- const deltaX = event.clientX - startDragX.value
97
- let newWidth = startWidth.value + deltaX
98
-
99
- // Add constraints (minimum width, maximum editor width with padding)
100
- const MIN_WIDTH = 200
101
- const PADDING = 40
102
- newWidth = Math.max(MIN_WIDTH, Math.min(newWidth, editorWidth - PADDING))
103
-
104
- const newHeight = newWidth * originalAspectRatio.value
105
-
106
- // Apply temporary styles for visual feedback
107
- iframeRef.value.style.width = `${newWidth}px`
108
- iframeRef.value.style.height = `${newHeight}px`
109
- containerRef.value.style.width = `${newWidth}px`
110
- }
111
-
112
- function stopResize() {
113
- if (!isResizing.value) return
114
-
115
- isResizing.value = false
116
- window.removeEventListener('mousemove', handleResize)
117
- window.removeEventListener('mouseup', stopResize)
118
- document.body.style.cursor = ''
119
-
120
- if (iframeRef.value && containerRef.value) {
121
- // Capture final dimensions while temporary styles are still applied
122
- const finalWidth = iframeRef.value.offsetWidth
123
- const finalHeight = iframeRef.value.offsetHeight
124
-
125
- // Update attributes
126
- props.updateAttributes({
127
- width: finalWidth,
128
- height: finalHeight,
129
- aspectRatio: originalAspectRatio.value
130
- })
131
-
132
- // Clear temporary styles immediately (like image extension)
133
- iframeRef.value.style.width = ''
134
- iframeRef.value.style.height = ''
135
- containerRef.value.style.width = ''
136
- }
137
- }
138
-
139
- function setAlignment(align: 'left' | 'center' | 'right') {
140
- props.updateAttributes({ align })
141
- }
142
-
143
- // Handle keyboard navigation
144
- function handleKeydown(event: KeyboardEvent) {
145
- if (event.key === 'Enter') {
146
- event.preventDefault()
147
- createParagraphAfterIframe()
148
- } else if (event.key === 'Escape' || event.key === 'ArrowDown') {
149
- event.preventDefault()
150
- setCursorAfterIframe()
151
- }
152
- if (event.key === 'ArrowUp') {
153
- event.preventDefault()
154
- setCursorBeforeIframe()
155
- }
156
- }
157
-
158
- function setCursorAt(pos: number) {
159
- props.editor.commands.focus()
160
- props.editor.chain().setTextSelection(pos).scrollIntoView().run()
161
- }
162
-
163
- function createParagraphAfterIframe() {
164
- const pos = props.getPos()
165
- props.editor.commands.focus()
166
- props.editor
167
- .chain()
168
- .setTextSelection(pos + 1)
169
- .createParagraphNear()
170
- .scrollIntoView()
171
- .run()
172
- }
173
-
174
- function setCursorAfterIframe() {
175
- const pos = props.getPos()
176
- setCursorAt(pos + 1)
177
- }
178
-
179
- function setCursorBeforeIframe() {
180
- const pos = props.getPos()
181
- setCursorAt(pos - 1)
182
- }
183
- </script>
184
-
185
- <template>
186
- <NodeViewWrapper>
187
- <div
188
- ref="containerRef"
189
- class="relative overflow-hidden not-prose my-6 rounded-6 block max-w-full focus:outline-none"
190
- :class="[
191
- { 'ring-2 ring-outline-gray-3 ring-offset-2': selected },
192
- node.attrs.align === 'center' ? 'mx-auto' : '',
193
- node.attrs.align === 'right' ? 'ml-auto mr-0' : '',
194
- node.attrs.align === 'left' ? 'mr-auto ml-0' : '',
195
- ]"
196
- :style="{
197
- width: node.attrs.width ? `${node.attrs.width}px` : 'auto',
198
- maxWidth: '100%'
199
- }"
200
- @keydown="handleKeydown"
201
- tabindex="0"
202
- >
203
- <div class="relative">
204
- <iframe
205
- v-if="node.attrs.src"
206
- ref="iframeRef"
207
- class="rounded-6 border-0 block max-w-full h-auto"
208
- :class="{
209
- 'pointer-events-none': isEditable && !props.node.attrs.interactive,
210
- }"
211
- :src="node.attrs.src"
212
- :style="iframeStyles"
213
- :title="node.attrs.title || ''"
214
- frameborder="0"
215
- allowfullscreen
216
- loading="lazy"
217
- referrerpolicy="no-referrer-when-downgrade"
218
- sandbox="allow-scripts allow-same-origin allow-popups allow-forms"
219
- @click.stop="selectIframe"
220
- />
221
-
222
- <!-- Transparent overlay for selection in edit mode -->
223
- <div
224
- v-if="isEditable && !props.node.attrs.interactive"
225
- class="absolute inset-0 cursor-pointer z-10"
226
- @click.stop="selectIframe"
227
- ></div>
228
-
229
- <!-- Controls overlay -->
230
- <div class="absolute bottom-2 right-2 flex items-center gap-2 z-20">
231
- <!-- Alignment Controls -->
232
- <div
233
- v-if="selected && isEditable"
234
- class="flex divide-x divide-ink-gray-6 rounded-5 bg-black/65"
235
- >
236
- <button
237
- @click.stop="setAlignment('left')"
238
- :class="[
239
- 'px-1.5 py-1 text-ink-gray-4 hover:text-white transition-colors duration-150',
240
- { 'text-white': node.attrs.align === 'left' }
241
- ]"
242
- title="Align Left"
243
- >
244
- <LucideAlignLeft class="size-4" />
245
- </button>
246
- <button
247
- @click.stop="setAlignment('center')"
248
- :class="[
249
- 'px-1.5 py-1 text-ink-gray-4 hover:text-white transition-colors duration-150',
250
- { 'text-white': node.attrs.align === 'center' }
251
- ]"
252
- title="Align Center"
253
- >
254
- <LucideAlignCenter class="size-4" />
255
- </button>
256
- <button
257
- @click.stop="setAlignment('right')"
258
- :class="[
259
- 'px-1.5 py-1 text-ink-gray-4 hover:text-white transition-colors duration-150',
260
- { 'text-white': node.attrs.align === 'right' }
261
- ]"
262
- title="Align Right"
263
- >
264
- <LucideAlignRight class="size-4" />
265
- </button>
266
- </div>
267
-
268
- <!-- Resize Handle -->
269
- <button
270
- v-if="selected && isEditable"
271
- class="cursor-nw-resize bg-black/65 rounded-5 p-1"
272
- @mousedown.prevent="startResize"
273
- title="Resize"
274
- >
275
- <LucideMoveDiagonal2 class="text-white size-4" />
276
- </button>
277
- </div>
278
-
279
-
280
- <!-- Loading state for new embeds -->
281
- <div
282
- v-if="!node.attrs.src"
283
- class="flex items-center justify-center bg-surface-gray-1 rounded-6 w-[640px] h-[360px]"
284
- >
285
- <div class="text-ink-gray-5 text-center">
286
- <div class="text-lg mb-1">🔗</div>
287
- <div class="text-sm">Loading embed...</div>
288
- </div>
289
- </div>
290
- </div>
291
-
292
- <!-- Caption/Title input -->
293
- <input
294
- v-if="(isEditable || node.attrs.title) && node.attrs.src"
295
- :value="node.attrs.title"
296
- class="w-full text-center bg-transparent text-sm text-ink-gray-6 h-7 border-0 mt-2 focus:outline-none focus:ring-0 placeholder-ink-gray-4 disabled:opacity-60"
297
- placeholder="Add caption"
298
- :disabled="!isEditable"
299
- @input="(e) => props.updateAttributes({ title: (e.target as HTMLInputElement).value })"
300
- @keydown="handleKeydown"
301
- />
302
- </div>
303
- </NodeViewWrapper>
304
- </template>
305
-
306
- <style scoped>
307
- /* Component-specific styles if needed */
308
- </style>