frappe-ui 1.1.0 → 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/CommandPalette/CommandPaletteItem.vue +9 -1
- package/experimental/SpriteIcons/IconPicker.vue +2 -1
- package/experimental.ts +0 -21
- package/package.json +1 -3
- package/src/components/Breadcrumbs/Breadcrumbs.vue +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/HoverCard/HoverCard.vue +21 -5
- package/src/components/MobileNav/MobileNavItem.vue +3 -22
- 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/Tooltip/Tooltip.vue +8 -0
- package/src/components/shared/deferredTrigger.ts +174 -0
- package/src/components/shared/navLink.ts +45 -0
- 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 +26 -9
- 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/list/ListRow.vue +8 -1
- package/src/utils/dialog.ts +20 -2
- package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
- package/tailwind/content.js +0 -1
- package/tailwind/plugin.js +22 -0
- 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
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { getCurrentInstance, ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defers an overlay's popup machinery (reka root, trigger, portal) until its
|
|
5
|
+
* trigger is first hovered or focused.
|
|
6
|
+
*
|
|
7
|
+
* Until then the overlay renders its trigger alone through reka's `Slot`,
|
|
8
|
+
* with the data attributes reka's closed trigger carries, so the DOM is the
|
|
9
|
+
* same and nothing shifts. On the first hover or focus the overlay mounts in
|
|
10
|
+
* full and the event is sent again to the new trigger, so reka opens the
|
|
11
|
+
* popup with its usual delay, as if it had been mounted all along.
|
|
12
|
+
*
|
|
13
|
+
* The shell listens for what the reka trigger of that `kind` opens on, so it
|
|
14
|
+
* mounts in the same cases. Touch screens do not hover: there a tooltip never
|
|
15
|
+
* mounts, and a hover card mounts only when a tap focuses its trigger.
|
|
16
|
+
*
|
|
17
|
+
* Mounting replaces the trigger element, because its ancestors change from
|
|
18
|
+
* `Slot` to reka's root and trigger. Focus and text selection inside the
|
|
19
|
+
* trigger move to the new element.
|
|
20
|
+
*
|
|
21
|
+
* Call it from the overlay's `setup`, and render the full overlay as its root
|
|
22
|
+
* once `mounted` is true.
|
|
23
|
+
*/
|
|
24
|
+
export function useDeferredTrigger(kind: 'tooltip' | 'hoverCard') {
|
|
25
|
+
const instance = getCurrentInstance()!
|
|
26
|
+
const mounted = ref(false)
|
|
27
|
+
// Reka's tooltip ignores focus that comes from a press (a click or a tap),
|
|
28
|
+
// so a pressed tooltip trigger does not mount either. Its hover card opens
|
|
29
|
+
// on any focus.
|
|
30
|
+
let pressed = false
|
|
31
|
+
|
|
32
|
+
function mount(event?: Event) {
|
|
33
|
+
if (mounted.value) return
|
|
34
|
+
mounted.value = true
|
|
35
|
+
|
|
36
|
+
const shell = event?.currentTarget
|
|
37
|
+
if (!event || !(shell instanceof Element)) return
|
|
38
|
+
const focus = captureFocus(shell)
|
|
39
|
+
|
|
40
|
+
// Render now rather than on the next tick, so reka starts its hover-delay
|
|
41
|
+
// timer in the same task as the real event, as it did when it was mounted
|
|
42
|
+
// from the start. Tests that hover and then advance a fake clock rely on it.
|
|
43
|
+
instance.update()
|
|
44
|
+
const trigger = firstElement(instance.subTree.el)
|
|
45
|
+
if (!trigger) return
|
|
46
|
+
const gotFocus = receivesEvent(trigger, 'focus', () =>
|
|
47
|
+
focus?.restore(trigger),
|
|
48
|
+
)
|
|
49
|
+
replay(event, trigger, gotFocus)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function onPointer(event: Event) {
|
|
53
|
+
if ((event as Partial<PointerEvent>).pointerType !== 'touch') mount(event)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function onFocus(event: Event) {
|
|
57
|
+
if (!pressed) mount(event)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function onPointerdown() {
|
|
61
|
+
if (kind !== 'tooltip') return
|
|
62
|
+
pressed = true
|
|
63
|
+
document.addEventListener(
|
|
64
|
+
'pointerup',
|
|
65
|
+
() => setTimeout(() => (pressed = false), 1),
|
|
66
|
+
{ once: true },
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Props for the `Slot` that renders the trigger before mounting. */
|
|
71
|
+
const shellProps = {
|
|
72
|
+
'data-slot': 'trigger',
|
|
73
|
+
'data-state': 'closed',
|
|
74
|
+
'data-grace-area-trigger': '',
|
|
75
|
+
// Reka's tooltip opens on pointermove, its hover card on pointerenter.
|
|
76
|
+
[kind === 'tooltip' ? 'onPointermove' : 'onPointerenter']: onPointer,
|
|
77
|
+
// `focus` covers the trigger itself, `focusin` its descendants.
|
|
78
|
+
onFocus,
|
|
79
|
+
onFocusin: onFocus,
|
|
80
|
+
onPointerdown,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return { mounted, mount, shellProps }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Sends the event that mounted the overlay to the new trigger, so reka runs
|
|
87
|
+
// its own open logic: hover delay, skip delay, touch filtering.
|
|
88
|
+
function replay(event: Event, trigger: Element, gotFocus: boolean) {
|
|
89
|
+
if (event.type.startsWith('pointer')) {
|
|
90
|
+
// A script can dispatch a plain `Event` named "pointermove", and reka
|
|
91
|
+
// still treats it as a pointer, so read its fields as optional.
|
|
92
|
+
const pointer: Partial<PointerEvent> = event
|
|
93
|
+
trigger.dispatchEvent(
|
|
94
|
+
new PointerEvent(event.type, {
|
|
95
|
+
pointerId: pointer.pointerId,
|
|
96
|
+
pointerType: pointer.pointerType ?? 'mouse',
|
|
97
|
+
isPrimary: pointer.isPrimary,
|
|
98
|
+
clientX: pointer.clientX,
|
|
99
|
+
clientY: pointer.clientY,
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
// Reka opens on a `focus` event that reaches the trigger. A descendant's
|
|
105
|
+
// focus only arrives as `focusin`, so it is not sent again. Restoring focus
|
|
106
|
+
// already sends `focus`, unless the window does not have focus. Reka must
|
|
107
|
+
// see it exactly once: a hover card starts an open timer for each one.
|
|
108
|
+
if (event.type === 'focus' && !gotFocus) {
|
|
109
|
+
trigger.dispatchEvent(new FocusEvent('focus'))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The first element a rendered tree starts with. Reka's root renders a
|
|
114
|
+
// fragment, whose node is an empty text anchor placed before the trigger.
|
|
115
|
+
// Vue types a rendered node loosely, as any renderer's node.
|
|
116
|
+
function firstElement(node: unknown): Element | null {
|
|
117
|
+
if (node instanceof Element) return node
|
|
118
|
+
if (node instanceof CharacterData) return node.nextElementSibling
|
|
119
|
+
return null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Runs `action` and reports whether it dispatched `type` on `target`.
|
|
123
|
+
// Focus events dispatch synchronously inside `focus()`.
|
|
124
|
+
function receivesEvent(target: Element, type: string, action: () => void) {
|
|
125
|
+
let received = false
|
|
126
|
+
const listener = () => (received = true)
|
|
127
|
+
target.addEventListener(type, listener)
|
|
128
|
+
action()
|
|
129
|
+
target.removeEventListener(type, listener)
|
|
130
|
+
return received
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Remembers where focus is inside the trigger by child position, so it can be
|
|
134
|
+
// put back in the same place once the trigger element is replaced.
|
|
135
|
+
function captureFocus(shell: Element) {
|
|
136
|
+
const active = document.activeElement
|
|
137
|
+
if (!active || !shell.contains(active)) return
|
|
138
|
+
|
|
139
|
+
const path: number[] = []
|
|
140
|
+
for (let node = active; node !== shell; node = node.parentElement!) {
|
|
141
|
+
path.unshift(Array.from(node.parentElement!.children).indexOf(node))
|
|
142
|
+
}
|
|
143
|
+
const selection = isTextField(active)
|
|
144
|
+
? ([
|
|
145
|
+
active.selectionStart,
|
|
146
|
+
active.selectionEnd,
|
|
147
|
+
active.selectionDirection ?? undefined,
|
|
148
|
+
] as const)
|
|
149
|
+
: null
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
restore(trigger: Element) {
|
|
153
|
+
let target: Element | undefined = trigger
|
|
154
|
+
for (const index of path) target = target?.children[index]
|
|
155
|
+
if (!(target instanceof HTMLElement)) return
|
|
156
|
+
target.focus({ preventScroll: true })
|
|
157
|
+
if (!selection || !isTextField(target)) return
|
|
158
|
+
try {
|
|
159
|
+
target.setSelectionRange(...selection)
|
|
160
|
+
} catch {
|
|
161
|
+
// Inputs like type="email" do not support selection ranges.
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isTextField(
|
|
168
|
+
element: Element,
|
|
169
|
+
): element is HTMLInputElement | HTMLTextAreaElement {
|
|
170
|
+
return (
|
|
171
|
+
element instanceof HTMLInputElement ||
|
|
172
|
+
element instanceof HTMLTextAreaElement
|
|
173
|
+
)
|
|
174
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { computed, getCurrentInstance } from 'vue'
|
|
2
|
+
import { RouterLink } from 'vue-router'
|
|
3
|
+
import { safeHref } from '../../utils/url-safety'
|
|
4
|
+
import type { RouteDestination } from './route'
|
|
5
|
+
|
|
6
|
+
interface NavLinkProps {
|
|
7
|
+
route?: RouteDestination
|
|
8
|
+
href?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The link half of a nav item: which element to render, the attributes it
|
|
13
|
+
* takes, and the route it points at. Every href passes through `safeHref`
|
|
14
|
+
* here, so a nav item cannot render an unchecked one.
|
|
15
|
+
*/
|
|
16
|
+
export function useNavLink(props: NavLinkProps) {
|
|
17
|
+
// Read the router/route off global properties instead of useRouter()/useRoute()
|
|
18
|
+
// so the item works — without warnings or crashes — when mounted outside a
|
|
19
|
+
// vue-router app (docs, tests, embedded use). vue-router installs $router/$route
|
|
20
|
+
// here; the $route getter stays reactive when read inside a computed.
|
|
21
|
+
const globals = getCurrentInstance()?.appContext.config.globalProperties
|
|
22
|
+
const hasRouter = computed(() => Boolean(globals?.$router))
|
|
23
|
+
|
|
24
|
+
// With a router, render RouterLink; without one, degrade to a plain <a>. It
|
|
25
|
+
// gets an href only when `route` is a string: a route object has no URL
|
|
26
|
+
// without a router to resolve it.
|
|
27
|
+
const linkComponent = computed(() =>
|
|
28
|
+
props.route && hasRouter.value ? RouterLink : 'a',
|
|
29
|
+
)
|
|
30
|
+
const linkAttrs = computed(() =>
|
|
31
|
+
props.route
|
|
32
|
+
? hasRouter.value
|
|
33
|
+
? { to: props.route }
|
|
34
|
+
: { href: safeHref(props.route) }
|
|
35
|
+
: { href: safeHref(props.href) },
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const resolvedRoute = computed(() =>
|
|
39
|
+
props.route && globals?.$router
|
|
40
|
+
? globals.$router.resolve(props.route)
|
|
41
|
+
: null,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return { globals, linkComponent, linkAttrs, resolvedRoute }
|
|
45
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { Editor } from '@tiptap/core'
|
|
19
19
|
import { fileSizeLimitMessage } from '#utils/fileSize'
|
|
20
|
-
import { isSafeUrl } from '#
|
|
20
|
+
import { isSafeUrl } from '#utils/url-safety'
|
|
21
21
|
import { findNodeByUploadId } from '#molecules/editor/extensions/shared/node-view'
|
|
22
22
|
import {
|
|
23
23
|
applyUploadError,
|
|
@@ -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
|
+
}
|
|
@@ -11,7 +11,11 @@ import {
|
|
|
11
11
|
type ResizeEdge,
|
|
12
12
|
} from '#molecules/editor/composables/useNodeViewResize'
|
|
13
13
|
import { safeGetPos } from '#molecules/editor/extensions/shared/node-view'
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
IFRAME_SANDBOX,
|
|
16
|
+
getIframeAllowlist,
|
|
17
|
+
validateIframeUrl,
|
|
18
|
+
} from './iframe-allowlist'
|
|
15
19
|
import { openIframeInsertDialog } from './iframeInsertDialogController'
|
|
16
20
|
import type { IframeAlign } from './iframe-commands'
|
|
17
21
|
|
|
@@ -47,6 +51,15 @@ const frameStyle = computed(() => {
|
|
|
47
51
|
|
|
48
52
|
const sandbox = computed<string>(() => IFRAME_SANDBOX)
|
|
49
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
|
+
|
|
50
63
|
const isInteractive = computed<boolean>(() => !!props.node.attrs.interactive)
|
|
51
64
|
const overlayActive = computed(() => isEditable.value && !isInteractive.value)
|
|
52
65
|
|
|
@@ -180,11 +193,11 @@ function commitCaption(event: Event): void {
|
|
|
180
193
|
>
|
|
181
194
|
<div class="relative">
|
|
182
195
|
<iframe
|
|
183
|
-
v-if="
|
|
196
|
+
v-if="safeSrc"
|
|
184
197
|
ref="iframeRef"
|
|
185
198
|
class="block h-auto max-w-full rounded-4 border-0"
|
|
186
199
|
:class="{ 'pointer-events-none': overlayActive }"
|
|
187
|
-
:src="
|
|
200
|
+
:src="safeSrc"
|
|
188
201
|
:style="frameStyle"
|
|
189
202
|
:title="node.attrs.title || ''"
|
|
190
203
|
:sandbox="sandbox"
|
|
@@ -204,7 +217,7 @@ function commitCaption(event: Event): void {
|
|
|
204
217
|
|
|
205
218
|
<!-- Shared media toolbar (caption / change link / align) -->
|
|
206
219
|
<MediaToolbar
|
|
207
|
-
v-if="
|
|
220
|
+
v-if="safeSrc"
|
|
208
221
|
:node="node"
|
|
209
222
|
media-type="embed"
|
|
210
223
|
:is-editable="isEditable"
|
|
@@ -223,21 +236,25 @@ function commitCaption(event: Event): void {
|
|
|
223
236
|
/>
|
|
224
237
|
<MediaResizeGuide :guide="() => guide" />
|
|
225
238
|
|
|
226
|
-
<!-- Placeholder while no src is set -->
|
|
239
|
+
<!-- Placeholder while no src is set, or when src is not allowed -->
|
|
227
240
|
<div
|
|
228
|
-
v-if="!
|
|
229
|
-
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"
|
|
230
243
|
>
|
|
231
244
|
<div class="text-center text-ink-gray-5">
|
|
232
245
|
<div class="mb-1 text-lg">🔗</div>
|
|
233
|
-
<div class="text-sm">
|
|
246
|
+
<div class="text-sm">
|
|
247
|
+
{{
|
|
248
|
+
node.attrs.src ? 'This embed is not allowed' : 'Loading embed…'
|
|
249
|
+
}}
|
|
250
|
+
</div>
|
|
234
251
|
</div>
|
|
235
252
|
</div>
|
|
236
253
|
</div>
|
|
237
254
|
|
|
238
255
|
<!-- Caption input (commits on blur / Enter) -->
|
|
239
256
|
<input
|
|
240
|
-
v-if="(node.attrs.title || showCaption) &&
|
|
257
|
+
v-if="(node.attrs.title || showCaption) && safeSrc"
|
|
241
258
|
:value="node.attrs.title"
|
|
242
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"
|
|
243
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,
|
|
@@ -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
|
@@ -10,7 +10,6 @@ import { moduleSingleton } from './moduleSingleton'
|
|
|
10
10
|
import { useId } from './useId'
|
|
11
11
|
import Dialog from '../components/Dialog/Dialog.vue'
|
|
12
12
|
import { Button } from '../components/Button'
|
|
13
|
-
import FormControl from '../components/FormControl/FormControl.vue'
|
|
14
13
|
import ErrorMessage from '../components/ErrorMessage/ErrorMessage.vue'
|
|
15
14
|
import type { DialogSize, DialogTheme } from '../components/Dialog/types'
|
|
16
15
|
import type { ButtonProps } from '../components/Button'
|
|
@@ -446,6 +445,17 @@ export function confirm(args: ConfirmArgs): DialogHandle {
|
|
|
446
445
|
|
|
447
446
|
// -- prompt --------------------------------------------------------------
|
|
448
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
|
+
|
|
449
459
|
// Initial value for a prompt field. Checkbox defaults to false; everything
|
|
450
460
|
// else (text/textarea/select/combobox) defaults to an empty string so the
|
|
451
461
|
// `required` check has something concrete to compare against.
|
|
@@ -586,6 +596,9 @@ export function prompt(args: PromptArgs): DialogHandle {
|
|
|
586
596
|
!field.type || field.type === 'text' || field.type === 'textarea',
|
|
587
597
|
)
|
|
588
598
|
|
|
599
|
+
// Set before the dialog joins the stack, at the end of this function.
|
|
600
|
+
let FormControl: Component
|
|
601
|
+
|
|
589
602
|
const renderField = (field: PromptField) => {
|
|
590
603
|
const onUpdate = (val: any) => {
|
|
591
604
|
values[field.name] = val
|
|
@@ -710,7 +723,12 @@ export function prompt(args: PromptArgs): DialogHandle {
|
|
|
710
723
|
},
|
|
711
724
|
})
|
|
712
725
|
|
|
713
|
-
|
|
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
|
+
})
|
|
714
732
|
return { close }
|
|
715
733
|
}
|
|
716
734
|
|