@dxos/react-ui-syntax-highlighter 0.10.0 → 0.11.1

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.
@@ -0,0 +1,259 @@
1
+ import { Children, forwardRef, useCallback, useMemo, useState } from "react";
2
+ import { Clipboard, Input, ScrollArea, composable, composableProps, useThemeContext } from "@dxos/react-ui";
3
+ import { createReplacer, safeStringify } from "@dxos/util";
4
+ import createElement from "react-syntax-highlighter/dist/esm/create-element";
5
+ import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
6
+ import { coldarkCold, coldarkDark } from "react-syntax-highlighter/dist/esm/styles/prism";
7
+ import { mx } from "@dxos/ui-theme";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ import { createContextScope } from "@radix-ui/react-context";
10
+ import { JSONPath } from "jsonpath-plus";
11
+ //#region src/SyntaxHighlighter/SyntaxHighlighter.tsx
12
+ var zeroWidthSpace = "​";
13
+ var languages = {
14
+ js: "javascript",
15
+ ts: "typescript"
16
+ };
17
+ /**
18
+ * Inline, non-scrolling wrapper around `react-syntax-highlighter`.
19
+ *
20
+ * Use directly for small snippets (e.g. inside markdown code blocks).
21
+ * For scrollable panels, compose with `Syntax.Viewport`.
22
+ *
23
+ * NOTE: Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.
24
+ * The lightweight version will load specific language parsers asynchronously.
25
+ *
26
+ * https://github.com/react-syntax-highlighter/react-syntax-highlighter
27
+ * https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html
28
+ */
29
+ var SyntaxHighlighter = composable(({ classNames, className, children, role, style, themeStyle, language = "text", fallback = zeroWidthSpace, copyButton, ...nativeProps }, forwardedRef) => {
30
+ const { themeMode } = useThemeContext();
31
+ const source = Children.toArray(children).join("") || fallback;
32
+ const prismTheme = themeStyle && typeof themeStyle === "object" && Object.keys(themeStyle).length > 0 ? themeStyle : themeMode === "dark" ? coldarkDark : coldarkCold;
33
+ return /* @__PURE__ */ jsxs("div", {
34
+ ...composableProps({
35
+ classNames,
36
+ className,
37
+ role,
38
+ style
39
+ }, {
40
+ role: "none",
41
+ classNames: mx("dx-expander p-1 overflow-auto", copyButton && "relative group")
42
+ }),
43
+ ref: forwardedRef,
44
+ children: [/* @__PURE__ */ jsx(NativeSyntaxHighlighter, {
45
+ language: languages[language] || language,
46
+ style: prismTheme,
47
+ customStyle: {
48
+ background: "unset",
49
+ border: "none",
50
+ boxShadow: "none",
51
+ padding: 0,
52
+ margin: 0,
53
+ overflow: "visible"
54
+ },
55
+ ...nativeProps,
56
+ children: source
57
+ }), copyButton && /* @__PURE__ */ jsx("div", {
58
+ className: "pointer-events-none absolute top-1 right-1 z-10 opacity-0 group-hover:opacity-100 focus-within:opacity-100",
59
+ children: /* @__PURE__ */ jsx(Clipboard.Provider, { children: /* @__PURE__ */ jsx(Clipboard.IconButton, {
60
+ value: source,
61
+ variant: "ghost",
62
+ size: 4,
63
+ classNames: "pointer-events-auto aspect-square rounded-sm"
64
+ }) })
65
+ })]
66
+ });
67
+ });
68
+ SyntaxHighlighter.displayName = "SyntaxHighlighter";
69
+ //#endregion
70
+ //#region src/JsonHighlighter/JsonHighlighter.tsx
71
+ var resolveReplacer = (replacer) => {
72
+ if (!replacer) return;
73
+ return typeof replacer === "function" ? replacer : createReplacer(replacer);
74
+ };
75
+ /**
76
+ * Inline, non-scrolling JSON renderer.
77
+ *
78
+ * Thin wrapper around `SyntaxHighlighter` that stringifies `data` with an optional replacer.
79
+ * `replacer` accepts either `CreateReplacerProps` (declarative truncation) or a raw
80
+ * `JSON.stringify`-compatible function (for bespoke serialization).
81
+ * For filtering and scroll behaviour, compose with the `Syntax.*` namespace.
82
+ */
83
+ var JsonHighlighter = composable(({ data, replacer, indent = 2, testId, ...props }, forwardedRef) => {
84
+ return /* @__PURE__ */ jsx(SyntaxHighlighter, {
85
+ ...props,
86
+ language: "json",
87
+ "data-testid": testId,
88
+ ref: forwardedRef,
89
+ children: safeStringify(data, resolveReplacer(replacer), indent)
90
+ });
91
+ });
92
+ JsonHighlighter.displayName = "JsonHighlighter";
93
+ //#endregion
94
+ //#region src/Syntax/SyntaxContext.ts
95
+ var SYNTAX_NAME = "Syntax";
96
+ var [createSyntaxContext, createSyntaxScope] = createContextScope(SYNTAX_NAME);
97
+ var [SyntaxProvider, useSyntaxContext] = createSyntaxContext(SYNTAX_NAME);
98
+ //#endregion
99
+ //#region src/Syntax/Syntax.tsx
100
+ var SYNTAX_ROOT_NAME = "Syntax.Root";
101
+ /**
102
+ * Headless context provider. Selects JSON mode when the `data` prop is passed at all — even
103
+ * `data={undefined}` — so loading states render an empty JSON view rather than flipping to
104
+ * text mode (which would trip `Syntax.Filter`'s JSON-only guard). Mode is chosen by prop
105
+ * presence, not value.
106
+ */
107
+ var SyntaxRoot = (props) => {
108
+ const { __scopeSyntax, children, language, source, replacer, getReplacer, defaultDepth = 0, onDepthChange } = props;
109
+ const isJson = "data" in props;
110
+ const data = props.data;
111
+ const [filterText, setFilterText] = useState("");
112
+ const [depth, setDepthState] = useState(defaultDepth);
113
+ const setDepth = useCallback((next) => {
114
+ setDepthState(next);
115
+ onDepthChange?.(next);
116
+ }, [onDepthChange]);
117
+ const effectiveReplacer = useMemo(() => getReplacer ? getReplacer(depth) : replacer, [
118
+ getReplacer,
119
+ replacer,
120
+ depth
121
+ ]);
122
+ const { filteredData, filterError } = useMemo(() => {
123
+ if (!isJson || !filterText.trim().length) return {
124
+ filteredData: data,
125
+ filterError: null
126
+ };
127
+ try {
128
+ return {
129
+ filteredData: JSONPath({
130
+ path: filterText,
131
+ json: data
132
+ }),
133
+ filterError: null
134
+ };
135
+ } catch (err) {
136
+ return {
137
+ filteredData: data,
138
+ filterError: err
139
+ };
140
+ }
141
+ }, [
142
+ isJson,
143
+ data,
144
+ filterText
145
+ ]);
146
+ return /* @__PURE__ */ jsx(SyntaxProvider, {
147
+ scope: __scopeSyntax,
148
+ mode: isJson ? "json" : "text",
149
+ source,
150
+ language,
151
+ data,
152
+ filteredData,
153
+ filterText,
154
+ setFilterText,
155
+ filterError,
156
+ replacer: effectiveReplacer,
157
+ depth,
158
+ setDepth,
159
+ children
160
+ });
161
+ };
162
+ SyntaxRoot.displayName = SYNTAX_ROOT_NAME;
163
+ var SYNTAX_CONTENT_NAME = "Syntax.Content";
164
+ /** Flex-column layout container for composite parts. */
165
+ var SyntaxContent = composable(({ children, ...props }, forwardedRef) => {
166
+ return /* @__PURE__ */ jsx("div", {
167
+ ...composableProps(props, { classNames: "flex flex-col h-full min-h-0 overflow-hidden" }),
168
+ ref: forwardedRef,
169
+ children
170
+ });
171
+ });
172
+ SyntaxContent.displayName = SYNTAX_CONTENT_NAME;
173
+ var SYNTAX_FILTER_NAME = "Syntax.Filter";
174
+ /** JSONPath filter input. Only meaningful when `Syntax.Root` is in JSON mode. */
175
+ var SyntaxFilter = forwardRef(({ __scopeSyntax, classNames, placeholder = "JSONPath (e.g., $.graph.nodes)" }, forwardedRef) => {
176
+ const { mode, filterText, setFilterText, filterError } = useSyntaxContext(SYNTAX_FILTER_NAME, __scopeSyntax);
177
+ if (mode !== "json") throw new Error(`\`${SYNTAX_FILTER_NAME}\` requires \`Syntax.Root\` to be in JSON mode (pass \`data\`).`);
178
+ return /* @__PURE__ */ jsx(Input.Root, {
179
+ validationValence: filterError ? "error" : "success",
180
+ children: /* @__PURE__ */ jsx(Input.TextInput, {
181
+ classNames: [
182
+ "p-1 px-2 font-mono",
183
+ filterError && "border-rose-500",
184
+ classNames
185
+ ],
186
+ variant: "subdued",
187
+ value: filterText,
188
+ placeholder,
189
+ onChange: (event) => setFilterText(event.target.value),
190
+ ref: forwardedRef
191
+ })
192
+ });
193
+ });
194
+ SyntaxFilter.displayName = SYNTAX_FILTER_NAME;
195
+ var SYNTAX_DEPTH_NAME = "Syntax.Depth";
196
+ /**
197
+ * Numeric expansion-depth control bound to `Syntax.Root`'s depth state. Meaningful when the Root is
198
+ * given a `getReplacer` that consumes depth (e.g. to resolve references N levels deep).
199
+ */
200
+ var SyntaxDepth = forwardRef(({ __scopeSyntax, classNames }, forwardedRef) => {
201
+ const { depth, setDepth } = useSyntaxContext(SYNTAX_DEPTH_NAME, __scopeSyntax);
202
+ return /* @__PURE__ */ jsx(Input.Root, { children: /* @__PURE__ */ jsx(Input.TextInput, {
203
+ classNames: ["p-1 px-2 font-mono", classNames],
204
+ variant: "subdued",
205
+ type: "number",
206
+ min: 0,
207
+ step: 1,
208
+ "aria-label": "Depth",
209
+ value: depth,
210
+ onChange: (event) => setDepth(Math.max(0, Number(event.target.value) || 0)),
211
+ ref: forwardedRef
212
+ }) });
213
+ });
214
+ SyntaxDepth.displayName = SYNTAX_DEPTH_NAME;
215
+ var SYNTAX_VIEWPORT_NAME = "Syntax.Viewport";
216
+ /** Optional scroll wrapper. Compose around `Syntax.Code` to make it scrollable. */
217
+ var SyntaxViewport = composable(({ children, ...props }, forwardedRef) => {
218
+ return /* @__PURE__ */ jsx(ScrollArea.Root, {
219
+ ...composableProps(props),
220
+ orientation: "all",
221
+ thin: true,
222
+ ref: forwardedRef,
223
+ children: /* @__PURE__ */ jsx(ScrollArea.Viewport, { children })
224
+ });
225
+ });
226
+ SyntaxViewport.displayName = SYNTAX_VIEWPORT_NAME;
227
+ var SYNTAX_CODE_NAME = "Syntax.Code";
228
+ /** Highlighted code leaf. Reads source/data from `Syntax.Root` context. */
229
+ var SyntaxCode = composable(({ __scopeSyntax, testId, ...props }, forwardedRef) => {
230
+ const context = useSyntaxContext(SYNTAX_CODE_NAME, __scopeSyntax);
231
+ const merged = composableProps(props, { classNames: "py-1 px-2 text-sm" });
232
+ if (context.mode === "json") return /* @__PURE__ */ jsx(JsonHighlighter, {
233
+ ...merged,
234
+ data: context.filteredData,
235
+ replacer: context.replacer,
236
+ testId,
237
+ ref: forwardedRef
238
+ });
239
+ return /* @__PURE__ */ jsx(SyntaxHighlighter, {
240
+ ...merged,
241
+ language: context.language,
242
+ "data-testid": testId,
243
+ ref: forwardedRef,
244
+ children: context.source ?? ""
245
+ });
246
+ });
247
+ SyntaxCode.displayName = SYNTAX_CODE_NAME;
248
+ var Syntax = {
249
+ Root: SyntaxRoot,
250
+ Content: SyntaxContent,
251
+ Filter: SyntaxFilter,
252
+ Depth: SyntaxDepth,
253
+ Viewport: SyntaxViewport,
254
+ Code: SyntaxCode
255
+ };
256
+ //#endregion
257
+ export { JsonHighlighter, Syntax, SyntaxHighlighter, createElement, createSyntaxScope };
258
+
259
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/SyntaxHighlighter/SyntaxHighlighter.tsx","../../src/JsonHighlighter/JsonHighlighter.tsx","../../src/Syntax/SyntaxContext.ts","../../src/Syntax/Syntax.tsx"],"sourcesContent":["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { Children } from 'react';\nimport { type SyntaxHighlighterProps as NaturalSyntaxHighlighterProps } from 'react-syntax-highlighter';\nimport NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-async-light';\nimport { coldarkDark as dark, coldarkCold as light } from 'react-syntax-highlighter/dist/esm/styles/prism';\n\nimport { Clipboard, composable, composableProps, useThemeContext } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nconst zeroWidthSpace = '\\u200b';\n\nconst languages = {\n js: 'javascript',\n ts: 'typescript',\n};\n\nexport type SyntaxHighlighterProps = Pick<\n NaturalSyntaxHighlighterProps,\n | 'language'\n | 'renderer'\n | 'showLineNumbers'\n | 'showInlineLineNumbers'\n | 'startingLineNumber'\n | 'wrapLines'\n | 'wrapLongLines'\n | 'PreTag'\n> & {\n themeStyle?: NaturalSyntaxHighlighterProps['style'];\n fallback?: string;\n copyButton?: boolean;\n};\n\n/**\n * Inline, non-scrolling wrapper around `react-syntax-highlighter`.\n *\n * Use directly for small snippets (e.g. inside markdown code blocks).\n * For scrollable panels, compose with `Syntax.Viewport`.\n *\n * NOTE: Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.\n * The lightweight version will load specific language parsers asynchronously.\n *\n * https://github.com/react-syntax-highlighter/react-syntax-highlighter\n * https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html\n */\nexport const SyntaxHighlighter = composable<HTMLDivElement, SyntaxHighlighterProps>(\n (\n {\n classNames,\n className,\n children,\n role,\n style,\n themeStyle,\n language = 'text',\n fallback = zeroWidthSpace,\n copyButton,\n ...nativeProps\n },\n forwardedRef,\n ) => {\n const { themeMode } = useThemeContext();\n const source = Children.toArray(children).join('') || fallback;\n\n const hasCustomTheme = themeStyle && typeof themeStyle === 'object' && Object.keys(themeStyle).length > 0;\n const prismTheme = hasCustomTheme ? themeStyle : themeMode === 'dark' ? dark : light;\n\n return (\n <div\n {...composableProps(\n { classNames, className, role, style },\n {\n role: 'none',\n classNames: mx('dx-expander p-1 overflow-auto', copyButton && 'relative group'),\n },\n )}\n ref={forwardedRef}\n >\n <NativeSyntaxHighlighter\n language={languages[language as keyof typeof languages] || language}\n style={prismTheme}\n customStyle={{\n background: 'unset',\n border: 'none',\n boxShadow: 'none',\n padding: 0,\n margin: 0,\n // Non-scrolling wrapper: defer all scrolling to an enclosing `Syntax.Viewport`.\n // The prism theme sets `overflow: auto` on the <pre>, which otherwise creates a\n // nested native horizontal scrollbar alongside the viewport's custom one.\n overflow: 'visible',\n }}\n {...nativeProps}\n >\n {/* Non-empty fallback prevents collapse. */}\n {source}\n </NativeSyntaxHighlighter>\n\n {copyButton && (\n <div className='pointer-events-none absolute top-1 right-1 z-10 opacity-0 group-hover:opacity-100 focus-within:opacity-100'>\n <Clipboard.Provider>\n <Clipboard.IconButton\n value={source}\n variant='ghost'\n size={4}\n classNames='pointer-events-auto aspect-square rounded-sm'\n />\n </Clipboard.Provider>\n </div>\n )}\n </div>\n );\n },\n);\n\nSyntaxHighlighter.displayName = 'SyntaxHighlighter';\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport React from 'react';\n\nimport { composable } from '@dxos/react-ui';\nimport { type CreateReplacerProps, createReplacer, safeStringify } from '@dxos/util';\n\nimport { SyntaxHighlighter, type SyntaxHighlighterProps } from '../SyntaxHighlighter';\n\nexport type JsonReplacer = CreateReplacerProps | ((key: string, value: any) => any);\n\nexport type JsonHighlighterProps = Omit<SyntaxHighlighterProps, 'children' | 'language'> & {\n data?: any;\n replacer?: JsonReplacer;\n /** Indentation passed to `JSON.stringify`. Default: `2` (pretty-printed). Pass `0` for single-line output. */\n indent?: number;\n testId?: string;\n};\n\nconst resolveReplacer = (replacer?: JsonReplacer) => {\n if (!replacer) {\n return undefined;\n }\n return typeof replacer === 'function' ? replacer : createReplacer(replacer);\n};\n\n/**\n * Inline, non-scrolling JSON renderer.\n *\n * Thin wrapper around `SyntaxHighlighter` that stringifies `data` with an optional replacer.\n * `replacer` accepts either `CreateReplacerProps` (declarative truncation) or a raw\n * `JSON.stringify`-compatible function (for bespoke serialization).\n * For filtering and scroll behaviour, compose with the `Syntax.*` namespace.\n */\nexport const JsonHighlighter = composable<HTMLDivElement, JsonHighlighterProps>(\n ({ data, replacer, indent = 2, testId, ...props }, forwardedRef) => {\n return (\n <SyntaxHighlighter {...props} language='json' data-testid={testId} ref={forwardedRef}>\n {safeStringify(data, resolveReplacer(replacer), indent)}\n </SyntaxHighlighter>\n );\n },\n);\n\nJsonHighlighter.displayName = 'JsonHighlighter';\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Scope, createContextScope } from '@radix-ui/react-context';\n\nimport { type SyntaxContextValue } from './Syntax';\n\n// Kept out of `Syntax.tsx`: react-refresh only fast-refreshes a module whose exports are all\n// components, so a context and its hook exported beside them force a full page reload on every edit.\n\nexport const SYNTAX_NAME = 'Syntax';\n\nexport type SyntaxScopedProps<P> = P & { __scopeSyntax?: Scope };\n\nexport const [createSyntaxContext, createSyntaxScope] = createContextScope(SYNTAX_NAME);\nexport const [SyntaxProvider, useSyntaxContext] = createSyntaxContext<SyntaxContextValue>(SYNTAX_NAME);\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { JSONPath } from 'jsonpath-plus';\nimport React, { type PropsWithChildren, forwardRef, useCallback, useMemo, useState } from 'react';\n\nimport { Input, ScrollArea } from '@dxos/react-ui';\nimport { composable, composableProps } from '@dxos/react-ui';\nimport { type ComposableProps } from '@dxos/ui-types';\n\nimport { JsonHighlighter, type JsonReplacer } from '../JsonHighlighter';\nimport { SyntaxHighlighter } from '../SyntaxHighlighter';\nimport { SyntaxProvider, type SyntaxScopedProps, useSyntaxContext } from './SyntaxContext';\n\n//\n// Context\n//\n\nexport type SyntaxContextValue = {\n mode: 'text' | 'json';\n // Text mode.\n source?: string;\n language?: string;\n // JSON mode.\n data?: any;\n filteredData?: any;\n filterText: string;\n setFilterText: (text: string) => void;\n filterError: Error | null;\n replacer?: JsonReplacer;\n // Expansion depth (JSON mode); consumed by a `getReplacer` factory, edited via `Syntax.Depth`.\n depth: number;\n setDepth: (depth: number) => void;\n};\n\n//\n// Root\n//\n\nconst SYNTAX_ROOT_NAME = 'Syntax.Root';\n\ntype SyntaxRootProps = PropsWithChildren<{\n // Text mode.\n language?: string;\n source?: string;\n // JSON mode (presence of the `data` prop selects JSON mode; `undefined` is still JSON).\n data?: any;\n /**\n * `JSON.stringify` replacer applied to `data`. Use the function form to follow domain\n * references (e.g. ECHO refs) by returning a transformed value at the root call. Keeps\n * this package free of any domain-specific knowledge.\n */\n replacer?: JsonReplacer;\n /**\n * Depth-parametrized replacer, re-evaluated as the `Syntax.Depth` control changes. Takes\n * precedence over `replacer`. The consumer owns any domain knowledge (e.g. how depth maps to\n * ref resolution), so this package stays domain-free.\n */\n getReplacer?: (depth: number) => JsonReplacer | undefined;\n /** Initial expansion depth for `Syntax.Depth` / `getReplacer`. */\n defaultDepth?: number;\n /** Notified when the depth changes (via `Syntax.Depth`). */\n onDepthChange?: (depth: number) => void;\n}>;\n\n/**\n * Headless context provider. Selects JSON mode when the `data` prop is passed at all — even\n * `data={undefined}` — so loading states render an empty JSON view rather than flipping to\n * text mode (which would trip `Syntax.Filter`'s JSON-only guard). Mode is chosen by prop\n * presence, not value.\n */\nconst SyntaxRoot = (props: SyntaxScopedProps<SyntaxRootProps>) => {\n const { __scopeSyntax, children, language, source, replacer, getReplacer, defaultDepth = 0, onDepthChange } = props;\n const isJson = 'data' in props;\n const data = props.data;\n const [filterText, setFilterText] = useState('');\n const [depth, setDepthState] = useState(defaultDepth);\n const setDepth = useCallback(\n (next: number) => {\n setDepthState(next);\n onDepthChange?.(next);\n },\n [onDepthChange],\n );\n\n // `getReplacer` (depth-parametrized) takes precedence over the static `replacer`.\n const effectiveReplacer = useMemo(\n () => (getReplacer ? getReplacer(depth) : replacer),\n [getReplacer, replacer, depth],\n );\n\n const { filteredData, filterError } = useMemo<{ filteredData: any; filterError: Error | null }>(() => {\n if (!isJson || !filterText.trim().length) {\n return { filteredData: data, filterError: null };\n }\n try {\n return { filteredData: JSONPath({ path: filterText, json: data }), filterError: null };\n } catch (err) {\n return { filteredData: data, filterError: err as Error };\n }\n }, [isJson, data, filterText]);\n\n return (\n <SyntaxProvider\n scope={__scopeSyntax}\n mode={isJson ? 'json' : 'text'}\n source={source}\n language={language}\n data={data}\n filteredData={filteredData}\n filterText={filterText}\n setFilterText={setFilterText}\n filterError={filterError}\n replacer={effectiveReplacer}\n depth={depth}\n setDepth={setDepth}\n >\n {children}\n </SyntaxProvider>\n );\n};\n\nSyntaxRoot.displayName = SYNTAX_ROOT_NAME;\n\n//\n// Content\n//\n\nconst SYNTAX_CONTENT_NAME = 'Syntax.Content';\n\ntype SyntaxContentProps = ComposableProps;\n\n/** Flex-column layout container for composite parts. */\nconst SyntaxContent = composable<HTMLDivElement, SyntaxContentProps>(({ children, ...props }, forwardedRef) => {\n return (\n <div {...composableProps(props, { classNames: 'flex flex-col h-full min-h-0 overflow-hidden' })} ref={forwardedRef}>\n {children}\n </div>\n );\n});\n\nSyntaxContent.displayName = SYNTAX_CONTENT_NAME;\n\n//\n// Filter\n//\n\nconst SYNTAX_FILTER_NAME = 'Syntax.Filter';\n\ntype SyntaxFilterProps = ComposableProps<{\n placeholder?: string;\n}>;\n\n/** JSONPath filter input. Only meaningful when `Syntax.Root` is in JSON mode. */\nconst SyntaxFilter = forwardRef<HTMLInputElement, SyntaxScopedProps<SyntaxFilterProps>>(\n ({ __scopeSyntax, classNames, placeholder = 'JSONPath (e.g., $.graph.nodes)' }, forwardedRef) => {\n const { mode, filterText, setFilterText, filterError } = useSyntaxContext(SYNTAX_FILTER_NAME, __scopeSyntax);\n if (mode !== 'json') {\n throw new Error(`\\`${SYNTAX_FILTER_NAME}\\` requires \\`Syntax.Root\\` to be in JSON mode (pass \\`data\\`).`);\n }\n\n return (\n <Input.Root validationValence={filterError ? 'error' : 'success'}>\n <Input.TextInput\n classNames={['p-1 px-2 font-mono', filterError && 'border-rose-500', classNames]}\n variant='subdued'\n value={filterText}\n placeholder={placeholder}\n onChange={(event) => setFilterText(event.target.value)}\n ref={forwardedRef}\n />\n </Input.Root>\n );\n },\n);\n\nSyntaxFilter.displayName = SYNTAX_FILTER_NAME;\n\n//\n// Depth\n//\n\nconst SYNTAX_DEPTH_NAME = 'Syntax.Depth';\n\ntype SyntaxDepthProps = ComposableProps;\n\n/**\n * Numeric expansion-depth control bound to `Syntax.Root`'s depth state. Meaningful when the Root is\n * given a `getReplacer` that consumes depth (e.g. to resolve references N levels deep).\n */\nconst SyntaxDepth = forwardRef<HTMLInputElement, SyntaxScopedProps<SyntaxDepthProps>>(\n ({ __scopeSyntax, classNames }, forwardedRef) => {\n const { depth, setDepth } = useSyntaxContext(SYNTAX_DEPTH_NAME, __scopeSyntax);\n return (\n <Input.Root>\n <Input.TextInput\n classNames={['p-1 px-2 font-mono', classNames]}\n variant='subdued'\n type='number'\n min={0}\n step={1}\n aria-label='Depth'\n value={depth}\n onChange={(event) => setDepth(Math.max(0, Number(event.target.value) || 0))}\n ref={forwardedRef}\n />\n </Input.Root>\n );\n },\n);\n\nSyntaxDepth.displayName = SYNTAX_DEPTH_NAME;\n\n//\n// Viewport\n//\n\nconst SYNTAX_VIEWPORT_NAME = 'Syntax.Viewport';\n\ntype SyntaxViewportProps = ComposableProps;\n\n/** Optional scroll wrapper. Compose around `Syntax.Code` to make it scrollable. */\nconst SyntaxViewport = composable<HTMLDivElement, SyntaxViewportProps>(({ children, ...props }, forwardedRef) => {\n return (\n <ScrollArea.Root {...composableProps(props)} orientation='all' thin ref={forwardedRef}>\n <ScrollArea.Viewport>{children}</ScrollArea.Viewport>\n </ScrollArea.Root>\n );\n});\n\nSyntaxViewport.displayName = SYNTAX_VIEWPORT_NAME;\n\n//\n// Code\n//\n\nconst SYNTAX_CODE_NAME = 'Syntax.Code';\n\ntype SyntaxCodeProps = ComposableProps<{\n testId?: string;\n}>;\n\n/** Highlighted code leaf. Reads source/data from `Syntax.Root` context. */\nconst SyntaxCode = composable<HTMLDivElement, SyntaxScopedProps<SyntaxCodeProps>>(\n ({ __scopeSyntax, testId, ...props }, forwardedRef) => {\n const context = useSyntaxContext(SYNTAX_CODE_NAME, __scopeSyntax);\n const merged = composableProps(props, { classNames: 'py-1 px-2 text-sm' });\n\n if (context.mode === 'json') {\n return (\n <JsonHighlighter\n {...merged}\n data={context.filteredData}\n replacer={context.replacer}\n testId={testId}\n ref={forwardedRef}\n />\n );\n }\n\n return (\n <SyntaxHighlighter {...merged} language={context.language} data-testid={testId} ref={forwardedRef}>\n {context.source ?? ''}\n </SyntaxHighlighter>\n );\n },\n);\n\nSyntaxCode.displayName = SYNTAX_CODE_NAME;\n\n//\n// Syntax\n//\n\nexport const Syntax = {\n Root: SyntaxRoot,\n Content: SyntaxContent,\n Filter: SyntaxFilter,\n Depth: SyntaxDepth,\n Viewport: SyntaxViewport,\n Code: SyntaxCode,\n};\n\nexport type {\n SyntaxCodeProps,\n SyntaxContentProps,\n SyntaxDepthProps,\n SyntaxFilterProps,\n SyntaxRootProps,\n SyntaxViewportProps,\n};\n"],"mappings":";;;;;;;;;;;AAYA,IAAM,iBAAiB;AAEvB,IA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oBAAC,WAAW,UAAZ,EAAsB,SAA8B,CAAA;CACrC,CAAA;AAErB,CAAC;AAED,eAAe,cAAc;AAM7B,IAAM,mBAAmB;;AAOzB,IAAM,aAAa,YAChB,EAAE,eAAe,QAAQ,GAAG,SAAS,iBAAiB;CACrD,MAAM,UAAU,iBAAiB,kBAAkB,aAAa;CAChE,MAAM,SAAS,gBAAgB,OAAO,EAAE,YAAY,oBAAoB,CAAC;CAEzE,IAAI,QAAQ,SAAS,QACnB,OACE,oBAAC,iBAAD;EACE,GAAI;EACJ,MAAM,QAAQ;EACd,UAAU,QAAQ;EACV;EACR,KAAK;CACN,CAAA;CAIL,OACE,oBAAC,mBAAD;EAAmB,GAAI;EAAQ,UAAU,QAAQ;EAAU,eAAa;EAAQ,KAAK;YAClF,QAAQ,UAAU;CACF,CAAA;AAEvB,CACF;AAEA,WAAW,cAAc;AAMzB,IAAa,SAAS;CACpB,MAAM;CACN,SAAS;CACT,QAAQ;CACR,OAAO;CACP,UAAU;CACV,MAAM;AACR"}
@@ -19,5 +19,5 @@ export type JsonHighlighterProps = Omit<SyntaxHighlighterProps, 'children' | 'la
19
19
  */
20
20
  export declare const JsonHighlighter: React.ForwardRefExoticComponent<Omit<JsonHighlighterProps, "className"> & {
21
21
  classNames?: import("@dxos/ui-types").ClassNameValue;
22
- } & Pick<React.HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
22
+ } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
23
23
  //# sourceMappingURL=JsonHighlighter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"JsonHighlighter.d.ts","sourceRoot":"","sources":["../../../../src/JsonHighlighter/JsonHighlighter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,KAAK,mBAAmB,EAAiC,MAAM,YAAY,CAAC;AAErF,OAAO,EAAqB,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;AAEpF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,UAAU,CAAC,GAAG;IACzF,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,8GAA8G;IAC9G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AASF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;;2HAQ3B,CAAC"}
1
+ {"version":3,"file":"JsonHighlighter.d.ts","sourceRoot":"","sources":["../../../../src/JsonHighlighter/JsonHighlighter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,KAAK,mBAAmB,EAAiC,MAAM,YAAY,CAAC;AAErF,OAAO,EAAqB,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;AAEpF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,UAAU,CAAC,GAAG;IACzF,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,8GAA8G;IAC9G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AASF;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;;6GAQ3B,CAAC"}
@@ -4,7 +4,7 @@ declare const meta: {
4
4
  title: string;
5
5
  component: import("react").ForwardRefExoticComponent<Omit<import("./JsonHighlighter").JsonHighlighterProps, "className"> & {
6
6
  classNames?: import("@dxos/ui-types").ClassNameValue;
7
- } & Pick<import("react").HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>;
7
+ } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>;
8
8
  decorators: import("@storybook/react").Decorator[];
9
9
  };
10
10
  export default meta;
@@ -1,11 +1,20 @@
1
- import { type Scope } from '@radix-ui/react-context';
2
1
  import React, { type PropsWithChildren } from 'react';
3
2
  import { type ComposableProps } from '@dxos/ui-types';
4
3
  import { type JsonReplacer } from '../JsonHighlighter';
5
- type ScopedProps<P> = P & {
6
- __scopeSyntax?: Scope;
4
+ import { type SyntaxScopedProps } from './SyntaxContext';
5
+ export type SyntaxContextValue = {
6
+ mode: 'text' | 'json';
7
+ source?: string;
8
+ language?: string;
9
+ data?: any;
10
+ filteredData?: any;
11
+ filterText: string;
12
+ setFilterText: (text: string) => void;
13
+ filterError: Error | null;
14
+ replacer?: JsonReplacer;
15
+ depth: number;
16
+ setDepth: (depth: number) => void;
7
17
  };
8
- declare const createSyntaxScope: import("@radix-ui/react-context").CreateScope;
9
18
  type SyntaxRootProps = PropsWithChildren<{
10
19
  language?: string;
11
20
  source?: string;
@@ -16,8 +25,18 @@ type SyntaxRootProps = PropsWithChildren<{
16
25
  * this package free of any domain-specific knowledge.
17
26
  */
18
27
  replacer?: JsonReplacer;
28
+ /**
29
+ * Depth-parametrized replacer, re-evaluated as the `Syntax.Depth` control changes. Takes
30
+ * precedence over `replacer`. The consumer owns any domain knowledge (e.g. how depth maps to
31
+ * ref resolution), so this package stays domain-free.
32
+ */
33
+ getReplacer?: (depth: number) => JsonReplacer | undefined;
34
+ /** Initial expansion depth for `Syntax.Depth` / `getReplacer`. */
35
+ defaultDepth?: number;
36
+ /** Notified when the depth changes (via `Syntax.Depth`). */
37
+ onDepthChange?: (depth: number) => void;
19
38
  }>;
20
- declare function SyntaxRoot(props: ScopedProps<SyntaxRootProps>): React.JSX.Element;
39
+ declare function SyntaxRoot(props: SyntaxScopedProps<SyntaxRootProps>): React.JSX.Element;
21
40
  declare namespace SyntaxRoot {
22
41
  var displayName: string;
23
42
  }
@@ -25,32 +44,37 @@ type SyntaxContentProps = ComposableProps;
25
44
  type SyntaxFilterProps = ComposableProps<{
26
45
  placeholder?: string;
27
46
  }>;
47
+ type SyntaxDepthProps = ComposableProps;
28
48
  type SyntaxViewportProps = ComposableProps;
29
49
  type SyntaxCodeProps = ComposableProps<{
30
50
  testId?: string;
31
51
  }>;
32
52
  export declare const Syntax: {
33
53
  Root: {
34
- (props: ScopedProps<SyntaxRootProps>): React.JSX.Element;
54
+ (props: SyntaxScopedProps<SyntaxRootProps>): React.JSX.Element;
35
55
  displayName: string;
36
56
  };
37
57
  Content: React.ForwardRefExoticComponent<Omit<SyntaxContentProps, "className"> & {
38
58
  classNames?: import("@dxos/ui-types").ClassNameValue;
39
- } & Pick<React.HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
59
+ } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
40
60
  Filter: React.ForwardRefExoticComponent<Omit<{
41
61
  placeholder?: string;
42
62
  }, "className"> & {
43
63
  classNames?: import("@dxos/ui-types").ClassNameValue;
44
- } & Pick<React.HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & {
45
- __scopeSyntax?: Scope;
64
+ } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & {
65
+ __scopeSyntax?: import("@radix-ui/react-context").Scope;
66
+ } & React.RefAttributes<HTMLInputElement>>;
67
+ Depth: React.ForwardRefExoticComponent<Omit<{}, "className"> & {
68
+ classNames?: import("@dxos/ui-types").ClassNameValue;
69
+ } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & {
70
+ __scopeSyntax?: import("@radix-ui/react-context").Scope;
46
71
  } & React.RefAttributes<HTMLInputElement>>;
47
72
  Viewport: React.ForwardRefExoticComponent<Omit<SyntaxViewportProps, "className"> & {
48
73
  classNames?: import("@dxos/ui-types").ClassNameValue;
49
- } & Pick<React.HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
50
- Code: React.ForwardRefExoticComponent<Omit<ScopedProps<SyntaxCodeProps>, "className"> & {
74
+ } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
75
+ Code: React.ForwardRefExoticComponent<Omit<SyntaxScopedProps<SyntaxCodeProps>, "className"> & {
51
76
  classNames?: import("@dxos/ui-types").ClassNameValue;
52
- } & Pick<React.HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
77
+ } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
53
78
  };
54
- export { createSyntaxScope };
55
- export type { SyntaxCodeProps, SyntaxContentProps, SyntaxFilterProps, SyntaxRootProps, SyntaxViewportProps };
79
+ export type { SyntaxCodeProps, SyntaxContentProps, SyntaxDepthProps, SyntaxFilterProps, SyntaxRootProps, SyntaxViewportProps, };
56
80
  //# sourceMappingURL=Syntax.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Syntax.d.ts","sourceRoot":"","sources":["../../../../src/Syntax/Syntax.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAsB,MAAM,yBAAyB,CAAC;AAEzE,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAiC,MAAM,OAAO,CAAC;AAIrF,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAuBxE,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,aAAa,CAAC,EAA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,KAAK,eAAe,GAAG,eAAe,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAkCH,eAAO,MAAM,MAAM;IACjB,IAAI;gBA5MqB,iBAAiB,CAAC,eAAe,CAAC;;;IA6M3D,OAAO;;;IACP,MAAM;sBA/HQ,MAAM;;;;;;IAgIpB,KAAK;;;;;IACL,QAAQ;;;IACR,IAAI;;;CACL,CAAC;AAEF,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,GACpB,CAAC"}
@@ -3,16 +3,7 @@ import React from 'react';
3
3
  declare const meta: {
4
4
  title: string;
5
5
  component: {
6
- (props: {
7
- language?: string;
8
- source?: string;
9
- data?: any;
10
- replacer?: import("..").JsonReplacer;
11
- } & {
12
- children?: React.ReactNode | undefined;
13
- } & {
14
- __scopeSyntax?: import("@radix-ui/react-context").Scope;
15
- }): React.JSX.Element;
6
+ (props: import("./SyntaxContext").SyntaxScopedProps<import("./Syntax").SyntaxRootProps>): React.JSX.Element;
16
7
  displayName: string;
17
8
  };
18
9
  decorators: import("@storybook/react").Decorator[];
@@ -1 +1 @@
1
- {"version":3,"file":"Syntax.stories.d.ts","sourceRoot":"","sources":["../../../../src/Syntax/Syntax.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AA8C1B,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;CAIM,CAAC;eAEF,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,yDAAyD;AACzD,eAAO,MAAM,IAAI,EAAE,KAelB,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,IAAI,EAAE,KAkBlB,CAAC"}
1
+ {"version":3,"file":"Syntax.stories.d.ts","sourceRoot":"","sources":["../../../../src/Syntax/Syntax.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AA8C1B,QAAA,MAAM,IAAI;;;;;;;CAIM,CAAC;eAEF,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,yDAAyD;AACzD,eAAO,MAAM,IAAI,EAAE,KAelB,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,IAAI,EAAE,KAkBlB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type Scope } from '@radix-ui/react-context';
2
+ import { type SyntaxContextValue } from './Syntax';
3
+ export declare const SYNTAX_NAME = "Syntax";
4
+ export type SyntaxScopedProps<P> = P & {
5
+ __scopeSyntax?: Scope;
6
+ };
7
+ export declare const createSyntaxContext: <ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType | undefined) => readonly [React.FC<ContextValueType & {
8
+ scope: Scope<ContextValueType>;
9
+ children: import("react").ReactNode;
10
+ }>, (consumerName: string, scope: Scope<ContextValueType | undefined>) => ContextValueType], createSyntaxScope: import("@radix-ui/react-context").CreateScope;
11
+ export declare const SyntaxProvider: import("react").FC<SyntaxContextValue & {
12
+ scope: Scope<SyntaxContextValue>;
13
+ children: React.ReactNode;
14
+ }>, useSyntaxContext: (consumerName: string, scope: Scope<SyntaxContextValue | undefined>) => SyntaxContextValue;
15
+ //# sourceMappingURL=SyntaxContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SyntaxContext.d.ts","sourceRoot":"","sources":["../../../../src/Syntax/SyntaxContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAsB,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKnD,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,aAAa,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEjE,eAAO,MAAO,mBAAmB;;;6FAAE,iBAAiB,+CAAmC,CAAC;AACxF,eAAO,MAAO,cAAc;;;IAAE,gBAAgB,4FAAwD,CAAC"}
@@ -1,2 +1,3 @@
1
+ export { createSyntaxScope } from './SyntaxContext';
1
2
  export * from './Syntax';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Syntax/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Syntax/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,cAAc,UAAU,CAAC"}
@@ -19,5 +19,5 @@ export type SyntaxHighlighterProps = Pick<NaturalSyntaxHighlighterProps, 'langua
19
19
  */
20
20
  export declare const SyntaxHighlighter: React.ForwardRefExoticComponent<Omit<SyntaxHighlighterProps, "className"> & {
21
21
  classNames?: import("@dxos/ui-types").ClassNameValue;
22
- } & Pick<React.HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
22
+ } & Pick<React.HTMLAttributes<Element>, "children" | "role" | "style"> & React.RefAttributes<HTMLDivElement>>;
23
23
  //# sourceMappingURL=SyntaxHighlighter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SyntaxHighlighter.d.ts","sourceRoot":"","sources":["../../../../src/SyntaxHighlighter/SyntaxHighlighter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,KAAK,sBAAsB,IAAI,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAcxG,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,6BAA6B,EAC3B,UAAU,GACV,UAAU,GACV,iBAAiB,GACjB,uBAAuB,GACvB,oBAAoB,GACpB,WAAW,GACX,eAAe,GACf,QAAQ,CACX,GAAG;IACF,UAAU,CAAC,EAAE,6BAA6B,CAAC,OAAO,CAAC,CAAC;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB;;2HAoE7B,CAAC"}
1
+ {"version":3,"file":"SyntaxHighlighter.d.ts","sourceRoot":"","sources":["../../../../src/SyntaxHighlighter/SyntaxHighlighter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,KAAK,sBAAsB,IAAI,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAcxG,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,6BAA6B,EAC3B,UAAU,GACV,UAAU,GACV,iBAAiB,GACjB,uBAAuB,GACvB,oBAAoB,GACpB,WAAW,GACX,eAAe,GACf,QAAQ,CACX,GAAG;IACF,UAAU,CAAC,EAAE,6BAA6B,CAAC,OAAO,CAAC,CAAC;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB;;6GAoE7B,CAAC"}
@@ -4,7 +4,7 @@ declare const meta: {
4
4
  title: string;
5
5
  component: import("react").ForwardRefExoticComponent<Omit<import("./SyntaxHighlighter").SyntaxHighlighterProps, "className"> & {
6
6
  classNames?: import("@dxos/ui-types").ClassNameValue;
7
- } & Pick<import("react").HTMLAttributes<Element>, "children" | "className" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>;
7
+ } & Pick<import("react").HTMLAttributes<Element>, "children" | "role" | "style"> & import("react").RefAttributes<HTMLDivElement>>;
8
8
  decorators: import("@storybook/react").Decorator[];
9
9
  parameters: {
10
10
  layout: string;