@firecms/core 3.4.0-canary.63041d0 → 3.4.0-canary.9408c41

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 (160) hide show
  1. package/README.md +4 -0
  2. package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +3 -1
  3. package/dist/components/EntityCollectionView/EntityCollectionBoardView.d.ts +3 -1
  4. package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +3 -2
  5. package/dist/components/EntityCollectionView/EntityCollectionViewActions.d.ts +3 -1
  6. package/dist/components/EntityCollectionView/EntityCollectionViewStartActions.d.ts +3 -1
  7. package/dist/components/EntityCollectionView/useBoardDataController.d.ts +3 -1
  8. package/dist/components/ErrorBoundary.d.ts +1 -3
  9. package/dist/components/LicenseBanner.d.ts +23 -0
  10. package/dist/components/ReferenceTable/ReferenceSelectionTable.d.ts +10 -1
  11. package/dist/components/common/useDataSourceTableController.d.ts +4 -2
  12. package/dist/components/common/useTableSearchHelper.d.ts +3 -1
  13. package/dist/components/index.d.ts +1 -0
  14. package/dist/contexts/LicenseStatusContext.d.ts +16 -0
  15. package/dist/core/EntityEditView.d.ts +2 -0
  16. package/dist/core/EntityEditViewFormActions.d.ts +1 -1
  17. package/dist/core/index.d.ts +1 -0
  18. package/dist/core/plugin_translations.d.ts +38 -0
  19. package/dist/core/pro_plugins.d.ts +40 -0
  20. package/dist/de-DMp6cIY1.js +702 -0
  21. package/dist/de-DMp6cIY1.js.map +1 -0
  22. package/dist/editor/extensions/Image.d.ts +11 -0
  23. package/dist/editor/index.d.ts +2 -1
  24. package/dist/editor/lazy_editor.d.ts +6 -0
  25. package/dist/editor-BSo_aS1I.js +4563 -0
  26. package/dist/editor-BSo_aS1I.js.map +1 -0
  27. package/dist/form/EntityForm.d.ts +8 -1
  28. package/dist/form/EntityFormActions.d.ts +2 -0
  29. package/dist/fr-Cckz4IkR.js +702 -0
  30. package/dist/fr-Cckz4IkR.js.map +1 -0
  31. package/dist/hi-CDCoIqbu.js +702 -0
  32. package/dist/hi-CDCoIqbu.js.map +1 -0
  33. package/dist/hooks/data/delete.d.ts +1 -1
  34. package/dist/hooks/data/useCollectionFetch.d.ts +7 -1
  35. package/dist/hooks/data/useEntityFetch.d.ts +4 -1
  36. package/dist/hooks/index.d.ts +2 -0
  37. package/dist/hooks/useLicenseStatus.d.ts +16 -0
  38. package/dist/hooks/useProjectLog.d.ts +11 -6
  39. package/dist/hooks/useTranslation.d.ts +1 -1
  40. package/dist/i18n/__tests__/FireCMSi18nProvider.test.d.ts +1 -0
  41. package/dist/i18n/__tests__/nested_provider_lifecycle.test.d.ts +1 -0
  42. package/dist/index.es.js +3113 -10785
  43. package/dist/index.es.js.map +1 -1
  44. package/dist/index.umd.js +7939 -6836
  45. package/dist/index.umd.js.map +1 -1
  46. package/dist/it-BJCUqixj.js +702 -0
  47. package/dist/it-BJCUqixj.js.map +1 -0
  48. package/dist/pl-DgT_joFf.js +704 -0
  49. package/dist/pl-DgT_joFf.js.map +1 -0
  50. package/dist/pt-B3dN3x0X.js +704 -0
  51. package/dist/pt-B3dN3x0X.js.map +1 -0
  52. package/dist/types/analytics.d.ts +1 -1
  53. package/dist/types/collections.d.ts +7 -0
  54. package/dist/types/datasource.d.ts +25 -4
  55. package/dist/types/entities.d.ts +21 -1
  56. package/dist/types/entity_actions.d.ts +6 -0
  57. package/dist/types/entity_callbacks.d.ts +21 -0
  58. package/dist/types/firecms.d.ts +18 -1
  59. package/dist/types/firecms_context.d.ts +8 -0
  60. package/dist/types/index.d.ts +1 -0
  61. package/dist/types/license.d.ts +54 -0
  62. package/dist/types/navigation.d.ts +34 -5
  63. package/dist/types/plugins.d.ts +22 -1
  64. package/dist/types/side_entity_controller.d.ts +3 -2
  65. package/dist/types/translations.d.ts +35 -2
  66. package/dist/util/date_fns_locales.d.ts +18 -0
  67. package/dist/util/entity_cache.d.ts +11 -0
  68. package/dist/util/index.d.ts +1 -0
  69. package/dist/util/lazy_eager.d.ts +3 -3
  70. package/dist/util/navigation_utils.d.ts +84 -2
  71. package/dist/util/parent_references_from_path.d.ts +16 -0
  72. package/dist/util/paths.d.ts +28 -0
  73. package/dist/util/permissions.d.ts +10 -4
  74. package/package.json +5 -6
  75. package/src/app/Scaffold.tsx +7 -0
  76. package/src/components/DeleteEntityDialog.tsx +2 -0
  77. package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +2 -2
  78. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +5 -1
  79. package/src/components/EntityCollectionView/EntityCollectionBoardView.tsx +12 -0
  80. package/src/components/EntityCollectionView/EntityCollectionView.tsx +49 -16
  81. package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +6 -2
  82. package/src/components/EntityCollectionView/EntityCollectionViewStartActions.tsx +4 -0
  83. package/src/components/EntityCollectionView/useBoardDataController.tsx +17 -1
  84. package/src/components/EntityPreview.tsx +4 -1
  85. package/src/components/ErrorBoundary.tsx +12 -18
  86. package/src/components/LicenseBanner.tsx +209 -0
  87. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +19 -2
  88. package/src/components/common/default_entity_actions.tsx +22 -2
  89. package/src/components/common/useDataSourceTableController.tsx +32 -8
  90. package/src/components/common/useTableSearchHelper.ts +5 -0
  91. package/src/components/index.tsx +1 -0
  92. package/src/contexts/LicenseStatusContext.tsx +50 -0
  93. package/src/core/DefaultAppBar.tsx +28 -16
  94. package/src/core/EntityEditView.tsx +11 -12
  95. package/src/core/EntityEditViewFormActions.tsx +3 -2
  96. package/src/core/EntitySidePanel.tsx +6 -4
  97. package/src/core/FireCMS.tsx +73 -47
  98. package/src/core/SideDialogs.tsx +44 -1
  99. package/src/core/index.tsx +1 -0
  100. package/src/core/plugin_translations.ts +87 -0
  101. package/src/core/pro_plugins.ts +79 -0
  102. package/src/editor/components/SlashCommandMenu.tsx +4 -1
  103. package/src/editor/extensions/Image.ts +17 -1
  104. package/src/editor/hooks/useProseMirror.ts +5 -0
  105. package/src/editor/index.ts +11 -1
  106. package/src/editor/lazy_editor.tsx +33 -0
  107. package/src/form/EntityForm.tsx +30 -9
  108. package/src/form/EntityFormActions.tsx +2 -0
  109. package/src/hooks/data/delete.ts +8 -0
  110. package/src/hooks/data/save.ts +5 -2
  111. package/src/hooks/data/useCollectionFetch.tsx +21 -1
  112. package/src/hooks/data/useEntityFetch.tsx +28 -6
  113. package/src/hooks/index.tsx +2 -0
  114. package/src/hooks/useBuildNavigationController.tsx +70 -15
  115. package/src/hooks/useFireCMSContext.tsx +7 -3
  116. package/src/hooks/useLicenseStatus.tsx +32 -0
  117. package/src/hooks/useProjectLog.tsx +27 -9
  118. package/src/hooks/useResolvedNavigationFrom.tsx +3 -1
  119. package/src/hooks/useTranslation.ts +3 -1
  120. package/src/i18n/FireCMSi18nProvider.tsx +199 -25
  121. package/src/i18n/__tests__/FireCMSi18nProvider.test.tsx +91 -0
  122. package/src/i18n/__tests__/nested_provider_lifecycle.test.tsx +67 -0
  123. package/src/internal/useBuildDataSource.ts +26 -15
  124. package/src/internal/useBuildSideEntityController.tsx +13 -5
  125. package/src/locales/de.ts +18 -2
  126. package/src/locales/en.ts +21 -3
  127. package/src/locales/es.ts +18 -2
  128. package/src/locales/fr.ts +18 -2
  129. package/src/locales/hi.ts +18 -2
  130. package/src/locales/it.ts +18 -2
  131. package/src/locales/pl.ts +18 -2
  132. package/src/locales/pt.ts +18 -2
  133. package/src/preview/components/DatePreview.tsx +2 -4
  134. package/src/preview/components/ReferencePreview.tsx +7 -3
  135. package/src/routes/FireCMSRoute.tsx +9 -4
  136. package/src/types/analytics.ts +3 -0
  137. package/src/types/collections.ts +8 -0
  138. package/src/types/datasource.ts +25 -4
  139. package/src/types/entities.ts +24 -1
  140. package/src/types/entity_actions.tsx +6 -0
  141. package/src/types/entity_callbacks.ts +24 -0
  142. package/src/types/firecms.tsx +19 -1
  143. package/src/types/firecms_context.tsx +9 -0
  144. package/src/types/index.ts +1 -0
  145. package/src/types/license.ts +62 -0
  146. package/src/types/navigation.ts +35 -5
  147. package/src/types/plugins.tsx +23 -1
  148. package/src/types/side_entity_controller.tsx +3 -2
  149. package/src/types/translations.ts +35 -2
  150. package/src/util/date_fns_locales.ts +168 -0
  151. package/src/util/entities.ts +3 -1
  152. package/src/util/entity_cache.ts +18 -0
  153. package/src/util/index.ts +1 -0
  154. package/src/util/lazy_eager.tsx +30 -8
  155. package/src/util/navigation_from_path.ts +6 -1
  156. package/src/util/navigation_utils.ts +210 -3
  157. package/src/util/parent_references_from_path.ts +42 -3
  158. package/src/util/paths.ts +40 -3
  159. package/src/util/permissions.ts +22 -10
  160. package/src/util/useStorageUploadController.tsx +6 -1
@@ -0,0 +1,33 @@
1
+ "use client";
2
+
3
+ import React from "react";
4
+
5
+ import { CircularProgressCenter } from "../components/CircularProgressCenter";
6
+ import type { FireCMSEditorProps } from "./editor";
7
+
8
+ /**
9
+ * `FireCMSEditor`, loaded on demand.
10
+ *
11
+ * The editor is built on ProseMirror — roughly 250KB across a dozen packages —
12
+ * and is only reachable from a markdown field, which most views never render.
13
+ * `MarkdownEditorFieldBinding` already loaded it lazily, but that split was
14
+ * defeated by `src/index.ts` re-exporting the editor from the package barrel:
15
+ * a static re-export puts the module back in the entry graph regardless of who
16
+ * imports it dynamically. So ProseMirror sat in `@firecms/core` for everyone.
17
+ *
18
+ * The name and props are unchanged, and this component carries its own Suspense
19
+ * boundary, so it stays a drop-in for the synchronous component it replaces —
20
+ * a consumer rendering it without a boundary of their own still works.
21
+ */
22
+ const LazyFireCMSEditor = React.lazy(() =>
23
+ import("./editor").then((module) => ({ default: module.FireCMSEditor })));
24
+
25
+ export function FireCMSEditor(props: FireCMSEditorProps) {
26
+ return (
27
+ <React.Suspense fallback={<CircularProgressCenter/>}>
28
+ <LazyFireCMSEditor {...props}/>
29
+ </React.Suspense>
30
+ );
31
+ }
32
+
33
+ FireCMSEditor.displayName = "FireCMSEditor";
@@ -48,6 +48,7 @@ import { useAnalyticsController } from "../hooks/useAnalyticsController";
48
48
  import { FormEntry, FormLayout, LabelWithIconAndTooltip, PropertyFieldBinding } from "../form";
49
49
  import { ValidationError } from "yup";
50
50
  import {
51
+ entityCacheKey,
51
52
  flattenKeys,
52
53
  getEntityFromCache,
53
54
  removeEntityFromCache,
@@ -64,6 +65,8 @@ export type OnUpdateParams = {
64
65
  entity: Entity<any>,
65
66
  status: EntityStatus,
66
67
  path: string,
68
+ /** `path` split at its real segment boundaries, when known. Never derived from `path`. */
69
+ pathSegments?: string[],
67
70
  entityId?: string;
68
71
  selectedTab?: string;
69
72
  collection: EntityCollection<any>
@@ -71,6 +74,11 @@ export type OnUpdateParams = {
71
74
 
72
75
  export type EntityFormProps<M extends Record<string, any>> = {
73
76
  path: string;
77
+ /**
78
+ * `path` split at its real segment boundaries; forwarded to the datasource for
79
+ * generateEntityId and checkUniqueField. Never derived from `path`.
80
+ */
81
+ pathSegments?: string[];
74
82
  fullIdPath?: string;
75
83
  collection: EntityCollection<M>;
76
84
  entityId?: string;
@@ -214,6 +222,7 @@ export function getChanges<T extends object>(source: Partial<T>, comparison: Par
214
222
 
215
223
  export function EntityForm<M extends Record<string, any>>({
216
224
  path,
225
+ pathSegments,
217
226
  fullIdPath,
218
227
  entityId: entityIdProp,
219
228
  collection,
@@ -270,6 +279,7 @@ export function EntityForm<M extends Record<string, any>>({
270
279
  entityId: entityIdProp,
271
280
  collection,
272
281
  path,
282
+ pathSegments,
273
283
  values: valuesToBeSaved
274
284
  });
275
285
  }, false, 2000);
@@ -292,7 +302,7 @@ export function EntityForm<M extends Record<string, any>>({
292
302
  if (mustSetCustomId) {
293
303
  return undefined;
294
304
  } else {
295
- return dataSource.generateEntityId(path, collection);
305
+ return dataSource.generateEntityId(path, collection, pathSegments);
296
306
  }
297
307
  } else {
298
308
  return entityIdProp;
@@ -308,7 +318,7 @@ export function EntityForm<M extends Record<string, any>>({
308
318
  const baseInitialValues = useMemo(() => getInitialEntityValues(authController, collection, path, status, entity, customizationController.propertyConfigs), [authController, collection, path, status, entity, customizationController.propertyConfigs]);
309
319
 
310
320
  const localChangesDataRaw = useMemo(() => entityId
311
- ? getEntityFromCache(path + "/" + entityId)
321
+ ? getEntityFromCache(entityCacheKey(path, entityId))
312
322
  : getEntityFromCache(path + "#new"), [entityId, path]);
313
323
 
314
324
  const [localChangesCleared, setLocalChangesCleared] = useState<boolean>(false);
@@ -387,7 +397,7 @@ export function EntityForm<M extends Record<string, any>>({
387
397
  onValuesModified?.(false, initialValues as M);
388
398
  },
389
399
  onValuesChangeDeferred: (values: M, controller: FormexController<M>) => {
390
- const key = (status === "new" || status === "copy") ? path + "#new" : path + "/" + entityId;
400
+ const key = (status === "new" || status === "copy") ? path + "#new" : entityCacheKey(path, entityId);
391
401
  if (controller.dirty && localChangesBackup !== false) {
392
402
  const touchedValues = removeEmptyContainers(extractTouchedValues(values, controller.touched));
393
403
  if (touchedValues && Object.keys(touchedValues).length > 0) {
@@ -468,8 +478,8 @@ export function EntityForm<M extends Record<string, any>>({
468
478
  removeEntityFromMemoryCache(path + "#new");
469
479
  removeEntityFromCache(path + "#new");
470
480
  } else {
471
- removeEntityFromMemoryCache(path + "/" + entityId);
472
- removeEntityFromCache(path + "/" + entityId);
481
+ removeEntityFromMemoryCache(entityCacheKey(path, entityId));
482
+ removeEntityFromCache(entityCacheKey(path, entityId));
473
483
  }
474
484
  }
475
485
 
@@ -491,6 +501,7 @@ export function EntityForm<M extends Record<string, any>>({
491
501
  entity: updatedEntity,
492
502
  status,
493
503
  path,
504
+ pathSegments,
494
505
  entityId: updatedEntity.id,
495
506
  collection
496
507
  });
@@ -511,16 +522,20 @@ export function EntityForm<M extends Record<string, any>>({
511
522
  previousValues,
512
523
  entityId,
513
524
  collection,
514
- path
525
+ path,
526
+ pathSegments
515
527
  }: {
516
528
  collection: EntityCollection<M>,
517
529
  path: string,
530
+ /** `path` split at its real segment boundaries, travelling with the `path` above. */
531
+ pathSegments?: string[],
518
532
  entityId: string | undefined,
519
533
  values: M,
520
534
  previousValues?: M,
521
535
  }) => {
522
536
  return saveEntityWithCallbacks({
523
537
  path,
538
+ pathSegments,
524
539
  entityId,
525
540
  values,
526
541
  previousValues,
@@ -538,6 +553,7 @@ export function EntityForm<M extends Record<string, any>>({
538
553
  type EntityFormSaveParams<M extends Record<string, any>> = {
539
554
  collection: ResolvedEntityCollection<M>,
540
555
  path: string,
556
+ pathSegments?: string[],
541
557
  entityId: string | undefined,
542
558
  values: EntityValues<M>,
543
559
  previousValues?: EntityValues<M>,
@@ -547,6 +563,7 @@ export function EntityForm<M extends Record<string, any>>({
547
563
  const onSaveEntityRequest = async ({
548
564
  collection,
549
565
  path,
566
+ pathSegments,
550
567
  entityId,
551
568
  values,
552
569
  previousValues,
@@ -560,6 +577,7 @@ export function EntityForm<M extends Record<string, any>>({
560
577
  return saveEntity({
561
578
  collection,
562
579
  path,
580
+ pathSegments,
563
581
  entityId,
564
582
  values,
565
583
  previousValues
@@ -573,6 +591,7 @@ export function EntityForm<M extends Record<string, any>>({
573
591
  return onSaveEntityRequest({
574
592
  collection: resolvedCollection,
575
593
  path,
594
+ pathSegments,
576
595
  entityId,
577
596
  values,
578
597
  previousValues: entity?.values,
@@ -623,13 +642,14 @@ export function EntityForm<M extends Record<string, any>>({
623
642
  const plugins = customizationController.plugins;
624
643
 
625
644
  const actionsDisabled = disabled || formex.isSubmitting || (status === "existing" && !formex.dirty) || Boolean(disabledProp);
626
- const parentCollectionIds = navigationController.getParentCollectionIds(path);
645
+ const parentCollectionIds = navigationController.getParentCollectionIds(path, pathSegments);
627
646
 
628
647
  if (plugins && collection) {
629
648
  const actionProps: PluginFormActionProps = {
630
649
  entityId,
631
650
  parentCollectionIds,
632
651
  path,
652
+ pathSegments,
633
653
  status,
634
654
  collection,
635
655
  context,
@@ -692,7 +712,7 @@ export function EntityForm<M extends Record<string, any>>({
692
712
  const uniqueFieldValidator: CustomFieldValidator = useCallback(({
693
713
  name,
694
714
  value
695
- }) => dataSource.checkUniqueField(path, name, value, entityId, collection),
715
+ }) => dataSource.checkUniqueField(path, name, value, entityId, collection, pathSegments),
696
716
  [dataSource, path, entityId]);
697
717
 
698
718
  const validationSchema = useMemo(() => entityId
@@ -890,6 +910,7 @@ export function EntityForm<M extends Record<string, any>>({
890
910
  const dialogActions = <EntityFormActionsComponent
891
911
  collection={resolvedCollection}
892
912
  path={path}
913
+ pathSegments={pathSegments}
893
914
  fullPath={path}
894
915
  fullIdPath={fullIdPath}
895
916
  entity={entity}
@@ -924,7 +945,7 @@ export function EntityForm<M extends Record<string, any>>({
924
945
 
925
946
  {manualApplyLocalChanges && hasLocalChanges &&
926
947
  <LocalChangesMenu
927
- cacheKey={status === "new" || status === "copy" ? path + "#new" : path + "/" + entityId}
948
+ cacheKey={status === "new" || status === "copy" ? path + "#new" : entityCacheKey(path, entityId)}
928
949
  properties={resolvedCollection.properties}
929
950
  cachedData={localChangesDataRaw as Partial<M>}
930
951
  formex={formex}
@@ -26,6 +26,8 @@ export interface EntityFormActionsProps {
26
26
  fullIdPath?: string;
27
27
  collection: ResolvedEntityCollection;
28
28
  path: string;
29
+ /** `path` split at its real segment boundaries, when known. Never derived from `path`. */
30
+ pathSegments?: string[];
29
31
  entity?: Entity;
30
32
  layout: "bottom" | "side";
31
33
  savingError?: Error;
@@ -46,6 +46,7 @@ export type DeleteEntityWithCallbacksProps<M extends Record<string, any>, USER e
46
46
  export async function deleteEntityWithCallbacks<M extends Record<string, any>, USER extends User>({
47
47
  dataSource,
48
48
  entity,
49
+ pathSegments,
49
50
  collection,
50
51
  callbacks,
51
52
  onDeleteSuccess,
@@ -62,11 +63,17 @@ export async function deleteEntityWithCallbacks<M extends Record<string, any>, U
62
63
 
63
64
  console.debug("Deleting entity", entity.path, entity.id);
64
65
 
66
+ // An explicit `pathSegments` wins, then the ones the entity was loaded with. The prop
67
+ // used to be accepted and silently ignored, which is the same class of bug this field
68
+ // exists to prevent.
69
+ const resolvedPathSegments = pathSegments ?? entity.pathSegments;
70
+
65
71
  const entityDeleteProps: EntityOnDeleteProps<M, any> = {
66
72
  entity,
67
73
  collection,
68
74
  entityId: entity.id,
69
75
  path: entity.path,
76
+ pathSegments: resolvedPathSegments,
70
77
  context
71
78
  };
72
79
 
@@ -81,6 +88,7 @@ export async function deleteEntityWithCallbacks<M extends Record<string, any>, U
81
88
  }
82
89
  }
83
90
  return dataSource.deleteEntity({
91
+ pathSegments: resolvedPathSegments,
84
92
  entity,
85
93
  collection
86
94
  }).then(() => {
@@ -68,7 +68,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, USE
68
68
 
69
69
  const customizationController = context.customizationController;
70
70
 
71
- const resolvedPath = context.navigation.resolveIdsFrom(path);
71
+ const resolvedPath = context.navigation.resolveIdsFrom(path, pathSegments);
72
72
 
73
73
  const callbacks = collection.callbacks;
74
74
  if (callbacks?.onPreSave) {
@@ -84,6 +84,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, USE
84
84
  updatedValues = await callbacks.onPreSave({
85
85
  collection: resolvedCollection,
86
86
  path,
87
+ pathSegments,
87
88
  resolvedPath,
88
89
  entityId,
89
90
  values,
@@ -104,7 +105,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, USE
104
105
  return dataSource.saveEntity({
105
106
  collection,
106
107
  path: resolvedPath,
107
- pathSegments: pathSegments ?? resolvedPath.split("/"),
108
+ pathSegments,
108
109
  entityId,
109
110
  values: updatedValues,
110
111
  previousValues,
@@ -123,6 +124,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, USE
123
124
  callbacks.onSaveSuccess({
124
125
  collection: resolvedCollection,
125
126
  path,
127
+ pathSegments,
126
128
  resolvedPath,
127
129
  entityId: entity.id,
128
130
  values: updatedValues,
@@ -152,6 +154,7 @@ export async function saveEntityWithCallbacks<M extends Record<string, any>, USE
152
154
  callbacks.onSaveFailure({
153
155
  collection: resolvedCollection,
154
156
  path,
157
+ pathSegments,
155
158
  resolvedPath,
156
159
  entityId,
157
160
  values: updatedValues,
@@ -13,6 +13,12 @@ export interface CollectionFetchProps<M extends Record<string, any>> {
13
13
  * Absolute collection path
14
14
  */
15
15
  path: string;
16
+ /**
17
+ * `path` split at its real segment boundaries. Forwarded to the datasource so a parent
18
+ * entity id containing "/" stays unambiguous. Never derived from `path` — see
19
+ * `pathSegments` on the datasource props.
20
+ */
21
+ pathSegments?: string[];
16
22
 
17
23
  /**
18
24
  * collection of the entity displayed by this collection
@@ -63,6 +69,7 @@ export interface CollectionFetchResult<M extends Record<string, any>> {
63
69
  export function useCollectionFetch<M extends Record<string, any>, USER extends User>(
64
70
  {
65
71
  path: inputPath,
72
+ pathSegments: inputPathSegments,
66
73
  collection,
67
74
  filterValues,
68
75
  sortBy,
@@ -73,7 +80,13 @@ export function useCollectionFetch<M extends Record<string, any>, USER extends U
73
80
  const dataSource = useDataSource(collection);
74
81
  const navigationController = useNavigationController();
75
82
 
76
- const path = navigationController.resolveIdsFrom(inputPath);
83
+ // Resolved together so the two representations always describe the same chain.
84
+ // Segments are resolved, never derived: only collection ids are swapped for their
85
+ // real paths, and entity ids are carried through whole (see useEntityFetch).
86
+ const pathSegments = inputPathSegments
87
+ ? (navigationController.resolveSegmentsFrom?.(inputPathSegments) ?? inputPathSegments)
88
+ : undefined;
89
+ const path = navigationController.resolveIdsFrom(inputPath, inputPathSegments);
77
90
 
78
91
  const sortByProperty = sortBy ? sortBy[0] : undefined;
79
92
  const currentSort = sortBy ? sortBy[1] : undefined;
@@ -91,6 +104,10 @@ export function useCollectionFetch<M extends Record<string, any>, USER extends U
91
104
  setDataLoading(true);
92
105
 
93
106
  const onEntitiesUpdate = async (entities: Entity<M>[]) => {
107
+ // See useEntityFetch: entities carry the segments they were loaded with.
108
+ if (pathSegments) {
109
+ entities = entities.map(e => e.pathSegments ? e : { ...e, pathSegments });
110
+ }
94
111
  if (collection.callbacks?.onFetch) {
95
112
  try {
96
113
  entities = await Promise.all(
@@ -98,6 +115,7 @@ export function useCollectionFetch<M extends Record<string, any>, USER extends U
98
115
  collection.callbacks!.onFetch!({
99
116
  collection,
100
117
  path,
118
+ pathSegments,
101
119
  entity,
102
120
  context
103
121
  })));
@@ -124,6 +142,7 @@ export function useCollectionFetch<M extends Record<string, any>, USER extends U
124
142
  if (dataSource.listenCollection) {
125
143
  return dataSource.listenCollection<M>({
126
144
  path,
145
+ pathSegments,
127
146
  collection,
128
147
  onUpdate: onEntitiesUpdate,
129
148
  onError,
@@ -137,6 +156,7 @@ export function useCollectionFetch<M extends Record<string, any>, USER extends U
137
156
  } else {
138
157
  dataSource.fetchCollection<M>({
139
158
  path,
159
+ pathSegments,
140
160
  collection,
141
161
  searchString,
142
162
  filter: filterValues,
@@ -3,6 +3,7 @@ import { Entity, EntityCollection, FireCMSContext, User } from "../../types";
3
3
  import { useDataSource } from "./useDataSource";
4
4
  import { useNavigationController } from "../useNavigationController";
5
5
  import { useFireCMSContext } from "../useFireCMSContext";
6
+ import { entityCacheKey } from "../../util/entity_cache";
6
7
 
7
8
  /**
8
9
  * @group Hooks and utilities
@@ -11,7 +12,10 @@ export interface EntityFetchProps<M extends Record<string, any>, USER extends Us
11
12
  path: string;
12
13
  /**
13
14
  * `path` split at its real segment boundaries. Forwarded to the datasource so a parent
14
- * entity id containing "/" stays unambiguous. Defaults to splitting the resolved path.
15
+ * entity id containing "/" stays unambiguous.
16
+ *
17
+ * Optional, and never derived by splitting `path` — a guess would be wrong in exactly
18
+ * the case the field exists for. Absent means "not known here", not "no slashes".
15
19
  */
16
20
  pathSegments?: string[];
17
21
  entityId?: string;
@@ -54,8 +58,19 @@ export function useEntityFetch<M extends Record<string, any>, USER extends User>
54
58
  const dataSource = useDataSource(collection);
55
59
  const navigationController = useNavigationController();
56
60
 
57
- const path = navigationController.resolveIdsFrom(inputPath);
58
- const pathSegments = inputPathSegments ?? path.split("/");
61
+ // Never fabricate segments. If the caller did not thread them, pass undefined so a
62
+ // delegate can tell "not provided" from a real answer — splitting `path` here would
63
+ // produce a confidently wrong array for any id containing "/".
64
+ //
65
+ // When they were threaded, both representations are resolved from them together, so
66
+ // `path` cannot end up describing a different chain than `pathSegments`.
67
+ // `resolveSegmentsFrom` is optional on the controller: a host app may be supplying one
68
+ // built against an earlier version. Falling back to the segments as given is what
69
+ // happened before it existed — they are used unresolved, never invented.
70
+ const pathSegments = inputPathSegments
71
+ ? (navigationController.resolveSegmentsFrom?.(inputPathSegments) ?? inputPathSegments)
72
+ : undefined;
73
+ const path = navigationController.resolveIdsFrom(inputPath, inputPathSegments);
59
74
 
60
75
  const context: FireCMSContext<USER> = useFireCMSContext();
61
76
 
@@ -68,11 +83,18 @@ export function useEntityFetch<M extends Record<string, any>, USER extends User>
68
83
  setDataLoading(true);
69
84
 
70
85
  const onEntityUpdate = async (updatedEntity: Entity<M> | undefined) => {
86
+ // Attach the segments this entity was loaded with, so anything derived from it
87
+ // later — a reference, a delete — stays resolvable without re-deriving them
88
+ // from the flattened path. Delegates are not required to set this themselves.
89
+ if (updatedEntity && pathSegments && !updatedEntity.pathSegments) {
90
+ updatedEntity = { ...updatedEntity, pathSegments };
91
+ }
71
92
  if (collection.callbacks?.onFetch && updatedEntity) {
72
93
  try {
73
94
  updatedEntity = await collection.callbacks.onFetch({
74
95
  collection,
75
96
  path,
97
+ pathSegments,
76
98
  entity: updatedEntity,
77
99
  context
78
100
  });
@@ -80,7 +102,7 @@ export function useEntityFetch<M extends Record<string, any>, USER extends User>
80
102
  console.error(e);
81
103
  }
82
104
  }
83
- CACHE[`${path}/${entityId}`] = updatedEntity;
105
+ CACHE[entityCacheKey(path, entityId)] = updatedEntity;
84
106
  setEntity(updatedEntity);
85
107
  setDataLoading(false);
86
108
  setDataLoadingError(undefined);
@@ -93,8 +115,8 @@ export function useEntityFetch<M extends Record<string, any>, USER extends User>
93
115
  setDataLoadingError(error);
94
116
  };
95
117
 
96
- if (entityId && useCache && CACHE[`${path}/${entityId}`]) {
97
- setEntity(CACHE[`${path}/${entityId}`]);
118
+ if (entityId && useCache && CACHE[entityCacheKey(path, entityId)]) {
119
+ setEntity(CACHE[entityCacheKey(path, entityId)]);
98
120
  setDataLoading(false);
99
121
  setDataLoadingError(undefined);
100
122
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -14,6 +14,7 @@ export * from "./useDialogsController";
14
14
  export * from "./useSideDialogsController";
15
15
  export * from "./useSideEntityController";
16
16
  export * from "./useFireCMSContext";
17
+ export * from "./useAnalyticsController";
17
18
  export * from "./useSnackbarController";
18
19
  export * from "./useModeController";
19
20
  export * from "./useClipboard";
@@ -32,3 +33,4 @@ export * from "./useBuildModeController";
32
33
 
33
34
  export * from "./useValidateAuthenticator";
34
35
  export * from "./useTranslation";
36
+ export * from "./useLicenseStatus";
@@ -1,6 +1,8 @@
1
- import { useCallback, useEffect, useRef, useState } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
2
  import equal from "react-fast-compare"
3
3
  import { useBlocker, useNavigate } from "react-router-dom";
4
+ import { filterPausedPlugins, isProPaused } from "../core/pro_plugins";
5
+ import { useLicenseStatus } from "./useLicenseStatus";
4
6
 
5
7
  import {
6
8
  AuthController,
@@ -22,11 +24,14 @@ import {
22
24
  } from "../types";
23
25
  import {
24
26
  applyPermissionsFunctionIfEmpty,
27
+ collectionSegmentsFrom,
28
+ fullPathToCollectionSegments,
25
29
  getCollectionByPathOrId,
26
30
  mergeDeep,
27
31
  removeFunctions,
28
32
  removeInitialAndTrailingSlashes,
29
33
  resolveCollectionPathIds,
34
+ resolveCollectionPathSegments,
30
35
  resolvePermissions
31
36
  } from "../util";
32
37
  import { getParentReferencesFromPath } from "../util/parent_references_from_path";
@@ -112,7 +117,7 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
112
117
  views: viewsProp,
113
118
  adminViews: adminViewsProp,
114
119
  viewsOrder,
115
- plugins,
120
+ plugins: allPlugins,
116
121
  userConfigPersistence,
117
122
  dataSourceDelegate,
118
123
  disabled,
@@ -121,6 +126,27 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
121
126
 
122
127
  const navigate = useNavigate();
123
128
 
129
+ // While PRO is paused, PRO plugins contribute no collections, collection
130
+ // modifications, views or navigation entries. This hook runs above
131
+ // `FireCMS`, so the status arrives through the store `FireCMS` publishes to,
132
+ // and its arrival re-renders this hook, which resolves navigation again.
133
+ const licenseStatus = useLicenseStatus();
134
+ const proPaused = isProPaused(licenseStatus);
135
+ const plugins = useMemo(
136
+ () => filterPausedPlugins(allPlugins, licenseStatus),
137
+ [allPlugins, licenseStatus]
138
+ );
139
+
140
+ // Navigation resolves asynchronously, so a resolution started before the
141
+ // pause changed can finish after one started since. This ref holds the
142
+ // current pause so the older one is dropped instead of restoring what the
143
+ // paused plugins contributed. Declared before the effect that refreshes.
144
+ const proPausedRef = useRef(proPaused);
145
+ useEffect(() => {
146
+ proPausedRef.current = proPaused;
147
+ }, [proPaused]);
148
+ const resolvedProPausedRef = useRef<boolean | undefined>(undefined);
149
+
124
150
  const collectionsRef = useRef<EntityCollection[] | undefined>(undefined);
125
151
  const viewsRef = useRef<CMSView[] | undefined>(undefined);
126
152
  const adminViewsRef = useRef<CMSView[] | undefined>(undefined);
@@ -299,7 +325,7 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
299
325
  groups: uniqueGroups,
300
326
  onNavigationEntriesUpdate: onNavigationEntriesUpdateCallback!,
301
327
  };
302
- }, [navigationGroupMappings, buildCMSUrlPath, buildUrlCollectionPath, pluginGroups]);
328
+ }, [navigationGroupMappings, buildCMSUrlPath, buildUrlCollectionPath, pluginGroups, plugins]);
303
329
 
304
330
  const onNavigationEntriesOrderUpdate = useCallback((entries: NavigationGroupMapping[]) => {
305
331
  if (!plugins) {
@@ -339,6 +365,8 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
339
365
 
340
366
  console.debug("Refreshing navigation");
341
367
 
368
+ const resolvingWhilePaused = proPaused;
369
+
342
370
  try {
343
371
 
344
372
  const [resolvedCollections = [], resolvedViews, resolvedAdminViews = []] = await Promise.all([
@@ -348,10 +376,21 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
348
376
  ]
349
377
  );
350
378
 
379
+ // Superseded: a newer resolution runs with the current pause.
380
+ if (resolvingWhilePaused !== proPausedRef.current)
381
+ return;
382
+
351
383
  const computedTopLevelNav = computeTopNavigation(resolvedCollections, resolvedViews, resolvedAdminViews, viewsOrder, undefined, onNavigationEntriesOrderUpdate);
352
384
 
353
- let shouldUpdateTopLevelNav = false;
354
- if (!areCollectionListsEqual(collectionsRef.current ?? [], resolvedCollections)) {
385
+ // When the pause changes, everything below is replaced, including
386
+ // what the comparisons ignore: they skip functions, and a plugin may
387
+ // have added only collection callbacks, or only regrouped entries.
388
+ const pauseChanged = resolvedProPausedRef.current !== undefined
389
+ && resolvedProPausedRef.current !== resolvingWhilePaused;
390
+ resolvedProPausedRef.current = resolvingWhilePaused;
391
+
392
+ let shouldUpdateTopLevelNav = pauseChanged;
393
+ if (pauseChanged || !areCollectionListsEqual(collectionsRef.current ?? [], resolvedCollections)) {
355
394
  collectionsRef.current = resolvedCollections;
356
395
  console.debug("Collections have changed", resolvedCollections);
357
396
  shouldUpdateTopLevelNav = true;
@@ -360,7 +399,7 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
360
399
  collectionsRef.current = resolvedCollections;
361
400
  shouldUpdateTopLevelNav = true;
362
401
  }
363
- if (!equal(viewsRef.current, resolvedViews)) {
402
+ if (pauseChanged || !equal(viewsRef.current, resolvedViews)) {
364
403
  viewsRef.current = resolvedViews;
365
404
  shouldUpdateTopLevelNav = true;
366
405
  }
@@ -397,6 +436,8 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
397
436
  viewsProp,
398
437
  adminViewsProp,
399
438
  computeTopNavigation,
439
+ plugins,
440
+ proPaused
400
441
  ]);
401
442
 
402
443
  useEffect(() => {
@@ -405,13 +446,14 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
405
446
 
406
447
  const getCollection = useCallback((
407
448
  idOrPath: string,
408
- includeUserOverride = false
449
+ includeUserOverride = false,
450
+ pathSegments?: string[]
409
451
  ): EC | undefined => {
410
452
  const collections = collectionsRef.current;
411
453
  if (!collections)
412
454
  return undefined;
413
455
 
414
- const baseCollection = getCollectionByPathOrId(removeInitialAndTrailingSlashes(idOrPath), collections);
456
+ const baseCollection = getCollectionByPathOrId(removeInitialAndTrailingSlashes(idOrPath), collections, pathSegments);
415
457
 
416
458
  const userOverride = includeUserOverride ? userConfigPersistence?.getCollectionConfig(idOrPath) : undefined;
417
459
  let overriddenCollection = baseCollection;
@@ -505,23 +547,33 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
505
547
  throw Error("Expected path starting with " + fullCollectionPath);
506
548
  }, [fullCollectionPath]);
507
549
 
508
- const resolveIdsFrom = useCallback((path: string): string => {
550
+ const resolveIdsFrom = useCallback((path: string, pathSegments?: string[]): string => {
551
+ const collections = collectionsRef.current ?? [];
552
+ return resolveCollectionPathIds(path, collections, pathSegments);
553
+ }, []);
554
+
555
+ const resolveSegmentsFrom = useCallback((pathSegments: string[]): string[] => {
509
556
  const collections = collectionsRef.current ?? [];
510
- return resolveCollectionPathIds(path, collections);
557
+ return resolveCollectionPathSegments(pathSegments, collections);
511
558
  }, []);
512
559
 
513
- const getAllParentReferencesForPath = useCallback((path: string): EntityReference[] => {
560
+ const getAllParentReferencesForPath = useCallback((path: string, pathSegments?: string[]): EntityReference[] => {
514
561
  const collections = collectionsRef.current ?? [];
515
562
  return getParentReferencesFromPath({
516
563
  path,
564
+ pathSegments,
517
565
  collections
518
566
  });
519
567
  }, []);
520
568
 
521
- const getParentCollectionIds = useCallback((path: string): string[] => {
569
+ const getParentCollectionIds = useCallback((path: string, pathSegments?: string[]): string[] => {
522
570
 
523
- const strings = path.split("/");
524
- const oddPathSegments = strings.filter((_, i) => i % 2 === 0);
571
+ // Positional filtering only picks out the collection segments while no entity id
572
+ // contains "/"; with one, every following segment shifts. Given the real boundaries
573
+ // the same rule applies correctly; without them this is the historical reading.
574
+ const oddPathSegments = pathSegments
575
+ ? collectionSegmentsFrom(pathSegments)
576
+ : fullPathToCollectionSegments(path);
525
577
  oddPathSegments.pop();
526
578
 
527
579
  const result: string[][] = [];
@@ -567,13 +619,16 @@ export function useBuildNavigationController<EC extends EntityCollection, USER e
567
619
  urlPathToDataPath,
568
620
  buildUrlCollectionPath,
569
621
  resolveIdsFrom,
622
+ resolveSegmentsFrom,
570
623
  topLevelNavigation,
571
624
  refreshNavigation,
572
625
  getParentReferencesFromPath: getAllParentReferencesForPath,
573
626
  getParentCollectionIds,
574
627
  convertIdsToPaths,
575
628
  navigate,
576
- plugins
629
+ // All of them, paused or not: `FireCMS` sends every key to the license
630
+ // check and applies the same pause to what it renders.
631
+ plugins: allPlugins
577
632
  };
578
633
  }
579
634