@sincpro/web-ui 2.14.2 → 2.16.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/README.md +66 -4
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/media/Carousel.d.ts +34 -0
- package/dist/components/media/Carousel.js +148 -0
- package/dist/components/media/Stories.d.ts +71 -0
- package/dist/components/media/Stories.js +174 -0
- package/dist/components/media/index.d.ts +2 -0
- package/dist/components/media/index.js +4 -0
- package/dist/components/media/motion.d.ts +7 -0
- package/dist/components/media/motion.js +17 -0
- package/dist/components/navigation/PortalNav.d.ts +49 -0
- package/dist/components/navigation/PortalNav.js +40 -0
- package/dist/components/navigation/index.d.ts +1 -0
- package/dist/components/navigation/index.js +3 -0
- package/dist/components/preview/FilePreview.d.ts +5 -3
- package/dist/components/preview/FilePreview.js +39 -3
- package/dist/components/preview/index.d.ts +1 -1
- package/dist/components/preview/index.js +1 -1
- package/dist/components/preview/previewKind.d.ts +12 -2
- package/dist/components/preview/previewKind.js +44 -2
- package/dist/components/shell/Notifications.d.ts +64 -0
- package/dist/components/shell/Notifications.js +84 -0
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +3 -0
- package/dist/foundations/copy.es.js +39 -0
- package/dist/foundations/uiCopy.d.ts +67 -0
- package/dist/foundations/uiCopy.js +46 -1
- package/dist/primitives/choice/CheckField.d.ts +26 -0
- package/dist/primitives/choice/CheckField.js +45 -0
- package/dist/primitives/choice/index.d.ts +1 -0
- package/dist/primitives/choice/index.js +2 -0
- package/dist/primitives/field/RichTextEditor.d.ts +13 -1
- package/dist/primitives/field/RichTextEditor.js +152 -8
- package/dist/primitives/field/RichTextInput.d.ts +14 -3
- package/dist/primitives/field/RichTextInput.js +9 -3
- package/dist/primitives/field/index.d.ts +1 -1
- package/dist/primitives/value/RichText.d.ts +15 -3
- package/dist/primitives/value/RichText.js +26 -73
- package/dist/primitives/value/index.d.ts +1 -0
- package/dist/primitives/value/index.js +2 -0
- package/dist/primitives/value/richTextPlain.d.ts +1 -1
- package/dist/primitives/value/richTextPlain.js +2 -2
- package/dist/primitives/value/richTextPolicy.d.ts +39 -0
- package/dist/primitives/value/richTextPolicy.js +195 -0
- package/dist/tokens.css +22 -0
- package/package.json +2 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type FormMode } from "../../foundations/form.js";
|
|
2
|
+
export type CheckFieldProps = {
|
|
3
|
+
/** The sentence that IS its name: «Recibir el boletín por correo». */
|
|
4
|
+
label: string;
|
|
5
|
+
/** A line under it: what saying yes does. */
|
|
6
|
+
hint?: string;
|
|
7
|
+
checked: boolean;
|
|
8
|
+
onChange?: (next: boolean) => void;
|
|
9
|
+
/** A box (the default) or a switch. In the «settings» style it is always a switch: a
|
|
10
|
+
* settings row turns something on, it does not tick an item of a list. */
|
|
11
|
+
control?: "checkbox" | "switch";
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Forces the mode; by default the form's (read mode draws the answer). */
|
|
14
|
+
mode?: FormMode;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A yes/no whose sentence is its own name, as a row of a form.
|
|
18
|
+
*
|
|
19
|
+
* Context: a `Checkbox` inside a `Field` says its name twice («Boletín · Recibir el
|
|
20
|
+
* boletín») and, in `FormSection columns`, sits under an empty label — the box at the height
|
|
21
|
+
* of the neighbours' LABELS, not of their controls. This row keeps a label's height empty
|
|
22
|
+
* above it (stacked), or the label column empty beside it (horizontal), so the box lines up
|
|
23
|
+
* with the inputs next to it. In the «settings» style it is that style's row: the sentence
|
|
24
|
+
* and its help on the left, the switch on the right, named by the sentence.
|
|
25
|
+
*/
|
|
26
|
+
export declare function CheckField({ label, hint, checked, onChange, control, disabled, mode, }: CheckFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { byDensity, useDensity } from "../../foundations/density.js";
|
|
4
|
+
import { FieldIdsContext, useFormStyle, } from "../../foundations/form.js";
|
|
5
|
+
import { Switch } from "./Switch.js";
|
|
6
|
+
import { Checkbox } from "../field/Checks.js";
|
|
7
|
+
import { useSheetLayout } from "../field/layout.js";
|
|
8
|
+
import { useId } from "react";
|
|
9
|
+
/**
|
|
10
|
+
* A yes/no whose sentence is its own name, as a row of a form.
|
|
11
|
+
*
|
|
12
|
+
* Context: a `Checkbox` inside a `Field` says its name twice («Boletín · Recibir el
|
|
13
|
+
* boletín») and, in `FormSection columns`, sits under an empty label — the box at the height
|
|
14
|
+
* of the neighbours' LABELS, not of their controls. This row keeps a label's height empty
|
|
15
|
+
* above it (stacked), or the label column empty beside it (horizontal), so the box lines up
|
|
16
|
+
* with the inputs next to it. In the «settings» style it is that style's row: the sentence
|
|
17
|
+
* and its help on the left, the switch on the right, named by the sentence.
|
|
18
|
+
*/
|
|
19
|
+
export function CheckField({ label, hint, checked, onChange, control = "checkbox", disabled = false, mode, }) {
|
|
20
|
+
const d = useDensity();
|
|
21
|
+
const settings = useFormStyle() === "settings";
|
|
22
|
+
const horizontal = useSheetLayout() === "horizontal";
|
|
23
|
+
const id = useId();
|
|
24
|
+
const hintId = hint === undefined ? undefined : `${id}-hint`;
|
|
25
|
+
const hintNode = hint === undefined ? null : (_jsx("p", { id: hintId, className: "max-w-prose text-micro text-muted", children: hint }));
|
|
26
|
+
if (settings) {
|
|
27
|
+
/* The sentence names the switch the way a field's label does: through the field ids. */
|
|
28
|
+
const ids = {
|
|
29
|
+
id,
|
|
30
|
+
labelId: `${id}-label`,
|
|
31
|
+
label,
|
|
32
|
+
describedBy: hintId,
|
|
33
|
+
invalid: false,
|
|
34
|
+
};
|
|
35
|
+
return (_jsxs("div", { "data-ui": "check-field", "data-style": "settings", className: "flex min-w-0 items-start justify-between gap-6", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("label", { id: ids.labelId, htmlFor: id, className: "text-meta font-medium text-ink", children: label }), hintNode] }), _jsx(FieldIdsContext.Provider, { value: ids, children: _jsx("span", { className: "shrink-0", children: _jsx(Switch, { checked: checked, onChange: onChange, disabled: disabled, ...(mode === undefined ? {} : { mode }) }) }) })] }));
|
|
36
|
+
}
|
|
37
|
+
const answer = control === "switch" ? (_jsx(Switch, { checked: checked, onChange: onChange, disabled: disabled, describedBy: hintId, ...(mode === undefined ? {} : { mode }), children: label })) : (_jsx(Checkbox, { checked: checked, onChange: onChange, label: label, disabled: disabled, describedBy: hintId, ...(mode === undefined ? {} : { mode }) }));
|
|
38
|
+
/* Its own context: inside a `Field` by mistake it would be named twice. */
|
|
39
|
+
const row = (_jsxs(FieldIdsContext.Provider, { value: null, children: [_jsx("div", { className: "flex min-h-(--size-control-md) items-center", children: answer }), hintNode] }));
|
|
40
|
+
if (horizontal) {
|
|
41
|
+
return (_jsxs("div", { "data-ui": "check-field", className: "grid-label grid min-w-0 items-start gap-x-4", children: [_jsx("span", { "aria-hidden": true }), _jsx("div", { className: "flex min-w-0 flex-col gap-1", children: row })] }));
|
|
42
|
+
}
|
|
43
|
+
/* The empty line is a label's, in its type: the box starts where the neighbours' inputs do. */
|
|
44
|
+
return (_jsxs("div", { "data-ui": "check-field", className: `flex min-w-0 flex-col ${byDensity(d, "gap-1", "gap-0.5")}`, children: [_jsx("span", { "aria-hidden": true, className: "text-micro select-none", children: " " }), _jsx("div", { className: "flex min-w-0 flex-col gap-1", children: row })] }));
|
|
45
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { CheckField, type CheckFieldProps, } from "./CheckField.js";
|
|
1
2
|
export { ComboBox, type ComboBoxProps } from "./ComboBox.js";
|
|
2
3
|
export { KanbanState, type KanbanStateValue, } from "./KanbanState.js";
|
|
3
4
|
export { type ChoiceOption, type SegmentOption, } from "./options.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* THE CHOICES — pick one of many by typing (ComboBox), one of a few in sight
|
|
2
2
|
(RadioGroup, SegmentedControl), turn on or off (Switch), a value in a range (Slider)
|
|
3
3
|
and search for loose text (SearchField). The value is always plain data. */
|
|
4
|
+
/* A yes/no as a form row: the sentence is its name, lined up with the inputs beside it. */
|
|
5
|
+
export { CheckField, } from "./CheckField.js";
|
|
4
6
|
export { ComboBox } from "./ComboBox.js";
|
|
5
7
|
export { KanbanState, } from "./KanbanState.js";
|
|
6
8
|
export {} from "./options.js";
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { type EmbedProvider } from "../value/richTextPolicy.js";
|
|
1
2
|
export type MentionItem = {
|
|
2
3
|
id: string;
|
|
3
4
|
label: string;
|
|
4
5
|
};
|
|
6
|
+
/** Pictures in the text: the application stores each file and answers where it lives. */
|
|
7
|
+
export type RichTextImages = {
|
|
8
|
+
/** Store the picture; answer its address (relative is fine: `/v1/media/12`) and,
|
|
9
|
+
* if it has one, its description. A thrown `Error`'s message is shown as the failure. */
|
|
10
|
+
upload: (file: File) => Promise<{
|
|
11
|
+
src: string;
|
|
12
|
+
alt?: string;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
5
15
|
export type RichTextEditorProps = {
|
|
6
16
|
id: string | undefined;
|
|
7
17
|
labelledBy: string | undefined;
|
|
@@ -14,5 +24,7 @@ export type RichTextEditorProps = {
|
|
|
14
24
|
disabled: boolean;
|
|
15
25
|
toolbar: "full" | "basic" | "none";
|
|
16
26
|
mentions: ((query: string) => readonly MentionItem[] | Promise<readonly MentionItem[]>) | undefined;
|
|
27
|
+
images?: RichTextImages | undefined;
|
|
28
|
+
embeds?: readonly EmbedProvider[] | undefined;
|
|
17
29
|
};
|
|
18
|
-
export declare function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel, value, onChange, placeholder, disabled, toolbar, mentions, }: RichTextEditorProps): import("react").JSX.Element;
|
|
30
|
+
export declare function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel, value, onChange, placeholder, disabled, toolbar, mentions, images, embeds, }: RichTextEditorProps): import("react").JSX.Element;
|
|
@@ -1,17 +1,59 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useUiCopy } from "../../foundations/copy.js";
|
|
3
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
4
4
|
import { Button, IconButton } from "../button/Button.js";
|
|
5
5
|
import { emailHref, telHref, urlHref } from "./contact.js";
|
|
6
6
|
import { PopoverTrigger } from "../overlay/PopoverTrigger.js";
|
|
7
7
|
import { Toolbar, ToolbarSeparator } from "../toolbar/Toolbar.js";
|
|
8
|
+
import { EMBED_IFRAME_ATTRIBUTES, embedOf, isRichTextUri, } from "../value/richTextPolicy.js";
|
|
9
|
+
import Image from "@tiptap/extension-image";
|
|
8
10
|
import Mention from "@tiptap/extension-mention";
|
|
9
11
|
import { TableKit } from "@tiptap/extension-table";
|
|
10
12
|
import { Placeholder } from "@tiptap/extensions";
|
|
11
|
-
import { EditorContent, useEditor, useEditorState } from "@tiptap/react";
|
|
13
|
+
import { EditorContent, Node, useEditor, useEditorState } from "@tiptap/react";
|
|
12
14
|
import StarterKit from "@tiptap/starter-kit";
|
|
13
|
-
import { Bold, Heading2, Heading3, Italic, Link as LinkIcon, List, ListOrdered, Redo2, RemoveFormatting, Strikethrough, Table, TextQuote, Underline, Undo2, } from "lucide-react";
|
|
15
|
+
import { Bold, Heading2, Heading3, ImagePlus, Italic, Link as LinkIcon, List, ListOrdered, Redo2, RemoveFormatting, Strikethrough, Table, TextQuote, Underline, Undo2, Video, } from "lucide-react";
|
|
14
16
|
import { useEffect, useId, useRef, useState } from "react";
|
|
17
|
+
const PROVIDER_NAME = { youtube: "YouTube", vimeo: "Vimeo" };
|
|
18
|
+
/** A video's player as one block: drawn as `<div data-embed><iframe></div>`, read back only
|
|
19
|
+
* from an address the policy turns into an allowed player. */
|
|
20
|
+
function embedNode(providers, title) {
|
|
21
|
+
const read = (element) => {
|
|
22
|
+
const frame = element.tagName === "IFRAME" ? element : element.querySelector("iframe");
|
|
23
|
+
const found = embedOf(frame?.getAttribute("src") ?? "", providers);
|
|
24
|
+
return found === null ? false : { src: found.src, provider: found.provider };
|
|
25
|
+
};
|
|
26
|
+
return Node.create({
|
|
27
|
+
name: "embed",
|
|
28
|
+
group: "block",
|
|
29
|
+
atom: true,
|
|
30
|
+
draggable: true,
|
|
31
|
+
addAttributes: () => ({ src: { default: null }, provider: { default: null } }),
|
|
32
|
+
parseHTML: () => [
|
|
33
|
+
{ tag: "div[data-embed]", getAttrs: read },
|
|
34
|
+
{ tag: "iframe[src]", getAttrs: read },
|
|
35
|
+
],
|
|
36
|
+
renderHTML: ({ node }) => {
|
|
37
|
+
const provider = String(node.attrs["provider"]);
|
|
38
|
+
return [
|
|
39
|
+
"div",
|
|
40
|
+
{ "data-embed": provider },
|
|
41
|
+
[
|
|
42
|
+
"iframe",
|
|
43
|
+
{
|
|
44
|
+
src: node.attrs["src"],
|
|
45
|
+
title: title(PROVIDER_NAME[provider] ?? provider),
|
|
46
|
+
...EMBED_IFRAME_ATTRIBUTES,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
];
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** The pictures among some files — what a paste or a drop hands over. */
|
|
54
|
+
function imagesIn(files) {
|
|
55
|
+
return [...(files ?? [])].filter((file) => file.type.startsWith("image/"));
|
|
56
|
+
}
|
|
15
57
|
/** A link address as people write it: a website, an email, a phone — or nothing valid. */
|
|
16
58
|
function linkHref(text) {
|
|
17
59
|
const clean = text.trim();
|
|
@@ -45,7 +87,27 @@ function LinkForm({ editor, close }) {
|
|
|
45
87
|
close();
|
|
46
88
|
}, children: copy.removeLink })), _jsx(Button, { role: "secondary", size: "sm", type: "submit", children: copy.applyLink })] })] }));
|
|
47
89
|
}
|
|
48
|
-
function
|
|
90
|
+
function VideoForm({ editor, providers, close, }) {
|
|
91
|
+
const copy = useUiCopy().richText;
|
|
92
|
+
const [text, setText] = useState("");
|
|
93
|
+
const [tried, setTried] = useState(false);
|
|
94
|
+
const inputId = useId();
|
|
95
|
+
const found = embedOf(text, providers);
|
|
96
|
+
const apply = () => {
|
|
97
|
+
setTried(true);
|
|
98
|
+
if (found === null)
|
|
99
|
+
return;
|
|
100
|
+
editor.chain().focus().insertContent({ type: "embed", attrs: found }).run();
|
|
101
|
+
close();
|
|
102
|
+
};
|
|
103
|
+
return (_jsxs("form", { className: "flex w-72 max-w-full flex-col gap-2", onSubmit: (event) => {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
apply();
|
|
106
|
+
}, children: [_jsx("label", { htmlFor: inputId, className: "text-micro font-medium text-muted", children: copy.videoUrl }), _jsx("input", { id: inputId, value: text, autoFocus: true, inputMode: "url", spellCheck: false, "aria-invalid": tried && found === null, ...(tried && found === null ? { "aria-describedby": `${inputId}-error` } : {}), onChange: (event) => setText(event.target.value), className: "h-(--size-control-md) w-full min-w-0 rounded-control border border-line-strong bg-surface px-2.5 text-meta text-ink outline-0 focus-visible:border-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary" }), tried && found === null ? (_jsx("p", { id: `${inputId}-error`, role: "alert", className: "text-micro text-danger", children: fillCopy(copy.badVideo, {
|
|
107
|
+
providers: providers.map((one) => PROVIDER_NAME[one]).join(", "),
|
|
108
|
+
}) })) : null, _jsx("div", { className: "flex items-center justify-end gap-2", children: _jsx(Button, { role: "secondary", size: "sm", type: "submit", children: copy.insertVideo }) })] }));
|
|
109
|
+
}
|
|
110
|
+
function Bar({ editor, full, media }) {
|
|
49
111
|
const copy = useUiCopy().richText;
|
|
50
112
|
const on = useEditorState({
|
|
51
113
|
editor,
|
|
@@ -78,7 +140,7 @@ function Bar({ editor, full }) {
|
|
|
78
140
|
? toggle(copy.subheading, Heading3, on.h3, () => chain().toggleHeading({ level: 3 }).run())
|
|
79
141
|
: null, toggle(copy.bulletList, List, on.bullet, () => chain().toggleBulletList().run()), toggle(copy.orderedList, ListOrdered, on.ordered, () => chain().toggleOrderedList().run()), full
|
|
80
142
|
? toggle(copy.quote, TextQuote, on.quote, () => chain().toggleBlockquote().run())
|
|
81
|
-
: null, _jsx(ToolbarSeparator, {}), _jsx(PopoverTrigger, { title: copy.link, trigger: _jsx(IconButton, { icon: LinkIcon, label: copy.link, "aria-pressed": on.link, disabled: !editor.isEditable }), children: (close) => _jsx(LinkForm, { editor: editor, close: close }) }), full ? (_jsx(IconButton, { icon: Table, label: copy.table, disabled: !editor.isEditable, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run() })) : null, full ? (_jsxs(_Fragment, { children: [_jsx(ToolbarSeparator, {}), _jsx(IconButton, { icon: Undo2, label: copy.undo, disabled: !on.undo, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().undo().run() }), _jsx(IconButton, { icon: Redo2, label: copy.redo, disabled: !on.redo, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().redo().run() }), _jsx(IconButton, { icon: RemoveFormatting, label: copy.clear, disabled: !editor.isEditable, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().unsetAllMarks().clearNodes().run() })] })) : null] }) }));
|
|
143
|
+
: null, _jsx(ToolbarSeparator, {}), _jsx(PopoverTrigger, { title: copy.link, trigger: _jsx(IconButton, { icon: LinkIcon, label: copy.link, "aria-pressed": on.link, disabled: !editor.isEditable }), children: (close) => _jsx(LinkForm, { editor: editor, close: close }) }), media.pickImage === undefined ? null : (_jsx(IconButton, { icon: ImagePlus, label: copy.image, busy: media.uploading, disabled: !editor.isEditable, onMouseDown: (event) => event.preventDefault(), onClick: media.pickImage })), media.embeds === undefined || media.embeds.length === 0 ? null : (_jsx(PopoverTrigger, { title: copy.video, trigger: _jsx(IconButton, { icon: Video, label: copy.video, disabled: !editor.isEditable }), children: (close) => (_jsx(VideoForm, { editor: editor, providers: media.embeds ?? [], close: close })) })), full ? (_jsx(IconButton, { icon: Table, label: copy.table, disabled: !editor.isEditable, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run() })) : null, full ? (_jsxs(_Fragment, { children: [_jsx(ToolbarSeparator, {}), _jsx(IconButton, { icon: Undo2, label: copy.undo, disabled: !on.undo, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().undo().run() }), _jsx(IconButton, { icon: Redo2, label: copy.redo, disabled: !on.redo, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().redo().run() }), _jsx(IconButton, { icon: RemoveFormatting, label: copy.clear, disabled: !editor.isEditable, onMouseDown: (event) => event.preventDefault(), onClick: () => chain().unsetAllMarks().clearNodes().run() })] })) : null] }) }));
|
|
82
144
|
}
|
|
83
145
|
/** The list that opens on «@»: fixed under the caret, moved through from the editor. */
|
|
84
146
|
function MentionList({ asking, active, listId, }) {
|
|
@@ -91,11 +153,18 @@ function MentionList({ asking, active, listId, }) {
|
|
|
91
153
|
asking.pick(item);
|
|
92
154
|
}, className: `cursor-default rounded-control px-2 py-1 text-meta text-ink ${index === active ? "bg-ui-option-active" : ""}`, children: item.label }, item.id)))) }));
|
|
93
155
|
}
|
|
94
|
-
export function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel, value, onChange, placeholder, disabled, toolbar, mentions, }) {
|
|
156
|
+
export function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel, value, onChange, placeholder, disabled, toolbar, mentions, images, embeds, }) {
|
|
157
|
+
const copy = useUiCopy().richText;
|
|
95
158
|
const changed = useRef(onChange);
|
|
96
159
|
changed.current = onChange;
|
|
97
160
|
const searching = useRef(mentions);
|
|
98
161
|
searching.current = mentions;
|
|
162
|
+
/* Pictures on their way to the application: how many, and the last failure. */
|
|
163
|
+
const [uploading, setUploading] = useState(0);
|
|
164
|
+
const [failure, setFailure] = useState(null);
|
|
165
|
+
const fileInput = useRef(null);
|
|
166
|
+
/* Set below once the editor exists; the paste and drop handlers are fixed at creation. */
|
|
167
|
+
const uploadRef = useRef(null);
|
|
99
168
|
const [asking, setAsking] = useState(null);
|
|
100
169
|
const [active, setActive] = useState(0);
|
|
101
170
|
const activeRef = useRef(0);
|
|
@@ -118,6 +187,10 @@ export function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel
|
|
|
118
187
|
}),
|
|
119
188
|
TableKit.configure({ table: { resizable: false } }),
|
|
120
189
|
...(placeholder === undefined ? [] : [Placeholder.configure({ placeholder })]),
|
|
190
|
+
...(images === undefined ? [] : [Image.configure({ allowBase64: false })]),
|
|
191
|
+
...(embeds === undefined || embeds.length === 0
|
|
192
|
+
? []
|
|
193
|
+
: [embedNode(embeds, (provider) => fillCopy(copy.videoTitle, { provider }))]),
|
|
121
194
|
...(mentions === undefined
|
|
122
195
|
? []
|
|
123
196
|
: [
|
|
@@ -174,6 +247,23 @@ export function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel
|
|
|
174
247
|
]),
|
|
175
248
|
],
|
|
176
249
|
editorProps: {
|
|
250
|
+
handlePaste: (_view, event) => {
|
|
251
|
+
const files = imagesIn(event.clipboardData?.files);
|
|
252
|
+
if (files.length === 0 || uploadRef.current === null)
|
|
253
|
+
return false;
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
uploadRef.current(files, null);
|
|
256
|
+
return true;
|
|
257
|
+
},
|
|
258
|
+
handleDrop: (view, event, _slice, moved) => {
|
|
259
|
+
const files = imagesIn(event.dataTransfer?.files);
|
|
260
|
+
if (moved || files.length === 0 || uploadRef.current === null)
|
|
261
|
+
return false;
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
const at = view.posAtCoords({ left: event.clientX, top: event.clientY });
|
|
264
|
+
uploadRef.current(files, at?.pos ?? null);
|
|
265
|
+
return true;
|
|
266
|
+
},
|
|
177
267
|
attributes: {
|
|
178
268
|
class: "rich-text min-h-24 max-h-96 overflow-y-auto px-2.5 py-2 outline-0",
|
|
179
269
|
role: "textbox",
|
|
@@ -209,6 +299,48 @@ export function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel
|
|
|
209
299
|
listId,
|
|
210
300
|
]);
|
|
211
301
|
useEffect(() => editor?.setEditable(!disabled), [editor, disabled]);
|
|
302
|
+
/* One picture after another, in the order given; each goes in where the caret is when it
|
|
303
|
+
arrives (or where it was dropped), so typing meanwhile is not lost. */
|
|
304
|
+
uploadRef.current =
|
|
305
|
+
editor === null || images === undefined
|
|
306
|
+
? null
|
|
307
|
+
: (files, at) => {
|
|
308
|
+
if (!editor.isEditable)
|
|
309
|
+
return;
|
|
310
|
+
setFailure(null);
|
|
311
|
+
setUploading((count) => count + 1);
|
|
312
|
+
void (async () => {
|
|
313
|
+
let place = at;
|
|
314
|
+
try {
|
|
315
|
+
for (const file of files) {
|
|
316
|
+
const stored = await images.upload(file);
|
|
317
|
+
if (!isRichTextUri(stored.src))
|
|
318
|
+
throw new Error(copy.imageFailed);
|
|
319
|
+
const node = {
|
|
320
|
+
type: "image",
|
|
321
|
+
attrs: { src: stored.src, alt: stored.alt ?? "" },
|
|
322
|
+
};
|
|
323
|
+
if (editor.isDestroyed)
|
|
324
|
+
return;
|
|
325
|
+
if (place === null)
|
|
326
|
+
editor.chain().focus().insertContent(node).run();
|
|
327
|
+
else {
|
|
328
|
+
const inside = Math.min(place, editor.state.doc.content.size);
|
|
329
|
+
editor.chain().insertContentAt(inside, node).run();
|
|
330
|
+
place = editor.state.selection.to;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
setFailure(error instanceof Error && error.message !== ""
|
|
336
|
+
? error.message
|
|
337
|
+
: copy.imageFailed);
|
|
338
|
+
}
|
|
339
|
+
finally {
|
|
340
|
+
setUploading((count) => count - 1);
|
|
341
|
+
}
|
|
342
|
+
})();
|
|
343
|
+
};
|
|
212
344
|
/* A value written from outside (a reset, a suggestion applied) replaces the content — but
|
|
213
345
|
never while the person is typing, which would move their caret. */
|
|
214
346
|
useEffect(() => {
|
|
@@ -218,7 +350,19 @@ export function RichTextEditor({ id, labelledBy, describedBy, invalid, ariaLabel
|
|
|
218
350
|
if (current !== value)
|
|
219
351
|
editor.commands.setContent(value === "" ? "" : value, { emitUpdate: false });
|
|
220
352
|
}, [editor, value]);
|
|
221
|
-
|
|
353
|
+
const media = {
|
|
354
|
+
pickImage: images === undefined ? undefined : () => fileInput.current?.click(),
|
|
355
|
+
uploading: uploading > 0,
|
|
356
|
+
embeds,
|
|
357
|
+
};
|
|
358
|
+
return (_jsxs("div", { ...(uploading > 0 ? { "aria-busy": true } : {}), className: `w-full min-w-0 overflow-clip rounded-control border bg-surface transition-colors duration-(--duration-instant) focus-within:outline-2 focus-within:outline-offset-2 ${invalid
|
|
222
359
|
? "border-danger focus-within:outline-danger"
|
|
223
|
-
: "border-line-strong focus-within:border-primary focus-within:outline-primary"} ${disabled ? "bg-ground text-muted" : ""}`, children: [editor === null || toolbar === "none" ? null : (_jsx(Bar, { editor: editor, full: toolbar === "full"
|
|
360
|
+
: "border-line-strong focus-within:border-primary focus-within:outline-primary"} ${disabled ? "bg-ground text-muted" : ""}`, children: [editor === null || toolbar === "none" ? null : (_jsx(Bar, { editor: editor, full: toolbar === "full", media: media })), images === undefined ? null : (_jsx("input", { ref: fileInput, type: "file", accept: "image/*", multiple: true, hidden: true, tabIndex: -1, "aria-hidden": true, onChange: (event) => {
|
|
361
|
+
const files = imagesIn(event.target.files);
|
|
362
|
+
event.target.value = "";
|
|
363
|
+
if (files.length > 0)
|
|
364
|
+
uploadRef.current?.(files, null);
|
|
365
|
+
} })), _jsx(EditorContent, { editor: editor }), images === undefined ? null : (_jsx("p", { role: "status", className: uploading > 0
|
|
366
|
+
? "border-t border-line px-2.5 py-1 text-micro text-muted"
|
|
367
|
+
: "sr-only", children: uploading > 0 ? copy.imageUploading : "" })), failure === null ? null : (_jsx("p", { role: "alert", className: "border-t border-line px-2.5 py-1 text-micro text-danger", children: failure })), asking === null ? null : (_jsx(MentionList, { asking: asking, active: active, listId: listId }))] }));
|
|
224
368
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ControlProps } from "./Field.js";
|
|
2
|
-
import type { MentionItem } from "./RichTextEditor.js";
|
|
2
|
+
import type { MentionItem, RichTextImages } from "./RichTextEditor.js";
|
|
3
|
+
import type { EmbedProvider } from "../value/richTextPolicy.js";
|
|
3
4
|
/**
|
|
4
5
|
* Formatted text — a description, the notes of an order, the body of an email: an Odoo `html`
|
|
5
6
|
* field. The value is HTML in and HTML out.
|
|
@@ -17,8 +18,14 @@ import type { MentionItem } from "./RichTextEditor.js";
|
|
|
17
18
|
* `toolbar` picks how much to offer: `full` (headings, quote, table, undo), `basic` (bold,
|
|
18
19
|
* italic, lists, link — a comment), `none` (only the keyboard shortcuts). `mentions` turns on
|
|
19
20
|
* «@»: the application answers who matches what was typed.
|
|
21
|
+
*
|
|
22
|
+
* An article needs more, and asks for it: `images` adds pictures — the toolbar's button, a
|
|
23
|
+
* paste, a drop — each handed to the application's `upload`, which stores it and answers its
|
|
24
|
+
* address; `embeds` adds the player of a YouTube (`youtube-nocookie.com`) or Vimeo video by
|
|
25
|
+
* its address. Without them, the field is what it was. Read mode draws the players of the
|
|
26
|
+
* same `embeds`.
|
|
20
27
|
*/
|
|
21
|
-
export declare function RichTextInput({ id: ownId, value, onChange, placeholder, describedBy: ownDescribedBy, invalid: ownInvalid, disabled, mode, toolbar, mentions, "aria-label": ariaLabel, }: ControlProps & {
|
|
28
|
+
export declare function RichTextInput({ id: ownId, value, onChange, placeholder, describedBy: ownDescribedBy, invalid: ownInvalid, disabled, mode, toolbar, mentions, images, embeds, "aria-label": ariaLabel, }: ControlProps & {
|
|
22
29
|
/** HTML. `""` is empty. */
|
|
23
30
|
value: string;
|
|
24
31
|
onChange?: (html: string) => void;
|
|
@@ -26,5 +33,9 @@ export declare function RichTextInput({ id: ownId, value, onChange, placeholder,
|
|
|
26
33
|
toolbar?: "full" | "basic" | "none";
|
|
27
34
|
/** Who can be mentioned with «@», for what was typed after it. */
|
|
28
35
|
mentions?: (query: string) => readonly MentionItem[] | Promise<readonly MentionItem[]>;
|
|
36
|
+
/** Pictures in the text: the application stores each one (`upload`) and answers where. */
|
|
37
|
+
images?: RichTextImages;
|
|
38
|
+
/** The video hosts whose players may be added by address, e.g. `["youtube", "vimeo"]`. */
|
|
39
|
+
embeds?: readonly EmbedProvider[];
|
|
29
40
|
}): import("react").JSX.Element;
|
|
30
|
-
export type { MentionItem };
|
|
41
|
+
export type { EmbedProvider, MentionItem, RichTextImages };
|
|
@@ -25,14 +25,20 @@ const RichTextEditor = lazy(() => import("./RichTextEditor.js").then((module) =>
|
|
|
25
25
|
* `toolbar` picks how much to offer: `full` (headings, quote, table, undo), `basic` (bold,
|
|
26
26
|
* italic, lists, link — a comment), `none` (only the keyboard shortcuts). `mentions` turns on
|
|
27
27
|
* «@»: the application answers who matches what was typed.
|
|
28
|
+
*
|
|
29
|
+
* An article needs more, and asks for it: `images` adds pictures — the toolbar's button, a
|
|
30
|
+
* paste, a drop — each handed to the application's `upload`, which stores it and answers its
|
|
31
|
+
* address; `embeds` adds the player of a YouTube (`youtube-nocookie.com`) or Vimeo video by
|
|
32
|
+
* its address. Without them, the field is what it was. Read mode draws the players of the
|
|
33
|
+
* same `embeds`.
|
|
28
34
|
*/
|
|
29
|
-
export function RichTextInput({ id: ownId, value, onChange, placeholder, describedBy: ownDescribedBy, invalid: ownInvalid, disabled = false, mode, toolbar = "full", mentions, "aria-label": ariaLabel, }) {
|
|
35
|
+
export function RichTextInput({ id: ownId, value, onChange, placeholder, describedBy: ownDescribedBy, invalid: ownInvalid, disabled = false, mode, toolbar = "full", mentions, images, embeds, "aria-label": ariaLabel, }) {
|
|
30
36
|
const { id, labelledBy, describedBy, invalid } = useFieldIds({
|
|
31
37
|
id: ownId,
|
|
32
38
|
describedBy: ownDescribedBy,
|
|
33
39
|
invalid: ownInvalid,
|
|
34
40
|
});
|
|
35
41
|
if (useFormMode(mode) === "read")
|
|
36
|
-
return _jsx(RichTextValue, { value: value });
|
|
37
|
-
return (_jsx(Suspense, { fallback: _jsx("div", { "aria-busy": "true", className: "h-32 w-full min-w-0 animate-reveal-late rounded-control border border-line-strong bg-ground" }), children: _jsx(RichTextEditor, { id: id, labelledBy: labelledBy, describedBy: describedBy, invalid: invalid, ariaLabel: ariaLabel, value: value, onChange: onChange, placeholder: placeholder, disabled: disabled, toolbar: toolbar, mentions: mentions }) }));
|
|
42
|
+
return _jsx(RichTextValue, { value: value, embeds: embeds });
|
|
43
|
+
return (_jsx(Suspense, { fallback: _jsx("div", { "aria-busy": "true", className: "h-32 w-full min-w-0 animate-reveal-late rounded-control border border-line-strong bg-ground" }), children: _jsx(RichTextEditor, { id: id, labelledBy: labelledBy, describedBy: describedBy, invalid: invalid, ariaLabel: ariaLabel, value: value, onChange: onChange, placeholder: placeholder, disabled: disabled, toolbar: toolbar, mentions: mentions, images: images, embeds: embeds }) }));
|
|
38
44
|
}
|
|
@@ -17,7 +17,7 @@ export { DataField, Field, NumberInput, ReadValue, Select, type SelectOption, Te
|
|
|
17
17
|
export { type ImageChange, ImageInput } from "./ImageInput.js";
|
|
18
18
|
export { type FieldLayout, FieldLayoutProvider, useSheetLayout, } from "./layout.js";
|
|
19
19
|
export { PasswordInput } from "./PasswordInput.js";
|
|
20
|
-
export { type MentionItem, RichTextInput, } from "./RichTextInput.js";
|
|
20
|
+
export { type MentionItem, type RichTextImages, RichTextInput, } from "./RichTextInput.js";
|
|
21
21
|
export { formatPattern, isPatternComplete, patternLength, patternValue, } from "./pattern.js";
|
|
22
22
|
export { PatternInput } from "./PatternInput.js";
|
|
23
23
|
export { SignatureInput } from "./SignatureInput.js";
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { isRichTextEmpty, richTextPlain } from "./richTextPlain.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { type EmbedProvider, type RichTextPolicyOptions } from "./richTextPolicy.js";
|
|
3
|
+
/** The HTML with everything that runs taken out, or `null` where there is no DOM to do it.
|
|
4
|
+
* `embeds` lets the players of those video hosts through (`richTextPolicy.ts`). */
|
|
5
|
+
export declare function sanitizeRichText(html: string, options?: RichTextPolicyOptions): string | null;
|
|
4
6
|
export { isRichTextEmpty, richTextPlain };
|
|
5
7
|
/** The HTML of a note, read: cleaned, in the system's text style (`rich-text` in tokens.css). */
|
|
6
|
-
export declare function RichTextValue({ value }: {
|
|
8
|
+
export declare function RichTextValue({ value, embeds, sanitized, }: {
|
|
7
9
|
value: string | null | undefined;
|
|
10
|
+
/** The video hosts whose players are drawn (`RichTextInput embeds`). Without it, no iframe. */
|
|
11
|
+
embeds?: readonly EmbedProvider[];
|
|
12
|
+
/**
|
|
13
|
+
* The HTML was ALREADY cleaned by a trusted server under the rich text's policy
|
|
14
|
+
* (`sanitizeRichTextWith`, or the same allow-list in the backend): draw it as HTML on the
|
|
15
|
+
* server render too, instead of its plain words. The browser cleans it again anyway. Never
|
|
16
|
+
* set it for HTML that reaches the page without that cleaning — on the server it is drawn
|
|
17
|
+
* as it comes.
|
|
18
|
+
*/
|
|
19
|
+
sanitized?: boolean;
|
|
8
20
|
}): import("react").JSX.Element;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
4
|
import { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
5
|
+
import { sanitizeRichTextWith, } from "./richTextPolicy.js";
|
|
5
6
|
import DOMPurify from "dompurify";
|
|
6
7
|
import { useSyncExternalStore } from "react";
|
|
7
8
|
/* ==================================================================== *
|
|
@@ -20,79 +21,25 @@ import { useSyncExternalStore } from "react";
|
|
|
20
21
|
* safe answer is the TEXT, tags removed and escaped by React — never the HTML
|
|
21
22
|
* unchecked. The browser then upgrades it to the cleaned HTML; the switch goes
|
|
22
23
|
* through `useSyncExternalStore`, so hydration does not see two different trees.
|
|
24
|
+
*
|
|
25
|
+
* ── Unless the server already cleaned it (`sanitized`) ──────────────
|
|
26
|
+
*
|
|
27
|
+
* An article read by a search engine, or by anyone before the scripts arrive,
|
|
28
|
+
* needs its headings, images and video in the server's HTML. `sanitized` is
|
|
29
|
+
* the application saying «this HTML was cleaned by a server I trust, under the
|
|
30
|
+
* same policy» (`richTextPolicy.ts`): then the server render draws it AS HTML.
|
|
31
|
+
* It is a contract, not a check — on the server nothing can verify it, so a
|
|
32
|
+
* value that skipped that cleaning runs in the reader's page. The browser does
|
|
33
|
+
* not take the word for it: once hydrated, the value is cleaned by DOMPurify
|
|
34
|
+
* again, as without the flag. If the server's cleaning produced the same
|
|
35
|
+
* string (`sanitizeRichTextWith` with the same options does), nothing moves.
|
|
23
36
|
* ==================================================================== */
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"strong",
|
|
28
|
-
"b",
|
|
29
|
-
"em",
|
|
30
|
-
"i",
|
|
31
|
-
"u",
|
|
32
|
-
"s",
|
|
33
|
-
"strike",
|
|
34
|
-
"del",
|
|
35
|
-
"code",
|
|
36
|
-
"pre",
|
|
37
|
-
"h1",
|
|
38
|
-
"h2",
|
|
39
|
-
"h3",
|
|
40
|
-
"h4",
|
|
41
|
-
"ul",
|
|
42
|
-
"ol",
|
|
43
|
-
"li",
|
|
44
|
-
"blockquote",
|
|
45
|
-
"hr",
|
|
46
|
-
"a",
|
|
47
|
-
"span",
|
|
48
|
-
"table",
|
|
49
|
-
"thead",
|
|
50
|
-
"tbody",
|
|
51
|
-
"tr",
|
|
52
|
-
"th",
|
|
53
|
-
"td",
|
|
54
|
-
"colgroup",
|
|
55
|
-
"col",
|
|
56
|
-
"img",
|
|
57
|
-
];
|
|
58
|
-
const ALLOWED_ATTR = [
|
|
59
|
-
"href",
|
|
60
|
-
"title",
|
|
61
|
-
"colspan",
|
|
62
|
-
"rowspan",
|
|
63
|
-
"src",
|
|
64
|
-
"alt",
|
|
65
|
-
"data-type",
|
|
66
|
-
"data-id",
|
|
67
|
-
"data-label",
|
|
68
|
-
];
|
|
69
|
-
let hooked = false;
|
|
70
|
-
/** The HTML with everything that runs taken out, or `null` where there is no DOM to do it. */
|
|
71
|
-
export function sanitizeRichText(html) {
|
|
37
|
+
/** The HTML with everything that runs taken out, or `null` where there is no DOM to do it.
|
|
38
|
+
* `embeds` lets the players of those video hosts through (`richTextPolicy.ts`). */
|
|
39
|
+
export function sanitizeRichText(html, options = {}) {
|
|
72
40
|
if (typeof window === "undefined" || !DOMPurify.isSupported)
|
|
73
41
|
return null;
|
|
74
|
-
|
|
75
|
-
hooked = true;
|
|
76
|
-
DOMPurify.addHook("afterSanitizeAttributes", (node) => {
|
|
77
|
-
if (node.tagName === "A") {
|
|
78
|
-
node.setAttribute("target", "_blank");
|
|
79
|
-
node.setAttribute("rel", "noopener noreferrer");
|
|
80
|
-
}
|
|
81
|
-
if (node.tagName === "IMG") {
|
|
82
|
-
/* An image whose address was not allowed is a broken box: gone. One without a
|
|
83
|
-
description is read as decoration (`alt=""`) instead of as its file name. */
|
|
84
|
-
if (!node.hasAttribute("src"))
|
|
85
|
-
node.remove();
|
|
86
|
-
else if (!node.hasAttribute("alt"))
|
|
87
|
-
node.setAttribute("alt", "");
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return DOMPurify.sanitize(html, {
|
|
92
|
-
ALLOWED_TAGS,
|
|
93
|
-
ALLOWED_ATTR,
|
|
94
|
-
ALLOWED_URI_REGEXP: /^(?:https?:|mailto:|tel:|data:image\/(?:png|jpeg|gif|webp);)/i,
|
|
95
|
-
});
|
|
42
|
+
return sanitizeRichTextWith(DOMPurify, html, options);
|
|
96
43
|
}
|
|
97
44
|
/* `richTextPlain` and `isRichTextEmpty` are plain functions (`richTextPlain.ts`), without the
|
|
98
45
|
directive, so a server component reads them; re-exported so every path that read them here
|
|
@@ -100,16 +47,22 @@ export function sanitizeRichText(html) {
|
|
|
100
47
|
export { isRichTextEmpty, richTextPlain };
|
|
101
48
|
const subscribe = () => () => { };
|
|
102
49
|
/** The HTML of a note, read: cleaned, in the system's text style (`rich-text` in tokens.css). */
|
|
103
|
-
export function RichTextValue({ value }) {
|
|
50
|
+
export function RichTextValue({ value, embeds, sanitized = false, }) {
|
|
104
51
|
const unset = useUiCopy().field.unset;
|
|
105
52
|
const inBrowser = useSyncExternalStore(subscribe, () => true, () => false);
|
|
106
53
|
if (isRichTextEmpty(value)) {
|
|
107
54
|
return _jsx("span", { className: "text-meta text-muted italic", children: unset });
|
|
108
55
|
}
|
|
109
56
|
const html = value ?? "";
|
|
110
|
-
const clean = inBrowser
|
|
57
|
+
const clean = inBrowser
|
|
58
|
+
? sanitizeRichText(html, { embeds })
|
|
59
|
+
: sanitized
|
|
60
|
+
? /* Cleaned by the server, by the application's word (`sanitized`, above). */
|
|
61
|
+
html
|
|
62
|
+
: null;
|
|
111
63
|
if (clean === null)
|
|
112
64
|
return _jsx("p", { className: "rich-text", children: richTextPlain(html) });
|
|
113
|
-
/* Cleaned by DOMPurify just above, with the tags and URLs
|
|
65
|
+
/* Cleaned by DOMPurify just above, with the tags and URLs of `richTextPolicy.ts` — or, on
|
|
66
|
+
the server render, by the server the application vouches for. */
|
|
114
67
|
return _jsx("div", { className: "rich-text min-w-0", dangerouslySetInnerHTML: { __html: clean } });
|
|
115
68
|
}
|
|
@@ -13,6 +13,7 @@ export { QrCode, type QrCodeProps } from "./QrCode.js";
|
|
|
13
13
|
export { RelationCard, type RelationCardProps, type RelationSummary, RelationValue, type RelationValueProps, } from "./Relation.js";
|
|
14
14
|
export { RichTextValue, sanitizeRichText } from "./RichText.js";
|
|
15
15
|
export { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
16
|
+
export { EMBED_IFRAME_ATTRIBUTES, embedOf, type EmbedProvider, embedProviderOf, isRichTextUri, RICH_TEXT_ALLOWED_ATTR, RICH_TEXT_ALLOWED_TAGS, RICH_TEXT_URI, type RichTextPolicyOptions, richTextPurifyConfig, sanitizeRichTextWith, } from "./richTextPolicy.js";
|
|
16
17
|
export { type Rounding, type RoundingMethod, roundTo, } from "./rounding.js";
|
|
17
18
|
export { Elapsed, type ElapsedProps } from "./Elapsed.js";
|
|
18
19
|
export { elapsedMillis, type ElapsedSince, type ElapsedThresholds, elapsedTone, formatElapsed, sinceMillis, } from "./elapsedTime.js";
|
|
@@ -20,6 +20,8 @@ export { RelationCard, RelationValue, } from "./Relation.js";
|
|
|
20
20
|
/* The HTML of a note, read — cleaned of anything that runs. */
|
|
21
21
|
export { RichTextValue, sanitizeRichText } from "./RichText.js";
|
|
22
22
|
export { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
23
|
+
/* The rich text's policy — the same allow-list for the browser, the editor and a server. */
|
|
24
|
+
export { EMBED_IFRAME_ATTRIBUTES, embedOf, embedProviderOf, isRichTextUri, RICH_TEXT_ALLOWED_ATTR, RICH_TEXT_ALLOWED_TAGS, RICH_TEXT_URI, richTextPurifyConfig, sanitizeRichTextWith, } from "./richTextPolicy.js";
|
|
23
25
|
export { roundTo, } from "./rounding.js";
|
|
24
26
|
/* HOW LONG IT HAS BEEN WAITING — a kitchen's ticket, a case under an SLA: live, in a tone by
|
|
25
27
|
two thresholds. The arithmetic is pure (`elapsedTime.ts`), so a sort or a server reads it. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** The words of an HTML, without its tags: what is shown where it cannot be cleaned. */
|
|
2
2
|
export declare function richTextPlain(html: string): string;
|
|
3
|
-
/** Nothing written: no text
|
|
3
|
+
/** Nothing written: no text, no image, no video — «<p></p>» from an emptied editor counts as nothing. */
|
|
4
4
|
export declare function isRichTextEmpty(html: string | null | undefined): boolean;
|
|
@@ -15,9 +15,9 @@ export function richTextPlain(html) {
|
|
|
15
15
|
.replace(/\s+/g, " ")
|
|
16
16
|
.trim();
|
|
17
17
|
}
|
|
18
|
-
/** Nothing written: no text
|
|
18
|
+
/** Nothing written: no text, no image, no video — «<p></p>» from an emptied editor counts as nothing. */
|
|
19
19
|
export function isRichTextEmpty(html) {
|
|
20
20
|
if (html === null || html === undefined)
|
|
21
21
|
return true;
|
|
22
|
-
return richTextPlain(html) === "" && !/<(?:img|hr|table)\b/i.test(html);
|
|
22
|
+
return richTextPlain(html) === "" && !/<(?:img|hr|table|iframe)\b/i.test(html);
|
|
23
23
|
}
|