react-native-enriched-markdown-scaffold 0.6.0-scaffold.8 → 0.7.4-scaffold.2

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 (150) hide show
  1. package/ReactNativeEnrichedMarkdown.podspec +62 -11
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +3 -0
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +1 -0
  4. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerDelegate.java +9 -0
  5. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextInputManagerInterface.java +3 -0
  6. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +3 -0
  7. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +1 -0
  8. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +20 -0
  9. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +744 -0
  10. package/android/src/main/baseline-prof.txt +75 -2
  11. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +62 -0
  12. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +10 -2
  13. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +10 -0
  14. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +9 -2
  15. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +10 -0
  16. package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/AccessibilityLabels.kt +15 -0
  17. package/android/src/main/java/com/swmansion/enriched/markdown/accessibility/MarkdownAccessibilityHelper.kt +44 -7
  18. package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputManager.kt +52 -0
  19. package/android/src/main/java/com/swmansion/enriched/markdown/input/EnrichedMarkdownTextInputView.kt +89 -11
  20. package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/FormattingStore.kt +19 -0
  21. package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputParser.kt +22 -3
  22. package/android/src/main/java/com/swmansion/enriched/markdown/input/formatting/InputRemend.kt +1 -0
  23. package/android/src/main/java/com/swmansion/enriched/markdown/input/layout/InputMeasurementStore.kt +7 -1
  24. package/android/src/main/java/com/swmansion/enriched/markdown/input/toolbar/InputContextMenu.kt +54 -13
  25. package/android/src/main/java/com/swmansion/enriched/markdown/parser/MarkdownASTNode.kt +17 -0
  26. package/android/src/main/java/com/swmansion/enriched/markdown/renderer/SpanStyleCache.kt +4 -4
  27. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +30 -0
  28. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkEvents.kt +22 -0
  29. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/SelectionActionMode.kt +36 -7
  30. package/android/src/main/java/com/swmansion/enriched/markdown/views/TableContainerView.kt +73 -3
  31. package/android/src/main/jni/CMakeLists.txt +15 -1
  32. package/android/src/math/java/com/swmansion/enriched/markdown/views/MathContainerView.kt +24 -2
  33. package/app.plugin.js +2 -1
  34. package/cpp/parser/MD4CParser.cpp +1 -1
  35. package/cpp/wasm/build.sh +9 -9
  36. package/docs/ACCESSIBILITY.md +172 -0
  37. package/docs/API_REFERENCE.md +948 -0
  38. package/docs/COPY_OPTIONS.md +127 -0
  39. package/docs/ELEMENTS_STRUCTURE.md +112 -0
  40. package/docs/IMAGE_CACHING.md +25 -0
  41. package/docs/INPUT.md +233 -0
  42. package/docs/LATEX_MATH.md +136 -0
  43. package/docs/MACOS.md +19 -0
  44. package/docs/MARKDOWN_STREAMING.md +36 -0
  45. package/docs/MENTIONS.md +97 -0
  46. package/docs/RTL.md +82 -0
  47. package/docs/STYLES.md +519 -0
  48. package/docs/TEXT.md +110 -0
  49. package/docs/WEB.md +49 -0
  50. package/ios/EnrichedMarkdown.mm +82 -25
  51. package/ios/EnrichedMarkdownText.mm +37 -5
  52. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +20 -0
  53. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +744 -0
  54. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/RCTComponentViewHelpers.h +15 -0
  55. package/ios/input/ENRMFormattingStore.h +5 -0
  56. package/ios/input/ENRMFormattingStore.mm +34 -0
  57. package/ios/input/ENRMInputTextView.h +2 -0
  58. package/ios/input/ENRMInputTextView.mm +8 -17
  59. package/ios/input/ENRMMarkdownSerializer.mm +1 -1
  60. package/ios/input/EnrichedMarkdownTextInput+ContextMenu.mm +71 -53
  61. package/ios/input/EnrichedMarkdownTextInput+Internal.h +26 -0
  62. package/ios/input/EnrichedMarkdownTextInput.h +1 -0
  63. package/ios/input/EnrichedMarkdownTextInput.mm +230 -29
  64. package/ios/input/styles/ENRMBoldStyleHandler.mm +3 -2
  65. package/ios/input/styles/ENRMItalicStyleHandler.mm +3 -2
  66. package/ios/renderer/AttributedRenderer.m +51 -6
  67. package/ios/renderer/ENRMMathInlineRenderer.m +5 -1
  68. package/ios/styles/ENRMFontSlot.h +1 -1
  69. package/ios/utils/ENRMAccessibilityLabels.h +36 -0
  70. package/ios/utils/ENRMAccessibilityLabels.m +5 -0
  71. package/ios/utils/EditMenuUtils+macOS.m +4 -5
  72. package/ios/utils/EditMenuUtils.h +70 -0
  73. package/ios/utils/EditMenuUtils.m +14 -11
  74. package/ios/utils/LastElementUtils.h +39 -2
  75. package/ios/utils/MarkdownAccessibilityElementBuilder.h +18 -16
  76. package/ios/utils/MarkdownAccessibilityElementBuilder.m +64 -32
  77. package/ios/utils/ParagraphStyleUtils.m +21 -2
  78. package/ios/views/ENRMMathContainerView.h +8 -0
  79. package/ios/views/ENRMMathContainerView.m +7 -5
  80. package/ios/views/ENRMTableIOSGridView.h +40 -0
  81. package/ios/views/ENRMTableIOSGridView.m +216 -0
  82. package/ios/views/EnrichedMarkdownInternalText.h +2 -0
  83. package/ios/views/EnrichedMarkdownInternalText.m +2 -0
  84. package/ios/views/TableContainerView.h +8 -0
  85. package/ios/views/TableContainerView.m +72 -128
  86. package/lib/module/EnrichedMarkdownNativeComponent.ts +37 -0
  87. package/lib/module/EnrichedMarkdownTextInput.js +48 -1
  88. package/lib/module/EnrichedMarkdownTextInput.js.map +1 -1
  89. package/lib/module/EnrichedMarkdownTextInputNativeComponent.ts +35 -0
  90. package/lib/module/EnrichedMarkdownTextNativeComponent.ts +37 -0
  91. package/lib/module/accessibilityLabelDefaults.js +64 -0
  92. package/lib/module/accessibilityLabelDefaults.js.map +1 -0
  93. package/lib/module/index.js +1 -0
  94. package/lib/module/index.js.map +1 -1
  95. package/lib/module/native/EnrichedMarkdownText.js +72 -4
  96. package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
  97. package/lib/module/normalizeMenuItem.js +38 -0
  98. package/lib/module/normalizeMenuItem.js.map +1 -0
  99. package/lib/module/types/AccessibilityLabels.js +2 -0
  100. package/lib/module/types/AccessibilityLabels.js.map +1 -0
  101. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +34 -0
  102. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
  103. package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts +55 -1
  104. package/lib/typescript/src/EnrichedMarkdownTextInput.d.ts.map +1 -1
  105. package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts +30 -0
  106. package/lib/typescript/src/EnrichedMarkdownTextInputNativeComponent.d.ts.map +1 -1
  107. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +34 -0
  108. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
  109. package/lib/typescript/src/accessibilityLabelDefaults.d.ts +16 -0
  110. package/lib/typescript/src/accessibilityLabelDefaults.d.ts.map +1 -0
  111. package/lib/typescript/src/index.d.ts +4 -2
  112. package/lib/typescript/src/index.d.ts.map +1 -1
  113. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +3 -3
  114. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
  115. package/lib/typescript/src/normalizeMenuItem.d.ts +7 -0
  116. package/lib/typescript/src/normalizeMenuItem.d.ts.map +1 -0
  117. package/lib/typescript/src/types/AccessibilityLabels.d.ts +114 -0
  118. package/lib/typescript/src/types/AccessibilityLabels.d.ts.map +1 -0
  119. package/lib/typescript/src/types/MarkdownTextProps.d.ts +78 -9
  120. package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
  121. package/package.json +4 -2
  122. package/plugin/build/withAndroidMath.js +19 -0
  123. package/plugin/build/withIosMath.js +28 -0
  124. package/plugin/build/withReactNativeEnrichedMarkdown.js +11 -0
  125. package/plugin/tsconfig.build.json +16 -0
  126. package/src/EnrichedMarkdownNativeComponent.ts +37 -0
  127. package/src/EnrichedMarkdownTextInput.tsx +117 -1
  128. package/src/EnrichedMarkdownTextInputNativeComponent.ts +35 -0
  129. package/src/EnrichedMarkdownTextNativeComponent.ts +37 -0
  130. package/src/accessibilityLabelDefaults.ts +83 -0
  131. package/src/index.tsx +11 -0
  132. package/src/native/EnrichedMarkdownText.tsx +120 -6
  133. package/src/normalizeMenuItem.ts +52 -0
  134. package/src/types/AccessibilityLabels.ts +118 -0
  135. package/src/types/MarkdownTextProps.ts +74 -9
  136. package/lib/module/plugin/withAndroidMath.js +0 -20
  137. package/lib/module/plugin/withAndroidMath.js.map +0 -1
  138. package/lib/module/plugin/withIosMath.js +0 -23
  139. package/lib/module/plugin/withIosMath.js.map +0 -1
  140. package/lib/module/plugin/withReactNativeEnrichedMarkdown.js +0 -16
  141. package/lib/module/plugin/withReactNativeEnrichedMarkdown.js.map +0 -1
  142. package/lib/typescript/src/plugin/withAndroidMath.d.ts +0 -5
  143. package/lib/typescript/src/plugin/withAndroidMath.d.ts.map +0 -1
  144. package/lib/typescript/src/plugin/withIosMath.d.ts +0 -5
  145. package/lib/typescript/src/plugin/withIosMath.d.ts.map +0 -1
  146. package/lib/typescript/src/plugin/withReactNativeEnrichedMarkdown.d.ts +0 -6
  147. package/lib/typescript/src/plugin/withReactNativeEnrichedMarkdown.d.ts.map +0 -1
  148. /package/{src/plugin → plugin/src}/withAndroidMath.ts +0 -0
  149. /package/{src/plugin → plugin/src}/withIosMath.ts +0 -0
  150. /package/{src/plugin → plugin/src}/withReactNativeEnrichedMarkdown.ts +0 -0
@@ -3,6 +3,11 @@ import EnrichedMarkdownTextNativeComponent from '../EnrichedMarkdownTextNativeCo
3
3
  import type { MarkdownStyleInternal } from '../EnrichedMarkdownTextNativeComponent';
4
4
  import EnrichedMarkdownNativeComponent from '../EnrichedMarkdownNativeComponent';
5
5
  import { normalizeMarkdownStyle } from '../normalizeMarkdownStyle';
6
+ import { resolveAccessibilityLabels } from '../accessibilityLabelDefaults';
7
+ import {
8
+ normalizeMenuItem,
9
+ normalizeLegacyBooleanMenuItem,
10
+ } from '../normalizeMenuItem';
6
11
  import type { NativeSyntheticEvent } from 'react-native';
7
12
  import type { MarkdownStyle, Md4cFlags } from '../types/MarkdownStyle';
8
13
  import type {
@@ -10,6 +15,7 @@ import type {
10
15
  StreamingConfig,
11
16
  ContextMenuItem,
12
17
  SelectionMenuConfig,
18
+ SelectionMenuPluralLabels,
13
19
  } from '../types/MarkdownTextProps';
14
20
  import type {
15
21
  LinkPressEvent,
@@ -24,9 +30,71 @@ export type {
24
30
  StreamingConfig,
25
31
  ContextMenuItem,
26
32
  SelectionMenuConfig,
33
+ SelectionMenuPluralLabels,
27
34
  };
28
35
  export type { LinkPressEvent, LinkLongPressEvent, TaskListItemPressEvent };
29
36
 
37
+ // Default English labels for the built-in selection menu actions. Defaults are
38
+ // resolved here (JS-side) so the native code always receives a concrete string.
39
+ const DEFAULT_COPY_LABEL = 'Copy';
40
+ const DEFAULT_COPY_AS_MARKDOWN_LABEL = 'Copy as Markdown';
41
+ const DEFAULT_COPY_IMAGE_URL_LABEL = 'Copy Image URL';
42
+ const DEFAULT_COPY_IMAGE_URLS_LABEL = 'Copy {count} Image URLs';
43
+
44
+ /**
45
+ * Resolves `pluralLabels` into a per-count template table (index = image count,
46
+ * 0..100) the native side can index without any locale logic. `Intl.PluralRules`
47
+ * selects the CLDR category for each count; missing categories fall back to the
48
+ * required `other`. Index 1 uses the singular `label` (the single-image case).
49
+ * Native uses `other` (copyImageUrlsLabel) for counts > 100, and falls back to
50
+ * the singular/`{count}` templates entirely when this returns an empty array
51
+ * (no plural labels set, or `Intl.PluralRules` unavailable).
52
+ */
53
+ const buildPluralTemplates = (
54
+ pluralLabels: SelectionMenuPluralLabels | undefined,
55
+ singularLabel: string
56
+ ): string[] => {
57
+ if (!pluralLabels) return [];
58
+
59
+ const IntlRef = Intl as unknown as {
60
+ PluralRules?: new (locales?: string | string[]) => {
61
+ select(n: number): string;
62
+ };
63
+ };
64
+ if (typeof IntlRef.PluralRules !== 'function') return [];
65
+
66
+ let pluralRules: { select(n: number): string };
67
+ try {
68
+ // TODO: expose `copyImageUrl.pluralLocale?: string` so i18n apps can force
69
+ // a locale independent of the device. Today this resolves to the JS
70
+ // runtime's default locale, so on an English device only `one` and `other`
71
+ // ever fire even when richer plural labels are configured.
72
+ pluralRules = new IntlRef.PluralRules();
73
+ } catch {
74
+ return [];
75
+ }
76
+
77
+ const { other } = pluralLabels;
78
+ const byCategory: Record<string, string> = {
79
+ zero: pluralLabels.zero ?? other,
80
+ one: pluralLabels.one ?? other,
81
+ two: pluralLabels.two ?? other,
82
+ few: pluralLabels.few ?? other,
83
+ many: pluralLabels.many ?? other,
84
+ other,
85
+ };
86
+
87
+ const templates: string[] = [];
88
+ for (let n = 0; n <= 100; n++) {
89
+ // The literal single-image case uses the (non-plural) singular label; every
90
+ // other count uses its CLDR category form.
91
+ templates.push(
92
+ n === 1 ? singularLabel : (byCategory[pluralRules.select(n)] ?? other)
93
+ );
94
+ }
95
+ return templates;
96
+ };
97
+
30
98
  const defaultMd4cFlags: Md4cFlags = {
31
99
  underline: false,
32
100
  superscript: false,
@@ -54,6 +122,7 @@ export const EnrichedMarkdownText = ({
54
122
  spoilerOverlay = 'particles',
55
123
  contextMenuItems,
56
124
  selectionMenuConfig,
125
+ accessibilityLabels,
57
126
  selectionColor,
58
127
  selectionHandleColor,
59
128
  textBreakStrategy,
@@ -142,12 +211,56 @@ export const EnrichedMarkdownText = ({
142
211
 
143
212
  const tableMode = streamingConfig?.tableMode ?? 'progressive';
144
213
  const normalizedStreamingConfig = useMemo(() => ({ tableMode }), [tableMode]);
145
- const normalizedSelectionMenuConfig = useMemo(
146
- () => ({
147
- copyAsMarkdown: selectionMenuConfig?.copyAsMarkdown ?? true,
148
- copyImageUrl: selectionMenuConfig?.copyImageUrl ?? true,
149
- }),
150
- [selectionMenuConfig]
214
+ const normalizedSelectionMenuConfig = useMemo(() => {
215
+ // The boolean acceptance is confined to this wrapper boundary via a single
216
+ // `as unknown` cast; the public type only exposes the object shape.
217
+ const config = selectionMenuConfig as
218
+ | {
219
+ copy?: unknown;
220
+ copyAsMarkdown?: unknown;
221
+ copyImageUrl?: unknown;
222
+ }
223
+ | undefined;
224
+
225
+ const copy = normalizeMenuItem(config?.copy, true, DEFAULT_COPY_LABEL);
226
+ const copyAsMarkdown = normalizeLegacyBooleanMenuItem(
227
+ config?.copyAsMarkdown,
228
+ 'selectionMenuConfig',
229
+ 'copyAsMarkdown',
230
+ true,
231
+ DEFAULT_COPY_AS_MARKDOWN_LABEL
232
+ );
233
+ const copyImageUrl = normalizeLegacyBooleanMenuItem(
234
+ config?.copyImageUrl,
235
+ 'selectionMenuConfig',
236
+ 'copyImageUrl',
237
+ true,
238
+ DEFAULT_COPY_IMAGE_URL_LABEL
239
+ );
240
+
241
+ const pluralLabels = (
242
+ config?.copyImageUrl as
243
+ | { pluralLabels?: SelectionMenuPluralLabels }
244
+ | undefined
245
+ )?.pluralLabels;
246
+
247
+ return {
248
+ copyAsMarkdown: copyAsMarkdown.enabled,
249
+ copyImageUrl: copyImageUrl.enabled,
250
+ copyLabel: copy.label,
251
+ copyAsMarkdownLabel: copyAsMarkdown.label,
252
+ copyImageUrlLabel: copyImageUrl.label,
253
+ copyImageUrlsLabel: pluralLabels?.other ?? DEFAULT_COPY_IMAGE_URLS_LABEL,
254
+ copyImageUrlPluralTemplates: buildPluralTemplates(
255
+ pluralLabels,
256
+ copyImageUrl.label
257
+ ),
258
+ };
259
+ }, [selectionMenuConfig]);
260
+
261
+ const resolvedAccessibilityLabels = useMemo(
262
+ () => resolveAccessibilityLabels(accessibilityLabels),
263
+ [accessibilityLabels]
151
264
  );
152
265
 
153
266
  const sharedProps = {
@@ -168,6 +281,7 @@ export const EnrichedMarkdownText = ({
168
281
  style: containerStyle,
169
282
  contextMenuItems: nativeContextMenuItems,
170
283
  selectionMenuConfig: normalizedSelectionMenuConfig,
284
+ accessibilityLabels: resolvedAccessibilityLabels,
171
285
  onContextMenuItemPress: handleContextMenuItemPress,
172
286
  selectionColor,
173
287
  selectionHandleColor,
@@ -0,0 +1,52 @@
1
+ // Not __DEV__-gated on purpose: deprecation warnings need to surface in
2
+ // staging/TestFlight/CI prod builds too.
3
+ const warned = new Set<string>();
4
+
5
+ const warnOnce = (key: string, msg: string) => {
6
+ if (warned.has(key)) return;
7
+ warned.add(key);
8
+ console.warn(msg);
9
+ };
10
+
11
+ export type NormalizedMenuItem = { enabled: boolean; label: string };
12
+
13
+ // TODO: revisit grouping cross-cutting utilities (this, styleUtils, linkVariantUtils,
14
+ // normalizeMarkdownStyle, etc.) into a shared module once the set grows further.
15
+ export const normalizeMenuItem = (
16
+ raw: unknown,
17
+ defaultEnabled: boolean,
18
+ defaultLabel: string
19
+ ): NormalizedMenuItem => {
20
+ if (raw === undefined)
21
+ return { enabled: defaultEnabled, label: defaultLabel };
22
+ // Validate per leaf so an empty string stays an empty string (an emoji-only
23
+ // item is a legitimate use case), while null / non-object / wrong-typed
24
+ // fields fall back to defaults — `getBoolean` on the Android side throws on
25
+ // non-booleans, and a null root would crash JS on property access.
26
+ const obj =
27
+ typeof raw === 'object' && raw !== null
28
+ ? (raw as { enabled?: unknown; label?: unknown })
29
+ : {};
30
+ return {
31
+ enabled: typeof obj.enabled === 'boolean' ? obj.enabled : defaultEnabled,
32
+ label: typeof obj.label === 'string' ? obj.label : defaultLabel,
33
+ };
34
+ };
35
+
36
+ export const normalizeLegacyBooleanMenuItem = (
37
+ raw: unknown,
38
+ parentProp: string,
39
+ field: string,
40
+ defaultEnabled: boolean,
41
+ defaultLabel: string
42
+ ): NormalizedMenuItem => {
43
+ if (typeof raw === 'boolean') {
44
+ warnOnce(
45
+ `${parentProp}.${field}`,
46
+ `[react-native-enriched-markdown] ${parentProp}.${field} as a boolean is ` +
47
+ `deprecated; use { enabled: ${raw} }. The boolean form will be removed in 0.8.`
48
+ );
49
+ return { enabled: raw, label: defaultLabel };
50
+ }
51
+ return normalizeMenuItem(raw, defaultEnabled, defaultLabel);
52
+ };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Strings spoken by VoiceOver (iOS) / TalkBack (Android) when navigating
3
+ * the rendered markdown.
4
+ *
5
+ * Every key is optional — when omitted, defaults from
6
+ * `accessibilityLabelDefaults.ts` are applied on the JS side before being
7
+ * forwarded to native. Native code can rely on every field being a concrete
8
+ * string at the point it is consumed.
9
+ *
10
+ * **Placeholder syntax.** Where a label has dynamic content, the default uses
11
+ * `{n}` (count / index, 1-based), `{content}` (resolved cell text or similar),
12
+ * or `{latex}` (math source). Translations must preserve the placeholder names
13
+ * exactly — native code substitutes them at speak time.
14
+ *
15
+ * **No plurals.** Defaults intentionally use the cardinal form (`"Row 2"`,
16
+ * `"List item 2"`) instead of ordinals or count-aware variants. Screen readers
17
+ * already announce numbers locale-appropriately, and a single template avoids
18
+ * the per-language plural rules (en `1/2+`, pl `1/2-4/5+`, ar `0/1/2/3-10/11-99/100+`, …).
19
+ *
20
+ * The shape is split into logical sub-groups so that consumers can override
21
+ * just the announcements that matter to them without re-declaring the rest.
22
+ */
23
+ export interface AccessibilityLabels {
24
+ /** Labels spoken for list items. iOS + Android. */
25
+ list?: {
26
+ /** @default 'Bullet point' */
27
+ bulletPoint?: string;
28
+ /**
29
+ * Spoken when the bullet is inside another list.
30
+ * @default 'Nested bullet point'
31
+ */
32
+ nestedBulletPoint?: string;
33
+ /**
34
+ * `{n}` → 1-based item number.
35
+ * @default 'List item {n}'
36
+ */
37
+ orderedItem?: string;
38
+ /**
39
+ * `{n}` → 1-based item number.
40
+ * @default 'Nested list item {n}'
41
+ */
42
+ nestedOrderedItem?: string;
43
+ };
44
+
45
+ /** Labels appended for content inside a blockquote. iOS + Android. */
46
+ blockquote?: {
47
+ /**
48
+ * Spoken for top-level blockquote content.
49
+ * @default 'Blockquote'
50
+ */
51
+ quote?: string;
52
+ /**
53
+ * Spoken for content nested inside another blockquote.
54
+ * @default 'Nested blockquote'
55
+ */
56
+ nestedQuote?: string;
57
+ };
58
+
59
+ /** Labels spoken for tables. iOS + Android. */
60
+ table?: {
61
+ /**
62
+ * `{n}` → 1-based row index, `{content}` → comma-joined cell texts.
63
+ * @default 'Row {n}: {content}'
64
+ */
65
+ row?: string;
66
+ };
67
+
68
+ /** Labels spoken for math equations. iOS + Android. */
69
+ math?: {
70
+ /**
71
+ * `{latex}` → equation source.
72
+ * @default 'Math: {latex}'
73
+ */
74
+ equation?: string;
75
+ };
76
+
77
+ /**
78
+ * Labels for the VoiceOver rotor (the secondary jump-by-type navigator on iOS).
79
+ * iOS only — Android has no rotor concept.
80
+ */
81
+ rotor?: {
82
+ /** @default 'Headings' */
83
+ headings?: string;
84
+ /** @default 'Links' */
85
+ links?: string;
86
+ /** @default 'Images' */
87
+ images?: string;
88
+ };
89
+ }
90
+
91
+ /**
92
+ * Fully-populated counterpart of `AccessibilityLabels` — every leaf field is a
93
+ * concrete string. Produced by `resolveAccessibilityLabels()` and what native
94
+ * code should be wired to consume.
95
+ */
96
+ export interface ResolvedAccessibilityLabels {
97
+ list: {
98
+ bulletPoint: string;
99
+ nestedBulletPoint: string;
100
+ orderedItem: string;
101
+ nestedOrderedItem: string;
102
+ };
103
+ blockquote: {
104
+ quote: string;
105
+ nestedQuote: string;
106
+ };
107
+ table: {
108
+ row: string;
109
+ };
110
+ math: {
111
+ equation: string;
112
+ };
113
+ rotor: {
114
+ headings: string;
115
+ links: string;
116
+ images: string;
117
+ };
118
+ }
@@ -1,5 +1,6 @@
1
1
  import type { ColorValue, ViewProps, ViewStyle, TextStyle } from 'react-native';
2
2
  import type { MarkdownStyle, Md4cFlags } from './MarkdownStyle';
3
+ import type { AccessibilityLabels } from './AccessibilityLabels';
3
4
  import type {
4
5
  LinkPressEvent,
5
6
  LinkLongPressEvent,
@@ -20,17 +21,71 @@ export interface ContextMenuItem {
20
21
  visible?: boolean;
21
22
  }
22
23
 
24
+ /**
25
+ * Plural forms for the "Copy Image URL(s)" action, keyed by CLDR plural
26
+ * category. The right form is chosen at runtime from the number of selected
27
+ * images using `Intl.PluralRules` (resolved against the app's default locale).
28
+ *
29
+ * Each value is a template where the `{count}` token is replaced with the
30
+ * number of selected images. Only `other` is required by CLDR; any category
31
+ * left `undefined` falls back to `other`.
32
+ *
33
+ * @example
34
+ * // Polish: one / few / many / other
35
+ * pluralLabels: {
36
+ * one: 'Kopiuj adres URL obrazu',
37
+ * few: 'Kopiuj adresy URL {count} obrazów',
38
+ * many: 'Kopiuj adresy URL {count} obrazów',
39
+ * other: 'Kopiuj adresy URL {count} obrazu',
40
+ * }
41
+ */
42
+ export interface SelectionMenuPluralLabels {
43
+ /**
44
+ * Required base form. Any category left `undefined` falls back to `other`,
45
+ * so the menu never shows the English default once `pluralLabels` is set.
46
+ */
47
+ other: string;
48
+ zero?: string;
49
+ one?: string;
50
+ two?: string;
51
+ few?: string;
52
+ many?: string;
53
+ }
54
+
55
+ /**
56
+ * Controls the built-in items added to the native text selection menu and
57
+ * lets you localize their labels.
58
+ *
59
+ * Each item accepts an object: `{ enabled }` toggles visibility (the system
60
+ * `copy` item can't be hidden — only relabeled) and `label` overrides the
61
+ * English default. Wire `label` to your i18n library to match the rest of your
62
+ * app's UI. Labels apply to the main text selection menu as well as the table
63
+ * and math block copy menus.
64
+ *
65
+ * @platform ios, android, macos
66
+ */
23
67
  export interface SelectionMenuConfig {
24
68
  /**
25
- * Shows the built-in "Copy as Markdown" action for text selections.
26
- * @default true
69
+ * The system "Copy" item. It can't be hidden — only its label is configurable.
70
+ * @default { label: "Copy" }
27
71
  */
28
- copyAsMarkdown?: boolean;
72
+ copy?: { label?: string };
29
73
  /**
30
- * Shows the built-in "Copy Image URL" action when selected content contains images.
31
- * @default true
74
+ * The built-in "Copy as Markdown" action for text selections.
75
+ * @default { enabled: true, label: "Copy as Markdown" }
76
+ */
77
+ copyAsMarkdown?: { enabled?: boolean; label?: string };
78
+ /**
79
+ * The built-in "Copy Image URL" action, shown when the selection contains
80
+ * images. `label` is used for a single image; `pluralLabels` provides the
81
+ * forms for multiple images.
82
+ * @default { enabled: true, label: "Copy Image URL" }
32
83
  */
33
- copyImageUrl?: boolean;
84
+ copyImageUrl?: {
85
+ enabled?: boolean;
86
+ label?: string;
87
+ pluralLabels?: SelectionMenuPluralLabels;
88
+ };
34
89
  }
35
90
 
36
91
  export interface StreamingConfig {
@@ -200,12 +255,22 @@ export interface EnrichedMarkdownTextProps extends Omit<ViewProps, 'style'> {
200
255
  */
201
256
  contextMenuItems?: ContextMenuItem[];
202
257
  /**
203
- * Controls built-in items added to the native text selection menu.
204
- * Custom app-provided actions are controlled separately with `contextMenuItems`.
205
- * @default { copyAsMarkdown: true, copyImageUrl: true }
258
+ * Controls the built-in items added to the native text selection menu and
259
+ * lets you localize their labels. Custom app-provided actions are controlled
260
+ * separately with `contextMenuItems`.
261
+ * @default { copyAsMarkdown: { enabled: true }, copyImageUrl: { enabled: true } }
206
262
  * @platform ios, android, macos
207
263
  */
208
264
  selectionMenuConfig?: SelectionMenuConfig;
265
+ /**
266
+ * Translations for VoiceOver / TalkBack announcements (list items, table
267
+ * rows, math, and the iOS rotor). All keys are optional and fall back to
268
+ * the English defaults from `accessibilityLabelDefaults.ts` — see
269
+ * `AccessibilityLabels` for the placeholder syntax and the no-plural
270
+ * rationale.
271
+ * @platform ios, android
272
+ */
273
+ accessibilityLabels?: AccessibilityLabels;
209
274
  /**
210
275
  * Sets the text direction on the root container.
211
276
  * Useful for RTL languages — CSS logical properties in the renderers
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- import { withGradleProperties } from '@expo/config-plugins';
4
- export const withAndroidMath = (config, {
5
- enableMath = true
6
- }) => {
7
- if (enableMath) {
8
- return config;
9
- }
10
- return withGradleProperties(config, gradleConfig => {
11
- gradleConfig.modResults = gradleConfig.modResults.filter(prop => prop.type !== 'property' || prop.key !== 'enrichedMarkdown.enableMath');
12
- gradleConfig.modResults.push({
13
- type: 'property',
14
- key: 'enrichedMarkdown.enableMath',
15
- value: 'false'
16
- });
17
- return gradleConfig;
18
- });
19
- };
20
- //# sourceMappingURL=withAndroidMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["withGradleProperties","withAndroidMath","config","enableMath","gradleConfig","modResults","filter","prop","type","key","push","value"],"sourceRoot":"../../../src","sources":["plugin/withAndroidMath.ts"],"mappings":";;AAAA,SAASA,oBAAoB,QAA2B,sBAAsB;AAE9E,OAAO,MAAMC,eAAuD,GAAGA,CACrEC,MAAM,EACN;EAAEC,UAAU,GAAG;AAAK,CAAC,KAClB;EACH,IAAIA,UAAU,EAAE;IACd,OAAOD,MAAM;EACf;EACA,OAAOF,oBAAoB,CAACE,MAAM,EAAGE,YAAY,IAAK;IACpDA,YAAY,CAACC,UAAU,GAAGD,YAAY,CAACC,UAAU,CAACC,MAAM,CACrDC,IAAI,IACHA,IAAI,CAACC,IAAI,KAAK,UAAU,IAAID,IAAI,CAACE,GAAG,KAAK,6BAC7C,CAAC;IAEDL,YAAY,CAACC,UAAU,CAACK,IAAI,CAAC;MAC3BF,IAAI,EAAE,UAAU;MAChBC,GAAG,EAAE,6BAA6B;MAClCE,KAAK,EAAE;IACT,CAAC,CAAC;IAEF,OAAOP,YAAY;EACrB,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- import { withDangerousMod } from '@expo/config-plugins';
4
- import fs from 'fs';
5
- import path from 'path';
6
- const IOS_MATH_OPTION = "ENV['ENRICHED_MARKDOWN_ENABLE_MATH'] = '0'";
7
- export const withIosMath = (config, {
8
- enableMath = true
9
- }) => {
10
- if (enableMath) {
11
- return config;
12
- }
13
- return withDangerousMod(config, ['ios', async modConfig => {
14
- const file = path.join(modConfig.modRequest.platformProjectRoot, 'Podfile');
15
- const contents = fs.readFileSync(file, 'utf8');
16
- const lines = contents.split('\n');
17
- const filteredLines = lines.filter(line => !line.includes('ENRICHED_MARKDOWN_ENABLE_MATH'));
18
- filteredLines.unshift(IOS_MATH_OPTION);
19
- fs.writeFileSync(file, filteredLines.join('\n'));
20
- return modConfig;
21
- }]);
22
- };
23
- //# sourceMappingURL=withIosMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["withDangerousMod","fs","path","IOS_MATH_OPTION","withIosMath","config","enableMath","modConfig","file","join","modRequest","platformProjectRoot","contents","readFileSync","lines","split","filteredLines","filter","line","includes","unshift","writeFileSync"],"sourceRoot":"../../../src","sources":["plugin/withIosMath.ts"],"mappings":";;AAAA,SAASA,gBAAgB,QAA2B,sBAAsB;AAC1E,OAAOC,EAAE,MAAM,IAAI;AACnB,OAAOC,IAAI,MAAM,MAAM;AAEvB,MAAMC,eAAe,GAAG,4CAA4C;AAEpE,OAAO,MAAMC,WAAmD,GAAGA,CACjEC,MAAM,EACN;EAAEC,UAAU,GAAG;AAAK,CAAC,KAClB;EACH,IAAIA,UAAU,EAAE;IACd,OAAOD,MAAM;EACf;EACA,OAAOL,gBAAgB,CAACK,MAAM,EAAE,CAC9B,KAAK,EACL,MAAOE,SAAS,IAAK;IACnB,MAAMC,IAAI,GAAGN,IAAI,CAACO,IAAI,CACpBF,SAAS,CAACG,UAAU,CAACC,mBAAmB,EACxC,SACF,CAAC;IACD,MAAMC,QAAQ,GAAGX,EAAE,CAACY,YAAY,CAACL,IAAI,EAAE,MAAM,CAAC;IAE9C,MAAMM,KAAK,GAAGF,QAAQ,CAACG,KAAK,CAAC,IAAI,CAAC;IAClC,MAAMC,aAAa,GAAGF,KAAK,CAACG,MAAM,CAC/BC,IAAY,IAAK,CAACA,IAAI,CAACC,QAAQ,CAAC,+BAA+B,CAClE,CAAC;IAEDH,aAAa,CAACI,OAAO,CAACjB,eAAe,CAAC;IAEtCF,EAAE,CAACoB,aAAa,CAACb,IAAI,EAAEQ,aAAa,CAACP,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhD,OAAOF,SAAS;EAClB,CAAC,CACF,CAAC;AACJ,CAAC","ignoreList":[]}
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- import { withIosMath } from "./withIosMath.js";
4
- import { withAndroidMath } from "./withAndroidMath.js";
5
- const withEnrichedMarkdown = (config, props) => {
6
- const enableMath = props?.enableMath !== false;
7
- config = withAndroidMath(config, {
8
- enableMath
9
- });
10
- config = withIosMath(config, {
11
- enableMath
12
- });
13
- return config;
14
- };
15
- export default withEnrichedMarkdown;
16
- //# sourceMappingURL=withReactNativeEnrichedMarkdown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["withIosMath","withAndroidMath","withEnrichedMarkdown","config","props","enableMath"],"sourceRoot":"../../../src","sources":["plugin/withReactNativeEnrichedMarkdown.ts"],"mappings":";;AACA,SAASA,WAAW,QAAQ,kBAAe;AAC3C,SAASC,eAAe,QAAQ,sBAAmB;AAEnD,MAAMC,oBAAmE,GAAGA,CAC1EC,MAAM,EACNC,KAAK,KACF;EACH,MAAMC,UAAU,GAAGD,KAAK,EAAEC,UAAU,KAAK,KAAK;EAE9CF,MAAM,GAAGF,eAAe,CAACE,MAAM,EAAE;IAAEE;EAAW,CAAC,CAAC;EAChDF,MAAM,GAAGH,WAAW,CAACG,MAAM,EAAE;IAAEE;EAAW,CAAC,CAAC;EAE5C,OAAOF,MAAM;AACf,CAAC;AAED,eAAeD,oBAAoB","ignoreList":[]}
@@ -1,5 +0,0 @@
1
- import { type ConfigPlugin } from '@expo/config-plugins';
2
- export declare const withAndroidMath: ConfigPlugin<{
3
- enableMath?: boolean;
4
- }>;
5
- //# sourceMappingURL=withAndroidMath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withAndroidMath.d.ts","sourceRoot":"","sources":["../../../../src/plugin/withAndroidMath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE/E,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAqBlE,CAAC"}
@@ -1,5 +0,0 @@
1
- import { type ConfigPlugin } from '@expo/config-plugins';
2
- export declare const withIosMath: ConfigPlugin<{
3
- enableMath?: boolean;
4
- }>;
5
- //# sourceMappingURL=withIosMath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withIosMath.d.ts","sourceRoot":"","sources":["../../../../src/plugin/withIosMath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAM3E,eAAO,MAAM,WAAW,EAAE,YAAY,CAAC;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CA4B9D,CAAC"}
@@ -1,6 +0,0 @@
1
- import { type ConfigPlugin } from '@expo/config-plugins';
2
- declare const withEnrichedMarkdown: ConfigPlugin<{
3
- enableMath?: boolean;
4
- } | void>;
5
- export default withEnrichedMarkdown;
6
- //# sourceMappingURL=withReactNativeEnrichedMarkdown.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withReactNativeEnrichedMarkdown.d.ts","sourceRoot":"","sources":["../../../../src/plugin/withReactNativeEnrichedMarkdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,QAAA,MAAM,oBAAoB,EAAE,YAAY,CAAC;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAUvE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
File without changes
File without changes