@flytedan/flytebot-design-system 0.88.0 → 0.89.0

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.d.cts CHANGED
@@ -3334,6 +3334,14 @@ interface CodeEditorProps {
3334
3334
  * a message list under the editor) and announced to screen readers via an
3335
3335
  * `aria-live` region. */
3336
3336
  diagnostics?: CodeEditorDiagnostic[];
3337
+ /** The source language: highlighting, bracket matching and indentation on
3338
+ * Enter. Default "sql". */
3339
+ language?: "sql" | "json";
3340
+ /** JSON mode only: text in, diagnostics out (for example a schema path such
3341
+ * as spec.model). Runs on every edit once the text parses; the parser's own
3342
+ * syntax error replaces it while the text does not. Shown beside any
3343
+ * `diagnostics` the caller passes. */
3344
+ validate?: (text: string) => CodeEditorDiagnostic[];
3337
3345
  /** The documented key that moves focus out of the editor after Tab has
3338
3346
  * started indenting. Shown as help text under the editor. Default true. */
3339
3347
  showEscapeHint?: boolean;
@@ -3344,14 +3352,14 @@ interface CodeEditorProps {
3344
3352
  autoFocus?: boolean;
3345
3353
  }
3346
3354
  /**
3347
- * An editable, monospace SQL code editor: line numbers, syntax highlighting,
3355
+ * An editable, monospace code editor (SQL, or JSON with `language="json"`): line numbers, syntax highlighting,
3348
3356
  * a controlled value/onChange, disabled/read-only states, and diagnostics
3349
3357
  * anchored to a line/column range — shown inline as an underline plus a
3350
3358
  * message list, and announced to screen readers through an `aria-live`
3351
3359
  * region. See the file header above for the engine choice and the
3352
3360
  * keyboard-trap contract (Tab indents; Escape then Tab moves focus out).
3353
3361
  */
3354
- declare function CodeEditor({ value, onChange, label, help, error, required, disabled, readOnly, placeholder: placeholderText, diagnostics, showEscapeHint, minHeight, id, className, style, autoFocus, }: CodeEditorProps): React.JSX.Element;
3362
+ declare function CodeEditor({ value, onChange, label, help, error, required, disabled, readOnly, placeholder: placeholderText, diagnostics: passedDiagnostics, language, validate, showEscapeHint, minHeight, id, className, style, autoFocus, }: CodeEditorProps): React.JSX.Element;
3355
3363
 
3356
3364
  interface RadioGroupOption {
3357
3365
  value: string;
package/dist/index.d.ts CHANGED
@@ -3334,6 +3334,14 @@ interface CodeEditorProps {
3334
3334
  * a message list under the editor) and announced to screen readers via an
3335
3335
  * `aria-live` region. */
3336
3336
  diagnostics?: CodeEditorDiagnostic[];
3337
+ /** The source language: highlighting, bracket matching and indentation on
3338
+ * Enter. Default "sql". */
3339
+ language?: "sql" | "json";
3340
+ /** JSON mode only: text in, diagnostics out (for example a schema path such
3341
+ * as spec.model). Runs on every edit once the text parses; the parser's own
3342
+ * syntax error replaces it while the text does not. Shown beside any
3343
+ * `diagnostics` the caller passes. */
3344
+ validate?: (text: string) => CodeEditorDiagnostic[];
3337
3345
  /** The documented key that moves focus out of the editor after Tab has
3338
3346
  * started indenting. Shown as help text under the editor. Default true. */
3339
3347
  showEscapeHint?: boolean;
@@ -3344,14 +3352,14 @@ interface CodeEditorProps {
3344
3352
  autoFocus?: boolean;
3345
3353
  }
3346
3354
  /**
3347
- * An editable, monospace SQL code editor: line numbers, syntax highlighting,
3355
+ * An editable, monospace code editor (SQL, or JSON with `language="json"`): line numbers, syntax highlighting,
3348
3356
  * a controlled value/onChange, disabled/read-only states, and diagnostics
3349
3357
  * anchored to a line/column range — shown inline as an underline plus a
3350
3358
  * message list, and announced to screen readers through an `aria-live`
3351
3359
  * region. See the file header above for the engine choice and the
3352
3360
  * keyboard-trap contract (Tab indents; Escape then Tab moves focus out).
3353
3361
  */
3354
- declare function CodeEditor({ value, onChange, label, help, error, required, disabled, readOnly, placeholder: placeholderText, diagnostics, showEscapeHint, minHeight, id, className, style, autoFocus, }: CodeEditorProps): React.JSX.Element;
3362
+ declare function CodeEditor({ value, onChange, label, help, error, required, disabled, readOnly, placeholder: placeholderText, diagnostics: passedDiagnostics, language, validate, showEscapeHint, minHeight, id, className, style, autoFocus, }: CodeEditorProps): React.JSX.Element;
3355
3363
 
3356
3364
  interface RadioGroupOption {
3357
3365
  value: string;
package/dist/index.js CHANGED
@@ -8749,11 +8749,59 @@ var MarkdownEditor = React60.forwardRef(function MarkdownEditor2({
8749
8749
  // src/components/forms/CodeEditor.tsx
8750
8750
  import * as React61 from "react";
8751
8751
  import { EditorView, keymap, lineNumbers, placeholder as cmPlaceholder, drawSelection, Decoration } from "@codemirror/view";
8752
- import { EditorState, StateEffect, StateField, Compartment } from "@codemirror/state";
8752
+ import { EditorState as EditorState2, StateEffect, StateField, Compartment } from "@codemirror/state";
8753
8753
  import { defaultKeymap, history, historyKeymap, indentMore, indentLess } from "@codemirror/commands";
8754
8754
  import { sql as sqlLang } from "@codemirror/lang-sql";
8755
+ import { json as jsonLang } from "@codemirror/lang-json";
8755
8756
  import { syntaxHighlighting, HighlightStyle, indentOnInput, bracketMatching } from "@codemirror/language";
8756
8757
  import { tags } from "@lezer/highlight";
8758
+
8759
+ // src/components/forms/jsonDiagnostics.ts
8760
+ import { EditorState } from "@codemirror/state";
8761
+ import { json } from "@codemirror/lang-json";
8762
+ import { ensureSyntaxTree } from "@codemirror/language";
8763
+ var PARSE_BUDGET_MS = 1e3;
8764
+ function firstErrorOffset(state) {
8765
+ const tree = ensureSyntaxTree(state, state.doc.length, PARSE_BUDGET_MS);
8766
+ let at = -1;
8767
+ tree?.iterate({
8768
+ enter(node) {
8769
+ if (at >= 0) return false;
8770
+ if (node.type.isError) {
8771
+ at = node.from;
8772
+ return false;
8773
+ }
8774
+ return void 0;
8775
+ }
8776
+ });
8777
+ return at;
8778
+ }
8779
+ function jsonSyntaxDiagnostics(text) {
8780
+ if (!text.trim()) return [];
8781
+ try {
8782
+ JSON.parse(text);
8783
+ return [];
8784
+ } catch (e) {
8785
+ if (!(e instanceof SyntaxError)) throw e;
8786
+ const state = EditorState.create({ doc: text, extensions: [json()] });
8787
+ const offset = firstErrorOffset(state);
8788
+ const line = state.doc.lineAt(offset < 0 ? state.doc.length : offset);
8789
+ const at = offset < 0 ? state.doc.length : offset;
8790
+ return [{
8791
+ line: line.number,
8792
+ column: at - line.from + 1,
8793
+ message: e.message.replace(/, ".*" is not valid JSON$/s, ""),
8794
+ severity: "error"
8795
+ }];
8796
+ }
8797
+ }
8798
+ function jsonModeDiagnostics(text, validate) {
8799
+ const syntax = jsonSyntaxDiagnostics(text);
8800
+ if (syntax.length || !validate) return syntax;
8801
+ return validate(text);
8802
+ }
8803
+
8804
+ // src/components/forms/CodeEditor.tsx
8757
8805
  import { jsx as jsx86, jsxs as jsxs73 } from "react/jsx-runtime";
8758
8806
  function clampOffset(state, line, column) {
8759
8807
  const total = state.doc.lines;
@@ -8840,7 +8888,9 @@ function CodeEditor({
8840
8888
  disabled = false,
8841
8889
  readOnly = false,
8842
8890
  placeholder: placeholderText = "",
8843
- diagnostics = [],
8891
+ diagnostics: passedDiagnostics,
8892
+ language = "sql",
8893
+ validate,
8844
8894
  showEscapeHint = true,
8845
8895
  minHeight = 160,
8846
8896
  id,
@@ -8849,6 +8899,13 @@ function CodeEditor({
8849
8899
  autoFocus = false
8850
8900
  }) {
8851
8901
  const fieldId = useFieldId(id);
8902
+ const diagnostics = React61.useMemo(
8903
+ () => [
8904
+ ...passedDiagnostics ?? [],
8905
+ ...language === "json" ? jsonModeDiagnostics(value, validate) : []
8906
+ ],
8907
+ [passedDiagnostics, language, value, validate]
8908
+ );
8852
8909
  const descId = fieldId + "-desc";
8853
8910
  const liveId = fieldId + "-live";
8854
8911
  const hostRef = React61.useRef(null);
@@ -8857,6 +8914,7 @@ function CodeEditor({
8857
8914
  const onChangeRef = React61.useRef(onChange);
8858
8915
  onChangeRef.current = onChange;
8859
8916
  const editableCompartment = React61.useRef(new Compartment()).current;
8917
+ const languageCompartment = React61.useRef(new Compartment()).current;
8860
8918
  const readOnlyCompartment = React61.useRef(new Compartment()).current;
8861
8919
  const attributesCompartment = React61.useRef(new Compartment()).current;
8862
8920
  const errorRef = React61.useRef(error);
@@ -8880,7 +8938,7 @@ function CodeEditor({
8880
8938
  valueRef.current = next;
8881
8939
  onChangeRef.current && onChangeRef.current(next);
8882
8940
  });
8883
- const state = EditorState.create({
8941
+ const state = EditorState2.create({
8884
8942
  doc: value,
8885
8943
  extensions: [
8886
8944
  lineNumbers(),
@@ -8888,7 +8946,7 @@ function CodeEditor({
8888
8946
  drawSelection(),
8889
8947
  indentOnInput(),
8890
8948
  bracketMatching(),
8891
- sqlLang(),
8949
+ languageCompartment.of(language === "json" ? jsonLang() : sqlLang()),
8892
8950
  syntaxHighlighting(tokenHighlight),
8893
8951
  diagnosticsField,
8894
8952
  decorationsFromDiagnostics(),
@@ -8900,7 +8958,7 @@ function CodeEditor({
8900
8958
  ...historyKeymap
8901
8959
  ]),
8902
8960
  editableCompartment.of(EditorView.editable.of(!disabled)),
8903
- readOnlyCompartment.of(EditorState.readOnly.of(readOnly)),
8961
+ readOnlyCompartment.of(EditorState2.readOnly.of(readOnly)),
8904
8962
  updateListener,
8905
8963
  attributesCompartment.of(EditorView.contentAttributes.of(contentAttributes()))
8906
8964
  ]
@@ -8930,7 +8988,12 @@ function CodeEditor({
8930
8988
  React61.useEffect(() => {
8931
8989
  const view = viewRef.current;
8932
8990
  if (!view) return;
8933
- view.dispatch({ effects: readOnlyCompartment.reconfigure(EditorState.readOnly.of(readOnly)) });
8991
+ view.dispatch({ effects: languageCompartment.reconfigure(language === "json" ? jsonLang() : sqlLang()) });
8992
+ }, [language, languageCompartment]);
8993
+ React61.useEffect(() => {
8994
+ const view = viewRef.current;
8995
+ if (!view) return;
8996
+ view.dispatch({ effects: readOnlyCompartment.reconfigure(EditorState2.readOnly.of(readOnly)) });
8934
8997
  }, [readOnly, readOnlyCompartment]);
8935
8998
  React61.useEffect(() => {
8936
8999
  const view = viewRef.current;