@dxos/react-ui-syntax-highlighter 0.8.4-main.74a063c4e0 → 0.8.4-main.765dc60934

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 +132 -84
  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 +132 -84
  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 +9 -6
  21. package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.d.ts.map +1 -1
  22. package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.stories.d.ts +1 -5
  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 +13 -15
  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/{Json/Json.stories.tsx → Syntax/Syntax.stories.tsx} +37 -44
  32. package/src/Syntax/Syntax.tsx +229 -0
  33. package/src/Syntax/index.ts +5 -0
  34. package/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx +2 -2
  35. package/src/SyntaxHighlighter/SyntaxHighlighter.tsx +74 -25
  36. package/src/index.ts +2 -1
  37. package/dist/types/src/Json/Json.d.ts +0 -49
  38. package/dist/types/src/Json/Json.d.ts.map +0 -1
  39. package/dist/types/src/Json/Json.stories.d.ts +0 -21
  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.tsx +0 -190
  44. package/src/Json/index.ts +0 -5
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,38 +1,41 @@
1
- // src/Json/Json.tsx
2
- import { JSONPath } from "jsonpath-plus";
3
- import React2, { createContext, forwardRef, useContext, useEffect, useMemo, useState } from "react";
4
- import { Input } from "@dxos/react-ui";
5
- import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
1
+ // src/JsonHighlighter/JsonHighlighter.tsx
2
+ import React2 from "react";
3
+ import { composable as composable2 } from "@dxos/ui-theme";
6
4
  import { createReplacer, safeStringify } from "@dxos/util";
7
5
 
8
6
  // src/SyntaxHighlighter/index.ts
9
7
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
10
8
 
11
9
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
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 { ScrollArea, useThemeContext } from "@dxos/react-ui";
13
+ import { Clipboard, useThemeContext } from "@dxos/react-ui";
16
14
  import { composable, composableProps } from "@dxos/ui-theme";
17
15
  var zeroWidthSpace = "\u200B";
18
16
  var languages = {
19
17
  js: "javascript",
20
18
  ts: "typescript"
21
19
  };
22
- var SyntaxHighlighter = composable(({ children, language = "text", fallback = zeroWidthSpace, classNames, className, style, ...nativeProps }, forwardedRef) => {
20
+ var SyntaxHighlighter = composable(({ classNames, className, children, role, style, themeStyle, language = "text", fallback = zeroWidthSpace, copyButton, ...nativeProps }, forwardedRef) => {
23
21
  const { themeMode } = useThemeContext();
24
- return /* @__PURE__ */ React.createElement(ScrollArea.Root, {
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", {
25
26
  ...composableProps({
26
27
  classNames,
27
- className
28
+ className,
29
+ role,
30
+ style
31
+ }, {
32
+ role: "none",
33
+ classNames: copyButton && "relative group"
28
34
  }),
29
- thin: true,
30
35
  ref: forwardedRef
31
- }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React.createElement("div", {
32
- role: "none"
33
36
  }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
34
37
  language: languages[language] || language,
35
- style: style ?? (themeMode === "dark" ? dark : light),
38
+ style: prismTheme,
36
39
  customStyle: {
37
40
  background: "unset",
38
41
  border: "none",
@@ -41,83 +44,108 @@ var SyntaxHighlighter = composable(({ children, language = "text", fallback = ze
41
44
  margin: 0
42
45
  },
43
46
  ...nativeProps
44
- }, children || fallback))));
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
+ }))));
45
55
  });
46
56
  SyntaxHighlighter.displayName = "SyntaxHighlighter";
47
57
 
48
- // src/Json/Json.tsx
49
- var JsonContext = /* @__PURE__ */ createContext(null);
50
- var useJsonContext = (consumerName) => {
51
- const context = useContext(JsonContext);
52
- if (!context) {
53
- throw new Error(`\`${consumerName}\` must be used within \`Json.Root\`.`);
58
+ // src/JsonHighlighter/JsonHighlighter.tsx
59
+ var resolveReplacer = (replacer) => {
60
+ if (!replacer) {
61
+ return void 0;
54
62
  }
55
- return context;
63
+ return typeof replacer === "function" ? replacer : createReplacer(replacer);
56
64
  };
57
- var useOptionalJsonContext = () => {
58
- return useContext(JsonContext);
59
- };
60
- var JSON_ROOT_NAME = "Json.Root";
61
- var JsonRoot = /* @__PURE__ */ forwardRef(({ children, data, replacer }, _forwardedRef) => {
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/ui-theme";
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;
62
89
  const [filterText, setFilterText] = useState("");
63
- const [filteredData, setFilteredData] = useState(data);
64
- const [filterError, setFilterError] = useState(null);
65
- useEffect(() => {
66
- if (!filterText.trim().length) {
67
- setFilteredData(data);
68
- setFilterError(null);
69
- } else {
70
- try {
71
- setFilteredData(JSONPath({
90
+ const { filteredData, filterError } = useMemo(() => {
91
+ if (!isJson || !filterText.trim().length) {
92
+ return {
93
+ filteredData: data,
94
+ filterError: null
95
+ };
96
+ }
97
+ try {
98
+ return {
99
+ filteredData: JSONPath({
72
100
  path: filterText,
73
101
  json: data
74
- }));
75
- setFilterError(null);
76
- } catch (err) {
77
- setFilteredData(data);
78
- setFilterError(err);
79
- }
102
+ }),
103
+ filterError: null
104
+ };
105
+ } catch (err) {
106
+ return {
107
+ filteredData: data,
108
+ filterError: err
109
+ };
80
110
  }
81
111
  }, [
112
+ isJson,
82
113
  data,
83
114
  filterText
84
115
  ]);
85
- const context = useMemo(() => ({
116
+ return /* @__PURE__ */ React3.createElement(SyntaxProvider, {
117
+ scope: __scopeSyntax,
118
+ mode: isJson ? "json" : "text",
119
+ source,
120
+ language,
86
121
  data,
87
122
  filteredData,
88
123
  filterText,
89
124
  setFilterText,
90
125
  filterError,
91
126
  replacer
92
- }), [
93
- data,
94
- filteredData,
95
- filterText,
96
- setFilterText,
97
- filterError,
98
- replacer
99
- ]);
100
- return /* @__PURE__ */ React2.createElement(JsonContext.Provider, {
101
- value: context
102
127
  }, children);
103
- });
104
- JsonRoot.displayName = JSON_ROOT_NAME;
105
- var JSON_CONTENT_NAME = "Json.Content";
106
- var JsonContent = composable2(({ children, ...props }, forwardedRef) => {
107
- return /* @__PURE__ */ React2.createElement("div", {
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", {
108
133
  ...composableProps2(props, {
109
134
  classNames: "flex flex-col h-full min-h-0 overflow-hidden"
110
135
  }),
111
136
  ref: forwardedRef
112
137
  }, children);
113
138
  });
114
- JsonContent.displayName = JSON_CONTENT_NAME;
115
- var JSON_FILTER_NAME = "Json.Filter";
116
- var JsonFilter = /* @__PURE__ */ forwardRef(({ classNames, placeholder = "JSONPath (e.g., $.graph.nodes)" }, forwardedRef) => {
117
- const { filterText, setFilterText, filterError } = useJsonContext(JSON_FILTER_NAME);
118
- return /* @__PURE__ */ React2.createElement(Input.Root, {
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, {
119
147
  validationValence: filterError ? "error" : "success"
120
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
148
+ }, /* @__PURE__ */ React3.createElement(Input.TextInput, {
121
149
  classNames: [
122
150
  "p-1 px-2 font-mono",
123
151
  filterError && "border-rose-500",
@@ -130,31 +158,51 @@ var JsonFilter = /* @__PURE__ */ forwardRef(({ classNames, placeholder = "JSONPa
130
158
  ref: forwardedRef
131
159
  }));
132
160
  });
133
- JsonFilter.displayName = JSON_FILTER_NAME;
134
- var JSON_DATA_NAME = "Json.Data";
135
- var JsonData = composable2(({ data: dataProp, replacer: replacerProp, testId, ...props }, forwardedRef) => {
136
- const context = useOptionalJsonContext();
137
- const data = dataProp ?? context?.filteredData;
138
- const replacer = replacerProp ?? context?.replacer;
139
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
140
- ...composableProps2(props, {
141
- classNames: "flex-1 min-h-0 w-full py-1 px-2 overflow-y-auto text-sm"
142
- }),
143
- language: "json",
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,
144
189
  "data-testid": testId,
145
190
  ref: forwardedRef
146
- }, safeStringify(data, replacer && createReplacer(replacer), 2));
191
+ }, context.source ?? "");
147
192
  });
148
- JsonData.displayName = JSON_DATA_NAME;
149
- var Json = {
150
- Root: JsonRoot,
151
- Content: JsonContent,
152
- Filter: JsonFilter,
153
- Data: JsonData
193
+ SyntaxCode.displayName = SYNTAX_CODE_NAME;
194
+ var Syntax = {
195
+ Root: SyntaxRoot,
196
+ Content: SyntaxContent,
197
+ Filter: SyntaxFilter,
198
+ Viewport: SyntaxViewport,
199
+ Code: SyntaxCode
154
200
  };
155
201
  export {
156
- Json,
202
+ JsonHighlighter,
203
+ Syntax,
157
204
  SyntaxHighlighter,
158
- createElement
205
+ createElement,
206
+ createSyntaxScope
159
207
  };
160
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\nimport { JSONPath } from 'jsonpath-plus';\nimport React, {\n createContext,\n type PropsWithChildren,\n forwardRef,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nimport { Input } from '@dxos/react-ui';\nimport { composable, composableProps } from '@dxos/ui-theme';\nimport { type ComposableProps } from '@dxos/ui-types';\nimport { type CreateReplacerProps, createReplacer, safeStringify } from '@dxos/util';\n\nimport { SyntaxHighlighter } from '../SyntaxHighlighter';\n\n//\n// Context\n//\n\ntype JsonContextType = {\n data: any;\n filteredData: any;\n filterText: string;\n setFilterText: (text: string) => void;\n filterError: Error | null;\n replacer?: CreateReplacerProps;\n};\n\nconst JsonContext = createContext<JsonContextType | null>(null);\n\n/** Require Json context (throws if used outside Json.Root). */\nconst useJsonContext = (consumerName: string): JsonContextType => {\n const context = useContext(JsonContext);\n if (!context) {\n throw new Error(`\\`${consumerName}\\` must be used within \\`Json.Root\\`.`);\n }\n return context;\n};\n\n/** Optional Json context (returns null outside Json.Root). */\nconst useOptionalJsonContext = (): JsonContextType | null => {\n return useContext(JsonContext);\n};\n\n//\n// Root\n//\n\nconst JSON_ROOT_NAME = 'Json.Root';\n\ntype JsonRootProps = PropsWithChildren<{\n data?: any;\n replacer?: CreateReplacerProps;\n}>;\n\n/** Headless context provider for Json composite. */\nconst JsonRoot = forwardRef<HTMLDivElement, JsonRootProps>(({ children, data, replacer }, _forwardedRef) => {\n const [filterText, setFilterText] = useState('');\n const [filteredData, setFilteredData] = useState(data);\n const [filterError, setFilterError] = useState<Error | null>(null);\n\n useEffect(() => {\n if (!filterText.trim().length) {\n setFilteredData(data);\n setFilterError(null);\n } else {\n try {\n setFilteredData(JSONPath({ path: filterText, json: data }));\n setFilterError(null);\n } catch (err) {\n setFilteredData(data);\n setFilterError(err as Error);\n }\n }\n }, [data, filterText]);\n\n const context = useMemo(\n () => ({ data, filteredData, filterText, setFilterText, filterError, replacer }),\n [data, filteredData, filterText, setFilterText, filterError, replacer],\n );\n\n return <JsonContext.Provider value={context}>{children}</JsonContext.Provider>;\n});\n\nJsonRoot.displayName = JSON_ROOT_NAME;\n\n//\n// Content\n//\n\nconst JSON_CONTENT_NAME = 'Json.Content';\n\ntype JsonContentProps = ComposableProps;\n\n/** Layout container for Json composite parts. */\nconst JsonContent = composable<HTMLDivElement, JsonContentProps>(({ 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\nJsonContent.displayName = JSON_CONTENT_NAME;\n\n//\n// Filter\n//\n\nconst JSON_FILTER_NAME = 'Json.Filter';\n\ntype JsonFilterProps = ComposableProps<{\n placeholder?: string;\n}>;\n\n/** JSONPath filter input. Must be used within Json.Root. */\nconst JsonFilter = forwardRef<HTMLInputElement, JsonFilterProps>(\n ({ classNames, placeholder = 'JSONPath (e.g., $.graph.nodes)' }, forwardedRef) => {\n const { filterText, setFilterText, filterError } = useJsonContext(JSON_FILTER_NAME);\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\nJsonFilter.displayName = JSON_FILTER_NAME;\n\n//\n// Data\n//\n\nconst JSON_DATA_NAME = 'Json.Data';\n\ntype JsonDataProps = ComposableProps<{\n data?: any;\n replacer?: CreateReplacerProps;\n testId?: string;\n}>;\n\n/** Syntax-highlighted JSON display. Works standalone or within Json.Root. */\nconst JsonData = composable<HTMLDivElement, JsonDataProps>(\n ({ data: dataProp, replacer: replacerProp, testId, ...props }, forwardedRef) => {\n const context = useOptionalJsonContext();\n const data = dataProp ?? context?.filteredData;\n const replacer = replacerProp ?? context?.replacer;\n\n return (\n <SyntaxHighlighter\n {...composableProps(props, { classNames: 'flex-1 min-h-0 w-full py-1 px-2 overflow-y-auto text-sm' })}\n language='json'\n data-testid={testId}\n ref={forwardedRef}\n >\n {safeStringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n );\n },\n);\n\nJsonData.displayName = JSON_DATA_NAME;\n\n//\n// Json\n//\n\nexport const Json = {\n Root: JsonRoot,\n Content: JsonContent,\n Filter: JsonFilter,\n Data: JsonData,\n};\n\nexport type { JsonRootProps, JsonContentProps, JsonFilterProps, JsonDataProps };\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, { CSSProperties } 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 { ScrollArea, useThemeContext } from '@dxos/react-ui';\nimport { composable, composableProps } from '@dxos/ui-theme';\n\nconst zeroWidthSpace = '\\u200b';\n\nconst languages = {\n js: 'javascript',\n ts: 'typescript',\n};\n\nexport type SyntaxHighlighterProps = NaturalSyntaxHighlighterProps & {\n fallback?: string;\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 */\nexport const SyntaxHighlighter = composable<HTMLDivElement, SyntaxHighlighterProps>(\n (\n { children, language = 'text', fallback = zeroWidthSpace, classNames, className, style, ...nativeProps },\n forwardedRef,\n ) => {\n const { themeMode } = useThemeContext();\n\n return (\n <ScrollArea.Root {...composableProps({ classNames, className })} thin ref={forwardedRef}>\n <ScrollArea.Viewport>\n {/* NOTE: The div prevents NativeSyntaxHighlighter from managing scrolling. */}\n <div role='none'>\n <NativeSyntaxHighlighter\n language={languages[language as keyof typeof languages] || language}\n style={(style as { [key: string]: CSSProperties }) ?? (themeMode === 'dark' ? dark : light)}\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 {children || fallback}\n </NativeSyntaxHighlighter>\n </div>\n </ScrollArea.Viewport>\n </ScrollArea.Root>\n );\n },\n);\n\nSyntaxHighlighter.displayName = 'SyntaxHighlighter';\n"],
5
- "mappings": ";AAIA,SAASA,gBAAgB;AACzB,OAAOC,UACLC,eAEAC,YACAC,YACAC,WACAC,SACAC,gBACK;AAEP,SAASC,aAAa;AACtB,SAASC,cAAAA,aAAYC,mBAAAA,wBAAuB;AAE5C,SAAmCC,g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,SACE,gBAAAb,OAAA,cAACgB,MAAMC,MAAI;IAACC,mBAAmB5B,cAAc,UAAU;KACrD,gBAAAU,OAAA,cAACgB,MAAMG,WAAS;IACdR,YAAY;MAAC;MAAsBrB,eAAe;MAAmBqB;;IACrES,SAAQ;IACRlB,OAAOjB;IACP8B;IACAM,UAAU,CAACC,UAAUpC,cAAcoC,MAAMC,OAAOrB,KAAK;IACrDU,KAAKJ;;AAIb,CAAA;AAGFM,WAAWX,cAAcU;AAMzB,IAAMW,iBAAiB;AASvB,IAAMC,WAAWnB,YACf,CAAC,EAAExB,MAAM4C,UAAU3C,UAAU4C,cAAcC,QAAQ,GAAGrB,MAAAA,GAASC,iBAAAA;AAC7D,QAAMlC,UAAUG,uBAAAA;AAChB,QAAMK,OAAO4C,YAAYpD,SAASc;AAClC,QAAML,WAAW4C,gBAAgBrD,SAASS;AAE1C,SACE,gBAAAiB,OAAA,cAAC6B,mBAAAA;IACE,GAAGnB,iBAAgBH,OAAO;MAAEI,YAAY;IAA0D,CAAA;IACnGmB,UAAS;IACTC,eAAaH;IACbhB,KAAKJ;KAEJwB,cAAclD,MAAMC,YAAYkD,eAAelD,QAAAA,GAAW,CAAA,CAAA;AAGjE,CAAA;AAGF0C,SAAStB,cAAcqB;AAMhB,IAAMU,OAAO;EAClBjB,MAAMtC;EACNwD,SAAS9B;EACT+B,QAAQtB;EACRuB,MAAMZ;AACR;",
6
- "names": ["JSONPath", "React", "createContext", "forwardRef", "useContext", "useEffect", "useMemo", "useState", "Input", "composable", "composableProps", "createReplacer", "safeStringify", "createElement", "React", "NativeSyntaxHighlighter", "coldarkDark", "dark", "coldarkCold", "light", "ScrollArea", "useThemeContext", "composable", "composableProps", "zeroWidthSpace", "languages", "js", "ts", "SyntaxHighlighter", "composable", "children", "language", "fallback", "classNames", "className", "style", "nativeProps", "forwardedRef", "themeMode", "useThemeContext", "ScrollArea", "Root", "composableProps", "thin", "ref", "Viewport", "div", "role", "NativeSyntaxHighlighter", "dark", "light", "customStyle", "background", "border", "boxShadow", "padding", "margin", "displayName", "JsonContext", "createContext", "useJsonContext", "consumerName", "context", "useContext", "Error", "useOptionalJsonContext", "JSON_ROOT_NAME", "JsonRoot", "forwardRef", "children", "data", "replacer", "_forwardedRef", "filterText", "setFilterText", "useState", "filteredData", "setFilteredData", "filterError", "setFilterError", "useEffect", "trim", "length", "JSONPath", "path", "json", "err", "useMemo", "React", "Provider", "value", "displayName", "JSON_CONTENT_NAME", "JsonContent", "composable", "props", "forwardedRef", "div", "composableProps", "classNames", "ref", "JSON_FILTER_NAME", "JsonFilter", "placeholder", "Input", "Root", "validationValence", "TextInput", "variant", "onChange", "event", "target", "JSON_DATA_NAME", "JsonData", "dataProp", "replacerProp", "testId", "SyntaxHighlighter", "language", "data-testid", "safeStringify", "createReplacer", "Json", "Content", "Filter", "Data"]
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/ui-theme';\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/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: 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/ui-theme';\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,SAAmCC,gBAAgBC,qBAAqB;;;ACFxE,OAAOC,mBAAmB;;;ACD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AC4B,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":7063,"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/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":16024,"imports":[{"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/ui-theme","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/Json/index.ts":{"bytes":618,"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":12707},"dist/lib/browser/index.mjs":{"imports":[{"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/ui-theme","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/ui-theme","kind":"import-statement","external":true}],"exports":["Json","SyntaxHighlighter","createElement"],"entryPoint":"src/index.ts","inputs":{"src/Json/Json.tsx":{"bytesInOutput":3608},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":1359},"src/Json/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":5263}}}
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/ui-theme","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/ui-theme","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/ui-theme","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/ui-theme","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/ui-theme","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/ui-theme","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}}}