diff --git a/src/components/schema-table.js b/src/components/schema-table.js index 4ea72a23..8791751f 100644 --- a/src/components/schema-table.js +++ b/src/components/schema-table.js @@ -97,10 +97,12 @@ export default class SchemaTable extends LitElement { animation-duration: 0s !important; } .tr:not(.collapsed) + .object-body { + visibility: visible; animation: linear 0.2s expand-height; } .tr.collapsed + .object-body { animation: linear 0.2s collapse-height; + visibility: hidden; max-height: 0; } .obj-toggle { @@ -148,12 +150,16 @@ export default class SchemaTable extends LitElement { max-width: 25%; } -
+
-
-
Field
-
Type
-
Description
+
+
Field
+
Type
+
Description
${result || ''}
@@ -245,20 +251,20 @@ export default class SchemaTable extends LitElement { const outerResult = html` ${newSchemaLevel >= 0 && key ? html` -
-
this.toggleObjectExpand(e)}> +
+
this.toggleObjectExpand(e)} @keydown="${(e) => { if (e.key === 'Enter') { e.target.click(); }}}" aria-expanded="true" aria-controls="${keyLabel}-obj-body">
- ${(keyLabel || keyDescr) ? html`
` : ''} + ${(keyLabel || keyDescr) ? html`` : ''} ${data['::type'] === 'xxx-of-option' || key.startsWith('::OPTION') ? html`${keyLabel}${keyDescr}` : keyLabel.endsWith('*') - ? html` ${keyLabel.substring(0, keyLabel.length - 1)}` + ? html` ${keyLabel.substring(0, keyLabel.length - 1)}` : html`${keyLabel === '::props' ? '' : keyLabel}` }
-
+
${displaySchemaLink ? html` -
+
${unsafeHTML(toMarkdown(displayLine))} ${data['::metadata']?.constraints?.length ? html`
Constraints: ${data['::metadata'].constraints.join(', ')}

` : ''} @@ -275,12 +281,12 @@ export default class SchemaTable extends LitElement {
` : html` ${data['::type'] === 'array' && dataType === 'array' - ? html`
${dataType}
` + ? html`
${dataType}
` : '' } ` } -
+
${recursiveResult}
`; @@ -301,20 +307,20 @@ export default class SchemaTable extends LitElement { } const result = html` -
-
+
+
${keyLabel?.endsWith('*') - ? html`${keyLabel.substring(0, keyLabel.length - 1)}` + ? html`${keyLabel.substring(0, keyLabel.length - 1)}` : key.startsWith('::OPTION') ? html`${keyLabel}${keyDescr}` : html`${keyLabel ? html` ${keyLabel}` : html`${schemaTitle}`}` }
-
+
${dataType === 'array' ? '[' : ''}${format || type}${dataType === 'array' ? ']' : ''}
${readOrWriteOnly}
-
+
${unsafeHTML(toMarkdown(`${`${(schemaTitle || title) ? `**${schemaTitle || title}${schemaDescription || description ? ':' : ''}**` : ''} ${schemaDescription || description}` || ''}`))} @@ -333,6 +339,62 @@ export default class SchemaTable extends LitElement { toggleObjectExpand(e) { const rowEl = e.target.closest('.tr'); rowEl.classList.toggle('collapsed'); + e.target.setAttribute('aria-expanded', !rowEl.classList.contains('collapsed')); + } + + treegridKeydown(e) { + if (e.shiftKey) {return true;} + const cell = e.target; + if (cell.getAttribute('role') !== 'gridcell') {return true;} + const row = Array.from(cell.parentNode.children); + const table = Array.from(cell.closest('.table').querySelectorAll('.tr')); + const index = row.indexOf(cell); + const rIndex = table.indexOf(cell.parentNode); + switch (e.key) { + case 'ArrowRight': + if (index < row.length - 1) { + row[index + 1].tabIndex = 0; + row[index + 1].focus(); + cell.tabIndex = '-1'; + } + break; + case 'ArrowLeft': + if (index > 0) { + row[index - 1].tabIndex = 0; + row[index - 1].focus(); + cell.tabIndex = '-1'; + } + break; + case 'ArrowDown': + if (rIndex < table.length - 1) { + table[rIndex + 1].children[index].tabIndex = 0; + table[rIndex + 1].children[index].focus(); + cell.tabIndex = '-1'; + } + break; + case 'ArrowUp': + if (rIndex > 0) { + table[rIndex - 1].children[index].tabIndex = 0; + table[rIndex - 1].children[index].focus(); + cell.tabIndex = '-1'; + } + break; + case 'Home': + e.preventDefault(); + cell.tabIndex = '-1'; + row[0].tabIndex = 0; + row[0].focus(); + break; + case 'End': + e.preventDefault(); + cell.tabIndex = '-1'; + row[row.length - 1].tabIndex = 0; + row[row.length - 1].focus(); + break; + default: + break; + } + return true; } } if (!customElements.get('openapi-explorer')) { diff --git a/src/styles/schema-styles.js b/src/styles/schema-styles.js index 19f5d098..5f369aaa 100644 --- a/src/styles/schema-styles.js +++ b/src/styles/schema-styles.js @@ -33,6 +33,7 @@ export default css` .key-descr { font-family:var(--font-regular); flex-shrink: 1; + flex-grow: 1; text-overflow: ellipsis; overflow: hidden; display: none;