@rebasepro/cms 0.25.1 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js +1 -1
- package/dist/collection_editor/ui/collection_editor/AICollectionGeneratorPopover.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.d.ts +7 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +9 -2
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
- package/dist/collection_editor/useLiveSchemaEditing.js +4 -1
- package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/EntityTableCell.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/EntityTableCell.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +2 -28
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.d.ts +12 -0
- package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.js +33 -0
- package/dist/components/CollectionViewBinding/DefaultCollectionEmptyState.js.map +1 -0
- package/dist/components/CollectionsScopeContext.d.ts +5 -1
- package/dist/components/CollectionsScopeContext.js +10 -2
- package/dist/components/CollectionsScopeContext.js.map +1 -1
- package/dist/components/DefaultAppBar.js +2 -1
- package/dist/components/DefaultAppBar.js.map +1 -1
- package/dist/components/DefaultDrawer.js +19 -6
- package/dist/components/DefaultDrawer.js.map +1 -1
- package/dist/components/DefaultMissingReference.d.ts +8 -0
- package/dist/components/DefaultMissingReference.js +13 -0
- package/dist/components/DefaultMissingReference.js.map +1 -0
- package/dist/components/EntityFormPanel.d.ts +7 -2
- package/dist/components/EntityFormPanel.js +72 -29
- package/dist/components/EntityFormPanel.js.map +1 -1
- package/dist/components/HomePage/ContentHomePage.js +7 -5
- package/dist/components/HomePage/ContentHomePage.js.map +1 -1
- package/dist/components/HomePage/HomePageDnD.js +3 -1
- package/dist/components/HomePage/HomePageDnD.js.map +1 -1
- package/dist/components/HomePage/SmallNavigationCard.js +25 -0
- package/dist/components/HomePage/SmallNavigationCard.js.map +1 -0
- package/dist/components/RebaseAuthGate.js +3 -2
- package/dist/components/RebaseAuthGate.js.map +1 -1
- package/dist/components/RebaseLayout.d.ts +4 -1
- package/dist/components/RebaseLayout.js +7 -1
- package/dist/components/RebaseLayout.js.map +1 -1
- package/dist/components/RebaseShell.d.ts +4 -1
- package/dist/components/RebaseShell.js.map +1 -1
- package/dist/components/SideDialogs.js +10 -4
- package/dist/components/SideDialogs.js.map +1 -1
- package/dist/components/app/Scaffold.js +5 -1
- package/dist/components/app/Scaffold.js.map +1 -1
- package/dist/components/field_configs.js +1 -1
- package/dist/components/history/EntityHistoryView.js +6 -4
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/components/history/LastEditedByIndicator.d.ts +2 -1
- package/dist/data_export/export/export.d.ts +2 -13
- package/dist/data_export/export/export.js +1 -36
- package/dist/data_export/export/export.js.map +1 -1
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/EntityForm.js +17 -13
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormBinding.d.ts +1 -1
- package/dist/form/EntityFormBinding.js +42 -4
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/PropertyFieldBinding.js +1 -1
- package/dist/form/components/FieldBlock.d.ts +8 -1
- package/dist/form/components/FieldBlock.js +16 -2
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FormSections.js +1 -1
- package/dist/form/components/FormSections.js.map +1 -1
- package/dist/form/components/LabelWithIcon.js +5 -2
- package/dist/form/components/LabelWithIcon.js.map +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js +2 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js +28 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +7 -3
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js +63 -42
- package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js +2 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/TextFieldBinding.js +8 -6
- package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
- package/dist/form/form_utils.d.ts +18 -1
- package/dist/form/form_utils.js +38 -2
- package/dist/form/form_utils.js.map +1 -1
- package/dist/form/index.d.ts +1 -1
- package/dist/form/label_placement.d.ts +23 -0
- package/dist/form/label_placement.js +71 -0
- package/dist/form/label_placement.js.map +1 -0
- package/dist/form/resolve_form_properties.d.ts +35 -3
- package/dist/form/resolve_form_properties.js +67 -6
- package/dist/form/resolve_form_properties.js.map +1 -1
- package/dist/hooks/useHistory.d.ts +5 -0
- package/dist/hooks/useHistory.js +22 -6
- package/dist/hooks/useHistory.js.map +1 -1
- package/dist/index.d.ts +50 -0
- package/dist/index.js +34 -7
- package/dist/preview/components/ReferencePreview.js +1 -1
- package/dist/preview/components/ReferencePreview.js.map +1 -1
- package/dist/preview/components/RelationPreview.js +1 -1
- package/dist/preview/components/RelationPreview.js.map +1 -1
- package/dist/types/components/EntityFormProps.d.ts +11 -0
- package/package.json +11 -10
- package/recipes/README.md +131 -0
- package/recipes/bulk-set-status.tsx +62 -0
- package/recipes/calendar-view.tsx +123 -0
- package/recipes/custom-login.tsx +60 -0
- package/recipes/my-preferences.tsx +68 -0
- package/recipes/orders-dashboard.tsx +125 -0
- package/recipes/site-settings.tsx +63 -0
package/dist/hooks/useHistory.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { useApiBase, useApiConfig } from "@rebasepro/app";
|
|
2
|
+
import { useApiBase, useApiConfig, useRlsSimulation } from "@rebasepro/app";
|
|
3
|
+
import { simulationHeaders } from "@rebasepro/types";
|
|
3
4
|
//#region src/hooks/useHistory.ts
|
|
4
5
|
/**
|
|
5
6
|
* Hook to fetch entity history from the backend REST API.
|
|
6
7
|
* Replaces the old subcollection-based approach with a proper API call.
|
|
8
|
+
*
|
|
9
|
+
* While access is simulated ("Simulate access") every request carries the
|
|
10
|
+
* simulation, as the data views' `client.simulate()` does: the history is read
|
|
11
|
+
* as the simulated identity, and the server refuses a revert as the simulated
|
|
12
|
+
* write it would be.
|
|
7
13
|
*/
|
|
8
14
|
function useHistory(params) {
|
|
9
15
|
const { slug, entityId, enabled = true, pageSize = 10, refreshToken } = params;
|
|
10
16
|
const apiConfig = useApiConfig();
|
|
11
17
|
const apiBase = useApiBase();
|
|
18
|
+
const { simulation } = useRlsSimulation();
|
|
19
|
+
const simulated = useMemo(() => simulationHeaders(simulation), [simulation]);
|
|
12
20
|
const [entries, setEntries] = useState([]);
|
|
13
21
|
const [total, setTotal] = useState(0);
|
|
14
22
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -16,7 +24,7 @@ function useHistory(params) {
|
|
|
16
24
|
const [error, setError] = useState();
|
|
17
25
|
const [offset, setOffset] = useState(0);
|
|
18
26
|
const [refreshTrigger, setRefreshTrigger] = useState(0);
|
|
19
|
-
const entityKey = `${slug}/${entityId}/${refreshToken ?? 0}`;
|
|
27
|
+
const entityKey = `${slug}/${entityId}/${refreshToken ?? 0}/${JSON.stringify(simulated)}`;
|
|
20
28
|
const currentEntityRef = useRef(void 0);
|
|
21
29
|
const fetchEntries = useCallback(async (currentOffset, signal) => {
|
|
22
30
|
if (!apiConfig?.apiUrl || !entityId || !enabled) return;
|
|
@@ -24,7 +32,10 @@ function useHistory(params) {
|
|
|
24
32
|
setError(void 0);
|
|
25
33
|
try {
|
|
26
34
|
const token = await apiConfig.getAuthToken?.();
|
|
27
|
-
const headers = {
|
|
35
|
+
const headers = {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
...simulated
|
|
38
|
+
};
|
|
28
39
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
29
40
|
const url = `${apiBase}/data/${slug}/${entityId}/history?limit=${pageSize}&offset=${currentOffset}`;
|
|
30
41
|
const response = await fetch(url, {
|
|
@@ -55,7 +66,8 @@ function useHistory(params) {
|
|
|
55
66
|
entityId,
|
|
56
67
|
entityKey,
|
|
57
68
|
enabled,
|
|
58
|
-
pageSize
|
|
69
|
+
pageSize,
|
|
70
|
+
simulated
|
|
59
71
|
]);
|
|
60
72
|
useEffect(() => {
|
|
61
73
|
const isNewEntity = currentEntityRef.current !== entityKey;
|
|
@@ -92,7 +104,10 @@ function useHistory(params) {
|
|
|
92
104
|
const revert = useCallback(async (historyId) => {
|
|
93
105
|
if (!apiConfig?.apiUrl || !entityId) throw new Error("Cannot revert: missing API configuration or entity ID");
|
|
94
106
|
const token = await apiConfig.getAuthToken?.();
|
|
95
|
-
const headers = {
|
|
107
|
+
const headers = {
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
...simulated
|
|
110
|
+
};
|
|
96
111
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
97
112
|
const url = `${apiBase}/data/${slug}/${entityId}/history/${historyId}/revert`;
|
|
98
113
|
const response = await fetch(url, {
|
|
@@ -111,7 +126,8 @@ function useHistory(params) {
|
|
|
111
126
|
apiConfig,
|
|
112
127
|
apiBase,
|
|
113
128
|
slug,
|
|
114
|
-
entityId
|
|
129
|
+
entityId,
|
|
130
|
+
simulated
|
|
115
131
|
]);
|
|
116
132
|
return useMemo(() => ({
|
|
117
133
|
entries,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHistory.js","names":[],"sources":["../../src/hooks/useHistory.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, useMemo } from \"react\";\nimport { useApiBase, useApiConfig } from \"@rebasepro/app\";\nimport type { EntityHistoryEntry } from \"@rebasepro/types\";\n\n/**\n * What the history REST endpoint returns. The fourth declaration of this shape\n * — the two drivers had one each and disagreed on `updated_at` — now an alias\n * of the one in `@rebasepro/types`.\n */\nexport type HistoryEntryData = EntityHistoryEntry;\n\nexport interface UseEntityHistoryResult {\n entries: HistoryEntryData[];\n total: number;\n isLoading: boolean;\n hasMore: boolean;\n error?: Error;\n loadMore: () => void;\n revert: (historyId: string) => Promise<Record<string, unknown>>;\n}\n\n/**\n * Hook to fetch entity history from the backend REST API.\n * Replaces the old subcollection-based approach with a proper API call.\n */\nexport function useHistory(params: {\n slug: string;\n entityId: string | number | undefined;\n enabled?: boolean;\n pageSize?: number;\n /**\n * Bumped by the caller when the record is saved. A save is the one event\n * that adds a revision, and nothing else here would notice it: without\n * this the open panel keeps showing the list it fetched when it opened,\n * so the revision you just created never appears.\n */\n refreshToken?: number;\n}): UseEntityHistoryResult {\n const { slug, entityId, enabled = true, pageSize = 10, refreshToken } = params;\n const apiConfig = useApiConfig();\n const apiBase = useApiBase();\n\n const [entries, setEntries] = useState<HistoryEntryData[]>([]);\n const [total, setTotal] = useState(0);\n const [isLoading, setIsLoading] = useState(false);\n const [hasMore, setHasMore] = useState(true);\n const [error, setError] = useState<Error | undefined>();\n const [offset, setOffset] = useState(0);\n const [refreshTrigger, setRefreshTrigger] = useState(0);\n\n // Track the current entity identity so we can detect stale responses.\n // `refreshToken` is part of the identity on purpose: a save makes the list\n // we are holding a stale page of a longer list, which is the same problem\n // as having moved to a different record.\n const entityKey = `${slug}/${entityId}/${refreshToken ?? 0}`;\n const currentEntityRef = useRef<string | undefined>(undefined);\n\n const fetchEntries = useCallback(async (\n currentOffset: number,\n signal?: AbortSignal\n ) => {\n if (!apiConfig?.apiUrl || !entityId || !enabled) return;\n\n setIsLoading(true);\n setError(undefined);\n\n try {\n const token = await apiConfig.getAuthToken?.();\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\"\n };\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n\n const url = `${apiBase}/data/${slug}/${entityId}/history?limit=${pageSize}&offset=${currentOffset}`;\n const response = await fetch(url, { headers,\nsignal });\n\n // Check if the request was aborted or the entity changed while in-flight\n if (signal?.aborted) return;\n if (currentEntityRef.current !== entityKey) return;\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({ error: { message: response.statusText } }));\n throw new Error(errorData.error?.message || `Failed to fetch history (${response.status})`);\n }\n\n const result = await response.json();\n\n if (currentOffset === 0) {\n setEntries(result.data);\n } else {\n setEntries(prev => [...prev, ...result.data]);\n }\n\n setTotal(result.meta.total);\n setHasMore(result.meta.hasMore);\n } catch (err) {\n // Don't set error state for intentional aborts\n if (err instanceof DOMException && err.name === \"AbortError\") return;\n setError(err instanceof Error ? err : new Error(String(err)));\n } finally {\n setIsLoading(false);\n }\n }, [apiConfig, apiBase, slug, entityId, entityKey, enabled, pageSize]);\n\n // Single unified effect: reset state when entity changes, fetch when offset changes.\n // Uses AbortController to cancel stale requests on entity change or unmount.\n useEffect(() => {\n const isNewEntity = currentEntityRef.current !== entityKey;\n\n if (isNewEntity) {\n // Reset state for new entity\n currentEntityRef.current = entityKey;\n setEntries([]);\n setTotal(0);\n setHasMore(true);\n setOffset(0);\n }\n\n if (!enabled || !entityId) return;\n\n const abortController = new AbortController();\n // When entity changed, always fetch from offset 0\n const effectiveOffset = isNewEntity ? 0 : offset;\n fetchEntries(effectiveOffset, abortController.signal);\n\n return () => {\n abortController.abort();\n };\n }, [fetchEntries, offset, enabled, entityId, entityKey, refreshTrigger]);\n\n const loadMore = useCallback(() => {\n // `entries` already holds every page up to the current offset; adding\n // the offset to it counted those pages twice and stopped the scroll\n // short of the oldest revisions.\n if (!isLoading && hasMore && entries.length < total) {\n setOffset(prev => prev + pageSize);\n }\n }, [isLoading, hasMore, pageSize, entries.length, total]);\n\n const revert = useCallback(async (historyId: string): Promise<Record<string, unknown>> => {\n if (!apiConfig?.apiUrl || !entityId) {\n throw new Error(\"Cannot revert: missing API configuration or entity ID\");\n }\n\n const token = await apiConfig.getAuthToken?.();\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\"\n };\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n\n const url = `${apiBase}/data/${slug}/${entityId}/history/${historyId}/revert`;\n const response = await fetch(url, { method: \"POST\",\nheaders });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({ error: { message: response.statusText } }));\n throw new Error(errorData.error?.message || `Failed to revert (${response.status})`);\n }\n\n const result = await response.json();\n\n // Refresh the history list after revert by resetting the entity ref\n // and triggering the effect.\n currentEntityRef.current = undefined;\n setRefreshTrigger(prev => prev + 1);\n\n // Return the reverted entity data so callers can update the form\n return result.data as Record<string, unknown>;\n }, [apiConfig, apiBase, slug, entityId]);\n\n return useMemo(() => ({\n entries,\n total,\n isLoading,\n hasMore,\n error,\n loadMore,\n revert\n }), [entries, total, isLoading, hasMore, error, loadMore, revert]);\n}\n"],"mappings":";;;;;;;AAyBA,SAAgB,WAAW,QAYA;CACvB,MAAM,EAAE,MAAM,UAAU,UAAU,MAAM,WAAW,IAAI,iBAAiB;CACxE,MAAM,YAAY,aAAa;CAC/B,MAAM,UAAU,WAAW;CAE3B,MAAM,CAAC,SAAS,cAAc,SAA6B,CAAC,CAAC;CAC7D,MAAM,CAAC,OAAO,YAAY,SAAS,CAAC;CACpC,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAChD,MAAM,CAAC,SAAS,cAAc,SAAS,IAAI;CAC3C,MAAM,CAAC,OAAO,YAAY,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AK;EAInC,iBAAiB,UAAU,KAAA;EAC3B,mBAAkB,SAAQ,OAAO,CAAC;EAGlC,OAAO,OAAO;CAClB,GAAG;EAAC;EAAW;EAAS;EAAM;CAAQ,CAAC;CAEvC,OAAO,eAAe;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,IAAI;EAAC;EAAS;EAAO;EAAW;EAAS;EAAO;EAAU;CAAM,CAAC;AACrE"}
|
|
1
|
+
{"version":3,"file":"useHistory.js","names":[],"sources":["../../src/hooks/useHistory.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState, useMemo } from \"react\";\nimport { useApiBase, useApiConfig, useRlsSimulation } from \"@rebasepro/app\";\nimport { simulationHeaders } from \"@rebasepro/types\";\nimport type { EntityHistoryEntry } from \"@rebasepro/types\";\n\n/**\n * What the history REST endpoint returns. The fourth declaration of this shape\n * — the two drivers had one each and disagreed on `updated_at` — now an alias\n * of the one in `@rebasepro/types`.\n */\nexport type HistoryEntryData = EntityHistoryEntry;\n\nexport interface UseEntityHistoryResult {\n entries: HistoryEntryData[];\n total: number;\n isLoading: boolean;\n hasMore: boolean;\n error?: Error;\n loadMore: () => void;\n revert: (historyId: string) => Promise<Record<string, unknown>>;\n}\n\n/**\n * Hook to fetch entity history from the backend REST API.\n * Replaces the old subcollection-based approach with a proper API call.\n *\n * While access is simulated (\"Simulate access\") every request carries the\n * simulation, as the data views' `client.simulate()` does: the history is read\n * as the simulated identity, and the server refuses a revert as the simulated\n * write it would be.\n */\nexport function useHistory(params: {\n slug: string;\n entityId: string | number | undefined;\n enabled?: boolean;\n pageSize?: number;\n /**\n * Bumped by the caller when the record is saved. A save is the one event\n * that adds a revision, and nothing else here would notice it: without\n * this the open panel keeps showing the list it fetched when it opened,\n * so the revision you just created never appears.\n */\n refreshToken?: number;\n}): UseEntityHistoryResult {\n const { slug, entityId, enabled = true, pageSize = 10, refreshToken } = params;\n const apiConfig = useApiConfig();\n const apiBase = useApiBase();\n const { simulation } = useRlsSimulation();\n const simulated = useMemo(() => simulationHeaders(simulation), [simulation]);\n\n const [entries, setEntries] = useState<HistoryEntryData[]>([]);\n const [total, setTotal] = useState(0);\n const [isLoading, setIsLoading] = useState(false);\n const [hasMore, setHasMore] = useState(true);\n const [error, setError] = useState<Error | undefined>();\n const [offset, setOffset] = useState(0);\n const [refreshTrigger, setRefreshTrigger] = useState(0);\n\n // Track the current entity identity so we can detect stale responses.\n // `refreshToken` is part of the identity on purpose: a save makes the list\n // we are holding a stale page of a longer list, which is the same problem\n // as having moved to a different record.\n // So is the simulation: another identity reads another history.\n const entityKey = `${slug}/${entityId}/${refreshToken ?? 0}/${JSON.stringify(simulated)}`;\n const currentEntityRef = useRef<string | undefined>(undefined);\n\n const fetchEntries = useCallback(async (\n currentOffset: number,\n signal?: AbortSignal\n ) => {\n if (!apiConfig?.apiUrl || !entityId || !enabled) return;\n\n setIsLoading(true);\n setError(undefined);\n\n try {\n const token = await apiConfig.getAuthToken?.();\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n ...simulated\n };\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n\n const url = `${apiBase}/data/${slug}/${entityId}/history?limit=${pageSize}&offset=${currentOffset}`;\n const response = await fetch(url, { headers,\nsignal });\n\n // Check if the request was aborted or the entity changed while in-flight\n if (signal?.aborted) return;\n if (currentEntityRef.current !== entityKey) return;\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({ error: { message: response.statusText } }));\n throw new Error(errorData.error?.message || `Failed to fetch history (${response.status})`);\n }\n\n const result = await response.json();\n\n if (currentOffset === 0) {\n setEntries(result.data);\n } else {\n setEntries(prev => [...prev, ...result.data]);\n }\n\n setTotal(result.meta.total);\n setHasMore(result.meta.hasMore);\n } catch (err) {\n // Don't set error state for intentional aborts\n if (err instanceof DOMException && err.name === \"AbortError\") return;\n setError(err instanceof Error ? err : new Error(String(err)));\n } finally {\n setIsLoading(false);\n }\n }, [apiConfig, apiBase, slug, entityId, entityKey, enabled, pageSize, simulated]);\n\n // Single unified effect: reset state when entity changes, fetch when offset changes.\n // Uses AbortController to cancel stale requests on entity change or unmount.\n useEffect(() => {\n const isNewEntity = currentEntityRef.current !== entityKey;\n\n if (isNewEntity) {\n // Reset state for new entity\n currentEntityRef.current = entityKey;\n setEntries([]);\n setTotal(0);\n setHasMore(true);\n setOffset(0);\n }\n\n if (!enabled || !entityId) return;\n\n const abortController = new AbortController();\n // When entity changed, always fetch from offset 0\n const effectiveOffset = isNewEntity ? 0 : offset;\n fetchEntries(effectiveOffset, abortController.signal);\n\n return () => {\n abortController.abort();\n };\n }, [fetchEntries, offset, enabled, entityId, entityKey, refreshTrigger]);\n\n const loadMore = useCallback(() => {\n // `entries` already holds every page up to the current offset; adding\n // the offset to it counted those pages twice and stopped the scroll\n // short of the oldest revisions.\n if (!isLoading && hasMore && entries.length < total) {\n setOffset(prev => prev + pageSize);\n }\n }, [isLoading, hasMore, pageSize, entries.length, total]);\n\n const revert = useCallback(async (historyId: string): Promise<Record<string, unknown>> => {\n if (!apiConfig?.apiUrl || !entityId) {\n throw new Error(\"Cannot revert: missing API configuration or entity ID\");\n }\n\n const token = await apiConfig.getAuthToken?.();\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n ...simulated\n };\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n\n const url = `${apiBase}/data/${slug}/${entityId}/history/${historyId}/revert`;\n const response = await fetch(url, { method: \"POST\",\nheaders });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({ error: { message: response.statusText } }));\n throw new Error(errorData.error?.message || `Failed to revert (${response.status})`);\n }\n\n const result = await response.json();\n\n // Refresh the history list after revert by resetting the entity ref\n // and triggering the effect.\n currentEntityRef.current = undefined;\n setRefreshTrigger(prev => prev + 1);\n\n // Return the reverted entity data so callers can update the form\n return result.data as Record<string, unknown>;\n }, [apiConfig, apiBase, slug, entityId, simulated]);\n\n return useMemo(() => ({\n entries,\n total,\n isLoading,\n hasMore,\n error,\n loadMore,\n revert\n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AAI,CAAC,WAAW,UAAU,CAAC,UACvB,MAAM,IAAI,MAAM,uDAAuD;EAG3E,MAAM,QAAQ,MAAM,UAAU,eAAe;EAC7C,MAAM,UAAkC;GACpC,gBAAgB;GAChB,GAAG;EACP;EACA,IAAI,OAAO,QAAQ,mBAAmB,UAAU;EAEhD,MAAM,MAAM,GAAG,QAAQ,QAAQ,KAAK,GAAG,SAAS,WAAW,UAAU;EACrE,MAAM,WAAW,MAAM,MAAM,KAAK;GAAE,QAAQ;GACpD;EAAQ,CAAC;EAED,IAAI,CAAC,SAAS,IAAI;GACd,MAAM,YAAY,MAAM,SAAS,KAAK,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,SAAS,WAAW,EAAE,EAAE;GACjG,MAAM,IAAI,MAAM,UAAU,OAAO,WAAW,qBAAqB,SAAS,OAAO,EAAE;EACvF;EAEA,MAAM,SAAS,MAAM,SAAS,KAAK;EAInC,iBAAiB,UAAU,KAAA;EAC3B,mBAAkB,SAAQ,OAAO,CAAC;EAGlC,OAAO,OAAO;CAClB,GAAG;EAAC;EAAW;EAAS;EAAM;EAAU;CAAS,CAAC;CAElD,OAAO,eAAe;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,IAAI;EAAC;EAAS;EAAO;EAAW;EAAS;EAAO;EAAU;CAAM,CAAC;AACrE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,53 @@ export * from "./collection_editor/index.js";
|
|
|
17
17
|
export * from "./collection_editor/liveSchemaClient.js";
|
|
18
18
|
export * from "./collection_editor/useLiveSchemaEditing.js";
|
|
19
19
|
export { CreationResultDialog } from "./components/admin/CreationResultDialog.js";
|
|
20
|
+
export { NavigationCard } from "./components/HomePage/NavigationCard.js";
|
|
21
|
+
export type { NavigationCardProps } from "./components/HomePage/NavigationCard.js";
|
|
22
|
+
export { SmallNavigationCard } from "./components/HomePage/SmallNavigationCard.js";
|
|
23
|
+
export type { SmallNavigationCardProps } from "./components/HomePage/SmallNavigationCard.js";
|
|
24
|
+
export { StringNumberFilterField } from "./components/SelectableTable/filters/StringNumberFilterField.js";
|
|
25
|
+
export { BooleanFilterField } from "./components/SelectableTable/filters/BooleanFilterField.js";
|
|
26
|
+
export { DateTimeFilterField } from "./components/SelectableTable/filters/DateTimeFilterField.js";
|
|
27
|
+
export { ReferenceFilterField } from "./components/SelectableTable/filters/ReferenceFilterField.js";
|
|
28
|
+
export { RelationFilterField } from "./components/SelectableTable/filters/RelationFilterField.js";
|
|
29
|
+
export { getDatePropertyMode, getDatePropertyTimezone } from "./preview/util.js";
|
|
30
|
+
export { DrawerExpansionContext, useDrawerExpansion, useDrawerExpandedWhile } from "./components/drawer_expansion.js";
|
|
31
|
+
export type { DrawerExpansion } from "./components/drawer_expansion.js";
|
|
32
|
+
export { NAVIGATION_DEFAULT_GROUP_NAME } from "./hooks/navigation/utils.js";
|
|
33
|
+
export { CollectionTableToolbar, useToolbarLabels } from "./components/CollectionTableBinding/internal/CollectionTableToolbar.js";
|
|
34
|
+
export type { CollectionTableToolbarProps } from "./components/CollectionTableBinding/internal/CollectionTableToolbar.js";
|
|
35
|
+
export { EditorCollectionAction } from "./collection_editor/ui/EditorCollectionAction.js";
|
|
36
|
+
export type { CollectionTableBindingProps } from "./components/CollectionTableBinding/CollectionTableBindingProps.js";
|
|
37
|
+
export { EntityTableCell } from "./components/CollectionTableBinding/internal/EntityTableCell.js";
|
|
38
|
+
export type { EntityTableCellProps, EntityTableCellOpener } from "./components/CollectionTableBinding/internal/EntityTableCell.js";
|
|
39
|
+
export { PropertyTableCell } from "./components/CollectionTableBinding/PropertyTableCell.js";
|
|
40
|
+
export type { PropertyTableCellProps } from "./components/CollectionTableBinding/PropertyTableCell.js";
|
|
41
|
+
export { AdditionalFieldValue } from "./components/AdditionalFieldValue.js";
|
|
42
|
+
export type { AdditionalFieldValueProps } from "./components/AdditionalFieldValue.js";
|
|
43
|
+
export { propertiesToColumns } from "./components/CollectionTableBinding/column_utils.js";
|
|
44
|
+
export type { PropertiesToColumnsParams } from "./components/CollectionTableBinding/column_utils.js";
|
|
45
|
+
export type { CustomFieldValidator } from "./form/validation.js";
|
|
46
|
+
export { resolveCollectionSlotKeys, useCollectionSlotKeys, useEntitySlots } from "./components/CollectionViewBinding/usePreviewSlots.js";
|
|
47
|
+
export type { CollectionSlotKeys, EntityPreviewSlots, PreviewSlot, DatePreviewSlot, RelationChipSlot, RelationChipItem } from "./components/CollectionViewBinding/usePreviewSlots.js";
|
|
48
|
+
export { SlotValue, TagChips } from "./components/CollectionViewBinding/SlotValue.js";
|
|
49
|
+
export type { SlotValueProps } from "./components/CollectionViewBinding/SlotValue.js";
|
|
50
|
+
export { useEntityTitle } from "./hooks/useEntityDisplay.js";
|
|
51
|
+
export type { UseEntityDisplayParams, ResolvedDisplayValue } from "./hooks/useEntityDisplay.js";
|
|
52
|
+
export { useSearchExplanation, MatchExplanation, fieldLabel } from "./components/CollectionViewBinding/SearchExplanation.js";
|
|
53
|
+
export { Highlighted } from "./components/CollectionViewBinding/SearchHighlight.js";
|
|
54
|
+
export { NestedEntityPreviewBoundary } from "./components/EntityPreviewNesting.js";
|
|
55
|
+
export type { EntityPreviewLayout } from "./components/EntityPreviewNesting.js";
|
|
56
|
+
export { isEmptyPreviewValue } from "./preview/util.js";
|
|
57
|
+
export { unlinkEntityAction } from "./components/common/default_entity_actions.js";
|
|
58
|
+
export { entityActionName, resolveEntityActionState } from "./util/entity_actions.js";
|
|
59
|
+
export type { EntityActionState } from "./util/entity_actions.js";
|
|
60
|
+
export { useSideDialogContext } from "./components/SideDialogs.js";
|
|
61
|
+
export type { SideDialogController } from "./components/SideDialogs.js";
|
|
62
|
+
export { useChildViewSource } from "./hooks/useChildViewSource.js";
|
|
63
|
+
export { EditViewBinding } from "./components/EditViewBinding.js";
|
|
64
|
+
export type { EditViewBindingProps } from "./components/EditViewBinding.js";
|
|
65
|
+
export { DetailViewBinding } from "./components/DetailViewBinding.js";
|
|
66
|
+
export type { DetailViewBindingProps } from "./components/DetailViewBinding.js";
|
|
67
|
+
export { NavigationCardBinding } from "./components/HomePage/NavigationCardBinding.js";
|
|
68
|
+
export { NavigationGroup } from "./components/HomePage/NavigationGroup.js";
|
|
69
|
+
export { FavouritesView } from "./components/HomePage/FavouritesView.js";
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,12 @@ import { EditorAIControllerProvider, useProvidedEditorAIController } from "./con
|
|
|
2
2
|
import { getBracketNotation, getDefaultPropertiesOrder, getIconForProperty, getIconForWidget, getPropertiesWithPropertiesOrder, getPropertyInPath, getResolvedPropertyInPath, isReferenceProperty, isRelationProperty } from "./util/property_utils.js";
|
|
3
3
|
import { PropertyKeyHint } from "./components/PropertyKeyHint.js";
|
|
4
4
|
import { FieldBlock, LABEL_ICON_SIZE, isSelfLabellingProperty, spanClass } from "./form/components/FieldBlock.js";
|
|
5
|
+
import { getDefaultFieldId, getFieldId } from "./components/field_ids.js";
|
|
6
|
+
import { AdditionalFieldValue } from "./components/AdditionalFieldValue.js";
|
|
5
7
|
import { FormRail, RecordMeta } from "./form/components/FormRail.js";
|
|
6
8
|
import { FormSections } from "./form/components/FormSections.js";
|
|
7
9
|
import { EmptyValue } from "./preview/components/EmptyValue.js";
|
|
8
|
-
import { sanitizeUrl } from "./preview/util.js";
|
|
10
|
+
import { getDatePropertyMode, getDatePropertyTimezone, isEmptyPreviewValue, sanitizeUrl } from "./preview/util.js";
|
|
9
11
|
import { ImagePreview } from "./preview/components/ImagePreview.js";
|
|
10
12
|
import { UrlComponentPreview } from "./preview/components/UrlComponentPreview.js";
|
|
11
13
|
import { SkeletonPropertyComponent, renderSkeletonCaptionText, renderSkeletonIcon, renderSkeletonImageThumbnail, renderSkeletonText } from "./preview/property_previews/SkeletonPropertyComponent.js";
|
|
@@ -15,8 +17,11 @@ import { StringPropertyPreview } from "./preview/property_previews/StringPropert
|
|
|
15
17
|
import { ArrayPropertyPreview } from "./preview/property_previews/ArrayPropertyPreview.js";
|
|
16
18
|
import { getEntityPreviewKeys, getEntityTitlePropertyKey, getEntityTitlePropertyKeyForEntity } from "./util/previews.js";
|
|
17
19
|
import { getUserLabel, useResolvedUser } from "./hooks/useResolvedUsers.js";
|
|
20
|
+
import { useEntityTitle } from "./hooks/useEntityDisplay.js";
|
|
21
|
+
import { resolveCollectionSlotKeys, useCollectionSlotKeys, useEntitySlots } from "./components/CollectionViewBinding/usePreviewSlots.js";
|
|
18
22
|
import { CollectionRegistryContext, useCollectionRegistryController } from "./hooks/navigation/contexts/CollectionRegistryContext.js";
|
|
19
23
|
import { SidePanelControllerContext, useSidePanel } from "./hooks/useSidePanel.js";
|
|
24
|
+
import { NestedEntityPreviewBoundary } from "./components/EntityPreviewNesting.js";
|
|
20
25
|
import { EntityPreviewBinding } from "./components/EntityPreviewBinding.js";
|
|
21
26
|
import { ReferencePreview } from "./preview/components/ReferencePreview.js";
|
|
22
27
|
import { InlineEntityListPreview } from "./preview/components/InlineEntityListPreview.js";
|
|
@@ -39,13 +44,22 @@ import { LabelWithIcon } from "./form/components/LabelWithIcon.js";
|
|
|
39
44
|
import { ReadOnlyFieldBinding } from "./form/field_bindings/ReadOnlyFieldBinding.js";
|
|
40
45
|
import { useClearRestoreValue } from "./form/useClearRestoreValue.js";
|
|
41
46
|
import { ArrayCustomShapedFieldBinding } from "./form/field_bindings/ArrayCustomShapedFieldBinding.js";
|
|
47
|
+
import { EntityTableCell } from "./components/CollectionTableBinding/internal/EntityTableCell.js";
|
|
42
48
|
import { SelectableTableContext } from "./components/SelectableTable/SelectableTableContext.js";
|
|
49
|
+
import { PropertyTableCell } from "./components/CollectionTableBinding/PropertyTableCell.js";
|
|
43
50
|
import { useSideDialogsController } from "./hooks/useSideDialogsController.js";
|
|
44
51
|
import { NavigationStateContext, useNavigationStateController } from "./hooks/navigation/contexts/NavigationStateContext.js";
|
|
45
52
|
import { UrlContext, useUrlController } from "./hooks/navigation/contexts/UrlContext.js";
|
|
46
53
|
import { useAdminContext } from "./hooks/useAdminContext.js";
|
|
47
|
-
import { mergeEntityActions } from "./util/entity_actions.js";
|
|
54
|
+
import { entityActionName, mergeEntityActions, resolveEntityActionState } from "./util/entity_actions.js";
|
|
48
55
|
import { CollectionRowActions } from "./components/CollectionTableBinding/CollectionRowActions.js";
|
|
56
|
+
import { CollectionTableToolbar, useToolbarLabels } from "./components/CollectionTableBinding/internal/CollectionTableToolbar.js";
|
|
57
|
+
import { propertiesToColumns } from "./components/CollectionTableBinding/column_utils.js";
|
|
58
|
+
import { StringNumberFilterField } from "./components/SelectableTable/filters/StringNumberFilterField.js";
|
|
59
|
+
import { BooleanFilterField } from "./components/SelectableTable/filters/BooleanFilterField.js";
|
|
60
|
+
import { DateTimeFilterField } from "./components/SelectableTable/filters/DateTimeFilterField.js";
|
|
61
|
+
import { ReferenceFilterField } from "./components/SelectableTable/filters/ReferenceFilterField.js";
|
|
62
|
+
import { RelationFilterField } from "./components/SelectableTable/filters/RelationFilterField.js";
|
|
49
63
|
import { SelectableTable } from "./components/SelectableTable/SelectableTable.js";
|
|
50
64
|
import { CollectionTableBinding } from "./components/CollectionTableBinding/CollectionTableBinding.js";
|
|
51
65
|
import { VirtualTableInput } from "./components/CollectionTableBinding/index.js";
|
|
@@ -56,14 +70,15 @@ import { useHistory } from "./hooks/useHistory.js";
|
|
|
56
70
|
import { useBuildCollectionRegistryController } from "./hooks/navigation/useBuildCollectionRegistryController.js";
|
|
57
71
|
import { addInitialSlash, getCollectionBySlugWithin, getCollectionPathsCombinations, getLastSegment, removeInitialAndTrailingSlashes, removeInitialSlash, removeTrailingSlash, resolveCollectionPathIds } from "./util/navigation_utils.js";
|
|
58
72
|
import { CreationResultDialog } from "./components/admin/CreationResultDialog.js";
|
|
59
|
-
import { copyEntityAction, deleteEntityAction, editEntityAction, resetPasswordAction } from "./components/common/default_entity_actions.js";
|
|
73
|
+
import { copyEntityAction, deleteEntityAction, editEntityAction, resetPasswordAction, unlinkEntityAction } from "./components/common/default_entity_actions.js";
|
|
74
|
+
import { NAVIGATION_DEFAULT_GROUP_NAME } from "./hooks/navigation/utils.js";
|
|
60
75
|
import { useResolvedCollections } from "./hooks/navigation/useResolvedCollections.js";
|
|
61
76
|
import { useResolvedViews } from "./hooks/navigation/useResolvedViews.js";
|
|
62
77
|
import { useTopLevelNavigation } from "./hooks/navigation/useTopLevelNavigation.js";
|
|
63
78
|
import { useBuildNavigationStateController } from "./hooks/navigation/useBuildNavigationStateController.js";
|
|
64
79
|
import { useBuildUrlController } from "./hooks/navigation/useBuildUrlController.js";
|
|
65
80
|
import { useBreadcrumbsController } from "./hooks/useBreadcrumbsController.js";
|
|
66
|
-
import { SideDialogs } from "./components/SideDialogs.js";
|
|
81
|
+
import { SideDialogs, useSideDialogContext } from "./components/SideDialogs.js";
|
|
67
82
|
import { SelectionTableBinding } from "./components/ReferenceTable/SelectionTableBinding.js";
|
|
68
83
|
import { useSelectionDialog } from "./hooks/useSelectionDialog.js";
|
|
69
84
|
import { ArrayContainer } from "./components/ArrayContainer.js";
|
|
@@ -81,10 +96,9 @@ import { StorageUploadFieldBinding } from "./form/field_bindings/StorageUploadFi
|
|
|
81
96
|
import { SwitchFieldBinding } from "./form/field_bindings/SwitchFieldBinding.js";
|
|
82
97
|
import { TextFieldBinding } from "./form/field_bindings/TextFieldBinding.js";
|
|
83
98
|
import { VectorFieldBinding } from "./form/field_bindings/VectorFieldBinding.js";
|
|
84
|
-
import { getDefaultFieldId, getFieldId } from "./components/field_ids.js";
|
|
85
99
|
import { DEFAULT_FIELD_CONFIGS, getDefaultFieldConfig, getFieldConfig } from "./components/field_configs.js";
|
|
86
100
|
import { PropertyFieldBinding } from "./form/PropertyFieldBinding.js";
|
|
87
|
-
import { extractTouchedValues, getChanges, getInitialEntityValues, removeEmptyContainers, zodToFormErrors } from "./form/form_utils.js";
|
|
101
|
+
import { extractTouchedValues, getChanges, getInitialEntityValues, getParentLinkValues, getTouchedPropertyValues, getUnappliedLocalChanges, overlayEdit, removeEmptyContainers, zodToFormErrors } from "./form/form_utils.js";
|
|
88
102
|
import { EntityForm } from "./form/EntityForm.js";
|
|
89
103
|
import { EntityFormBinding } from "./form/EntityFormBinding.js";
|
|
90
104
|
import { CustomViewRoute } from "./routes/CustomViewRoute.js";
|
|
@@ -109,15 +123,23 @@ import { ImportConversionProblems } from "./data_import/components/ImportConvers
|
|
|
109
123
|
import { DataNewPropertiesMapping } from "./data_import/components/DataNewPropertiesMapping.js";
|
|
110
124
|
import { ImportNewPropertyFieldPreview } from "./data_import/components/ImportNewPropertyFieldPreview.js";
|
|
111
125
|
import { useCollectionEditorController } from "./collection_editor/useCollectionEditorController.js";
|
|
126
|
+
import { EditorCollectionAction } from "./collection_editor/ui/EditorCollectionAction.js";
|
|
112
127
|
import { CollectionViewActions } from "./components/CollectionViewBinding/CollectionViewActions.js";
|
|
128
|
+
import { Highlighted } from "./components/CollectionViewBinding/SearchHighlight.js";
|
|
129
|
+
import { MatchExplanation, fieldLabel, useSearchExplanation } from "./components/CollectionViewBinding/SearchExplanation.js";
|
|
130
|
+
import { SlotValue, TagChips } from "./components/CollectionViewBinding/SlotValue.js";
|
|
113
131
|
import { EntityCardBinding } from "./components/CollectionViewBinding/EntityCardBinding.js";
|
|
114
132
|
import { CollectionCardViewBinding } from "./components/CollectionViewBinding/CollectionCardViewBinding.js";
|
|
133
|
+
import { useChildViewSource } from "./hooks/useChildViewSource.js";
|
|
134
|
+
import { EditViewBinding } from "./components/EditViewBinding.js";
|
|
115
135
|
import { CollectionViewBinding } from "./components/CollectionViewBinding/CollectionViewBinding.js";
|
|
136
|
+
import { DetailViewBinding } from "./components/DetailViewBinding.js";
|
|
116
137
|
import { ReferenceWidget } from "./components/ReferenceWidget.js";
|
|
117
138
|
import { SidePanelProvider } from "./components/SidePanelProvider.js";
|
|
118
139
|
import { AdminModeSyncer } from "./components/AdminModeSyncer.js";
|
|
119
140
|
import { useApp } from "./components/app/useApp.js";
|
|
120
141
|
import { AppBar } from "./components/app/AppBar.js";
|
|
142
|
+
import { DrawerExpansionContext, useDrawerExpandedWhile, useDrawerExpansion } from "./components/drawer_expansion.js";
|
|
121
143
|
import { DrawerNavigationItem } from "./components/DrawerNavigationItem.js";
|
|
122
144
|
import { DrawerNavigationGroup } from "./components/DrawerNavigationGroup.js";
|
|
123
145
|
import { DefaultDrawer, DrawerFooterActions } from "./components/DefaultDrawer.js";
|
|
@@ -131,6 +153,10 @@ import { useLocalCollectionsConfigController } from "./collection_editor/useLoca
|
|
|
131
153
|
import { useCollectionsConfigController } from "./collection_editor/useCollectionsConfigController.js";
|
|
132
154
|
import { RebaseNavigation } from "./components/RebaseNavigation.js";
|
|
133
155
|
import { RebaseLayout } from "./components/RebaseLayout.js";
|
|
156
|
+
import { FavouritesView } from "./components/HomePage/FavouritesView.js";
|
|
157
|
+
import { NavigationGroup } from "./components/HomePage/NavigationGroup.js";
|
|
158
|
+
import { NavigationCard } from "./components/HomePage/NavigationCard.js";
|
|
159
|
+
import { NavigationCardBinding } from "./components/HomePage/NavigationCardBinding.js";
|
|
134
160
|
import { RebaseRouteDefs } from "./components/RebaseRouteDefs.js";
|
|
135
161
|
import { RebaseShell } from "./components/RebaseShell.js";
|
|
136
162
|
import { CollectionsProvider } from "./components/CollectionsProvider.js";
|
|
@@ -148,4 +174,5 @@ import { validateCollectionJson } from "./collection_editor/validateCollectionJs
|
|
|
148
174
|
import { CollectionGenerationApiError, DEFAULT_COLLECTION_GENERATION_ENDPOINT, buildCollectionGenerationCallback } from "./collection_editor/api/generateCollectionApi.js";
|
|
149
175
|
import { MissingReferenceWidget } from "./collection_editor/ui/MissingReferenceWidget.js";
|
|
150
176
|
import { getFullId, getFullIdPath, idToPropertiesPath, namespaceToPropertiesOrderPath, namespaceToPropertiesPath } from "./collection_editor/ui/collection_editor/util.js";
|
|
151
|
-
|
|
177
|
+
import { SmallNavigationCard } from "./components/HomePage/SmallNavigationCard.js";
|
|
178
|
+
export { AdditionalFieldValue, AdminModeSyncer, AppBar, ArrayContainer, ArrayCustomShapedFieldBinding, ArrayEnumPreview, ArrayOfMapsPreview, ArrayOfReferencesFieldBinding, ArrayOfReferencesPreview, ArrayOfStorageComponentsPreview, ArrayOfStringsPreview, ArrayOneOfPreview, ArrayPropertyEnumPreview, ArrayPropertyPreview, BasicExportAction, BlockFieldBinding, BooleanFilterField, BooleanPreview, CollectionCardViewBinding, CollectionGenerationApiError, CollectionPanel, CollectionRegistryContext, CollectionRowActions, CollectionTableBinding, CollectionTableToolbar, CollectionViewActions, CollectionViewBinding, CollectionsProvider, CreationResultDialog, CustomViewRoute, DEFAULT_COLLECTION_GENERATION_ENDPOINT, DEFAULT_FIELD_CONFIGS, DataNewPropertiesMapping, DatePreview, DateTimeFieldBinding, DateTimeFilterField, DefaultDrawer, DetailViewBinding, Drawer, DrawerExpansionContext, DrawerFooterActions, DrawerNavigationGroup, DrawerNavigationItem, EXPORT_PAGE_SIZE, EditViewBinding, EditorAIControllerProvider, EditorCollectionAction, EmptyValue, EntityCardBinding, EntityForm, EntityFormBinding, EntityFormPanel, EntityPreviewBinding, EntityTableCell, EntityViewBinding, EnumValuesChip, ExportCollectionAction, FavouritesView, FieldBlock, FieldCaption, FieldHelperText, FormRail, FormSections, Highlighted, IMPORT_BATCH_MAX_BYTES, IMPORT_BATCH_SIZE, ImagePreview, ImportCollectionAction, ImportConversionProblems, ImportDataPreview, ImportFileUpload, ImportNewPropertyFieldPreview, ImportSaveInProgress, InlineEntityListPreview, KeyValueFieldBinding, KeyValuePreview, LABEL_ICON_SIZE, LabelWithIcon, LiveSchemaError, MAX_EXPORT_ROWS, MAX_SELECTION_ROWS, MapFieldBinding, MapPropertyPreview, MarkdownEditorFieldBinding, MatchExplanation, MissingReferenceWidget, MultiSelectFieldBinding, NAVIGATION_DEFAULT_GROUP_NAME, NavigationCard, NavigationCardBinding, NavigationGroup, NavigationStateContext, NestedEntityPreviewBoundary, NumberPropertyPreview, PropertyConfigBadge, PropertyFieldBinding, PropertyKeyHint, PropertyPreview, PropertySelectEntry, PropertyTableCell, ReadOnlyFieldBinding, RebaseAuthGate, RebaseCMS, RebaseLayout, RebaseNavigation, RebaseRoute, RebaseRouteDefs, RebaseShell, RecordMeta, ReferenceFieldBinding, ReferenceFilterField, ReferencePreview, ReferenceWidget, RelationFilterField, RelationPreview, RepeatFieldBinding, SELECTION_PAGE_SIZE, Scaffold, SchemaChangeCancelled, SearchIconsView, SelectFieldBinding, SelectableTable, SelectableTableContext, SelectionMenu, SelectionTableBinding, SideDialogs, SidePanelControllerContext, SidePanelProvider, SkeletonPropertyComponent, SlotValue, SmallNavigationCard, StorageThumbnail, StorageThumbnailInternal, StorageUploadFieldBinding, StringNumberFilterField, StringPropertyPreview, SwitchFieldBinding, TagChips, TextFieldBinding, UrlComponentPreview, UrlContext, UserPreview, VectorFieldBinding, VirtualTableInput, addInitialSlash, asUnavailable, buildCollectionGenerationCallback, buildSidePanelsFromUrl, convertDataToEntity, convertFileToJson, convertImportData, copyEntityAction, createLiveSchemaClient, createStaticDataController, deleteEntityAction, detectCsvDelimiter, downloadBlob, downloadDataAsCsv, downloadEntitiesExport, editEntityAction, entityActionName, entryToCSVRow, escapeCsvFormula, extractTouchedValues, fetchAllEntitiesForExport, fieldLabel, flattenEntry, fromSerializableCollectionConfig, fromSerializableCollectionConfigs, fromSerializableProperties, fromSerializableProperty, getBracketNotation, getChanges, getCollectionBySlugWithin, getCollectionPathsCombinations, getDatePropertyMode, getDatePropertyTimezone, getDefaultFieldConfig, getDefaultFieldId, getDefaultPropertiesOrder, getEntityCSVExportableData, getEntityJsonExportableData, getEntityPreviewKeys, getEntityTitlePropertyKey, getEntityTitlePropertyKeyForEntity, getEntityViewWidth, getFieldConfig, getFieldId, getFullId, getFullIdPath, getIconForProperty, getIconForWidget, getInferenceType, getInitialEntityValues, getLastSegment, getParentLinkValues, getPropertiesWithPropertiesOrder, getPropertyInPath, getResolvedPropertyInPath, getTouchedPropertyValues, getUnappliedLocalChanges, getUserLabel, idToPropertiesPath, isEmptyPreviewValue, isReferenceProperty, isRelationProperty, isSchemaChangeCancelled, isSelfLabellingProperty, mapPropertiesToConfigs, mapPropertyToConfig, mappedColumnTarget, mergeEntityActions, namespaceToPropertiesOrderPath, namespaceToPropertiesPath, overlayEdit, parseCsvRows, parseCsvToObjects, processValueMapping, propertiesToColumns, removeEmptyContainers, removeInitialAndTrailingSlashes, removeInitialSlash, removeTrailingSlash, renderSkeletonCaptionText, renderSkeletonIcon, renderSkeletonImageThumbnail, renderSkeletonText, resetPasswordAction, resolveCollectionPathIds, resolveCollectionSlotKeys, resolveEntityAction, resolveEntityActionState, resolveEntityView, resolveNavigationFrom, resolveSelection, sanitizeUrl, saveImportedEntities, selectionQueryToFindParams, serializeSelectionQuery, slashDateOrdersByColumn, spanClass, toSerializableCollectionConfig, toSerializableProperties, toSerializableProperty, unescapeCsvFormula, unlinkEntityAction, useAdminContext, useApp, useBreadcrumbsController, useBuildCollectionRegistryController, useBuildNavigationStateController, useBuildSidePanel, useBuildUrlController, useChildViewSource, useClearRestoreValue, useCollectionDataController, useCollectionEditorController, useCollectionRegistryController, useCollectionSlotKeys, useCollectionsConfigController, useDrawerExpandedWhile, useDrawerExpansion, useEntitySlots, useEntityTitle, useHistory, useImportConfig, useJsonCollectionsConfigController, useLiveSchemaEditing, useLocalCollectionsConfigController, useNavigationStateController, useProvidedEditorAIController, useResolvedCollections, useResolvedNavigationFrom, useResolvedUser, useResolvedViews, useSearchExplanation, useSelectionController, useSelectionDialog, useSideDialogContext, useSideDialogsController, useSidePanel, useToolbarLabels, useTopLevelNavigation, useUrlController, validateCollectionJson, zodToFormErrors };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DefaultMissingReference } from "../../components/DefaultMissingReference.js";
|
|
1
2
|
import { useCollectionRegistryController } from "../../hooks/navigation/contexts/CollectionRegistryContext.js";
|
|
2
3
|
import { useEntityPreviewLayout, useIsNestedEntityPreview } from "../../components/EntityPreviewNesting.js";
|
|
3
4
|
import { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from "../../components/EntityPreviewBinding.js";
|
|
@@ -28,7 +29,6 @@ var ReferencePreview = function ReferencePreview(props) {
|
|
|
28
29
|
}
|
|
29
30
|
return /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(ReferencePreviewInternal, { ...props }) });
|
|
30
31
|
};
|
|
31
|
-
var DefaultMissingReference = () => null;
|
|
32
32
|
function ReferencePreviewInternalInner({ disabled, reference, previewProperties, size, hover, onClick, includeEntityLink = true, includeId = true, textOnly, path, collection }) {
|
|
33
33
|
const ResolvedMissingReference = useComponentOverride("Entity.MissingReference", DefaultMissingReference);
|
|
34
34
|
const nested = useIsNestedEntityPreview();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferencePreview.js","names":[],"sources":["../../../src/preview/components/ReferencePreview.tsx"],"sourcesContent":["\nimport * as React from \"react\";\n\nimport { EntityReference } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useCustomizationController, useBatchedFetch, useComponentOverride, CollectionScopeProvider } from \"@rebasepro/app\";\nimport { Skeleton } from \"@rebasepro/ui\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\nimport { ErrorView } from \"@rebasepro/app\";\nimport { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport {\n InlineEntityPreview,\n InlineEntityPreviewMissing,\n InlineEntityPreviewSkeleton\n} from \"../../components/InlineEntityPreview\";\nimport { useEntityPreviewLayout, useIsNestedEntityPreview } from \"../../components/EntityPreviewNesting\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useReferencePaths } from \"../../hooks/useReferencePaths\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport type ReferencePreviewProps = {\n disabled?: boolean;\n reference: EntityReference,\n size?: PreviewSize;\n previewProperties?: string[];\n onClick?: (e: React.SyntheticEvent) => void;\n hover?: boolean;\n includeEntityLink?: boolean;\n includeId?: boolean;\n textOnly?: boolean;\n};\n\n/**\n * @group Preview components\n */\nexport const ReferencePreview = function ReferencePreview(props: ReferencePreviewProps) {\n const reference = props.reference;\n const nested = useIsNestedEntityPreview();\n if (!(typeof reference === \"object\" && \"isEntityReference\" in reference && reference.isEntityReference())) {\n console.warn(\"Reference preview received value of type\", typeof reference);\n if (props.textOnly || nested) {\n return <span>{String(reference)}</span>;\n }\n return <EntityPreviewContainer\n onClick={props.onClick}\n size={props.size ?? \"medium\"}>\n <ErrorView error={\"Unexpected value. Click to edit\"}\n tooltip={JSON.stringify(reference)}/>\n </EntityPreviewContainer>;\n }\n return <ErrorBoundary>\n <ReferencePreviewInternal {...props}/>\n </ErrorBoundary>;\n};\n\nconst DefaultMissingReference: React.FC<{ path: string }> = () => null;\n\nfunction ReferencePreviewInternalInner({\n disabled,\n reference,\n previewProperties,\n size,\n hover,\n onClick,\n includeEntityLink = true,\n includeId = true,\n textOnly,\n path,\n collection\n}: ReferencePreviewProps & { path: string, collection?: AdminCollection }) {\n const ResolvedMissingReference = useComponentOverride(\"Entity.MissingReference\", DefaultMissingReference);\n const nested = useIsNestedEntityPreview();\n\n if (!collection) {\n if (ResolvedMissingReference !== DefaultMissingReference) {\n return <ResolvedMissingReference path={reference.path}/>;\n } else {\n if (textOnly) {\n return <span>{reference.path}</span>;\n }\n if (nested) {\n return <InlineEntityPreviewMissing label={String(reference.id)}\n tooltip={`Collection not found: ${reference.path}`}/>;\n }\n return <EntityPreviewContainer\n onClick={onClick}\n size={size ?? \"medium\"}>\n <ErrorView error={\"Unexpected reference value. Click to edit\"}\n tooltip={reference.pathWithId}/>\n </EntityPreviewContainer>;\n }\n }\n\n return <ReferencePreviewExisting\n reference={reference}\n path={path}\n collection={collection}\n previewProperties={previewProperties}\n size={size}\n disabled={disabled}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n onClick={onClick}\n textOnly={textOnly}\n hover={hover}/>\n}\n\nfunction ReferencePreviewInternal(props: ReferencePreviewProps) {\n const collectionRegistryController = useCollectionRegistryController();\n // The reference carries the path its record is stored under; the\n // collection is looked up, and the record fetched, by the admin's.\n const { toCollectionPath } = useReferencePaths();\n const path = toCollectionPath(props.reference.path, props.reference.driver);\n const collection = collectionRegistryController.getCollection(path);\n\n const content = (\n <ReferencePreviewInternalInner\n {...props}\n path={path}\n collection={collection}\n />\n );\n\n if (collection) {\n return (\n <CollectionScopeProvider collection={collection}>\n {content}\n </CollectionScopeProvider>\n );\n }\n return content;\n}\n\nfunction ReferencePreviewExisting<M extends Record<string, unknown> = Record<string, unknown>>({\n reference,\n path,\n collection,\n previewProperties,\n size,\n disabled,\n includeEntityLink,\n includeId,\n onClick,\n hover,\n textOnly\n}: ReferencePreviewProps & {\n path: string,\n collection: AdminCollection<M>\n}) {\n\n const ResolvedEntityPreview = useComponentOverride(\"EntityPreview\", EntityPreviewBinding);\n const customizationController = useCustomizationController();\n const nested = useIsNestedEntityPreview();\n const layout = useEntityPreviewLayout();\n\n // Nested inside another preview, filling a title slot, or rendered small\n // (a table cell, a list row): one line of text, not a second card. The\n // card only makes sense where there is room for it. See {@link InlineEntityPreview}.\n const inline = nested || Boolean(textOnly) || size === \"small\";\n\n // Batched with every other reference shown in the same tick: one read and\n // one live subscription for a column of 23 distinct targets, where each\n // preview used to open its own `listenById` (23 subscriptions, and 23\n // server refetches per write to the target collection). An array of\n // references in a form is one batch for the whole array.\n const {\n entity,\n dataLoading,\n dataLoadingError\n } = useBatchedFetch({\n path,\n entityId: reference.id,\n collection\n });\n\n // Only what the fetch currently reports — see the note in RelationPreview:\n // the module-level Map that used to back this kept a deleted row on screen\n // for the rest of the session, and across a sign-out.\n const usedEntity = entity;\n\n let body: React.ReactNode;\n\n if (!reference) {\n body = <ErrorView error={\"Reference not set\"}/>;\n } else if (usedEntity && !usedEntity.values) {\n body = <ErrorView error={\"Reference does not exist\"}\n tooltip={reference.path}/>;\n }\n if (body) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(reference.id)}\n tooltip={reference.pathWithId}/>;\n }\n\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n {body}\n </EntityPreviewContainer>\n );\n }\n\n if (dataLoading && !usedEntity) {\n if (inline) {\n return <InlineEntityPreviewSkeleton/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <Skeleton/>\n </EntityPreviewContainer>\n );\n }\n\n if (!usedEntity) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(reference.id)}\n tooltip={\"Entity not found\"}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <ErrorView error={\"Entity not found\"}/>\n </EntityPreviewContainer>\n );\n }\n\n if (inline) {\n return <InlineEntityPreview entity={usedEntity}\n collection={collection}\n disabled={disabled}\n onClick={onClick}\n // In a title slot the row itself is the click target; only a\n // preview nested inside a card opens its own side panel.\n includeEntityLink={!textOnly && includeEntityLink !== false}/>;\n }\n\n // See RelationPreview: a row of a table cell, not a card taller than it.\n if (layout === \"row\" && ResolvedEntityPreview === EntityPreviewBinding) {\n return <EntityPreviewBindingData layout={\"row\"}\n size={size}\n entity={usedEntity}\n collection={collection}\n previewKeys={previewProperties}\n includeEntityLink={!disabled && includeEntityLink !== false}/>;\n }\n\n return <ResolvedEntityPreview size={size}\n previewKeys={previewProperties}\n disabled={disabled}\n entity={usedEntity}\n collection={collection}\n onClick={onClick}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n hover={hover}/>;\n\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,IAAa,mBAAmB,SAAS,iBAAiB,OAA8B;CACpF,MAAM,YAAY,MAAM;CACxB,MAAM,SAAS,yBAAyB;CACxC,IAAI,EAAE,OAAO,cAAc,YAAY,uBAAuB,aAAa,UAAU,kBAAkB,IAAI;EACvG,QAAQ,KAAK,4CAA4C,OAAO,SAAS;E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AS;EAAoB,CAAA;EAErC,OACI,oBAAC,wBAAD;GAAwB,SAAS,WAAW,KAAA,IAAY;GACpD,OAAO,WAAW,KAAA,IAAY;GACxB;aACN,oBAAC,WAAD,EAAW,OAAO,mBAAoB,CAAA;EAClB,CAAA;CAEhC;CAEA,IAAI,QACA,OAAO,oBAAC,qBAAD;EAAqB,QAAQ;EACpB;EACF;EACD;EAGT,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAIrE,IAAI,WAAW,SAAS,0BAA0B,sBAC9C,OAAO,oBAAC,0BAAD;EAA0B,QAAQ;EAC/B;EACN,QAAQ;EACI;EACZ,aAAa;EACb,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAGrE,OAAO,oBAAC,uBAAD;EAA6B;EAChC,aAAa;EACH;EACV,QAAQ;EACI;EACH;EACU;EACR;EACJ;CAAO,CAAA;AAEtB"}
|
|
1
|
+
{"version":3,"file":"ReferencePreview.js","names":[],"sources":["../../../src/preview/components/ReferencePreview.tsx"],"sourcesContent":["\nimport * as React from \"react\";\nimport { DefaultMissingReference } from \"../../components/DefaultMissingReference\";\n\nimport { EntityReference } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useCustomizationController, useBatchedFetch, useComponentOverride, CollectionScopeProvider } from \"@rebasepro/app\";\nimport { Skeleton } from \"@rebasepro/ui\";\nimport { ErrorBoundary } from \"@rebasepro/ui\";\nimport { ErrorView } from \"@rebasepro/app\";\nimport { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport {\n InlineEntityPreview,\n InlineEntityPreviewMissing,\n InlineEntityPreviewSkeleton\n} from \"../../components/InlineEntityPreview\";\nimport { useEntityPreviewLayout, useIsNestedEntityPreview } from \"../../components/EntityPreviewNesting\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { useReferencePaths } from \"../../hooks/useReferencePaths\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport type ReferencePreviewProps = {\n disabled?: boolean;\n reference: EntityReference,\n size?: PreviewSize;\n previewProperties?: string[];\n onClick?: (e: React.SyntheticEvent) => void;\n hover?: boolean;\n includeEntityLink?: boolean;\n includeId?: boolean;\n textOnly?: boolean;\n};\n\n/**\n * @group Preview components\n */\nexport const ReferencePreview = function ReferencePreview(props: ReferencePreviewProps) {\n const reference = props.reference;\n const nested = useIsNestedEntityPreview();\n if (!(typeof reference === \"object\" && \"isEntityReference\" in reference && reference.isEntityReference())) {\n console.warn(\"Reference preview received value of type\", typeof reference);\n if (props.textOnly || nested) {\n return <span>{String(reference)}</span>;\n }\n return <EntityPreviewContainer\n onClick={props.onClick}\n size={props.size ?? \"medium\"}>\n <ErrorView error={\"Unexpected value. Click to edit\"}\n tooltip={JSON.stringify(reference)}/>\n </EntityPreviewContainer>;\n }\n return <ErrorBoundary>\n <ReferencePreviewInternal {...props}/>\n </ErrorBoundary>;\n};\n\n\nfunction ReferencePreviewInternalInner({\n disabled,\n reference,\n previewProperties,\n size,\n hover,\n onClick,\n includeEntityLink = true,\n includeId = true,\n textOnly,\n path,\n collection\n}: ReferencePreviewProps & { path: string, collection?: AdminCollection }) {\n const ResolvedMissingReference = useComponentOverride(\"Entity.MissingReference\", DefaultMissingReference);\n const nested = useIsNestedEntityPreview();\n\n if (!collection) {\n if (ResolvedMissingReference !== DefaultMissingReference) {\n return <ResolvedMissingReference path={reference.path}/>;\n } else {\n if (textOnly) {\n return <span>{reference.path}</span>;\n }\n if (nested) {\n return <InlineEntityPreviewMissing label={String(reference.id)}\n tooltip={`Collection not found: ${reference.path}`}/>;\n }\n return <EntityPreviewContainer\n onClick={onClick}\n size={size ?? \"medium\"}>\n <ErrorView error={\"Unexpected reference value. Click to edit\"}\n tooltip={reference.pathWithId}/>\n </EntityPreviewContainer>;\n }\n }\n\n return <ReferencePreviewExisting\n reference={reference}\n path={path}\n collection={collection}\n previewProperties={previewProperties}\n size={size}\n disabled={disabled}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n onClick={onClick}\n textOnly={textOnly}\n hover={hover}/>\n}\n\nfunction ReferencePreviewInternal(props: ReferencePreviewProps) {\n const collectionRegistryController = useCollectionRegistryController();\n // The reference carries the path its record is stored under; the\n // collection is looked up, and the record fetched, by the admin's.\n const { toCollectionPath } = useReferencePaths();\n const path = toCollectionPath(props.reference.path, props.reference.driver);\n const collection = collectionRegistryController.getCollection(path);\n\n const content = (\n <ReferencePreviewInternalInner\n {...props}\n path={path}\n collection={collection}\n />\n );\n\n if (collection) {\n return (\n <CollectionScopeProvider collection={collection}>\n {content}\n </CollectionScopeProvider>\n );\n }\n return content;\n}\n\nfunction ReferencePreviewExisting<M extends Record<string, unknown> = Record<string, unknown>>({\n reference,\n path,\n collection,\n previewProperties,\n size,\n disabled,\n includeEntityLink,\n includeId,\n onClick,\n hover,\n textOnly\n}: ReferencePreviewProps & {\n path: string,\n collection: AdminCollection<M>\n}) {\n\n const ResolvedEntityPreview = useComponentOverride(\"EntityPreview\", EntityPreviewBinding);\n const customizationController = useCustomizationController();\n const nested = useIsNestedEntityPreview();\n const layout = useEntityPreviewLayout();\n\n // Nested inside another preview, filling a title slot, or rendered small\n // (a table cell, a list row): one line of text, not a second card. The\n // card only makes sense where there is room for it. See {@link InlineEntityPreview}.\n const inline = nested || Boolean(textOnly) || size === \"small\";\n\n // Batched with every other reference shown in the same tick: one read and\n // one live subscription for a column of 23 distinct targets, where each\n // preview used to open its own `listenById` (23 subscriptions, and 23\n // server refetches per write to the target collection). An array of\n // references in a form is one batch for the whole array.\n const {\n entity,\n dataLoading,\n dataLoadingError\n } = useBatchedFetch({\n path,\n entityId: reference.id,\n collection\n });\n\n // Only what the fetch currently reports — see the note in RelationPreview:\n // the module-level Map that used to back this kept a deleted row on screen\n // for the rest of the session, and across a sign-out.\n const usedEntity = entity;\n\n let body: React.ReactNode;\n\n if (!reference) {\n body = <ErrorView error={\"Reference not set\"}/>;\n } else if (usedEntity && !usedEntity.values) {\n body = <ErrorView error={\"Reference does not exist\"}\n tooltip={reference.path}/>;\n }\n if (body) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(reference.id)}\n tooltip={reference.pathWithId}/>;\n }\n\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n {body}\n </EntityPreviewContainer>\n );\n }\n\n if (dataLoading && !usedEntity) {\n if (inline) {\n return <InlineEntityPreviewSkeleton/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <Skeleton/>\n </EntityPreviewContainer>\n );\n }\n\n if (!usedEntity) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(reference.id)}\n tooltip={\"Entity not found\"}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <ErrorView error={\"Entity not found\"}/>\n </EntityPreviewContainer>\n );\n }\n\n if (inline) {\n return <InlineEntityPreview entity={usedEntity}\n collection={collection}\n disabled={disabled}\n onClick={onClick}\n // In a title slot the row itself is the click target; only a\n // preview nested inside a card opens its own side panel.\n includeEntityLink={!textOnly && includeEntityLink !== false}/>;\n }\n\n // See RelationPreview: a row of a table cell, not a card taller than it.\n if (layout === \"row\" && ResolvedEntityPreview === EntityPreviewBinding) {\n return <EntityPreviewBindingData layout={\"row\"}\n size={size}\n entity={usedEntity}\n collection={collection}\n previewKeys={previewProperties}\n includeEntityLink={!disabled && includeEntityLink !== false}/>;\n }\n\n return <ResolvedEntityPreview size={size}\n previewKeys={previewProperties}\n disabled={disabled}\n entity={usedEntity}\n collection={collection}\n onClick={onClick}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n hover={hover}/>;\n\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,IAAa,mBAAmB,SAAS,iBAAiB,OAA8B;CACpF,MAAM,YAAY,MAAM;CACxB,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AAA;CAEhC;CAEA,IAAI,CAAC,YAAY;EACb,IAAI,QACA,OAAO,oBAAC,4BAAD;GAA4B,OAAO,OAAO,UAAU,EAAE;GACzD,SAAS;EAAoB,CAAA;EAErC,OACI,oBAAC,wBAAD;GAAwB,SAAS,WAAW,KAAA,IAAY;GACpD,OAAO,WAAW,KAAA,IAAY;GACxB;aACN,oBAAC,WAAD,EAAW,OAAO,mBAAoB,CAAA;EAClB,CAAA;CAEhC;CAEA,IAAI,QACA,OAAO,oBAAC,qBAAD;EAAqB,QAAQ;EACpB;EACF;EACD;EAGT,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAIrE,IAAI,WAAW,SAAS,0BAA0B,sBAC9C,OAAO,oBAAC,0BAAD;EAA0B,QAAQ;EAC/B;EACN,QAAQ;EACI;EACZ,aAAa;EACb,mBAAmB,CAAC,YAAY,sBAAsB;CAAO,CAAA;CAGrE,OAAO,oBAAC,uBAAD;EAA6B;EAChC,aAAa;EACH;EACV,QAAQ;EACI;EACH;EACU;EACR;EACJ;CAAO,CAAA;AAEtB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DefaultMissingReference } from "../../components/DefaultMissingReference.js";
|
|
1
2
|
import { useCollectionRegistryController } from "../../hooks/navigation/contexts/CollectionRegistryContext.js";
|
|
2
3
|
import { useEntityPreviewLayout, useIsNestedEntityPreview } from "../../components/EntityPreviewNesting.js";
|
|
3
4
|
import { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from "../../components/EntityPreviewBinding.js";
|
|
@@ -69,7 +70,6 @@ var RelationPreview = function RelationPreview(props) {
|
|
|
69
70
|
}
|
|
70
71
|
return /* @__PURE__ */ jsx(RelationPreviewInternal, { ...props });
|
|
71
72
|
};
|
|
72
|
-
var DefaultMissingReference = () => null;
|
|
73
73
|
function RelationPreviewInternalInner({ disabled, relation, previewProperties, size, hover, onClick, includeEntityLink = true, includeId = true, textOnly, collection }) {
|
|
74
74
|
const ResolvedMissingReference = useComponentOverride("Entity.MissingReference", DefaultMissingReference);
|
|
75
75
|
const nested = useIsNestedEntityPreview();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationPreview.js","names":[],"sources":["../../../src/preview/components/RelationPreview.tsx"],"sourcesContent":["\nimport * as React from \"react\";\n\nimport { Entity, EntityRelation } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useCustomizationController, useFetch, ErrorView, useComponentOverride, CollectionScopeProvider } from \"@rebasepro/app\";\nimport { Skeleton } from \"@rebasepro/ui\";\nimport { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport {\n InlineEntityPreview,\n InlineEntityPreviewMissing,\n InlineEntityPreviewSkeleton\n} from \"../../components/InlineEntityPreview\";\nimport { useEntityPreviewLayout, useIsNestedEntityPreview } from \"../../components/EntityPreviewNesting\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport type RelationPreviewProps = {\n disabled?: boolean;\n relation: EntityRelation,\n size?: PreviewSize;\n previewProperties?: string[];\n onClick?: (e: React.SyntheticEvent) => void;\n hover?: boolean;\n includeEntityLink?: boolean;\n includeId?: boolean;\n textOnly?: boolean;\n};\n\n/**\n * Extract a display name from a plain relation-shaped object that isn't\n * a proper EntityRelation instance. Tries common name fields in the\n * entity's values, then falls back to the id.\n */\nfunction extractDisplayFromPlainObject(obj: unknown): string {\n if (!obj || typeof obj !== \"object\") return \"—\";\n const record = obj as Record<string, unknown>;\n\n // Try data.values.{name,title,...} (EntityRelation.data is a Entity with .values)\n const data = record.data;\n if (data && typeof data === \"object\") {\n const dataRecord = data as Record<string, unknown>;\n const values = (dataRecord.values && typeof dataRecord.values === \"object\")\n ? dataRecord.values as Record<string, unknown>\n : dataRecord;\n const nameFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\", \"username\"];\n for (const field of nameFields) {\n const v = values[field];\n if (v && typeof v === \"string\") return v;\n }\n }\n\n // Try direct fields on the object itself (some serialization paths flatten the data)\n const directFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\"];\n for (const field of directFields) {\n const v = record[field];\n if (v && typeof v === \"string\") return v;\n }\n\n // Last resort: show the id\n if (\"id\" in record && record.id != null) return String(record.id);\n\n return \"—\";\n}\n\n/**\n * @group Preview components\n */\nexport const RelationPreview = function RelationPreview(props: RelationPreviewProps) {\n const relation = props.relation;\n const nested = useIsNestedEntityPreview();\n if (!(typeof relation === \"object\" && \"isEntityRelation\" in relation && relation.isEntityRelation())) {\n console.warn(\"Relation preview received value of type\", typeof relation);\n if (props.textOnly || nested) {\n const display = extractDisplayFromPlainObject(relation);\n return <span className=\"truncate\">{display}</span>;\n }\n return <EntityPreviewContainer\n onClick={props.onClick}\n size={props.size}>\n <ErrorView error={\"Unexpected value. Click to edit\"}\n tooltip={JSON.stringify(relation)}/>\n </EntityPreviewContainer>;\n }\n return <RelationPreviewInternal {...props}/>;\n};\n\nconst DefaultMissingReference: React.FC<{ path: string }> = () => null;\n\nfunction RelationPreviewInternalInner({\n disabled,\n relation,\n previewProperties,\n size,\n hover,\n onClick,\n includeEntityLink = true,\n includeId = true,\n textOnly,\n collection\n}: RelationPreviewProps & { collection?: AdminCollection }) {\n const ResolvedMissingReference = useComponentOverride(\"Entity.MissingReference\", DefaultMissingReference);\n const nested = useIsNestedEntityPreview();\n\n if (!collection) {\n if (ResolvedMissingReference !== DefaultMissingReference) {\n return <ResolvedMissingReference path={relation.path}/>;\n } else {\n if (textOnly) {\n return <span>{relation.path}</span>;\n }\n if (nested) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={`Collection not found: ${relation.path}`}/>;\n }\n return <EntityPreviewContainer size={size}>\n <ErrorView error={`Collection not found: ${relation.path}`}/>\n </EntityPreviewContainer>;\n }\n }\n\n return <RelationPreviewExisting\n relation={relation}\n collection={collection}\n previewProperties={previewProperties}\n size={size}\n disabled={disabled}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n onClick={onClick}\n textOnly={textOnly}\n hover={hover}/>\n}\n\nfunction RelationPreviewInternal(props: RelationPreviewProps) {\n const collectionRegistryController = useCollectionRegistryController();\n const collection = collectionRegistryController.getCollection(props.relation.path);\n\n const content = (\n <RelationPreviewInternalInner\n {...props}\n collection={collection}\n />\n );\n\n if (collection) {\n return (\n <CollectionScopeProvider collection={collection}>\n {content}\n </CollectionScopeProvider>\n );\n }\n return content;\n}\n\nfunction RelationPreviewExisting<M extends Record<string, unknown> = Record<string, unknown>>({\n relation,\n collection,\n previewProperties,\n size,\n disabled,\n includeEntityLink,\n includeId,\n onClick,\n hover,\n textOnly\n}: RelationPreviewProps & {\n collection: AdminCollection<M>\n}) {\n\n // admin wire format embeds relation data as { id, path, values }\n const passedEntity = relation.data as Entity<M> | undefined;\n const ResolvedEntityPreview = useComponentOverride(\"EntityPreview\", EntityPreviewBinding);\n const customizationController = useCustomizationController();\n const nested = useIsNestedEntityPreview();\n const layout = useEntityPreviewLayout();\n\n // Nested inside another preview, filling a title slot, or rendered small\n // (a table cell, a list row): one line of text, not a second card. The\n // card only makes sense where there is room for it. See {@link InlineEntityPreview}.\n const inline = nested || Boolean(textOnly) || size === \"small\";\n\n const {\n entity,\n dataLoading,\n dataLoadingError\n } = useFetch({\n path: relation.path,\n entityId: passedEntity ? undefined : relation.id,\n collection,\n useCache: true\n });\n\n // Only what the fetch currently reports. There used to be a module-level\n // Map behind this, written on every successful fetch and never invalidated:\n // when the target row was deleted `useFetch` correctly reported it gone and\n // the card carried on rendering the copy in the Map, so the \"missing\"\n // branches below were unreachable for anything previewed this session — and\n // the Map outlived a sign-out. `useFetch` keeps its own cache, seeds the\n // first render from it, and clears the entry when the row disappears.\n const usedEntity = passedEntity ?? entity;\n\n let body: React.ReactNode;\n\n if (!relation) {\n body = <ErrorView error={\"Relation not set\"}/>;\n } else if (usedEntity && !usedEntity.values) {\n body = <ErrorView error={\"Relation does not exist\"}\n tooltip={relation.path}/>;\n }\n\n if (body) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={relation.pathWithId}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n {body}\n </EntityPreviewContainer>\n );\n }\n\n if (dataLoading && !usedEntity) {\n if (inline) {\n return <InlineEntityPreviewSkeleton/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <Skeleton/>\n </EntityPreviewContainer>\n );\n }\n\n if (!usedEntity) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={\"Entity not found\"}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <ErrorView error={\"Entity not found\"}/>\n </EntityPreviewContainer>\n );\n }\n\n if (inline) {\n return <InlineEntityPreview entity={usedEntity}\n collection={collection}\n disabled={disabled}\n onClick={onClick}\n // In a title slot the row itself is the click target; only a\n // preview nested inside a card opens its own side panel.\n includeEntityLink={!textOnly && includeEntityLink !== false}/>;\n }\n\n // A table cell tall enough for more than a line: the record as a row of\n // it, not a card taller than the row. An overridden preview is the\n // developer's own and is drawn as given.\n if (layout === \"row\" && ResolvedEntityPreview === EntityPreviewBinding) {\n return <EntityPreviewBindingData layout={\"row\"}\n size={size}\n entity={usedEntity}\n collection={collection}\n previewKeys={previewProperties}\n includeEntityLink={!disabled && includeEntityLink !== false}/>;\n }\n\n return <ResolvedEntityPreview size={size}\n previewKeys={previewProperties}\n disabled={disabled}\n entity={usedEntity}\n collection={collection}\n onClick={onClick}\n includeEntityLink={includeEntityLink}\n includeId={false}\n hover={hover}/>;\n\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,SAAS,8BAA8B,KAAsB;CACzD,IAAI,CAAC,OAAO,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CAAO,CAAA;AAEtB"}
|
|
1
|
+
{"version":3,"file":"RelationPreview.js","names":[],"sources":["../../../src/preview/components/RelationPreview.tsx"],"sourcesContent":["\nimport * as React from \"react\";\nimport { DefaultMissingReference } from \"../../components/DefaultMissingReference\";\n\nimport { Entity, EntityRelation } from \"@rebasepro/types\";\nimport type { PreviewSize } from \"../../types/components/PropertyPreviewProps\";\nimport { useCustomizationController, useFetch, ErrorView, useComponentOverride, CollectionScopeProvider } from \"@rebasepro/app\";\nimport { Skeleton } from \"@rebasepro/ui\";\nimport { EntityPreviewBinding, EntityPreviewBindingData, EntityPreviewContainer } from \"../../components/EntityPreviewBinding\";\nimport {\n InlineEntityPreview,\n InlineEntityPreviewMissing,\n InlineEntityPreviewSkeleton\n} from \"../../components/InlineEntityPreview\";\nimport { useEntityPreviewLayout, useIsNestedEntityPreview } from \"../../components/EntityPreviewNesting\";\nimport { useCollectionRegistryController } from \"../../hooks/navigation/contexts/CollectionRegistryContext\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\nexport type RelationPreviewProps = {\n disabled?: boolean;\n relation: EntityRelation,\n size?: PreviewSize;\n previewProperties?: string[];\n onClick?: (e: React.SyntheticEvent) => void;\n hover?: boolean;\n includeEntityLink?: boolean;\n includeId?: boolean;\n textOnly?: boolean;\n};\n\n/**\n * Extract a display name from a plain relation-shaped object that isn't\n * a proper EntityRelation instance. Tries common name fields in the\n * entity's values, then falls back to the id.\n */\nfunction extractDisplayFromPlainObject(obj: unknown): string {\n if (!obj || typeof obj !== \"object\") return \"—\";\n const record = obj as Record<string, unknown>;\n\n // Try data.values.{name,title,...} (EntityRelation.data is a Entity with .values)\n const data = record.data;\n if (data && typeof data === \"object\") {\n const dataRecord = data as Record<string, unknown>;\n const values = (dataRecord.values && typeof dataRecord.values === \"object\")\n ? dataRecord.values as Record<string, unknown>\n : dataRecord;\n const nameFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\", \"username\"];\n for (const field of nameFields) {\n const v = values[field];\n if (v && typeof v === \"string\") return v;\n }\n }\n\n // Try direct fields on the object itself (some serialization paths flatten the data)\n const directFields = [\"name\", \"title\", \"label\", \"display_name\", \"displayName\", \"email\"];\n for (const field of directFields) {\n const v = record[field];\n if (v && typeof v === \"string\") return v;\n }\n\n // Last resort: show the id\n if (\"id\" in record && record.id != null) return String(record.id);\n\n return \"—\";\n}\n\n/**\n * @group Preview components\n */\nexport const RelationPreview = function RelationPreview(props: RelationPreviewProps) {\n const relation = props.relation;\n const nested = useIsNestedEntityPreview();\n if (!(typeof relation === \"object\" && \"isEntityRelation\" in relation && relation.isEntityRelation())) {\n console.warn(\"Relation preview received value of type\", typeof relation);\n if (props.textOnly || nested) {\n const display = extractDisplayFromPlainObject(relation);\n return <span className=\"truncate\">{display}</span>;\n }\n return <EntityPreviewContainer\n onClick={props.onClick}\n size={props.size}>\n <ErrorView error={\"Unexpected value. Click to edit\"}\n tooltip={JSON.stringify(relation)}/>\n </EntityPreviewContainer>;\n }\n return <RelationPreviewInternal {...props}/>;\n};\n\n\nfunction RelationPreviewInternalInner({\n disabled,\n relation,\n previewProperties,\n size,\n hover,\n onClick,\n includeEntityLink = true,\n includeId = true,\n textOnly,\n collection\n}: RelationPreviewProps & { collection?: AdminCollection }) {\n const ResolvedMissingReference = useComponentOverride(\"Entity.MissingReference\", DefaultMissingReference);\n const nested = useIsNestedEntityPreview();\n\n if (!collection) {\n if (ResolvedMissingReference !== DefaultMissingReference) {\n return <ResolvedMissingReference path={relation.path}/>;\n } else {\n if (textOnly) {\n return <span>{relation.path}</span>;\n }\n if (nested) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={`Collection not found: ${relation.path}`}/>;\n }\n return <EntityPreviewContainer size={size}>\n <ErrorView error={`Collection not found: ${relation.path}`}/>\n </EntityPreviewContainer>;\n }\n }\n\n return <RelationPreviewExisting\n relation={relation}\n collection={collection}\n previewProperties={previewProperties}\n size={size}\n disabled={disabled}\n includeEntityLink={includeEntityLink}\n includeId={includeId}\n onClick={onClick}\n textOnly={textOnly}\n hover={hover}/>\n}\n\nfunction RelationPreviewInternal(props: RelationPreviewProps) {\n const collectionRegistryController = useCollectionRegistryController();\n const collection = collectionRegistryController.getCollection(props.relation.path);\n\n const content = (\n <RelationPreviewInternalInner\n {...props}\n collection={collection}\n />\n );\n\n if (collection) {\n return (\n <CollectionScopeProvider collection={collection}>\n {content}\n </CollectionScopeProvider>\n );\n }\n return content;\n}\n\nfunction RelationPreviewExisting<M extends Record<string, unknown> = Record<string, unknown>>({\n relation,\n collection,\n previewProperties,\n size,\n disabled,\n includeEntityLink,\n includeId,\n onClick,\n hover,\n textOnly\n}: RelationPreviewProps & {\n collection: AdminCollection<M>\n}) {\n\n // admin wire format embeds relation data as { id, path, values }\n const passedEntity = relation.data as Entity<M> | undefined;\n const ResolvedEntityPreview = useComponentOverride(\"EntityPreview\", EntityPreviewBinding);\n const customizationController = useCustomizationController();\n const nested = useIsNestedEntityPreview();\n const layout = useEntityPreviewLayout();\n\n // Nested inside another preview, filling a title slot, or rendered small\n // (a table cell, a list row): one line of text, not a second card. The\n // card only makes sense where there is room for it. See {@link InlineEntityPreview}.\n const inline = nested || Boolean(textOnly) || size === \"small\";\n\n const {\n entity,\n dataLoading,\n dataLoadingError\n } = useFetch({\n path: relation.path,\n entityId: passedEntity ? undefined : relation.id,\n collection,\n useCache: true\n });\n\n // Only what the fetch currently reports. There used to be a module-level\n // Map behind this, written on every successful fetch and never invalidated:\n // when the target row was deleted `useFetch` correctly reported it gone and\n // the card carried on rendering the copy in the Map, so the \"missing\"\n // branches below were unreachable for anything previewed this session — and\n // the Map outlived a sign-out. `useFetch` keeps its own cache, seeds the\n // first render from it, and clears the entry when the row disappears.\n const usedEntity = passedEntity ?? entity;\n\n let body: React.ReactNode;\n\n if (!relation) {\n body = <ErrorView error={\"Relation not set\"}/>;\n } else if (usedEntity && !usedEntity.values) {\n body = <ErrorView error={\"Relation does not exist\"}\n tooltip={relation.path}/>;\n }\n\n if (body) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={relation.pathWithId}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n {body}\n </EntityPreviewContainer>\n );\n }\n\n if (dataLoading && !usedEntity) {\n if (inline) {\n return <InlineEntityPreviewSkeleton/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <Skeleton/>\n </EntityPreviewContainer>\n );\n }\n\n if (!usedEntity) {\n if (inline) {\n return <InlineEntityPreviewMissing label={String(relation.id)}\n tooltip={\"Entity not found\"}/>;\n }\n return (\n <EntityPreviewContainer onClick={disabled ? undefined : onClick}\n hover={disabled ? undefined : hover}\n size={size}>\n <ErrorView error={\"Entity not found\"}/>\n </EntityPreviewContainer>\n );\n }\n\n if (inline) {\n return <InlineEntityPreview entity={usedEntity}\n collection={collection}\n disabled={disabled}\n onClick={onClick}\n // In a title slot the row itself is the click target; only a\n // preview nested inside a card opens its own side panel.\n includeEntityLink={!textOnly && includeEntityLink !== false}/>;\n }\n\n // A table cell tall enough for more than a line: the record as a row of\n // it, not a card taller than the row. An overridden preview is the\n // developer's own and is drawn as given.\n if (layout === \"row\" && ResolvedEntityPreview === EntityPreviewBinding) {\n return <EntityPreviewBindingData layout={\"row\"}\n size={size}\n entity={usedEntity}\n collection={collection}\n previewKeys={previewProperties}\n includeEntityLink={!disabled && includeEntityLink !== false}/>;\n }\n\n return <ResolvedEntityPreview size={size}\n previewKeys={previewProperties}\n disabled={disabled}\n entity={usedEntity}\n collection={collection}\n onClick={onClick}\n includeEntityLink={includeEntityLink}\n includeId={false}\n hover={hover}/>;\n\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,SAAS,8BAA8B,KAAsB;CACzD,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAC5C,MAAM,SAAS;CAGf,MAAM,OAAO,OAAO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
|
path: string;
|
|
13
13
|
fullIdPath?: string;
|
|
14
14
|
collection: AdminCollection<M>;
|
|
15
|
+
/**
|
|
16
|
+
* The record's id. On a new record (`initialStatus: "new"`), the id it is
|
|
17
|
+
* created under; omit it to let the data source assign one.
|
|
18
|
+
*/
|
|
15
19
|
entityId?: string | number;
|
|
16
20
|
entity?: Entity<M>;
|
|
17
21
|
databaseId?: string;
|
|
@@ -74,6 +78,13 @@ export type EntityFormProps<M extends Record<string, unknown>> = {
|
|
|
74
78
|
name: string;
|
|
75
79
|
value: unknown;
|
|
76
80
|
}) => Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* Properties a new record takes from its address rather than from the
|
|
83
|
+
* user: the link back to the parent of a record created under
|
|
84
|
+
* `parent/{id}/{relation}`. Shown and disabled while the record is new.
|
|
85
|
+
* The EntityFormBinding wrapper fills these in.
|
|
86
|
+
*/
|
|
87
|
+
lockedPropertyKeys?: string[];
|
|
77
88
|
/** Content rendered before the form fields */
|
|
78
89
|
beforeFields?: React.ReactNode;
|
|
79
90
|
/** Content rendered after the form fields */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Rebase CMS — content management views, forms, and routing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rebase",
|
|
@@ -93,14 +93,14 @@
|
|
|
93
93
|
"react-use-measure": "^2.1.7",
|
|
94
94
|
"read-excel-file": "^9.3.10",
|
|
95
95
|
"zod": "^4.4.3",
|
|
96
|
-
"@rebasepro/app": "0.
|
|
97
|
-
"@rebasepro/
|
|
98
|
-
"@rebasepro/
|
|
99
|
-
"@rebasepro/
|
|
100
|
-
"@rebasepro/inference": "0.
|
|
101
|
-
"@rebasepro/types": "0.
|
|
102
|
-
"@rebasepro/
|
|
103
|
-
"@rebasepro/
|
|
96
|
+
"@rebasepro/app": "0.27.0",
|
|
97
|
+
"@rebasepro/common": "0.27.0",
|
|
98
|
+
"@rebasepro/cms-types": "0.27.0",
|
|
99
|
+
"@rebasepro/forms": "0.27.0",
|
|
100
|
+
"@rebasepro/inference": "0.27.0",
|
|
101
|
+
"@rebasepro/types": "0.27.0",
|
|
102
|
+
"@rebasepro/utils": "0.27.0",
|
|
103
|
+
"@rebasepro/ui": "0.27.0"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"react": "^19.2.7",
|
|
@@ -127,7 +127,8 @@
|
|
|
127
127
|
"vite": "^8.1.5"
|
|
128
128
|
},
|
|
129
129
|
"files": [
|
|
130
|
-
"dist"
|
|
130
|
+
"dist",
|
|
131
|
+
"recipes"
|
|
131
132
|
],
|
|
132
133
|
"gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
|
|
133
134
|
"publishConfig": {
|