opacacms 0.1.1 → 0.1.2

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.
Files changed (212) hide show
  1. package/package.json +36 -1
  2. package/bun.lock +0 -34
  3. package/global.d.ts +0 -11
  4. package/src/admin/api-client.ts +0 -63
  5. package/src/admin/auth-client.ts +0 -40
  6. package/src/admin/custom-field.ts +0 -179
  7. package/src/admin/index.ts +0 -15
  8. package/src/admin/react.tsx +0 -72
  9. package/src/admin/router.ts +0 -9
  10. package/src/admin/stores/admin-queries.ts +0 -121
  11. package/src/admin/stores/auth.ts +0 -61
  12. package/src/admin/stores/column-visibility.ts +0 -67
  13. package/src/admin/stores/config.ts +0 -15
  14. package/src/admin/stores/media.ts +0 -95
  15. package/src/admin/stores/query.ts +0 -13
  16. package/src/admin/stores/ui.ts +0 -29
  17. package/src/admin/ui/admin-client.tsx +0 -283
  18. package/src/admin/ui/admin-layout.tsx +0 -276
  19. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  20. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  21. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  22. package/src/admin/ui/components/Table.tsx +0 -67
  23. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  24. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  25. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  26. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  27. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  28. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  29. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  30. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  31. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  32. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  33. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  34. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  35. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  36. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  37. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  38. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  39. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  40. package/src/admin/ui/components/fields/index.tsx +0 -371
  41. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  42. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  43. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  44. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  45. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  46. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  47. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  48. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  49. package/src/admin/ui/components/fields/utils.ts +0 -1
  50. package/src/admin/ui/components/link.tsx +0 -41
  51. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  52. package/src/admin/ui/components/toast.tsx +0 -72
  53. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  54. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  55. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  56. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  57. package/src/admin/ui/components/ui/button.tsx +0 -26
  58. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  59. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  60. package/src/admin/ui/components/ui/group.tsx +0 -20
  61. package/src/admin/ui/components/ui/index.ts +0 -17
  62. package/src/admin/ui/components/ui/input.tsx +0 -12
  63. package/src/admin/ui/components/ui/join.tsx +0 -53
  64. package/src/admin/ui/components/ui/label.tsx +0 -11
  65. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  66. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  67. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  68. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  69. package/src/admin/ui/components/ui/select.tsx +0 -187
  70. package/src/admin/ui/components/ui/separator.tsx +0 -21
  71. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  72. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  73. package/src/admin/ui/components/ui/utils.ts +0 -3
  74. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  75. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  76. package/src/admin/ui/styles/accordion.scss +0 -60
  77. package/src/admin/ui/styles/animations.scss +0 -41
  78. package/src/admin/ui/styles/asset-manager.scss +0 -547
  79. package/src/admin/ui/styles/badge.scss +0 -13
  80. package/src/admin/ui/styles/base.scss +0 -22
  81. package/src/admin/ui/styles/button.scss +0 -161
  82. package/src/admin/ui/styles/card.scss +0 -13
  83. package/src/admin/ui/styles/collapsible.scss +0 -75
  84. package/src/admin/ui/styles/data-detail.scss +0 -92
  85. package/src/admin/ui/styles/dialog.scss +0 -102
  86. package/src/admin/ui/styles/empty-state.scss +0 -22
  87. package/src/admin/ui/styles/group.scss +0 -19
  88. package/src/admin/ui/styles/index.scss +0 -33
  89. package/src/admin/ui/styles/input.scss +0 -80
  90. package/src/admin/ui/styles/label.scss +0 -12
  91. package/src/admin/ui/styles/layout.scss +0 -56
  92. package/src/admin/ui/styles/lexical.scss +0 -469
  93. package/src/admin/ui/styles/loading.scss +0 -102
  94. package/src/admin/ui/styles/media-registry.scss +0 -597
  95. package/src/admin/ui/styles/pagination.scss +0 -20
  96. package/src/admin/ui/styles/radio-group.scss +0 -66
  97. package/src/admin/ui/styles/row.scss +0 -17
  98. package/src/admin/ui/styles/scrollbar.scss +0 -36
  99. package/src/admin/ui/styles/select.scss +0 -121
  100. package/src/admin/ui/styles/separator.scss +0 -14
  101. package/src/admin/ui/styles/sheet.scss +0 -152
  102. package/src/admin/ui/styles/sidebar.scss +0 -148
  103. package/src/admin/ui/styles/switch.scss +0 -59
  104. package/src/admin/ui/styles/table.scss +0 -207
  105. package/src/admin/ui/styles/tabs.scss +0 -62
  106. package/src/admin/ui/styles/toast.scss +0 -45
  107. package/src/admin/ui/styles/variables.scss +0 -24
  108. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  109. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  110. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  111. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  112. package/src/admin/ui/views/init-view.tsx +0 -182
  113. package/src/admin/ui/views/login-view.tsx +0 -123
  114. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  115. package/src/admin/ui/views/settings-view.tsx +0 -729
  116. package/src/admin/webcomponent.tsx +0 -15
  117. package/src/auth/index.ts +0 -194
  118. package/src/auth/migrations.ts +0 -87
  119. package/src/auth/premissions.ts +0 -46
  120. package/src/cli/commands/generate-types.ts +0 -116
  121. package/src/cli/commands/init.ts +0 -95
  122. package/src/cli/commands/migrate-commands.ts +0 -160
  123. package/src/cli/commands/seed-command.ts +0 -11
  124. package/src/cli/d1-mock.ts +0 -101
  125. package/src/cli/index.test.ts +0 -84
  126. package/src/cli/index.ts +0 -183
  127. package/src/cli/r2-mock.ts +0 -217
  128. package/src/cli/seeding.ts +0 -409
  129. package/src/client.ts +0 -181
  130. package/src/config-utils.ts +0 -102
  131. package/src/config.ts +0 -49
  132. package/src/db/adapter.ts +0 -53
  133. package/src/db/better-sqlite.ts +0 -630
  134. package/src/db/bun-sqlite.ts +0 -646
  135. package/src/db/d1.ts +0 -711
  136. package/src/db/index.ts +0 -2
  137. package/src/db/kysely/data-mapper.ts +0 -142
  138. package/src/db/kysely/field-mapper.ts +0 -148
  139. package/src/db/kysely/migration-generator.ts +0 -223
  140. package/src/db/kysely/query-builder.ts +0 -92
  141. package/src/db/kysely/schema-builder.ts +0 -439
  142. package/src/db/kysely/sql-utils.ts +0 -13
  143. package/src/db/migration.ts +0 -40
  144. package/src/db/postgres.ts +0 -621
  145. package/src/db/sqlite.ts +0 -658
  146. package/src/db/system-schema.ts +0 -121
  147. package/src/index.ts +0 -11
  148. package/src/runtimes/README.md +0 -59
  149. package/src/runtimes/bun.ts +0 -49
  150. package/src/runtimes/cloudflare-workers.ts +0 -38
  151. package/src/runtimes/next.ts +0 -26
  152. package/src/runtimes/node.ts +0 -52
  153. package/src/schema/collection.ts +0 -184
  154. package/src/schema/fields/base.ts +0 -164
  155. package/src/schema/fields/index.ts +0 -427
  156. package/src/schema/global.ts +0 -145
  157. package/src/schema/index.ts +0 -4
  158. package/src/schema/infer.ts +0 -72
  159. package/src/server/admin-router.ts +0 -20
  160. package/src/server/admin.ts +0 -142
  161. package/src/server/assets.ts +0 -306
  162. package/src/server/collection-router.ts +0 -55
  163. package/src/server/handlers.ts +0 -722
  164. package/src/server/middlewares/admin.ts +0 -27
  165. package/src/server/middlewares/auth.ts +0 -89
  166. package/src/server/middlewares/context.ts +0 -17
  167. package/src/server/middlewares/cors.ts +0 -24
  168. package/src/server/middlewares/database-init.ts +0 -74
  169. package/src/server/middlewares/rate-limit.ts +0 -71
  170. package/src/server/router.ts +0 -47
  171. package/src/server/setup-middlewares.ts +0 -58
  172. package/src/server/system-router.ts +0 -35
  173. package/src/server.ts +0 -9
  174. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  175. package/src/storage/adapters/local.ts +0 -146
  176. package/src/storage/adapters/s3.ts +0 -186
  177. package/src/storage/errors.ts +0 -46
  178. package/src/storage/index.ts +0 -6
  179. package/src/storage/types.ts +0 -39
  180. package/src/types.ts +0 -605
  181. package/src/utils/lexical.ts +0 -37
  182. package/src/utils/logger.ts +0 -73
  183. package/src/validation.ts +0 -429
  184. package/src/validator.ts +0 -179
  185. package/test/admin-custom-field.test.ts +0 -162
  186. package/test/admin-react-field.test.tsx +0 -134
  187. package/test/api-features.test.ts +0 -78
  188. package/test/api.test.ts +0 -178
  189. package/test/auth.test.ts +0 -62
  190. package/test/cli-integration.test.ts +0 -148
  191. package/test/cli.test.ts +0 -25
  192. package/test/db/postgres.test.ts +0 -95
  193. package/test/db/sqlite-filter.test.ts +0 -53
  194. package/test/db/sqlite.test.ts +0 -82
  195. package/test/engine-features.test.ts +0 -79
  196. package/test/globals.test.ts +0 -74
  197. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  198. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  199. package/test/integration-tmp/my-test-app/index.ts +0 -8
  200. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  201. package/test/integration-tmp/my-test-app/package.json +0 -12
  202. package/test/populate.test.ts +0 -79
  203. package/test/runtimes.test.ts +0 -43
  204. package/test/schema-builder.test.ts +0 -107
  205. package/test/schema-features.test.ts +0 -63
  206. package/test/seeding.test.ts +0 -68
  207. package/test/storage/local.test.ts +0 -72
  208. package/test/storage/s3.test.ts +0 -60
  209. package/test/structural-data.test.ts +0 -100
  210. package/test/test-setup.ts +0 -11
  211. package/test/validation.test.ts +0 -162
  212. package/tsconfig.json +0 -42
@@ -1,75 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "./utils";
3
- import "../../styles/radio-group.scss";
4
-
5
- export interface RadioGroupProps extends React.HTMLAttributes<HTMLDivElement> {
6
- value?: string;
7
- onValueChange?: (value: string) => void;
8
- disabled?: boolean;
9
- name?: string;
10
- }
11
-
12
- export const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(
13
- ({ className, value, onValueChange, disabled, name, children, ...props }, ref) => {
14
- const contextValue = React.useMemo(
15
- () => ({ value, onValueChange, disabled, name }),
16
- [value, onValueChange, disabled, name],
17
- );
18
-
19
- return (
20
- <RadioGroupContext.Provider value={contextValue}>
21
- <div ref={ref} className={cn("opaca-ui-radio-group", className)} {...props}>
22
- {children}
23
- </div>
24
- </RadioGroupContext.Provider>
25
- );
26
- },
27
- );
28
- RadioGroup.displayName = "RadioGroup";
29
-
30
- interface RadioGroupContextValue {
31
- value?: string;
32
- onValueChange?: (value: string) => void;
33
- disabled?: boolean;
34
- name?: string;
35
- }
36
-
37
- const RadioGroupContext = React.createContext<RadioGroupContextValue>({});
38
-
39
- export interface RadioGroupItemProps extends React.InputHTMLAttributes<HTMLInputElement> {
40
- value: string;
41
- }
42
-
43
- export const RadioGroupItem = React.forwardRef<HTMLInputElement, RadioGroupItemProps>(
44
- ({ className, value, disabled, id, ...props }, ref) => {
45
- const context = React.useContext(RadioGroupContext);
46
-
47
- const isDisabled = disabled || context.disabled;
48
- const isChecked = context.value === value;
49
- const name = context.name;
50
-
51
- const handleChange = () => {
52
- if (!isDisabled && context.onValueChange) {
53
- context.onValueChange(value);
54
- }
55
- };
56
-
57
- return (
58
- <div className="opaca-ui-radio-item">
59
- <input
60
- type="radio"
61
- ref={ref}
62
- id={id}
63
- name={name}
64
- value={value}
65
- checked={isChecked}
66
- disabled={isDisabled}
67
- onChange={handleChange}
68
- className={cn(className)}
69
- {...props}
70
- />
71
- </div>
72
- );
73
- },
74
- );
75
- RadioGroupItem.displayName = "RadioGroupItem";
@@ -1,122 +0,0 @@
1
- import { useStore } from "@nanostores/react";
2
- import { AlertCircle, Loader2 } from "lucide-react";
3
- import type React from "react";
4
- import { useEffect, useMemo, useState } from "react";
5
- import { api } from "../../../api-client";
6
- import { $config } from "../../../stores/config";
7
- import { FieldRenderer } from "../fields/index";
8
- import { Sheet, SheetContent, SheetHeader, SheetTitle } from "./sheet";
9
-
10
- interface RelationshipDetailSheetProps {
11
- isOpen: boolean;
12
- onOpenChange: (open: boolean) => void;
13
- relationTo: string;
14
- id: string | number;
15
- }
16
-
17
- export const RelationshipDetailSheet: React.FC<RelationshipDetailSheetProps> = ({
18
- isOpen,
19
- onOpenChange,
20
- relationTo,
21
- id,
22
- }) => {
23
- const [data, setData] = useState<Record<string, any> | null>(null);
24
- const [loading, setLoading] = useState(false);
25
- const [error, setError] = useState<string | null>(null);
26
- const config = useStore($config);
27
-
28
- const collection = useMemo(() => {
29
- return config?.collections.find((c) => c.slug === relationTo || c.apiPath === relationTo);
30
- }, [config, relationTo]);
31
-
32
- useEffect(() => {
33
- if (isOpen && id && relationTo) {
34
- setLoading(true);
35
- setError(null);
36
- api
37
- .get(`api/${relationTo}/${id}`)
38
- .json<Record<string, any>>()
39
- .then((res) => {
40
- setData(res);
41
- setLoading(false);
42
- })
43
- .catch((err: Error) => {
44
- console.error("Failed to fetch relation details:", err);
45
- setError("Failed to load document details.");
46
- setLoading(false);
47
- });
48
- } else {
49
- setData(null);
50
- }
51
- }, [isOpen, id, relationTo]);
52
-
53
- return (
54
- <Sheet open={isOpen} onOpenChange={onOpenChange}>
55
- <SheetContent className="p-0 sm:max-w-[500px]" onClose={() => onOpenChange(false)}>
56
- <div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
57
- <div style={{ padding: "1.5rem 1.5rem 1rem" }}>
58
- <SheetHeader>
59
- <SheetTitle>{collection?.label || relationTo} Details</SheetTitle>
60
- </SheetHeader>
61
- <div
62
- style={{ fontSize: "0.875rem", color: "var(--opaca-text-dim)", marginTop: "0.25rem" }}
63
- >
64
- ID: {id}
65
- </div>
66
- </div>
67
-
68
- <div style={{ flex: 1, overflowY: "auto", padding: "1.5rem" }}>
69
- {loading ? (
70
- <div
71
- style={{
72
- display: "flex",
73
- alignItems: "center",
74
- justifyContent: "center",
75
- padding: "3rem",
76
- gap: "0.75rem",
77
- }}
78
- >
79
- <Loader2 size={20} className="opaca-spin" />
80
- <span style={{ color: "var(--opaca-text-dim)" }}>Loading details...</span>
81
- </div>
82
- ) : error ? (
83
- <div
84
- style={{
85
- padding: "1rem",
86
- backgroundColor: "rgba(239, 68, 68, 0.1)",
87
- border: "1px solid var(--opaca-error)",
88
- color: "var(--opaca-error)",
89
- borderRadius: "var(--opaca-radius)",
90
- display: "flex",
91
- alignItems: "center",
92
- gap: "0.75rem",
93
- }}
94
- >
95
- <AlertCircle size={18} />
96
- {error}
97
- </div>
98
- ) : data && collection ? (
99
- <div style={{ display: "grid", gap: "1.5rem" }}>
100
- {collection.fields.map((field, index) => (
101
- <FieldRenderer
102
- key={field.name || index}
103
- field={field}
104
- value={field.name ? data[field.name] : undefined}
105
- onChange={() => {}} // Read-only
106
- readOnly={true}
107
- disabled={true}
108
- parentData={data}
109
- />
110
- ))}
111
- </div>
112
- ) : (
113
- <div style={{ textAlign: "center", padding: "2rem", opacity: 0.5 }}>
114
- No details found for this document.
115
- </div>
116
- )}
117
- </div>
118
- </div>
119
- </SheetContent>
120
- </Sheet>
121
- );
122
- };
@@ -1,58 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "./utils";
3
-
4
- export interface RelationshipProps extends React.HTMLAttributes<HTMLDivElement> {
5
- label?: string;
6
- relationTo: string;
7
- children?: React.ReactNode;
8
- onClick?: () => void;
9
- }
10
-
11
- export const Relationship = React.forwardRef<HTMLDivElement, RelationshipProps>(
12
- ({ className, label, relationTo, children, onClick, ...props }, ref) => {
13
- return (
14
- <div
15
- ref={ref}
16
- className={cn("opaca-ui-relationship", className)}
17
- {...props}
18
- onClick={onClick}
19
- style={{ cursor: onClick ? "pointer" : "default", ...props.style }}
20
- >
21
- {label && (
22
- <div
23
- style={{
24
- display: "block",
25
- marginBottom: "0.5rem",
26
- fontSize: "0.75rem",
27
- fontWeight: 500,
28
- color: "var(--opaca-text-muted)",
29
- textTransform: "uppercase",
30
- letterSpacing: "0.03em",
31
- }}
32
- >
33
- {label}
34
- </div>
35
- )}
36
- <div
37
- style={{
38
- display: "flex",
39
- alignItems: "center",
40
- justifyContent: "space-between",
41
- padding: "0.75rem",
42
- border: "1px solid var(--opaca-border)",
43
- borderRadius: "var(--opaca-radius)",
44
- backgroundColor: "rgba(255, 255, 255, 0.02)",
45
- transition: "all 0.2s ease",
46
- fontSize: "0.8125rem",
47
- }}
48
- className="opaca-ui-relationship-trigger"
49
- >
50
- <span>{children || `Select ${relationTo}...`}</span>
51
- <span style={{ fontSize: "0.7rem", opacity: 0.5 }}>Link: {relationTo}</span>
52
- </div>
53
- </div>
54
- );
55
- },
56
- );
57
-
58
- Relationship.displayName = "Relationship";
@@ -1,19 +0,0 @@
1
- import type * as React from "react";
2
- import { cn } from "./utils";
3
-
4
- interface ScrollAreaProps extends React.HTMLAttributes<HTMLDivElement> {
5
- children: React.ReactNode;
6
- maxHeight?: string | number;
7
- }
8
-
9
- export function ScrollArea({ children, className, maxHeight, ...props }: ScrollAreaProps) {
10
- return (
11
- <div
12
- className={cn("opaca-scroll-area", className)}
13
- style={{ maxHeight, overflowY: "auto", ...props.style }}
14
- {...props}
15
- >
16
- {children}
17
- </div>
18
- );
19
- }
@@ -1,187 +0,0 @@
1
- import { ChevronDown } from "lucide-react";
2
- import * as React from "react";
3
- import { createPortal } from "react-dom";
4
- import { cn } from "./utils";
5
- import "../../styles/select.scss";
6
-
7
- export interface SelectProps {
8
- value?: string;
9
- onValueChange?: (value: string) => void;
10
- children: React.ReactNode;
11
- placeholder?: string;
12
- disabled?: boolean;
13
- className?: string;
14
- }
15
-
16
- const SelectContext = React.createContext<{
17
- value?: string;
18
- onValueChange?: (value: string) => void;
19
- open: boolean;
20
- setOpen: (open: boolean) => void;
21
- triggerRef: React.RefObject<HTMLButtonElement | null>;
22
- } | null>(null);
23
-
24
- export function Select({
25
- value,
26
- onValueChange,
27
- children,
28
- open: controlledOpen,
29
- onOpenChange,
30
- }: SelectProps & { open?: boolean; onOpenChange?: (open: boolean) => void }) {
31
- const [internalOpen, setInternalOpen] = React.useState(false);
32
- const open = controlledOpen ?? internalOpen;
33
- const setOpen = onOpenChange ?? setInternalOpen;
34
- const triggerRef = React.useRef<HTMLButtonElement>(null);
35
-
36
- return (
37
- <SelectContext.Provider value={{ value, onValueChange, open, setOpen, triggerRef }}>
38
- <div className="opaca-ui-select">{children}</div>
39
- </SelectContext.Provider>
40
- );
41
- }
42
-
43
- export function SelectTrigger({
44
- children,
45
- className,
46
- }: {
47
- children?: React.ReactNode;
48
- className?: string;
49
- }) {
50
- const context = React.useContext(SelectContext);
51
- if (!context) throw new Error("SelectTrigger must be used within a Select");
52
-
53
- return (
54
- <button
55
- ref={context.triggerRef}
56
- type="button"
57
- className={cn("opaca-ui-select-trigger", className)}
58
- onClick={() => context.setOpen(!context.open)}
59
- data-state={context.open ? "open" : "closed"}
60
- >
61
- <span className="trigger-content">{children}</span>
62
- <ChevronDown size={14} className="trigger-icon" />
63
- </button>
64
- );
65
- }
66
-
67
- export function SelectValue({ placeholder }: { placeholder?: string }) {
68
- const context = React.useContext(SelectContext);
69
- if (!context) throw new Error("SelectValue must be used within a Select");
70
-
71
- return (
72
- <span className={!context.value ? "trigger-placeholder" : ""}>
73
- {context.value || placeholder}
74
- </span>
75
- );
76
- }
77
-
78
- export function SelectContent({
79
- children,
80
- className,
81
- }: {
82
- children: React.ReactNode;
83
- className?: string;
84
- }) {
85
- const context = React.useContext(SelectContext);
86
- if (!context) throw new Error("SelectContent must be used within a Select");
87
-
88
- const [position, setPosition] = React.useState({ top: 0, left: 0, width: 0 });
89
-
90
- const updatePosition = React.useCallback(() => {
91
- if (context.open && context.triggerRef.current) {
92
- const rect = context.triggerRef.current.getBoundingClientRect();
93
- setPosition({
94
- top: rect.bottom,
95
- left: rect.left,
96
- width: rect.width,
97
- });
98
- }
99
- }, [context.open, context.triggerRef]);
100
-
101
- React.useEffect(() => {
102
- if (context.open) {
103
- updatePosition();
104
- window.addEventListener("scroll", updatePosition, true);
105
- window.addEventListener("resize", updatePosition);
106
- return () => {
107
- window.removeEventListener("scroll", updatePosition, true);
108
- window.removeEventListener("resize", updatePosition);
109
- };
110
- }
111
- }, [context.open, updatePosition]);
112
-
113
- if (!context.open) return null;
114
-
115
- return createPortal(
116
- <div
117
- className="opaca-ui-select-portal"
118
- style={{
119
- top: position.top + 4,
120
- left: position.left,
121
- width: position.width,
122
- }}
123
- >
124
- <button
125
- type="button"
126
- className="opaca-ui-select-content-overlay"
127
- style={{
128
- position: "fixed",
129
- inset: 0,
130
- zIndex: -1,
131
- background: "transparent",
132
- border: "none",
133
- padding: 0,
134
- width: "100%",
135
- height: "100%",
136
- cursor: "default",
137
- }}
138
- onClick={() => context.setOpen(false)}
139
- tabIndex={-1}
140
- aria-hidden="true"
141
- />
142
- <div className={cn("opaca-ui-select-content", className)}>{children}</div>
143
- </div>,
144
- document.body,
145
- );
146
- }
147
-
148
- export function SelectItem({
149
- value,
150
- children,
151
- className,
152
- }: {
153
- value: string;
154
- children: React.ReactNode;
155
- className?: string;
156
- }) {
157
- const context = React.useContext(SelectContext);
158
- if (!context) throw new Error("SelectItem must be used within a Select");
159
-
160
- const isSelected = context.value === value;
161
-
162
- return (
163
- <button
164
- type="button"
165
- className={cn("opaca-ui-select-item", className)}
166
- data-selected={isSelected}
167
- onClick={() => {
168
- context.onValueChange?.(value);
169
- context.setOpen(false);
170
- }}
171
- >
172
- {children}
173
- </button>
174
- );
175
- }
176
-
177
- export function SelectGroup({ children }: { children: React.ReactNode }) {
178
- return <div className="opaca-ui-select-group">{children}</div>;
179
- }
180
-
181
- export function SelectLabel({ children }: { children: React.ReactNode }) {
182
- return <div className="opaca-ui-select-label">{children}</div>;
183
- }
184
-
185
- export function SelectSeparator() {
186
- return <div className="opaca-ui-select-separator" />;
187
- }
@@ -1,21 +0,0 @@
1
- import type React from "react";
2
-
3
- interface SeparatorProps {
4
- className?: string;
5
- orientation?: "horizontal" | "vertical";
6
- margin?: string;
7
- }
8
-
9
- export const Separator: React.FC<SeparatorProps> = ({
10
- className = "",
11
- orientation = "horizontal",
12
- margin,
13
- }) => {
14
- return (
15
- <div
16
- className={`opaca-separator ${orientation} ${className}`}
17
- style={margin ? { margin } : undefined}
18
- role="none"
19
- />
20
- );
21
- };
@@ -1,106 +0,0 @@
1
- import type * as React from "react";
2
- import { createPortal } from "react-dom";
3
- import { cn } from "./utils";
4
- import "../../styles/sheet.scss";
5
-
6
- export function Sheet({
7
- open,
8
- onOpenChange,
9
- children,
10
- }: {
11
- open: boolean;
12
- onOpenChange: (open: boolean) => void;
13
- children: React.ReactNode;
14
- }) {
15
- if (!open) return null;
16
- return createPortal(
17
- <div className="opaca-ui-sheet-portal">
18
- <button
19
- type="button"
20
- className="opaca-ui-sheet-overlay"
21
- onClick={() => onOpenChange(false)}
22
- tabIndex={-1}
23
- aria-hidden="true"
24
- />
25
- <div className="opaca-ui-sheet-wrapper">{children}</div>
26
- </div>,
27
- document.body,
28
- );
29
- }
30
-
31
- export function SheetContent({
32
- children,
33
- className,
34
- onClose,
35
- }: {
36
- children: React.ReactNode;
37
- className?: string;
38
- onClose?: () => void;
39
- }) {
40
- return (
41
- <div className={cn("opaca-ui-sheet-content", className)}>
42
- {children}
43
- {onClose && (
44
- <button type="button" onClick={onClose} className="opaca-ui-sheet-close">
45
- <svg
46
- aria-hidden="true"
47
- xmlns="http://www.w3.org/2000/svg"
48
- width="24"
49
- height="24"
50
- viewBox="0 0 24 24"
51
- fill="none"
52
- stroke="currentColor"
53
- strokeWidth="2"
54
- strokeLinecap="round"
55
- strokeLinejoin="round"
56
- className="opaca-ui-sheet-close-icon"
57
- >
58
- <line x1="18" x2="6" y1="6" y2="18"></line>
59
- <line x1="6" x2="18" y1="6" y2="18"></line>
60
- </svg>
61
- <span className="opaca-ui-sr-only">Close</span>
62
- </button>
63
- )}
64
- </div>
65
- );
66
- }
67
-
68
- export function SheetHeader({
69
- children,
70
- className,
71
- }: {
72
- children: React.ReactNode;
73
- className?: string;
74
- }) {
75
- return <div className={cn("opaca-ui-sheet-header", className)}>{children}</div>;
76
- }
77
-
78
- export function SheetTitle({
79
- children,
80
- className,
81
- }: {
82
- children: React.ReactNode;
83
- className?: string;
84
- }) {
85
- return <h2 className={cn("opaca-ui-sheet-title", className)}>{children}</h2>;
86
- }
87
-
88
- export function SheetDescription({
89
- children,
90
- className,
91
- }: {
92
- children: React.ReactNode;
93
- className?: string;
94
- }) {
95
- return <p className={cn("opaca-ui-sheet-description", className)}>{children}</p>;
96
- }
97
-
98
- export function SheetFooter({
99
- children,
100
- className,
101
- }: {
102
- children: React.ReactNode;
103
- className?: string;
104
- }) {
105
- return <div className={cn("opaca-ui-sheet-footer", className)}>{children}</div>;
106
- }
@@ -1,116 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "./utils";
3
- import "../../styles/tabs.scss";
4
-
5
- interface TabsContextValue {
6
- value?: string;
7
- onValueChange?: (value: string) => void;
8
- }
9
-
10
- const TabsContext = React.createContext<TabsContextValue>({});
11
-
12
- export interface TabsProps extends React.HTMLAttributes<HTMLDivElement> {
13
- value?: string;
14
- defaultValue?: string;
15
- onValueChange?: (value: string) => void;
16
- }
17
-
18
- export const Tabs = React.forwardRef<HTMLDivElement, TabsProps>(
19
- ({ className, value, defaultValue, onValueChange, children, ...props }, ref) => {
20
- const [uncontrolledValue, setUncontrolledValue] = React.useState<string | undefined>(
21
- defaultValue,
22
- );
23
-
24
- const isControlled = value !== undefined;
25
- const currentValue = isControlled ? value : uncontrolledValue;
26
-
27
- const handleValueChange = React.useCallback(
28
- (newValue: string) => {
29
- if (!isControlled) {
30
- setUncontrolledValue(newValue);
31
- }
32
- if (onValueChange) {
33
- onValueChange(newValue);
34
- }
35
- },
36
- [isControlled, onValueChange],
37
- );
38
-
39
- const contextValue = React.useMemo(
40
- () => ({ value: currentValue, onValueChange: handleValueChange }),
41
- [currentValue, handleValueChange],
42
- );
43
-
44
- return (
45
- <TabsContext.Provider value={contextValue}>
46
- <div ref={ref} className={cn("opaca-ui-tabs", className)} {...props}>
47
- {children}
48
- </div>
49
- </TabsContext.Provider>
50
- );
51
- },
52
- );
53
- Tabs.displayName = "Tabs";
54
-
55
- export const TabsList = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
56
- ({ className, ...props }, ref) => (
57
- <div ref={ref} className={cn("opaca-ui-tabs-list", className)} role="tablist" {...props} />
58
- ),
59
- );
60
- TabsList.displayName = "TabsList";
61
-
62
- export interface TabsTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
63
- value: string;
64
- }
65
-
66
- export const TabsTrigger = React.forwardRef<HTMLButtonElement, TabsTriggerProps>(
67
- ({ className, value, disabled, ...props }, ref) => {
68
- const context = React.useContext(TabsContext);
69
- const isSelected = context.value === value;
70
-
71
- return (
72
- <button
73
- type="button"
74
- role="tab"
75
- aria-selected={isSelected}
76
- data-state={isSelected ? "active" : "inactive"}
77
- disabled={disabled}
78
- onClick={() => {
79
- if (!disabled && context.onValueChange) {
80
- context.onValueChange(value);
81
- }
82
- }}
83
- ref={ref}
84
- className={cn("opaca-ui-tabs-trigger", className)}
85
- {...props}
86
- />
87
- );
88
- },
89
- );
90
- TabsTrigger.displayName = "TabsTrigger";
91
-
92
- export interface TabsContentProps extends React.HTMLAttributes<HTMLDivElement> {
93
- value: string;
94
- }
95
-
96
- export const TabsContent = React.forwardRef<HTMLDivElement, TabsContentProps>(
97
- ({ className, value, ...props }, ref) => {
98
- const context = React.useContext(TabsContext);
99
- const isSelected = context.value === value;
100
-
101
- if (!isSelected) {
102
- return null;
103
- }
104
-
105
- return (
106
- <div
107
- role="tabpanel"
108
- data-state={isSelected ? "active" : "inactive"}
109
- ref={ref}
110
- className={cn("opaca-ui-tabs-content", className)}
111
- {...props}
112
- />
113
- );
114
- },
115
- );
116
- TabsContent.displayName = "TabsContent";