@firecms/core 3.3.0 → 3.4.0-canary.00f9be5

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 (220) hide show
  1. package/README.md +4 -0
  2. package/dist/app/useApp.d.ts +1 -0
  3. package/dist/components/EntityCollectionTable/column_utils.d.ts +4 -3
  4. package/dist/components/EntityCollectionTable/internal/CollectionTableToolbar.d.ts +6 -1
  5. package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +3 -1
  6. package/dist/components/EntityCollectionView/EntityCollectionBoardView.d.ts +3 -1
  7. package/dist/components/EntityCollectionView/EntityCollectionView.d.ts +8 -0
  8. package/dist/components/EntityCollectionView/EntityCollectionViewActions.d.ts +3 -1
  9. package/dist/components/EntityCollectionView/EntityCollectionViewStartActions.d.ts +3 -1
  10. package/dist/components/EntityCollectionView/FiltersDialog.d.ts +2 -1
  11. package/dist/components/EntityCollectionView/useBoardDataController.d.ts +3 -1
  12. package/dist/components/EntityPreview.d.ts +3 -1
  13. package/dist/components/ErrorBoundary.d.ts +1 -3
  14. package/dist/components/LicenseBanner.d.ts +23 -0
  15. package/dist/components/ReferenceTable/ReferenceSelectionTable.d.ts +10 -1
  16. package/dist/components/SelectableTable/filters/filter_text_input.d.ts +30 -0
  17. package/dist/components/SelectableTable/filters/filter_text_input.test.d.ts +1 -0
  18. package/dist/components/common/table_url_params.d.ts +24 -0
  19. package/dist/components/common/useDataSourceTableController.d.ts +9 -1
  20. package/dist/components/common/useTableSearchHelper.d.ts +9 -1
  21. package/dist/components/index.d.ts +1 -0
  22. package/dist/contexts/LicenseStatusContext.d.ts +16 -0
  23. package/dist/core/DefaultDrawer.d.ts +10 -3
  24. package/dist/core/EntityEditView.d.ts +9 -1
  25. package/dist/core/EntityEditViewFormActions.d.ts +1 -1
  26. package/dist/core/field_configs.d.ts +1 -1
  27. package/dist/core/index.d.ts +1 -0
  28. package/dist/core/plugin_translations.d.ts +38 -0
  29. package/dist/core/pro_plugins.d.ts +40 -0
  30. package/dist/de-BF5vcQPY.js +703 -0
  31. package/dist/de-BF5vcQPY.js.map +1 -0
  32. package/dist/editor/extensions/Image.d.ts +11 -0
  33. package/dist/editor/index.d.ts +2 -1
  34. package/dist/editor/lazy_editor.d.ts +6 -0
  35. package/dist/editor-BSo_aS1I.js +4563 -0
  36. package/dist/editor-BSo_aS1I.js.map +1 -0
  37. package/dist/form/EntityForm.d.ts +8 -1
  38. package/dist/form/EntityFormActions.d.ts +2 -0
  39. package/dist/form/field_bindings/GeopointFieldBinding.d.ts +5 -0
  40. package/dist/form/index.d.ts +1 -0
  41. package/dist/fr-DH9_wyFI.js +703 -0
  42. package/dist/fr-DH9_wyFI.js.map +1 -0
  43. package/dist/hi-BM8dm1Lu.js +703 -0
  44. package/dist/hi-BM8dm1Lu.js.map +1 -0
  45. package/dist/hooks/data/delete.d.ts +1 -1
  46. package/dist/hooks/data/save.d.ts +1 -1
  47. package/dist/hooks/data/useCollectionFetch.d.ts +7 -1
  48. package/dist/hooks/data/useEntityFetch.d.ts +9 -1
  49. package/dist/hooks/index.d.ts +2 -0
  50. package/dist/hooks/useLicenseStatus.d.ts +16 -0
  51. package/dist/hooks/useProjectLog.d.ts +11 -6
  52. package/dist/hooks/useTranslation.d.ts +1 -1
  53. package/dist/i18n/__tests__/FireCMSi18nProvider.test.d.ts +1 -0
  54. package/dist/i18n/__tests__/nested_provider_lifecycle.test.d.ts +1 -0
  55. package/dist/index.es.js +4516 -10668
  56. package/dist/index.es.js.map +1 -1
  57. package/dist/index.umd.js +9403 -6774
  58. package/dist/index.umd.js.map +1 -1
  59. package/dist/it-D3K1gfe4.js +703 -0
  60. package/dist/it-D3K1gfe4.js.map +1 -0
  61. package/dist/locales/pl.d.ts +2 -0
  62. package/dist/pl-CP1zeLzn.js +705 -0
  63. package/dist/pl-CP1zeLzn.js.map +1 -0
  64. package/dist/preview/index.d.ts +1 -0
  65. package/dist/preview/property_previews/GeopointPropertyPreview.d.ts +4 -0
  66. package/dist/pt-Cus7eKQR.js +705 -0
  67. package/dist/pt-Cus7eKQR.js.map +1 -0
  68. package/dist/types/analytics.d.ts +1 -1
  69. package/dist/types/collections.d.ts +31 -0
  70. package/dist/types/datasource.d.ts +67 -4
  71. package/dist/types/entities.d.ts +21 -1
  72. package/dist/types/entity_actions.d.ts +6 -0
  73. package/dist/types/entity_callbacks.d.ts +21 -0
  74. package/dist/types/firecms.d.ts +18 -1
  75. package/dist/types/firecms_context.d.ts +8 -0
  76. package/dist/types/index.d.ts +1 -0
  77. package/dist/types/license.d.ts +55 -0
  78. package/dist/types/navigation.d.ts +34 -5
  79. package/dist/types/plugins.d.ts +22 -1
  80. package/dist/types/properties.d.ts +17 -1
  81. package/dist/types/side_entity_controller.d.ts +7 -0
  82. package/dist/types/translations.d.ts +43 -2
  83. package/dist/util/__tests__/collections.test.d.ts +1 -0
  84. package/dist/util/__tests__/urls.test.d.ts +1 -0
  85. package/dist/util/collections.d.ts +1 -1
  86. package/dist/util/date_fns_locales.d.ts +18 -0
  87. package/dist/util/entities.d.ts +1 -0
  88. package/dist/util/entity_cache.d.ts +11 -0
  89. package/dist/util/geopoint.d.ts +22 -0
  90. package/dist/util/index.d.ts +3 -0
  91. package/dist/util/lazy_eager.d.ts +3 -3
  92. package/dist/util/navigation_blocking.d.ts +22 -0
  93. package/dist/util/navigation_from_path.d.ts +17 -0
  94. package/dist/util/navigation_utils.d.ts +107 -3
  95. package/dist/util/parent_references_from_path.d.ts +16 -0
  96. package/dist/util/paths.d.ts +28 -0
  97. package/dist/util/permissions.d.ts +10 -4
  98. package/dist/util/urls.d.ts +22 -0
  99. package/package.json +17 -11
  100. package/src/app/Scaffold.tsx +41 -44
  101. package/src/app/useApp.tsx +1 -0
  102. package/src/components/DeleteEntityDialog.tsx +2 -0
  103. package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +2 -2
  104. package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +3 -1
  105. package/src/components/EntityCollectionTable/column_utils.tsx +11 -19
  106. package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +1 -1
  107. package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +7 -0
  108. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +5 -1
  109. package/src/components/EntityCollectionView/EntityCollectionBoardView.tsx +12 -0
  110. package/src/components/EntityCollectionView/EntityCollectionView.tsx +66 -15
  111. package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +6 -2
  112. package/src/components/EntityCollectionView/EntityCollectionViewStartActions.tsx +8 -1
  113. package/src/components/EntityCollectionView/FiltersDialog.tsx +39 -28
  114. package/src/components/EntityCollectionView/useBoardDataController.tsx +17 -1
  115. package/src/components/EntityPreview.tsx +45 -41
  116. package/src/components/ErrorBoundary.tsx +12 -18
  117. package/src/components/LicenseBanner.tsx +207 -0
  118. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +19 -2
  119. package/src/components/ReferenceWidget.tsx +1 -1
  120. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +2 -2
  121. package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +33 -7
  122. package/src/components/SelectableTable/filters/filter_text_input.test.ts +184 -0
  123. package/src/components/SelectableTable/filters/filter_text_input.ts +71 -0
  124. package/src/components/VirtualTable/VirtualTable.tsx +19 -8
  125. package/src/components/common/default_entity_actions.tsx +22 -2
  126. package/src/components/common/table_url_params.ts +172 -0
  127. package/src/components/common/useDataSourceTableController.tsx +126 -163
  128. package/src/components/common/useTableSearchHelper.ts +26 -2
  129. package/src/components/index.tsx +1 -0
  130. package/src/contexts/LicenseStatusContext.tsx +50 -0
  131. package/src/contexts/SnackbarProvider.tsx +14 -1
  132. package/src/core/DefaultAppBar.tsx +28 -16
  133. package/src/core/DefaultDrawer.tsx +150 -64
  134. package/src/core/DrawerNavigationGroup.tsx +27 -29
  135. package/src/core/DrawerNavigationItem.tsx +10 -12
  136. package/src/core/EntityEditView.tsx +77 -35
  137. package/src/core/EntityEditViewFormActions.tsx +3 -2
  138. package/src/core/EntitySidePanel.tsx +8 -4
  139. package/src/core/FireCMS.tsx +73 -47
  140. package/src/core/SideDialogs.tsx +44 -1
  141. package/src/core/field_configs.tsx +15 -0
  142. package/src/core/index.tsx +1 -0
  143. package/src/core/plugin_translations.ts +87 -0
  144. package/src/core/pro_plugins.ts +79 -0
  145. package/src/editor/components/SlashCommandMenu.tsx +4 -1
  146. package/src/editor/extensions/Image.ts +17 -1
  147. package/src/editor/hooks/useProseMirror.ts +5 -0
  148. package/src/editor/index.ts +11 -1
  149. package/src/editor/lazy_editor.tsx +33 -0
  150. package/src/form/EntityForm.tsx +31 -10
  151. package/src/form/EntityFormActions.tsx +2 -0
  152. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +1 -1
  153. package/src/form/field_bindings/GeopointFieldBinding.tsx +139 -0
  154. package/src/form/index.tsx +1 -0
  155. package/src/hooks/data/delete.ts +8 -0
  156. package/src/hooks/data/save.ts +6 -1
  157. package/src/hooks/data/useCollectionFetch.tsx +21 -1
  158. package/src/hooks/data/useEntityFetch.tsx +35 -4
  159. package/src/hooks/index.tsx +2 -0
  160. package/src/hooks/useBuildNavigationController.tsx +70 -15
  161. package/src/hooks/useFireCMSContext.tsx +7 -3
  162. package/src/hooks/useLicenseStatus.tsx +32 -0
  163. package/src/hooks/useProjectLog.tsx +27 -9
  164. package/src/hooks/useResolvedNavigationFrom.tsx +3 -1
  165. package/src/hooks/useTranslation.ts +3 -1
  166. package/src/hooks/useValidateAuthenticator.tsx +4 -0
  167. package/src/i18n/FireCMSi18nProvider.tsx +199 -23
  168. package/src/i18n/__tests__/FireCMSi18nProvider.test.tsx +91 -0
  169. package/src/i18n/__tests__/nested_provider_lifecycle.test.tsx +67 -0
  170. package/src/internal/useBuildDataSource.ts +37 -15
  171. package/src/internal/useBuildSideEntityController.tsx +20 -5
  172. package/src/locales/de.ts +26 -4
  173. package/src/locales/en.ts +30 -6
  174. package/src/locales/es.ts +26 -4
  175. package/src/locales/fr.ts +26 -4
  176. package/src/locales/hi.ts +26 -4
  177. package/src/locales/it.ts +26 -4
  178. package/src/locales/pl.ts +752 -0
  179. package/src/locales/pt.ts +26 -4
  180. package/src/preview/PropertyPreview.tsx +12 -0
  181. package/src/preview/components/DatePreview.tsx +2 -4
  182. package/src/preview/components/ReferencePreview.tsx +7 -3
  183. package/src/preview/components/StorageThumbnail.tsx +24 -2
  184. package/src/preview/index.ts +1 -0
  185. package/src/preview/property_previews/GeopointPropertyPreview.tsx +23 -0
  186. package/src/routes/FireCMSRoute.tsx +54 -27
  187. package/src/types/analytics.ts +3 -0
  188. package/src/types/collections.ts +34 -0
  189. package/src/types/datasource.ts +67 -4
  190. package/src/types/entities.ts +24 -1
  191. package/src/types/entity_actions.tsx +6 -0
  192. package/src/types/entity_callbacks.ts +24 -0
  193. package/src/types/firecms.tsx +19 -1
  194. package/src/types/firecms_context.tsx +9 -0
  195. package/src/types/index.ts +1 -0
  196. package/src/types/license.ts +63 -0
  197. package/src/types/navigation.ts +35 -5
  198. package/src/types/plugins.tsx +23 -1
  199. package/src/types/properties.ts +17 -0
  200. package/src/types/side_entity_controller.tsx +7 -0
  201. package/src/types/translations.ts +43 -2
  202. package/src/util/__tests__/collections.test.ts +32 -0
  203. package/src/util/__tests__/urls.test.ts +131 -0
  204. package/src/util/collections.ts +1 -1
  205. package/src/util/date_fns_locales.ts +168 -0
  206. package/src/util/entities.ts +16 -1
  207. package/src/util/entity_cache.ts +18 -0
  208. package/src/util/geopoint.ts +81 -0
  209. package/src/util/index.ts +3 -0
  210. package/src/util/lazy_eager.tsx +30 -8
  211. package/src/util/navigation_blocking.ts +45 -0
  212. package/src/util/navigation_from_path.ts +47 -7
  213. package/src/util/navigation_utils.ts +250 -5
  214. package/src/util/parent_references_from_path.ts +45 -4
  215. package/src/util/paths.ts +40 -3
  216. package/src/util/permissions.ts +22 -10
  217. package/src/util/previews.ts +8 -1
  218. package/src/util/resolutions.ts +8 -0
  219. package/src/util/urls.ts +52 -0
  220. package/src/util/useStorageUploadController.tsx +6 -1
@@ -0,0 +1,168 @@
1
+ import { useEffect, useReducer } from "react";
2
+ import type { Locale as DateFnsLocale } from "date-fns";
3
+ import { Locale } from "../types";
4
+
5
+ /**
6
+ * On-demand loading of date-fns locales.
7
+ *
8
+ * `import * as locales from "date-fns/locale"` pulls in every locale date-fns
9
+ * ships — 625KB of parsed JavaScript, loaded on every single page view, to
10
+ * support a `locale` setting that is unset for almost every project. Worse, it
11
+ * sat on the critical path: `@firecms/core` imported it statically, so the
12
+ * browser could not render anything until it had come down.
13
+ *
14
+ * Each locale now has its own dynamic import, so exactly one small chunk is
15
+ * fetched, and only when a project actually configures a locale. Projects that
16
+ * do not configure one (the default) pay nothing at all.
17
+ *
18
+ * The map is written out rather than built from a template literal because Vite
19
+ * and webpack both need the specifier to be statically analysable to emit the
20
+ * chunks.
21
+ */
22
+ const loaders: Partial<Record<Locale, () => Promise<DateFnsLocale>>> = {
23
+ af: () => import("date-fns/locale/af").then(m => m.af),
24
+ ar: () => import("date-fns/locale/ar").then(m => m.ar),
25
+ arDZ: () => import("date-fns/locale/ar-DZ").then(m => m.arDZ),
26
+ arMA: () => import("date-fns/locale/ar-MA").then(m => m.arMA),
27
+ arSA: () => import("date-fns/locale/ar-SA").then(m => m.arSA),
28
+ az: () => import("date-fns/locale/az").then(m => m.az),
29
+ be: () => import("date-fns/locale/be").then(m => m.be),
30
+ bg: () => import("date-fns/locale/bg").then(m => m.bg),
31
+ bn: () => import("date-fns/locale/bn").then(m => m.bn),
32
+ ca: () => import("date-fns/locale/ca").then(m => m.ca),
33
+ cs: () => import("date-fns/locale/cs").then(m => m.cs),
34
+ cy: () => import("date-fns/locale/cy").then(m => m.cy),
35
+ da: () => import("date-fns/locale/da").then(m => m.da),
36
+ de: () => import("date-fns/locale/de").then(m => m.de),
37
+ el: () => import("date-fns/locale/el").then(m => m.el),
38
+ enAU: () => import("date-fns/locale/en-AU").then(m => m.enAU),
39
+ enCA: () => import("date-fns/locale/en-CA").then(m => m.enCA),
40
+ enGB: () => import("date-fns/locale/en-GB").then(m => m.enGB),
41
+ enIN: () => import("date-fns/locale/en-IN").then(m => m.enIN),
42
+ enNZ: () => import("date-fns/locale/en-NZ").then(m => m.enNZ),
43
+ enUS: () => import("date-fns/locale/en-US").then(m => m.enUS),
44
+ eo: () => import("date-fns/locale/eo").then(m => m.eo),
45
+ es: () => import("date-fns/locale/es").then(m => m.es),
46
+ et: () => import("date-fns/locale/et").then(m => m.et),
47
+ eu: () => import("date-fns/locale/eu").then(m => m.eu),
48
+ faIR: () => import("date-fns/locale/fa-IR").then(m => m.faIR),
49
+ fi: () => import("date-fns/locale/fi").then(m => m.fi),
50
+ fr: () => import("date-fns/locale/fr").then(m => m.fr),
51
+ frCA: () => import("date-fns/locale/fr-CA").then(m => m.frCA),
52
+ frCH: () => import("date-fns/locale/fr-CH").then(m => m.frCH),
53
+ gd: () => import("date-fns/locale/gd").then(m => m.gd),
54
+ gl: () => import("date-fns/locale/gl").then(m => m.gl),
55
+ gu: () => import("date-fns/locale/gu").then(m => m.gu),
56
+ he: () => import("date-fns/locale/he").then(m => m.he),
57
+ hi: () => import("date-fns/locale/hi").then(m => m.hi),
58
+ hr: () => import("date-fns/locale/hr").then(m => m.hr),
59
+ hu: () => import("date-fns/locale/hu").then(m => m.hu),
60
+ hy: () => import("date-fns/locale/hy").then(m => m.hy),
61
+ id: () => import("date-fns/locale/id").then(m => m.id),
62
+ is: () => import("date-fns/locale/is").then(m => m.is),
63
+ it: () => import("date-fns/locale/it").then(m => m.it),
64
+ ja: () => import("date-fns/locale/ja").then(m => m.ja),
65
+ ka: () => import("date-fns/locale/ka").then(m => m.ka),
66
+ kk: () => import("date-fns/locale/kk").then(m => m.kk),
67
+ kn: () => import("date-fns/locale/kn").then(m => m.kn),
68
+ ko: () => import("date-fns/locale/ko").then(m => m.ko),
69
+ lb: () => import("date-fns/locale/lb").then(m => m.lb),
70
+ lt: () => import("date-fns/locale/lt").then(m => m.lt),
71
+ lv: () => import("date-fns/locale/lv").then(m => m.lv),
72
+ mk: () => import("date-fns/locale/mk").then(m => m.mk),
73
+ ms: () => import("date-fns/locale/ms").then(m => m.ms),
74
+ mt: () => import("date-fns/locale/mt").then(m => m.mt),
75
+ nb: () => import("date-fns/locale/nb").then(m => m.nb),
76
+ nl: () => import("date-fns/locale/nl").then(m => m.nl),
77
+ nlBE: () => import("date-fns/locale/nl-BE").then(m => m.nlBE),
78
+ nn: () => import("date-fns/locale/nn").then(m => m.nn),
79
+ pl: () => import("date-fns/locale/pl").then(m => m.pl),
80
+ pt: () => import("date-fns/locale/pt").then(m => m.pt),
81
+ ptBR: () => import("date-fns/locale/pt-BR").then(m => m.ptBR),
82
+ ro: () => import("date-fns/locale/ro").then(m => m.ro),
83
+ ru: () => import("date-fns/locale/ru").then(m => m.ru),
84
+ sk: () => import("date-fns/locale/sk").then(m => m.sk),
85
+ sl: () => import("date-fns/locale/sl").then(m => m.sl),
86
+ sr: () => import("date-fns/locale/sr").then(m => m.sr),
87
+ srLatn: () => import("date-fns/locale/sr-Latn").then(m => m.srLatn),
88
+ sv: () => import("date-fns/locale/sv").then(m => m.sv),
89
+ ta: () => import("date-fns/locale/ta").then(m => m.ta),
90
+ te: () => import("date-fns/locale/te").then(m => m.te),
91
+ th: () => import("date-fns/locale/th").then(m => m.th),
92
+ tr: () => import("date-fns/locale/tr").then(m => m.tr),
93
+ ug: () => import("date-fns/locale/ug").then(m => m.ug),
94
+ uk: () => import("date-fns/locale/uk").then(m => m.uk),
95
+ uz: () => import("date-fns/locale/uz").then(m => m.uz),
96
+ vi: () => import("date-fns/locale/vi").then(m => m.vi),
97
+ zhCN: () => import("date-fns/locale/zh-CN").then(m => m.zhCN),
98
+ zhTW: () => import("date-fns/locale/zh-TW").then(m => m.zhTW),
99
+ };
100
+
101
+ const cache = new Map<Locale, DateFnsLocale>();
102
+ const inFlight = new Map<Locale, Promise<DateFnsLocale | undefined>>();
103
+
104
+ /**
105
+ * Load a date-fns locale, resolving from cache when it is already in memory.
106
+ * Concurrent callers for the same locale share one request.
107
+ */
108
+ export function loadDateFnsLocale(locale: Locale): Promise<DateFnsLocale | undefined> {
109
+ const cached = cache.get(locale);
110
+ if (cached) {
111
+ return Promise.resolve(cached);
112
+ }
113
+ const pending = inFlight.get(locale);
114
+ if (pending) {
115
+ return pending;
116
+ }
117
+ const loader = loaders[locale];
118
+ if (!loader) {
119
+ // An unknown key behaves as it did when the whole barrel was imported:
120
+ // the lookup missed and date-fns fell back to its built-in English.
121
+ return Promise.resolve(undefined);
122
+ }
123
+ const promise = loader()
124
+ .then((loaded) => {
125
+ cache.set(locale, loaded);
126
+ return loaded;
127
+ })
128
+ .catch(() => undefined)
129
+ .finally(() => {
130
+ inFlight.delete(locale);
131
+ });
132
+ inFlight.set(locale, promise);
133
+ return promise;
134
+ }
135
+
136
+ /** The locale if it is already loaded, otherwise undefined. Never suspends. */
137
+ export function getLoadedDateFnsLocale(locale?: Locale): DateFnsLocale | undefined {
138
+ return locale ? cache.get(locale) : undefined;
139
+ }
140
+
141
+ /**
142
+ * The date-fns locale for `locale`, loading it in the background on first use.
143
+ *
144
+ * Returns undefined until the chunk arrives, which formats the first paint with
145
+ * date-fns' built-in English and then re-renders. That is a change only for
146
+ * projects that set a locale, and only for the few hundred milliseconds before
147
+ * the chunk lands — in exchange for every project no longer waiting on 625KB.
148
+ */
149
+ export function useDateFnsLocale(locale?: Locale): DateFnsLocale | undefined {
150
+ const [, forceUpdate] = useReducer((count: number) => count + 1, 0);
151
+
152
+ useEffect(() => {
153
+ if (!locale || cache.has(locale)) {
154
+ return;
155
+ }
156
+ let active = true;
157
+ loadDateFnsLocale(locale).then((loaded) => {
158
+ if (active && loaded) {
159
+ forceUpdate();
160
+ }
161
+ });
162
+ return () => {
163
+ active = false;
164
+ };
165
+ }, [locale]);
166
+
167
+ return locale ? cache.get(locale) : undefined;
168
+ }
@@ -75,6 +75,8 @@ export function getDefaultValueForDataType(dataType: DataType) {
75
75
  return [];
76
76
  } else if (dataType === "map") {
77
77
  return {};
78
+ } else if (dataType === "geopoint") {
79
+ return null;
78
80
  } else {
79
81
  return null;
80
82
  }
@@ -137,7 +139,12 @@ export function sanitizeData<M extends Record<string, any>>
137
139
  }
138
140
 
139
141
  export function getReferenceFrom<M extends Record<string, any>>(entity: Entity<M>): EntityReference {
140
- return new EntityReference(entity.id, entity.path, entity.databaseId);
142
+ if (!entity) {
143
+ throw new Error("getReferenceFrom: entity is null or undefined");
144
+ }
145
+ // Carry the segments the entity was loaded with, so a reference to an entity under a
146
+ // slash-bearing parent stays resolvable. Undefined when the entity does not have them.
147
+ return new EntityReference(entity.id, entity.path, entity.databaseId, entity.pathSegments);
141
148
  }
142
149
 
143
150
  export function traverseValuesProperties<M extends Record<string, any>>(
@@ -196,3 +203,11 @@ export function traverseValueProperty(inputValue: any,
196
203
 
197
204
  return value;
198
205
  }
206
+
207
+ export function isDataTypeFilterable(dataType: DataType, isPartOfArray = false) {
208
+ if (isPartOfArray) {
209
+ return ["string", "number", "date", "reference"].includes(dataType);
210
+ }
211
+
212
+ return ["string", "number", "boolean", "date", "reference", "array"].includes(dataType);
213
+ }
@@ -1,5 +1,23 @@
1
1
  import { EntityReference, GeoPoint, Vector } from "../types";
2
2
  import { isObject, isPlainObject } from "./objects";
3
+ import { encodeEntityId } from "./navigation_utils";
4
+
5
+ /**
6
+ * Key identifying one entity in a cache.
7
+ *
8
+ * The id is escaped so that a `(path, entityId)` pair maps to exactly one key. Without it
9
+ * `("a", "b/c")` and `("a/b", "c")` both flatten to `"a/b/c"`, and one entity's cached
10
+ * values are served for the other.
11
+ *
12
+ * `encodeEntityId` is the identity for any id without "/", "?", "#" or "%", so this changes
13
+ * no key in an app whose ids cannot contain them.
14
+ */
15
+ export function entityCacheKey(path: string | undefined, entityId: string | undefined): string {
16
+ // Either part may be undefined at a call site that used to build the key by string
17
+ // concatenation; both are stringified exactly as `path + "/" + entityId` did, so such a
18
+ // caller keeps the key it had.
19
+ return `${path}/${entityId === undefined ? entityId : encodeEntityId(entityId)}`;
20
+ }
3
21
 
4
22
  // Define a unique prefix for entity keys in localStorage to avoid key collisions
5
23
  const LOCAL_STORAGE_PREFIX = "entity_cache::";
@@ -0,0 +1,81 @@
1
+ import { GeoPoint } from "../types";
2
+
3
+ export type GeoPointLike = GeoPoint | {
4
+ latitude?: number;
5
+ longitude?: number;
6
+ lat?: number;
7
+ lng?: number;
8
+ _lat?: number;
9
+ _long?: number;
10
+ } | null | undefined;
11
+
12
+ export interface GeoPointCoordinates {
13
+ latitude: number;
14
+ longitude: number;
15
+ }
16
+
17
+ function toNumber(value: any): number | undefined {
18
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
19
+ }
20
+
21
+ export function getGeoPointCoordinates(value: GeoPointLike): GeoPointCoordinates | undefined {
22
+ if (!value) return undefined;
23
+ if (value instanceof GeoPoint) {
24
+ return { latitude: value.latitude, longitude: value.longitude };
25
+ }
26
+ if (typeof value !== "object") return undefined;
27
+
28
+ const latitude = toNumber((value as any).latitude ?? (value as any).lat ?? (value as any)._lat);
29
+ const longitude = toNumber((value as any).longitude ?? (value as any).lng ?? (value as any)._long);
30
+
31
+ if (latitude === undefined || longitude === undefined) return undefined;
32
+
33
+ return { latitude, longitude };
34
+ }
35
+
36
+ export function normalizeGeoPoint(value: GeoPointLike): GeoPoint | undefined {
37
+ const coordinates = getGeoPointCoordinates(value);
38
+ if (!coordinates) return undefined;
39
+ if (value instanceof GeoPoint) return value;
40
+ return new GeoPoint(coordinates.latitude, coordinates.longitude);
41
+ }
42
+
43
+ export function formatGeoPoint(value: GeoPointLike, options?: { maximumFractionDigits?: number }): string {
44
+ const coordinates = getGeoPointCoordinates(value);
45
+ if (!coordinates) return "";
46
+
47
+ const maximumFractionDigits = options?.maximumFractionDigits ?? 6;
48
+ // Coordinates are always formatted with a dot as decimal separator, independently of the
49
+ // user locale. Locale-aware formatting would use a comma in locales such as de or fr,
50
+ // making the "lat, lng" output ambiguous and impossible to parse back.
51
+ const formatter = new Intl.NumberFormat("en-US", {
52
+ maximumFractionDigits,
53
+ minimumFractionDigits: Math.min(2, maximumFractionDigits),
54
+ useGrouping: false
55
+ });
56
+
57
+ return `${formatter.format(coordinates.latitude)}, ${formatter.format(coordinates.longitude)}`;
58
+ }
59
+
60
+ export function parseGeoPoint(input: string): { point: GeoPoint | null; error?: string } {
61
+ const trimmed = input.trim();
62
+ if (!trimmed) return { point: null };
63
+
64
+ const parts = trimmed.split(",").map((part) => part.trim()).filter((part) => part !== "");
65
+ if (parts.length !== 2) return { point: null, error: "Use \"lat, lng\" format" };
66
+
67
+ const latitude = parseFloat(parts[0]);
68
+ const longitude = parseFloat(parts[1]);
69
+
70
+ if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
71
+ return { point: null, error: "Latitude and longitude must be numbers" };
72
+ }
73
+ if (latitude < -90 || latitude > 90) {
74
+ return { point: null, error: "Latitude must be between -90 and 90" };
75
+ }
76
+ if (longitude < -180 || longitude > 180) {
77
+ return { point: null, error: "Longitude must be between -180 and 180" };
78
+ }
79
+
80
+ return { point: new GeoPoint(latitude, longitude) };
81
+ }
package/src/util/index.ts CHANGED
@@ -6,12 +6,14 @@ export * from "./enums";
6
6
  export * from "./objects";
7
7
  export * from "./paths";
8
8
  export * from "./regexp";
9
+ export * from "./urls";
9
10
  export * from "./navigation_utils";
10
11
  export * from "./entity_actions";
11
12
  export * from "./useDebouncedCallback";
12
13
  export * from "./property_utils";
13
14
  export * from "./resolutions";
14
15
  export * from "./permissions";
16
+ export * from "./geopoint";
15
17
  export * from "./icon_list";
16
18
  export * from "./icon_synonyms";
17
19
  export * from "./icons";
@@ -26,3 +28,4 @@ export * from "./storage";
26
28
  export * from "./callbacks";
27
29
  export * from "./conditions";
28
30
  export * from "./lazy_eager";
31
+ export * from "./date_fns_locales";
@@ -1,9 +1,35 @@
1
1
  import React from "react";
2
2
 
3
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.
4
+ * Prefetch after the page has loaded, never during it.
5
+ *
6
+ * An idle callback scheduled at module evaluation time fires in the gaps between
7
+ * the tasks of the initial load — which is exactly when the critical chunks are
8
+ * still in flight. With a dozen route components each queueing one, the
9
+ * background prefetch was competing with the render path for connections and
10
+ * bandwidth. Waiting for the load event costs the prefetch nothing that matters:
11
+ * it exists to be ready before a navigation, not before first paint.
12
+ */
13
+ function schedulePrefetch(load: () => void) {
14
+ const whenIdle = () => {
15
+ if ("requestIdleCallback" in window) {
16
+ (window as any).requestIdleCallback(load);
17
+ } else {
18
+ setTimeout(load, 500);
19
+ }
20
+ };
21
+
22
+ if (document.readyState === "complete") {
23
+ whenIdle();
24
+ } else {
25
+ window.addEventListener("load", whenIdle, { once: true });
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Returns a React.lazy component that is also preloaded in the background, once
31
+ * the page has finished loading.
32
+ * This ensures that chunks are split, but fetched before they are actually needed.
7
33
  */
8
34
  export function lazyEager<T extends React.ComponentType<any>>(
9
35
  factory: () => Promise<any>,
@@ -22,11 +48,7 @@ export function lazyEager<T extends React.ComponentType<any>>(
22
48
  };
23
49
 
24
50
  if (typeof window !== "undefined") {
25
- if ("requestIdleCallback" in window) {
26
- (window as any).requestIdleCallback(load);
27
- } else {
28
- setTimeout(load, 500);
29
- }
51
+ schedulePrefetch(load);
30
52
  }
31
53
 
32
54
  return React.lazy(load);
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Pure predicate deciding whether an in-progress navigation away from an open
3
+ * entity form should be blocked (to warn about unsaved changes).
4
+ *
5
+ * Extracted from FireCMSRoute so the branching can be unit-tested without
6
+ * mounting the router. This is an internal helper — it is intentionally not
7
+ * re-exported from the package index.
8
+ */
9
+ export interface NavigationBlockLocation {
10
+ pathname: string;
11
+ hash: string;
12
+ }
13
+
14
+ const SIDE_PANEL_HASHES = ["#side", "#new_side"];
15
+
16
+ export function shouldBlockEntityNavigation(params: {
17
+ currentLocation: NavigationBlockLocation;
18
+ nextLocation: NavigationBlockLocation;
19
+ /** Path of the currently open entity (basePath + "/" + entityId). */
20
+ entityPath: string;
21
+ /** Collection path the entity form lives under. */
22
+ basePath: string;
23
+ /** Whether the form currently has unsaved modifications. */
24
+ blocked: boolean;
25
+ }): boolean {
26
+ const { currentLocation, nextLocation, entityPath, basePath, blocked } = params;
27
+
28
+ // Navigating deeper within the same entity — never block.
29
+ if (nextLocation.pathname.startsWith(entityPath))
30
+ return false;
31
+
32
+ // Side panel overlay navigations preserve the underlying form via
33
+ // base_location in router state — no data is lost in either direction.
34
+
35
+ // Opening a side panel (e.g. clicking a relation/reference arrow).
36
+ if (SIDE_PANEL_HASHES.includes(nextLocation.hash))
37
+ return false;
38
+
39
+ // Closing a side panel (navigate(-1) back to the form's own path).
40
+ if (SIDE_PANEL_HASHES.includes(currentLocation.hash) &&
41
+ nextLocation.pathname === basePath)
42
+ return false;
43
+
44
+ return blocked;
45
+ }
@@ -1,5 +1,5 @@
1
1
  import { EntityCollection, EntityCustomView } from "../types";
2
- import { getCollectionPathsCombinations, removeInitialAndTrailingSlashes } from "./navigation_utils";
2
+ import { decodeEntityId, getCollectionPathsCombinations, removeInitialAndTrailingSlashes } from "./navigation_utils";
3
3
  import { resolveEntityView } from "./resolutions";
4
4
 
5
5
  export type NavigationViewInternal<M extends Record<string, any> = any> =
@@ -13,6 +13,8 @@ export interface NavigationViewEntityInternal<M extends Record<string, any>> {
13
13
  path: string;
14
14
  fullIdPath: string;
15
15
  fullPath: string;
16
+ /** `path` split at its real boundaries — see `pathSegments` on the datasource props. */
17
+ pathSegments: string[];
16
18
  parentCollection: EntityCollection<M>;
17
19
  }
18
20
 
@@ -22,6 +24,8 @@ export interface NavigationViewCollectionInternal<M extends Record<string, any>>
22
24
  path: string;
23
25
  fullIdPath: string;
24
26
  fullPath: string;
27
+ /** `path` split at its real boundaries — see `pathSegments` on the datasource props. */
28
+ pathSegments: string[];
25
29
  collection: EntityCollection<M>;
26
30
  }
27
31
 
@@ -30,15 +34,28 @@ export interface NavigationViewEntityCustomInternal<M extends Record<string, any
30
34
  path: string;
31
35
  fullIdPath: string;
32
36
  fullPath: string;
37
+ /** `path` split at its real boundaries — see `pathSegments` on the datasource props. */
38
+ pathSegments: string[];
33
39
  entityId: string;
34
40
  view: EntityCustomView<M>;
35
41
  }
36
42
 
43
+ /**
44
+ * Note on encoding: `path` arrives from the URL, so any entity id in it is escaped (see
45
+ * `encodeEntityId`). Two chains are threaded through the recursion:
46
+ *
47
+ * - `currentFullPath` carries RAW ids and feeds the `path` / `fullPath` used to address
48
+ * the datasource.
49
+ * - `currentFullUrlPath` carries ESCAPED ids and feeds `fullPath`, which is handed back
50
+ * to `buildUrlCollectionPath` for breadcrumbs and links.
51
+ */
37
52
  export function getNavigationEntriesFromPath(props: {
38
53
  path: string,
39
54
  collections: EntityCollection[] | undefined,
40
55
  currentFullPath?: string,
41
56
  currentFullIdPath?: string,
57
+ currentFullUrlPath?: string,
58
+ currentPathSegments?: string[],
42
59
  contextEntityViews?: EntityCustomView<any>[]
43
60
  }): NavigationViewInternal [] {
44
61
 
@@ -46,7 +63,9 @@ export function getNavigationEntriesFromPath(props: {
46
63
  path,
47
64
  collections = [],
48
65
  currentFullPath,
49
- currentFullIdPath
66
+ currentFullIdPath,
67
+ currentFullUrlPath,
68
+ currentPathSegments = []
50
69
  } = props;
51
70
 
52
71
  const subpaths = removeInitialAndTrailingSlashes(path).split("/");
@@ -66,28 +85,41 @@ export function getNavigationEntriesFromPath(props: {
66
85
  const collectionPath = currentFullPath && currentFullPath.length > 0
67
86
  ? (currentFullPath + "/" + collection.path)
68
87
  : collection.path;
88
+ const collectionUrlPath = currentFullUrlPath && currentFullUrlPath.length > 0
89
+ ? (currentFullUrlPath + "/" + collection.path)
90
+ : collection.path;
69
91
  const fullIdPath = currentFullIdPath && currentFullIdPath.length > 0
70
92
  ? (currentFullIdPath + "/" + collection.id)
71
93
  : collection.id;
94
+ // A collection `path` may itself span several segments (e.g. "users/uid/experiences"),
95
+ // and those are unambiguous, so they are spread rather than kept whole.
96
+ const collectionSegments = [...currentPathSegments, ...collection.path.split("/")];
72
97
  result.push({
73
98
  type: "collection",
74
99
  id: collection.id,
75
100
  path: collectionPath,
76
- fullPath: collectionPath,
101
+ fullPath: collectionUrlPath,
77
102
  fullIdPath,
103
+ pathSegments: collectionSegments,
78
104
  collection
79
105
  });
80
106
  const restOfThePath = removeInitialAndTrailingSlashes(removeInitialAndTrailingSlashes(path).replace(subpathCombination, ""));
81
107
  const nextSegments = restOfThePath.length > 0 ? restOfThePath.split("/") : [];
82
108
  if (nextSegments.length > 0) {
83
- const entityId = nextSegments[0];
109
+ const encodedEntityId = nextSegments[0];
110
+ const entityId = decodeEntityId(encodedEntityId);
84
111
  const fullPath = collectionPath + "/" + entityId;
112
+ const fullUrlPath = collectionUrlPath + "/" + encodedEntityId;
113
+ // The id is ONE segment however many slashes it contains — that is the
114
+ // whole point of this array.
115
+ const entitySegments = [...collectionSegments, entityId];
85
116
  result.push({
86
117
  type: "entity",
87
118
  entityId,
88
119
  path: collectionPath,
89
120
  fullIdPath,
90
- fullPath: fullPath,
121
+ fullPath: fullUrlPath,
122
+ pathSegments: collectionSegments,
91
123
  parentCollection: collection
92
124
  });
93
125
  if (nextSegments.length > 1) {
@@ -106,7 +138,8 @@ export function getNavigationEntriesFromPath(props: {
106
138
  path: collectionPath,
107
139
  entityId: entityId,
108
140
  fullIdPath,
109
- fullPath: fullPath + "/" + customView.key,
141
+ fullPath: fullUrlPath + "/" + customView.key,
142
+ pathSegments: collectionSegments,
110
143
  view: customView
111
144
  });
112
145
  } else if (collection.subcollections) {
@@ -114,7 +147,14 @@ export function getNavigationEntriesFromPath(props: {
114
147
  path: newPath,
115
148
  collections: collection.subcollections,
116
149
  currentFullPath: fullPath,
117
- currentFullIdPath: fullIdPath,
150
+ // The entity id is a hop in the id chain exactly as it is in the
151
+ // other two. Without it a nested `fullIdPath` was
152
+ // "products/locales" rather than "products/pid/locales", so any
153
+ // URL built from it pointed at a collection that does not exist.
154
+ // Escaped, because `fullIdPath` is URL-facing.
155
+ currentFullIdPath: fullIdPath + "/" + encodedEntityId,
156
+ currentFullUrlPath: fullUrlPath,
157
+ currentPathSegments: entitySegments,
118
158
  contextEntityViews: props.contextEntityViews
119
159
  }));
120
160
  }