react-native-enriched-markdown-scaffold 1.0.2-scaffold.4 → 1.0.2-scaffold.5

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 (68) hide show
  1. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +12 -0
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +2 -0
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +12 -0
  4. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +2 -0
  5. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +74 -0
  6. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +68 -0
  7. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +10 -0
  8. package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +2 -0
  9. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +107 -0
  10. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +19 -0
  11. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +14 -0
  12. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +48 -0
  13. package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +14 -0
  14. package/android/src/main/java/com/swmansion/enriched/markdown/events/SelectionChangeEvent.kt +42 -0
  15. package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +14 -0
  16. package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/SelectionChangeReporter.kt +230 -0
  17. package/android/src/main/java/com/swmansion/enriched/markdown/views/CodeBlockContainerView.kt +11 -1
  18. package/android/src/main/java/com/swmansion/enriched/markdown/views/TableContainerView.kt +8 -1
  19. package/android/src/math/java/com/swmansion/enriched/markdown/views/MathContainerView.kt +8 -1
  20. package/docs/API_REFERENCE.md +58 -0
  21. package/ios/EnrichedMarkdown.mm +174 -2
  22. package/ios/EnrichedMarkdownText.mm +103 -1
  23. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +74 -0
  24. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +68 -0
  25. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +10 -0
  26. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +2 -0
  27. package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/RCTComponentViewHelpers.h +50 -2
  28. package/ios/utils/ENRMLinkChip.m +14 -14
  29. package/ios/utils/ENRMLinkLayout.m +12 -12
  30. package/ios/utils/ENRMSelectionChange.h +96 -0
  31. package/ios/utils/ENRMSelectionChange.m +204 -0
  32. package/ios/utils/EditMenuUtils+macOS.m +1 -1
  33. package/ios/utils/MarkdownAccessibilityElementBuilder.m +1 -2
  34. package/ios/views/ENRMCodeBlockContainerView.h +3 -0
  35. package/ios/views/ENRMCodeBlockContainerView.m +3 -0
  36. package/ios/views/ENRMMathContainerView.h +3 -0
  37. package/ios/views/ENRMMathContainerView.m +3 -0
  38. package/ios/views/TableContainerView.h +3 -0
  39. package/ios/views/TableContainerView.m +4 -1
  40. package/lib/module/EnrichedMarkdownNativeComponent.ts +60 -1
  41. package/lib/module/EnrichedMarkdownTextNativeComponent.ts +60 -1
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/jest/index.js +13 -0
  44. package/lib/module/jest/index.js.map +1 -1
  45. package/lib/module/native/EnrichedMarkdownText.js +44 -4
  46. package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
  47. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +53 -2
  48. package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
  49. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +53 -2
  50. package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
  51. package/lib/typescript/src/index.d.ts +2 -2
  52. package/lib/typescript/src/index.d.ts.map +1 -1
  53. package/lib/typescript/src/jest/index.d.ts +1 -1
  54. package/lib/typescript/src/jest/index.d.ts.map +1 -1
  55. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +5 -5
  56. package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
  57. package/lib/typescript/src/types/MarkdownTextProps.d.ts +36 -3
  58. package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
  59. package/lib/typescript/src/types/events.d.ts +36 -0
  60. package/lib/typescript/src/types/events.d.ts.map +1 -1
  61. package/package.json +1 -1
  62. package/src/EnrichedMarkdownNativeComponent.ts +60 -1
  63. package/src/EnrichedMarkdownTextNativeComponent.ts +60 -1
  64. package/src/index.tsx +3 -0
  65. package/src/jest/index.tsx +21 -1
  66. package/src/native/EnrichedMarkdownText.tsx +85 -9
  67. package/src/types/MarkdownTextProps.ts +43 -2
  68. package/src/types/events.ts +38 -0
@@ -1,5 +1,11 @@
1
- import type { ReactNode } from 'react';
2
- import type { ColorValue, ViewProps, ViewStyle, TextStyle } from 'react-native';
1
+ import type { ReactNode, RefObject } from 'react';
2
+ import type {
3
+ ColorValue,
4
+ HostInstance,
5
+ ViewProps,
6
+ ViewStyle,
7
+ TextStyle,
8
+ } from 'react-native';
3
9
  import type { MarkdownStyle, Md4cFlags } from './MarkdownStyle';
4
10
  import type { AccessibilityLabels } from './AccessibilityLabels';
5
11
  import type {
@@ -8,8 +14,22 @@ import type {
8
14
  TaskListItemPressEvent,
9
15
  CopyPressEvent,
10
16
  CopyEvent,
17
+ SelectionChangeEvent,
11
18
  } from './events';
12
19
 
20
+ /** Imperative handle of `EnrichedMarkdownText`, reached through its `ref`. */
21
+ export interface EnrichedMarkdownTextInstance {
22
+ /**
23
+ * Clears the text selection (and any long-pressed block) and fires
24
+ * `onSelectionChange` with `active: false`.
25
+ * @platform ios, android
26
+ */
27
+ clearSelection: () => void;
28
+ measure: HostInstance['measure'];
29
+ measureInWindow: HostInstance['measureInWindow'];
30
+ measureLayout: HostInstance['measureLayout'];
31
+ }
32
+
13
33
  /**
14
34
  * A rect in dp, relative to the component's content box (inside any
15
35
  * `containerStyle` padding).
@@ -169,6 +189,11 @@ export interface StreamingConfig {
169
189
  }
170
190
 
171
191
  export interface EnrichedMarkdownTextProps extends Omit<ViewProps, 'style'> {
192
+ /**
193
+ * Imperative handle: `clearSelection()` plus the host `measure*` methods.
194
+ * @platform ios, android
195
+ */
196
+ ref?: RefObject<EnrichedMarkdownTextInstance | null>;
172
197
  /**
173
198
  * Markdown content to render.
174
199
  * @platform ios, android, web
@@ -269,6 +294,22 @@ export interface EnrichedMarkdownTextProps extends Omit<ViewProps, 'style'> {
269
294
  * @platform ios, android
270
295
  */
271
296
  onCopy?: (event: CopyEvent) => void;
297
+ /**
298
+ * Reports the text selection so the app can draw its own menu (pair it with
299
+ * `contextMenuHidden`). Fires at most once per frame while the selection
300
+ * changes, and with `active: false` once it is gone. With
301
+ * `contextMenuHidden`, a long press on a table / math / code block fires it
302
+ * too (`source` is the block kind, `whole: true`), since those blocks have no
303
+ * text selection of their own. Only one part of a component holds a
304
+ * selection at a time; clearing the selection of *other* components is up to
305
+ * the app (`ref.current.clearSelection()`).
306
+ *
307
+ * Rects are relative to the view that `ref.current.measureInWindow`
308
+ * measures — add that origin to position UI on screen. There is no
309
+ * "dragging" flag: debounce before showing a menu.
310
+ * @platform ios, android
311
+ */
312
+ onSelectionChange?: (event: SelectionChangeEvent) => void;
272
313
  /**
273
314
  * Controls whether the system link preview is shown on long press (iOS only).
274
315
  *
@@ -40,6 +40,44 @@ export interface CopyEvent {
40
40
  whole: boolean;
41
41
  }
42
42
 
43
+ /**
44
+ * A rect in dp, relative to the component's native view: add the origin from
45
+ * the component ref's `measureInWindow` to get window coordinates.
46
+ */
47
+ export interface SelectionRect {
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ }
53
+
54
+ /**
55
+ * Payload of `onSelectionChange`: the current text selection, or a table /
56
+ * math / code block long-pressed while `contextMenuHidden` is on. Content
57
+ * fields carry what `onCopy` would receive for the same selection.
58
+ */
59
+ export interface SelectionChangeEvent {
60
+ /** `false` once the selection is gone; every other field is then empty / zero. */
61
+ active: boolean;
62
+ /** `'selection'` for text; the block kind for a long-pressed block. */
63
+ source: CopyEvent['source'];
64
+ /** Rendered text of the selection, or the block's raw content. */
65
+ text: string;
66
+ /** Same as `CopyEvent.markdown` for this selection. */
67
+ markdown: string;
68
+ /** Same as `CopyEvent.whole`. Always `true` for blocks. */
69
+ whole: boolean;
70
+ /**
71
+ * Bounding box of the selection (full content width when it spans several
72
+ * lines); the block's frame for blocks.
73
+ */
74
+ rect: SelectionRect;
75
+ /** Selected part of the first line (block: same as `rect`). */
76
+ startRect: SelectionRect;
77
+ /** Selected part of the last line (block: same as `rect`). */
78
+ endRect: SelectionRect;
79
+ }
80
+
43
81
  /**
44
82
  * Native-level context menu item config sent to the native component.
45
83
  * Does not include the `onPress` callback — callbacks are managed on the JS side.