@lostgradient/cinder 0.17.0 → 0.19.1

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/components.json +3 -2
  3. package/dist/cli/index.js +2 -2
  4. package/dist/cli/types.d.ts +1 -0
  5. package/dist/components/approval-card/index.js +105 -37
  6. package/dist/components/code-block/index.js +103 -36
  7. package/dist/components/combobox/combobox.schema.js +14 -1
  8. package/dist/components/combobox/combobox.svelte.d.ts +12 -12
  9. package/dist/components/combobox/combobox.types.d.ts +11 -5
  10. package/dist/components/combobox/index.js +94 -16
  11. package/dist/components/event-stream-viewer/index.js +3 -2
  12. package/dist/components/faceted-filter-bar/faceted-filter-bar.css +1 -1
  13. package/dist/components/invocation-rule-builder/index.js +3602 -380
  14. package/dist/components/invocation-rule-builder/invocation-rule-builder.css +14 -0
  15. package/dist/components/json-editor/index.js +86 -18
  16. package/dist/components/json-editor/json-editor-enhancement.d.ts +7 -0
  17. package/dist/components/json-editor/json-editor-enhancement.js +201 -0
  18. package/dist/components/json-editor/json-editor.css +68 -0
  19. package/dist/components/json-editor/json-editor.schema.js +5 -1
  20. package/dist/components/json-editor/json-editor.types.d.ts +2 -0
  21. package/dist/components/run-step-timeline/index.js +3 -2
  22. package/dist/components/schedule-builder/index.js +11 -5
  23. package/dist/components/schema-form/index.js +11 -5
  24. package/dist/components/select/index.js +11 -5
  25. package/dist/components/select/select.schema.js +5 -1
  26. package/dist/components/select/select.types.d.ts +2 -0
  27. package/dist/components/stat-group/stat-group.css +1 -0
  28. package/dist/components/status-dot/index.js +3 -2
  29. package/dist/highlighters/shiki/default.d.ts +5 -0
  30. package/dist/highlighters/shiki/default.js +278 -0
  31. package/dist/highlighters/shiki/index.d.ts +9 -2
  32. package/dist/highlighters/shiki/index.js +72 -35
  33. package/dist/index.js +618 -360
  34. package/dist/server/components/approval-card/index.js +2 -2
  35. package/dist/server/components/combobox/index.js +5 -3
  36. package/dist/server/components/event-stream-viewer/index.js +2 -2
  37. package/dist/server/components/invocation-rule-builder/index.js +15 -2
  38. package/dist/server/components/json-editor/index.js +1 -1
  39. package/dist/server/components/json-editor/json-editor-enhancement.js +150 -0
  40. package/dist/server/components/run-step-timeline/index.js +2 -2
  41. package/dist/server/components/schedule-builder/index.js +2 -2
  42. package/dist/server/components/schema-form/index.js +2 -2
  43. package/dist/server/components/select/index.js +2 -2
  44. package/dist/server/components/status-dot/index.js +2 -2
  45. package/dist/server/highlighters/shiki/default.js +39 -0
  46. package/dist/server/highlighters/shiki/index.js +7 -131
  47. package/dist/server/index.js +14 -13
  48. package/dist/server/{index.server-npxtkwjp.js → index.server-0gg1njz4.js} +3 -2
  49. package/dist/server/{index.server-j87v28yy.js → index.server-0hjcds3y.js} +35 -18
  50. package/dist/server/{index.server-9vqfmhez.js → index.server-20km2ga0.js} +1 -1
  51. package/dist/server/{index.server-qxneqxf8.js → index.server-62593nnh.js} +1 -1
  52. package/dist/server/{index.server-m8ya4p7w.js → index.server-8grn4zd3.js} +74 -14
  53. package/dist/server/index.server-c9gtmre4.js +178 -0
  54. package/dist/server/{index.server-66nm5gd5.js → index.server-ghvvqkfc.js} +1 -1
  55. package/dist/server/{index.server-tez36va4.js → index.server-kvn6cj65.js} +1 -1
  56. package/dist/server/{index.server-9nac5z11.js → index.server-psqfjzpc.js} +1 -1
  57. package/dist/server/{index.server-93vt8ktj.js → index.server-v73af5rk.js} +18 -2
  58. package/dist/server/{index.server-qke3ekjt.js → index.server-ww54rv4y.js} +1 -1
  59. package/dist/server/index.server-x4a15jpm.js +9 -0
  60. package/dist/server/{index.server-ex3ea9z0.js → index.server-xsdzbgs2.js} +3 -2
  61. package/dist/server/{index.server-8ak2cftv.js → index.server-z754e36a.js} +1 -1
  62. package/dist/utilities/json-highlight.d.ts +2 -0
  63. package/package.json +19 -1
  64. package/src/components/code-block/code-block-default-highlighter.ts +2 -2
  65. package/src/components/combobox/combobox.schema.json +13 -0
  66. package/src/components/combobox/combobox.schema.ts +13 -0
  67. package/src/components/combobox/combobox.svelte +100 -14
  68. package/src/components/combobox/combobox.types.ts +11 -5
  69. package/src/components/faceted-filter-bar/faceted-filter-bar.css +1 -1
  70. package/src/components/invocation-rule-builder/invocation-rule-builder.css +14 -0
  71. package/src/components/invocation-rule-builder/invocation-rule-builder.examples.json +1 -1
  72. package/src/components/invocation-rule-builder/invocation-rule-builder.svelte +30 -16
  73. package/src/components/json-editor/json-editor-enhancement.ts +48 -0
  74. package/src/components/json-editor/json-editor.css +68 -0
  75. package/src/components/json-editor/json-editor.examples.json +2 -2
  76. package/src/components/json-editor/json-editor.schema.json +4 -0
  77. package/src/components/json-editor/json-editor.schema.ts +5 -0
  78. package/src/components/json-editor/json-editor.svelte +80 -20
  79. package/src/components/json-editor/json-editor.types.ts +2 -0
  80. package/src/components/select/select.schema.json +4 -0
  81. package/src/components/select/select.schema.ts +4 -0
  82. package/src/components/select/select.svelte +9 -2
  83. package/src/components/select/select.types.ts +2 -0
  84. package/src/components/stat-group/stat-group.css +1 -0
  85. package/src/components/status-dot/status-dot.svelte +6 -1
  86. package/src/highlighters/shiki/default.ts +46 -0
  87. package/src/highlighters/shiki/index.ts +101 -32
  88. package/src/utilities/json-highlight.ts +5 -0
@@ -20,6 +20,10 @@ const schema = {
20
20
  type: 'string',
21
21
  description: 'Visible label rendered in a `<label>` associated via `for`.',
22
22
  },
23
+ 'aria-label': {
24
+ type: 'string',
25
+ description: 'Accessible name for the input when no visible label is rendered.',
26
+ },
23
27
  placeholder: {
24
28
  type: 'string',
25
29
  description: 'Placeholder when no value is selected.',
@@ -45,6 +49,10 @@ const schema = {
45
49
  type: 'number',
46
50
  description: 'Hard cap on visible filtered options. Default 200.',
47
51
  },
52
+ allowCustomValue: {
53
+ type: 'boolean',
54
+ description: 'Allow committing typed text that is not present in `options`.',
55
+ },
48
56
  'aria-describedby': {
49
57
  type: 'string',
50
58
  description:
@@ -65,6 +73,11 @@ const schema = {
65
73
  description:
66
74
  'Custom synchronous filter. Receives an option and the current input\nvalue; returns true to keep. Defaults to case-insensitive substring\nmatch on label.',
67
75
  },
76
+ {
77
+ name: 'onchange',
78
+ reason: 'function-or-snippet',
79
+ description: 'Called when an option, or an arbitrary value when enabled, is committed.',
80
+ },
68
81
  {
69
82
  name: 'options',
70
83
  reason: 'unknown-shape',
@@ -2,14 +2,14 @@
2
2
  export {};
3
3
  </script>
4
4
 
5
- <script lang="ts" generics="T extends string = string">
5
+ <script lang="ts" generics="T extends string = string, AllowCustom extends boolean = false">
6
6
  import { untrack } from 'svelte';
7
7
  import { resolveFieldControl } from '../../_internal/field-control.ts';
8
8
  import { getFormFieldContext } from '../../_internal/form-field-context.ts';
9
9
  import { pushEscapeHandler } from '../../_internal/overlay.ts';
10
10
  import { classNames } from '../../utilities/class-names.ts';
11
11
  import Popover from '../popover/popover.svelte';
12
- let { id, value = $bindable(''), name, inputValue = $bindable(''), options, label, placeholder, filter, description, error, disabled, required, maxVisibleOptions = 200, class: className, 'aria-describedby': consumerDescribedBy, } = $props();
12
+ let { id, value = $bindable(''), onchange, name, inputValue = $bindable(''), options, label, 'aria-label': ariaLabel, placeholder, filter, description, error, disabled, required, maxVisibleOptions = 200, allowCustomValue = false, class: className, 'aria-describedby': consumerDescribedBy, } = $props();
13
13
  const context = getFormFieldContext();
14
14
  const field = $derived(resolveFieldControl({
15
15
  id,
@@ -55,9 +55,22 @@ let inputElement = $state(null);
55
55
  let hiddenInputElement = $state(null);
56
56
  let listboxElement = $state(null);
57
57
  let committedLabel = $state('');
58
+ let initialCustomValue = $state('');
59
+ let hasUserCommittedValue = $state(false);
60
+ let hasExplicitNavigation = $state(false);
61
+ let hasStoredInitialValue = $state(false);
58
62
  let resetSyncTimeout;
59
- const initialValue = untrack(() => value);
63
+ let initialValue = $state(untrack(() => value));
60
64
  const initialInputValue = untrack(() => inputValue);
65
+ $effect.pre(() => {
66
+ if (!hasUserCommittedValue && !hasStoredInitialValue && value) {
67
+ initialValue = value;
68
+ hasStoredInitialValue = true;
69
+ }
70
+ if (allowCustomValue && !hasUserCommittedValue && value && !initialCustomValue) {
71
+ initialCustomValue = value;
72
+ }
73
+ });
61
74
  // Reset active index whenever the filtered set changes so we don't point
62
75
  // at a stale option.
63
76
  $effect(() => {
@@ -88,6 +101,13 @@ $effect(() => {
88
101
  inputValue = matched.label;
89
102
  }
90
103
  }
104
+ else if (allowCustomValue) {
105
+ if (!initialCustomValue)
106
+ initialCustomValue = value;
107
+ committedLabel = value;
108
+ if (untrack(() => inputValue) !== value)
109
+ inputValue = value;
110
+ }
91
111
  });
92
112
  // Escape ownership.
93
113
  //
@@ -125,14 +145,34 @@ $effect(() => {
125
145
  const releaseEscape = pushEscapeHandler(handleEscape);
126
146
  return releaseEscape;
127
147
  });
128
- const activeOptionId = $derived(activeIndex >= 0 && activeIndex < filteredOptions.length
148
+ const listboxVisible = $derived(open && filteredOptions.length > 0);
149
+ const activeOptionId = $derived(listboxVisible && activeIndex >= 0 && activeIndex < filteredOptions.length
129
150
  ? `${id}-option-${activeIndex}`
130
151
  : undefined);
152
+ function findCommittedOption(rawValue) {
153
+ const query = rawValue.trim();
154
+ if (!query)
155
+ return undefined;
156
+ let labelMatch;
157
+ for (const option of options) {
158
+ if (option.disabled)
159
+ continue;
160
+ if (option.value === query)
161
+ return option;
162
+ // Keep scanning after the first label match so an exact value match later
163
+ // in the list still wins over a human-readable label collision.
164
+ if (labelMatch === undefined && option.label === query) {
165
+ labelMatch = option;
166
+ }
167
+ }
168
+ return labelMatch;
169
+ }
131
170
  function handleInput(event) {
132
171
  const target = event.target;
133
172
  inputValue = target.value;
134
173
  open = true;
135
174
  activeIndex = filteredOptions.length > 0 ? 0 : -1;
175
+ hasExplicitNavigation = false;
136
176
  }
137
177
  function handleFocus() {
138
178
  if (!resolvedDisabled)
@@ -145,6 +185,10 @@ function handleBlur(event) {
145
185
  const next = event.relatedTarget;
146
186
  if (next && listboxElement?.contains(next))
147
187
  return;
188
+ if (allowCustomValue && inputValue.trim() && inputValue !== committedLabel) {
189
+ commitCustomValue();
190
+ return;
191
+ }
148
192
  open = false;
149
193
  // Restore the committed label if the live text drifted from it. Leaving the
150
194
  // field on a stale edit (without selecting an option) would desync the
@@ -158,10 +202,36 @@ function handleBlur(event) {
158
202
  function selectOption(option) {
159
203
  if (option.disabled)
160
204
  return;
205
+ hasUserCommittedValue = true;
161
206
  value = option.value;
162
207
  inputValue = option.label;
163
208
  committedLabel = option.label;
164
209
  open = false;
210
+ onchange?.(option.value);
211
+ }
212
+ function commitCustomValue() {
213
+ const nextValue = inputValue.trim();
214
+ if (!allowCustomValue || !nextValue)
215
+ return;
216
+ if (options.some((option) => option.disabled && (option.value === nextValue || option.label === nextValue))) {
217
+ inputValue = committedLabel;
218
+ if (inputElement)
219
+ inputElement.value = committedLabel;
220
+ open = false;
221
+ return;
222
+ }
223
+ hasUserCommittedValue = true;
224
+ const matched = findCommittedOption(nextValue);
225
+ const committedValue = matched?.value ?? nextValue;
226
+ const committedText = matched?.label ?? nextValue;
227
+ const previousValue = value;
228
+ // This path only runs when arbitrary values are explicitly allowed.
229
+ value = committedValue;
230
+ inputValue = committedText;
231
+ committedLabel = committedText;
232
+ open = false;
233
+ if (committedValue !== previousValue)
234
+ onchange?.(committedValue);
165
235
  }
166
236
  function resetToInitialValue(event) {
167
237
  if (resetSyncTimeout !== undefined)
@@ -170,17 +240,24 @@ function resetToInitialValue(event) {
170
240
  resetSyncTimeout = undefined;
171
241
  if (event.defaultPrevented)
172
242
  return;
173
- value = initialValue;
174
- const matched = options.find((option) => option.value === initialValue);
175
- const nextInputValue = matched?.label ?? initialInputValue;
243
+ // Use captured initialValue directly; don't fall back to defaultValue
244
+ // because Svelte's reactive binding updates the attribute (and thus defaultValue).
245
+ const resetValue = hasStoredInitialValue
246
+ ? initialValue
247
+ : allowCustomValue
248
+ ? initialCustomValue || committedLabel
249
+ : '';
250
+ value = resetValue;
251
+ const matched = options.find((option) => option.value === resetValue);
252
+ const nextInputValue = matched?.label ?? (allowCustomValue ? resetValue : initialInputValue);
176
253
  inputValue = nextInputValue;
177
- committedLabel = matched?.label ?? '';
254
+ committedLabel = matched?.label ?? (allowCustomValue ? resetValue : '');
178
255
  open = false;
179
256
  activeIndex = -1;
180
257
  if (inputElement)
181
258
  inputElement.value = nextInputValue;
182
259
  if (hiddenInputElement)
183
- hiddenInputElement.value = initialValue;
260
+ hiddenInputElement.value = resetValue;
184
261
  }, 0);
185
262
  }
186
263
  $effect(() => {
@@ -198,7 +275,7 @@ $effect(() => {
198
275
  };
199
276
  });
200
277
  $effect(() => {
201
- inputElement?.setCustomValidity((resolvedRequired && !value) || inputValue !== committedLabel
278
+ inputElement?.setCustomValidity((resolvedRequired && !value) || (!allowCustomValue && inputValue !== committedLabel)
202
279
  ? 'Please select an option.'
203
280
  : '');
204
281
  });
@@ -209,6 +286,7 @@ function handleKeydown(event) {
209
286
  if (filteredOptions.length === 0)
210
287
  return;
211
288
  activeIndex = (activeIndex + 1) % filteredOptions.length;
289
+ hasExplicitNavigation = true;
212
290
  }
213
291
  else if (event.key === 'ArrowUp') {
214
292
  event.preventDefault();
@@ -216,22 +294,29 @@ function handleKeydown(event) {
216
294
  if (filteredOptions.length === 0)
217
295
  return;
218
296
  activeIndex = activeIndex <= 0 ? filteredOptions.length - 1 : activeIndex - 1;
297
+ hasExplicitNavigation = true;
219
298
  }
220
299
  else if (event.key === 'Home') {
221
300
  if (!open)
222
301
  return;
223
302
  event.preventDefault();
224
303
  activeIndex = filteredOptions.length > 0 ? 0 : -1;
304
+ hasExplicitNavigation = true;
225
305
  }
226
306
  else if (event.key === 'End') {
227
307
  if (!open)
228
308
  return;
229
309
  event.preventDefault();
230
310
  activeIndex = filteredOptions.length - 1;
311
+ hasExplicitNavigation = true;
231
312
  }
232
313
  else if (event.key === 'Enter' && open) {
233
314
  const option = filteredOptions[activeIndex];
234
- if (option) {
315
+ if (allowCustomValue && !(hasExplicitNavigation && option)) {
316
+ event.preventDefault();
317
+ commitCustomValue();
318
+ }
319
+ else if (option) {
235
320
  event.preventDefault();
236
321
  selectOption(option);
237
322
  }
@@ -275,8 +360,9 @@ function handleKeydown(event) {
275
360
  {placeholder}
276
361
  value={inputValue}
277
362
  aria-autocomplete="list"
278
- aria-expanded={open}
279
- aria-controls={listboxId}
363
+ aria-label={ariaLabel?.trim() || undefined}
364
+ aria-expanded={listboxVisible}
365
+ aria-controls={listboxVisible ? listboxId : undefined}
280
366
  aria-activedescendant={activeOptionId}
281
367
  aria-invalid={field.ariaInvalid}
282
368
  aria-required={resolvedRequired || undefined}
@@ -298,7 +384,7 @@ function handleKeydown(event) {
298
384
  />
299
385
  {/if}
300
386
 
301
- {#if open && filteredOptions.length > 0}
387
+ {#if listboxVisible}
302
388
  <Popover
303
389
  bind:open
304
390
  id={listboxId}
@@ -28,16 +28,18 @@ export type ComboboxOption<T extends string = string> = {
28
28
  * - No async / remote loading; no debounced fetch.
29
29
  * - No virtualization. Visible options are capped at 200; consumers with
30
30
  * larger lists must paginate or pre-filter externally.
31
- * - No multi-select, no token chips, no "create new" / free-text submission.
31
+ * - No multi-select or token chips; custom-value submission is opt-in.
32
32
  *
33
- * Bigger Combobox patterns will live as separate components or as an
34
- * extension once consumer needs justify them.
33
+ * Custom-value submission is opt-in through `allowCustomValue`; the default
34
+ * remains a constrained single-select.
35
35
  */
36
- export type ComboboxProps<T extends string = string> = {
36
+ export type ComboboxProps<T extends string = string, AllowCustom extends boolean = false> = {
37
37
  /** Unique identifier — required for label association and ARIA wiring. */
38
38
  id: string;
39
39
  /** Currently selected value. Bindable. `''` when nothing is selected. */
40
- value?: NoInfer<T> | '';
40
+ value?: AllowCustom extends true ? string : NoInfer<T> | '';
41
+ /** Called when an option, or an arbitrary value when enabled, is committed. */
42
+ onchange?: (value: AllowCustom extends true ? string : T) => void;
41
43
  /** Native form field name. Renders a hidden input carrying the selected value. */
42
44
  name?: string | undefined;
43
45
  /** Free-text input value (the text the user has typed). Bindable. */
@@ -46,6 +48,8 @@ export type ComboboxProps<T extends string = string> = {
46
48
  options: readonly ComboboxOption<T>[];
47
49
  /** Visible label rendered in a `<label>` associated via `for`. */
48
50
  label?: string;
51
+ /** Accessible name for the input when no visible label is rendered. */
52
+ 'aria-label'?: string;
49
53
  /** Placeholder when no value is selected. */
50
54
  placeholder?: string;
51
55
  /**
@@ -68,6 +72,8 @@ export type ComboboxProps<T extends string = string> = {
68
72
  required?: boolean;
69
73
  /** Hard cap on visible filtered options. Default 200. */
70
74
  maxVisibleOptions?: number;
75
+ /** Allow committing typed text that is not present in `options`. */
76
+ allowCustomValue?: AllowCustom;
71
77
  /**
72
78
  * External element id(s) to compose into `aria-describedby`. Composed
73
79
  * after the component-generated description and error ids, matching the
@@ -54,7 +54,7 @@
54
54
  font: inherit;
55
55
  font-size: var(--cinder-text-sm);
56
56
  line-height: var(--cinder-leading-normal);
57
- block-size: var(--cinder-control-height-sm, 2rem);
57
+ min-block-size: var(--cinder-control-height-sm, 2rem);
58
58
  cursor: pointer;
59
59
  transition:
60
60
  border-color var(--cinder-duration-fast) var(--cinder-ease-standard),
@@ -1,4 +1,5 @@
1
1
  @layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
2
+ @import '../combobox/combobox.css';
2
3
 
3
4
  @layer cinder.components {
4
5
  .cinder-invocation-rule-builder {
@@ -133,6 +134,19 @@
133
134
  background-repeat: no-repeat;
134
135
  }
135
136
 
137
+ .cinder-invocation-rule-builder__condition-combobox {
138
+ flex: 1 1 8rem;
139
+ min-inline-size: 6rem;
140
+ }
141
+
142
+ .cinder-invocation-rule-builder__condition-combobox .cinder-combobox__control {
143
+ min-block-size: var(--cinder-control-height-sm, 2rem);
144
+ }
145
+
146
+ .cinder-invocation-rule-builder__condition-combobox .cinder-combobox__input {
147
+ min-block-size: var(--cinder-control-height-sm, 2rem);
148
+ }
149
+
136
150
  .cinder-invocation-rule-builder__condition-select:focus-visible {
137
151
  outline: var(--cinder-ring-width) solid transparent;
138
152
  box-shadow: var(--_cinder-focus-ring-shadow);
@@ -19,7 +19,7 @@
19
19
  "id": "flat-conditions",
20
20
  "title": "Flat AND-only conditions",
21
21
  "description": "Edit one controlled conditions array directly, without rule names, ordering, actions, or a way to add another group.",
22
- "code": "<script lang=\"ts\">\n import {\n InvocationRuleBuilder,\n type InvocationRuleCondition,\n type InvocationRuleConditionChange,\n type InvocationRuleOption,\n } from '@lostgradient/cinder/invocation-rule-builder';\n\n const fieldOptions: InvocationRuleOption[] = [\n {\n value: 'status',\n label: 'Status',\n type: 'enum',\n options: [\n { value: 'running', label: 'Running' },\n { value: 'failed', label: 'Failed' },\n ],\n },\n { value: 'retry-count', label: 'Retry count', type: 'number' },\n ];\n\n let conditions = $state<InvocationRuleCondition[]>([\n { id: 'status', field: 'status', operator: 'eq', value: 'failed' },\n { id: 'retries', field: 'retry-count', operator: 'gte', value: '3' },\n ]);\n\n function handleChange(\n nextConditions: InvocationRuleCondition[],\n _change: InvocationRuleConditionChange,\n ): void {\n conditions = nextConditions;\n }\n</script>\n\n<InvocationRuleBuilder\n mode=\"flat-conditions\"\n {conditions}\n onchange={handleChange}\n {fieldOptions}\n label=\"Workflow filters\"\n/>\n"
22
+ "code": "<script lang=\"ts\">\n import {\n InvocationRuleBuilder,\n type InvocationRuleCondition,\n type InvocationRuleConditionChange,\n type InvocationRuleOption,\n } from '@lostgradient/cinder/invocation-rule-builder';\n\n const fieldOptions: InvocationRuleOption[] = [\n {\n value: 'status',\n label: 'Status',\n type: 'enum',\n options: [\n { value: 'running', label: 'Running' },\n { value: 'failed', label: 'Failed' },\n ],\n },\n { value: 'retry-count', label: 'Retry count', type: 'number' },\n ];\n\n let conditions = $state<InvocationRuleCondition[]>([\n { id: 'status', field: 'status', operator: 'eq', value: 'failed' },\n { id: 'retries', field: 'retry-count', operator: 'gte', value: '3' },\n { id: 'custom', field: 'team.owner', operator: 'eq', value: 'platform' },\n ]);\n\n function handleChange(\n nextConditions: InvocationRuleCondition[],\n _change: InvocationRuleConditionChange,\n ): void {\n conditions = nextConditions;\n }\n</script>\n\n<InvocationRuleBuilder\n mode=\"flat-conditions\"\n {conditions}\n onchange={handleChange}\n {fieldOptions}\n label=\"Workflow filters\"\n/>\n"
23
23
  },
24
24
  {
25
25
  "id": "readonly",
@@ -5,6 +5,7 @@ export {};
5
5
  <script lang="ts">
6
6
  import { tick } from 'svelte';
7
7
  import { classNames } from '../../utilities/class-names.ts';
8
+ import Combobox from '../combobox/combobox.svelte';
8
9
  /**
9
10
  * Fixed operator vocabulary for conditions-only mode (`mode="conditions"`).
10
11
  * Cinder supplies these with default labels; the `operatorOptions` prop is
@@ -490,22 +491,35 @@ function actionSummary(action) {
490
491
  >
491
492
  {#each rule.conditions as condition, conditionIndex (condition.id)}
492
493
  <div class="cinder-invocation-rule-builder__condition" role="listitem">
493
- <select
494
- class="cinder-invocation-rule-builder__condition-select"
495
- aria-label={`Field for condition ${conditionIndex + 1} of ${rule.label}`}
496
- value={condition.field}
497
- onchange={(event) =>
498
- handleUpdateCondition(
499
- rule.id,
500
- condition.id,
501
- 'field',
502
- (event.target as HTMLSelectElement).value,
503
- )}
504
- >
505
- {#each fieldOptions as option (option.value)}
506
- <option value={option.value}>{option.label}</option>
507
- {/each}
508
- </select>
494
+ {#if conditionsOnly}
495
+ <Combobox
496
+ id={`${baseId}-rule-${ruleIndex}-condition-${conditionIndex}-field`}
497
+ value={condition.field}
498
+ options={fieldOptions}
499
+ allowCustomValue
500
+ aria-label={`Field for condition ${conditionIndex + 1} of ${rule.label}`}
501
+ onchange={(value) =>
502
+ handleUpdateCondition(rule.id, condition.id, 'field', value)}
503
+ class="cinder-invocation-rule-builder__condition-combobox"
504
+ />
505
+ {:else}
506
+ <select
507
+ class="cinder-invocation-rule-builder__condition-select"
508
+ aria-label={`Field for condition ${conditionIndex + 1} of ${rule.label}`}
509
+ value={condition.field}
510
+ onchange={(event) =>
511
+ handleUpdateCondition(
512
+ rule.id,
513
+ condition.id,
514
+ 'field',
515
+ (event.target as HTMLSelectElement).value,
516
+ )}
517
+ >
518
+ {#each fieldOptions as option (option.value)}
519
+ <option value={option.value}>{option.label}</option>
520
+ {/each}
521
+ </select>
522
+ {/if}
509
523
 
510
524
  <select
511
525
  class="cinder-invocation-rule-builder__condition-select"
@@ -0,0 +1,48 @@
1
+ import { highlightJsonValidated } from '../../utilities/json-highlight.ts';
2
+
3
+ export type JsonLint = {
4
+ position: number;
5
+ };
6
+
7
+ function lintJson(value: string, validated: boolean): JsonLint | undefined {
8
+ if (validated) return undefined;
9
+ try {
10
+ JSON.parse(value);
11
+ return undefined;
12
+ } catch (error) {
13
+ const message = error instanceof SyntaxError ? error.message : '';
14
+ const positionMatch = message.match(/position (\d+)/i);
15
+ const lineColumnMatch = message.match(/line\s+(\d+)\s+column\s+(\d+)/i);
16
+ let position = Number(positionMatch?.[1] ?? value.length);
17
+ if (!positionMatch && lineColumnMatch) {
18
+ const line = Number(lineColumnMatch[1]);
19
+ const column = Number(lineColumnMatch[2]);
20
+ const lines = value.split('\n');
21
+ position =
22
+ lines.slice(0, line - 1).reduce((offset, current) => offset + current.length + 1, 0) +
23
+ Math.max(0, column - 1);
24
+ }
25
+ return { position };
26
+ }
27
+ }
28
+
29
+ function escapeHtml(text: string): string {
30
+ return text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
31
+ }
32
+
33
+ export function enhanceJson(
34
+ value: string,
35
+ validated = false,
36
+ ): { html: string; lint: JsonLint | undefined } {
37
+ const lint = lintJson(value, validated);
38
+ if (!lint) return { html: highlightJsonValidated(value), lint };
39
+
40
+ const position = Math.min(lint.position, value.length);
41
+ const before = escapeHtml(value.slice(0, position));
42
+ const character = escapeHtml(value[position] ?? '\u00a0');
43
+ const after = escapeHtml(value.slice(position + 1));
44
+ return {
45
+ html: `<code class="cinder-json">${before}<span class="cinder-json-lint">${character}</span>${after}</code>`,
46
+ lint,
47
+ };
48
+ }
@@ -20,6 +20,8 @@
20
20
  }
21
21
 
22
22
  .cinder-json-editor__textarea {
23
+ display: block;
24
+ inline-size: 100%;
23
25
  min-block-size: 10rem;
24
26
  resize: vertical;
25
27
  border: 1px solid var(--cinder-border);
@@ -31,6 +33,72 @@
31
33
  font-size: var(--cinder-text-sm);
32
34
  }
33
35
 
36
+ .cinder-json-editor__input {
37
+ position: relative;
38
+ }
39
+
40
+ .cinder-json-editor__highlight {
41
+ position: absolute;
42
+ inset: 0;
43
+ overflow: auto;
44
+ margin: 0;
45
+ border: 1px solid transparent;
46
+ border-radius: var(--cinder-radius-md);
47
+ padding: var(--cinder-space-2);
48
+ background: var(--cinder-surface);
49
+ pointer-events: none;
50
+ white-space: pre-wrap;
51
+ overflow-wrap: anywhere;
52
+ font-family: var(--cinder-font-mono);
53
+ font-size: var(--cinder-text-sm);
54
+ line-height: normal;
55
+ scrollbar-width: none;
56
+ }
57
+
58
+ .cinder-json-editor__input--nowrap .cinder-json-editor__highlight {
59
+ white-space: pre;
60
+ overflow-wrap: normal;
61
+ width: 100%;
62
+ }
63
+
64
+ .cinder-json-editor__highlight::-webkit-scrollbar {
65
+ display: none;
66
+ }
67
+
68
+ .cinder-json-editor__input--highlighted .cinder-json-editor__textarea {
69
+ position: relative;
70
+ background: transparent;
71
+ color: transparent;
72
+ caret-color: var(--cinder-text);
73
+ }
74
+
75
+ .cinder-json-editor .cinder-json-token-key {
76
+ color: var(--cinder-accent-text);
77
+ }
78
+
79
+ .cinder-json-editor .cinder-json-token-string {
80
+ color: var(--cinder-color-success-fg);
81
+ }
82
+
83
+ .cinder-json-editor .cinder-json-token-number {
84
+ color: var(--cinder-color-warning-fg);
85
+ }
86
+
87
+ .cinder-json-editor .cinder-json-token-boolean,
88
+ .cinder-json-editor .cinder-json-token-null {
89
+ color: var(--cinder-color-info-fg);
90
+ }
91
+
92
+ .cinder-json-editor .cinder-json-token-punctuation {
93
+ color: var(--cinder-text-muted);
94
+ }
95
+
96
+ .cinder-json-editor .cinder-json-lint {
97
+ text-decoration: underline wavy var(--cinder-danger);
98
+ text-decoration-thickness: 1px;
99
+ text-underline-offset: 2px;
100
+ }
101
+
34
102
  .cinder-json-editor__textarea:focus-visible {
35
103
  outline: var(--cinder-ring-width) solid transparent;
36
104
  box-shadow: var(--_cinder-focus-ring-shadow);
@@ -6,8 +6,8 @@
6
6
  {
7
7
  "id": "basic",
8
8
  "title": "Controlled JSON editor",
9
- "description": "A native, controlled JSON text field with parse feedback and no code-editor bundle dependency.",
10
- "code": "<script lang=\"ts\">\n import { JsonEditor } from '@lostgradient/cinder/json-editor';\n\n let value = $state('{\\n \"region\": \"us-west-2\",\\n \"dryRun\": true\\n}');\n</script>\n\n<JsonEditor\n id=\"payload\"\n label=\"Request payload\"\n description=\"Enter the JSON body sent with the request.\"\n {value}\n onValueChange={(nextValue) => (value = nextValue)}\n/>\n"
9
+ "description": "A controlled JSON text field with optional lazy syntax highlighting and parse feedback.",
10
+ "code": "<script lang=\"ts\">\n import { JsonEditor } from '@lostgradient/cinder/json-editor';\n\n let value = $state('{\\n \"region\": \"us-west-2\",\\n \"dryRun\": true\\n}');\n</script>\n\n<JsonEditor\n id=\"payload\"\n label=\"Request payload\"\n description=\"Enter the JSON body sent with the request.\"\n {value}\n onValueChange={(nextValue) => (value = nextValue)}\n highlight={true}\n/>\n"
11
11
  }
12
12
  ]
13
13
  }
@@ -38,6 +38,10 @@
38
38
  "type": "boolean",
39
39
  "description": "Whether valid JSON should render an announced success message. Defaults to true."
40
40
  },
41
+ "highlight": {
42
+ "type": "boolean",
43
+ "description": "Enables a lazy syntax-highlighted view with inline parse-error annotation. Defaults to false."
44
+ },
41
45
  "class": {
42
46
  "type": "string",
43
47
  "description": "Extra class names merged onto the field wrapper."
@@ -41,6 +41,11 @@ const schema = {
41
41
  description:
42
42
  'Whether valid JSON should render an announced success message. Defaults to true.',
43
43
  },
44
+ highlight: {
45
+ type: 'boolean',
46
+ description:
47
+ 'Enables a lazy syntax-highlighted view with inline parse-error annotation. Defaults to false.',
48
+ },
44
49
  class: {
45
50
  type: 'string',
46
51
  description: 'Extra class names merged onto the field wrapper.',