@apollohg/react-native-rich-text-editor 2.0.0 → 2.0.1
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 +1 -1
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/android/build.gradle +3 -0
- package/app.plugin.js +42 -39
- package/dist/AtomHost.js +18 -11
- package/dist/EditorAddon.js +4 -2
- package/dist/EditorAddonNormalization.js +17 -9
- package/dist/EditorMentionThemeNormalization.js +6 -3
- package/dist/EditorMentionThemeValidation.js +28 -11
- package/dist/EditorStyleSheetNormalization.js +84 -37
- package/dist/EditorTheme.d.ts +4 -0
- package/dist/EditorTheme.js +5 -3
- package/dist/EditorToolbarComponent.d.ts +1 -1
- package/dist/EditorToolbarComponent.js +1 -1
- package/dist/EditorToolbarRegistry.js +5 -5
- package/dist/EditorToolbarTypes.d.ts +12 -12
- package/dist/EditorToolbarVisuals.js +1 -1
- package/dist/ExternalTextComposition.js +89 -43
- package/dist/ImageLoadingPolicy.d.ts +1 -1
- package/dist/NativeEditorBoundaryError.d.ts +7 -7
- package/dist/NativeEditorBoundaryError.js +9 -5
- package/dist/NativeEditorCollaborationTransport.d.ts +7 -7
- package/dist/NativeEditorCollaborationTransport.js +28 -15
- package/dist/NativeEditorCreateConfig.js +11 -6
- package/dist/NativeEditorCreateJson.js +51 -25
- package/dist/NativeEditorCreateValidation.js +11 -6
- package/dist/NativeEditorDocumentBridge.d.ts +1 -1
- package/dist/NativeEditorDocumentBridge.js +32 -18
- package/dist/NativeEditorDocumentHandle.d.ts +4 -4
- package/dist/NativeEditorDocumentHandle.js +1 -1
- package/dist/NativeEditorLocalAwareness.js +25 -13
- package/dist/NativeEditorNativeModule.d.ts +8 -1
- package/dist/NativeEditorNativeModule.js +7 -5
- package/dist/NativeEditorRenderNormalization.js +66 -25
- package/dist/NativeEditorResultNormalization.js +53 -29
- package/dist/NativeEditorTypes.d.ts +10 -10
- package/dist/NativeEditorV2Decimal.js +6 -3
- package/dist/NativeProseViewer.js +11 -3
- package/dist/ResourceLimits.d.ts +2 -2
- package/dist/ResourceLimits.js +7 -2
- package/dist/RichTextEditor.js +1 -1
- package/dist/RichTextEditorNativeTypes.d.ts +1 -1
- package/dist/RichTextEditorNativeView.d.ts +1 -3
- package/dist/RichTextEditorSerialization.js +24 -14
- package/dist/RichTextEditorTypes.d.ts +1 -1
- package/dist/YjsCollaboration.d.ts +7 -7
- package/dist/YjsCollaboration.js +42 -26
- package/dist/addons.d.ts +4 -4
- package/dist/addons.js +3 -3
- package/dist/atomInstances.js +6 -3
- package/dist/atomUpdates.js +7 -4
- package/dist/atoms.js +20 -12
- package/dist/attributeValidation.js +55 -24
- package/dist/contentExpression.js +80 -42
- package/dist/listMarkers.d.ts +1 -1
- package/dist/listMarkers.js +1 -1
- package/dist/schemaDefinition.d.ts +1 -1
- package/dist/schemaDefinition.js +23 -14
- package/dist/schemaDocument.js +1 -1
- package/dist/schemaDocumentConstruction.js +25 -14
- package/dist/schemaNormalization.js +51 -29
- package/dist/schemaPresets.d.ts +1 -1
- package/dist/schemaPresets.js +9 -4
- package/dist/schemaResolution.js +46 -25
- package/dist/specs/PreparedProseViewerNativeComponent.d.ts +4 -0
- package/dist/useEditorToolbarInteractions.d.ts +2 -2
- package/dist/useEditorToolbarInteractions.js +45 -23
- package/dist/useEditorToolbarItems.d.ts +1 -1
- package/dist/useEditorToolbarItems.js +4 -3
- package/dist/useEditorToolbarPresentation.d.ts +3 -3
- package/dist/useEditorToolbarPresentation.js +4 -4
- package/dist/useEditorToolbarState.d.ts +1 -1
- package/dist/useEditorToolbarState.js +1 -1
- package/dist/useFocusPreservingFrames.js +11 -8
- package/dist/useNativeEditor.d.ts +1 -1
- package/dist/useNativeEditor.js +21 -11
- package/dist/useRichTextEditorCommands.d.ts +2 -2
- package/dist/useRichTextEditorCommands.js +59 -29
- package/dist/useRichTextEditorEvents.d.ts +3 -3
- package/dist/useRichTextEditorEvents.js +75 -32
- package/dist/useRichTextEditorMentions.d.ts +4 -4
- package/dist/useRichTextEditorMentions.js +48 -29
- package/dist/useRichTextEditorPresentation.d.ts +4 -4
- package/dist/useRichTextEditorPresentation.js +25 -23
- package/dist/useRichTextEditorState.d.ts +3 -3
- package/dist/useRichTextEditorState.js +20 -15
- package/dist/useRichTextEditorUpdates.d.ts +1 -1
- package/dist/useRichTextEditorUpdates.js +99 -41
- package/dist/useViewerAtoms.js +63 -36
- package/ios/EditorCore.xcframework/Info.plist +5 -5
- package/ios/EditorCore.xcframework/ios-arm64/libeditor_core.a +0 -0
- package/ios/EditorCore.xcframework/ios-arm64_x86_64-simulator/libeditor_core.a +0 -0
- package/package.json +11 -3
- package/react-native.config.js +1 -1
- package/rust/android/arm64-v8a/libeditor_core.so +0 -0
- package/rust/android/armeabi-v7a/libeditor_core.so +0 -0
- package/rust/android/x86/libeditor_core.so +0 -0
- package/rust/android/x86_64/libeditor_core.so +0 -0
- package/src/AtomHost.tsx +58 -28
- package/src/EditorAddon.ts +18 -8
- package/src/EditorAddonNormalization.ts +40 -11
- package/src/EditorMentionThemeNormalization.ts +15 -4
- package/src/EditorMentionThemeValidation.ts +51 -14
- package/src/EditorStyleSheet.ts +1 -0
- package/src/EditorStyleSheetNormalization.ts +195 -64
- package/src/EditorTheme.ts +13 -5
- package/src/EditorToolbarComponent.tsx +2 -1
- package/src/EditorToolbarRegistry.tsx +23 -13
- package/src/EditorToolbarTypes.tsx +12 -12
- package/src/EditorToolbarVisuals.tsx +6 -3
- package/src/EditorUpdateRevision.ts +1 -0
- package/src/ExternalTextComposition.ts +259 -49
- package/src/ImageLoadingPolicy.ts +3 -1
- package/src/NativeEditorBoundaryError.ts +38 -11
- package/src/NativeEditorCollaborationTransport.ts +108 -27
- package/src/NativeEditorCreateConfig.ts +92 -19
- package/src/NativeEditorCreateJson.ts +163 -26
- package/src/NativeEditorCreateValidation.ts +33 -12
- package/src/NativeEditorDocumentBridge.ts +111 -19
- package/src/NativeEditorDocumentHandle.ts +9 -4
- package/src/NativeEditorLocalAwareness.ts +70 -15
- package/src/NativeEditorNativeModule.ts +13 -9
- package/src/NativeEditorRenderNormalization.ts +128 -29
- package/src/NativeEditorResultNormalization.ts +143 -32
- package/src/NativeEditorTypes.ts +12 -11
- package/src/NativeEditorV2Decimal.ts +12 -3
- package/src/NativeProseViewer.tsx +46 -16
- package/src/ResourceLimits.ts +15 -8
- package/src/RichTextEditor.tsx +3 -1
- package/src/RichTextEditorNativeTypes.tsx +1 -1
- package/src/RichTextEditorNativeView.tsx +2 -8
- package/src/RichTextEditorSerialization.tsx +70 -24
- package/src/RichTextEditorTypes.tsx +1 -1
- package/src/YjsCollaboration.ts +143 -47
- package/src/addons.ts +12 -8
- package/src/atomInstances.ts +25 -5
- package/src/atomUpdates.ts +23 -6
- package/src/atoms.ts +85 -18
- package/src/attributeValidation.ts +97 -33
- package/src/contentExpression.ts +218 -63
- package/src/listMarkers.ts +1 -1
- package/src/schemaDefinition.ts +82 -20
- package/src/schemaDocument.ts +15 -1
- package/src/schemaDocumentConstruction.ts +80 -16
- package/src/schemaNormalization.ts +155 -41
- package/src/schemaPresets.ts +37 -31
- package/src/schemaResolution.ts +126 -27
- package/src/specs/PreparedProseViewerNativeComponent.ts +4 -2
- package/src/useEditorToolbarInteractions.tsx +85 -36
- package/src/useEditorToolbarItems.tsx +50 -22
- package/src/useEditorToolbarPresentation.tsx +81 -58
- package/src/useEditorToolbarState.tsx +8 -6
- package/src/useFocusPreservingFrames.ts +43 -15
- package/src/useNativeEditor.ts +111 -51
- package/src/useRichTextEditorCommands.tsx +127 -54
- package/src/useRichTextEditorEvents.tsx +144 -42
- package/src/useRichTextEditorMentions.tsx +118 -37
- package/src/useRichTextEditorPresentation.tsx +128 -114
- package/src/useRichTextEditorState.tsx +76 -40
- package/src/useRichTextEditorUpdates.tsx +207 -56
- package/src/useViewerAtoms.tsx +162 -66
|
@@ -82,29 +82,31 @@ export function areToolbarFrameListsEqual(
|
|
|
82
82
|
if (left.length !== right.length) {
|
|
83
83
|
return false;
|
|
84
84
|
}
|
|
85
|
+
|
|
85
86
|
return left.every((frame, index) => areToolbarFramesEqual(frame, right[index]));
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
export function notifyEditorToolbarFrameListeners() {
|
|
89
|
-
editorToolbarFrameListeners.forEach(
|
|
90
|
+
editorToolbarFrameListeners.forEach(listener => listener());
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
export function notifyEditorToolbarMentionStateListeners() {
|
|
93
|
-
editorToolbarMentionStateListeners.forEach(
|
|
94
|
+
editorToolbarMentionStateListeners.forEach(listener => listener());
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
export function getEditorToolbarFramesSnapshot(ownerId: number): EditorToolbarFrame[] {
|
|
97
98
|
return Array.from(editorToolbarFrames.values())
|
|
98
99
|
.filter(
|
|
99
|
-
|
|
100
|
+
registration =>
|
|
100
101
|
registration.ownerId === ownerId ||
|
|
101
102
|
(registration.ownerId == null && activeEditorToolbarFrameOwnerId === ownerId)
|
|
102
103
|
)
|
|
103
|
-
.map(
|
|
104
|
+
.map(registration => registration.frame);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
export function subscribeEditorToolbarMentionState(listener: EditorToolbarFrameListener) {
|
|
107
108
|
editorToolbarMentionStateListeners.add(listener);
|
|
109
|
+
|
|
108
110
|
return () => {
|
|
109
111
|
editorToolbarMentionStateListeners.delete(listener);
|
|
110
112
|
};
|
|
@@ -131,10 +133,12 @@ export function registerEditorToolbarFrame(
|
|
|
131
133
|
if (editorToolbarFrames.delete(id)) {
|
|
132
134
|
notifyEditorToolbarFrameListeners();
|
|
133
135
|
}
|
|
136
|
+
|
|
134
137
|
return;
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
const currentRegistration = editorToolbarFrames.get(id);
|
|
141
|
+
|
|
138
142
|
if (
|
|
139
143
|
currentRegistration?.ownerId === ownerId &&
|
|
140
144
|
areToolbarFramesEqual(currentRegistration.frame, frame)
|
|
@@ -174,33 +178,36 @@ export function setActiveEditorToolbarFrameOwnerForEditor(ownerId: number, isAct
|
|
|
174
178
|
const nextOwnerId = isActive
|
|
175
179
|
? ownerId
|
|
176
180
|
: activeEditorToolbarFrameOwnerId === ownerId
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
? null
|
|
182
|
+
: activeEditorToolbarFrameOwnerId;
|
|
183
|
+
|
|
179
184
|
if (activeEditorToolbarFrameOwnerId === nextOwnerId) {
|
|
180
185
|
return;
|
|
181
186
|
}
|
|
187
|
+
|
|
182
188
|
activeEditorToolbarFrameOwnerId = nextOwnerId;
|
|
183
189
|
notifyEditorToolbarFrameListeners();
|
|
184
190
|
}
|
|
185
191
|
|
|
186
192
|
export function useEditorToolbarFrames(ownerId: number): readonly EditorToolbarFrame[] {
|
|
187
|
-
const [frames, setFrames] = useState<EditorToolbarFrame[]>(() =>
|
|
188
|
-
getEditorToolbarFramesSnapshot(ownerId)
|
|
189
|
-
);
|
|
193
|
+
const [ frames, setFrames ] = useState<EditorToolbarFrame[]>(() =>
|
|
194
|
+
getEditorToolbarFramesSnapshot(ownerId));
|
|
190
195
|
|
|
191
196
|
useEffect(() => {
|
|
192
197
|
const listener = () => {
|
|
193
198
|
const nextFrames = getEditorToolbarFramesSnapshot(ownerId);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
199
|
+
|
|
200
|
+
setFrames(currentFrames =>
|
|
201
|
+
areToolbarFrameListsEqual(currentFrames, nextFrames) ? currentFrames : nextFrames);
|
|
197
202
|
};
|
|
203
|
+
|
|
198
204
|
editorToolbarFrameListeners.add(listener);
|
|
199
205
|
listener();
|
|
206
|
+
|
|
200
207
|
return () => {
|
|
201
208
|
editorToolbarFrameListeners.delete(listener);
|
|
202
209
|
};
|
|
203
|
-
}, [ownerId]);
|
|
210
|
+
}, [ ownerId ]);
|
|
204
211
|
|
|
205
212
|
return frames;
|
|
206
213
|
}
|
|
@@ -213,8 +220,10 @@ export function setEditorToolbarMentionState(
|
|
|
213
220
|
if (editorToolbarMentionState?.ownerId !== ownerId) {
|
|
214
221
|
return;
|
|
215
222
|
}
|
|
223
|
+
|
|
216
224
|
editorToolbarMentionState = null;
|
|
217
225
|
notifyEditorToolbarMentionStateListeners();
|
|
226
|
+
|
|
218
227
|
return;
|
|
219
228
|
}
|
|
220
229
|
|
|
@@ -222,6 +231,7 @@ export function setEditorToolbarMentionState(
|
|
|
222
231
|
ownerId,
|
|
223
232
|
...state,
|
|
224
233
|
};
|
|
234
|
+
|
|
225
235
|
notifyEditorToolbarMentionStateListeners();
|
|
226
236
|
}
|
|
227
237
|
|
|
@@ -64,9 +64,9 @@ export interface EditorToolbarMaterialIcon {
|
|
|
64
64
|
/**
|
|
65
65
|
* A toolbar button's icon:
|
|
66
66
|
*
|
|
67
|
-
* - `default`
|
|
68
|
-
* - `glyph`
|
|
69
|
-
* - `platform`
|
|
67
|
+
* - `default` : one of the package's built-in icons.
|
|
68
|
+
* - `glyph` : arbitrary text or an emoji, drawn as-is.
|
|
69
|
+
* - `platform` : per-platform native icons, with `fallbackText` when the
|
|
70
70
|
* platform cannot resolve the named icon.
|
|
71
71
|
*/
|
|
72
72
|
export type EditorToolbarIcon =
|
|
@@ -102,14 +102,14 @@ export interface EditorToolbarButtonStyle {
|
|
|
102
102
|
* name), an `icon`, an optional `key` (defaults to something derived from the
|
|
103
103
|
* variant), and an optional `placement`.
|
|
104
104
|
*
|
|
105
|
-
* - `mark`
|
|
106
|
-
* - `link` / `image`
|
|
107
|
-
* - `heading`
|
|
108
|
-
* - `blockquote`
|
|
109
|
-
* - `list`
|
|
110
|
-
* - `command`
|
|
111
|
-
* - `node`
|
|
112
|
-
* - `action`
|
|
105
|
+
* - `mark` : toggles the named mark; active and enabled state come from the engine.
|
|
106
|
+
* - `link` / `image` : calls the editor's `onRequestLink` / `onRequestImage`.
|
|
107
|
+
* - `heading` : toggles the given heading level.
|
|
108
|
+
* - `blockquote` : toggles blockquote wrapping.
|
|
109
|
+
* - `list` : toggles the given list type.
|
|
110
|
+
* - `command` : runs an {@link EditorToolbarCommand}.
|
|
111
|
+
* - `node` : inserts the named node type, e.g. `'horizontalRule'`.
|
|
112
|
+
* - `action` : host-defined; calls `onToolbarAction` with its `key`, and the
|
|
113
113
|
* host supplies `isActive`/`isDisabled` since the engine knows nothing about it.
|
|
114
114
|
*/
|
|
115
115
|
export type EditorToolbarLeafItem = (
|
|
@@ -191,7 +191,7 @@ export type EditorToolbarLeafItem = (
|
|
|
191
191
|
export type EditorToolbarGroupChildItem = EditorToolbarLeafItem;
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
|
-
* Several buttons collapsed behind one
|
|
194
|
+
* Several buttons collapsed behind one : heading levels, say. The group
|
|
195
195
|
* reports active when any child is active, and disabled when every child is.
|
|
196
196
|
*/
|
|
197
197
|
export interface EditorToolbarGroupItem {
|
|
@@ -18,7 +18,7 @@ export const MENU_MARGIN = 8;
|
|
|
18
18
|
|
|
19
19
|
export const MENU_WIDTH = 192;
|
|
20
20
|
|
|
21
|
-
export const KEYBOARD_FRAME_REMEASURE_DELAYS_MS = [50, 150, 300] as const;
|
|
21
|
+
export const KEYBOARD_FRAME_REMEASURE_DELAYS_MS = [ 50, 150, 300 ] as const;
|
|
22
22
|
|
|
23
23
|
export const ACTIVE_BG = 'rgba(0, 122, 255, 0.12)';
|
|
24
24
|
|
|
@@ -61,7 +61,7 @@ export const DEFAULT_GLYPH_ICONS: Record<EditorToolbarDefaultIconId, string> = {
|
|
|
61
61
|
indentList: '→',
|
|
62
62
|
outdentList: '←',
|
|
63
63
|
lineBreak: '↵',
|
|
64
|
-
horizontalRule: '
|
|
64
|
+
horizontalRule: ':',
|
|
65
65
|
undo: '↩',
|
|
66
66
|
redo: '↪',
|
|
67
67
|
};
|
|
@@ -95,6 +95,7 @@ export function resolveMentionSuggestionDisplayLabel(
|
|
|
95
95
|
trigger: string
|
|
96
96
|
): string {
|
|
97
97
|
const label = suggestion.label?.trim() || suggestion.title;
|
|
98
|
+
|
|
98
99
|
return trigger.length > 0 && !label.startsWith(trigger) ? `${trigger}${label}` : label;
|
|
99
100
|
}
|
|
100
101
|
|
|
@@ -108,6 +109,7 @@ export function ToolbarIcon({
|
|
|
108
109
|
size?: number;
|
|
109
110
|
}) {
|
|
110
111
|
const materialIconName = resolveMaterialIconName(icon);
|
|
112
|
+
|
|
111
113
|
if (materialIconName) {
|
|
112
114
|
return (
|
|
113
115
|
<View style={styles.iconContainer}>
|
|
@@ -117,9 +119,10 @@ export function ToolbarIcon({
|
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
const glyph = resolveGlyphText(icon) ?? '?';
|
|
122
|
+
|
|
120
123
|
return (
|
|
121
124
|
<View style={styles.iconContainer}>
|
|
122
|
-
<Text style={[styles.iconText, size == null ? null : { fontSize: size }, { color }]}>
|
|
125
|
+
<Text style={[ styles.iconText, size == null ? null : { fontSize: size }, { color } ]}>
|
|
123
126
|
{glyph}
|
|
124
127
|
</Text>
|
|
125
128
|
</View>
|