@rebasepro/admin 0.13.0 → 0.13.1-canary.g394d868
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/{CollectionEditorDialog-CjXkWZ64.js → CollectionEditorDialog-D78xsXgL.js} +3 -3
- package/dist/{CollectionEditorDialog-CjXkWZ64.js.map → CollectionEditorDialog-D78xsXgL.js.map} +1 -1
- package/dist/{PropertyEditView-W8I3YV89.js → PropertyEditView-B88EC-1f.js} +2 -2
- package/dist/{PropertyEditView-W8I3YV89.js.map → PropertyEditView-B88EC-1f.js.map} +1 -1
- package/dist/{RouterCollectionsStudioView-BsLTNoqX.js → RouterCollectionsStudioView-B1Ws7h9l.js} +4 -4
- package/dist/{RouterCollectionsStudioView-BsLTNoqX.js.map → RouterCollectionsStudioView-B1Ws7h9l.js.map} +1 -1
- package/dist/collection_editor/serializable_types.d.ts +1 -0
- package/dist/collection_editor_ui.js +4 -4
- package/dist/components/AdditionalFieldValue.d.ts +25 -0
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +16 -0
- package/dist/components/CollectionViewBinding/SlotValue.d.ts +63 -0
- package/dist/components/CollectionViewBinding/SplitListCloseButton.d.ts +17 -4
- package/dist/components/CollectionViewBinding/SplitListShowButton.d.ts +12 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +55 -5
- package/dist/components/DetailViewBinding.d.ts +15 -0
- package/dist/components/DrawerNavigationGroup.d.ts +9 -6
- package/dist/components/DrawerNavigationItem.d.ts +16 -6
- package/dist/components/EditViewBinding.d.ts +30 -1
- package/dist/components/EntityDisplayHeader.d.ts +53 -0
- package/dist/components/EntityIdentityBar.d.ts +43 -1
- package/dist/components/EntityViewBinding.d.ts +60 -6
- package/dist/components/RebaseLayout.d.ts +1 -1
- package/dist/components/RebaseShell.d.ts +1 -1
- package/dist/components/RelationSelector.d.ts +8 -1
- package/dist/components/UserSelector.d.ts +8 -1
- package/dist/components/app/Scaffold.d.ts +9 -3
- package/dist/components/index.d.ts +2 -0
- package/dist/{export-J79rMoNj.js → export-BZhdWhkB.js} +2 -2
- package/dist/{export-J79rMoNj.js.map → export-BZhdWhkB.js.map} +1 -1
- package/dist/form/components/FieldBlock.d.ts +58 -4
- package/dist/form/components/FormRail.d.ts +13 -0
- package/dist/form/components/FormSections.d.ts +15 -1
- package/dist/form/components/useRailVisible.d.ts +5 -4
- package/dist/form/form_utils.d.ts +38 -1
- package/dist/{history-D7L_JlLO.js → history-BPpt68CL.js} +4 -4
- package/dist/{history-D7L_JlLO.js.map → history-BPpt68CL.js.map} +1 -1
- package/dist/hooks/useEntityDisplay.d.ts +102 -0
- package/dist/hooks/useEntityDisplayTitle.d.ts +18 -9
- package/dist/{import-BvYl--U4.js → import-gRfemegK.js} +3 -3
- package/dist/{import-BvYl--U4.js.map → import-gRfemegK.js.map} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +152 -57
- package/dist/index.js.map +1 -1
- package/dist/preview/compact_text.d.ts +23 -0
- package/dist/preview/components/BooleanPreview.d.ts +3 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
- package/dist/routes/RebaseRoute.d.ts +1 -1
- package/dist/types/components/PropertyPreviewProps.d.ts +19 -0
- package/dist/util/number_format.d.ts +14 -0
- package/dist/util/previews.d.ts +9 -2
- package/dist/{util-GiwPgxnL.js → util-BHq3VOjH.js} +9080 -7861
- package/dist/util-BHq3VOjH.js.map +1 -0
- package/package.json +9 -9
- package/src/collection_editor/serializable_types.ts +1 -0
- package/src/components/AdditionalFieldValue.tsx +68 -0
- package/src/components/CollectionTableBinding/CollectionTableBinding.tsx +7 -8
- package/src/components/CollectionTableBinding/PropertyTableCell.tsx +2 -2
- package/src/components/CollectionTableBinding/column_utils.tsx +15 -6
- package/src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx +2 -2
- package/src/components/CollectionViewBinding/BoardCardBinding.tsx +26 -27
- package/src/components/CollectionViewBinding/CollectionListViewBinding.tsx +172 -112
- package/src/components/CollectionViewBinding/CollectionViewActions.tsx +1 -1
- package/src/components/CollectionViewBinding/CollectionViewBinding.tsx +38 -8
- package/src/components/CollectionViewBinding/EntityCardBinding.tsx +23 -36
- package/src/components/CollectionViewBinding/SlotValue.tsx +156 -0
- package/src/components/CollectionViewBinding/SplitListCloseButton.tsx +23 -7
- package/src/components/CollectionViewBinding/SplitListShowButton.tsx +28 -0
- package/src/components/CollectionViewBinding/SplitListView.tsx +33 -2
- package/src/components/CollectionViewBinding/useBoardDataController.tsx +12 -3
- package/src/components/CollectionViewBinding/usePreviewSlots.ts +177 -54
- package/src/components/DefaultDrawer.tsx +19 -23
- package/src/components/DetailViewBinding.tsx +87 -55
- package/src/components/DrawerNavigationGroup.tsx +16 -39
- package/src/components/DrawerNavigationItem.tsx +44 -16
- package/src/components/EditViewBinding.tsx +211 -41
- package/src/components/EntityDisplayHeader.tsx +170 -0
- package/src/components/EntityIdentityBar.tsx +149 -23
- package/src/components/EntityPreviewBinding.tsx +58 -18
- package/src/components/EntityViewBinding.tsx +342 -41
- package/src/components/InlineEntityPreview.tsx +10 -10
- package/src/components/RebaseLayout.tsx +2 -2
- package/src/components/RebaseShell.tsx +2 -2
- package/src/components/ReferenceTable/SelectionTableBinding.tsx +4 -2
- package/src/components/RelationSelector.tsx +15 -4
- package/src/components/SideDialogs.tsx +15 -3
- package/src/components/SidePanelBinding.tsx +122 -66
- package/src/components/UserSelector.tsx +15 -4
- package/src/components/app/Scaffold.tsx +112 -10
- package/src/components/index.ts +3 -0
- package/src/form/EntityForm.tsx +64 -52
- package/src/form/EntityFormBinding.tsx +24 -11
- package/src/form/PropertyFieldBinding.tsx +2 -2
- package/src/form/components/FieldBlock.tsx +80 -10
- package/src/form/components/FormRail.tsx +19 -2
- package/src/form/components/FormSections.tsx +32 -5
- package/src/form/components/StorageUploadProgress.tsx +9 -3
- package/src/form/components/useRailVisible.tsx +5 -4
- package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +2 -2
- package/src/form/field_bindings/BinaryFieldBinding.tsx +10 -5
- package/src/form/field_bindings/BlockFieldBinding.tsx +3 -3
- package/src/form/field_bindings/GeopointFieldBinding.tsx +23 -16
- package/src/form/field_bindings/MapFieldBinding.tsx +2 -2
- package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +13 -7
- package/src/form/field_bindings/MultiSelectFieldBinding.tsx +7 -1
- package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +7 -1
- package/src/form/field_bindings/ReferenceFieldBinding.tsx +1 -1
- package/src/form/field_bindings/RelationFieldBinding.tsx +5 -2
- package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -3
- package/src/form/field_bindings/StorageUploadFieldBinding.tsx +2 -2
- package/src/form/field_bindings/UserSelectFieldBinding.tsx +4 -1
- package/src/form/field_bindings/VectorFieldBinding.tsx +6 -4
- package/src/form/form_utils.ts +78 -0
- package/src/hooks/navigation/useBuildCollectionRegistryController.tsx +29 -5
- package/src/hooks/useEntityDisplay.tsx +262 -0
- package/src/hooks/useEntityDisplayTitle.tsx +27 -38
- package/src/index.ts +9 -1
- package/src/preview/PropertyPreview.tsx +25 -5
- package/src/preview/compact_text.ts +68 -0
- package/src/preview/components/BooleanPreview.tsx +5 -2
- package/src/preview/components/StorageThumbnail.tsx +5 -2
- package/src/preview/property_previews/ArrayOfRelationsPreview.tsx +6 -3
- package/src/preview/property_previews/ArrayOfStringsPreview.tsx +26 -1
- package/src/preview/property_previews/ArrayOneOfPreview.tsx +10 -1
- package/src/preview/property_previews/ArrayPropertyPreview.tsx +10 -1
- package/src/preview/property_previews/MapPropertyPreview.tsx +52 -1
- package/src/preview/property_previews/NumberPropertyPreview.tsx +9 -1
- package/src/preview/property_previews/StringPropertyPreview.tsx +8 -5
- package/src/routes/RebaseRoute.tsx +62 -4
- package/src/types/components/PropertyPreviewProps.tsx +21 -0
- package/src/util/number_format.ts +46 -0
- package/src/util/previews.ts +8 -55
- package/src/util/property_utils.tsx +6 -1
- package/dist/util-GiwPgxnL.js.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { NumberFormatOptions } from "@rebasepro/admin-types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Write a number out for reading, per a property's declared `admin.format`.
|
|
5
|
+
*
|
|
6
|
+
* Nothing is inferred here. With no options the number is returned as it came
|
|
7
|
+
* out of the database — `String(value)`, not a locale-grouped rendering — so a
|
|
8
|
+
* panel that declares nothing shows exactly the stored value, and an author who
|
|
9
|
+
* wants thousands separators asks for them.
|
|
10
|
+
*
|
|
11
|
+
* `Intl.NumberFormat` throws on a bad currency code or an out-of-range fraction
|
|
12
|
+
* count, and a record must not blank because one property is misconfigured, so a
|
|
13
|
+
* failure falls back to the raw value.
|
|
14
|
+
*/
|
|
15
|
+
export function formatNumber(
|
|
16
|
+
value: number,
|
|
17
|
+
options: NumberFormatOptions | undefined,
|
|
18
|
+
fallbackLocale?: string
|
|
19
|
+
): string {
|
|
20
|
+
|
|
21
|
+
if (!options) return String(value);
|
|
22
|
+
|
|
23
|
+
// A currency code is the whole declaration in the common case: writing
|
|
24
|
+
// `{ currency: "EUR" }` and getting a bare `185.11` because `style` was
|
|
25
|
+
// omitted is a trap, and there is nothing else `currency` could mean.
|
|
26
|
+
const style = options.style ?? (options.currency ? "currency" : "decimal");
|
|
27
|
+
|
|
28
|
+
if (style === "currency" && !options.currency) {
|
|
29
|
+
// `Intl` throws on this rather than picking a currency, which is the
|
|
30
|
+
// right call — there is no sensible default — but the record still has
|
|
31
|
+
// to render.
|
|
32
|
+
return String(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
return new Intl.NumberFormat(options.locale ?? fallbackLocale ?? undefined, {
|
|
37
|
+
style,
|
|
38
|
+
currency: options.currency,
|
|
39
|
+
minimumFractionDigits: options.minimumFractionDigits,
|
|
40
|
+
maximumFractionDigits: options.maximumFractionDigits,
|
|
41
|
+
notation: options.notation
|
|
42
|
+
}).format(value);
|
|
43
|
+
} catch {
|
|
44
|
+
return String(value);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/util/previews.ts
CHANGED
|
@@ -1,64 +1,17 @@
|
|
|
1
1
|
import type { Property } from "@rebasepro/types";
|
|
2
2
|
import type { PropertyConfig, AdminCollection } from "@rebasepro/admin-types";
|
|
3
|
-
import { AuthController } from "@rebasepro/admin-types";
|
|
4
|
-
import { isPropertyBuilder } from "@rebasepro/common";
|
|
5
3
|
import { getTitlePropertyKey, getTitlePropertyKeyForValues } from "@rebasepro/app";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
function isHiddenProperty(property: Property | undefined): boolean {
|
|
9
|
-
if (!property) return false;
|
|
10
|
-
return Boolean(property.admin?.hideFromCollection);
|
|
11
|
-
}
|
|
4
|
+
import { isPropertyBuilder } from "@rebasepro/common";
|
|
12
5
|
|
|
13
6
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
7
|
+
* Which properties fill a preview surface, best first.
|
|
8
|
+
*
|
|
9
|
+
* The implementation lives in `@rebasepro/app` so that the admin package and
|
|
10
|
+
* the app package cannot disagree about what a record looks like in a card —
|
|
11
|
+
* they had drifted, and only one of the two copies had learned to keep
|
|
12
|
+
* relations out of the list.
|
|
17
13
|
*/
|
|
18
|
-
|
|
19
|
-
if (!property) return false;
|
|
20
|
-
// Single string with storage config
|
|
21
|
-
if (property.type === "string" && property.storage) return true;
|
|
22
|
-
// String displayed as image URL
|
|
23
|
-
if (property.type === "string" && property.admin?.urlPreview === "image") return true;
|
|
24
|
-
// Array whose inner element has storage config or image URL
|
|
25
|
-
if (property.type === "array" && property.of && !Array.isArray(property.of)) {
|
|
26
|
-
const inner = property.of;
|
|
27
|
-
if (inner.type === "string" && (inner.storage || inner.admin?.urlPreview === "image")) return true;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getEntityPreviewKeys(
|
|
33
|
-
authController: AuthController,
|
|
34
|
-
targetCollection: AdminCollection<any>,
|
|
35
|
-
fields: Record<string, PropertyConfig>,
|
|
36
|
-
previewProperties?: string[],
|
|
37
|
-
limit = 3) {
|
|
38
|
-
const allProperties = Object.keys(targetCollection.properties);
|
|
39
|
-
let listProperties = previewProperties?.filter(p => allProperties.includes(p as string));
|
|
40
|
-
if (!listProperties && targetCollection.previewProperties) {
|
|
41
|
-
listProperties = targetCollection.previewProperties?.filter(p => allProperties.includes(p as string));
|
|
42
|
-
}
|
|
43
|
-
if (listProperties && listProperties.length > 0) {
|
|
44
|
-
return listProperties;
|
|
45
|
-
} else {
|
|
46
|
-
const hasExplicitOrder = !!(targetCollection.propertiesOrder as string[] | undefined);
|
|
47
|
-
listProperties = (targetCollection.propertiesOrder as string[]) || allProperties;
|
|
48
|
-
return listProperties
|
|
49
|
-
.filter(key => {
|
|
50
|
-
const prop = targetCollection.properties[key];
|
|
51
|
-
const isIdProp = prop && typeof prop === "object" && "isId" in prop && Boolean((prop as { isId?: boolean }).isId);
|
|
52
|
-
return !isIdProp && key !== "id";
|
|
53
|
-
})
|
|
54
|
-
.filter(key => {
|
|
55
|
-
const property = targetCollection.properties[key];
|
|
56
|
-
return property && !isPropertyBuilder(property) && !isReferenceProperty(property) && !isHiddenProperty(property)
|
|
57
|
-
&& !isStorageProperty(property as Property)
|
|
58
|
-
&& (hasExplicitOrder || !isRelationProperty(property));
|
|
59
|
-
}).slice(0, limit);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
14
|
+
export { getEntityPreviewKeys } from "@rebasepro/app";
|
|
62
15
|
|
|
63
16
|
/**
|
|
64
17
|
* The property that fills the title slot for a collection.
|
|
@@ -159,8 +159,13 @@ export function getResolvedPropertyInPath(properties: Record<string, Property>,
|
|
|
159
159
|
}
|
|
160
160
|
if (path.includes(".")) {
|
|
161
161
|
const pathSegments = path.split(".");
|
|
162
|
+
// A path whose root is not a property at all is simply not found.
|
|
163
|
+
// Reading `.type` off the miss threw a TypeError instead, which
|
|
164
|
+
// turned one unresolvable column key into a crash for whatever was
|
|
165
|
+
// walking the properties — see `propertiesToColumns`, where that is
|
|
166
|
+
// the whole table. `getPropertyInPath` above already guards this.
|
|
162
167
|
const childProperty = properties[pathSegments[0]];
|
|
163
|
-
if (childProperty
|
|
168
|
+
if (childProperty?.type === "map" && childProperty.properties) {
|
|
164
169
|
return getResolvedPropertyInPath(childProperty.properties, pathSegments.slice(1).join("."))
|
|
165
170
|
}
|
|
166
171
|
}
|