@goplusvn/core 0.1.0 → 0.1.1
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/package.json +2 -1
- package/src/assets/erp_wallpaper.png +0 -0
- package/src/assets/goeat_logo.png +0 -0
- package/src/audit/audit-manager.ts +139 -0
- package/src/audit/index.ts +11 -0
- package/src/audit/memory-audit-logger.ts +86 -0
- package/src/audit/types.ts +50 -0
- package/src/auth/auth-service.ts +97 -0
- package/src/auth/index.ts +266 -0
- package/src/code-generation/index.ts +69 -0
- package/src/configs/auth-routes.ts +17 -0
- package/src/configs/crud.ts +136 -0
- package/src/configs/data/navigations.ts +781 -0
- package/src/configs/data/oauth-links.ts +10 -0
- package/src/configs/entities/material-categories.config.ts +125 -0
- package/src/configs/i18n.ts +12 -0
- package/src/configs/index.ts +26 -0
- package/src/configs/status.ts +25 -0
- package/src/configs/themes.ts +100 -0
- package/src/crud/components/crud-bulk-actions.tsx +91 -0
- package/src/crud/components/crud-card-view.tsx +241 -0
- package/src/crud/components/crud-context.tsx +122 -0
- package/src/crud/components/crud-delete-dialog.tsx +145 -0
- package/src/crud/components/crud-dialog.tsx +406 -0
- package/src/crud/components/crud-empty-state.tsx +104 -0
- package/src/crud/components/crud-export-button.tsx +170 -0
- package/src/crud/components/crud-field-renderer.tsx +653 -0
- package/src/crud/components/crud-filter-chips.tsx +102 -0
- package/src/crud/components/crud-filters/checkbox-filter.tsx +97 -0
- package/src/crud/components/crud-filters/datetime-filter.tsx +83 -0
- package/src/crud/components/crud-filters/filter-builder.tsx +66 -0
- package/src/crud/components/crud-filters/index.tsx +76 -0
- package/src/crud/components/crud-filters/radio-filter.tsx +86 -0
- package/src/crud/components/crud-filters/select-filter.tsx +141 -0
- package/src/crud/components/crud-filters/text-filter.tsx +86 -0
- package/src/crud/components/crud-form.tsx +642 -0
- package/src/crud/components/crud-import-dialog.tsx +440 -0
- package/src/crud/components/crud-infinite-scroll.tsx +116 -0
- package/src/crud/components/crud-page.tsx +1017 -0
- package/src/crud/components/crud-provider.tsx +277 -0
- package/src/crud/components/crud-row-actions.tsx +189 -0
- package/src/crud/components/crud-search.tsx +82 -0
- package/src/crud/components/crud-sheet.tsx +336 -0
- package/src/crud/components/crud-table-skeleton.tsx +26 -0
- package/src/crud/components/crud-table-toolbar.tsx +91 -0
- package/src/crud/components/crud-table.tsx +352 -0
- package/src/crud/components/crud-virtual-table.tsx +55 -0
- package/src/crud/components/index.tsx +20 -0
- package/src/crud/crud-filters/checkbox-filter.tsx +87 -0
- package/src/crud/crud-filters/datetime-filter.tsx +82 -0
- package/src/crud/crud-filters/filter-builder.tsx +64 -0
- package/src/crud/crud-filters/index.tsx +78 -0
- package/src/crud/crud-filters/radio-filter.tsx +79 -0
- package/src/crud/crud-filters/select-filter.tsx +148 -0
- package/src/crud/crud-filters/text-filter.tsx +81 -0
- package/src/crud/index.ts +43 -0
- package/src/crud/lib/crud-service.test.ts +334 -0
- package/src/crud/lib/crud-service.ts +358 -0
- package/src/crud/lib/crud-utils.test.ts +354 -0
- package/src/crud/lib/crud-utils.ts +299 -0
- package/src/crud/lib/crud-validator.ts +247 -0
- package/src/crud/lib/data-loader.ts +234 -0
- package/src/crud/lib/field-calculator.ts +241 -0
- package/src/crud/lib/field-formatter.ts +240 -0
- package/src/crud/lib/import-export-service.test.ts +290 -0
- package/src/crud/lib/import-export-service.ts +352 -0
- package/src/crud/lib/import-server-utils.ts +109 -0
- package/src/crud/lib/lazy-loader.ts +241 -0
- package/src/crud/lib/parse-filters.ts +85 -0
- package/src/crud/lib/permissions.ts +52 -0
- package/src/crud/lib/serialize-config.ts +60 -0
- package/src/crud/lib/stream-loader.ts +145 -0
- package/src/crud/lib/translate-config.ts +335 -0
- package/src/crud/lib/types.ts +11 -0
- package/src/crud/pages/entity-crud-page.tsx +144 -0
- package/src/crud/server.ts +8 -0
- package/src/home/constants.tsx +142 -0
- package/src/home/feature-showcase.tsx +171 -0
- package/src/home/home-page.tsx +191 -0
- package/src/home/hooks/index.ts +1 -0
- package/src/home/hooks/useWidgetPreferences.ts +167 -0
- package/src/home/index.ts +33 -0
- package/src/home/quick-access-dialog.tsx +271 -0
- package/src/home/quick-access-menu.tsx +267 -0
- package/src/home/types.ts +140 -0
- package/src/home/welcome-card.tsx +92 -0
- package/src/home/widget-container.tsx +258 -0
- package/src/home/widgets/base-widget.tsx +200 -0
- package/src/home/widgets/customers-widget.tsx +74 -0
- package/src/home/widgets/index.ts +6 -0
- package/src/home/widgets/orders-widget.tsx +87 -0
- package/src/home/widgets/revenue-widget.tsx +71 -0
- package/src/home/widgets/stock-widget.tsx +109 -0
- package/src/hooks/index.tsx +598 -0
- package/src/hooks/use-tenant.test.tsx +30 -0
- package/src/hooks/use-tenant.ts +5 -0
- package/src/index.ts +17 -0
- package/src/infrastructure/__tests__/architecture-verification.spec.ts +103 -0
- package/src/infrastructure/api-service.ts +317 -0
- package/src/infrastructure/cache/cache-manager.ts +107 -0
- package/src/infrastructure/cache/cache.ts +120 -0
- package/src/infrastructure/cache/index.ts +8 -0
- package/src/infrastructure/cache/types.ts +48 -0
- package/src/infrastructure/cron/cron-manager.ts +239 -0
- package/src/infrastructure/cron/index.ts +6 -0
- package/src/infrastructure/cron/types.ts +41 -0
- package/src/infrastructure/event-bus/event-bus.ts +145 -0
- package/src/infrastructure/event-bus/index.ts +2 -0
- package/src/infrastructure/event-bus/types.ts +22 -0
- package/src/infrastructure/index.ts +32 -0
- package/src/infrastructure/lock/decorators.ts +67 -0
- package/src/infrastructure/lock/index.ts +2 -0
- package/src/infrastructure/lock/lock-manager.ts +33 -0
- package/src/infrastructure/logger/index.ts +2 -0
- package/src/infrastructure/logger/logger.ts +96 -0
- package/src/infrastructure/logger/types.ts +25 -0
- package/src/layout/index.tsx +185 -0
- package/src/navigation/index.ts +91 -0
- package/src/notification/index.ts +14 -0
- package/src/notification/notification-service.ts +120 -0
- package/src/notification/storage/in-memory.ts +56 -0
- package/src/notification/storage/index.ts +1 -0
- package/src/notification/types.ts +51 -0
- package/src/organization/branch-service.ts +299 -0
- package/src/organization/branches.config.ts +154 -0
- package/src/organization/index.ts +5 -0
- package/src/plugin/apps-registry.ts +97 -0
- package/src/plugin/index.ts +5 -0
- package/src/plugin/types.ts +41 -0
- package/src/providers/index.tsx +109 -0
- package/src/providers/tenant-provider.tsx +45 -0
- package/src/rbac/components/roles/role-card.tsx +158 -0
- package/src/rbac/components/roles/role-stats-cards.tsx +29 -0
- package/src/rbac/components/roles/role-toolbar.tsx +123 -0
- package/src/rbac/hooks/use-role-operations.ts +159 -0
- package/src/rbac/hooks/use-roles-data.ts +59 -0
- package/src/rbac/index.ts +297 -0
- package/src/rbac/lib/permission-helpers.ts +63 -0
- package/src/rbac/pages/action-list-page.tsx +25 -0
- package/src/rbac/pages/resource-list-page.tsx +25 -0
- package/src/rbac/pages/role-list-page.tsx +378 -0
- package/src/rbac/permission-service.ts +140 -0
- package/src/rbac/permissions.ts +135 -0
- package/src/rbac/resource-service.ts +115 -0
- package/src/rbac/resource-validator.ts +119 -0
- package/src/rbac/role-service.ts +165 -0
- package/src/rbac/server.ts +16 -0
- package/src/rbac/types.ts +38 -0
- package/src/schemas/action.schema.ts +66 -0
- package/src/schemas/branch.schema.ts +52 -0
- package/src/schemas/coming-soon-schema.ts +9 -0
- package/src/schemas/company.schema.ts +44 -0
- package/src/schemas/forgot-passward-schema.ts +9 -0
- package/src/schemas/index.ts +30 -0
- package/src/schemas/material-category.schema.ts +43 -0
- package/src/schemas/material-pricing.schema.ts +74 -0
- package/src/schemas/material.schema.ts +76 -0
- package/src/schemas/materials.ts +52 -0
- package/src/schemas/new-passward-schema.ts +15 -0
- package/src/schemas/partner-company.schema.ts +149 -0
- package/src/schemas/register-schema.ts +36 -0
- package/src/schemas/resource.schema.ts +133 -0
- package/src/schemas/role.schema.ts +11 -0
- package/src/schemas/sign-in-schema.ts +24 -0
- package/src/schemas/supplier-pricing.schema.ts +15 -0
- package/src/schemas/supplier.schema.ts +120 -0
- package/src/schemas/system-category-group.schema.ts +67 -0
- package/src/schemas/system-category.schema.ts +77 -0
- package/src/schemas/system-config.schema.ts +118 -0
- package/src/schemas/uom.schema.ts +75 -0
- package/src/schemas/user-supplier.schema.ts +179 -0
- package/src/schemas/user.schema.ts +18 -0
- package/src/schemas/verify-email-schema.ts +9 -0
- package/src/schemas/warehouse.schema.ts +49 -0
- package/src/system/components/categories/category-list.tsx +529 -0
- package/src/system/components/categories/category-manager.tsx +89 -0
- package/src/system/components/categories/group-sidebar.tsx +308 -0
- package/src/system/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/components/settings/setting-field.tsx +291 -0
- package/src/system/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/components/settings/settings-groups.ts +80 -0
- package/src/system/components/settings/settings-search.tsx +71 -0
- package/src/system/components/settings/settings-section.tsx +74 -0
- package/src/system/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/constants.ts +3 -0
- package/src/system/index.ts +150 -0
- package/src/system/job-manager.ts +176 -0
- package/src/system/pages/components/categories/category-list.tsx +537 -0
- package/src/system/pages/components/categories/category-manager.tsx +90 -0
- package/src/system/pages/components/categories/group-sidebar.tsx +311 -0
- package/src/system/pages/components/settings/sales-rules-settings.tsx +222 -0
- package/src/system/pages/components/settings/setting-dialogs.tsx +197 -0
- package/src/system/pages/components/settings/setting-field.tsx +292 -0
- package/src/system/pages/components/settings/setting-form-dialog.tsx +308 -0
- package/src/system/pages/components/settings/settings-groups.ts +87 -0
- package/src/system/pages/components/settings/settings-page.tsx +372 -0
- package/src/system/pages/components/settings/settings-search.tsx +71 -0
- package/src/system/pages/components/settings/settings-section.tsx +74 -0
- package/src/system/pages/components/settings/settings-sidebar.tsx +81 -0
- package/src/system/pages/components/settings/system-settings.tsx +244 -0
- package/src/system/pages/system-category-page.tsx +15 -0
- package/src/system/pages/system-settings-page.tsx +380 -0
- package/src/system/schemas/system-category-group.schema.ts +46 -0
- package/src/system/schemas/system-category.schema.ts +56 -0
- package/src/system/services/settings-service.ts +127 -0
- package/src/system/services/system-category-service.ts +63 -0
- package/src/system/types.ts +45 -0
- package/src/types/index.ts +703 -0
- package/src/ui/auth/auth-layout.tsx +135 -0
- package/src/ui/auth/forgot-password-form.tsx +98 -0
- package/src/ui/auth/index.tsx +7 -0
- package/src/ui/auth/new-password-form.tsx +107 -0
- package/src/ui/auth/oauth-links.tsx +30 -0
- package/src/ui/auth/register-form.tsx +202 -0
- package/src/ui/auth/sign-in-form.tsx +238 -0
- package/src/ui/auth/verify-email-form.tsx +104 -0
- package/src/ui/crud/index.tsx +10 -0
- package/src/ui/data-display/accordion.tsx +65 -0
- package/src/ui/data-display/aspect-ratio.tsx +11 -0
- package/src/ui/data-display/avatar.tsx +163 -0
- package/src/ui/data-display/bento-grid.tsx +77 -0
- package/src/ui/data-display/carousel.tsx +249 -0
- package/src/ui/data-display/chart.tsx +363 -0
- package/src/ui/data-display/code-block-highlight.tsx +54 -0
- package/src/ui/data-display/collapsible.tsx +42 -0
- package/src/ui/data-display/compact-stat-bar.tsx +149 -0
- package/src/ui/data-display/data-table/data-table-context.tsx +255 -0
- package/src/ui/data-display/data-table/data-table-empty-state.tsx +133 -0
- package/src/ui/data-display/data-table/data-table-skeleton.tsx +145 -0
- package/src/ui/data-display/data-table/data-table-toolbar.tsx +353 -0
- package/src/ui/data-display/data-table/data-table.tsx +597 -0
- package/src/ui/data-display/data-table/index.ts +44 -0
- package/src/ui/data-display/data-table-column-header.tsx +75 -0
- package/src/ui/data-display/data-table-pagination.tsx +130 -0
- package/src/ui/data-display/data-table-view-options.tsx +59 -0
- package/src/ui/data-display/formatted-number-input.tsx +210 -0
- package/src/ui/data-display/highlight.tsx +20 -0
- package/src/ui/data-display/hover-card.tsx +48 -0
- package/src/ui/data-display/index.tsx +50 -0
- package/src/ui/data-display/iphone-15-pro.tsx +114 -0
- package/src/ui/data-display/kanban/index.ts +4 -0
- package/src/ui/data-display/kanban/kanban-board.tsx +192 -0
- package/src/ui/data-display/kanban/kanban-column.tsx +74 -0
- package/src/ui/data-display/kanban/kanban-item.tsx +50 -0
- package/src/ui/data-display/kanban/kanban-types.ts +21 -0
- package/src/ui/data-display/kpi-card.tsx +68 -0
- package/src/ui/data-display/media-grid.tsx +110 -0
- package/src/ui/data-display/safari.tsx +175 -0
- package/src/ui/data-display/show-more-text.tsx +55 -0
- package/src/ui/data-display/tabs.tsx +68 -0
- package/src/ui/data-display/timeline.tsx +256 -0
- package/src/ui/feedback/alert.tsx +60 -0
- package/src/ui/feedback/context-menu.tsx +245 -0
- package/src/ui/feedback/drawer.tsx +132 -0
- package/src/ui/feedback/error-dialog.tsx +273 -0
- package/src/ui/feedback/index.tsx +183 -0
- package/src/ui/feedback/progress.tsx +32 -0
- package/src/ui/feedback/sheet.tsx +148 -0
- package/src/ui/feedback/sonner.tsx +36 -0
- package/src/ui/forms/command.tsx +157 -0
- package/src/ui/forms/date-picker.tsx +73 -0
- package/src/ui/forms/date-range-picker.tsx +76 -0
- package/src/ui/forms/date-time-picker.tsx +109 -0
- package/src/ui/forms/editor/editor-menu-bar.tsx +394 -0
- package/src/ui/forms/editor/index.tsx +130 -0
- package/src/ui/forms/editor/multi-select-example.tsx +1234 -0
- package/src/ui/forms/emoji-picker.tsx +109 -0
- package/src/ui/forms/file-dropzone.tsx +169 -0
- package/src/ui/forms/file-thumbnail.tsx +29 -0
- package/src/ui/forms/index.tsx +201 -0
- package/src/ui/forms/input-file.tsx +99 -0
- package/src/ui/forms/input-group.tsx +46 -0
- package/src/ui/forms/input-otp.tsx +81 -0
- package/src/ui/forms/input-phone.tsx +172 -0
- package/src/ui/forms/input-spin.tsx +116 -0
- package/src/ui/forms/input-tags.tsx +219 -0
- package/src/ui/forms/input-time.tsx +42 -0
- package/src/ui/forms/multi-select.tsx +629 -0
- package/src/ui/forms/multiple-date-picker.tsx +74 -0
- package/src/ui/forms/radio-group.tsx +42 -0
- package/src/ui/forms/rating.tsx +158 -0
- package/src/ui/forms/time-picker.tsx +57 -0
- package/src/ui/index.tsx +17 -0
- package/src/ui/layout/animated-list.tsx +77 -0
- package/src/ui/layout/animated-sidebar.tsx +294 -0
- package/src/ui/layout/command-menu.tsx +355 -0
- package/src/ui/layout/customizer.tsx +324 -0
- package/src/ui/layout/footer.tsx +43 -0
- package/src/ui/layout/full-screen-toggle.tsx +52 -0
- package/src/ui/layout/header-breadcrumb.tsx +77 -0
- package/src/ui/layout/horizontal-layout-header.tsx +83 -0
- package/src/ui/layout/horizontal-layout.tsx +50 -0
- package/src/ui/layout/index.tsx +25 -0
- package/src/ui/layout/language-dropdown.tsx +103 -0
- package/src/ui/layout/logo.tsx +63 -0
- package/src/ui/layout/main-layout.tsx +57 -0
- package/src/ui/layout/mode-dropdown.tsx +58 -0
- package/src/ui/layout/notification-dropdown.tsx +127 -0
- package/src/ui/layout/page-tabs.tsx +306 -0
- package/src/ui/layout/route-cache.tsx +214 -0
- package/src/ui/layout/sidebar-group-icon-menu.tsx +195 -0
- package/src/ui/layout/sidebar.tsx +279 -0
- package/src/ui/layout/tab-content-cache.tsx +201 -0
- package/src/ui/layout/tab-navigation-provider.tsx +536 -0
- package/src/ui/layout/toggle-mobile-sidebar.tsx +33 -0
- package/src/ui/layout/top-bar-header-menubar.tsx +412 -0
- package/src/ui/layout/user-dropdown.tsx +188 -0
- package/src/ui/layout/vertical-layout-header.tsx +65 -0
- package/src/ui/layout/vertical-layout.tsx +47 -0
- package/src/ui/management/audit-log-page.tsx +209 -0
- package/src/ui/management/cache-management.tsx +349 -0
- package/src/ui/management/index.ts +3 -0
- package/src/ui/management/job-management.tsx +308 -0
- package/src/ui/pages/not-found.tsx +30 -0
- package/src/ui/primitives/badge.tsx +66 -0
- package/src/ui/primitives/breadcrumb.tsx +103 -0
- package/src/ui/primitives/button.tsx +129 -0
- package/src/ui/primitives/calendar.tsx +74 -0
- package/src/ui/primitives/card.tsx +86 -0
- package/src/ui/primitives/checkbox.tsx +31 -0
- package/src/ui/primitives/client.ts +30 -0
- package/src/ui/primitives/combobox.tsx +290 -0
- package/src/ui/primitives/dialog.tsx +121 -0
- package/src/ui/primitives/dropdown-menu.tsx +239 -0
- package/src/ui/primitives/dynamic-icon.tsx +24 -0
- package/src/ui/primitives/index.tsx +134 -0
- package/src/ui/primitives/input-number.tsx +131 -0
- package/src/ui/primitives/input.tsx +22 -0
- package/src/ui/primitives/keyboard.tsx +23 -0
- package/src/ui/primitives/label.tsx +24 -0
- package/src/ui/primitives/menubar.tsx +262 -0
- package/src/ui/primitives/navigation-menu.tsx +157 -0
- package/src/ui/primitives/pagination.tsx +118 -0
- package/src/ui/primitives/popover.tsx +56 -0
- package/src/ui/primitives/prefetch-link.tsx +60 -0
- package/src/ui/primitives/resizable.tsx +59 -0
- package/src/ui/primitives/scroll-area.tsx +63 -0
- package/src/ui/primitives/select.tsx +172 -0
- package/src/ui/primitives/separator.tsx +51 -0
- package/src/ui/primitives/sidebar.tsx +844 -0
- package/src/ui/primitives/slider.tsx +27 -0
- package/src/ui/primitives/status-badge.tsx +47 -0
- package/src/ui/primitives/sticky-layout.tsx +50 -0
- package/src/ui/primitives/switch.tsx +29 -0
- package/src/ui/primitives/table.tsx +116 -0
- package/src/ui/primitives/tabs.tsx +55 -0
- package/src/ui/primitives/toggle-group.tsx +70 -0
- package/src/ui/primitives/toggle.tsx +47 -0
- package/src/ui/primitives/tooltip.tsx +59 -0
- package/src/user/components/dangerous-zone.tsx +34 -0
- package/src/user/components/delete-account-form.tsx +40 -0
- package/src/user/components/index.ts +4 -0
- package/src/user/components/profile-info-form.tsx +390 -0
- package/src/user/components/profile-info.tsx +32 -0
- package/src/user/components/unified-profile-dialog.tsx +1019 -0
- package/src/user/components/user-stats.tsx +27 -0
- package/src/user/components/user-toolbar.tsx +137 -0
- package/src/user/components/users-card-view.tsx +253 -0
- package/src/user/index.ts +11 -0
- package/src/user/pages/user-list-page.tsx +234 -0
- package/src/user/pages/users-client-page.tsx +385 -0
- package/src/user/profile-page.tsx +19 -0
- package/src/user/schemas.ts +68 -0
- package/src/user/types.ts +34 -0
- package/src/user/user-service.ts +538 -0
- package/src/utils/index.ts +906 -0
- package/src/workflow/activity-timeline.tsx +412 -0
- package/src/workflow/approval-workflow.tsx +31 -0
- package/src/workflow/index.ts +2 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { format } from "date-fns";
|
|
5
|
+
import { CalendarIcon } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
import type { ComponentProps } from "react";
|
|
8
|
+
|
|
9
|
+
import { cn } from "../../utils";
|
|
10
|
+
|
|
11
|
+
import { Button } from "../primitives";
|
|
12
|
+
import { Calendar } from "../primitives/client";
|
|
13
|
+
import { InputTime } from "./input-time";
|
|
14
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../primitives/client";
|
|
15
|
+
import { Separator } from "../primitives";
|
|
16
|
+
|
|
17
|
+
type DateTimePickerProps = Omit<
|
|
18
|
+
ComponentProps<typeof Calendar>,
|
|
19
|
+
"mode" | "selected" | "onSelect"
|
|
20
|
+
> & {
|
|
21
|
+
value?: Date;
|
|
22
|
+
onValueChange?: (date?: Date) => void;
|
|
23
|
+
formatStr?: string;
|
|
24
|
+
popoverContentClassName?: string;
|
|
25
|
+
popoverContentOptions?: ComponentProps<typeof PopoverContent>;
|
|
26
|
+
buttonClassName?: string;
|
|
27
|
+
buttonOptions?: ComponentProps<typeof Button>;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function DateTimePicker({
|
|
32
|
+
value,
|
|
33
|
+
onValueChange,
|
|
34
|
+
formatStr = "yyyy-MM-dd p",
|
|
35
|
+
popoverContentClassName,
|
|
36
|
+
popoverContentOptions,
|
|
37
|
+
buttonClassName,
|
|
38
|
+
buttonOptions,
|
|
39
|
+
placeholder = "Pick date and time",
|
|
40
|
+
...props
|
|
41
|
+
}: DateTimePickerProps) {
|
|
42
|
+
const [selectedDate, setSelectedDate] = useState<Date | undefined>(value);
|
|
43
|
+
|
|
44
|
+
const handleDateSelect = (selected?: Date | undefined) => {
|
|
45
|
+
if (!selected) return;
|
|
46
|
+
|
|
47
|
+
// Preserve the time when changing the date
|
|
48
|
+
const newDateTime = new Date(selected);
|
|
49
|
+
if (selectedDate) {
|
|
50
|
+
newDateTime.setHours(selectedDate.getHours());
|
|
51
|
+
newDateTime.setMinutes(selectedDate.getMinutes());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setSelectedDate(newDateTime);
|
|
55
|
+
onValueChange?.(newDateTime);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleTimeChange = (timeString?: string) => {
|
|
59
|
+
if (!timeString) return;
|
|
60
|
+
|
|
61
|
+
const [hours, minutes] = timeString.split(":").map(Number);
|
|
62
|
+
|
|
63
|
+
if (selectedDate) {
|
|
64
|
+
const newDateTime = new Date(selectedDate);
|
|
65
|
+
newDateTime.setHours(hours);
|
|
66
|
+
newDateTime.setMinutes(minutes);
|
|
67
|
+
|
|
68
|
+
setSelectedDate(newDateTime);
|
|
69
|
+
onValueChange?.(newDateTime);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Popover modal>
|
|
75
|
+
<PopoverTrigger asChild>
|
|
76
|
+
<Button
|
|
77
|
+
variant="outline"
|
|
78
|
+
className={cn("w-full px-3 text-start font-normal", buttonClassName)}
|
|
79
|
+
{...buttonOptions}
|
|
80
|
+
>
|
|
81
|
+
{selectedDate ? (
|
|
82
|
+
<span>{format(selectedDate, formatStr)}</span>
|
|
83
|
+
) : (
|
|
84
|
+
<span className="text-muted-foreground">{placeholder}</span>
|
|
85
|
+
)}
|
|
86
|
+
<CalendarIcon className="ms-auto h-4 w-4 text-muted-foreground" />
|
|
87
|
+
</Button>
|
|
88
|
+
</PopoverTrigger>
|
|
89
|
+
<PopoverContent
|
|
90
|
+
className={cn("w-auto p-0", popoverContentClassName)}
|
|
91
|
+
align="start"
|
|
92
|
+
{...popoverContentOptions}
|
|
93
|
+
>
|
|
94
|
+
<Calendar
|
|
95
|
+
mode="single"
|
|
96
|
+
selected={selectedDate}
|
|
97
|
+
onSelect={handleDateSelect}
|
|
98
|
+
{...props}
|
|
99
|
+
/>
|
|
100
|
+
<Separator />
|
|
101
|
+
<InputTime
|
|
102
|
+
className="rounded-t-none border-0"
|
|
103
|
+
onValueChange={handleTimeChange}
|
|
104
|
+
value={selectedDate ? format(selectedDate, "p") : undefined}
|
|
105
|
+
/>
|
|
106
|
+
</PopoverContent>
|
|
107
|
+
</Popover>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useRef, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
AlignCenter,
|
|
6
|
+
AlignJustify,
|
|
7
|
+
AlignLeft,
|
|
8
|
+
AlignRight,
|
|
9
|
+
Bold,
|
|
10
|
+
Check,
|
|
11
|
+
Code,
|
|
12
|
+
Image as ImageIcon,
|
|
13
|
+
Italic,
|
|
14
|
+
Link as LinkIcon,
|
|
15
|
+
List,
|
|
16
|
+
ListOrdered,
|
|
17
|
+
Minus,
|
|
18
|
+
Palette,
|
|
19
|
+
Quote,
|
|
20
|
+
Redo,
|
|
21
|
+
Strikethrough,
|
|
22
|
+
Type,
|
|
23
|
+
Undo,
|
|
24
|
+
Unlink,
|
|
25
|
+
} from "lucide-react";
|
|
26
|
+
|
|
27
|
+
import type { DynamicIconNameType } from "../../../types";
|
|
28
|
+
import type { ChainedCommands, Editor } from "@tiptap/react";
|
|
29
|
+
import type { FormEvent } from "react";
|
|
30
|
+
|
|
31
|
+
import { cn } from "../../../utils";
|
|
32
|
+
|
|
33
|
+
import { Button } from "../../primitives";
|
|
34
|
+
import { Input } from "../../primitives";
|
|
35
|
+
import { InputFile } from "../input-file";
|
|
36
|
+
import {
|
|
37
|
+
Popover,
|
|
38
|
+
PopoverContent,
|
|
39
|
+
PopoverTrigger,
|
|
40
|
+
} from "../../primitives/client";
|
|
41
|
+
import { Separator } from "../../primitives";
|
|
42
|
+
import { Toggle } from "../../primitives/client";
|
|
43
|
+
import { DynamicIcon } from "../../primitives/client";
|
|
44
|
+
|
|
45
|
+
interface SizeType {
|
|
46
|
+
label: string;
|
|
47
|
+
level: 1 | 2 | 3;
|
|
48
|
+
textSize: `text-${string}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const sizes: SizeType[] = [
|
|
52
|
+
{ label: "Normal", level: 3, textSize: "text-lg" },
|
|
53
|
+
{ label: "Large", level: 2, textSize: "text-xl" },
|
|
54
|
+
{ label: "Extra Large", level: 1, textSize: "text-2xl" },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
function SizeHandler({ editor }: { editor: Editor }) {
|
|
58
|
+
return (
|
|
59
|
+
<Popover>
|
|
60
|
+
<PopoverTrigger asChild>
|
|
61
|
+
<Button
|
|
62
|
+
variant="ghost"
|
|
63
|
+
size="icon"
|
|
64
|
+
className="h-8 w-8"
|
|
65
|
+
aria-label="Select text style"
|
|
66
|
+
>
|
|
67
|
+
<Type className="h-4 w-4" />
|
|
68
|
+
</Button>
|
|
69
|
+
</PopoverTrigger>
|
|
70
|
+
<PopoverContent align="start" className="min-w-[8rem] w-auto p-1">
|
|
71
|
+
<div className="flex flex-col">
|
|
72
|
+
<Button
|
|
73
|
+
variant="ghost"
|
|
74
|
+
onClick={() => editor.chain().focus().setParagraph().run()}
|
|
75
|
+
className={cn(
|
|
76
|
+
"justify-start px-3 py-2 text-left text-base",
|
|
77
|
+
editor.isActive("paragraph") && "bg-muted",
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
Small
|
|
81
|
+
</Button>
|
|
82
|
+
{sizes.map((size: SizeType) => (
|
|
83
|
+
<Button
|
|
84
|
+
key={size.level}
|
|
85
|
+
variant="ghost"
|
|
86
|
+
onClick={() =>
|
|
87
|
+
editor
|
|
88
|
+
.chain()
|
|
89
|
+
.focus()
|
|
90
|
+
.toggleHeading({ level: size.level })
|
|
91
|
+
.run()
|
|
92
|
+
}
|
|
93
|
+
className={cn(
|
|
94
|
+
"justify-start px-3 py-2 text-left",
|
|
95
|
+
size.textSize,
|
|
96
|
+
editor.isActive("heading", { level: size.level }) && "bg-muted",
|
|
97
|
+
)}
|
|
98
|
+
>
|
|
99
|
+
{size.label}
|
|
100
|
+
</Button>
|
|
101
|
+
))}
|
|
102
|
+
</div>
|
|
103
|
+
</PopoverContent>
|
|
104
|
+
</Popover>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface FormatType {
|
|
109
|
+
format: string;
|
|
110
|
+
iconName: DynamicIconNameType;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const formats: FormatType[] = [
|
|
114
|
+
{
|
|
115
|
+
format: "bold",
|
|
116
|
+
iconName: "Bold",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
format: "italic",
|
|
120
|
+
iconName: "Italic",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
format: "underline",
|
|
124
|
+
iconName: "Underline",
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
format: "strike",
|
|
128
|
+
iconName: "Strikethrough",
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
function FormatHandler({
|
|
133
|
+
editor,
|
|
134
|
+
format,
|
|
135
|
+
iconName,
|
|
136
|
+
}: {
|
|
137
|
+
editor: Editor;
|
|
138
|
+
format: string;
|
|
139
|
+
iconName: DynamicIconNameType;
|
|
140
|
+
}) {
|
|
141
|
+
const toggleCommands: Record<string, () => ChainedCommands> = {
|
|
142
|
+
bold: () => editor.chain().focus().toggleBold(),
|
|
143
|
+
italic: () => editor.chain().focus().toggleItalic(),
|
|
144
|
+
underline: () => editor.chain().focus().toggleUnderline(),
|
|
145
|
+
strike: () => editor.chain().focus().toggleStrike(),
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
function handlePressChange() {
|
|
149
|
+
const command = toggleCommands[format];
|
|
150
|
+
|
|
151
|
+
if (command) {
|
|
152
|
+
command().run();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<Toggle
|
|
158
|
+
size="sm"
|
|
159
|
+
pressed={editor.isActive(format)}
|
|
160
|
+
onPressedChange={handlePressChange}
|
|
161
|
+
aria-label={`Toggle ${format} format`}
|
|
162
|
+
>
|
|
163
|
+
<DynamicIcon name={iconName} className="h-4 w-4" />
|
|
164
|
+
</Toggle>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
interface AlignmentType {
|
|
169
|
+
alignment: string;
|
|
170
|
+
iconName: DynamicIconNameType;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const alignments: AlignmentType[] = [
|
|
174
|
+
{ alignment: "left", iconName: "AlignLeft" },
|
|
175
|
+
{ alignment: "center", iconName: "AlignCenter" },
|
|
176
|
+
{ alignment: "right", iconName: "AlignRight" },
|
|
177
|
+
{ alignment: "justify", iconName: "AlignJustify" },
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
function AlignmentHandler({
|
|
181
|
+
editor,
|
|
182
|
+
alignment,
|
|
183
|
+
iconName,
|
|
184
|
+
}: {
|
|
185
|
+
editor: Editor;
|
|
186
|
+
alignment: string;
|
|
187
|
+
iconName: DynamicIconNameType;
|
|
188
|
+
}) {
|
|
189
|
+
return (
|
|
190
|
+
<Toggle
|
|
191
|
+
size="sm"
|
|
192
|
+
pressed={editor.isActive({ textAlign: alignment })}
|
|
193
|
+
onPressedChange={() =>
|
|
194
|
+
editor.chain().focus().setTextAlign(alignment).run()
|
|
195
|
+
}
|
|
196
|
+
aria-label={`Switch ${alignment} alignment`}
|
|
197
|
+
>
|
|
198
|
+
<DynamicIcon name={iconName} className="h-4 w-4" />
|
|
199
|
+
</Toggle>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function ImageHandler({ editor }: { editor: Editor }) {
|
|
204
|
+
const [imageSrc, setImageSrc] = useState<string | null>(null);
|
|
205
|
+
|
|
206
|
+
function handleFileChange(files: FileList) {
|
|
207
|
+
if (files.length < 1) return;
|
|
208
|
+
const objectURL = URL.createObjectURL(files[0]);
|
|
209
|
+
setImageSrc(objectURL);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function handleSubmit(e: FormEvent<HTMLFormElement>) {
|
|
213
|
+
e.preventDefault();
|
|
214
|
+
if (editor && imageSrc) {
|
|
215
|
+
editor.chain().focus().setImage({ src: imageSrc }).run();
|
|
216
|
+
setImageSrc(null);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<Popover>
|
|
222
|
+
<PopoverTrigger asChild>
|
|
223
|
+
<Button
|
|
224
|
+
type="button"
|
|
225
|
+
variant="ghost"
|
|
226
|
+
size="icon"
|
|
227
|
+
className="h-8 w-8"
|
|
228
|
+
aria-label="Insert image"
|
|
229
|
+
>
|
|
230
|
+
<ImageIcon className="h-4 w-4" />
|
|
231
|
+
</Button>
|
|
232
|
+
</PopoverTrigger>
|
|
233
|
+
<PopoverContent>
|
|
234
|
+
<form
|
|
235
|
+
onSubmit={(e) => {
|
|
236
|
+
e.stopPropagation();
|
|
237
|
+
handleSubmit(e);
|
|
238
|
+
}}
|
|
239
|
+
className="flex justify-center items-center gap-2"
|
|
240
|
+
>
|
|
241
|
+
<InputFile onValueChange={handleFileChange} />
|
|
242
|
+
<Button
|
|
243
|
+
type="submit"
|
|
244
|
+
variant="ghost"
|
|
245
|
+
size="icon"
|
|
246
|
+
className="shrink-0 h-8 w-8"
|
|
247
|
+
aria-label="Submit"
|
|
248
|
+
>
|
|
249
|
+
<Check className="h-4 w-4" />
|
|
250
|
+
</Button>
|
|
251
|
+
</form>
|
|
252
|
+
</PopoverContent>
|
|
253
|
+
</Popover>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function LinkHandler({ editor }: { editor: Editor }) {
|
|
258
|
+
const isLinkActive = editor.isActive("link");
|
|
259
|
+
|
|
260
|
+
return isLinkActive ? (
|
|
261
|
+
<Button
|
|
262
|
+
type="button"
|
|
263
|
+
variant="ghost"
|
|
264
|
+
size="icon"
|
|
265
|
+
className="h-8 w-8"
|
|
266
|
+
onClick={() => editor.chain().focus().unsetLink().run()}
|
|
267
|
+
aria-label="Remove link"
|
|
268
|
+
>
|
|
269
|
+
<Unlink className="h-4 w-4" />
|
|
270
|
+
</Button>
|
|
271
|
+
) : (
|
|
272
|
+
<Popover>
|
|
273
|
+
<PopoverTrigger asChild>
|
|
274
|
+
<Button
|
|
275
|
+
type="button"
|
|
276
|
+
variant="ghost"
|
|
277
|
+
size="icon"
|
|
278
|
+
className="h-8 w-8"
|
|
279
|
+
aria-label="Insert link"
|
|
280
|
+
>
|
|
281
|
+
<LinkIcon className="h-4 w-4" />
|
|
282
|
+
</Button>
|
|
283
|
+
</PopoverTrigger>
|
|
284
|
+
<PopoverContent className="flex justify-center items-center gap-2">
|
|
285
|
+
<p className="shrink-0">Insert link</p>
|
|
286
|
+
<Input
|
|
287
|
+
autoFocus
|
|
288
|
+
type="text"
|
|
289
|
+
placeholder="https://www.example.com"
|
|
290
|
+
onKeyDown={(e) => {
|
|
291
|
+
if (e.key === "Enter") {
|
|
292
|
+
editor
|
|
293
|
+
.chain()
|
|
294
|
+
.focus()
|
|
295
|
+
.setLink({
|
|
296
|
+
href: (e.target as HTMLInputElement).value,
|
|
297
|
+
})
|
|
298
|
+
.run();
|
|
299
|
+
}
|
|
300
|
+
}}
|
|
301
|
+
/>
|
|
302
|
+
<Button
|
|
303
|
+
type="button"
|
|
304
|
+
variant="ghost"
|
|
305
|
+
size="icon"
|
|
306
|
+
className="shrink-0 h-8 w-8"
|
|
307
|
+
onClick={(e) => {
|
|
308
|
+
editor
|
|
309
|
+
.chain()
|
|
310
|
+
.focus()
|
|
311
|
+
.setLink({
|
|
312
|
+
href: (e.target as HTMLInputElement).value,
|
|
313
|
+
})
|
|
314
|
+
.run();
|
|
315
|
+
}}
|
|
316
|
+
aria-label="Submit"
|
|
317
|
+
>
|
|
318
|
+
<Check className="h-4 w-4" />
|
|
319
|
+
</Button>
|
|
320
|
+
</PopoverContent>
|
|
321
|
+
</Popover>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function ColorHandler({ editor }: { editor: Editor }) {
|
|
326
|
+
const selectedColor = editor.getAttributes("textStyle").color;
|
|
327
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
328
|
+
|
|
329
|
+
return (
|
|
330
|
+
<Button
|
|
331
|
+
type="button"
|
|
332
|
+
variant="ghost"
|
|
333
|
+
size="icon"
|
|
334
|
+
className="relative overflow-hidden"
|
|
335
|
+
onClick={() => inputRef.current?.click()}
|
|
336
|
+
aria-label="Select text color"
|
|
337
|
+
>
|
|
338
|
+
<Palette style={{ color: selectedColor }} className="size-4" />
|
|
339
|
+
<Input
|
|
340
|
+
ref={inputRef}
|
|
341
|
+
type="color"
|
|
342
|
+
value={selectedColor}
|
|
343
|
+
onChange={(e) =>
|
|
344
|
+
editor
|
|
345
|
+
.chain()
|
|
346
|
+
.focus()
|
|
347
|
+
.setColor(e.target.value as string)
|
|
348
|
+
.run()
|
|
349
|
+
}
|
|
350
|
+
className="sr-only"
|
|
351
|
+
tabIndex={-1}
|
|
352
|
+
/>
|
|
353
|
+
</Button>
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function EditorMenuBar({ editor }: { editor: Editor }) {
|
|
358
|
+
return (
|
|
359
|
+
<div
|
|
360
|
+
className="flex flex-wrap items-center gap-1.5 p-1.5"
|
|
361
|
+
aria-label="Editor Menu Bar"
|
|
362
|
+
>
|
|
363
|
+
<SizeHandler editor={editor} />
|
|
364
|
+
<ColorHandler editor={editor} />
|
|
365
|
+
|
|
366
|
+
<Separator orientation="vertical" className="h-4" />
|
|
367
|
+
|
|
368
|
+
{formats.map(({ format, iconName }) => (
|
|
369
|
+
<FormatHandler
|
|
370
|
+
key={format}
|
|
371
|
+
editor={editor}
|
|
372
|
+
format={format}
|
|
373
|
+
iconName={iconName}
|
|
374
|
+
/>
|
|
375
|
+
))}
|
|
376
|
+
|
|
377
|
+
<Separator orientation="vertical" className="h-4" />
|
|
378
|
+
|
|
379
|
+
{alignments.map(({ alignment, iconName }) => (
|
|
380
|
+
<AlignmentHandler
|
|
381
|
+
key={alignment}
|
|
382
|
+
editor={editor}
|
|
383
|
+
alignment={alignment}
|
|
384
|
+
iconName={iconName}
|
|
385
|
+
/>
|
|
386
|
+
))}
|
|
387
|
+
|
|
388
|
+
<Separator orientation="vertical" className="h-4" />
|
|
389
|
+
|
|
390
|
+
<ImageHandler editor={editor} />
|
|
391
|
+
<LinkHandler editor={editor} />
|
|
392
|
+
</div>
|
|
393
|
+
);
|
|
394
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useDirection } from "@radix-ui/react-direction";
|
|
4
|
+
import Color from "@tiptap/extension-color";
|
|
5
|
+
import Image from "@tiptap/extension-image";
|
|
6
|
+
import Link from "@tiptap/extension-link";
|
|
7
|
+
import Placeholder from "@tiptap/extension-placeholder";
|
|
8
|
+
import TextAlign from "@tiptap/extension-text-align";
|
|
9
|
+
import TextStyle from "@tiptap/extension-text-style";
|
|
10
|
+
import Typography from "@tiptap/extension-typography";
|
|
11
|
+
import Underline from "@tiptap/extension-underline";
|
|
12
|
+
import { BubbleMenu, EditorContent, useEditor } from "@tiptap/react";
|
|
13
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
14
|
+
|
|
15
|
+
import type { UseEditorOptions } from "@tiptap/react";
|
|
16
|
+
|
|
17
|
+
import { cn } from "../../../utils";
|
|
18
|
+
|
|
19
|
+
import { useIsRtl } from "../../../hooks";
|
|
20
|
+
import { Card } from "../../primitives";
|
|
21
|
+
import { ScrollArea } from "../../primitives/client";
|
|
22
|
+
import { EditorMenuBar } from "./editor-menu-bar";
|
|
23
|
+
|
|
24
|
+
interface EditorProps extends UseEditorOptions {
|
|
25
|
+
value?: string;
|
|
26
|
+
onValueChange?: (value: string) => void;
|
|
27
|
+
bubbleMenu?: boolean;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
className?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function Editor({
|
|
33
|
+
value,
|
|
34
|
+
onValueChange,
|
|
35
|
+
bubbleMenu = false,
|
|
36
|
+
placeholder,
|
|
37
|
+
className,
|
|
38
|
+
...props
|
|
39
|
+
}: EditorProps) {
|
|
40
|
+
const direction = useDirection();
|
|
41
|
+
const isRtl = useIsRtl();
|
|
42
|
+
|
|
43
|
+
const editor = useEditor({
|
|
44
|
+
immediatelyRender: false,
|
|
45
|
+
editorProps: {
|
|
46
|
+
attributes: {
|
|
47
|
+
class: cn(
|
|
48
|
+
"px-3 py-2 break-all [&_p]:m-0 [&_.is-editor-empty]:before:absolute [&_.is-editor-empty]:before:top-2 [&_.is-editor-empty]:before:cursor-text [&_.is-editor-empty]:before:text-muted-foreground [&_.is-editor-empty]:before:content-[attr(data-placeholder)] prose prose-headings:font-normal prose-headings:text-foreground prose-h1:text-2xl prose-h2:text-xl prose-h3:text-lg dark:prose-invert focus:outline-hidden",
|
|
49
|
+
className,
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
extensions: [
|
|
54
|
+
StarterKit,
|
|
55
|
+
Underline,
|
|
56
|
+
TextAlign.configure({
|
|
57
|
+
types: ["heading", "paragraph"],
|
|
58
|
+
defaultAlignment: isRtl ? "right" : "left",
|
|
59
|
+
}),
|
|
60
|
+
Color,
|
|
61
|
+
TextStyle,
|
|
62
|
+
Image,
|
|
63
|
+
Link.configure({
|
|
64
|
+
openOnClick: true,
|
|
65
|
+
HTMLAttributes: {
|
|
66
|
+
rel: "noopener noreferrer",
|
|
67
|
+
target: "_blank",
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
Placeholder.configure({
|
|
71
|
+
placeholder: placeholder,
|
|
72
|
+
showOnlyCurrent: true,
|
|
73
|
+
}),
|
|
74
|
+
Typography,
|
|
75
|
+
],
|
|
76
|
+
content: value,
|
|
77
|
+
onUpdate: ({ editor }) => {
|
|
78
|
+
onValueChange?.(editor.getHTML());
|
|
79
|
+
},
|
|
80
|
+
...props,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (!editor) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Card>
|
|
89
|
+
{bubbleMenu ? (
|
|
90
|
+
<BubbleMenu
|
|
91
|
+
className="z-50 h-auto rounded-md border bg-popover text-popover-foreground shadow-md outline-hidden"
|
|
92
|
+
editor={editor}
|
|
93
|
+
tippyOptions={{
|
|
94
|
+
duration: 100,
|
|
95
|
+
maxWidth: "98vw",
|
|
96
|
+
appendTo: document.body,
|
|
97
|
+
zIndex: 50,
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<EditorMenuBar editor={editor} />
|
|
101
|
+
</BubbleMenu>
|
|
102
|
+
) : (
|
|
103
|
+
<EditorMenuBar editor={editor} />
|
|
104
|
+
)}
|
|
105
|
+
<ScrollArea
|
|
106
|
+
className={cn(
|
|
107
|
+
"flex flex-col min-h-9 rounded-md cursor-text",
|
|
108
|
+
!bubbleMenu && "border-t border-border",
|
|
109
|
+
editor.isFocused && "outline-hidden ring-1 ring-ring",
|
|
110
|
+
)}
|
|
111
|
+
>
|
|
112
|
+
<EditorContent
|
|
113
|
+
editor={editor}
|
|
114
|
+
dir={direction}
|
|
115
|
+
className={cn(
|
|
116
|
+
editor.isActive({ textAlign: "left" }) &&
|
|
117
|
+
"[&_.is-editor-empty]:before:left-3",
|
|
118
|
+
editor.isActive({ textAlign: "right" }) &&
|
|
119
|
+
"[&_.is-editor-empty]:before:right-3",
|
|
120
|
+
editor.isActive({ textAlign: "center" }) &&
|
|
121
|
+
"[&_.is-editor-empty]:before:left-1/2 [&_.is-editor-empty]:before:absolute [&_.is-editor-empty]:before:-translate-x-1/2",
|
|
122
|
+
editor.isActive({ textAlign: "justify" }) &&
|
|
123
|
+
"[&_.is-editor-empty]:before:left-3",
|
|
124
|
+
)}
|
|
125
|
+
onClick={() => editor.commands.focus()}
|
|
126
|
+
/>
|
|
127
|
+
</ScrollArea>
|
|
128
|
+
</Card>
|
|
129
|
+
);
|
|
130
|
+
}
|