@health-samurai/react-components 0.0.0-alpha.2 → 0.0.0-alpha.21
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/LICENSE +21 -0
- package/README.md +102 -1
- package/dist/bundle.css +2349 -754
- package/dist/src/components/button-dropdown.d.ts +10 -0
- package/dist/src/components/button-dropdown.d.ts.map +1 -0
- package/dist/src/components/button-dropdown.js +70 -0
- package/dist/src/components/button-dropdown.js.map +1 -0
- package/dist/src/components/button-dropdown.stories.js +48 -0
- package/dist/src/components/button-dropdown.stories.js.map +1 -0
- package/dist/src/components/code-editor/fhir-autocomplete.d.ts +70 -0
- package/dist/src/components/code-editor/fhir-autocomplete.d.ts.map +1 -0
- package/dist/src/components/code-editor/fhir-autocomplete.js +1850 -0
- package/dist/src/components/code-editor/fhir-autocomplete.js.map +1 -0
- package/dist/src/components/code-editor/fhir-autocomplete.test.js +1099 -0
- package/dist/src/components/code-editor/fhir-autocomplete.test.js.map +1 -0
- package/dist/src/components/code-editor/http/grammar/http.d.ts +3 -0
- package/dist/src/components/code-editor/http/grammar/http.d.ts.map +1 -0
- package/dist/src/components/code-editor/http/grammar/http.grammar +74 -0
- package/dist/src/components/code-editor/http/grammar/http.js +38 -0
- package/dist/src/components/code-editor/http/grammar/http.js.map +1 -0
- package/dist/src/components/code-editor/http/grammar/http.terms.d.ts +2 -0
- package/dist/src/components/code-editor/http/grammar/http.terms.d.ts.map +1 -0
- package/dist/src/components/code-editor/http/grammar/http.terms.js +4 -0
- package/dist/src/components/code-editor/http/grammar/http.terms.js.map +1 -0
- package/dist/src/components/code-editor/http/grammar/http.test.js +80 -0
- package/dist/src/components/code-editor/http/grammar/http.test.js.map +1 -0
- package/dist/src/components/code-editor/http/index.d.ts +12 -0
- package/dist/src/components/code-editor/http/index.d.ts.map +1 -0
- package/dist/src/components/code-editor/http/index.js +486 -0
- package/dist/src/components/code-editor/http/index.js.map +1 -0
- package/dist/src/components/code-editor/index.d.ts +39 -1
- package/dist/src/components/code-editor/index.d.ts.map +1 -1
- package/dist/src/components/code-editor/index.js +1792 -45
- package/dist/src/components/code-editor/index.js.map +1 -1
- package/dist/src/components/code-editor/json-ast.d.ts +46 -0
- package/dist/src/components/code-editor/json-ast.d.ts.map +1 -0
- package/dist/src/components/code-editor/json-ast.js +465 -0
- package/dist/src/components/code-editor/json-ast.js.map +1 -0
- package/dist/src/components/code-editor/json-ast.test.js +206 -0
- package/dist/src/components/code-editor/json-ast.test.js.map +1 -0
- package/dist/src/components/code-editor/sql-completion.d.ts +22 -0
- package/dist/src/components/code-editor/sql-completion.d.ts.map +1 -0
- package/dist/src/components/code-editor/sql-completion.js +897 -0
- package/dist/src/components/code-editor/sql-completion.js.map +1 -0
- package/dist/src/components/code-editor.stories.js +280 -3
- package/dist/src/components/code-editor.stories.js.map +1 -1
- package/dist/src/components/copy-icon.d.ts +5 -1
- package/dist/src/components/copy-icon.d.ts.map +1 -1
- package/dist/src/components/copy-icon.js +41 -3
- package/dist/src/components/copy-icon.js.map +1 -1
- package/dist/src/components/data-table.d.ts +9 -0
- package/dist/src/components/data-table.d.ts.map +1 -0
- package/dist/src/components/data-table.js +66 -0
- package/dist/src/components/data-table.js.map +1 -0
- package/dist/src/components/data-table.stories.js +240 -0
- package/dist/src/components/data-table.stories.js.map +1 -0
- package/dist/src/components/date-picker-input.d.ts +10 -0
- package/dist/src/components/date-picker-input.d.ts.map +1 -0
- package/dist/src/components/date-picker-input.js +90 -0
- package/dist/src/components/date-picker-input.js.map +1 -0
- package/dist/src/components/date-picker-input.stories.js +76 -0
- package/dist/src/components/date-picker-input.stories.js.map +1 -0
- package/dist/src/components/fhir-structure-view.d.ts +34 -0
- package/dist/src/components/fhir-structure-view.d.ts.map +1 -0
- package/dist/src/components/fhir-structure-view.js +230 -0
- package/dist/src/components/fhir-structure-view.js.map +1 -0
- package/dist/src/components/fhir-structure-view.stories.js +447 -0
- package/dist/src/components/fhir-structure-view.stories.js.map +1 -0
- package/dist/src/components/icon-button.d.ts +12 -0
- package/dist/src/components/icon-button.d.ts.map +1 -0
- package/dist/src/components/icon-button.js +41 -0
- package/dist/src/components/icon-button.js.map +1 -0
- package/dist/src/components/icon-button.stories.js +157 -0
- package/dist/src/components/icon-button.stories.js.map +1 -0
- package/dist/src/components/operation-outcome-view.d.ts +27 -0
- package/dist/src/components/operation-outcome-view.d.ts.map +1 -0
- package/dist/src/components/operation-outcome-view.js +198 -0
- package/dist/src/components/operation-outcome-view.js.map +1 -0
- package/dist/src/components/operation-outcome-view.stories.js +207 -0
- package/dist/src/components/operation-outcome-view.stories.js.map +1 -0
- package/dist/src/components/request-line-editor.d.ts +13 -35
- package/dist/src/components/request-line-editor.d.ts.map +1 -1
- package/dist/src/components/request-line-editor.js +73 -49
- package/dist/src/components/request-line-editor.js.map +1 -1
- package/dist/src/components/request-line-editor.stories.js +17 -53
- package/dist/src/components/request-line-editor.stories.js.map +1 -1
- package/dist/src/components/sandbox.d.ts +13 -0
- package/dist/src/components/sandbox.d.ts.map +1 -0
- package/dist/src/components/sandbox.js +107 -0
- package/dist/src/components/sandbox.js.map +1 -0
- package/dist/src/components/sandbox.stories.js +126 -0
- package/dist/src/components/sandbox.stories.js.map +1 -0
- package/dist/src/components/segment-control.d.ts +13 -0
- package/dist/src/components/segment-control.d.ts.map +1 -0
- package/dist/src/components/segment-control.js +33 -0
- package/dist/src/components/segment-control.js.map +1 -0
- package/dist/src/components/segment-control.stories.js +68 -0
- package/dist/src/components/segment-control.stories.js.map +1 -0
- package/dist/src/components/split-button.d.ts +12 -0
- package/dist/src/components/split-button.d.ts.map +1 -0
- package/dist/src/components/split-button.js +33 -0
- package/dist/src/components/split-button.js.map +1 -0
- package/dist/src/components/split-button.stories.js +84 -0
- package/dist/src/components/split-button.stories.js.map +1 -0
- package/dist/src/components/tag.d.ts +16 -0
- package/dist/src/components/tag.d.ts.map +1 -0
- package/dist/src/components/tag.js +198 -0
- package/dist/src/components/tag.js.map +1 -0
- package/dist/src/components/tag.stories.js +459 -0
- package/dist/src/components/tag.stories.js.map +1 -0
- package/dist/src/components/tile.d.ts +15 -0
- package/dist/src/components/tile.d.ts.map +1 -0
- package/dist/src/components/tile.js +76 -0
- package/dist/src/components/tile.js.map +1 -0
- package/dist/src/components/tile.stories.js +167 -0
- package/dist/src/components/tile.stories.js.map +1 -0
- package/dist/src/components/toolbar.d.ts +18 -0
- package/dist/src/components/toolbar.d.ts.map +1 -0
- package/dist/src/components/toolbar.js +61 -0
- package/dist/src/components/toolbar.js.map +1 -0
- package/dist/src/components/toolbar.stories.js +69 -0
- package/dist/src/components/toolbar.stories.js.map +1 -0
- package/dist/src/components/tree-view.d.ts +47 -0
- package/dist/src/components/tree-view.d.ts.map +1 -0
- package/dist/src/components/tree-view.js +122 -0
- package/dist/src/components/tree-view.js.map +1 -0
- package/dist/src/components/tree-view.stories.js +283 -0
- package/dist/src/components/tree-view.stories.js.map +1 -0
- package/dist/src/icons.d.ts +11 -0
- package/dist/src/icons.d.ts.map +1 -0
- package/dist/src/icons.js +328 -0
- package/dist/src/icons.js.map +1 -0
- package/dist/src/index.css +358 -74
- package/dist/src/index.d.ts +17 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +17 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/shadcn/components/ui/accordion.d.ts +2 -2
- package/dist/src/shadcn/components/ui/accordion.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/accordion.js +35 -9
- package/dist/src/shadcn/components/ui/accordion.js.map +1 -1
- package/dist/src/shadcn/components/ui/alert-dialog.d.ts +12 -4
- package/dist/src/shadcn/components/ui/alert-dialog.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/alert-dialog.js +128 -18
- package/dist/src/shadcn/components/ui/alert-dialog.js.map +1 -1
- package/dist/src/shadcn/components/ui/alert-dialog.stories.js +269 -19
- package/dist/src/shadcn/components/ui/alert-dialog.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/alert.d.ts +29 -6
- package/dist/src/shadcn/components/ui/alert.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/alert.js +50 -19
- package/dist/src/shadcn/components/ui/alert.js.map +1 -1
- package/dist/src/shadcn/components/ui/alert.stories.js +140 -36
- package/dist/src/shadcn/components/ui/alert.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/aspect-ratio.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/aspect-ratio.js +1 -0
- package/dist/src/shadcn/components/ui/aspect-ratio.js.map +1 -1
- package/dist/src/shadcn/components/ui/avatar.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/avatar.js +4 -3
- package/dist/src/shadcn/components/ui/avatar.js.map +1 -1
- package/dist/src/shadcn/components/ui/avatar.stories.js +68 -2
- package/dist/src/shadcn/components/ui/avatar.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/badge.d.ts +1 -1
- package/dist/src/shadcn/components/ui/badge.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/badge.js +16 -5
- package/dist/src/shadcn/components/ui/badge.js.map +1 -1
- package/dist/src/shadcn/components/ui/breadcrumb.d.ts +5 -2
- package/dist/src/shadcn/components/ui/breadcrumb.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/breadcrumb.js +98 -13
- package/dist/src/shadcn/components/ui/breadcrumb.js.map +1 -1
- package/dist/src/shadcn/components/ui/breadcrumb.stories.js +205 -45
- package/dist/src/shadcn/components/ui/breadcrumb.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/button.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/button.js +65 -11
- package/dist/src/shadcn/components/ui/button.js.map +1 -1
- package/dist/src/shadcn/components/ui/button.stories.js +99 -17
- package/dist/src/shadcn/components/ui/button.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/calendar.d.ts +1 -1
- package/dist/src/shadcn/components/ui/calendar.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/calendar.js +1 -0
- package/dist/src/shadcn/components/ui/calendar.js.map +1 -1
- package/dist/src/shadcn/components/ui/card.d.ts +5 -1
- package/dist/src/shadcn/components/ui/card.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/card.js +28 -7
- package/dist/src/shadcn/components/ui/card.js.map +1 -1
- package/dist/src/shadcn/components/ui/card.stories.js +23 -2
- package/dist/src/shadcn/components/ui/card.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/carousel.d.ts +1 -1
- package/dist/src/shadcn/components/ui/carousel.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/carousel.js +1 -0
- package/dist/src/shadcn/components/ui/carousel.js.map +1 -1
- package/dist/src/shadcn/components/ui/chart.d.ts +5 -5
- package/dist/src/shadcn/components/ui/chart.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/chart.js +4 -3
- package/dist/src/shadcn/components/ui/chart.js.map +1 -1
- package/dist/src/shadcn/components/ui/checkbox.d.ts +5 -1
- package/dist/src/shadcn/components/ui/checkbox.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/checkbox.js +46 -6
- package/dist/src/shadcn/components/ui/checkbox.js.map +1 -1
- package/dist/src/shadcn/components/ui/checkbox.stories.js +156 -46
- package/dist/src/shadcn/components/ui/checkbox.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/combobox.d.ts +29 -0
- package/dist/src/shadcn/components/ui/combobox.d.ts.map +1 -0
- package/dist/src/shadcn/components/ui/combobox.js +226 -0
- package/dist/src/shadcn/components/ui/combobox.js.map +1 -0
- package/dist/src/shadcn/components/ui/combobox.stories.js +167 -0
- package/dist/src/shadcn/components/ui/combobox.stories.js.map +1 -0
- package/dist/src/shadcn/components/ui/command.d.ts +4 -2
- package/dist/src/shadcn/components/ui/command.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/command.js +75 -13
- package/dist/src/shadcn/components/ui/command.js.map +1 -1
- package/dist/src/shadcn/components/ui/command.stories.js +277 -57
- package/dist/src/shadcn/components/ui/command.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/context-menu.d.ts +7 -3
- package/dist/src/shadcn/components/ui/context-menu.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/context-menu.js +120 -13
- package/dist/src/shadcn/components/ui/context-menu.js.map +1 -1
- package/dist/src/shadcn/components/ui/dialog.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/dialog.js +35 -7
- package/dist/src/shadcn/components/ui/dialog.js.map +1 -1
- package/dist/src/shadcn/components/ui/drawer.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/drawer.js +27 -5
- package/dist/src/shadcn/components/ui/drawer.js.map +1 -1
- package/dist/src/shadcn/components/ui/dropdown-menu.d.ts +7 -3
- package/dist/src/shadcn/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/dropdown-menu.js +122 -14
- package/dist/src/shadcn/components/ui/dropdown-menu.js.map +1 -1
- package/dist/src/shadcn/components/ui/dropdown-menu.stories.js +22 -5
- package/dist/src/shadcn/components/ui/dropdown-menu.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/form.d.ts +2 -2
- package/dist/src/shadcn/components/ui/form.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/form.js +17 -8
- package/dist/src/shadcn/components/ui/form.js.map +1 -1
- package/dist/src/shadcn/components/ui/hover-card.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/hover-card.js +2 -1
- package/dist/src/shadcn/components/ui/hover-card.js.map +1 -1
- package/dist/src/shadcn/components/ui/input-otp.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/input-otp.js +1 -0
- package/dist/src/shadcn/components/ui/input-otp.js.map +1 -1
- package/dist/src/shadcn/components/ui/input.d.ts +3 -1
- package/dist/src/shadcn/components/ui/input.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/input.js +126 -17
- package/dist/src/shadcn/components/ui/input.js.map +1 -1
- package/dist/src/shadcn/components/ui/input.stories.js +218 -29
- package/dist/src/shadcn/components/ui/input.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/label.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/label.js +9 -1
- package/dist/src/shadcn/components/ui/label.js.map +1 -1
- package/dist/src/shadcn/components/ui/menubar.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/menubar.js +35 -13
- package/dist/src/shadcn/components/ui/menubar.js.map +1 -1
- package/dist/src/shadcn/components/ui/pagination.d.ts +9 -2
- package/dist/src/shadcn/components/ui/pagination.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/pagination.js +41 -24
- package/dist/src/shadcn/components/ui/pagination.js.map +1 -1
- package/dist/src/shadcn/components/ui/pagination.stories.js +44 -37
- package/dist/src/shadcn/components/ui/pagination.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/popover.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/popover.js +13 -1
- package/dist/src/shadcn/components/ui/popover.js.map +1 -1
- package/dist/src/shadcn/components/ui/progress.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/progress.js +6 -2
- package/dist/src/shadcn/components/ui/progress.js.map +1 -1
- package/dist/src/shadcn/components/ui/radio-button-group.d.ts +21 -0
- package/dist/src/shadcn/components/ui/radio-button-group.d.ts.map +1 -0
- package/dist/src/shadcn/components/ui/radio-button-group.js +148 -0
- package/dist/src/shadcn/components/ui/radio-button-group.js.map +1 -0
- package/dist/src/shadcn/components/ui/radio-button-group.stories.js +283 -0
- package/dist/src/shadcn/components/ui/radio-button-group.stories.js.map +1 -0
- package/dist/src/shadcn/components/ui/radio-group.d.ts +5 -1
- package/dist/src/shadcn/components/ui/radio-group.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/radio-group.js +40 -7
- package/dist/src/shadcn/components/ui/radio-group.js.map +1 -1
- package/dist/src/shadcn/components/ui/radio-group.stories.js +107 -32
- package/dist/src/shadcn/components/ui/radio-group.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/resizable.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/resizable.js +2 -1
- package/dist/src/shadcn/components/ui/resizable.js.map +1 -1
- package/dist/src/shadcn/components/ui/resizable.stories.js +2 -2
- package/dist/src/shadcn/components/ui/resizable.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/scroll-area.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/scroll-area.js +10 -3
- package/dist/src/shadcn/components/ui/scroll-area.js.map +1 -1
- package/dist/src/shadcn/components/ui/select.d.ts +1 -2
- package/dist/src/shadcn/components/ui/select.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/select.js +49 -19
- package/dist/src/shadcn/components/ui/select.js.map +1 -1
- package/dist/src/shadcn/components/ui/select.stories.js +193 -70
- package/dist/src/shadcn/components/ui/select.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/separator.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/separator.js +8 -1
- package/dist/src/shadcn/components/ui/separator.js.map +1 -1
- package/dist/src/shadcn/components/ui/sheet.js +1 -1
- package/dist/src/shadcn/components/ui/sheet.js.map +1 -1
- package/dist/src/shadcn/components/ui/sidebar.d.ts +4 -4
- package/dist/src/shadcn/components/ui/sidebar.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/sidebar.js +21 -6
- package/dist/src/shadcn/components/ui/sidebar.js.map +1 -1
- package/dist/src/shadcn/components/ui/skeleton.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/skeleton.js +3 -1
- package/dist/src/shadcn/components/ui/skeleton.js.map +1 -1
- package/dist/src/shadcn/components/ui/slider.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/slider.js +35 -4
- package/dist/src/shadcn/components/ui/slider.js.map +1 -1
- package/dist/src/shadcn/components/ui/sonner.d.ts +24 -2
- package/dist/src/shadcn/components/ui/sonner.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/sonner.js +127 -9
- package/dist/src/shadcn/components/ui/sonner.js.map +1 -1
- package/dist/src/shadcn/components/ui/sonner.stories.js +251 -12
- package/dist/src/shadcn/components/ui/sonner.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/switch.d.ts +7 -1
- package/dist/src/shadcn/components/ui/switch.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/switch.js +55 -3
- package/dist/src/shadcn/components/ui/switch.js.map +1 -1
- package/dist/src/shadcn/components/ui/switch.stories.js +84 -9
- package/dist/src/shadcn/components/ui/switch.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/table.d.ts +23 -6
- package/dist/src/shadcn/components/ui/table.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/table.js +65 -20
- package/dist/src/shadcn/components/ui/table.js.map +1 -1
- package/dist/src/shadcn/components/ui/table.stories.js +217 -97
- package/dist/src/shadcn/components/ui/table.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/tabs.d.ts +30 -5
- package/dist/src/shadcn/components/ui/tabs.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/tabs.js +470 -23
- package/dist/src/shadcn/components/ui/tabs.js.map +1 -1
- package/dist/src/shadcn/components/ui/tabs.stories.js +405 -181
- package/dist/src/shadcn/components/ui/tabs.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/textarea.d.ts +8 -1
- package/dist/src/shadcn/components/ui/textarea.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/textarea.js +30 -2
- package/dist/src/shadcn/components/ui/textarea.js.map +1 -1
- package/dist/src/shadcn/components/ui/textarea.stories.js +85 -4
- package/dist/src/shadcn/components/ui/textarea.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/toggle-group.d.ts +3 -3
- package/dist/src/shadcn/components/ui/toggle-group.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/toggle-group.js +14 -12
- package/dist/src/shadcn/components/ui/toggle-group.js.map +1 -1
- package/dist/src/shadcn/components/ui/toggle.d.ts +3 -4
- package/dist/src/shadcn/components/ui/toggle.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/toggle.js +44 -16
- package/dist/src/shadcn/components/ui/toggle.js.map +1 -1
- package/dist/src/shadcn/components/ui/toggle.stories.js +130 -7
- package/dist/src/shadcn/components/ui/toggle.stories.js.map +1 -1
- package/dist/src/shadcn/components/ui/tooltip.d.ts.map +1 -1
- package/dist/src/shadcn/components/ui/tooltip.js +12 -1
- package/dist/src/shadcn/components/ui/tooltip.js.map +1 -1
- package/dist/src/shadcn/components/ui/tree.d.ts +29 -0
- package/dist/src/shadcn/components/ui/tree.d.ts.map +1 -0
- package/dist/src/shadcn/components/ui/tree.js +135 -0
- package/dist/src/shadcn/components/ui/tree.js.map +1 -0
- package/dist/src/shadcn/shadcn.css +4 -4
- package/dist/src/tokens.css +50 -20
- package/dist/src/typography.css +78 -15
- package/package.json +84 -64
- package/src/components/button-dropdown.stories.tsx +41 -0
- package/src/components/button-dropdown.tsx +97 -0
- package/src/components/code-editor/fhir-autocomplete.test.ts +993 -0
- package/src/components/code-editor/fhir-autocomplete.ts +2322 -0
- package/src/components/code-editor/http/grammar/http.grammar +74 -0
- package/src/components/code-editor/http/grammar/http.terms.ts +9 -0
- package/src/components/code-editor/http/grammar/http.test.ts +110 -0
- package/src/components/code-editor/http/grammar/http.ts +21 -0
- package/src/components/code-editor/http/index.ts +424 -0
- package/src/components/code-editor/index.tsx +1944 -42
- package/src/components/code-editor/json-ast.test.ts +230 -0
- package/src/components/code-editor/json-ast.ts +590 -0
- package/src/components/code-editor/sql-completion.ts +1112 -0
- package/src/components/code-editor.stories.tsx +325 -2
- package/src/components/copy-icon.tsx +57 -3
- package/src/components/data-table.stories.tsx +91 -0
- package/src/components/data-table.tsx +126 -0
- package/src/components/date-picker-input.stories.tsx +79 -0
- package/src/components/date-picker-input.tsx +104 -0
- package/src/components/fhir-structure-view.stories.tsx +439 -0
- package/src/components/fhir-structure-view.tsx +233 -0
- package/src/components/icon-button.stories.tsx +86 -0
- package/src/components/icon-button.tsx +57 -0
- package/src/components/operation-outcome-view.stories.tsx +163 -0
- package/src/components/operation-outcome-view.tsx +254 -0
- package/src/components/request-line-editor.stories.tsx +17 -27
- package/src/components/request-line-editor.tsx +103 -61
- package/src/components/sandbox.stories.tsx +131 -0
- package/src/components/sandbox.tsx +191 -0
- package/src/components/segment-control.stories.tsx +61 -0
- package/src/components/segment-control.tsx +83 -0
- package/src/components/split-button.stories.tsx +68 -0
- package/src/components/split-button.tsx +74 -0
- package/src/components/tag.stories.tsx +371 -0
- package/src/components/tag.tsx +236 -0
- package/src/components/tile.stories.tsx +149 -0
- package/src/components/tile.tsx +105 -0
- package/src/components/toolbar.stories.tsx +64 -0
- package/src/components/toolbar.tsx +98 -0
- package/src/components/tree-view.stories.tsx +265 -0
- package/src/components/tree-view.tsx +246 -0
- package/src/icons.tsx +331 -0
- package/src/index.css +358 -74
- package/src/index.tsx +17 -3
- package/src/shadcn/components/ui/accordion.tsx +91 -10
- package/src/shadcn/components/ui/alert-dialog.stories.tsx +209 -15
- package/src/shadcn/components/ui/alert-dialog.tsx +236 -26
- package/src/shadcn/components/ui/alert.stories.tsx +120 -21
- package/src/shadcn/components/ui/alert.tsx +125 -28
- package/src/shadcn/components/ui/aspect-ratio.tsx +1 -0
- package/src/shadcn/components/ui/avatar.stories.tsx +74 -1
- package/src/shadcn/components/ui/avatar.tsx +22 -6
- package/src/shadcn/components/ui/badge.tsx +67 -18
- package/src/shadcn/components/ui/breadcrumb.stories.tsx +161 -41
- package/src/shadcn/components/ui/breadcrumb.tsx +172 -23
- package/src/shadcn/components/ui/button.stories.tsx +106 -18
- package/src/shadcn/components/ui/button.tsx +151 -55
- package/src/shadcn/components/ui/calendar.tsx +1 -0
- package/src/shadcn/components/ui/card.stories.tsx +17 -3
- package/src/shadcn/components/ui/card.tsx +89 -14
- package/src/shadcn/components/ui/carousel.tsx +1 -0
- package/src/shadcn/components/ui/chart.tsx +9 -5
- package/src/shadcn/components/ui/checkbox.stories.tsx +78 -30
- package/src/shadcn/components/ui/checkbox.tsx +91 -8
- package/src/shadcn/components/ui/combobox.stories.tsx +148 -0
- package/src/shadcn/components/ui/combobox.tsx +324 -0
- package/src/shadcn/components/ui/command.stories.tsx +184 -39
- package/src/shadcn/components/ui/command.tsx +218 -37
- package/src/shadcn/components/ui/context-menu.tsx +333 -40
- package/src/shadcn/components/ui/dialog.tsx +101 -13
- package/src/shadcn/components/ui/drawer.tsx +94 -18
- package/src/shadcn/components/ui/dropdown-menu.stories.tsx +18 -2
- package/src/shadcn/components/ui/dropdown-menu.tsx +334 -68
- package/src/shadcn/components/ui/form.tsx +22 -11
- package/src/shadcn/components/ui/hover-card.tsx +2 -1
- package/src/shadcn/components/ui/input-otp.tsx +1 -0
- package/src/shadcn/components/ui/input.stories.tsx +235 -27
- package/src/shadcn/components/ui/input.tsx +400 -29
- package/src/shadcn/components/ui/label.tsx +22 -4
- package/src/shadcn/components/ui/menubar.tsx +188 -43
- package/src/shadcn/components/ui/pagination.stories.tsx +8 -2
- package/src/shadcn/components/ui/pagination.tsx +65 -8
- package/src/shadcn/components/ui/popover.tsx +36 -4
- package/src/shadcn/components/ui/progress.tsx +21 -5
- package/src/shadcn/components/ui/radio-button-group.stories.tsx +247 -0
- package/src/shadcn/components/ui/radio-button-group.tsx +188 -0
- package/src/shadcn/components/ui/radio-group.stories.tsx +70 -14
- package/src/shadcn/components/ui/radio-group.tsx +85 -9
- package/src/shadcn/components/ui/resizable.stories.tsx +2 -2
- package/src/shadcn/components/ui/resizable.tsx +2 -1
- package/src/shadcn/components/ui/scroll-area.tsx +34 -5
- package/src/shadcn/components/ui/select.stories.tsx +108 -32
- package/src/shadcn/components/ui/select.tsx +182 -36
- package/src/shadcn/components/ui/separator.tsx +16 -5
- package/src/shadcn/components/ui/sheet.tsx +1 -1
- package/src/shadcn/components/ui/sidebar.tsx +69 -26
- package/src/shadcn/components/ui/skeleton.tsx +4 -1
- package/src/shadcn/components/ui/slider.tsx +83 -11
- package/src/shadcn/components/ui/sonner.stories.tsx +238 -17
- package/src/shadcn/components/ui/sonner.tsx +254 -11
- package/src/shadcn/components/ui/switch.stories.tsx +52 -5
- package/src/shadcn/components/ui/switch.tsx +92 -7
- package/src/shadcn/components/ui/table.stories.tsx +252 -72
- package/src/shadcn/components/ui/table.tsx +204 -26
- package/src/shadcn/components/ui/tabs.stories.tsx +235 -123
- package/src/shadcn/components/ui/tabs.tsx +694 -36
- package/src/shadcn/components/ui/textarea.stories.tsx +94 -2
- package/src/shadcn/components/ui/textarea.tsx +70 -5
- package/src/shadcn/components/ui/toggle-group.tsx +35 -13
- package/src/shadcn/components/ui/toggle.stories.tsx +92 -5
- package/src/shadcn/components/ui/toggle.tsx +96 -23
- package/src/shadcn/components/ui/tooltip.tsx +34 -8
- package/src/shadcn/components/ui/tree.tsx +257 -0
- package/src/shadcn/shadcn.css +4 -4
- package/src/tokens.css +50 -20
- package/src/typography.css +78 -15
- package/dist/src/components/code-editor.stories.d.ts +0 -7
- package/dist/src/components/code-editor.stories.d.ts.map +0 -1
- package/dist/src/components/request-line-editor.stories.d.ts +0 -11
- package/dist/src/components/request-line-editor.stories.d.ts.map +0 -1
- package/dist/src/index.stories.d.ts +0 -14
- package/dist/src/index.stories.d.ts.map +0 -1
- package/dist/src/index.stories.js +0 -19
- package/dist/src/index.stories.js.map +0 -1
- package/dist/src/shadcn/components/ui/accordion.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/accordion.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/alert-dialog.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/alert-dialog.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/alert.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/alert.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/aspect-ratio.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/aspect-ratio.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/avatar.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/avatar.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/badge.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/badge.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/breadcrumb.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/breadcrumb.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/button.stories.d.ts +0 -23
- package/dist/src/shadcn/components/ui/button.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/calendar.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/calendar.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/card.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/card.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/carousel.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/carousel.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/chart.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/chart.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/checkbox.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/checkbox.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/collapsible.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/collapsible.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/command.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/command.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/context-menu.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/context-menu.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/dialog.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/dialog.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/drawer.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/drawer.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/dropdown-menu.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/dropdown-menu.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/form.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/form.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/hover-card.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/hover-card.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/input-otp.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/input-otp.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/input.stories.d.ts +0 -18
- package/dist/src/shadcn/components/ui/input.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/label.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/label.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/menubar.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/menubar.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/navigation-menu.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/navigation-menu.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/pagination.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/pagination.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/popover.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/popover.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/progress.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/progress.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/radio-group.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/radio-group.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/resizable.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/resizable.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/scroll-area.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/scroll-area.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/select.stories.d.ts +0 -11
- package/dist/src/shadcn/components/ui/select.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/separator.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/separator.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/sheet.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/sheet.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/sidebar.stories.d.ts +0 -11
- package/dist/src/shadcn/components/ui/sidebar.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/skeleton.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/skeleton.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/slider.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/slider.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/sonner.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/sonner.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/switch.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/switch.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/table.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/table.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/tabs.stories.d.ts +0 -32
- package/dist/src/shadcn/components/ui/tabs.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/textarea.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/textarea.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/toggle-group.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/toggle-group.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/toggle.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/toggle.stories.d.ts.map +0 -1
- package/dist/src/shadcn/components/ui/tooltip.stories.d.ts +0 -8
- package/dist/src/shadcn/components/ui/tooltip.stories.d.ts.map +0 -1
- package/src/index.stories.tsx +0 -21
|
@@ -0,0 +1,1112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
autocompletion,
|
|
3
|
+
type Completion,
|
|
4
|
+
type CompletionContext,
|
|
5
|
+
type CompletionResult,
|
|
6
|
+
type CompletionSource,
|
|
7
|
+
startCompletion,
|
|
8
|
+
} from "@codemirror/autocomplete";
|
|
9
|
+
import { EditorState, type Extension } from "@codemirror/state";
|
|
10
|
+
import { EditorView } from "@codemirror/view";
|
|
11
|
+
|
|
12
|
+
// ── Public types ──
|
|
13
|
+
|
|
14
|
+
export type SqlQueryType =
|
|
15
|
+
| "tables"
|
|
16
|
+
| "columns"
|
|
17
|
+
| "functions"
|
|
18
|
+
| "jsonb_columns"
|
|
19
|
+
| "structure_definition";
|
|
20
|
+
|
|
21
|
+
interface StructureDefinitionElementType {
|
|
22
|
+
code: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface StructureDefinitionElement {
|
|
26
|
+
path?: string;
|
|
27
|
+
type?: StructureDefinitionElementType[];
|
|
28
|
+
max?: string;
|
|
29
|
+
short?: string;
|
|
30
|
+
definition?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface StructureDefinition {
|
|
34
|
+
name?: string;
|
|
35
|
+
snapshot?: {
|
|
36
|
+
element: StructureDefinitionElement[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface SqlConfig {
|
|
41
|
+
executeSql: (
|
|
42
|
+
query: string,
|
|
43
|
+
type: SqlQueryType,
|
|
44
|
+
) => Promise<Record<string, unknown>[]>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ── Internal types ──
|
|
48
|
+
|
|
49
|
+
type SchemaMap = Record<string, string[]>;
|
|
50
|
+
type JsonbColumnMap = Record<string, string[]>;
|
|
51
|
+
type ColumnInfo = { name: string; dataType: string };
|
|
52
|
+
type ColumnMap = Record<string, ColumnInfo[]>;
|
|
53
|
+
|
|
54
|
+
type FhirFieldInfo = {
|
|
55
|
+
name: string;
|
|
56
|
+
datatype: string;
|
|
57
|
+
isArray: boolean;
|
|
58
|
+
description: string | undefined;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type FhirPathChildren = Record<string, FhirFieldInfo[]>;
|
|
62
|
+
|
|
63
|
+
type JsonbChain = {
|
|
64
|
+
tableOrAlias: string | null;
|
|
65
|
+
column: string;
|
|
66
|
+
path: string[];
|
|
67
|
+
isPathOp: boolean;
|
|
68
|
+
partialInput: string;
|
|
69
|
+
insideQuote: boolean;
|
|
70
|
+
lastRawSegment: string | null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type AliasEntry = { schema: string; table: string };
|
|
74
|
+
|
|
75
|
+
export interface SqlMetadata {
|
|
76
|
+
schemas: SchemaMap;
|
|
77
|
+
jsonbColumns: JsonbColumnMap;
|
|
78
|
+
functions: string[];
|
|
79
|
+
columns: ColumnMap;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ── SQL queries ──
|
|
83
|
+
|
|
84
|
+
const TABLES_QUERY = `SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOT IN ('pg_catalog', 'information_schema', 'pgagent') AND table_type = 'BASE TABLE' ORDER BY table_schema, table_name`;
|
|
85
|
+
|
|
86
|
+
const JSONB_COLUMNS_QUERY = `SELECT c.table_schema, c.table_name, c.column_name FROM information_schema.columns c JOIN information_schema.tables t ON c.table_schema = t.table_schema AND c.table_name = t.table_name WHERE t.table_type = 'BASE TABLE' AND c.table_schema NOT IN ('pg_catalog', 'information_schema', 'pgagent') AND c.udt_name = 'jsonb'`;
|
|
87
|
+
|
|
88
|
+
const FUNCTIONS_QUERY = `SELECT DISTINCT p.proname AS name FROM pg_proc p JOIN pg_namespace n ON p.pronamespace = n.oid LEFT JOIN pg_depend d ON d.objid = p.oid AND d.deptype = 'e' WHERE n.nspname NOT IN ('pg_catalog', 'information_schema') AND d.objid IS NULL ORDER BY p.proname`;
|
|
89
|
+
|
|
90
|
+
const COLUMNS_QUERY = `SELECT c.table_schema, c.table_name, c.column_name, c.data_type FROM information_schema.columns c JOIN information_schema.tables t ON c.table_schema = t.table_schema AND c.table_name = t.table_name WHERE t.table_type = 'BASE TABLE' AND c.table_schema NOT IN ('pg_catalog', 'information_schema', 'pgagent') ORDER BY c.table_schema, c.table_name, c.ordinal_position`;
|
|
91
|
+
|
|
92
|
+
// ── FHIR StructureDefinition processing ──
|
|
93
|
+
|
|
94
|
+
function isExpandedVariant(path: string, unionBases: Set<string>): boolean {
|
|
95
|
+
const parts = path.split(".");
|
|
96
|
+
if (parts.length < 2) return false;
|
|
97
|
+
const parentPath = parts.slice(0, -1).join(".");
|
|
98
|
+
const name = parts[parts.length - 1]!;
|
|
99
|
+
|
|
100
|
+
for (const base of unionBases) {
|
|
101
|
+
const baseParts = base.split(".");
|
|
102
|
+
const baseName = baseParts[baseParts.length - 1]!;
|
|
103
|
+
const baseParent = baseParts.slice(0, -1).join(".");
|
|
104
|
+
|
|
105
|
+
if (
|
|
106
|
+
parentPath === baseParent &&
|
|
107
|
+
name.startsWith(baseName) &&
|
|
108
|
+
name.length > baseName.length &&
|
|
109
|
+
/^[A-Z]/.test(name.slice(baseName.length))
|
|
110
|
+
) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function buildFromStructureDefinition(
|
|
118
|
+
sd: StructureDefinition,
|
|
119
|
+
): FhirPathChildren {
|
|
120
|
+
const elements = sd.snapshot?.element ?? [];
|
|
121
|
+
const result: FhirPathChildren = {};
|
|
122
|
+
|
|
123
|
+
const unionBases = new Set<string>();
|
|
124
|
+
for (const el of elements) {
|
|
125
|
+
if (!el.path) continue;
|
|
126
|
+
const name = el.path.split(".").pop() ?? "";
|
|
127
|
+
if (name.endsWith("[x]")) {
|
|
128
|
+
unionBases.add(el.path.replace(/\[x\]$/, ""));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for (const el of elements) {
|
|
133
|
+
if (!el.path) continue;
|
|
134
|
+
const parts = el.path.split(".");
|
|
135
|
+
if (parts.length < 2) continue;
|
|
136
|
+
|
|
137
|
+
if (isExpandedVariant(el.path, unionBases)) continue;
|
|
138
|
+
|
|
139
|
+
const parentPath = parts.slice(0, -1).join(".");
|
|
140
|
+
const rawName = parts[parts.length - 1]!;
|
|
141
|
+
|
|
142
|
+
if (!result[parentPath]) result[parentPath] = [];
|
|
143
|
+
|
|
144
|
+
if (rawName.endsWith("[x]")) {
|
|
145
|
+
const name = rawName.slice(0, -3);
|
|
146
|
+
if (result[parentPath].some((f) => f.name === name)) continue;
|
|
147
|
+
|
|
148
|
+
result[parentPath].push({
|
|
149
|
+
name,
|
|
150
|
+
datatype: "union",
|
|
151
|
+
isArray: el.max === "*",
|
|
152
|
+
description: el.short ?? el.definition,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const unionPath = `${parentPath}.${name}`;
|
|
156
|
+
if (!result[unionPath]) result[unionPath] = [];
|
|
157
|
+
for (const t of el.type ?? []) {
|
|
158
|
+
if (!result[unionPath].some((f) => f.name === t.code)) {
|
|
159
|
+
result[unionPath].push({
|
|
160
|
+
name: t.code,
|
|
161
|
+
datatype: t.code,
|
|
162
|
+
isArray: false,
|
|
163
|
+
description: el.short ?? el.definition,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
if (result[parentPath].some((f) => f.name === rawName)) continue;
|
|
169
|
+
|
|
170
|
+
result[parentPath].push({
|
|
171
|
+
name: rawName,
|
|
172
|
+
datatype: el.type?.[0]?.code ?? "",
|
|
173
|
+
isArray: el.max === "*",
|
|
174
|
+
description: el.short ?? el.definition,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function transformReferenceFields(result: FhirPathChildren): void {
|
|
183
|
+
for (const [path, children] of Object.entries(result)) {
|
|
184
|
+
const hasReferenceField = children.some((c) => c.name === "reference");
|
|
185
|
+
if (!hasReferenceField) continue;
|
|
186
|
+
|
|
187
|
+
result[path] = children.flatMap((child) => {
|
|
188
|
+
if (child.name === "reference") {
|
|
189
|
+
return [
|
|
190
|
+
{
|
|
191
|
+
name: "id",
|
|
192
|
+
datatype: "string",
|
|
193
|
+
isArray: false,
|
|
194
|
+
description: "Resource ID" as string | undefined,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "resourceType",
|
|
198
|
+
datatype: "string",
|
|
199
|
+
isArray: false,
|
|
200
|
+
description: "Resource type" as string | undefined,
|
|
201
|
+
},
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
return [child];
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ── SQL parsing utilities ──
|
|
210
|
+
|
|
211
|
+
const SQL_TABLE_KEYWORDS =
|
|
212
|
+
/\b(?:from|join|inner\s+join|left\s+join|right\s+join|full\s+join|cross\s+join|into|update|table)\s+$/i;
|
|
213
|
+
|
|
214
|
+
function isInsideString(textBefore: string): boolean {
|
|
215
|
+
let count = 0;
|
|
216
|
+
for (let i = 0; i < textBefore.length; i++) {
|
|
217
|
+
if (textBefore[i] === "'") {
|
|
218
|
+
if (i + 1 < textBefore.length && textBefore[i + 1] === "'") {
|
|
219
|
+
i++;
|
|
220
|
+
} else {
|
|
221
|
+
count++;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return count % 2 !== 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function isInJsonbContext(textBefore: string): boolean {
|
|
229
|
+
return parseJsonbChain(textBefore) !== null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function parseJsonbChain(textBefore: string): JsonbChain | null {
|
|
233
|
+
const pathOpMatch = textBefore.match(/((?:\w+\.)?\w+)\s*#>>?\s*'\{([^}]*)$/);
|
|
234
|
+
if (pathOpMatch) {
|
|
235
|
+
const ref = pathOpMatch[1]!;
|
|
236
|
+
const pathContent = pathOpMatch[2]!;
|
|
237
|
+
const segments = pathContent ? pathContent.split(",") : [];
|
|
238
|
+
const partialInput = segments.length > 0 ? (segments.pop() ?? "") : "";
|
|
239
|
+
const lastRawSegment =
|
|
240
|
+
segments.length > 0 ? (segments[segments.length - 1] ?? null) : null;
|
|
241
|
+
const path = segments.filter((s) => !/^\d+$/.test(s));
|
|
242
|
+
|
|
243
|
+
const dotParts = ref.split(".");
|
|
244
|
+
if (dotParts.length === 2) {
|
|
245
|
+
return {
|
|
246
|
+
tableOrAlias: dotParts[0]!,
|
|
247
|
+
column: dotParts[1]!,
|
|
248
|
+
path,
|
|
249
|
+
isPathOp: true,
|
|
250
|
+
partialInput,
|
|
251
|
+
insideQuote: false,
|
|
252
|
+
lastRawSegment,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
tableOrAlias: null,
|
|
257
|
+
column: dotParts[0]!,
|
|
258
|
+
path,
|
|
259
|
+
isPathOp: true,
|
|
260
|
+
partialInput,
|
|
261
|
+
insideQuote: false,
|
|
262
|
+
lastRawSegment,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const arrowPattern =
|
|
267
|
+
/(?:((?:\w+\.)?\w+)((?:\s*->>?\s*(?:'[^']*'|\d+))*)\s*->>?\s*)('?)([^']*)?$/;
|
|
268
|
+
const arrowMatch = textBefore.match(arrowPattern);
|
|
269
|
+
if (!arrowMatch) return null;
|
|
270
|
+
|
|
271
|
+
const ref = arrowMatch[1]!;
|
|
272
|
+
const chainPart = arrowMatch[2] || "";
|
|
273
|
+
const insideQuote = arrowMatch[3] === "'";
|
|
274
|
+
const partialInput = arrowMatch[4] ?? "";
|
|
275
|
+
|
|
276
|
+
const chainSegments: string[] = [];
|
|
277
|
+
let lastRawSeg: string | null = null;
|
|
278
|
+
const segmentRegex = /->>?\s*(?:'([^']*)'|(\d+))/g;
|
|
279
|
+
for (
|
|
280
|
+
let m = segmentRegex.exec(chainPart);
|
|
281
|
+
m !== null;
|
|
282
|
+
m = segmentRegex.exec(chainPart)
|
|
283
|
+
) {
|
|
284
|
+
const seg = m[1] ?? m[2] ?? "";
|
|
285
|
+
lastRawSeg = seg;
|
|
286
|
+
if (!/^\d+$/.test(seg)) {
|
|
287
|
+
chainSegments.push(seg);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const dotParts = ref.split(".");
|
|
292
|
+
if (dotParts.length === 2) {
|
|
293
|
+
return {
|
|
294
|
+
tableOrAlias: dotParts[0]!,
|
|
295
|
+
column: dotParts[1]!,
|
|
296
|
+
path: chainSegments,
|
|
297
|
+
isPathOp: false,
|
|
298
|
+
partialInput,
|
|
299
|
+
insideQuote,
|
|
300
|
+
lastRawSegment: lastRawSeg,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
tableOrAlias: null,
|
|
305
|
+
column: dotParts[0]!,
|
|
306
|
+
path: chainSegments,
|
|
307
|
+
isPathOp: false,
|
|
308
|
+
partialInput,
|
|
309
|
+
insideQuote,
|
|
310
|
+
lastRawSegment: lastRawSeg,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function buildAliasMap(
|
|
315
|
+
sql: string,
|
|
316
|
+
schemas: SchemaMap,
|
|
317
|
+
): Record<string, AliasEntry> {
|
|
318
|
+
const aliases: Record<string, AliasEntry> = {};
|
|
319
|
+
const regex = /\b(?:FROM|JOIN)\s+((?:\w+\.)?\w+)(?:\s+(?:AS\s+)?(\w+))?/gi;
|
|
320
|
+
|
|
321
|
+
for (let match = regex.exec(sql); match !== null; match = regex.exec(sql)) {
|
|
322
|
+
const fullTable = match[1]!;
|
|
323
|
+
const alias = match[2];
|
|
324
|
+
|
|
325
|
+
let schema: string;
|
|
326
|
+
let table: string;
|
|
327
|
+
if (fullTable.includes(".")) {
|
|
328
|
+
const parts = fullTable.split(".");
|
|
329
|
+
schema = parts[0]!;
|
|
330
|
+
table = parts[1]!;
|
|
331
|
+
} else {
|
|
332
|
+
table = fullTable;
|
|
333
|
+
let found: string | null = null;
|
|
334
|
+
for (const [s, tables] of Object.entries(schemas)) {
|
|
335
|
+
if (tables.includes(table)) {
|
|
336
|
+
found = s;
|
|
337
|
+
if (s === "public") break;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
schema = found ?? "public";
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (alias) {
|
|
344
|
+
aliases[alias.toLowerCase()] = { schema, table };
|
|
345
|
+
}
|
|
346
|
+
aliases[table.toLowerCase()] = { schema, table };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return aliases;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function tableToResourceType(table: string): string {
|
|
353
|
+
return table
|
|
354
|
+
.split("_")
|
|
355
|
+
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
|
356
|
+
.join("");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function getCurrentStatement(doc: string, pos: number): string {
|
|
360
|
+
let start = 0;
|
|
361
|
+
let end = doc.length;
|
|
362
|
+
|
|
363
|
+
const before = doc.lastIndexOf(";", pos - 1);
|
|
364
|
+
if (before !== -1) start = before + 1;
|
|
365
|
+
|
|
366
|
+
const after = doc.indexOf(";", pos);
|
|
367
|
+
if (after !== -1) end = after;
|
|
368
|
+
|
|
369
|
+
return doc.slice(start, end);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ── Completion result builders ──
|
|
373
|
+
|
|
374
|
+
function buildJsonbResult(
|
|
375
|
+
chain: JsonbChain,
|
|
376
|
+
pathChildren: FhirPathChildren,
|
|
377
|
+
resourceType: string,
|
|
378
|
+
context: CompletionContext,
|
|
379
|
+
): CompletionResult | null {
|
|
380
|
+
const lookupPath =
|
|
381
|
+
chain.path.length > 0
|
|
382
|
+
? `${resourceType}.${chain.path.join(".")}`
|
|
383
|
+
: resourceType;
|
|
384
|
+
|
|
385
|
+
const children = pathChildren[lookupPath];
|
|
386
|
+
if (!children || children.length === 0) return null;
|
|
387
|
+
|
|
388
|
+
const partial = chain.partialInput.toLowerCase();
|
|
389
|
+
const filtered = partial
|
|
390
|
+
? children.filter((f) => f.name.toLowerCase().startsWith(partial))
|
|
391
|
+
: children;
|
|
392
|
+
|
|
393
|
+
if (filtered.length === 0) return null;
|
|
394
|
+
|
|
395
|
+
if (chain.isPathOp) {
|
|
396
|
+
return {
|
|
397
|
+
from: context.pos - chain.partialInput.length,
|
|
398
|
+
validFor: /^\w*$/,
|
|
399
|
+
options: filtered.map(
|
|
400
|
+
(f): Completion => ({
|
|
401
|
+
label: f.name,
|
|
402
|
+
type: "property",
|
|
403
|
+
detail: f.datatype + (f.isArray ? "[]" : ""),
|
|
404
|
+
...(f.description != null ? { info: f.description } : {}),
|
|
405
|
+
}),
|
|
406
|
+
),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (chain.insideQuote) {
|
|
411
|
+
return {
|
|
412
|
+
from: context.pos - chain.partialInput.length,
|
|
413
|
+
validFor: /^\w*$/,
|
|
414
|
+
options: filtered.map(
|
|
415
|
+
(f): Completion => ({
|
|
416
|
+
label: f.name,
|
|
417
|
+
type: "property",
|
|
418
|
+
detail: f.datatype + (f.isArray ? "[]" : ""),
|
|
419
|
+
...(f.description != null ? { info: f.description } : {}),
|
|
420
|
+
apply: (
|
|
421
|
+
view: EditorView,
|
|
422
|
+
_completion: Completion,
|
|
423
|
+
from: number,
|
|
424
|
+
to: number,
|
|
425
|
+
) => {
|
|
426
|
+
const after = view.state.sliceDoc(to, to + 1);
|
|
427
|
+
const end = after === "'" ? to + 1 : to;
|
|
428
|
+
const insert = `${f.name}'`;
|
|
429
|
+
view.dispatch({
|
|
430
|
+
changes: { from, to: end, insert },
|
|
431
|
+
selection: { anchor: from + insert.length },
|
|
432
|
+
});
|
|
433
|
+
},
|
|
434
|
+
}),
|
|
435
|
+
),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return {
|
|
440
|
+
from: context.pos - chain.partialInput.length,
|
|
441
|
+
validFor: /^'?\w*'?$/,
|
|
442
|
+
options: filtered.map(
|
|
443
|
+
(f): Completion => ({
|
|
444
|
+
label: `'${f.name}'`,
|
|
445
|
+
type: "property",
|
|
446
|
+
detail: f.datatype + (f.isArray ? "[]" : ""),
|
|
447
|
+
...(f.description != null ? { info: f.description } : {}),
|
|
448
|
+
apply: `'${f.name}'`,
|
|
449
|
+
}),
|
|
450
|
+
),
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function isArrayPosition(
|
|
455
|
+
chain: JsonbChain,
|
|
456
|
+
pathChildren: FhirPathChildren,
|
|
457
|
+
resourceType: string,
|
|
458
|
+
): boolean {
|
|
459
|
+
if (!chain.lastRawSegment || /^\d+$/.test(chain.lastRawSegment)) return false;
|
|
460
|
+
if (!chain.isPathOp && chain.insideQuote) return false;
|
|
461
|
+
|
|
462
|
+
const fieldName = chain.lastRawSegment;
|
|
463
|
+
const parentPath =
|
|
464
|
+
chain.path.length > 1
|
|
465
|
+
? `${resourceType}.${chain.path.slice(0, -1).join(".")}`
|
|
466
|
+
: resourceType;
|
|
467
|
+
const parentChildren = pathChildren[parentPath];
|
|
468
|
+
if (!parentChildren) return false;
|
|
469
|
+
|
|
470
|
+
const element = parentChildren.find((f) => f.name === fieldName);
|
|
471
|
+
return !!element?.isArray;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function buildArrayIndexResult(
|
|
475
|
+
chain: JsonbChain,
|
|
476
|
+
context: CompletionContext,
|
|
477
|
+
): CompletionResult {
|
|
478
|
+
return {
|
|
479
|
+
from: context.pos - chain.partialInput.length,
|
|
480
|
+
options: [
|
|
481
|
+
{
|
|
482
|
+
label: "0",
|
|
483
|
+
type: "enum",
|
|
484
|
+
detail: "array index",
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
async function resolveNestedTypes(
|
|
491
|
+
pathChildren: FhirPathChildren,
|
|
492
|
+
resourceType: string,
|
|
493
|
+
path: string[],
|
|
494
|
+
fetchSchema: (type: string) => Promise<FhirPathChildren | null>,
|
|
495
|
+
): Promise<void> {
|
|
496
|
+
for (let i = 0; i < path.length; i++) {
|
|
497
|
+
const currentPath = `${resourceType}.${path.slice(0, i + 1).join(".")}`;
|
|
498
|
+
|
|
499
|
+
if (pathChildren[currentPath]) continue;
|
|
500
|
+
|
|
501
|
+
const parentPath =
|
|
502
|
+
i === 0 ? resourceType : `${resourceType}.${path.slice(0, i).join(".")}`;
|
|
503
|
+
const parentChildren = pathChildren[parentPath];
|
|
504
|
+
if (!parentChildren) return;
|
|
505
|
+
|
|
506
|
+
const segmentName = path[i]!;
|
|
507
|
+
const element = parentChildren.find((f) => f.name === segmentName);
|
|
508
|
+
if (!element?.datatype) return;
|
|
509
|
+
|
|
510
|
+
if (element.datatype === "union") continue;
|
|
511
|
+
|
|
512
|
+
const firstChar = element.datatype[0]!;
|
|
513
|
+
if (firstChar !== firstChar.toUpperCase()) return;
|
|
514
|
+
|
|
515
|
+
const typeChildren = await fetchSchema(element.datatype);
|
|
516
|
+
if (!typeChildren) return;
|
|
517
|
+
|
|
518
|
+
const typeName = element.datatype;
|
|
519
|
+
for (const [key, children] of Object.entries(typeChildren)) {
|
|
520
|
+
const suffix = key === typeName ? "" : key.slice(typeName.length);
|
|
521
|
+
pathChildren[currentPath + suffix] = children;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// ── Completion extensions ──
|
|
527
|
+
|
|
528
|
+
function tableCompletionExtension(schemas: SchemaMap): Extension {
|
|
529
|
+
const source = (context: CompletionContext): CompletionResult | null => {
|
|
530
|
+
const line = context.state.doc.lineAt(context.pos);
|
|
531
|
+
const textBefore = line.text.slice(0, context.pos - line.from);
|
|
532
|
+
|
|
533
|
+
if (isInsideString(textBefore)) return null;
|
|
534
|
+
|
|
535
|
+
const schemaDot = textBefore.match(/(\w+)\.(\w*)$/);
|
|
536
|
+
if (schemaDot) {
|
|
537
|
+
const schemaName = schemaDot[1]!;
|
|
538
|
+
const tables = schemas[schemaName];
|
|
539
|
+
if (!tables) return null;
|
|
540
|
+
return {
|
|
541
|
+
from: context.pos - (schemaDot[2] ?? "").length,
|
|
542
|
+
options: tables.map((t) => ({ label: t, type: "table" })),
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const word = context.matchBefore(/\w*/);
|
|
547
|
+
if (!word) return null;
|
|
548
|
+
|
|
549
|
+
const beforeWord = textBefore.slice(0, word.from - line.from);
|
|
550
|
+
if (!SQL_TABLE_KEYWORDS.test(beforeWord) && !context.explicit) return null;
|
|
551
|
+
|
|
552
|
+
const options: { label: string; type: string; detail?: string }[] = [];
|
|
553
|
+
|
|
554
|
+
for (const [schema, tables] of Object.entries(schemas)) {
|
|
555
|
+
options.push({ label: `${schema}.`, type: "keyword", detail: "schema" });
|
|
556
|
+
for (const table of tables) {
|
|
557
|
+
if (schema === "public") {
|
|
558
|
+
options.push({ label: table, type: "table" });
|
|
559
|
+
} else {
|
|
560
|
+
options.push({
|
|
561
|
+
label: `${schema}.${table}`,
|
|
562
|
+
type: "table",
|
|
563
|
+
detail: schema,
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
return { from: word.from, options };
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
return EditorState.languageData.of(() => [{ autocomplete: source }]);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function columnCompletionExtension(ctx: {
|
|
576
|
+
schemas: SchemaMap;
|
|
577
|
+
columns: ColumnMap;
|
|
578
|
+
}): Extension {
|
|
579
|
+
const source = (context: CompletionContext): CompletionResult | null => {
|
|
580
|
+
const line = context.state.doc.lineAt(context.pos);
|
|
581
|
+
const textBefore = line.text.slice(0, context.pos - line.from);
|
|
582
|
+
|
|
583
|
+
if (isInsideString(textBefore)) return null;
|
|
584
|
+
|
|
585
|
+
const fullDoc = context.state.doc.toString();
|
|
586
|
+
const statement = getCurrentStatement(fullDoc, context.pos);
|
|
587
|
+
const aliases = buildAliasMap(statement, ctx.schemas);
|
|
588
|
+
|
|
589
|
+
if (Object.keys(aliases).length === 0) return null;
|
|
590
|
+
|
|
591
|
+
const aliasDot = textBefore.match(/(\w+)\.(\w*)$/);
|
|
592
|
+
if (aliasDot) {
|
|
593
|
+
const beforeAlias = textBefore.slice(
|
|
594
|
+
0,
|
|
595
|
+
textBefore.length - aliasDot[0].length,
|
|
596
|
+
);
|
|
597
|
+
if (SQL_TABLE_KEYWORDS.test(beforeAlias)) return null;
|
|
598
|
+
|
|
599
|
+
const aliasName = aliasDot[1]!;
|
|
600
|
+
const entry = aliases[aliasName.toLowerCase()];
|
|
601
|
+
if (!entry) return null;
|
|
602
|
+
const key = `${entry.schema}.${entry.table}`;
|
|
603
|
+
const cols = ctx.columns[key];
|
|
604
|
+
if (!cols || cols.length === 0) return null;
|
|
605
|
+
|
|
606
|
+
return {
|
|
607
|
+
from: context.pos - (aliasDot[2] ?? "").length,
|
|
608
|
+
options: cols.map((c) => ({
|
|
609
|
+
label: c.name,
|
|
610
|
+
type: "variable",
|
|
611
|
+
detail: c.dataType,
|
|
612
|
+
})),
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const word = context.matchBefore(/\w*/);
|
|
617
|
+
if (!word) return null;
|
|
618
|
+
if (word.from === word.to && !context.explicit) return null;
|
|
619
|
+
|
|
620
|
+
const textBeforeWord = textBefore.slice(0, word.from - line.from);
|
|
621
|
+
if (SQL_TABLE_KEYWORDS.test(textBeforeWord)) return null;
|
|
622
|
+
|
|
623
|
+
const seen = new Set<string>();
|
|
624
|
+
const options: { label: string; type: string; detail: string }[] = [];
|
|
625
|
+
for (const entry of Object.values(aliases)) {
|
|
626
|
+
const key = `${entry.schema}.${entry.table}`;
|
|
627
|
+
const cols = ctx.columns[key];
|
|
628
|
+
if (!cols) continue;
|
|
629
|
+
for (const c of cols) {
|
|
630
|
+
const dedup = `${c.name}::${entry.table}`;
|
|
631
|
+
if (seen.has(dedup)) continue;
|
|
632
|
+
seen.add(dedup);
|
|
633
|
+
options.push({
|
|
634
|
+
label: c.name,
|
|
635
|
+
type: "variable",
|
|
636
|
+
detail: `${c.dataType} · ${entry.table}`,
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (options.length === 0) return null;
|
|
642
|
+
return { from: word.from, options };
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
return EditorState.languageData.of(() => [{ autocomplete: source }]);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function triggerCompletionAfter(view: EditorView) {
|
|
649
|
+
requestAnimationFrame(() => startCompletion(view));
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function jsonbOperatorExtension(): Extension {
|
|
653
|
+
const source = (context: CompletionContext): CompletionResult | null => {
|
|
654
|
+
const line = context.state.doc.lineAt(context.pos);
|
|
655
|
+
const textBefore = line.text.slice(0, context.pos - line.from);
|
|
656
|
+
|
|
657
|
+
if (/\w\s*#$/.test(textBefore)) {
|
|
658
|
+
return {
|
|
659
|
+
from: context.pos - 1,
|
|
660
|
+
options: [
|
|
661
|
+
{
|
|
662
|
+
label: "#>> '{}'",
|
|
663
|
+
type: "operator",
|
|
664
|
+
apply: (view, _completion, from, to) => {
|
|
665
|
+
const insert = "#>> '{";
|
|
666
|
+
view.dispatch({
|
|
667
|
+
changes: { from, to, insert: `${insert}}' ` },
|
|
668
|
+
selection: { anchor: from + insert.length },
|
|
669
|
+
});
|
|
670
|
+
triggerCompletionAfter(view);
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
label: "#> '{}'",
|
|
675
|
+
type: "operator",
|
|
676
|
+
apply: (view, _completion, from, to) => {
|
|
677
|
+
const insert = "#> '{";
|
|
678
|
+
view.dispatch({
|
|
679
|
+
changes: { from, to, insert: `${insert}}' ` },
|
|
680
|
+
selection: { anchor: from + insert.length },
|
|
681
|
+
});
|
|
682
|
+
triggerCompletionAfter(view);
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
],
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (/\w\s*->$/.test(textBefore) && !/\w\s*->>$/.test(textBefore)) {
|
|
690
|
+
return {
|
|
691
|
+
from: context.pos - 2,
|
|
692
|
+
options: [
|
|
693
|
+
{
|
|
694
|
+
label: "->> ''",
|
|
695
|
+
type: "operator",
|
|
696
|
+
apply: (view, _completion, from, to) => {
|
|
697
|
+
const insert = "->> '";
|
|
698
|
+
view.dispatch({
|
|
699
|
+
changes: { from, to, insert: `${insert}' ` },
|
|
700
|
+
selection: { anchor: from + insert.length },
|
|
701
|
+
});
|
|
702
|
+
triggerCompletionAfter(view);
|
|
703
|
+
},
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
label: "-> ''",
|
|
707
|
+
type: "operator",
|
|
708
|
+
apply: (view, _completion, from, to) => {
|
|
709
|
+
const insert = "-> '";
|
|
710
|
+
view.dispatch({
|
|
711
|
+
changes: { from, to, insert: `${insert}' ` },
|
|
712
|
+
selection: { anchor: from + insert.length },
|
|
713
|
+
});
|
|
714
|
+
triggerCompletionAfter(view);
|
|
715
|
+
},
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
label: "->> 0",
|
|
719
|
+
type: "operator",
|
|
720
|
+
apply: (view, _completion, from, to) => {
|
|
721
|
+
const insert = "->> ";
|
|
722
|
+
view.dispatch({
|
|
723
|
+
changes: { from, to, insert: `${insert}0 ` },
|
|
724
|
+
selection: {
|
|
725
|
+
anchor: from + insert.length,
|
|
726
|
+
head: from + insert.length + 1,
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
},
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
label: "-> 0",
|
|
733
|
+
type: "operator",
|
|
734
|
+
apply: (view, _completion, from, to) => {
|
|
735
|
+
const insert = "-> ";
|
|
736
|
+
view.dispatch({
|
|
737
|
+
changes: { from, to, insert: `${insert}0 ` },
|
|
738
|
+
selection: {
|
|
739
|
+
anchor: from + insert.length,
|
|
740
|
+
head: from + insert.length + 1,
|
|
741
|
+
},
|
|
742
|
+
});
|
|
743
|
+
},
|
|
744
|
+
},
|
|
745
|
+
],
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
return null;
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
return EditorState.languageData.of(() => [{ autocomplete: source }]);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function jsonbCompletionExtension(ctx: {
|
|
756
|
+
schemas: SchemaMap;
|
|
757
|
+
jsonbColumns: JsonbColumnMap;
|
|
758
|
+
sdCache: Record<string, FhirPathChildren>;
|
|
759
|
+
sdNotFound: Set<string>;
|
|
760
|
+
fetchSchema: (type: string) => Promise<FhirPathChildren | null>;
|
|
761
|
+
}): Extension {
|
|
762
|
+
const resolveChain = (
|
|
763
|
+
context: CompletionContext,
|
|
764
|
+
): { chain: JsonbChain; resourceType: string } | null => {
|
|
765
|
+
const line = context.state.doc.lineAt(context.pos);
|
|
766
|
+
const textBefore = line.text.slice(0, context.pos - line.from);
|
|
767
|
+
|
|
768
|
+
const chain = parseJsonbChain(textBefore);
|
|
769
|
+
if (!chain) return null;
|
|
770
|
+
|
|
771
|
+
const fullDoc = context.state.doc.toString();
|
|
772
|
+
const statement = getCurrentStatement(fullDoc, context.pos);
|
|
773
|
+
const aliases = buildAliasMap(statement, ctx.schemas);
|
|
774
|
+
|
|
775
|
+
let resolved: AliasEntry | null = null;
|
|
776
|
+
|
|
777
|
+
if (chain.tableOrAlias) {
|
|
778
|
+
resolved = aliases[chain.tableOrAlias.toLowerCase()] ?? null;
|
|
779
|
+
} else {
|
|
780
|
+
for (const entry of Object.values(aliases)) {
|
|
781
|
+
const key = `${entry.schema}.${entry.table}`;
|
|
782
|
+
const cols = ctx.jsonbColumns[key];
|
|
783
|
+
if (cols?.includes(chain.column)) {
|
|
784
|
+
resolved = entry;
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
if (!resolved) return null;
|
|
791
|
+
|
|
792
|
+
const jsonbKey = `${resolved.schema}.${resolved.table}`;
|
|
793
|
+
const jsonbCols = ctx.jsonbColumns[jsonbKey];
|
|
794
|
+
if (!jsonbCols?.includes(chain.column)) return null;
|
|
795
|
+
|
|
796
|
+
if (chain.column !== "resource") return null;
|
|
797
|
+
|
|
798
|
+
const resourceType = tableToResourceType(resolved.table);
|
|
799
|
+
if (ctx.sdNotFound.has(resourceType)) return null;
|
|
800
|
+
|
|
801
|
+
return { chain, resourceType };
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
const complete = async (
|
|
805
|
+
chain: JsonbChain,
|
|
806
|
+
resourceType: string,
|
|
807
|
+
pathChildren: FhirPathChildren,
|
|
808
|
+
context: CompletionContext,
|
|
809
|
+
): Promise<CompletionResult | null> => {
|
|
810
|
+
if (chain.path.length > 0) {
|
|
811
|
+
await resolveNestedTypes(
|
|
812
|
+
pathChildren,
|
|
813
|
+
resourceType,
|
|
814
|
+
chain.path,
|
|
815
|
+
ctx.fetchSchema,
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
if (isArrayPosition(chain, pathChildren, resourceType)) {
|
|
820
|
+
return buildArrayIndexResult(chain, context);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
return buildJsonbResult(chain, pathChildren, resourceType, context);
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
const source = (
|
|
827
|
+
context: CompletionContext,
|
|
828
|
+
): CompletionResult | null | Promise<CompletionResult | null> => {
|
|
829
|
+
const info = resolveChain(context);
|
|
830
|
+
if (!info) return null;
|
|
831
|
+
|
|
832
|
+
const { chain, resourceType } = info;
|
|
833
|
+
|
|
834
|
+
const cached = ctx.sdCache[resourceType];
|
|
835
|
+
if (cached) {
|
|
836
|
+
if (chain.path.length === 0) {
|
|
837
|
+
return buildJsonbResult(chain, cached, resourceType, context);
|
|
838
|
+
}
|
|
839
|
+
return complete(chain, resourceType, cached, context);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
return ctx.fetchSchema(resourceType).then((fetched) => {
|
|
843
|
+
if (!fetched) return null;
|
|
844
|
+
return complete(chain, resourceType, fetched, context);
|
|
845
|
+
});
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
return EditorState.languageData.of(() => [{ autocomplete: source }]);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function sqlCompletionOverride(): Extension {
|
|
852
|
+
return autocompletion({
|
|
853
|
+
override: [
|
|
854
|
+
async (context: CompletionContext): Promise<CompletionResult | null> => {
|
|
855
|
+
const line = context.state.doc.lineAt(context.pos);
|
|
856
|
+
const textBefore = line.text.slice(0, context.pos - line.from);
|
|
857
|
+
const inJsonb = isInJsonbContext(textBefore);
|
|
858
|
+
|
|
859
|
+
const langSources = context.state.languageDataAt<CompletionSource>(
|
|
860
|
+
"autocomplete",
|
|
861
|
+
context.pos,
|
|
862
|
+
);
|
|
863
|
+
|
|
864
|
+
const results = (
|
|
865
|
+
await Promise.all(
|
|
866
|
+
langSources.map((src) => Promise.resolve(src(context))),
|
|
867
|
+
)
|
|
868
|
+
).filter((r): r is CompletionResult => r !== null);
|
|
869
|
+
|
|
870
|
+
if (results.length === 0) return null;
|
|
871
|
+
|
|
872
|
+
if (inJsonb) {
|
|
873
|
+
const jsonbTypes = new Set(["property", "enum", "operator"]);
|
|
874
|
+
const jsonbResult = results.find((r) =>
|
|
875
|
+
r.options.some((o) => jsonbTypes.has(o.type ?? "")),
|
|
876
|
+
);
|
|
877
|
+
if (!jsonbResult) return null;
|
|
878
|
+
return {
|
|
879
|
+
...jsonbResult,
|
|
880
|
+
options: jsonbResult.options.filter((o) =>
|
|
881
|
+
jsonbTypes.has(o.type ?? ""),
|
|
882
|
+
),
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
const aliasColumnResult = results.find(
|
|
887
|
+
(r) =>
|
|
888
|
+
r.options.length > 0 &&
|
|
889
|
+
r.options.every((o) => o.type === "variable"),
|
|
890
|
+
);
|
|
891
|
+
if (aliasColumnResult) return aliasColumnResult;
|
|
892
|
+
|
|
893
|
+
const hasTableResults = results.some((r) =>
|
|
894
|
+
r.options.some((o) => o.type === "table"),
|
|
895
|
+
);
|
|
896
|
+
|
|
897
|
+
if (hasTableResults) {
|
|
898
|
+
const tableOptions = results.flatMap((r) =>
|
|
899
|
+
r.options.filter((o) => o.type === "table" || o.type === "keyword"),
|
|
900
|
+
);
|
|
901
|
+
const from = results.find((r) =>
|
|
902
|
+
r.options.some((o) => o.type === "table"),
|
|
903
|
+
)?.from;
|
|
904
|
+
if (from == null) return null;
|
|
905
|
+
return { from, options: tableOptions };
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
if (results.length === 1) return results[0]!;
|
|
909
|
+
|
|
910
|
+
const groups = new Map<
|
|
911
|
+
number,
|
|
912
|
+
{ from: number; options: Completion[] }
|
|
913
|
+
>();
|
|
914
|
+
for (const r of results) {
|
|
915
|
+
const existing = groups.get(r.from);
|
|
916
|
+
if (existing) {
|
|
917
|
+
existing.options.push(...r.options);
|
|
918
|
+
} else {
|
|
919
|
+
groups.set(r.from, {
|
|
920
|
+
from: r.from,
|
|
921
|
+
options: [...r.options],
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
let best: { from: number; options: Completion[] } | null = null;
|
|
927
|
+
for (const g of groups.values()) {
|
|
928
|
+
if (!best || g.options.length > best.options.length) best = g;
|
|
929
|
+
}
|
|
930
|
+
if (best) {
|
|
931
|
+
best.options = best.options.map((o) => {
|
|
932
|
+
if (o.type === "keyword") return { ...o, boost: 2 };
|
|
933
|
+
if (o.type === "type") return { ...o, boost: 1 };
|
|
934
|
+
if (o.type === "variable") return { ...o, boost: -1 };
|
|
935
|
+
return o;
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
return best;
|
|
939
|
+
},
|
|
940
|
+
],
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// ── Public API ──
|
|
945
|
+
|
|
946
|
+
export async function fetchSqlMetadata(
|
|
947
|
+
executeSql: SqlConfig["executeSql"],
|
|
948
|
+
): Promise<SqlMetadata> {
|
|
949
|
+
const [tablesRows, jsonbRows, functionsRows, columnsRows] = await Promise.all(
|
|
950
|
+
[
|
|
951
|
+
executeSql(TABLES_QUERY, "tables"),
|
|
952
|
+
executeSql(JSONB_COLUMNS_QUERY, "jsonb_columns"),
|
|
953
|
+
executeSql(FUNCTIONS_QUERY, "functions"),
|
|
954
|
+
executeSql(COLUMNS_QUERY, "columns"),
|
|
955
|
+
],
|
|
956
|
+
);
|
|
957
|
+
|
|
958
|
+
const schemas: SchemaMap = {};
|
|
959
|
+
for (const row of tablesRows) {
|
|
960
|
+
const s = String(row.table_schema);
|
|
961
|
+
if (!schemas[s]) schemas[s] = [];
|
|
962
|
+
schemas[s].push(String(row.table_name));
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const jsonbColumns: JsonbColumnMap = {};
|
|
966
|
+
for (const row of jsonbRows) {
|
|
967
|
+
const key = `${row.table_schema}.${row.table_name}`;
|
|
968
|
+
if (!jsonbColumns[key]) jsonbColumns[key] = [];
|
|
969
|
+
jsonbColumns[key].push(String(row.column_name));
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const functions = functionsRows.map((r) => String(r.name));
|
|
973
|
+
|
|
974
|
+
const columns: ColumnMap = {};
|
|
975
|
+
for (const row of columnsRows) {
|
|
976
|
+
const key = `${row.table_schema}.${row.table_name}`;
|
|
977
|
+
if (!columns[key]) columns[key] = [];
|
|
978
|
+
columns[key].push({
|
|
979
|
+
name: String(row.column_name),
|
|
980
|
+
dataType: String(row.data_type),
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
return { schemas, jsonbColumns, functions, columns };
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
export function buildSqlCompletionExtensions(
|
|
988
|
+
metadata: SqlMetadata,
|
|
989
|
+
executeSql: SqlConfig["executeSql"],
|
|
990
|
+
): Extension[] {
|
|
991
|
+
const sdCache: Record<string, FhirPathChildren> = {};
|
|
992
|
+
const sdNotFound = new Set<string>();
|
|
993
|
+
|
|
994
|
+
const fetchSchema = async (
|
|
995
|
+
resourceType: string,
|
|
996
|
+
): Promise<FhirPathChildren | null> => {
|
|
997
|
+
if (sdCache[resourceType]) return sdCache[resourceType];
|
|
998
|
+
if (sdNotFound.has(resourceType)) return null;
|
|
999
|
+
|
|
1000
|
+
try {
|
|
1001
|
+
const name = resourceType.replace(/'/g, "''");
|
|
1002
|
+
const rows = await executeSql(
|
|
1003
|
+
`SELECT resource FROM far.canonicalresource WHERE rt = 'StructureDefinition' AND resource->>'name' = '${name}' LIMIT 1`,
|
|
1004
|
+
"structure_definition",
|
|
1005
|
+
);
|
|
1006
|
+
const sd = (rows[0]?.resource ?? null) as StructureDefinition | null;
|
|
1007
|
+
if (!sd) {
|
|
1008
|
+
sdNotFound.add(resourceType);
|
|
1009
|
+
return null;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
const pathChildren = buildFromStructureDefinition(sd);
|
|
1013
|
+
transformReferenceFields(pathChildren);
|
|
1014
|
+
sdCache[resourceType] = pathChildren;
|
|
1015
|
+
return pathChildren;
|
|
1016
|
+
} catch {
|
|
1017
|
+
sdNotFound.add(resourceType);
|
|
1018
|
+
return null;
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
return [
|
|
1023
|
+
EditorView.theme({
|
|
1024
|
+
".cm-tooltip.cm-tooltip-autocomplete": {
|
|
1025
|
+
background: "var(--color-bg-primary)",
|
|
1026
|
+
border: "1px solid var(--color-border-primary)",
|
|
1027
|
+
borderRadius: "var(--radius-md)",
|
|
1028
|
+
padding: "4px",
|
|
1029
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.1)",
|
|
1030
|
+
fontFamily: "var(--font-family-sans)",
|
|
1031
|
+
fontSize: "14px",
|
|
1032
|
+
},
|
|
1033
|
+
".cm-tooltip.cm-tooltip-autocomplete > ul": {
|
|
1034
|
+
maxHeight: "300px",
|
|
1035
|
+
},
|
|
1036
|
+
".cm-tooltip-autocomplete ul li": {
|
|
1037
|
+
padding: "4px 8px",
|
|
1038
|
+
borderRadius: "4px",
|
|
1039
|
+
},
|
|
1040
|
+
".cm-tooltip-autocomplete ul li[aria-selected]": {
|
|
1041
|
+
background: "var(--color-bg-quaternary)",
|
|
1042
|
+
color: "var(--color-text-primary)",
|
|
1043
|
+
},
|
|
1044
|
+
".cm-completionLabel": {
|
|
1045
|
+
color: "var(--color-text-primary)",
|
|
1046
|
+
fontSize: "14px",
|
|
1047
|
+
},
|
|
1048
|
+
".cm-completionDetail": {
|
|
1049
|
+
color: "var(--color-text-tertiary)",
|
|
1050
|
+
fontSize: "12px",
|
|
1051
|
+
fontStyle: "normal",
|
|
1052
|
+
marginLeft: "8px",
|
|
1053
|
+
},
|
|
1054
|
+
".cm-completionIcon": {
|
|
1055
|
+
padding: "0",
|
|
1056
|
+
marginRight: "6px",
|
|
1057
|
+
width: "18px",
|
|
1058
|
+
height: "18px",
|
|
1059
|
+
display: "inline-flex",
|
|
1060
|
+
alignItems: "center",
|
|
1061
|
+
justifyContent: "center",
|
|
1062
|
+
borderRadius: "4px",
|
|
1063
|
+
fontSize: "11px",
|
|
1064
|
+
fontWeight: "600",
|
|
1065
|
+
lineHeight: "1",
|
|
1066
|
+
boxSizing: "border-box",
|
|
1067
|
+
},
|
|
1068
|
+
".cm-completionIcon-table": {
|
|
1069
|
+
background: "var(--color-blue-100)",
|
|
1070
|
+
color: "var(--color-blue-600)",
|
|
1071
|
+
},
|
|
1072
|
+
".cm-completionIcon-table::after": {
|
|
1073
|
+
content: "'T'",
|
|
1074
|
+
},
|
|
1075
|
+
".cm-completionIcon-keyword": {
|
|
1076
|
+
background: "var(--color-green-200)",
|
|
1077
|
+
color: "var(--color-green-700)",
|
|
1078
|
+
},
|
|
1079
|
+
".cm-completionIcon-keyword::after": {
|
|
1080
|
+
content: "'S'",
|
|
1081
|
+
},
|
|
1082
|
+
".cm-completionIcon-property": {
|
|
1083
|
+
background: "var(--color-purple-100)",
|
|
1084
|
+
color: "var(--color-purple-600)",
|
|
1085
|
+
},
|
|
1086
|
+
".cm-completionIcon-property::after": {
|
|
1087
|
+
content: "'F'",
|
|
1088
|
+
},
|
|
1089
|
+
".cm-completionIcon-variable": {
|
|
1090
|
+
background: "var(--color-yellow-200)",
|
|
1091
|
+
color: "var(--color-yellow-700)",
|
|
1092
|
+
},
|
|
1093
|
+
".cm-completionIcon-variable::after": {
|
|
1094
|
+
content: "'C'",
|
|
1095
|
+
},
|
|
1096
|
+
}),
|
|
1097
|
+
tableCompletionExtension(metadata.schemas),
|
|
1098
|
+
columnCompletionExtension({
|
|
1099
|
+
schemas: metadata.schemas,
|
|
1100
|
+
columns: metadata.columns,
|
|
1101
|
+
}),
|
|
1102
|
+
jsonbCompletionExtension({
|
|
1103
|
+
schemas: metadata.schemas,
|
|
1104
|
+
jsonbColumns: metadata.jsonbColumns,
|
|
1105
|
+
sdCache,
|
|
1106
|
+
sdNotFound,
|
|
1107
|
+
fetchSchema,
|
|
1108
|
+
}),
|
|
1109
|
+
jsonbOperatorExtension(),
|
|
1110
|
+
sqlCompletionOverride(),
|
|
1111
|
+
];
|
|
1112
|
+
}
|