@ankhorage/zora 28.3.0 → 28.4.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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/capabilities/index.js +52 -1
- package/dist/capabilities/index.js.map +6 -5
- package/dist/constants/authoring.d.ts +4 -3
- package/dist/constants/authoring.d.ts.map +1 -1
- package/dist/constants/authoring.js +2 -0
- package/dist/constants/authoring.js.map +1 -1
- package/dist/features/accordion/accordionItemMeta.d.ts +1 -1
- package/dist/features/bottom-sheet/bottomSheetMeta.d.ts +1 -1
- package/dist/features/card/cardMeta.d.ts +1 -1
- package/dist/features/card/mediaCardMeta.d.ts +1 -1
- package/dist/features/card/postCardMeta.d.ts +1 -1
- package/dist/features/chat/messageBubbleMeta.d.ts +1 -1
- package/dist/features/dialog/dialogMeta.d.ts +2 -2
- package/dist/features/gradient/gradientMeta.d.ts +1 -1
- package/dist/features/keyboard-avoiding-view/keyboardAvoidingViewMeta.d.ts +1 -1
- package/dist/features/layout/gridMeta.d.ts +1 -1
- package/dist/features/layout/screenMeta.d.ts +1 -1
- package/dist/features/layout/scrollViewMeta.d.ts +1 -1
- package/dist/features/layout/viewMeta.d.ts +1 -1
- package/dist/features/list/flatListMeta.d.ts +1 -1
- package/dist/features/list/sectionListMeta.d.ts +1 -1
- package/dist/features/master-detail/masterDetailMeta.d.ts +1 -1
- package/dist/features/reader/meta.d.ts +2 -2
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.d.ts.map +1 -1
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.js +2 -0
- package/dist/features/registry/ZORA_BASE_COMPONENT_REGISTRY.js.map +1 -1
- package/dist/features/registry/bindableComponentMeta.d.ts +2 -2
- package/dist/features/registry/componentMeta.d.ts.map +1 -1
- package/dist/features/registry/componentMeta.js +2 -0
- package/dist/features/registry/componentMeta.js.map +1 -1
- package/dist/features/rich-text/adapters/inbound/RichText.d.ts +11 -0
- package/dist/features/rich-text/adapters/inbound/RichText.d.ts.map +1 -0
- package/dist/features/rich-text/adapters/inbound/RichText.js +11 -0
- package/dist/features/rich-text/adapters/inbound/RichText.js.map +1 -0
- package/dist/features/rich-text/adapters/inbound/RichText.web.d.ts +5 -0
- package/dist/features/rich-text/adapters/inbound/RichText.web.d.ts.map +1 -0
- package/dist/features/rich-text/adapters/inbound/RichText.web.js +17 -0
- package/dist/features/rich-text/adapters/inbound/RichText.web.js.map +1 -0
- package/dist/features/rich-text/adapters/inbound/RichTextClient.d.ts +5 -0
- package/dist/features/rich-text/adapters/inbound/RichTextClient.d.ts.map +1 -0
- package/dist/features/rich-text/adapters/inbound/RichTextClient.js +94 -0
- package/dist/features/rich-text/adapters/inbound/RichTextClient.js.map +1 -0
- package/dist/features/rich-text/public.d.ts +3 -0
- package/dist/features/rich-text/public.d.ts.map +1 -0
- package/dist/features/rich-text/public.js +2 -0
- package/dist/features/rich-text/public.js.map +1 -0
- package/dist/features/rich-text/richTextMeta.d.ts +65 -0
- package/dist/features/rich-text/richTextMeta.d.ts.map +1 -0
- package/dist/features/rich-text/richTextMeta.js +48 -0
- package/dist/features/rich-text/richTextMeta.js.map +1 -0
- package/dist/features/rich-text/utils/resolveRichTextHtmlStyle.d.ts +5 -0
- package/dist/features/rich-text/utils/resolveRichTextHtmlStyle.d.ts.map +1 -0
- package/dist/features/rich-text/utils/resolveRichTextHtmlStyle.js +29 -0
- package/dist/features/rich-text/utils/resolveRichTextHtmlStyle.js.map +1 -0
- package/dist/features/rich-text/utils/sanitizeRichTextHtml.d.ts +3 -0
- package/dist/features/rich-text/utils/sanitizeRichTextHtml.d.ts.map +1 -0
- package/dist/features/rich-text/utils/sanitizeRichTextHtml.js +38 -0
- package/dist/features/rich-text/utils/sanitizeRichTextHtml.js.map +1 -0
- package/dist/features/scanner/meta.d.ts +2 -2
- package/dist/features/section/screenSectionMeta.d.ts +1 -1
- package/dist/features/surface/surfaceMeta.d.ts +1 -1
- package/dist/features/tabs/tabPanelMeta.d.ts +1 -1
- package/dist/readerFree.d.ts +1 -0
- package/dist/readerFree.d.ts.map +1 -1
- package/dist/readerFree.js +1 -0
- package/dist/readerFree.js.map +1 -1
- package/dist/types/rich-text.d.ts +24 -0
- package/dist/types/rich-text.d.ts.map +1 -0
- package/dist/types/rich-text.js +2 -0
- package/dist/types/rich-text.js.map +1 -0
- package/package.json +56 -2
- package/src/constants/authoring.ts +2 -0
- package/src/features/registry/ZORA_BASE_COMPONENT_REGISTRY.ts +2 -0
- package/src/features/registry/componentMeta.test.ts +1 -0
- package/src/features/registry/componentMeta.ts +2 -0
- package/src/features/rich-text/adapters/inbound/RichText.tsx +15 -0
- package/src/features/rich-text/adapters/inbound/RichText.web.tsx +28 -0
- package/src/features/rich-text/adapters/inbound/RichTextClient.tsx +246 -0
- package/src/features/rich-text/public.ts +2 -0
- package/src/features/rich-text/richTextMeta.test.ts +52 -0
- package/src/features/rich-text/richTextMeta.ts +50 -0
- package/src/features/rich-text/utils/resolveRichTextHtmlStyle.test.ts +17 -0
- package/src/features/rich-text/utils/resolveRichTextHtmlStyle.ts +31 -0
- package/src/features/rich-text/utils/sanitizeRichTextHtml.test.ts +29 -0
- package/src/features/rich-text/utils/sanitizeRichTextHtml.ts +40 -0
- package/src/readerFree.ts +1 -0
- package/src/types/rich-text.ts +24 -0
- package/src/webPackageExports.test.ts +9 -0
- package/web-dist/chunks/Accordion-v86n9tvj.js +37 -0
- package/web-dist/chunks/RichTextClient-8x3t7bwd.js +1676 -0
- package/web-dist/components/reader/Reader.js +1 -1
- package/web-dist/components/rich-text/RichText.d.ts +13 -0
- package/web-dist/components/rich-text/RichText.dependency-0.d.ts +27 -0
- package/web-dist/components/rich-text/RichText.dependency-1.d.ts +3 -0
- package/web-dist/components/rich-text/RichText.js +35 -0
- package/web-dist/components/rich-text/RichText.types-0.d.ts +24 -0
- package/web-dist/components/rich-text/index.d.ts +2 -0
- package/web-dist/components/rich-text/index.js +2 -0
- package/web-dist/components/toolbar/Toolbar.js +7 -36
- package/web-dist/manifest.json +49 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
EnrichedText,
|
|
4
|
+
EnrichedTextInput,
|
|
5
|
+
type EnrichedTextInputInstance,
|
|
6
|
+
} from 'react-native-enriched-html';
|
|
7
|
+
|
|
8
|
+
import type { RichTextProps } from '../../../../types/rich-text';
|
|
9
|
+
import { IconButton } from '../../../button/public';
|
|
10
|
+
import { TextInput } from '../../../form/text-input/public';
|
|
11
|
+
import { View } from '../../../layout/public';
|
|
12
|
+
import { useZoraTheme } from '../../../theme/composition/useZoraTheme';
|
|
13
|
+
import { Toolbar } from '../../../toolbar/public';
|
|
14
|
+
import { resolveRichTextHtmlStyle } from '../../utils/resolveRichTextHtmlStyle';
|
|
15
|
+
import { sanitizeRichTextHtml } from '../../utils/sanitizeRichTextHtml';
|
|
16
|
+
|
|
17
|
+
interface RichTextSelection {
|
|
18
|
+
readonly start: number;
|
|
19
|
+
readonly end: number;
|
|
20
|
+
readonly text: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*** Applies ZORA theme tokens and controlled HTML updates to the upstream editor. */
|
|
24
|
+
export function RichTextClient({
|
|
25
|
+
html,
|
|
26
|
+
editable = false,
|
|
27
|
+
placeholder,
|
|
28
|
+
onChangeHtml,
|
|
29
|
+
onLinkPress,
|
|
30
|
+
interactionPolicy,
|
|
31
|
+
testID,
|
|
32
|
+
}: RichTextProps) {
|
|
33
|
+
const { theme } = useZoraTheme();
|
|
34
|
+
const editorRef = React.useRef<EnrichedTextInputInstance>(null);
|
|
35
|
+
const sanitizedHtml = React.useMemo(() => sanitizeRichTextHtml(html), [html]);
|
|
36
|
+
const currentHtml = React.useRef(sanitizedHtml);
|
|
37
|
+
const [selection, setSelection] = React.useState<RichTextSelection>({
|
|
38
|
+
start: 0,
|
|
39
|
+
end: 0,
|
|
40
|
+
text: '',
|
|
41
|
+
});
|
|
42
|
+
const [linkEditorVisible, setLinkEditorVisible] = React.useState(false);
|
|
43
|
+
const [linkUrl, setLinkUrl] = React.useState('');
|
|
44
|
+
const htmlStyle = React.useMemo(() => resolveRichTextHtmlStyle(theme), [theme]);
|
|
45
|
+
const contentStyle = React.useMemo(
|
|
46
|
+
() => ({
|
|
47
|
+
backgroundColor: theme.semantics.surface.default,
|
|
48
|
+
borderColor: theme.semantics.border.default,
|
|
49
|
+
borderRadius: theme.radii.l,
|
|
50
|
+
borderWidth: 1,
|
|
51
|
+
color: theme.semantics.content.default,
|
|
52
|
+
fontFamily: theme.typography.fonts.normal[theme.typography.weights.regular],
|
|
53
|
+
fontSize: theme.typography.sizes.m,
|
|
54
|
+
lineHeight: 24,
|
|
55
|
+
padding: theme.spacing.m,
|
|
56
|
+
}),
|
|
57
|
+
[theme],
|
|
58
|
+
);
|
|
59
|
+
const passive = interactionPolicy === 'passive';
|
|
60
|
+
const canEdit = editable && !passive;
|
|
61
|
+
const handleLinkPress = React.useCallback(
|
|
62
|
+
({ url }: { readonly url: string }) => {
|
|
63
|
+
if (!passive) onLinkPress?.(url);
|
|
64
|
+
},
|
|
65
|
+
[onLinkPress, passive],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
if (sanitizedHtml === currentHtml.current) return;
|
|
70
|
+
editorRef.current?.setValue(sanitizedHtml);
|
|
71
|
+
currentHtml.current = sanitizedHtml;
|
|
72
|
+
}, [sanitizedHtml]);
|
|
73
|
+
|
|
74
|
+
if (!editable) {
|
|
75
|
+
return (
|
|
76
|
+
<EnrichedText
|
|
77
|
+
htmlStyle={htmlStyle}
|
|
78
|
+
onLinkPress={onLinkPress === undefined || passive ? undefined : handleLinkPress}
|
|
79
|
+
selectable={!passive}
|
|
80
|
+
style={contentStyle}
|
|
81
|
+
testID={testID}
|
|
82
|
+
>
|
|
83
|
+
{sanitizedHtml}
|
|
84
|
+
</EnrichedText>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<View gap="s">
|
|
90
|
+
<RichTextToolbar
|
|
91
|
+
disabled={!canEdit}
|
|
92
|
+
editorRef={editorRef}
|
|
93
|
+
linkEditorVisible={linkEditorVisible}
|
|
94
|
+
onLinkEditorVisibilityChange={setLinkEditorVisible}
|
|
95
|
+
/>
|
|
96
|
+
{linkEditorVisible ? (
|
|
97
|
+
<View align="center" direction="row" gap="s">
|
|
98
|
+
<TextInput
|
|
99
|
+
disabled={!canEdit}
|
|
100
|
+
onChangeText={setLinkUrl}
|
|
101
|
+
placeholder="https://example.com"
|
|
102
|
+
size="m"
|
|
103
|
+
value={linkUrl}
|
|
104
|
+
/>
|
|
105
|
+
<IconButton
|
|
106
|
+
color="primary"
|
|
107
|
+
disabled={!canEdit || linkUrl.length === 0}
|
|
108
|
+
icon={{ name: 'check', provider: 'FontAwesome6', variant: 'solid' }}
|
|
109
|
+
label="Apply link"
|
|
110
|
+
onPress={() => {
|
|
111
|
+
if (selection.text.length === 0) return;
|
|
112
|
+
editorRef.current?.setLink(selection.start, selection.end, selection.text, linkUrl);
|
|
113
|
+
setLinkEditorVisible(false);
|
|
114
|
+
setLinkUrl('');
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
</View>
|
|
118
|
+
) : null}
|
|
119
|
+
<EnrichedTextInput
|
|
120
|
+
cursorColor={theme.semantics.border.focus}
|
|
121
|
+
defaultValue={sanitizedHtml}
|
|
122
|
+
editable={canEdit}
|
|
123
|
+
htmlStyle={htmlStyle}
|
|
124
|
+
onChangeHtml={(event) => {
|
|
125
|
+
const nextHtml = sanitizeRichTextHtml(event.nativeEvent.value);
|
|
126
|
+
currentHtml.current = nextHtml;
|
|
127
|
+
onChangeHtml?.(nextHtml);
|
|
128
|
+
}}
|
|
129
|
+
onChangeSelection={(event) => setSelection(event.nativeEvent)}
|
|
130
|
+
onLinkPress={onLinkPress === undefined || passive ? undefined : handleLinkPress}
|
|
131
|
+
placeholder={placeholder}
|
|
132
|
+
placeholderTextColor={theme.semantics.content.muted}
|
|
133
|
+
ref={editorRef}
|
|
134
|
+
selectionColor={theme.semantics.action.primary.softBg}
|
|
135
|
+
style={contentStyle}
|
|
136
|
+
testID={testID}
|
|
137
|
+
/>
|
|
138
|
+
</View>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/*** Renders the supported rich-text formatting actions with ZORA toolbar controls. */
|
|
143
|
+
function RichTextToolbar({
|
|
144
|
+
disabled,
|
|
145
|
+
editorRef,
|
|
146
|
+
linkEditorVisible,
|
|
147
|
+
onLinkEditorVisibilityChange,
|
|
148
|
+
}: {
|
|
149
|
+
readonly disabled: boolean;
|
|
150
|
+
readonly editorRef: React.RefObject<EnrichedTextInputInstance | null>;
|
|
151
|
+
readonly linkEditorVisible: boolean;
|
|
152
|
+
readonly onLinkEditorVisibilityChange: (visible: boolean) => void;
|
|
153
|
+
}) {
|
|
154
|
+
return (
|
|
155
|
+
<View gap="s">
|
|
156
|
+
<Toolbar compact>
|
|
157
|
+
<IconButton
|
|
158
|
+
disabled={disabled}
|
|
159
|
+
icon={{ name: 'heading', provider: 'FontAwesome6', variant: 'solid' }}
|
|
160
|
+
label="Heading level 1"
|
|
161
|
+
onPress={() => editorRef.current?.toggleH1()}
|
|
162
|
+
/>
|
|
163
|
+
<IconButton
|
|
164
|
+
disabled={disabled}
|
|
165
|
+
icon={{ name: 'heading', provider: 'FontAwesome6', variant: 'solid' }}
|
|
166
|
+
label="Heading level 2"
|
|
167
|
+
onPress={() => editorRef.current?.toggleH2()}
|
|
168
|
+
/>
|
|
169
|
+
<IconButton
|
|
170
|
+
disabled={disabled}
|
|
171
|
+
icon={{ name: 'heading', provider: 'FontAwesome6', variant: 'solid' }}
|
|
172
|
+
label="Heading level 3"
|
|
173
|
+
onPress={() => editorRef.current?.toggleH3()}
|
|
174
|
+
/>
|
|
175
|
+
<IconButton
|
|
176
|
+
disabled={disabled}
|
|
177
|
+
icon={{ name: 'bold', provider: 'FontAwesome6', variant: 'solid' }}
|
|
178
|
+
label="Bold"
|
|
179
|
+
onPress={() => editorRef.current?.toggleBold()}
|
|
180
|
+
/>
|
|
181
|
+
<IconButton
|
|
182
|
+
disabled={disabled}
|
|
183
|
+
icon={{ name: 'italic', provider: 'FontAwesome6', variant: 'solid' }}
|
|
184
|
+
label="Italic"
|
|
185
|
+
onPress={() => editorRef.current?.toggleItalic()}
|
|
186
|
+
/>
|
|
187
|
+
<IconButton
|
|
188
|
+
disabled={disabled}
|
|
189
|
+
icon={{ name: 'underline', provider: 'FontAwesome6', variant: 'solid' }}
|
|
190
|
+
label="Underline"
|
|
191
|
+
onPress={() => editorRef.current?.toggleUnderline()}
|
|
192
|
+
/>
|
|
193
|
+
<IconButton
|
|
194
|
+
disabled={disabled}
|
|
195
|
+
icon={{ name: 'strikethrough', provider: 'FontAwesome6', variant: 'solid' }}
|
|
196
|
+
label="Strikethrough"
|
|
197
|
+
onPress={() => editorRef.current?.toggleStrikeThrough()}
|
|
198
|
+
/>
|
|
199
|
+
<IconButton
|
|
200
|
+
disabled={disabled}
|
|
201
|
+
icon={{ name: 'link', provider: 'FontAwesome6', variant: 'solid' }}
|
|
202
|
+
label="Link"
|
|
203
|
+
onPress={() => onLinkEditorVisibilityChange(!linkEditorVisible)}
|
|
204
|
+
/>
|
|
205
|
+
</Toolbar>
|
|
206
|
+
<Toolbar compact>
|
|
207
|
+
<IconButton
|
|
208
|
+
disabled={disabled}
|
|
209
|
+
icon={{ name: 'list-ol', provider: 'FontAwesome6', variant: 'solid' }}
|
|
210
|
+
label="Ordered list"
|
|
211
|
+
onPress={() => editorRef.current?.toggleOrderedList()}
|
|
212
|
+
/>
|
|
213
|
+
<IconButton
|
|
214
|
+
disabled={disabled}
|
|
215
|
+
icon={{ name: 'list-ul', provider: 'FontAwesome6', variant: 'solid' }}
|
|
216
|
+
label="Unordered list"
|
|
217
|
+
onPress={() => editorRef.current?.toggleUnorderedList()}
|
|
218
|
+
/>
|
|
219
|
+
<IconButton
|
|
220
|
+
disabled={disabled}
|
|
221
|
+
icon={{ name: 'align-left', provider: 'FontAwesome6', variant: 'solid' }}
|
|
222
|
+
label="Align left"
|
|
223
|
+
onPress={() => editorRef.current?.setTextAlignment('left')}
|
|
224
|
+
/>
|
|
225
|
+
<IconButton
|
|
226
|
+
disabled={disabled}
|
|
227
|
+
icon={{ name: 'align-center', provider: 'FontAwesome6', variant: 'solid' }}
|
|
228
|
+
label="Align center"
|
|
229
|
+
onPress={() => editorRef.current?.setTextAlignment('center')}
|
|
230
|
+
/>
|
|
231
|
+
<IconButton
|
|
232
|
+
disabled={disabled}
|
|
233
|
+
icon={{ name: 'align-right', provider: 'FontAwesome6', variant: 'solid' }}
|
|
234
|
+
label="Align right"
|
|
235
|
+
onPress={() => editorRef.current?.setTextAlignment('right')}
|
|
236
|
+
/>
|
|
237
|
+
<IconButton
|
|
238
|
+
disabled={disabled}
|
|
239
|
+
icon={{ name: 'align-justify', provider: 'FontAwesome6', variant: 'solid' }}
|
|
240
|
+
label="Justify"
|
|
241
|
+
onPress={() => editorRef.current?.setTextAlignment('justify')}
|
|
242
|
+
/>
|
|
243
|
+
</Toolbar>
|
|
244
|
+
</View>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { richTextMeta } from './richTextMeta';
|
|
4
|
+
|
|
5
|
+
describe('RichText authoring metadata', () => {
|
|
6
|
+
test('uses upstream history and suppresses editor and link interactions while passive', async () => {
|
|
7
|
+
const [clientSource, nativeSource, webSource] = await Promise.all([
|
|
8
|
+
Bun.file('src/features/rich-text/adapters/inbound/RichTextClient.tsx').text(),
|
|
9
|
+
Bun.file('src/features/rich-text/adapters/inbound/RichText.tsx').text(),
|
|
10
|
+
Bun.file('src/features/rich-text/adapters/inbound/RichText.web.tsx').text(),
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
expect(nativeSource).toContain('upstream TipTap history keyboard shortcuts');
|
|
14
|
+
expect(nativeSource).toContain('platform text-control history');
|
|
15
|
+
expect(nativeSource).toContain('programmatic undo or redo controls');
|
|
16
|
+
expect(webSource).toContain("await import('./RichTextClient')");
|
|
17
|
+
expect(clientSource).toContain("from '../../utils/sanitizeRichTextHtml'");
|
|
18
|
+
expect(clientSource).toContain(
|
|
19
|
+
'const sanitizedHtml = React.useMemo(() => sanitizeRichTextHtml(html), [html]);',
|
|
20
|
+
);
|
|
21
|
+
expect(clientSource).toContain(
|
|
22
|
+
'const nextHtml = sanitizeRichTextHtml(event.nativeEvent.value);',
|
|
23
|
+
);
|
|
24
|
+
expect(clientSource).toContain("const passive = interactionPolicy === 'passive';");
|
|
25
|
+
expect(clientSource).toContain('editable={canEdit}');
|
|
26
|
+
expect(clientSource).toContain('selectable={!passive}');
|
|
27
|
+
expect(clientSource).toContain(
|
|
28
|
+
'onLinkPress={onLinkPress === undefined || passive ? undefined : handleLinkPress}',
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('describes the serializable HTML component contract and host-owned events', () => {
|
|
33
|
+
expect(richTextMeta.directManifestNode).toBe(true);
|
|
34
|
+
expect(richTextMeta.allowedChildren).toEqual([]);
|
|
35
|
+
expect(richTextMeta.blueprint.defaultProps).toEqual({
|
|
36
|
+
html: '<p>Rich text</p>',
|
|
37
|
+
editable: false,
|
|
38
|
+
});
|
|
39
|
+
expect(richTextMeta.props.html).toMatchObject({
|
|
40
|
+
type: 'string',
|
|
41
|
+
authoring: { authority: 'instance' },
|
|
42
|
+
});
|
|
43
|
+
expect(richTextMeta.events.changeHtml).toMatchObject({
|
|
44
|
+
eventType: 'richText.changeHtml',
|
|
45
|
+
payloadFields: [{ path: 'html', type: 'string', label: 'HTML' }],
|
|
46
|
+
});
|
|
47
|
+
expect(richTextMeta.events.linkPress).toMatchObject({
|
|
48
|
+
eventType: 'richText.linkPress',
|
|
49
|
+
payloadFields: [{ path: 'url', type: 'string', label: 'URL' }],
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ZoraComponentMeta } from '../../types/authoring';
|
|
2
|
+
|
|
3
|
+
export const richTextMeta = {
|
|
4
|
+
name: 'RichText',
|
|
5
|
+
category: 'component',
|
|
6
|
+
directManifestNode: true,
|
|
7
|
+
allowedChildren: [],
|
|
8
|
+
description:
|
|
9
|
+
'Portable normalized HTML rendered read-only or edited with the supported cross-platform WYSIWYG editor.',
|
|
10
|
+
blueprint: {
|
|
11
|
+
label: 'Rich text',
|
|
12
|
+
defaultProps: { html: '<p>Rich text</p>', editable: false },
|
|
13
|
+
},
|
|
14
|
+
events: {
|
|
15
|
+
changeHtml: {
|
|
16
|
+
label: 'HTML change',
|
|
17
|
+
eventType: 'richText.changeHtml',
|
|
18
|
+
description: 'Emitted when the editor produces normalized HTML.',
|
|
19
|
+
payloadFields: [{ path: 'html', type: 'string', label: 'HTML' }],
|
|
20
|
+
},
|
|
21
|
+
linkPress: {
|
|
22
|
+
label: 'Link press',
|
|
23
|
+
eventType: 'richText.linkPress',
|
|
24
|
+
description: 'Requests host-owned navigation for a rich-text link.',
|
|
25
|
+
payloadFields: [{ path: 'url', type: 'string', label: 'URL' }],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
props: {
|
|
29
|
+
html: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
category: 'Content',
|
|
32
|
+
label: 'HTML',
|
|
33
|
+
default: '<p>Rich text</p>',
|
|
34
|
+
authoring: { authority: 'instance' },
|
|
35
|
+
},
|
|
36
|
+
editable: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
category: 'State',
|
|
39
|
+
label: 'Editable',
|
|
40
|
+
default: false,
|
|
41
|
+
authoring: { authority: 'instance' },
|
|
42
|
+
},
|
|
43
|
+
placeholder: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
category: 'Content',
|
|
46
|
+
label: 'Placeholder',
|
|
47
|
+
authoring: { authority: 'instance' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
} as const satisfies ZoraComponentMeta;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createTheme } from '@ankhorage/surface/theme';
|
|
2
|
+
import { expect, test } from 'bun:test';
|
|
3
|
+
|
|
4
|
+
import { resolveRichTextHtmlStyle } from './resolveRichTextHtmlStyle';
|
|
5
|
+
|
|
6
|
+
test('resolves headings, links, and lists from the active ZORA theme', () => {
|
|
7
|
+
const theme = createTheme();
|
|
8
|
+
const style = resolveRichTextHtmlStyle(theme);
|
|
9
|
+
|
|
10
|
+
expect(style.h1).toEqual({ fontSize: theme.typography.headings[1].size, bold: true });
|
|
11
|
+
expect(style.a).toMatchObject({
|
|
12
|
+
color: theme.semantics.action.primary.base,
|
|
13
|
+
pressColor: theme.semantics.action.primary.hover,
|
|
14
|
+
});
|
|
15
|
+
expect(style.ol?.markerColor).toBe(theme.semantics.content.default);
|
|
16
|
+
expect(style.ul?.bulletColor).toBe(theme.semantics.content.default);
|
|
17
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SurfaceTheme } from '@ankhorage/surface';
|
|
2
|
+
import type { EnrichedTextHtmlStyle, HtmlStyle } from 'react-native-enriched-html';
|
|
3
|
+
|
|
4
|
+
/** Resolves the upstream HTML renderer tokens from the active ZORA theme. */
|
|
5
|
+
export function resolveRichTextHtmlStyle(theme: SurfaceTheme): HtmlStyle & EnrichedTextHtmlStyle {
|
|
6
|
+
return {
|
|
7
|
+
h1: { fontSize: theme.typography.headings[1].size, bold: true },
|
|
8
|
+
h2: { fontSize: theme.typography.headings[2].size, bold: true },
|
|
9
|
+
h3: { fontSize: theme.typography.headings[3].size, bold: true },
|
|
10
|
+
h4: { fontSize: theme.typography.headings[4].size, bold: true },
|
|
11
|
+
h5: { fontSize: theme.typography.headings[5].size, bold: true },
|
|
12
|
+
h6: { fontSize: theme.typography.headings[6].size, bold: true },
|
|
13
|
+
a: {
|
|
14
|
+
color: theme.semantics.action.primary.base,
|
|
15
|
+
pressColor: theme.semantics.action.primary.hover,
|
|
16
|
+
textDecorationLine: 'underline',
|
|
17
|
+
},
|
|
18
|
+
ol: {
|
|
19
|
+
gapWidth: theme.spacing.s,
|
|
20
|
+
marginLeft: theme.spacing.l,
|
|
21
|
+
markerColor: theme.semantics.content.default,
|
|
22
|
+
markerFontWeight: theme.typography.weights.regular,
|
|
23
|
+
},
|
|
24
|
+
ul: {
|
|
25
|
+
bulletColor: theme.semantics.content.default,
|
|
26
|
+
bulletSize: theme.spacing.xs,
|
|
27
|
+
gapWidth: theme.spacing.s,
|
|
28
|
+
marginLeft: theme.spacing.l,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { sanitizeRichTextHtml } from './sanitizeRichTextHtml';
|
|
4
|
+
|
|
5
|
+
describe('sanitizeRichTextHtml', () => {
|
|
6
|
+
test('preserves the supported RichText formatting vocabulary', () => {
|
|
7
|
+
expect(
|
|
8
|
+
sanitizeRichTextHtml(
|
|
9
|
+
'<h1 style="text-align: center">Heading</h1><p><b>Bold</b><i>Italic</i><u>Underline</u><s>Strike</s><a href="https://example.com">Link</a></p><ol style="text-align: right"><li>One</li></ol><ul><li>Two</li></ul>',
|
|
10
|
+
),
|
|
11
|
+
).toBe(
|
|
12
|
+
'<h1 style="text-align:center;">Heading</h1><p><b>Bold</b><i>Italic</i><u>Underline</u><s>Strike</s><a href="https://example.com">Link</a></p><ol style="text-align:right;"><li>One</li></ol><ul><li>Two</li></ul>',
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(sanitizeRichTextHtml('<html><h1>Title</h1><br><p>Some body text.</p></html>')).toBe(
|
|
16
|
+
'<html><h1>Title</h1><br><p>Some body text.</p></html>',
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('removes executable content and unsupported formatting', () => {
|
|
21
|
+
expect(
|
|
22
|
+
sanitizeRichTextHtml(
|
|
23
|
+
'<script>alert(1)</script><p style="color: red; text-align: justify" onclick="alert(1)"><a href="javascript:alert(1)">Unsafe</a></p><img src="https://example.com/image.png">',
|
|
24
|
+
),
|
|
25
|
+
).toBe(
|
|
26
|
+
'<p style="text-align:justify;"><a href>Unsafe</a></p><img src="https://example.com/image.png">',
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FilterXSS } from 'xss';
|
|
2
|
+
|
|
3
|
+
/** Sanitizes RichText HTML to the formatting vocabulary supported by every platform. */
|
|
4
|
+
export function sanitizeRichTextHtml(html: string): string {
|
|
5
|
+
return richTextHtmlSanitizer.process(html);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const alignmentAttributes = ['style'];
|
|
9
|
+
|
|
10
|
+
const richTextHtmlSanitizer = new FilterXSS({
|
|
11
|
+
whiteList: {
|
|
12
|
+
a: ['href'],
|
|
13
|
+
b: [],
|
|
14
|
+
br: [],
|
|
15
|
+
del: [],
|
|
16
|
+
em: [],
|
|
17
|
+
h1: alignmentAttributes,
|
|
18
|
+
h2: alignmentAttributes,
|
|
19
|
+
h3: alignmentAttributes,
|
|
20
|
+
h4: alignmentAttributes,
|
|
21
|
+
h5: alignmentAttributes,
|
|
22
|
+
h6: alignmentAttributes,
|
|
23
|
+
html: [],
|
|
24
|
+
i: [],
|
|
25
|
+
li: [],
|
|
26
|
+
ol: alignmentAttributes,
|
|
27
|
+
p: alignmentAttributes,
|
|
28
|
+
s: [],
|
|
29
|
+
strike: [],
|
|
30
|
+
strong: [],
|
|
31
|
+
u: [],
|
|
32
|
+
ul: alignmentAttributes,
|
|
33
|
+
},
|
|
34
|
+
css: {
|
|
35
|
+
whiteList: {
|
|
36
|
+
'text-align': /^(left|center|right|justify)$/,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
stripIgnoreTagBody: ['script', 'style'],
|
|
40
|
+
});
|
package/src/readerFree.ts
CHANGED
|
@@ -417,6 +417,7 @@ export {
|
|
|
417
417
|
createZoraComponentRegistry,
|
|
418
418
|
ZORA_BASE_COMPONENT_REGISTRY,
|
|
419
419
|
} from './features/registry/readerFreeRegistry';
|
|
420
|
+
export { RichText, type RichTextProps } from './features/rich-text/public';
|
|
420
421
|
export type {
|
|
421
422
|
BarcodeScannerViewProps,
|
|
422
423
|
BarcodeScanResult,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ZoraBaseProps } from './base';
|
|
2
|
+
|
|
3
|
+
/** Props for ZORA's canonical portable rich-text display and editor component. */
|
|
4
|
+
export interface RichTextProps extends ZoraBaseProps {
|
|
5
|
+
/** Canonical normalized HTML produced by RichText's supported editor. */
|
|
6
|
+
html: string;
|
|
7
|
+
/**
|
|
8
|
+
* Enables the WYSIWYG editor and its ZORA toolbar. Undo and redo use the
|
|
9
|
+
* upstream platform history: TipTap keyboard shortcuts on web and the
|
|
10
|
+
* native platform text-control history on iOS and Android. No programmatic
|
|
11
|
+
* history API is available.
|
|
12
|
+
*/
|
|
13
|
+
editable?: boolean;
|
|
14
|
+
/** Placeholder shown by the editor when its content is empty. */
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
/** Receives the normalized HTML emitted by the supported editor. */
|
|
17
|
+
onChangeHtml?: (html: string) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Requests host-owned navigation for a rendered rich-text link. In editable
|
|
20
|
+
* mode, the upstream callback is available on web only; read-only links are
|
|
21
|
+
* supported on web, iOS, and Android.
|
|
22
|
+
*/
|
|
23
|
+
onLinkPress?: (url: string) => void;
|
|
24
|
+
}
|
|
@@ -317,6 +317,15 @@ test('SSR-renders ordinary UI from its public web subpaths', async () => {
|
|
|
317
317
|
expect(markup).toContain('Continue');
|
|
318
318
|
});
|
|
319
319
|
|
|
320
|
+
/** Verifies that RichText keeps the upstream browser-only implementation outside SSR. */
|
|
321
|
+
test('defers RichText until browser hydration', async () => {
|
|
322
|
+
const { RichText } = await import('@ankhorage/zora/web/rich-text');
|
|
323
|
+
|
|
324
|
+
expect(
|
|
325
|
+
renderToStaticMarkup(React.createElement(RichText, { html: '<p>Server content</p>' })),
|
|
326
|
+
).toBe('');
|
|
327
|
+
});
|
|
328
|
+
|
|
320
329
|
/** Verifies that the color controls are available through their generated public web entrypoints. */
|
|
321
330
|
test('publishes the independent color controls through canonical web subpaths', async () => {
|
|
322
331
|
const [{ ColorPicker }, { ColorWheel }, { ColorTone }, { ColorHueScale }] = await Promise.all([
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
Card2
|
|
4
|
+
} from "./Accordion-2xkxthf1.js";
|
|
5
|
+
import {
|
|
6
|
+
withZoraThemeScope
|
|
7
|
+
} from "./Accordion-tk8zf9ff.js";
|
|
8
|
+
import {
|
|
9
|
+
View2
|
|
10
|
+
} from "./Accordion-f8a49gy8.js";
|
|
11
|
+
|
|
12
|
+
// src/features/toolbar/adapters/inbound/Toolbar.tsx
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
var Toolbar2 = withZoraThemeScope(ToolbarInner);
|
|
15
|
+
function ToolbarInner({
|
|
16
|
+
themeId: _themeId,
|
|
17
|
+
mode: _mode,
|
|
18
|
+
interactionPolicy,
|
|
19
|
+
children,
|
|
20
|
+
floating = false,
|
|
21
|
+
compact = true,
|
|
22
|
+
testID
|
|
23
|
+
}) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Card2, {
|
|
25
|
+
compact,
|
|
26
|
+
interactionPolicy,
|
|
27
|
+
tone: floating ? "default" : "subtle",
|
|
28
|
+
testID,
|
|
29
|
+
children: /* @__PURE__ */ jsx(View2, {
|
|
30
|
+
align: "center",
|
|
31
|
+
direction: "row",
|
|
32
|
+
gap: "s",
|
|
33
|
+
children
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { Toolbar2 };
|