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.
- package/experimental/Calendar/CalendarEventRow.vue +0 -4
- package/experimental/Calendar/calendarUtils.ts +33 -21
- package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
- package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
- package/experimental/MultiEmailInput/types.ts +12 -3
- package/experimental/SpriteIcons/IconPicker.vue +2 -1
- package/experimental/Stepper/StepIndicator.vue +129 -0
- package/experimental/Stepper/Stepper.api.md +117 -0
- package/experimental/Stepper/Stepper.md +95 -0
- package/experimental/Stepper/Stepper.vue +82 -0
- package/experimental/Stepper/StepperHorizontal.vue +93 -0
- package/experimental/Stepper/StepperVertical.vue +291 -0
- package/experimental/Stepper/index.ts +11 -0
- package/experimental/Stepper/resolve.ts +87 -0
- package/experimental/Stepper/types.ts +89 -0
- package/experimental.ts +2 -21
- package/package.json +1 -3
- package/src/charts/CalendarHeatmapChart.vue +353 -0
- package/src/charts/DonutChart.vue +34 -58
- package/src/charts/HeatmapChart.vue +26 -64
- package/src/charts/NumberCard.vue +62 -7
- package/src/charts/PercentageBarChart.vue +243 -0
- package/src/charts/SankeyChart.vue +14 -11
- package/src/charts/ScatterChart.vue +24 -20
- package/src/charts/axisChartCommon.ts +182 -18
- package/src/charts/axisFormat.ts +8 -3
- package/src/charts/calendarHeatmapOptions.ts +604 -0
- package/src/charts/colorMath.ts +26 -0
- package/src/charts/components/ChartContainer.vue +63 -53
- package/src/charts/components/ChartLegend.vue +216 -24
- package/src/charts/components/ChartScale.vue +85 -0
- package/src/charts/core/dataLabelFit.ts +45 -6
- package/src/charts/core/useAxisChart.ts +36 -19
- package/src/charts/core/useChart.ts +6 -1
- package/src/charts/core/usePlotKeyboard.ts +13 -2
- package/src/charts/docs/BarChart.md +11 -3
- package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
- package/src/charts/docs/CalendarHeatmapChart.md +33 -0
- package/src/charts/docs/ChartContainer.api.md +6 -0
- package/src/charts/docs/ChartLegend.api.md +1 -1
- package/src/charts/docs/ChartLegend.md +25 -3
- package/src/charts/docs/DonutChart.api.md +12 -0
- package/src/charts/docs/DonutChart.md +17 -0
- package/src/charts/docs/HeatmapChart.api.md +1 -1
- package/src/charts/docs/LineChart.md +5 -3
- package/src/charts/docs/NumberCard.api.md +6 -0
- package/src/charts/docs/NumberCard.md +6 -0
- package/src/charts/docs/Overview.md +13 -6
- package/src/charts/docs/PercentageBarChart.api.md +148 -0
- package/src/charts/docs/PercentageBarChart.md +42 -0
- package/src/charts/docs/ScatterChart.md +2 -3
- package/src/charts/donutChartOptions.ts +22 -130
- package/src/charts/format.ts +4 -1
- package/src/charts/heatmapOptions.ts +17 -12
- package/src/charts/hiddenSeries.ts +8 -3
- package/src/charts/index.ts +12 -0
- package/src/charts/legendOverflow.ts +40 -0
- package/src/charts/numberCardFormat.ts +19 -13
- package/src/charts/referenceLines.ts +2 -1
- package/src/charts/scatterOptions.ts +16 -3
- package/src/charts/seriesData.ts +8 -3
- package/src/charts/slices.ts +228 -0
- package/src/charts/tokens.ts +99 -0
- package/src/charts/types.ts +318 -9
- package/src/components/Avatar/Avatar.md +27 -2
- package/src/components/Avatar/Avatar.vue +29 -12
- package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
- package/src/components/Combobox/Combobox.vue +9 -2
- package/src/components/Combobox/ComboboxResults.vue +6 -1
- package/src/components/Combobox/utils.ts +2 -1
- package/src/components/DatePicker/DatePicker.md +7 -0
- package/src/components/DatePicker/DatePicker.vue +6 -0
- package/src/components/DatePicker/DateTimePicker.vue +6 -0
- package/src/components/DatePicker/composables.ts +18 -1
- package/src/components/DatePicker/utils.ts +53 -0
- package/src/components/Dialog/Dialog.md +3 -1
- package/src/components/Duration/Duration.api.md +16 -3
- package/src/components/Duration/Duration.md +21 -0
- package/src/components/Duration/Duration.vue +29 -8
- package/src/components/Duration/duration.ts +105 -44
- package/src/components/Duration/index.ts +1 -0
- package/src/components/Duration/types.ts +30 -1
- package/src/components/HoverCard/HoverCard.vue +21 -5
- package/src/components/Menu/utils.ts +3 -2
- package/src/components/MobileNav/MobileNavItem.vue +3 -22
- package/src/components/MultiSelect/MultiSelect.api.md +5 -0
- package/src/components/MultiSelect/MultiSelect.vue +34 -0
- package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
- package/src/components/MultiSelect/types.ts +6 -0
- package/src/components/Select/Select.vue +4 -4
- package/src/components/Select/utils.ts +1 -0
- package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
- package/src/components/SettingsDialog/SettingsDialog.md +2 -1
- package/src/components/SettingsDialog/SettingsRow.vue +12 -2
- package/src/components/Sidebar/SidebarItem.vue +3 -33
- package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
- package/src/components/Switch/Switch.vue +3 -3
- package/src/components/Tooltip/Tooltip.vue +8 -0
- package/src/components/shared/deferredTrigger.ts +174 -0
- package/src/components/shared/navLink.ts +45 -0
- package/src/components/shared/selection/utils.ts +8 -1
- package/src/data-fetching/useCall/useCall.ts +25 -26
- package/src/data-fetching/useFrappeFetch.ts +48 -2
- package/src/data-fetching/useList/useList.ts +11 -3
- package/src/data-fetching/utils.ts +15 -1
- package/src/molecules/editor/components/MediaNodeView.vue +10 -1
- package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
- package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
- package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
- package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
- package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
- package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
- package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
- package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
- package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
- package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
- package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
- package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
- package/src/molecules/editor/useEditor.ts +12 -6
- package/src/molecules/list/ListRow.vue +8 -1
- package/src/utils/dialog.ts +57 -16
- package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
- package/tailwind/content.js +1 -1
- package/tailwind/plugin.js +22 -0
- package/vite/README.md +5 -3
- package/vite/codeLanguages.js +41 -17
- package/vite/doctypeInterfaceGenerator.js +52 -39
- package/vitepress/index.node.ts +0 -2
- package/experimental/TextEditor/TextEditor.api.md +0 -161
- package/experimental/TextEditor/TextEditor.vue +0 -298
- package/experimental/TextEditor/classIcon.ts +0 -21
- package/experimental/TextEditor/commands.js +0 -344
- package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
- package/experimental/TextEditor/components/FontColor.vue +0 -153
- package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
- package/experimental/TextEditor/components/InsertImage.vue +0 -54
- package/experimental/TextEditor/components/InsertLink.vue +0 -13
- package/experimental/TextEditor/components/InsertVideo.vue +0 -14
- package/experimental/TextEditor/components/LinkPopup.vue +0 -99
- package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
- package/experimental/TextEditor/components/MentionList.vue +0 -95
- package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
- package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
- package/experimental/TextEditor/components/index.js +0 -0
- package/experimental/TextEditor/extensions/code-block.ts +0 -119
- package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
- package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
- package/experimental/TextEditor/extensions/color/index.ts +0 -2
- package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
- package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
- package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
- package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
- package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
- package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
- package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
- package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
- package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
- package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
- package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
- package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
- package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
- package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
- package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
- package/experimental/TextEditor/extensions/image/index.ts +0 -5
- package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
- package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
- package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
- package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
- package/experimental/TextEditor/extensions/link/index.ts +0 -1
- package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
- package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
- package/experimental/TextEditor/extensions/mention/index.ts +0 -1
- package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
- package/experimental/TextEditor/extensions/mention/style.css +0 -11
- package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
- package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
- package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
- package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
- package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
- package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
- package/experimental/TextEditor/extensions/tag/index.ts +0 -1
- package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
- package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
- package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
- package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
- package/experimental/TextEditor/extensions/video-extension.ts +0 -653
- package/experimental/TextEditor/hljs-github.css +0 -197
- package/experimental/TextEditor/index.ts +0 -21
- package/experimental/TextEditor/style.css +0 -190
- package/experimental/TextEditor/types.ts +0 -72
- package/experimental/TextEditor/utils.js +0 -11
- 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
|
-
|
|
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
|
|
36
|
-
|
|
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 {
|
|
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="
|
|
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="
|
|
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="
|
|
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="!
|
|
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">
|
|
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) &&
|
|
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
|
-
|
|
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
|
|
48
|
-
*
|
|
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:
|
|
92
|
+
url: unknown,
|
|
92
93
|
options?: ValidateIframeUrlOptions,
|
|
93
|
-
):
|
|
94
|
+
): url is string {
|
|
95
|
+
if (typeof url !== 'string') return false
|
|
94
96
|
if (!isSafeUrl(url, { allowedSchemes: ['http', 'https'] })) return false
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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(
|
|
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(
|
|
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
|
}
|
|
@@ -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
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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 {
|
|
18
|
-
|
|
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) =>
|
|
63
|
-
|
|
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
|
-
//
|
|
130
|
-
//
|
|
131
|
-
getAttrs: (element) =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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 '#
|
|
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 '#
|
|
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 '#
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
|
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>()
|
package/src/utils/dialog.ts
CHANGED
|
@@ -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
|
-
//
|
|
555
|
-
//
|
|
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(
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2
|
+
* Shared URL-safety primitives for components and the editor.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
package/tailwind/content.js
CHANGED
|
@@ -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}'),
|
package/tailwind/plugin.js
CHANGED
|
@@ -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(),
|