@dxos/react-ui-syntax-highlighter 0.8.4-main.f9ba587 → 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,97 +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";
6
- import { mx as mx2 } from "@dxos/react-ui-theme";
5
+ import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
6
+ import { createReplacer, safeStringify } from "@dxos/util";
7
7
 
8
8
  // src/SyntaxHighlighter/index.ts
9
9
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
10
10
 
11
11
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
12
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
13
12
  import React from "react";
14
- import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/light-async";
15
- import { github as light, a11yDark as dark } from "react-syntax-highlighter/dist/esm/styles/hljs";
16
- import { useThemeContext } from "@dxos/react-ui";
17
- 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";
18
17
  var zeroWidthSpace = "\u200B";
19
- light.hljs.background = "";
20
- dark.hljs.background = "";
21
- var SyntaxHighlighter = ({ classNames, children, fallback = zeroWidthSpace, ...props }) => {
22
- var _effect = _useSignals();
23
- try {
24
- const { themeMode } = useThemeContext();
25
- return /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
26
- className: mx("w-full p-0 font-thin overflow-auto scrollbar-thin !text-baseText", classNames),
27
- style: themeMode === "dark" ? dark : light,
28
- ...props
29
- }, children || fallback);
30
- } finally {
31
- _effect.f();
32
- }
18
+ var languages = {
19
+ js: "javascript",
20
+ ts: "typescript"
33
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";
34
47
 
35
48
  // src/Json/Json.tsx
36
- var Json = ({ data, classNames, testId }) => {
37
- var _effect = _useSignals2();
38
- try {
39
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
40
- language: "json",
41
- classNames: [
42
- "w-full",
43
- classNames
44
- ],
45
- "data-testid": testId
46
- }, JSON.stringify(data, null, 2));
47
- } finally {
48
- _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\`.`);
49
54
  }
55
+ return context;
56
+ };
57
+ var useOptionalJsonContext = () => {
58
+ return useContext(JsonContext);
50
59
  };
51
- var JsonFilter = ({ data: initialData, classNames, testId }) => {
52
- var _effect = _useSignals2();
53
- try {
54
- const [data, setData] = useState(initialData);
55
- const [text, setText] = useState("");
56
- const [error, setError] = useState(null);
57
- useEffect(() => {
58
- if (!initialData || !text.trim().length) {
59
- setData(initialData);
60
- } else {
61
- try {
62
- setData(jp.query(initialData, text));
63
- setError(null);
64
- } catch (err) {
65
- setData(initialData);
66
- setError(err);
67
- }
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);
68
79
  }
69
- }, [
70
- initialData,
71
- text
72
- ]);
73
- return /* @__PURE__ */ React2.createElement("div", {
74
- className: "flex flex-col grow overflow-hidden"
75
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
76
- validationValence: error ? "error" : "success"
77
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
78
- classNames: mx2("p-1 px-2 font-mono", error && "border-red-500"),
79
- variant: "subdued",
80
- value: text,
81
- onChange: (event) => setText(event.target.value),
82
- placeholder: "JSONPath (e.g., $.graph.nodes)"
83
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
84
- language: "json",
85
- classNames: mx2("grow overflow-y-auto", classNames),
86
- "data-testid": testId
87
- }, JSON.stringify(data, null, 2)));
88
- } finally {
89
- _effect.f();
90
- }
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
91
154
  };
92
155
  export {
93
156
  Json,
94
- JsonFilter,
95
157
  SyntaxHighlighter,
96
158
  createElement
97
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';\nimport { mx } from '@dxos/react-ui-theme';\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={mx('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={mx('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 { github as light, a11yDark as dark } 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;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A;AACRM,mBAASM,GAAAA;QACX;MACF;IACF,GAAG;MAACZ;MAAaG;KAAK;AAEtB,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,YAAY4B,IAAG,sBAAsBd,SAAS,gBAAA;MAC9Ce,SAAQ;MACRC,OAAOlB;MACPmB,UAAU,CAACC,UAAUnB,QAAQmB,MAAMC,OAAOH,KAAK;MAC/CI,aAAY;SAGhB,gBAAAhC,OAAA,cAACC,mBAAAA;MAAkBC,UAAS;MAAOJ,YAAY4B,IAAG,wBAAwB5B,UAAAA;MAAaK,eAAaJ;OACjGK,KAAKC,UAAUR,MAAM,MAAM,CAAA,CAAA,CAAA;;;;AAIpC;",
6
- "names": ["jp", "React", "useEffect", "useState", "Input", "mx", "createElement", "React", "NativeSyntaxHighlighter", "github", "light", "a11yDark", "dark", "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", "mx", "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 </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,gBAAgBC,qBAAqB;;;ACbxE,OAAOC,mBAAmB;;;ACD1B,OAAOC,WAA8B;AAErC,OAAOC,6BAA6B;AACpC,SAASC,eAAeC,MAAMC,eAAeC,aAAa;AAE1D,SAASC,YAAYC,uBAAuB;AAC5C,SAASC,YAAYC,uBAAuB;AAE5C,IAAMC,iBAAiB;AAEvB,IAAMC,YAAY;EAChBC,IAAI;EACJC,IAAI;AACN;AAaO,IAAMC,oBAAoBC,WAC/B,CACE,EAAEC,UAAUC,WAAW,QAAQC,WAAWR,gBAAgBS,YAAYC,WAAWC,OAAO,GAAGC,YAAAA,GAC3FC,iBAAAA;AAEA,QAAM,EAAEC,UAAS,IAAKC,gBAAAA;AAEtB,SACE,sBAAA,cAACC,WAAWC,MAAI;IAAE,GAAGC,gBAAgB;MAAET;MAAYC;IAAU,CAAA;IAAIS,MAAAA;IAAKC,KAAKP;KACzE,sBAAA,cAACG,WAAWK,UAAQ,MAElB,sBAAA,cAACC,OAAAA;IAAIC,MAAK;KACR,sBAAA,cAACC,yBAAAA;IACCjB,UAAUN,UAAUM,QAAAA,KAAuCA;IAC3DI,OAAQA,UAA+CG,cAAc,SAASW,OAAOC;IACrFC,aAAa;MACXC,YAAY;MACZC,QAAQ;MACRC,WAAW;MACXC,SAAS;MACTC,QAAQ;IACV;IACC,GAAGpB;KAGHN,YAAYE,QAAAA,CAAAA,CAAAA,CAAAA;AAMzB,CAAA;AAGFJ,kBAAkB6B,cAA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"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":7262,"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":"@dxos/react-ui-theme","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":6344},"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":"@dxos/react-ui-theme","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":1964},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":956},"src/Json/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":3230}}}
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,99 +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";
8
- import { mx as mx2 } from "@dxos/react-ui-theme";
7
+ import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
8
+ import { createReplacer, safeStringify } from "@dxos/util";
9
9
 
10
10
  // src/SyntaxHighlighter/index.ts
11
11
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
12
12
 
13
13
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
14
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
15
14
  import React from "react";
16
- import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/light-async";
17
- import { github as light, a11yDark as dark } from "react-syntax-highlighter/dist/esm/styles/hljs";
18
- import { useThemeContext } from "@dxos/react-ui";
19
- 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";
20
19
  var zeroWidthSpace = "\u200B";
21
- light.hljs.background = "";
22
- dark.hljs.background = "";
23
- var SyntaxHighlighter = ({ classNames, children, fallback = zeroWidthSpace, ...props }) => {
24
- var _effect = _useSignals();
25
- try {
26
- const { themeMode } = useThemeContext();
27
- return /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
28
- className: mx("w-full p-0 font-thin overflow-auto scrollbar-thin !text-baseText", classNames),
29
- style: themeMode === "dark" ? dark : light,
30
- ...props
31
- }, children || fallback);
32
- } finally {
33
- _effect.f();
34
- }
20
+ var languages = {
21
+ js: "javascript",
22
+ ts: "typescript"
35
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";
36
49
 
37
50
  // src/Json/Json.tsx
38
- var Json = ({ data, classNames, testId }) => {
39
- var _effect = _useSignals2();
40
- try {
41
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
42
- language: "json",
43
- classNames: [
44
- "w-full",
45
- classNames
46
- ],
47
- "data-testid": testId
48
- }, JSON.stringify(data, null, 2));
49
- } finally {
50
- _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\`.`);
51
56
  }
57
+ return context;
58
+ };
59
+ var useOptionalJsonContext = () => {
60
+ return useContext(JsonContext);
52
61
  };
53
- var JsonFilter = ({ data: initialData, classNames, testId }) => {
54
- var _effect = _useSignals2();
55
- try {
56
- const [data, setData] = useState(initialData);
57
- const [text, setText] = useState("");
58
- const [error, setError] = useState(null);
59
- useEffect(() => {
60
- if (!initialData || !text.trim().length) {
61
- setData(initialData);
62
- } else {
63
- try {
64
- setData(jp.query(initialData, text));
65
- setError(null);
66
- } catch (err) {
67
- setData(initialData);
68
- setError(err);
69
- }
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);
70
81
  }
71
- }, [
72
- initialData,
73
- text
74
- ]);
75
- return /* @__PURE__ */ React2.createElement("div", {
76
- className: "flex flex-col grow overflow-hidden"
77
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
78
- validationValence: error ? "error" : "success"
79
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
80
- classNames: mx2("p-1 px-2 font-mono", error && "border-red-500"),
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: mx2("grow overflow-y-auto", classNames),
88
- "data-testid": testId
89
- }, JSON.stringify(data, null, 2)));
90
- } finally {
91
- _effect.f();
92
- }
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
93
156
  };
94
157
  export {
95
158
  Json,
96
- JsonFilter,
97
159
  SyntaxHighlighter,
98
160
  createElement
99
161
  };