@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,237 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AuthSession,
|
|
3
|
+
PermissionPolicy,
|
|
4
|
+
PermissionRule,
|
|
5
|
+
WithPermissionOptions,
|
|
6
|
+
} from './types';
|
|
7
|
+
import { useAuthContext } from './AuthProvider';
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Core Hooks
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Hook to access the entire auth context
|
|
15
|
+
*/
|
|
16
|
+
export function useAuth() {
|
|
17
|
+
return useAuthContext();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hook to get the current auth status
|
|
22
|
+
*/
|
|
23
|
+
export function useAuthStatus() {
|
|
24
|
+
const { status } = useAuthContext();
|
|
25
|
+
return status;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Hook to check if user is authenticated
|
|
30
|
+
*/
|
|
31
|
+
export function useIsAuthenticated() {
|
|
32
|
+
const { status } = useAuthContext();
|
|
33
|
+
return status === 'authenticated';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Hook to get the current session
|
|
38
|
+
*/
|
|
39
|
+
export function useAuthSession<TSession extends AuthSession>() {
|
|
40
|
+
const { session } = useAuthContext();
|
|
41
|
+
return session as TSession | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Hook to get the current user
|
|
46
|
+
*/
|
|
47
|
+
export function useAuthUser<TUser>() {
|
|
48
|
+
const { user } = useAuthContext();
|
|
49
|
+
return user as TUser | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Hook to get user roles
|
|
54
|
+
*/
|
|
55
|
+
export function useAuthRoles<TRole extends string = string>() {
|
|
56
|
+
const { roles } = useAuthContext();
|
|
57
|
+
return roles as TRole[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Hook to get user permissions
|
|
62
|
+
*/
|
|
63
|
+
export function useAuthPermissions<TPermission extends string = string>() {
|
|
64
|
+
const { permissions } = useAuthContext();
|
|
65
|
+
return permissions as TPermission[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Hook to get authentication error
|
|
70
|
+
*/
|
|
71
|
+
export function useAuthError() {
|
|
72
|
+
const { error } = useAuthContext();
|
|
73
|
+
return error;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ============================================================================
|
|
77
|
+
// Permission Hooks
|
|
78
|
+
// ============================================================================
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Hook to check if user has specific permission(s)
|
|
82
|
+
* Supports permission policies with AND/OR operators
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* // Check single permission
|
|
87
|
+
* const canEdit = usePermission('post:edit');
|
|
88
|
+
*
|
|
89
|
+
* // Check multiple permissions (all required by default)
|
|
90
|
+
* const canManage = usePermission(['post:edit', 'post:delete']);
|
|
91
|
+
*
|
|
92
|
+
* // Check multiple permissions (any one required)
|
|
93
|
+
* const canModify = usePermission(['post:edit', 'post:delete'], { requireAll: false });
|
|
94
|
+
*
|
|
95
|
+
* // Check with policy
|
|
96
|
+
* const canAccess = usePermission({
|
|
97
|
+
* operator: 'OR',
|
|
98
|
+
* permissions: ['admin:access', 'moderator:access']
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function usePermission<TPermission extends string = string>(
|
|
103
|
+
permission: TPermission | TPermission[] | PermissionPolicy<TPermission>,
|
|
104
|
+
options?: { requireAll?: boolean },
|
|
105
|
+
) {
|
|
106
|
+
const { hasPermission } = useAuthContext();
|
|
107
|
+
return hasPermission(permission, options);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Hook to check if user has specific role(s)
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* // Check single role
|
|
116
|
+
* const isAdmin = useRole('admin');
|
|
117
|
+
*
|
|
118
|
+
* // Check multiple roles (all required by default)
|
|
119
|
+
* const isSuperAdmin = useRole(['admin', 'super']);
|
|
120
|
+
*
|
|
121
|
+
* // Check multiple roles (any one required)
|
|
122
|
+
* const isStaff = useRole(['admin', 'moderator'], { requireAll: false });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function useRole<TRole extends string = string>(
|
|
126
|
+
roles: TRole | TRole[],
|
|
127
|
+
options?: { requireAll?: boolean },
|
|
128
|
+
) {
|
|
129
|
+
const { hasRole } = useAuthContext();
|
|
130
|
+
return hasRole(roles, options);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Hook to check complex permission rules
|
|
135
|
+
* Combines role and permission checks with flexible logic
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* // Check if user has admin role AND edit permission
|
|
140
|
+
* const canAdminEdit = useCan({
|
|
141
|
+
* roles: 'admin',
|
|
142
|
+
* permissions: 'post:edit',
|
|
143
|
+
* requireAll: true
|
|
144
|
+
* });
|
|
145
|
+
*
|
|
146
|
+
* // Check if user has admin role OR edit permission
|
|
147
|
+
* const canAccess = useCan({
|
|
148
|
+
* roles: 'admin',
|
|
149
|
+
* permissions: 'post:edit',
|
|
150
|
+
* requireAll: false
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Complex policy
|
|
154
|
+
* const canManage = useCan({
|
|
155
|
+
* roles: ['admin', 'moderator'],
|
|
156
|
+
* permissions: {
|
|
157
|
+
* operator: 'OR',
|
|
158
|
+
* permissions: ['post:edit', 'post:delete']
|
|
159
|
+
* }
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export function useCan<
|
|
164
|
+
TRole extends string = string,
|
|
165
|
+
TPermission extends string = string,
|
|
166
|
+
>(
|
|
167
|
+
rule:
|
|
168
|
+
| WithPermissionOptions<TRole, TPermission>
|
|
169
|
+
| PermissionRule<TRole, TPermission>,
|
|
170
|
+
) {
|
|
171
|
+
const { can } = useAuthContext();
|
|
172
|
+
return can(rule as PermissionRule<TRole, TPermission>);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ============================================================================
|
|
176
|
+
// Token Hooks
|
|
177
|
+
// ============================================================================
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Hook to get the current auth token
|
|
181
|
+
*/
|
|
182
|
+
export function useAuthToken() {
|
|
183
|
+
const { getToken } = useAuthContext();
|
|
184
|
+
return getToken();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Hook to check if token is expired
|
|
189
|
+
*/
|
|
190
|
+
export function useIsTokenExpired() {
|
|
191
|
+
const { isTokenExpired } = useAuthContext();
|
|
192
|
+
return isTokenExpired();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Hook to get time until token expiry in milliseconds
|
|
197
|
+
*/
|
|
198
|
+
export function useTimeUntilExpiry() {
|
|
199
|
+
const { getTimeUntilExpiry } = useAuthContext();
|
|
200
|
+
return getTimeUntilExpiry();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ============================================================================
|
|
204
|
+
// Action Hooks
|
|
205
|
+
// ============================================================================
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Hook to get the login function
|
|
209
|
+
*/
|
|
210
|
+
export function useLogin<TCredentials = unknown>() {
|
|
211
|
+
const { login } = useAuthContext();
|
|
212
|
+
return login as ((credentials: TCredentials) => Promise<unknown>) | undefined;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Hook to get the logout function
|
|
217
|
+
*/
|
|
218
|
+
export function useLogout() {
|
|
219
|
+
const { logout } = useAuthContext();
|
|
220
|
+
return logout;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Hook to get the refresh function
|
|
225
|
+
*/
|
|
226
|
+
export function useRefresh() {
|
|
227
|
+
const { refresh } = useAuthContext();
|
|
228
|
+
return refresh;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Hook to get the setSession function
|
|
233
|
+
*/
|
|
234
|
+
export function useSetSession<TSession extends AuthSession>() {
|
|
235
|
+
const { setSession } = useAuthContext();
|
|
236
|
+
return setSession as (session: TSession | null) => Promise<unknown>;
|
|
237
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Core
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
export { createAuthAdapter } from './adapter';
|
|
6
|
+
export { AuthProvider, useAuthContext } from './AuthProvider';
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Storage
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
createStorage,
|
|
14
|
+
createMemoryStorage,
|
|
15
|
+
createBrowserStorage,
|
|
16
|
+
createCookieStorage,
|
|
17
|
+
} from './storage';
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Utilities
|
|
21
|
+
// ============================================================================
|
|
22
|
+
|
|
23
|
+
export { createTokenManager } from './token-manager';
|
|
24
|
+
export {
|
|
25
|
+
expandPermissions,
|
|
26
|
+
expandRoles,
|
|
27
|
+
checkPermissions,
|
|
28
|
+
checkRoles,
|
|
29
|
+
evaluatePermissionRule,
|
|
30
|
+
} from './permission-checker';
|
|
31
|
+
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Client Adapters
|
|
34
|
+
// ============================================================================
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
createGraphQLAuthAdapter,
|
|
38
|
+
createRESTAuthAdapter,
|
|
39
|
+
createAxiosAuthInterceptor,
|
|
40
|
+
createAuthFetch,
|
|
41
|
+
createApolloAuthLink,
|
|
42
|
+
} from './client-adapters';
|
|
43
|
+
|
|
44
|
+
export type {
|
|
45
|
+
GraphQLClientAdapterOptions,
|
|
46
|
+
RESTClientAdapterOptions,
|
|
47
|
+
} from './client-adapters';
|
|
48
|
+
|
|
49
|
+
// ============================================================================
|
|
50
|
+
// Hooks
|
|
51
|
+
// ============================================================================
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
useAuth,
|
|
55
|
+
useAuthStatus,
|
|
56
|
+
useIsAuthenticated,
|
|
57
|
+
useAuthSession,
|
|
58
|
+
useAuthUser,
|
|
59
|
+
useAuthRoles,
|
|
60
|
+
useAuthPermissions,
|
|
61
|
+
useAuthError,
|
|
62
|
+
usePermission,
|
|
63
|
+
useRole,
|
|
64
|
+
useCan,
|
|
65
|
+
useAuthToken,
|
|
66
|
+
useIsTokenExpired,
|
|
67
|
+
useTimeUntilExpiry,
|
|
68
|
+
useLogin,
|
|
69
|
+
useLogout,
|
|
70
|
+
useRefresh,
|
|
71
|
+
useSetSession,
|
|
72
|
+
} from './hooks';
|
|
73
|
+
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Components
|
|
76
|
+
// ============================================================================
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
RequireAuth,
|
|
80
|
+
Can,
|
|
81
|
+
withPermission,
|
|
82
|
+
ShowWhenAuthenticated,
|
|
83
|
+
ShowWhenUnauthenticated,
|
|
84
|
+
ShowWhenLoading,
|
|
85
|
+
ShowWhenError,
|
|
86
|
+
} from './components';
|
|
87
|
+
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// Types
|
|
90
|
+
// ============================================================================
|
|
91
|
+
|
|
92
|
+
export type {
|
|
93
|
+
// Core types
|
|
94
|
+
AuthStatus,
|
|
95
|
+
TokenType,
|
|
96
|
+
RefreshStrategy,
|
|
97
|
+
AuthSession,
|
|
98
|
+
// Permission types
|
|
99
|
+
PermissionOperator,
|
|
100
|
+
PermissionPolicy,
|
|
101
|
+
PermissionRule,
|
|
102
|
+
PermissionHierarchy,
|
|
103
|
+
RoleHierarchy,
|
|
104
|
+
// State types
|
|
105
|
+
AuthAdapterState,
|
|
106
|
+
AuthAdapterSubscriber,
|
|
107
|
+
// Storage types
|
|
108
|
+
AuthStorage,
|
|
109
|
+
StorageType,
|
|
110
|
+
StorageOptions,
|
|
111
|
+
// Middleware types
|
|
112
|
+
AuthMiddleware,
|
|
113
|
+
// Token manager types
|
|
114
|
+
TokenManager,
|
|
115
|
+
// Adapter types
|
|
116
|
+
AuthAdapterConfig,
|
|
117
|
+
AuthAdapter,
|
|
118
|
+
// Context types
|
|
119
|
+
AuthContextValue,
|
|
120
|
+
// Component prop types
|
|
121
|
+
RequireAuthProps,
|
|
122
|
+
CanProps,
|
|
123
|
+
WithPermissionOptions,
|
|
124
|
+
// Client adapter types
|
|
125
|
+
GraphQLAuthClient,
|
|
126
|
+
RESTAuthClient,
|
|
127
|
+
ClientAdapter,
|
|
128
|
+
// Utility types
|
|
129
|
+
InferSession,
|
|
130
|
+
InferUser,
|
|
131
|
+
InferRole,
|
|
132
|
+
InferPermission,
|
|
133
|
+
InferCredentials,
|
|
134
|
+
} from './types';
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PermissionHierarchy,
|
|
3
|
+
PermissionPolicy,
|
|
4
|
+
PermissionRule,
|
|
5
|
+
RoleHierarchy,
|
|
6
|
+
} from './types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Expands permissions based on hierarchy
|
|
10
|
+
* e.g., if user has 'admin' and hierarchy defines admin: ['read', 'write'],
|
|
11
|
+
* user effectively has ['admin', 'read', 'write']
|
|
12
|
+
*/
|
|
13
|
+
export function expandPermissions<T extends string>(
|
|
14
|
+
permissions: T[],
|
|
15
|
+
hierarchy?: PermissionHierarchy<T>,
|
|
16
|
+
): T[] {
|
|
17
|
+
if (!hierarchy) return permissions;
|
|
18
|
+
|
|
19
|
+
const expanded = new Set<T>(permissions);
|
|
20
|
+
const queue = [...permissions];
|
|
21
|
+
|
|
22
|
+
while (queue.length > 0) {
|
|
23
|
+
const current = queue.shift();
|
|
24
|
+
if (!current) continue;
|
|
25
|
+
const children = hierarchy[current];
|
|
26
|
+
|
|
27
|
+
if (children) {
|
|
28
|
+
for (const child of children) {
|
|
29
|
+
if (!expanded.has(child)) {
|
|
30
|
+
expanded.add(child);
|
|
31
|
+
queue.push(child);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return Array.from(expanded);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Expands roles based on hierarchy
|
|
42
|
+
* e.g., if user has 'admin' and hierarchy defines admin: ['moderator', 'user'],
|
|
43
|
+
* user effectively has ['admin', 'moderator', 'user']
|
|
44
|
+
*/
|
|
45
|
+
export function expandRoles<T extends string>(
|
|
46
|
+
roles: T[],
|
|
47
|
+
hierarchy?: RoleHierarchy<T>,
|
|
48
|
+
): T[] {
|
|
49
|
+
if (!hierarchy) return roles;
|
|
50
|
+
|
|
51
|
+
const expanded = new Set<T>(roles);
|
|
52
|
+
const queue = [...roles];
|
|
53
|
+
|
|
54
|
+
while (queue.length > 0) {
|
|
55
|
+
const current = queue.shift();
|
|
56
|
+
if (!current) continue;
|
|
57
|
+
const children = hierarchy[current];
|
|
58
|
+
|
|
59
|
+
if (children) {
|
|
60
|
+
for (const child of children) {
|
|
61
|
+
if (!expanded.has(child)) {
|
|
62
|
+
expanded.add(child);
|
|
63
|
+
queue.push(child);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return Array.from(expanded);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Checks if target permissions match against user permissions
|
|
74
|
+
* Supports both array of permissions and permission policies (AND/OR operations)
|
|
75
|
+
*/
|
|
76
|
+
export function checkPermissions<T extends string>(
|
|
77
|
+
userPermissions: T[],
|
|
78
|
+
target: T | T[] | PermissionPolicy<T>,
|
|
79
|
+
options?: { requireAll?: boolean },
|
|
80
|
+
): boolean {
|
|
81
|
+
// Handle permission policy (with AND/OR operator)
|
|
82
|
+
if (typeof target === 'object' && 'permissions' in target) {
|
|
83
|
+
const policy = target as PermissionPolicy<T>;
|
|
84
|
+
const operator = policy.operator ?? 'AND';
|
|
85
|
+
|
|
86
|
+
if (operator === 'AND') {
|
|
87
|
+
return policy.permissions.every((p) => userPermissions.includes(p));
|
|
88
|
+
} else {
|
|
89
|
+
return policy.permissions.some((p) => userPermissions.includes(p));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Handle simple string or array
|
|
94
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
95
|
+
const requireAll = options?.requireAll ?? true;
|
|
96
|
+
|
|
97
|
+
if (targets.length === 0) return true;
|
|
98
|
+
|
|
99
|
+
return requireAll
|
|
100
|
+
? targets.every((p) => userPermissions.includes(p))
|
|
101
|
+
: targets.some((p) => userPermissions.includes(p));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Checks if target roles match against user roles
|
|
106
|
+
*/
|
|
107
|
+
export function checkRoles<T extends string>(
|
|
108
|
+
userRoles: T[],
|
|
109
|
+
target: T | T[],
|
|
110
|
+
options?: { requireAll?: boolean },
|
|
111
|
+
): boolean {
|
|
112
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
113
|
+
const requireAll = options?.requireAll ?? true;
|
|
114
|
+
|
|
115
|
+
if (targets.length === 0) return true;
|
|
116
|
+
|
|
117
|
+
return requireAll
|
|
118
|
+
? targets.every((r) => userRoles.includes(r))
|
|
119
|
+
: targets.some((r) => userRoles.includes(r));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Evaluates a permission rule (combination of roles and permissions)
|
|
124
|
+
*/
|
|
125
|
+
export function evaluatePermissionRule<
|
|
126
|
+
TRole extends string = string,
|
|
127
|
+
TPermission extends string = string,
|
|
128
|
+
>(
|
|
129
|
+
userRoles: TRole[],
|
|
130
|
+
userPermissions: TPermission[],
|
|
131
|
+
rule: PermissionRule<TRole, TPermission>,
|
|
132
|
+
): boolean {
|
|
133
|
+
if (!rule.roles && !rule.permissions) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const requireAll = rule.requireAll ?? true;
|
|
138
|
+
|
|
139
|
+
const roleAllowed = rule.roles
|
|
140
|
+
? checkRoles(userRoles, rule.roles, { requireAll })
|
|
141
|
+
: true;
|
|
142
|
+
|
|
143
|
+
const permissionAllowed = rule.permissions
|
|
144
|
+
? checkPermissions(userPermissions, rule.permissions, { requireAll })
|
|
145
|
+
: true;
|
|
146
|
+
|
|
147
|
+
return requireAll
|
|
148
|
+
? roleAllowed && permissionAllowed
|
|
149
|
+
: roleAllowed || permissionAllowed;
|
|
150
|
+
}
|