@k3-universe/react-kit 0.0.27 → 0.0.29
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/.storybook/main.ts +1 -1
- package/.storybook/preview.ts +18 -10
- package/biome.json +10 -0
- package/dist/index.js +2319 -1227
- package/dist/kit/builder/auth/AuthProvider.d.ts +36 -0
- package/dist/kit/builder/auth/AuthProvider.d.ts.map +1 -0
- package/dist/kit/builder/auth/adapter.d.ts +14 -0
- package/dist/kit/builder/auth/adapter.d.ts.map +1 -0
- package/dist/kit/builder/auth/client-adapters.d.ts +149 -0
- package/dist/kit/builder/auth/client-adapters.d.ts.map +1 -0
- package/dist/kit/builder/auth/components.d.ts +119 -0
- package/dist/kit/builder/auth/components.d.ts.map +1 -0
- package/dist/kit/builder/auth/hooks.d.ts +158 -0
- package/dist/kit/builder/auth/hooks.d.ts.map +1 -0
- package/dist/kit/builder/auth/index.d.ts +11 -0
- package/dist/kit/builder/auth/index.d.ts.map +1 -0
- package/dist/kit/builder/auth/permission-checker.d.ts +31 -0
- package/dist/kit/builder/auth/permission-checker.d.ts.map +1 -0
- package/dist/kit/builder/auth/storage.d.ts +17 -0
- package/dist/kit/builder/auth/storage.d.ts.map +1 -0
- package/dist/kit/builder/auth/token-manager.d.ts +9 -0
- package/dist/kit/builder/auth/token-manager.d.ts.map +1 -0
- package/dist/kit/builder/auth/types.d.ts +183 -0
- package/dist/kit/builder/auth/types.d.ts.map +1 -0
- package/dist/kit/builder/data-table/components/DataTable.d.ts +2 -1
- package/dist/kit/builder/data-table/components/DataTable.d.ts.map +1 -1
- package/dist/kit/builder/data-table/components/DataTableColumnHeader.d.ts +2 -2
- package/dist/kit/builder/data-table/components/DataTableColumnHeader.d.ts.map +1 -1
- package/dist/kit/builder/data-table/components/DataTablePagination.d.ts +2 -1
- package/dist/kit/builder/data-table/components/DataTablePagination.d.ts.map +1 -1
- package/dist/kit/builder/data-table/components/DataTableViewOptions.d.ts +1 -1
- package/dist/kit/builder/data-table/components/DataTableViewOptions.d.ts.map +1 -1
- package/dist/kit/builder/data-table/types.d.ts.map +1 -1
- package/dist/kit/builder/dialog/index.d.ts +1 -1
- package/dist/kit/builder/dialog/index.d.ts.map +1 -1
- package/dist/kit/builder/dialog/provider.d.ts +0 -1
- package/dist/kit/builder/dialog/provider.d.ts.map +1 -1
- package/dist/kit/builder/form/components/FormBuilder.d.ts.map +1 -1
- package/dist/kit/builder/form/components/FormBuilderActions.d.ts.map +1 -1
- package/dist/kit/builder/form/components/FormBuilderContext.d.ts.map +1 -1
- package/dist/kit/builder/form/components/FormBuilderField.d.ts +1 -1
- package/dist/kit/builder/form/components/FormBuilderField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/ArrayField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/ArrayField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/AutocompleteField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/AutocompleteField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/CheckboxField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/CheckboxField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/DateField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/DateField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/DatePickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/DatePickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/DateRangePickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/DateRangePickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/DateTimePickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/DateTimePickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/DateTimeRangePickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/DateTimeRangePickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/FileField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/FileField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/MonthPickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/MonthPickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/MonthRangePickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/MonthRangePickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/NumberField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/NumberField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/ObjectField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/RadioField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/RadioField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/SelectField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/SelectField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/SwitchField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/SwitchField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/TextField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/TextField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/TextareaField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/TextareaField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/TimePickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/TimePickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/TimeRangePickerField.d.ts +1 -1
- package/dist/kit/builder/form/components/fields/TimeRangePickerField.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/index.d.ts.map +1 -1
- package/dist/kit/builder/form/components/fields/types.d.ts.map +1 -1
- package/dist/kit/builder/form/components/sectionNodes.d.ts.map +1 -1
- package/dist/kit/builder/form/hooks/useFormBuilder.d.ts.map +1 -1
- package/dist/kit/builder/form/types.d.ts.map +1 -1
- package/dist/kit/builder/form/utils/section-factories.d.ts.map +1 -1
- package/dist/kit/builder/page/Page.d.ts.map +1 -1
- package/dist/kit/builder/page/index.d.ts.map +1 -1
- package/dist/kit/builder/section/SectionBuilder.d.ts +1 -1
- package/dist/kit/builder/section/SectionBuilder.d.ts.map +1 -1
- package/dist/kit/builder/section/SectionContainer.d.ts +14 -0
- package/dist/kit/builder/section/SectionContainer.d.ts.map +1 -0
- package/dist/kit/builder/stack-dialog/context.d.ts.map +1 -1
- package/dist/kit/builder/stack-dialog/hooks.d.ts.map +1 -1
- package/dist/kit/builder/stack-dialog/index.d.ts +3 -3
- package/dist/kit/builder/stack-dialog/index.d.ts.map +1 -1
- package/dist/kit/builder/stack-dialog/provider.d.ts.map +1 -1
- package/dist/kit/builder/stack-dialog/renderer.d.ts.map +1 -1
- package/dist/kit/builder/stack-dialog/types.d.ts +1 -1
- package/dist/kit/builder/stack-dialog/types.d.ts.map +1 -1
- package/dist/kit/components/autocomplete/Autocomplete.d.ts +1 -1
- package/dist/kit/components/autocomplete/Autocomplete.d.ts.map +1 -1
- package/dist/kit/components/autocomplete/types.d.ts.map +1 -1
- package/dist/kit/components/datepicker/DatePicker.d.ts.map +1 -1
- package/dist/kit/components/datepicker/DateRangePicker.d.ts.map +1 -1
- package/dist/kit/components/datetimepicker/DateTimePicker.d.ts.map +1 -1
- package/dist/kit/components/datetimepicker/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/kit/components/datetimepicker/index.d.ts.map +1 -1
- package/dist/kit/components/fileuploader/FileUploader.d.ts.map +1 -1
- package/dist/kit/components/fileuploader/types.d.ts +2 -2
- package/dist/kit/components/forminfo/FormInfoError.d.ts.map +1 -1
- package/dist/kit/components/login/Login.d.ts +1 -1
- package/dist/kit/components/login/Login.d.ts.map +1 -1
- package/dist/kit/components/monthpicker/MonthInput.d.ts.map +1 -1
- package/dist/kit/components/monthpicker/MonthPicker.d.ts.map +1 -1
- package/dist/kit/components/monthpicker/MonthRangeInput.d.ts.map +1 -1
- package/dist/kit/components/monthpicker/MonthRangePicker.d.ts.map +1 -1
- package/dist/kit/components/timepicker/TimePicker.d.ts.map +1 -1
- package/dist/kit/components/timepicker/TimeRangePicker.d.ts.map +1 -1
- package/dist/kit/components/timepicker/index.d.ts.map +1 -1
- package/dist/kit/layouts/admin/components/AdminLayout.d.ts.map +1 -1
- package/dist/kit/layouts/admin/components/ThemeToggle.d.ts.map +1 -1
- package/dist/kit/layouts/admin/hooks/menu.d.ts.map +1 -1
- package/dist/kit/layouts/admin/providers/AdminMenuProvider.d.ts +1 -1
- package/dist/kit/layouts/admin/providers/AdminMenuProvider.d.ts.map +1 -1
- package/dist/shadcn/hooks/use-mobile.d.ts.map +1 -1
- package/dist/shadcn/ui/accordion.d.ts +2 -2
- package/dist/shadcn/ui/accordion.d.ts.map +1 -1
- package/dist/shadcn/ui/alert-dialog.d.ts +4 -4
- package/dist/shadcn/ui/alert-dialog.d.ts.map +1 -1
- package/dist/shadcn/ui/alert.d.ts +4 -4
- package/dist/shadcn/ui/alert.d.ts.map +1 -1
- package/dist/shadcn/ui/aspect-ratio.d.ts +1 -1
- package/dist/shadcn/ui/aspect-ratio.d.ts.map +1 -1
- package/dist/shadcn/ui/avatar.d.ts +2 -2
- package/dist/shadcn/ui/avatar.d.ts.map +1 -1
- package/dist/shadcn/ui/badge.d.ts +2 -2
- package/dist/shadcn/ui/badge.d.ts.map +1 -1
- package/dist/shadcn/ui/breadcrumb.d.ts +8 -8
- package/dist/shadcn/ui/breadcrumb.d.ts.map +1 -1
- package/dist/shadcn/ui/button.d.ts +2 -2
- package/dist/shadcn/ui/button.d.ts.map +1 -1
- package/dist/shadcn/ui/calendar.d.ts +2 -2
- package/dist/shadcn/ui/calendar.d.ts.map +1 -1
- package/dist/shadcn/ui/card.d.ts +8 -8
- package/dist/shadcn/ui/card.d.ts.map +1 -1
- package/dist/shadcn/ui/carousel.d.ts +5 -5
- package/dist/shadcn/ui/carousel.d.ts.map +1 -1
- package/dist/shadcn/ui/chart.d.ts +7 -7
- package/dist/shadcn/ui/chart.d.ts.map +1 -1
- package/dist/shadcn/ui/checkbox.d.ts +2 -2
- package/dist/shadcn/ui/checkbox.d.ts.map +1 -1
- package/dist/shadcn/ui/collapsible.d.ts +1 -1
- package/dist/shadcn/ui/collapsible.d.ts.map +1 -1
- package/dist/shadcn/ui/command.d.ts +2 -2
- package/dist/shadcn/ui/command.d.ts.map +1 -1
- package/dist/shadcn/ui/context-menu.d.ts +4 -4
- package/dist/shadcn/ui/context-menu.d.ts.map +1 -1
- package/dist/shadcn/ui/dialog.d.ts +4 -4
- package/dist/shadcn/ui/dialog.d.ts.map +1 -1
- package/dist/shadcn/ui/drawer.d.ts +3 -3
- package/dist/shadcn/ui/drawer.d.ts.map +1 -1
- package/dist/shadcn/ui/dropdown-menu.d.ts +4 -4
- package/dist/shadcn/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/shadcn/ui/form.d.ts +5 -5
- package/dist/shadcn/ui/form.d.ts.map +1 -1
- package/dist/shadcn/ui/hover-card.d.ts +2 -2
- package/dist/shadcn/ui/hover-card.d.ts.map +1 -1
- package/dist/shadcn/ui/input-otp.d.ts +4 -4
- package/dist/shadcn/ui/input-otp.d.ts.map +1 -1
- package/dist/shadcn/ui/input.d.ts +2 -2
- package/dist/shadcn/ui/input.d.ts.map +1 -1
- package/dist/shadcn/ui/label.d.ts +2 -2
- package/dist/shadcn/ui/label.d.ts.map +1 -1
- package/dist/shadcn/ui/menubar.d.ts +4 -4
- package/dist/shadcn/ui/menubar.d.ts.map +1 -1
- package/dist/shadcn/ui/navigation-menu.d.ts +2 -2
- package/dist/shadcn/ui/navigation-menu.d.ts.map +1 -1
- package/dist/shadcn/ui/pagination.d.ts +6 -6
- package/dist/shadcn/ui/pagination.d.ts.map +1 -1
- package/dist/shadcn/ui/popover.d.ts +2 -2
- package/dist/shadcn/ui/popover.d.ts.map +1 -1
- package/dist/shadcn/ui/progress.d.ts +2 -2
- package/dist/shadcn/ui/progress.d.ts.map +1 -1
- package/dist/shadcn/ui/radio-group.d.ts +2 -2
- package/dist/shadcn/ui/radio-group.d.ts.map +1 -1
- package/dist/shadcn/ui/resizable.d.ts +2 -2
- package/dist/shadcn/ui/resizable.d.ts.map +1 -1
- package/dist/shadcn/ui/scroll-area.d.ts +2 -2
- package/dist/shadcn/ui/scroll-area.d.ts.map +1 -1
- package/dist/shadcn/ui/select.d.ts +3 -3
- package/dist/shadcn/ui/select.d.ts.map +1 -1
- package/dist/shadcn/ui/separator.d.ts +2 -2
- package/dist/shadcn/ui/separator.d.ts.map +1 -1
- package/dist/shadcn/ui/sheet.d.ts +5 -5
- package/dist/shadcn/ui/sheet.d.ts.map +1 -1
- package/dist/shadcn/ui/sidebar.d.ts +26 -26
- package/dist/shadcn/ui/sidebar.d.ts.map +1 -1
- package/dist/shadcn/ui/skeleton.d.ts +1 -1
- package/dist/shadcn/ui/skeleton.d.ts.map +1 -1
- package/dist/shadcn/ui/slider.d.ts +2 -2
- package/dist/shadcn/ui/slider.d.ts.map +1 -1
- package/dist/shadcn/ui/sonner.d.ts.map +1 -1
- package/dist/shadcn/ui/switch.d.ts +2 -2
- package/dist/shadcn/ui/switch.d.ts.map +1 -1
- package/dist/shadcn/ui/table.d.ts +9 -9
- package/dist/shadcn/ui/table.d.ts.map +1 -1
- package/dist/shadcn/ui/tabs.d.ts +2 -2
- package/dist/shadcn/ui/tabs.d.ts.map +1 -1
- package/dist/shadcn/ui/textarea.d.ts +2 -2
- package/dist/shadcn/ui/textarea.d.ts.map +1 -1
- package/dist/shadcn/ui/toggle-group.d.ts +2 -2
- package/dist/shadcn/ui/toggle-group.d.ts.map +1 -1
- package/dist/shadcn/ui/toggle.d.ts +2 -2
- package/dist/shadcn/ui/toggle.d.ts.map +1 -1
- package/dist/shadcn/ui/tooltip.d.ts +2 -2
- package/dist/shadcn/ui/tooltip.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/kit/builder/auth/AuthProvider.tsx +131 -0
- package/src/kit/builder/auth/adapter.ts +436 -0
- package/src/kit/builder/auth/client-adapters.ts +398 -0
- package/src/kit/builder/auth/components.tsx +221 -0
- package/src/kit/builder/auth/hooks.ts +237 -0
- package/src/kit/builder/auth/index.ts +134 -0
- package/src/kit/builder/auth/permission-checker.ts +150 -0
- package/src/kit/builder/auth/storage.ts +366 -0
- package/src/kit/builder/auth/token-manager.ts +55 -0
- package/src/kit/builder/auth/types.ts +393 -0
- package/src/kit/builder/data-table/components/DataTable.tsx +216 -82
- package/src/kit/builder/data-table/components/DataTableColumnHeader.tsx +9 -5
- package/src/kit/builder/data-table/components/DataTablePagination.tsx +49 -27
- package/src/kit/builder/data-table/components/DataTableViewOptions.tsx +13 -4
- package/src/kit/builder/data-table/types.ts +18 -3
- package/src/kit/builder/dialog/index.ts +5 -1
- package/src/kit/builder/dialog/provider.tsx +56 -27
- package/src/kit/builder/form/components/FormBuilder.tsx +10 -14
- package/src/kit/builder/form/components/FormBuilderActions.tsx +1 -1
- package/src/kit/builder/form/components/FormBuilderContext.tsx +13 -6
- package/src/kit/builder/form/components/FormBuilderField.tsx +70 -20
- package/src/kit/builder/form/components/fields/ArrayField.tsx +148 -62
- package/src/kit/builder/form/components/fields/AutocompleteField.tsx +53 -18
- package/src/kit/builder/form/components/fields/CheckboxField.tsx +20 -11
- package/src/kit/builder/form/components/fields/DateField.tsx +17 -6
- package/src/kit/builder/form/components/fields/DatePickerField.tsx +15 -10
- package/src/kit/builder/form/components/fields/DateRangePickerField.tsx +20 -15
- package/src/kit/builder/form/components/fields/DateTimePickerField.tsx +16 -11
- package/src/kit/builder/form/components/fields/DateTimeRangePickerField.tsx +23 -17
- package/src/kit/builder/form/components/fields/FileField.tsx +10 -5
- package/src/kit/builder/form/components/fields/MonthPickerField.tsx +18 -11
- package/src/kit/builder/form/components/fields/MonthRangePickerField.tsx +23 -17
- package/src/kit/builder/form/components/fields/NumberField.tsx +9 -4
- package/src/kit/builder/form/components/fields/ObjectField.tsx +12 -7
- package/src/kit/builder/form/components/fields/RadioField.tsx +32 -14
- package/src/kit/builder/form/components/fields/SelectField.tsx +26 -11
- package/src/kit/builder/form/components/fields/SwitchField.tsx +20 -11
- package/src/kit/builder/form/components/fields/TextField.tsx +11 -5
- package/src/kit/builder/form/components/fields/TextareaField.tsx +9 -4
- package/src/kit/builder/form/components/fields/TimePickerField.tsx +16 -11
- package/src/kit/builder/form/components/fields/TimeRangePickerField.tsx +23 -17
- package/src/kit/builder/form/components/fields/index.ts +21 -21
- package/src/kit/builder/form/components/fields/types.ts +15 -11
- package/src/kit/builder/form/components/sectionNodes.tsx +63 -40
- package/src/kit/builder/form/hooks/useFormBuilder.ts +83 -34
- package/src/kit/builder/form/types.ts +173 -148
- package/src/kit/builder/form/utils/section-factories.ts +4 -1
- package/src/kit/builder/form/utils/transformers.ts +4 -4
- package/src/kit/builder/form/utils/validations.ts +1 -1
- package/src/kit/builder/page/Page.tsx +26 -6
- package/src/kit/builder/page/index.ts +1 -1
- package/src/kit/builder/section/SectionBuilder.tsx +252 -127
- package/src/kit/builder/section/SectionContainer.tsx +85 -0
- package/src/kit/builder/stack-dialog/context.ts +10 -4
- package/src/kit/builder/stack-dialog/hooks.ts +4 -3
- package/src/kit/builder/stack-dialog/index.ts +5 -11
- package/src/kit/builder/stack-dialog/provider.tsx +11 -11
- package/src/kit/builder/stack-dialog/renderer.tsx +23 -26
- package/src/kit/builder/stack-dialog/types.ts +18 -18
- package/src/kit/components/autocomplete/Autocomplete.tsx +631 -549
- package/src/kit/components/autocomplete/types.ts +17 -17
- package/src/kit/components/datepicker/DatePicker.tsx +33 -9
- package/src/kit/components/datepicker/DateRangePicker.tsx +159 -87
- package/src/kit/components/datetimepicker/DateTimePicker.tsx +136 -30
- package/src/kit/components/datetimepicker/DateTimeRangePicker.tsx +257 -67
- package/src/kit/components/datetimepicker/index.ts +3 -3
- package/src/kit/components/fileuploader/FileUploader.tsx +315 -180
- package/src/kit/components/fileuploader/index.ts +3 -3
- package/src/kit/components/fileuploader/types.ts +3 -3
- package/src/kit/components/forminfo/FormInfoError.tsx +26 -11
- package/src/kit/components/login/Login.tsx +13 -4
- package/src/kit/components/monthpicker/MonthInput.tsx +13 -4
- package/src/kit/components/monthpicker/MonthPicker.tsx +12 -11
- package/src/kit/components/monthpicker/MonthRangeInput.tsx +29 -8
- package/src/kit/components/monthpicker/MonthRangePicker.tsx +23 -21
- package/src/kit/components/timepicker/TimePicker.tsx +19 -11
- package/src/kit/components/timepicker/TimeRangePicker.tsx +106 -29
- package/src/kit/components/timepicker/index.ts +3 -3
- package/src/kit/layouts/admin/components/AdminLayout.tsx +53 -24
- package/src/kit/layouts/admin/components/ThemeToggle.tsx +3 -9
- package/src/kit/layouts/admin/hooks/menu.ts +11 -5
- package/src/kit/layouts/admin/providers/AdminMenuProvider.tsx +59 -39
- package/src/kit/layouts/admin/types/index.ts +1 -1
- package/src/kit/themes/base.css +1 -1
- package/src/kit/themes/clean-slate.css +40 -32
- package/src/kit/themes/default.css +34 -24
- package/src/kit/themes/minimal-modern.css +37 -29
- package/src/kit/themes/spotify.css +56 -39
- package/src/shadcn/hooks/use-mobile.ts +13 -11
- package/src/shadcn/lib/utils.ts +2 -2
- package/src/shadcn/ui/accordion.tsx +14 -14
- package/src/shadcn/ui/alert-dialog.tsx +29 -29
- package/src/shadcn/ui/alert.tsx +20 -20
- package/src/shadcn/ui/aspect-ratio.tsx +4 -4
- package/src/shadcn/ui/avatar.tsx +13 -13
- package/src/shadcn/ui/badge.tsx +16 -16
- package/src/shadcn/ui/breadcrumb.tsx +28 -28
- package/src/shadcn/ui/button.tsx +23 -23
- package/src/shadcn/ui/calendar.tsx +82 -78
- package/src/shadcn/ui/card.tsx +27 -27
- package/src/shadcn/ui/carousel.tsx +93 -93
- package/src/shadcn/ui/chart.tsx +103 -103
- package/src/shadcn/ui/checkbox.tsx +9 -9
- package/src/shadcn/ui/collapsible.tsx +6 -6
- package/src/shadcn/ui/command.tsx +36 -36
- package/src/shadcn/ui/context-menu.tsx +40 -40
- package/src/shadcn/ui/dialog.tsx +28 -28
- package/src/shadcn/ui/drawer.tsx +30 -30
- package/src/shadcn/ui/dropdown-menu.tsx +41 -41
- package/src/shadcn/ui/form.tsx +48 -47
- package/src/shadcn/ui/hover-card.tsx +11 -11
- package/src/shadcn/ui/input-otp.tsx +23 -23
- package/src/shadcn/ui/input.tsx +9 -9
- package/src/shadcn/ui/label.tsx +8 -8
- package/src/shadcn/ui/menubar.tsx +47 -47
- package/src/shadcn/ui/navigation-menu.tsx +33 -33
- package/src/shadcn/ui/pagination.tsx +28 -28
- package/src/shadcn/ui/popover.tsx +12 -12
- package/src/shadcn/ui/progress.tsx +8 -8
- package/src/shadcn/ui/radio-group.tsx +11 -11
- package/src/shadcn/ui/resizable.tsx +14 -14
- package/src/shadcn/ui/scroll-area.tsx +15 -15
- package/src/shadcn/ui/select.tsx +34 -34
- package/src/shadcn/ui/separator.tsx +9 -9
- package/src/shadcn/ui/sheet.tsx +36 -36
- package/src/shadcn/ui/sidebar.tsx +227 -227
- package/src/shadcn/ui/skeleton.tsx +5 -5
- package/src/shadcn/ui/slider.tsx +12 -12
- package/src/shadcn/ui/sonner.tsx +11 -11
- package/src/shadcn/ui/switch.tsx +9 -9
- package/src/shadcn/ui/table.tsx +32 -32
- package/src/shadcn/ui/tabs.tsx +14 -14
- package/src/shadcn/ui/textarea.tsx +7 -7
- package/src/shadcn/ui/toggle-group.tsx +17 -17
- package/src/shadcn/ui/toggle.tsx +16 -16
- package/src/shadcn/ui/tooltip.tsx +11 -11
- package/src/stories/FileUploader.stories.tsx +23 -4
- package/src/stories/kit/builder/DataTable.Basic.stories.tsx +14 -4
- package/src/stories/kit/builder/DataTable.Filters.stories.tsx +36 -14
- package/src/stories/kit/builder/DataTable.Pagination.stories.tsx +3 -2
- package/src/stories/kit/builder/DataTable.SelectionAndActions.stories.tsx +18 -4
- package/src/stories/kit/builder/DataTable.Sorting.stories.tsx +18 -7
- package/src/stories/kit/builder/Dialog.stories.tsx +19 -13
- package/src/stories/kit/builder/Form.ArrayLayouts.stories.tsx +40 -16
- package/src/stories/kit/builder/Form.Autocomplete.stories.tsx +34 -22
- package/src/stories/kit/builder/Form.Basic.stories.tsx +38 -6
- package/src/stories/kit/builder/Form.Complex.stories.tsx +356 -111
- package/src/stories/kit/builder/Form.DateTime.stories.tsx +12 -8
- package/src/stories/kit/builder/Form.Dynamic.stories.tsx +695 -132
- package/src/stories/kit/builder/Form.Files.stories.tsx +37 -26
- package/src/stories/kit/builder/Form.MultipleFormBuilder.stories.tsx +46 -42
- package/src/stories/kit/builder/Form.Pickers.stories.tsx +12 -8
- package/src/stories/kit/builder/Form.Simple.stories.tsx +15 -6
- package/src/stories/kit/builder/Form.Time.stories.tsx +12 -8
- package/src/stories/kit/builder/Page.stories.tsx +32 -6
- package/src/stories/kit/builder/Section.stories.tsx +58 -11
- package/src/stories/kit/components/Autocomplete.stories.tsx +55 -22
- package/src/stories/kit/components/DatePicker.stories.tsx +80 -13
- package/src/stories/kit/components/DateRangePicker.stories.tsx +52 -11
- package/src/stories/kit/components/Login.stories.tsx +8 -2
- package/src/stories/kit/components/MonthPicker.stories.tsx +26 -6
- package/src/stories/kit/components/MonthRangePicker.stories.tsx +24 -5
- package/src/stories/kit/components/TimePicker.stories.tsx +18 -16
- package/src/stories/kit/components/TimeRangePicker.stories.tsx +18 -12
- package/src/stories/kit/layouts/admin/AdminLayout.Basic.stories.tsx +29 -6
- package/src/stories/kit/layouts/admin/AdminLayout.Collapsible.stories.tsx +26 -5
- package/src/stories/kit/layouts/admin/AdminLayout.Complex.stories.tsx +101 -18
- package/src/stories/kit/layouts/admin/AdminLayout.CustomSidebarHeaderComponent.stories.tsx +18 -4
- package/src/stories/kit/layouts/admin/AdminLayout.CustomSidebarTitleAndIcon.stories.tsx +17 -4
- package/src/stories/kit/layouts/admin/AdminLayout.HeaderSlots.stories.tsx +28 -6
- package/src/stories/shadcn/ui/Accordion.stories.tsx +33 -10
- package/src/stories/shadcn/ui/AlertDialog.stories.tsx +3 -1
- package/src/stories/shadcn/ui/Button.stories.tsx +3 -1
- package/src/stories/shadcn/ui/Calendar.stories.tsx +6 -1
- package/src/stories/shadcn/ui/Card.stories.tsx +11 -2
- package/src/stories/shadcn/ui/Checkbox.stories.tsx +11 -3
- package/src/stories/shadcn/ui/Collapsible.stories.tsx +12 -5
- package/src/stories/shadcn/ui/ContextMenu.stories.tsx +12 -4
- package/src/stories/shadcn/ui/Dialog.stories.tsx +15 -3
- package/src/stories/shadcn/ui/Drawer.stories.tsx +5 -2
- package/src/stories/shadcn/ui/DropdownMenu.stories.tsx +15 -5
- package/src/stories/shadcn/ui/Form.stories.tsx +5 -2
- package/src/stories/shadcn/ui/HoverCard.stories.tsx +8 -2
- package/src/stories/shadcn/ui/Input.stories.tsx +3 -1
- package/src/stories/shadcn/ui/InputOtp.stories.tsx +9 -2
- package/src/stories/shadcn/ui/Menubar.stories.tsx +21 -7
- package/src/stories/shadcn/ui/NavigationMenu.stories.tsx +30 -5
- package/src/stories/shadcn/ui/Popover.stories.tsx +8 -2
- package/src/stories/shadcn/ui/Resizable.stories.tsx +17 -5
- package/src/stories/shadcn/ui/ScrollArea.stories.tsx +54 -2
- package/src/stories/shadcn/ui/Select.stories.tsx +7 -1
- package/src/stories/shadcn/ui/Sheet.stories.tsx +2 -1
- package/src/stories/shadcn/ui/Sidebar.stories.tsx +13 -2
- package/src/stories/shadcn/ui/Sonner.stories.tsx +12 -2
- package/src/stories/shadcn/ui/Table.stories.tsx +86 -27
- package/src/stories/shadcn/ui/Tabs.stories.tsx +9 -2
- package/src/stories/shadcn/ui/Textarea.stories.tsx +3 -1
- package/src/stories/shadcn/ui/Toggle.stories.tsx +10 -2
- package/src/stories/shadcn/ui/Tooltip.stories.tsx +6 -1
- package/tsconfig.json +1 -5
- package/tsconfig.tsbuildinfo +1 -0
- package/eslint.config.mjs +0 -19
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AuthAdapterConfig,
|
|
3
|
+
AuthSession,
|
|
4
|
+
GraphQLAuthClient,
|
|
5
|
+
RESTAuthClient,
|
|
6
|
+
} from './types';
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// GraphQL Client Adapter
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export type GraphQLClientAdapterOptions<
|
|
13
|
+
TUser = unknown,
|
|
14
|
+
TRole extends string = string,
|
|
15
|
+
TPermission extends string = string,
|
|
16
|
+
TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<
|
|
17
|
+
TUser,
|
|
18
|
+
TRole,
|
|
19
|
+
TPermission
|
|
20
|
+
>,
|
|
21
|
+
TCredentials = unknown,
|
|
22
|
+
> = {
|
|
23
|
+
client: GraphQLAuthClient<TSession, TCredentials>;
|
|
24
|
+
resolveUser?: (session: TSession | null) => TUser | null;
|
|
25
|
+
resolveRoles?: (session: TSession | null) => TRole[];
|
|
26
|
+
resolvePermissions?: (session: TSession | null) => TPermission[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an auth adapter config for GraphQL clients
|
|
31
|
+
* Works with Apollo Client, urql, graphql-request, etc.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { ApolloClient } from '@apollo/client';
|
|
36
|
+
* import { createGraphQLAuthAdapter } from '@k3mart/react-kit/auth2';
|
|
37
|
+
*
|
|
38
|
+
* const apolloClient = new ApolloClient({ ... });
|
|
39
|
+
*
|
|
40
|
+
* const authConfig = createGraphQLAuthAdapter({
|
|
41
|
+
* client: {
|
|
42
|
+
* login: async (credentials) => {
|
|
43
|
+
* const result = await apolloClient.mutate({
|
|
44
|
+
* mutation: LOGIN_MUTATION,
|
|
45
|
+
* variables: credentials,
|
|
46
|
+
* });
|
|
47
|
+
* return result.data.login;
|
|
48
|
+
* },
|
|
49
|
+
* logout: async () => {
|
|
50
|
+
* await apolloClient.mutate({ mutation: LOGOUT_MUTATION });
|
|
51
|
+
* },
|
|
52
|
+
* refresh: async (refreshToken) => {
|
|
53
|
+
* const result = await apolloClient.mutate({
|
|
54
|
+
* mutation: REFRESH_MUTATION,
|
|
55
|
+
* variables: { refreshToken },
|
|
56
|
+
* });
|
|
57
|
+
* return result.data.refresh;
|
|
58
|
+
* },
|
|
59
|
+
* getCurrentUser: async () => {
|
|
60
|
+
* const result = await apolloClient.query({
|
|
61
|
+
* query: GET_CURRENT_USER_QUERY,
|
|
62
|
+
* });
|
|
63
|
+
* return result.data.currentUser;
|
|
64
|
+
* },
|
|
65
|
+
* },
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function createGraphQLAuthAdapter<
|
|
70
|
+
TUser = unknown,
|
|
71
|
+
TRole extends string = string,
|
|
72
|
+
TPermission extends string = string,
|
|
73
|
+
TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<
|
|
74
|
+
TUser,
|
|
75
|
+
TRole,
|
|
76
|
+
TPermission
|
|
77
|
+
>,
|
|
78
|
+
TCredentials = unknown,
|
|
79
|
+
>(
|
|
80
|
+
options: GraphQLClientAdapterOptions<
|
|
81
|
+
TUser,
|
|
82
|
+
TRole,
|
|
83
|
+
TPermission,
|
|
84
|
+
TSession,
|
|
85
|
+
TCredentials
|
|
86
|
+
>,
|
|
87
|
+
): Partial<
|
|
88
|
+
AuthAdapterConfig<TUser, TRole, TPermission, TSession, TCredentials>
|
|
89
|
+
> {
|
|
90
|
+
return {
|
|
91
|
+
login: options.client.login,
|
|
92
|
+
logout: options.client.logout,
|
|
93
|
+
refresh: options.client.refresh
|
|
94
|
+
? async (session: TSession) => {
|
|
95
|
+
if (!session.refreshToken) {
|
|
96
|
+
throw new Error('No refresh token available');
|
|
97
|
+
}
|
|
98
|
+
if (!options.client.refresh) {
|
|
99
|
+
throw new Error('Refresh function not provided');
|
|
100
|
+
}
|
|
101
|
+
return await options.client.refresh(session.refreshToken);
|
|
102
|
+
}
|
|
103
|
+
: undefined,
|
|
104
|
+
loadSession: options.client.getCurrentUser,
|
|
105
|
+
resolveUser: options.resolveUser,
|
|
106
|
+
resolveRoles: options.resolveRoles,
|
|
107
|
+
resolvePermissions: options.resolvePermissions,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ============================================================================
|
|
112
|
+
// REST Client Adapter
|
|
113
|
+
// ============================================================================
|
|
114
|
+
|
|
115
|
+
export type RESTClientAdapterOptions<
|
|
116
|
+
TUser = unknown,
|
|
117
|
+
TRole extends string = string,
|
|
118
|
+
TPermission extends string = string,
|
|
119
|
+
TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<
|
|
120
|
+
TUser,
|
|
121
|
+
TRole,
|
|
122
|
+
TPermission
|
|
123
|
+
>,
|
|
124
|
+
TCredentials = unknown,
|
|
125
|
+
> = {
|
|
126
|
+
client: RESTAuthClient<TSession, TCredentials>;
|
|
127
|
+
resolveUser?: (session: TSession | null) => TUser | null;
|
|
128
|
+
resolveRoles?: (session: TSession | null) => TRole[];
|
|
129
|
+
resolvePermissions?: (session: TSession | null) => TPermission[];
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates an auth adapter config for REST API clients
|
|
134
|
+
* Works with fetch, axios, ky, etc.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```tsx
|
|
138
|
+
* import axios from 'axios';
|
|
139
|
+
* import { createRESTAuthAdapter } from '@k3mart/react-kit/auth2';
|
|
140
|
+
*
|
|
141
|
+
* const api = axios.create({ baseURL: 'https://api.example.com' });
|
|
142
|
+
*
|
|
143
|
+
* const authConfig = createRESTAuthAdapter({
|
|
144
|
+
* client: {
|
|
145
|
+
* login: async (credentials) => {
|
|
146
|
+
* const response = await api.post('/auth/login', credentials);
|
|
147
|
+
* return response.data;
|
|
148
|
+
* },
|
|
149
|
+
* logout: async () => {
|
|
150
|
+
* await api.post('/auth/logout');
|
|
151
|
+
* },
|
|
152
|
+
* refresh: async (refreshToken) => {
|
|
153
|
+
* const response = await api.post('/auth/refresh', { refreshToken });
|
|
154
|
+
* return response.data;
|
|
155
|
+
* },
|
|
156
|
+
* getCurrentUser: async () => {
|
|
157
|
+
* const response = await api.get('/auth/me');
|
|
158
|
+
* return response.data;
|
|
159
|
+
* },
|
|
160
|
+
* },
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export function createRESTAuthAdapter<
|
|
165
|
+
TUser = unknown,
|
|
166
|
+
TRole extends string = string,
|
|
167
|
+
TPermission extends string = string,
|
|
168
|
+
TSession extends AuthSession<TUser, TRole, TPermission> = AuthSession<
|
|
169
|
+
TUser,
|
|
170
|
+
TRole,
|
|
171
|
+
TPermission
|
|
172
|
+
>,
|
|
173
|
+
TCredentials = unknown,
|
|
174
|
+
>(
|
|
175
|
+
options: RESTClientAdapterOptions<
|
|
176
|
+
TUser,
|
|
177
|
+
TRole,
|
|
178
|
+
TPermission,
|
|
179
|
+
TSession,
|
|
180
|
+
TCredentials
|
|
181
|
+
>,
|
|
182
|
+
): Partial<
|
|
183
|
+
AuthAdapterConfig<TUser, TRole, TPermission, TSession, TCredentials>
|
|
184
|
+
> {
|
|
185
|
+
return {
|
|
186
|
+
login: options.client.login,
|
|
187
|
+
logout: options.client.logout,
|
|
188
|
+
refresh: options.client.refresh
|
|
189
|
+
? async (session: TSession) => {
|
|
190
|
+
if (!session.refreshToken) {
|
|
191
|
+
throw new Error('No refresh token available');
|
|
192
|
+
}
|
|
193
|
+
if (!options.client.refresh) {
|
|
194
|
+
throw new Error('Refresh function not provided');
|
|
195
|
+
}
|
|
196
|
+
return await options.client.refresh(session.refreshToken);
|
|
197
|
+
}
|
|
198
|
+
: undefined,
|
|
199
|
+
loadSession: options.client.getCurrentUser,
|
|
200
|
+
resolveUser: options.resolveUser,
|
|
201
|
+
resolveRoles: options.resolveRoles,
|
|
202
|
+
resolvePermissions: options.resolvePermissions,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ============================================================================
|
|
207
|
+
// HTTP Interceptor Utilities
|
|
208
|
+
// ============================================================================
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Helper to create an axios interceptor that automatically adds auth token
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```tsx
|
|
215
|
+
* import axios from 'axios';
|
|
216
|
+
* import { createAxiosAuthInterceptor } from '@k3mart/react-kit/auth2';
|
|
217
|
+
*
|
|
218
|
+
* const api = axios.create({ baseURL: 'https://api.example.com' });
|
|
219
|
+
*
|
|
220
|
+
* createAxiosAuthInterceptor(api, authAdapter);
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
export function createAxiosAuthInterceptor(
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
+
axiosInstance: any,
|
|
226
|
+
getToken: () => string | null,
|
|
227
|
+
options?: {
|
|
228
|
+
tokenType?: string;
|
|
229
|
+
onTokenExpired?: () => void;
|
|
230
|
+
refreshToken?: () => Promise<void>;
|
|
231
|
+
},
|
|
232
|
+
) {
|
|
233
|
+
const tokenType = options?.tokenType ?? 'Bearer';
|
|
234
|
+
|
|
235
|
+
// Request interceptor
|
|
236
|
+
axiosInstance.interceptors.request.use(
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
238
|
+
async (config: any) => {
|
|
239
|
+
const token = getToken();
|
|
240
|
+
if (token) {
|
|
241
|
+
config.headers.Authorization = `${tokenType} ${token}`;
|
|
242
|
+
}
|
|
243
|
+
return config;
|
|
244
|
+
},
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
246
|
+
(error: any) => Promise.reject(error),
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
// Response interceptor for token refresh
|
|
250
|
+
if (options?.refreshToken) {
|
|
251
|
+
axiosInstance.interceptors.response.use(
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
253
|
+
(response: any) => response,
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
255
|
+
async (error: any) => {
|
|
256
|
+
const originalRequest = error.config;
|
|
257
|
+
|
|
258
|
+
// If token expired and we haven't retried yet
|
|
259
|
+
if (
|
|
260
|
+
error.response?.status === 401 &&
|
|
261
|
+
!originalRequest._retry &&
|
|
262
|
+
options.refreshToken
|
|
263
|
+
) {
|
|
264
|
+
originalRequest._retry = true;
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
await options.refreshToken();
|
|
268
|
+
const token = getToken();
|
|
269
|
+
if (token) {
|
|
270
|
+
originalRequest.headers.Authorization = `${tokenType} ${token}`;
|
|
271
|
+
}
|
|
272
|
+
return axiosInstance(originalRequest);
|
|
273
|
+
} catch (refreshError) {
|
|
274
|
+
options.onTokenExpired?.();
|
|
275
|
+
return Promise.reject(refreshError);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return Promise.reject(error);
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Helper to create a fetch wrapper with auth token injection
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```tsx
|
|
290
|
+
* import { createAuthFetch } from '@k3mart/react-kit/auth2';
|
|
291
|
+
*
|
|
292
|
+
* const authenticatedFetch = createAuthFetch(
|
|
293
|
+
* () => authAdapter.getToken(),
|
|
294
|
+
* {
|
|
295
|
+
* onTokenExpired: () => authAdapter.logout(),
|
|
296
|
+
* refreshToken: () => authAdapter.refresh(),
|
|
297
|
+
* }
|
|
298
|
+
* );
|
|
299
|
+
*
|
|
300
|
+
* // Use it like regular fetch
|
|
301
|
+
* const response = await authenticatedFetch('/api/users');
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
export function createAuthFetch(
|
|
305
|
+
getToken: () => string | null,
|
|
306
|
+
options?: {
|
|
307
|
+
tokenType?: string;
|
|
308
|
+
onTokenExpired?: () => void;
|
|
309
|
+
refreshToken?: () => Promise<void>;
|
|
310
|
+
},
|
|
311
|
+
): typeof fetch {
|
|
312
|
+
const tokenType = options?.tokenType ?? 'Bearer';
|
|
313
|
+
|
|
314
|
+
return async (
|
|
315
|
+
input: RequestInfo | URL,
|
|
316
|
+
init?: RequestInit,
|
|
317
|
+
): Promise<Response> => {
|
|
318
|
+
const token = getToken();
|
|
319
|
+
const headers = new Headers(init?.headers);
|
|
320
|
+
|
|
321
|
+
if (token) {
|
|
322
|
+
headers.set('Authorization', `${tokenType} ${token}`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const response = await fetch(input, {
|
|
326
|
+
...init,
|
|
327
|
+
headers,
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// Handle token expiration
|
|
331
|
+
if (response.status === 401 && options?.refreshToken) {
|
|
332
|
+
try {
|
|
333
|
+
await options.refreshToken();
|
|
334
|
+
const newToken = getToken();
|
|
335
|
+
|
|
336
|
+
if (newToken) {
|
|
337
|
+
headers.set('Authorization', `${tokenType} ${newToken}`);
|
|
338
|
+
return await fetch(input, {
|
|
339
|
+
...init,
|
|
340
|
+
headers,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
} catch (error) {
|
|
344
|
+
options.onTokenExpired?.();
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return response;
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Helper to create Apollo Link with auth token injection
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```tsx
|
|
358
|
+
* import { ApolloClient, InMemoryCache, from } from '@apollo/client';
|
|
359
|
+
* import { createApolloAuthLink } from '@k3mart/react-kit/auth2';
|
|
360
|
+
*
|
|
361
|
+
* const authLink = createApolloAuthLink(() => authAdapter.getToken());
|
|
362
|
+
*
|
|
363
|
+
* const client = new ApolloClient({
|
|
364
|
+
* link: from([authLink, httpLink]),
|
|
365
|
+
* cache: new InMemoryCache(),
|
|
366
|
+
* });
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
export function createApolloAuthLink(
|
|
370
|
+
getToken: () => string | null,
|
|
371
|
+
options?: {
|
|
372
|
+
tokenType?: string;
|
|
373
|
+
},
|
|
374
|
+
) {
|
|
375
|
+
const tokenType = options?.tokenType ?? 'Bearer';
|
|
376
|
+
|
|
377
|
+
// This requires @apollo/client to be installed
|
|
378
|
+
// We'll return a function that creates the link to avoid direct dependency
|
|
379
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
380
|
+
return (ApolloLink: any) => {
|
|
381
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
382
|
+
return new ApolloLink((operation: any, forward: any) => {
|
|
383
|
+
const token = getToken();
|
|
384
|
+
|
|
385
|
+
if (token) {
|
|
386
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
387
|
+
operation.setContext(({ headers = {} }: any) => ({
|
|
388
|
+
headers: {
|
|
389
|
+
...headers,
|
|
390
|
+
authorization: `${tokenType} ${token}`,
|
|
391
|
+
},
|
|
392
|
+
}));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return forward(operation);
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
CanProps,
|
|
4
|
+
RequireAuthProps,
|
|
5
|
+
WithPermissionOptions,
|
|
6
|
+
} from './types';
|
|
7
|
+
import { useAuthContext } from './AuthProvider';
|
|
8
|
+
import { useCan } from './hooks';
|
|
9
|
+
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// RequireAuth Component
|
|
12
|
+
// ============================================================================
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Component that requires authentication
|
|
16
|
+
* Optionally checks for specific roles and permissions
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* // Basic authentication check
|
|
21
|
+
* <RequireAuth fallback={<Login />}>
|
|
22
|
+
* <Dashboard />
|
|
23
|
+
* </RequireAuth>
|
|
24
|
+
*
|
|
25
|
+
* // With role check
|
|
26
|
+
* <RequireAuth
|
|
27
|
+
* roles="admin"
|
|
28
|
+
* fallback={<Forbidden />}
|
|
29
|
+
* loadingFallback={<Spinner />}
|
|
30
|
+
* >
|
|
31
|
+
* <AdminPanel />
|
|
32
|
+
* </RequireAuth>
|
|
33
|
+
*
|
|
34
|
+
* // With permission check
|
|
35
|
+
* <RequireAuth
|
|
36
|
+
* permissions={['post:edit', 'post:delete']}
|
|
37
|
+
* fallback={<Forbidden />}
|
|
38
|
+
* >
|
|
39
|
+
* <PostEditor />
|
|
40
|
+
* </RequireAuth>
|
|
41
|
+
*
|
|
42
|
+
* // Complex rule
|
|
43
|
+
* <RequireAuth
|
|
44
|
+
* roles={['admin', 'moderator']}
|
|
45
|
+
* permissions={{
|
|
46
|
+
* operator: 'OR',
|
|
47
|
+
* permissions: ['post:edit', 'post:delete']
|
|
48
|
+
* }}
|
|
49
|
+
* requireAll={false}
|
|
50
|
+
* fallback={<Forbidden />}
|
|
51
|
+
* >
|
|
52
|
+
* <ContentManager />
|
|
53
|
+
* </RequireAuth>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function RequireAuth<
|
|
57
|
+
TRole extends string = string,
|
|
58
|
+
TPermission extends string = string,
|
|
59
|
+
>({
|
|
60
|
+
children,
|
|
61
|
+
fallback = null,
|
|
62
|
+
loadingFallback = null,
|
|
63
|
+
roles,
|
|
64
|
+
permissions,
|
|
65
|
+
requireAll = true,
|
|
66
|
+
}: RequireAuthProps<TRole, TPermission>) {
|
|
67
|
+
const { status, can } = useAuthContext();
|
|
68
|
+
|
|
69
|
+
if (status === 'loading' || status === 'idle') {
|
|
70
|
+
return loadingFallback;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (status !== 'authenticated') {
|
|
74
|
+
return fallback;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If no specific roles/permissions required, just check authentication
|
|
78
|
+
if (!roles && !permissions) {
|
|
79
|
+
return children;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Check role/permission rules
|
|
83
|
+
const allowed = can({ roles, permissions, requireAll });
|
|
84
|
+
|
|
85
|
+
if (!allowed) {
|
|
86
|
+
return fallback;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return children;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// Can Component
|
|
94
|
+
// ============================================================================
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Component for conditional rendering based on permissions
|
|
98
|
+
* More flexible than RequireAuth - doesn't check authentication status
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* // Show button only if user can edit
|
|
103
|
+
* <Can permissions="post:edit" fallback={<ReadOnlyView />}>
|
|
104
|
+
* <EditButton />
|
|
105
|
+
* </Can>
|
|
106
|
+
*
|
|
107
|
+
* // Show admin panel if user is admin
|
|
108
|
+
* <Can roles="admin">
|
|
109
|
+
* <AdminPanel />
|
|
110
|
+
* </Can>
|
|
111
|
+
*
|
|
112
|
+
* // Complex permission check
|
|
113
|
+
* <Can
|
|
114
|
+
* roles={['admin', 'moderator']}
|
|
115
|
+
* permissions={{
|
|
116
|
+
* operator: 'OR',
|
|
117
|
+
* permissions: ['post:edit', 'post:delete']
|
|
118
|
+
* }}
|
|
119
|
+
* requireAll={false}
|
|
120
|
+
* >
|
|
121
|
+
* <ManageButton />
|
|
122
|
+
* </Can>
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function Can<
|
|
126
|
+
TRole extends string = string,
|
|
127
|
+
TPermission extends string = string,
|
|
128
|
+
>({
|
|
129
|
+
children,
|
|
130
|
+
fallback = null,
|
|
131
|
+
roles,
|
|
132
|
+
permissions,
|
|
133
|
+
requireAll = true,
|
|
134
|
+
}: CanProps<TRole, TPermission>) {
|
|
135
|
+
const allowed = useCan({ roles, permissions, requireAll });
|
|
136
|
+
if (!allowed) return fallback;
|
|
137
|
+
return children;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Higher-Order Component
|
|
142
|
+
// ============================================================================
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Higher-order component that wraps a component with permission checks
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* const AdminButton = withPermission(Button, {
|
|
150
|
+
* roles: 'admin'
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* const EditButton = withPermission(Button, {
|
|
154
|
+
* permissions: 'post:edit'
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* // Use like regular component
|
|
158
|
+
* <AdminButton onClick={handleAdmin}>Admin Action</AdminButton>
|
|
159
|
+
* <EditButton onClick={handleEdit}>Edit Post</EditButton>
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export function withPermission<
|
|
163
|
+
TRole extends string = string,
|
|
164
|
+
TPermission extends string = string,
|
|
165
|
+
TProps extends Record<string, unknown> = Record<string, unknown>,
|
|
166
|
+
>(
|
|
167
|
+
Component: ComponentType<TProps>,
|
|
168
|
+
options: WithPermissionOptions<TRole, TPermission>,
|
|
169
|
+
): ComponentType<TProps> {
|
|
170
|
+
const WithPermissionWrapper = (props: TProps) => {
|
|
171
|
+
const allowed = useCan(options);
|
|
172
|
+
if (!allowed) return null;
|
|
173
|
+
return <Component {...props} />;
|
|
174
|
+
};
|
|
175
|
+
WithPermissionWrapper.displayName = `WithPermission(${Component.displayName ?? Component.name ?? 'Component'})`;
|
|
176
|
+
return WithPermissionWrapper as ComponentType<TProps>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ============================================================================
|
|
180
|
+
// Show/Hide Components
|
|
181
|
+
// ============================================================================
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Component that shows children only when authenticated
|
|
185
|
+
*/
|
|
186
|
+
export function ShowWhenAuthenticated({
|
|
187
|
+
children,
|
|
188
|
+
}: {
|
|
189
|
+
children: React.ReactNode;
|
|
190
|
+
}) {
|
|
191
|
+
const { status } = useAuthContext();
|
|
192
|
+
return status === 'authenticated' ? children : null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Component that shows children only when NOT authenticated
|
|
197
|
+
*/
|
|
198
|
+
export function ShowWhenUnauthenticated({
|
|
199
|
+
children,
|
|
200
|
+
}: {
|
|
201
|
+
children: React.ReactNode;
|
|
202
|
+
}) {
|
|
203
|
+
const { status } = useAuthContext();
|
|
204
|
+
return status === 'unauthenticated' ? children : null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Component that shows children only while loading
|
|
209
|
+
*/
|
|
210
|
+
export function ShowWhenLoading({ children }: { children: React.ReactNode }) {
|
|
211
|
+
const { status } = useAuthContext();
|
|
212
|
+
return status === 'loading' ? children : null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Component that shows children only when there's an error
|
|
217
|
+
*/
|
|
218
|
+
export function ShowWhenError({ children }: { children: React.ReactNode }) {
|
|
219
|
+
const { status } = useAuthContext();
|
|
220
|
+
return status === 'error' ? children : null;
|
|
221
|
+
}
|