@rebasepro/app 0.13.0 → 0.13.1-canary.g3660bd5

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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The store behind a computed display value.
3
+ *
4
+ * A record's title is asked for far more often than it changes, and by many
5
+ * components at once: a list of fifty rows, each row's relation chips, the
6
+ * breadcrumb above them. Resolving per component is what makes an async display
7
+ * value a bad idea — fifty rows becomes fifty reads, then fifty more on the next
8
+ * render.
9
+ *
10
+ * So resolution is keyed by record *and* role, in-flight calls are shared, and
11
+ * results are kept until something says otherwise. Deliberately not a React
12
+ * thing: the same store answers an imperative caller (an export, a breadcrumb
13
+ * built outside the tree), and it is testable without a renderer.
14
+ */
15
+ import type { EntityDisplayRole } from "@rebasepro/admin-types";
16
+ export type EntityDisplayKey = string;
17
+ /** The identity of one role of one record, as a cache key. */
18
+ export declare function entityDisplayKey(path: string, entityId: string | number | undefined, role: EntityDisplayRole): EntityDisplayKey;
19
+ export declare class EntityDisplayCache {
20
+ private readonly entries;
21
+ private readonly listeners;
22
+ /**
23
+ * The resolved value, or `undefined` when this pair has not been resolved
24
+ * yet. `null` is a resolved absence, and the two must stay distinct: a
25
+ * caller that reads "not yet" as "nothing" flickers its fallback in on every
26
+ * mount.
27
+ */
28
+ peek(key: EntityDisplayKey): unknown | undefined;
29
+ /** True while a resolution for this pair is in flight. */
30
+ isLoading(key: EntityDisplayKey): boolean;
31
+ /**
32
+ * Resolve once per record and role. Concurrent callers share the first
33
+ * call's promise; later callers get the cached value with no promise at all.
34
+ *
35
+ * A resolver that throws is recorded as "nothing" rather than retried: the
36
+ * alternative is every render re-running a call that just failed. And it is
37
+ * reported here, which is a correction.
38
+ *
39
+ * It used to say "the caller that saw the rejection is the one that logs
40
+ * it", and `useEntityDisplay` duly attached a `.catch()` that warned. But
41
+ * both failure paths below swallow and return a *resolved* promise, so that
42
+ * catch could never run — the two halves each did the reasonable thing and
43
+ * between them the log was unreachable. A resolver that blew up produced a
44
+ * blank chip and total silence, which is the failure mode
45
+ * `EntityDisplayResolver`'s own contract ("treated as `undefined` and logged
46
+ * once") exists to rule out.
47
+ *
48
+ * Reporting belongs here for the reason the caller could not do it: this is
49
+ * the one place that runs exactly once per key, so "once" is a property of
50
+ * the code rather than a hope about how many components mount.
51
+ */
52
+ resolve(key: EntityDisplayKey, resolver: () => unknown): Promise<unknown>;
53
+ /**
54
+ * Drop what is known about a record, so the next ask resolves again. Called
55
+ * after a write: the row that just saved may be called something else now.
56
+ */
57
+ invalidate(path: string, entityId?: string | number): void;
58
+ /** Drop everything. The user signed out, or the app swapped datasource. */
59
+ clear(): void;
60
+ subscribe(listener: () => void): () => void;
61
+ private set;
62
+ /**
63
+ * Record a failed resolution as "nothing", and say so once.
64
+ *
65
+ * The key is the message: it is `<role> <path> <id>`, which is exactly what a
66
+ * reader needs to find the resolver that blew up. A warning with no key would
67
+ * tell them a display resolver failed somewhere in a list of fifty rows.
68
+ *
69
+ * `console.warn` rather than a thrown error, because this runs while a row is
70
+ * rendering: the contract is that a title which cannot be fetched must not
71
+ * take down the row that shows it.
72
+ */
73
+ private fail;
74
+ private emit;
75
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Reading a collection's `display` block.
3
+ *
4
+ * Two questions, kept apart because they are answered at different times: which
5
+ * *property* fills a role (readable from values already in hand) and which
6
+ * *resolver* fills it (may have to go to the network). A caller that cannot
7
+ * await — a sort comparator, an export column, a server render — uses the key
8
+ * and is documented to ignore resolvers.
9
+ */
10
+ import type { AdminCollection, EntityDisplayResolver, EntityDisplayRole } from "@rebasepro/admin-types";
11
+ /**
12
+ * The property path a role is declared to read, when it is declared as a path.
13
+ *
14
+ * Returns `undefined` for a role filled by a resolver — a resolver has no key —
15
+ * and for a role the collection says nothing about, which is then derived.
16
+ *
17
+ * @group Collections
18
+ */
19
+ export declare function getDisplayPropertyKey<M extends Record<string, unknown>>(collection: AdminCollection<M>, role: EntityDisplayRole): string | undefined;
20
+ /**
21
+ * The resolver a role is declared to use, when it is declared as one.
22
+ *
23
+ * @group Collections
24
+ */
25
+ export declare function getDisplayResolver<M extends Record<string, unknown>>(collection: AdminCollection<M>, role: EntityDisplayRole): EntityDisplayResolver<M, unknown> | undefined;
26
+ /**
27
+ * True when the collection states this role at all, in either form.
28
+ *
29
+ * The derivation is a guess about what a collection probably means; a statement
30
+ * outranks it, and the heuristics that look for "the first enum" or "the leading
31
+ * relation" have to stand down when one exists.
32
+ *
33
+ * @group Collections
34
+ */
35
+ export declare function hasDeclaredDisplay<M extends Record<string, unknown>>(collection: AdminCollection<M>, role: EntityDisplayRole): boolean;
@@ -1,2 +1,10 @@
1
1
  import { CollectionConfig } from "@rebasepro/types";
2
+ /**
3
+ * The property that fills a record's image slot.
4
+ *
5
+ * `admin.display.image` first, then six fallbacks in descending confidence —
6
+ * the first image-typed storage property, an array of them, a URL rendered as an
7
+ * image, and so on. The ladder stays for collections that say nothing; a
8
+ * collection that names its picture is not guessed at.
9
+ */
2
10
  export declare function getEntityImagePreviewPropertyKey<M extends Record<string, unknown>>(collection: CollectionConfig<M>): string | undefined;
@@ -34,6 +34,12 @@ export interface ResolvedFormSection {
34
34
  /** Initial state only; the form owns it after first interaction. */
35
35
  collapsed: boolean;
36
36
  fields: ResolvedFormField[];
37
+ /**
38
+ * Declared arrangement for the read-only view. Carried through untouched —
39
+ * the resolver decides *which* fields a section holds, not how the surface
40
+ * that renders it stacks them, and only the read view honours this.
41
+ */
42
+ readVariant?: "grid" | "summary";
37
43
  }
38
44
  export interface ResolvedFormLayout {
39
45
  sections: ResolvedFormSection[];
@@ -1,9 +1,13 @@
1
1
  export * from "./collection_view_config";
2
2
  export * from "./entity_image_preview";
3
+ export * from "./entity-display";
4
+ export * from "./entity-display-cache";
3
5
  export * from "./filter-operator-resolution";
4
6
  export * from "./form-layout";
5
7
  export * from "./navigation_from_path";
6
8
  export * from "./navigation_utils";
7
9
  export * from "./parent_references_from_path";
10
+ export * from "./property-path";
8
11
  export * from "./property_presentation";
12
+ export * from "./summary-property";
9
13
  export * from "./title-property";
@@ -0,0 +1,16 @@
1
+ import type { Properties, Property } from "@rebasepro/types";
2
+ /**
3
+ * The property at a dotted path, walking `map` children — `address.street`.
4
+ *
5
+ * The value counterpart is `getValueInPath` in `@rebasepro/utils`; this is the
6
+ * schema half, and the two have to be used together. Reading a dotted path off
7
+ * an entity while looking its property up with a flat `properties[path]` gives
8
+ * the value and `undefined` for how to render it, which is how a declared title
9
+ * on a nested field silently fell back to a derived one.
10
+ *
11
+ * There were three copies of this: one private to `useColumnsIds`, one exported
12
+ * from the admin layer, and the flat lookup in the title resolver that was not
13
+ * this function at all. This is the one, in the lowest layer that needs it —
14
+ * admin re-exports it under the name it already published.
15
+ */
16
+ export declare function getPropertyInPath(properties: Properties, path: string): Property | undefined;
@@ -0,0 +1,65 @@
1
+ import type { Property } from "@rebasepro/types";
2
+ /**
3
+ * Whether a property can stand in for a record in *one line*.
4
+ *
5
+ * Preview surfaces — the reference card, a list row, a board card — have a
6
+ * single line per property and no way to grow. That is a constraint on the
7
+ * *value*, not on the property's importance: a Markdown biography is the most
8
+ * interesting column on an author, and it is still the wrong thing to paste
9
+ * into a 44px card. Ranking it here means the picker can skip it without
10
+ * anyone having to configure their way out of a broken card.
11
+ *
12
+ * Kept beside {@link getTitlePropertyCandidates} because the two answer
13
+ * neighbouring questions — "what is this record called" and "what else can be
14
+ * said about it in a line" — from the same property schema.
15
+ *
16
+ * @group Collections
17
+ */
18
+ export declare const SUMMARY_RANK: {
19
+ /**
20
+ * No single-line form exists. A map renders as a key/value table and an
21
+ * array of maps as a stack of them; there is no first line to take.
22
+ */
23
+ readonly UNUSABLE: 0;
24
+ /**
25
+ * Readable in one line, but only as an excerpt — the property holds a
26
+ * document, and the line is its opening. Worth showing when nothing better
27
+ * is available, never in preference to a value that fits whole.
28
+ */
29
+ readonly EXCERPT: 1;
30
+ /** Short and self-contained: the line *is* the value. */
31
+ readonly DIRECT: 2;
32
+ };
33
+ /** One of the three summary ranks. */
34
+ export type SummaryRank = typeof SUMMARY_RANK[keyof typeof SUMMARY_RANK];
35
+ /**
36
+ * File-storage backed content (single image, array of images, generic upload…).
37
+ * Preview surfaces give these their own image slot, so they are never also a
38
+ * text line.
39
+ *
40
+ * @group Collections
41
+ */
42
+ export declare function isStorageProperty(property: Property | undefined): boolean;
43
+ /**
44
+ * True when the property holds free text long enough to be a document rather
45
+ * than a value — Markdown, or an explicitly multi-line string.
46
+ *
47
+ * @group Collections
48
+ */
49
+ export declare function isLongTextProperty(property: Property | undefined): boolean;
50
+ /**
51
+ * How well a property reads as one line of a preview. See {@link SUMMARY_RANK}.
52
+ *
53
+ * Decided from the property *schema* only: no values are consulted, so the
54
+ * answer is stable for a collection and can be memoised per collection rather
55
+ * than per row.
56
+ *
57
+ * @group Collections
58
+ */
59
+ export declare function rankSummaryProperty(property: Property | undefined): SummaryRank;
60
+ /**
61
+ * True when the property has any single-line form at all.
62
+ *
63
+ * @group Collections
64
+ */
65
+ export declare function canSummariseProperty(property: Property | undefined): boolean;