From a5682b0058531b86eaf52c5918d8fbc4170a916b Mon Sep 17 00:00:00 2001 From: Andrei Demian Date: Fri, 9 Oct 2026 11:30:54 -0700 Subject: [PATCH 1/2] release init --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 21 +- README.md | 23 +- SelectableMarkdown.podspec | 3 +- .../com/selectablemarkdown/RunTextMeasure.kt | 2 +- .../SelectableMarkdownModule.kt | 2 +- .../SelectableRunHostView.kt | 3 - conformance/run-commonmark.mjs | 10 +- docs/ARCHITECTURE.md | 24 +- docs/BENCHMARKS.md | 8 +- docs/NATIVE.md | 55 ++- docs/PERFORMANCE.md | 20 +- docs/SELECTION.md | 17 +- docs/STREAMING.md | 14 +- native/node/README.md | 16 +- native/node/addon.cpp | 3 +- package.json | 45 ++- platform/cpp/FlatBuffer.cpp | 7 +- platform/cpp/OffsetParser.cpp | 9 +- platform/cpp/OffsetParser.h | 5 +- platform/cpp/Protocol.h | 3 + platform/cpp/vendor/md4c/UPSTREAM.md | 8 +- platform/cpp/vendor/md4c/md4c.c | 7 + platform/cpp/vendor/md4c/md4c.h | 2 + .../md4c/patches/0001-fence-closed.patch | 45 +++ platform/cpp/vendor/md4c/patches/README.md | 4 +- platform/ios/SelectableRunHostView.swift | 20 +- scripts/check-unreleased-breaking.mjs | 41 +- src/agui/useAgUiSession.ts | 1 + src/engine/Engine.ts | 3 +- src/engine/engine.test.ts | 1 + src/engine/htmlSubset.depth.test.ts | 31 ++ src/engine/htmlSubset.test.ts | 26 ++ src/engine/htmlSubset.ts | 179 ++++++--- src/engine/links.test.ts | 22 ++ src/engine/links.ts | 13 +- src/engine/native/__tests__/protocol.test.ts | 81 ++++ .../__tests__/smart-punctuation.test.ts | 69 +++- src/engine/native/__tests__/spans.test.ts | 2 +- .../__tests__/widen-regressions.test.ts | 151 ++++++++ src/engine/native/decode.ts | 351 ++++++++++++++---- src/engine/native/index.ts | 3 + src/engine/native/protocol.ts | 2 + src/engine/native/widen.ts | 208 +++++++++-- src/engine/options.ts | 21 ++ src/engine/urlPolicy.ts | 4 +- src/index.ts | 1 + src/stream/StreamSession.ts | 35 +- src/stream/regressions.test.ts | 51 +++ src/stream/repair.test.ts | 9 +- src/stream/repair.ts | 15 +- src/view/RunHost.tsx | 17 +- src/view/SelectableMarkdown.tsx | 153 ++++++-- src/view/embedMeasure.test.tsx | 92 +++++ src/view/imageRatios.test.tsx | 37 ++ src/view/runDecorations.ts | 210 ++++++++--- src/view/wireFinite.test.tsx | 52 +++ 57 files changed, 1889 insertions(+), 370 deletions(-) create mode 100644 platform/cpp/vendor/md4c/patches/0001-fence-closed.patch create mode 100644 src/engine/htmlSubset.depth.test.ts create mode 100644 src/engine/links.test.ts create mode 100644 src/engine/native/__tests__/widen-regressions.test.ts create mode 100644 src/stream/regressions.test.ts create mode 100644 src/view/embedMeasure.test.tsx create mode 100644 src/view/wireFinite.test.tsx diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70679b0..d8e1dcc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,7 +54,7 @@ jobs: # succeeds anyway — and if they are genuinely missing, that build is # the step that should go red, with a message about headers. continue-on-error: true - run: npx --yes node-gyp install + run: npx --yes node-gyp@13.1.0 install - name: Build the native parser (test addon) # No --if-available: see above. A compile error, a link error, an # undefined-symbol violation and an unequipped machine all fail this diff --git a/CHANGELOG.md b/CHANGELOG.md index c66be9c..cc6f914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,25 @@ Versions follow [semver](https://semver.org/); pre-1.0, breaking changes land in ## [Unreleased] +- Fix (Android): `SelectableRunHostView.kt` referenced an undefined `pressed` in `pressableBounds`, so every app on 0.13.1 failed Kotlin compilation. +- Fix (engine): the closing-fence search after fenced code no longer backtracks exponentially on a line of `> ` markers (a 59-byte message took seconds, 35 markers took minutes), and no longer takes a later sibling's or a top-level fence as the closer of a block its container ended, which produced overlapping spans and an unanchored code block. md4c now reports whether a fence closed the block (vendored patch 0001, `kDetailFenceClosed` on the wire; the protocol version is unchanged). +- Fix (engine): link tails are scanned by the link grammar instead of to the balancing bracket, so reference links each followed by a lone `(` or an unterminated title cost linear time (100 kB: 2.4 s to 92 ms). +- Fix (engine): a thematic break inside a list item or blockquote (`- ***`, `> ***`) gets its real span instead of a zero-width one, and the span sweep no longer tolerates a zero-width rule. +- Fix (engine): `extractLinks` and `html: { allow }` no longer overflow the stack on deeply nested inlines; the HTML-subset tokenizer trims trailing whitespace in linear time. +- Fix (engine): the decoder throws `NativeProtocolError` for an event range outside the source or running backwards, decodes an invalid UTF-8 string-table entry to U+FFFD instead of throwing `RangeError`, and wraps the inline children of an unknown node type in a paragraph. +- Engine: smart punctuation pairs quotes as `cmark --smart` does; an unpaired `"` or `'` now renders as the closing form (`"abc` → `”abc`). +- Engine: `maxSourceLength` (default 1,048,576 UTF-16 units; `Infinity` opts out). `parseDocument` and `nativeEngine` throw a `RangeError` for longer input before parsing it. `ResolvedEngineOptions` gains `maxSourceLength`, and the default is exported as `DEFAULT_MAX_SOURCE_LENGTH`. +- Fix (streaming): tail repair's trailing-whitespace trim and the fast path's autolink guard are linear (40,000 spaces before a pending closer: 3.3 s to under a millisecond per append; 10,000 `(http:` candidates on one line: 1.5 s to under a millisecond), and a NUL in a plain delta forces a reparse so the snapshot matches a fresh parse. +- Streaming: under `hideUriLikeLabels`, a label ending in a bare `scheme:` stays visible until its `/` arrives; `isUriLikeLabel('fhir:')` is false. +- Fix (view): measuring a `height: 'auto'` embed no longer reprojects and re-renders every run; a failed `Image.getSize` is not retried on every streaming snapshot; decoration inset resolution is O(n log n) in marks (8,000-item list: 111 ms to 2 ms); non-finite theme numbers are dropped before the bridge. +- iOS: a snapshot no longer pays a full attributed-string compare and copy before the splice. +- Packaging: `dist/view/codeBlocks` resolves under the `react-native` condition; the podspec declares iOS 15.1, React Native 0.82's floor; `npm run release` and the release workflow refuse a BREAKING entry under a version that is not a minor bump; CI pins `node-gyp`. +- Docs: a standalone list is one `` whose markers copy (0.13.1's notes said otherwise); the selection-menu items never write the clipboard; `native/node` ships in the tarball; the theme has an `html` group and `html` takes an object form; open-ended HTML blocks under `'strip'`; corrected widening examples and test counts. + ## [0.13.1] — 2026-10-02 +Carries three BREAKING entries under a patch number, against the policy above: 0.13.0 was never published, and v0.12.0 was tagged but reached neither npm nor a GitHub release. The release guard now refuses a break under a patch version. + - BREAKING: complete `MarkdownTheme` objects now require `colors.highlight`, `table.frame`, `table.hideEmptyHeader`, `blocks`, `list`, `link`, and `html`. Use `mergeTheme(overrides)` to fill defaults before passing a theme to the run resolvers, or update complete theme literals. - Theme: `blocks` group of per-kind margins (`paragraph`, `heading`, `list`, `listItem`, `quote`, `code`, `table`, `rule`, `firstBlockLead`), collapsed web-style and measured from box edges. In a run each margin is the height of the separator's blank line, so selection offsets do not move. Unset, spacing is unchanged. @@ -115,6 +132,8 @@ Versions follow [semver](https://semver.org/); pre-1.0, breaking changes land in - `` renders the session's snapshot; the session owns its parse context. - Tests are excluded from the published tarball. -[Unreleased]: https://github.com/superpowerdotcom/react-native-selectable-markdown/compare/v0.11.0...HEAD +[Unreleased]: https://github.com/superpowerdotcom/react-native-selectable-markdown/compare/v0.13.1...HEAD +[0.13.1]: https://github.com/superpowerdotcom/react-native-selectable-markdown/releases/tag/v0.13.1 +[0.12.0]: https://github.com/superpowerdotcom/react-native-selectable-markdown/compare/v0.11.0...v0.12.0 [0.11.0]: https://github.com/superpowerdotcom/react-native-selectable-markdown/releases/tag/v0.11.0 [0.10.0]: https://github.com/superpowerdotcom/react-native-selectable-markdown/releases/tag/v0.10.0 diff --git a/README.md b/README.md index ea0e29d..a739779 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,15 @@ export function Message({ markdown }: { markdown: string }) { onSelectionCopy={({ action, plain, markdown, span }) => { // action: which item was tapped. plain: the selected display text. // markdown: exact source slice. span: UTF-16 range into the source. + // The items only report. Write the clipboard here, e.g. + // Clipboard.setString(action === 'copy-markdown' ? markdown : plain). }} /> ); } ``` -`selectionActions` needs `onSelectionCopy`: with no handler the custom menu is empty rather than one item short, because an item that reports nowhere is not offered (DEV warns). The reverse is not true — a handler on its own is the common case and gets both default items. An entry may also be `{ id, title }`, which is the one way to localise both platforms from JS; any id beyond the two built-ins is your own action and must carry a title, and it arrives at `onSelectionCopy` with the same `plain`, `markdown` and `span`. A `session` supersedes `source`, which is then never parsed (DEV warns). +`selectionActions` needs `onSelectionCopy`: with no handler the custom menu is empty rather than one item short, because an item that reports nowhere is not offered (DEV warns). Neither built-in item writes the clipboard itself: the handler does, with whichever clipboard module the app already uses. The reverse is not true — a handler on its own is the common case and gets both default items. An entry may also be `{ id, title }`, which is the one way to localise both platforms from JS; any id beyond the two built-ins is your own action and must carry a title, and it arrives at `onSelectionCopy` with the same `plain`, `markdown` and `span`. A `session` supersedes `source`, which is then never parsed (DEV warns). For a toolbar of your own, `onSelectionChange` reports `{ span, plain }` as the user drags and `null` when the selection goes away — the half `onSelectionCopy` cannot give you, since it fires only after a menu item is tapped. A `ref` typed `SelectableMarkdownHandle` adds `getSelection()`, `clearSelection()` and `setSelection(span)`. `setSelection` returns `false` for two kinds of refusal: no run shows the span (past the end of the document, a standalone block, a span of pure markup like a fence or a `# `, a run not mounted yet), or the run that shows it cannot take a selection right now (Android's unsettled streaming tail, a run rendered `selectable={false}`, a binary built against a native spec older than the selection commands). It can select wider than asked when the span lands inside an entity, an image's alt text or an embed placeholder, and it presents no menu and issues no scroll — there is no scroll-to-span, though it does take focus, which a scrolling ancestor is entitled to react to. Full contract in [docs/SELECTION.md](docs/SELECTION.md). @@ -130,7 +132,7 @@ function AssistantMessage(props: { events: TextMessageEvents; messageId: string The session finalizes on message end and on run finished or failed, since an aborted stream never sends END; a `messageId` switch settles the outgoing session as `'aborted'` rather than stranding it mid-stream, and it stays in the hook's map, so switching back shows the settled document. The third argument is either bare parse options, as above, or a full session init — `{ engine, options, coalesce, smoother, holdBackChars, holdIdleMs, repair, bufferScheduler, idleScheduler, now }`, where `smoother` is a factory because there is one session per messageId. Each delta commits on its own unless the init carries a buffering field (`smoother`, `holdBackChars`, `holdIdleMs`, either scheduler) or an explicit `coalesce: true`; `repair` and `now` deliberately do not switch coalescing on. Every field is latched when a messageId's session is created, so changing the init later reaches the next new message, not the one already streaming. What the per-message adapter does not do is hold at run end: neither `useAgUiSession` nor `bindMessageEvents` calls `notifyRunFinalized`, so run end finalizes straight through a metered tail — a smoothed reveal commits the rest in one revision instead of playing it out. -For a transport that owns a whole run, `bindRunTextEvents(events, store, policy?)` and its hook `useAgUiRunSessions(events, init?)` (the same session fields, plus `policy`) manage per-message sessions: they seed pre-existing messages without re-typing, route new ones through `appendBuffered`, and report `holding: true` until every smoother has drained at run end. Policy fields are documented on `RunBindingPolicy`. The three run-lifecycle callbacks take an optional trailing `runId`; pass it when the transport has one, and `bindRunTextEvents` ignores a late run finished or failed from a run it already watched go spent. An id stops being spent the moment that run starts again — announce a retry that reuses it with `onRunStarted` and it keeps its right to finalize — and `onAttached` catch-up clears the spent-run memory outright, since nothing learned before a gap the binding cannot see into is trustworthy. `bindMessageEvents` observes no run start and filters nothing. +For a transport that owns a whole run, `bindRunTextEvents(events, store, policy?)` and its hook `useAgUiRunSessions(events, init?)` (the same session fields except `coalesce`, which its buffering fields imply, plus `policy`) manage per-message sessions: they seed pre-existing messages without re-typing, route new ones through `appendBuffered`, and report `holding: true` until every smoother has drained at run end. Policy fields are documented on `RunBindingPolicy`. The three run-lifecycle callbacks take an optional trailing `runId`; pass it when the transport has one, and `bindRunTextEvents` ignores a late run finished or failed from a run it already watched go spent. An id stops being spent the moment that run starts again — announce a retry that reuses it with `onRunStarted` and it keeps its right to finalize — and `onAttached` catch-up clears the spent-run memory outright, since nothing learned before a gap the binding cannot see into is trustworthy. `bindMessageEvents` observes no run start and filters nothing. ### Headless @@ -157,7 +159,7 @@ const theme: PartialTheme = { ``` -Overrides merge one level deep over a base theme. The groups are `colors`, `fonts`, `spacing`, `code`, `quote`, `table`, `headings`, `rule`, `glyphs`, `blocks`, `list` and `link`. `colorScheme` is `'light'`, `'dark'` or `'auto'` (the default; follows the system). `mergeTheme(overrides, base)` computes a theme ahead of render. `glyphs` (bullet and task markers) are part of the projected text, so changing them shifts selection offsets; the library handles that. The font keys are `body`, `mono`, `baseSize`, `lineHeight`, `strongWeight` and the optional `strongFamily`; an unknown token is ignored, with a DEV warning. Four tokens also cross groups, each only when the token it feeds is not itself overridden: `code.borderRadius` feeds `table.borderRadius` (squaring your code blocks squares your tables), and the deprecated `spacing.quoteIndent`, `spacing.tableCellPadding` and `colors.quoteBar` feed `quote.indent`, `table.cellPaddingH`/`cellPaddingV` and `quote.barColor`. +Overrides merge one level deep over a base theme. The groups are `colors`, `fonts`, `spacing`, `code`, `quote`, `table`, `headings`, `rule`, `glyphs`, `blocks`, `list`, `link` and `html`. `colorScheme` is `'light'`, `'dark'` or `'auto'` (the default; follows the system). `mergeTheme(overrides, base)` computes a theme ahead of render. `glyphs` (bullet and task markers) are part of the projected text, so changing them shifts selection offsets; the library handles that. The font keys are `body`, `mono`, `baseSize`, `lineHeight`, `strongWeight` and the optional `strongFamily`; an unknown token is ignored, with a DEV warning. Four tokens also cross groups, each only when the token it feeds is not itself overridden: `code.borderRadius` feeds `table.borderRadius` (squaring your code blocks squares your tables), and the deprecated `spacing.quoteIndent`, `spacing.tableCellPadding` and `colors.quoteBar` feed `quote.indent`, `table.cellPaddingH`/`cellPaddingV` and `quote.barColor`. To style one mark rather than a construct (a heading ramp, a bold face instead of a weight bump), pass `attributeForMark`. Give it a stable identity; it takes part in the per-run memo. @@ -255,9 +257,10 @@ No options (or `presets.commonmark`) turns every extension off — not a spec-co | `math` | off | off | `$5 and $10` must never become math. | | `spoilers` | off | off | On only in `everything`. Parses only a balanced `\|\|x\|\|` inside one paragraph or heading; a stray `\|` stays text. | | `underline` | off | off | `_` stops meaning emphasis. On only in `everything`. | -| `smartPunctuation` | off | off | Smart quotes and dashes in prose only; code and URLs stay byte-exact. On in `everything`. | -| `html` | `'strip'` | `'strip'` | `'strip'` drops an HTML block with the lines it covers — a `
`, a `
` or a raw `` contributes nothing to the document — and drops inline tags while keeping the text between them. `
` is the exception: it becomes a hard break spanning the tag. `'raw'` keeps both as `htmlBlock` / `htmlSpan` nodes. | -| Link prefixes | `https://`, `http://`, `mailto:` | same | A case-insensitive prefix test, not scheme parsing: `https:example.com` matches nothing and renders as plain text, not a dead link. Your list replaces this one; spread `DEFAULT_LINK_PREFIXES` to keep it. A prefix reaching into a path (`myapp://checkout/`) is a scope: a destination whose path climbs back out of it with `..` (raw or percent-encoded once) is refused, one that descends and returns (`a/../b`) is not, and a `..` inside a query string or fragment is left alone. | +| `smartPunctuation` | off | off | Smart quotes and dashes in prose only; code and URLs stay byte-exact. Quotes pair the way `cmark --smart` pairs them, so an unpaired `"` renders as the closing form. On in `everything`. | +| `maxSourceLength` | 1,048,576 | same | The longest source `parseDocument` accepts, in UTF-16 units; longer input throws a `RangeError` before anything is parsed, from a session's `append` too. `Infinity` opts out. The native parse keeps one event per construct in memory, and node-dense text (`*a*a*a…`) amplifies its size by two orders of magnitude. | +| `html` | `'strip'` | `'strip'` | `'strip'` drops an HTML block with the lines it covers — a `
`, a `
` or a raw `
` contributes nothing to the document — and drops inline tags while keeping the text between them. `
` is the exception: it becomes a hard break spanning the tag. A block opening with `