vira 32.0.0-beta.0 → 32.0.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/dist/elements/color/vira-all-color-space-sliders.element.d.ts +11 -0
- package/dist/elements/color/vira-all-color-space-sliders.element.js +55 -0
- package/dist/elements/color/vira-all-spaces-color-picker.element.d.ts +15 -0
- package/dist/elements/color/vira-all-spaces-color-picker.element.js +73 -0
- package/dist/elements/color/vira-color-details.element.d.ts +14 -0
- package/{src/elements/color/vira-color-details.element.ts → dist/elements/color/vira-color-details.element.js} +43 -59
- package/dist/elements/color/vira-color-format-sliders.element.d.ts +14 -0
- package/dist/elements/color/vira-color-format-sliders.element.js +60 -0
- package/dist/elements/color/vira-color-pair-contrast-summary.element.d.ts +9 -0
- package/{src/elements/color/vira-color-pair-contrast-summary.element.ts → dist/elements/color/vira-color-pair-contrast-summary.element.js} +68 -100
- package/dist/elements/color/vira-color-pair.element.d.ts +17 -0
- package/{src/elements/color/vira-color-pair.element.ts → dist/elements/color/vira-color-pair.element.js} +50 -71
- package/dist/elements/color/vira-color-picker.element.d.ts +20 -0
- package/{src/elements/color/vira-color-picker.element.ts → dist/elements/color/vira-color-picker.element.js} +92 -117
- package/dist/elements/color/vira-color-slider.element.d.ts +14 -0
- package/dist/elements/color/vira-color-slider.element.js +124 -0
- package/dist/elements/color/vira-color-swatch.element.d.ts +20 -0
- package/{src/elements/color/vira-color-swatch.element.ts → dist/elements/color/vira-color-swatch.element.js} +6 -16
- package/dist/elements/color/vira-contrast-indicator.element.d.ts +10 -0
- package/{src/elements/color/vira-contrast-indicator.element.ts → dist/elements/color/vira-contrast-indicator.element.js} +13 -28
- package/dist/elements/index.js +39 -0
- package/dist/elements/pop-up/vira-menu-item.element.d.ts +38 -0
- package/{src/elements/pop-up/vira-menu-item.element.ts → dist/elements/pop-up/vira-menu-item.element.js} +80 -117
- package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +45 -0
- package/dist/elements/pop-up/vira-menu-trigger.element.js +100 -0
- package/dist/elements/pop-up/vira-menu.element.d.ts +36 -0
- package/{src/elements/pop-up/vira-menu.element.ts → dist/elements/pop-up/vira-menu.element.js} +28 -31
- package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +109 -0
- package/dist/elements/pop-up/vira-pop-up-trigger.element.js +408 -0
- package/dist/elements/vira-absolute-time.element.d.ts +35 -0
- package/dist/elements/vira-absolute-time.element.js +43 -0
- package/dist/elements/vira-bold-text.element.d.ts +9 -0
- package/{src/elements/vira-bold-text.element.ts → dist/elements/vira-bold-text.element.js} +11 -10
- package/dist/elements/vira-button.element.d.ts +44 -0
- package/{src/elements/vira-button.element.ts → dist/elements/vira-button.element.js} +107 -255
- package/dist/elements/vira-card.element.d.ts +18 -0
- package/{src/elements/vira-card.element.ts → dist/elements/vira-card.element.js} +19 -18
- package/dist/elements/vira-checkbox.element.d.ts +44 -0
- package/{src/elements/vira-checkbox.element.ts → dist/elements/vira-checkbox.element.js} +48 -95
- package/dist/elements/vira-collapsible-card.element.d.ts +36 -0
- package/{src/elements/vira-collapsible-card.element.ts → dist/elements/vira-collapsible-card.element.js} +44 -71
- package/dist/elements/vira-collapsible-wrapper.element.d.ts +30 -0
- package/{src/elements/vira-collapsible-wrapper.element.ts → dist/elements/vira-collapsible-wrapper.element.js} +47 -59
- package/dist/elements/vira-date-input.element.d.ts +47 -0
- package/dist/elements/vira-date-input.element.js +142 -0
- package/dist/elements/vira-drawer.element.d.ts +24 -0
- package/{src/elements/vira-drawer.element.ts → dist/elements/vira-drawer.element.js} +98 -125
- package/dist/elements/vira-dropdown.element.d.ts +43 -0
- package/dist/elements/vira-dropdown.element.js +247 -0
- package/dist/elements/vira-error.element.d.ts +7 -0
- package/{src/elements/vira-error.element.ts → dist/elements/vira-error.element.js} +7 -8
- package/dist/elements/vira-form.element.d.ts +56 -0
- package/dist/elements/vira-form.element.js +376 -0
- package/dist/elements/vira-icon.element.d.ts +13 -0
- package/{src/elements/vira-icon.element.ts → dist/elements/vira-icon.element.js} +12 -16
- package/dist/elements/vira-image.element.d.ts +45 -0
- package/{src/elements/vira-image.element.ts → dist/elements/vira-image.element.js} +50 -70
- package/dist/elements/vira-input.element.d.ts +64 -0
- package/{src/elements/vira-input.element.ts → dist/elements/vira-input.element.js} +112 -167
- package/dist/elements/vira-json-form.element.d.ts +35 -0
- package/{src/elements/vira-json-form.element.ts → dist/elements/vira-json-form.element.js} +356 -522
- package/dist/elements/vira-link.element.d.ts +78 -0
- package/{src/elements/vira-link.element.ts → dist/elements/vira-link.element.js} +24 -83
- package/dist/elements/vira-modal.element.d.ts +40 -0
- package/{src/elements/vira-modal.element.ts → dist/elements/vira-modal.element.js} +68 -104
- package/dist/elements/vira-progress.element.d.ts +18 -0
- package/{src/elements/vira-progress.element.ts → dist/elements/vira-progress.element.js} +12 -25
- package/dist/elements/vira-relative-time.element.d.ts +42 -0
- package/dist/elements/vira-relative-time.element.js +96 -0
- package/dist/elements/vira-select.element.d.ts +44 -0
- package/{src/elements/vira-select.element.ts → dist/elements/vira-select.element.js} +89 -138
- package/dist/elements/vira-tabs.element.d.ts +124 -0
- package/{src/elements/vira-tabs.element.ts → dist/elements/vira-tabs.element.js} +242 -446
- package/dist/elements/vira-tag.element.d.ts +40 -0
- package/{src/elements/vira-tag.element.ts → dist/elements/vira-tag.element.js} +152 -266
- package/dist/elements/vira-text-area.element.d.ts +48 -0
- package/{src/elements/vira-text-area.element.ts → dist/elements/vira-text-area.element.js} +52 -70
- package/dist/elements/vira-theme-switcher.element.d.ts +17 -0
- package/{src/elements/vira-theme-switcher.element.ts → dist/elements/vira-theme-switcher.element.js} +34 -49
- package/dist/icons/colored-icon.d.ts +11 -0
- package/{src/icons/colored-icon.ts → dist/icons/colored-icon.js} +17 -24
- package/dist/icons/icon-css-vars.d.ts +14 -0
- package/{src/icons/icon-css-vars.ts → dist/icons/icon-css-vars.js} +1 -2
- package/{src/icons/icon-svg.ts → dist/icons/icon-svg.d.ts} +3 -15
- package/dist/icons/icon-svg.js +12 -0
- package/dist/icons/icon-svgs/16/check-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/check-16.icon.ts → dist/icons/icon-svgs/16/check-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/16/chevron-down-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/chevron-down-16.icon.ts → dist/icons/icon-svgs/16/chevron-down-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/16/chevron-up-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/chevron-up-16.icon.ts → dist/icons/icon-svgs/16/chevron-up-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/16/dash-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/dash-16.icon.ts → dist/icons/icon-svgs/16/dash-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/16/element-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/element-16.icon.ts → dist/icons/icon-svgs/16/element-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/16/plus-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/plus-16.icon.ts → dist/icons/icon-svgs/16/plus-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/16/upload-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/upload-16.icon.ts → dist/icons/icon-svgs/16/upload-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/16/x-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/16/x-16.icon.ts → dist/icons/icon-svgs/16/x-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/arrow-down-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/arrow-down-24.icon.ts → dist/icons/icon-svgs/24/arrow-down-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/arrow-left-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/arrow-left-24.icon.ts → dist/icons/icon-svgs/24/arrow-left-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/arrow-right-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/arrow-right-24.icon.ts → dist/icons/icon-svgs/24/arrow-right-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/arrow-up-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/arrow-up-24.icon.ts → dist/icons/icon-svgs/24/arrow-up-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/auto-theme-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/auto-theme-24.icon.ts → dist/icons/icon-svgs/24/auto-theme-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/bell-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/bell-24.icon.ts → dist/icons/icon-svgs/24/bell-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/chat-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/chat-24.icon.ts → dist/icons/icon-svgs/24/chat-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/check-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/check-24.icon.ts → dist/icons/icon-svgs/24/check-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/chevron-down-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/chevron-down-24.icon.ts → dist/icons/icon-svgs/24/chevron-down-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/chevron-up-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/chevron-up-24.icon.ts → dist/icons/icon-svgs/24/chevron-up-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/close-x-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/close-x-24.icon.ts → dist/icons/icon-svgs/24/close-x-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/commit-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/commit-24.icon.ts → dist/icons/icon-svgs/24/commit-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/copy-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/copy-24.icon.ts → dist/icons/icon-svgs/24/copy-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/document-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/document-24.icon.ts → dist/icons/icon-svgs/24/document-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/document-search-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/document-search-24.icon.ts → dist/icons/icon-svgs/24/document-search-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/double-chevron-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/double-chevron-24.icon.ts → dist/icons/icon-svgs/24/double-chevron-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/element-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/element-24.icon.ts → dist/icons/icon-svgs/24/element-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/external-link-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/external-link-24.icon.ts → dist/icons/icon-svgs/24/external-link-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/eye-closed-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/eye-closed-24.icon.ts → dist/icons/icon-svgs/24/eye-closed-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/eye-open-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/eye-open-24.icon.ts → dist/icons/icon-svgs/24/eye-open-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/filter-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/filter-24.icon.ts → dist/icons/icon-svgs/24/filter-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/globe-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/globe-24.icon.ts → dist/icons/icon-svgs/24/globe-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/link-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/link-24.icon.ts → dist/icons/icon-svgs/24/link-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/loader-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/loader-24.icon.ts → dist/icons/icon-svgs/24/loader-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/loader-animated-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/loader-animated-24.icon.ts → dist/icons/icon-svgs/24/loader-animated-24.icon.js} +6 -8
- package/dist/icons/icon-svgs/24/lock-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/lock-24.icon.ts → dist/icons/icon-svgs/24/lock-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/magnifying-glass-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/magnifying-glass-24.icon.ts → dist/icons/icon-svgs/24/magnifying-glass-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/moon-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/moon-24.icon.ts → dist/icons/icon-svgs/24/moon-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/options-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/options-24.icon.ts → dist/icons/icon-svgs/24/options-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/pencil-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/pencil-24.icon.ts → dist/icons/icon-svgs/24/pencil-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/plus-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/plus-24.icon.ts → dist/icons/icon-svgs/24/plus-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/printer-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/printer-24.icon.ts → dist/icons/icon-svgs/24/printer-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/shield-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/shield-24.icon.ts → dist/icons/icon-svgs/24/shield-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/sort-ascending-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/sort-ascending-24.icon.ts → dist/icons/icon-svgs/24/sort-ascending-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/sort-descending-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/sort-descending-24.icon.ts → dist/icons/icon-svgs/24/sort-descending-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/sparkle-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/sparkle-24.icon.ts → dist/icons/icon-svgs/24/sparkle-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/speaker-loud-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/speaker-loud-24.icon.ts → dist/icons/icon-svgs/24/speaker-loud-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/speaker-medium-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/speaker-medium-24.icon.ts → dist/icons/icon-svgs/24/speaker-medium-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/speaker-muted-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/speaker-muted-24.icon.ts → dist/icons/icon-svgs/24/speaker-muted-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/speaker-quiet-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/speaker-quiet-24.icon.ts → dist/icons/icon-svgs/24/speaker-quiet-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/star-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/star-24.icon.ts → dist/icons/icon-svgs/24/star-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/status-failure-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/status-failure-24.icon.ts → dist/icons/icon-svgs/24/status-failure-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/status-in-progress-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/status-in-progress-24.icon.ts → dist/icons/icon-svgs/24/status-in-progress-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/status-success-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/status-success-24.icon.ts → dist/icons/icon-svgs/24/status-success-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/status-unknown-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/status-unknown-24.icon.ts → dist/icons/icon-svgs/24/status-unknown-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/status-warning-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/status-warning-24.icon.ts → dist/icons/icon-svgs/24/status-warning-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/sun-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/sun-24.icon.ts → dist/icons/icon-svgs/24/sun-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/upload-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/upload-24.icon.ts → dist/icons/icon-svgs/24/upload-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/24/x-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/24/x-24.icon.ts → dist/icons/icon-svgs/24/x-24.icon.js} +4 -5
- package/dist/icons/index.d.ts +197 -0
- package/{src/icons/index.ts → dist/icons/index.js} +60 -65
- package/dist/icons/lucide-icons.d.ts +15 -0
- package/dist/icons/lucide-icons.js +79 -0
- package/dist/icons/sized-icon.d.ts +8 -0
- package/{src/icons/sized-icon.ts → dist/icons/sized-icon.js} +1 -3
- package/dist/index.js +4 -0
- package/dist/styles/disabled.d.ts +6 -0
- package/{src/styles/disabled.ts → dist/styles/disabled.js} +2 -3
- package/dist/styles/durations.d.ts +22 -0
- package/{src/styles/durations.ts → dist/styles/durations.js} +1 -2
- package/dist/styles/focus.d.ts +26 -0
- package/{src/styles/focus.ts → dist/styles/focus.js} +12 -40
- package/dist/styles/font.d.ts +12 -0
- package/{src/styles/font.ts → dist/styles/font.js} +1 -3
- package/dist/styles/form-styles.d.ts +46 -0
- package/dist/styles/form-styles.js +53 -0
- package/dist/styles/form-variants.d.ts +117 -0
- package/{src/styles/form-variants.ts → dist/styles/form-variants.js} +34 -42
- package/{src/styles/index.ts → dist/styles/index.d.ts} +0 -1
- package/dist/styles/index.js +14 -0
- package/dist/styles/native-styles.d.ts +13 -0
- package/{src/styles/native-styles.ts → dist/styles/native-styles.js} +3 -5
- package/dist/styles/scrollbar.d.ts +6 -0
- package/{src/styles/scrollbar.ts → dist/styles/scrollbar.js} +3 -4
- package/dist/styles/shadows.d.ts +19 -0
- package/{src/styles/shadows.ts → dist/styles/shadows.js} +5 -7
- package/dist/styles/user-select.d.ts +6 -0
- package/{src/styles/user-select.ts → dist/styles/user-select.js} +2 -3
- package/dist/styles/vira-color-palette.d.ts +178 -0
- package/{src/styles/vira-color-palette.ts → dist/styles/vira-color-palette.js} +1 -3
- package/dist/styles/vira-color-theme-object.d.ts +65 -0
- package/dist/styles/vira-color-theme-object.js +65 -0
- package/dist/styles/vira-color-theme.d.ts +2785 -0
- package/{src/styles/vira-color-theme.ts → dist/styles/vira-color-theme.js} +1222 -1227
- package/dist/util/color-local-storage.client.d.ts +4 -0
- package/dist/util/color-local-storage.client.js +6 -0
- package/dist/util/define-table.d.ts +115 -0
- package/dist/util/define-table.js +115 -0
- package/dist/util/define-vira-element.d.ts +18 -0
- package/dist/util/define-vira-element.js +19 -0
- package/dist/util/dynamic-element.d.ts +62 -0
- package/dist/util/dynamic-element.js +61 -0
- package/dist/util/index.js +11 -0
- package/dist/util/overflow-observer.d.ts +25 -0
- package/{src/util/overflow-observer.ts → dist/util/overflow-observer.js} +1 -30
- package/dist/util/pop-up-helpers.d.ts +59 -0
- package/dist/util/pop-up-helpers.js +66 -0
- package/dist/util/pop-up-manager.d.ts +200 -0
- package/dist/util/pop-up-manager.js +258 -0
- package/dist/util/shared-text-input-logic.d.ts +69 -0
- package/dist/util/shared-text-input-logic.js +114 -0
- package/dist/util/vira-form-fields.d.ts +145 -0
- package/dist/util/vira-form-fields.js +66 -0
- package/dist/util/vira-json-schema.d.ts +206 -0
- package/{src/util/vira-json-schema.ts → dist/util/vira-json-schema.js} +155 -298
- package/{src/util/vira-select-option.ts → dist/util/vira-select-option.d.ts} +2 -9
- package/dist/util/vira-select-option.js +8 -0
- package/dist/util/vira-theme-client.d.ts +83 -0
- package/dist/util/vira-theme-client.js +93 -0
- package/package.json +13 -13
- package/src/elements/color/vira-all-color-space-sliders.element.ts +0 -66
- package/src/elements/color/vira-all-spaces-color-picker.element.ts +0 -85
- package/src/elements/color/vira-color-format-sliders.element.ts +0 -78
- package/src/elements/color/vira-color-slider.element.ts +0 -169
- package/src/elements/pop-up/vira-menu-trigger.element.ts +0 -135
- package/src/elements/pop-up/vira-pop-up-trigger.element.ts +0 -539
- package/src/elements/vira-absolute-time.element.ts +0 -81
- package/src/elements/vira-date-input.element.ts +0 -185
- package/src/elements/vira-dropdown.element.ts +0 -310
- package/src/elements/vira-form.element.ts +0 -466
- package/src/elements/vira-relative-time.element.ts +0 -135
- package/src/icons/icon-color.test-helper.ts +0 -9
- package/src/icons/lucide-icons.ts +0 -120
- package/src/styles/form-styles.ts +0 -86
- package/src/styles/vira-color-palette.json +0 -170
- package/src/styles/vira-color-theme-object.ts +0 -170
- package/src/util/color-local-storage.client.ts +0 -7
- package/src/util/define-table.ts +0 -286
- package/src/util/define-vira-element.ts +0 -29
- package/src/util/dynamic-element.ts +0 -128
- package/src/util/pop-up-helpers.ts +0 -133
- package/src/util/pop-up-manager.ts +0 -434
- package/src/util/shared-text-input-logic.ts +0 -192
- package/src/util/vira-form-fields.ts +0 -195
- package/src/util/vira-theme-client.ts +0 -140
- /package/{src/elements/index.ts → dist/elements/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/util/index.ts → dist/util/index.d.ts} +0 -0
|
@@ -1,93 +1,53 @@
|
|
|
1
|
-
import {assertWrap, check} from '@augment-vir/assert';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from '
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
allowsFreeformString,
|
|
17
|
-
createDefaultForJsonType,
|
|
18
|
-
createResolveContext,
|
|
19
|
-
deleteValueAtPath,
|
|
20
|
-
getAdditionalPropertiesSchema,
|
|
21
|
-
getAllowedJsonTypes,
|
|
22
|
-
getDefinedProperties,
|
|
23
|
-
getItemSchema,
|
|
24
|
-
getJsonType,
|
|
25
|
-
getNewItemSchema,
|
|
26
|
-
getPropertySchema,
|
|
27
|
-
getRequiredProperties,
|
|
28
|
-
getSchemaEnumValues,
|
|
29
|
-
getSchemaTitle,
|
|
30
|
-
getStringEnumValues,
|
|
31
|
-
pathToKey,
|
|
32
|
-
pickBranchForType,
|
|
33
|
-
setValueAtPath,
|
|
34
|
-
validateAgainstSchema,
|
|
35
|
-
ViraJsonType,
|
|
36
|
-
viraJsonTypeLabels,
|
|
37
|
-
type SchemaResolveContext,
|
|
38
|
-
type ViraJsonPath,
|
|
39
|
-
type ViraJsonSchema,
|
|
40
|
-
} from '../util/vira-json-schema.js';
|
|
41
|
-
import {type ViraSelectOption} from '../util/vira-select-option.js';
|
|
42
|
-
import {ViraButton} from './vira-button.element.js';
|
|
43
|
-
import {ViraCheckbox} from './vira-checkbox.element.js';
|
|
44
|
-
import {ViraError} from './vira-error.element.js';
|
|
45
|
-
import {ViraInput, ViraInputType} from './vira-input.element.js';
|
|
46
|
-
import {ViraSelect} from './vira-select.element.js';
|
|
47
|
-
import {ViraTextArea} from './vira-text-area.element.js';
|
|
48
|
-
|
|
1
|
+
import { assertWrap, check } from '@augment-vir/assert';
|
|
2
|
+
import { omitObjectKeys, wrapInTry, } from '@augment-vir/common';
|
|
3
|
+
import { css, defineElementEvent, html, listen, nothing } from 'element-vir';
|
|
4
|
+
import { Plus16Icon, X16Icon } from '../icons/index.js';
|
|
5
|
+
import { viraFontCssVars } from '../styles/font.js';
|
|
6
|
+
import { viraFormCssVars } from '../styles/form-styles.js';
|
|
7
|
+
import { ViraColorVariant, ViraEmphasis, ViraSize } from '../styles/form-variants.js';
|
|
8
|
+
import { defineViraElement } from '../util/define-vira-element.js';
|
|
9
|
+
import { allowsFreeformString, createDefaultForJsonType, createResolveContext, deleteValueAtPath, getAdditionalPropertiesSchema, getAllowedJsonTypes, getDefinedProperties, getItemSchema, getJsonType, getNewItemSchema, getPropertySchema, getRequiredProperties, getSchemaEnumValues, getSchemaTitle, getStringEnumValues, pathToKey, pickBranchForType, setValueAtPath, validateAgainstSchema, ViraJsonType, viraJsonTypeLabels, } from '../util/vira-json-schema.js';
|
|
10
|
+
import { ViraButton } from './vira-button.element.js';
|
|
11
|
+
import { ViraCheckbox } from './vira-checkbox.element.js';
|
|
12
|
+
import { ViraError } from './vira-error.element.js';
|
|
13
|
+
import { ViraInput, ViraInputType } from './vira-input.element.js';
|
|
14
|
+
import { ViraSelect } from './vira-select.element.js';
|
|
15
|
+
import { ViraTextArea } from './vira-text-area.element.js';
|
|
49
16
|
/**
|
|
50
17
|
* Editing mode for a string field that offers both a fixed set of enum options and free-form text.
|
|
51
18
|
*
|
|
52
19
|
* @category Internal
|
|
53
20
|
*/
|
|
54
|
-
export
|
|
21
|
+
export var ViraJsonStringMode;
|
|
22
|
+
(function (ViraJsonStringMode) {
|
|
55
23
|
/** Pick from the schema's enum options via a dropdown. */
|
|
56
|
-
Options =
|
|
24
|
+
ViraJsonStringMode["Options"] = "options";
|
|
57
25
|
/** Enter an arbitrary string via a text input. */
|
|
58
|
-
Custom =
|
|
59
|
-
}
|
|
60
|
-
|
|
26
|
+
ViraJsonStringMode["Custom"] = "custom";
|
|
27
|
+
})(ViraJsonStringMode || (ViraJsonStringMode = {}));
|
|
61
28
|
/**
|
|
62
29
|
* An editor for arbitrary JSON values, optionally constrained by a standard JSON Schema
|
|
63
30
|
* ({@link ViraJsonSchema}).
|
|
64
31
|
*
|
|
65
32
|
* @category Elements
|
|
66
33
|
*/
|
|
67
|
-
export const ViraJsonForm = defineViraElement
|
|
68
|
-
{
|
|
69
|
-
value: JsonValue;
|
|
70
|
-
} & PartialWithUndefined<{
|
|
71
|
-
schema: Readonly<ViraJsonSchema>;
|
|
72
|
-
isDisabled: boolean;
|
|
73
|
-
}>
|
|
74
|
-
>()({
|
|
34
|
+
export const ViraJsonForm = defineViraElement()({
|
|
75
35
|
tagName: 'vira-json-form',
|
|
76
36
|
events: {
|
|
77
|
-
valueChange: defineElementEvent
|
|
37
|
+
valueChange: defineElementEvent(),
|
|
78
38
|
},
|
|
79
39
|
state() {
|
|
80
40
|
return {
|
|
81
|
-
pendingKeys: {}
|
|
82
|
-
pendingTypes: {}
|
|
83
|
-
pendingArrayValues: {}
|
|
84
|
-
stringModes: {}
|
|
41
|
+
pendingKeys: {},
|
|
42
|
+
pendingTypes: {},
|
|
43
|
+
pendingArrayValues: {},
|
|
44
|
+
stringModes: {},
|
|
85
45
|
showRaw: false,
|
|
86
|
-
rawDraft: undefined
|
|
87
|
-
rawError: undefined
|
|
46
|
+
rawDraft: undefined,
|
|
47
|
+
rawError: undefined,
|
|
88
48
|
};
|
|
89
49
|
},
|
|
90
|
-
styles: css`
|
|
50
|
+
styles: css `
|
|
91
51
|
:host {
|
|
92
52
|
display: flex;
|
|
93
53
|
flex-direction: column;
|
|
@@ -241,50 +201,35 @@ export const ViraJsonForm = defineViraElement<
|
|
|
241
201
|
font-size: ${viraFormCssVars['vira-form-small-text-size'].value};
|
|
242
202
|
}
|
|
243
203
|
`,
|
|
244
|
-
render({inputs, state, dispatch, events, updateState, host}) {
|
|
204
|
+
render({ inputs, state, dispatch, events, updateState, host }) {
|
|
245
205
|
const isDisabled = !!inputs.isDisabled;
|
|
246
|
-
const resolveContext
|
|
247
|
-
|
|
248
|
-
function jsonPrimitiveToString(
|
|
249
|
-
entry: string | number | boolean | null | undefined,
|
|
250
|
-
): string {
|
|
206
|
+
const resolveContext = createResolveContext(inputs.schema);
|
|
207
|
+
function jsonPrimitiveToString(entry) {
|
|
251
208
|
return entry == undefined ? 'null' : String(entry);
|
|
252
209
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
detail: newRoot,
|
|
258
|
-
}),
|
|
259
|
-
);
|
|
210
|
+
function emitRoot(newRoot) {
|
|
211
|
+
dispatch(new events.valueChange({
|
|
212
|
+
detail: newRoot,
|
|
213
|
+
}));
|
|
260
214
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
newValue,
|
|
268
|
-
}),
|
|
269
|
-
);
|
|
215
|
+
function emitReplaceAt(path, newValue) {
|
|
216
|
+
emitRoot(setValueAtPath({
|
|
217
|
+
root: inputs.value,
|
|
218
|
+
path,
|
|
219
|
+
newValue,
|
|
220
|
+
}));
|
|
270
221
|
}
|
|
271
|
-
|
|
272
|
-
function emitDeleteAt(path: ViraJsonPath) {
|
|
222
|
+
function emitDeleteAt(path) {
|
|
273
223
|
emitRoot(deleteValueAtPath(inputs.value, path));
|
|
274
224
|
}
|
|
275
|
-
|
|
276
|
-
function getPendingType(
|
|
277
|
-
pathKey: string,
|
|
278
|
-
allowedTypes: ReadonlyArray<ViraJsonType>,
|
|
279
|
-
): ViraJsonType {
|
|
225
|
+
function getPendingType(pathKey, allowedTypes) {
|
|
280
226
|
const current = state.pendingTypes[pathKey];
|
|
281
227
|
if (current && allowedTypes.includes(current)) {
|
|
282
228
|
return current;
|
|
283
229
|
}
|
|
284
230
|
return allowedTypes[0] ?? ViraJsonType.String;
|
|
285
231
|
}
|
|
286
|
-
|
|
287
|
-
function setPendingType(pathKey: string, type: ViraJsonType) {
|
|
232
|
+
function setPendingType(pathKey, type) {
|
|
288
233
|
updateState({
|
|
289
234
|
pendingTypes: {
|
|
290
235
|
...state.pendingTypes,
|
|
@@ -292,8 +237,7 @@ export const ViraJsonForm = defineViraElement<
|
|
|
292
237
|
},
|
|
293
238
|
});
|
|
294
239
|
}
|
|
295
|
-
|
|
296
|
-
function setPendingKey({pathKey, key}: Readonly<{pathKey: string; key: string}>) {
|
|
240
|
+
function setPendingKey({ pathKey, key }) {
|
|
297
241
|
updateState({
|
|
298
242
|
pendingKeys: {
|
|
299
243
|
...state.pendingKeys,
|
|
@@ -301,13 +245,11 @@ export const ViraJsonForm = defineViraElement<
|
|
|
301
245
|
},
|
|
302
246
|
});
|
|
303
247
|
}
|
|
304
|
-
|
|
305
|
-
function getPendingArrayValue(pathKey: string, fallback: JsonValue): JsonValue {
|
|
248
|
+
function getPendingArrayValue(pathKey, fallback) {
|
|
306
249
|
const stored = state.pendingArrayValues[pathKey];
|
|
307
250
|
return stored === undefined ? fallback : stored;
|
|
308
251
|
}
|
|
309
|
-
|
|
310
|
-
function setPendingArrayValue(pathKey: string, value: JsonValue) {
|
|
252
|
+
function setPendingArrayValue(pathKey, value) {
|
|
311
253
|
updateState({
|
|
312
254
|
pendingArrayValues: {
|
|
313
255
|
...state.pendingArrayValues,
|
|
@@ -315,16 +257,7 @@ export const ViraJsonForm = defineViraElement<
|
|
|
315
257
|
},
|
|
316
258
|
});
|
|
317
259
|
}
|
|
318
|
-
|
|
319
|
-
function getStringMode({
|
|
320
|
-
pathKey,
|
|
321
|
-
value,
|
|
322
|
-
enumValues,
|
|
323
|
-
}: Readonly<{
|
|
324
|
-
pathKey: string;
|
|
325
|
-
value: string;
|
|
326
|
-
enumValues: ReadonlyArray<string>;
|
|
327
|
-
}>): ViraJsonStringMode {
|
|
260
|
+
function getStringMode({ pathKey, value, enumValues, }) {
|
|
328
261
|
const stored = state.stringModes[pathKey];
|
|
329
262
|
if (stored) {
|
|
330
263
|
return stored;
|
|
@@ -333,8 +266,7 @@ export const ViraJsonForm = defineViraElement<
|
|
|
333
266
|
? ViraJsonStringMode.Options
|
|
334
267
|
: ViraJsonStringMode.Custom;
|
|
335
268
|
}
|
|
336
|
-
|
|
337
|
-
function setStringMode(pathKey: string, mode: ViraJsonStringMode) {
|
|
269
|
+
function setStringMode(pathKey, mode) {
|
|
338
270
|
updateState({
|
|
339
271
|
stringModes: {
|
|
340
272
|
...state.stringModes,
|
|
@@ -342,205 +274,173 @@ export const ViraJsonForm = defineViraElement<
|
|
|
342
274
|
},
|
|
343
275
|
});
|
|
344
276
|
}
|
|
345
|
-
|
|
346
|
-
function clearPending(pathKey: string) {
|
|
277
|
+
function clearPending(pathKey) {
|
|
347
278
|
updateState({
|
|
348
279
|
pendingKeys: omitObjectKeys(state.pendingKeys, [pathKey]),
|
|
349
280
|
pendingTypes: omitObjectKeys(state.pendingTypes, [pathKey]),
|
|
350
281
|
pendingArrayValues: omitObjectKeys(state.pendingArrayValues, [pathKey]),
|
|
351
282
|
});
|
|
352
283
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return html`
|
|
284
|
+
function renderDeleteButton(onDelete) {
|
|
285
|
+
return html `
|
|
356
286
|
<${ViraButton.assign({
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
287
|
+
icon: X16Icon,
|
|
288
|
+
buttonEmphasis: ViraEmphasis.Subtle,
|
|
289
|
+
color: ViraColorVariant.Danger,
|
|
290
|
+
buttonSize: ViraSize.Small,
|
|
291
|
+
})}
|
|
362
292
|
title="Remove"
|
|
363
293
|
${listen('click', onDelete)}
|
|
364
294
|
></${ViraButton}>
|
|
365
295
|
`;
|
|
366
296
|
}
|
|
367
|
-
|
|
368
|
-
function renderPrimitive(
|
|
369
|
-
path: ViraJsonPath,
|
|
370
|
-
value: JsonValue,
|
|
371
|
-
schema: ViraJsonSchema | undefined,
|
|
372
|
-
): HTMLTemplateResult {
|
|
297
|
+
function renderPrimitive(path, value, schema) {
|
|
373
298
|
const type = getJsonType(value);
|
|
374
299
|
const enumValues = getSchemaEnumValues(schema, resolveContext);
|
|
375
|
-
|
|
376
300
|
if (enumValues && enumValues.length > 0) {
|
|
377
|
-
const options
|
|
378
|
-
const asString = jsonPrimitiveToString(entry
|
|
301
|
+
const options = enumValues.map((entry) => {
|
|
302
|
+
const asString = jsonPrimitiveToString(entry);
|
|
379
303
|
return {
|
|
380
304
|
value: asString,
|
|
381
305
|
label: asString,
|
|
382
306
|
};
|
|
383
307
|
});
|
|
384
|
-
const isPrimitive =
|
|
385
|
-
value == undefined ||
|
|
308
|
+
const isPrimitive = value == undefined ||
|
|
386
309
|
check.isString(value) ||
|
|
387
310
|
check.isNumber(value) ||
|
|
388
311
|
check.isBoolean(value);
|
|
389
|
-
return html`
|
|
312
|
+
return html `
|
|
390
313
|
<${ViraSelect.assign({
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
314
|
+
options,
|
|
315
|
+
value: isPrimitive ? jsonPrimitiveToString(value) : undefined,
|
|
316
|
+
disabled: isDisabled,
|
|
317
|
+
})}
|
|
395
318
|
${listen(ViraSelect.events.valueChange, (event) => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
emitReplaceAt(path, selected ?? event.detail);
|
|
400
|
-
})}
|
|
319
|
+
const selected = enumValues.find((entry) => jsonPrimitiveToString(entry) === event.detail);
|
|
320
|
+
emitReplaceAt(path, selected ?? event.detail);
|
|
321
|
+
})}
|
|
401
322
|
></${ViraSelect}>
|
|
402
323
|
`;
|
|
403
|
-
}
|
|
404
|
-
|
|
324
|
+
}
|
|
325
|
+
else if (type === ViraJsonType.Boolean) {
|
|
326
|
+
return html `
|
|
405
327
|
<${ViraCheckbox.assign({
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
328
|
+
value: value === true,
|
|
329
|
+
isDisabled,
|
|
330
|
+
})}
|
|
409
331
|
${listen(ViraCheckbox.events.valueChange, (event) => {
|
|
410
|
-
|
|
411
|
-
|
|
332
|
+
emitReplaceAt(path, event.detail);
|
|
333
|
+
})}
|
|
412
334
|
></${ViraCheckbox}>
|
|
413
335
|
`;
|
|
414
|
-
}
|
|
336
|
+
}
|
|
337
|
+
else if (type === ViraJsonType.Number || type === ViraJsonType.Integer) {
|
|
415
338
|
const schemaAllowedTypes = getAllowedJsonTypes(schema, resolveContext);
|
|
416
|
-
const isIntegerOnly =
|
|
417
|
-
schemaAllowedTypes.length === 1 &&
|
|
339
|
+
const isIntegerOnly = schemaAllowedTypes.length === 1 &&
|
|
418
340
|
schemaAllowedTypes[0] === ViraJsonType.Integer;
|
|
419
|
-
return html`
|
|
341
|
+
return html `
|
|
420
342
|
<${ViraInput.assign({
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
343
|
+
type: ViraInputType.Number,
|
|
344
|
+
value: check.isNumber(value) ? String(value) : '',
|
|
345
|
+
disabled: isDisabled,
|
|
346
|
+
allowedInputs: isIntegerOnly ? /[\d-]/ : /[\d.-]/,
|
|
347
|
+
})}
|
|
426
348
|
${listen(ViraInput.events.valueChange, (event) => {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
349
|
+
const text = event.detail;
|
|
350
|
+
const parsed = text === '' ? 0 : Number(text);
|
|
351
|
+
const clean = Number.isFinite(parsed) ? parsed : 0;
|
|
352
|
+
emitReplaceAt(path, isIntegerOnly ? Math.trunc(clean) : clean);
|
|
353
|
+
})}
|
|
432
354
|
></${ViraInput}>
|
|
433
355
|
`;
|
|
434
|
-
}
|
|
435
|
-
|
|
356
|
+
}
|
|
357
|
+
else if (type === ViraJsonType.Null) {
|
|
358
|
+
return html `
|
|
436
359
|
<span class="json-null-indicator">null</span>
|
|
437
360
|
`;
|
|
438
|
-
}
|
|
439
|
-
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
return html `
|
|
440
364
|
<${ViraInput.assign({
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
365
|
+
value: check.isString(value) ? value : '',
|
|
366
|
+
disabled: isDisabled,
|
|
367
|
+
})}
|
|
444
368
|
${listen(ViraInput.events.valueChange, (event) => {
|
|
445
|
-
|
|
446
|
-
|
|
369
|
+
emitReplaceAt(path, event.detail);
|
|
370
|
+
})}
|
|
447
371
|
></${ViraInput}>
|
|
448
372
|
`;
|
|
449
373
|
}
|
|
450
374
|
}
|
|
451
|
-
|
|
452
|
-
function renderInlineValueEditor(
|
|
453
|
-
type: ViraJsonType,
|
|
454
|
-
currentValue: JsonValue,
|
|
455
|
-
onChange: (value: JsonValue) => void,
|
|
456
|
-
): HTMLTemplateResult | typeof nothing {
|
|
375
|
+
function renderInlineValueEditor(type, currentValue, onChange) {
|
|
457
376
|
if (type === ViraJsonType.String) {
|
|
458
377
|
const text = check.isString(currentValue) ? currentValue : '';
|
|
459
|
-
return html`
|
|
378
|
+
return html `
|
|
460
379
|
<${ViraInput.assign({
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
380
|
+
value: text,
|
|
381
|
+
placeholder: 'new item value',
|
|
382
|
+
})}
|
|
464
383
|
class="json-add-value-input"
|
|
465
384
|
${listen(ViraInput.events.valueChange, (event) => {
|
|
466
|
-
|
|
467
|
-
|
|
385
|
+
onChange(event.detail);
|
|
386
|
+
})}
|
|
468
387
|
></${ViraInput}>
|
|
469
388
|
`;
|
|
470
|
-
}
|
|
389
|
+
}
|
|
390
|
+
else if (type === ViraJsonType.Number || type === ViraJsonType.Integer) {
|
|
471
391
|
const isIntegerOnly = type === ViraJsonType.Integer;
|
|
472
392
|
const numText = check.isNumber(currentValue) ? String(currentValue) : '';
|
|
473
|
-
return html`
|
|
393
|
+
return html `
|
|
474
394
|
<${ViraInput.assign({
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
395
|
+
type: ViraInputType.Number,
|
|
396
|
+
value: numText,
|
|
397
|
+
placeholder: 'new item value',
|
|
398
|
+
allowedInputs: isIntegerOnly ? /[\d-]/ : /[\d.-]/,
|
|
399
|
+
})}
|
|
480
400
|
class="json-add-value-input"
|
|
481
401
|
${listen(ViraInput.events.valueChange, (event) => {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
402
|
+
const text = event.detail;
|
|
403
|
+
const parsed = text === '' ? 0 : Number(text);
|
|
404
|
+
const clean = Number.isFinite(parsed) ? parsed : 0;
|
|
405
|
+
onChange(isIntegerOnly ? Math.trunc(clean) : clean);
|
|
406
|
+
})}
|
|
487
407
|
></${ViraInput}>
|
|
488
408
|
`;
|
|
489
|
-
}
|
|
490
|
-
|
|
409
|
+
}
|
|
410
|
+
else if (type === ViraJsonType.Boolean) {
|
|
411
|
+
return html `
|
|
491
412
|
<${ViraCheckbox.assign({
|
|
492
|
-
|
|
493
|
-
|
|
413
|
+
value: currentValue === true,
|
|
414
|
+
})}
|
|
494
415
|
${listen(ViraCheckbox.events.valueChange, (event) => {
|
|
495
|
-
|
|
496
|
-
|
|
416
|
+
onChange(event.detail);
|
|
417
|
+
})}
|
|
497
418
|
></${ViraCheckbox}>
|
|
498
419
|
`;
|
|
499
|
-
}
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
500
422
|
return nothing;
|
|
501
423
|
}
|
|
502
424
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
isAddDisabled,
|
|
506
|
-
tooltip,
|
|
507
|
-
onClick,
|
|
508
|
-
}: {
|
|
509
|
-
isAddDisabled: boolean;
|
|
510
|
-
tooltip: string;
|
|
511
|
-
onClick: () => void;
|
|
512
|
-
}): HTMLTemplateResult {
|
|
513
|
-
return html`
|
|
425
|
+
function renderPlusButton({ isAddDisabled, tooltip, onClick, }) {
|
|
426
|
+
return html `
|
|
514
427
|
<${ViraButton.assign({
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
428
|
+
icon: Plus16Icon,
|
|
429
|
+
color: ViraColorVariant.Positive,
|
|
430
|
+
buttonSize: ViraSize.Small,
|
|
431
|
+
isDisabled: isAddDisabled,
|
|
432
|
+
})}
|
|
520
433
|
title=${tooltip}
|
|
521
434
|
${listen('click', () => {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
435
|
+
if (isAddDisabled) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
onClick();
|
|
439
|
+
})}
|
|
527
440
|
></${ViraButton}>
|
|
528
441
|
`;
|
|
529
442
|
}
|
|
530
|
-
|
|
531
|
-
function renderObjectAddControl({
|
|
532
|
-
pathKey,
|
|
533
|
-
allowedTypes,
|
|
534
|
-
canAdd,
|
|
535
|
-
disabledReason,
|
|
536
|
-
onAdd,
|
|
537
|
-
}: {
|
|
538
|
-
pathKey: string;
|
|
539
|
-
allowedTypes: ReadonlyArray<ViraJsonType>;
|
|
540
|
-
canAdd: boolean;
|
|
541
|
-
disabledReason: string;
|
|
542
|
-
onAdd: (type: ViraJsonType) => void;
|
|
543
|
-
}): HTMLTemplateResult | typeof nothing {
|
|
443
|
+
function renderObjectAddControl({ pathKey, allowedTypes, canAdd, disabledReason, onAdd, }) {
|
|
544
444
|
if (allowedTypes.length === 0) {
|
|
545
445
|
return nothing;
|
|
546
446
|
}
|
|
@@ -550,117 +450,107 @@ export const ViraJsonForm = defineViraElement<
|
|
|
550
450
|
return renderPlusButton({
|
|
551
451
|
isAddDisabled,
|
|
552
452
|
tooltip: isAddDisabled ? disabledReason : `Add ${viraJsonTypeLabels[onlyType]}`,
|
|
553
|
-
onClick
|
|
453
|
+
onClick() {
|
|
454
|
+
return onAdd(onlyType);
|
|
455
|
+
},
|
|
554
456
|
});
|
|
555
457
|
}
|
|
556
458
|
const selectedType = getPendingType(pathKey, allowedTypes);
|
|
557
|
-
const options
|
|
459
|
+
const options = allowedTypes.map((type) => {
|
|
558
460
|
return {
|
|
559
461
|
value: type,
|
|
560
462
|
label: viraJsonTypeLabels[type],
|
|
561
463
|
};
|
|
562
464
|
});
|
|
563
|
-
return html`
|
|
465
|
+
return html `
|
|
564
466
|
<${ViraSelect.assign({
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
467
|
+
options,
|
|
468
|
+
value: selectedType,
|
|
469
|
+
})}
|
|
568
470
|
${listen(ViraSelect.events.valueChange, (event) => {
|
|
569
|
-
|
|
570
|
-
|
|
471
|
+
setPendingType(pathKey, event.detail);
|
|
472
|
+
})}
|
|
571
473
|
></${ViraSelect}>
|
|
572
474
|
${renderPlusButton({
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
475
|
+
isAddDisabled,
|
|
476
|
+
tooltip: isAddDisabled
|
|
477
|
+
? disabledReason
|
|
478
|
+
: `Add ${viraJsonTypeLabels[selectedType]}`,
|
|
479
|
+
onClick() {
|
|
480
|
+
return onAdd(selectedType);
|
|
481
|
+
},
|
|
482
|
+
})}
|
|
579
483
|
`;
|
|
580
484
|
}
|
|
581
|
-
|
|
582
|
-
function renderArrayAddControl({
|
|
583
|
-
pathKey,
|
|
584
|
-
allowedTypes,
|
|
585
|
-
onAdd,
|
|
586
|
-
}: {
|
|
587
|
-
pathKey: string;
|
|
588
|
-
allowedTypes: ReadonlyArray<ViraJsonType>;
|
|
589
|
-
onAdd: (newValue: JsonValue) => void;
|
|
590
|
-
}): HTMLTemplateResult | typeof nothing {
|
|
485
|
+
function renderArrayAddControl({ pathKey, allowedTypes, onAdd, }) {
|
|
591
486
|
if (allowedTypes.length === 0) {
|
|
592
487
|
return nothing;
|
|
593
|
-
}
|
|
488
|
+
}
|
|
489
|
+
else if (allowedTypes.length === 1) {
|
|
594
490
|
const onlyType = assertWrap.isDefined(allowedTypes[0]);
|
|
595
|
-
const isPrimitivePrimitive =
|
|
596
|
-
onlyType === ViraJsonType.String ||
|
|
491
|
+
const isPrimitivePrimitive = onlyType === ViraJsonType.String ||
|
|
597
492
|
onlyType === ViraJsonType.Number ||
|
|
598
493
|
onlyType === ViraJsonType.Integer ||
|
|
599
494
|
onlyType === ViraJsonType.Boolean;
|
|
600
|
-
|
|
601
495
|
if (!isPrimitivePrimitive) {
|
|
602
496
|
return renderPlusButton({
|
|
603
497
|
isAddDisabled: false,
|
|
604
498
|
tooltip: `Add ${viraJsonTypeLabels[onlyType]}`,
|
|
605
|
-
onClick
|
|
499
|
+
onClick() {
|
|
500
|
+
return onAdd(createDefaultForJsonType(onlyType));
|
|
501
|
+
},
|
|
606
502
|
});
|
|
607
503
|
}
|
|
608
|
-
|
|
609
504
|
const fallback = createDefaultForJsonType(onlyType);
|
|
610
505
|
const pendingValue = getPendingArrayValue(pathKey, fallback);
|
|
611
506
|
const inlineEditor = renderInlineValueEditor(onlyType, pendingValue, (value) => {
|
|
612
507
|
return setPendingArrayValue(pathKey, value);
|
|
613
508
|
});
|
|
614
|
-
return html`
|
|
509
|
+
return html `
|
|
615
510
|
${inlineEditor}
|
|
616
511
|
${renderPlusButton({
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
512
|
+
isAddDisabled: false,
|
|
513
|
+
tooltip: `Add ${viraJsonTypeLabels[onlyType]}`,
|
|
514
|
+
onClick() {
|
|
515
|
+
onAdd(pendingValue);
|
|
516
|
+
clearPending(pathKey);
|
|
517
|
+
},
|
|
518
|
+
})}
|
|
624
519
|
`;
|
|
625
|
-
}
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
626
522
|
const selectedType = getPendingType(pathKey, allowedTypes);
|
|
627
|
-
const options
|
|
523
|
+
const options = allowedTypes.map((type) => {
|
|
628
524
|
return {
|
|
629
525
|
value: type,
|
|
630
526
|
label: viraJsonTypeLabels[type],
|
|
631
527
|
};
|
|
632
528
|
});
|
|
633
|
-
return html`
|
|
529
|
+
return html `
|
|
634
530
|
<${ViraSelect.assign({
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
531
|
+
options,
|
|
532
|
+
value: selectedType,
|
|
533
|
+
})}
|
|
638
534
|
${listen(ViraSelect.events.valueChange, (event) => {
|
|
639
|
-
|
|
640
|
-
|
|
535
|
+
setPendingType(pathKey, event.detail);
|
|
536
|
+
})}
|
|
641
537
|
></${ViraSelect}>
|
|
642
538
|
${renderPlusButton({
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
539
|
+
isAddDisabled: false,
|
|
540
|
+
tooltip: `Add ${viraJsonTypeLabels[selectedType]}`,
|
|
541
|
+
onClick() {
|
|
542
|
+
return onAdd(createDefaultForJsonType(selectedType));
|
|
543
|
+
},
|
|
544
|
+
})}
|
|
647
545
|
`;
|
|
648
546
|
}
|
|
649
547
|
}
|
|
650
|
-
|
|
651
|
-
function getNestedTypeLabel(schema: ViraJsonSchema | undefined, value: JsonValue): string {
|
|
548
|
+
function getNestedTypeLabel(schema, value) {
|
|
652
549
|
const concreteType = getJsonType(value);
|
|
653
550
|
const narrowedSchema = pickBranchForType(schema, concreteType, resolveContext);
|
|
654
|
-
return (
|
|
655
|
-
getSchemaTitle(narrowedSchema, resolveContext) || viraJsonTypeLabels[concreteType]
|
|
656
|
-
);
|
|
551
|
+
return (getSchemaTitle(narrowedSchema, resolveContext) || viraJsonTypeLabels[concreteType]);
|
|
657
552
|
}
|
|
658
|
-
|
|
659
|
-
function renderObjectGroup(
|
|
660
|
-
path: ViraJsonPath,
|
|
661
|
-
value: JsonObject,
|
|
662
|
-
schema: ViraJsonSchema | undefined,
|
|
663
|
-
): HTMLTemplateResult {
|
|
553
|
+
function renderObjectGroup(path, value, schema) {
|
|
664
554
|
const pathKey = pathToKey(path);
|
|
665
555
|
const isRoot = path.length === 0;
|
|
666
556
|
const requiredKeys = new Set(getRequiredProperties(schema, resolveContext));
|
|
@@ -668,31 +558,28 @@ export const ViraJsonForm = defineViraElement<
|
|
|
668
558
|
const definedKeys = new Set(Object.keys(definedProperties));
|
|
669
559
|
const presentKeys = Object.keys(value);
|
|
670
560
|
const additional = getAdditionalPropertiesSchema(schema, resolveContext);
|
|
671
|
-
|
|
672
561
|
const rowTemplates = presentKeys.map((key) => {
|
|
673
562
|
const childSchema = getPropertySchema(schema, key, resolveContext);
|
|
674
563
|
const isRequired = requiredKeys.has(key);
|
|
675
564
|
const isSchemaDefined = definedKeys.has(key);
|
|
676
565
|
const canDelete = !isDisabled && !isRequired;
|
|
677
|
-
const childValue
|
|
566
|
+
const childValue = value[key] ?? null;
|
|
678
567
|
const childType = getJsonType(childValue);
|
|
679
|
-
const isChildNested =
|
|
680
|
-
|
|
681
|
-
const childPath: ViraJsonPath = [
|
|
568
|
+
const isChildNested = childType === ViraJsonType.Object || childType === ViraJsonType.Array;
|
|
569
|
+
const childPath = [
|
|
682
570
|
...path,
|
|
683
571
|
key,
|
|
684
572
|
];
|
|
685
573
|
const childOnDelete = canDelete
|
|
686
574
|
? () => {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
575
|
+
emitDeleteAt(childPath);
|
|
576
|
+
if (!isSchemaDefined) {
|
|
577
|
+
clearPending(pathKey);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
692
580
|
: undefined;
|
|
693
|
-
|
|
694
581
|
if (isChildNested) {
|
|
695
|
-
return html`
|
|
582
|
+
return html `
|
|
696
583
|
<tr class="json-row-nested">
|
|
697
584
|
<td colspan="3">
|
|
698
585
|
<div class="json-row-nested-header">
|
|
@@ -709,8 +596,7 @@ export const ViraJsonForm = defineViraElement<
|
|
|
709
596
|
</tr>
|
|
710
597
|
`;
|
|
711
598
|
}
|
|
712
|
-
|
|
713
|
-
return html`
|
|
599
|
+
return html `
|
|
714
600
|
<tr class="json-row-primitive">
|
|
715
601
|
<td class="json-row-label">${key}${isRequired ? '*' : ''}</td>
|
|
716
602
|
<td class="json-row-editor">
|
|
@@ -722,142 +608,122 @@ export const ViraJsonForm = defineViraElement<
|
|
|
722
608
|
</tr>
|
|
723
609
|
`;
|
|
724
610
|
});
|
|
725
|
-
|
|
726
611
|
const missingDefinedKeys = [...definedKeys].filter((key) => !(key in value));
|
|
727
612
|
const suggestedKeyButtons = isDisabled
|
|
728
613
|
? []
|
|
729
614
|
: missingDefinedKeys.map((key) => {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
615
|
+
const childSchema = definedProperties[key];
|
|
616
|
+
const childAllowed = getAllowedJsonTypes(childSchema, resolveContext);
|
|
617
|
+
const addType = childAllowed[0] ?? ViraJsonType.String;
|
|
618
|
+
return html `
|
|
734
619
|
<${ViraButton.assign({
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
620
|
+
text: `"${key}"`,
|
|
621
|
+
icon: Plus16Icon,
|
|
622
|
+
color: ViraColorVariant.Positive,
|
|
623
|
+
buttonSize: ViraSize.Small,
|
|
624
|
+
})}
|
|
740
625
|
${listen('click', () => {
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
createDefaultForJsonType(addType),
|
|
747
|
-
);
|
|
748
|
-
})}
|
|
626
|
+
emitReplaceAt([
|
|
627
|
+
...path,
|
|
628
|
+
key,
|
|
629
|
+
], createDefaultForJsonType(addType));
|
|
630
|
+
})}
|
|
749
631
|
></${ViraButton}>
|
|
750
632
|
`;
|
|
751
|
-
|
|
752
|
-
|
|
633
|
+
});
|
|
753
634
|
const pendingKey = state.pendingKeys[pathKey] ?? '';
|
|
754
635
|
const trimmedPendingKey = pendingKey.trim();
|
|
755
636
|
const canAddArbitraryField = !!trimmedPendingKey && !(trimmedPendingKey in value);
|
|
756
637
|
const additionalAllowedTypes = additional.allowed
|
|
757
638
|
? getAllowedJsonTypes(additional.schema, resolveContext)
|
|
758
639
|
: [];
|
|
759
|
-
|
|
760
640
|
const arbitraryAddDisabledReason = trimmedPendingKey
|
|
761
641
|
? `Field "${trimmedPendingKey}" already exists.`
|
|
762
642
|
: 'Enter a field name to add.';
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
additional.allowed && !isDisabled
|
|
766
|
-
? html`
|
|
643
|
+
const arbitraryAddRow = additional.allowed && !isDisabled
|
|
644
|
+
? html `
|
|
767
645
|
<tr>
|
|
768
646
|
<td colspan="3">
|
|
769
647
|
<div class="json-add-row">
|
|
770
648
|
<${ViraInput.assign({
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
649
|
+
value: pendingKey,
|
|
650
|
+
placeholder: 'new field name',
|
|
651
|
+
})}
|
|
774
652
|
${listen(ViraInput.events.valueChange, (event) => {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
653
|
+
setPendingKey({
|
|
654
|
+
pathKey,
|
|
655
|
+
key: event.detail,
|
|
656
|
+
});
|
|
657
|
+
})}
|
|
780
658
|
></${ViraInput}>
|
|
781
659
|
${renderObjectAddControl({
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
clearPending(pathKey);
|
|
798
|
-
},
|
|
799
|
-
})}
|
|
660
|
+
pathKey,
|
|
661
|
+
allowedTypes: additionalAllowedTypes,
|
|
662
|
+
canAdd: canAddArbitraryField,
|
|
663
|
+
disabledReason: arbitraryAddDisabledReason,
|
|
664
|
+
onAdd(type) {
|
|
665
|
+
if (!canAddArbitraryField) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
emitReplaceAt([
|
|
669
|
+
...path,
|
|
670
|
+
trimmedPendingKey,
|
|
671
|
+
], createDefaultForJsonType(type));
|
|
672
|
+
clearPending(pathKey);
|
|
673
|
+
},
|
|
674
|
+
})}
|
|
800
675
|
</div>
|
|
801
676
|
</td>
|
|
802
677
|
</tr>
|
|
803
678
|
`
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
return html`
|
|
679
|
+
: nothing;
|
|
680
|
+
return html `
|
|
807
681
|
<table class="json-group ${isRoot ? '' : 'json-group-nested'}">
|
|
808
682
|
<tbody>
|
|
809
683
|
${rowTemplates.length === 0 && suggestedKeyButtons.length === 0
|
|
810
|
-
|
|
684
|
+
? html `
|
|
811
685
|
<tr>
|
|
812
686
|
<td colspan="3">
|
|
813
687
|
<span class="json-empty-note">(empty object)</span>
|
|
814
688
|
</td>
|
|
815
689
|
</tr>
|
|
816
690
|
`
|
|
817
|
-
|
|
691
|
+
: nothing}
|
|
818
692
|
${rowTemplates}
|
|
819
693
|
${suggestedKeyButtons.length > 0
|
|
820
|
-
|
|
694
|
+
? html `
|
|
821
695
|
<tr>
|
|
822
696
|
<td colspan="3">
|
|
823
697
|
<div class="json-add-row">${suggestedKeyButtons}</div>
|
|
824
698
|
</td>
|
|
825
699
|
</tr>
|
|
826
700
|
`
|
|
827
|
-
|
|
701
|
+
: nothing}
|
|
828
702
|
${arbitraryAddRow}
|
|
829
703
|
</tbody>
|
|
830
704
|
</table>
|
|
831
705
|
`;
|
|
832
706
|
}
|
|
833
|
-
|
|
834
|
-
function renderArrayGroup(
|
|
835
|
-
path: ViraJsonPath,
|
|
836
|
-
value: ReadonlyArray<JsonValue>,
|
|
837
|
-
schema: ViraJsonSchema | undefined,
|
|
838
|
-
): HTMLTemplateResult {
|
|
707
|
+
function renderArrayGroup(path, value, schema) {
|
|
839
708
|
const pathKey = pathToKey(path);
|
|
840
709
|
const isRoot = path.length === 0;
|
|
841
710
|
const newItemSchema = getNewItemSchema(schema, value.length, resolveContext);
|
|
842
711
|
const allowedItemTypes = getAllowedJsonTypes(newItemSchema, resolveContext);
|
|
843
|
-
|
|
844
712
|
const rowTemplates = value.map((item, index) => {
|
|
845
713
|
const childSchema = getItemSchema(schema, index, resolveContext);
|
|
846
714
|
const childType = getJsonType(item);
|
|
847
|
-
const isChildNested =
|
|
848
|
-
|
|
849
|
-
const childPath: ViraJsonPath = [
|
|
715
|
+
const isChildNested = childType === ViraJsonType.Object || childType === ViraJsonType.Array;
|
|
716
|
+
const childPath = [
|
|
850
717
|
...path,
|
|
851
718
|
index,
|
|
852
719
|
];
|
|
853
720
|
const childOnDelete = isDisabled
|
|
854
721
|
? undefined
|
|
855
722
|
: () => {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
723
|
+
emitDeleteAt(childPath);
|
|
724
|
+
};
|
|
859
725
|
if (isChildNested) {
|
|
860
|
-
return html`
|
|
726
|
+
return html `
|
|
861
727
|
<tr class="json-row-nested">
|
|
862
728
|
<td colspan="3">
|
|
863
729
|
<div class="json-row-nested-header">
|
|
@@ -874,8 +740,7 @@ export const ViraJsonForm = defineViraElement<
|
|
|
874
740
|
</tr>
|
|
875
741
|
`;
|
|
876
742
|
}
|
|
877
|
-
|
|
878
|
-
return html`
|
|
743
|
+
return html `
|
|
879
744
|
<tr class="json-row-primitive">
|
|
880
745
|
<td class="json-row-label">[${index}]</td>
|
|
881
746
|
<td class="json-row-editor">
|
|
@@ -887,95 +752,81 @@ export const ViraJsonForm = defineViraElement<
|
|
|
887
752
|
</tr>
|
|
888
753
|
`;
|
|
889
754
|
});
|
|
890
|
-
|
|
891
755
|
const addRow = isDisabled
|
|
892
756
|
? nothing
|
|
893
|
-
: html`
|
|
757
|
+
: html `
|
|
894
758
|
<tr>
|
|
895
759
|
<td colspan="3">
|
|
896
760
|
<div class="json-add-row">
|
|
897
761
|
${renderArrayAddControl({
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
);
|
|
908
|
-
},
|
|
909
|
-
})}
|
|
762
|
+
pathKey,
|
|
763
|
+
allowedTypes: allowedItemTypes,
|
|
764
|
+
onAdd(newValue) {
|
|
765
|
+
emitReplaceAt([
|
|
766
|
+
...path,
|
|
767
|
+
value.length,
|
|
768
|
+
], newValue);
|
|
769
|
+
},
|
|
770
|
+
})}
|
|
910
771
|
</div>
|
|
911
772
|
</td>
|
|
912
773
|
</tr>
|
|
913
774
|
`;
|
|
914
|
-
|
|
915
|
-
return html`
|
|
775
|
+
return html `
|
|
916
776
|
<table class="json-group ${isRoot ? '' : 'json-group-nested'}">
|
|
917
777
|
<tbody>
|
|
918
778
|
${rowTemplates.length === 0
|
|
919
|
-
|
|
779
|
+
? html `
|
|
920
780
|
<tr>
|
|
921
781
|
<td colspan="3">
|
|
922
782
|
<span class="json-empty-note">(empty array)</span>
|
|
923
783
|
</td>
|
|
924
784
|
</tr>
|
|
925
785
|
`
|
|
926
|
-
|
|
786
|
+
: nothing}
|
|
927
787
|
${rowTemplates} ${addRow}
|
|
928
788
|
</tbody>
|
|
929
789
|
</table>
|
|
930
790
|
`;
|
|
931
791
|
}
|
|
932
|
-
|
|
933
|
-
function renderStringEnumOrRaw(
|
|
934
|
-
path: ViraJsonPath,
|
|
935
|
-
value: string,
|
|
936
|
-
enumValues: ReadonlyArray<string>,
|
|
937
|
-
): HTMLTemplateResult {
|
|
792
|
+
function renderStringEnumOrRaw(path, value, enumValues) {
|
|
938
793
|
const pathKey = pathToKey(path);
|
|
939
794
|
const mode = getStringMode({
|
|
940
795
|
pathKey,
|
|
941
796
|
value,
|
|
942
797
|
enumValues,
|
|
943
798
|
});
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
mode === ViraJsonStringMode.Options
|
|
947
|
-
? html`
|
|
799
|
+
const editor = mode === ViraJsonStringMode.Options
|
|
800
|
+
? html `
|
|
948
801
|
<${ViraSelect.assign({
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
802
|
+
options: enumValues.map((entry) => {
|
|
803
|
+
return {
|
|
804
|
+
value: entry,
|
|
805
|
+
label: entry,
|
|
806
|
+
};
|
|
807
|
+
}),
|
|
808
|
+
value: enumValues.includes(value) ? value : undefined,
|
|
809
|
+
disabled: isDisabled,
|
|
810
|
+
})}
|
|
958
811
|
${listen(ViraSelect.events.valueChange, (event) => {
|
|
959
|
-
|
|
960
|
-
|
|
812
|
+
emitReplaceAt(path, event.detail);
|
|
813
|
+
})}
|
|
961
814
|
></${ViraSelect}>
|
|
962
815
|
`
|
|
963
|
-
|
|
816
|
+
: html `
|
|
964
817
|
<${ViraInput.assign({
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
818
|
+
value,
|
|
819
|
+
disabled: isDisabled,
|
|
820
|
+
})}
|
|
968
821
|
${listen(ViraInput.events.valueChange, (event) => {
|
|
969
|
-
|
|
970
|
-
|
|
822
|
+
emitReplaceAt(path, event.detail);
|
|
823
|
+
})}
|
|
971
824
|
></${ViraInput}>
|
|
972
825
|
`;
|
|
973
|
-
|
|
974
826
|
if (isDisabled) {
|
|
975
827
|
return editor;
|
|
976
828
|
}
|
|
977
|
-
|
|
978
|
-
const modeOptions: ReadonlyArray<ViraSelectOption> = [
|
|
829
|
+
const modeOptions = [
|
|
979
830
|
{
|
|
980
831
|
value: ViraJsonStringMode.Options,
|
|
981
832
|
label: 'Options',
|
|
@@ -985,170 +836,153 @@ export const ViraJsonForm = defineViraElement<
|
|
|
985
836
|
label: 'Custom',
|
|
986
837
|
},
|
|
987
838
|
];
|
|
988
|
-
|
|
989
|
-
return html`
|
|
839
|
+
return html `
|
|
990
840
|
<div class="json-value-with-switcher">
|
|
991
841
|
<span class="json-value-editor-slot">${editor}</span>
|
|
992
842
|
<${ViraSelect.assign({
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
843
|
+
options: modeOptions,
|
|
844
|
+
value: mode,
|
|
845
|
+
})}
|
|
996
846
|
title="Choose from options or enter a custom value"
|
|
997
847
|
${listen(ViraSelect.events.valueChange, (event) => {
|
|
998
|
-
|
|
999
|
-
|
|
848
|
+
setStringMode(pathKey, event.detail);
|
|
849
|
+
})}
|
|
1000
850
|
></${ViraSelect}>
|
|
1001
851
|
</div>
|
|
1002
852
|
`;
|
|
1003
853
|
}
|
|
1004
|
-
|
|
1005
|
-
function renderValue(
|
|
1006
|
-
path: ViraJsonPath,
|
|
1007
|
-
value: JsonValue,
|
|
1008
|
-
schema: ViraJsonSchema | undefined,
|
|
1009
|
-
): HTMLTemplateResult {
|
|
854
|
+
function renderValue(path, value, schema) {
|
|
1010
855
|
const concreteType = getJsonType(value);
|
|
1011
856
|
const allowedTypes = getAllowedJsonTypes(schema, resolveContext);
|
|
1012
857
|
const narrowedSchema = pickBranchForType(schema, concreteType, resolveContext);
|
|
1013
|
-
|
|
1014
858
|
if (check.isArray(value)) {
|
|
1015
859
|
return renderArrayGroup(path, value, narrowedSchema);
|
|
1016
|
-
}
|
|
860
|
+
}
|
|
861
|
+
else if (check.isObject(value)) {
|
|
1017
862
|
return renderObjectGroup(path, value, narrowedSchema);
|
|
1018
863
|
}
|
|
1019
|
-
|
|
1020
864
|
/**
|
|
1021
865
|
* When a string field constrains values to an enum but also permits free-form strings,
|
|
1022
866
|
* offer both: an options dropdown plus a switcher to toggle to raw text entry.
|
|
1023
867
|
*/
|
|
1024
|
-
const isStringOnlyField =
|
|
1025
|
-
allowedTypes.length === 1 && allowedTypes[0] === ViraJsonType.String;
|
|
868
|
+
const isStringOnlyField = allowedTypes.length === 1 && allowedTypes[0] === ViraJsonType.String;
|
|
1026
869
|
const stringEnumValues = isStringOnlyField
|
|
1027
870
|
? getStringEnumValues(schema, resolveContext)
|
|
1028
871
|
: [];
|
|
1029
|
-
if (
|
|
1030
|
-
check.isString(value) &&
|
|
872
|
+
if (check.isString(value) &&
|
|
1031
873
|
stringEnumValues.length > 0 &&
|
|
1032
|
-
allowsFreeformString(schema, resolveContext)
|
|
1033
|
-
) {
|
|
874
|
+
allowsFreeformString(schema, resolveContext)) {
|
|
1034
875
|
return renderStringEnumOrRaw(path, value, stringEnumValues);
|
|
1035
876
|
}
|
|
1036
|
-
|
|
1037
877
|
const editor = renderPrimitive(path, value, narrowedSchema);
|
|
1038
|
-
const showSwitcher =
|
|
1039
|
-
!isDisabled &&
|
|
878
|
+
const showSwitcher = !isDisabled &&
|
|
1040
879
|
allowedTypes.length > 1 &&
|
|
1041
880
|
!allowedTypes.includes(ViraJsonType.Object) &&
|
|
1042
881
|
!allowedTypes.includes(ViraJsonType.Array);
|
|
1043
|
-
|
|
1044
882
|
if (!showSwitcher) {
|
|
1045
883
|
return editor;
|
|
1046
884
|
}
|
|
1047
|
-
|
|
1048
885
|
const switcherSelected = allowedTypes.includes(concreteType)
|
|
1049
886
|
? concreteType
|
|
1050
887
|
: (allowedTypes[0] ?? concreteType);
|
|
1051
|
-
const switcherOptions
|
|
888
|
+
const switcherOptions = allowedTypes.map((type) => {
|
|
1052
889
|
return {
|
|
1053
890
|
value: type,
|
|
1054
891
|
label: viraJsonTypeLabels[type],
|
|
1055
892
|
};
|
|
1056
893
|
});
|
|
1057
|
-
return html`
|
|
894
|
+
return html `
|
|
1058
895
|
<div class="json-value-with-switcher">
|
|
1059
896
|
<span class="json-value-editor-slot">${editor}</span>
|
|
1060
897
|
<${ViraSelect.assign({
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
898
|
+
options: switcherOptions,
|
|
899
|
+
value: switcherSelected,
|
|
900
|
+
})}
|
|
1064
901
|
title="Change type"
|
|
1065
902
|
${listen(ViraSelect.events.valueChange, (event) => {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
903
|
+
const newType = event.detail;
|
|
904
|
+
emitReplaceAt(path, createDefaultForJsonType(newType));
|
|
905
|
+
})}
|
|
1069
906
|
></${ViraSelect}>
|
|
1070
907
|
</div>
|
|
1071
908
|
`;
|
|
1072
909
|
}
|
|
1073
|
-
|
|
1074
|
-
const toolbarTemplate = html`
|
|
910
|
+
const toolbarTemplate = html `
|
|
1075
911
|
<div class="json-toolbar">
|
|
1076
912
|
<${ViraButton.assign({
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
913
|
+
text: state.showRaw ? 'Rich' : 'Raw',
|
|
914
|
+
buttonEmphasis: ViraEmphasis.Subtle,
|
|
915
|
+
color: ViraColorVariant.Neutral,
|
|
916
|
+
buttonSize: ViraSize.Small,
|
|
917
|
+
})}
|
|
1082
918
|
title=${state.showRaw ? 'Show rich editor' : 'Show raw JSON'}
|
|
1083
919
|
${listen('click', () => {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
920
|
+
const goingToRaw = !state.showRaw;
|
|
921
|
+
host.style.minWidth = goingToRaw ? `${host.offsetWidth}px` : '';
|
|
922
|
+
updateState({
|
|
923
|
+
showRaw: goingToRaw,
|
|
924
|
+
rawDraft: undefined,
|
|
925
|
+
rawError: undefined,
|
|
926
|
+
});
|
|
927
|
+
})}
|
|
1092
928
|
></${ViraButton}>
|
|
1093
929
|
</div>
|
|
1094
930
|
`;
|
|
1095
|
-
|
|
1096
931
|
if (state.showRaw) {
|
|
1097
932
|
const rawText = state.rawDraft ?? JSON.stringify(inputs.value, undefined, 4);
|
|
1098
|
-
return html`
|
|
933
|
+
return html `
|
|
1099
934
|
${toolbarTemplate}
|
|
1100
935
|
<${ViraTextArea.assign({
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
936
|
+
value: rawText,
|
|
937
|
+
disabled: isDisabled,
|
|
938
|
+
disableBrowserHelps: true,
|
|
939
|
+
rows: 12,
|
|
940
|
+
})}
|
|
1106
941
|
class="json-raw-textarea"
|
|
1107
942
|
${listen(ViraTextArea.events.valueChange, (event) => {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
943
|
+
const text = event.detail;
|
|
944
|
+
const parsed = wrapInTry(() => JSON.parse(text));
|
|
945
|
+
if (parsed instanceof Error) {
|
|
946
|
+
updateState({
|
|
947
|
+
rawDraft: text,
|
|
948
|
+
rawError: parsed.message,
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
updateState({
|
|
953
|
+
rawDraft: text,
|
|
954
|
+
rawError: undefined,
|
|
955
|
+
});
|
|
956
|
+
emitRoot(parsed);
|
|
957
|
+
}
|
|
958
|
+
})}
|
|
1123
959
|
></${ViraTextArea}>
|
|
1124
960
|
${state.rawError
|
|
1125
|
-
|
|
961
|
+
? html `
|
|
1126
962
|
<${ViraError}>${state.rawError}</${ViraError}>
|
|
1127
963
|
`
|
|
1128
|
-
|
|
964
|
+
: nothing}
|
|
1129
965
|
`;
|
|
1130
966
|
}
|
|
1131
|
-
|
|
1132
967
|
const validationErrors = validateAgainstSchema(inputs.value, inputs.schema);
|
|
1133
968
|
if (validationErrors.length > 0) {
|
|
1134
|
-
return html`
|
|
969
|
+
return html `
|
|
1135
970
|
${toolbarTemplate}
|
|
1136
971
|
<${ViraError}>
|
|
1137
972
|
<div class="json-validation-errors">
|
|
1138
973
|
<div>Value does not match schema:</div>
|
|
1139
974
|
<ul>
|
|
1140
975
|
${validationErrors.map((errorMessage) => {
|
|
1141
|
-
|
|
976
|
+
return html `
|
|
1142
977
|
<li>${errorMessage}</li>
|
|
1143
978
|
`;
|
|
1144
|
-
|
|
979
|
+
})}
|
|
1145
980
|
</ul>
|
|
1146
981
|
</div>
|
|
1147
982
|
</${ViraError}>
|
|
1148
983
|
`;
|
|
1149
984
|
}
|
|
1150
|
-
|
|
1151
|
-
return html`
|
|
985
|
+
return html `
|
|
1152
986
|
${toolbarTemplate} ${renderValue([], inputs.value, inputs.schema)}
|
|
1153
987
|
`;
|
|
1154
988
|
},
|