opacacms 0.1.12 → 0.1.13
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/dist/admin/index.js +0 -4
- package/dist/admin/webcomponent.d.ts +0 -1
- package/dist/admin/webcomponent.js +0 -4
- package/dist/admin.css +1 -0
- package/package.json +8 -2
- package/bun.lock +0 -34
- package/dist/admin/index.css +0 -47
- package/dist/admin/webcomponent.css +0 -47
- package/global.d.ts +0 -11
- package/src/admin/api-client.ts +0 -63
- package/src/admin/auth-client.ts +0 -40
- package/src/admin/custom-field.ts +0 -179
- package/src/admin/index.ts +0 -15
- package/src/admin/react.tsx +0 -72
- package/src/admin/router.ts +0 -9
- package/src/admin/stores/admin-queries.ts +0 -121
- package/src/admin/stores/auth.ts +0 -61
- package/src/admin/stores/column-visibility.ts +0 -67
- package/src/admin/stores/config.ts +0 -15
- package/src/admin/stores/media.ts +0 -95
- package/src/admin/stores/query.ts +0 -13
- package/src/admin/stores/ui.ts +0 -29
- package/src/admin/ui/admin-client.tsx +0 -283
- package/src/admin/ui/admin-layout.tsx +0 -276
- package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
- package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
- package/src/admin/ui/components/DataDetailView.tsx +0 -175
- package/src/admin/ui/components/Table.tsx +0 -67
- package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
- package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
- package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
- package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
- package/src/admin/ui/components/fields/DateField.tsx +0 -45
- package/src/admin/ui/components/fields/FileField.tsx +0 -322
- package/src/admin/ui/components/fields/GroupField.tsx +0 -50
- package/src/admin/ui/components/fields/JoinField.tsx +0 -23
- package/src/admin/ui/components/fields/NumberField.tsx +0 -46
- package/src/admin/ui/components/fields/RadioField.tsx +0 -62
- package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
- package/src/admin/ui/components/fields/RowField.tsx +0 -40
- package/src/admin/ui/components/fields/SelectField.tsx +0 -59
- package/src/admin/ui/components/fields/TabsField.tsx +0 -101
- package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
- package/src/admin/ui/components/fields/TextField.tsx +0 -49
- package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
- package/src/admin/ui/components/fields/index.tsx +0 -371
- package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
- package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
- package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
- package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
- package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
- package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
- package/src/admin/ui/components/fields/utils.ts +0 -1
- package/src/admin/ui/components/link.tsx +0 -41
- package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
- package/src/admin/ui/components/toast.tsx +0 -72
- package/src/admin/ui/components/ui/accordion.tsx +0 -51
- package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
- package/src/admin/ui/components/ui/blocks.tsx +0 -32
- package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
- package/src/admin/ui/components/ui/button.tsx +0 -26
- package/src/admin/ui/components/ui/collapsible.tsx +0 -124
- package/src/admin/ui/components/ui/dialog.tsx +0 -79
- package/src/admin/ui/components/ui/group.tsx +0 -20
- package/src/admin/ui/components/ui/index.ts +0 -17
- package/src/admin/ui/components/ui/input.tsx +0 -12
- package/src/admin/ui/components/ui/join.tsx +0 -53
- package/src/admin/ui/components/ui/label.tsx +0 -11
- package/src/admin/ui/components/ui/radio-group.tsx +0 -75
- package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
- package/src/admin/ui/components/ui/relationship.tsx +0 -58
- package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
- package/src/admin/ui/components/ui/select.tsx +0 -187
- package/src/admin/ui/components/ui/separator.tsx +0 -21
- package/src/admin/ui/components/ui/sheet.tsx +0 -106
- package/src/admin/ui/components/ui/tabs.tsx +0 -116
- package/src/admin/ui/components/ui/utils.ts +0 -3
- package/src/admin/ui/hooks/use-debounce.ts +0 -15
- package/src/admin/ui/styles/_locale-switcher.scss +0 -33
- package/src/admin/ui/styles/accordion.scss +0 -60
- package/src/admin/ui/styles/animations.scss +0 -41
- package/src/admin/ui/styles/asset-manager.scss +0 -547
- package/src/admin/ui/styles/badge.scss +0 -13
- package/src/admin/ui/styles/base.scss +0 -22
- package/src/admin/ui/styles/button.scss +0 -161
- package/src/admin/ui/styles/card.scss +0 -13
- package/src/admin/ui/styles/collapsible.scss +0 -75
- package/src/admin/ui/styles/data-detail.scss +0 -92
- package/src/admin/ui/styles/dialog.scss +0 -102
- package/src/admin/ui/styles/empty-state.scss +0 -22
- package/src/admin/ui/styles/group.scss +0 -19
- package/src/admin/ui/styles/index.scss +0 -33
- package/src/admin/ui/styles/input.scss +0 -80
- package/src/admin/ui/styles/label.scss +0 -12
- package/src/admin/ui/styles/layout.scss +0 -56
- package/src/admin/ui/styles/lexical.scss +0 -469
- package/src/admin/ui/styles/loading.scss +0 -102
- package/src/admin/ui/styles/media-registry.scss +0 -597
- package/src/admin/ui/styles/pagination.scss +0 -20
- package/src/admin/ui/styles/radio-group.scss +0 -66
- package/src/admin/ui/styles/row.scss +0 -17
- package/src/admin/ui/styles/scrollbar.scss +0 -36
- package/src/admin/ui/styles/select.scss +0 -121
- package/src/admin/ui/styles/separator.scss +0 -14
- package/src/admin/ui/styles/sheet.scss +0 -152
- package/src/admin/ui/styles/sidebar.scss +0 -148
- package/src/admin/ui/styles/switch.scss +0 -59
- package/src/admin/ui/styles/table.scss +0 -207
- package/src/admin/ui/styles/tabs.scss +0 -62
- package/src/admin/ui/styles/toast.scss +0 -45
- package/src/admin/ui/styles/variables.scss +0 -24
- package/src/admin/ui/views/collection-list-view.tsx +0 -720
- package/src/admin/ui/views/dashboard-view.tsx +0 -263
- package/src/admin/ui/views/document-edit-view.tsx +0 -384
- package/src/admin/ui/views/global-edit-view.tsx +0 -226
- package/src/admin/ui/views/init-view.tsx +0 -182
- package/src/admin/ui/views/login-view.tsx +0 -123
- package/src/admin/ui/views/media-registry-view.tsx +0 -1104
- package/src/admin/ui/views/settings-view.tsx +0 -729
- package/src/admin/webcomponent.tsx +0 -15
- package/src/auth/index.ts +0 -194
- package/src/auth/migrations.ts +0 -87
- package/src/auth/premissions.ts +0 -46
- package/src/cli/commands/generate-types.ts +0 -116
- package/src/cli/commands/init.ts +0 -95
- package/src/cli/commands/migrate-commands.ts +0 -160
- package/src/cli/commands/seed-command.ts +0 -11
- package/src/cli/d1-mock.ts +0 -101
- package/src/cli/index.test.ts +0 -84
- package/src/cli/index.ts +0 -183
- package/src/cli/r2-mock.ts +0 -217
- package/src/cli/seeding.ts +0 -409
- package/src/client.ts +0 -181
- package/src/config-utils.ts +0 -102
- package/src/config.ts +0 -49
- package/src/db/adapter.ts +0 -53
- package/src/db/better-sqlite.ts +0 -657
- package/src/db/bun-sqlite.ts +0 -666
- package/src/db/d1.ts +0 -721
- package/src/db/index.ts +0 -10
- package/src/db/kysely/data-mapper.ts +0 -142
- package/src/db/kysely/field-mapper.ts +0 -149
- package/src/db/kysely/migration-generator.ts +0 -223
- package/src/db/kysely/query-builder.ts +0 -92
- package/src/db/kysely/schema-builder.ts +0 -439
- package/src/db/kysely/sql-utils.ts +0 -13
- package/src/db/postgres.ts +0 -631
- package/src/db/sqlite.ts +0 -670
- package/src/db/system-schema.ts +0 -121
- package/src/index.ts +0 -13
- package/src/runtimes/README.md +0 -59
- package/src/runtimes/bun.ts +0 -49
- package/src/runtimes/cloudflare-workers.ts +0 -38
- package/src/runtimes/next.ts +0 -26
- package/src/runtimes/node.ts +0 -52
- package/src/schema/collection.ts +0 -184
- package/src/schema/fields/base.ts +0 -164
- package/src/schema/fields/index.ts +0 -427
- package/src/schema/global.ts +0 -145
- package/src/schema/index.ts +0 -4
- package/src/schema/infer.ts +0 -72
- package/src/server/admin-router.ts +0 -20
- package/src/server/admin.ts +0 -142
- package/src/server/assets.ts +0 -306
- package/src/server/collection-router.ts +0 -55
- package/src/server/handlers.ts +0 -722
- package/src/server/middlewares/admin.ts +0 -27
- package/src/server/middlewares/auth.ts +0 -89
- package/src/server/middlewares/context.ts +0 -17
- package/src/server/middlewares/cors.ts +0 -24
- package/src/server/middlewares/database-init.ts +0 -74
- package/src/server/middlewares/rate-limit.ts +0 -77
- package/src/server/router.ts +0 -47
- package/src/server/setup-middlewares.ts +0 -58
- package/src/server/system-router.ts +0 -35
- package/src/server.ts +0 -9
- package/src/storage/adapters/cloudflare-r2.ts +0 -136
- package/src/storage/adapters/local.ts +0 -146
- package/src/storage/adapters/s3.ts +0 -186
- package/src/storage/errors.ts +0 -46
- package/src/storage/index.ts +0 -5
- package/src/storage/types.ts +0 -39
- package/src/types.ts +0 -577
- package/src/utils/lexical.ts +0 -37
- package/src/utils/logger.ts +0 -73
- package/src/validation.ts +0 -429
- package/src/validator.ts +0 -179
- package/test/admin-custom-field.test.ts +0 -162
- package/test/admin-react-field.test.tsx +0 -134
- package/test/api-features.test.ts +0 -78
- package/test/api.test.ts +0 -178
- package/test/auth.test.ts +0 -62
- package/test/cli-integration.test.ts +0 -148
- package/test/cli.test.ts +0 -25
- package/test/db/postgres.test.ts +0 -95
- package/test/db/sqlite-filter.test.ts +0 -53
- package/test/db/sqlite.test.ts +0 -82
- package/test/engine-features.test.ts +0 -79
- package/test/globals.test.ts +0 -74
- package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
- package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
- package/test/integration-tmp/my-test-app/index.ts +0 -8
- package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
- package/test/integration-tmp/my-test-app/package.json +0 -12
- package/test/populate.test.ts +0 -79
- package/test/runtimes.test.ts +0 -43
- package/test/schema-builder.test.ts +0 -107
- package/test/schema-features.test.ts +0 -63
- package/test/seeding.test.ts +0 -68
- package/test/storage/local.test.ts +0 -72
- package/test/storage/s3.test.ts +0 -60
- package/test/structural-data.test.ts +0 -100
- package/test/test-setup.ts +0 -11
- package/test/validation.test.ts +0 -162
- package/tsconfig.json +0 -42
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type React from "react";
|
|
2
|
-
|
|
3
|
-
interface TextAreaFieldProps {
|
|
4
|
-
name: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
value: string | null;
|
|
7
|
-
onChange: (val: string | null) => void;
|
|
8
|
-
required?: boolean;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
readOnly?: boolean;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
error?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const TextAreaField: React.FC<TextAreaFieldProps> = ({
|
|
16
|
-
name,
|
|
17
|
-
label,
|
|
18
|
-
value,
|
|
19
|
-
onChange,
|
|
20
|
-
required,
|
|
21
|
-
disabled,
|
|
22
|
-
readOnly,
|
|
23
|
-
placeholder,
|
|
24
|
-
error,
|
|
25
|
-
}) => {
|
|
26
|
-
return (
|
|
27
|
-
<div className="opaca-form-group">
|
|
28
|
-
<label className="opaca-label" htmlFor={`field-${name}`}>
|
|
29
|
-
{label || name}
|
|
30
|
-
{required && <span style={{ color: "var(--opaca-error)", marginLeft: "4px" }}>*</span>}
|
|
31
|
-
</label>
|
|
32
|
-
<textarea
|
|
33
|
-
id={`field-${name}`}
|
|
34
|
-
className={`opaca-input ${error ? "error" : ""}`}
|
|
35
|
-
style={{
|
|
36
|
-
minHeight: "160px",
|
|
37
|
-
resize: "vertical",
|
|
38
|
-
padding: "1rem",
|
|
39
|
-
lineHeight: "1.5",
|
|
40
|
-
}}
|
|
41
|
-
value={value || ""}
|
|
42
|
-
readOnly={readOnly}
|
|
43
|
-
disabled={disabled}
|
|
44
|
-
onChange={(e) => {
|
|
45
|
-
const val = e.target.value;
|
|
46
|
-
onChange(val === "" && !required ? null : val);
|
|
47
|
-
}}
|
|
48
|
-
placeholder={placeholder || `Enter ${label || name}...`}
|
|
49
|
-
required={required}
|
|
50
|
-
/>
|
|
51
|
-
{error && <span className="opaca-field-error">{error}</span>}
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type React from "react";
|
|
2
|
-
|
|
3
|
-
interface TextFieldProps {
|
|
4
|
-
name: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
value: string | null;
|
|
7
|
-
onChange: (val: string | null) => void;
|
|
8
|
-
required?: boolean;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
readOnly?: boolean;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
error?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const TextField: React.FC<TextFieldProps> = ({
|
|
16
|
-
name,
|
|
17
|
-
label,
|
|
18
|
-
value,
|
|
19
|
-
onChange,
|
|
20
|
-
required,
|
|
21
|
-
disabled,
|
|
22
|
-
readOnly,
|
|
23
|
-
placeholder,
|
|
24
|
-
error,
|
|
25
|
-
}) => {
|
|
26
|
-
return (
|
|
27
|
-
<div className="opaca-form-group">
|
|
28
|
-
<label className="opaca-label" htmlFor={`field-${name}`}>
|
|
29
|
-
{label || name}
|
|
30
|
-
{required && <span style={{ color: "var(--opaca-error)", marginLeft: "4px" }}>*</span>}
|
|
31
|
-
</label>
|
|
32
|
-
<input
|
|
33
|
-
id={`field-${name}`}
|
|
34
|
-
type="text"
|
|
35
|
-
className={`opaca-input ${error ? "error" : ""}`}
|
|
36
|
-
value={value || ""}
|
|
37
|
-
readOnly={readOnly}
|
|
38
|
-
disabled={disabled}
|
|
39
|
-
onChange={(e) => {
|
|
40
|
-
const val = e.target.value;
|
|
41
|
-
onChange(val === "" && !required ? null : val);
|
|
42
|
-
}}
|
|
43
|
-
placeholder={placeholder || `Enter ${label || name}...`}
|
|
44
|
-
required={required}
|
|
45
|
-
/>
|
|
46
|
-
{error && <span className="opaca-field-error">{error}</span>}
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type React from "react";
|
|
2
|
-
|
|
3
|
-
interface VirtualFieldProps {
|
|
4
|
-
name: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
value: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const VirtualField: React.FC<VirtualFieldProps> = ({ name, label, value }) => {
|
|
10
|
-
const displayValue =
|
|
11
|
-
value === null || value === undefined
|
|
12
|
-
? ""
|
|
13
|
-
: typeof value === "object"
|
|
14
|
-
? JSON.stringify(value)
|
|
15
|
-
: String(value);
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<div className="opaca-form-group">
|
|
19
|
-
<label className="opaca-label" htmlFor={`field-${name}`}>
|
|
20
|
-
{label || name}
|
|
21
|
-
<span
|
|
22
|
-
style={{
|
|
23
|
-
color: "rgba(255, 255, 255, 0.4)",
|
|
24
|
-
marginLeft: "8px",
|
|
25
|
-
fontSize: "11px",
|
|
26
|
-
fontWeight: "normal",
|
|
27
|
-
textTransform: "uppercase",
|
|
28
|
-
letterSpacing: "0.5px",
|
|
29
|
-
}}
|
|
30
|
-
>
|
|
31
|
-
(Computed)
|
|
32
|
-
</span>
|
|
33
|
-
</label>
|
|
34
|
-
<div
|
|
35
|
-
className="opaca-input read-only virtual"
|
|
36
|
-
style={{
|
|
37
|
-
backgroundColor: "rgba(255, 255, 255, 0.03)",
|
|
38
|
-
minHeight: "42px",
|
|
39
|
-
display: "flex",
|
|
40
|
-
alignItems: "center",
|
|
41
|
-
padding: "0 12px",
|
|
42
|
-
borderRadius: "8px",
|
|
43
|
-
border: "1px solid rgba(255, 255, 255, 0.05)",
|
|
44
|
-
color: "rgba(255, 255, 255, 0.7)",
|
|
45
|
-
fontSize: "14px",
|
|
46
|
-
fontFamily: "monospace",
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
49
|
-
{displayValue}
|
|
50
|
-
</div>
|
|
51
|
-
</div>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from "react";
|
|
2
|
-
import { ArrayField } from "./ArrayField";
|
|
3
|
-
import { BlocksField } from "./BlocksField";
|
|
4
|
-
import { BooleanField } from "./BooleanField";
|
|
5
|
-
import { CollapsibleField } from "./CollapsibleField";
|
|
6
|
-
import { DateField } from "./DateField";
|
|
7
|
-
import { FileField } from "./FileField";
|
|
8
|
-
import { GroupField } from "./GroupField";
|
|
9
|
-
import { JoinField } from "./JoinField";
|
|
10
|
-
import { NumberField } from "./NumberField";
|
|
11
|
-
import { RadioField } from "./RadioField";
|
|
12
|
-
import { RelationshipField } from "./RelationshipField";
|
|
13
|
-
import { RowField } from "./RowField";
|
|
14
|
-
import { RichTextEditor } from "./richtext-editor";
|
|
15
|
-
import { SelectField } from "./SelectField";
|
|
16
|
-
import { TabsField } from "./TabsField";
|
|
17
|
-
import { TextAreaField } from "./TextAreaField";
|
|
18
|
-
import { TextField } from "./TextField";
|
|
19
|
-
import { capitalize } from "./utils";
|
|
20
|
-
import { VirtualField } from "./VirtualField";
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
ArrayField,
|
|
24
|
-
BlocksField,
|
|
25
|
-
BooleanField,
|
|
26
|
-
CollapsibleField,
|
|
27
|
-
DateField,
|
|
28
|
-
FileField,
|
|
29
|
-
GroupField,
|
|
30
|
-
JoinField,
|
|
31
|
-
NumberField,
|
|
32
|
-
RadioField,
|
|
33
|
-
RelationshipField,
|
|
34
|
-
SelectField,
|
|
35
|
-
TabsField,
|
|
36
|
-
TextAreaField,
|
|
37
|
-
TextField,
|
|
38
|
-
VirtualField,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
interface FieldRendererProps {
|
|
42
|
-
field: any; // Collection Field definition
|
|
43
|
-
value: any;
|
|
44
|
-
onChange: (val: any, secondaryVal?: any) => void;
|
|
45
|
-
disabled?: boolean;
|
|
46
|
-
readOnly?: boolean;
|
|
47
|
-
error?: string;
|
|
48
|
-
parentData?: any;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const CustomFieldWrapper: React.FC<{
|
|
52
|
-
tagName: string;
|
|
53
|
-
field: any;
|
|
54
|
-
value: any;
|
|
55
|
-
onChange: (val: any) => void;
|
|
56
|
-
isDisabled: boolean;
|
|
57
|
-
isReadOnly: boolean;
|
|
58
|
-
error?: string;
|
|
59
|
-
parentData?: any;
|
|
60
|
-
}> = ({ tagName, field, value, onChange, isDisabled, isReadOnly, error, parentData }) => {
|
|
61
|
-
const ref = useRef<HTMLElement>(null);
|
|
62
|
-
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
const el = ref.current;
|
|
65
|
-
if (el) {
|
|
66
|
-
// Pass complex data via object properties to the Web Component
|
|
67
|
-
(el as any).value = value;
|
|
68
|
-
(el as any).fieldConfig = field;
|
|
69
|
-
(el as any).error = error;
|
|
70
|
-
(el as any).parentData = parentData;
|
|
71
|
-
|
|
72
|
-
const handleCustomChange = (e: Event) => {
|
|
73
|
-
const detail = (e as CustomEvent).detail;
|
|
74
|
-
if (detail && "value" in detail) {
|
|
75
|
-
onChange(detail.value);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
el.addEventListener("opacachange", handleCustomChange);
|
|
80
|
-
return () => {
|
|
81
|
-
el.removeEventListener("opacachange", handleCustomChange);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}, [value, field, onChange, error, parentData]);
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<div className="opaca-form-group">
|
|
88
|
-
<label htmlFor={field.name} className="opaca-label">
|
|
89
|
-
{field.label || (field.name ? capitalize(field.name) : undefined)}
|
|
90
|
-
{field.required && (
|
|
91
|
-
<span style={{ color: "var(--opaca-error)", marginLeft: "4px" }}>*</span>
|
|
92
|
-
)}
|
|
93
|
-
</label>
|
|
94
|
-
{React.createElement(tagName, {
|
|
95
|
-
ref,
|
|
96
|
-
id: field.name,
|
|
97
|
-
"data-name": field.name,
|
|
98
|
-
"data-disabled": isDisabled ? "true" : undefined,
|
|
99
|
-
"data-readonly": isReadOnly ? "true" : undefined,
|
|
100
|
-
className: "opaca-custom-field",
|
|
101
|
-
})}
|
|
102
|
-
{error && <span className="opaca-field-error">{error}</span>}
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const FieldRenderer: React.FC<FieldRendererProps> = ({
|
|
108
|
-
field,
|
|
109
|
-
value,
|
|
110
|
-
onChange,
|
|
111
|
-
disabled,
|
|
112
|
-
readOnly,
|
|
113
|
-
error,
|
|
114
|
-
parentData,
|
|
115
|
-
}) => {
|
|
116
|
-
const fieldAccess = field.name ? parentData?._access?.[field.name] || {} : {};
|
|
117
|
-
|
|
118
|
-
const isReadOnly =
|
|
119
|
-
readOnly ||
|
|
120
|
-
fieldAccess.readOnly ||
|
|
121
|
-
(typeof field.access?.readOnly === "boolean" ? field.access.readOnly : false);
|
|
122
|
-
|
|
123
|
-
const isDisabled =
|
|
124
|
-
disabled ||
|
|
125
|
-
fieldAccess.disabled ||
|
|
126
|
-
(typeof field.access?.disabled === "boolean" ? field.access.disabled : false) ||
|
|
127
|
-
isReadOnly;
|
|
128
|
-
|
|
129
|
-
const isHidden =
|
|
130
|
-
field.type === "slug" ||
|
|
131
|
-
fieldAccess.hidden ||
|
|
132
|
-
(typeof field.access?.hidden === "boolean" ? field.access.hidden : false);
|
|
133
|
-
|
|
134
|
-
if (isHidden) return null;
|
|
135
|
-
|
|
136
|
-
const commonProps = {
|
|
137
|
-
name: field.name,
|
|
138
|
-
label: field.label || (field.name ? capitalize(field.name) : undefined),
|
|
139
|
-
value,
|
|
140
|
-
onChange,
|
|
141
|
-
required: field.required,
|
|
142
|
-
disabled: isDisabled,
|
|
143
|
-
readOnly: isReadOnly,
|
|
144
|
-
error,
|
|
145
|
-
placeholder: field.placeholder,
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// 0. Handle Custom Field Components
|
|
149
|
-
// Since we are in a web/workers environment, the custom component
|
|
150
|
-
// needs to be resolved or looked up. For now, we assume it's a string identifier
|
|
151
|
-
// or that the user has provided a way to register them.
|
|
152
|
-
// In a real framework, this might use a Context or a registry.
|
|
153
|
-
// We'll add a placeholder or a simple dynamic lookup if possible.
|
|
154
|
-
if (field.admin?.components?.Field && typeof field.admin.components.Field === "string") {
|
|
155
|
-
return (
|
|
156
|
-
<CustomFieldWrapper
|
|
157
|
-
tagName={field.admin.components.Field}
|
|
158
|
-
field={field}
|
|
159
|
-
value={value}
|
|
160
|
-
onChange={onChange}
|
|
161
|
-
isDisabled={isDisabled}
|
|
162
|
-
isReadOnly={isReadOnly}
|
|
163
|
-
error={error}
|
|
164
|
-
parentData={parentData}
|
|
165
|
-
/>
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
switch (field.type) {
|
|
170
|
-
case "text":
|
|
171
|
-
return <TextField {...commonProps} />;
|
|
172
|
-
case "virtual":
|
|
173
|
-
return <VirtualField name={commonProps.name} label={commonProps.label} value={value} />;
|
|
174
|
-
case "textarea":
|
|
175
|
-
return <TextAreaField {...commonProps} />;
|
|
176
|
-
case "number":
|
|
177
|
-
return <NumberField {...commonProps} />;
|
|
178
|
-
case "date":
|
|
179
|
-
return <DateField {...commonProps} />;
|
|
180
|
-
case "boolean":
|
|
181
|
-
return <BooleanField {...commonProps} />;
|
|
182
|
-
case "select":
|
|
183
|
-
return (
|
|
184
|
-
<SelectField {...commonProps} choices={field.choices || field.options?.choices || []} />
|
|
185
|
-
);
|
|
186
|
-
case "file":
|
|
187
|
-
return <FileField {...commonProps} options={field.options} bucket={field.bucket} />;
|
|
188
|
-
case "radio":
|
|
189
|
-
return (
|
|
190
|
-
<RadioField {...commonProps} choices={field.choices || field.options?.choices || []} />
|
|
191
|
-
);
|
|
192
|
-
case "row":
|
|
193
|
-
return (
|
|
194
|
-
<RowField
|
|
195
|
-
fields={field.fields || []}
|
|
196
|
-
parentData={parentData}
|
|
197
|
-
disabled={isDisabled}
|
|
198
|
-
readOnly={isReadOnly}
|
|
199
|
-
onChange={(name, val) => {
|
|
200
|
-
// Merge nested updates into parentData for layout fields
|
|
201
|
-
if (parentData && typeof parentData === "object" && !Array.isArray(parentData)) {
|
|
202
|
-
onChange({ ...parentData, [name]: val });
|
|
203
|
-
} else {
|
|
204
|
-
onChange(val);
|
|
205
|
-
}
|
|
206
|
-
}}
|
|
207
|
-
renderField={(f, v, subOnChange) => (
|
|
208
|
-
<FieldRenderer
|
|
209
|
-
field={f}
|
|
210
|
-
value={f.name && v === undefined ? parentData?.[f.name] : v}
|
|
211
|
-
onChange={subOnChange}
|
|
212
|
-
disabled={isDisabled}
|
|
213
|
-
readOnly={isReadOnly}
|
|
214
|
-
parentData={parentData}
|
|
215
|
-
/>
|
|
216
|
-
)}
|
|
217
|
-
/>
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
case "group":
|
|
221
|
-
return (
|
|
222
|
-
<GroupField
|
|
223
|
-
{...commonProps}
|
|
224
|
-
fields={field.fields || []}
|
|
225
|
-
renderField={(f, v, subOnChange) => (
|
|
226
|
-
<FieldRenderer
|
|
227
|
-
field={f}
|
|
228
|
-
value={f.name && v === undefined ? parentData?.[f.name] : v}
|
|
229
|
-
onChange={subOnChange}
|
|
230
|
-
disabled={isDisabled}
|
|
231
|
-
readOnly={isReadOnly}
|
|
232
|
-
parentData={value} // Pass group data as parentData
|
|
233
|
-
/>
|
|
234
|
-
)}
|
|
235
|
-
/>
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
case "tabs":
|
|
239
|
-
return (
|
|
240
|
-
<TabsField
|
|
241
|
-
{...commonProps}
|
|
242
|
-
tabs={field.tabs || []}
|
|
243
|
-
parentData={parentData}
|
|
244
|
-
onChange={(name, val) => {
|
|
245
|
-
// Merge nested updates into parentData for layout fields
|
|
246
|
-
if (parentData && typeof parentData === "object" && !Array.isArray(parentData)) {
|
|
247
|
-
onChange({ ...parentData, [name]: val });
|
|
248
|
-
} else {
|
|
249
|
-
onChange(val);
|
|
250
|
-
}
|
|
251
|
-
}}
|
|
252
|
-
renderField={(f, v, subOnChange) => (
|
|
253
|
-
<FieldRenderer
|
|
254
|
-
field={f}
|
|
255
|
-
value={f.name && value === undefined ? parentData?.[f.name] : v}
|
|
256
|
-
onChange={subOnChange}
|
|
257
|
-
disabled={isDisabled}
|
|
258
|
-
readOnly={isReadOnly}
|
|
259
|
-
parentData={parentData}
|
|
260
|
-
/>
|
|
261
|
-
)}
|
|
262
|
-
/>
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
case "collapsible":
|
|
266
|
-
return (
|
|
267
|
-
<CollapsibleField
|
|
268
|
-
{...commonProps}
|
|
269
|
-
fields={field.fields || []}
|
|
270
|
-
parentData={parentData}
|
|
271
|
-
options={field.options}
|
|
272
|
-
onChange={(name, val) => {
|
|
273
|
-
// Merge nested updates into parentData for layout fields
|
|
274
|
-
if (parentData && typeof parentData === "object" && !Array.isArray(parentData)) {
|
|
275
|
-
onChange({ ...parentData, [name]: val });
|
|
276
|
-
} else {
|
|
277
|
-
onChange(val);
|
|
278
|
-
}
|
|
279
|
-
}}
|
|
280
|
-
renderField={(f, v, subOnChange) => (
|
|
281
|
-
<FieldRenderer
|
|
282
|
-
field={f}
|
|
283
|
-
value={v}
|
|
284
|
-
onChange={subOnChange}
|
|
285
|
-
disabled={isDisabled}
|
|
286
|
-
readOnly={isReadOnly}
|
|
287
|
-
parentData={parentData}
|
|
288
|
-
/>
|
|
289
|
-
)}
|
|
290
|
-
/>
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
case "blocks":
|
|
294
|
-
return (
|
|
295
|
-
<BlocksField
|
|
296
|
-
{...commonProps}
|
|
297
|
-
blocks={field.blocks || field.options?.blocks || []}
|
|
298
|
-
renderField={(f, v, subOnChange) => (
|
|
299
|
-
<FieldRenderer
|
|
300
|
-
field={f}
|
|
301
|
-
value={v}
|
|
302
|
-
onChange={subOnChange}
|
|
303
|
-
disabled={isDisabled}
|
|
304
|
-
readOnly={isReadOnly}
|
|
305
|
-
parentData={v} // In blocks, the item itself is the parent data
|
|
306
|
-
/>
|
|
307
|
-
)}
|
|
308
|
-
/>
|
|
309
|
-
);
|
|
310
|
-
case "relationship":
|
|
311
|
-
return (
|
|
312
|
-
<RelationshipField
|
|
313
|
-
{...commonProps}
|
|
314
|
-
relationTo={field.relationTo || field.options?.relationTo}
|
|
315
|
-
displayField={field.displayField || field.options?.displayField}
|
|
316
|
-
hasMany={field.hasMany}
|
|
317
|
-
/>
|
|
318
|
-
);
|
|
319
|
-
case "join":
|
|
320
|
-
return (
|
|
321
|
-
<JoinField {...commonProps} collection={field.collection || field.options?.collection} />
|
|
322
|
-
);
|
|
323
|
-
case "array":
|
|
324
|
-
return (
|
|
325
|
-
<ArrayField
|
|
326
|
-
{...commonProps}
|
|
327
|
-
fields={field.fields || []}
|
|
328
|
-
renderField={(f, v, subOnChange) => (
|
|
329
|
-
<FieldRenderer
|
|
330
|
-
field={f}
|
|
331
|
-
value={v}
|
|
332
|
-
onChange={subOnChange}
|
|
333
|
-
disabled={isDisabled}
|
|
334
|
-
readOnly={isReadOnly}
|
|
335
|
-
parentData={v}
|
|
336
|
-
/>
|
|
337
|
-
)}
|
|
338
|
-
/>
|
|
339
|
-
);
|
|
340
|
-
case "richtext":
|
|
341
|
-
return (
|
|
342
|
-
<div className="opaca-form-group">
|
|
343
|
-
<label htmlFor={field.name} className="opaca-label">
|
|
344
|
-
{field.label || (field.name ? capitalize(field.name) : undefined)}
|
|
345
|
-
{field.required && (
|
|
346
|
-
<span style={{ color: "var(--opaca-error)", marginLeft: "4px" }}>*</span>
|
|
347
|
-
)}
|
|
348
|
-
</label>
|
|
349
|
-
<RichTextEditor
|
|
350
|
-
value={value || ""}
|
|
351
|
-
onChange={onChange}
|
|
352
|
-
disabled={isDisabled} // Use isDisabled
|
|
353
|
-
readOnly={isReadOnly} // Use isReadOnly
|
|
354
|
-
defaultMode={field.options?.defaultMode}
|
|
355
|
-
/>
|
|
356
|
-
{error && <span className="opaca-field-error">{error}</span>}
|
|
357
|
-
</div>
|
|
358
|
-
);
|
|
359
|
-
default:
|
|
360
|
-
console.warn("FieldRenderer: fallback to default for type:", field.type, field);
|
|
361
|
-
return (
|
|
362
|
-
<div className="opaca-form-group">
|
|
363
|
-
<label htmlFor={field.name} className="opaca-label">
|
|
364
|
-
{field.label || (field.name ? capitalize(field.name) : undefined)} (Unknown Type:{" "}
|
|
365
|
-
{field.type}) {/* Fixed label using capitalize */}
|
|
366
|
-
</label>
|
|
367
|
-
<input type="text" className="opaca-input" value={value || ""} readOnly disabled />
|
|
368
|
-
</div>
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
};
|