@dxos/react-ui-syntax-highlighter 0.8.4-main.ead640a → 0.8.4-main.effb148878

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/LICENSE +102 -5
  2. package/dist/lib/browser/index.mjs +185 -133
  3. package/dist/lib/browser/index.mjs.map +4 -4
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/node-esm/index.mjs +185 -133
  6. package/dist/lib/node-esm/index.mjs.map +4 -4
  7. package/dist/lib/node-esm/meta.json +1 -1
  8. package/dist/types/src/JsonHighlighter/JsonHighlighter.d.ts +23 -0
  9. package/dist/types/src/JsonHighlighter/JsonHighlighter.d.ts.map +1 -0
  10. package/dist/types/src/JsonHighlighter/JsonHighlighter.stories.d.ts +14 -0
  11. package/dist/types/src/JsonHighlighter/JsonHighlighter.stories.d.ts.map +1 -0
  12. package/dist/types/src/JsonHighlighter/index.d.ts +2 -0
  13. package/dist/types/src/JsonHighlighter/index.d.ts.map +1 -0
  14. package/dist/types/src/Syntax/Syntax.d.ts +49 -0
  15. package/dist/types/src/Syntax/Syntax.d.ts.map +1 -0
  16. package/dist/types/src/Syntax/Syntax.stories.d.ts +23 -0
  17. package/dist/types/src/Syntax/Syntax.stories.d.ts.map +1 -0
  18. package/dist/types/src/Syntax/index.d.ts +2 -0
  19. package/dist/types/src/Syntax/index.d.ts.map +1 -0
  20. package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.d.ts +12 -4
  21. package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.d.ts.map +1 -1
  22. package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.stories.d.ts +6 -1
  23. package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.stories.d.ts.map +1 -1
  24. package/dist/types/src/index.d.ts +2 -1
  25. package/dist/types/src/index.d.ts.map +1 -1
  26. package/dist/types/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +24 -24
  28. package/src/JsonHighlighter/JsonHighlighter.stories.tsx +65 -0
  29. package/src/JsonHighlighter/JsonHighlighter.tsx +47 -0
  30. package/src/JsonHighlighter/index.ts +5 -0
  31. package/src/Syntax/Syntax.stories.tsx +99 -0
  32. package/src/Syntax/Syntax.tsx +229 -0
  33. package/src/{Json → Syntax}/index.ts +1 -1
  34. package/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx +11 -10
  35. package/src/SyntaxHighlighter/SyntaxHighlighter.tsx +93 -42
  36. package/src/index.ts +2 -1
  37. package/dist/types/src/Json/Json.d.ts +0 -20
  38. package/dist/types/src/Json/Json.d.ts.map +0 -1
  39. package/dist/types/src/Json/Json.stories.d.ts +0 -13
  40. package/dist/types/src/Json/Json.stories.d.ts.map +0 -1
  41. package/dist/types/src/Json/index.d.ts +0 -2
  42. package/dist/types/src/Json/index.d.ts.map +0 -1
  43. package/src/Json/Json.stories.tsx +0 -93
  44. package/src/Json/Json.tsx +0 -130
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -1,156 +1,208 @@
1
- // src/Json/Json.tsx
2
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
3
- import jp from "jsonpath";
4
- import React2, { useEffect, useState } from "react";
5
- import { Input } from "@dxos/react-ui";
1
+ // src/JsonHighlighter/JsonHighlighter.tsx
2
+ import React2 from "react";
3
+ import { composable as composable2 } from "@dxos/react-ui";
4
+ import { createReplacer, safeStringify } from "@dxos/util";
6
5
 
7
6
  // src/SyntaxHighlighter/index.ts
8
7
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
9
8
 
10
9
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
11
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
12
- import React from "react";
10
+ import React, { Children } from "react";
13
11
  import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
14
12
  import { coldarkDark as dark, coldarkCold as light } from "react-syntax-highlighter/dist/esm/styles/prism";
15
- import { useThemeContext } from "@dxos/react-ui";
16
- import { mx } from "@dxos/react-ui-theme";
13
+ import { Clipboard, useThemeContext } from "@dxos/react-ui";
14
+ import { composable, composableProps } from "@dxos/react-ui";
17
15
  var zeroWidthSpace = "\u200B";
18
- var SyntaxHighlighter = ({ classNames, children, language = "text", fallback = zeroWidthSpace, ...props }) => {
19
- var _effect = _useSignals();
20
- try {
21
- const { themeMode } = useThemeContext();
22
- return /* @__PURE__ */ React.createElement("div", {
23
- className: mx("flex is-full p-1 overflow-hidden text-baseText", classNames)
24
- }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
25
- className: "is-full overflow-auto scrollbar-thin",
26
- language: languages[language] || language,
27
- style: themeMode === "dark" ? dark : light,
28
- customStyle: {
29
- background: "unset",
30
- border: "none",
31
- boxShadow: "none",
32
- padding: 0,
33
- margin: 0
34
- },
35
- ...props
36
- }, children || fallback));
37
- } finally {
38
- _effect.f();
39
- }
40
- };
41
16
  var languages = {
42
17
  js: "javascript",
43
18
  ts: "typescript"
44
19
  };
20
+ var SyntaxHighlighter = composable(({ classNames, className, children, role, style, themeStyle, language = "text", fallback = zeroWidthSpace, copyButton, ...nativeProps }, forwardedRef) => {
21
+ const { themeMode } = useThemeContext();
22
+ const source = Children.toArray(children).join("") || fallback;
23
+ const hasCustomTheme = themeStyle && typeof themeStyle === "object" && Object.keys(themeStyle).length > 0;
24
+ const prismTheme = hasCustomTheme ? themeStyle : themeMode === "dark" ? dark : light;
25
+ return /* @__PURE__ */ React.createElement("div", {
26
+ ...composableProps({
27
+ classNames,
28
+ className,
29
+ role,
30
+ style
31
+ }, {
32
+ role: "none",
33
+ classNames: copyButton && "relative group"
34
+ }),
35
+ ref: forwardedRef
36
+ }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
37
+ language: languages[language] || language,
38
+ style: prismTheme,
39
+ customStyle: {
40
+ background: "unset",
41
+ border: "none",
42
+ boxShadow: "none",
43
+ padding: 0,
44
+ margin: 0
45
+ },
46
+ ...nativeProps
47
+ }, source), copyButton && /* @__PURE__ */ React.createElement("div", {
48
+ className: "pointer-events-none absolute top-1 right-1 z-10 opacity-0 group-hover:opacity-100 focus-within:opacity-100"
49
+ }, /* @__PURE__ */ React.createElement(Clipboard.Provider, null, /* @__PURE__ */ React.createElement(Clipboard.IconButton, {
50
+ value: source,
51
+ variant: "ghost",
52
+ size: 4,
53
+ classNames: "pointer-events-auto aspect-square rounded-sm"
54
+ }))));
55
+ });
56
+ SyntaxHighlighter.displayName = "SyntaxHighlighter";
45
57
 
46
- // src/Json/Json.tsx
47
- var defaultClassNames = "!m-0 grow overflow-y-auto text-sm";
48
- var Json = ({ filter, ...params }) => {
49
- var _effect = _useSignals2();
50
- try {
51
- if (filter) {
52
- return /* @__PURE__ */ React2.createElement(JsonFilter, params);
53
- }
54
- const { classNames, data, replacer, testId } = params;
55
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
56
- language: "json",
57
- classNames: [
58
- defaultClassNames,
59
- classNames
60
- ],
61
- "data-testid": testId
62
- }, JSON.stringify(data, replacer && createReplacer(replacer), 2));
63
- } finally {
64
- _effect.f();
58
+ // src/JsonHighlighter/JsonHighlighter.tsx
59
+ var resolveReplacer = (replacer) => {
60
+ if (!replacer) {
61
+ return void 0;
65
62
  }
63
+ return typeof replacer === "function" ? replacer : createReplacer(replacer);
66
64
  };
67
- var JsonFilter = ({ classNames, data: initialData, replacer, testId }) => {
68
- var _effect = _useSignals2();
69
- try {
70
- const [data, setData] = useState(initialData);
71
- const [text, setText] = useState("");
72
- const [error, setError] = useState(null);
73
- useEffect(() => {
74
- if (!initialData || !text.trim().length) {
75
- setData(initialData);
76
- } else {
77
- try {
78
- setData(jp.query(initialData, text));
79
- setError(null);
80
- } catch (err) {
81
- setData(initialData);
82
- setError(err);
83
- }
84
- }
85
- }, [
86
- initialData,
87
- text
88
- ]);
89
- return /* @__PURE__ */ React2.createElement("div", {
90
- className: "flex flex-col grow overflow-hidden"
91
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
92
- validationValence: error ? "error" : "success"
93
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
94
- classNames: [
95
- "p-1 px-2 font-mono",
96
- error && "border-red-500"
97
- ],
98
- variant: "subdued",
99
- value: text,
100
- onChange: (event) => setText(event.target.value),
101
- placeholder: "JSONPath (e.g., $.graph.nodes)"
102
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
103
- language: "json",
104
- classNames: [
105
- defaultClassNames,
106
- classNames
107
- ],
108
- "data-testid": testId
109
- }, JSON.stringify(data, replacer && createReplacer(replacer), 2)));
110
- } finally {
111
- _effect.f();
112
- }
113
- };
114
- var createReplacer = ({ omit, parse, maxDepth, maxArrayLen, maxStringLen }) => {
115
- let currentDepth = 0;
116
- const depthMap = /* @__PURE__ */ new WeakMap();
117
- return function(key, value) {
118
- if (key === "") {
119
- currentDepth = 0;
120
- } else if (this && typeof this === "object") {
121
- const parentDepth = depthMap.get(this) ?? 0;
122
- currentDepth = parentDepth + 1;
123
- }
124
- if (value && typeof value === "object") {
125
- depthMap.set(value, currentDepth);
126
- if (maxDepth != null && currentDepth >= maxDepth) {
127
- return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
128
- }
129
- }
130
- if (omit?.includes(key)) {
131
- return void 0;
132
- }
133
- if (parse?.includes(key) && typeof value === "string") {
134
- try {
135
- return JSON.parse(value);
136
- } catch {
137
- return value;
138
- }
139
- }
140
- if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
141
- return `[length: ${value.length}]`;
65
+ var JsonHighlighter = composable2(({ data, replacer, indent = 2, testId, ...props }, forwardedRef) => {
66
+ return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
67
+ ...props,
68
+ language: "json",
69
+ "data-testid": testId,
70
+ ref: forwardedRef
71
+ }, safeStringify(data, resolveReplacer(replacer), indent));
72
+ });
73
+ JsonHighlighter.displayName = "JsonHighlighter";
74
+
75
+ // src/Syntax/Syntax.tsx
76
+ import { createContextScope } from "@radix-ui/react-context";
77
+ import { JSONPath } from "jsonpath-plus";
78
+ import React3, { forwardRef, useMemo, useState } from "react";
79
+ import { Input, ScrollArea } from "@dxos/react-ui";
80
+ import { composable as composable3, composableProps as composableProps2 } from "@dxos/react-ui";
81
+ var SYNTAX_NAME = "Syntax";
82
+ var [createSyntaxContext, createSyntaxScope] = createContextScope(SYNTAX_NAME);
83
+ var [SyntaxProvider, useSyntaxContext] = createSyntaxContext(SYNTAX_NAME);
84
+ var SYNTAX_ROOT_NAME = "Syntax.Root";
85
+ var SyntaxRoot = (props) => {
86
+ const { __scopeSyntax, children, language, source, replacer } = props;
87
+ const isJson = "data" in props;
88
+ const data = props.data;
89
+ const [filterText, setFilterText] = useState("");
90
+ const { filteredData, filterError } = useMemo(() => {
91
+ if (!isJson || !filterText.trim().length) {
92
+ return {
93
+ filteredData: data,
94
+ filterError: null
95
+ };
142
96
  }
143
- if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
144
- return value.slice(0, maxStringLen) + "...";
97
+ try {
98
+ return {
99
+ filteredData: JSONPath({
100
+ path: filterText,
101
+ json: data
102
+ }),
103
+ filterError: null
104
+ };
105
+ } catch (err) {
106
+ return {
107
+ filteredData: data,
108
+ filterError: err
109
+ };
145
110
  }
146
- return value;
147
- };
111
+ }, [
112
+ isJson,
113
+ data,
114
+ filterText
115
+ ]);
116
+ return /* @__PURE__ */ React3.createElement(SyntaxProvider, {
117
+ scope: __scopeSyntax,
118
+ mode: isJson ? "json" : "text",
119
+ source,
120
+ language,
121
+ data,
122
+ filteredData,
123
+ filterText,
124
+ setFilterText,
125
+ filterError,
126
+ replacer
127
+ }, children);
128
+ };
129
+ SyntaxRoot.displayName = SYNTAX_ROOT_NAME;
130
+ var SYNTAX_CONTENT_NAME = "Syntax.Content";
131
+ var SyntaxContent = composable3(({ children, ...props }, forwardedRef) => {
132
+ return /* @__PURE__ */ React3.createElement("div", {
133
+ ...composableProps2(props, {
134
+ classNames: "flex flex-col h-full min-h-0 overflow-hidden"
135
+ }),
136
+ ref: forwardedRef
137
+ }, children);
138
+ });
139
+ SyntaxContent.displayName = SYNTAX_CONTENT_NAME;
140
+ var SYNTAX_FILTER_NAME = "Syntax.Filter";
141
+ var SyntaxFilter = /* @__PURE__ */ forwardRef(({ __scopeSyntax, classNames, placeholder = "JSONPath (e.g., $.graph.nodes)" }, forwardedRef) => {
142
+ const { mode, filterText, setFilterText, filterError } = useSyntaxContext(SYNTAX_FILTER_NAME, __scopeSyntax);
143
+ if (mode !== "json") {
144
+ throw new Error(`\`${SYNTAX_FILTER_NAME}\` requires \`Syntax.Root\` to be in JSON mode (pass \`data\`).`);
145
+ }
146
+ return /* @__PURE__ */ React3.createElement(Input.Root, {
147
+ validationValence: filterError ? "error" : "success"
148
+ }, /* @__PURE__ */ React3.createElement(Input.TextInput, {
149
+ classNames: [
150
+ "p-1 px-2 font-mono",
151
+ filterError && "border-rose-500",
152
+ classNames
153
+ ],
154
+ variant: "subdued",
155
+ value: filterText,
156
+ placeholder,
157
+ onChange: (event) => setFilterText(event.target.value),
158
+ ref: forwardedRef
159
+ }));
160
+ });
161
+ SyntaxFilter.displayName = SYNTAX_FILTER_NAME;
162
+ var SYNTAX_VIEWPORT_NAME = "Syntax.Viewport";
163
+ var SyntaxViewport = composable3(({ children, ...props }, forwardedRef) => {
164
+ return /* @__PURE__ */ React3.createElement(ScrollArea.Root, {
165
+ ...composableProps2(props),
166
+ thin: true,
167
+ ref: forwardedRef
168
+ }, /* @__PURE__ */ React3.createElement(ScrollArea.Viewport, null, children));
169
+ });
170
+ SyntaxViewport.displayName = SYNTAX_VIEWPORT_NAME;
171
+ var SYNTAX_CODE_NAME = "Syntax.Code";
172
+ var SyntaxCode = composable3(({ __scopeSyntax, testId, ...props }, forwardedRef) => {
173
+ const context = useSyntaxContext(SYNTAX_CODE_NAME, __scopeSyntax);
174
+ const merged = composableProps2(props, {
175
+ classNames: "py-1 px-2 text-sm"
176
+ });
177
+ if (context.mode === "json") {
178
+ return /* @__PURE__ */ React3.createElement(JsonHighlighter, {
179
+ ...merged,
180
+ data: context.filteredData,
181
+ replacer: context.replacer,
182
+ testId,
183
+ ref: forwardedRef
184
+ });
185
+ }
186
+ return /* @__PURE__ */ React3.createElement(SyntaxHighlighter, {
187
+ ...merged,
188
+ language: context.language,
189
+ "data-testid": testId,
190
+ ref: forwardedRef
191
+ }, context.source ?? "");
192
+ });
193
+ SyntaxCode.displayName = SYNTAX_CODE_NAME;
194
+ var Syntax = {
195
+ Root: SyntaxRoot,
196
+ Content: SyntaxContent,
197
+ Filter: SyntaxFilter,
198
+ Viewport: SyntaxViewport,
199
+ Code: SyntaxCode
148
200
  };
149
201
  export {
150
- Json,
151
- JsonFilter,
202
+ JsonHighlighter,
203
+ Syntax,
152
204
  SyntaxHighlighter,
153
205
  createElement,
154
- createReplacer
206
+ createSyntaxScope
155
207
  };
156
208
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/Json/Json.tsx", "../../../src/SyntaxHighlighter/index.ts", "../../../src/SyntaxHighlighter/SyntaxHighlighter.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(burdon): Use to jsonpath-plus.\nimport jp from 'jsonpath';\nimport React, { useEffect, useState } from 'react';\n\nimport { Input, type ThemedClassName } from '@dxos/react-ui';\n\nimport { SyntaxHighlighter } from '../SyntaxHighlighter';\n\nconst defaultClassNames = '!m-0 grow overflow-y-auto text-sm';\n\nexport type JsonProps = ThemedClassName<{\n data?: any;\n filter?: boolean;\n replacer?: CreateReplacerProps;\n testId?: string;\n}>;\n\nexport const Json = ({ filter, ...params }: JsonProps) => {\n if (filter) {\n return <JsonFilter {...params} />;\n }\n\n const { classNames, data, replacer, testId } = params;\n return (\n <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>\n {JSON.stringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n );\n};\n\nexport const JsonFilter = ({ classNames, data: initialData, replacer, testId }: JsonProps) => {\n const [data, setData] = useState(initialData);\n const [text, setText] = useState('');\n const [error, setError] = useState<Error | null>(null);\n useEffect(() => {\n if (!initialData || !text.trim().length) {\n setData(initialData);\n } else {\n try {\n setData(jp.query(initialData, text));\n setError(null);\n } catch (err) {\n setData(initialData);\n setError(err as Error);\n }\n }\n }, [initialData, text]); // TODO(burdon): Need structural diff.\n\n return (\n <div className='flex flex-col grow overflow-hidden'>\n <Input.Root validationValence={error ? 'error' : 'success'}>\n <Input.TextInput\n classNames={['p-1 px-2 font-mono', error && 'border-red-500']}\n variant='subdued'\n value={text}\n onChange={(event) => setText(event.target.value)}\n placeholder='JSONPath (e.g., $.graph.nodes)'\n />\n </Input.Root>\n <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>\n {JSON.stringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n </div>\n );\n};\n\nexport type CreateReplacerProps = {\n omit?: string[];\n parse?: string[];\n maxDepth?: number;\n maxArrayLen?: number;\n maxStringLen?: number;\n};\n\nexport type JsonReplacer = (this: any, key: string, value: any) => any;\n\nexport const createReplacer = ({\n omit,\n parse,\n maxDepth,\n maxArrayLen,\n maxStringLen,\n}: CreateReplacerProps): JsonReplacer => {\n let currentDepth = 0;\n const depthMap = new WeakMap<object, number>();\n\n return function (this: any, key: string, value: any) {\n // Track depth.\n if (key === '') {\n currentDepth = 0;\n } else if (this && typeof this === 'object') {\n const parentDepth = depthMap.get(this) ?? 0;\n currentDepth = parentDepth + 1;\n }\n\n // Store depth for this object.\n if (value && typeof value === 'object') {\n depthMap.set(value, currentDepth);\n\n // Check max depth.\n if (maxDepth != null && currentDepth >= maxDepth) {\n return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;\n }\n }\n\n // Apply other filters.\n if (omit?.includes(key)) {\n return undefined;\n }\n if (parse?.includes(key) && typeof value === 'string') {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n }\n if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {\n return `[length: ${value.length}]`;\n }\n if (maxStringLen != null && typeof value === 'string' && value.length > maxStringLen) {\n return value.slice(0, maxStringLen) + '...';\n }\n\n return value;\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// eslint-disable-next-line no-restricted-imports\nimport createElement from 'react-syntax-highlighter/dist/esm/create-element';\n\nexport { createElement };\n\nexport * from './SyntaxHighlighter';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React 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 { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst zeroWidthSpace = '\\u200b';\n\nexport type SyntaxHighlighterProps = ThemedClassName<\n NaturalSyntaxHighlighterProps & {\n fallback?: string;\n }\n>;\n\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 */\n// TODO(burdon): Replace with react-ui-editor (and reuse styles).\nexport const SyntaxHighlighter = ({\n classNames,\n children,\n language = 'text',\n fallback = zeroWidthSpace,\n ...props\n}: SyntaxHighlighterProps) => {\n const { themeMode } = useThemeContext();\n\n return (\n <div className={mx('flex is-full p-1 overflow-hidden text-baseText', classNames)}>\n <NativeSyntaxHighlighter\n className='is-full overflow-auto scrollbar-thin'\n language={languages[language as keyof typeof languages] || language}\n style={themeMode === 'dark' ? dark : light}\n customStyle={{\n background: 'unset',\n border: 'none',\n boxShadow: 'none',\n padding: 0,\n margin: 0,\n }}\n {...props}\n >\n {/* Non-empty fallback prevents collapse. */}\n {children || fallback}\n </NativeSyntaxHighlighter>\n </div>\n );\n};\n\nconst languages = {\n js: 'javascript',\n ts: 'typescript',\n};\n"],
5
- "mappings": ";;AAKA,OAAOA,QAAQ;AACf,OAAOC,UAASC,WAAWC,gBAAgB;AAE3C,SAASC,aAAmC;;;ACH5C,OAAOC,mBAAmB;;;;ACD1B,OAAOC,WAAW;AAElB,OAAOC,6BAA6B;AACpC,SAASC,eAAeC,MAAMC,eAAeC,aAAa;AAE1D,SAA+BC,uBAAuB;AACtD,SAASC,UAAU;AAEnB,IAAMC,iBAAiB;AAgBhB,IAAMC,oBAAoB,CAAC,EAChCC,YACAC,UACAC,WAAW,QACXC,WAAWL,gBACX,GAAGM,MAAAA,MACoB;;;AACvB,UAAM,EAAEC,UAAS,IAAKC,gBAAAA;AAEtB,WACE,sBAAA,cAACC,OAAAA;MAAIC,WAAWC,GAAG,kDAAkDT,UAAAA;OACnE,sBAAA,cAACU,yBAAAA;MACCF,WAAU;MACVN,UAAUS,UAAUT,QAAAA,KAAuCA;MAC3DU,OAAOP,cAAc,SAASQ,OAAOC;MACrCC,aAAa;QACXC,YAAY;QACZC,QAAQ;QACRC,WAAW;QACXC,SAAS;QACTC,QAAQ;MACV;MACC,GAAGhB;OAGHH,YAAYE,QAAAA,CAAAA;;;;AAIrB;AAEA,IAAMQ,YAAY;EAChBU,IAAI;EACJC,IAAI;AAC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State", "Input", "createElement", "React", "NativeSyntaxHighlighter", "coldarkDark", "dark", "coldarkCold", "light", "useThemeContext", "mx", "zeroWidthSpace", "SyntaxHighlighter", "classNames", "children", "language", "fallback", "props", "themeMode", "useThemeContext", "div", "className", "mx", "NativeSyntaxHighlighter", "languages", "style", "dark", "light", "customStyle", "background", "border", "boxShadow", "padding", "margin", "js", "ts", "defaultClassNames", "Json", "filter", "params", "React", "JsonFilter", "classNames", "data", "replacer", "testId", "SyntaxHighlighter", "language", "data-testid", "JSON", "stringify", "createReplacer", "initialData", "setData", "useState", "text", "setText", "error", "setError", "useEffect", "trim", "length", "jp", "query", "err", "div", "className", "Input", "Root", "validationValence", "TextInput", "variant", "value", "onChange", "event", "target", "placeholder", "omit", "parse", "maxDepth", "maxArrayLen", "maxStringLen", "currentDepth", "depthMap", "WeakMap", "key", "parentDepth", "get", "set", "Array", "isArray", "Object", "keys", "includes", "undefined", "slice"]
3
+ "sources": ["../../../src/JsonHighlighter/JsonHighlighter.tsx", "../../../src/SyntaxHighlighter/index.ts", "../../../src/SyntaxHighlighter/SyntaxHighlighter.tsx", "../../../src/Syntax/Syntax.tsx"],
4
+ "sourcesContent": ["//\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 2024 DXOS.org\n//\n\n// eslint-disable-next-line no-restricted-imports\nimport createElement from 'react-syntax-highlighter/dist/esm/create-element';\n\nexport { createElement };\n\nexport * from './SyntaxHighlighter';\n", "//\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, useThemeContext } from '@dxos/react-ui';\nimport { composable, composableProps } from '@dxos/react-ui';\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: 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 }}\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 { createContextScope, type Scope } from '@radix-ui/react-context';\nimport { JSONPath } from 'jsonpath-plus';\nimport React, { type FC, type PropsWithChildren, forwardRef, 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';\n\n//\n// Context\n//\n\nconst SYNTAX_NAME = 'Syntax';\n\ntype 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};\n\ntype ScopedProps<P> = P & { __scopeSyntax?: Scope };\n\nconst [createSyntaxContext, createSyntaxScope] = createContextScope(SYNTAX_NAME);\nconst [SyntaxProvider, useSyntaxContext] = createSyntaxContext<SyntaxContextValue>(SYNTAX_NAME);\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\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: FC<ScopedProps<SyntaxRootProps>> = (props) => {\n const { __scopeSyntax, children, language, source, replacer } = props;\n const isJson = 'data' in props;\n const data = props.data;\n const [filterText, setFilterText] = useState('');\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={replacer}\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, ScopedProps<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// 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)} 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, ScopedProps<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 Viewport: SyntaxViewport,\n Code: SyntaxCode,\n};\n\nexport { createSyntaxScope };\n\nexport type { SyntaxRootProps, SyntaxContentProps, SyntaxFilterProps, SyntaxViewportProps, SyntaxCodeProps };\n"],
5
+ "mappings": ";AAIA,OAAOA,YAAW;AAElB,SAASC,cAAAA,mBAAkB;AAC3B,SAA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,MAAAA,GAAS2B,iBAAAA;AAC9F,SACE,gBAAAP,OAAA,cAAC4B,WAAWV,MAAI;IAAE,GAAGT,iBAAgB7B,KAAAA;IAAQiD,MAAAA;IAAKlB,KAAKJ;KACrD,gBAAAP,OAAA,cAAC4B,WAAWE,UAAQ,MAAEhD,QAAAA,CAAAA;AAG5B,CAAA;AAEA6C,eAAexB,cAAcuB;AAM7B,IAAMK,mBAAmB;AAOzB,IAAMC,aAAa1B,YACjB,CAAC,EAAEzB,eAAeoD,QAAQ,GAAGrD,MAAAA,GAAS2B,iBAAAA;AACpC,QAAM2B,UAAUzD,iBAAiBsD,kBAAkBlD,aAAAA;AACnD,QAAMsD,SAAS1B,iBAAgB7B,OAAO;IAAE8B,YAAY;EAAoB,CAAA;AAExE,MAAIwB,QAAQhC,SAAS,QAAQ;AAC3B,WACE,gBAAAF,OAAA,cAACoC,iBAAAA;MACE,GAAGD;MACJhD,MAAM+C,QAAQ3C;MACdN,UAAUiD,QAAQjD;MAClBgD;MACAtB,KAAKJ;;EAGX;AAEA,SACE,gBAAAP,OAAA,cAACqC,mBAAAA;IAAmB,GAAGF;IAAQpD,UAAUmD,QAAQnD;IAAUuD,eAAaL;IAAQtB,KAAKJ;KAClF2B,QAAQlD,UAAU,EAAA;AAGzB,CAAA;AAGFgD,WAAW7B,cAAc4B;AAMlB,IAAMQ,SAAS;EACpBrB,MAAMvC;EACN6D,SAASnC;EACToC,QAAQ5B;EACRiB,UAAUH;EACVe,MAAMV;AACR;",
6
+ "names": ["React", "composable", "createReplacer", "safeStringify", "createElement", "React", "Children", "NativeSyntaxHighlighter", "coldarkDark", "dark", "coldarkCold", "light", "Clipboard", "useThemeContext", "composable", "composableProps", "zeroWidthSpace", "languages", "js", "ts", "SyntaxHighlighter", "classNames", "className", "children", "role", "style", "themeStyle", "language", "fallback", "copyButton", "nativeProps", "forwardedRef", "themeMode", "source", "toArray", "join", "hasCustomTheme", "Object", "keys", "length", "prismTheme", "div", "ref", "customStyle", "background", "border", "boxShadow", "padding", "margin", "Provider", "IconButton", "value", "variant", "size", "displayName", "resolveReplacer", "replacer", "undefined", "createReplacer", "JsonHighlighter", "composable", "data", "indent", "testId", "props", "forwardedRef", "React", "SyntaxHighlighter", "language", "data-testid", "ref", "safeStringify", "displayName", "createContextScope", "JSONPath", "React", "forwardRef", "useMemo", "useState", "Input", "ScrollArea", "composable", "composableProps", "SYNTAX_NAME", "createSyntaxContext", "createSyntaxScope", "createContextScope", "SyntaxProvider", "useSyntaxContext", "SYNTAX_ROOT_NAME", "SyntaxRoot", "props", "__scopeSyntax", "children", "language", "source", "replacer", "isJson", "data", "filterText", "setFilterText", "useState", "filteredData", "filterError", "useMemo", "trim", "length", "JSONPath", "path", "json", "err", "React", "scope", "mode", "displayName", "SYNTAX_CONTENT_NAME", "SyntaxContent", "composable", "forwardedRef", "div", "composableProps", "classNames", "ref", "SYNTAX_FILTER_NAME", "SyntaxFilter", "forwardRef", "placeholder", "Error", "Input", "Root", "validationValence", "TextInput", "variant", "value", "onChange", "event", "target", "SYNTAX_VIEWPORT_NAME", "SyntaxViewport", "ScrollArea", "thin", "Viewport", "SYNTAX_CODE_NAME", "SyntaxCode", "testId", "context", "merged", "JsonHighlighter", "SyntaxHighlighter", "data-testid", "Syntax", "Content", "Filter", "Code"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytes":6186,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/SyntaxHighlighter/index.ts":{"bytes":979,"imports":[{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/SyntaxHighlighter.tsx","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"},"src/Json/Json.tsx":{"bytes":13573,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"jsonpath","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"../SyntaxHighlighter"}],"format":"esm"},"src/Json/index.ts":{"bytes":463,"imports":[{"path":"src/Json/Json.tsx","kind":"import-statement","original":"./Json"}],"format":"esm"},"src/index.ts":{"bytes":571,"imports":[{"path":"src/Json/index.ts","kind":"import-statement","original":"./Json"},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10249},"dist/lib/browser/index.mjs":{"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"jsonpath","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"exports":["Json","JsonFilter","SyntaxHighlighter","createElement","createReplacer"],"entryPoint":"src/index.ts","inputs":{"src/Json/Json.tsx":{"bytesInOutput":3419},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":1283},"src/Json/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":5030}}}
1
+ {"inputs":{"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytes":9899,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"format":"esm"},"src/SyntaxHighlighter/index.ts":{"bytes":871,"imports":[{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/SyntaxHighlighter.tsx","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"},"src/JsonHighlighter/JsonHighlighter.tsx":{"bytes":4584,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"../SyntaxHighlighter"}],"format":"esm"},"src/JsonHighlighter/index.ts":{"bytes":395,"imports":[{"path":"src/JsonHighlighter/JsonHighlighter.tsx","kind":"import-statement","original":"./JsonHighlighter"}],"format":"esm"},"src/Syntax/Syntax.tsx":{"bytes":19872,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"jsonpath-plus","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"src/JsonHighlighter/index.ts","kind":"import-statement","original":"../JsonHighlighter"},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"../SyntaxHighlighter"}],"format":"esm"},"src/Syntax/index.ts":{"bytes":370,"imports":[{"path":"src/Syntax/Syntax.tsx","kind":"import-statement","original":"./Syntax"}],"format":"esm"},"src/index.ts":{"bytes":590,"imports":[{"path":"src/JsonHighlighter/index.ts","kind":"import-statement","original":"./JsonHighlighter"},{"path":"src/Syntax/index.ts","kind":"import-statement","original":"./Syntax"},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":18553},"dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"jsonpath-plus","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true}],"exports":["JsonHighlighter","Syntax","SyntaxHighlighter","createElement","createSyntaxScope"],"entryPoint":"src/index.ts","inputs":{"src/JsonHighlighter/JsonHighlighter.tsx":{"bytesInOutput":681},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":1995},"src/index.ts":{"bytesInOutput":0},"src/Syntax/Syntax.tsx":{"bytesInOutput":4138}},"bytes":7222}}}