vira 31.18.1 → 31.18.2
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/elements/vira-json-form.element.js +192 -141
- package/dist/elements/vira-text-area.element.js +1 -0
- package/dist/icons/icon-svgs/16/plus-16.icon.d.ts +8 -0
- package/dist/icons/icon-svgs/{plus-24.icon.js → 16/plus-16.icon.js} +7 -7
- package/dist/icons/index.d.ts +3 -0
- package/dist/icons/index.js +4 -0
- package/package.json +1 -1
- package/dist/icons/icon-svgs/plus-24.icon.d.ts +0 -8
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { assertWrap, check } from '@augment-vir/assert';
|
|
2
2
|
import { omitObjectKeys, wrapInTry } from '@augment-vir/common';
|
|
3
|
-
import { extractEventTarget } from '@augment-vir/web';
|
|
4
3
|
import { css, defineElementEvent, html, listen, nothing } from 'element-vir';
|
|
5
|
-
import {
|
|
4
|
+
import { Plus16Icon, X16Icon } from '../icons/index.js';
|
|
6
5
|
import { viraFontCssVars } from '../styles/font.js';
|
|
7
6
|
import { viraFormCssVars } from '../styles/form-styles.js';
|
|
8
7
|
import { ViraColorVariant, ViraEmphasis, ViraSize } from '../styles/form-variants.js';
|
|
@@ -13,6 +12,7 @@ import { ViraCheckbox } from './vira-checkbox.element.js';
|
|
|
13
12
|
import { ViraError } from './vira-error.element.js';
|
|
14
13
|
import { ViraInput, ViraInputType } from './vira-input.element.js';
|
|
15
14
|
import { ViraSelect } from './vira-select.element.js';
|
|
15
|
+
import { ViraTextArea } from './vira-text-area.element.js';
|
|
16
16
|
/**
|
|
17
17
|
* An editor for arbitrary JSON values, optionally constrained by a standard JSON Schema
|
|
18
18
|
* ({@link ViraJsonSchema}).
|
|
@@ -48,24 +48,10 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
48
48
|
justify-content: flex-end;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
.json-raw-textarea {
|
|
52
|
-
|
|
53
|
-
padding: 10px 12px;
|
|
54
|
-
border: 1px solid ${viraFormCssVars['vira-form-border-color'].value};
|
|
55
|
-
border-radius: ${viraFormCssVars['vira-form-wrapper-radius'].value};
|
|
56
|
-
background-color: ${viraFormCssVars['vira-form-background-color'].value};
|
|
57
|
-
color: ${viraFormCssVars['vira-form-foreground-color'].value};
|
|
51
|
+
${ViraTextArea}.json-raw-textarea {
|
|
52
|
+
width: 100%;
|
|
58
53
|
font-family: ${viraFontCssVars['vira-monospace'].value};
|
|
59
54
|
font-size: ${viraFormCssVars['vira-form-small-text-size'].value};
|
|
60
|
-
box-sizing: border-box;
|
|
61
|
-
width: 100%;
|
|
62
|
-
min-height: 240px;
|
|
63
|
-
resize: vertical;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.json-raw-textarea:focus {
|
|
67
|
-
outline: none;
|
|
68
|
-
border-color: ${viraFormCssVars['vira-form-focus-outline-color'].value};
|
|
69
55
|
}
|
|
70
56
|
|
|
71
57
|
.json-validation-errors {
|
|
@@ -80,68 +66,71 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
80
66
|
}
|
|
81
67
|
|
|
82
68
|
.json-group {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
padding: 10px 12px;
|
|
87
|
-
border: 1px solid ${viraFormCssVars['vira-form-border-color'].value};
|
|
88
|
-
border-radius: ${viraFormCssVars['vira-form-wrapper-radius'].value};
|
|
89
|
-
background-color: ${viraFormCssVars['vira-form-background-color'].value};
|
|
69
|
+
border-collapse: separate;
|
|
70
|
+
border-spacing: 0;
|
|
71
|
+
width: 100%;
|
|
90
72
|
box-sizing: border-box;
|
|
91
73
|
}
|
|
92
74
|
|
|
93
|
-
.json-group-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
75
|
+
.json-group-nested {
|
|
76
|
+
margin-top: 4px;
|
|
77
|
+
padding-left: 12px;
|
|
78
|
+
padding-bottom: 8px;
|
|
79
|
+
border-left: 2px solid ${viraFormCssVars['vira-form-border-color'].value};
|
|
80
|
+
border-bottom: 2px solid ${viraFormCssVars['vira-form-border-color'].value};
|
|
97
81
|
}
|
|
98
82
|
|
|
99
|
-
.json-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
color: ${viraFormCssVars['vira-form-secondary-body-foreground'].value};
|
|
103
|
-
font-size: ${viraFormCssVars['vira-form-small-text-size'].value};
|
|
83
|
+
.json-row-primitive > td {
|
|
84
|
+
padding: 4px 8px 4px 0;
|
|
85
|
+
vertical-align: middle;
|
|
104
86
|
}
|
|
105
87
|
|
|
106
|
-
.json-row {
|
|
107
|
-
|
|
108
|
-
gap: 8px;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.json-row-primitive {
|
|
112
|
-
align-items: center;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.json-row-nested {
|
|
116
|
-
flex-direction: column;
|
|
117
|
-
align-items: stretch;
|
|
118
|
-
gap: 4px;
|
|
88
|
+
.json-row-primitive > td:last-child {
|
|
89
|
+
padding-right: 0;
|
|
119
90
|
}
|
|
120
91
|
|
|
121
|
-
.json-row-label {
|
|
122
|
-
|
|
92
|
+
td.json-row-label {
|
|
93
|
+
text-align: left;
|
|
123
94
|
min-width: 80px;
|
|
95
|
+
white-space: nowrap;
|
|
124
96
|
font-weight: ${viraFormCssVars['vira-form-label-font-weight'].value};
|
|
125
|
-
word-break: break-word;
|
|
126
97
|
}
|
|
127
98
|
|
|
128
|
-
.json-row-editor {
|
|
129
|
-
|
|
130
|
-
min-width: 0;
|
|
131
|
-
display: flex;
|
|
132
|
-
flex-direction: column;
|
|
99
|
+
td.json-row-editor {
|
|
100
|
+
width: 100%;
|
|
133
101
|
}
|
|
134
102
|
|
|
135
|
-
.json-row-editor > * {
|
|
103
|
+
td.json-row-editor > * {
|
|
136
104
|
width: 100%;
|
|
137
105
|
max-width: 100%;
|
|
106
|
+
box-sizing: border-box;
|
|
138
107
|
}
|
|
139
108
|
|
|
140
|
-
.json-row-delete {
|
|
141
|
-
flex-shrink: 0;
|
|
109
|
+
td.json-row-delete {
|
|
142
110
|
width: 24px;
|
|
111
|
+
text-align: center;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.json-row-nested > td {
|
|
115
|
+
padding: 4px 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.json-row-nested-header {
|
|
143
119
|
display: flex;
|
|
144
|
-
|
|
120
|
+
align-items: center;
|
|
121
|
+
gap: 8px;
|
|
122
|
+
margin-bottom: 4px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.json-row-nested-header > .json-row-label {
|
|
126
|
+
flex-grow: 1;
|
|
127
|
+
font-weight: ${viraFormCssVars['vira-form-label-font-weight'].value};
|
|
128
|
+
word-break: break-word;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.json-type-tag {
|
|
132
|
+
font-weight: normal;
|
|
133
|
+
color: ${viraFormCssVars['vira-form-secondary-body-foreground'].value};
|
|
145
134
|
}
|
|
146
135
|
|
|
147
136
|
.json-value-with-switcher {
|
|
@@ -169,8 +158,10 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
169
158
|
.json-add-row {
|
|
170
159
|
display: flex;
|
|
171
160
|
align-items: center;
|
|
161
|
+
justify-content: flex-end;
|
|
172
162
|
gap: 6px;
|
|
173
163
|
flex-wrap: wrap;
|
|
164
|
+
padding: 8px 0;
|
|
174
165
|
}
|
|
175
166
|
|
|
176
167
|
.json-add-row ${ViraInput}, .json-add-row ${ViraSelect} {
|
|
@@ -190,6 +181,8 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
190
181
|
}
|
|
191
182
|
|
|
192
183
|
.json-empty-note {
|
|
184
|
+
display: block;
|
|
185
|
+
padding: 4px 0;
|
|
193
186
|
color: ${viraFormCssVars['vira-form-placeholder-color'].value};
|
|
194
187
|
font-style: italic;
|
|
195
188
|
font-size: ${viraFormCssVars['vira-form-small-text-size'].value};
|
|
@@ -392,8 +385,9 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
392
385
|
function renderPlusButton({ isAddDisabled, tooltip, onClick, }) {
|
|
393
386
|
return html `
|
|
394
387
|
<${ViraButton.assign({
|
|
395
|
-
icon:
|
|
396
|
-
color: ViraColorVariant.
|
|
388
|
+
icon: Plus16Icon,
|
|
389
|
+
color: ViraColorVariant.Positive,
|
|
390
|
+
buttonSize: ViraSize.Small,
|
|
397
391
|
isDisabled: isAddDisabled,
|
|
398
392
|
})}
|
|
399
393
|
title=${tooltip}
|
|
@@ -406,7 +400,7 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
406
400
|
></${ViraButton}>
|
|
407
401
|
`;
|
|
408
402
|
}
|
|
409
|
-
function renderObjectAddControl({ pathKey, allowedTypes, canAdd, onAdd, }) {
|
|
403
|
+
function renderObjectAddControl({ pathKey, allowedTypes, canAdd, disabledReason, onAdd, }) {
|
|
410
404
|
if (allowedTypes.length === 0) {
|
|
411
405
|
return nothing;
|
|
412
406
|
}
|
|
@@ -415,7 +409,7 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
415
409
|
const onlyType = assertWrap.isDefined(allowedTypes[0]);
|
|
416
410
|
return renderPlusButton({
|
|
417
411
|
isAddDisabled,
|
|
418
|
-
tooltip: `Add ${viraJsonTypeLabels[onlyType]}`,
|
|
412
|
+
tooltip: isAddDisabled ? disabledReason : `Add ${viraJsonTypeLabels[onlyType]}`,
|
|
419
413
|
onClick: () => onAdd(onlyType),
|
|
420
414
|
});
|
|
421
415
|
}
|
|
@@ -437,7 +431,9 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
437
431
|
></${ViraSelect}>
|
|
438
432
|
${renderPlusButton({
|
|
439
433
|
isAddDisabled,
|
|
440
|
-
tooltip:
|
|
434
|
+
tooltip: isAddDisabled
|
|
435
|
+
? disabledReason
|
|
436
|
+
: `Add ${viraJsonTypeLabels[selectedType]}`,
|
|
441
437
|
onClick: () => onAdd(selectedType),
|
|
442
438
|
})}
|
|
443
439
|
`;
|
|
@@ -497,8 +493,14 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
497
493
|
})}
|
|
498
494
|
`;
|
|
499
495
|
}
|
|
500
|
-
function
|
|
496
|
+
function getNestedTypeLabel(schema, value) {
|
|
497
|
+
const concreteType = getJsonType(value);
|
|
498
|
+
const narrowedSchema = pickBranchForType(schema, concreteType, resolveContext);
|
|
499
|
+
return (getSchemaTitle(narrowedSchema, resolveContext) || viraJsonTypeLabels[concreteType]);
|
|
500
|
+
}
|
|
501
|
+
function renderObjectGroup(path, value, schema) {
|
|
501
502
|
const pathKey = pathToKey(path);
|
|
503
|
+
const isRoot = path.length === 0;
|
|
502
504
|
const requiredKeys = new Set(getRequiredProperties(schema, resolveContext));
|
|
503
505
|
const definedProperties = getDefinedProperties(schema, resolveContext);
|
|
504
506
|
const definedKeys = new Set(Object.keys(definedProperties));
|
|
@@ -524,20 +526,34 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
524
526
|
}
|
|
525
527
|
}
|
|
526
528
|
: undefined;
|
|
529
|
+
if (isChildNested) {
|
|
530
|
+
return html `
|
|
531
|
+
<tr class="json-row-nested">
|
|
532
|
+
<td colspan="3">
|
|
533
|
+
<div class="json-row-nested-header">
|
|
534
|
+
<span class="json-row-label">
|
|
535
|
+
${key}${isRequired ? '*' : ''}
|
|
536
|
+
<span class="json-type-tag">
|
|
537
|
+
: ${getNestedTypeLabel(childSchema, childValue)}
|
|
538
|
+
</span>
|
|
539
|
+
</span>
|
|
540
|
+
${childOnDelete ? renderDeleteButton(childOnDelete) : nothing}
|
|
541
|
+
</div>
|
|
542
|
+
${renderValue(childPath, childValue, childSchema)}
|
|
543
|
+
</td>
|
|
544
|
+
</tr>
|
|
545
|
+
`;
|
|
546
|
+
}
|
|
527
547
|
return html `
|
|
528
|
-
<
|
|
529
|
-
class="json-row
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
? renderDeleteButton(childOnDelete)
|
|
538
|
-
: nothing}
|
|
539
|
-
</span>
|
|
540
|
-
</div>
|
|
548
|
+
<tr class="json-row-primitive">
|
|
549
|
+
<td class="json-row-label">${key}${isRequired ? '*' : ''}</td>
|
|
550
|
+
<td class="json-row-editor">
|
|
551
|
+
${renderValue(childPath, childValue, childSchema)}
|
|
552
|
+
</td>
|
|
553
|
+
<td class="json-row-delete">
|
|
554
|
+
${childOnDelete ? renderDeleteButton(childOnDelete) : nothing}
|
|
555
|
+
</td>
|
|
556
|
+
</tr>
|
|
541
557
|
`;
|
|
542
558
|
});
|
|
543
559
|
const missingDefinedKeys = [...definedKeys].filter((key) => !(key in value));
|
|
@@ -550,8 +566,9 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
550
566
|
return html `
|
|
551
567
|
<${ViraButton.assign({
|
|
552
568
|
text: `"${key}"`,
|
|
553
|
-
icon:
|
|
554
|
-
color: ViraColorVariant.
|
|
569
|
+
icon: Plus16Icon,
|
|
570
|
+
color: ViraColorVariant.Positive,
|
|
571
|
+
buttonSize: ViraSize.Small,
|
|
555
572
|
})}
|
|
556
573
|
${listen('click', () => {
|
|
557
574
|
emitReplaceAt([
|
|
@@ -568,21 +585,27 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
568
585
|
const additionalAllowedTypes = additional.allowed
|
|
569
586
|
? getAllowedJsonTypes(additional.schema, resolveContext)
|
|
570
587
|
: [];
|
|
588
|
+
const arbitraryAddDisabledReason = trimmedPendingKey
|
|
589
|
+
? `Field "${trimmedPendingKey}" already exists.`
|
|
590
|
+
: 'Enter a field name to add.';
|
|
571
591
|
const arbitraryAddRow = additional.allowed && !isDisabled
|
|
572
592
|
? html `
|
|
573
|
-
<
|
|
574
|
-
|
|
593
|
+
<tr>
|
|
594
|
+
<td colspan="3">
|
|
595
|
+
<div class="json-add-row">
|
|
596
|
+
<${ViraInput.assign({
|
|
575
597
|
value: pendingKey,
|
|
576
598
|
placeholder: 'new field name',
|
|
577
599
|
})}
|
|
578
|
-
|
|
600
|
+
${listen(ViraInput.events.valueChange, (event) => {
|
|
579
601
|
setPendingKey(pathKey, event.detail);
|
|
580
602
|
})}
|
|
581
|
-
|
|
582
|
-
|
|
603
|
+
></${ViraInput}>
|
|
604
|
+
${renderObjectAddControl({
|
|
583
605
|
pathKey,
|
|
584
606
|
allowedTypes: additionalAllowedTypes,
|
|
585
607
|
canAdd: canAddArbitraryField,
|
|
608
|
+
disabledReason: arbitraryAddDisabledReason,
|
|
586
609
|
onAdd: (type) => {
|
|
587
610
|
if (!canAddArbitraryField) {
|
|
588
611
|
return;
|
|
@@ -594,33 +617,41 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
594
617
|
clearPending(pathKey);
|
|
595
618
|
},
|
|
596
619
|
})}
|
|
597
|
-
|
|
620
|
+
</div>
|
|
621
|
+
</td>
|
|
622
|
+
</tr>
|
|
598
623
|
`
|
|
599
624
|
: nothing;
|
|
600
|
-
const title = getSchemaTitle(schema, resolveContext) || 'object';
|
|
601
625
|
return html `
|
|
602
|
-
<
|
|
603
|
-
<
|
|
604
|
-
|
|
605
|
-
${onDelete ? renderDeleteButton(onDelete) : nothing}
|
|
606
|
-
</div>
|
|
607
|
-
${rowTemplates.length === 0 && suggestedKeyButtons.length === 0
|
|
626
|
+
<table class="json-group ${isRoot ? '' : 'json-group-nested'}">
|
|
627
|
+
<tbody>
|
|
628
|
+
${rowTemplates.length === 0 && suggestedKeyButtons.length === 0
|
|
608
629
|
? html `
|
|
609
|
-
|
|
610
|
-
|
|
630
|
+
<tr>
|
|
631
|
+
<td colspan="3">
|
|
632
|
+
<span class="json-empty-note">(empty object)</span>
|
|
633
|
+
</td>
|
|
634
|
+
</tr>
|
|
635
|
+
`
|
|
611
636
|
: nothing}
|
|
612
|
-
|
|
613
|
-
|
|
637
|
+
${rowTemplates}
|
|
638
|
+
${suggestedKeyButtons.length > 0
|
|
614
639
|
? html `
|
|
615
|
-
|
|
616
|
-
|
|
640
|
+
<tr>
|
|
641
|
+
<td colspan="3">
|
|
642
|
+
<div class="json-add-row">${suggestedKeyButtons}</div>
|
|
643
|
+
</td>
|
|
644
|
+
</tr>
|
|
645
|
+
`
|
|
617
646
|
: nothing}
|
|
618
|
-
|
|
619
|
-
|
|
647
|
+
${arbitraryAddRow}
|
|
648
|
+
</tbody>
|
|
649
|
+
</table>
|
|
620
650
|
`;
|
|
621
651
|
}
|
|
622
|
-
function renderArrayGroup(path, value, schema
|
|
652
|
+
function renderArrayGroup(path, value, schema) {
|
|
623
653
|
const pathKey = pathToKey(path);
|
|
654
|
+
const isRoot = path.length === 0;
|
|
624
655
|
const newItemSchema = getNewItemSchema(schema, value.length, resolveContext);
|
|
625
656
|
const allowedItemTypes = getAllowedJsonTypes(newItemSchema, resolveContext);
|
|
626
657
|
const rowTemplates = value.map((item, index) => {
|
|
@@ -636,28 +667,43 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
636
667
|
: () => {
|
|
637
668
|
emitDeleteAt(childPath);
|
|
638
669
|
};
|
|
670
|
+
if (isChildNested) {
|
|
671
|
+
return html `
|
|
672
|
+
<tr class="json-row-nested">
|
|
673
|
+
<td colspan="3">
|
|
674
|
+
<div class="json-row-nested-header">
|
|
675
|
+
<span class="json-row-label">
|
|
676
|
+
[${index}]
|
|
677
|
+
<span class="json-type-tag">
|
|
678
|
+
: ${getNestedTypeLabel(childSchema, item)}
|
|
679
|
+
</span>
|
|
680
|
+
</span>
|
|
681
|
+
${childOnDelete ? renderDeleteButton(childOnDelete) : nothing}
|
|
682
|
+
</div>
|
|
683
|
+
${renderValue(childPath, item, childSchema)}
|
|
684
|
+
</td>
|
|
685
|
+
</tr>
|
|
686
|
+
`;
|
|
687
|
+
}
|
|
639
688
|
return html `
|
|
640
|
-
<
|
|
641
|
-
class="json-row
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
? renderDeleteButton(childOnDelete)
|
|
650
|
-
: nothing}
|
|
651
|
-
</span>
|
|
652
|
-
</div>
|
|
689
|
+
<tr class="json-row-primitive">
|
|
690
|
+
<td class="json-row-label">[${index}]</td>
|
|
691
|
+
<td class="json-row-editor">
|
|
692
|
+
${renderValue(childPath, item, childSchema)}
|
|
693
|
+
</td>
|
|
694
|
+
<td class="json-row-delete">
|
|
695
|
+
${childOnDelete ? renderDeleteButton(childOnDelete) : nothing}
|
|
696
|
+
</td>
|
|
697
|
+
</tr>
|
|
653
698
|
`;
|
|
654
699
|
});
|
|
655
|
-
const title = getSchemaTitle(schema, resolveContext) || 'array';
|
|
656
700
|
const addRow = isDisabled
|
|
657
701
|
? nothing
|
|
658
702
|
: html `
|
|
659
|
-
<
|
|
660
|
-
|
|
703
|
+
<tr>
|
|
704
|
+
<td colspan="3">
|
|
705
|
+
<div class="json-add-row">
|
|
706
|
+
${renderArrayAddControl({
|
|
661
707
|
pathKey,
|
|
662
708
|
allowedTypes: allowedItemTypes,
|
|
663
709
|
onAdd: (newValue) => {
|
|
@@ -667,32 +713,36 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
667
713
|
], newValue);
|
|
668
714
|
},
|
|
669
715
|
})}
|
|
670
|
-
|
|
716
|
+
</div>
|
|
717
|
+
</td>
|
|
718
|
+
</tr>
|
|
671
719
|
`;
|
|
672
720
|
return html `
|
|
673
|
-
<
|
|
674
|
-
<
|
|
675
|
-
|
|
676
|
-
${onDelete ? renderDeleteButton(onDelete) : nothing}
|
|
677
|
-
</div>
|
|
678
|
-
${rowTemplates.length === 0
|
|
721
|
+
<table class="json-group ${isRoot ? '' : 'json-group-nested'}">
|
|
722
|
+
<tbody>
|
|
723
|
+
${rowTemplates.length === 0
|
|
679
724
|
? html `
|
|
680
|
-
|
|
681
|
-
|
|
725
|
+
<tr>
|
|
726
|
+
<td colspan="3">
|
|
727
|
+
<span class="json-empty-note">(empty array)</span>
|
|
728
|
+
</td>
|
|
729
|
+
</tr>
|
|
730
|
+
`
|
|
682
731
|
: nothing}
|
|
683
|
-
|
|
684
|
-
|
|
732
|
+
${rowTemplates} ${addRow}
|
|
733
|
+
</tbody>
|
|
734
|
+
</table>
|
|
685
735
|
`;
|
|
686
736
|
}
|
|
687
|
-
function renderValue(path, value, schema
|
|
737
|
+
function renderValue(path, value, schema) {
|
|
688
738
|
const concreteType = getJsonType(value);
|
|
689
739
|
const allowedTypes = getAllowedJsonTypes(schema, resolveContext);
|
|
690
740
|
const narrowedSchema = pickBranchForType(schema, concreteType, resolveContext);
|
|
691
741
|
if (check.isArray(value)) {
|
|
692
|
-
return renderArrayGroup(path, value, narrowedSchema
|
|
742
|
+
return renderArrayGroup(path, value, narrowedSchema);
|
|
693
743
|
}
|
|
694
744
|
else if (check.isObject(value)) {
|
|
695
|
-
return renderObjectGroup(path, value, narrowedSchema
|
|
745
|
+
return renderObjectGroup(path, value, narrowedSchema);
|
|
696
746
|
}
|
|
697
747
|
const editor = renderPrimitive(path, value, narrowedSchema);
|
|
698
748
|
const showSwitcher = !isDisabled &&
|
|
@@ -752,14 +802,15 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
752
802
|
const rawText = state.rawDraft ?? JSON.stringify(inputs.value, undefined, 4);
|
|
753
803
|
return html `
|
|
754
804
|
${toolbarTemplate}
|
|
755
|
-
|
|
805
|
+
<${ViraTextArea.assign({
|
|
806
|
+
value: rawText,
|
|
807
|
+
disabled: isDisabled,
|
|
808
|
+
disableBrowserHelps: true,
|
|
809
|
+
rows: 12,
|
|
810
|
+
})}
|
|
756
811
|
class="json-raw-textarea"
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
.value=${rawText}
|
|
760
|
-
${listen('input', (event) => {
|
|
761
|
-
const textarea = extractEventTarget(event, HTMLTextAreaElement);
|
|
762
|
-
const text = textarea.value;
|
|
812
|
+
${listen(ViraTextArea.events.valueChange, (event) => {
|
|
813
|
+
const text = event.detail;
|
|
763
814
|
const parsed = wrapInTry(() => JSON.parse(text));
|
|
764
815
|
if (parsed instanceof Error) {
|
|
765
816
|
updateState({
|
|
@@ -775,7 +826,7 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
775
826
|
emitRoot(parsed);
|
|
776
827
|
}
|
|
777
828
|
})}
|
|
778
|
-
|
|
829
|
+
></${ViraTextArea}>
|
|
779
830
|
${state.rawError
|
|
780
831
|
? html `
|
|
781
832
|
<${ViraError}>${state.rawError}</${ViraError}>
|
|
@@ -800,7 +851,7 @@ export const ViraJsonForm = defineViraElement()({
|
|
|
800
851
|
`;
|
|
801
852
|
}
|
|
802
853
|
return html `
|
|
803
|
-
${toolbarTemplate} ${renderValue([], inputs.value, inputs.schema
|
|
854
|
+
${toolbarTemplate} ${renderValue([], inputs.value, inputs.schema)}
|
|
804
855
|
`;
|
|
805
856
|
},
|
|
806
857
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { html } from 'element-vir';
|
|
2
|
-
import { viraIconCssVars } from '
|
|
3
|
-
import { defineIcon } from '
|
|
2
|
+
import { viraIconCssVars } from '../../icon-css-vars.js';
|
|
3
|
+
import { defineIcon } from '../../icon-svg.js';
|
|
4
4
|
/**
|
|
5
5
|
* A plus icon.
|
|
6
6
|
*
|
|
7
7
|
* @category Icon
|
|
8
8
|
* @category SVG
|
|
9
|
-
* @see https://electrovir.github.io/vira/book/icons/
|
|
9
|
+
* @see https://electrovir.github.io/vira/book/icons/plus16icon
|
|
10
10
|
*/
|
|
11
|
-
export const
|
|
12
|
-
name: '
|
|
11
|
+
export const Plus16Icon = defineIcon({
|
|
12
|
+
name: 'Plus16Icon',
|
|
13
13
|
svgTemplate: html `
|
|
14
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
14
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
|
15
15
|
<path
|
|
16
|
-
d="
|
|
16
|
+
d="M8 3v10M3 8h10"
|
|
17
17
|
fill="none"
|
|
18
18
|
stroke=${viraIconCssVars['vira-icon-stroke-color'].value}
|
|
19
19
|
stroke-width=${viraIconCssVars['vira-icon-stroke-width'].value}
|
package/dist/icons/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './icon-svgs/16/chevron-down-16.icon.js';
|
|
|
8
8
|
export * from './icon-svgs/16/chevron-up-16.icon.js';
|
|
9
9
|
export * from './icon-svgs/16/dash-16.icon.js';
|
|
10
10
|
export * from './icon-svgs/16/element-16.icon.js';
|
|
11
|
+
export * from './icon-svgs/16/plus-16.icon.js';
|
|
11
12
|
export * from './icon-svgs/16/upload-16.icon.js';
|
|
12
13
|
export * from './icon-svgs/16/x-16.icon.js';
|
|
13
14
|
export * from './icon-svgs/24/arrow-down-24.icon.js';
|
|
@@ -100,6 +101,7 @@ export declare const allIconsByName: {
|
|
|
100
101
|
readonly Moon24Icon: import("./icon-svg.js").ViraIconSvg;
|
|
101
102
|
readonly Options24Icon: import("./icon-svg.js").ViraIconSvg;
|
|
102
103
|
readonly Pencil24Icon: import("./icon-svg.js").ViraIconSvg;
|
|
104
|
+
readonly Plus16Icon: import("./icon-svg.js").ViraIconSvg;
|
|
103
105
|
readonly Plus24Icon: import("./icon-svg.js").ViraIconSvg;
|
|
104
106
|
readonly Printer24Icon: import("./icon-svg.js").ViraIconSvg;
|
|
105
107
|
readonly Shield24Icon: import("./icon-svg.js").ViraIconSvg;
|
|
@@ -189,6 +191,7 @@ export declare const all16IconsByName: {
|
|
|
189
191
|
readonly ChevronUp16Icon: import("./icon-svg.js").ViraIconSvg;
|
|
190
192
|
readonly Dash16Icon: import("./icon-svg.js").ViraIconSvg;
|
|
191
193
|
readonly Element16Icon: import("./icon-svg.js").ViraIconSvg;
|
|
194
|
+
readonly Plus16Icon: import("./icon-svg.js").ViraIconSvg;
|
|
192
195
|
readonly Upload16Icon: import("./icon-svg.js").ViraIconSvg;
|
|
193
196
|
readonly X16Icon: import("./icon-svg.js").ViraIconSvg;
|
|
194
197
|
};
|
package/dist/icons/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { ChevronDown16Icon } from './icon-svgs/16/chevron-down-16.icon.js';
|
|
|
3
3
|
import { ChevronUp16Icon } from './icon-svgs/16/chevron-up-16.icon.js';
|
|
4
4
|
import { Dash16Icon } from './icon-svgs/16/dash-16.icon.js';
|
|
5
5
|
import { Element16Icon } from './icon-svgs/16/element-16.icon.js';
|
|
6
|
+
import { Plus16Icon } from './icon-svgs/16/plus-16.icon.js';
|
|
6
7
|
import { Upload16Icon } from './icon-svgs/16/upload-16.icon.js';
|
|
7
8
|
import { X16Icon } from './icon-svgs/16/x-16.icon.js';
|
|
8
9
|
import { ArrowDown24Icon } from './icon-svgs/24/arrow-down-24.icon.js';
|
|
@@ -64,6 +65,7 @@ export * from './icon-svgs/16/chevron-down-16.icon.js';
|
|
|
64
65
|
export * from './icon-svgs/16/chevron-up-16.icon.js';
|
|
65
66
|
export * from './icon-svgs/16/dash-16.icon.js';
|
|
66
67
|
export * from './icon-svgs/16/element-16.icon.js';
|
|
68
|
+
export * from './icon-svgs/16/plus-16.icon.js';
|
|
67
69
|
export * from './icon-svgs/16/upload-16.icon.js';
|
|
68
70
|
export * from './icon-svgs/16/x-16.icon.js';
|
|
69
71
|
export * from './icon-svgs/24/arrow-down-24.icon.js';
|
|
@@ -156,6 +158,7 @@ export const allIconsByName = {
|
|
|
156
158
|
Moon24Icon,
|
|
157
159
|
Options24Icon,
|
|
158
160
|
Pencil24Icon,
|
|
161
|
+
Plus16Icon,
|
|
159
162
|
Plus24Icon,
|
|
160
163
|
Printer24Icon,
|
|
161
164
|
Shield24Icon,
|
|
@@ -245,6 +248,7 @@ export const all16IconsByName = {
|
|
|
245
248
|
ChevronUp16Icon,
|
|
246
249
|
Dash16Icon,
|
|
247
250
|
Element16Icon,
|
|
251
|
+
Plus16Icon,
|
|
248
252
|
Upload16Icon,
|
|
249
253
|
X16Icon,
|
|
250
254
|
};
|
package/package.json
CHANGED