@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.
Files changed (47) hide show
  1. package/README.md +66 -4
  2. package/dist/components/index.d.ts +1 -0
  3. package/dist/components/index.js +1 -0
  4. package/dist/components/media/Carousel.d.ts +34 -0
  5. package/dist/components/media/Carousel.js +148 -0
  6. package/dist/components/media/Stories.d.ts +71 -0
  7. package/dist/components/media/Stories.js +174 -0
  8. package/dist/components/media/index.d.ts +2 -0
  9. package/dist/components/media/index.js +4 -0
  10. package/dist/components/media/motion.d.ts +7 -0
  11. package/dist/components/media/motion.js +17 -0
  12. package/dist/components/navigation/PortalNav.d.ts +49 -0
  13. package/dist/components/navigation/PortalNav.js +40 -0
  14. package/dist/components/navigation/index.d.ts +1 -0
  15. package/dist/components/navigation/index.js +3 -0
  16. package/dist/components/preview/FilePreview.d.ts +5 -3
  17. package/dist/components/preview/FilePreview.js +39 -3
  18. package/dist/components/preview/index.d.ts +1 -1
  19. package/dist/components/preview/index.js +1 -1
  20. package/dist/components/preview/previewKind.d.ts +12 -2
  21. package/dist/components/preview/previewKind.js +44 -2
  22. package/dist/components/shell/Notifications.d.ts +64 -0
  23. package/dist/components/shell/Notifications.js +84 -0
  24. package/dist/components/shell/index.d.ts +1 -0
  25. package/dist/components/shell/index.js +3 -0
  26. package/dist/foundations/copy.es.js +39 -0
  27. package/dist/foundations/uiCopy.d.ts +67 -0
  28. package/dist/foundations/uiCopy.js +46 -1
  29. package/dist/primitives/choice/CheckField.d.ts +26 -0
  30. package/dist/primitives/choice/CheckField.js +45 -0
  31. package/dist/primitives/choice/index.d.ts +1 -0
  32. package/dist/primitives/choice/index.js +2 -0
  33. package/dist/primitives/field/RichTextEditor.d.ts +13 -1
  34. package/dist/primitives/field/RichTextEditor.js +152 -8
  35. package/dist/primitives/field/RichTextInput.d.ts +14 -3
  36. package/dist/primitives/field/RichTextInput.js +9 -3
  37. package/dist/primitives/field/index.d.ts +1 -1
  38. package/dist/primitives/value/RichText.d.ts +15 -3
  39. package/dist/primitives/value/RichText.js +26 -73
  40. package/dist/primitives/value/index.d.ts +1 -0
  41. package/dist/primitives/value/index.js +2 -0
  42. package/dist/primitives/value/richTextPlain.d.ts +1 -1
  43. package/dist/primitives/value/richTextPlain.js +2 -2
  44. package/dist/primitives/value/richTextPolicy.d.ts +39 -0
  45. package/dist/primitives/value/richTextPolicy.js +195 -0
  46. package/dist/tokens.css +22 -0
  47. package/package.json +2 -1
@@ -0,0 +1,39 @@
1
+ import type { Config, DOMPurify } from "dompurify";
2
+ /** A video host the rich text may embed. */
3
+ export type EmbedProvider = "youtube" | "vimeo";
4
+ /** The tags a rich text keeps. `div` and `iframe` are added only when embeds are allowed. */
5
+ export declare const RICH_TEXT_ALLOWED_TAGS: readonly string[];
6
+ /** The attributes a rich text keeps (`data-embed` only when embeds are allowed). */
7
+ export declare const RICH_TEXT_ALLOWED_ATTR: readonly string[];
8
+ /** The addresses a link or an image may have: web, email, phone, an inline picture, or a
9
+ * relative one. Anything that starts with another scheme is not matched. */
10
+ export declare const RICH_TEXT_URI: RegExp;
11
+ /** Whether an address may stay in a link or an image — the test DOMPurify makes. */
12
+ export declare function isRichTextUri(address: string): boolean;
13
+ /** The provider whose canonical player this address is — or `null`. Exact, no variants. */
14
+ export declare function embedProviderOf(src: string, providers: readonly EmbedProvider[]): EmbedProvider | null;
15
+ /**
16
+ * The player for a video's address as people copy it — a YouTube watch, short, live or
17
+ * `youtu.be` link, a Vimeo page — or `null` when it is not a video of an allowed provider.
18
+ * YouTube always plays from `youtube-nocookie.com`; Vimeo from `player.vimeo.com`.
19
+ */
20
+ export declare function embedOf(address: string, providers: readonly EmbedProvider[]): {
21
+ provider: EmbedProvider;
22
+ src: string;
23
+ } | null;
24
+ /** The attributes a video's player is drawn with — written, never taken from the HTML. */
25
+ export declare const EMBED_IFRAME_ATTRIBUTES: Readonly<Record<string, string>>;
26
+ /** What the rich text is cleaned for. */
27
+ export type RichTextPolicyOptions = {
28
+ /** The video hosts whose players survive. Without it, every `<iframe>` is dropped. */
29
+ embeds?: readonly EmbedProvider[] | undefined;
30
+ };
31
+ /** The DOMPurify configuration of the policy (the hooks are in `sanitizeRichTextWith`). */
32
+ export declare function richTextPurifyConfig(options?: RichTextPolicyOptions): Config;
33
+ /**
34
+ * A note's HTML cleaned under the policy with the DOMPurify you bring: the browser's, or — on
35
+ * a server — one bound to a jsdom window (`DOMPurify(new JSDOM("").window)`). Links open in
36
+ * another tab without our window; an image without an allowed address is removed and one
37
+ * without a description is marked as decoration; a video stays only as an allowed player.
38
+ */
39
+ export declare function sanitizeRichTextWith(purify: DOMPurify, html: string, options?: RichTextPolicyOptions): string;
@@ -0,0 +1,195 @@
1
+ /** The tags a rich text keeps. `div` and `iframe` are added only when embeds are allowed. */
2
+ export const RICH_TEXT_ALLOWED_TAGS = [
3
+ "p",
4
+ "br",
5
+ "strong",
6
+ "b",
7
+ "em",
8
+ "i",
9
+ "u",
10
+ "s",
11
+ "strike",
12
+ "del",
13
+ "code",
14
+ "pre",
15
+ "h1",
16
+ "h2",
17
+ "h3",
18
+ "h4",
19
+ "ul",
20
+ "ol",
21
+ "li",
22
+ "blockquote",
23
+ "hr",
24
+ "a",
25
+ "span",
26
+ "table",
27
+ "thead",
28
+ "tbody",
29
+ "tr",
30
+ "th",
31
+ "td",
32
+ "colgroup",
33
+ "col",
34
+ "img",
35
+ ];
36
+ /** The attributes a rich text keeps (`data-embed` only when embeds are allowed). */
37
+ export const RICH_TEXT_ALLOWED_ATTR = [
38
+ "href",
39
+ "title",
40
+ "colspan",
41
+ "rowspan",
42
+ "src",
43
+ "alt",
44
+ "data-type",
45
+ "data-id",
46
+ "data-label",
47
+ ];
48
+ /** The addresses a link or an image may have: web, email, phone, an inline picture, or a
49
+ * relative one. Anything that starts with another scheme is not matched. */
50
+ export const RICH_TEXT_URI = /^(?:https?:|mailto:|tel:|data:image\/(?:png|jpeg|gif|webp);|(?![a-z][a-z\d+.-]*:))/i;
51
+ /* What DOMPurify strips from an address before testing it (its ATTR_WHITESPACE). */
52
+ // eslint-disable-next-line no-control-regex
53
+ const ATTR_WHITESPACE = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
54
+ /** Whether an address may stay in a link or an image — the test DOMPurify makes. */
55
+ export function isRichTextUri(address) {
56
+ return RICH_TEXT_URI.test(address.replace(ATTR_WHITESPACE, ""));
57
+ }
58
+ const YOUTUBE_ID = /^[\w-]{11}$/;
59
+ const YOUTUBE_EMBED = /^https:\/\/www\.youtube-nocookie\.com\/embed\/[\w-]{11}(?:\?start=\d+)?$/;
60
+ const VIMEO_EMBED = /^https:\/\/player\.vimeo\.com\/video\/\d+(?:\?h=[\da-f]+)?$/;
61
+ /** The provider whose canonical player this address is — or `null`. Exact, no variants. */
62
+ export function embedProviderOf(src, providers) {
63
+ if (providers.includes("youtube") && YOUTUBE_EMBED.test(src))
64
+ return "youtube";
65
+ if (providers.includes("vimeo") && VIMEO_EMBED.test(src))
66
+ return "vimeo";
67
+ return null;
68
+ }
69
+ /** «90», «90s», «1m30s» → seconds; anything else → `null`. */
70
+ function seconds(time) {
71
+ if (time === null)
72
+ return null;
73
+ const match = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/.exec(time);
74
+ if (match === null || time === "")
75
+ return null;
76
+ const [, h = "0", m = "0", s = "0"] = match;
77
+ const total = Number(h) * 3600 + Number(m) * 60 + Number(s);
78
+ return total > 0 ? total : null;
79
+ }
80
+ /**
81
+ * The player for a video's address as people copy it — a YouTube watch, short, live or
82
+ * `youtu.be` link, a Vimeo page — or `null` when it is not a video of an allowed provider.
83
+ * YouTube always plays from `youtube-nocookie.com`; Vimeo from `player.vimeo.com`.
84
+ */
85
+ export function embedOf(address, providers) {
86
+ let url;
87
+ try {
88
+ const clean = address.trim();
89
+ url = new URL(/^[a-z][a-z\d+.-]*:\/\//i.test(clean) ? clean : `https://${clean}`);
90
+ }
91
+ catch {
92
+ return null;
93
+ }
94
+ if (url.protocol !== "https:" && url.protocol !== "http:")
95
+ return null;
96
+ const host = url.hostname.toLowerCase().replace(/^(?:www|m)\./, "");
97
+ const parts = url.pathname.split("/").filter((part) => part !== "");
98
+ if (providers.includes("youtube")) {
99
+ let id;
100
+ if (host === "youtu.be")
101
+ id = parts[0];
102
+ else if (host === "youtube.com" || host === "youtube-nocookie.com") {
103
+ if (parts[0] === "watch")
104
+ id = url.searchParams.get("v") ?? undefined;
105
+ else if (["embed", "shorts", "live", "v"].includes(parts[0] ?? ""))
106
+ id = parts[1];
107
+ }
108
+ if (id !== undefined && YOUTUBE_ID.test(id)) {
109
+ const start = seconds(url.searchParams.get("t") ?? url.searchParams.get("start"));
110
+ const src = `https://www.youtube-nocookie.com/embed/${id}${start === null ? "" : `?start=${start}`}`;
111
+ return { provider: "youtube", src };
112
+ }
113
+ }
114
+ if (providers.includes("vimeo")) {
115
+ let id;
116
+ let hash;
117
+ if (host === "player.vimeo.com" && parts[0] === "video") {
118
+ id = parts[1];
119
+ hash = url.searchParams.get("h") ?? undefined;
120
+ }
121
+ else if (host === "vimeo.com") {
122
+ const at = parts.findIndex((part) => /^\d+$/.test(part));
123
+ if (at !== -1) {
124
+ id = parts[at];
125
+ hash = parts[at + 1] ?? url.searchParams.get("h") ?? undefined;
126
+ }
127
+ }
128
+ if (id !== undefined && /^\d+$/.test(id)) {
129
+ const unlisted = hash !== undefined && /^[\da-f]+$/i.test(hash) ? hash : null;
130
+ const src = `https://player.vimeo.com/video/${id}${unlisted === null ? "" : `?h=${unlisted.toLowerCase()}`}`;
131
+ return { provider: "vimeo", src };
132
+ }
133
+ }
134
+ return null;
135
+ }
136
+ /** The attributes a video's player is drawn with — written, never taken from the HTML. */
137
+ export const EMBED_IFRAME_ATTRIBUTES = {
138
+ allow: "encrypted-media; fullscreen; picture-in-picture",
139
+ allowfullscreen: "",
140
+ loading: "lazy",
141
+ referrerpolicy: "strict-origin-when-cross-origin",
142
+ sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups",
143
+ };
144
+ /** The DOMPurify configuration of the policy (the hooks are in `sanitizeRichTextWith`). */
145
+ export function richTextPurifyConfig(options = {}) {
146
+ const embeds = (options.embeds ?? []).length > 0;
147
+ return {
148
+ ALLOWED_TAGS: [...RICH_TEXT_ALLOWED_TAGS, ...(embeds ? ["div", "iframe"] : [])],
149
+ ALLOWED_ATTR: [...RICH_TEXT_ALLOWED_ATTR, ...(embeds ? ["data-embed"] : [])],
150
+ ALLOWED_URI_REGEXP: RICH_TEXT_URI,
151
+ };
152
+ }
153
+ /**
154
+ * A note's HTML cleaned under the policy with the DOMPurify you bring: the browser's, or — on
155
+ * a server — one bound to a jsdom window (`DOMPurify(new JSDOM("").window)`). Links open in
156
+ * another tab without our window; an image without an allowed address is removed and one
157
+ * without a description is marked as decoration; a video stays only as an allowed player.
158
+ */
159
+ export function sanitizeRichTextWith(purify, html, options = {}) {
160
+ const providers = options.embeds ?? [];
161
+ const hook = (node) => {
162
+ if (node.tagName === "A") {
163
+ node.setAttribute("target", "_blank");
164
+ node.setAttribute("rel", "noopener noreferrer");
165
+ }
166
+ if (node.tagName === "IMG") {
167
+ /* An image whose address was not allowed is a broken box: gone. One without a
168
+ description is read as decoration (`alt=""`) instead of as its file name. */
169
+ if (!node.hasAttribute("src"))
170
+ node.remove();
171
+ else if (!node.hasAttribute("alt"))
172
+ node.setAttribute("alt", "");
173
+ }
174
+ if (node.tagName === "IFRAME") {
175
+ const provider = embedProviderOf(node.getAttribute("src") ?? "", providers);
176
+ if (provider === null) {
177
+ node.remove();
178
+ return;
179
+ }
180
+ /* A frame is named for whoever cannot see it; the editor writes «Video de …». Named
181
+ BEFORE the written attributes, so cleaning the output again yields the same string. */
182
+ if (!node.hasAttribute("title"))
183
+ node.setAttribute("title", provider === "youtube" ? "YouTube" : "Vimeo");
184
+ for (const [name, value] of Object.entries(EMBED_IFRAME_ATTRIBUTES))
185
+ node.setAttribute(name, value);
186
+ }
187
+ };
188
+ purify.addHook("afterSanitizeAttributes", hook);
189
+ try {
190
+ return purify.sanitize(html, richTextPurifyConfig(options));
191
+ }
192
+ finally {
193
+ purify.removeHook("afterSanitizeAttributes", hook);
194
+ }
195
+ }
package/dist/tokens.css CHANGED
@@ -1785,6 +1785,28 @@
1785
1785
  border-radius: var(--radius-mark);
1786
1786
  padding: 0 calc(var(--spacing) * 0.5);
1787
1787
  }
1788
+ /* A picture of an article never pushes the column wider than the text. */
1789
+ & img {
1790
+ max-width: 100%;
1791
+ height: auto;
1792
+ border-radius: var(--radius-control);
1793
+ }
1794
+ /* A video's player (`RichTextInput embeds`): the column's width, in the 16:9 of a video. */
1795
+ & [data-embed] {
1796
+ aspect-ratio: 16 / 9;
1797
+ width: 100%;
1798
+ }
1799
+ & [data-embed] iframe {
1800
+ width: 100%;
1801
+ height: 100%;
1802
+ border: 0;
1803
+ border-radius: var(--radius-control);
1804
+ }
1805
+ /* In the editor, the picture or player picked as one piece (a click, an arrow). */
1806
+ & .ProseMirror-selectednode {
1807
+ outline: calc(var(--spacing) * 0.5) solid var(--color-primary);
1808
+ outline-offset: calc(var(--spacing) * 0.5);
1809
+ }
1788
1810
  & p.is-editor-empty:first-child::before {
1789
1811
  content: attr(data-placeholder);
1790
1812
  color: var(--color-muted);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-ui",
3
- "version": "2.14.2",
3
+ "version": "2.16.0",
4
4
  "description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -57,6 +57,7 @@
57
57
  "@fullcalendar/react": "7.1.3",
58
58
  "@internationalized/date": "^3.12.4",
59
59
  "@svar-ui/react-gantt": "2.8.2",
60
+ "@tiptap/extension-image": "^3.32.2",
60
61
  "@tiptap/extension-mention": "^3.32.2",
61
62
  "@tiptap/extension-table": "^3.32.2",
62
63
  "@tiptap/extensions": "^3.32.2",