@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.
Files changed (161) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/android/build.gradle +3 -0
  4. package/app.plugin.js +42 -39
  5. package/dist/AtomHost.js +18 -11
  6. package/dist/EditorAddon.js +4 -2
  7. package/dist/EditorAddonNormalization.js +17 -9
  8. package/dist/EditorMentionThemeNormalization.js +6 -3
  9. package/dist/EditorMentionThemeValidation.js +28 -11
  10. package/dist/EditorStyleSheetNormalization.js +84 -37
  11. package/dist/EditorTheme.d.ts +4 -0
  12. package/dist/EditorTheme.js +5 -3
  13. package/dist/EditorToolbarComponent.d.ts +1 -1
  14. package/dist/EditorToolbarComponent.js +1 -1
  15. package/dist/EditorToolbarRegistry.js +5 -5
  16. package/dist/EditorToolbarTypes.d.ts +12 -12
  17. package/dist/EditorToolbarVisuals.js +1 -1
  18. package/dist/ExternalTextComposition.js +89 -43
  19. package/dist/ImageLoadingPolicy.d.ts +1 -1
  20. package/dist/NativeEditorBoundaryError.d.ts +7 -7
  21. package/dist/NativeEditorBoundaryError.js +9 -5
  22. package/dist/NativeEditorCollaborationTransport.d.ts +7 -7
  23. package/dist/NativeEditorCollaborationTransport.js +28 -15
  24. package/dist/NativeEditorCreateConfig.js +11 -6
  25. package/dist/NativeEditorCreateJson.js +51 -25
  26. package/dist/NativeEditorCreateValidation.js +11 -6
  27. package/dist/NativeEditorDocumentBridge.d.ts +1 -1
  28. package/dist/NativeEditorDocumentBridge.js +32 -18
  29. package/dist/NativeEditorDocumentHandle.d.ts +4 -4
  30. package/dist/NativeEditorDocumentHandle.js +1 -1
  31. package/dist/NativeEditorLocalAwareness.js +25 -13
  32. package/dist/NativeEditorNativeModule.d.ts +8 -1
  33. package/dist/NativeEditorNativeModule.js +7 -5
  34. package/dist/NativeEditorRenderNormalization.js +66 -25
  35. package/dist/NativeEditorResultNormalization.js +53 -29
  36. package/dist/NativeEditorTypes.d.ts +10 -10
  37. package/dist/NativeEditorV2Decimal.js +6 -3
  38. package/dist/NativeProseViewer.js +11 -3
  39. package/dist/ResourceLimits.d.ts +2 -2
  40. package/dist/ResourceLimits.js +7 -2
  41. package/dist/RichTextEditor.js +1 -1
  42. package/dist/RichTextEditorNativeTypes.d.ts +1 -1
  43. package/dist/RichTextEditorNativeView.d.ts +1 -3
  44. package/dist/RichTextEditorSerialization.js +24 -14
  45. package/dist/RichTextEditorTypes.d.ts +1 -1
  46. package/dist/YjsCollaboration.d.ts +7 -7
  47. package/dist/YjsCollaboration.js +42 -26
  48. package/dist/addons.d.ts +4 -4
  49. package/dist/addons.js +3 -3
  50. package/dist/atomInstances.js +6 -3
  51. package/dist/atomUpdates.js +7 -4
  52. package/dist/atoms.js +20 -12
  53. package/dist/attributeValidation.js +55 -24
  54. package/dist/contentExpression.js +80 -42
  55. package/dist/listMarkers.d.ts +1 -1
  56. package/dist/listMarkers.js +1 -1
  57. package/dist/schemaDefinition.d.ts +1 -1
  58. package/dist/schemaDefinition.js +23 -14
  59. package/dist/schemaDocument.js +1 -1
  60. package/dist/schemaDocumentConstruction.js +25 -14
  61. package/dist/schemaNormalization.js +51 -29
  62. package/dist/schemaPresets.d.ts +1 -1
  63. package/dist/schemaPresets.js +9 -4
  64. package/dist/schemaResolution.js +46 -25
  65. package/dist/specs/PreparedProseViewerNativeComponent.d.ts +4 -0
  66. package/dist/useEditorToolbarInteractions.d.ts +2 -2
  67. package/dist/useEditorToolbarInteractions.js +45 -23
  68. package/dist/useEditorToolbarItems.d.ts +1 -1
  69. package/dist/useEditorToolbarItems.js +4 -3
  70. package/dist/useEditorToolbarPresentation.d.ts +3 -3
  71. package/dist/useEditorToolbarPresentation.js +4 -4
  72. package/dist/useEditorToolbarState.d.ts +1 -1
  73. package/dist/useEditorToolbarState.js +1 -1
  74. package/dist/useFocusPreservingFrames.js +11 -8
  75. package/dist/useNativeEditor.d.ts +1 -1
  76. package/dist/useNativeEditor.js +21 -11
  77. package/dist/useRichTextEditorCommands.d.ts +2 -2
  78. package/dist/useRichTextEditorCommands.js +59 -29
  79. package/dist/useRichTextEditorEvents.d.ts +3 -3
  80. package/dist/useRichTextEditorEvents.js +75 -32
  81. package/dist/useRichTextEditorMentions.d.ts +4 -4
  82. package/dist/useRichTextEditorMentions.js +48 -29
  83. package/dist/useRichTextEditorPresentation.d.ts +4 -4
  84. package/dist/useRichTextEditorPresentation.js +25 -23
  85. package/dist/useRichTextEditorState.d.ts +3 -3
  86. package/dist/useRichTextEditorState.js +20 -15
  87. package/dist/useRichTextEditorUpdates.d.ts +1 -1
  88. package/dist/useRichTextEditorUpdates.js +99 -41
  89. package/dist/useViewerAtoms.js +63 -36
  90. package/ios/EditorCore.xcframework/Info.plist +5 -5
  91. package/ios/EditorCore.xcframework/ios-arm64/libeditor_core.a +0 -0
  92. package/ios/EditorCore.xcframework/ios-arm64_x86_64-simulator/libeditor_core.a +0 -0
  93. package/package.json +11 -3
  94. package/react-native.config.js +1 -1
  95. package/rust/android/arm64-v8a/libeditor_core.so +0 -0
  96. package/rust/android/armeabi-v7a/libeditor_core.so +0 -0
  97. package/rust/android/x86/libeditor_core.so +0 -0
  98. package/rust/android/x86_64/libeditor_core.so +0 -0
  99. package/src/AtomHost.tsx +58 -28
  100. package/src/EditorAddon.ts +18 -8
  101. package/src/EditorAddonNormalization.ts +40 -11
  102. package/src/EditorMentionThemeNormalization.ts +15 -4
  103. package/src/EditorMentionThemeValidation.ts +51 -14
  104. package/src/EditorStyleSheet.ts +1 -0
  105. package/src/EditorStyleSheetNormalization.ts +195 -64
  106. package/src/EditorTheme.ts +13 -5
  107. package/src/EditorToolbarComponent.tsx +2 -1
  108. package/src/EditorToolbarRegistry.tsx +23 -13
  109. package/src/EditorToolbarTypes.tsx +12 -12
  110. package/src/EditorToolbarVisuals.tsx +6 -3
  111. package/src/EditorUpdateRevision.ts +1 -0
  112. package/src/ExternalTextComposition.ts +259 -49
  113. package/src/ImageLoadingPolicy.ts +3 -1
  114. package/src/NativeEditorBoundaryError.ts +38 -11
  115. package/src/NativeEditorCollaborationTransport.ts +108 -27
  116. package/src/NativeEditorCreateConfig.ts +92 -19
  117. package/src/NativeEditorCreateJson.ts +163 -26
  118. package/src/NativeEditorCreateValidation.ts +33 -12
  119. package/src/NativeEditorDocumentBridge.ts +111 -19
  120. package/src/NativeEditorDocumentHandle.ts +9 -4
  121. package/src/NativeEditorLocalAwareness.ts +70 -15
  122. package/src/NativeEditorNativeModule.ts +13 -9
  123. package/src/NativeEditorRenderNormalization.ts +128 -29
  124. package/src/NativeEditorResultNormalization.ts +143 -32
  125. package/src/NativeEditorTypes.ts +12 -11
  126. package/src/NativeEditorV2Decimal.ts +12 -3
  127. package/src/NativeProseViewer.tsx +46 -16
  128. package/src/ResourceLimits.ts +15 -8
  129. package/src/RichTextEditor.tsx +3 -1
  130. package/src/RichTextEditorNativeTypes.tsx +1 -1
  131. package/src/RichTextEditorNativeView.tsx +2 -8
  132. package/src/RichTextEditorSerialization.tsx +70 -24
  133. package/src/RichTextEditorTypes.tsx +1 -1
  134. package/src/YjsCollaboration.ts +143 -47
  135. package/src/addons.ts +12 -8
  136. package/src/atomInstances.ts +25 -5
  137. package/src/atomUpdates.ts +23 -6
  138. package/src/atoms.ts +85 -18
  139. package/src/attributeValidation.ts +97 -33
  140. package/src/contentExpression.ts +218 -63
  141. package/src/listMarkers.ts +1 -1
  142. package/src/schemaDefinition.ts +82 -20
  143. package/src/schemaDocument.ts +15 -1
  144. package/src/schemaDocumentConstruction.ts +80 -16
  145. package/src/schemaNormalization.ts +155 -41
  146. package/src/schemaPresets.ts +37 -31
  147. package/src/schemaResolution.ts +126 -27
  148. package/src/specs/PreparedProseViewerNativeComponent.ts +4 -2
  149. package/src/useEditorToolbarInteractions.tsx +85 -36
  150. package/src/useEditorToolbarItems.tsx +50 -22
  151. package/src/useEditorToolbarPresentation.tsx +81 -58
  152. package/src/useEditorToolbarState.tsx +8 -6
  153. package/src/useFocusPreservingFrames.ts +43 -15
  154. package/src/useNativeEditor.ts +111 -51
  155. package/src/useRichTextEditorCommands.tsx +127 -54
  156. package/src/useRichTextEditorEvents.tsx +144 -42
  157. package/src/useRichTextEditorMentions.tsx +118 -37
  158. package/src/useRichTextEditorPresentation.tsx +128 -114
  159. package/src/useRichTextEditorState.tsx +76 -40
  160. package/src/useRichTextEditorUpdates.tsx +207 -56
  161. 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((listener) => listener());
90
+ editorToolbarFrameListeners.forEach(listener => listener());
90
91
  }
91
92
 
92
93
  export function notifyEditorToolbarMentionStateListeners() {
93
- editorToolbarMentionStateListeners.forEach((listener) => listener());
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
- (registration) =>
100
+ registration =>
100
101
  registration.ownerId === ownerId ||
101
102
  (registration.ownerId == null && activeEditorToolbarFrameOwnerId === ownerId)
102
103
  )
103
- .map((registration) => registration.frame);
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
- ? null
178
- : activeEditorToolbarFrameOwnerId;
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
- setFrames((currentFrames) =>
195
- areToolbarFrameListsEqual(currentFrames, nextFrames) ? currentFrames : nextFrames
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` 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
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` 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
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 heading levels, say. The group
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>
@@ -22,5 +22,6 @@ export function allocateEditorUpdateRevision(
22
22
  },
23
23
  };
24
24
  }
25
+
25
26
  return { revision: currentRevision + 1 };
26
27
  }