@firecms/core 3.2.0-canary.9c3d298 → 3.3.0-canary.451aa49

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 (67) hide show
  1. package/dist/components/VirtualTable/VirtualTableHeader.d.ts +1 -0
  2. package/dist/components/VirtualTable/VirtualTableHeaderRow.d.ts +1 -1
  3. package/dist/components/VirtualTable/VirtualTableProps.d.ts +6 -1
  4. package/dist/components/VirtualTable/types.d.ts +1 -0
  5. package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
  6. package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.es.js +20186 -19539
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.umd.js +24292 -23645
  11. package/dist/index.umd.js.map +1 -1
  12. package/dist/types/collections.d.ts +38 -0
  13. package/dist/types/properties.d.ts +9 -8
  14. package/dist/types/translations.d.ts +23 -0
  15. package/dist/util/index.d.ts +1 -0
  16. package/dist/util/lazy_eager.d.ts +7 -0
  17. package/dist/util/objects.d.ts +1 -0
  18. package/package.json +4 -4
  19. package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +9 -3
  20. package/src/components/EntityCollectionView/EntityCollectionView.tsx +3 -5
  21. package/src/components/EntityJsonPreview.tsx +2 -1
  22. package/src/components/ErrorBoundary.tsx +3 -3
  23. package/src/components/VirtualTable/VirtualTable.tsx +5 -3
  24. package/src/components/VirtualTable/VirtualTableHeader.tsx +9 -8
  25. package/src/components/VirtualTable/VirtualTableHeaderRow.tsx +8 -3
  26. package/src/components/VirtualTable/VirtualTableProps.tsx +7 -1
  27. package/src/components/VirtualTable/types.tsx +1 -0
  28. package/src/core/DrawerNavigationGroup.tsx +1 -1
  29. package/src/core/EntityEditView.tsx +50 -5
  30. package/src/core/EntitySidePanel.tsx +2 -1
  31. package/src/core/field_configs.tsx +4 -2
  32. package/src/form/EntityForm.tsx +64 -4
  33. package/src/form/PropertyFieldBinding.tsx +4 -3
  34. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +18 -5
  35. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +18 -5
  36. package/src/form/field_bindings/BlockFieldBinding.tsx +21 -7
  37. package/src/form/field_bindings/DateTimeFieldBinding.tsx +1 -1
  38. package/src/form/field_bindings/KeyValueFieldBinding.tsx +23 -6
  39. package/src/form/field_bindings/MapFieldBinding.tsx +23 -8
  40. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +43 -20
  41. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +15 -1
  42. package/src/form/field_bindings/ReferenceAsStringFieldBinding.tsx +25 -11
  43. package/src/form/field_bindings/ReferenceFieldBinding.tsx +25 -11
  44. package/src/form/field_bindings/RepeatFieldBinding.tsx +18 -5
  45. package/src/form/field_bindings/SelectFieldBinding.tsx +7 -5
  46. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +24 -7
  47. package/src/form/field_bindings/SwitchFieldBinding.tsx +31 -14
  48. package/src/form/field_bindings/TextFieldBinding.tsx +10 -7
  49. package/src/form/field_bindings/UserSelectFieldBinding.tsx +7 -5
  50. package/src/index.ts +1 -0
  51. package/src/locales/de.ts +28 -1
  52. package/src/locales/en.ts +27 -0
  53. package/src/locales/es.ts +28 -1
  54. package/src/locales/fr.ts +28 -1
  55. package/src/locales/hi.ts +28 -1
  56. package/src/locales/it.ts +28 -1
  57. package/src/locales/pt.ts +28 -1
  58. package/src/preview/PropertyPreview.tsx +3 -2
  59. package/src/preview/components/ReferencePreview.tsx +2 -1
  60. package/src/preview/property_previews/MapPropertyPreview.tsx +49 -27
  61. package/src/routes/FireCMSRoute.tsx +63 -54
  62. package/src/types/collections.ts +40 -0
  63. package/src/types/properties.ts +11 -10
  64. package/src/types/translations.ts +27 -0
  65. package/src/util/index.ts +1 -0
  66. package/src/util/lazy_eager.tsx +33 -0
  67. package/src/util/objects.ts +15 -0
@@ -6,6 +6,7 @@ import { PropertyPreview } from "../PropertyPreview";
6
6
  import { cls, defaultBorderMixin, Typography } from "@firecms/ui";
7
7
  import { ErrorBoundary } from "../../components";
8
8
  import { EmptyValue } from "../components/EmptyValue";
9
+ import { DatePreview } from "../components/DatePreview";
9
10
 
10
11
  /**
11
12
  * @group Preview components
@@ -111,37 +112,58 @@ export function KeyValuePreview({ value }: { value: any }) {
111
112
  return <div
112
113
  className="flex flex-col gap-1 w-full">
113
114
  {
114
- Object.entries(value).map(([key, childValue]: [string, any]) => (
115
- <div
116
- key={`map_preview_table_${key}}`}
117
- className={cls(defaultBorderMixin, "last:border-b-0 border-b")}>
115
+ Object.entries(value).map(([key, childValue]: [string, any]) => {
116
+ const isTimestampObj = childValue && typeof childValue === "object" && (
117
+ childValue instanceof Date ||
118
+ ("_seconds" in childValue && "_nanoseconds" in childValue && typeof childValue._seconds === "number" && typeof childValue._nanoseconds === "number") ||
119
+ ("seconds" in childValue && "nanoseconds" in childValue && typeof childValue.seconds === "number" && typeof childValue.nanoseconds === "number")
120
+ );
121
+
122
+ const isScalar = childValue && (typeof childValue !== "object" || isTimestampObj);
123
+
124
+ return (
118
125
  <div
119
- className={"flex flex-row pt-0.5 pb-0.5 gap-2"}>
120
- <div
121
- key={`table-cell-title-${key}-${key}`}
122
- className="min-w-[140px] w-[25%] py-1">
123
- <Typography variant={"caption"}
124
- className={"font-semibold break-words"}
125
- color={"secondary"}>
126
- {key}
127
- </Typography>
128
- </div>
126
+ key={`map_preview_table_${key}}`}
127
+ className={cls(defaultBorderMixin, "last:border-b-0 border-b")}>
129
128
  <div
130
- className="flex-grow max-w-[75%]">
131
- {childValue && typeof childValue !== "object" && <Typography>
132
- <ErrorBoundary>
133
- {childValue.toString()}
134
- </ErrorBoundary>
135
- </Typography>}
129
+ className={"flex flex-row pt-0.5 pb-0.5 gap-2"}>
130
+ <div
131
+ key={`table-cell-title-${key}-${key}`}
132
+ className="min-w-[140px] w-[25%] py-1">
133
+ <Typography variant={"caption"}
134
+ className={"font-semibold break-words"}
135
+ color={"secondary"}>
136
+ {key}
137
+ </Typography>
138
+ </div>
139
+ <div
140
+ className="flex-grow max-w-[75%]">
141
+ {isScalar && (isTimestampObj ? (
142
+ <ErrorBoundary>
143
+ <DatePreview date={
144
+ childValue instanceof Date ? childValue :
145
+ typeof childValue.toDate === "function" ? childValue.toDate() :
146
+ "_seconds" in childValue ? new Date(childValue._seconds * 1000 + childValue._nanoseconds / 1000000) :
147
+ new Date(childValue.seconds * 1000 + childValue.nanoseconds / 1000000)
148
+ } />
149
+ </ErrorBoundary>
150
+ ) : (
151
+ <Typography>
152
+ <ErrorBoundary>
153
+ {childValue.toString()}
154
+ </ErrorBoundary>
155
+ </Typography>
156
+ ))}
157
+ </div>
136
158
  </div>
159
+ {typeof childValue === "object" && !isTimestampObj &&
160
+ <div className={cls(defaultBorderMixin, "border-l pl-4")}>
161
+ <KeyValuePreview value={childValue}/>
162
+ </div>
163
+ }
137
164
  </div>
138
- {typeof childValue === "object" &&
139
- <div className={cls(defaultBorderMixin, "border-l pl-4")}>
140
- <KeyValuePreview value={childValue}/>
141
- </div>
142
- }
143
- </div>
144
- ))
165
+ );
166
+ })
145
167
  }
146
168
  </div>;
147
169
  }
@@ -1,7 +1,6 @@
1
1
  import { Blocker, useBlocker, useLocation } from "react-router";
2
- import { EntityEditView } from "../core/EntityEditView";
2
+ import React, { useEffect, useRef, useState } from "react";
3
3
  import { useNavigationController } from "../hooks";
4
- import { useEffect, useRef, useState } from "react";
5
4
  import { useNavigate } from "react-router-dom";
6
5
  import {
7
6
  getNavigationEntriesFromPath,
@@ -11,7 +10,11 @@ import {
11
10
  } from "../util/navigation_from_path";
12
11
  import { useBreadcrumbsController } from "../hooks/useBreadcrumbsController";
13
12
  import { toArray } from "../util/arrays";
14
- import { EntityCollectionView, NotFoundPage } from "../components";
13
+ import { NotFoundPage } from "../components";
14
+ import { lazyEager } from "../util/lazy_eager";
15
+
16
+ const EntityEditView = lazyEager<typeof import("../core/EntityEditView")["EntityEditView"]>(() => import("../core/EntityEditView"), "EntityEditView");
17
+ const EntityCollectionView = lazyEager<typeof import("../components/EntityCollectionView/EntityCollectionView")["EntityCollectionView"]>(() => import("../components/EntityCollectionView/EntityCollectionView"), "EntityCollectionView");
15
18
  import { UnsavedChangesDialog } from "../components/UnsavedChangesDialog";
16
19
  import { EntityCollection } from "../types";
17
20
 
@@ -88,15 +91,17 @@ export function FireCMSRoute() {
88
91
  collection = navigation.getCollection(navigationEntries[0].path);
89
92
  if (!collection)
90
93
  return null;
91
- return <EntityCollectionView
92
- key={`collection_view_${collection.id ?? collection.path}`}
93
- isSubCollection={false}
94
- parentCollectionIds={[]}
95
- fullPath={collection.path}
96
- fullIdPath={collection.id}
97
- updateUrl={true}
98
- {...collection}
99
- Actions={toArray(collection.Actions)} />
94
+ return <React.Suspense fallback={null}>
95
+ <EntityCollectionView
96
+ key={`collection_view_${collection.id ?? collection.path}`}
97
+ isSubCollection={false}
98
+ parentCollectionIds={[]}
99
+ fullPath={collection.path}
100
+ fullIdPath={collection.id}
101
+ updateUrl={true}
102
+ {...collection}
103
+ Actions={toArray(collection.Actions)} />
104
+ </React.Suspense>;
100
105
  }
101
106
 
102
107
  if (isSidePanel) {
@@ -109,15 +114,17 @@ export function FireCMSRoute() {
109
114
  collection = navigation.getCollection(firstEntry.path);
110
115
  if (!collection)
111
116
  return null;
112
- return <EntityCollectionView
113
- key={`collection_view_${collection.id ?? collection.path}`}
114
- fullIdPath={collection.id}
115
- isSubCollection={false}
116
- parentCollectionIds={[]}
117
- fullPath={collection.path}
118
- updateUrl={true}
119
- {...collection}
120
- Actions={toArray(collection.Actions)} />;
117
+ return <React.Suspense fallback={null}>
118
+ <EntityCollectionView
119
+ key={`collection_view_${collection.id ?? collection.path}`}
120
+ fullIdPath={collection.id}
121
+ isSubCollection={false}
122
+ parentCollectionIds={[]}
123
+ fullPath={collection.path}
124
+ updateUrl={true}
125
+ {...collection}
126
+ Actions={toArray(collection.Actions)} />
127
+ </React.Suspense>;
121
128
  }
122
129
  }
123
130
 
@@ -215,39 +222,41 @@ function EntityFullScreenRoute({
215
222
  const fullIdPath = isNew ? lastCollectionEntry!.path : lastEntityEntry!.path;
216
223
  const collectionPath = navigation.resolveIdsFrom(fullIdPath);
217
224
  return <>
218
- <EntityEditView
219
- key={collection.id + "_" + (isNew ? "new" : (isCopy ? entityId + "_copy" : entityId))}
220
- entityId={isNew ? undefined : entityId}
221
- fullIdPath={fullIdPath}
222
- collection={collection}
223
- layout={"full_screen"}
224
- path={collectionPath}
225
- copy={isCopy}
226
- selectedTab={selectedTab ?? undefined}
227
- onValuesModified={(modified) => blocked.current = modified}
228
- onSaved={(params) => {
229
- const newSelectedTab = params.selectedTab;
230
- const newEntityId = params.entityId;
231
- if (newSelectedTab) {
232
- navigate(`${basePath}/${newEntityId}/${newSelectedTab}`, { replace: true });
233
- } else {
234
- navigate(`${basePath}/${newEntityId}`, { replace: true });
235
- }
236
- }}
237
- onTabChange={(params) => {
238
- setSelectedTab(params.selectedTab);
239
- if (isNew) {
240
- return;
241
- }
242
- const newSelectedTab = params.selectedTab;
243
- if (newSelectedTab) {
244
- navigate(`${basePath}/${entityId}/${newSelectedTab}`, { replace: true });
245
- } else {
246
- navigate(`${basePath}/${entityId}`, { replace: true });
247
- }
248
- }}
249
- parentCollectionIds={parentCollectionIds}
250
- />
225
+ <React.Suspense fallback={null}>
226
+ <EntityEditView
227
+ key={collection.id + "_" + (isNew ? "new" : (isCopy ? entityId + "_copy" : entityId))}
228
+ entityId={isNew ? undefined : entityId}
229
+ fullIdPath={fullIdPath}
230
+ collection={collection}
231
+ layout={"full_screen"}
232
+ path={collectionPath}
233
+ copy={isCopy}
234
+ selectedTab={selectedTab ?? undefined}
235
+ onValuesModified={(modified) => blocked.current = modified}
236
+ onSaved={(params) => {
237
+ const newSelectedTab = params.selectedTab;
238
+ const newEntityId = params.entityId;
239
+ if (newSelectedTab) {
240
+ navigate(`${basePath}/${newEntityId}/${newSelectedTab}`, { replace: true });
241
+ } else {
242
+ navigate(`${basePath}/${newEntityId}`, { replace: true });
243
+ }
244
+ }}
245
+ onTabChange={(params) => {
246
+ setSelectedTab(params.selectedTab);
247
+ if (isNew) {
248
+ return;
249
+ }
250
+ const newSelectedTab = params.selectedTab;
251
+ if (newSelectedTab) {
252
+ navigate(`${basePath}/${entityId}/${newSelectedTab}`, { replace: true });
253
+ } else {
254
+ navigate(`${basePath}/${entityId}`, { replace: true });
255
+ }
256
+ }}
257
+ parentCollectionIds={parentCollectionIds}
258
+ />
259
+ </React.Suspense>
251
260
 
252
261
  <UnsavedChangesDialog
253
262
  open={blocker?.state === "blocked"}
@@ -163,6 +163,31 @@ export interface EntityCollection<M extends Record<string, any> = any, USER exte
163
163
  */
164
164
  subcollections?: EntityCollection<any, any>[];
165
165
 
166
+ /**
167
+ * You can group subcollections and custom views into dropdown menus
168
+ * in the entity view tabs. Views listed in a group will be removed
169
+ * from the top-level tabs and shown under a single dropdown instead.
170
+ *
171
+ * @example
172
+ * ```tsx
173
+ * const productsCollection = buildCollection({
174
+ * id: "products",
175
+ * path: "products",
176
+ * name: "Products",
177
+ * properties: { ... },
178
+ * subcollections: [localesCollection, reviewsCollection],
179
+ * entityViews: [sampleView],
180
+ * viewGroups: [
181
+ * {
182
+ * name: "Related data",
183
+ * views: ["locales", "reviews", "sample_view"]
184
+ * }
185
+ * ]
186
+ * });
187
+ * ```
188
+ */
189
+ viewGroups?: ViewGroup[];
190
+
166
191
  /**
167
192
  * This interface defines all the callbacks that can be used when an entity
168
193
  * is being created, updated or deleted.
@@ -413,6 +438,21 @@ export interface KanbanConfig<M extends Record<string, any> = any> {
413
438
  columnProperty: Extract<keyof M, string>;
414
439
  }
415
440
 
441
+ /**
442
+ * You can group subcollections and custom views into dropdown menus in the entity view tabs.
443
+ * @group Collections
444
+ */
445
+ export interface ViewGroup {
446
+ /**
447
+ * Name of the group
448
+ */
449
+ name: string;
450
+ /**
451
+ * Array of subcollection paths/ids or custom view keys
452
+ */
453
+ views: string[];
454
+ }
455
+
416
456
  /**
417
457
  * View mode for displaying a collection.
418
458
  * @group Collections
@@ -180,6 +180,17 @@ export interface BaseProperty<T extends CMSType, CustomProps = any> {
180
180
  * @see https://jsonlogic.com/ for JSON Logic syntax
181
181
  */
182
182
  conditions?: PropertyConditions;
183
+
184
+ /**
185
+ * Set this property to true to provide the UX to explicitly set the value to `null`.
186
+ * Defaults to `false`.
187
+ */
188
+ nullable?: boolean;
189
+
190
+ /**
191
+ * @deprecated Use `nullable` instead.
192
+ */
193
+ clearable?: boolean;
183
194
  }
184
195
 
185
196
  /**
@@ -620,11 +631,6 @@ export interface NumberProperty extends BaseProperty<number> {
620
631
  * Rules for validating this property
621
632
  */
622
633
  validation?: NumberPropertyValidationSchema,
623
-
624
- /**
625
- * Add an icon to clear the value and set it to `null`. Defaults to `false`
626
- */
627
- clearable?: boolean;
628
634
  }
629
635
 
630
636
  /**
@@ -735,11 +741,6 @@ export interface StringProperty extends BaseProperty<string> {
735
741
  */
736
742
  validation?: StringPropertyValidationSchema;
737
743
 
738
- /**
739
- * Add an icon to clear the value and set it to `null`. Defaults to `false`
740
- */
741
- clearable?: boolean;
742
-
743
744
  /**
744
745
  * You can use this property (a string) to behave as a reference to another
745
746
  * collection. The stored value is the ID of the entity in the
@@ -467,6 +467,8 @@ export interface FireCMSTranslations {
467
467
  cms_users: string;
468
468
  roles_menu: string;
469
469
  project_settings: string;
470
+ firestore_explorer: string;
471
+ explore_your_firestore_data: string;
470
472
 
471
473
  // ─── FireCMS Cloud Login ──────────────────────────────────────
472
474
  build_admin_panel_in_minutes: string;
@@ -722,4 +724,29 @@ export interface FireCMSTranslations {
722
724
  settings_appcheck_refresh_note: string;
723
725
  settings_appcheck_updated: string;
724
726
  settings_appcheck_error: string;
727
+
728
+ // --- Permission Error View ---
729
+ missing_firestore_security_rules: string;
730
+ firecms_cloud_requires_security_rule: string;
731
+ cannot_be_accessed_without_it: string;
732
+ required_security_rule: string;
733
+ fix_automatically: string;
734
+ open_firebase_rules: string;
735
+ security_rules_updated_successfully: string;
736
+ sec_rules_fixing: string;
737
+ sec_rules_fixed: string;
738
+
739
+ // ─── GCP Marketplace ─────────────────────────────────────────
740
+ marketplace_managed_by_gcp: string;
741
+ marketplace_billing_note: string;
742
+ marketplace_manage_in_gcp_console: string;
743
+ marketplace_plan_changes_note: string;
744
+ marketplace_welcome_title: string;
745
+ marketplace_welcome_subtitle: string;
746
+ marketplace_select_or_create_project: string;
747
+ marketplace_link_project: string;
748
+ marketplace_linking: string;
749
+ marketplace_link_success: string;
750
+ marketplace_link_error: string;
751
+ marketplace_no_account_id: string;
725
752
  }
package/src/util/index.ts CHANGED
@@ -25,3 +25,4 @@ export * from "./useTraceUpdate";
25
25
  export * from "./storage";
26
26
  export * from "./callbacks";
27
27
  export * from "./conditions";
28
+ export * from "./lazy_eager";
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+
3
+ /**
4
+ * Returns a React.lazy component that is also preloaded immediately using
5
+ * requestIdleCallback or setTimeout.
6
+ * This ensures that chunks are split, but fetched in the background before they are actually needed.
7
+ */
8
+ export function lazyEager<T extends React.ComponentType<any>>(
9
+ factory: () => Promise<any>,
10
+ exportName: string = "default"
11
+ ): React.LazyExoticComponent<T> {
12
+ let promise: Promise<any> | null = null;
13
+
14
+ const load = () => {
15
+ if (!promise) {
16
+ promise = factory().then((module) => {
17
+ const component = module[exportName] || module.default || module;
18
+ return { default: component };
19
+ });
20
+ }
21
+ return promise;
22
+ };
23
+
24
+ if (typeof window !== "undefined") {
25
+ if ("requestIdleCallback" in window) {
26
+ (window as any).requestIdleCallback(load);
27
+ } else {
28
+ setTimeout(load, 500);
29
+ }
30
+ }
31
+
32
+ return React.lazy(load);
33
+ }
@@ -279,3 +279,18 @@ export function removePropsIfExisting(source: any, comparison: any) {
279
279
 
280
280
  return res;
281
281
  }
282
+
283
+ export function jsonStringifyReplacer(key: string, value: any) {
284
+ if (value && typeof value === "object") {
285
+ if (value instanceof Date) {
286
+ return value.toISOString();
287
+ }
288
+ if ("_seconds" in value && "_nanoseconds" in value && typeof value._seconds === "number" && typeof value._nanoseconds === "number") {
289
+ return new Date(value._seconds * 1000 + value._nanoseconds / 1000000).toISOString();
290
+ }
291
+ if ("seconds" in value && "nanoseconds" in value && typeof value.seconds === "number" && typeof value.nanoseconds === "number") {
292
+ return new Date(value.seconds * 1000 + value.nanoseconds / 1000000).toISOString();
293
+ }
294
+ }
295
+ return value;
296
+ }