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
@@ -4,6 +4,10 @@
4
4
  * No DOM mutation of the live document and no ProseMirror dispatch — these are
5
5
  * unit-testable string/DOM-fragment transforms used by
6
6
  * `paste-image-controller.ts` and `content-paste-extension.ts`.
7
+ *
8
+ * Pasted HTML comes from any page the user copied from. It is parsed into an
9
+ * inert document (see {@link parseInert}), never into an element of the live
10
+ * page, where `<img onerror>` and similar handlers would run.
7
11
  */
8
12
  import { DOMParser, Slice } from '@tiptap/pm/model'
9
13
  import type { Node, Schema } from '@tiptap/pm/model'
@@ -21,9 +25,7 @@ export function normalizeFontSizePtToPx(html: string): string {
21
25
 
22
26
  /** True iff the HTML string contains at least one `<img>` element. */
23
27
  export function htmlContainsImage(html: string): boolean {
24
- const div = document.createElement('div')
25
- div.innerHTML = html
26
- return div.querySelector('img') !== null
28
+ return parseInert(html).querySelector('img') !== null
27
29
  }
28
30
 
29
31
  /**
@@ -32,9 +34,8 @@ export function htmlContainsImage(html: string): boolean {
32
34
  * so pasted code/pre content survives.
33
35
  */
34
36
  export function parseHtmlToSlice(html: string, schema: Schema): Slice {
35
- const div = document.createElement('div')
36
- div.innerHTML = normalizeFontSizePtToPx(html)
37
- return DOMParser.fromSchema(schema).parseSlice(div, {
37
+ const body = parseInert(normalizeFontSizePtToPx(html))
38
+ return DOMParser.fromSchema(schema).parseSlice(body, {
38
39
  preserveWhitespace: true,
39
40
  })
40
41
  }
@@ -69,3 +70,12 @@ export function collectImageNodes(
69
70
  })
70
71
  return images
71
72
  }
73
+
74
+ /**
75
+ * The `<body>` of `html` parsed by the browser's `DOMParser`. That document
76
+ * has no browsing context: it runs no scripts or event handlers and loads no
77
+ * images, so untrusted markup is safe to query and walk.
78
+ */
79
+ function parseInert(html: string): HTMLElement {
80
+ return new globalThis.DOMParser().parseFromString(html, 'text/html').body
81
+ }
@@ -3,6 +3,7 @@ import { computed, ref, toRaw, watch } from 'vue'
3
3
  import { NodeViewWrapper, nodeViewProps } from '@tiptap/vue-3'
4
4
  import MediaToolbar from '#molecules/editor/components/MediaToolbar.vue'
5
5
  import MediaResizeHandle from '#molecules/editor/components/MediaResizeHandle.vue'
6
+ import MediaResizeGuide from '#molecules/editor/components/MediaResizeGuide.vue'
6
7
  import { SELECTED_MEDIA_RING } from '#molecules/editor/components/media-node-view-utils'
7
8
  import { useNodeViewEditable } from '#molecules/editor/composables/useNodeViewEditable'
8
9
  import {
@@ -10,7 +11,11 @@ import {
10
11
  type ResizeEdge,
11
12
  } from '#molecules/editor/composables/useNodeViewResize'
12
13
  import { safeGetPos } from '#molecules/editor/extensions/shared/node-view'
13
- import { IFRAME_SANDBOX } from './iframe-allowlist'
14
+ import {
15
+ IFRAME_SANDBOX,
16
+ getIframeAllowlist,
17
+ validateIframeUrl,
18
+ } from './iframe-allowlist'
14
19
  import { openIframeInsertDialog } from './iframeInsertDialogController'
15
20
  import type { IframeAlign } from './iframe-commands'
16
21
 
@@ -46,10 +51,19 @@ const frameStyle = computed(() => {
46
51
 
47
52
  const sandbox = computed<string>(() => IFRAME_SANDBOX)
48
53
 
54
+ // JSON content and collaboration updates never pass the HTML parse rule, so
55
+ // the stored attr is untrusted here. Render only an allowed embed.
56
+ const safeSrc = computed<string | null>(() => {
57
+ const src = props.node.attrs.src
58
+ return validateIframeUrl(src, { allowlist: getIframeAllowlist(editor) })
59
+ ? src
60
+ : null
61
+ })
62
+
49
63
  const isInteractive = computed<boolean>(() => !!props.node.attrs.interactive)
50
64
  const overlayActive = computed(() => isEditable.value && !isInteractive.value)
51
65
 
52
- const { startResize } = useNodeViewResize(editor, {
66
+ const { guide, startResize } = useNodeViewResize(editor, {
53
67
  mediaEl: () => iframeRef.value,
54
68
  containerEl: () => containerRef.value,
55
69
  getAspectRatio: () => aspectRatio.value,
@@ -179,11 +193,11 @@ function commitCaption(event: Event): void {
179
193
  >
180
194
  <div class="relative">
181
195
  <iframe
182
- v-if="node.attrs.src"
196
+ v-if="safeSrc"
183
197
  ref="iframeRef"
184
198
  class="block h-auto max-w-full rounded-4 border-0"
185
199
  :class="{ 'pointer-events-none': overlayActive }"
186
- :src="node.attrs.src"
200
+ :src="safeSrc"
187
201
  :style="frameStyle"
188
202
  :title="node.attrs.title || ''"
189
203
  :sandbox="sandbox"
@@ -203,7 +217,7 @@ function commitCaption(event: Event): void {
203
217
 
204
218
  <!-- Shared media toolbar (caption / change link / align) -->
205
219
  <MediaToolbar
206
- v-if="node.attrs.src"
220
+ v-if="safeSrc"
207
221
  :node="node"
208
222
  media-type="embed"
209
223
  :is-editable="isEditable"
@@ -220,22 +234,27 @@ function commitCaption(event: Event): void {
220
234
  @resize-start="onResizeStart"
221
235
  @resize-keydown="onResizeKeydown"
222
236
  />
237
+ <MediaResizeGuide :guide="() => guide" />
223
238
 
224
- <!-- Placeholder while no src is set -->
239
+ <!-- Placeholder while no src is set, or when src is not allowed -->
225
240
  <div
226
- v-if="!node.attrs.src"
227
- class="flex h-[360px] w-[640px] items-center justify-center rounded-4 bg-surface-gray-1"
241
+ v-if="!safeSrc"
242
+ class="flex h-[360px] w-[640px] max-w-full items-center justify-center rounded-4 bg-surface-gray-1"
228
243
  >
229
244
  <div class="text-center text-ink-gray-5">
230
245
  <div class="mb-1 text-lg">🔗</div>
231
- <div class="text-sm">Loading embed…</div>
246
+ <div class="text-sm">
247
+ {{
248
+ node.attrs.src ? 'This embed is not allowed' : 'Loading embed…'
249
+ }}
250
+ </div>
232
251
  </div>
233
252
  </div>
234
253
  </div>
235
254
 
236
255
  <!-- Caption input (commits on blur / Enter) -->
237
256
  <input
238
- v-if="(node.attrs.title || showCaption) && node.attrs.src"
257
+ v-if="(node.attrs.title || showCaption) && safeSrc"
239
258
  :value="node.attrs.title"
240
259
  class="mt-2 h-7 w-full border-0 bg-transparent text-center text-sm text-ink-gray-6 placeholder-ink-gray-4 focus:outline-none focus:ring-0 disabled:opacity-60"
241
260
  placeholder="Add caption"
@@ -9,10 +9,8 @@
9
9
  * dot-boundary suffix — never substring).
10
10
  */
11
11
  import type { Editor } from '@tiptap/core'
12
- import {
13
- isSafeUrl,
14
- matchesHostname,
15
- } from '#molecules/editor/extensions/shared/url-safety'
12
+ import { isSafeUrl, matchesHostname } from '#utils/url-safety'
13
+ import { processEmbedUrl } from './iframe-embed-utils'
16
14
 
17
15
  /**
18
16
  * Hostnames (and their embed sub-hosts) we permit as iframe sources.
@@ -44,8 +42,8 @@ export const IFRAME_ALLOWLIST: readonly string[] = [
44
42
  * without it, YouTube's player throws SecurityError and renders a black box.
45
43
  * It does NOT grant the iframe our origin; cross-origin isolation from the
46
44
  * host still applies. The `allow-scripts + allow-same-origin` sandbox-escape
47
- * concern only exists for content served from OUR origin, which the
48
- * allowlist precludes (absolute http(s) URLs on external hosts only).
45
+ * concern only exists for content served from OUR origin, which
46
+ * {@link validateIframeUrl} refuses.
49
47
  */
50
48
  export const IFRAME_SANDBOX =
51
49
  'allow-scripts allow-same-origin allow-popups allow-forms allow-presentation' as const
@@ -86,23 +84,44 @@ export interface ValidateIframeUrlOptions {
86
84
  * True iff `url` is an absolute http(s) URL whose hostname is on the allowlist
87
85
  * (and not on an optional blocklist). Relative, bare, and unknown-scheme inputs
88
86
  * are rejected — there is no `startsWith('/')` escape hatch.
87
+ *
88
+ * This is the one check every iframe path shares: the HTML parse rule, the
89
+ * `src` attribute on render, the node view, paste, the dialog and commands.
89
90
  */
90
91
  export function validateIframeUrl(
91
- url: string,
92
+ url: unknown,
92
93
  options?: ValidateIframeUrlOptions,
93
- ): boolean {
94
+ ): url is string {
95
+ if (typeof url !== 'string') return false
94
96
  if (!isSafeUrl(url, { allowedSchemes: ['http', 'https'] })) return false
95
97
 
96
- let host: string
97
- try {
98
- host = new URL(url).hostname
99
- } catch {
100
- return false
101
- }
98
+ const parsed = new URL(url)
99
+ // IFRAME_SANDBOX keeps `allow-same-origin`, which is only safe for pages
100
+ // from another origin. Refuse our own, even if an app allowlists its host.
101
+ if (isOwnOrigin(parsed)) return false
102
102
 
103
103
  const blocklist = options?.blocklist
104
- if (blocklist?.length && matchesHostname(host, blocklist)) return false
104
+ if (blocklist?.length && matchesHostname(parsed.hostname, blocklist)) {
105
+ return false
106
+ }
105
107
 
106
108
  const allowlist = options?.allowlist ?? IFRAME_ALLOWLIST
107
- return matchesHostname(host, allowlist)
109
+ return matchesHostname(parsed.hostname, allowlist)
110
+ }
111
+
112
+ /**
113
+ * Rewrite incoming markup's `src` into its embed form, or `null` when the
114
+ * result is not an allowed embed.
115
+ */
116
+ export function sanitizeIframeSrc(
117
+ raw: string | null,
118
+ allowlist?: readonly string[],
119
+ ): string | null {
120
+ if (!raw) return null
121
+ const src = processEmbedUrl(raw)
122
+ return validateIframeUrl(src, { allowlist }) ? src : null
123
+ }
124
+
125
+ function isOwnOrigin(url: URL): boolean {
126
+ return typeof window !== 'undefined' && url.origin === window.location.origin
108
127
  }
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * Everything is side-effect-free and unit-testable.
14
14
  */
15
- import { matchesHostname } from '#molecules/editor/extensions/shared/url-safety'
15
+ import { matchesHostname } from '#utils/url-safety'
16
16
 
17
17
  const EDITOR_PADDING = 40
18
18
 
@@ -5,17 +5,21 @@
5
5
  * node view, and thin delegation to `iframe-commands` + `iframe-paste-handler`.
6
6
  *
7
7
  * Security posture (locked product decision):
8
- * - `src` is validated against the allowlist on LOAD (`parseHTML` `getAttrs`)
9
- * and on insert/paste — substring matching and the `startsWith('/')` escape
10
- * hatch are gone (see `iframe-allowlist.ts`).
8
+ * - `src` is checked by {@link validateIframeUrl} wherever it is read or
9
+ * written: HTML parse, `renderHTML`, the node view, insert and paste.
10
+ * JSON content and collaboration updates skip HTML parsing, so the render
11
+ * side must never trust the stored attr.
11
12
  * - rendering always forces the {@link IFRAME_SANDBOX} value, so incoming
12
13
  * markup can never widen the sandbox beyond it.
13
14
  */
14
15
  import { Node, mergeAttributes } from '@tiptap/core'
15
16
  import { VueNodeViewRenderer } from '@tiptap/vue-3'
16
17
  import IframeNodeView from './IframeNodeView.vue'
17
- import { IFRAME_SANDBOX, validateIframeUrl } from './iframe-allowlist'
18
- import { processEmbedUrl } from './iframe-embed-utils'
18
+ import {
19
+ IFRAME_SANDBOX,
20
+ sanitizeIframeSrc,
21
+ validateIframeUrl,
22
+ } from './iframe-allowlist'
19
23
  import { buildIframeCommands, type IframeAlign } from './iframe-commands'
20
24
  import { createIframePastePlugin } from './iframe-paste-handler'
21
25
 
@@ -59,8 +63,18 @@ export const IframeExtension = Node.create<IframeOptions>({
59
63
  return {
60
64
  src: {
61
65
  default: null,
62
- parseHTML: (element) => element.getAttribute('src'),
63
- renderHTML: (attributes) => ({ src: attributes.src }),
66
+ parseHTML: (element) =>
67
+ sanitizeIframeSrc(
68
+ element.getAttribute('src'),
69
+ this.options.allowlist,
70
+ ),
71
+ renderHTML: (attributes) => ({
72
+ src: validateIframeUrl(attributes.src, {
73
+ allowlist: this.options.allowlist,
74
+ })
75
+ ? attributes.src
76
+ : null,
77
+ }),
64
78
  },
65
79
  width: {
66
80
  default: null,
@@ -126,29 +140,15 @@ export const IframeExtension = Node.create<IframeOptions>({
126
140
  return [
127
141
  {
128
142
  tag: 'iframe[src]',
129
- // Validate on LOAD: reject sources not on the allowlist so untrusted
130
- // pasted/loaded HTML cannot smuggle in an arbitrary embed.
131
- getAttrs: (element) => {
132
- const raw = (element as HTMLElement).getAttribute('src')
133
- if (!raw) return false
134
- const src = processEmbedUrl(raw)
135
- if (!validateIframeUrl(src, { allowlist: this.options.allowlist })) {
136
- return false
137
- }
138
- return {
139
- src,
140
- width: parseDimension(
141
- (element as HTMLElement).getAttribute('width'),
142
- ),
143
- height: parseDimension(
144
- (element as HTMLElement).getAttribute('height'),
145
- ),
146
- title: (element as HTMLElement).getAttribute('title') || null,
147
- align: normalizeAlign(
148
- (element as HTMLElement).getAttribute('data-align'),
149
- ),
150
- }
151
- },
143
+ // Drop the node when `src` is not an allowed embed. The `src`
144
+ // attribute's own parseHTML fills in the rewritten URL.
145
+ getAttrs: (element) =>
146
+ sanitizeIframeSrc(
147
+ (element as HTMLElement).getAttribute('src'),
148
+ this.options.allowlist,
149
+ )
150
+ ? null
151
+ : false,
152
152
  },
153
153
  ]
154
154
  },
@@ -69,7 +69,7 @@ import { onBeforeUnmount, onMounted, ref, useTemplateRef, nextTick } from 'vue'
69
69
  import Button from '#components/Button/Button.vue'
70
70
  import TextInput from '#components/TextInput/TextInput.vue'
71
71
  import EditorPopover from '#molecules/editor/components/EditorPopover.vue'
72
- import { isSafeUrl } from '#molecules/editor/extensions/shared/url-safety'
72
+ import { isSafeUrl } from '#utils/url-safety'
73
73
 
74
74
  const props = defineProps<{
75
75
  href: string
@@ -1,7 +1,7 @@
1
1
  import type { Editor } from '@tiptap/core'
2
2
  import type { MarkType } from '@tiptap/pm/model'
3
3
  import { Plugin, PluginKey } from '@tiptap/pm/state'
4
- import { isSafeUrl } from '#molecules/editor/extensions/shared/url-safety'
4
+ import { isSafeUrl } from '#utils/url-safety'
5
5
 
6
6
  /**
7
7
  * Options for {@link linkPastePlugin}.
@@ -21,7 +21,7 @@
21
21
  import type { Editor } from '@tiptap/core'
22
22
  import fileToBase64 from '#utils/file-to-base64'
23
23
  import { fileSizeLimitMessage } from '#utils/fileSize'
24
- import { isSafeUrl } from '#molecules/editor/extensions/shared/url-safety'
24
+ import { isSafeUrl } from '#utils/url-safety'
25
25
  import { findNodeByUploadId } from '#molecules/editor/extensions/shared/node-view'
26
26
  import {
27
27
  deleteLocalFile,
@@ -186,12 +186,18 @@ export function useEditor(
186
186
 
187
187
  applyingExternalUpdate = true
188
188
  try {
189
- editor.value.commands.setContent(
190
- content ?? '',
191
- format === 'markdown'
192
- ? { emitUpdate: false, contentType: 'markdown' }
193
- : { emitUpdate: false },
194
- )
189
+ // Kept out of history: a document loaded from outside is not an edit,
190
+ // so undo must not revert it (e.g. back to empty before a draft loaded).
191
+ editor.value
192
+ .chain()
193
+ .setContent(
194
+ content ?? '',
195
+ format === 'markdown'
196
+ ? { emitUpdate: false, contentType: 'markdown' }
197
+ : { emitUpdate: false },
198
+ )
199
+ .setMeta('addToHistory', false)
200
+ .run()
195
201
  // Same reason as at construction: while unmounted there are no
196
202
  // plugins, so nothing normalizes what `setContent` just parsed.
197
203
  // No-op when there is nothing to join.
@@ -12,7 +12,13 @@
12
12
  <slot />
13
13
  </ListRowBase>
14
14
  </RouterLink>
15
- <ListRowBase v-else-if="href" tag="a" :href="href" :value="value" @click="onClick">
15
+ <ListRowBase
16
+ v-else-if="href"
17
+ tag="a"
18
+ :href="safeHref(href)"
19
+ :value="value"
20
+ @click="onClick"
21
+ >
16
22
  <slot />
17
23
  </ListRowBase>
18
24
  <ListRowBase
@@ -29,6 +35,7 @@
29
35
  import { RouterLink } from 'vue-router'
30
36
  import { useListContext } from './list-context'
31
37
  import ListRowBase from './ListRowBase.vue'
38
+ import { safeHref } from '../../utils/url-safety'
32
39
  import type { ListRowProps } from './types'
33
40
 
34
41
  const props = defineProps<ListRowProps>()
@@ -7,9 +7,9 @@ import {
7
7
  type Ref,
8
8
  } from 'vue'
9
9
  import { moduleSingleton } from './moduleSingleton'
10
+ import { useId } from './useId'
10
11
  import Dialog from '../components/Dialog/Dialog.vue'
11
12
  import { Button } from '../components/Button'
12
- import FormControl from '../components/FormControl/FormControl.vue'
13
13
  import ErrorMessage from '../components/ErrorMessage/ErrorMessage.vue'
14
14
  import type { DialogSize, DialogTheme } from '../components/Dialog/types'
15
15
  import type { ButtonProps } from '../components/Button'
@@ -445,6 +445,17 @@ export function confirm(args: ConfirmArgs): DialogHandle {
445
445
 
446
446
  // -- prompt --------------------------------------------------------------
447
447
 
448
+ // FormControl imports every input type (date, time, combobox, select, …), and
449
+ // this module is reachable from the package index, so a static import would
450
+ // put all of them in every app's first download. Load it on the first prompt.
451
+ let formControl: Promise<Component> | undefined
452
+ function loadFormControl() {
453
+ formControl ??= import('../components/FormControl/FormControl.vue').then(
454
+ (module) => module.default,
455
+ )
456
+ return formControl
457
+ }
458
+
448
459
  // Initial value for a prompt field. Checkbox defaults to false; everything
449
460
  // else (text/textarea/select/combobox) defaults to an empty string so the
450
461
  // `required` check has something concrete to compare against.
@@ -551,8 +562,8 @@ export function prompt(args: PromptArgs): DialogHandle {
551
562
  if (state.loading) return
552
563
  const missing = checkRequired()
553
564
  if (missing) {
554
- // Match the previous behavior — silently no-op so HTML5 required UI
555
- // can take over via the underlying FormControl.
565
+ // Required fields are checked here because the form is `novalidate`.
566
+ // An empty required field blocks submit without a message.
556
567
  return
557
568
  }
558
569
  state.loading = true
@@ -580,6 +591,14 @@ export function prompt(args: PromptArgs): DialogHandle {
580
591
  const resolvedIcon = resolveIcon(args.theme, args.icon)
581
592
  const buttonTheme = themeToButtonTheme(args.theme)
582
593
 
594
+ const autofocusField = args.fields.find(
595
+ (field) =>
596
+ !field.type || field.type === 'text' || field.type === 'textarea',
597
+ )
598
+
599
+ // Set before the dialog joins the stack, at the end of this function.
600
+ let FormControl: Component
601
+
583
602
  const renderField = (field: PromptField) => {
584
603
  const onUpdate = (val: any) => {
585
604
  values[field.name] = val
@@ -609,6 +628,7 @@ export function prompt(args: PromptArgs): DialogHandle {
609
628
  label: field.label,
610
629
  description: field.description,
611
630
  type: (field.type as any) || 'text',
631
+ autofocus: field === autofocusField || undefined,
612
632
  required: field.required,
613
633
  placeholder: field.placeholder,
614
634
  options,
@@ -637,6 +657,7 @@ export function prompt(args: PromptArgs): DialogHandle {
637
657
  const component = defineComponent({
638
658
  name: 'ImperativePromptDialog',
639
659
  setup() {
660
+ const formId = useId()
640
661
  return () =>
641
662
  h(
642
663
  Dialog,
@@ -655,17 +676,31 @@ export function prompt(args: PromptArgs): DialogHandle {
655
676
  },
656
677
  {
657
678
  default: () =>
658
- h('div', { class: 'space-y-3' }, [
659
- args.message
660
- ? h(
661
- 'p',
662
- { class: 'text-p-base text-ink-gray-7' },
663
- args.message,
664
- )
665
- : null,
666
- ...args.fields.map(renderField),
667
- state.error ? h(ErrorMessage, { message: state.error }) : null,
668
- ]),
679
+ h(
680
+ 'form',
681
+ {
682
+ id: formId,
683
+ class: 'space-y-3',
684
+ novalidate: true,
685
+ onSubmit: (event: Event) => {
686
+ event.preventDefault()
687
+ onSubmit()
688
+ },
689
+ },
690
+ [
691
+ args.message
692
+ ? h(
693
+ 'p',
694
+ { class: 'text-p-base text-ink-gray-7' },
695
+ args.message,
696
+ )
697
+ : null,
698
+ ...args.fields.map(renderField),
699
+ state.error
700
+ ? h(ErrorMessage, { message: state.error })
701
+ : null,
702
+ ],
703
+ ),
669
704
  actions: () =>
670
705
  h('div', { class: 'flex flex-row-reverse gap-2' }, [
671
706
  h(Button, {
@@ -673,7 +708,8 @@ export function prompt(args: PromptArgs): DialogHandle {
673
708
  variant: 'solid',
674
709
  theme: buttonTheme,
675
710
  loading: state.loading,
676
- onClick: onSubmit,
711
+ type: 'submit',
712
+ form: formId,
677
713
  }),
678
714
  h(Button, {
679
715
  label: args.cancelLabel || 'Cancel',
@@ -687,7 +723,12 @@ export function prompt(args: PromptArgs): DialogHandle {
687
723
  },
688
724
  })
689
725
 
690
- assignedId = add(component)
726
+ // Join the stack only once FormControl has loaded, so the dialog's first
727
+ // frame already holds its fields. A dialog closed before then never shows.
728
+ loadFormControl().then((loaded) => {
729
+ FormControl = loaded
730
+ if (state.open) assignedId = add(component)
731
+ })
691
732
  return { close }
692
733
  }
693
734
 
@@ -1,27 +1,39 @@
1
1
  /**
2
- * Shared URL-safety primitives for editor extensions.
2
+ * Shared URL-safety primitives for components and the editor.
3
3
  *
4
- * Two concerns, kept deliberately small and pure:
5
- * 1. `isSafeUrl` — does a string parse to an absolute URL with an allowed scheme?
6
- * 2. `matchesHostname` — exact-or-dot-boundary host allowlist matching.
4
+ * 1. `safeHref` — keep a link `href` only when its scheme is safe.
5
+ * 2. `isSafeUrl` — does a string parse to an absolute URL with an allowed scheme?
6
+ * 3. `matchesHostname` — exact-or-dot-boundary host allowlist matching.
7
7
  *
8
- * These replace two long-standing holes in the legacy iframe/link code:
9
- * - the `domain.includes(allowed)` substring check (so `youtube.com.evil.com`
10
- * matched `youtube.com`), and
11
- * - the `url.startsWith('/')` blanket allow of any relative/bare string.
12
- *
13
- * NOTE: platform embed *transformation* (youtube /shorts + youtu.be query
14
- * params, vimeo unlisted hash, codepen, codesandbox, figma /file//proto//board,
15
- * google docs/drive, notion) is NOT done here — that lives in the iframe
16
- * cluster's embed utils. This module only decides whether a host is on an
17
- * allowlist and whether a URL is well-formed + scheme-safe, which is the
18
- * gate every one of those platforms must pass first.
8
+ * Every check uses the platform `URL` parser rather than a regex, so it sees
9
+ * a URL the way the browser will: `JaVaScRiPt:`, leading control characters
10
+ * and tabs inside the scheme all normalise to `javascript:` and fail.
11
+ */
12
+
13
+ /** Schemes a link may navigate to. Relative URLs are always allowed. */
14
+ const LINK_SCHEMES: readonly string[] = ['http', 'https', 'mailto', 'tel']
15
+
16
+ // Resolves relative links so only the scheme is checked. Never navigated to.
17
+ const RELATIVE_BASE = 'https://relative.invalid/'
18
+
19
+ /**
20
+ * `href` when it is a string that is relative or uses a link scheme (http,
21
+ * https, mailto, tel), otherwise `undefined`. Use it wherever an `href` comes
22
+ * from data, so a `javascript:` or `data:` URL never reaches an anchor.
19
23
  */
24
+ export function safeHref(href: unknown): string | undefined {
25
+ if (typeof href !== 'string' || !href) return undefined
26
+ const safe = isSafeUrl(href, {
27
+ allowedSchemes: LINK_SCHEMES,
28
+ base: RELATIVE_BASE,
29
+ })
30
+ return safe ? href : undefined
31
+ }
20
32
 
21
33
  /** Options for {@link isSafeUrl}. */
22
34
  export interface SafeUrlOptions {
23
35
  /** Schemes allowed (without the trailing colon). Defaults to `['http', 'https']`. */
24
- allowedSchemes?: string[]
36
+ allowedSchemes?: readonly string[]
25
37
  /**
26
38
  * Optional base to resolve relative URLs against (e.g. `window.location.origin`).
27
39
  * A server-relative `file_url` like `/files/x.png` resolves to an http(s) URL
@@ -49,11 +49,11 @@ export const content = [
49
49
  glob('experimental/Accordion/**/*.{vue,js,ts,jsx,tsx}'),
50
50
  glob('experimental/FloatingWindow/**/*.{vue,js,ts,jsx,tsx}'),
51
51
  glob('experimental/MultiEmailInput/**/*.{vue,js,ts,jsx,tsx}'),
52
+ glob('experimental/Stepper/**/*.{vue,js,ts,jsx,tsx}'),
52
53
  glob('experimental/Calendar/**/*.{vue,js,ts,jsx,tsx}'),
53
54
  glob('experimental/Charts/**/*.{vue,js,ts,jsx,tsx}'),
54
55
  glob('experimental/CommandPalette/**/*.{vue,js,ts,jsx,tsx}'),
55
56
  glob('experimental/ListView/**/*.{vue,js,ts,jsx,tsx}'),
56
- glob('experimental/TextEditor/**/*.{vue,js,ts,jsx,tsx}'),
57
57
  glob('experimental/ThemeSwitcher/**/*.{vue,js,ts,jsx,tsx}'),
58
58
  glob('experimental/SpriteIcons/**/*.{vue,js,ts,jsx,tsx}'),
59
59
  glob('vitepress/**/*.{vue,js,ts}'),
@@ -198,6 +198,26 @@ let darkCheckboxStyles = {
198
198
  },
199
199
  }
200
200
 
201
+ // Tailwind's `truncate` sets `overflow: hidden`, which also clips vertically at
202
+ // the line box, so a tight line height cuts off descenders. Here it clips only
203
+ // horizontally. `overflow-x: clip` does not let a flex or grid item shrink below
204
+ // its content as `hidden` did, so the min sizes are set too. Tailwind's
205
+ // `textOverflow` plugin owns all of these classes, so it is disabled below and
206
+ // they are defined here, in the component layer, where utilities on the element
207
+ // win.
208
+ const textOverflowStyles = {
209
+ '.truncate': {
210
+ overflowX: 'clip',
211
+ textOverflow: 'ellipsis',
212
+ whiteSpace: 'nowrap',
213
+ minWidth: '0',
214
+ minHeight: '0',
215
+ },
216
+ '.text-ellipsis': { textOverflow: 'ellipsis' },
217
+ '.overflow-ellipsis': { textOverflow: 'ellipsis' },
218
+ '.text-clip': { textOverflow: 'clip' },
219
+ }
220
+
201
221
  export default plugin(
202
222
  function ({ addBase, addComponents, matchUtilities, theme }) {
203
223
  // tokens.js keys the variables by theme; the selector each theme lands on
@@ -215,6 +235,7 @@ export default plugin(
215
235
  addComponents(componentStyles)
216
236
  addComponents(buildTextStyleUtilities())
217
237
  addComponents(buildFocusRingUtilities())
238
+ addComponents(textOverflowStyles)
218
239
  // Authoring sugar for the list-family styling hooks (frappe-ui/list),
219
240
  // on the spacing scale with variants and arbitrary values:
220
241
  // `max-sm:list-gap-3` instead of `max-sm:[--list-gap:0.75rem]`.
@@ -227,6 +248,7 @@ export default plugin(
227
248
  )
228
249
  },
229
250
  {
251
+ corePlugins: { textOverflow: false },
230
252
  theme: {
231
253
  colors: colorPalette,
232
254
  borderRadius: buildRadiusConfig(),