react-native-enriched-markdown-scaffold 1.0.2-scaffold.3 → 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.
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerDelegate.java +15 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownManagerInterface.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerDelegate.java +15 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedMarkdownTextManagerInterface.java +3 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.cpp +122 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h +100 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.cpp +20 -0
- package/android/generated/jni/react/renderer/components/EnrichedMarkdownTextSpec/Props.h +124 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdown.kt +145 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownInternalText.kt +19 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownManager.kt +22 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt +85 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownTextManager.kt +22 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/LinkLayoutEvent.kt +36 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/events/SelectionChangeEvent.kt +42 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/LinkRenderer.kt +37 -7
- package/android/src/main/java/com/swmansion/enriched/markdown/renderer/SpanStyleCache.kt +5 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/CodeBackgroundSpan.kt +13 -99
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/InlineChipPainter.kt +140 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkChipSpans.kt +177 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/spans/LinkSpan.kt +1 -6
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkStyle.kt +36 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/styles/LinkVariantEntry.kt +7 -3
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt +28 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/HTMLGenerator.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/conversion/MarkdownExtractor.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/LinkLayoutCollector.kt +100 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/SelectionActionMode.kt +4 -2
- package/android/src/main/java/com/swmansion/enriched/markdown/utils/text/view/SelectionChangeReporter.kt +230 -0
- package/android/src/main/java/com/swmansion/enriched/markdown/views/CodeBlockContainerView.kt +11 -1
- package/android/src/main/java/com/swmansion/enriched/markdown/views/TableContainerView.kt +22 -1
- package/android/src/math/java/com/swmansion/enriched/markdown/views/MathContainerView.kt +8 -1
- package/docs/API_REFERENCE.md +111 -0
- package/docs/MENTIONS.md +8 -1
- package/docs/STYLES.md +27 -0
- package/docs/TEXT.md +2 -0
- package/ios/EnrichedMarkdown.mm +221 -1
- package/ios/EnrichedMarkdownText.mm +142 -1
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.cpp +122 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/EventEmitters.h +100 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.cpp +20 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/Props.h +124 -0
- package/ios/generated/ReactCodegen/EnrichedMarkdownTextSpec/RCTComponentViewHelpers.h +50 -2
- package/ios/internals/MeasurementCache.h +5 -0
- package/ios/renderer/LinkRenderer.m +47 -15
- package/ios/styles/StyleConfig.h +16 -0
- package/ios/styles/StyleConfig.mm +60 -0
- package/ios/utils/CodeBackground.m +3 -65
- package/ios/utils/ENRMChipDrawing.h +24 -0
- package/ios/utils/ENRMChipDrawing.m +83 -0
- package/ios/utils/ENRMLinkChip.h +70 -0
- package/ios/utils/ENRMLinkChip.m +194 -0
- package/ios/utils/ENRMLinkLayout.h +50 -0
- package/ios/utils/ENRMLinkLayout.m +45 -0
- package/ios/utils/ENRMSelectionChange.h +96 -0
- package/ios/utils/ENRMSelectionChange.m +204 -0
- package/ios/utils/EditMenuUtils+macOS.m +4 -1
- package/ios/utils/EditMenuUtils.m +4 -1
- package/ios/utils/HTMLGenerator.m +2 -1
- package/ios/utils/MarkdownAccessibilityElementBuilder.m +3 -1
- package/ios/utils/MarkdownExtractor.m +2 -1
- package/ios/utils/RTFExportUtils.m +2 -0
- package/ios/utils/StylePropsUtils.h +37 -1
- package/ios/utils/TextViewLayoutManager.mm +3 -0
- package/ios/views/ENRMCodeBlockContainerView.h +3 -0
- package/ios/views/ENRMCodeBlockContainerView.m +3 -0
- package/ios/views/ENRMMathContainerView.h +3 -0
- package/ios/views/ENRMMathContainerView.m +3 -0
- package/ios/views/TableContainerView.h +6 -0
- package/ios/views/TableContainerView.m +24 -0
- package/lib/module/EnrichedMarkdownNativeComponent.ts +101 -1
- package/lib/module/EnrichedMarkdownTextNativeComponent.ts +101 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +13 -0
- package/lib/module/jest/index.js.map +1 -1
- package/lib/module/native/EnrichedMarkdownText.js +138 -9
- package/lib/module/native/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.js +13 -2
- package/lib/module/normalizeMarkdownStyle.js.map +1 -1
- package/lib/module/normalizeMarkdownStyle.web.js +13 -2
- package/lib/module/normalizeMarkdownStyle.web.js.map +1 -1
- package/lib/module/web/EnrichedMarkdownText.js +6 -3
- package/lib/module/web/EnrichedMarkdownText.js.map +1 -1
- package/lib/module/web/renderers/InlineRenderers.js +96 -3
- package/lib/module/web/renderers/InlineRenderers.js.map +1 -1
- package/lib/module/web/styles.js +18 -0
- package/lib/module/web/styles.js.map +1 -1
- package/lib/module/web/utils.js +13 -0
- package/lib/module/web/utils.js.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts +93 -2
- package/lib/typescript/src/EnrichedMarkdownNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts +93 -2
- package/lib/typescript/src/EnrichedMarkdownTextNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +1 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/lib/typescript/src/jest/index.d.ts +1 -1
- package/lib/typescript/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts +5 -5
- package/lib/typescript/src/native/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/normalizeMarkdownStyle.web.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyle.d.ts +28 -5
- package/lib/typescript/src/types/MarkdownStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts +10 -0
- package/lib/typescript/src/types/MarkdownStyleInternal.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.d.ts +76 -2
- package/lib/typescript/src/types/MarkdownTextProps.d.ts.map +1 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts +41 -1
- package/lib/typescript/src/types/MarkdownTextProps.web.d.ts.map +1 -1
- package/lib/typescript/src/types/events.d.ts +36 -0
- package/lib/typescript/src/types/events.d.ts.map +1 -1
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts +1 -1
- package/lib/typescript/src/web/EnrichedMarkdownText.d.ts.map +1 -1
- package/lib/typescript/src/web/renderers/InlineRenderers.d.ts.map +1 -1
- package/lib/typescript/src/web/styles.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +4 -0
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/lib/typescript/src/web/utils.d.ts +4 -0
- package/lib/typescript/src/web/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/EnrichedMarkdownNativeComponent.ts +101 -1
- package/src/EnrichedMarkdownTextNativeComponent.ts +101 -1
- package/src/index.tsx +5 -0
- package/src/index.web.tsx +5 -1
- package/src/jest/index.tsx +21 -1
- package/src/native/EnrichedMarkdownText.tsx +181 -8
- package/src/normalizeMarkdownStyle.ts +13 -0
- package/src/normalizeMarkdownStyle.web.ts +11 -0
- package/src/types/MarkdownStyle.ts +29 -5
- package/src/types/MarkdownStyleInternal.ts +10 -0
- package/src/types/MarkdownTextProps.ts +85 -1
- package/src/types/MarkdownTextProps.web.ts +43 -1
- package/src/types/events.ts +38 -0
- package/src/web/EnrichedMarkdownText.tsx +10 -3
- package/src/web/renderers/InlineRenderers.tsx +111 -3
- package/src/web/styles.ts +25 -0
- package/src/web/types.ts +4 -0
- package/src/web/utils.ts +8 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import "TableContainerView.h"
|
|
2
2
|
#import "AttributedRenderer.h"
|
|
3
3
|
#import "ENRMAccessibilityLabels.h"
|
|
4
|
+
#import "ENRMLinkChip.h"
|
|
4
5
|
#import "HTMLGenerator.h"
|
|
5
6
|
#import "LinkTapUtils.h"
|
|
6
7
|
#import "MarkdownASTNode.h"
|
|
@@ -90,6 +91,8 @@ static NSMutableAttributedString *ENRMTableRenderCellNode(MarkdownASTNode *cellN
|
|
|
90
91
|
NSMutableAttributedString *attributedText = [renderer renderRoot:temporaryRoot context:context];
|
|
91
92
|
|
|
92
93
|
[context applyLinkAttributesToString:attributedText];
|
|
94
|
+
// Cells draw with -drawWithRect:, which bypasses the layout manager that paints link chips.
|
|
95
|
+
ENRMApplyLinkChipBackgroundsAsTextBackground(attributedText);
|
|
93
96
|
|
|
94
97
|
ENRMApplyWritingDirectionMode(attributedText, writingDirectionMode, resolvedLayoutDirection);
|
|
95
98
|
|
|
@@ -302,6 +305,24 @@ static void ENRMTableComputeLayout(NSArray<NSArray<TableCellData *> *> *rows, NS
|
|
|
302
305
|
return _rows.count;
|
|
303
306
|
}
|
|
304
307
|
|
|
308
|
+
- (NSInteger)linkCount
|
|
309
|
+
{
|
|
310
|
+
__block NSInteger count = 0;
|
|
311
|
+
for (NSArray<TableCellData *> *row in _rows) {
|
|
312
|
+
for (TableCellData *cell in row) {
|
|
313
|
+
// LinkRenderer attaches one ENRMLinkChip instance per link.
|
|
314
|
+
[cell.attributedText enumerateAttribute:ENRMLinkChipAttributeName
|
|
315
|
+
inRange:NSMakeRange(0, cell.attributedText.length)
|
|
316
|
+
options:0
|
|
317
|
+
usingBlock:^(id chip, NSRange range, BOOL *stop) {
|
|
318
|
+
if (chip)
|
|
319
|
+
count++;
|
|
320
|
+
}];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return count;
|
|
324
|
+
}
|
|
325
|
+
|
|
305
326
|
#if !TARGET_OS_OSX
|
|
306
327
|
- (void)animateNewRowsFromPreviousCount:(NSUInteger)previousRowCount duration:(NSTimeInterval)duration
|
|
307
328
|
{
|
|
@@ -465,6 +486,9 @@ static void ENRMTableComputeLayout(NSArray<NSArray<TableCellData *> *> *rows, NS
|
|
|
465
486
|
{
|
|
466
487
|
// Returning nil is the UIKit-sanctioned way to suppress a context menu.
|
|
467
488
|
if (self.contextMenuHidden) {
|
|
489
|
+
if (self.onMenuSuppressed) {
|
|
490
|
+
self.onMenuSuppressed(_cachedMarkdown ?: @"", [self buildPlainTextFromRows] ?: @"");
|
|
491
|
+
}
|
|
468
492
|
return nil;
|
|
469
493
|
}
|
|
470
494
|
__weak __typeof(self) weakSelf = self;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
codegenNativeComponent,
|
|
3
|
+
codegenNativeCommands,
|
|
3
4
|
type ViewProps,
|
|
4
5
|
type CodegenTypes,
|
|
5
6
|
type ColorValue,
|
|
7
|
+
type HostComponent,
|
|
6
8
|
} from 'react-native';
|
|
9
|
+
import type React from 'react';
|
|
7
10
|
|
|
8
11
|
// All block styles extend this interface
|
|
9
12
|
interface BaseBlockStyleInternal {
|
|
@@ -75,6 +78,11 @@ interface LinkStyleInternal {
|
|
|
75
78
|
color: ColorValue;
|
|
76
79
|
underline: boolean;
|
|
77
80
|
backgroundColor: ColorValue;
|
|
81
|
+
borderRadius: CodegenTypes.Float;
|
|
82
|
+
paddingHorizontal: CodegenTypes.Float;
|
|
83
|
+
paddingVertical: CodegenTypes.Float;
|
|
84
|
+
borderColor: ColorValue;
|
|
85
|
+
borderWidth: CodegenTypes.Float;
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
// Mirrors EnrichedMarkdownTextNativeComponent.ts — kept in sync manually (codegen spec files must be self-contained).
|
|
@@ -83,6 +91,11 @@ interface LinkVariantEntryInternal {
|
|
|
83
91
|
color: ColorValue;
|
|
84
92
|
underline: boolean;
|
|
85
93
|
backgroundColor: ColorValue;
|
|
94
|
+
borderRadius: CodegenTypes.Float;
|
|
95
|
+
paddingHorizontal: CodegenTypes.Float;
|
|
96
|
+
paddingVertical: CodegenTypes.Float;
|
|
97
|
+
borderColor: ColorValue;
|
|
98
|
+
borderWidth: CodegenTypes.Float;
|
|
86
99
|
}
|
|
87
100
|
|
|
88
101
|
interface StrongStyleInternal {
|
|
@@ -245,6 +258,58 @@ export interface LinkLongPressEvent {
|
|
|
245
258
|
url: string;
|
|
246
259
|
}
|
|
247
260
|
|
|
261
|
+
/**
|
|
262
|
+
* `fragments` holds one entry per laid-out line of a link (a wrapping link
|
|
263
|
+
* yields several). Rects are in dp, relative to the native view's origin, and
|
|
264
|
+
* cover the drawn chip (glyphs + padding). Flattened rather than nested per
|
|
265
|
+
* link, and written inline, because codegen only accepts inline object
|
|
266
|
+
* literals as event array elements.
|
|
267
|
+
*/
|
|
268
|
+
export interface LinkLayoutEvent {
|
|
269
|
+
fragments: {
|
|
270
|
+
linkIndex: CodegenTypes.Int32;
|
|
271
|
+
url: string;
|
|
272
|
+
text: string;
|
|
273
|
+
x: CodegenTypes.Double;
|
|
274
|
+
y: CodegenTypes.Double;
|
|
275
|
+
width: CodegenTypes.Double;
|
|
276
|
+
height: CodegenTypes.Double;
|
|
277
|
+
}[];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Current text selection, or a long-pressed table / math / code block while
|
|
282
|
+
* `contextMenuHidden` is on. `active: false` means the selection was cleared
|
|
283
|
+
* (every other field is then empty / zero). Rects are in dp / pt, relative to
|
|
284
|
+
* the native view's origin; rect objects are written inline because codegen
|
|
285
|
+
* only accepts inline object literals in event payloads.
|
|
286
|
+
*/
|
|
287
|
+
export interface SelectionChangeEvent {
|
|
288
|
+
active: boolean;
|
|
289
|
+
source: string;
|
|
290
|
+
text: string;
|
|
291
|
+
markdown: string;
|
|
292
|
+
whole: boolean;
|
|
293
|
+
rect: {
|
|
294
|
+
x: CodegenTypes.Double;
|
|
295
|
+
y: CodegenTypes.Double;
|
|
296
|
+
width: CodegenTypes.Double;
|
|
297
|
+
height: CodegenTypes.Double;
|
|
298
|
+
};
|
|
299
|
+
startRect: {
|
|
300
|
+
x: CodegenTypes.Double;
|
|
301
|
+
y: CodegenTypes.Double;
|
|
302
|
+
width: CodegenTypes.Double;
|
|
303
|
+
height: CodegenTypes.Double;
|
|
304
|
+
};
|
|
305
|
+
endRect: {
|
|
306
|
+
x: CodegenTypes.Double;
|
|
307
|
+
y: CodegenTypes.Double;
|
|
308
|
+
width: CodegenTypes.Double;
|
|
309
|
+
height: CodegenTypes.Double;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
248
313
|
export interface TaskListItemPressEvent {
|
|
249
314
|
index: CodegenTypes.Int32;
|
|
250
315
|
checked: boolean;
|
|
@@ -400,6 +465,30 @@ export interface NativeProps extends ViewProps {
|
|
|
400
465
|
* - Android: Handles long press gestures on links.
|
|
401
466
|
*/
|
|
402
467
|
onLinkLongPress?: CodegenTypes.BubblingEventHandler<LinkLongPressEvent>;
|
|
468
|
+
/**
|
|
469
|
+
* When true, the view reports the laid-out rects of every link through
|
|
470
|
+
* `onLinkLayout` (after each render and whenever its size changes).
|
|
471
|
+
* Set by the JS wrapper only when `renderLinkDecoration` is provided.
|
|
472
|
+
* @default false
|
|
473
|
+
*/
|
|
474
|
+
emitLinkLayout?: CodegenTypes.WithDefault<boolean, false>;
|
|
475
|
+
/**
|
|
476
|
+
* Fired with the rects of every link fragment while `emitLinkLayout` is on.
|
|
477
|
+
* Deduplicated: not re-fired when the payload is unchanged.
|
|
478
|
+
*/
|
|
479
|
+
onLinkLayout?: CodegenTypes.DirectEventHandler<LinkLayoutEvent>;
|
|
480
|
+
/**
|
|
481
|
+
* When true, the view reports selection changes (and, with
|
|
482
|
+
* `contextMenuHidden`, block long-presses) through `onSelectionChange`.
|
|
483
|
+
* Set by the JS wrapper only when `onSelectionChange` is provided.
|
|
484
|
+
* @default false
|
|
485
|
+
*/
|
|
486
|
+
emitSelectionChange?: CodegenTypes.WithDefault<boolean, false>;
|
|
487
|
+
/**
|
|
488
|
+
* Fired while `emitSelectionChange` is on: coalesced to one event per frame,
|
|
489
|
+
* deduplicated, and `active: false` once the selection is gone.
|
|
490
|
+
*/
|
|
491
|
+
onSelectionChange?: CodegenTypes.DirectEventHandler<SelectionChangeEvent>;
|
|
403
492
|
/**
|
|
404
493
|
* Callback fired when a task list checkbox is tapped.
|
|
405
494
|
* Receives the 0-based task index, current checked state, and the item's plain text.
|
|
@@ -553,6 +642,17 @@ export interface NativeProps extends ViewProps {
|
|
|
553
642
|
writingDirection?: CodegenTypes.WithDefault<string, 'first-strong'>;
|
|
554
643
|
}
|
|
555
644
|
|
|
645
|
+
type ComponentType = HostComponent<NativeProps>;
|
|
646
|
+
|
|
647
|
+
interface NativeCommands {
|
|
648
|
+
/** Clears the text selection (and any active block) and fires `onSelectionChange` with `active: false`. */
|
|
649
|
+
clearSelection: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
653
|
+
supportedCommands: ['clearSelection'],
|
|
654
|
+
});
|
|
655
|
+
|
|
556
656
|
export default codegenNativeComponent<NativeProps>('EnrichedMarkdown', {
|
|
557
657
|
interfaceOnly: true,
|
|
558
|
-
})
|
|
658
|
+
}) as HostComponent<NativeProps>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
codegenNativeComponent,
|
|
3
|
+
codegenNativeCommands,
|
|
3
4
|
type ViewProps,
|
|
4
5
|
type CodegenTypes,
|
|
5
6
|
type ColorValue,
|
|
7
|
+
type HostComponent,
|
|
6
8
|
} from 'react-native';
|
|
9
|
+
import type React from 'react';
|
|
7
10
|
|
|
8
11
|
// All block styles extend this interface
|
|
9
12
|
interface BaseBlockStyleInternal {
|
|
@@ -75,6 +78,11 @@ interface LinkStyleInternal {
|
|
|
75
78
|
color: ColorValue;
|
|
76
79
|
underline: boolean;
|
|
77
80
|
backgroundColor: ColorValue;
|
|
81
|
+
borderRadius: CodegenTypes.Float;
|
|
82
|
+
paddingHorizontal: CodegenTypes.Float;
|
|
83
|
+
paddingVertical: CodegenTypes.Float;
|
|
84
|
+
borderColor: ColorValue;
|
|
85
|
+
borderWidth: CodegenTypes.Float;
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
// Mirrors EnrichedMarkdownNativeComponent.ts — kept in sync manually (codegen spec files must be self-contained).
|
|
@@ -83,6 +91,11 @@ interface LinkVariantEntryInternal {
|
|
|
83
91
|
color: ColorValue;
|
|
84
92
|
underline: boolean;
|
|
85
93
|
backgroundColor: ColorValue;
|
|
94
|
+
borderRadius: CodegenTypes.Float;
|
|
95
|
+
paddingHorizontal: CodegenTypes.Float;
|
|
96
|
+
paddingVertical: CodegenTypes.Float;
|
|
97
|
+
borderColor: ColorValue;
|
|
98
|
+
borderWidth: CodegenTypes.Float;
|
|
86
99
|
}
|
|
87
100
|
|
|
88
101
|
interface StrongStyleInternal {
|
|
@@ -246,6 +259,58 @@ export interface LinkLongPressEvent {
|
|
|
246
259
|
url: string;
|
|
247
260
|
}
|
|
248
261
|
|
|
262
|
+
/**
|
|
263
|
+
* `fragments` holds one entry per laid-out line of a link (a wrapping link
|
|
264
|
+
* yields several). Rects are in dp, relative to the native view's origin, and
|
|
265
|
+
* cover the drawn chip (glyphs + padding). Flattened rather than nested per
|
|
266
|
+
* link, and written inline, because codegen only accepts inline object
|
|
267
|
+
* literals as event array elements.
|
|
268
|
+
*/
|
|
269
|
+
export interface LinkLayoutEvent {
|
|
270
|
+
fragments: {
|
|
271
|
+
linkIndex: CodegenTypes.Int32;
|
|
272
|
+
url: string;
|
|
273
|
+
text: string;
|
|
274
|
+
x: CodegenTypes.Double;
|
|
275
|
+
y: CodegenTypes.Double;
|
|
276
|
+
width: CodegenTypes.Double;
|
|
277
|
+
height: CodegenTypes.Double;
|
|
278
|
+
}[];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Current text selection, or a long-pressed table / math / code block while
|
|
283
|
+
* `contextMenuHidden` is on. `active: false` means the selection was cleared
|
|
284
|
+
* (every other field is then empty / zero). Rects are in dp / pt, relative to
|
|
285
|
+
* the native view's origin; rect objects are written inline because codegen
|
|
286
|
+
* only accepts inline object literals in event payloads.
|
|
287
|
+
*/
|
|
288
|
+
export interface SelectionChangeEvent {
|
|
289
|
+
active: boolean;
|
|
290
|
+
source: string;
|
|
291
|
+
text: string;
|
|
292
|
+
markdown: string;
|
|
293
|
+
whole: boolean;
|
|
294
|
+
rect: {
|
|
295
|
+
x: CodegenTypes.Double;
|
|
296
|
+
y: CodegenTypes.Double;
|
|
297
|
+
width: CodegenTypes.Double;
|
|
298
|
+
height: CodegenTypes.Double;
|
|
299
|
+
};
|
|
300
|
+
startRect: {
|
|
301
|
+
x: CodegenTypes.Double;
|
|
302
|
+
y: CodegenTypes.Double;
|
|
303
|
+
width: CodegenTypes.Double;
|
|
304
|
+
height: CodegenTypes.Double;
|
|
305
|
+
};
|
|
306
|
+
endRect: {
|
|
307
|
+
x: CodegenTypes.Double;
|
|
308
|
+
y: CodegenTypes.Double;
|
|
309
|
+
width: CodegenTypes.Double;
|
|
310
|
+
height: CodegenTypes.Double;
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
249
314
|
export interface TaskListItemPressEvent {
|
|
250
315
|
index: CodegenTypes.Int32;
|
|
251
316
|
checked: boolean;
|
|
@@ -401,6 +466,30 @@ export interface NativeProps extends ViewProps {
|
|
|
401
466
|
* - Android: Handles long press gestures on links.
|
|
402
467
|
*/
|
|
403
468
|
onLinkLongPress?: CodegenTypes.BubblingEventHandler<LinkLongPressEvent>;
|
|
469
|
+
/**
|
|
470
|
+
* When true, the view reports the laid-out rects of every link through
|
|
471
|
+
* `onLinkLayout` (after each render and whenever its size changes).
|
|
472
|
+
* Set by the JS wrapper only when `renderLinkDecoration` is provided.
|
|
473
|
+
* @default false
|
|
474
|
+
*/
|
|
475
|
+
emitLinkLayout?: CodegenTypes.WithDefault<boolean, false>;
|
|
476
|
+
/**
|
|
477
|
+
* Fired with the rects of every link fragment while `emitLinkLayout` is on.
|
|
478
|
+
* Deduplicated: not re-fired when the payload is unchanged.
|
|
479
|
+
*/
|
|
480
|
+
onLinkLayout?: CodegenTypes.DirectEventHandler<LinkLayoutEvent>;
|
|
481
|
+
/**
|
|
482
|
+
* When true, the view reports selection changes (and, with
|
|
483
|
+
* `contextMenuHidden`, block long-presses) through `onSelectionChange`.
|
|
484
|
+
* Set by the JS wrapper only when `onSelectionChange` is provided.
|
|
485
|
+
* @default false
|
|
486
|
+
*/
|
|
487
|
+
emitSelectionChange?: CodegenTypes.WithDefault<boolean, false>;
|
|
488
|
+
/**
|
|
489
|
+
* Fired while `emitSelectionChange` is on: coalesced to one event per frame,
|
|
490
|
+
* deduplicated, and `active: false` once the selection is gone.
|
|
491
|
+
*/
|
|
492
|
+
onSelectionChange?: CodegenTypes.DirectEventHandler<SelectionChangeEvent>;
|
|
404
493
|
/**
|
|
405
494
|
* Callback fired when a task list checkbox is tapped.
|
|
406
495
|
* Receives the 0-based task index, current checked state, and the item's plain text.
|
|
@@ -553,6 +642,17 @@ export interface NativeProps extends ViewProps {
|
|
|
553
642
|
writingDirection?: CodegenTypes.WithDefault<string, 'first-strong'>;
|
|
554
643
|
}
|
|
555
644
|
|
|
645
|
+
type ComponentType = HostComponent<NativeProps>;
|
|
646
|
+
|
|
647
|
+
interface NativeCommands {
|
|
648
|
+
/** Clears the text selection (and any active block) and fires `onSelectionChange` with `active: false`. */
|
|
649
|
+
clearSelection: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
653
|
+
supportedCommands: ['clearSelection'],
|
|
654
|
+
});
|
|
655
|
+
|
|
556
656
|
export default codegenNativeComponent<NativeProps>('EnrichedMarkdownText', {
|
|
557
657
|
interfaceOnly: true,
|
|
558
|
-
})
|
|
658
|
+
}) as HostComponent<NativeProps>;
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","EnrichedMarkdownText","DEFAULT_ACCESSIBILITY_LABELS","resolveAccessibilityLabels","EnrichedMarkdownTextInput"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,oBAAoB,QAAQ,kCAA+B;
|
|
1
|
+
{"version":3,"names":["default","EnrichedMarkdownText","DEFAULT_ACCESSIBILITY_LABELS","resolveAccessibilityLabels","EnrichedMarkdownTextInput"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,oBAAoB,QAAQ,kCAA+B;AA2B/E,SACEC,4BAA4B,EAC5BC,0BAA0B,QACrB,iCAA8B;AAErC,SAASC,yBAAyB,QAAQ,gCAA6B","ignoreList":[]}
|
package/lib/module/jest/index.js
CHANGED
|
@@ -143,6 +143,7 @@ export const EnrichedMarkdownTextInput = ({
|
|
|
143
143
|
});
|
|
144
144
|
};
|
|
145
145
|
export const EnrichedMarkdownText = ({
|
|
146
|
+
ref,
|
|
146
147
|
markdown,
|
|
147
148
|
containerStyle,
|
|
148
149
|
testID,
|
|
@@ -156,6 +157,7 @@ export const EnrichedMarkdownText = ({
|
|
|
156
157
|
onLinkPress: _onLinkPress,
|
|
157
158
|
onLinkLongPress: _onLinkLongPress,
|
|
158
159
|
onTaskListItemPress: _onTaskListItemPress,
|
|
160
|
+
onSelectionChange: _onSelectionChange,
|
|
159
161
|
enableLinkPreview: _enableLinkPreview,
|
|
160
162
|
selectable: _selectable,
|
|
161
163
|
md4cFlags: _md4cFlags,
|
|
@@ -176,6 +178,17 @@ export const EnrichedMarkdownText = ({
|
|
|
176
178
|
lineBreakStrategyIOS: _lineBreakStrategyIOS,
|
|
177
179
|
writingDirection: _writingDirection
|
|
178
180
|
}) => {
|
|
181
|
+
const instanceRef = useRef(null);
|
|
182
|
+
if (instanceRef.current === null) {
|
|
183
|
+
instanceRef.current = {
|
|
184
|
+
// No native selection under Jest; the mock records the call.
|
|
185
|
+
clearSelection: spy(() => {}),
|
|
186
|
+
measure: spy(callback => callback(0, 0, 0, 0, 0, 0)),
|
|
187
|
+
measureInWindow: spy(callback => callback(0, 0, 0, 0)),
|
|
188
|
+
measureLayout: spy((_relativeToNativeNode, onSuccess) => onSuccess(0, 0, 0, 0))
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
useImperativeHandle(ref, () => instanceRef.current);
|
|
179
192
|
return /*#__PURE__*/_jsx(Text, {
|
|
180
193
|
style: containerStyle,
|
|
181
194
|
testID: testID,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useImperativeHandle","useRef","useState","Text","TextInput","jsx","_jsx","DEFAULT_ACCESSIBILITY_LABELS","resolveAccessibilityLabels","spy","impl","jest","fn","EMPTY_CARET_RECT","x","y","width","height","EnrichedMarkdownTextInput","ref","defaultValue","onChangeText","onChangeMarkdown","onFocus","onBlur","editable","placeholder","placeholderTextColor","autoFocus","multiline","scrollEnabled","style","testID","accessible","accessibilityLabel","accessibilityHint","accessibilityRole","accessibilityState","nativeID","markdownStyle","_markdownStyle","cursorColor","_cursorColor","selectionColor","_selectionColor","autoCapitalize","_autoCapitalize","onChangeSelection","_onChangeSelection","onChangeState","_onChangeState","onKeyPress","_onKeyPress","onCaretRectChange","_onCaretRectChange","onLinkDetected","_onLinkDetected","mentionIndicators","_mentionIndicators","onStartMention","_onStartMention","onChangeMention","_onChangeMention","onEndMention","_onEndMention","contextMenuItems","_contextMenuItems","selectionMenuConfig","_selectionMenuConfig","formatMenuConfig","_formatMenuConfig","linkRegex","_linkRegex","writingDirection","_writingDirection","text","setText","textRef","inputRef","applyText","next","current","handleChangeText","instanceRef","focus","blur","measure","callback","measureInWindow","measureLayout","_relativeToNativeNode","onSuccess","setValue","markdown","setSelection","_start","_end","toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","toggleSpoiler","toggleHeading","_level","toggleUnorderedList","toggleOrderedList","indentList","outdentList","setLink","_url","insertLink","_text","insertText","insertMention","_displayText","startMention","_indicator","removeLink","copyToClipboard","resolvePaste","_markdown","insertMath","_latex","_options","updateMath","removeMath","getMarkdown","Promise","resolve","getCaretRect","value","EnrichedMarkdownText","containerStyle","onLinkPress","_onLinkPress","onLinkLongPress","_onLinkLongPress","onTaskListItemPress","_onTaskListItemPress","enableLinkPreview","_enableLinkPreview","selectable","_selectable","md4cFlags","_md4cFlags","allowFontScaling","_allowFontScaling","maxFontSizeMultiplier","_maxFontSizeMultiplier","allowTrailingMargin","_allowTrailingMargin","flavor","_flavor","streamingAnimation","_streamingAnimation","streamingConfig","_streamingConfig","spoilerOverlay","_spoilerOverlay","imageRequestHeaders","_imageRequestHeaders","accessibilityLabels","_accessibilityLabels","selectionHandleColor","_selectionHandleColor","textBreakStrategy","_textBreakStrategy","lineBreakStrategyIOS","_lineBreakStrategyIOS","children"],"sourceRoot":"../../../src","sources":["jest/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAE7D,SAASC,IAAI,EAAEC,SAAS,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;
|
|
1
|
+
{"version":3,"names":["useImperativeHandle","useRef","useState","Text","TextInput","jsx","_jsx","DEFAULT_ACCESSIBILITY_LABELS","resolveAccessibilityLabels","spy","impl","jest","fn","EMPTY_CARET_RECT","x","y","width","height","EnrichedMarkdownTextInput","ref","defaultValue","onChangeText","onChangeMarkdown","onFocus","onBlur","editable","placeholder","placeholderTextColor","autoFocus","multiline","scrollEnabled","style","testID","accessible","accessibilityLabel","accessibilityHint","accessibilityRole","accessibilityState","nativeID","markdownStyle","_markdownStyle","cursorColor","_cursorColor","selectionColor","_selectionColor","autoCapitalize","_autoCapitalize","onChangeSelection","_onChangeSelection","onChangeState","_onChangeState","onKeyPress","_onKeyPress","onCaretRectChange","_onCaretRectChange","onLinkDetected","_onLinkDetected","mentionIndicators","_mentionIndicators","onStartMention","_onStartMention","onChangeMention","_onChangeMention","onEndMention","_onEndMention","contextMenuItems","_contextMenuItems","selectionMenuConfig","_selectionMenuConfig","formatMenuConfig","_formatMenuConfig","linkRegex","_linkRegex","writingDirection","_writingDirection","text","setText","textRef","inputRef","applyText","next","current","handleChangeText","instanceRef","focus","blur","measure","callback","measureInWindow","measureLayout","_relativeToNativeNode","onSuccess","setValue","markdown","setSelection","_start","_end","toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","toggleSpoiler","toggleHeading","_level","toggleUnorderedList","toggleOrderedList","indentList","outdentList","setLink","_url","insertLink","_text","insertText","insertMention","_displayText","startMention","_indicator","removeLink","copyToClipboard","resolvePaste","_markdown","insertMath","_latex","_options","updateMath","removeMath","getMarkdown","Promise","resolve","getCaretRect","value","EnrichedMarkdownText","containerStyle","onLinkPress","_onLinkPress","onLinkLongPress","_onLinkLongPress","onTaskListItemPress","_onTaskListItemPress","onSelectionChange","_onSelectionChange","enableLinkPreview","_enableLinkPreview","selectable","_selectable","md4cFlags","_md4cFlags","allowFontScaling","_allowFontScaling","maxFontSizeMultiplier","_maxFontSizeMultiplier","allowTrailingMargin","_allowTrailingMargin","flavor","_flavor","streamingAnimation","_streamingAnimation","streamingConfig","_streamingConfig","spoilerOverlay","_spoilerOverlay","imageRequestHeaders","_imageRequestHeaders","accessibilityLabels","_accessibilityLabels","selectionHandleColor","_selectionHandleColor","textBreakStrategy","_textBreakStrategy","lineBreakStrategyIOS","_lineBreakStrategyIOS","clearSelection","children"],"sourceRoot":"../../../src","sources":["jest/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAE7D,SAASC,IAAI,EAAEC,SAAS,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAY/C,SACEC,4BAA4B,EAC5BC,0BAA0B,QACrB,kCAA+B;AAKtC,MAAMC,GAAG,GAAqBC,IAAQ,IAAQC,IAAI,CAACC,EAAE,CAACF,IAAI,CAAC;AAE3D,MAAMG,gBAA2B,GAAG;EAAEC,CAAC,EAAE,CAAC;EAAEC,CAAC,EAAE,CAAC;EAAEC,KAAK,EAAE,CAAC;EAAEC,MAAM,EAAE;AAAE,CAAC;AAEvE,OA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W,CAACF,OAAQ,CAAC;EAEpD,oBACE3E,IAAA,CAACH,IAAI;IACH4B,KAAK,EAAEqG,cAAe;IACtBpG,MAAM,EAAEA,MAAO;IACfC,UAAU,EAAEA,UAAW;IACvBC,kBAAkB,EAAEA,kBAAmB;IACvCC,iBAAiB,EAAEA,iBAAkB;IACrCC,iBAAiB,EAAEA,iBAAkB;IACrCC,kBAAkB,EAAEA,kBAAmB;IACvCC,QAAQ,EAAEA,QAAS;IAAAsI,QAAA,EAElB/E;EAAQ,CACL,CAAC;AAEX,CAAC","ignoreList":[]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { useMemo, useCallback, useRef, useEffect } from 'react';
|
|
4
|
-
import EnrichedMarkdownTextNativeComponent from '../EnrichedMarkdownTextNativeComponent';
|
|
5
|
-
import EnrichedMarkdownNativeComponent from '../EnrichedMarkdownNativeComponent';
|
|
3
|
+
import { useMemo, useCallback, useRef, useEffect, useState, useImperativeHandle } from 'react';
|
|
4
|
+
import EnrichedMarkdownTextNativeComponent, { Commands as TextCommands } from '../EnrichedMarkdownTextNativeComponent';
|
|
5
|
+
import EnrichedMarkdownNativeComponent, { Commands as MarkdownCommands } from '../EnrichedMarkdownNativeComponent';
|
|
6
6
|
import { normalizeMarkdownStyle } from '../normalizeMarkdownStyle';
|
|
7
7
|
import { resolveAccessibilityLabels } from "../accessibilityLabelDefaults.js";
|
|
8
8
|
import { normalizeMenuItem, normalizeLegacyBooleanMenuItem } from "../normalizeMenuItem.js";
|
|
9
|
-
import {
|
|
9
|
+
import { StyleSheet, View } from 'react-native';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
11
|
// Default English labels for the built-in selection menu actions. Defaults are
|
|
11
12
|
// resolved here (JS-side) so the native code always receives a concrete string.
|
|
12
13
|
const DEFAULT_COPY_LABEL = 'Copy';
|
|
@@ -56,6 +57,44 @@ const buildPluralTemplates = (pluralLabels, singularLabel) => {
|
|
|
56
57
|
}
|
|
57
58
|
return templates;
|
|
58
59
|
};
|
|
60
|
+
/** Groups the flat per-line fragments native reports into one entry per link. */
|
|
61
|
+
const groupLinkFragments = fragments => {
|
|
62
|
+
const byIndex = new Map();
|
|
63
|
+
for (const {
|
|
64
|
+
linkIndex,
|
|
65
|
+
url,
|
|
66
|
+
text,
|
|
67
|
+
x,
|
|
68
|
+
y,
|
|
69
|
+
width,
|
|
70
|
+
height
|
|
71
|
+
} of fragments) {
|
|
72
|
+
const rect = {
|
|
73
|
+
x,
|
|
74
|
+
y,
|
|
75
|
+
width,
|
|
76
|
+
height
|
|
77
|
+
};
|
|
78
|
+
const info = byIndex.get(linkIndex);
|
|
79
|
+
if (info) {
|
|
80
|
+
info.rects.push(rect);
|
|
81
|
+
info.rect = rect;
|
|
82
|
+
} else {
|
|
83
|
+
byIndex.set(linkIndex, {
|
|
84
|
+
index: linkIndex,
|
|
85
|
+
url,
|
|
86
|
+
text,
|
|
87
|
+
rect,
|
|
88
|
+
rects: [rect]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [...byIndex.values()];
|
|
93
|
+
};
|
|
94
|
+
const ZERO_OFFSET = {
|
|
95
|
+
x: 0,
|
|
96
|
+
y: 0
|
|
97
|
+
};
|
|
59
98
|
const defaultMd4cFlags = {
|
|
60
99
|
underline: false,
|
|
61
100
|
superscript: false,
|
|
@@ -65,6 +104,7 @@ const defaultMd4cFlags = {
|
|
|
65
104
|
hardSoftBreaks: false
|
|
66
105
|
};
|
|
67
106
|
export const EnrichedMarkdownText = ({
|
|
107
|
+
ref,
|
|
68
108
|
markdown,
|
|
69
109
|
markdownStyle = {},
|
|
70
110
|
containerStyle,
|
|
@@ -74,6 +114,7 @@ export const EnrichedMarkdownText = ({
|
|
|
74
114
|
enableTaskListItemToggle = true,
|
|
75
115
|
onCopyPress,
|
|
76
116
|
onCopy,
|
|
117
|
+
onSelectionChange,
|
|
77
118
|
enableLinkPreview,
|
|
78
119
|
selectable = true,
|
|
79
120
|
md4cFlags = defaultMd4cFlags,
|
|
@@ -94,6 +135,8 @@ export const EnrichedMarkdownText = ({
|
|
|
94
135
|
textBreakStrategy,
|
|
95
136
|
lineBreakStrategyIOS,
|
|
96
137
|
writingDirection = 'first-strong',
|
|
138
|
+
renderLinkDecoration,
|
|
139
|
+
onLayout,
|
|
97
140
|
...rest
|
|
98
141
|
}) => {
|
|
99
142
|
const normalizedStyleRef = useRef(null);
|
|
@@ -202,6 +245,57 @@ export const EnrichedMarkdownText = ({
|
|
|
202
245
|
});
|
|
203
246
|
}, [onCopy]);
|
|
204
247
|
const interceptCopy = onCopy != null;
|
|
248
|
+
const decorated = renderLinkDecoration != null;
|
|
249
|
+
const [linkLayout, setLinkLayout] = useState([]);
|
|
250
|
+
// Where the native view sits inside the wrapper (the wrapper's padding).
|
|
251
|
+
const [nativeOffset, setNativeOffset] = useState(ZERO_OFFSET);
|
|
252
|
+
const handleLinkLayout = useCallback(e => {
|
|
253
|
+
setLinkLayout(groupLinkFragments(e.nativeEvent.fragments));
|
|
254
|
+
}, []);
|
|
255
|
+
const handleNativeLayout = useCallback(e => {
|
|
256
|
+
const {
|
|
257
|
+
x,
|
|
258
|
+
y
|
|
259
|
+
} = e.nativeEvent.layout;
|
|
260
|
+
setNativeOffset(prev => prev.x === x && prev.y === y ? prev : {
|
|
261
|
+
x,
|
|
262
|
+
y
|
|
263
|
+
});
|
|
264
|
+
}, []);
|
|
265
|
+
|
|
266
|
+
// Rects stay relative to the native view — the view the ref's
|
|
267
|
+
// `measureInWindow` measures — even when decorations wrap it.
|
|
268
|
+
const handleSelectionChange = useCallback(
|
|
269
|
+
// Codegen types `source` as a plain string; native only sends the four
|
|
270
|
+
// values of SelectionChangeEvent['source'].
|
|
271
|
+
e => {
|
|
272
|
+
const {
|
|
273
|
+
source,
|
|
274
|
+
...payload
|
|
275
|
+
} = e.nativeEvent;
|
|
276
|
+
onSelectionChange?.({
|
|
277
|
+
...payload,
|
|
278
|
+
source: source
|
|
279
|
+
});
|
|
280
|
+
}, [onSelectionChange]);
|
|
281
|
+
const nativeRef = useRef(null);
|
|
282
|
+
const isGithubFlavor = flavor === 'github';
|
|
283
|
+
useImperativeHandle(ref, () => ({
|
|
284
|
+
clearSelection: () => {
|
|
285
|
+
const node = nativeRef.current;
|
|
286
|
+
if (node == null) return;
|
|
287
|
+
// Codegen's ViewRef resolves to `never` with RN 0.84's function-based
|
|
288
|
+
// HostComponent type — the cast is safe at runtime.
|
|
289
|
+
if (isGithubFlavor) {
|
|
290
|
+
MarkdownCommands.clearSelection(node);
|
|
291
|
+
} else {
|
|
292
|
+
TextCommands.clearSelection(node);
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
measure: callback => nativeRef.current?.measure(callback),
|
|
296
|
+
measureInWindow: callback => nativeRef.current?.measureInWindow(callback),
|
|
297
|
+
measureLayout: (relativeToNativeNode, onSuccess, onFail) => nativeRef.current?.measureLayout(relativeToNativeNode, onSuccess, onFail)
|
|
298
|
+
}), [isGithubFlavor]);
|
|
205
299
|
const tableMode = streamingConfig?.tableMode ?? 'progressive';
|
|
206
300
|
const codeBlockMode = streamingConfig?.codeBlockMode ?? 'progressive';
|
|
207
301
|
const normalizedStreamingConfig = useMemo(() => ({
|
|
@@ -243,6 +337,8 @@ export const EnrichedMarkdownText = ({
|
|
|
243
337
|
enableTaskListItemToggle,
|
|
244
338
|
onCopyPress: handleCopyPress,
|
|
245
339
|
onCopyRequest: handleCopyRequest,
|
|
340
|
+
emitSelectionChange: onSelectionChange != null,
|
|
341
|
+
onSelectionChange: handleSelectionChange,
|
|
246
342
|
enableLinkPreview: onLinkLongPress == null && (enableLinkPreview ?? true),
|
|
247
343
|
selectable,
|
|
248
344
|
md4cFlags: normalizedMd4cFlags,
|
|
@@ -266,14 +362,47 @@ export const EnrichedMarkdownText = ({
|
|
|
266
362
|
writingDirection,
|
|
267
363
|
...rest
|
|
268
364
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
365
|
+
const NativeComponent = isGithubFlavor ? EnrichedMarkdownNativeComponent : EnrichedMarkdownTextNativeComponent;
|
|
366
|
+
|
|
367
|
+
// Without decorations the native view is returned as-is (no wrapper, no
|
|
368
|
+
// layout events) so existing layouts are untouched.
|
|
369
|
+
if (!decorated) {
|
|
370
|
+
return /*#__PURE__*/_jsx(NativeComponent, {
|
|
371
|
+
...sharedProps,
|
|
372
|
+
ref: nativeRef,
|
|
373
|
+
onLayout: onLayout
|
|
272
374
|
});
|
|
273
375
|
}
|
|
274
|
-
return /*#__PURE__*/
|
|
275
|
-
|
|
376
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
377
|
+
style: containerStyle,
|
|
378
|
+
onLayout: onLayout,
|
|
379
|
+
children: [/*#__PURE__*/_jsx(NativeComponent, {
|
|
380
|
+
...sharedProps,
|
|
381
|
+
ref: nativeRef,
|
|
382
|
+
style: undefined,
|
|
383
|
+
emitLinkLayout: true,
|
|
384
|
+
onLinkLayout: handleLinkLayout,
|
|
385
|
+
onLayout: handleNativeLayout
|
|
386
|
+
}), linkLayout.map(info => {
|
|
387
|
+
const decoration = renderLinkDecoration(info);
|
|
388
|
+
if (decoration == null) return null;
|
|
389
|
+
return /*#__PURE__*/_jsx(View, {
|
|
390
|
+
pointerEvents: "box-none",
|
|
391
|
+
style: [styles.decoration, {
|
|
392
|
+
left: nativeOffset.x + info.rect.x,
|
|
393
|
+
top: nativeOffset.y + info.rect.y,
|
|
394
|
+
width: info.rect.width,
|
|
395
|
+
height: info.rect.height
|
|
396
|
+
}],
|
|
397
|
+
children: decoration
|
|
398
|
+
}, info.index);
|
|
399
|
+
})]
|
|
276
400
|
});
|
|
277
401
|
};
|
|
402
|
+
const styles = StyleSheet.create({
|
|
403
|
+
decoration: {
|
|
404
|
+
position: 'absolute'
|
|
405
|
+
}
|
|
406
|
+
});
|
|
278
407
|
export default EnrichedMarkdownText;
|
|
279
408
|
//# sourceMappingURL=EnrichedMarkdownText.js.map
|