@dxos/react-ui-syntax-highlighter 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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,120 +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
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
13
  import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
15
14
  import { coldarkDark as dark, coldarkCold as light } from "react-syntax-highlighter/dist/esm/styles/prism";
16
- import { useThemeContext } from "@dxos/react-ui";
17
- import { mx } from "@dxos/react-ui-theme";
15
+ import { ScrollArea, useThemeContext } from "@dxos/react-ui";
16
+ import { composable, composableProps } from "@dxos/ui-theme";
18
17
  var zeroWidthSpace = "\u200B";
19
- var SyntaxHighlighter = ({ classNames, children, language = "text", fallback = zeroWidthSpace, ...props }) => {
20
- var _effect = _useSignals();
21
- try {
22
- const { themeMode } = useThemeContext();
23
- return /* @__PURE__ */ React.createElement("div", {
24
- className: mx("flex is-full p-1 overflow-hidden", classNames)
25
- }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
26
- className: "!m-0 is-full overflow-auto scrollbar-thin",
27
- language: languages[language] || language,
28
- style: themeMode === "dark" ? dark : light,
29
- customStyle: {
30
- background: "unset",
31
- border: "none",
32
- boxShadow: "none",
33
- padding: 0,
34
- margin: 0
35
- },
36
- ...props
37
- }, children || fallback));
38
- } finally {
39
- _effect.f();
40
- }
41
- };
42
18
  var languages = {
43
19
  js: "javascript",
44
20
  ts: "typescript"
45
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";
46
47
 
47
48
  // src/Json/Json.tsx
48
- var defaultClassNames = "grow overflow-y-auto text-sm";
49
- var Json = ({ filter, ...params }) => {
50
- var _effect = _useSignals2();
51
- try {
52
- if (filter) {
53
- return /* @__PURE__ */ React2.createElement(JsonFilter, params);
54
- }
55
- const { classNames, data, replacer, testId } = params;
56
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
57
- language: "json",
58
- classNames: [
59
- defaultClassNames,
60
- classNames
61
- ],
62
- "data-testid": testId
63
- }, safeStringify(data, replacer && createReplacer(replacer), 2));
64
- } finally {
65
- _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\`.`);
66
54
  }
55
+ return context;
67
56
  };
68
- var JsonFilter = ({ classNames, data: initialData, replacer, testId }) => {
69
- var _effect = _useSignals2();
70
- try {
71
- const [data, setData] = useState(initialData);
72
- const [text, setText] = useState("");
73
- const [error, setError] = useState(null);
74
- useEffect(() => {
75
- if (!initialData || !text.trim().length) {
76
- setData(initialData);
77
- } else {
78
- try {
79
- setData(jp.query(initialData, text));
80
- setError(null);
81
- } catch (err) {
82
- setData(initialData);
83
- setError(err);
84
- }
57
+ var useOptionalJsonContext = () => {
58
+ return useContext(JsonContext);
59
+ };
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);
85
79
  }
86
- }, [
87
- initialData,
88
- text
89
- ]);
90
- return /* @__PURE__ */ React2.createElement("div", {
91
- className: "flex flex-col grow overflow-hidden"
92
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
93
- validationValence: error ? "error" : "success"
94
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
95
- classNames: [
96
- "p-1 pli-2 font-mono",
97
- error && "border-red-500"
98
- ],
99
- variant: "subdued",
100
- value: text,
101
- onChange: (event) => setText(event.target.value),
102
- placeholder: "JSONPath (e.g., $.graph.nodes)"
103
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
104
- language: "json",
105
- classNames: [
106
- defaultClassNames,
107
- classNames
108
- ],
109
- "data-testid": testId
110
- }, safeStringify(data, replacer && createReplacer(replacer), 2)));
111
- } finally {
112
- _effect.f();
113
- }
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
114
154
  };
115
155
  export {
116
156
  Json,
117
- JsonFilter,
118
157
  SyntaxHighlighter,
119
158
  createElement
120
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): Use to jsonpath-plus.\nimport jp from 'jsonpath';\nimport React, { useEffect, useState } from 'react';\n\nimport { Input, type ThemedClassName } from '@dxos/react-ui';\nimport { type CreateReplacerProps, createReplacer, safeStringify } from '@dxos/util';\n\nimport { SyntaxHighlighter } from '../SyntaxHighlighter';\n\nconst defaultClassNames = 'grow overflow-y-auto text-sm';\n\nexport type JsonProps = ThemedClassName<{\n data?: any;\n filter?: boolean;\n replacer?: CreateReplacerProps;\n testId?: string;\n}>;\n\nexport const Json = ({ filter, ...params }: JsonProps) => {\n if (filter) {\n return <JsonFilter {...params} />;\n }\n\n const { classNames, data, replacer, testId } = params;\n return (\n <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>\n {safeStringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n );\n};\n\nexport const JsonFilter = ({ classNames, data: initialData, replacer, testId }: JsonProps) => {\n const [data, setData] = useState(initialData);\n const [text, setText] = useState('');\n const [error, setError] = useState<Error | null>(null);\n useEffect(() => {\n if (!initialData || !text.trim().length) {\n setData(initialData);\n } else {\n try {\n setData(jp.query(initialData, text));\n setError(null);\n } catch (err) {\n setData(initialData);\n setError(err as Error);\n }\n }\n }, [initialData, text]); // TODO(burdon): Need structural diff.\n\n return (\n <div className='flex flex-col grow overflow-hidden'>\n <Input.Root validationValence={error ? 'error' : 'success'}>\n <Input.TextInput\n classNames={['p-1 pli-2 font-mono', error && 'border-red-500']}\n variant='subdued'\n value={text}\n onChange={(event) => setText(event.target.value)}\n placeholder='JSONPath (e.g., $.graph.nodes)'\n />\n </Input.Root>\n <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>\n {safeStringify(data, replacer && createReplacer(replacer), 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 NaturalSyntaxHighlighterProps } from 'react-syntax-highlighter';\nimport NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-async-light';\nimport { coldarkDark as dark, coldarkCold as light } from 'react-syntax-highlighter/dist/esm/styles/prism';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst zeroWidthSpace = '\\u200b';\n\nexport type SyntaxHighlighterProps = ThemedClassName<\n NaturalSyntaxHighlighterProps & {\n fallback?: string;\n }\n>;\n\n/**\n * NOTE: Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.\n * The lightweight version will load specific language parsers asynchronously.\n *\n * https://github.com/react-syntax-highlighter/react-syntax-highlighter\n * https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html\n */\n// TODO(burdon): Replace with react-ui-editor (and reuse styles).\nexport const SyntaxHighlighter = ({\n classNames,\n children,\n language = 'text',\n fallback = zeroWidthSpace,\n ...props\n}: SyntaxHighlighterProps) => {\n const { themeMode } = useThemeContext();\n\n return (\n <div className={mx('flex is-full p-1 overflow-hidden', classNames)}>\n <NativeSyntaxHighlighter\n className='!m-0 is-full overflow-auto scrollbar-thin'\n language={languages[language as keyof typeof languages] || language}\n style={themeMode === 'dark' ? dark : light}\n customStyle={{\n background: 'unset',\n border: 'none',\n boxShadow: 'none',\n padding: 0,\n margin: 0,\n }}\n {...props}\n >\n {/* Non-empty fallback prevents collapse. */}\n {children || fallback}\n </NativeSyntaxHighlighter>\n </div>\n );\n};\n\nconst languages = {\n js: 'javascript',\n ts: 'typescript',\n};\n"],
5
- "mappings": ";;AAKA,OAAOA,QAAQ;AACf,OAAOC,UAASC,WAAWC,gBAAgB;AAE3C,SAASC,aAAmC;AAC5C,SAAmCC,gBAAgBC,qBAAqB;;;ACJxE,OAAOC,mBAAmB;;;;ACD1B,OAAOC,WAAW;AAElB,OAAOC,6BAA6B;AACpC,SAASC,eAAeC,MAAMC,eAAeC,aAAa;AAE1D,SAA+BC,uBAAuB;AACtD,SAASC,UAAU;AAEnB,IAAMC,iBAAiB;AAgBhB,IAAMC,oBAAoB,CAAC,EAChCC,YACAC,UACAC,WAAW,QACXC,WAAWL,gBACX,GAAGM,MAAAA,MACoB;;;AACvB,UAAM,EAAEC,UAAS,IAAKC,gBAAAA;AAEtB,WACE,sBAAA,cAACC,OAAAA;MAAIC,WAAWC,GAAG,oCAAoCT,UAAAA;OACrD,sBAAA,cAACU,yBAAAA;MACCF,WAAU;MACVN,UAAUS,UAAUT,QAAAA,KAAuCA;MAC3DU,OAAOP,cAAc,SAASQ,OAAOC;MACrCC,aAAa;QACXC,YAAY;QACZC,QAAQ;QACRC,WAAW;QACXC,SAAS;QACTC,QAAQ;MACV;MACC,GAAGhB;OAGHH,YAAYE,QAAAA,CAAAA;;;;AAIrB;AAEA,IAAMQ,YAAY;E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AAK;MAC/CI,aAAY;SAGhB,gBAAAnC,OAAA,cAACM,mBAAAA;MAAkBC,UAAS;MAAOL,YAAY;QAACN;QAAmBM;;MAAaM,eAAaH;OAC1FI,cAAcN,MAAMC,YAAYM,eAAeN,QAAAA,GAAW,CAAA,CAAA,CAAA;;;;AAInE;",
6
- "names": ["jp", "React", "useEffect", "useState", "Input", "createReplacer", "safeStringify", "createElement", "React", "NativeSyntaxHighlighter", "coldarkDark", "dark", "coldarkCold", "light", "useThemeContext", "mx", "zeroWidthSpace", "SyntaxHighlighter", "classNames", "children", "language", "fallback", "props", "themeMode", "useThemeContext", "div", "className", "mx", "NativeSyntaxHighlighter", "languages", "style", "dark", "light", "customStyle", "background", "border", "boxShadow", "padding", "margin", "js", "ts", "defaultClassNames", "Json", "filter", "params", "React", "JsonFilter", "classNames", "data", "replacer", "testId", "SyntaxHighlighter", "language", "data-testid", "safeStringify", "createReplacer", "initialData", "setData", "useState", "text", "setText", "error", "setError", "useEffect", "trim", "length", "jp", "query", "err", "div", "className", "Input", "Root", "validationValence", "TextInput", "variant", "value", "onChange", "event", "target", "placeholder"]
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,a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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":6165,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/SyntaxHighlighter/index.ts":{"bytes":979,"imports":[{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/SyntaxHighlighter.tsx","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"},"src/Json/Json.tsx":{"bytes":8431,"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/util","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":7621},"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/util","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"exports":["Json","JsonFilter","SyntaxHighlighter","createElement"],"entryPoint":"src/index.ts","inputs":{"src/Json/Json.tsx":{"bytesInOutput":2296},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":1274},"src/Json/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":3880}}}
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,122 +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
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
15
  import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
17
16
  import { coldarkDark as dark, coldarkCold as light } from "react-syntax-highlighter/dist/esm/styles/prism";
18
- import { useThemeContext } from "@dxos/react-ui";
19
- import { mx } from "@dxos/react-ui-theme";
17
+ import { ScrollArea, useThemeContext } from "@dxos/react-ui";
18
+ import { composable, composableProps } from "@dxos/ui-theme";
20
19
  var zeroWidthSpace = "\u200B";
21
- var SyntaxHighlighter = ({ classNames, children, language = "text", fallback = zeroWidthSpace, ...props }) => {
22
- var _effect = _useSignals();
23
- try {
24
- const { themeMode } = useThemeContext();
25
- return /* @__PURE__ */ React.createElement("div", {
26
- className: mx("flex is-full p-1 overflow-hidden", classNames)
27
- }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
28
- className: "!m-0 is-full overflow-auto scrollbar-thin",
29
- language: languages[language] || language,
30
- style: themeMode === "dark" ? dark : light,
31
- customStyle: {
32
- background: "unset",
33
- border: "none",
34
- boxShadow: "none",
35
- padding: 0,
36
- margin: 0
37
- },
38
- ...props
39
- }, children || fallback));
40
- } finally {
41
- _effect.f();
42
- }
43
- };
44
20
  var languages = {
45
21
  js: "javascript",
46
22
  ts: "typescript"
47
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";
48
49
 
49
50
  // src/Json/Json.tsx
50
- var defaultClassNames = "grow overflow-y-auto text-sm";
51
- var Json = ({ filter, ...params }) => {
52
- var _effect = _useSignals2();
53
- try {
54
- if (filter) {
55
- return /* @__PURE__ */ React2.createElement(JsonFilter, params);
56
- }
57
- const { classNames, data, replacer, testId } = params;
58
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
59
- language: "json",
60
- classNames: [
61
- defaultClassNames,
62
- classNames
63
- ],
64
- "data-testid": testId
65
- }, safeStringify(data, replacer && createReplacer(replacer), 2));
66
- } finally {
67
- _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\`.`);
68
56
  }
57
+ return context;
69
58
  };
70
- var JsonFilter = ({ classNames, data: initialData, replacer, testId }) => {
71
- var _effect = _useSignals2();
72
- try {
73
- const [data, setData] = useState(initialData);
74
- const [text, setText] = useState("");
75
- const [error, setError] = useState(null);
76
- useEffect(() => {
77
- if (!initialData || !text.trim().length) {
78
- setData(initialData);
79
- } else {
80
- try {
81
- setData(jp.query(initialData, text));
82
- setError(null);
83
- } catch (err) {
84
- setData(initialData);
85
- setError(err);
86
- }
59
+ var useOptionalJsonContext = () => {
60
+ return useContext(JsonContext);
61
+ };
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);
87
81
  }
88
- }, [
89
- initialData,
90
- text
91
- ]);
92
- return /* @__PURE__ */ React2.createElement("div", {
93
- className: "flex flex-col grow overflow-hidden"
94
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
95
- validationValence: error ? "error" : "success"
96
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
97
- classNames: [
98
- "p-1 pli-2 font-mono",
99
- error && "border-red-500"
100
- ],
101
- variant: "subdued",
102
- value: text,
103
- onChange: (event) => setText(event.target.value),
104
- placeholder: "JSONPath (e.g., $.graph.nodes)"
105
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
106
- language: "json",
107
- classNames: [
108
- defaultClassNames,
109
- classNames
110
- ],
111
- "data-testid": testId
112
- }, safeStringify(data, replacer && createReplacer(replacer), 2)));
113
- } finally {
114
- _effect.f();
115
- }
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
116
156
  };
117
157
  export {
118
158
  Json,
119
- JsonFilter,
120
159
  SyntaxHighlighter,
121
160
  createElement
122
161
  };