@qoretechnologies/reqraft 0.10.36 → 0.10.37-pr.95.g4e65c57

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 (57) hide show
  1. package/dist/components/codeSize/index.d.ts +37 -0
  2. package/dist/components/codeSize/index.d.ts.map +1 -0
  3. package/dist/components/codeSize/index.js +87 -0
  4. package/dist/components/codeSize/index.js.map +1 -0
  5. package/dist/components/form/engine/CompactRow.d.ts +6 -1
  6. package/dist/components/form/engine/CompactRow.d.ts.map +1 -1
  7. package/dist/components/form/engine/CompactRow.js +259 -19
  8. package/dist/components/form/engine/CompactRow.js.map +1 -1
  9. package/dist/components/form/engine/FormEngine.d.ts +20 -0
  10. package/dist/components/form/engine/FormEngine.d.ts.map +1 -1
  11. package/dist/components/form/engine/FormEngine.js +137 -24
  12. package/dist/components/form/engine/FormEngine.js.map +1 -1
  13. package/dist/components/form/engine/_structuredData/SchemaDataView.d.ts +37 -0
  14. package/dist/components/form/engine/_structuredData/SchemaDataView.d.ts.map +1 -0
  15. package/dist/components/form/engine/_structuredData/SchemaDataView.js +307 -0
  16. package/dist/components/form/engine/_structuredData/SchemaDataView.js.map +1 -0
  17. package/dist/components/form/engine/compactRowStyles.d.ts +13 -0
  18. package/dist/components/form/engine/compactRowStyles.d.ts.map +1 -1
  19. package/dist/components/form/engine/compactRowStyles.js +30 -5
  20. package/dist/components/form/engine/compactRowStyles.js.map +1 -1
  21. package/dist/components/form/engine/readFirst.d.ts +66 -1
  22. package/dist/components/form/engine/readFirst.d.ts.map +1 -1
  23. package/dist/components/form/engine/readFirst.js +175 -5
  24. package/dist/components/form/engine/readFirst.js.map +1 -1
  25. package/dist/components/form/fields/array/ArrayAuto.d.ts.map +1 -1
  26. package/dist/components/form/fields/array/ArrayAuto.js +51 -21
  27. package/dist/components/form/fields/array/ArrayAuto.js.map +1 -1
  28. package/dist/components/form/fields/array/ArrayAutoField.d.ts.map +1 -1
  29. package/dist/components/form/fields/array/ArrayAutoField.js +42 -25
  30. package/dist/components/form/fields/array/ArrayAutoField.js.map +1 -1
  31. package/dist/components/form/fields/auto/AutoFormField.d.ts +4 -0
  32. package/dist/components/form/fields/auto/AutoFormField.d.ts.map +1 -1
  33. package/dist/components/form/fields/auto/AutoFormField.js +8 -1
  34. package/dist/components/form/fields/auto/AutoFormField.js.map +1 -1
  35. package/dist/helpers/validations.d.ts +14 -0
  36. package/dist/helpers/validations.d.ts.map +1 -1
  37. package/dist/helpers/validations.js +58 -3
  38. package/dist/helpers/validations.js.map +1 -1
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +1 -0
  42. package/dist/index.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/components/codeSize/index.tsx +79 -0
  45. package/src/components/form/engine/CompactRow.tsx +313 -24
  46. package/src/components/form/engine/FormEngine.stories.tsx +487 -14
  47. package/src/components/form/engine/FormEngine.tsx +142 -8
  48. package/src/components/form/engine/_structuredData/SchemaDataView.stories.tsx +129 -0
  49. package/src/components/form/engine/_structuredData/SchemaDataView.tsx +594 -0
  50. package/src/components/form/engine/compactRowStyles.ts +44 -2
  51. package/src/components/form/engine/readFirst.ts +201 -5
  52. package/src/components/form/fields/array/ArrayAuto.tsx +35 -4
  53. package/src/components/form/fields/array/ArrayAutoField.stories.tsx +53 -0
  54. package/src/components/form/fields/array/ArrayAutoField.tsx +22 -4
  55. package/src/components/form/fields/auto/AutoFormField.tsx +11 -0
  56. package/src/helpers/validations.ts +59 -2
  57. package/src/index.tsx +1 -0
@@ -912,6 +912,169 @@ export const OptionInheritsRenderPropFromSiblingCompact: Story = {
912
912
  // cell couldn't provide on its own. Locks the compact preview so a future
913
913
  // CompactRow refactor can't silently reduce a Qorus source-code field to an
914
914
  // ellipsised one-liner again.
915
+ // An open field used to have exactly one way out — the green Done check — so
916
+ // every exit committed, Escape included. This locks the Cancel affordance in
917
+ // place: it appears only once there is something to discard, and it puts the
918
+ // value back to what the field was opened with.
919
+ export const CompactRowCancelEdit: Story = {
920
+ parameters: {
921
+ docs: {
922
+ description: {
923
+ story:
924
+ 'Renders a compact row opened for editing with a changed value — the Cancel action appears beside Done, and clicking it puts the field back to the value it was opened with and closes it.',
925
+ },
926
+ },
927
+ },
928
+ args: {
929
+ compact: true,
930
+ minColumnWidth: '360px',
931
+ value: { cookie_name: { type: 'string', value: 'my-cookie' } },
932
+ options: {
933
+ cookie_name: {
934
+ type: 'string',
935
+ ui_type: 'string',
936
+ display_name: 'Cookie Name',
937
+ short_desc: 'Cookie name for cookie authentication',
938
+ },
939
+ },
940
+ },
941
+ play: async ({ canvasElement }) => {
942
+ // Open the field.
943
+ const row = canvasElement.querySelector<HTMLElement>('[data-field="cookie_name"]');
944
+ expect(row).toBeTruthy();
945
+ fireEvent.click(row!);
946
+ await waitFor(() =>
947
+ expect(canvasElement.querySelector('.readfirst-row-editing')).toBeTruthy()
948
+ );
949
+
950
+ // An untouched field offers no Cancel — it would do exactly what Done does.
951
+ expect(canvasElement.querySelector('.options-readfirst-cancel')).toBeNull();
952
+
953
+ const input = canvasElement.querySelector<HTMLInputElement>(
954
+ '[data-field="cookie_name"] input, [data-field="cookie_name"] textarea'
955
+ );
956
+ expect(input).toBeTruthy();
957
+ fireEvent.change(input!, { target: { value: 'changed-cookie' } });
958
+
959
+ // Cancel appears the moment the value differs from what was opened.
960
+ await waitFor(
961
+ () => expect(canvasElement.querySelector('.options-readfirst-cancel')).toBeTruthy(),
962
+ { timeout: 5000 }
963
+ );
964
+
965
+ fireEvent.click(canvasElement.querySelector<HTMLElement>('.options-readfirst-cancel')!);
966
+
967
+ // The row closes and the opened-with value is back.
968
+ await waitFor(() => expect(canvasElement.querySelector('.readfirst-row-editing')).toBeNull(), {
969
+ timeout: 5000,
970
+ });
971
+ await waitFor(
972
+ () =>
973
+ expect(
974
+ canvasElement.querySelector('[data-field="cookie_name"]')?.textContent ?? ''
975
+ ).toContain('my-cookie'),
976
+ { timeout: 5000 }
977
+ );
978
+ },
979
+ };
980
+
981
+ // Language and Source code are one decision — "what is this code, and in what
982
+ // language" — and the form used to ask it as two unrelated rows one above the
983
+ // other. `absorb_fields` lets the editor take the language into its own
984
+ // container so the pair reads as the single element it is.
985
+ export const CompactRowAbsorbsLanguage: Story = {
986
+ parameters: {
987
+ docs: {
988
+ description: {
989
+ story:
990
+ 'Renders a code-editor row that absorbs its Language sibling — the language control sits inside the Source Code container above the editor instead of on a row of its own, and the collapsed row summarises it as a chip beside the code size.',
991
+ },
992
+ },
993
+ },
994
+ args: {
995
+ compact: true,
996
+ minColumnWidth: '360px',
997
+ componentOverrides: { 'code-editor': CodeEditorStandin },
998
+ value: {
999
+ language: { type: 'string', value: 'qore' },
1000
+ source: { type: 'string', value: '%new-style\nclass Example {\n}\n' },
1001
+ },
1002
+ options: {
1003
+ language: {
1004
+ type: 'string',
1005
+ ui_type: 'string',
1006
+ display_name: 'Language',
1007
+ allowed_values: [
1008
+ { display_name: 'Qore', value: { type: 'string', value: 'qore' } },
1009
+ { display_name: 'Python', value: { type: 'string', value: 'python' } },
1010
+ ],
1011
+ },
1012
+ source: {
1013
+ type: 'string',
1014
+ ui_type: 'code-editor',
1015
+ display_name: 'Source Code',
1016
+ inherit_props: { language: 'language' },
1017
+ absorb_fields: ['language'],
1018
+ },
1019
+ },
1020
+ },
1021
+ play: async ({ canvasElement }) => {
1022
+ // The absorbed field has no row of its own.
1023
+ await waitFor(() => expect(canvasElement.querySelector('[data-field="source"]')).toBeTruthy());
1024
+ expect(canvasElement.querySelector('[data-field="language"]')).toBeNull();
1025
+
1026
+ // Collapsed, the host still reports the absorbed value — otherwise the
1027
+ // language would vanish from the form whenever the editor is closed.
1028
+ const sourceRow = canvasElement.querySelector('[data-field="source"]');
1029
+ expect(sourceRow?.textContent ?? '').toContain('qore');
1030
+
1031
+ // Opening the host renders the language control inside its container.
1032
+ fireEvent.click(sourceRow as HTMLElement);
1033
+ await waitFor(() =>
1034
+ expect(canvasElement.querySelector('.readfirst-row-editing')).toBeTruthy()
1035
+ );
1036
+ await waitFor(() =>
1037
+ expect(canvasElement.querySelector('.options-readfirst-absorbed')).toBeTruthy()
1038
+ );
1039
+ // It is still identifiable as its own field, not a property of the editor.
1040
+ expect(canvasElement.querySelector('.options-readfirst-absorbed')?.textContent ?? '').toContain(
1041
+ 'Language'
1042
+ );
1043
+ },
1044
+ };
1045
+
1046
+ export const CompactRowCancelEditAffordance: Story = {
1047
+ ...CompactRowCancelEdit,
1048
+ parameters: {
1049
+ docs: {
1050
+ description: {
1051
+ story:
1052
+ 'Renders a compact row open for editing with a changed value, stopping while it is open — Cancel edit sits beside the green Done check, which is what an open field used to offer on its own.',
1053
+ },
1054
+ },
1055
+ },
1056
+ play: async ({ canvasElement }) => {
1057
+ const row = canvasElement.querySelector<HTMLElement>('[data-field="cookie_name"]');
1058
+ expect(row).toBeTruthy();
1059
+ fireEvent.click(row!);
1060
+ await waitFor(() =>
1061
+ expect(canvasElement.querySelector('.readfirst-row-editing')).toBeTruthy()
1062
+ );
1063
+
1064
+ const input = canvasElement.querySelector<HTMLInputElement>(
1065
+ '[data-field="cookie_name"] input, [data-field="cookie_name"] textarea'
1066
+ );
1067
+ fireEvent.change(input!, { target: { value: 'changed-cookie' } });
1068
+
1069
+ await waitFor(
1070
+ () => expect(canvasElement.querySelector('.options-readfirst-cancel')).toBeTruthy(),
1071
+ { timeout: 5000 }
1072
+ );
1073
+ // Both ways out are on screen together, which is the point of the story.
1074
+ expect(canvasElement.querySelector('.options-readfirst-done')).toBeTruthy();
1075
+ },
1076
+ };
1077
+
915
1078
  export const CompactRowCodeEditorPreview: Story = {
916
1079
  parameters: {
917
1080
  docs: {
@@ -1164,7 +1327,7 @@ export const NestedOptionInheritsRenderPropFromAncestorCompact: Story = {
1164
1327
  docs: {
1165
1328
  description: {
1166
1329
  story:
1167
- "Renders the NestedOptionInheritsRenderPropFromAncestor schema with compact=true — the compact renderer summarises the list-of-hash rows as 'init, run' rather than [object Object].",
1330
+ "Renders the NestedOptionInheritsRenderPropFromAncestor schema with compact=true — the compact renderer previews the list-of-hash rows through their arg_schema, naming each method, rather than printing [object Object].",
1168
1331
  },
1169
1332
  },
1170
1333
  },
@@ -1229,11 +1392,13 @@ export const NestedOptionInheritsRenderPropFromAncestorCompact: Story = {
1229
1392
  await waitFor(() => expect(canvas.getAllByText('Methods').length).toBeGreaterThan(0), {
1230
1393
  timeout: 5000,
1231
1394
  });
1232
- // The list-of-hashes value summarises by the items' names — never a raw
1233
- // "[object Object]" (regression: it used to stringify each hash envelope).
1234
- await expect(
1235
- await canvas.findByText('init, run', undefined, { timeout: 5000 })
1236
- ).toBeInTheDocument();
1395
+ // The list-of-hashes value names its items — never a raw "[object Object]"
1396
+ // (regression: it used to stringify each hash envelope). The names now come
1397
+ // from the schema preview rather than a joined summary line above it, so the
1398
+ // assertion moved with them; what must never come back is the stringified
1399
+ // envelope.
1400
+ await expect(await canvas.findByText('init', undefined, { timeout: 5000 })).toBeInTheDocument();
1401
+ await expect(await canvas.findByText('run')).toBeInTheDocument();
1237
1402
  await expect(canvasElement.textContent ?? '').not.toContain('[object Object]');
1238
1403
  },
1239
1404
  };
@@ -1290,12 +1455,16 @@ export const CompactNestedListRowsStayCompact: Story = {
1290
1455
  } as unknown as IOptionsSchema,
1291
1456
  },
1292
1457
  play: async ({ canvasElement }) => {
1293
- // Collapsed, the row summarises by the items' names.
1294
- await _testsWaitForText('init, run');
1458
+ // Collapsed, the row previews its items through their schema — one numbered
1459
+ // entry per method, each naming itself.
1460
+ // The method name heads its item now, so that is what identifies the row.
1461
+ await _testsWaitForText('init');
1462
+ await _testsWaitForText('run');
1295
1463
 
1296
1464
  // Open the Methods row — this mounts ArrayAuto and, with it, one
1297
- // arg_schema sub-form per row.
1298
- await _testsClickText('init, run');
1465
+ // arg_schema sub-form per row. Clicked by the field's NAME: the joined
1466
+ // summary that used to sit on this row is gone, replaced by the preview.
1467
+ await _testsClickText('Methods');
1299
1468
 
1300
1469
  await waitFor(
1301
1470
  () => expect(canvasElement.querySelectorAll('.array-auto-item')).toHaveLength(2),
@@ -1347,8 +1516,8 @@ export const CompactNestedListRowsStayCompactMobile: Story = {
1347
1516
  ),
1348
1517
  ],
1349
1518
  play: async ({ canvasElement }) => {
1350
- await _testsWaitForText('init, run');
1351
- await _testsClickText('init, run');
1519
+ await _testsWaitForText('init');
1520
+ await _testsClickText('Methods');
1352
1521
 
1353
1522
  await waitFor(
1354
1523
  () => expect(canvasElement.querySelectorAll('.array-auto-item')).toHaveLength(2),
@@ -4122,6 +4291,29 @@ export const CompactFieldTypes: Story = {
4122
4291
  secure: { type: 'bool', display_name: 'Secure' },
4123
4292
  },
4124
4293
  },
4294
+ // The list counterpart of `connectionInfo`: a list of hashes whose fields
4295
+ // are declared. This is the shape the schema preview was built for, and the
4296
+ // catalogue was missing it — it covered the described HASH but not the
4297
+ // described LIST, which is the case that was actually reported.
4298
+ routes: {
4299
+ type: 'list',
4300
+ ui_type: 'list',
4301
+ element_type: 'hash',
4302
+ display_name: 'List of hashes (arg_schema)',
4303
+ group: 'structured',
4304
+ arg_schema: {
4305
+ method: {
4306
+ type: 'string',
4307
+ display_name: 'Method',
4308
+ allowed_values: [
4309
+ { value: 'get', display_name: 'GET' },
4310
+ { value: 'post', display_name: 'POST' },
4311
+ ],
4312
+ },
4313
+ path: { type: 'string', display_name: 'Path' },
4314
+ handler: { type: 'string', ui_type: 'code-editor', display_name: 'Handler' },
4315
+ },
4316
+ },
4125
4317
  freeConfig: {
4126
4318
  type: 'free-hash',
4127
4319
  ui_type: 'free-hash',
@@ -4330,6 +4522,22 @@ export const CompactFieldTypes: Story = {
4330
4522
  secure: { type: 'bool', value: true },
4331
4523
  },
4332
4524
  },
4525
+ routes: {
4526
+ type: 'list',
4527
+ value: [
4528
+ // One item complete, one with the optional field unset — the empty
4529
+ // state stays exercised rather than being filled in everywhere.
4530
+ {
4531
+ type: 'hash',
4532
+ value: {
4533
+ method: 'get',
4534
+ path: '/orders',
4535
+ handler: 'sub get_orders() {\n return orders.all();\n}',
4536
+ },
4537
+ },
4538
+ { type: 'hash', value: { method: 'post', path: '/orders' } },
4539
+ ],
4540
+ },
4333
4541
  freeConfig: { type: 'free-hash', value: '%YAML 1.2\n---\nretries: 3\ntimeout: 30\n' },
4334
4542
  bigConfig: {
4335
4543
  type: 'hash',
@@ -4412,7 +4620,23 @@ export const CompactFieldTypes: Story = {
4412
4620
  await _testsWaitForText('#0000FF'); // colour → uppercase hex
4413
4621
  await _testsWaitForText('rgba(255, 0, 0, 0.5)'); // colour with alpha → rgba()
4414
4622
  await _testsWaitForText('config.txt'); // file → filename
4415
- await _testsWaitForText('3 fields'); // structured hash → field count summary
4623
+ // A hash the schema DESCRIBES needs no count: its preview names every field,
4624
+ // so "3 fields" above "Host / Port / Secure" would be the same fact twice.
4625
+ // A hash it does not describe keeps the count — the untyped tree beneath it
4626
+ // says nothing about what the value means, so the count is the only line
4627
+ // that does. Both halves asserted here: the distinction IS the behaviour.
4628
+ await _testsWaitForText('2 fields'); // undescribed hash → field count summary
4629
+ await _testsWaitForText('Host'); // described hash → its fields, by name
4630
+ await _testsWaitForTextToNotExist('3 fields');
4631
+
4632
+ // Described LIST of hashes: numbered items, labels by display_name, and the
4633
+ // allowed value read back as its label rather than the stored `get`.
4634
+ await _testsWaitForText('Path');
4635
+ await _testsWaitForText('/orders');
4636
+ await _testsWaitForText('GET');
4637
+ // A code sub-field renders AS code, not as a flattened mono line.
4638
+ await _testsWaitForText('Handler');
4639
+ await _testsWaitForText(/sub get_orders/);
4416
4640
  await _testsWaitForText('order-to-invoice'); // interface reference → raw value
4417
4641
 
4418
4642
  // Field stack (merged from dpql): byte-size shows its value string; the
@@ -4582,7 +4806,12 @@ export const CompactFieldTypesEditing: Story = {
4582
4806
  await userEvent.click(within(confirmationModal!).getByRole('button', { name: 'Clear value' }));
4583
4807
  await waitFor(() => {
4584
4808
  expect(editRow('enabled').querySelector('.options-readfirst-clear')).not.toBeInTheDocument();
4585
- expect(editRow('enabled').querySelector('.options-readfirst-revert')).toBeInTheDocument();
4809
+ // Clear swaps for the undo affordance. In an OPEN field that is
4810
+ // "Cancel edit" — the field was opened holding its form-load value, so
4811
+ // undoing this edit and reverting the field are the same thing and only
4812
+ // one button is offered. The form-load revert reappears here only when
4813
+ // the field was already modified before it was opened.
4814
+ expect(editRow('enabled').querySelector('.options-readfirst-cancel')).toBeInTheDocument();
4586
4815
  });
4587
4816
  },
4588
4817
  };
@@ -5915,3 +6144,247 @@ export const CompactRowMarkdownWithoutRenderer: Story = {
5915
6144
  expect(descText).not.toContain('**');
5916
6145
  },
5917
6146
  };
6147
+
6148
+ /**
6149
+ * The auth-profile scheme sub-schema, which is where all three of the list-row
6150
+ * affordances below were reported. One required choice with named allowed
6151
+ * values, one field that belongs to a single choice.
6152
+ */
6153
+ const AuthSchemeArgSchema = {
6154
+ type: {
6155
+ type: 'string',
6156
+ ui_type: 'string',
6157
+ display_name: 'Scheme Type',
6158
+ short_desc: 'Authentication scheme type',
6159
+ required: true,
6160
+ allowed_values: [
6161
+ { value: 'default', display_name: 'Default RBAC' },
6162
+ { value: 'cookie', display_name: 'Cookie' },
6163
+ { value: 'oauth2', display_name: 'OAuth2' },
6164
+ ],
6165
+ },
6166
+ cookie_name: {
6167
+ type: 'string',
6168
+ ui_type: 'string',
6169
+ display_name: 'Session Cookie Name',
6170
+ short_desc: 'Applies to the Cookie scheme alone',
6171
+ depends_on: ['type=cookie'],
6172
+ },
6173
+ } as unknown as IOptionsSchema;
6174
+
6175
+ const AuthSchemeOptions = {
6176
+ schemes: {
6177
+ type: 'list',
6178
+ ui_type: 'list',
6179
+ element_type: 'hash',
6180
+ display_name: 'Authentication Schemes',
6181
+ short_desc: 'Schemes tried in order, first match wins',
6182
+ required: true,
6183
+ arg_schema: AuthSchemeArgSchema,
6184
+ },
6185
+ } as unknown as IOptionsSchema;
6186
+
6187
+ /**
6188
+ * A list-of-hash row reads back in the words the form asked for the value.
6189
+ *
6190
+ * Reported on an auth profile: the row summarised as "2 items" and its preview
6191
+ * printed a data tree — "Object · 1 field" over `type: default`. Both are
6192
+ * exactly what is stored, and neither is a string the author has ever seen: the
6193
+ * form calls that key "Scheme Type" and that value "Default RBAC". A row meant
6194
+ * to confirm a choice showed a value nobody had chosen, in a shape nobody had
6195
+ * asked about.
6196
+ *
6197
+ * A generic data view has to announce what it found, because inference is all it
6198
+ * has. A field with an `arg_schema` needs none of that — the shape, the names and
6199
+ * the choices are known before the value arrives — so the preview renders
6200
+ * THROUGH the schema (`SchemaDataView`) and the summary resolves through the
6201
+ * same one. The row, the preview and the editor cannot describe a value three
6202
+ * ways.
6203
+ */
6204
+ export const CompactListOfHashReadsInSchemaWords: Story = {
6205
+ parameters: {
6206
+ docs: {
6207
+ description: {
6208
+ story:
6209
+ 'A list-of-hash option whose sub-schema names its fields and values. The collapsed row summarises by those names ("Default RBAC, Cookie") and the preview renders as labelled schema rows — "Scheme Type · Default RBAC" per numbered item — instead of an untyped data tree over the stored `type: default`.',
6210
+ },
6211
+ },
6212
+ },
6213
+ args: {
6214
+ compact: true,
6215
+ minColumnWidth: '300px',
6216
+ options: AuthSchemeOptions,
6217
+ value: {
6218
+ schemes: {
6219
+ type: 'list',
6220
+ value: [
6221
+ { type: 'hash', value: { type: 'default' } },
6222
+ { type: 'hash', value: { type: 'cookie', cookie_name: 'qorus-session' } },
6223
+ ],
6224
+ },
6225
+ },
6226
+ },
6227
+ play: async ({ canvasElement }) => {
6228
+ // The preview IS the value here — the row prints no summary line above it.
6229
+ // A joined "Default RBAC, Cookie" directly over a preview that names both
6230
+ // items is the same facts twice, the lossy version first.
6231
+ const preview = await waitFor(() => {
6232
+ const element = canvasElement.querySelector('.schema-data-view');
6233
+ expect(element).toBeTruthy();
6234
+ return element!;
6235
+ });
6236
+ const text = preview.textContent ?? '';
6237
+ // Each item is headed by its first value, so the list reads by name; the
6238
+ // remaining fields keep their labels.
6239
+ const titles = [...preview.querySelectorAll('.schema-view-item-title')].map((element) =>
6240
+ (element.textContent ?? '').trim()
6241
+ );
6242
+ expect(titles).toEqual(['Default RBAC', 'Cookie']);
6243
+ expect(text).toContain('Session Cookie Name');
6244
+
6245
+ // Nothing announces the container's shape — that is the tell of a renderer
6246
+ // guessing at data it has not been told about.
6247
+ expect(text).not.toMatch(/Object\b/);
6248
+ expect(text).not.toMatch(/\d+ fields?\b/);
6249
+
6250
+ // The joined summary is gone from the row, and it is the ROW that has to be
6251
+ // checked: the same words still exist inside the preview, so asserting on
6252
+ // the whole canvas would pass whether or not the line was removed.
6253
+ const valueLine = canvasElement.querySelector(
6254
+ '[data-field="schemes"] .options-readfirst-valuetext'
6255
+ );
6256
+ expect(valueLine?.textContent ?? '').not.toBe('Default RBAC, Cookie');
6257
+
6258
+ // A literal the author typed is set in mono; a chosen label is not.
6259
+ const mono = [...preview.querySelectorAll('.schema-view-data')].map((el) =>
6260
+ (el.textContent ?? '').trim()
6261
+ );
6262
+ expect(mono).toContain('qorus-session');
6263
+ expect(mono).not.toContain('Default RBAC');
6264
+
6265
+ // The stored spellings are what the author never chose, so they must not be
6266
+ // in the preview at all. Substring checks cannot say this — "Scheme Type"
6267
+ // contains "type" and "Default RBAC" contains "default" — so the assertion
6268
+ // is on whole leaf elements: no chip or cell reads exactly `type`,
6269
+ // `cookie_name` or `default`. A substring assertion here passed against a
6270
+ // preview that was still rendering the raw pair.
6271
+ const leafTexts = [...preview.querySelectorAll('*')]
6272
+ .filter((element) => element.children.length === 0)
6273
+ .map((element) => (element.textContent ?? '').trim());
6274
+ expect(leafTexts).toContain('Default RBAC');
6275
+ for (const stored of ['type', 'cookie_name', 'default']) {
6276
+ expect(leafTexts).not.toContain(stored);
6277
+ }
6278
+ expect(canvasElement.textContent ?? '').not.toContain('[object Object]');
6279
+ },
6280
+ };
6281
+
6282
+ /**
6283
+ * Adding a list item opens the field the item cannot be saved without.
6284
+ *
6285
+ * `+ Add new item for "Authentication Scheme"` added a row whose one required
6286
+ * field sat collapsed, so the author had to find it and click it before the
6287
+ * form could be completed — a second click to reach the only thing the first
6288
+ * click could have meant.
6289
+ *
6290
+ * The engine already had `autoFocusFirstRequired`, and it could not fire here:
6291
+ * it waits for focus to be free so it never steals a caret, and a form mounted
6292
+ * BY a click never sees free focus — the button that mounted it still holds it.
6293
+ * Opening a row and moving the caret are separate decisions, so they are now
6294
+ * separate flags; this one only opens.
6295
+ */
6296
+ export const CompactAddedListRowOpensItsRequiredField: Story = {
6297
+ parameters: {
6298
+ docs: {
6299
+ description: {
6300
+ story:
6301
+ 'Clicks "Add new item" on a list-of-hash option and shows the new row with its required "Scheme Type" field already open. Rows that were already in the value stay collapsed — only the row just added is opened.',
6302
+ },
6303
+ },
6304
+ },
6305
+ args: {
6306
+ compact: true,
6307
+ minColumnWidth: '300px',
6308
+ options: AuthSchemeOptions,
6309
+ value: {
6310
+ schemes: {
6311
+ type: 'list',
6312
+ value: [{ type: 'hash', value: { type: 'default' } }],
6313
+ },
6314
+ },
6315
+ },
6316
+ play: async ({ canvasElement }) => {
6317
+ // Open the list itself, which mounts the rows and the Add button. Clicked by
6318
+ // FIELD, not by its text: the row no longer prints a summary line, and the
6319
+ // words that remain live inside the preview.
6320
+ await _testsClickText('Authentication Schemes');
6321
+ await waitFor(() => expect(canvasElement.querySelectorAll('.array-auto-item')).toHaveLength(1));
6322
+
6323
+ // The row that was already there is collapsed — this is the state the new
6324
+ // row must NOT be confused with.
6325
+ const isOpen = (element: Element | null | undefined) =>
6326
+ !!element &&
6327
+ (element.classList.contains('readfirst-row-editing') ||
6328
+ element.classList.contains('options-readfirst-card'));
6329
+ const typeRows = () => canvasElement.querySelectorAll('[data-field="type"]');
6330
+ expect([...typeRows()].some(isOpen)).toBe(false);
6331
+
6332
+ await _testsClickButton({ label: 'Add new item for "Authentication Schemes"' });
6333
+
6334
+ await waitFor(() => expect(canvasElement.querySelectorAll('.array-auto-item')).toHaveLength(2));
6335
+ // Exactly one open required field: the one belonging to the row just added.
6336
+ await waitFor(() => expect([...typeRows()].filter(isOpen)).toHaveLength(1));
6337
+ },
6338
+ };
6339
+
6340
+ /**
6341
+ * The same schema-worded row at a phone-class width.
6342
+ *
6343
+ * The narrow branch is what makes this worth its own story: below 480px the row
6344
+ * stacks the value under the label, so a summary and a preview that were both
6345
+ * rewritten to be READ (rather than decoded) have to survive the stacking
6346
+ * without wrapping into an unreadable column. `compactNarrow` comes from
6347
+ * `useMeasure` on the form's own wrapper, not from a media query, so a narrow
6348
+ * container is the honest way to reach the branch here — the viewport-parameter
6349
+ * rule applies to media-query components, which this is not.
6350
+ */
6351
+ export const CompactListOfHashReadsInSchemaWordsMobile: Story = {
6352
+ parameters: {
6353
+ docs: {
6354
+ description: {
6355
+ story:
6356
+ 'The schema-worded list-of-hash row at a ~360px width: the summary and the renamed preview stack under the field name and stay legible in one column.',
6357
+ },
6358
+ },
6359
+ },
6360
+ args: CompactListOfHashReadsInSchemaWords.args,
6361
+ decorators: [
6362
+ (StoryComponent: React.ComponentType) => (
6363
+ <div style={{ maxWidth: 360, margin: '0 auto', border: '1px dashed #ffffff22' }}>
6364
+ <StoryComponent />
6365
+ </div>
6366
+ ),
6367
+ ],
6368
+ play: async ({ canvasElement }) => {
6369
+ await _testsWaitForText('Default RBAC');
6370
+
6371
+ // The narrow branch is actually engaged — otherwise this is the desktop
6372
+ // story with a border round it, and it would pass while proving nothing.
6373
+ await waitFor(() =>
6374
+ expect(canvasElement.querySelector('.readfirst-narrow')).toBeTruthy()
6375
+ );
6376
+
6377
+ const preview = await waitFor(() => {
6378
+ const element = canvasElement.querySelector('.schema-data-view');
6379
+ expect(element).toBeTruthy();
6380
+ return element!;
6381
+ });
6382
+ const leafTexts = [...preview.querySelectorAll('*')]
6383
+ .filter((element) => element.children.length === 0)
6384
+ .map((element) => (element.textContent ?? '').trim());
6385
+ expect(leafTexts).toContain('Session Cookie Name');
6386
+ for (const stored of ['type', 'cookie_name', 'default']) {
6387
+ expect(leafTexts).not.toContain(stored);
6388
+ }
6389
+ },
6390
+ };