@invana/editor 0.0.28 → 0.0.30

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.
package/dist/index.cjs CHANGED
@@ -122,7 +122,7 @@ function CodeBlock({
122
122
  ref,
123
123
  className: ui.cn(
124
124
  "overflow-hidden border border-border bg-muted/40 [&_.cm-editor]:bg-transparent",
125
- "[&_.cm-content]:font-mono [&_.cm-content]:text-meta [&_.cm-focused]:outline-none",
125
+ "[&_.cm-content]:font-mono [&_.cm-content]:text-sm [&_.cm-focused]:outline-none",
126
126
  "[&_.cm-gutters]:border-none [&_.cm-gutters]:bg-transparent [&_.cm-gutters]:text-muted-foreground",
127
127
  className
128
128
  ),
@@ -154,13 +154,13 @@ function MarkdownEditorBlock({
154
154
  );
155
155
  const { ref } = useCodeMirror({ value, extensions, onChange });
156
156
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ui.cn("relative border border-border bg-muted/40", className), ...props, children: [
157
- version != null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute right-1 top-1 z-10 border border-border bg-card px-1 text-meta text-muted-foreground", children: version }) : null,
157
+ version != null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute right-1 top-1 z-10 border border-border bg-card px-1 text-sm text-muted-foreground", children: version }) : null,
158
158
  /* @__PURE__ */ jsxRuntime.jsx(
159
159
  "div",
160
160
  {
161
161
  ref,
162
162
  className: ui.cn(
163
- "[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-meta",
163
+ "[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-sm",
164
164
  "[&_.cm-focused]:outline-none [&_.cm-cursor]:border-foreground"
165
165
  )
166
166
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-code-mirror.ts","../src/code-block.tsx","../src/markdown-editor-block.tsx"],"names":["React","view","Compartment","EditorView","EditorState","StreamLanguage","python","shell","javascript","json","cypher","language","React2","sy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,gFAAA;AAAA,QACA,kFAAA;AAAA,QACA,kGAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA,KAAA;AAAA,MACC,GAAG;AAAA;AAAA,GACN;AAEJ;ACrEO,SAAS,mBAAA,CAAoB;AAAA,EAClC,KAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,EAA6B;AAC3B,EAAA,MAAM,UAAA,GAAmBC,gBAAA,CAAA,OAAA;AAAA,IACvB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,MAKJf,eAAAA,CAAW,YAAA;AAAA,MACXgB,gBAAA,EAAQ;AAAA,MACRC,YAAO,EAAA,CAAG,CAAC,GAAGC,sBAAA,EAAe,GAAGC,sBAAa,CAAC,CAAA;AAAA,MAC9CnB,eAAAA,CAAW,QAAA,CAAS,EAAA,CAAG,CAAC,QAAQ;AAAA,KAClC;AAAA,IACA,CAAC,QAAQ;AAAA,GACX;AAEA,EAAA,MAAM,EAAE,KAAI,GAAI,aAAA,CAAc,EAAE,KAAA,EAAO,UAAA,EAAY,UAAU,CAAA;AAE7D,EAAA,uBACEoB,eAAA,CAAC,SAAI,SAAA,EAAWN,KAAAA,CAAG,6CAA6C,SAAS,CAAA,EAAI,GAAG,KAAA,EAC7E,QAAA,EAAA;AAAA,IAAA,OAAA,IAAW,uBACVD,cAAAA,CAAC,UAAK,SAAA,EAAU,+FAAA,EACb,mBACH,CAAA,GACE,IAAA;AAAA,oBACJA,cAAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,SAAA,EAAWC,KAAAA;AAAA,UACT,mFAAA;AAAA,UACA;AAAA;AACF;AAAA;AACF,GAAA,EACF,CAAA;AAEJ","file":"index.cjs","sourcesContent":["import * as React from \"react\"\nimport { Compartment, EditorState, type Extension } from \"@codemirror/state\"\nimport { EditorView } from \"@codemirror/view\"\n\nexport interface UseCodeMirrorOptions {\n value: string\n extensions: Extension[]\n onChange?: (value: string) => void\n}\n\n/**\n * Mounts a CodeMirror view into a ref'd element and keeps it in sync.\n *\n * The whole reason this is a hook rather than a component: CodeMirror owns its\n * own DOM, so React must not re-render into it. Value changes are pushed as\n * transactions, and only when they actually differ — writing the view's own\n * output back into it would move the cursor to the end on every keystroke.\n */\nexport function useCodeMirror({\n value,\n extensions,\n onChange,\n}: UseCodeMirrorOptions) {\n const host = React.useRef<HTMLDivElement | null>(null)\n const view = React.useRef<EditorView | null>(null)\n\n // Keep the latest onChange without tearing down the view when it changes\n // identity — a caller passing an inline arrow would otherwise remount the\n // editor on every render.\n const onChangeRef = React.useRef(onChange)\n React.useEffect(() => {\n onChangeRef.current = onChange\n }, [onChange])\n\n // The view is created once and reconfigured in place. Keying the effect on\n // `extensions` identity looked simpler, but a caller passing an inline array\n // would then rebuild the editor on every render — losing the cursor, the\n // selection and focus mid-keystroke. \"Callers are expected to memoise\" is a\n // trap, not a contract, so the hook does not depend on it.\n const extensionsRef = React.useRef(extensions)\n extensionsRef.current = extensions\n\n const compartment = React.useRef(new Compartment())\n\n React.useEffect(() => {\n if (!host.current) return\n const v = new EditorView({\n state: EditorState.create({\n doc: value,\n extensions: [\n compartment.current.of(extensionsRef.current),\n EditorView.updateListener.of((u) => {\n if (u.docChanged) onChangeRef.current?.(u.state.doc.toString())\n }),\n ],\n }),\n parent: host.current,\n })\n view.current = v\n return () => {\n v.destroy()\n view.current = null\n }\n // Mount once. Configuration changes go through the compartment below.\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Swap configuration without touching the document — this is what a\n // Compartment is for, and it is why toggling `readOnly` or a language keeps\n // the caret where it was.\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n v.dispatch({ effects: compartment.current.reconfigure(extensions) })\n }, [extensions])\n\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n const current = v.state.doc.toString()\n if (current === value) return\n v.dispatch({ changes: { from: 0, to: current.length, insert: value } })\n }, [value])\n\n return { ref: host, view }\n}\n","import * as React from \"react\"\nimport { EditorView, lineNumbers } from \"@codemirror/view\"\nimport { EditorState } from \"@codemirror/state\"\nimport {\n StreamLanguage,\n syntaxHighlighting,\n defaultHighlightStyle,\n} from \"@codemirror/language\"\nimport { python } from \"@codemirror/legacy-modes/mode/python\"\nimport { shell } from \"@codemirror/legacy-modes/mode/shell\"\nimport { javascript, json } from \"@codemirror/legacy-modes/mode/javascript\"\nimport { cypher } from \"@codemirror/legacy-modes/mode/cypher\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport type CodeLanguage =\n | \"python\"\n | \"shell\"\n | \"javascript\"\n | \"json\"\n | \"cypher\"\n | \"plain\"\n\nexport interface CodeBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n value: string\n language?: CodeLanguage\n /** Line numbers are off by default — a five-line snippet does not need a gutter. */\n showLineNumbers?: boolean\n /**\n * Cap the block's height in px and let it scroll inside that, for a document\n * whose length is not the point — a run's `result.json`, an exported model.\n *\n * Unset, the block is as tall as its content, which is right for a snippet\n * and wrong for a record that grows as a run proceeds.\n */\n maxHeight?: number\n}\n\nconst MODES = {\n python: () => StreamLanguage.define(python),\n shell: () => StreamLanguage.define(shell),\n javascript: () => StreamLanguage.define(javascript),\n json: () => StreamLanguage.define(json),\n cypher: () => StreamLanguage.define(cypher),\n plain: () => null,\n}\n\n/**\n * Code, shown as it is — read-only.\n *\n * The DAG in a hand-off, a query in a diagnosis, an exported model. It is not a\n * disabled editor: `EditorState.readOnly` plus a non-editable view means there\n * is no cursor to place and no illusion that typing would do something.\n */\nexport function CodeBlock({\n value,\n language = \"plain\",\n showLineNumbers,\n maxHeight,\n className,\n style,\n ...props\n}: CodeBlockProps) {\n const extensions = React.useMemo(() => {\n const mode = MODES[language]()\n return [\n // StreamLanguage only produces tokens; without a highlight style nothing\n // paints them and the block renders as flat text.\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n EditorView.editable.of(false),\n EditorState.readOnly.of(true),\n EditorView.lineWrapping,\n ...(showLineNumbers ? [lineNumbers()] : []),\n ...(mode ? [mode] : []),\n // The scroller lives inside CodeMirror rather than on the wrapper, so the\n // editor knows its own viewport and does not render every line of a long\n // document into a box that then clips them.\n ...(maxHeight != null\n ? [EditorView.theme({ \"&\": { maxHeight: `${maxHeight}px` } })]\n : []),\n ]\n }, [language, showLineNumbers, maxHeight])\n\n const { ref } = useCodeMirror({ value, extensions })\n\n return (\n <div\n ref={ref}\n className={cn(\n \"overflow-hidden border border-border bg-muted/40 [&_.cm-editor]:bg-transparent\",\n \"[&_.cm-content]:font-mono [&_.cm-content]:text-meta [&_.cm-focused]:outline-none\",\n \"[&_.cm-gutters]:border-none [&_.cm-gutters]:bg-transparent [&_.cm-gutters]:text-muted-foreground\",\n className,\n )}\n style={style}\n {...props}\n />\n )\n}\n","import * as React from \"react\"\nimport { EditorView } from \"@codemirror/view\"\nimport { history, defaultKeymap, historyKeymap } from \"@codemirror/commands\"\nimport { keymap } from \"@codemirror/view\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport interface MarkdownEditorBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n value: string\n onChange?: (value: string) => void\n readOnly?: boolean\n /** A version marker shown in the corner — `v5`, `v7 · editing`. */\n version?: React.ReactNode\n placeholder?: string\n}\n\n/**\n * The prose a person writes for an agent to read — graph rules, a skill's\n * content, an acceptance note.\n *\n * Plain markdown in a monospace field, not a rich-text editor. What is typed\n * here is offered verbatim in a model's prompt, so what you see has to be\n * exactly what the agent gets; a WYSIWYG layer would put a translation step\n * between the author and the thing that runs.\n *\n * `version` sits in the corner because these documents are versioned and a\n * running thinking finishes on the version it started with — editing without\n * seeing which version you are on is how two people overwrite each other.\n */\nexport function MarkdownEditorBlock({\n value,\n onChange,\n readOnly,\n version,\n className,\n ...props\n}: MarkdownEditorBlockProps) {\n const extensions = React.useMemo(\n () => [\n // No markdown syntax mode, deliberately. What is typed here is offered\n // verbatim in a model's prompt, and highlighting it would be decoration\n // on text whose whole contract is that it is plain. It also keeps this\n // package's dependencies to the CodeMirror set the product already ships.\n EditorView.lineWrapping,\n history(),\n keymap.of([...defaultKeymap, ...historyKeymap]),\n EditorView.editable.of(!readOnly),\n ],\n [readOnly],\n )\n\n const { ref } = useCodeMirror({ value, extensions, onChange })\n\n return (\n <div className={cn(\"relative border border-border bg-muted/40\", className)} {...props}>\n {version != null ? (\n <span className=\"absolute right-1 top-1 z-10 border border-border bg-card px-1 text-meta text-muted-foreground\">\n {version}\n </span>\n ) : null}\n <div\n ref={ref}\n className={cn(\n \"[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-meta\",\n \"[&_.cm-focused]:outline-none [&_.cm-cursor]:border-foreground\",\n )}\n />\n </div>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/use-code-mirror.ts","../src/code-block.tsx","../src/markdown-editor-block.tsx"],"names":["React","view","Compartment","EditorView","EditorState","StreamLanguage","python","shell","javascript","json","cypher","language","React2","syntaxHighlighting","defaultHighlightStyle","lineNumbers","jsx","cn","React3","history","keymap","defaultKeymap","historyKeymap","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,SAAS,aAAA,CAAc;AAAA,EAC5B,KAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA,EAAyB;AACvB,EAAA,MAAM,IAAA,GAAaA,wBAA8B,IAAI,CAAA;AACrD,EAAA,MAAMC,MAAA,GAAaD,wBAA0B,IAAI,CAAA;AAKjD,EAAA,MAAM,WAAA,GAAoBA,wBAAO,QAAQ,CAAA;AACzC,EAAMA,2BAAU,MAAM;AACpB,IAAA,WAAA,CAAY,OAAA,GAAU,QAAA;AAAA,EACxB,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAOb,EAAA,MAAM,aAAA,GAAsBA,wB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AAAA,CAAW,QAAA,CAAS,EAAA,CAAG,CAAC,QAAQ;AAAA,KAClC;AAAA,IACA,CAAC,QAAQ;AAAA,GACX;AAEA,EAAA,MAAM,EAAE,KAAI,GAAI,aAAA,CAAc,EAAE,KAAA,EAAO,UAAA,EAAY,UAAU,CAAA;AAE7D,EAAA,uBACEoB,eAAA,CAAC,SAAI,SAAA,EAAWN,KAAAA,CAAG,6CAA6C,SAAS,CAAA,EAAI,GAAG,KAAA,EAC7E,QAAA,EAAA;AAAA,IAAA,OAAA,IAAW,uBACVD,cAAAA,CAAC,UAAK,SAAA,EAAU,6FAAA,EACb,mBACH,CAAA,GACE,IAAA;AAAA,oBACJA,cAAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,SAAA,EAAWC,KAAAA;AAAA,UACT,iFAAA;AAAA,UACA;AAAA;AACF;AAAA;AACF,GAAA,EACF,CAAA;AAEJ","file":"index.cjs","sourcesContent":["import * as React from \"react\"\nimport { Compartment, EditorState, type Extension } from \"@codemirror/state\"\nimport { EditorView } from \"@codemirror/view\"\n\nexport interface UseCodeMirrorOptions {\n value: string\n extensions: Extension[]\n onChange?: (value: string) => void\n}\n\n/**\n * Mounts a CodeMirror view into a ref'd element and keeps it in sync.\n *\n * The whole reason this is a hook rather than a component: CodeMirror owns its\n * own DOM, so React must not re-render into it. Value changes are pushed as\n * transactions, and only when they actually differ — writing the view's own\n * output back into it would move the cursor to the end on every keystroke.\n */\nexport function useCodeMirror({\n value,\n extensions,\n onChange,\n}: UseCodeMirrorOptions) {\n const host = React.useRef<HTMLDivElement | null>(null)\n const view = React.useRef<EditorView | null>(null)\n\n // Keep the latest onChange without tearing down the view when it changes\n // identity — a caller passing an inline arrow would otherwise remount the\n // editor on every render.\n const onChangeRef = React.useRef(onChange)\n React.useEffect(() => {\n onChangeRef.current = onChange\n }, [onChange])\n\n // The view is created once and reconfigured in place. Keying the effect on\n // `extensions` identity looked simpler, but a caller passing an inline array\n // would then rebuild the editor on every render — losing the cursor, the\n // selection and focus mid-keystroke. \"Callers are expected to memoise\" is a\n // trap, not a contract, so the hook does not depend on it.\n const extensionsRef = React.useRef(extensions)\n extensionsRef.current = extensions\n\n const compartment = React.useRef(new Compartment())\n\n React.useEffect(() => {\n if (!host.current) return\n const v = new EditorView({\n state: EditorState.create({\n doc: value,\n extensions: [\n compartment.current.of(extensionsRef.current),\n EditorView.updateListener.of((u) => {\n if (u.docChanged) onChangeRef.current?.(u.state.doc.toString())\n }),\n ],\n }),\n parent: host.current,\n })\n view.current = v\n return () => {\n v.destroy()\n view.current = null\n }\n // Mount once. Configuration changes go through the compartment below.\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Swap configuration without touching the document — this is what a\n // Compartment is for, and it is why toggling `readOnly` or a language keeps\n // the caret where it was.\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n v.dispatch({ effects: compartment.current.reconfigure(extensions) })\n }, [extensions])\n\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n const current = v.state.doc.toString()\n if (current === value) return\n v.dispatch({ changes: { from: 0, to: current.length, insert: value } })\n }, [value])\n\n return { ref: host, view }\n}\n","import * as React from \"react\"\nimport { EditorView, lineNumbers } from \"@codemirror/view\"\nimport { EditorState } from \"@codemirror/state\"\nimport {\n StreamLanguage,\n syntaxHighlighting,\n defaultHighlightStyle,\n} from \"@codemirror/language\"\nimport { python } from \"@codemirror/legacy-modes/mode/python\"\nimport { shell } from \"@codemirror/legacy-modes/mode/shell\"\nimport { javascript, json } from \"@codemirror/legacy-modes/mode/javascript\"\nimport { cypher } from \"@codemirror/legacy-modes/mode/cypher\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport type CodeLanguage =\n | \"python\"\n | \"shell\"\n | \"javascript\"\n | \"json\"\n | \"cypher\"\n | \"plain\"\n\nexport interface CodeBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n value: string\n language?: CodeLanguage\n /** Line numbers are off by default — a five-line snippet does not need a gutter. */\n showLineNumbers?: boolean\n /**\n * Cap the block's height in px and let it scroll inside that, for a document\n * whose length is not the point — a run's `result.json`, an exported model.\n *\n * Unset, the block is as tall as its content, which is right for a snippet\n * and wrong for a record that grows as a run proceeds.\n */\n maxHeight?: number\n}\n\nconst MODES = {\n python: () => StreamLanguage.define(python),\n shell: () => StreamLanguage.define(shell),\n javascript: () => StreamLanguage.define(javascript),\n json: () => StreamLanguage.define(json),\n cypher: () => StreamLanguage.define(cypher),\n plain: () => null,\n}\n\n/**\n * Code, shown as it is — read-only.\n *\n * The DAG in a hand-off, a query in a diagnosis, an exported model. It is not a\n * disabled editor: `EditorState.readOnly` plus a non-editable view means there\n * is no cursor to place and no illusion that typing would do something.\n */\nexport function CodeBlock({\n value,\n language = \"plain\",\n showLineNumbers,\n maxHeight,\n className,\n style,\n ...props\n}: CodeBlockProps) {\n const extensions = React.useMemo(() => {\n const mode = MODES[language]()\n return [\n // StreamLanguage only produces tokens; without a highlight style nothing\n // paints them and the block renders as flat text.\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n EditorView.editable.of(false),\n EditorState.readOnly.of(true),\n EditorView.lineWrapping,\n ...(showLineNumbers ? [lineNumbers()] : []),\n ...(mode ? [mode] : []),\n // The scroller lives inside CodeMirror rather than on the wrapper, so the\n // editor knows its own viewport and does not render every line of a long\n // document into a box that then clips them.\n ...(maxHeight != null\n ? [EditorView.theme({ \"&\": { maxHeight: `${maxHeight}px` } })]\n : []),\n ]\n }, [language, showLineNumbers, maxHeight])\n\n const { ref } = useCodeMirror({ value, extensions })\n\n return (\n <div\n ref={ref}\n className={cn(\n \"overflow-hidden border border-border bg-muted/40 [&_.cm-editor]:bg-transparent\",\n \"[&_.cm-content]:font-mono [&_.cm-content]:text-sm [&_.cm-focused]:outline-none\",\n \"[&_.cm-gutters]:border-none [&_.cm-gutters]:bg-transparent [&_.cm-gutters]:text-muted-foreground\",\n className,\n )}\n style={style}\n {...props}\n />\n )\n}\n","import * as React from \"react\"\nimport { EditorView } from \"@codemirror/view\"\nimport { history, defaultKeymap, historyKeymap } from \"@codemirror/commands\"\nimport { keymap } from \"@codemirror/view\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport interface MarkdownEditorBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n value: string\n onChange?: (value: string) => void\n readOnly?: boolean\n /** A version marker shown in the corner — `v5`, `v7 · editing`. */\n version?: React.ReactNode\n placeholder?: string\n}\n\n/**\n * The prose a person writes for an agent to read — graph rules, a skill's\n * content, an acceptance note.\n *\n * Plain markdown in a monospace field, not a rich-text editor. What is typed\n * here is offered verbatim in a model's prompt, so what you see has to be\n * exactly what the agent gets; a WYSIWYG layer would put a translation step\n * between the author and the thing that runs.\n *\n * `version` sits in the corner because these documents are versioned and a\n * running thinking finishes on the version it started with — editing without\n * seeing which version you are on is how two people overwrite each other.\n */\nexport function MarkdownEditorBlock({\n value,\n onChange,\n readOnly,\n version,\n className,\n ...props\n}: MarkdownEditorBlockProps) {\n const extensions = React.useMemo(\n () => [\n // No markdown syntax mode, deliberately. What is typed here is offered\n // verbatim in a model's prompt, and highlighting it would be decoration\n // on text whose whole contract is that it is plain. It also keeps this\n // package's dependencies to the CodeMirror set the product already ships.\n EditorView.lineWrapping,\n history(),\n keymap.of([...defaultKeymap, ...historyKeymap]),\n EditorView.editable.of(!readOnly),\n ],\n [readOnly],\n )\n\n const { ref } = useCodeMirror({ value, extensions, onChange })\n\n return (\n <div className={cn(\"relative border border-border bg-muted/40\", className)} {...props}>\n {version != null ? (\n <span className=\"absolute right-1 top-1 z-10 border border-border bg-card px-1 text-sm text-muted-foreground\">\n {version}\n </span>\n ) : null}\n <div\n ref={ref}\n className={cn(\n \"[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-sm\",\n \"[&_.cm-focused]:outline-none [&_.cm-cursor]:border-foreground\",\n )}\n />\n </div>\n )\n}\n"]}
package/dist/index.js CHANGED
@@ -100,7 +100,7 @@ function CodeBlock({
100
100
  ref,
101
101
  className: cn(
102
102
  "overflow-hidden border border-border bg-muted/40 [&_.cm-editor]:bg-transparent",
103
- "[&_.cm-content]:font-mono [&_.cm-content]:text-meta [&_.cm-focused]:outline-none",
103
+ "[&_.cm-content]:font-mono [&_.cm-content]:text-sm [&_.cm-focused]:outline-none",
104
104
  "[&_.cm-gutters]:border-none [&_.cm-gutters]:bg-transparent [&_.cm-gutters]:text-muted-foreground",
105
105
  className
106
106
  ),
@@ -132,13 +132,13 @@ function MarkdownEditorBlock({
132
132
  );
133
133
  const { ref } = useCodeMirror({ value, extensions, onChange });
134
134
  return /* @__PURE__ */ jsxs("div", { className: cn("relative border border-border bg-muted/40", className), ...props, children: [
135
- version != null ? /* @__PURE__ */ jsx("span", { className: "absolute right-1 top-1 z-10 border border-border bg-card px-1 text-meta text-muted-foreground", children: version }) : null,
135
+ version != null ? /* @__PURE__ */ jsx("span", { className: "absolute right-1 top-1 z-10 border border-border bg-card px-1 text-sm text-muted-foreground", children: version }) : null,
136
136
  /* @__PURE__ */ jsx(
137
137
  "div",
138
138
  {
139
139
  ref,
140
140
  className: cn(
141
- "[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-meta",
141
+ "[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-sm",
142
142
  "[&_.cm-focused]:outline-none [&_.cm-cursor]:border-foreground"
143
143
  )
144
144
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/use-code-mirror.ts","../src/code-block.tsx","../src/markdown-editor-block.tsx"],"names":["React2","EditorView","EditorState","React3","cn","jsx"],"mappings":";;;;;;;;;;;;;AAkBO,SAAS,aAAA,CAAc;AAAA,EAC5B,KAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA,EAAyB;AACvB,EAAA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UAAA,GAAmBE,KAAA,CAAA,OAAA;AAAA,IACvB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,MAKJF,UAAAA,CAAW,YAAA;AAAA,MACX,OAAA,EAAQ;AAAA,MACR,OAAO,EAAA,CAAG,CAAC,GAAG,aAAA,EAAe,GAAG,aAAa,CAAC,CAAA;AAAA,MAC9CA,UAAAA,CAAW,QAAA,CAAS,EAAA,CAAG,CAAC,QAAQ;AAAA,KAClC;AAAA,IACA,CAAC,QAAQ;AAAA,GACX;AAEA,EAAA,MAAM,EAAE,KAAI,GAAI,aAAA,CAAc,EAAE,KAAA,EAAO,UAAA,EAAY,UAAU,CAAA;AAE7D,EAAA,uBACE,IAAA,CAAC,SAAI,SAAA,EAAWG,EAAAA,CAAG,6CAA6C,SAAS,CAAA,EAAI,GAAG,KAAA,EAC7E,QAAA,EAAA;AAAA,IAAA,OAAA,IAAW,uBACVC,GAAAA,CAAC,UAAK,SAAA,EAAU,+FAAA,EACb,mBACH,CAAA,GACE,IAAA;AAAA,oBACJA,GAAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,SAAA,EAAWD,EAAAA;AAAA,UACT,mFAAA;AAAA,UACA;AAAA;AACF;AAAA;AACF,GAAA,EACF,CAAA;AAEJ","file":"index.js","sourcesContent":["import * as React from \"react\"\nimport { Compartment, EditorState, type Extension } from \"@codemirror/state\"\nimport { EditorView } from \"@codemirror/view\"\n\nexport interface UseCodeMirrorOptions {\n value: string\n extensions: Extension[]\n onChange?: (value: string) => void\n}\n\n/**\n * Mounts a CodeMirror view into a ref'd element and keeps it in sync.\n *\n * The whole reason this is a hook rather than a component: CodeMirror owns its\n * own DOM, so React must not re-render into it. Value changes are pushed as\n * transactions, and only when they actually differ — writing the view's own\n * output back into it would move the cursor to the end on every keystroke.\n */\nexport function useCodeMirror({\n value,\n extensions,\n onChange,\n}: UseCodeMirrorOptions) {\n const host = React.useRef<HTMLDivElement | null>(null)\n const view = React.useRef<EditorView | null>(null)\n\n // Keep the latest onChange without tearing down the view when it changes\n // identity — a caller passing an inline arrow would otherwise remount the\n // editor on every render.\n const onChangeRef = React.useRef(onChange)\n React.useEffect(() => {\n onChangeRef.current = onChange\n }, [onChange])\n\n // The view is created once and reconfigured in place. Keying the effect on\n // `extensions` identity looked simpler, but a caller passing an inline array\n // would then rebuild the editor on every render — losing the cursor, the\n // selection and focus mid-keystroke. \"Callers are expected to memoise\" is a\n // trap, not a contract, so the hook does not depend on it.\n const extensionsRef = React.useRef(extensions)\n extensionsRef.current = extensions\n\n const compartment = React.useRef(new Compartment())\n\n React.useEffect(() => {\n if (!host.current) return\n const v = new EditorView({\n state: EditorState.create({\n doc: value,\n extensions: [\n compartment.current.of(extensionsRef.current),\n EditorView.updateListener.of((u) => {\n if (u.docChanged) onChangeRef.current?.(u.state.doc.toString())\n }),\n ],\n }),\n parent: host.current,\n })\n view.current = v\n return () => {\n v.destroy()\n view.current = null\n }\n // Mount once. Configuration changes go through the compartment below.\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Swap configuration without touching the document — this is what a\n // Compartment is for, and it is why toggling `readOnly` or a language keeps\n // the caret where it was.\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n v.dispatch({ effects: compartment.current.reconfigure(extensions) })\n }, [extensions])\n\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n const current = v.state.doc.toString()\n if (current === value) return\n v.dispatch({ changes: { from: 0, to: current.length, insert: value } })\n }, [value])\n\n return { ref: host, view }\n}\n","import * as React from \"react\"\nimport { EditorView, lineNumbers } from \"@codemirror/view\"\nimport { EditorState } from \"@codemirror/state\"\nimport {\n StreamLanguage,\n syntaxHighlighting,\n defaultHighlightStyle,\n} from \"@codemirror/language\"\nimport { python } from \"@codemirror/legacy-modes/mode/python\"\nimport { shell } from \"@codemirror/legacy-modes/mode/shell\"\nimport { javascript, json } from \"@codemirror/legacy-modes/mode/javascript\"\nimport { cypher } from \"@codemirror/legacy-modes/mode/cypher\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport type CodeLanguage =\n | \"python\"\n | \"shell\"\n | \"javascript\"\n | \"json\"\n | \"cypher\"\n | \"plain\"\n\nexport interface CodeBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n value: string\n language?: CodeLanguage\n /** Line numbers are off by default — a five-line snippet does not need a gutter. */\n showLineNumbers?: boolean\n /**\n * Cap the block's height in px and let it scroll inside that, for a document\n * whose length is not the point — a run's `result.json`, an exported model.\n *\n * Unset, the block is as tall as its content, which is right for a snippet\n * and wrong for a record that grows as a run proceeds.\n */\n maxHeight?: number\n}\n\nconst MODES = {\n python: () => StreamLanguage.define(python),\n shell: () => StreamLanguage.define(shell),\n javascript: () => StreamLanguage.define(javascript),\n json: () => StreamLanguage.define(json),\n cypher: () => StreamLanguage.define(cypher),\n plain: () => null,\n}\n\n/**\n * Code, shown as it is — read-only.\n *\n * The DAG in a hand-off, a query in a diagnosis, an exported model. It is not a\n * disabled editor: `EditorState.readOnly` plus a non-editable view means there\n * is no cursor to place and no illusion that typing would do something.\n */\nexport function CodeBlock({\n value,\n language = \"plain\",\n showLineNumbers,\n maxHeight,\n className,\n style,\n ...props\n}: CodeBlockProps) {\n const extensions = React.useMemo(() => {\n const mode = MODES[language]()\n return [\n // StreamLanguage only produces tokens; without a highlight style nothing\n // paints them and the block renders as flat text.\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n EditorView.editable.of(false),\n EditorState.readOnly.of(true),\n EditorView.lineWrapping,\n ...(showLineNumbers ? [lineNumbers()] : []),\n ...(mode ? [mode] : []),\n // The scroller lives inside CodeMirror rather than on the wrapper, so the\n // editor knows its own viewport and does not render every line of a long\n // document into a box that then clips them.\n ...(maxHeight != null\n ? [EditorView.theme({ \"&\": { maxHeight: `${maxHeight}px` } })]\n : []),\n ]\n }, [language, showLineNumbers, maxHeight])\n\n const { ref } = useCodeMirror({ value, extensions })\n\n return (\n <div\n ref={ref}\n className={cn(\n \"overflow-hidden border border-border bg-muted/40 [&_.cm-editor]:bg-transparent\",\n \"[&_.cm-content]:font-mono [&_.cm-content]:text-meta [&_.cm-focused]:outline-none\",\n \"[&_.cm-gutters]:border-none [&_.cm-gutters]:bg-transparent [&_.cm-gutters]:text-muted-foreground\",\n className,\n )}\n style={style}\n {...props}\n />\n )\n}\n","import * as React from \"react\"\nimport { EditorView } from \"@codemirror/view\"\nimport { history, defaultKeymap, historyKeymap } from \"@codemirror/commands\"\nimport { keymap } from \"@codemirror/view\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport interface MarkdownEditorBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n value: string\n onChange?: (value: string) => void\n readOnly?: boolean\n /** A version marker shown in the corner — `v5`, `v7 · editing`. */\n version?: React.ReactNode\n placeholder?: string\n}\n\n/**\n * The prose a person writes for an agent to read — graph rules, a skill's\n * content, an acceptance note.\n *\n * Plain markdown in a monospace field, not a rich-text editor. What is typed\n * here is offered verbatim in a model's prompt, so what you see has to be\n * exactly what the agent gets; a WYSIWYG layer would put a translation step\n * between the author and the thing that runs.\n *\n * `version` sits in the corner because these documents are versioned and a\n * running thinking finishes on the version it started with — editing without\n * seeing which version you are on is how two people overwrite each other.\n */\nexport function MarkdownEditorBlock({\n value,\n onChange,\n readOnly,\n version,\n className,\n ...props\n}: MarkdownEditorBlockProps) {\n const extensions = React.useMemo(\n () => [\n // No markdown syntax mode, deliberately. What is typed here is offered\n // verbatim in a model's prompt, and highlighting it would be decoration\n // on text whose whole contract is that it is plain. It also keeps this\n // package's dependencies to the CodeMirror set the product already ships.\n EditorView.lineWrapping,\n history(),\n keymap.of([...defaultKeymap, ...historyKeymap]),\n EditorView.editable.of(!readOnly),\n ],\n [readOnly],\n )\n\n const { ref } = useCodeMirror({ value, extensions, onChange })\n\n return (\n <div className={cn(\"relative border border-border bg-muted/40\", className)} {...props}>\n {version != null ? (\n <span className=\"absolute right-1 top-1 z-10 border border-border bg-card px-1 text-meta text-muted-foreground\">\n {version}\n </span>\n ) : null}\n <div\n ref={ref}\n className={cn(\n \"[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-meta\",\n \"[&_.cm-focused]:outline-none [&_.cm-cursor]:border-foreground\",\n )}\n />\n </div>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/use-code-mirror.ts","../src/code-block.tsx","../src/markdown-editor-block.tsx"],"names":["React2","EditorView","EditorState","React3","cn","jsx"],"mappings":";;;;;;;;;;;;;AAkBO,SAAS,aAAA,CAAc;AAAA,EAC5B,KAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA,EAAyB;AACvB,EAAA,MAAM,IAAA,GAAa,aAA8B,IAAI,CAAA;AACrD,EAAA,MAAM,IAAA,GAAa,aAA0B,IAAI,CAAA;AAKjD,EAAA,MAAM,WAAA,GAAoB,aAAO,QAAQ,CAAA;AACzC,EAAM,gBAAU,MAAM;AACpB,IAAA,WAAA,CAAY,OAAA,GAAU,QAAA;AAAA,EACxB,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAOb,EAAA,MAAM,aAAA,GAAsB,aAAO,UAAU,CAAA;AAC7C,EAAA,aAAA,CAAc,OAAA,GAAU,UAAA;AAExB,EAAA,MAAM,WAAA,GAAoB,KAAA,CAAA,MAAA,CAAO,IAAI,WAAA,EAAa,CAAA;AAElD,EAAM,gBAAU,MAAM;AACpB,IAAA,IAAI,CAAC,KAAK,OAAA,EAAS;AACnB,IAAA,MAAM,CAAA,GAAI,IAAI,UAAA,CAAW;AAAA,MACvB,KAAA,EAAO,YAAY,MAAA,CAAO;AAAA,QACxB,GAAA,EAAK,KAAA;AAAA,QACL,UAAA,EAAY;AAAA,UACV,WAAA,CAAY,OAAA,CAAQ,EAAA,CAAG,aAAA,CAAc,OAAO,CAAA;AAAA,UAC5C,UAAA,CAAW,cAAA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AAA;AAAA,UACA;AAAA;AACF;AAAA;AACF,GAAA,EACF,CAAA;AAEJ","file":"index.js","sourcesContent":["import * as React from \"react\"\nimport { Compartment, EditorState, type Extension } from \"@codemirror/state\"\nimport { EditorView } from \"@codemirror/view\"\n\nexport interface UseCodeMirrorOptions {\n value: string\n extensions: Extension[]\n onChange?: (value: string) => void\n}\n\n/**\n * Mounts a CodeMirror view into a ref'd element and keeps it in sync.\n *\n * The whole reason this is a hook rather than a component: CodeMirror owns its\n * own DOM, so React must not re-render into it. Value changes are pushed as\n * transactions, and only when they actually differ — writing the view's own\n * output back into it would move the cursor to the end on every keystroke.\n */\nexport function useCodeMirror({\n value,\n extensions,\n onChange,\n}: UseCodeMirrorOptions) {\n const host = React.useRef<HTMLDivElement | null>(null)\n const view = React.useRef<EditorView | null>(null)\n\n // Keep the latest onChange without tearing down the view when it changes\n // identity — a caller passing an inline arrow would otherwise remount the\n // editor on every render.\n const onChangeRef = React.useRef(onChange)\n React.useEffect(() => {\n onChangeRef.current = onChange\n }, [onChange])\n\n // The view is created once and reconfigured in place. Keying the effect on\n // `extensions` identity looked simpler, but a caller passing an inline array\n // would then rebuild the editor on every render — losing the cursor, the\n // selection and focus mid-keystroke. \"Callers are expected to memoise\" is a\n // trap, not a contract, so the hook does not depend on it.\n const extensionsRef = React.useRef(extensions)\n extensionsRef.current = extensions\n\n const compartment = React.useRef(new Compartment())\n\n React.useEffect(() => {\n if (!host.current) return\n const v = new EditorView({\n state: EditorState.create({\n doc: value,\n extensions: [\n compartment.current.of(extensionsRef.current),\n EditorView.updateListener.of((u) => {\n if (u.docChanged) onChangeRef.current?.(u.state.doc.toString())\n }),\n ],\n }),\n parent: host.current,\n })\n view.current = v\n return () => {\n v.destroy()\n view.current = null\n }\n // Mount once. Configuration changes go through the compartment below.\n }, []) // eslint-disable-line react-hooks/exhaustive-deps\n\n // Swap configuration without touching the document — this is what a\n // Compartment is for, and it is why toggling `readOnly` or a language keeps\n // the caret where it was.\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n v.dispatch({ effects: compartment.current.reconfigure(extensions) })\n }, [extensions])\n\n React.useEffect(() => {\n const v = view.current\n if (!v) return\n const current = v.state.doc.toString()\n if (current === value) return\n v.dispatch({ changes: { from: 0, to: current.length, insert: value } })\n }, [value])\n\n return { ref: host, view }\n}\n","import * as React from \"react\"\nimport { EditorView, lineNumbers } from \"@codemirror/view\"\nimport { EditorState } from \"@codemirror/state\"\nimport {\n StreamLanguage,\n syntaxHighlighting,\n defaultHighlightStyle,\n} from \"@codemirror/language\"\nimport { python } from \"@codemirror/legacy-modes/mode/python\"\nimport { shell } from \"@codemirror/legacy-modes/mode/shell\"\nimport { javascript, json } from \"@codemirror/legacy-modes/mode/javascript\"\nimport { cypher } from \"@codemirror/legacy-modes/mode/cypher\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport type CodeLanguage =\n | \"python\"\n | \"shell\"\n | \"javascript\"\n | \"json\"\n | \"cypher\"\n | \"plain\"\n\nexport interface CodeBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n value: string\n language?: CodeLanguage\n /** Line numbers are off by default — a five-line snippet does not need a gutter. */\n showLineNumbers?: boolean\n /**\n * Cap the block's height in px and let it scroll inside that, for a document\n * whose length is not the point — a run's `result.json`, an exported model.\n *\n * Unset, the block is as tall as its content, which is right for a snippet\n * and wrong for a record that grows as a run proceeds.\n */\n maxHeight?: number\n}\n\nconst MODES = {\n python: () => StreamLanguage.define(python),\n shell: () => StreamLanguage.define(shell),\n javascript: () => StreamLanguage.define(javascript),\n json: () => StreamLanguage.define(json),\n cypher: () => StreamLanguage.define(cypher),\n plain: () => null,\n}\n\n/**\n * Code, shown as it is — read-only.\n *\n * The DAG in a hand-off, a query in a diagnosis, an exported model. It is not a\n * disabled editor: `EditorState.readOnly` plus a non-editable view means there\n * is no cursor to place and no illusion that typing would do something.\n */\nexport function CodeBlock({\n value,\n language = \"plain\",\n showLineNumbers,\n maxHeight,\n className,\n style,\n ...props\n}: CodeBlockProps) {\n const extensions = React.useMemo(() => {\n const mode = MODES[language]()\n return [\n // StreamLanguage only produces tokens; without a highlight style nothing\n // paints them and the block renders as flat text.\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n EditorView.editable.of(false),\n EditorState.readOnly.of(true),\n EditorView.lineWrapping,\n ...(showLineNumbers ? [lineNumbers()] : []),\n ...(mode ? [mode] : []),\n // The scroller lives inside CodeMirror rather than on the wrapper, so the\n // editor knows its own viewport and does not render every line of a long\n // document into a box that then clips them.\n ...(maxHeight != null\n ? [EditorView.theme({ \"&\": { maxHeight: `${maxHeight}px` } })]\n : []),\n ]\n }, [language, showLineNumbers, maxHeight])\n\n const { ref } = useCodeMirror({ value, extensions })\n\n return (\n <div\n ref={ref}\n className={cn(\n \"overflow-hidden border border-border bg-muted/40 [&_.cm-editor]:bg-transparent\",\n \"[&_.cm-content]:font-mono [&_.cm-content]:text-sm [&_.cm-focused]:outline-none\",\n \"[&_.cm-gutters]:border-none [&_.cm-gutters]:bg-transparent [&_.cm-gutters]:text-muted-foreground\",\n className,\n )}\n style={style}\n {...props}\n />\n )\n}\n","import * as React from \"react\"\nimport { EditorView } from \"@codemirror/view\"\nimport { history, defaultKeymap, historyKeymap } from \"@codemirror/commands\"\nimport { keymap } from \"@codemirror/view\"\nimport { cn } from \"@invana/ui\"\n\nimport { useCodeMirror } from \"./use-code-mirror\"\n\nexport interface MarkdownEditorBlockProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n value: string\n onChange?: (value: string) => void\n readOnly?: boolean\n /** A version marker shown in the corner — `v5`, `v7 · editing`. */\n version?: React.ReactNode\n placeholder?: string\n}\n\n/**\n * The prose a person writes for an agent to read — graph rules, a skill's\n * content, an acceptance note.\n *\n * Plain markdown in a monospace field, not a rich-text editor. What is typed\n * here is offered verbatim in a model's prompt, so what you see has to be\n * exactly what the agent gets; a WYSIWYG layer would put a translation step\n * between the author and the thing that runs.\n *\n * `version` sits in the corner because these documents are versioned and a\n * running thinking finishes on the version it started with — editing without\n * seeing which version you are on is how two people overwrite each other.\n */\nexport function MarkdownEditorBlock({\n value,\n onChange,\n readOnly,\n version,\n className,\n ...props\n}: MarkdownEditorBlockProps) {\n const extensions = React.useMemo(\n () => [\n // No markdown syntax mode, deliberately. What is typed here is offered\n // verbatim in a model's prompt, and highlighting it would be decoration\n // on text whose whole contract is that it is plain. It also keeps this\n // package's dependencies to the CodeMirror set the product already ships.\n EditorView.lineWrapping,\n history(),\n keymap.of([...defaultKeymap, ...historyKeymap]),\n EditorView.editable.of(!readOnly),\n ],\n [readOnly],\n )\n\n const { ref } = useCodeMirror({ value, extensions, onChange })\n\n return (\n <div className={cn(\"relative border border-border bg-muted/40\", className)} {...props}>\n {version != null ? (\n <span className=\"absolute right-1 top-1 z-10 border border-border bg-card px-1 text-sm text-muted-foreground\">\n {version}\n </span>\n ) : null}\n <div\n ref={ref}\n className={cn(\n \"[&_.cm-editor]:bg-transparent [&_.cm-content]:font-mono [&_.cm-content]:text-sm\",\n \"[&_.cm-focused]:outline-none [&_.cm-cursor]:border-foreground\",\n )}\n />\n </div>\n )\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@invana/editor",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "Invana Design System - Code and markdown editing surfaces (CodeMirror 6)",
5
5
  "homepage": "https://github.com/invana/design-kit#readme",
6
6
  "type": "module",
@@ -40,8 +40,8 @@
40
40
  "peerDependencies": {
41
41
  "react": "^18 || ^19",
42
42
  "react-dom": "^18 || ^19",
43
- "@invana/styling": "0.0.28",
44
- "@invana/ui": "0.0.28"
43
+ "@invana/styling": "0.0.30",
44
+ "@invana/ui": "0.0.30"
45
45
  },
46
46
  "dependencies": {
47
47
  "@codemirror/commands": "^6.10.3",
@@ -57,8 +57,8 @@
57
57
  "react-dom": "^19.2.7",
58
58
  "tsup": "^8.5.1",
59
59
  "typescript": "~5.9.3",
60
- "@invana/ui": "0.0.28",
61
- "@invana/styling": "0.0.28"
60
+ "@invana/ui": "0.0.30",
61
+ "@invana/styling": "0.0.30"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "tsup",