@dxos/react-ui-syntax-highlighter 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5

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.
@@ -1,102 +1,159 @@
1
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";
2
+ import { JSONPath } from "jsonpath-plus";
3
+ import React2, { createContext, forwardRef, useContext, useEffect, useMemo, useState } from "react";
5
4
  import { Input } from "@dxos/react-ui";
5
+ import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
6
+ import { createReplacer, safeStringify } from "@dxos/util";
6
7
 
7
8
  // src/SyntaxHighlighter/index.ts
8
9
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
9
10
 
10
11
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
11
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
12
12
  import React from "react";
13
- import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/light-async";
14
- import { a11yDark as dark, github as light } from "react-syntax-highlighter/dist/esm/styles/hljs";
15
- import { useThemeContext } from "@dxos/react-ui";
16
- import { mx } from "@dxos/react-ui-theme";
13
+ import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
14
+ import { coldarkDark as dark, coldarkCold as light } from "react-syntax-highlighter/dist/esm/styles/prism";
15
+ import { ScrollArea, useThemeContext } from "@dxos/react-ui";
16
+ import { composable, composableProps } from "@dxos/ui-theme";
17
17
  var zeroWidthSpace = "\u200B";
18
- light.hljs.background = "";
19
- dark.hljs.background = "";
20
- var SyntaxHighlighter = ({ classNames, children, fallback = zeroWidthSpace, ...props }) => {
21
- var _effect = _useSignals();
22
- try {
23
- const { themeMode } = useThemeContext();
24
- return /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
25
- className: mx("w-full p-0 font-thin overflow-auto scrollbar-thin !text-baseText", classNames),
26
- style: themeMode === "dark" ? dark : light,
27
- ...props
28
- }, children || fallback);
29
- } finally {
30
- _effect.f();
31
- }
18
+ var languages = {
19
+ js: "javascript",
20
+ ts: "typescript"
32
21
  };
22
+ var SyntaxHighlighter = composable(({ children, language = "text", fallback = zeroWidthSpace, classNames, className, style, ...nativeProps }, forwardedRef) => {
23
+ const { themeMode } = useThemeContext();
24
+ return /* @__PURE__ */ React.createElement(ScrollArea.Root, {
25
+ ...composableProps({
26
+ classNames,
27
+ className
28
+ }),
29
+ thin: true,
30
+ ref: forwardedRef
31
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React.createElement("div", {
32
+ role: "none"
33
+ }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
34
+ language: languages[language] || language,
35
+ style: style ?? (themeMode === "dark" ? dark : light),
36
+ customStyle: {
37
+ background: "unset",
38
+ border: "none",
39
+ boxShadow: "none",
40
+ padding: 0,
41
+ margin: 0
42
+ },
43
+ ...nativeProps
44
+ }, children || fallback))));
45
+ });
46
+ SyntaxHighlighter.displayName = "SyntaxHighlighter";
33
47
 
34
48
  // src/Json/Json.tsx
35
- var Json = ({ data, classNames, testId }) => {
36
- var _effect = _useSignals2();
37
- try {
38
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
39
- language: "json",
40
- classNames: [
41
- "w-full",
42
- classNames
43
- ],
44
- "data-testid": testId
45
- }, JSON.stringify(data, null, 2));
46
- } finally {
47
- _effect.f();
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\`.`);
48
54
  }
55
+ return context;
56
+ };
57
+ var useOptionalJsonContext = () => {
58
+ return useContext(JsonContext);
49
59
  };
50
- var JsonFilter = ({ data: initialData, classNames, testId }) => {
51
- var _effect = _useSignals2();
52
- try {
53
- const [data, setData] = useState(initialData);
54
- const [text, setText] = useState("");
55
- const [error, setError] = useState(null);
56
- useEffect(() => {
57
- if (!initialData || !text.trim().length) {
58
- setData(initialData);
59
- } else {
60
- try {
61
- setData(jp.query(initialData, text));
62
- setError(null);
63
- } catch (err) {
64
- setData(initialData);
65
- setError(err);
66
- }
60
+ var JSON_ROOT_NAME = "Json.Root";
61
+ var JsonRoot = /* @__PURE__ */ forwardRef(({ children, data, replacer }, _forwardedRef) => {
62
+ 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({
72
+ path: filterText,
73
+ json: data
74
+ }));
75
+ setFilterError(null);
76
+ } catch (err) {
77
+ setFilteredData(data);
78
+ setFilterError(err);
67
79
  }
68
- }, [
69
- initialData,
70
- text
71
- ]);
72
- return /* @__PURE__ */ React2.createElement("div", {
73
- className: "flex flex-col grow overflow-hidden"
74
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
75
- validationValence: error ? "error" : "success"
76
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
77
- classNames: [
78
- "p-1 px-2 font-mono",
79
- error && "border-red-500"
80
- ],
81
- variant: "subdued",
82
- value: text,
83
- onChange: (event) => setText(event.target.value),
84
- placeholder: "JSONPath (e.g., $.graph.nodes)"
85
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
86
- language: "json",
87
- classNames: [
88
- "grow overflow-y-auto",
89
- classNames
90
- ],
91
- "data-testid": testId
92
- }, JSON.stringify(data, null, 2)));
93
- } finally {
94
- _effect.f();
95
- }
80
+ }
81
+ }, [
82
+ data,
83
+ filterText
84
+ ]);
85
+ const context = useMemo(() => ({
86
+ data,
87
+ filteredData,
88
+ filterText,
89
+ setFilterText,
90
+ filterError,
91
+ 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
+ }, 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", {
108
+ ...composableProps2(props, {
109
+ classNames: "flex flex-col h-full min-h-0 overflow-hidden"
110
+ }),
111
+ ref: forwardedRef
112
+ }, children);
113
+ });
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, {
119
+ validationValence: filterError ? "error" : "success"
120
+ }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
121
+ classNames: [
122
+ "p-1 px-2 font-mono",
123
+ filterError && "border-rose-500",
124
+ classNames
125
+ ],
126
+ variant: "subdued",
127
+ value: filterText,
128
+ placeholder,
129
+ onChange: (event) => setFilterText(event.target.value),
130
+ ref: forwardedRef
131
+ }));
132
+ });
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",
144
+ "data-testid": testId,
145
+ ref: forwardedRef
146
+ }, safeStringify(data, replacer && createReplacer(replacer), 2));
147
+ });
148
+ JsonData.displayName = JSON_DATA_NAME;
149
+ var Json = {
150
+ Root: JsonRoot,
151
+ Content: JsonContent,
152
+ Filter: JsonFilter,
153
+ Data: JsonData
96
154
  };
97
155
  export {
98
156
  Json,
99
- JsonFilter,
100
157
  SyntaxHighlighter,
101
158
  createElement
102
159
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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): Move 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\nexport type JsonProps = ThemedClassName<{ data?: any; testId?: string }>;\n\nexport const Json = ({ data, classNames, testId }: JsonProps) => {\n return (\n <SyntaxHighlighter language='json' classNames={['w-full', classNames]} data-testid={testId}>\n {JSON.stringify(data, null, 2)}\n </SyntaxHighlighter>\n );\n};\n\nexport const JsonFilter = ({ data: initialData, classNames, 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={['grow overflow-y-auto', classNames]} data-testid={testId}>\n {JSON.stringify(data, null, 2)}\n </SyntaxHighlighter>\n </div>\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 NativeSyntaxHighlighterProps } from 'react-syntax-highlighter';\n// Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.\n// Lightweight version will load specific language parsers asynchronously.\n// eslint-disable-next-line no-restricted-imports\nimport NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/light-async';\n// eslint-disable-next-line no-restricted-imports\nimport { a11yDark as dark, github as light } from 'react-syntax-highlighter/dist/esm/styles/hljs';\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 NativeSyntaxHighlighterProps & {\n fallback?: string;\n }\n>;\n\nlight.hljs.background = '';\ndark.hljs.background = '';\n\n/**\n * https://github.com/react-syntax-highlighter/react-syntax-highlighter\n */\nexport const SyntaxHighlighter = ({\n classNames,\n children,\n fallback = zeroWidthSpace,\n ...props\n}: SyntaxHighlighterProps) => {\n const { themeMode } = useThemeContext();\n\n return (\n <NativeSyntaxHighlighter\n className={mx('w-full p-0 font-thin overflow-auto scrollbar-thin !text-baseText', classNames)}\n style={themeMode === 'dark' ? dark : light}\n {...props}\n >\n {/* Non-empty fallback prevents collapse. */}\n {children || fallback}\n </NativeSyntaxHighlighter>\n );\n};\n"],
5
- "mappings": ";;AAKA,OAAOA,QAAQ;AACf,OAAOC,UAASC,WAAWC,gBAAgB;AAE3C,SAASC,aAAmC;;;ACH5C,OAAOC,mBA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tB,WACE,gBAAAV,OAAA,cAACoB,OAAAA;MAAIC,WAAU;OACb,gBAAArB,OAAA,cAACsB,MAAMC,MAAI;MAACC,mBAAmBZ,QAAQ,UAAU;OAC/C,gBAAAZ,OAAA,cAACsB,MAAMG,WAAS;MACd3B,YAAY;QAAC;QAAsBc,SAAS;;MAC5Cc,SAAQ;MACRC,OAAOjB;MACPkB,UAAU,CAACC,UAAUlB,QAAQkB,MAAMC,OAAOH,KAAK;MAC/CI,aAAY;SAGhB,gBAAA/B,OAAA,cAACC,mBAAAA;MAAkBC,UAAS;MAAOJ,YAAY;QAAC;QAAwBA;;MAAaK,eAAaJ;OAC/FK,KAAKC,UAAUR,MAAM,MAAM,CAAA,CAAA,CAAA;;;;AAIpC;",
6
- "names": ["jp", "React", "useEffect", "useState", "Input", "createElement", "React", "NativeSyntaxHighlighter", "a11yDark", "dark", "github", "light", "useThemeContext", "mx", "zeroWidthSpace", "light", "hljs", "background", "dark", "SyntaxHighlighter", "classNames", "children", "fallback", "props", "themeMode", "useThemeContext", "NativeSyntaxHighlighter", "className", "mx", "style", "Json", "data", "classNames", "testId", "React", "SyntaxHighlighter", "language", "data-testid", "JSON", "stringify", "JsonFilter", "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"]
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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C,KAAKJ;KACnG3B,QAAAA;AAGP,CAAA;AAEAwB,YAAYF,cAAcC;AAM1B,IAAMS,mBAAmB;AAOzB,IAAMC,aAAalC,2BACjB,CAAC,EAAE+B,YAAYI,cAAc,iCAAgC,GAAIP,iBAAAA;AAC/D,QAAM,EAAEvB,YAAYC,eAAeI,YAAW,IAAKlB,eAAeyC,gBAAAA;AAElE,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"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytes":4893,"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/light-async","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/hljs","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":7207,"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":6244},"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/light-async","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/hljs","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"],"entryPoint":"src/index.ts","inputs":{"src/Json/Json.tsx":{"bytesInOutput":1956},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":956},"src/Json/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":3222}}}
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,104 +1,161 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/Json/Json.tsx
4
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
5
- import jp from "jsonpath";
6
- import React2, { useEffect, useState } from "react";
4
+ import { JSONPath } from "jsonpath-plus";
5
+ import React2, { createContext, forwardRef, useContext, useEffect, useMemo, useState } from "react";
7
6
  import { Input } from "@dxos/react-ui";
7
+ import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
8
+ import { createReplacer, safeStringify } from "@dxos/util";
8
9
 
9
10
  // src/SyntaxHighlighter/index.ts
10
11
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
11
12
 
12
13
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
13
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
14
14
  import React from "react";
15
- import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/light-async";
16
- import { a11yDark as dark, github as light } from "react-syntax-highlighter/dist/esm/styles/hljs";
17
- import { useThemeContext } from "@dxos/react-ui";
18
- import { mx } from "@dxos/react-ui-theme";
15
+ import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
16
+ import { coldarkDark as dark, coldarkCold as light } from "react-syntax-highlighter/dist/esm/styles/prism";
17
+ import { ScrollArea, useThemeContext } from "@dxos/react-ui";
18
+ import { composable, composableProps } from "@dxos/ui-theme";
19
19
  var zeroWidthSpace = "\u200B";
20
- light.hljs.background = "";
21
- dark.hljs.background = "";
22
- var SyntaxHighlighter = ({ classNames, children, fallback = zeroWidthSpace, ...props }) => {
23
- var _effect = _useSignals();
24
- try {
25
- const { themeMode } = useThemeContext();
26
- return /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
27
- className: mx("w-full p-0 font-thin overflow-auto scrollbar-thin !text-baseText", classNames),
28
- style: themeMode === "dark" ? dark : light,
29
- ...props
30
- }, children || fallback);
31
- } finally {
32
- _effect.f();
33
- }
20
+ var languages = {
21
+ js: "javascript",
22
+ ts: "typescript"
34
23
  };
24
+ var SyntaxHighlighter = composable(({ children, language = "text", fallback = zeroWidthSpace, classNames, className, style, ...nativeProps }, forwardedRef) => {
25
+ const { themeMode } = useThemeContext();
26
+ return /* @__PURE__ */ React.createElement(ScrollArea.Root, {
27
+ ...composableProps({
28
+ classNames,
29
+ className
30
+ }),
31
+ thin: true,
32
+ ref: forwardedRef
33
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React.createElement("div", {
34
+ role: "none"
35
+ }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
36
+ language: languages[language] || language,
37
+ style: style ?? (themeMode === "dark" ? dark : light),
38
+ customStyle: {
39
+ background: "unset",
40
+ border: "none",
41
+ boxShadow: "none",
42
+ padding: 0,
43
+ margin: 0
44
+ },
45
+ ...nativeProps
46
+ }, children || fallback))));
47
+ });
48
+ SyntaxHighlighter.displayName = "SyntaxHighlighter";
35
49
 
36
50
  // src/Json/Json.tsx
37
- var Json = ({ data, classNames, testId }) => {
38
- var _effect = _useSignals2();
39
- try {
40
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
41
- language: "json",
42
- classNames: [
43
- "w-full",
44
- classNames
45
- ],
46
- "data-testid": testId
47
- }, JSON.stringify(data, null, 2));
48
- } finally {
49
- _effect.f();
51
+ var JsonContext = /* @__PURE__ */ createContext(null);
52
+ var useJsonContext = (consumerName) => {
53
+ const context = useContext(JsonContext);
54
+ if (!context) {
55
+ throw new Error(`\`${consumerName}\` must be used within \`Json.Root\`.`);
50
56
  }
57
+ return context;
58
+ };
59
+ var useOptionalJsonContext = () => {
60
+ return useContext(JsonContext);
51
61
  };
52
- var JsonFilter = ({ data: initialData, classNames, testId }) => {
53
- var _effect = _useSignals2();
54
- try {
55
- const [data, setData] = useState(initialData);
56
- const [text, setText] = useState("");
57
- const [error, setError] = useState(null);
58
- useEffect(() => {
59
- if (!initialData || !text.trim().length) {
60
- setData(initialData);
61
- } else {
62
- try {
63
- setData(jp.query(initialData, text));
64
- setError(null);
65
- } catch (err) {
66
- setData(initialData);
67
- setError(err);
68
- }
62
+ var JSON_ROOT_NAME = "Json.Root";
63
+ var JsonRoot = /* @__PURE__ */ forwardRef(({ children, data, replacer }, _forwardedRef) => {
64
+ const [filterText, setFilterText] = useState("");
65
+ const [filteredData, setFilteredData] = useState(data);
66
+ const [filterError, setFilterError] = useState(null);
67
+ useEffect(() => {
68
+ if (!filterText.trim().length) {
69
+ setFilteredData(data);
70
+ setFilterError(null);
71
+ } else {
72
+ try {
73
+ setFilteredData(JSONPath({
74
+ path: filterText,
75
+ json: data
76
+ }));
77
+ setFilterError(null);
78
+ } catch (err) {
79
+ setFilteredData(data);
80
+ setFilterError(err);
69
81
  }
70
- }, [
71
- initialData,
72
- text
73
- ]);
74
- return /* @__PURE__ */ React2.createElement("div", {
75
- className: "flex flex-col grow overflow-hidden"
76
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
77
- validationValence: error ? "error" : "success"
78
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
79
- classNames: [
80
- "p-1 px-2 font-mono",
81
- error && "border-red-500"
82
- ],
83
- variant: "subdued",
84
- value: text,
85
- onChange: (event) => setText(event.target.value),
86
- placeholder: "JSONPath (e.g., $.graph.nodes)"
87
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
88
- language: "json",
89
- classNames: [
90
- "grow overflow-y-auto",
91
- classNames
92
- ],
93
- "data-testid": testId
94
- }, JSON.stringify(data, null, 2)));
95
- } finally {
96
- _effect.f();
97
- }
82
+ }
83
+ }, [
84
+ data,
85
+ filterText
86
+ ]);
87
+ const context = useMemo(() => ({
88
+ data,
89
+ filteredData,
90
+ filterText,
91
+ setFilterText,
92
+ filterError,
93
+ replacer
94
+ }), [
95
+ data,
96
+ filteredData,
97
+ filterText,
98
+ setFilterText,
99
+ filterError,
100
+ replacer
101
+ ]);
102
+ return /* @__PURE__ */ React2.createElement(JsonContext.Provider, {
103
+ value: context
104
+ }, children);
105
+ });
106
+ JsonRoot.displayName = JSON_ROOT_NAME;
107
+ var JSON_CONTENT_NAME = "Json.Content";
108
+ var JsonContent = composable2(({ children, ...props }, forwardedRef) => {
109
+ return /* @__PURE__ */ React2.createElement("div", {
110
+ ...composableProps2(props, {
111
+ classNames: "flex flex-col h-full min-h-0 overflow-hidden"
112
+ }),
113
+ ref: forwardedRef
114
+ }, children);
115
+ });
116
+ JsonContent.displayName = JSON_CONTENT_NAME;
117
+ var JSON_FILTER_NAME = "Json.Filter";
118
+ var JsonFilter = /* @__PURE__ */ forwardRef(({ classNames, placeholder = "JSONPath (e.g., $.graph.nodes)" }, forwardedRef) => {
119
+ const { filterText, setFilterText, filterError } = useJsonContext(JSON_FILTER_NAME);
120
+ return /* @__PURE__ */ React2.createElement(Input.Root, {
121
+ validationValence: filterError ? "error" : "success"
122
+ }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
123
+ classNames: [
124
+ "p-1 px-2 font-mono",
125
+ filterError && "border-rose-500",
126
+ classNames
127
+ ],
128
+ variant: "subdued",
129
+ value: filterText,
130
+ placeholder,
131
+ onChange: (event) => setFilterText(event.target.value),
132
+ ref: forwardedRef
133
+ }));
134
+ });
135
+ JsonFilter.displayName = JSON_FILTER_NAME;
136
+ var JSON_DATA_NAME = "Json.Data";
137
+ var JsonData = composable2(({ data: dataProp, replacer: replacerProp, testId, ...props }, forwardedRef) => {
138
+ const context = useOptionalJsonContext();
139
+ const data = dataProp ?? context?.filteredData;
140
+ const replacer = replacerProp ?? context?.replacer;
141
+ return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
142
+ ...composableProps2(props, {
143
+ classNames: "flex-1 min-h-0 w-full py-1 px-2 overflow-y-auto text-sm"
144
+ }),
145
+ language: "json",
146
+ "data-testid": testId,
147
+ ref: forwardedRef
148
+ }, safeStringify(data, replacer && createReplacer(replacer), 2));
149
+ });
150
+ JsonData.displayName = JSON_DATA_NAME;
151
+ var Json = {
152
+ Root: JsonRoot,
153
+ Content: JsonContent,
154
+ Filter: JsonFilter,
155
+ Data: JsonData
98
156
  };
99
157
  export {
100
158
  Json,
101
- JsonFilter,
102
159
  SyntaxHighlighter,
103
160
  createElement
104
161
  };