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,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
- };
@@ -1,211 +0,0 @@
1
- import { CodeNode } from "@lexical/code";
2
- import { AutoLinkNode, LinkNode } from "@lexical/link";
3
- import { ListItemNode, ListNode } from "@lexical/list";
4
- import { MarkNode } from "@lexical/mark";
5
- import { LexicalComposer } from "@lexical/react/LexicalComposer";
6
- import { ContentEditable } from "@lexical/react/LexicalContentEditable";
7
- import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
8
- import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
9
- import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
10
- import { ListPlugin } from "@lexical/react/LexicalListPlugin";
11
- import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";
12
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
13
- import { HeadingNode, QuoteNode } from "@lexical/rich-text";
14
- import type { EditorState } from "lexical";
15
- import { useState } from "react";
16
- import { ImageNode } from "./nodes/ImageNode";
17
- import { ComponentPickerPlugin } from "./plugins/ComponentPickerPlugin";
18
- import { EditableSyncPlugin } from "./plugins/EditableSyncPlugin";
19
- import { NotionToolbarPlugin } from "./plugins/NotionToolbarPlugin";
20
- import { SimpleToolbarPlugin } from "./plugins/SimpleToolbarPlugin";
21
- import { ValueSyncPlugin } from "./plugins/ValueSyncPlugin";
22
- import "../../../styles/lexical.scss";
23
-
24
- export interface RichTextEditorProps {
25
- value: string;
26
- onChange: (value: string) => void;
27
- defaultMode?: "simple" | "notion";
28
- disabled?: boolean;
29
- readOnly?: boolean;
30
- }
31
-
32
- const theme = {
33
- ltr: "ltr",
34
- rtl: "rtl",
35
- placeholder: "editor-placeholder",
36
- paragraph: "editor-paragraph",
37
- quote: "editor-quote",
38
- heading: {
39
- h1: "editor-heading-h1",
40
- h2: "editor-heading-h2",
41
- h3: "editor-heading-h3",
42
- h4: "editor-heading-h4",
43
- h5: "editor-heading-h5",
44
- h6: "editor-heading-h6",
45
- },
46
- list: {
47
- nested: {
48
- listitem: "editor-nested-listitem",
49
- },
50
- ol: "editor-list-ol",
51
- ul: "editor-list-ul",
52
- listitem: "editor-listitem",
53
- listitemChecked: "editor-listitem-checked",
54
- listitemUnchecked: "editor-listitem-unchecked",
55
- },
56
- image: "editor-image",
57
- link: "editor-link",
58
- text: {
59
- bold: "editor-text-bold",
60
- italic: "editor-text-italic",
61
- overflowed: "editor-text-overflowed",
62
- hashtag: "editor-text-hashtag",
63
- underline: "editor-text-underline",
64
- strikethrough: "editor-text-strikethrough",
65
- underlineStrikethrough: "editor-text-underlineStrikethrough",
66
- code: "editor-text-code",
67
- },
68
- code: "editor-code",
69
- codeHighlight: {
70
- atrule: "editor-tokenAttr",
71
- attr: "editor-tokenAttr",
72
- boolean: "editor-tokenProperty",
73
- builtin: "editor-tokenSelector",
74
- cdata: "editor-tokenComment",
75
- char: "editor-tokenSelector",
76
- class: "editor-tokenFunction",
77
- "class-name": "editor-tokenFunction",
78
- comment: "editor-tokenComment",
79
- constant: "editor-tokenProperty",
80
- deleted: "editor-tokenProperty",
81
- doctype: "editor-tokenComment",
82
- entity: "editor-tokenOperator",
83
- function: "editor-tokenFunction",
84
- important: "editor-tokenVariable",
85
- inserted: "editor-tokenSelector",
86
- keyword: "editor-tokenAttr",
87
- namespace: "editor-tokenVariable",
88
- number: "editor-tokenProperty",
89
- operator: "editor-tokenOperator",
90
- prolog: "editor-tokenComment",
91
- property: "editor-tokenProperty",
92
- punctuation: "editor-tokenPunctuation",
93
- regex: "editor-tokenVariable",
94
- selector: "editor-tokenSelector",
95
- string: "editor-tokenSelector",
96
- symbol: "editor-tokenProperty",
97
- tag: "editor-tokenProperty",
98
- url: "editor-tokenOperator",
99
- variable: "editor-tokenVariable",
100
- },
101
- };
102
-
103
- function Placeholder() {
104
- return (
105
- <div className="opaca-lexical-placeholder">Press "/" for commands, or start typing...</div>
106
- );
107
- }
108
-
109
- export const normalizeEditorState = (value: unknown): string | undefined => {
110
- if (!value) return undefined;
111
-
112
- // already string
113
- if (typeof value === "string") {
114
- const trimmed = value.trim();
115
- return trimmed.startsWith("{") ? trimmed : undefined;
116
- }
117
-
118
- // object → stringify
119
- if (typeof value === "object") {
120
- try {
121
- return JSON.stringify(value);
122
- } catch {
123
- return undefined;
124
- }
125
- }
126
-
127
- return undefined;
128
- };
129
-
130
- export function RichTextEditor({
131
- value,
132
- onChange,
133
- defaultMode = "simple",
134
- disabled,
135
- readOnly,
136
- }: RichTextEditorProps) {
137
- const [mode, setMode] = useState<"simple" | "notion">(defaultMode);
138
- const isEditable = !disabled && !readOnly;
139
-
140
- const initialConfig = {
141
- namespace: "OpacaLexical",
142
- theme,
143
- editable: isEditable,
144
- nodes: [
145
- HeadingNode,
146
- ListNode,
147
- ListItemNode,
148
- QuoteNode,
149
- CodeNode,
150
- LinkNode,
151
- AutoLinkNode,
152
- MarkNode,
153
- ImageNode,
154
- ],
155
- onError: (error: Error) => {
156
- console.error(error);
157
- },
158
- editorState: normalizeEditorState(value),
159
- };
160
-
161
- const handleOnChange = (editorState: EditorState) => {
162
- // Only call onChange if we have actually serialized new content, otherwise we'll create infinite loops
163
- // In Lexical, we generally stringify the JSON
164
- const jsonString = JSON.stringify(editorState.toJSON());
165
- onChange(jsonString);
166
- };
167
-
168
- return (
169
- <div className="opaca-lexical-wrapper">
170
- {isEditable && (
171
- <div className="opaca-lexical-modes">
172
- <button
173
- type="button"
174
- className={`opaca-btn ${mode === "simple" ? "opaca-btn-primary" : "opaca-btn-outline"}`}
175
- onClick={() => setMode("simple")}
176
- >
177
- Simple
178
- </button>
179
- <button
180
- type="button"
181
- className={`opaca-btn ${mode === "notion" ? "opaca-btn-primary" : "opaca-btn-outline"}`}
182
- onClick={() => setMode("notion")}
183
- >
184
- Notion-like
185
- </button>
186
- </div>
187
- )}
188
-
189
- <div className={`opaca-lexical-container mode-${mode} ${!isEditable ? "is-readonly" : ""}`}>
190
- <LexicalComposer initialConfig={initialConfig}>
191
- {mode === "simple" && isEditable && <SimpleToolbarPlugin />}
192
- {mode === "notion" && isEditable && <NotionToolbarPlugin />}
193
- <div className="opaca-lexical-editor-inner">
194
- <RichTextPlugin
195
- contentEditable={<ContentEditable className="opaca-lexical-content" />}
196
- placeholder={<Placeholder />}
197
- ErrorBoundary={LexicalErrorBoundary as any}
198
- />
199
- <OnChangePlugin onChange={handleOnChange} ignoreSelectionChange />
200
- <ValueSyncPlugin value={value} />
201
- <EditableSyncPlugin isEditable={isEditable} />
202
- <HistoryPlugin />
203
- <ListPlugin />
204
- <LinkPlugin />
205
- <ComponentPickerPlugin />
206
- </div>
207
- </LexicalComposer>
208
- </div>
209
- </div>
210
- );
211
- }