@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/README.md CHANGED
@@ -40,7 +40,7 @@ function Example() {
40
40
  **32 core components** across seven groups — actions (Button, IconButton,
41
41
  SegmentedControl, Popover, Menu, MenuButton), forms (Input, NumberInput,
42
42
  Textarea, Select, DatePicker, TimePicker, Checkbox, Radio, Switch, Slider,
43
- RangeSlider, FileGrid, Dropzone, MarkdownEditor), surfaces (Card, CardRow,
43
+ RangeSlider, FileGrid, Dropzone, MarkdownEditor, CodeEditor), surfaces (Card, CardRow,
44
44
  Collapsible, Modal, Drawer), data (DataTable, FactList, Pagination, SortMenu, StatTile,
45
45
  Meter, CsiBadge, CsiMeter, CsiHero, Markdown, CodeBlock, DiffBlock, StepList,
46
46
  SegmentedMeter, QuotaRow, Clamp, RelativeTime), feedback (Badge, Tag, Avatar,
@@ -75,6 +75,11 @@ pnpm install
75
75
  pnpm run docs
76
76
  ```
77
77
 
78
+ CodeEditor edits SQL by default; `language="json"` adds JSON highlighting, bracket
79
+ matching and indentation on Enter, shows the parser's syntax error at its line and
80
+ column, and takes `validate={(text) => diagnostics}` for the caller's own checks
81
+ (for example a schema path such as `spec.model`).
82
+
78
83
  ## Development
79
84
 
80
85
  ```bash
package/dist/index.cjs CHANGED
@@ -9968,11 +9968,59 @@ var MarkdownEditor = React60.forwardRef(function MarkdownEditor2({
9968
9968
  // src/components/forms/CodeEditor.tsx
9969
9969
  var React61 = __toESM(require("react"), 1);
9970
9970
  var import_view = require("@codemirror/view");
9971
- var import_state = require("@codemirror/state");
9971
+ var import_state2 = require("@codemirror/state");
9972
9972
  var import_commands = require("@codemirror/commands");
9973
9973
  var import_lang_sql = require("@codemirror/lang-sql");
9974
- var import_language = require("@codemirror/language");
9974
+ var import_lang_json2 = require("@codemirror/lang-json");
9975
+ var import_language2 = require("@codemirror/language");
9975
9976
  var import_highlight = require("@lezer/highlight");
9977
+
9978
+ // src/components/forms/jsonDiagnostics.ts
9979
+ var import_state = require("@codemirror/state");
9980
+ var import_lang_json = require("@codemirror/lang-json");
9981
+ var import_language = require("@codemirror/language");
9982
+ var PARSE_BUDGET_MS = 1e3;
9983
+ function firstErrorOffset(state) {
9984
+ const tree = (0, import_language.ensureSyntaxTree)(state, state.doc.length, PARSE_BUDGET_MS);
9985
+ let at = -1;
9986
+ tree?.iterate({
9987
+ enter(node) {
9988
+ if (at >= 0) return false;
9989
+ if (node.type.isError) {
9990
+ at = node.from;
9991
+ return false;
9992
+ }
9993
+ return void 0;
9994
+ }
9995
+ });
9996
+ return at;
9997
+ }
9998
+ function jsonSyntaxDiagnostics(text) {
9999
+ if (!text.trim()) return [];
10000
+ try {
10001
+ JSON.parse(text);
10002
+ return [];
10003
+ } catch (e) {
10004
+ if (!(e instanceof SyntaxError)) throw e;
10005
+ const state = import_state.EditorState.create({ doc: text, extensions: [(0, import_lang_json.json)()] });
10006
+ const offset = firstErrorOffset(state);
10007
+ const line = state.doc.lineAt(offset < 0 ? state.doc.length : offset);
10008
+ const at = offset < 0 ? state.doc.length : offset;
10009
+ return [{
10010
+ line: line.number,
10011
+ column: at - line.from + 1,
10012
+ message: e.message.replace(/, ".*" is not valid JSON$/s, ""),
10013
+ severity: "error"
10014
+ }];
10015
+ }
10016
+ }
10017
+ function jsonModeDiagnostics(text, validate) {
10018
+ const syntax = jsonSyntaxDiagnostics(text);
10019
+ if (syntax.length || !validate) return syntax;
10020
+ return validate(text);
10021
+ }
10022
+
10023
+ // src/components/forms/CodeEditor.tsx
9976
10024
  var import_jsx_runtime87 = require("react/jsx-runtime");
9977
10025
  function clampOffset(state, line, column) {
9978
10026
  const total = state.doc.lines;
@@ -9990,8 +10038,8 @@ function toCmDiagnostics(state, diags) {
9990
10038
  return { from, to, severity: d.severity || "error", message: d.message, source: void 0 };
9991
10039
  });
9992
10040
  }
9993
- var setDiagnosticsEffect = import_state.StateEffect.define();
9994
- var diagnosticsField = import_state.StateField.define({
10041
+ var setDiagnosticsEffect = import_state2.StateEffect.define();
10042
+ var diagnosticsField = import_state2.StateField.define({
9995
10043
  create: () => [],
9996
10044
  update(value, tr) {
9997
10045
  for (const e of tr.effects) if (e.is(setDiagnosticsEffect)) return e.value;
@@ -9999,7 +10047,7 @@ var diagnosticsField = import_state.StateField.define({
9999
10047
  return value.map((d) => ({ ...d, from: tr.changes.mapPos(d.from), to: tr.changes.mapPos(d.to) }));
10000
10048
  }
10001
10049
  });
10002
- var tokenHighlight = import_language.HighlightStyle.define([
10050
+ var tokenHighlight = import_language2.HighlightStyle.define([
10003
10051
  { tag: import_highlight.tags.keyword, class: "tok-kw" },
10004
10052
  { tag: import_highlight.tags.string, class: "tok-str" },
10005
10053
  { tag: [import_highlight.tags.number, import_highlight.tags.bool], class: "tok-num" },
@@ -10059,7 +10107,9 @@ function CodeEditor({
10059
10107
  disabled = false,
10060
10108
  readOnly = false,
10061
10109
  placeholder: placeholderText = "",
10062
- diagnostics = [],
10110
+ diagnostics: passedDiagnostics,
10111
+ language = "sql",
10112
+ validate,
10063
10113
  showEscapeHint = true,
10064
10114
  minHeight = 160,
10065
10115
  id,
@@ -10068,6 +10118,13 @@ function CodeEditor({
10068
10118
  autoFocus = false
10069
10119
  }) {
10070
10120
  const fieldId = useFieldId(id);
10121
+ const diagnostics = React61.useMemo(
10122
+ () => [
10123
+ ...passedDiagnostics ?? [],
10124
+ ...language === "json" ? jsonModeDiagnostics(value, validate) : []
10125
+ ],
10126
+ [passedDiagnostics, language, value, validate]
10127
+ );
10071
10128
  const descId = fieldId + "-desc";
10072
10129
  const liveId = fieldId + "-live";
10073
10130
  const hostRef = React61.useRef(null);
@@ -10075,9 +10132,10 @@ function CodeEditor({
10075
10132
  const valueRef = React61.useRef(value);
10076
10133
  const onChangeRef = React61.useRef(onChange);
10077
10134
  onChangeRef.current = onChange;
10078
- const editableCompartment = React61.useRef(new import_state.Compartment()).current;
10079
- const readOnlyCompartment = React61.useRef(new import_state.Compartment()).current;
10080
- const attributesCompartment = React61.useRef(new import_state.Compartment()).current;
10135
+ const editableCompartment = React61.useRef(new import_state2.Compartment()).current;
10136
+ const languageCompartment = React61.useRef(new import_state2.Compartment()).current;
10137
+ const readOnlyCompartment = React61.useRef(new import_state2.Compartment()).current;
10138
+ const attributesCompartment = React61.useRef(new import_state2.Compartment()).current;
10081
10139
  const errorRef = React61.useRef(error);
10082
10140
  errorRef.current = error;
10083
10141
  const diagnosticsCountRef = React61.useRef(diagnostics.length);
@@ -10099,16 +10157,16 @@ function CodeEditor({
10099
10157
  valueRef.current = next;
10100
10158
  onChangeRef.current && onChangeRef.current(next);
10101
10159
  });
10102
- const state = import_state.EditorState.create({
10160
+ const state = import_state2.EditorState.create({
10103
10161
  doc: value,
10104
10162
  extensions: [
10105
10163
  (0, import_view.lineNumbers)(),
10106
10164
  (0, import_commands.history)(),
10107
10165
  (0, import_view.drawSelection)(),
10108
- (0, import_language.indentOnInput)(),
10109
- (0, import_language.bracketMatching)(),
10110
- (0, import_lang_sql.sql)(),
10111
- (0, import_language.syntaxHighlighting)(tokenHighlight),
10166
+ (0, import_language2.indentOnInput)(),
10167
+ (0, import_language2.bracketMatching)(),
10168
+ languageCompartment.of(language === "json" ? (0, import_lang_json2.json)() : (0, import_lang_sql.sql)()),
10169
+ (0, import_language2.syntaxHighlighting)(tokenHighlight),
10112
10170
  diagnosticsField,
10113
10171
  decorationsFromDiagnostics(),
10114
10172
  editorTheme,
@@ -10119,7 +10177,7 @@ function CodeEditor({
10119
10177
  ...import_commands.historyKeymap
10120
10178
  ]),
10121
10179
  editableCompartment.of(import_view.EditorView.editable.of(!disabled)),
10122
- readOnlyCompartment.of(import_state.EditorState.readOnly.of(readOnly)),
10180
+ readOnlyCompartment.of(import_state2.EditorState.readOnly.of(readOnly)),
10123
10181
  updateListener,
10124
10182
  attributesCompartment.of(import_view.EditorView.contentAttributes.of(contentAttributes()))
10125
10183
  ]
@@ -10149,7 +10207,12 @@ function CodeEditor({
10149
10207
  React61.useEffect(() => {
10150
10208
  const view = viewRef.current;
10151
10209
  if (!view) return;
10152
- view.dispatch({ effects: readOnlyCompartment.reconfigure(import_state.EditorState.readOnly.of(readOnly)) });
10210
+ view.dispatch({ effects: languageCompartment.reconfigure(language === "json" ? (0, import_lang_json2.json)() : (0, import_lang_sql.sql)()) });
10211
+ }, [language, languageCompartment]);
10212
+ React61.useEffect(() => {
10213
+ const view = viewRef.current;
10214
+ if (!view) return;
10215
+ view.dispatch({ effects: readOnlyCompartment.reconfigure(import_state2.EditorState.readOnly.of(readOnly)) });
10153
10216
  }, [readOnly, readOnlyCompartment]);
10154
10217
  React61.useEffect(() => {
10155
10218
  const view = viewRef.current;