@und-ui/richtext 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +94 -2
- package/custom-elements.json +1048 -0
- package/dist/components/rich-text-editor/rich-text-editor.d.ts +160 -0
- package/dist/components/rich-text-editor/rich-text-editor.d.ts.map +1 -0
- package/dist/components/rich-text-editor/rich-text-editor.js +1027 -0
- package/dist/components/rich-text-editor/rich-text-editor.js.map +1 -0
- package/dist/components/rich-text-editor/rich-text-editor.styles.d.ts +12 -0
- package/dist/components/rich-text-editor/rich-text-editor.styles.d.ts.map +1 -0
- package/dist/components/rich-text-editor/rich-text-editor.styles.js +300 -0
- package/dist/components/rich-text-editor/rich-text-editor.styles.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/rich-text-editor.d.ts +2 -0
- package/dist/rich-text-editor.d.ts.map +1 -0
- package/dist/rich-text-editor.js +8 -0
- package/dist/rich-text-editor.js.map +1 -0
- package/dist/sanitize.d.ts +19 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +429 -0
- package/dist/sanitize.js.map +1 -0
- package/package.json +77 -3
- package/src/components/rich-text-editor/rich-text-editor.styles.ts +301 -0
- package/src/components/rich-text-editor/rich-text-editor.ts +1124 -0
- package/src/index.ts +3 -0
- package/src/rich-text-editor.ts +9 -0
- package/src/sanitize.ts +438 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mayank
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,95 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @und-ui/richtext
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small, security-first rich text editor for **UND UI**: `und-rich-text-editor`. A formatting toolbar
|
|
4
|
+
(bold, italic, underline, strikethrough, inline code, link, headings, quote, lists), Markdown shortcuts
|
|
5
|
+
as you type, autolinked URLs, native undo, and a form value that is always sanitized HTML (plus
|
|
6
|
+
Markdown if you want it). No editor framework: about 10 kB gzipped on top of the shared `@und-ui/core`
|
|
7
|
+
runtime.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @und-ui/richtext @und-ui/tokens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script type="module">
|
|
15
|
+
import '@und-ui/richtext/rich-text-editor.js';
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<form method="post">
|
|
19
|
+
<und-rich-text-editor
|
|
20
|
+
label="Event description"
|
|
21
|
+
name="body"
|
|
22
|
+
markdown-name="body_md"
|
|
23
|
+
placeholder="What is happening, when and where?"
|
|
24
|
+
required
|
|
25
|
+
></und-rich-text-editor>
|
|
26
|
+
</form>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Attribute / property | What it does |
|
|
30
|
+
| -------------------- | -------------------------------------------------------------------------- |
|
|
31
|
+
| `label` | Visible label and accessible name of the editing area |
|
|
32
|
+
| `value` | The content as HTML. Input is sanitized; reading it returns sanitized HTML |
|
|
33
|
+
| `markdown` (read) | The content as Markdown (CommonMark plus `~~strikethrough~~`) |
|
|
34
|
+
| `name` | Form field name for the HTML |
|
|
35
|
+
| `markdown-name` | Optional second form field with the Markdown |
|
|
36
|
+
| `placeholder` | Text shown while empty |
|
|
37
|
+
| `required` | Requires some text (native constraint validation) |
|
|
38
|
+
| `disabled` | Disables editing (a disabled `<fieldset>` does too) |
|
|
39
|
+
| `readonly` | Shows the content without allowing edits |
|
|
40
|
+
| `no-toolbar` | Hides the toolbar (shortcuts still work) |
|
|
41
|
+
|
|
42
|
+
Children written inside the element are the initial content (their safe parts only).
|
|
43
|
+
|
|
44
|
+
## Shortcuts
|
|
45
|
+
|
|
46
|
+
- Ctrl/Cmd + B, I, U, E (code), K (link), Shift + X (strikethrough).
|
|
47
|
+
- At the start of a paragraph, then a space: `#` or `##` heading, `###` subheading, `-` or `*` list,
|
|
48
|
+
`1.` numbered list, `>` quote, ` ``` ` code block.
|
|
49
|
+
- Inline, when the closing mark is typed: `**bold**`, `_italic_` or `*italic*`, `~~strike~~`, `` `code` ``.
|
|
50
|
+
- A URL (`https://…` or `www.…`) becomes a link when you type a space or press Enter after it.
|
|
51
|
+
- The toolbar is one tab stop: arrow keys, Home and End move between buttons; Escape returns to the text.
|
|
52
|
+
|
|
53
|
+
## Security
|
|
54
|
+
|
|
55
|
+
- Pasted, dropped and assigned HTML is parsed into an inert document and rebuilt node by node from an
|
|
56
|
+
allowlist: `p h2 h3 ul ol li blockquote pre strong em u s code a br`. Everything else is unwrapped
|
|
57
|
+
or (scripts, styles, frames, SVG, MathML, forms, media) dropped with its content. No attributes
|
|
58
|
+
survive except `href` on links, and only for safe schemes (`http`, `https`, `mailto`, `tel` and
|
|
59
|
+
relative URLs; `javascript:`, `data:` and friends are refused). Links get
|
|
60
|
+
`rel="noopener noreferrer nofollow"`.
|
|
61
|
+
- The value is written by a serializer that escapes every text node; no `innerHTML` or other HTML
|
|
62
|
+
sink touches the page.
|
|
63
|
+
- Trusted Types: the only HTML parse goes to the inert `DOMParser` through a policy named
|
|
64
|
+
`und-ui-richtext`. Allow it (`trusted-types und-ui-richtext`); if the policy is blocked, pasted HTML
|
|
65
|
+
is inserted as plain text instead.
|
|
66
|
+
- Still sanitize on the server before you render stored HTML to other users: client-side checks can
|
|
67
|
+
be bypassed by anyone posting to your form directly. The sanitizer is exported
|
|
68
|
+
(`sanitizeHtml`, `sanitizeNode`, `toHtml`, `toMarkdown`, `cleanHref` from
|
|
69
|
+
`@und-ui/richtext/sanitize.js`) for Node with a DOM implementation, but a server-side library such
|
|
70
|
+
as DOMPurify or your framework's sanitizer is the right place for that.
|
|
71
|
+
|
|
72
|
+
## Accessibility
|
|
73
|
+
|
|
74
|
+
The editing area is a light-DOM `contenteditable` with `role="textbox"` and `aria-multiline`, named
|
|
75
|
+
by the visible label, so screen readers, spell checkers, browser translation and IME input behave as
|
|
76
|
+
on a plain editable region. Toolbar buttons are toggle buttons (`aria-pressed`) that follow the caret,
|
|
77
|
+
with `aria-keyshortcuts`. The link form is a labelled input with an error message announced by
|
|
78
|
+
`role="alert"`. Reduced motion and forced colours are supported.
|
|
79
|
+
|
|
80
|
+
Built-in strings are English; replace them with `setRichTextStrings({ bold, italic, link, … })`.
|
|
81
|
+
|
|
82
|
+
Visual design ported from Astryx (MIT, (c) Meta Platforms, Inc.); see `THIRD_PARTY_NOTICES.md` in the
|
|
83
|
+
repository. Toolbar icons from Lucide (ISC).
|
|
84
|
+
|
|
85
|
+
## Licence
|
|
86
|
+
|
|
87
|
+
MIT
|
|
88
|
+
|
|
89
|
+
## Framework wrappers
|
|
90
|
+
|
|
91
|
+
React, Vue and Angular wrappers ship in the framework packages as an optional subpath, so the main
|
|
92
|
+
framework entry never loads this package: `@und-ui/react/richtext`, `@und-ui/vue/richtext`,
|
|
93
|
+
`@und-ui/angular/richtext` (and `@und-ui/angular/richtext/forms` for ngModel and
|
|
94
|
+
formControl). Svelte and Solid typings: `@und-ui/svelte/richtext`, `@und-ui/solid/richtext`.
|
|
95
|
+
This package is an optional peer dependency of each of them.
|