@advui/editor 0.5.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 (28) hide show
  1. package/LICENSE +49 -0
  2. package/README.md +35 -0
  3. package/dist/components/rich-text-editor/RichTextContent.d.ts +10 -0
  4. package/dist/components/rich-text-editor/RichTextContent.d.ts.map +1 -0
  5. package/dist/components/rich-text-editor/RichTextContent.js +49 -0
  6. package/dist/components/rich-text-editor/RichTextContent.js.map +1 -0
  7. package/dist/components/rich-text-editor/RichTextEditor.d.ts +44 -0
  8. package/dist/components/rich-text-editor/RichTextEditor.d.ts.map +1 -0
  9. package/dist/components/rich-text-editor/RichTextEditor.js +144 -0
  10. package/dist/components/rich-text-editor/RichTextEditor.js.map +1 -0
  11. package/dist/components/rich-text-editor/index.d.ts +4 -0
  12. package/dist/components/rich-text-editor/index.d.ts.map +1 -0
  13. package/dist/components/rich-text-editor/index.js +4 -0
  14. package/dist/components/rich-text-editor/index.js.map +1 -0
  15. package/dist/components/rich-text-editor/markdown.d.ts +56 -0
  16. package/dist/components/rich-text-editor/markdown.d.ts.map +1 -0
  17. package/dist/components/rich-text-editor/markdown.js +203 -0
  18. package/dist/components/rich-text-editor/markdown.js.map +1 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +3 -0
  22. package/dist/index.js.map +1 -0
  23. package/package.json +85 -0
  24. package/src/components/rich-text-editor/RichTextContent.tsx +119 -0
  25. package/src/components/rich-text-editor/RichTextEditor.tsx +330 -0
  26. package/src/components/rich-text-editor/index.ts +14 -0
  27. package/src/components/rich-text-editor/markdown.ts +244 -0
  28. package/src/index.ts +2 -0
package/LICENSE ADDED
@@ -0,0 +1,49 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Universal UI contributors
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.
22
+
23
+ ---------------------------------------------------------------------------
24
+
25
+ Third-party notices
26
+
27
+ Icons in packages/icons are generated from Lucide (https://lucide.dev),
28
+ licensed under the ISC License:
29
+
30
+ ISC License
31
+ Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part
32
+ of Feather (MIT). All other copyright (c) for Lucide are held by Lucide
33
+ Contributors 2022.
34
+
35
+ Permission to use, copy, modify, and/or distribute this software for any
36
+ purpose with or without fee is hereby granted, provided that the above
37
+ copyright notice and this permission notice appear in all copies.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
40
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
41
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
42
+ SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
43
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
44
+ OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
45
+ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
46
+
47
+ Color scales in packages/theme are based on Radix Colors
48
+ (https://github.com/radix-ui/colors), licensed under the MIT License,
49
+ Copyright (c) 2022 WorkOS.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @advui/editor
2
+
3
+ Rich text editing for [Adv UI](https://github.com/zinmin232/advui), on web,
4
+ iOS and Android. `RichTextEditor` is a Markdown editor with a formatting
5
+ toolbar (bold, italic, strikethrough, heading, lists, quote, link, code),
6
+ keyboard shortcuts, a preview and a character count. `RichTextContent` shows
7
+ the same Markdown with the same styles; only `http(s)` and `mailto` links are
8
+ kept.
9
+
10
+ > Not on npm yet: `@advui/editor` will be published with the next release.
11
+ > Until then, copy the editor into your app with the CLI:
12
+ > `npx advui add rich-text-editor`.
13
+
14
+ ```bash
15
+ pnpm add @advui/editor @advui/core @advui/theme @advui/icons tamagui
16
+ ```
17
+
18
+ ```tsx
19
+ import { RichTextContent, RichTextEditor } from '@advui/editor'
20
+
21
+ <RichTextEditor aria-label="Report" value={markdown} onValueChange={setMarkdown} />
22
+
23
+ // Show saved text:
24
+ <RichTextContent>{markdown}</RichTextContent>
25
+ ```
26
+
27
+ The editor works the same on every platform and uses no editor engine: it
28
+ edits Markdown text in core's Textarea. It renders inside the app's
29
+ `UniversalProvider` from `@advui/core`, which is a peer dependency, as are
30
+ `react`, `react-native` and `tamagui`.
31
+
32
+ **Exports:** RichTextEditor, RichTextContent, `defaultRichTextTools`,
33
+ `applyFormat`, `parseMarkdown` and their types.
34
+
35
+ Docs: https://zinmin232.github.io/advui/docs/components/rich-text-editor. License: MIT.
@@ -0,0 +1,10 @@
1
+ import { type GetProps, View } from 'tamagui';
2
+ export interface RichTextContentProps extends Omit<GetProps<typeof View>, 'children'> {
3
+ /** Markdown, as written by Rich Text Editor. */
4
+ children: string;
5
+ /** Added to heading levels: with 1 (default), `#` is an h2 under your page's h1. */
6
+ headingOffset?: number;
7
+ }
8
+ /** Shows Markdown written with Rich Text Editor, with the same styles on every platform. */
9
+ export declare function RichTextContent({ children, headingOffset, ...props }: RichTextContentProps): import("react").JSX.Element;
10
+ //# sourceMappingURL=RichTextContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextContent.d.ts","sourceRoot":"","sources":["../../../src/components/rich-text-editor/RichTextContent.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAA;AAsG5D,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,EAAE,UAAU,CAAC;IACnF,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAA;IAChB,oFAAoF;IACpF,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,aAAiB,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,+BAM9F"}
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment } from 'react';
3
+ import { Linking } from 'react-native';
4
+ import { View, XStack, isWeb } from 'tamagui';
5
+ import { Text } from '@advui/core';
6
+ import { parseMarkdown } from './markdown';
7
+ const headingSizes = { 1: 'xl', 2: 'lg', 3: 'base' };
8
+ // Nested text takes the block's size: Text's own default would reset it.
9
+ function Inline({ nodes, size }) {
10
+ return nodes.map((node, i) => {
11
+ switch (node.type) {
12
+ case 'text':
13
+ return _jsx(Fragment, { children: node.text }, i);
14
+ case 'code':
15
+ return (_jsx(Text, { mono: true, size: size, backgroundColor: "$muted", borderRadius: "$xs", children: ` ${node.text} ` }, i));
16
+ case 'bold':
17
+ return (_jsx(Text, { size: size, fontWeight: "700", children: _jsx(Inline, { nodes: node.children, size: size }) }, i));
18
+ case 'italic':
19
+ return (_jsx(Text, { size: size, fontStyle: "italic", children: _jsx(Inline, { nodes: node.children, size: size }) }, i));
20
+ case 'strike':
21
+ return (_jsx(Text, { size: size, textDecorationLine: "line-through", children: _jsx(Inline, { nodes: node.children, size: size }) }, i));
22
+ case 'link':
23
+ return (_jsx(Text, { size: size, tone: "primary", textDecorationLine: "underline", ...(isWeb
24
+ ? { render: 'a', href: node.href, target: '_blank', rel: 'noopener noreferrer' }
25
+ : { role: 'link', onPress: () => void Linking.openURL(node.href) }), children: _jsx(Inline, { nodes: node.children, size: size }) }, i));
26
+ }
27
+ });
28
+ }
29
+ function Blocks({ blocks, headingOffset }) {
30
+ return blocks.map((block, i) => {
31
+ switch (block.type) {
32
+ case 'heading': {
33
+ const size = headingSizes[block.level] ?? 'base';
34
+ return (_jsx(Text, { role: "heading", "aria-level": Math.min(6, block.level + headingOffset), size: size, weight: "semibold", children: _jsx(Inline, { nodes: block.children, size: size }) }, i));
35
+ }
36
+ case 'paragraph':
37
+ return (_jsx(Text, { size: "sm", children: _jsx(Inline, { nodes: block.children, size: "sm" }) }, i));
38
+ case 'quote':
39
+ return (_jsx(View, { borderLeftWidth: 3, borderColor: "$border", paddingLeft: "$3", gap: "$2", children: _jsx(Blocks, { blocks: block.children, headingOffset: headingOffset }) }, i));
40
+ case 'list':
41
+ return (_jsx(View, { gap: "$1", ...(isWeb && { role: 'list' }), children: block.items.map((item, j) => (_jsxs(XStack, { gap: "$2", ...(isWeb && { role: 'listitem' }), children: [_jsx(Text, { "aria-hidden": true, size: "sm", tone: "muted", minWidth: "$4", textAlign: "right", children: block.ordered ? `${block.start + j}.` : '•' }), _jsx(Text, { size: "sm", flex: 1, children: _jsx(Inline, { nodes: item, size: "sm" }) })] }, j))) }, i));
42
+ }
43
+ });
44
+ }
45
+ /** Shows Markdown written with Rich Text Editor, with the same styles on every platform. */
46
+ export function RichTextContent({ children, headingOffset = 1, ...props }) {
47
+ return (_jsx(View, { gap: "$3", ...props, children: _jsx(Blocks, { blocks: parseMarkdown(children), headingOffset: headingOffset }) }));
48
+ }
49
+ //# sourceMappingURL=RichTextContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextContent.js","sourceRoot":"","sources":["../../../src/components/rich-text-editor/RichTextContent.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAiB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,EAAE,IAAI,EAAiB,MAAM,aAAa,CAAA;AACjD,OAAO,EAAmC,aAAa,EAAE,MAAM,YAAY,CAAA;AAE3E,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAW,CAAA;AAE7D,yEAAyE;AACzE,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAA2C;IACtE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QAC3B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,MAAM;gBACT,OAAO,KAAC,QAAQ,cAAU,IAAI,CAAC,IAAI,IAAb,CAAC,CAAwB,CAAA;YACjD,KAAK,MAAM;gBACT,OAAO,CACL,KAAC,IAAI,IAAS,IAAI,QAAC,IAAI,EAAE,IAAI,EAAE,eAAe,EAAC,QAAQ,EAAC,YAAY,EAAC,KAAK,YACvE,IAAI,IAAI,CAAC,IAAI,GAAG,IADR,CAAC,CAEL,CACR,CAAA;YACH,KAAK,MAAM;gBACT,OAAO,CACL,KAAC,IAAI,IAAS,IAAI,EAAE,IAAI,EAAE,UAAU,EAAC,KAAK,YACxC,KAAC,MAAM,IAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAI,IADnC,CAAC,CAE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C,SAAS,EAAC,OAAO,YACrE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GACvC,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAE,CAAC,YACrB,KAAC,MAAM,IAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAC,IAAI,GAAG,GAC5B,KANI,CAAC,CAOL,CACV,CAAC,IAVO,CAAC,CAWL,CACR,CAAA;QACL,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AASD,4FAA4F;AAC5F,MAAM,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,aAAa,GAAG,CAAC,EAAE,GAAG,KAAK,EAAwB;IAC7F,OAAO,CACL,KAAC,IAAI,IAAC,GAAG,EAAC,IAAI,KAAK,KAAK,YACtB,KAAC,MAAM,IAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,aAAa,EAAE,aAAa,GAAI,GACpE,CACR,CAAA;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { type GetProps, View } from 'tamagui';
2
+ import { type RichTextTool } from './markdown';
3
+ export interface RichTextEditorLabels {
4
+ toolbar: string;
5
+ tools: Record<RichTextTool, string>;
6
+ preview: string;
7
+ /** Shown in the preview when there is nothing to show. */
8
+ empty: string;
9
+ /** Character count with `maxLength`: "120 of 500 characters". */
10
+ count: (length: number, max: number) => string;
11
+ }
12
+ export declare const defaultRichTextTools: RichTextTool[];
13
+ export interface RichTextEditorProps {
14
+ /** Markdown (controlled). */
15
+ value?: string;
16
+ defaultValue?: string;
17
+ onValueChange?: (value: string) => void;
18
+ placeholder?: string;
19
+ /** Toolbar buttons, in order. Default: all nine. */
20
+ tools?: RichTextTool[];
21
+ /** Minimum height of the text area. Default: `$32`. */
22
+ minHeight?: GetProps<typeof View>['minHeight'];
23
+ maxLength?: number;
24
+ disabled?: boolean;
25
+ invalid?: boolean;
26
+ id?: string;
27
+ 'aria-label'?: string;
28
+ 'aria-labelledby'?: string;
29
+ 'aria-describedby'?: string;
30
+ 'aria-required'?: boolean;
31
+ /** Native: help read after the name (Form Field sets it). */
32
+ accessibilityHint?: string;
33
+ /** Toolbar, tool and preview names, for translation. */
34
+ labels?: Partial<Omit<RichTextEditorLabels, 'tools'>> & {
35
+ tools?: Partial<RichTextEditorLabels['tools']>;
36
+ };
37
+ }
38
+ /**
39
+ * A Markdown editor with a formatting toolbar and a preview. It stores plain
40
+ * Markdown, so the text is safe to save and shows the same on every platform
41
+ * with Rich Text Content.
42
+ */
43
+ export declare function RichTextEditor({ value: valueProp, defaultValue, onValueChange, placeholder, tools, minHeight, maxLength, disabled, invalid, id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-required': ariaRequired, accessibilityHint, labels: labelsProp, }: RichTextEditorProps): import("react").JSX.Element;
44
+ //# sourceMappingURL=RichTextEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextEditor.d.ts","sourceRoot":"","sources":["../../../src/components/rich-text-editor/RichTextEditor.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,QAAQ,EAAuB,IAAI,EAAiB,MAAM,SAAS,CAAA;AAUjF,OAAO,EAAE,KAAK,YAAY,EAA8C,MAAM,YAAY,CAAA;AAE1F,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAA;IACb,iEAAiE;IACjE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;CAC/C;AAkCD,eAAO,MAAM,oBAAoB,EAAE,YAAY,EAU9C,CAAA;AAED,MAAM,WAAW,m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mMrB"}
@@ -0,0 +1,144 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { BoldIcon, CodeIcon, HeadingIcon, ItalicIcon, LinkIcon, ListIcon, ListOrderedIcon, QuoteIcon, StrikethroughIcon, } from '@advui/icons';
3
+ import { useId, useLayoutEffect, useRef, useState } from 'react';
4
+ import { View, XStack, isWeb } from 'tamagui';
5
+ import { Button, IconButton, Text, Textarea, fieldBoxStyle, useControllableState, } from '@advui/core';
6
+ import { RichTextContent } from './RichTextContent';
7
+ import { applyFormat, shortcuts } from './markdown';
8
+ const defaultLabels = {
9
+ toolbar: 'Formatting',
10
+ tools: {
11
+ bold: 'Bold',
12
+ italic: 'Italic',
13
+ strikethrough: 'Strikethrough',
14
+ code: 'Code',
15
+ link: 'Link',
16
+ heading: 'Heading',
17
+ bulletList: 'Bulleted list',
18
+ orderedList: 'Numbered list',
19
+ quote: 'Quote',
20
+ },
21
+ preview: 'Preview',
22
+ empty: 'Nothing to preview.',
23
+ count: (length, max) => `${length} of ${max} characters`,
24
+ };
25
+ const icons = {
26
+ bold: _jsx(BoldIcon, {}),
27
+ italic: _jsx(ItalicIcon, {}),
28
+ strikethrough: _jsx(StrikethroughIcon, {}),
29
+ code: _jsx(CodeIcon, {}),
30
+ link: _jsx(LinkIcon, {}),
31
+ heading: _jsx(HeadingIcon, {}),
32
+ bulletList: _jsx(ListIcon, {}),
33
+ orderedList: _jsx(ListOrderedIcon, {}),
34
+ quote: _jsx(QuoteIcon, {}),
35
+ };
36
+ const shortcutHints = { bold: 'B', italic: 'I', link: 'K' };
37
+ export const defaultRichTextTools = [
38
+ 'bold',
39
+ 'italic',
40
+ 'strikethrough',
41
+ 'heading',
42
+ 'bulletList',
43
+ 'orderedList',
44
+ 'quote',
45
+ 'link',
46
+ 'code',
47
+ ];
48
+ /**
49
+ * A Markdown editor with a formatting toolbar and a preview. It stores plain
50
+ * Markdown, so the text is safe to save and shows the same on every platform
51
+ * with Rich Text Content.
52
+ */
53
+ export function RichTextEditor({ value: valueProp, defaultValue = '', onValueChange, placeholder, tools = defaultRichTextTools, minHeight = '$32', maxLength, disabled = false, invalid = false, id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-required': ariaRequired, accessibilityHint, labels: labelsProp, }) {
54
+ const labels = {
55
+ ...defaultLabels,
56
+ ...labelsProp,
57
+ tools: { ...defaultLabels.tools, ...labelsProp?.tools },
58
+ };
59
+ const [value, setValue] = useControllableState({
60
+ value: valueProp,
61
+ defaultValue,
62
+ onChange: onValueChange,
63
+ });
64
+ const [preview, setPreview] = useState(false);
65
+ const [activeTool, setActiveTool] = useState(0);
66
+ const field = useRef(null);
67
+ // Native reports the caret as it moves; web reads it from the textarea.
68
+ const selection = useRef({ start: value.length, end: value.length });
69
+ const pending = useRef(null);
70
+ const generatedId = useId();
71
+ const fieldId = id ?? `${generatedId}-field`;
72
+ const countId = `${generatedId}-count`;
73
+ // Put the selection where the tool left it, once the new text is in.
74
+ useLayoutEffect(() => {
75
+ const next = pending.current;
76
+ const node = field.current;
77
+ if (!next || !node)
78
+ return;
79
+ pending.current = null;
80
+ node.focus?.();
81
+ if (node.setSelectionRange)
82
+ node.setSelectionRange(next.start, next.end);
83
+ else
84
+ node.setSelection?.(next.start, next.end);
85
+ selection.current = next;
86
+ });
87
+ const apply = (tool) => {
88
+ const node = field.current;
89
+ const current = isWeb && node?.selectionStart != null
90
+ ? { start: node.selectionStart, end: node.selectionEnd ?? node.selectionStart }
91
+ : selection.current;
92
+ const result = applyFormat(value, current, tool);
93
+ if (maxLength != null && result.value.length > maxLength)
94
+ return;
95
+ pending.current = result.selection;
96
+ setValue(result.value);
97
+ };
98
+ const onFieldKeyDown = (event) => {
99
+ if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey)
100
+ return;
101
+ const tool = shortcuts[event.key.toLowerCase()];
102
+ if (tool && tools.includes(tool)) {
103
+ event.preventDefault();
104
+ apply(tool);
105
+ }
106
+ };
107
+ // One tab stop for the toolbar; the arrow keys move along it (WAI-ARIA toolbar).
108
+ const onToolbarKeyDown = (event) => {
109
+ const last = tools.length - 1;
110
+ const moves = {
111
+ ArrowRight: activeTool >= last ? 0 : activeTool + 1,
112
+ ArrowLeft: activeTool <= 0 ? last : activeTool - 1,
113
+ Home: 0,
114
+ End: last,
115
+ };
116
+ if (!(event.key in moves))
117
+ return;
118
+ event.preventDefault();
119
+ const next = moves[event.key];
120
+ setActiveTool(next);
121
+ document.getElementById(`${generatedId}-tool-${next}`)?.focus();
122
+ };
123
+ const toolsDisabled = disabled || preview;
124
+ return (_jsxs(View, { ...fieldBoxStyle, ...(invalid && { borderColor: '$error' }), opacity: disabled ? 0.5 : 1, overflow: "hidden", width: "100%", children: [_jsxs(XStack, { alignItems: "center", justifyContent: "space-between", gap: "$2", padding: "$1", borderBottomWidth: 1, borderColor: "$border", children: [_jsx(XStack, { flexWrap: "wrap", flex: 1, ...(isWeb && {
125
+ role: 'toolbar',
126
+ 'aria-label': labels.toolbar,
127
+ 'aria-controls': fieldId,
128
+ onKeyDown: onToolbarKeyDown,
129
+ }), children: tools.map((tool, i) => (_jsx(IconButton, { id: `${generatedId}-tool-${i}`, size: "sm", icon: icons[tool], "aria-label": labels.tools[tool], ...(isWeb && {
130
+ tabIndex: i === activeTool ? 0 : -1,
131
+ title: shortcutHints[tool]
132
+ ? `${labels.tools[tool]} (Ctrl+${shortcutHints[tool]})`
133
+ : labels.tools[tool],
134
+ // Keep the text selected while pressing a tool.
135
+ onMouseDown: (event) => event.preventDefault(),
136
+ onFocus: () => setActiveTool(i),
137
+ }), disabled: toolsDisabled, onPress: () => apply(tool) }, tool))) }), _jsx(Button, { size: "sm", variant: "ghost", "aria-pressed": preview, disabled: disabled, onPress: () => setPreview(!preview), ...(preview && { backgroundColor: '$accent' }), children: labels.preview })] }), preview ? (_jsx(View, { minHeight: minHeight, padding: "$3", ...(isWeb && { role: 'region', 'aria-label': labels.preview }), children: value.trim() ? (_jsx(RichTextContent, { children: value })) : (_jsx(Text, { size: "sm", tone: "muted", children: labels.empty })) })) : (_jsx(Textarea, { ref: field, id: fieldId, value: value, onChangeText: setValue, placeholder: placeholder, disabled: disabled, invalid: invalid, maxLength: maxLength, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-required": ariaRequired, ...(accessibilityHint && { accessibilityHint }), "aria-describedby": [ariaDescribedBy, maxLength != null ? countId : null].filter(Boolean).join(' ') ||
138
+ undefined, minHeight: minHeight,
139
+ // The frame draws the border; the text area sits flush inside it.
140
+ borderWidth: 0, borderRadius: 0, backgroundColor: "transparent", focusVisibleStyle: { outlineWidth: 0, outlineStyle: 'none' }, onSelectionChange: (event) => {
141
+ selection.current = event.nativeEvent.selection;
142
+ }, ...(isWeb && { onKeyDown: onFieldKeyDown }) })), maxLength != null ? (_jsx(Text, { id: countId, size: "xs", tone: "muted", textAlign: "right", paddingHorizontal: "$3", paddingBottom: "$2", children: labels.count(value.length, maxLength) })) : null] }));
143
+ }
144
+ //# sourceMappingURL=RichTextEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextEditor.js","sourceRoot":"","sources":["../../../src/components/rich-text-editor/RichTextEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,SAAS,EACT,iBAAiB,GAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAqB,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnF,OAAO,EAAsC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACjF,OAAO,EACL,MAAM,EACN,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAm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;oBAC/E,SAAS,EAEX,SAAS,EAAE,SAAS;gBACpB,kEAAkE;gBAClE,WAAW,EAAE,CAAC,EACd,YAAY,EAAE,CAAC,EACf,eAAe,EAAC,aAAa,EAC7B,iBAAiB,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,EAC5D,iBAAiB,EAAE,CAAC,KAAoD,EAAE,EAAE;oBAC1E,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,SAAS,CAAA;gBACjD,CAAC,KACG,CAAC,KAAK,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,GAC5C,CACH,EACA,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,CACnB,KAAC,IAAI,IACH,EAAE,EAAE,OAAO,EACX,IAAI,EAAC,IAAI,EACT,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,OAAO,EACjB,iBAAiB,EAAC,IAAI,EACtB,aAAa,EAAC,IAAI,YAEjB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,GACjC,CACR,CAAC,CAAC,CAAC,IAAI,IACH,CACR,CAAA;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { RichTextContent, type RichTextContentProps } from './RichTextContent';
2
+ export { RichTextEditor, defaultRichTextTools, type RichTextEditorLabels, type RichTextEditorProps, } from './RichTextEditor';
3
+ export { applyFormat, parseMarkdown, type FormatResult, type RichTextTool, type TextSelection, } from './markdown';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/rich-text-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,WAAW,EACX,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { RichTextContent } from './RichTextContent';
2
+ export { RichTextEditor, defaultRichTextTools, } from './RichTextEditor';
3
+ export { applyFormat, parseMarkdown, } from './markdown';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/rich-text-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA6B,MAAM,mBAAmB,CAAA;AAC9E,OAAO,EACL,cAAc,EACd,oBAAoB,GAGrB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,WAAW,EACX,aAAa,GAId,MAAM,YAAY,CAAA"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The Markdown subset Rich Text Editor writes and Rich Text Content reads:
3
+ * **bold**, _italic_, ~~strike~~, `code`, [links](https://…), `#` headings,
4
+ * `-` and `1.` lists, and `>` quotes.
5
+ */
6
+ export type RichTextTool = 'bold' | 'italic' | 'strikethrough' | 'code' | 'link' | 'heading' | 'bulletList' | 'orderedList' | 'quote';
7
+ export interface TextSelection {
8
+ start: number;
9
+ end: number;
10
+ }
11
+ export interface FormatResult {
12
+ value: string;
13
+ selection: TextSelection;
14
+ }
15
+ /**
16
+ * Applies a toolbar tool to the text around the selection. Pressing a tool
17
+ * again removes it. Returns the new text and what to select next.
18
+ */
19
+ export declare function applyFormat(value: string, selection: TextSelection, tool: RichTextTool, placeholder?: string): FormatResult;
20
+ /** Keyboard shortcuts (with ⌘ or Ctrl). */
21
+ export declare const shortcuts: Partial<Record<string, RichTextTool>>;
22
+ export type InlineNode = {
23
+ type: 'text';
24
+ text: string;
25
+ } | {
26
+ type: 'code';
27
+ text: string;
28
+ } | {
29
+ type: 'bold' | 'italic' | 'strike';
30
+ children: InlineNode[];
31
+ } | {
32
+ type: 'link';
33
+ href: string;
34
+ children: InlineNode[];
35
+ };
36
+ export type BlockNode = {
37
+ type: 'paragraph';
38
+ children: InlineNode[];
39
+ } | {
40
+ type: 'heading';
41
+ level: number;
42
+ children: InlineNode[];
43
+ } | {
44
+ type: 'quote';
45
+ children: BlockNode[];
46
+ } | {
47
+ type: 'list';
48
+ ordered: boolean;
49
+ start: number;
50
+ items: InlineNode[][];
51
+ };
52
+ /** Only web and mail links are followed; anything else (e.g. `javascript:`) stays text. */
53
+ export declare function safeHref(href: string): string | null;
54
+ export declare function parseInline(text: string): InlineNode[];
55
+ export declare function parseMarkdown(source: string): BlockNode[];
56
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/components/rich-text-editor/markdown.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,QAAQ,GACR,eAAe,GACf,MAAM,GACN,MAAM,GACN,SAAS,GACT,YAAY,GACZ,aAAa,GACb,OAAO,CAAA;AAEX,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,aAAa,CAAA;CACzB;AAmBD;;;GAGG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,YAAY,EAClB,WAAW,SAAyC,GACnD,YAAY,CA+Ed;AAED,2CAA2C;AAC3C,eAAO,MAAM,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAI3D,CAAA;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,MAAM,C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