mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 10:15:46 +00:00
* chore(app): vendor react-native-enriched-markdown with the Paseo patch applied Copy react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 (upstream software-mansion/enriched-markdown 766fc0e67) into packages/react-native-enriched-markdown, with patches/react-native-enriched-markdown+1.2.0-nightly-20261014-766fc0e67.patch applied. Nothing else changes in this commit; the package is not a workspace yet. Reproduce: npm pack react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 tar xzf react-native-enriched-markdown-*.tgz mkdir -p t/node_modules && mv package t/node_modules/react-native-enriched-markdown (cd t && git init -q && git apply ../patches/react-native-enriched-markdown+*.patch) diff -r t/node_modules/react-native-enriched-markdown packages/react-native-enriched-markdown The diff is empty. * chore(app): consume react-native-enriched-markdown from its workspace Make packages/react-native-enriched-markdown a private workspace and point the app at it, then remove the patch-package patch it replaces. - package.json: private, version follows the root like every workspace, only the postinstall script that downloads tree-sitter grammars. Upstream's devDependencies would install a second react-native, so they are gone. - The package keeps its name, so autolinking, the Gradle project :react-native-enriched-markdown, the CocoaPods spec and imports are unchanged. - Lockfile: drop the nested registry copy under packages/app/node_modules; npm links node_modules/react-native-enriched-markdown to the workspace. - Formatting, lint and knip skip the vendored code. CI routes changes to it through the app and browser suites. - The codegen test checks the vendored package's generated props. - docs/markdown-renderer.md describes the fork and how to edit it. * fix(app): keep numbered sub-list markers off their text on Android From #9964, moved from the package patch into the vendored package. On Android, a numbered list nested in a bulleted item drew "1." over the first letters of each item. A nested item's text indent summed the root list's narrow bullet column with a fixed marginLeft, while its marker was right-aligned to its own wider "99." column, so the number landed on the text. iOS already indents from the item's own column. Backport the Android hunks of upstream enriched-markdown #1015 (size the number column to the widest marker) and #1023 (nested items start their text from their own marker column). test:android now also runs the backported ListRenderingTest and TaskListInteractionTest suites. docs/markdown-renderer.md lists the fork's backports, this one and #924, which the removed postinstall comment used to track. The vendored tree equals the #9964 patch applied to the pristine package. * fix(app): keep Android assistant replies inside their turns From #10380, moved from the package patch into the vendored package. On Android, an assistant reply with blockquotes nested inside a list could overlap its "Worked for ..." footer and the next user message: the displayed text and the layout measurement applied spans in different orders, and the list-wide line height inflated the blockquote spacers when it ran after them. Use the same span order for Android Markdown measurement and display. Apply list line height before blockquote spacers so nested quotes keep their configured padding and the reply fits above the turn footer. test:android now also runs ListBlockquoteMeasurementTest. Applied on top of #9964; the two changes share only ListRenderer.kt, where #10380's import and line-height call sit beside #9964's marker width code. Every other file equals the #10380 patch applied to the pristine package. * chore(app): match the vendored Markdown web block renderer source to its build The package patch changed lib/module/web/renderers/BlockRenderers.js (the renderers.codeBlock override and the zoom-in cursor on images) but not src/web/renderers/BlockRenderers.tsx. The app runs lib, so behavior does not change. Port both changes into src so src stays the source of lib.
408 lines
11 KiB
TypeScript
408 lines
11 KiB
TypeScript
import {
|
|
codegenNativeComponent,
|
|
codegenNativeCommands,
|
|
type ViewProps,
|
|
type ColorValue,
|
|
type HostComponent,
|
|
type CodegenTypes,
|
|
} from 'react-native';
|
|
import type React from 'react';
|
|
|
|
interface HeadingStyleInternal {
|
|
fontSize: CodegenTypes.Float;
|
|
fontWeight: string;
|
|
color: ColorValue;
|
|
}
|
|
|
|
interface MarkdownTextInputStyleInternal {
|
|
strong: {
|
|
color?: ColorValue;
|
|
};
|
|
em: {
|
|
color?: ColorValue;
|
|
};
|
|
link: {
|
|
color: ColorValue;
|
|
underline: boolean;
|
|
backgroundColor: ColorValue;
|
|
};
|
|
linkVariants: ReadonlyArray<
|
|
Readonly<{
|
|
pattern: string;
|
|
color: ColorValue;
|
|
underline: boolean;
|
|
backgroundColor: ColorValue;
|
|
}>
|
|
>;
|
|
spoiler: {
|
|
color: ColorValue;
|
|
backgroundColor: ColorValue;
|
|
};
|
|
// Per-level heading styles, mirroring the readonly renderer's markdownStyle
|
|
// h1..h6 so heading sizing is configured consistently across read and edit
|
|
// views. Always provided with complete defaults via normalizeMarkdownTextInputStyle.
|
|
h1: HeadingStyleInternal;
|
|
h2: HeadingStyleInternal;
|
|
h3: HeadingStyleInternal;
|
|
h4: HeadingStyleInternal;
|
|
h5: HeadingStyleInternal;
|
|
h6: HeadingStyleInternal;
|
|
list: {
|
|
// Vertical spacing (points) added above each list item. iOS applies it via
|
|
// paragraphSpacingBefore; Android via a LineHeightSpan. Float for parity with
|
|
// every other spacing value in the library.
|
|
itemSpacing: CodegenTypes.Float;
|
|
};
|
|
}
|
|
|
|
interface TargetedEvent {
|
|
target: CodegenTypes.Int32;
|
|
}
|
|
|
|
export interface OnChangeTextEvent {
|
|
value: string;
|
|
}
|
|
|
|
export interface OnChangeMarkdownEvent {
|
|
value: string;
|
|
}
|
|
|
|
export interface OnKeyPressEvent {
|
|
key: string;
|
|
}
|
|
|
|
export interface OnChangeSelectionEvent {
|
|
start: CodegenTypes.Int32;
|
|
end: CodegenTypes.Int32;
|
|
}
|
|
|
|
export interface OnChangeStateEvent {
|
|
bold: { isActive: boolean };
|
|
italic: { isActive: boolean };
|
|
underline: { isActive: boolean };
|
|
strikethrough: { isActive: boolean };
|
|
spoiler: { isActive: boolean };
|
|
link: { isActive: boolean; destination: string };
|
|
heading: { isActive: boolean; level: CodegenTypes.Int32 };
|
|
unorderedList: { isActive: boolean; depth: CodegenTypes.Int32 };
|
|
orderedList: { isActive: boolean; depth: CodegenTypes.Int32 };
|
|
}
|
|
|
|
export interface OnRequestMarkdownResultEvent {
|
|
requestId: CodegenTypes.Int32;
|
|
markdown: string;
|
|
}
|
|
|
|
export interface OnRequestCaretRectResultEvent {
|
|
requestId: CodegenTypes.Int32;
|
|
x: CodegenTypes.Double;
|
|
y: CodegenTypes.Double;
|
|
width: CodegenTypes.Double;
|
|
height: CodegenTypes.Double;
|
|
}
|
|
|
|
export interface OnCaretRectChangeEvent {
|
|
x: CodegenTypes.Double;
|
|
y: CodegenTypes.Double;
|
|
width: CodegenTypes.Double;
|
|
height: CodegenTypes.Double;
|
|
}
|
|
|
|
export interface LinkNativeRegex {
|
|
pattern: string;
|
|
caseInsensitive: boolean;
|
|
dotAll: boolean;
|
|
isDisabled: boolean;
|
|
isDefault: boolean;
|
|
}
|
|
|
|
export interface OnLinkDetected {
|
|
text: string;
|
|
url: string;
|
|
start: CodegenTypes.Int32;
|
|
end: CodegenTypes.Int32;
|
|
}
|
|
|
|
export interface OnStartMentionEvent {
|
|
indicator: string;
|
|
}
|
|
|
|
export interface OnChangeMentionEvent {
|
|
indicator: string;
|
|
text: string;
|
|
}
|
|
|
|
export interface OnEndMentionEvent {
|
|
indicator: string;
|
|
}
|
|
|
|
export interface ContextMenuItemConfig {
|
|
text: string;
|
|
icon?: string;
|
|
}
|
|
|
|
export interface InputSelectionMenuConfigInternal {
|
|
format: boolean;
|
|
formatLabel: string;
|
|
copyAsMarkdown: boolean;
|
|
copyAsMarkdownLabel: string;
|
|
}
|
|
|
|
export interface FormatMenuConfigInternal {
|
|
bold: boolean;
|
|
boldLabel: string;
|
|
italic: boolean;
|
|
italicLabel: string;
|
|
underline: boolean;
|
|
underlineLabel: string;
|
|
strikethrough: boolean;
|
|
strikethroughLabel: string;
|
|
spoiler: boolean;
|
|
spoilerLabel: string;
|
|
link: boolean;
|
|
linkLabel: string;
|
|
}
|
|
|
|
export interface MarkdownShortcutsConfigInternal {
|
|
heading: boolean;
|
|
unorderedList: boolean;
|
|
orderedList: boolean;
|
|
}
|
|
|
|
export interface OnContextMenuItemPressEvent {
|
|
itemText: string;
|
|
selectedText: string;
|
|
selectionStart: CodegenTypes.Int32;
|
|
selectionEnd: CodegenTypes.Int32;
|
|
styleState: {
|
|
bold: { isActive: boolean };
|
|
italic: { isActive: boolean };
|
|
underline: { isActive: boolean };
|
|
strikethrough: { isActive: boolean };
|
|
spoiler: { isActive: boolean };
|
|
link: { isActive: boolean; destination: string };
|
|
heading: { isActive: boolean; level: CodegenTypes.Int32 };
|
|
unorderedList: { isActive: boolean; depth: CodegenTypes.Int32 };
|
|
orderedList: { isActive: boolean; depth: CodegenTypes.Int32 };
|
|
};
|
|
}
|
|
|
|
export interface NativeProps extends ViewProps {
|
|
/**
|
|
* Initial markdown content.
|
|
*/
|
|
defaultValue?: string;
|
|
/**
|
|
* Placeholder text shown when the input is empty.
|
|
*/
|
|
placeholder?: string;
|
|
/**
|
|
* Color of the placeholder text.
|
|
*/
|
|
placeholderTextColor?: ColorValue;
|
|
/**
|
|
* Whether the input is editable.
|
|
* @default true
|
|
*/
|
|
editable?: boolean;
|
|
/**
|
|
* Whether the input should auto-focus on mount.
|
|
* @default false
|
|
*/
|
|
autoFocus?: boolean;
|
|
/**
|
|
* Whether the input is scrollable.
|
|
* @default true
|
|
*/
|
|
scrollEnabled?: boolean;
|
|
/**
|
|
* Which markdown block prefixes typed at a paragraph start convert into the
|
|
* matching block. Always complete — the JS side normalizes the public
|
|
* `boolean | MarkdownShortcutsConfig` form before it gets here.
|
|
*/
|
|
markdownShortcuts: Readonly<MarkdownShortcutsConfigInternal>;
|
|
/**
|
|
* Auto-capitalization behavior.
|
|
*/
|
|
autoCapitalize?: string;
|
|
/**
|
|
* Whether the input supports multiple lines.
|
|
* @default true
|
|
*/
|
|
multiline?: boolean;
|
|
/**
|
|
* Color of the cursor.
|
|
*/
|
|
cursorColor?: ColorValue;
|
|
/**
|
|
* Color of the text selection highlight.
|
|
*/
|
|
selectionColor?: ColorValue;
|
|
/**
|
|
* Inline format style overrides.
|
|
* Always provided with complete defaults via normalizeMarkdownTextInputStyle.
|
|
*/
|
|
markdownStyle: MarkdownTextInputStyleInternal;
|
|
|
|
// These should not be passed as regular props.
|
|
color?: ColorValue;
|
|
fontSize?: CodegenTypes.Float;
|
|
lineHeight?: CodegenTypes.Float;
|
|
fontFamily?: string;
|
|
fontWeight?: string;
|
|
|
|
/**
|
|
* Whether onChangeMarkdown handler is set. When true, the native side
|
|
* serializes formatting ranges to Markdown on every change.
|
|
*/
|
|
isOnChangeMarkdownSet?: boolean;
|
|
|
|
/**
|
|
* Custom items to show in the text selection context menu.
|
|
* Each item is shown by its `text` label; invisible items should be filtered out before passing here.
|
|
*/
|
|
contextMenuItems?: ReadonlyArray<Readonly<ContextMenuItemConfig>>;
|
|
|
|
/**
|
|
* Controls built-in items in the text selection context menu.
|
|
* `format` toggles the Format submenu; `copyAsMarkdown` toggles the Copy as Markdown action.
|
|
*/
|
|
selectionMenuConfig: Readonly<InputSelectionMenuConfigInternal>;
|
|
|
|
/**
|
|
* Controls which items appear inside the Format submenu.
|
|
*/
|
|
formatMenuConfig: Readonly<FormatMenuConfigInternal>;
|
|
|
|
/**
|
|
* Regex configuration for automatic link detection.
|
|
* Omit or pass undefined to use platform defaults.
|
|
*/
|
|
linkRegex?: Readonly<LinkNativeRegex>;
|
|
|
|
/**
|
|
* List of trigger strings that start a mention flow (e.g. `['@', '#']`).
|
|
* Detection fires when the cursor is immediately after a token that starts with one of these strings.
|
|
*/
|
|
mentionIndicators?: ReadonlyArray<string>;
|
|
|
|
/**
|
|
* Paragraph writing direction.
|
|
* - 'first-strong' (default): resolves each paragraph from its first strong directional character;
|
|
* neutral-only paragraphs fall back to the view's resolved layout direction. Library extension —
|
|
* matches Android's TEXT_DIRECTION_FIRST_STRONG.
|
|
* - 'auto': React Native parity; iOS TextKit follows the app's userInterfaceLayoutDirection.
|
|
* - 'ltr' / 'rtl': force base direction on every paragraph.
|
|
* @default 'first-strong'
|
|
* @platform ios
|
|
*/
|
|
writingDirection?: CodegenTypes.WithDefault<string, 'first-strong'>;
|
|
|
|
// Events
|
|
onChangeText?: CodegenTypes.DirectEventHandler<OnChangeTextEvent>;
|
|
onChangeMarkdown?: CodegenTypes.DirectEventHandler<OnChangeMarkdownEvent>;
|
|
onChangeSelection?: CodegenTypes.DirectEventHandler<OnChangeSelectionEvent>;
|
|
onInputKeyPress?: CodegenTypes.DirectEventHandler<OnKeyPressEvent>;
|
|
onChangeState?: CodegenTypes.DirectEventHandler<OnChangeStateEvent>;
|
|
onInputFocus?: CodegenTypes.DirectEventHandler<TargetedEvent>;
|
|
onInputBlur?: CodegenTypes.DirectEventHandler<TargetedEvent>;
|
|
onRequestMarkdownResult?: CodegenTypes.DirectEventHandler<OnRequestMarkdownResultEvent>;
|
|
onRequestCaretRectResult?: CodegenTypes.DirectEventHandler<OnRequestCaretRectResultEvent>;
|
|
onCaretRectChange?: CodegenTypes.DirectEventHandler<OnCaretRectChangeEvent>;
|
|
onContextMenuItemPress?: CodegenTypes.DirectEventHandler<OnContextMenuItemPressEvent>;
|
|
onLinkDetected?: CodegenTypes.DirectEventHandler<OnLinkDetected>;
|
|
onStartMention?: CodegenTypes.DirectEventHandler<OnStartMentionEvent>;
|
|
onChangeMention?: CodegenTypes.DirectEventHandler<OnChangeMentionEvent>;
|
|
onEndMention?: CodegenTypes.DirectEventHandler<OnEndMentionEvent>;
|
|
}
|
|
|
|
type ComponentType = HostComponent<NativeProps>;
|
|
|
|
interface NativeCommands {
|
|
focus: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
blur: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
setValue: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
markdown: string
|
|
) => void;
|
|
setSelection: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
start: CodegenTypes.Int32,
|
|
end: CodegenTypes.Int32
|
|
) => void;
|
|
toggleBold: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
toggleItalic: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
toggleUnderline: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
toggleStrikethrough: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
toggleSpoiler: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
toggleHeading: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
level: CodegenTypes.Int32
|
|
) => void;
|
|
toggleUnorderedList: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
toggleOrderedList: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
indentList: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
outdentList: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
setLink: (viewRef: React.ElementRef<ComponentType>, url: string) => void;
|
|
insertLink: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
text: string,
|
|
url: string
|
|
) => void;
|
|
insertText: (viewRef: React.ElementRef<ComponentType>, text: string) => void;
|
|
insertMention: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
displayText: string,
|
|
url: string
|
|
) => void;
|
|
startMention: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
indicator: string
|
|
) => void;
|
|
removeLink: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
copyToClipboard: (viewRef: React.ElementRef<ComponentType>) => void;
|
|
requestMarkdown: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
requestId: CodegenTypes.Int32
|
|
) => void;
|
|
requestCaretRect: (
|
|
viewRef: React.ElementRef<ComponentType>,
|
|
requestId: CodegenTypes.Int32
|
|
) => void;
|
|
}
|
|
|
|
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
|
supportedCommands: [
|
|
'focus',
|
|
'blur',
|
|
'setValue',
|
|
'setSelection',
|
|
'toggleBold',
|
|
'toggleItalic',
|
|
'toggleUnderline',
|
|
'toggleStrikethrough',
|
|
'toggleSpoiler',
|
|
'toggleHeading',
|
|
'toggleUnorderedList',
|
|
'toggleOrderedList',
|
|
'indentList',
|
|
'outdentList',
|
|
'setLink',
|
|
'insertLink',
|
|
'insertText',
|
|
'insertMention',
|
|
'startMention',
|
|
'removeLink',
|
|
'copyToClipboard',
|
|
'requestMarkdown',
|
|
'requestCaretRect',
|
|
],
|
|
});
|
|
|
|
export default codegenNativeComponent<NativeProps>(
|
|
'EnrichedMarkdownTextInput',
|
|
{
|
|
interfaceOnly: true,
|
|
}
|
|
) as HostComponent<NativeProps>;
|