@flanksource/clicky-ui 0.3.1 → 0.3.3
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/comments/CommentAuthor.cjs +58 -0
- package/dist/comments/CommentAuthor.cjs.map +1 -0
- package/dist/comments/CommentAuthor.d.ts +17 -0
- package/dist/comments/CommentAuthor.d.ts.map +1 -0
- package/dist/comments/CommentAuthor.js +58 -0
- package/dist/comments/CommentAuthor.js.map +1 -0
- package/dist/comments/CommentCard.cjs +343 -0
- package/dist/comments/CommentCard.cjs.map +1 -0
- package/dist/comments/CommentCard.d.ts +27 -0
- package/dist/comments/CommentCard.d.ts.map +1 -0
- package/dist/comments/CommentCard.js +343 -0
- package/dist/comments/CommentCard.js.map +1 -0
- package/dist/comments/CommentComposer.cjs +207 -0
- package/dist/comments/CommentComposer.cjs.map +1 -0
- package/dist/comments/CommentComposer.d.ts +23 -0
- package/dist/comments/CommentComposer.d.ts.map +1 -0
- package/dist/comments/CommentComposer.js +207 -0
- package/dist/comments/CommentComposer.js.map +1 -0
- package/dist/comments/CommentFilterBar.cjs +145 -0
- package/dist/comments/CommentFilterBar.cjs.map +1 -0
- package/dist/comments/CommentFilterBar.d.ts +15 -0
- package/dist/comments/CommentFilterBar.d.ts.map +1 -0
- package/dist/comments/CommentFilterBar.js +145 -0
- package/dist/comments/CommentFilterBar.js.map +1 -0
- package/dist/comments/CommentMarkdown.cjs +156 -0
- package/dist/comments/CommentMarkdown.cjs.map +1 -0
- package/dist/comments/CommentMarkdown.d.ts +13 -0
- package/dist/comments/CommentMarkdown.d.ts.map +1 -0
- package/dist/comments/CommentMarkdown.js +156 -0
- package/dist/comments/CommentMarkdown.js.map +1 -0
- package/dist/comments/CommentProgress.cjs +86 -0
- package/dist/comments/CommentProgress.cjs.map +1 -0
- package/dist/comments/CommentProgress.d.ts +16 -0
- package/dist/comments/CommentProgress.d.ts.map +1 -0
- package/dist/comments/CommentProgress.js +86 -0
- package/dist/comments/CommentProgress.js.map +1 -0
- package/dist/comments/CommentProvider.cjs +99 -0
- package/dist/comments/CommentProvider.cjs.map +1 -0
- package/dist/comments/CommentProvider.d.ts +19 -0
- package/dist/comments/CommentProvider.d.ts.map +1 -0
- package/dist/comments/CommentProvider.js +99 -0
- package/dist/comments/CommentProvider.js.map +1 -0
- package/dist/comments/CommentSidePanel.cjs +219 -0
- package/dist/comments/CommentSidePanel.cjs.map +1 -0
- package/dist/comments/CommentSidePanel.d.ts +16 -0
- package/dist/comments/CommentSidePanel.d.ts.map +1 -0
- package/dist/comments/CommentSidePanel.js +219 -0
- package/dist/comments/CommentSidePanel.js.map +1 -0
- package/dist/comments/CommentThread.cjs +57 -0
- package/dist/comments/CommentThread.cjs.map +1 -0
- package/dist/comments/CommentThread.d.ts +24 -0
- package/dist/comments/CommentThread.d.ts.map +1 -0
- package/dist/comments/CommentThread.js +57 -0
- package/dist/comments/CommentThread.js.map +1 -0
- package/dist/comments/CommentThreadList.cjs +124 -0
- package/dist/comments/CommentThreadList.cjs.map +1 -0
- package/dist/comments/CommentThreadList.d.ts +25 -0
- package/dist/comments/CommentThreadList.d.ts.map +1 -0
- package/dist/comments/CommentThreadList.js +124 -0
- package/dist/comments/CommentThreadList.js.map +1 -0
- package/dist/comments/GroupedComments.cjs +74 -0
- package/dist/comments/GroupedComments.cjs.map +1 -0
- package/dist/comments/GroupedComments.d.ts +18 -0
- package/dist/comments/GroupedComments.d.ts.map +1 -0
- package/dist/comments/GroupedComments.js +74 -0
- package/dist/comments/GroupedComments.js.map +1 -0
- package/dist/comments/MentionTextarea.cjs +253 -0
- package/dist/comments/MentionTextarea.cjs.map +1 -0
- package/dist/comments/MentionTextarea.d.ts +28 -0
- package/dist/comments/MentionTextarea.d.ts.map +1 -0
- package/dist/comments/MentionTextarea.js +253 -0
- package/dist/comments/MentionTextarea.js.map +1 -0
- package/dist/comments/comment-context.cjs +33 -0
- package/dist/comments/comment-context.cjs.map +1 -0
- package/dist/comments/comment-context.d.ts +32 -0
- package/dist/comments/comment-context.d.ts.map +1 -0
- package/dist/comments/comment-context.js +33 -0
- package/dist/comments/comment-context.js.map +1 -0
- package/dist/comments/comment-fixtures.d.ts +11 -0
- package/dist/comments/comment-fixtures.d.ts.map +1 -0
- package/dist/comments/comment-types.cjs +19 -0
- package/dist/comments/comment-types.cjs.map +1 -0
- package/dist/comments/comment-types.d.ts +170 -0
- package/dist/comments/comment-types.d.ts.map +1 -0
- package/dist/comments/comment-types.js +19 -0
- package/dist/comments/comment-types.js.map +1 -0
- package/dist/comments/comment-utils.cjs +216 -0
- package/dist/comments/comment-utils.cjs.map +1 -0
- package/dist/comments/comment-utils.d.ts +59 -0
- package/dist/comments/comment-utils.d.ts.map +1 -0
- package/dist/comments/comment-utils.js +216 -0
- package/dist/comments/comment-utils.js.map +1 -0
- package/dist/comments.cjs +57 -0
- package/dist/comments.cjs.map +1 -0
- package/dist/comments.d.ts +16 -0
- package/dist/comments.d.ts.map +1 -0
- package/dist/comments.js +57 -0
- package/dist/comments.js.map +1 -0
- package/dist/components/FilterBar.cjs +13 -3
- package/dist/components/FilterBar.cjs.map +1 -1
- package/dist/components/FilterBar.js +13 -3
- package/dist/components/FilterBar.js.map +1 -1
- package/dist/components/JsonSchemaForm.cjs +20 -6
- package/dist/components/JsonSchemaForm.cjs.map +1 -1
- package/dist/components/JsonSchemaForm.d.ts +1 -1
- package/dist/components/JsonSchemaForm.d.ts.map +1 -1
- package/dist/components/JsonSchemaForm.js +22 -8
- package/dist/components/JsonSchemaForm.js.map +1 -1
- package/dist/components/NamespacePicker.cjs +52 -0
- package/dist/components/NamespacePicker.cjs.map +1 -0
- package/dist/components/NamespacePicker.d.ts +17 -0
- package/dist/components/NamespacePicker.d.ts.map +1 -0
- package/dist/components/NamespacePicker.js +52 -0
- package/dist/components/NamespacePicker.js.map +1 -0
- package/dist/components/form-lookup-context.cjs +36 -0
- package/dist/components/form-lookup-context.cjs.map +1 -0
- package/dist/components/form-lookup-context.d.ts +9 -0
- package/dist/components/form-lookup-context.d.ts.map +1 -0
- package/dist/components/form-lookup-context.js +36 -0
- package/dist/components/form-lookup-context.js.map +1 -0
- package/dist/components/json-schema-form-discriminator.cjs +67 -0
- package/dist/components/json-schema-form-discriminator.cjs.map +1 -0
- package/dist/components/json-schema-form-discriminator.d.ts +10 -0
- package/dist/components/json-schema-form-discriminator.d.ts.map +1 -0
- package/dist/components/json-schema-form-discriminator.js +67 -0
- package/dist/components/json-schema-form-discriminator.js.map +1 -0
- package/dist/components/json-schema-form-fields.cjs +66 -1
- package/dist/components/json-schema-form-fields.cjs.map +1 -1
- package/dist/components/json-schema-form-fields.d.ts +7 -0
- package/dist/components/json-schema-form-fields.d.ts.map +1 -1
- package/dist/components/json-schema-form-fields.js +66 -1
- package/dist/components/json-schema-form-fields.js.map +1 -1
- package/dist/components/json-schema-form-grid.cjs +92 -0
- package/dist/components/json-schema-form-grid.cjs.map +1 -0
- package/dist/components/json-schema-form-grid.d.ts +9 -0
- package/dist/components/json-schema-form-grid.d.ts.map +1 -0
- package/dist/components/json-schema-form-grid.js +92 -0
- package/dist/components/json-schema-form-grid.js.map +1 -0
- package/dist/components/json-schema-form-render.cjs +20 -3
- package/dist/components/json-schema-form-render.cjs.map +1 -1
- package/dist/components/json-schema-form-render.d.ts.map +1 -1
- package/dist/components/json-schema-form-render.js +22 -5
- package/dist/components/json-schema-form-render.js.map +1 -1
- package/dist/components/json-schema-form-resolve.cjs +24 -2
- package/dist/components/json-schema-form-resolve.cjs.map +1 -1
- package/dist/components/json-schema-form-resolve.d.ts.map +1 -1
- package/dist/components/json-schema-form-resolve.js +24 -2
- package/dist/components/json-schema-form-resolve.js.map +1 -1
- package/dist/components/json-schema-form-types.d.ts +37 -2
- package/dist/components/json-schema-form-types.d.ts.map +1 -1
- package/dist/components/json-schema-form-utils.cjs +8 -0
- package/dist/components/json-schema-form-utils.cjs.map +1 -1
- package/dist/components/json-schema-form-utils.d.ts +1 -0
- package/dist/components/json-schema-form-utils.d.ts.map +1 -1
- package/dist/components/json-schema-form-utils.js +8 -0
- package/dist/components/json-schema-form-utils.js.map +1 -1
- package/dist/components/workload-picker-utils.cjs.map +1 -1
- package/dist/components/workload-picker-utils.d.ts +11 -1
- package/dist/components/workload-picker-utils.d.ts.map +1 -1
- package/dist/components/workload-picker-utils.js.map +1 -1
- package/dist/components.cjs +6 -0
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.ts +4 -2
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +6 -0
- package/dist/components.js.map +1 -1
- package/dist/data/Clicky.cjs +225 -60
- package/dist/data/Clicky.cjs.map +1 -1
- package/dist/data/Clicky.d.ts +7 -1
- package/dist/data/Clicky.d.ts.map +1 -1
- package/dist/data/Clicky.fixtures.d.ts +3 -1
- package/dist/data/Clicky.fixtures.d.ts.map +1 -1
- package/dist/data/Clicky.js +226 -61
- package/dist/data/Clicky.js.map +1 -1
- package/dist/data/ExecutionTree.cjs +68 -0
- package/dist/data/ExecutionTree.cjs.map +1 -0
- package/dist/data/ExecutionTree.d.ts +40 -0
- package/dist/data/ExecutionTree.d.ts.map +1 -0
- package/dist/data/ExecutionTree.js +68 -0
- package/dist/data/ExecutionTree.js.map +1 -0
- package/dist/data/GaugeHoverCard.cjs +35 -0
- package/dist/data/GaugeHoverCard.cjs.map +1 -0
- package/dist/data/GaugeHoverCard.d.ts +25 -0
- package/dist/data/GaugeHoverCard.d.ts.map +1 -0
- package/dist/data/GaugeHoverCard.js +35 -0
- package/dist/data/GaugeHoverCard.js.map +1 -0
- package/dist/data/MarkdownEditor.cjs +616 -0
- package/dist/data/MarkdownEditor.cjs.map +1 -0
- package/dist/data/MarkdownEditor.d.ts +61 -0
- package/dist/data/MarkdownEditor.d.ts.map +1 -0
- package/dist/data/MarkdownEditor.js +616 -0
- package/dist/data/MarkdownEditor.js.map +1 -0
- package/dist/data/MarkdownEditor.model.cjs +27 -0
- package/dist/data/MarkdownEditor.model.cjs.map +1 -0
- package/dist/data/MarkdownEditor.model.d.ts +38 -0
- package/dist/data/MarkdownEditor.model.d.ts.map +1 -0
- package/dist/data/MarkdownEditor.model.js +27 -0
- package/dist/data/MarkdownEditor.model.js.map +1 -0
- package/dist/data/ObjectGraph.cjs +44 -0
- package/dist/data/ObjectGraph.cjs.map +1 -0
- package/dist/data/ObjectGraph.d.ts +39 -0
- package/dist/data/ObjectGraph.d.ts.map +1 -0
- package/dist/data/ObjectGraph.js +44 -0
- package/dist/data/ObjectGraph.js.map +1 -0
- package/dist/data/SchemaViewer.cjs +152 -0
- package/dist/data/SchemaViewer.cjs.map +1 -0
- package/dist/data/SchemaViewer.d.ts +27 -0
- package/dist/data/SchemaViewer.d.ts.map +1 -0
- package/dist/data/SchemaViewer.js +152 -0
- package/dist/data/SchemaViewer.js.map +1 -0
- package/dist/data/TimeseriesCoreBars.cjs +51 -12
- package/dist/data/TimeseriesCoreBars.cjs.map +1 -1
- package/dist/data/TimeseriesCoreBars.d.ts +32 -5
- package/dist/data/TimeseriesCoreBars.d.ts.map +1 -1
- package/dist/data/TimeseriesCoreBars.js +51 -12
- package/dist/data/TimeseriesCoreBars.js.map +1 -1
- package/dist/data/TimeseriesCoreBars.model.cjs +5 -5
- package/dist/data/TimeseriesCoreBars.model.cjs.map +1 -1
- package/dist/data/TimeseriesCoreBars.model.d.ts +4 -4
- package/dist/data/TimeseriesCoreBars.model.d.ts.map +1 -1
- package/dist/data/TimeseriesCoreBars.model.js +5 -5
- package/dist/data/TimeseriesCoreBars.model.js.map +1 -1
- package/dist/data/TimeseriesGauge.cjs +103 -65
- package/dist/data/TimeseriesGauge.cjs.map +1 -1
- package/dist/data/TimeseriesGauge.d.ts +10 -1
- package/dist/data/TimeseriesGauge.d.ts.map +1 -1
- package/dist/data/TimeseriesGauge.js +104 -66
- package/dist/data/TimeseriesGauge.js.map +1 -1
- package/dist/data/WorkloadCard.cjs +4 -4
- package/dist/data/WorkloadCard.cjs.map +1 -1
- package/dist/data/WorkloadCard.d.ts +3 -2
- package/dist/data/WorkloadCard.d.ts.map +1 -1
- package/dist/data/WorkloadCard.js +4 -4
- package/dist/data/WorkloadCard.js.map +1 -1
- package/dist/data/ai/ChatWindow.cjs +11 -19
- package/dist/data/ai/ChatWindow.cjs.map +1 -1
- package/dist/data/ai/ChatWindow.d.ts +1 -7
- package/dist/data/ai/ChatWindow.d.ts.map +1 -1
- package/dist/data/ai/ChatWindow.js +11 -19
- package/dist/data/ai/ChatWindow.js.map +1 -1
- package/dist/data/ai/ChatWindowRequestBody.cjs +20 -0
- package/dist/data/ai/ChatWindowRequestBody.cjs.map +1 -0
- package/dist/data/ai/ChatWindowRequestBody.d.ts +9 -0
- package/dist/data/ai/ChatWindowRequestBody.d.ts.map +1 -0
- package/dist/data/ai/ChatWindowRequestBody.js +20 -0
- package/dist/data/ai/ChatWindowRequestBody.js.map +1 -0
- package/dist/data/chat/Chat.cjs +12 -0
- package/dist/data/chat/Chat.cjs.map +1 -1
- package/dist/data/chat/Chat.d.ts +8 -1
- package/dist/data/chat/Chat.d.ts.map +1 -1
- package/dist/data/chat/Chat.js +12 -0
- package/dist/data/chat/Chat.js.map +1 -1
- package/dist/data/gauge-stats.cjs +19 -0
- package/dist/data/gauge-stats.cjs.map +1 -0
- package/dist/data/gauge-stats.d.ts +15 -0
- package/dist/data/gauge-stats.d.ts.map +1 -0
- package/dist/data/gauge-stats.js +19 -0
- package/dist/data/gauge-stats.js.map +1 -0
- package/dist/data/schema-viewer-model.cjs +436 -0
- package/dist/data/schema-viewer-model.cjs.map +1 -0
- package/dist/data/schema-viewer-model.d.ts +64 -0
- package/dist/data/schema-viewer-model.d.ts.map +1 -0
- package/dist/data/schema-viewer-model.js +436 -0
- package/dist/data/schema-viewer-model.js.map +1 -0
- package/dist/data/version-info.cjs +2 -2
- package/dist/data/version-info.js +2 -2
- package/dist/data.cjs +23 -0
- package/dist/data.cjs.map +1 -1
- package/dist/data.d.ts +11 -3
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +23 -0
- package/dist/data.js.map +1 -1
- package/dist/index.cjs +87 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +87 -2
- package/dist/index.js.map +1 -1
- package/dist/rpc/EntityExplorerApp.cjs +102 -143
- package/dist/rpc/EntityExplorerApp.cjs.map +1 -1
- package/dist/rpc/EntityExplorerApp.d.ts +34 -1
- package/dist/rpc/EntityExplorerApp.d.ts.map +1 -1
- package/dist/rpc/EntityExplorerApp.js +105 -146
- package/dist/rpc/EntityExplorerApp.js.map +1 -1
- package/dist/rpc/OperationActionBar.cjs +135 -0
- package/dist/rpc/OperationActionBar.cjs.map +1 -0
- package/dist/rpc/OperationActionBar.d.ts +20 -0
- package/dist/rpc/OperationActionBar.d.ts.map +1 -0
- package/dist/rpc/OperationActionBar.js +135 -0
- package/dist/rpc/OperationActionBar.js.map +1 -0
- package/dist/rpc/OperationCatalog.cjs +79 -116
- package/dist/rpc/OperationCatalog.cjs.map +1 -1
- package/dist/rpc/OperationCatalog.d.ts +8 -1
- package/dist/rpc/OperationCatalog.d.ts.map +1 -1
- package/dist/rpc/OperationCatalog.js +80 -117
- package/dist/rpc/OperationCatalog.js.map +1 -1
- package/dist/rpc/OperationCommandPage.cjs +134 -223
- package/dist/rpc/OperationCommandPage.cjs.map +1 -1
- package/dist/rpc/OperationCommandPage.d.ts +1 -1
- package/dist/rpc/OperationCommandPage.d.ts.map +1 -1
- package/dist/rpc/OperationCommandPage.js +135 -224
- package/dist/rpc/OperationCommandPage.js.map +1 -1
- package/dist/rpc/OperationEntityPage.cjs +49 -100
- package/dist/rpc/OperationEntityPage.cjs.map +1 -1
- package/dist/rpc/OperationEntityPage.d.ts +6 -1
- package/dist/rpc/OperationEntityPage.d.ts.map +1 -1
- package/dist/rpc/OperationEntityPage.js +50 -101
- package/dist/rpc/OperationEntityPage.js.map +1 -1
- package/dist/rpc/OperationResultView.cjs +43 -0
- package/dist/rpc/OperationResultView.cjs.map +1 -0
- package/dist/rpc/OperationResultView.d.ts +30 -0
- package/dist/rpc/OperationResultView.d.ts.map +1 -0
- package/dist/rpc/OperationResultView.js +43 -0
- package/dist/rpc/OperationResultView.js.map +1 -0
- package/dist/rpc/SchemaActionForm.cjs +102 -0
- package/dist/rpc/SchemaActionForm.cjs.map +1 -0
- package/dist/rpc/SchemaActionForm.d.ts +23 -0
- package/dist/rpc/SchemaActionForm.d.ts.map +1 -0
- package/dist/rpc/SchemaActionForm.js +102 -0
- package/dist/rpc/SchemaActionForm.js.map +1 -0
- package/dist/rpc/accept-options.cjs.map +1 -1
- package/dist/rpc/accept-options.d.ts +0 -1
- package/dist/rpc/accept-options.d.ts.map +1 -1
- package/dist/rpc/accept-options.js.map +1 -1
- package/dist/rpc/apiClient.cjs +34 -2
- package/dist/rpc/apiClient.cjs.map +1 -1
- package/dist/rpc/apiClient.d.ts +4 -1
- package/dist/rpc/apiClient.d.ts.map +1 -1
- package/dist/rpc/apiClient.js +34 -2
- package/dist/rpc/apiClient.js.map +1 -1
- package/dist/rpc/clickyMetadata.cjs +4 -4
- package/dist/rpc/clickyMetadata.cjs.map +1 -1
- package/dist/rpc/clickyMetadata.d.ts +0 -1
- package/dist/rpc/clickyMetadata.d.ts.map +1 -1
- package/dist/rpc/clickyMetadata.js +4 -4
- package/dist/rpc/clickyMetadata.js.map +1 -1
- package/dist/rpc/formMetadata.cjs +1 -0
- package/dist/rpc/formMetadata.cjs.map +1 -1
- package/dist/rpc/formMetadata.d.ts +6 -1
- package/dist/rpc/formMetadata.d.ts.map +1 -1
- package/dist/rpc/formMetadata.js +1 -0
- package/dist/rpc/formMetadata.js.map +1 -1
- package/dist/rpc/rowNavigation.cjs +86 -0
- package/dist/rpc/rowNavigation.cjs.map +1 -0
- package/dist/rpc/rowNavigation.d.ts +14 -0
- package/dist/rpc/rowNavigation.d.ts.map +1 -0
- package/dist/rpc/rowNavigation.js +86 -0
- package/dist/rpc/rowNavigation.js.map +1 -0
- package/dist/rpc/schemaActionPath.cjs +22 -0
- package/dist/rpc/schemaActionPath.cjs.map +1 -0
- package/dist/rpc/schemaActionPath.d.ts +4 -0
- package/dist/rpc/schemaActionPath.d.ts.map +1 -0
- package/dist/rpc/schemaActionPath.js +22 -0
- package/dist/rpc/schemaActionPath.js.map +1 -0
- package/dist/rpc/surfaceIconMap.cjs +35 -0
- package/dist/rpc/surfaceIconMap.cjs.map +1 -0
- package/dist/rpc/surfaceIconMap.d.ts +3 -0
- package/dist/rpc/surfaceIconMap.d.ts.map +1 -0
- package/dist/rpc/surfaceIconMap.js +35 -0
- package/dist/rpc/surfaceIconMap.js.map +1 -0
- package/dist/rpc/types.cjs.map +1 -1
- package/dist/rpc/types.d.ts +2 -0
- package/dist/rpc/types.d.ts.map +1 -1
- package/dist/rpc/types.js.map +1 -1
- package/dist/rpc/useOperations.cjs.map +1 -1
- package/dist/rpc/useOperations.d.ts +4 -1
- package/dist/rpc/useOperations.d.ts.map +1 -1
- package/dist/rpc/useOperations.js.map +1 -1
- package/dist/rpc.cjs +4 -2
- package/dist/rpc.cjs.map +1 -1
- package/dist/rpc.d.ts +7 -6
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +4 -2
- package/dist/rpc.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -1
- package/dist/rpc/AcceptPicker.cjs +0 -137
- package/dist/rpc/AcceptPicker.cjs.map +0 -1
- package/dist/rpc/AcceptPicker.d.ts +0 -12
- package/dist/rpc/AcceptPicker.d.ts.map +0 -1
- package/dist/rpc/AcceptPicker.js +0 -137
- package/dist/rpc/AcceptPicker.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema-form-render.js","sources":["../../src/components/json-schema-form-render.tsx"],"sourcesContent":["import { type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { LabelIcon } from \"../data/Icon\";\nimport {\n BooleanControl,\n DateControl,\n DisplayControl,\n EnumControl,\n FieldLabel,\n FieldWrapper,\n LinkControl,\n NumberControl,\n ObjectSection,\n ReadOnlyValue,\n StringControl,\n TextareaControl,\n} from \"./json-schema-form-fields\";\nimport { ArrayControl } from \"./json-schema-form-array\";\nimport { ObjectControl, StringMapControl } from \"./json-schema-form-object\";\nimport { effectiveProperties, resolveControl } from \"./json-schema-form-resolve\";\nimport type {\n FieldArgs,\n FieldControl,\n JsonSchemaObject,\n RenderApi,\n RenderContext,\n} from \"./json-schema-form-types\";\nimport {\n fieldInputId,\n orderByPriority,\n orderByXOrder,\n orderRequiredFirst,\n softError,\n} from \"./json-schema-form-utils\";\nimport { labelSizeClass } from \"./json-schema-form-size\";\n\n// This module is the top of the json-schema-form graph: it imports the control\n// components and dispatches into them, while container controls recurse back in\n// only through ctx.render (see RenderApi). Nothing here is a React component,\n// so the component modules stay Fast-Refresh-eligible and cycle-free.\n\n// renderValueControl produces just the value node for a field, dispatching on\n// its resolved kind. The RenderContext carries readOnly + the pre/post stacks so\n// container controls (array/object/map) can recurse with full context.\nexport function renderValueControl(field: FieldControl, ctx: RenderContext): ReactNode {\n const fieldId = fieldInputId(field.key, ctx.idPrefix);\n // A field the schema marks `readOnly` is never editable: it shows its current\n // value as plain text, not a disabled input. (The form-level ctx.readOnly,\n // below, instead disables the real controls so the structure stays visible.)\n // Containers (array/object/map) still render structurally so nested read-only\n // values surface, and textarea/display/link own their non-editable rendering\n // (multi-line text / static element / hyperlink), so all of these are excluded\n // from the plain ReadOnlyValue fallback.\n if (field.readOnly && !ownsReadOnlyRendering(field.kind)) {\n return <ReadOnlyValue field={field} fieldId={fieldId} size={ctx.size} />;\n }\n const readOnly = ctx.readOnly || field.readOnly === true;\n const size = ctx.size;\n switch (field.kind) {\n case \"enum\":\n return <EnumControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"boolean\":\n return <BooleanControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"number\":\n return <NumberControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"date\":\n return <DateControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"textarea\":\n return <TextareaControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"display\":\n return <DisplayControl field={field} size={size} />;\n case \"link\":\n return <LinkControl field={field} fieldId={fieldId} size={size} />;\n case \"array\":\n return <ArrayControl field={field} fieldId={fieldId} ctx={ctx} />;\n case \"object\":\n return <ObjectControl field={field} ctx={ctx} />;\n case \"string-map\":\n return <StringMapControl field={field} ctx={ctx} />;\n default:\n return <StringControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n }\n}\n\n// ownsReadOnlyRendering reports whether a control renders its own non-editable\n// form, so the renderer must not pre-empt it with the plain ReadOnlyValue text:\n// containers recurse structurally, and textarea/display/link have bespoke\n// read-only output.\nfunction ownsReadOnlyRendering(kind: FieldControl[\"kind\"]): boolean {\n return (\n kind === \"array\" ||\n kind === \"object\" ||\n kind === \"string-map\" ||\n kind === \"textarea\" ||\n kind === \"display\" ||\n kind === \"link\"\n );\n}\n\n// buildField resolves a control, applies the pre-extensions (any returning\n// null drops the field), renders the value node, then applies the\n// post-extensions to the {label, value} node pair.\nfunction buildField(\n args: FieldArgs,\n ctx: RenderContext,\n): { field: FieldControl; label: ReactNode; value: ReactNode } | null {\n const base = resolveControl(args);\n let field: FieldControl | null = base;\n for (const ext of ctx.pre) {\n if (!field) break;\n field = ext(field, { key: args.key, prop: args.prop, value: args.value });\n }\n if (!field) return null;\n // Drop read-only fields entirely when the form opts out of displaying them.\n // Checked after pre-extensions so an extension that sets/clears readOnly wins.\n if (ctx.hideReadOnlyFields && field.readOnly) return null;\n\n const fieldId = fieldInputId(field.key, ctx.idPrefix);\n let label: ReactNode = <FieldLabel field={field} fieldId={fieldId} size={ctx.size} />;\n // A field's `x-layout: inline|stack` overrides the form-level layout for its\n // own value subtree (the field's own row keeps the parent layout). \"table\" is\n // handled structurally inside the array/string-map controls, not here.\n const overrideMode =\n field.layout === \"inline\" ? \"inline\" : field.layout === \"stack\" ? \"stacked\" : undefined;\n const valueCtx: RenderContext = overrideMode\n ? { ...ctx, layout: { ...ctx.layout, mode: overrideMode } }\n : ctx;\n let value: ReactNode = renderValueControl(field, valueCtx);\n for (const ext of ctx.post) {\n const next = ext(field, { label, value });\n label = next.label;\n value = next.value;\n }\n return { field, label, value };\n}\n\n// renderFieldNodes runs the full pipeline and returns the raw {label, value}\n// nodes (no FieldWrapper). Used where the caller arranges layout itself — map\n// rows (value only) and scalar array items.\nexport function renderFieldNodes(\n args: FieldArgs,\n ctx: RenderContext,\n): { label: ReactNode; value: ReactNode } | null {\n const built = buildField(args, ctx);\n if (!built) return null;\n return { label: built.label, value: built.value };\n}\n\n// renderFieldRow runs the pipeline and wraps it in a FieldWrapper with the soft\n// validation hint. `labelOverride` lets a container relabel a field that has no\n// natural key (e.g. array items → \"Item 1\").\nexport function renderFieldRow(\n args: FieldArgs,\n ctx: RenderContext,\n opts?: { labelOverride?: string },\n): ReactNode | null {\n const built = buildField(args, ctx);\n if (!built) return null;\n const { field } = built;\n // Object fields — and table-laid-out arrays/string-maps — render as a flat\n // section: a header followed by their body at full width, rather than an\n // inline label + narrow value column. This keeps deep schemas (e.g. policy →\n // shape, asfile → params) readable as a single column of labelled sections,\n // and gives a `x-layout: \"table\"` array the full width its columns need\n // instead of cramming it into the inline value column.\n if (field.kind === \"object\" || field.layout === \"table\") {\n return (\n <ObjectSection\n label={opts?.labelOverride ?? field.label}\n required={field.required}\n size={ctx.size}\n {...(field.badge ? { badge: field.badge } : {})}\n {...(field.helper ? { helper: field.helper } : {})}\n {...(field.labelIcon != null ? { labelIcon: field.labelIcon } : {})}\n >\n {built.value}\n </ObjectSection>\n );\n }\n // A display field (heading/divider/info/spacer) is the label — it carries no\n // value column, so it spans the full grid width with no inline label cell.\n if (field.kind === \"display\") {\n return <div className=\"col-span-full\">{built.value}</div>;\n }\n const label = opts?.labelOverride ? (\n <span className={cn(\"flex items-center gap-2 font-medium\", labelSizeClass[ctx.size])}>\n <LabelIcon icon={field.labelIcon} className=\"text-[15px] text-muted-foreground\" />\n <span>{opts.labelOverride}</span>\n {field.required && <span className=\"text-destructive\">*</span>}\n {field.badge && (\n <span className=\"rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground\">\n {field.badge}\n </span>\n )}\n </span>\n ) : (\n built.label\n );\n const err = softError(field);\n return (\n <FieldWrapper\n layout={ctx.layout}\n size={ctx.size}\n label={label}\n value={built.value}\n {...(field.helper ? { helper: field.helper } : {})}\n {...(err ? { error: err } : {})}\n />\n );\n}\n\n// renderObjectFields maps an object subschema's effective properties to field\n// rows. It is the recursive heart, shared by the top-level form and the nested\n// ObjectControl. Edits spread immutably onto the object.\nexport function renderObjectFields(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n onChange: (next: Record<string, unknown>) => void,\n ctx: RenderContext,\n opts?: { hiddenKeys?: string[] },\n): ReactNode[] {\n const { properties, required } = effectiveProperties(schema, value);\n const hidden = new Set(opts?.hiddenKeys ?? []);\n const ordered = orderByXOrder(Object.entries(properties), schema[\"x-order\"]);\n const entries =\n ctx.sortMode === \"required-first\"\n ? orderRequiredFirst(ordered, required)\n : ctx.sortMode === \"priority\"\n ? orderByPriority(ordered, required, value)\n : ordered;\n return entries.flatMap(([key, prop]) => {\n if (hidden.has(key)) return [];\n const row = renderFieldRow(\n {\n key,\n prop,\n required: required.includes(key),\n value: value[key],\n onChange: (next) => onChange({ ...value, [key]: next }),\n },\n ctx,\n );\n // `contents` keeps the keyed wrapper out of the box tree so the row's own\n // node (a subgrid FieldWrapper or a full-width ObjectSection) is a direct\n // child of the FieldsGrid and snaps to its label/value tracks.\n return row ? [<div key={key} className=\"contents\">{row}</div>] : [];\n });\n}\n\n// renderApi is the RenderContext injection bundle: the root form stores it on\n// the context so container controls can recurse without importing this module.\nexport const renderApi: RenderApi = {\n renderFieldNodes,\n renderFieldRow,\n renderObjectFields,\n};\n"],"names":[],"mappings":";;;;;;;;;;AA4C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AAC7C,QAAM,UAAU,cAAc,OAAO,QAAQ,UAAU,GAAG,OAAO,SAAS,CAAC;AAC3E,QAAM,UACJ,IAAI,aAAa,mBACb,mBAAmB,SAAS,QAAQ,IACpC,IAAI,aAAa,aACf,gBAAgB,SAAS,UAAU,KAAK,IACxC;AACR,SAAO,QAAQ,QAAQ,CAAC,CAAC,KAAK,IAAI,MAAM;AACtC,QAAI,OAAO,IAAI,GAAG,UAAU,CAAA;AAC5B,UAAM,MAAM;AAAA,MACV;AAAA,QACE;AAAA,QACA;AAAA,QACA,UAAU,SAAS,SAAS,GAAG;AAAA,QAC/B,OAAO,MAAM,GAAG;AAAA,QAChB,UAAU,CAAC,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG,KAAA,CAAM;AAAA,MAAA;AAAA,MAExD;AAAA,IAAA;AAKF,WAAO,MAAM,CAAC,oBAAC,OAAA,EAAc,WAAU,YAAY,UAAA,IAAA,GAA3B,GAA+B,CAAM,IAAI,CAAA;AAAA,EACnE,CAAC;AACH;AAIO,MAAM,YAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AACF;"}
|
|
1
|
+
{"version":3,"file":"json-schema-form-render.js","sources":["../../src/components/json-schema-form-render.tsx"],"sourcesContent":["import { type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { LabelIcon } from \"../data/Icon\";\nimport {\n BooleanControl,\n DateControl,\n DisplayControl,\n EnumControl,\n FieldLabel,\n FieldWrapper,\n LinkControl,\n LookupControl,\n NumberControl,\n ObjectSection,\n ReadOnlyValue,\n StringControl,\n TextareaControl,\n} from \"./json-schema-form-fields\";\nimport { ArrayControl } from \"./json-schema-form-array\";\nimport { ObjectControl, StringMapControl } from \"./json-schema-form-object\";\nimport { effectiveProperties, resolveControl } from \"./json-schema-form-resolve\";\nimport type {\n FieldArgs,\n FieldControl,\n JsonSchemaObject,\n RenderApi,\n RenderContext,\n} from \"./json-schema-form-types\";\nimport {\n fieldInputId,\n orderByClickyOrder,\n orderByPriority,\n orderByXOrder,\n orderRequiredFirst,\n softError,\n} from \"./json-schema-form-utils\";\nimport { labelSizeClass } from \"./json-schema-form-size\";\n\n// This module is the top of the json-schema-form graph: it imports the control\n// components and dispatches into them, while container controls recurse back in\n// only through ctx.render (see RenderApi). Nothing here is a React component,\n// so the component modules stay Fast-Refresh-eligible and cycle-free.\n\n// renderValueControl produces just the value node for a field, dispatching on\n// its resolved kind. The RenderContext carries readOnly + the pre/post stacks so\n// container controls (array/object/map) can recurse with full context.\nexport function renderValueControl(field: FieldControl, ctx: RenderContext): ReactNode {\n const fieldId = fieldInputId(field.key, ctx.idPrefix);\n // A field the schema marks `readOnly` is never editable: it shows its current\n // value as plain text, not a disabled input. (The form-level ctx.readOnly,\n // below, instead disables the real controls so the structure stays visible.)\n // Containers (array/object/map) still render structurally so nested read-only\n // values surface, and textarea/display/link own their non-editable rendering\n // (multi-line text / static element / hyperlink), so all of these are excluded\n // from the plain ReadOnlyValue fallback.\n if (field.readOnly && !ownsReadOnlyRendering(field.kind)) {\n return <ReadOnlyValue field={field} fieldId={fieldId} size={ctx.size} />;\n }\n const readOnly = ctx.readOnly || field.readOnly === true;\n const size = ctx.size;\n switch (field.kind) {\n case \"enum\":\n return <EnumControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"lookup\":\n return (\n <LookupControl\n field={field}\n fieldId={fieldId}\n readOnly={readOnly}\n size={size}\n {...(ctx.rootValue ? { rootValue: ctx.rootValue } : {})}\n />\n );\n case \"boolean\":\n return <BooleanControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"number\":\n return <NumberControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"date\":\n return <DateControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"textarea\":\n return <TextareaControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n case \"display\":\n return <DisplayControl field={field} size={size} />;\n case \"link\":\n return <LinkControl field={field} fieldId={fieldId} size={size} />;\n case \"array\":\n return <ArrayControl field={field} fieldId={fieldId} ctx={ctx} />;\n case \"object\":\n return <ObjectControl field={field} ctx={ctx} />;\n case \"string-map\":\n return <StringMapControl field={field} ctx={ctx} />;\n default:\n return <StringControl field={field} fieldId={fieldId} readOnly={readOnly} size={size} />;\n }\n}\n\n// ownsReadOnlyRendering reports whether a control renders its own non-editable\n// form, so the renderer must not pre-empt it with the plain ReadOnlyValue text:\n// containers recurse structurally, and textarea/display/link have bespoke\n// read-only output.\nfunction ownsReadOnlyRendering(kind: FieldControl[\"kind\"]): boolean {\n return (\n kind === \"array\" ||\n kind === \"object\" ||\n kind === \"string-map\" ||\n kind === \"textarea\" ||\n kind === \"display\" ||\n kind === \"link\"\n );\n}\n\n// buildField resolves a control, applies the pre-extensions (any returning\n// null drops the field), renders the value node, then applies the\n// post-extensions to the {label, value} node pair.\nfunction buildField(\n args: FieldArgs,\n ctx: RenderContext,\n): { field: FieldControl; label: ReactNode; value: ReactNode } | null {\n const base = resolveControl(args);\n let field: FieldControl | null = base;\n for (const ext of ctx.pre) {\n if (!field) break;\n field = ext(field, {\n key: args.key,\n prop: args.prop,\n value: args.value,\n ...(ctx.rootValue ? { rootValue: ctx.rootValue } : {}),\n });\n }\n if (!field) return null;\n // Drop read-only fields entirely when the form opts out of displaying them.\n // Checked after pre-extensions so an extension that sets/clears readOnly wins.\n if (ctx.hideReadOnlyFields && field.readOnly) return null;\n\n const fieldId = fieldInputId(field.key, ctx.idPrefix);\n let label: ReactNode = <FieldLabel field={field} fieldId={fieldId} size={ctx.size} />;\n // A field's `x-layout: inline|stack` overrides the form-level layout for its\n // own value subtree (the field's own row keeps the parent layout). \"table\" is\n // handled structurally inside the array/string-map controls, not here.\n const overrideMode =\n field.layout === \"inline\" ? \"inline\" : field.layout === \"stack\" ? \"stacked\" : undefined;\n const valueCtx: RenderContext = overrideMode\n ? { ...ctx, layout: { ...ctx.layout, mode: overrideMode } }\n : ctx;\n let value: ReactNode = renderValueControl(field, valueCtx);\n const postCtx = ctx.rootValue ? { rootValue: ctx.rootValue } : {};\n for (const ext of ctx.post) {\n const next = ext(field, { label, value }, postCtx);\n label = next.label;\n value = next.value;\n }\n return { field, label, value };\n}\n\n// renderFieldNodes runs the full pipeline and returns the raw {label, value}\n// nodes (no FieldWrapper). Used where the caller arranges layout itself — map\n// rows (value only) and scalar array items.\nexport function renderFieldNodes(\n args: FieldArgs,\n ctx: RenderContext,\n): { label: ReactNode; value: ReactNode } | null {\n const built = buildField(args, ctx);\n if (!built) return null;\n return { label: built.label, value: built.value };\n}\n\n// renderFieldRow runs the pipeline and wraps it in a FieldWrapper with the soft\n// validation hint. `labelOverride` lets a container relabel a field that has no\n// natural key (e.g. array items → \"Item 1\").\nexport function renderFieldRow(\n args: FieldArgs,\n ctx: RenderContext,\n opts?: { labelOverride?: string },\n): ReactNode | null {\n const built = buildField(args, ctx);\n if (!built) return null;\n const { field } = built;\n // Object fields — and table-laid-out arrays/string-maps — render as a flat\n // section: a header followed by their body at full width, rather than an\n // inline label + narrow value column. This keeps deep schemas (e.g. policy →\n // shape, asfile → params) readable as a single column of labelled sections,\n // and gives a `x-layout: \"table\"` array the full width its columns need\n // instead of cramming it into the inline value column.\n if (field.kind === \"object\" || field.layout === \"table\") {\n return (\n <ObjectSection\n label={opts?.labelOverride ?? field.label}\n required={field.required}\n size={ctx.size}\n {...(field.badge ? { badge: field.badge } : {})}\n {...(field.helper ? { helper: field.helper } : {})}\n {...(field.labelIcon != null ? { labelIcon: field.labelIcon } : {})}\n >\n {built.value}\n </ObjectSection>\n );\n }\n // A display field (heading/divider/info/spacer) is the label — it carries no\n // value column, so it spans the full grid width with no inline label cell.\n if (field.kind === \"display\") {\n return <div className=\"col-span-full\">{built.value}</div>;\n }\n const label = opts?.labelOverride ? (\n <span className={cn(\"flex items-center gap-2 font-medium\", labelSizeClass[ctx.size])}>\n <LabelIcon icon={field.labelIcon} className=\"text-[15px] text-muted-foreground\" />\n <span>{opts.labelOverride}</span>\n {field.required && <span className=\"text-destructive\">*</span>}\n {field.badge && (\n <span className=\"rounded bg-muted px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground\">\n {field.badge}\n </span>\n )}\n </span>\n ) : (\n built.label\n );\n const err = softError(field);\n return (\n <FieldWrapper\n layout={ctx.layout}\n size={ctx.size}\n label={label}\n value={built.value}\n {...(field.helper ? { helper: field.helper } : {})}\n {...(err ? { error: err } : {})}\n />\n );\n}\n\n// renderObjectFields maps an object subschema's effective properties to field\n// rows. It is the recursive heart, shared by the top-level form and the nested\n// ObjectControl. Edits spread immutably onto the object.\nexport function renderObjectFields(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n onChange: (next: Record<string, unknown>) => void,\n ctx: RenderContext,\n opts?: { hiddenKeys?: string[] },\n): ReactNode[] {\n const { properties, required } = effectiveProperties(schema, value);\n const hidden = new Set(opts?.hiddenKeys ?? []);\n // Per-property `x-clicky-order` wins (composes across merged branches); the\n // object-level `x-order` array is the fallback; document order otherwise.\n const ordered = orderByClickyOrder(orderByXOrder(Object.entries(properties), schema[\"x-order\"]));\n const entries =\n ctx.sortMode === \"required-first\"\n ? orderRequiredFirst(ordered, required)\n : ctx.sortMode === \"priority\"\n ? orderByPriority(ordered, required, value)\n : ordered;\n return entries.flatMap(([key, prop]) => {\n if (hidden.has(key)) return [];\n const row = renderFieldRow(\n {\n key,\n prop,\n required: required.includes(key),\n value: value[key],\n onChange: (next) => onChange({ ...value, [key]: next }),\n },\n ctx,\n );\n // `contents` keeps the keyed wrapper out of the box tree so the row's own\n // node (a subgrid FieldWrapper or a full-width ObjectSection) is a direct\n // child of the FieldsGrid and snaps to its label/value tracks.\n return row ? [<div key={key} className=\"contents\">{row}</div>] : [];\n });\n}\n\n// renderApi is the RenderContext injection bundle: the root form stores it on\n// the context so container controls can recurse without importing this module.\nexport const renderApi: RenderApi = {\n renderFieldNodes,\n renderFieldRow,\n renderObjectFields,\n};\n"],"names":[],"mappings":";;;;;;;;;;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MACZ,MAAM,IAAI;AAAA,MACV;AAAA,MACA,OAAO,MAAM;AAAA,MACZ,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAA,IAAW,CAAA;AAAA,MAC9C,GAAI,MAAM,EAAE,OAAO,QAAQ,CAAA;AAAA,IAAC;AAAA,EAAA;AAGnC;AAKO,SAAS,mBACd,QACA,OACA,UACA,KACA,MACa;AACb,QAAM,EAAE,YAAY,SAAA,IAAa,oBAAoB,QAAQ,KAAK;AAClE,QAAM,SAAS,IAAI,KAAI,6BAAM,eAAc,CAAA,CAAE;AAG7C,QAAM,UAAU,mBAAmB,cAAc,OAAO,QAAQ,UAAU,GAAG,OAAO,SAAS,CAAC,CAAC;AAC/F,QAAM,UACJ,IAAI,aAAa,mBACb,mBAAmB,SAAS,QAAQ,IACpC,IAAI,aAAa,aACf,gBAAgB,SAAS,UAAU,KAAK,IACxC;AACR,SAAO,QAAQ,QAAQ,CAAC,CAAC,KAAK,IAAI,MAAM;AACtC,QAAI,OAAO,IAAI,GAAG,UAAU,CAAA;AAC5B,UAAM,MAAM;AAAA,MACV;AAAA,QACE;AAAA,QACA;AAAA,QACA,UAAU,SAAS,SAAS,GAAG;AAAA,QAC/B,OAAO,MAAM,GAAG;AAAA,QAChB,UAAU,CAAC,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG,KAAA,CAAM;AAAA,MAAA;AAAA,MAExD;AAAA,IAAA;AAKF,WAAO,MAAM,CAAC,oBAAC,OAAA,EAAc,WAAU,YAAY,UAAA,IAAA,GAA3B,GAA+B,CAAM,IAAI,CAAA;AAAA,EACnE,CAAC;AACH;AAIO,MAAM,YAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AACF;"}
|
|
@@ -18,21 +18,38 @@ function schemaHasType(prop, type) {
|
|
|
18
18
|
}
|
|
19
19
|
function enumOptions(prop) {
|
|
20
20
|
const labels = prop["x-enum-labels"];
|
|
21
|
+
const icons = prop["x-enum-icons"];
|
|
21
22
|
return (prop.enum ?? []).map((v) => {
|
|
22
23
|
const value = String(v);
|
|
23
24
|
const desc = labels == null ? void 0 : labels[value];
|
|
25
|
+
const icon = icons == null ? void 0 : icons[value];
|
|
24
26
|
return {
|
|
25
27
|
value,
|
|
26
|
-
label: typeof desc === "string" && desc && desc !== value ? `${desc} (${value})` : value
|
|
28
|
+
label: typeof desc === "string" && desc && desc !== value ? `${desc} (${value})` : value,
|
|
29
|
+
...typeof icon === "string" && icon ? { icon } : {}
|
|
27
30
|
};
|
|
28
31
|
});
|
|
29
32
|
}
|
|
33
|
+
function enumDisplay(prop) {
|
|
34
|
+
const d = prop["x-enum-display"];
|
|
35
|
+
if (d === "combobox" || d === "radio" || d === "grid") return d;
|
|
36
|
+
const icons = prop["x-enum-icons"];
|
|
37
|
+
if (icons && Object.keys(icons).length > 0) return "grid";
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
30
40
|
function enumBranch(prop) {
|
|
31
41
|
for (const branch of [...prop.anyOf ?? [], ...prop.oneOf ?? []]) {
|
|
32
42
|
if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;
|
|
33
43
|
}
|
|
34
44
|
return void 0;
|
|
35
45
|
}
|
|
46
|
+
function lookupDescriptor(prop) {
|
|
47
|
+
const raw = prop["x-clicky-lookup"];
|
|
48
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
49
|
+
const d = raw;
|
|
50
|
+
if (typeof d.url !== "string" || typeof d.filter !== "string") return void 0;
|
|
51
|
+
return raw;
|
|
52
|
+
}
|
|
36
53
|
function resolveControl(args) {
|
|
37
54
|
const { key, prop, required, value, onChange } = args;
|
|
38
55
|
const labelIcon = prop["x-icon"];
|
|
@@ -51,8 +68,13 @@ function resolveControl(args) {
|
|
|
51
68
|
...typeof prop.description === "string" ? { description: prop.description } : {},
|
|
52
69
|
...labelIcon != null && labelIcon !== "" ? { labelIcon } : {}
|
|
53
70
|
};
|
|
71
|
+
const lookup = lookupDescriptor(prop);
|
|
72
|
+
if (lookup) {
|
|
73
|
+
return { ...base, kind: "lookup", lookup, options: [], allowCustomValue: lookup.multi !== true };
|
|
74
|
+
}
|
|
54
75
|
if (Array.isArray(prop.enum) && prop.enum.length > 0) {
|
|
55
|
-
|
|
76
|
+
const display = enumDisplay(prop);
|
|
77
|
+
return { ...base, kind: "enum", options: enumOptions(prop), ...display ? { display } : {} };
|
|
56
78
|
}
|
|
57
79
|
const branch = enumBranch(prop);
|
|
58
80
|
if (branch) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema-form-resolve.cjs","sources":["../../src/components/json-schema-form-resolve.ts"],"sourcesContent":["import type {\n FieldControl,\n FieldOption,\n JsonSchemaObject,\n JsonSchemaProperty,\n} from \"./json-schema-form-types\";\n\n// isOpenStringMap reports whether a property is an object whose entries are\n// described by a sub-schema in `additionalProperties` (a typed key/value map) or\n// by `patternProperties` (a per-key-pattern value map). Either makes it an\n// editable key/value control rather than a fixed-property sub-form.\nexport function isOpenStringMap(prop: JsonSchemaProperty): boolean {\n if (!schemaHasType(prop, \"object\")) return false;\n if (typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null) {\n return true;\n }\n return !!prop.patternProperties && Object.keys(prop.patternProperties).length > 0;\n}\n\n// patternSchemasOf compiles a schema's `patternProperties` into the ordered\n// {pattern, schema} list the string-map control matches keys against.\nfunction patternSchemasOf(prop: JsonSchemaProperty): { pattern: string; schema: JsonSchemaProperty }[] | undefined {\n const pp = prop.patternProperties;\n if (!pp || Object.keys(pp).length === 0) return undefined;\n return Object.entries(pp).map(([pattern, schema]) => ({ pattern, schema }));\n}\n\nfunction schemaHasType(prop: JsonSchemaProperty, type: string): boolean {\n if (Array.isArray(prop.type)) return prop.type.includes(type as never);\n return prop.type === type;\n}\n\nfunction enumOptions(prop: JsonSchemaProperty): FieldOption[] {\n const labels = prop[\"x-enum-labels\"];\n return (prop.enum ?? []).map((v) => {\n const value = String(v);\n const desc = labels?.[value];\n return {\n value,\n label: typeof desc === \"string\" && desc && desc !== value ? `${desc} (${value})` : value,\n };\n });\n}\n\n// enumBranch returns the first anyOf/oneOf member carrying a non-empty `enum`,\n// for a union of \"an enum value OR a free-form string\" (e.g. a value-or-token\n// field). It lets such a union render as a dropdown. Returns undefined when no\n// branch enumerates values.\nexport function enumBranch(prop: JsonSchemaProperty): JsonSchemaProperty | undefined {\n for (const branch of [...(prop.anyOf ?? []), ...(prop.oneOf ?? [])]) {\n if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;\n }\n return undefined;\n}\n\nexport interface ResolveControlArgs {\n key: string;\n prop: JsonSchemaProperty;\n required: boolean;\n value: unknown;\n onChange: (next: unknown) => void;\n}\n\n// resolveControl infers a base, render-ready FieldControl from a property\n// schema. It keys off schema keywords only — never the field name: ascode/token\n// heuristics are layered on by consumer pre-extensions. The one exception is the\n// standard `format: date`/`date-time` keyword, which is a schema-declared signal\n// (not a name guess) and so drives a date control directly. First match wins.\nexport function resolveControl(args: ResolveControlArgs): FieldControl {\n const { key, prop, required, value, onChange } = args;\n const labelIcon = prop[\"x-icon\"];\n const xLayout = prop[\"x-layout\"];\n const layout =\n xLayout === \"inline\" || xLayout === \"stack\" || xLayout === \"table\" ? xLayout : undefined;\n const keyOptions = keyOptionsFor(prop);\n const base: FieldControl = {\n key,\n kind: \"string\",\n label: typeof prop.title === \"string\" && prop.title ? prop.title : key,\n required,\n schema: prop,\n value,\n onChange,\n ...(prop.readOnly === true ? { readOnly: true } : {}),\n ...(typeof prop.description === \"string\" ? { description: prop.description } : {}),\n ...(labelIcon != null && labelIcon !== \"\" ? { labelIcon: labelIcon as FieldControl[\"labelIcon\"] } : {}),\n };\n\n if (Array.isArray(prop.enum) && prop.enum.length > 0) {\n return { ...base, kind: \"enum\", options: enumOptions(prop) };\n }\n // A value-or-template union: the enum lives in an anyOf/oneOf branch alongside\n // free-form branches. Render it as a dropdown using that branch's enum; the\n // free-form branches are honoured via a consumer's allowCustomValue pre-ext.\n const branch = enumBranch(prop);\n if (branch) {\n return { ...base, kind: \"enum\", options: enumOptions(branch) };\n }\n // A schema-declared date/date-time string renders as a date control.\n if (prop.format === \"date\" || prop.format === \"date-time\") {\n return { ...base, kind: \"date\", dateFormat: prop.format };\n }\n // A long-form string declares `format: textarea` to render a multi-line box.\n if (prop.format === \"textarea\" && schemaHasType(prop, \"string\")) {\n return { ...base, kind: \"textarea\" };\n }\n if (schemaHasType(prop, \"boolean\")) {\n return { ...base, kind: \"boolean\" };\n }\n if (schemaHasType(prop, \"integer\") || schemaHasType(prop, \"number\")) {\n return {\n ...base,\n kind: \"number\",\n coerceNumber: true,\n // A percent number carries a static \"%\" unit shown inside the input.\n ...(prop.format === \"percent\" ? { unit: \"%\" } : {}),\n ...(typeof prop.minimum === \"number\" ? { minimum: prop.minimum } : {}),\n };\n }\n if (schemaHasType(prop, \"array\")) {\n return {\n ...base,\n kind: \"array\",\n ...(prop.items ? { itemSchema: prop.items } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // An open map: object whose entries are described by an additionalProperties\n // sub-schema and/or per-key patternProperties. Renders as editable key/value\n // rows (+ any known properties), with the value form resolved per key.\n if (isOpenStringMap(prop)) {\n const addl =\n typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null\n ? (prop.additionalProperties as JsonSchemaProperty)\n : undefined;\n const patterns = patternSchemasOf(prop);\n // A constrained picker (propertyNames enum) or patternProperties still lets\n // the author ADD keys — the additions are limited to the allowed set, not\n // free-form — so `additionalProperties: false` doesn't disable \"Add field\"\n // in that case. It only closes a plain open map with no key constraints.\n const allowExtraKeys = keyOptions || patterns ? true : prop.additionalProperties !== false;\n return {\n ...base,\n kind: \"string-map\",\n ...(addl ? { valueSchema: addl } : {}),\n ...(patterns ? { valuePatternSchemas: patterns } : {}),\n ...(prop.properties ? { knownProperties: prop.properties } : {}),\n allowExtraKeys,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A structured object: fixed `properties`, not an open map. Renders as a\n // nested sub-form (labels, required, if/then) — recursed into by the renderer.\n if (schemaHasType(prop, \"object\") && prop.properties) {\n return {\n ...base,\n kind: \"object\",\n objectProperties: prop.properties,\n ...(prop.required ? { objectRequired: prop.required } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A bare object with neither properties nor an additionalProperties schema:\n // treat as an open string map unless explicitly closed.\n if (schemaHasType(prop, \"object\")) {\n return {\n ...base,\n kind: \"string-map\",\n allowExtraKeys: prop.additionalProperties !== false,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n return base;\n}\n\n// keyOptionsFor resolves the strict map-key picker options from a map schema's\n// `propertyNames.enum` (e.g. an AsCode-constrained key set). Returns undefined\n// when the keys are unconstrained, so the key stays free-text.\nfunction keyOptionsFor(prop: JsonSchemaProperty): FieldOption[] | undefined {\n const pn = prop.propertyNames as JsonSchemaProperty | undefined;\n if (!pn || !Array.isArray(pn.enum) || pn.enum.length === 0) return undefined;\n return enumOptions(pn);\n}\n\n// isScalarStringItems reports whether an array's item schema is a plain string\n// with no richer shape — the case the array control renders as compact tags.\n// Anything with an enum/const/properties/items/additionalProperties/allOf needs\n// a real per-item control instead.\nexport function isScalarStringItems(items: JsonSchemaProperty | undefined): boolean {\n if (!items) return true; // untyped items default to string tags\n if (items.type !== undefined && !schemaHasType(items, \"string\")) return false;\n return (\n items.enum === undefined &&\n items.const === undefined &&\n items.properties === undefined &&\n items.items === undefined &&\n items.additionalProperties === undefined &&\n items.allOf === undefined\n );\n}\n\n// matchesIf reports whether the `if` sub-schema holds for the current value:\n// every `if.required` key is present AND every `if.properties[k].const` equals\n// value[k].\nexport function matchesIf(\n ifSchema: JsonSchemaProperty | undefined,\n value: Record<string, unknown>,\n): boolean {\n if (!ifSchema) return false;\n for (const k of ifSchema.required ?? []) {\n if (!(k in value)) return false;\n }\n for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {\n if (\"const\" in sub && value[k] !== sub.const) return false;\n }\n return true;\n}\n\nexport interface EffectiveProperties {\n properties: Record<string, JsonSchemaProperty>;\n required: string[];\n}\n\n// effectiveProperties merges the schema's base `properties` with each `allOf`\n// member's contribution. An `if`/`then` member contributes `then.properties`\n// only when its `if` matches the current value; an unconditional member (e.g.\n// an inlined `$ref` composition, which carries its own `properties` and no\n// `if`) always contributes. Later members win on key collision; required is the\n// union. Pure and idempotent.\nexport function effectiveProperties(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n): EffectiveProperties {\n const properties: Record<string, JsonSchemaProperty> = { ...schema.properties };\n const required = new Set(schema.required ?? []);\n for (const clause of schema.allOf ?? []) {\n // Unconditional composition member: merge its own properties/required.\n if (clause.if === undefined && clause.then === undefined) {\n for (const [k, sub] of Object.entries(clause.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of clause.required ?? []) required.add(k);\n continue;\n }\n if (!matchesIf(clause.if, value)) continue;\n const then = clause.then ?? {};\n for (const [k, sub] of Object.entries(then.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of then.required ?? []) required.add(k);\n }\n return { properties, required: [...required] };\n}\n"],"names":[],"mappings":";;AAWO,SAAS,gBAAgB,MAAmC;AACjE,MAAI,CAAC,cAAc,MAAM,QAAQ,EAAG,QAAO;AAC3C,MAAI,OAAO,KAAK,yBAAyB,YAAY,KAAK,yBAAyB,MAAM;AACvF,WAAO;AAAA,EACT;AACA,SAAO,CAAC,CAAC,KAAK,qBAAqB,OAAO,KAAK,KAAK,iBAAiB,EAAE,SAAS;AAClF;AAIA,SAAS,iBAAiB,MAAyF;AACjH,QAAM,KAAK,KAAK;AAChB,MAAI,CAAC,MAAM,OAAO,KAAK,EAAE,EAAE,WAAW,EAAG,QAAO;AAChD,SAAO,OAAO,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,SAAS,SAAS;AAC5E;AAEA,SAAS,cAAc,MAA0B,MAAuB;AACtE,MAAI,MAAM,QAAQ,KAAK,IAAI,EAAG,QAAO,KAAK,KAAK,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sourcesContent":["import type {\n EnumDisplay,\n FieldControl,\n FieldOption,\n JsonSchemaObject,\n JsonSchemaProperty,\n LookupDescriptor,\n} from \"./json-schema-form-types\";\n\n// isOpenStringMap reports whether a property is an object whose entries are\n// described by a sub-schema in `additionalProperties` (a typed key/value map) or\n// by `patternProperties` (a per-key-pattern value map). Either makes it an\n// editable key/value control rather than a fixed-property sub-form.\nexport function isOpenStringMap(prop: JsonSchemaProperty): boolean {\n if (!schemaHasType(prop, \"object\")) return false;\n if (typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null) {\n return true;\n }\n return !!prop.patternProperties && Object.keys(prop.patternProperties).length > 0;\n}\n\n// patternSchemasOf compiles a schema's `patternProperties` into the ordered\n// {pattern, schema} list the string-map control matches keys against.\nfunction patternSchemasOf(prop: JsonSchemaProperty): { pattern: string; schema: JsonSchemaProperty }[] | undefined {\n const pp = prop.patternProperties;\n if (!pp || Object.keys(pp).length === 0) return undefined;\n return Object.entries(pp).map(([pattern, schema]) => ({ pattern, schema }));\n}\n\nfunction schemaHasType(prop: JsonSchemaProperty, type: string): boolean {\n if (Array.isArray(prop.type)) return prop.type.includes(type as never);\n return prop.type === type;\n}\n\nfunction enumOptions(prop: JsonSchemaProperty): FieldOption[] {\n const labels = prop[\"x-enum-labels\"];\n const icons = prop[\"x-enum-icons\"];\n return (prop.enum ?? []).map((v) => {\n const value = String(v);\n const desc = labels?.[value];\n const icon = icons?.[value];\n return {\n value,\n label: typeof desc === \"string\" && desc && desc !== value ? `${desc} (${value})` : value,\n ...(typeof icon === \"string\" && icon ? { icon } : {}),\n };\n });\n}\n\n// enumDisplay resolves how an enum should render: an explicit `x-enum-display`\n// wins; otherwise an enum carrying `x-enum-icons` defaults to the icon grid.\n// Returns undefined to keep the combobox default.\nfunction enumDisplay(prop: JsonSchemaProperty): EnumDisplay | undefined {\n const d = prop[\"x-enum-display\"];\n if (d === \"combobox\" || d === \"radio\" || d === \"grid\") return d;\n const icons = prop[\"x-enum-icons\"];\n if (icons && Object.keys(icons).length > 0) return \"grid\";\n return undefined;\n}\n\n// enumBranch returns the first anyOf/oneOf member carrying a non-empty `enum`,\n// for a union of \"an enum value OR a free-form string\" (e.g. a value-or-token\n// field). It lets such a union render as a dropdown. Returns undefined when no\n// branch enumerates values.\nexport function enumBranch(prop: JsonSchemaProperty): JsonSchemaProperty | undefined {\n for (const branch of [...(prop.anyOf ?? []), ...(prop.oneOf ?? [])]) {\n if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;\n }\n return undefined;\n}\n\n// lookupDescriptor reads the `x-clicky-lookup` extension into a LookupDescriptor,\n// returning undefined when the keyword is absent or lacks its required url/filter.\nfunction lookupDescriptor(prop: JsonSchemaProperty): LookupDescriptor | undefined {\n const raw = prop[\"x-clicky-lookup\"];\n if (!raw || typeof raw !== \"object\") return undefined;\n const d = raw as Record<string, unknown>;\n if (typeof d.url !== \"string\" || typeof d.filter !== \"string\") return undefined;\n return raw as LookupDescriptor;\n}\n\nexport interface ResolveControlArgs {\n key: string;\n prop: JsonSchemaProperty;\n required: boolean;\n value: unknown;\n onChange: (next: unknown) => void;\n}\n\n// resolveControl infers a base, render-ready FieldControl from a property\n// schema. It keys off schema keywords only — never the field name: ascode/token\n// heuristics are layered on by consumer pre-extensions. The one exception is the\n// standard `format: date`/`date-time` keyword, which is a schema-declared signal\n// (not a name guess) and so drives a date control directly. First match wins.\nexport function resolveControl(args: ResolveControlArgs): FieldControl {\n const { key, prop, required, value, onChange } = args;\n const labelIcon = prop[\"x-icon\"];\n const xLayout = prop[\"x-layout\"];\n const layout =\n xLayout === \"inline\" || xLayout === \"stack\" || xLayout === \"table\" ? xLayout : undefined;\n const keyOptions = keyOptionsFor(prop);\n const base: FieldControl = {\n key,\n kind: \"string\",\n label: typeof prop.title === \"string\" && prop.title ? prop.title : key,\n required,\n schema: prop,\n value,\n onChange,\n ...(prop.readOnly === true ? { readOnly: true } : {}),\n ...(typeof prop.description === \"string\" ? { description: prop.description } : {}),\n ...(labelIcon != null && labelIcon !== \"\" ? { labelIcon: labelIcon as FieldControl[\"labelIcon\"] } : {}),\n };\n\n // An `x-clicky-lookup` field is an async entity-reference picker: options load\n // lazily from another entity's list endpoint. Single-select also allows\n // free-form entry so a typed value outside the option set still commits.\n const lookup = lookupDescriptor(prop);\n if (lookup) {\n return { ...base, kind: \"lookup\", lookup, options: [], allowCustomValue: lookup.multi !== true };\n }\n if (Array.isArray(prop.enum) && prop.enum.length > 0) {\n const display = enumDisplay(prop);\n return { ...base, kind: \"enum\", options: enumOptions(prop), ...(display ? { display } : {}) };\n }\n // A value-or-template union: the enum lives in an anyOf/oneOf branch alongside\n // free-form branches. Render it as a dropdown using that branch's enum; the\n // free-form branches are honoured via a consumer's allowCustomValue pre-ext.\n const branch = enumBranch(prop);\n if (branch) {\n return { ...base, kind: \"enum\", options: enumOptions(branch) };\n }\n // A schema-declared date/date-time string renders as a date control.\n if (prop.format === \"date\" || prop.format === \"date-time\") {\n return { ...base, kind: \"date\", dateFormat: prop.format };\n }\n // A long-form string declares `format: textarea` to render a multi-line box.\n if (prop.format === \"textarea\" && schemaHasType(prop, \"string\")) {\n return { ...base, kind: \"textarea\" };\n }\n if (schemaHasType(prop, \"boolean\")) {\n return { ...base, kind: \"boolean\" };\n }\n if (schemaHasType(prop, \"integer\") || schemaHasType(prop, \"number\")) {\n return {\n ...base,\n kind: \"number\",\n coerceNumber: true,\n // A percent number carries a static \"%\" unit shown inside the input.\n ...(prop.format === \"percent\" ? { unit: \"%\" } : {}),\n ...(typeof prop.minimum === \"number\" ? { minimum: prop.minimum } : {}),\n };\n }\n if (schemaHasType(prop, \"array\")) {\n return {\n ...base,\n kind: \"array\",\n ...(prop.items ? { itemSchema: prop.items } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // An open map: object whose entries are described by an additionalProperties\n // sub-schema and/or per-key patternProperties. Renders as editable key/value\n // rows (+ any known properties), with the value form resolved per key.\n if (isOpenStringMap(prop)) {\n const addl =\n typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null\n ? (prop.additionalProperties as JsonSchemaProperty)\n : undefined;\n const patterns = patternSchemasOf(prop);\n // A constrained picker (propertyNames enum) or patternProperties still lets\n // the author ADD keys — the additions are limited to the allowed set, not\n // free-form — so `additionalProperties: false` doesn't disable \"Add field\"\n // in that case. It only closes a plain open map with no key constraints.\n const allowExtraKeys = keyOptions || patterns ? true : prop.additionalProperties !== false;\n return {\n ...base,\n kind: \"string-map\",\n ...(addl ? { valueSchema: addl } : {}),\n ...(patterns ? { valuePatternSchemas: patterns } : {}),\n ...(prop.properties ? { knownProperties: prop.properties } : {}),\n allowExtraKeys,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A structured object: fixed `properties`, not an open map. Renders as a\n // nested sub-form (labels, required, if/then) — recursed into by the renderer.\n if (schemaHasType(prop, \"object\") && prop.properties) {\n return {\n ...base,\n kind: \"object\",\n objectProperties: prop.properties,\n ...(prop.required ? { objectRequired: prop.required } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A bare object with neither properties nor an additionalProperties schema:\n // treat as an open string map unless explicitly closed.\n if (schemaHasType(prop, \"object\")) {\n return {\n ...base,\n kind: \"string-map\",\n allowExtraKeys: prop.additionalProperties !== false,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n return base;\n}\n\n// keyOptionsFor resolves the strict map-key picker options from a map schema's\n// `propertyNames.enum` (e.g. an AsCode-constrained key set). Returns undefined\n// when the keys are unconstrained, so the key stays free-text.\nfunction keyOptionsFor(prop: JsonSchemaProperty): FieldOption[] | undefined {\n const pn = prop.propertyNames as JsonSchemaProperty | undefined;\n if (!pn || !Array.isArray(pn.enum) || pn.enum.length === 0) return undefined;\n return enumOptions(pn);\n}\n\n// isScalarStringItems reports whether an array's item schema is a plain string\n// with no richer shape — the case the array control renders as compact tags.\n// Anything with an enum/const/properties/items/additionalProperties/allOf needs\n// a real per-item control instead.\nexport function isScalarStringItems(items: JsonSchemaProperty | undefined): boolean {\n if (!items) return true; // untyped items default to string tags\n if (items.type !== undefined && !schemaHasType(items, \"string\")) return false;\n return (\n items.enum === undefined &&\n items.const === undefined &&\n items.properties === undefined &&\n items.items === undefined &&\n items.additionalProperties === undefined &&\n items.allOf === undefined\n );\n}\n\n// matchesIf reports whether the `if` sub-schema holds for the current value:\n// every `if.required` key is present AND every `if.properties[k].const` equals\n// value[k].\nexport function matchesIf(\n ifSchema: JsonSchemaProperty | undefined,\n value: Record<string, unknown>,\n): boolean {\n if (!ifSchema) return false;\n for (const k of ifSchema.required ?? []) {\n if (!(k in value)) return false;\n }\n for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {\n if (\"const\" in sub && value[k] !== sub.const) return false;\n }\n return true;\n}\n\nexport interface EffectiveProperties {\n properties: Record<string, JsonSchemaProperty>;\n required: string[];\n}\n\n// effectiveProperties merges the schema's base `properties` with each `allOf`\n// member's contribution. An `if`/`then` member contributes `then.properties`\n// only when its `if` matches the current value; an unconditional member (e.g.\n// an inlined `$ref` composition, which carries its own `properties` and no\n// `if`) always contributes. Later members win on key collision; required is the\n// union. Pure and idempotent.\nexport function effectiveProperties(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n): EffectiveProperties {\n const properties: Record<string, JsonSchemaProperty> = { ...schema.properties };\n const required = new Set(schema.required ?? []);\n for (const clause of schema.allOf ?? []) {\n // Unconditional composition member: merge its own properties/required.\n if (clause.if === undefined && clause.then === undefined) {\n for (const [k, sub] of Object.entries(clause.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of clause.required ?? []) required.add(k);\n continue;\n }\n if (!matchesIf(clause.if, value)) continue;\n const then = clause.then ?? {};\n for (const [k, sub] of Object.entries(then.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of then.required ?? []) required.add(k);\n }\n return { properties, required: [...required] };\n}\n"],"names":[],"mappings":";;AAaO,SAAS,gBAAgB,MAAmC;AACjE,MAAI,CAAC,cAAc,MAAM,QAAQ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|
-
{"version":3,"file":"json-schema-form-resolve.d.ts","sourceRoot":"","sources":["../../src/components/json-schema-form-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"json-schema-form-resolve.d.ts","sourceRoot":"","sources":["../../src/components/json-schema-form-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,EAEZ,gBAAgB,EAChB,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAMlC,wBAAgB,eAAe,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAMjE;AA6CD,wBAAgB,UAAU,CAAC,IAAI,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,SAAS,CAKnF;AAYD,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACnC;AAOD,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,YAAY,CAmHrE;AAeD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,GAAG,OAAO,CAWlF;AAKD,wBAAgB,SAAS,CACvB,QAAQ,EAAE,kBAAkB,GAAG,SAAS,EACxC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAST;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC/C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAQD,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,mBAAmB,CAoBrB"}
|
|
@@ -16,21 +16,38 @@ function schemaHasType(prop, type) {
|
|
|
16
16
|
}
|
|
17
17
|
function enumOptions(prop) {
|
|
18
18
|
const labels = prop["x-enum-labels"];
|
|
19
|
+
const icons = prop["x-enum-icons"];
|
|
19
20
|
return (prop.enum ?? []).map((v) => {
|
|
20
21
|
const value = String(v);
|
|
21
22
|
const desc = labels == null ? void 0 : labels[value];
|
|
23
|
+
const icon = icons == null ? void 0 : icons[value];
|
|
22
24
|
return {
|
|
23
25
|
value,
|
|
24
|
-
label: typeof desc === "string" && desc && desc !== value ? `${desc} (${value})` : value
|
|
26
|
+
label: typeof desc === "string" && desc && desc !== value ? `${desc} (${value})` : value,
|
|
27
|
+
...typeof icon === "string" && icon ? { icon } : {}
|
|
25
28
|
};
|
|
26
29
|
});
|
|
27
30
|
}
|
|
31
|
+
function enumDisplay(prop) {
|
|
32
|
+
const d = prop["x-enum-display"];
|
|
33
|
+
if (d === "combobox" || d === "radio" || d === "grid") return d;
|
|
34
|
+
const icons = prop["x-enum-icons"];
|
|
35
|
+
if (icons && Object.keys(icons).length > 0) return "grid";
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
28
38
|
function enumBranch(prop) {
|
|
29
39
|
for (const branch of [...prop.anyOf ?? [], ...prop.oneOf ?? []]) {
|
|
30
40
|
if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;
|
|
31
41
|
}
|
|
32
42
|
return void 0;
|
|
33
43
|
}
|
|
44
|
+
function lookupDescriptor(prop) {
|
|
45
|
+
const raw = prop["x-clicky-lookup"];
|
|
46
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
47
|
+
const d = raw;
|
|
48
|
+
if (typeof d.url !== "string" || typeof d.filter !== "string") return void 0;
|
|
49
|
+
return raw;
|
|
50
|
+
}
|
|
34
51
|
function resolveControl(args) {
|
|
35
52
|
const { key, prop, required, value, onChange } = args;
|
|
36
53
|
const labelIcon = prop["x-icon"];
|
|
@@ -49,8 +66,13 @@ function resolveControl(args) {
|
|
|
49
66
|
...typeof prop.description === "string" ? { description: prop.description } : {},
|
|
50
67
|
...labelIcon != null && labelIcon !== "" ? { labelIcon } : {}
|
|
51
68
|
};
|
|
69
|
+
const lookup = lookupDescriptor(prop);
|
|
70
|
+
if (lookup) {
|
|
71
|
+
return { ...base, kind: "lookup", lookup, options: [], allowCustomValue: lookup.multi !== true };
|
|
72
|
+
}
|
|
52
73
|
if (Array.isArray(prop.enum) && prop.enum.length > 0) {
|
|
53
|
-
|
|
74
|
+
const display = enumDisplay(prop);
|
|
75
|
+
return { ...base, kind: "enum", options: enumOptions(prop), ...display ? { display } : {} };
|
|
54
76
|
}
|
|
55
77
|
const branch = enumBranch(prop);
|
|
56
78
|
if (branch) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema-form-resolve.js","sources":["../../src/components/json-schema-form-resolve.ts"],"sourcesContent":["import type {\n FieldControl,\n FieldOption,\n JsonSchemaObject,\n JsonSchemaProperty,\n} from \"./json-schema-form-types\";\n\n// isOpenStringMap reports whether a property is an object whose entries are\n// described by a sub-schema in `additionalProperties` (a typed key/value map) or\n// by `patternProperties` (a per-key-pattern value map). Either makes it an\n// editable key/value control rather than a fixed-property sub-form.\nexport function isOpenStringMap(prop: JsonSchemaProperty): boolean {\n if (!schemaHasType(prop, \"object\")) return false;\n if (typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null) {\n return true;\n }\n return !!prop.patternProperties && Object.keys(prop.patternProperties).length > 0;\n}\n\n// patternSchemasOf compiles a schema's `patternProperties` into the ordered\n// {pattern, schema} list the string-map control matches keys against.\nfunction patternSchemasOf(prop: JsonSchemaProperty): { pattern: string; schema: JsonSchemaProperty }[] | undefined {\n const pp = prop.patternProperties;\n if (!pp || Object.keys(pp).length === 0) return undefined;\n return Object.entries(pp).map(([pattern, schema]) => ({ pattern, schema }));\n}\n\nfunction schemaHasType(prop: JsonSchemaProperty, type: string): boolean {\n if (Array.isArray(prop.type)) return prop.type.includes(type as never);\n return prop.type === type;\n}\n\nfunction enumOptions(prop: JsonSchemaProperty): FieldOption[] {\n const labels = prop[\"x-enum-labels\"];\n return (prop.enum ?? []).map((v) => {\n const value = String(v);\n const desc = labels?.[value];\n return {\n value,\n label: typeof desc === \"string\" && desc && desc !== value ? `${desc} (${value})` : value,\n };\n });\n}\n\n// enumBranch returns the first anyOf/oneOf member carrying a non-empty `enum`,\n// for a union of \"an enum value OR a free-form string\" (e.g. a value-or-token\n// field). It lets such a union render as a dropdown. Returns undefined when no\n// branch enumerates values.\nexport function enumBranch(prop: JsonSchemaProperty): JsonSchemaProperty | undefined {\n for (const branch of [...(prop.anyOf ?? []), ...(prop.oneOf ?? [])]) {\n if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;\n }\n return undefined;\n}\n\nexport interface ResolveControlArgs {\n key: string;\n prop: JsonSchemaProperty;\n required: boolean;\n value: unknown;\n onChange: (next: unknown) => void;\n}\n\n// resolveControl infers a base, render-ready FieldControl from a property\n// schema. It keys off schema keywords only — never the field name: ascode/token\n// heuristics are layered on by consumer pre-extensions. The one exception is the\n// standard `format: date`/`date-time` keyword, which is a schema-declared signal\n// (not a name guess) and so drives a date control directly. First match wins.\nexport function resolveControl(args: ResolveControlArgs): FieldControl {\n const { key, prop, required, value, onChange } = args;\n const labelIcon = prop[\"x-icon\"];\n const xLayout = prop[\"x-layout\"];\n const layout =\n xLayout === \"inline\" || xLayout === \"stack\" || xLayout === \"table\" ? xLayout : undefined;\n const keyOptions = keyOptionsFor(prop);\n const base: FieldControl = {\n key,\n kind: \"string\",\n label: typeof prop.title === \"string\" && prop.title ? prop.title : key,\n required,\n schema: prop,\n value,\n onChange,\n ...(prop.readOnly === true ? { readOnly: true } : {}),\n ...(typeof prop.description === \"string\" ? { description: prop.description } : {}),\n ...(labelIcon != null && labelIcon !== \"\" ? { labelIcon: labelIcon as FieldControl[\"labelIcon\"] } : {}),\n };\n\n if (Array.isArray(prop.enum) && prop.enum.length > 0) {\n return { ...base, kind: \"enum\", options: enumOptions(prop) };\n }\n // A value-or-template union: the enum lives in an anyOf/oneOf branch alongside\n // free-form branches. Render it as a dropdown using that branch's enum; the\n // free-form branches are honoured via a consumer's allowCustomValue pre-ext.\n const branch = enumBranch(prop);\n if (branch) {\n return { ...base, kind: \"enum\", options: enumOptions(branch) };\n }\n // A schema-declared date/date-time string renders as a date control.\n if (prop.format === \"date\" || prop.format === \"date-time\") {\n return { ...base, kind: \"date\", dateFormat: prop.format };\n }\n // A long-form string declares `format: textarea` to render a multi-line box.\n if (prop.format === \"textarea\" && schemaHasType(prop, \"string\")) {\n return { ...base, kind: \"textarea\" };\n }\n if (schemaHasType(prop, \"boolean\")) {\n return { ...base, kind: \"boolean\" };\n }\n if (schemaHasType(prop, \"integer\") || schemaHasType(prop, \"number\")) {\n return {\n ...base,\n kind: \"number\",\n coerceNumber: true,\n // A percent number carries a static \"%\" unit shown inside the input.\n ...(prop.format === \"percent\" ? { unit: \"%\" } : {}),\n ...(typeof prop.minimum === \"number\" ? { minimum: prop.minimum } : {}),\n };\n }\n if (schemaHasType(prop, \"array\")) {\n return {\n ...base,\n kind: \"array\",\n ...(prop.items ? { itemSchema: prop.items } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // An open map: object whose entries are described by an additionalProperties\n // sub-schema and/or per-key patternProperties. Renders as editable key/value\n // rows (+ any known properties), with the value form resolved per key.\n if (isOpenStringMap(prop)) {\n const addl =\n typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null\n ? (prop.additionalProperties as JsonSchemaProperty)\n : undefined;\n const patterns = patternSchemasOf(prop);\n // A constrained picker (propertyNames enum) or patternProperties still lets\n // the author ADD keys — the additions are limited to the allowed set, not\n // free-form — so `additionalProperties: false` doesn't disable \"Add field\"\n // in that case. It only closes a plain open map with no key constraints.\n const allowExtraKeys = keyOptions || patterns ? true : prop.additionalProperties !== false;\n return {\n ...base,\n kind: \"string-map\",\n ...(addl ? { valueSchema: addl } : {}),\n ...(patterns ? { valuePatternSchemas: patterns } : {}),\n ...(prop.properties ? { knownProperties: prop.properties } : {}),\n allowExtraKeys,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A structured object: fixed `properties`, not an open map. Renders as a\n // nested sub-form (labels, required, if/then) — recursed into by the renderer.\n if (schemaHasType(prop, \"object\") && prop.properties) {\n return {\n ...base,\n kind: \"object\",\n objectProperties: prop.properties,\n ...(prop.required ? { objectRequired: prop.required } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A bare object with neither properties nor an additionalProperties schema:\n // treat as an open string map unless explicitly closed.\n if (schemaHasType(prop, \"object\")) {\n return {\n ...base,\n kind: \"string-map\",\n allowExtraKeys: prop.additionalProperties !== false,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n return base;\n}\n\n// keyOptionsFor resolves the strict map-key picker options from a map schema's\n// `propertyNames.enum` (e.g. an AsCode-constrained key set). Returns undefined\n// when the keys are unconstrained, so the key stays free-text.\nfunction keyOptionsFor(prop: JsonSchemaProperty): FieldOption[] | undefined {\n const pn = prop.propertyNames as JsonSchemaProperty | undefined;\n if (!pn || !Array.isArray(pn.enum) || pn.enum.length === 0) return undefined;\n return enumOptions(pn);\n}\n\n// isScalarStringItems reports whether an array's item schema is a plain string\n// with no richer shape — the case the array control renders as compact tags.\n// Anything with an enum/const/properties/items/additionalProperties/allOf needs\n// a real per-item control instead.\nexport function isScalarStringItems(items: JsonSchemaProperty | undefined): boolean {\n if (!items) return true; // untyped items default to string tags\n if (items.type !== undefined && !schemaHasType(items, \"string\")) return false;\n return (\n items.enum === undefined &&\n items.const === undefined &&\n items.properties === undefined &&\n items.items === undefined &&\n items.additionalProperties === undefined &&\n items.allOf === undefined\n );\n}\n\n// matchesIf reports whether the `if` sub-schema holds for the current value:\n// every `if.required` key is present AND every `if.properties[k].const` equals\n// value[k].\nexport function matchesIf(\n ifSchema: JsonSchemaProperty | undefined,\n value: Record<string, unknown>,\n): boolean {\n if (!ifSchema) return false;\n for (const k of ifSchema.required ?? []) {\n if (!(k in value)) return false;\n }\n for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {\n if (\"const\" in sub && value[k] !== sub.const) return false;\n }\n return true;\n}\n\nexport interface EffectiveProperties {\n properties: Record<string, JsonSchemaProperty>;\n required: string[];\n}\n\n// effectiveProperties merges the schema's base `properties` with each `allOf`\n// member's contribution. An `if`/`then` member contributes `then.properties`\n// only when its `if` matches the current value; an unconditional member (e.g.\n// an inlined `$ref` composition, which carries its own `properties` and no\n// `if`) always contributes. Later members win on key collision; required is the\n// union. Pure and idempotent.\nexport function effectiveProperties(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n): EffectiveProperties {\n const properties: Record<string, JsonSchemaProperty> = { ...schema.properties };\n const required = new Set(schema.required ?? []);\n for (const clause of schema.allOf ?? []) {\n // Unconditional composition member: merge its own properties/required.\n if (clause.if === undefined && clause.then === undefined) {\n for (const [k, sub] of Object.entries(clause.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of clause.required ?? []) required.add(k);\n continue;\n }\n if (!matchesIf(clause.if, value)) continue;\n const then = clause.then ?? {};\n for (const [k, sub] of Object.entries(then.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of then.required ?? []) required.add(k);\n }\n return { properties, required: [...required] };\n}\n"],"names":[],"mappings":"AAWO,SAAS,gBAAgB,MAAmC;AACjE,MAAI,CAAC,cAAc,MAAM,QAAQ,EAAG,QAAO;AAC3C,MAAI,OAAO,KAAK,yBAAyB,YAAY,KAAK,yBAAyB,MAAM;AACvF,WAAO;AAAA,EACT;AACA,SAAO,CAAC,CAAC,KAAK,qBAAqB,OAAO,KAAK,KAAK,iBAAiB,EAAE,SAAS;AAClF;AAIA,SAAS,iBAAiB,MAAyF;AACjH,QAAM,KAAK,KAAK;AAChB,MAAI,CAAC,MAAM,OAAO,KAAK,EAAE,EAAE,WAAW,EAAG,QAAO;AAChD,SAAO,OAAO,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC,SAAS,MAA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AAY,UAAU,CAAC,GAAG,QAAQ,EAAA;AAC7C;"}
|
|
1
|
+
{"version":3,"file":"json-schema-form-resolve.js","sources":["../../src/components/json-schema-form-resolve.ts"],"sourcesContent":["import type {\n EnumDisplay,\n FieldControl,\n FieldOption,\n JsonSchemaObject,\n JsonSchemaProperty,\n LookupDescriptor,\n} from \"./json-schema-form-types\";\n\n// isOpenStringMap reports whether a property is an object whose entries are\n// described by a sub-schema in `additionalProperties` (a typed key/value map) or\n// by `patternProperties` (a per-key-pattern value map). Either makes it an\n// editable key/value control rather than a fixed-property sub-form.\nexport function isOpenStringMap(prop: JsonSchemaProperty): boolean {\n if (!schemaHasType(prop, \"object\")) return false;\n if (typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null) {\n return true;\n }\n return !!prop.patternProperties && Object.keys(prop.patternProperties).length > 0;\n}\n\n// patternSchemasOf compiles a schema's `patternProperties` into the ordered\n// {pattern, schema} list the string-map control matches keys against.\nfunction patternSchemasOf(prop: JsonSchemaProperty): { pattern: string; schema: JsonSchemaProperty }[] | undefined {\n const pp = prop.patternProperties;\n if (!pp || Object.keys(pp).length === 0) return undefined;\n return Object.entries(pp).map(([pattern, schema]) => ({ pattern, schema }));\n}\n\nfunction schemaHasType(prop: JsonSchemaProperty, type: string): boolean {\n if (Array.isArray(prop.type)) return prop.type.includes(type as never);\n return prop.type === type;\n}\n\nfunction enumOptions(prop: JsonSchemaProperty): FieldOption[] {\n const labels = prop[\"x-enum-labels\"];\n const icons = prop[\"x-enum-icons\"];\n return (prop.enum ?? []).map((v) => {\n const value = String(v);\n const desc = labels?.[value];\n const icon = icons?.[value];\n return {\n value,\n label: typeof desc === \"string\" && desc && desc !== value ? `${desc} (${value})` : value,\n ...(typeof icon === \"string\" && icon ? { icon } : {}),\n };\n });\n}\n\n// enumDisplay resolves how an enum should render: an explicit `x-enum-display`\n// wins; otherwise an enum carrying `x-enum-icons` defaults to the icon grid.\n// Returns undefined to keep the combobox default.\nfunction enumDisplay(prop: JsonSchemaProperty): EnumDisplay | undefined {\n const d = prop[\"x-enum-display\"];\n if (d === \"combobox\" || d === \"radio\" || d === \"grid\") return d;\n const icons = prop[\"x-enum-icons\"];\n if (icons && Object.keys(icons).length > 0) return \"grid\";\n return undefined;\n}\n\n// enumBranch returns the first anyOf/oneOf member carrying a non-empty `enum`,\n// for a union of \"an enum value OR a free-form string\" (e.g. a value-or-token\n// field). It lets such a union render as a dropdown. Returns undefined when no\n// branch enumerates values.\nexport function enumBranch(prop: JsonSchemaProperty): JsonSchemaProperty | undefined {\n for (const branch of [...(prop.anyOf ?? []), ...(prop.oneOf ?? [])]) {\n if (Array.isArray(branch.enum) && branch.enum.length > 0) return branch;\n }\n return undefined;\n}\n\n// lookupDescriptor reads the `x-clicky-lookup` extension into a LookupDescriptor,\n// returning undefined when the keyword is absent or lacks its required url/filter.\nfunction lookupDescriptor(prop: JsonSchemaProperty): LookupDescriptor | undefined {\n const raw = prop[\"x-clicky-lookup\"];\n if (!raw || typeof raw !== \"object\") return undefined;\n const d = raw as Record<string, unknown>;\n if (typeof d.url !== \"string\" || typeof d.filter !== \"string\") return undefined;\n return raw as LookupDescriptor;\n}\n\nexport interface ResolveControlArgs {\n key: string;\n prop: JsonSchemaProperty;\n required: boolean;\n value: unknown;\n onChange: (next: unknown) => void;\n}\n\n// resolveControl infers a base, render-ready FieldControl from a property\n// schema. It keys off schema keywords only — never the field name: ascode/token\n// heuristics are layered on by consumer pre-extensions. The one exception is the\n// standard `format: date`/`date-time` keyword, which is a schema-declared signal\n// (not a name guess) and so drives a date control directly. First match wins.\nexport function resolveControl(args: ResolveControlArgs): FieldControl {\n const { key, prop, required, value, onChange } = args;\n const labelIcon = prop[\"x-icon\"];\n const xLayout = prop[\"x-layout\"];\n const layout =\n xLayout === \"inline\" || xLayout === \"stack\" || xLayout === \"table\" ? xLayout : undefined;\n const keyOptions = keyOptionsFor(prop);\n const base: FieldControl = {\n key,\n kind: \"string\",\n label: typeof prop.title === \"string\" && prop.title ? prop.title : key,\n required,\n schema: prop,\n value,\n onChange,\n ...(prop.readOnly === true ? { readOnly: true } : {}),\n ...(typeof prop.description === \"string\" ? { description: prop.description } : {}),\n ...(labelIcon != null && labelIcon !== \"\" ? { labelIcon: labelIcon as FieldControl[\"labelIcon\"] } : {}),\n };\n\n // An `x-clicky-lookup` field is an async entity-reference picker: options load\n // lazily from another entity's list endpoint. Single-select also allows\n // free-form entry so a typed value outside the option set still commits.\n const lookup = lookupDescriptor(prop);\n if (lookup) {\n return { ...base, kind: \"lookup\", lookup, options: [], allowCustomValue: lookup.multi !== true };\n }\n if (Array.isArray(prop.enum) && prop.enum.length > 0) {\n const display = enumDisplay(prop);\n return { ...base, kind: \"enum\", options: enumOptions(prop), ...(display ? { display } : {}) };\n }\n // A value-or-template union: the enum lives in an anyOf/oneOf branch alongside\n // free-form branches. Render it as a dropdown using that branch's enum; the\n // free-form branches are honoured via a consumer's allowCustomValue pre-ext.\n const branch = enumBranch(prop);\n if (branch) {\n return { ...base, kind: \"enum\", options: enumOptions(branch) };\n }\n // A schema-declared date/date-time string renders as a date control.\n if (prop.format === \"date\" || prop.format === \"date-time\") {\n return { ...base, kind: \"date\", dateFormat: prop.format };\n }\n // A long-form string declares `format: textarea` to render a multi-line box.\n if (prop.format === \"textarea\" && schemaHasType(prop, \"string\")) {\n return { ...base, kind: \"textarea\" };\n }\n if (schemaHasType(prop, \"boolean\")) {\n return { ...base, kind: \"boolean\" };\n }\n if (schemaHasType(prop, \"integer\") || schemaHasType(prop, \"number\")) {\n return {\n ...base,\n kind: \"number\",\n coerceNumber: true,\n // A percent number carries a static \"%\" unit shown inside the input.\n ...(prop.format === \"percent\" ? { unit: \"%\" } : {}),\n ...(typeof prop.minimum === \"number\" ? { minimum: prop.minimum } : {}),\n };\n }\n if (schemaHasType(prop, \"array\")) {\n return {\n ...base,\n kind: \"array\",\n ...(prop.items ? { itemSchema: prop.items } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // An open map: object whose entries are described by an additionalProperties\n // sub-schema and/or per-key patternProperties. Renders as editable key/value\n // rows (+ any known properties), with the value form resolved per key.\n if (isOpenStringMap(prop)) {\n const addl =\n typeof prop.additionalProperties === \"object\" && prop.additionalProperties !== null\n ? (prop.additionalProperties as JsonSchemaProperty)\n : undefined;\n const patterns = patternSchemasOf(prop);\n // A constrained picker (propertyNames enum) or patternProperties still lets\n // the author ADD keys — the additions are limited to the allowed set, not\n // free-form — so `additionalProperties: false` doesn't disable \"Add field\"\n // in that case. It only closes a plain open map with no key constraints.\n const allowExtraKeys = keyOptions || patterns ? true : prop.additionalProperties !== false;\n return {\n ...base,\n kind: \"string-map\",\n ...(addl ? { valueSchema: addl } : {}),\n ...(patterns ? { valuePatternSchemas: patterns } : {}),\n ...(prop.properties ? { knownProperties: prop.properties } : {}),\n allowExtraKeys,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A structured object: fixed `properties`, not an open map. Renders as a\n // nested sub-form (labels, required, if/then) — recursed into by the renderer.\n if (schemaHasType(prop, \"object\") && prop.properties) {\n return {\n ...base,\n kind: \"object\",\n objectProperties: prop.properties,\n ...(prop.required ? { objectRequired: prop.required } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n // A bare object with neither properties nor an additionalProperties schema:\n // treat as an open string map unless explicitly closed.\n if (schemaHasType(prop, \"object\")) {\n return {\n ...base,\n kind: \"string-map\",\n allowExtraKeys: prop.additionalProperties !== false,\n ...(keyOptions ? { keyOptions } : {}),\n ...(layout ? { layout } : {}),\n };\n }\n return base;\n}\n\n// keyOptionsFor resolves the strict map-key picker options from a map schema's\n// `propertyNames.enum` (e.g. an AsCode-constrained key set). Returns undefined\n// when the keys are unconstrained, so the key stays free-text.\nfunction keyOptionsFor(prop: JsonSchemaProperty): FieldOption[] | undefined {\n const pn = prop.propertyNames as JsonSchemaProperty | undefined;\n if (!pn || !Array.isArray(pn.enum) || pn.enum.length === 0) return undefined;\n return enumOptions(pn);\n}\n\n// isScalarStringItems reports whether an array's item schema is a plain string\n// with no richer shape — the case the array control renders as compact tags.\n// Anything with an enum/const/properties/items/additionalProperties/allOf needs\n// a real per-item control instead.\nexport function isScalarStringItems(items: JsonSchemaProperty | undefined): boolean {\n if (!items) return true; // untyped items default to string tags\n if (items.type !== undefined && !schemaHasType(items, \"string\")) return false;\n return (\n items.enum === undefined &&\n items.const === undefined &&\n items.properties === undefined &&\n items.items === undefined &&\n items.additionalProperties === undefined &&\n items.allOf === undefined\n );\n}\n\n// matchesIf reports whether the `if` sub-schema holds for the current value:\n// every `if.required` key is present AND every `if.properties[k].const` equals\n// value[k].\nexport function matchesIf(\n ifSchema: JsonSchemaProperty | undefined,\n value: Record<string, unknown>,\n): boolean {\n if (!ifSchema) return false;\n for (const k of ifSchema.required ?? []) {\n if (!(k in value)) return false;\n }\n for (const [k, sub] of Object.entries(ifSchema.properties ?? {})) {\n if (\"const\" in sub && value[k] !== sub.const) return false;\n }\n return true;\n}\n\nexport interface EffectiveProperties {\n properties: Record<string, JsonSchemaProperty>;\n required: string[];\n}\n\n// effectiveProperties merges the schema's base `properties` with each `allOf`\n// member's contribution. An `if`/`then` member contributes `then.properties`\n// only when its `if` matches the current value; an unconditional member (e.g.\n// an inlined `$ref` composition, which carries its own `properties` and no\n// `if`) always contributes. Later members win on key collision; required is the\n// union. Pure and idempotent.\nexport function effectiveProperties(\n schema: JsonSchemaObject,\n value: Record<string, unknown>,\n): EffectiveProperties {\n const properties: Record<string, JsonSchemaProperty> = { ...schema.properties };\n const required = new Set(schema.required ?? []);\n for (const clause of schema.allOf ?? []) {\n // Unconditional composition member: merge its own properties/required.\n if (clause.if === undefined && clause.then === undefined) {\n for (const [k, sub] of Object.entries(clause.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of clause.required ?? []) required.add(k);\n continue;\n }\n if (!matchesIf(clause.if, value)) continue;\n const then = clause.then ?? {};\n for (const [k, sub] of Object.entries(then.properties ?? {})) {\n properties[k] = sub;\n }\n for (const k of then.required ?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AC;AAAA,EACrD;AACA,SAAO,EAAE,YAAY,UAAU,CAAC,GAAG,QAAQ,EAAA;AAC7C;"}
|
|
@@ -26,6 +26,9 @@ export interface JsonSchemaProperty {
|
|
|
26
26
|
else?: JsonSchemaProperty;
|
|
27
27
|
"x-order"?: string[];
|
|
28
28
|
"x-enum-labels"?: Record<string, string>;
|
|
29
|
+
"x-enum-icons"?: Record<string, string>;
|
|
30
|
+
"x-enum-display"?: EnumDisplay;
|
|
31
|
+
"x-clicky-order"?: number;
|
|
29
32
|
[key: string]: unknown;
|
|
30
33
|
}
|
|
31
34
|
export type JsonSchemaType = "object" | "array" | "string" | "integer" | "number" | "boolean" | "null";
|
|
@@ -43,10 +46,11 @@ export interface JsonSchemaObject extends JsonSchemaProperty {
|
|
|
43
46
|
required?: string[];
|
|
44
47
|
additionalProperties?: boolean | JsonSchemaProperty;
|
|
45
48
|
allOf?: JsonSchemaConditional[];
|
|
49
|
+
"x-discriminator"?: string;
|
|
46
50
|
}
|
|
47
|
-
export type FieldControlKind = "string" | "number" | "boolean" | "enum" | "date" | "string-map" | "array" | "object" | "textarea" | "display" | "link";
|
|
51
|
+
export type FieldControlKind = "string" | "number" | "boolean" | "enum" | "lookup" | "date" | "string-map" | "array" | "object" | "textarea" | "display" | "link";
|
|
48
52
|
export type DisplayVariant = "heading" | "text" | "divider" | "spacer";
|
|
49
|
-
export type EnumDisplay = "combobox" | "radio";
|
|
53
|
+
export type EnumDisplay = "combobox" | "radio" | "grid";
|
|
50
54
|
export interface FieldControl {
|
|
51
55
|
key: string;
|
|
52
56
|
kind: FieldControlKind;
|
|
@@ -60,6 +64,8 @@ export interface FieldControl {
|
|
|
60
64
|
labelIcon?: LabelIconSpec;
|
|
61
65
|
options?: FieldOption[];
|
|
62
66
|
allowCustomValue?: boolean;
|
|
67
|
+
lookup?: LookupDescriptor;
|
|
68
|
+
loading?: boolean;
|
|
63
69
|
display?: EnumDisplay;
|
|
64
70
|
badge?: string;
|
|
65
71
|
helper?: string;
|
|
@@ -87,15 +93,37 @@ export interface FieldControl {
|
|
|
87
93
|
export interface FieldOption {
|
|
88
94
|
value: string;
|
|
89
95
|
label: string;
|
|
96
|
+
icon?: LabelIconSpec;
|
|
90
97
|
}
|
|
98
|
+
export interface LookupDescriptor {
|
|
99
|
+
url: string;
|
|
100
|
+
filter: string;
|
|
101
|
+
searchParam?: string;
|
|
102
|
+
multi?: boolean;
|
|
103
|
+
scope?: LookupScope;
|
|
104
|
+
}
|
|
105
|
+
export interface LookupScope {
|
|
106
|
+
param: string;
|
|
107
|
+
from: string;
|
|
108
|
+
map?: Record<string, string[]>;
|
|
109
|
+
join?: string;
|
|
110
|
+
}
|
|
111
|
+
export type LookupFetcher = (args: {
|
|
112
|
+
descriptor: LookupDescriptor;
|
|
113
|
+
query: string;
|
|
114
|
+
rootValue?: Record<string, unknown>;
|
|
115
|
+
}) => Promise<FieldOption[]>;
|
|
91
116
|
export type PreExtension = (field: FieldControl, ctx: {
|
|
92
117
|
key: string;
|
|
93
118
|
prop: JsonSchemaProperty;
|
|
94
119
|
value: unknown;
|
|
120
|
+
rootValue?: Record<string, unknown>;
|
|
95
121
|
}) => FieldControl | null;
|
|
96
122
|
export type PostExtension = (field: FieldControl, nodes: {
|
|
97
123
|
label: ReactNode;
|
|
98
124
|
value: ReactNode;
|
|
125
|
+
}, ctx?: {
|
|
126
|
+
rootValue?: Record<string, unknown>;
|
|
99
127
|
}) => {
|
|
100
128
|
label: ReactNode;
|
|
101
129
|
value: ReactNode;
|
|
@@ -128,6 +156,7 @@ export interface RenderContext {
|
|
|
128
156
|
sortMode: SortMode;
|
|
129
157
|
pre: PreExtension[];
|
|
130
158
|
post: PostExtension[];
|
|
159
|
+
rootValue?: Record<string, unknown>;
|
|
131
160
|
depth: number;
|
|
132
161
|
render: RenderApi;
|
|
133
162
|
}
|
|
@@ -189,6 +218,12 @@ export interface JsonSchemaFormProps {
|
|
|
189
218
|
title?: string;
|
|
190
219
|
pre?: PreExtension[];
|
|
191
220
|
post?: PostExtension[];
|
|
221
|
+
/**
|
|
222
|
+
* Resolves options for `x-clicky-lookup` fields (async entity-reference
|
|
223
|
+
* pickers). When set, the form provides it to its lookup controls via context.
|
|
224
|
+
* Hosts typically build it from the operations api client's lookup endpoint.
|
|
225
|
+
*/
|
|
226
|
+
lookupFetcher?: LookupFetcher;
|
|
192
227
|
/**
|
|
193
228
|
* Show the top-right three-dot display-options menu (size, layout, and sort).
|
|
194
229
|
* Defaults to true. The menu controls only this form's appearance — never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema-form-types.d.ts","sourceRoot":"","sources":["../../src/components/json-schema-form-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAK/D,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAEpB,oBAAoB,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CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC;IACrB,IAAI,CAAC,EAAE,aAAa,EAAE,CAAC;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -39,6 +39,13 @@ function orderByXOrder(entries, order) {
|
|
|
39
39
|
const rest = entries.filter(([key]) => !rank.has(key));
|
|
40
40
|
return [...listed, ...rest];
|
|
41
41
|
}
|
|
42
|
+
function orderByClickyOrder(entries) {
|
|
43
|
+
const rank = (prop) => {
|
|
44
|
+
const o = prop["x-clicky-order"];
|
|
45
|
+
return typeof o === "number" ? o : Number.POSITIVE_INFINITY;
|
|
46
|
+
};
|
|
47
|
+
return entries.map((entry, index) => ({ entry, index, rank: rank(entry[1]) })).sort((a, b) => a.rank - b.rank || a.index - b.index).map((ranked) => ranked.entry);
|
|
48
|
+
}
|
|
42
49
|
function orderRequiredFirst(entries, required) {
|
|
43
50
|
const isRequired = new Set(required);
|
|
44
51
|
const head = entries.filter(([key]) => isRequired.has(key));
|
|
@@ -97,6 +104,7 @@ exports.isEmptyValue = isEmptyValue;
|
|
|
97
104
|
exports.isPlainObject = isPlainObject;
|
|
98
105
|
exports.keyPickerOptions = keyPickerOptions;
|
|
99
106
|
exports.moveItem = moveItem;
|
|
107
|
+
exports.orderByClickyOrder = orderByClickyOrder;
|
|
100
108
|
exports.orderByPriority = orderByPriority;
|
|
101
109
|
exports.orderByXOrder = orderByXOrder;
|
|
102
110
|
exports.orderRequiredFirst = orderRequiredFirst;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema-form-utils.cjs","sources":["../../src/components/json-schema-form-utils.ts"],"sourcesContent":["import { cn } from \"../lib/utils\";\nimport { inputSizeClass, type FormSize } from \"./json-schema-form-size\";\nimport type { FieldControl, FieldOption, JsonSchemaProperty } from \"./json-schema-form-types\";\n\n// Non-size styling shared by every text-like input box; the size token supplies\n// height, horizontal padding, and text size (see inputSizeClass).\nconst INPUT_BASE =\n \"w-full min-w-0 rounded-md border border-input bg-background text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring\";\n\nexport function inputClass(size: FormSize): string {\n return cn(INPUT_BASE, inputSizeClass[size]);\n}\n\nexport function fieldInputId(key: string, prefix?: string): string {\n const safe = key.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n return prefix ? `jsf-${prefix}-${safe}` : `jsf-${safe}`;\n}\n\nexport function defaultPlaceholder(schema: JsonSchemaProperty): string {\n if (schema.default != null && typeof schema.default !== \"object\") return String(schema.default);\n return \"\";\n}\n\nexport function toText(value: unknown): string {\n if (value === undefined || value === null) return \"\";\n if (typeof value === \"object\") return \"\";\n return String(value);\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n// withSyntheticValue prepends the current value as an option when it is not in\n// the enum, so an out-of-enum value (e.g. a template token) still displays.\nexport function withSyntheticValue(options: FieldOption[], value: string): FieldOption[] {\n if (!value || options.some((o) => o.value === value)) return options;\n return [{ value, label: value }, ...options];\n}\n\n// keyPickerOptions narrows the map-key enum to keys not already used by another\n// entry, while always keeping this row's current key so it stays selectable.\nexport function keyPickerOptions(\n options: FieldOption[],\n usedKeys: string[],\n currentKey: string,\n): FieldOption[] {\n const taken = new Set(usedKeys.filter((k) => k !== currentKey));\n return options.filter((o) => !taken.has(o.value));\n}\n\n// orderByXOrder reorders property entries by the schema's `x-order` hint: keys\n// named there render first (in that order), the rest keep document order. A\n// missing/empty hint is a no-op, so document order remains the default.\nexport function orderByXOrder<T>(entries: [string, T][], order: unknown): [string, T][] {\n if (!Array.isArray(order) || order.length === 0) return entries;\n const rank = new Map(\n order.filter((k): k is string => typeof k === \"string\").map((k, i) => [k, i]),\n );\n const listed = entries\n .filter(([key]) => rank.has(key))\n .sort((a, b) => rank.get(a[0])! - rank.get(b[0])!);\n const rest = entries.filter(([key]) => !rank.has(key));\n return [...listed, ...rest];\n}\n\n// orderRequiredFirst stably partitions property entries so the keys named in\n// `required` come first (in their original order), then the rest (in theirs).\n// A stable two-pass partition, so it never reshuffles within either group.\nexport function orderRequiredFirst<T>(\n entries: [string, T][],\n required: string[],\n): [string, T][] {\n const isRequired = new Set(required);\n const head = entries.filter(([key]) => isRequired.has(key));\n const tail = entries.filter(([key]) => !isRequired.has(key));\n return [...head, ...tail];\n}\n\n// isEmptyValue reports whether a field's value carries no data, so priority\n// sorting can sink unfilled fields. Empty = undefined/null/\"\" plus empty arrays\n// and empty plain objects; `false` and `0` count as filled (they are choices).\nexport function isEmptyValue(value: unknown): boolean {\n if (value === undefined || value === null || value === \"\") return true;\n if (Array.isArray(value)) return value.length === 0;\n if (typeof value === \"object\") return Object.keys(value).length === 0;\n return false;\n}\n\n// orderByPriority sorts property entries so the fields that matter most surface\n// first, ranking each by a score: +2 if required, +1 if its value is non-empty.\n// Required-and-filled lead, then required-and-empty, then optional-and-filled,\n// then optional-and-empty. Ties keep their incoming order (explicit index\n// tie-break, so it does not depend on the engine's sort stability).\nexport function orderByPriority<T>(\n entries: [string, T][],\n required: string[],\n values: Record<string, unknown>,\n): [string, T][] {\n const isRequired = new Set(required);\n const score = (key: string): number =>\n (isRequired.has(key) ? 2 : 0) + (isEmptyValue(values[key]) ? 0 : 1);\n return entries\n .map((entry, index) => ({ entry, index, score: score(entry[0]) }))\n .sort((a, b) => b.score - a.score || a.index - b.index)\n .map((ranked) => ranked.entry);\n}\n\n// softError computes a display-only validation hint. It never blocks onChange.\n// Consumers suppress the unknown-enum hint by setting allowCustomValue.\nexport function softError(field: FieldControl): string | undefined {\n const v = field.value;\n const isEmpty = v === undefined || v === null || v === \"\";\n if (field.required && isEmpty) return \"Required\";\n\n if (field.kind === \"number\" && typeof field.minimum === \"number\" && typeof v === \"number\") {\n if (v < field.minimum) return `Must be ≥ ${field.minimum}`;\n }\n\n if (field.kind === \"enum\" && !field.allowCustomValue && !isEmpty) {\n const known = (field.options ?? []).some((o) => o.value === String(v));\n if (!known) return \"Unknown value (allowed)\";\n }\n return undefined;\n}\n\n// Immutable array helpers used by the array control.\nexport function setIndex<T>(arr: T[], i: number, v: T): T[] {\n return arr.map((x, idx) => (idx === i ? v : x));\n}\n\nexport function removeIndex<T>(arr: T[], i: number): T[] {\n return arr.filter((_, idx) => idx !== i);\n}\n\nexport function moveItem<T>(arr: T[], from: number, to: number): T[] {\n if (to < 0 || to >= arr.length) return arr;\n const next = [...arr];\n const [moved] = next.splice(from, 1);\n next.splice(to, 0, moved as T);\n return next;\n}\n\n// seedFromSchema produces the initial value for a freshly-added array item or\n// object field, honouring an explicit default.\nexport function seedFromSchema(schema: JsonSchemaProperty): unknown {\n if (schema.default !== undefined) return schema.default;\n const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;\n if (type === \"array\") return [];\n if (type === \"object\") return {};\n if (type === \"boolean\") return false;\n // Numbers seed as \"\" so the soft Required hint can show without coercion\n // surprises; the number control coerces on first real input.\n return \"\";\n}\n"],"names":["cn","inputSizeClass"],"mappings":";;;;AAMA,MAAM,aACJ;AAEK,SAAS,WAAW,MAAwB;AACjD,SAAOA,SAAG,YAAYC,mBAAAA,eAAe,IAAI,CAAC;AAC5C;AAEO,SAAS,aAAa,KAAa,QAAyB;AACjE,QAAM,OAAO,IAAI,QAAQ,mBAAmB,GAAG;AAC/C,SAAO,SAAS,OAAO,MAAM,IAAI,IAAI,KAAK,OAAO,IAAI;AACvD;AAEO,SAAS,mBAAmB,QAAoC;AACrE,MAAI,OAAO,WAAW,QAAQ,OAAO,OAAO,YAAY,SAAU,QAAO,OAAO,OAAO,OAAO;AAC9F,SAAO;AACT;AAEO,SAAS,OAAO,OAAwB;AAC7C,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,SAAO,OAAO,KAAK;AACrB;AAEO,SAAS,cAAc,OAAkD;AAC9E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAIO,SAAS,mBAAmB,SAAwB,OAA8B;AACvF,MAAI,CAAC,SAAS,QAAQ,KAAK,CAAC,MAAM,EAAE,UAAU,KAAK,EAAG,QAAO;AAC7D,SAAO,CAAC,EAAE,OAAO,OAAO,MAAA,GAAS,GAAG,OAAO;AAC7C;AAIO,SAAS,iBACd,SACA,UACA,YACe;AACf,QAAM,QAAQ,IAAI,IAAI,SAAS,OAAO,CAAC,MAAM,MAAM,UAAU,CAAC;AAC9D,SAAO,QAAQ,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EA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O;AAChD,QAAM,OAAO,MAAM,QAAQ,OAAO,IAAI,IAAI,OAAO,KAAK,CAAC,IAAI,OAAO;AAClE,MAAI,SAAS,QAAS,QAAO,CAAA;AAC7B,MAAI,SAAS,SAAU,QAAO,CAAA;AAC9B,MAAI,SAAS,UAAW,QAAO;AAG/B,SAAO;AACT;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"json-schema-form-utils.cjs","sources":["../../src/components/json-schema-form-utils.ts"],"sourcesContent":["import { cn } from \"../lib/utils\";\nimport { inputSizeClass, type FormSize } from \"./json-schema-form-size\";\nimport type { FieldControl, FieldOption, JsonSchemaProperty } from \"./json-schema-form-types\";\n\n// Non-size styling shared by every text-like input box; the size token supplies\n// height, horizontal padding, and text size (see inputSizeClass).\nconst INPUT_BASE =\n \"w-full min-w-0 rounded-md border border-input bg-background text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring\";\n\nexport function inputClass(size: FormSize): string {\n return cn(INPUT_BASE, inputSizeClass[size]);\n}\n\nexport function fieldInputId(key: string, prefix?: string): string {\n const safe = key.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n return prefix ? `jsf-${prefix}-${safe}` : `jsf-${safe}`;\n}\n\nexport function defaultPlaceholder(schema: JsonSchemaProperty): string {\n if (schema.default != null && typeof schema.default !== \"object\") return String(schema.default);\n return \"\";\n}\n\nexport function toText(value: unknown): string {\n if (value === undefined || value === null) return \"\";\n if (typeof value === \"object\") return \"\";\n return String(value);\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n// withSyntheticValue prepends the current value as an option when it is not in\n// the enum, so an out-of-enum value (e.g. a template token) still displays.\nexport function withSyntheticValue(options: FieldOption[], value: string): FieldOption[] {\n if (!value || options.some((o) => o.value === value)) return options;\n return [{ value, label: value }, ...options];\n}\n\n// keyPickerOptions narrows the map-key enum to keys not already used by another\n// entry, while always keeping this row's current key so it stays selectable.\nexport function keyPickerOptions(\n options: FieldOption[],\n usedKeys: string[],\n currentKey: string,\n): FieldOption[] {\n const taken = new Set(usedKeys.filter((k) => k !== currentKey));\n return options.filter((o) => !taken.has(o.value));\n}\n\n// orderByXOrder reorders property entries by the schema's `x-order` hint: keys\n// named there render first (in that order), the rest keep document order. A\n// missing/empty hint is a no-op, so document order remains the default.\nexport function orderByXOrder<T>(entries: [string, T][], order: unknown): [string, T][] {\n if (!Array.isArray(order) || order.length === 0) return entries;\n const rank = new Map(\n order.filter((k): k is string => typeof k === \"string\").map((k, i) => [k, i]),\n );\n const listed = entries\n .filter(([key]) => rank.has(key))\n .sort((a, b) => rank.get(a[0])! - rank.get(b[0])!);\n const rest = entries.filter(([key]) => !rank.has(key));\n return [...listed, ...rest];\n}\n\n// orderByClickyOrder stably sorts property entries by each property's numeric\n// `x-clicky-order` (lower first); entries without it keep their incoming order\n// after the ordered ones. An explicit index tie-break keeps it stable regardless\n// of the engine's sort stability. Unlike the object-level `x-order` array, this\n// composes across merged if/then branches because each property carries its own\n// order — the right tool when fields come from different (embedded) sources.\nexport function orderByClickyOrder(\n entries: [string, JsonSchemaProperty][],\n): [string, JsonSchemaProperty][] {\n const rank = (prop: JsonSchemaProperty): number => {\n const o = prop[\"x-clicky-order\"];\n return typeof o === \"number\" ? o : Number.POSITIVE_INFINITY;\n };\n return entries\n .map((entry, index) => ({ entry, index, rank: rank(entry[1]) }))\n .sort((a, b) => a.rank - b.rank || a.index - b.index)\n .map((ranked) => ranked.entry);\n}\n\n// orderRequiredFirst stably partitions property entries so the keys named in\n// `required` come first (in their original order), then the rest (in theirs).\n// A stable two-pass partition, so it never reshuffles within either group.\nexport function orderRequiredFirst<T>(\n entries: [string, T][],\n required: string[],\n): [string, T][] {\n const isRequired = new Set(required);\n const head = entries.filter(([key]) => isRequired.has(key));\n const tail = entries.filter(([key]) => !isRequired.has(key));\n return [...head, ...tail];\n}\n\n// isEmptyValue reports whether a field's value carries no data, so priority\n// sorting can sink unfilled fields. Empty = undefined/null/\"\" plus empty arrays\n// and empty plain objects; `false` and `0` count as filled (they are choices).\nexport function isEmptyValue(value: unknown): boolean {\n if (value === undefined || value === null || value === \"\") return true;\n if (Array.isArray(value)) return value.length === 0;\n if (typeof value === \"object\") return Object.keys(value).length === 0;\n return false;\n}\n\n// orderByPriority sorts property entries so the fields that matter most surface\n// first, ranking each by a score: +2 if required, +1 if its value is non-empty.\n// Required-and-filled lead, then required-and-empty, then optional-and-filled,\n// then optional-and-empty. Ties keep their incoming order (explicit index\n// tie-break, so it does not depend on the engine's sort stability).\nexport function orderByPriority<T>(\n entries: [string, T][],\n required: string[],\n values: Record<string, unknown>,\n): [string, T][] {\n const isRequired = new Set(required);\n const score = (key: string): number =>\n (isRequired.has(key) ? 2 : 0) + (isEmptyValue(values[key]) ? 0 : 1);\n return entries\n .map((entry, index) => ({ entry, index, score: score(entry[0]) }))\n .sort((a, b) => b.score - a.score || a.index - b.index)\n .map((ranked) => ranked.entry);\n}\n\n// softError computes a display-only validation hint. It never blocks onChange.\n// Consumers suppress the unknown-enum hint by setting allowCustomValue.\nexport function softError(field: FieldControl): string | undefined {\n const v = field.value;\n const isEmpty = v === undefined || v === null || v === \"\";\n if (field.required && isEmpty) return \"Required\";\n\n if (field.kind === \"number\" && typeof field.minimum === \"number\" && typeof v === \"number\") {\n if (v < field.minimum) return `Must be ≥ ${field.minimum}`;\n }\n\n if (field.kind === \"enum\" && !field.allowCustomValue && !isEmpty) {\n const known = (field.options ?? []).some((o) => o.value === String(v));\n if (!known) return \"Unknown value (allowed)\";\n }\n return undefined;\n}\n\n// Immutable array helpers used by the array control.\nexport function setIndex<T>(arr: T[], i: number, v: T): T[] {\n return arr.map((x, idx) => (idx === i ? v : x));\n}\n\nexport function removeIndex<T>(arr: T[], i: number): T[] {\n return arr.filter((_, idx) => idx !== i);\n}\n\nexport function moveItem<T>(arr: T[], from: number, to: number): T[] {\n if (to < 0 || to >= arr.length) return arr;\n const next = [...arr];\n const [moved] = next.splice(from, 1);\n next.splice(to, 0, moved as T);\n return next;\n}\n\n// seedFromSchema produces the initial value for a freshly-added array item or\n// object field, honouring an explicit default.\nexport function seedFromSchema(schema: JsonSchemaProperty): unknown {\n if (schema.default !== undefined) return schema.default;\n const type = Array.isArray(schema.type) ? schema.type[0] : schema.type;\n if (type === \"array\") return [];\n if (type === \"object\") return {};\n if (type === \"boolean\") return false;\n // Numbers seed as \"\" so the soft Required hint can show without coercion\n // surprises; the number control coerces on first real input.\n return \"\";\n}\n"],"names":["cn","inputSizeClass"],"mappings":";;;;AAMA,MAAM,aACJ;AAEK,SAAS,WAAW,MAAwB;AACjD,SAAOA,SAAG,YAAYC,mBAAAA,eAAe,IAAI,CAAC;AAC5C;AAEO,SAAS,aAAa,KAAa,QAAyB;AACjE,QAAM,OAAO,IAAI,QAAQ,mBAAmB,GAAG;AAC/C,SAAO,SAAS,OAAO,MAAM,IAAI,IAAI,KAAK,OAAO,IAAI;AACvD;AAEO,SAAS,mBAAmB,QAAoC;AACrE,MAAI,OAAO,WAAW,QAAQ,OAAO,OAAO,YAAY,SAAU,QAAO,OAAO,OAAO,OAAO;AAC9F,SAAO;AACT;AAEO,SAAS,OAAO,OAAwB;AAC7C,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,SAAO,OAAO,KAAK;AACrB;AAEO,SAAS,cAAc,OAAkD;AAC9E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAIO,SAAS,mBAAmB,SAAwB,OAA8B;AACvF,MAAI,CAAC,SAAS,QAAQ,KAAK,CAAC,MAAM,EAAE,UAAU,KAAK,EAAG,QAAO;AAC7D,SAAO,CAAC,EAAE,OAAO,OAAO,MAAA,GAAS,GAAG,OAAO;AAC7C;AAIO,SAAS,iBACd,SACA,UACA,YACe;AACf,QAAM,QAAQ,IA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AW,GAAW;AAC1D,SAAO,IAAI,IAAI,CAAC,GAAG,QAAS,QAAQ,IAAI,IAAI,CAAE;AAChD;AAEO,SAAS,YAAe,KAAU,GAAgB;AACvD,SAAO,IAAI,OAAO,CAAC,GAAG,QAAQ,QAAQ,CAAC;AACzC;AAEO,SAAS,SAAY,KAAU,MAAc,IAAiB;AACnE,MAAI,KAAK,KAAK,MAAM,IAAI,OAAQ,QAAO;AACvC,QAAM,OAAO,CAAC,GAAG,GAAG;AACpB,QAAM,CAAC,KAAK,IAAI,KAAK,OAAO,MAAM,CAAC;AACnC,OAAK,OAAO,IAAI,GAAG,KAAU;AAC7B,SAAO;AACT;AAIO,SAAS,eAAe,QAAqC;AAClE,MAAI,OAAO,YAAY,OAAW,QAAO,OAAO;AAChD,QAAM,OAAO,MAAM,QAAQ,OAAO,IAAI,IAAI,OAAO,KAAK,CAAC,IAAI,OAAO;AAClE,MAAI,SAAS,QAAS,QAAO,CAAA;AAC7B,MAAI,SAAS,SAAU,QAAO,CAAA;AAC9B,MAAI,SAAS,UAAW,QAAO;AAG/B,SAAO;AACT;;;;;;;;;;;;;;;;;;"}
|
|
@@ -8,6 +8,7 @@ export declare function isPlainObject(value: unknown): value is Record<string, u
|
|
|
8
8
|
export declare function withSyntheticValue(options: FieldOption[], value: string): FieldOption[];
|
|
9
9
|
export declare function keyPickerOptions(options: FieldOption[], usedKeys: string[], currentKey: string): FieldOption[];
|
|
10
10
|
export declare function orderByXOrder<T>(entries: [string, T][], order: unknown): [string, T][];
|
|
11
|
+
export declare function orderByClickyOrder(entries: [string, JsonSchemaProperty][]): [string, JsonSchemaProperty][];
|
|
11
12
|
export declare function orderRequiredFirst<T>(entries: [string, T][], required: string[]): [string, T][];
|
|
12
13
|
export declare function isEmptyValue(value: unknown): boolean;
|
|
13
14
|
export declare function orderByPriority<T>(entries: [string, T][], required: string[], values: Record<string, unknown>): [string, T][];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema-form-utils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AAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAE1D;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAEvD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,EAAE,CAMnE;AAID,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CASlE"}
|
|
@@ -37,6 +37,13 @@ function orderByXOrder(entries, order) {
|
|
|
37
37
|
const rest = entries.filter(([key]) => !rank.has(key));
|
|
38
38
|
return [...listed, ...rest];
|
|
39
39
|
}
|
|
40
|
+
function orderByClickyOrder(entries) {
|
|
41
|
+
const rank = (prop) => {
|
|
42
|
+
const o = prop["x-clicky-order"];
|
|
43
|
+
return typeof o === "number" ? o : Number.POSITIVE_INFINITY;
|
|
44
|
+
};
|
|
45
|
+
return entries.map((entry, index) => ({ entry, index, rank: rank(entry[1]) })).sort((a, b) => a.rank - b.rank || a.index - b.index).map((ranked) => ranked.entry);
|
|
46
|
+
}
|
|
40
47
|
function orderRequiredFirst(entries, required) {
|
|
41
48
|
const isRequired = new Set(required);
|
|
42
49
|
const head = entries.filter(([key]) => isRequired.has(key));
|
|
@@ -96,6 +103,7 @@ export {
|
|
|
96
103
|
isPlainObject,
|
|
97
104
|
keyPickerOptions,
|
|
98
105
|
moveItem,
|
|
106
|
+
orderByClickyOrder,
|
|
99
107
|
orderByPriority,
|
|
100
108
|
orderByXOrder,
|
|
101
109
|
orderRequiredFirst,
|