@multiplatform.one/components 7.47.0 → 7.47.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 (44) hide show
  1. package/dist/cjs/OverflowRow/index.cjs +64 -2
  2. package/dist/cjs/OverflowRow/index.native.js +67 -2
  3. package/dist/cjs/OverflowRow/index.native.js.map +1 -1
  4. package/dist/cjs/code/Highlighter/index.cjs +9 -2
  5. package/dist/cjs/code/Highlighter/index.native.js +13 -2
  6. package/dist/cjs/code/Highlighter/index.native.js.map +1 -1
  7. package/dist/cjs/code/Highlighter/namedGroupMatchAll.cjs +96 -0
  8. package/dist/cjs/code/Highlighter/namedGroupMatchAll.native.js +108 -0
  9. package/dist/cjs/code/Highlighter/namedGroupMatchAll.native.js.map +1 -0
  10. package/dist/esm/OverflowRow/index.mjs +66 -4
  11. package/dist/esm/OverflowRow/index.mjs.map +1 -1
  12. package/dist/esm/OverflowRow/index.native.js +69 -4
  13. package/dist/esm/OverflowRow/index.native.js.map +1 -1
  14. package/dist/esm/code/Highlighter/index.mjs +9 -2
  15. package/dist/esm/code/Highlighter/index.mjs.map +1 -1
  16. package/dist/esm/code/Highlighter/index.native.js +13 -2
  17. package/dist/esm/code/Highlighter/index.native.js.map +1 -1
  18. package/dist/esm/code/Highlighter/namedGroupMatchAll.mjs +70 -0
  19. package/dist/esm/code/Highlighter/namedGroupMatchAll.mjs.map +1 -0
  20. package/dist/esm/code/Highlighter/namedGroupMatchAll.native.js +79 -0
  21. package/dist/esm/code/Highlighter/namedGroupMatchAll.native.js.map +1 -0
  22. package/dist/jsx/OverflowRow/index.mjs +66 -4
  23. package/dist/jsx/OverflowRow/index.mjs.map +1 -1
  24. package/dist/jsx/OverflowRow/index.native.js +67 -2
  25. package/dist/jsx/OverflowRow/index.native.js.map +1 -1
  26. package/dist/jsx/code/Highlighter/index.mjs +9 -2
  27. package/dist/jsx/code/Highlighter/index.mjs.map +1 -1
  28. package/dist/jsx/code/Highlighter/index.native.js +13 -2
  29. package/dist/jsx/code/Highlighter/index.native.js.map +1 -1
  30. package/dist/jsx/code/Highlighter/namedGroupMatchAll.mjs +70 -0
  31. package/dist/jsx/code/Highlighter/namedGroupMatchAll.mjs.map +1 -0
  32. package/dist/jsx/code/Highlighter/namedGroupMatchAll.native.js +108 -0
  33. package/dist/jsx/code/Highlighter/namedGroupMatchAll.native.js.map +1 -0
  34. package/package.json +9 -9
  35. package/src/OverflowRow/OverflowRow.native.spec.tsx +124 -1
  36. package/src/OverflowRow/index.tsx +102 -4
  37. package/src/code/CodeBlock/codeBlock.stories.ts +15 -0
  38. package/src/code/Highlighter/Highlighter.native.spec.ts +76 -0
  39. package/src/code/Highlighter/index.ts +16 -1
  40. package/src/code/Highlighter/namedGroupMatchAll.ts +90 -0
  41. package/types/OverflowRow/index.d.ts.map +1 -1
  42. package/types/code/Highlighter/index.d.ts.map +1 -1
  43. package/types/code/Highlighter/namedGroupMatchAll.d.ts +22 -0
  44. package/types/code/Highlighter/namedGroupMatchAll.d.ts.map +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/components",
3
- "version": "7.47.0",
3
+ "version": "7.47.2",
4
4
  "description": "multiplatform.one ui components",
5
5
  "keywords": [
6
6
  "components",
@@ -58,11 +58,11 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@floating-ui/react": "^0.27.20",
61
- "@multiplatform.one/forms": "^7.47.0",
62
- "@multiplatform.one/i18n": "^7.47.0",
63
- "@multiplatform.one/platform": "^7.47.0",
64
- "@multiplatform.one/router": "^7.47.0",
65
- "@multiplatform.one/theme": "^7.47.0",
61
+ "@multiplatform.one/forms": "^7.47.2",
62
+ "@multiplatform.one/i18n": "^7.47.2",
63
+ "@multiplatform.one/platform": "^7.47.2",
64
+ "@multiplatform.one/router": "^7.47.2",
65
+ "@multiplatform.one/theme": "^7.47.2",
66
66
  "@phosphor-icons/react": "^2.1.10",
67
67
  "@shopify/flash-list": "^2.3.1",
68
68
  "@tamagui/colors": "2.7.6",
@@ -89,9 +89,9 @@
89
89
  "tamagui": "2.7.6"
90
90
  },
91
91
  "devDependencies": {
92
- "@multiplatform.one/config": "7.47.0",
93
- "@multiplatform.one/storybook": "7.47.0",
94
- "@multiplatform.one/test-utils": "7.47.0",
92
+ "@multiplatform.one/config": "7.47.2",
93
+ "@multiplatform.one/storybook": "7.47.2",
94
+ "@multiplatform.one/test-utils": "7.47.2",
95
95
  "@tamagui/build": "2.7.6",
96
96
  "@testing-library/jest-dom": "^7.0.1",
97
97
  "@testing-library/react": "^16.3.3",
@@ -1,4 +1,4 @@
1
- import { act, createElement, createRef } from "react";
1
+ import { act, createElement, createRef, type ReactElement } from "react";
2
2
  import { createRoot, type Root } from "react-dom/client";
3
3
  import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
4
4
 
@@ -184,4 +184,127 @@ describe("OverflowRow through native Tamagui", () => {
184
184
  expect(fade("start")).toBeNull();
185
185
  expect(fade("end")).toBeNull();
186
186
  });
187
+
188
+ describe("selection rows (LC-136)", () => {
189
+ function Choice(_: { selected?: boolean; label: string }) {
190
+ return null;
191
+ }
192
+ const labels = ["a", "b", "c", "d", "e", "f"];
193
+ function choices(selected: string) {
194
+ return labels.map((label) =>
195
+ createElement(Choice, { key: label, label, selected: label === selected }),
196
+ );
197
+ }
198
+ function wrappers() {
199
+ const latest = new Map<string, Record<string, unknown>>();
200
+ for (const props of runtime.allHostProps("View")) {
201
+ const child = props.children as ReactElement<{ label?: string }> | undefined;
202
+ if (typeof props.onLayout === "function" && child?.type === Choice)
203
+ latest.set(child.props.label!, props);
204
+ }
205
+ return latest;
206
+ }
207
+ function layout(sizes: { viewport: number; content: number }) {
208
+ call("onLayout", { nativeEvent: { layout: { width: sizes.viewport, height: 40 } } });
209
+ call("onContentSizeChange", sizes.content, 40);
210
+ for (const [label, props] of wrappers()) {
211
+ const i = labels.indexOf(label);
212
+ act(() =>
213
+ (props.onLayout as (event: unknown) => void)({
214
+ nativeEvent: { layout: { x: i * 100, y: 0, width: 90, height: 40 } },
215
+ }),
216
+ );
217
+ }
218
+ }
219
+ function scrollSpy() {
220
+ const scrollTo = vi.fn();
221
+ Object.assign(runtime.hostInstance("ScrollView"), { scrollTo });
222
+ return scrollTo;
223
+ }
224
+
225
+ it("opens with an offscreen selected choice in view, without animating", () => {
226
+ (runtime.reactNative.Platform as { OS: string }).OS = "ios";
227
+ const scrollTo = scrollSpy();
228
+ render({ children: choices("f") });
229
+ layout({ viewport: 200, content: 590 });
230
+ expect(scrollTo).toHaveBeenCalledExactlyOnceWith({ x: 390, animated: false });
231
+ });
232
+
233
+ it("leaves a visible selection, the user's scroll and a later visible pick alone", () => {
234
+ const scrollTo = scrollSpy();
235
+ render({ children: choices("b") });
236
+ layout({ viewport: 200, content: 590 });
237
+ expect(scrollTo).not.toHaveBeenCalled();
238
+ scroll(300);
239
+ expect(scrollTo).not.toHaveBeenCalled();
240
+ act(() =>
241
+ root.render(
242
+ createElement(
243
+ TamaguiProvider,
244
+ { config, defaultTheme: "light" },
245
+ createElement(OverflowRow, { children: choices("d") }),
246
+ ),
247
+ ),
248
+ );
249
+ expect(scrollTo).not.toHaveBeenCalled();
250
+ });
251
+
252
+ it("scrolls back to a selection that moved off the start", () => {
253
+ const scrollTo = scrollSpy();
254
+ render({ children: choices("e") });
255
+ layout({ viewport: 200, content: 590 });
256
+ expect(scrollTo).toHaveBeenLastCalledWith({ x: 290, animated: false });
257
+ scroll(390);
258
+ act(() =>
259
+ root.render(
260
+ createElement(
261
+ TamaguiProvider,
262
+ { config, defaultTheme: "light" },
263
+ createElement(OverflowRow, { children: choices("a") }),
264
+ ),
265
+ ),
266
+ );
267
+ expect(scrollTo).toHaveBeenLastCalledWith({ x: 0, animated: true });
268
+ });
269
+
270
+ it("follows a selected chip that grows when it takes its check", () => {
271
+ const scrollTo = scrollSpy();
272
+ render({ children: choices("a") });
273
+ layout({ viewport: 200, content: 590 });
274
+ expect(scrollTo).not.toHaveBeenCalled();
275
+ act(() =>
276
+ root.render(
277
+ createElement(
278
+ TamaguiProvider,
279
+ { config, defaultTheme: "light" },
280
+ createElement(OverflowRow, { children: choices("c") }),
281
+ ),
282
+ ),
283
+ );
284
+ expect(scrollTo).toHaveBeenLastCalledWith({ x: 90, animated: true });
285
+ const grown = () =>
286
+ act(() =>
287
+ (wrappers().get("c")!.onLayout as (event: unknown) => void)({
288
+ nativeEvent: { layout: { x: 200, y: 0, width: 110, height: 40 } },
289
+ }),
290
+ );
291
+ grown();
292
+ expect(scrollTo).toHaveBeenLastCalledWith({ x: 110, animated: true });
293
+ grown();
294
+ expect(scrollTo).toHaveBeenCalledTimes(2);
295
+ });
296
+
297
+ it("keeps an RTL row at its start and a row without selection unwrapped", () => {
298
+ (runtime.reactNative.I18nManager as { isRTL: boolean }).isRTL = true;
299
+ const scrollTo = scrollSpy();
300
+ render({ children: choices("f") });
301
+ layout({ viewport: 200, content: 590 });
302
+ expect(scrollTo).not.toHaveBeenCalled();
303
+ act(() => root.unmount());
304
+ runtime.resetHosts();
305
+ (runtime.reactNative.I18nManager as { isRTL: boolean }).isRTL = false;
306
+ render({ children: labels.map((label) => createElement(Choice, { key: label, label })) });
307
+ expect(wrappers().size).toBe(0);
308
+ });
309
+ });
187
310
  });
@@ -1,6 +1,16 @@
1
1
  import { getRgba } from "@tamagui/core";
2
2
  import { useResolvedKnobs, type SizeKey } from "@multiplatform.one/theme";
3
- import { forwardRef, useEffect, useState, type ComponentRef } from "react";
3
+ import {
4
+ Children,
5
+ forwardRef,
6
+ isValidElement,
7
+ useCallback,
8
+ useEffect,
9
+ useRef,
10
+ useState,
11
+ type ComponentRef,
12
+ type ReactNode,
13
+ } from "react";
4
14
  import {
5
15
  XStack,
6
16
  YStack,
@@ -10,7 +20,7 @@ import {
10
20
  type SpaceTokens,
11
21
  type YStackProps,
12
22
  } from "tamagui";
13
- import { Platform } from "react-native";
23
+ import { Platform, View, type LayoutChangeEvent } from "react-native";
14
24
  import { useDirection } from "../hooks/useDirection";
15
25
  import { LinearGradient } from "tamagui/linear-gradient";
16
26
  import { ScrollView, type ScrollViewProps } from "../ScrollView";
@@ -23,6 +33,28 @@ export interface OverflowRowProps extends Omit<ScrollViewProps, "horizontal"> {
23
33
  containerProps?: Omit<YStackProps, "children">;
24
34
  }
25
35
 
36
+ type ScrollHandle = ComponentRef<typeof ScrollView> & {
37
+ scrollTo?: (options: { x: number; animated: boolean }) => void;
38
+ };
39
+
40
+ function keyOf(child: ReactNode, index: number): string {
41
+ return isValidElement(child) && child.key != null ? String(child.key) : String(index);
42
+ }
43
+
44
+ /** The selected child's key; null when no child is selected, undefined when none takes `selected`. */
45
+ function selectionOf(items: ReactNode[]): string | null | undefined {
46
+ let selectable = false;
47
+ let key: string | null = null;
48
+ items.forEach((child, i) => {
49
+ if (!isValidElement(child)) return;
50
+ const selected = (child.props as { selected?: unknown }).selected;
51
+ if (selected === undefined) return;
52
+ selectable = true;
53
+ if (selected === true && key === null) key = keyOf(child, i);
54
+ });
55
+ return selectable ? key : undefined;
56
+ }
57
+
26
58
  export const OverflowRow = forwardRef<ComponentRef<typeof ScrollView>, OverflowRowProps>(
27
59
  function OverflowRow(
28
60
  {
@@ -52,6 +84,20 @@ export const OverflowRow = forwardRef<ComponentRef<typeof ScrollView>, OverflowR
52
84
  const rgba = getRgba(surfaceColor);
53
85
  const clearColor = rgba ? `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, 0)` : "transparent";
54
86
  const initialOffsetX = props.contentOffset?.x;
87
+ const items = Children.toArray(children);
88
+ const selectedKey = selectionOf(items);
89
+ const scrollRef = useRef<ScrollHandle | null>(null);
90
+ const setScrollRef = useCallback(
91
+ (node: ScrollHandle | null) => {
92
+ scrollRef.current = node;
93
+ if (typeof ref === "function") ref(node);
94
+ else if (ref) ref.current = node;
95
+ },
96
+ [ref],
97
+ );
98
+ const boxes = useRef(new Map<string, { x: number; width: number }>());
99
+ const revealed = useRef<{ key: string; x: number; width: number } | undefined>(undefined);
100
+ const [selectedLayout, setSelectedLayout] = useState(0);
55
101
  const [measurements, setMeasurements] = useState({
56
102
  viewport: 0,
57
103
  content: 0,
@@ -85,6 +131,42 @@ export const OverflowRow = forwardRef<ComponentRef<typeof ScrollView>, OverflowR
85
131
  end: measurements.viewport > 0 && maxOffset - offset > 1,
86
132
  };
87
133
 
134
+ const fadeInset =
135
+ fade === false
136
+ ? 0
137
+ : Number(getTokenValue(fade as Parameters<typeof getTokenValue>[0], "size")) || 0;
138
+ // LC-136: a selection row opens with its selected choice in view (a preset
139
+ // switch remounts the picker at offset 0). RTL offsets differ per platform,
140
+ // so RTL rows keep their start.
141
+ useEffect(() => {
142
+ if (rtl || selectedKey == null) return;
143
+ const box = boxes.current.get(selectedKey);
144
+ if (!box || measurements.viewport <= 0 || measurements.content <= 0) return;
145
+ // A chip grows when it takes its check, after this effect first sees it,
146
+ // so a new box for the same selection is revealed again.
147
+ const last = revealed.current;
148
+ if (last?.key === selectedKey && last.x === box.x && last.width === box.width) return;
149
+ const first = last === undefined;
150
+ revealed.current = { key: selectedKey, ...box };
151
+ const start = box.x - fadeInset;
152
+ const end = box.x + box.width + fadeInset - measurements.viewport;
153
+ const target = start < offset ? start : end > offset ? end : undefined;
154
+ if (target === undefined) return;
155
+ scrollRef.current?.scrollTo?.({
156
+ x: Math.max(0, Math.min(target, maxOffset)),
157
+ animated: !first,
158
+ });
159
+ }, [
160
+ rtl,
161
+ selectedKey,
162
+ selectedLayout,
163
+ measurements.viewport,
164
+ measurements.content,
165
+ fadeInset,
166
+ offset,
167
+ maxOffset,
168
+ ]);
169
+
88
170
  function measure(next: Partial<typeof measurements>) {
89
171
  setMeasurements((previous) => ({ ...previous, ...next }));
90
172
  }
@@ -95,7 +177,7 @@ export const OverflowRow = forwardRef<ComponentRef<typeof ScrollView>, OverflowR
95
177
  showsHorizontalScrollIndicator={showsHorizontalScrollIndicator}
96
178
  scrollEventThrottle={scrollEventThrottle}
97
179
  {...props}
98
- ref={ref}
180
+ ref={setScrollRef}
99
181
  horizontal
100
182
  onLayout={(event) => {
101
183
  measure({ viewport: event.nativeEvent.layout.width });
@@ -117,7 +199,23 @@ export const OverflowRow = forwardRef<ComponentRef<typeof ScrollView>, OverflowR
117
199
  }}
118
200
  >
119
201
  <XStack alignItems="center" {...knobProps.gap} {...(gap === undefined ? {} : { gap })}>
120
- {children}
202
+ {selectedKey === undefined
203
+ ? children
204
+ : items.map((child, i) => {
205
+ const key = keyOf(child, i);
206
+ return (
207
+ <View
208
+ key={key}
209
+ onLayout={(event: LayoutChangeEvent) => {
210
+ const { x, width } = event.nativeEvent.layout;
211
+ boxes.current.set(key, { x, width });
212
+ if (key === selectedKey) setSelectedLayout((n) => n + 1);
213
+ }}
214
+ >
215
+ {child}
216
+ </View>
217
+ );
218
+ })}
121
219
  </XStack>
122
220
  </ScrollView>
123
221
  {fade !== false && edges.start ? (
@@ -29,3 +29,18 @@ function howdy() {
29
29
  };
30
30
 
31
31
  export default meta;
32
+
33
+ export const shell: StoryObj<typeof CodeBlock> = {
34
+ name: "Shell",
35
+ args: {
36
+ backgroundColor: "$color2",
37
+ language: "bash",
38
+ children: `#!/bin/sh
39
+ set -eu
40
+ for f in scripts/*.sh; do
41
+ echo "lint $f" | grep -v skip # FZ-7829
42
+ shfmt -d "$f"
43
+ done
44
+ `,
45
+ },
46
+ };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * FZ-7829. On Hermes, `String.prototype.matchAll` returns matches whose
3
+ * `groups` is undefined (its @@matchAll copies the regex without the
4
+ * group-name mapping). shiki's JS regex engine converts grammars through
5
+ * helpers that read `match.groups` from `matchAll`, so on iOS shell and python
6
+ * came back as plain lines. This suite gives Node that same matchAll and
7
+ * asserts the shipped languages still come back coloured.
8
+ */
9
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
10
+ import { highlightCode } from "./index";
11
+ import { resetNamedGroupMatchAllProbe, withNamedGroupMatchAll } from "./namedGroupMatchAll";
12
+
13
+ const nativeMatchAll = String.prototype.matchAll;
14
+
15
+ function hermesMatchAll(this: string, regexp: RegExp): IterableIterator<RegExpExecArray> {
16
+ const inner = nativeMatchAll.call(this, regexp);
17
+ const iterator: IterableIterator<RegExpExecArray> = {
18
+ next() {
19
+ const step = inner.next();
20
+ if (!step.done) step.value.groups = undefined;
21
+ return step;
22
+ },
23
+ [Symbol.iterator]() {
24
+ return iterator;
25
+ },
26
+ };
27
+ return iterator;
28
+ }
29
+
30
+ const colours = (lines: { color?: string }[][]) =>
31
+ new Set(lines.flat().flatMap((token) => (token.color ? [token.color] : [])));
32
+
33
+ const snippets: Record<string, string> = {
34
+ bash: 'set -eu\nfor f in *.sh; do\n echo "lint $f" | grep -v skip # note\ndone',
35
+ typescript: "const x: number = 1; // c",
36
+ javascript: "function f(a) { return `${a}`; }",
37
+ json: '{"a": [1, true, null]}',
38
+ yaml: 'a: 1\nb: [x, "y"]',
39
+ python: "def f(x):\n return x + 1 # c",
40
+ };
41
+
42
+ describe("highlightCode under Hermes's matchAll", () => {
43
+ beforeAll(() => {
44
+ String.prototype.matchAll = hermesMatchAll as typeof nativeMatchAll;
45
+ resetNamedGroupMatchAllProbe();
46
+ });
47
+
48
+ afterAll(() => {
49
+ String.prototype.matchAll = nativeMatchAll;
50
+ resetNamedGroupMatchAllProbe();
51
+ });
52
+
53
+ it("the emulation drops named groups the way Hermes does", () => {
54
+ const first = "x".matchAll(new RegExp("(?<g>x)", "g")).next().value;
55
+ expect(first?.groups).toBeUndefined();
56
+ });
57
+
58
+ it("colours a shell snippet", { timeout: 60000 }, async () => {
59
+ const lines = await highlightCode(snippets.bash!, "bash");
60
+ expect(lines.map((line) => line.map((token) => token.content).join("")).join("\n")).toBe(
61
+ snippets.bash,
62
+ );
63
+ expect(colours(lines).size).toBeGreaterThan(1);
64
+ expect([...colours(lines)].some((colour) => colour.startsWith("$syntax"))).toBe(true);
65
+ });
66
+
67
+ it.each(Object.keys(snippets))("colours %s", { timeout: 60000 }, async (language) => {
68
+ const lines = await highlightCode(snippets[language]!, language);
69
+ expect(colours(lines).size).toBeGreaterThan(1);
70
+ });
71
+
72
+ it("puts the engine's matchAll back after converting", () => {
73
+ expect(withNamedGroupMatchAll(() => String.prototype.matchAll)).not.toBe(hermesMatchAll);
74
+ expect(String.prototype.matchAll).toBe(hermesMatchAll);
75
+ });
76
+ });
@@ -8,6 +8,7 @@
8
8
 
9
9
  import { createContext, useContext, useEffect, useState } from "react";
10
10
  import { houseSyntaxTheme } from "./houseSyntaxTheme";
11
+ import { withNamedGroupMatchAll } from "./namedGroupMatchAll";
11
12
 
12
13
  export * from "./houseSyntaxTheme";
13
14
 
@@ -78,6 +79,15 @@ function plainTextTokens(code: string): HighlightLine[] {
78
79
  // of an eager preload.
79
80
  let highlighterPromise: Promise<any> | null = null;
80
81
 
82
+ // shiki stops a line at 500ms by default and returns the rest as one plain
83
+ // token. The JS engine converts a grammar's regexes lazily inside that clock,
84
+ // so on Hermes (no JIT) or a loaded CPU the first lines of a big grammar like
85
+ // TypeScript ran out of time and came back uncoloured; any wall-clock budget
86
+ // flakes the same way. The clock is off, and a line too long to tokenize
87
+ // cheaply stays plain instead.
88
+ const tokenizeTimeLimit = 0;
89
+ const tokenizeMaxLineLength = 5000;
90
+
81
91
  function getHighlighter(): Promise<any> {
82
92
  if (!highlighterPromise) {
83
93
  highlighterPromise = Promise.all([import("shiki"), import("shiki/engine/javascript")]).then(
@@ -85,7 +95,10 @@ function getHighlighter(): Promise<any> {
85
95
  shiki.createHighlighter({
86
96
  themes: [],
87
97
  langs: [],
88
- engine: jsEngine.createJavaScriptRegexEngine(),
98
+ engine: jsEngine.createJavaScriptRegexEngine({
99
+ regexConstructor: (pattern: string) =>
100
+ withNamedGroupMatchAll(() => jsEngine.defaultJavaScriptRegexConstructor(pattern)),
101
+ }),
89
102
  }),
90
103
  );
91
104
  }
@@ -119,6 +132,8 @@ export async function highlightCode(
119
132
  const result = highlighter.codeToTokens(code, {
120
133
  lang: lang as any,
121
134
  theme: theme as any,
135
+ tokenizeTimeLimit,
136
+ tokenizeMaxLineLength,
122
137
  });
123
138
  return result.tokens.map((line: any[]) =>
124
139
  line.map((token) => ({
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Hermes drops named groups from `String.prototype.matchAll` results.
3
+ *
4
+ * `RegExp.prototype[@@matchAll]` copies the regex through a fast path that
5
+ * reuses the compiled bytecode but never copies the group-name mapping
6
+ * (`JSRegExp::initialize(self, other, flags)`, hermes rn/0.83-stable and main),
7
+ * so every match comes back with `groups === undefined` while `exec` on the
8
+ * same regex is fine. shiki's JavaScript engine converts Oniguruma patterns
9
+ * with `oniguruma-to-es`, whose `regex` / `regex-utilities` helpers destructure
10
+ * `match.groups` from `matchAll`; on Hermes that throws, `highlightCode`
11
+ * catches it, and shell, python and every grammar that reaches those helpers
12
+ * render as uncoloured lines (FZ-7829).
13
+ */
14
+
15
+ let dropsGroups: boolean | undefined;
16
+
17
+ function matchAllDropsGroups(): boolean {
18
+ if (dropsGroups === undefined) {
19
+ try {
20
+ // Built from a string so Babel's named-groups transform leaves it native.
21
+ const first = "x".matchAll(new RegExp("(?<g>x)", "g")).next().value;
22
+ dropsGroups = !!first && first.groups === undefined;
23
+ } catch {
24
+ dropsGroups = false;
25
+ }
26
+ }
27
+ return dropsGroups;
28
+ }
29
+
30
+ function advance(str: string, index: number, unicode: boolean): number {
31
+ if (!unicode || index + 1 >= str.length) return index + 1;
32
+ const code = str.charCodeAt(index);
33
+ if (code < 0xd800 || code > 0xdbff) return index + 1;
34
+ const next = str.charCodeAt(index + 1);
35
+ return next >= 0xdc00 && next <= 0xdfff ? index + 2 : index + 1;
36
+ }
37
+
38
+ function matchAllViaExec(str: string, regexp: RegExp): IterableIterator<RegExpExecArray> {
39
+ // A string pattern takes Hermes's full compile path, which keeps the names.
40
+ const matcher = new RegExp(regexp.source, regexp.flags);
41
+ matcher.lastIndex = regexp.lastIndex;
42
+ const unicode = regexp.unicode || regexp.flags.includes("v");
43
+ let done = false;
44
+ const iterator: IterableIterator<RegExpExecArray> = {
45
+ next() {
46
+ if (done) return { value: undefined, done: true };
47
+ const match = matcher.exec(str);
48
+ if (!match) {
49
+ done = true;
50
+ return { value: undefined, done: true };
51
+ }
52
+ if (match[0] === "") matcher.lastIndex = advance(str, matcher.lastIndex, unicode);
53
+ return { value: match, done: false };
54
+ },
55
+ [Symbol.iterator]() {
56
+ return iterator;
57
+ },
58
+ };
59
+ return iterator;
60
+ }
61
+
62
+ /**
63
+ * Runs `fn` with a `String.prototype.matchAll` that keeps named groups, only
64
+ * on an engine that loses them, and puts the native method back afterwards.
65
+ * Everywhere else it just calls `fn`.
66
+ */
67
+ export function withNamedGroupMatchAll<T>(fn: () => T): T {
68
+ if (!matchAllDropsGroups()) return fn();
69
+ const native = String.prototype.matchAll;
70
+ String.prototype.matchAll = function matchAll(this: string, regexp: RegExp) {
71
+ if (
72
+ regexp instanceof RegExp &&
73
+ Object.getPrototypeOf(regexp) === RegExp.prototype &&
74
+ regexp.global
75
+ ) {
76
+ return matchAllViaExec(String(this), regexp);
77
+ }
78
+ return native.call(this, regexp);
79
+ } as typeof native;
80
+ try {
81
+ return fn();
82
+ } finally {
83
+ String.prototype.matchAll = native;
84
+ }
85
+ }
86
+
87
+ /** Test hook: forget the cached engine probe. */
88
+ export function resetNamedGroupMatchAllProbe(): void {
89
+ dropsGroups = undefined;
90
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/OverflowRow/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,wBAAwB,CAAC;AAEhC,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC;IAC3E,IAAI,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IACvB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,cAAc,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;CAChD;AAED,eAAO,MAAM,WAAW,gIAwIvB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/OverflowRow/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAY1E,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,wBAAwB,CAAC;AAEhC,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC;IAC3E,IAAI,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IACvB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,cAAc,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;CAChD;AAwBD,eAAO,MAAM,WAAW,gIA0MvB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code/Highlighter/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,cAAc,oBAAoB,CAAC;AAEnC,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,wFAAwF;IACxF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,cAAc,EAAE,CAAC;AAE7C,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,YAAY,4CAAuC,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,aAAa,EAAE,GAAG,IAAI,CA0BxB;AA4BD;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,SAAwB,GAC5B,OAAO,CAAC,aAAa,EAAE,CAAC,CA8B1B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/code/Highlighter/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,cAAc,oBAAoB,CAAC;AAEnC,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,wFAAwF;IACxF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,cAAc,EAAE,CAAC;AAE7C,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,YAAY,4CAAuC,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,aAAa,EAAE,GAAG,IAAI,CA0BxB;AAwCD;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,SAAwB,GAC5B,OAAO,CAAC,aAAa,EAAE,CAAC,CAgC1B"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Hermes drops named groups from `String.prototype.matchAll` results.
3
+ *
4
+ * `RegExp.prototype[@@matchAll]` copies the regex through a fast path that
5
+ * reuses the compiled bytecode but never copies the group-name mapping
6
+ * (`JSRegExp::initialize(self, other, flags)`, hermes rn/0.83-stable and main),
7
+ * so every match comes back with `groups === undefined` while `exec` on the
8
+ * same regex is fine. shiki's JavaScript engine converts Oniguruma patterns
9
+ * with `oniguruma-to-es`, whose `regex` / `regex-utilities` helpers destructure
10
+ * `match.groups` from `matchAll`; on Hermes that throws, `highlightCode`
11
+ * catches it, and shell, python and every grammar that reaches those helpers
12
+ * render as uncoloured lines (FZ-7829).
13
+ */
14
+ /**
15
+ * Runs `fn` with a `String.prototype.matchAll` that keeps named groups, only
16
+ * on an engine that loses them, and puts the native method back afterwards.
17
+ * Everywhere else it just calls `fn`.
18
+ */
19
+ export declare function withNamedGroupMatchAll<T>(fn: () => T): T;
20
+ /** Test hook: forget the cached engine probe. */
21
+ export declare function resetNamedGroupMatchAllProbe(): void;
22
+ //# sourceMappingURL=namedGroupMatchAll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namedGroupMatchAll.d.ts","sourceRoot":"","sources":["../../../src/code/Highlighter/namedGroupMatchAll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAiDH;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAkBxD;AAED,iDAAiD;AACjD,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD"}