@gogitcms/design-system 0.16.0-next.1 → 0.16.0-next.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/ApplyChangesModal.test.tsx +48 -0
  3. package/src/__tests__/BranchDeletedModal.test.tsx +42 -0
  4. package/src/__tests__/ContentBrowser.fieldfocus.test.tsx +109 -0
  5. package/src/__tests__/ContentBrowser.forms.test.tsx +47 -1
  6. package/src/__tests__/ContentBrowser.history.test.tsx +385 -0
  7. package/src/__tests__/ContentBrowser.historycollab.test.tsx +433 -0
  8. package/src/__tests__/ContentBrowser.references.test.tsx +179 -0
  9. package/src/__tests__/ContentBrowser.slotmedia.test.tsx +150 -0
  10. package/src/__tests__/MediaField.test.tsx +18 -0
  11. package/src/__tests__/ProtectedBranchModal.test.tsx +68 -0
  12. package/src/components/ApplyChangesModal.tsx +70 -21
  13. package/src/components/BranchDeletedModal.tsx +111 -0
  14. package/src/components/ChangeDetail.tsx +94 -11
  15. package/src/components/CollabField.tsx +71 -0
  16. package/src/components/ContentBrowser.tsx +494 -77
  17. package/src/components/DocumentDetails.tsx +0 -0
  18. package/src/components/DocumentHistory.tsx +408 -0
  19. package/src/components/MediaField.tsx +62 -0
  20. package/src/components/MediaPreview.tsx +14 -1
  21. package/src/components/MediaPreview.web.tsx +18 -3
  22. package/src/components/Notifications.tsx +146 -28
  23. package/src/components/ProtectedBranchModal.tsx +136 -0
  24. package/src/components/ReferenceField.tsx +0 -0
  25. package/src/components/primitives.tsx +46 -1
  26. package/src/fieldComponents.ts +2 -2
  27. package/src/history.ts +82 -0
  28. package/src/icons.ts +1 -0
  29. package/src/index.ts +28 -3
  30. package/src/media.ts +15 -0
  31. package/src/references.ts +97 -0
@@ -0,0 +1,97 @@
1
+ // The document picker's declaration and its host data seam.
2
+ //
3
+ // This is the TypeScript mirror of packages/importer/schema/references.go — the
4
+ // Go file is the source of truth validated on config import; keep the two in
5
+ // sync. A reference field points at documents of other collections (or its
6
+ // own). A string field stores the target's key; an object field stores the key
7
+ // under `keyName` plus embedded copies the SERVER computes on every save — the
8
+ // editor shows those copies read-only and never writes them
9
+ // (docs/references.md).
10
+
11
+ // ReferenceDef is a field's `reference:` block as the API delivers it.
12
+ export interface ReferenceDef {
13
+ // The collections the field may point at.
14
+ collections: string[];
15
+ // Which rendered form of the target the field stores: "_path" (the target's
16
+ // project-relative path) or the name of a field on the target.
17
+ key: string;
18
+ // For the object shape, the child that holds the key ("ref" unless renamed).
19
+ keyName: string;
20
+ // The embedded copies, in the order the derived children appear.
21
+ embed: ReferenceEmbed[];
22
+ // What deleting a referenced document does: restrict | unset.
23
+ onDelete: string;
24
+ }
25
+
26
+ export interface ReferenceEmbed {
27
+ name: string;
28
+ source: string;
29
+ }
30
+
31
+ // ReferenceTarget is one document a reference can point at, keyed as the field
32
+ // stores it. `path` is repository-relative, like a document's.
33
+ export interface ReferenceTarget {
34
+ id: string;
35
+ collection: string;
36
+ path: string;
37
+ key: string;
38
+ label: string;
39
+ }
40
+
41
+ // ReferenceResolution is the answer to "what does this stored key name?".
42
+ // `target` null with `ambiguous` false is a dangling reference; `ambiguous`
43
+ // means a field key several documents share, and `candidates` holds them.
44
+ export interface ReferenceResolution {
45
+ key: string;
46
+ target?: ReferenceTarget | null;
47
+ ambiguous: boolean;
48
+ candidates: ReferenceTarget[];
49
+ }
50
+
51
+ // Referrer is one document that points at another, and the field it does so
52
+ // from.
53
+ export interface Referrer {
54
+ id: string;
55
+ collection: string;
56
+ path: string;
57
+ label: string;
58
+ fieldPath: string;
59
+ }
60
+
61
+ // ReferenceApi is the data seam between the design system and its host, the
62
+ // same split as MediaApi: the DS owns the picker and the display, the host owns
63
+ // fetching. Omitting it from ContentBrowser renders reference fields read-only.
64
+ export interface ReferenceApi {
65
+ // Documents the field may point at — the picker's list. `collections` and
66
+ // `key` are the field's ReferenceDef; `query` matches labels.
67
+ search: (params: { collections: string[]; key: string; query?: string; limit?: number }) => Promise<ReferenceTarget[]>;
68
+ // Resolve stored keys to their documents, batched per document.
69
+ resolve: (collections: string[], key: string, keys: string[]) => Promise<ReferenceResolution[]>;
70
+ // Documents that point at one — "Referenced by". Omit to hide the section.
71
+ referrers?: (documentId: string) => Promise<Referrer[]>;
72
+ }
73
+
74
+ // The key child an object reference stores by default. Mirrors the Go
75
+ // DefaultKeyName.
76
+ export const DEFAULT_REFERENCE_KEY_NAME = "ref";
77
+
78
+ // referenceKey reads the stored key out of a reference field's value, for
79
+ // either shape. Empty when the field is unset.
80
+ export function referenceKey(value: unknown, shape: "string" | "object", def: ReferenceDef): string {
81
+ if (shape === "object") {
82
+ if (typeof value !== "object" || value === null) return "";
83
+ const key = (value as Record<string, unknown>)[def.keyName || DEFAULT_REFERENCE_KEY_NAME];
84
+ return typeof key === "string" ? key.trim() : "";
85
+ }
86
+ return typeof value === "string" ? value.trim() : "";
87
+ }
88
+
89
+ // referenceValue builds the value the field writes when a target is picked:
90
+ // the key alone in a string field; in an object field the key under keyName,
91
+ // with any copies the value already carried kept until the server replaces
92
+ // them on save — writing nothing else is what keeps the copies the server's.
93
+ export function referenceValue(target: ReferenceTarget, shape: "string" | "object", def: ReferenceDef, previous: unknown): unknown {
94
+ if (shape === "string") return target.key;
95
+ const prev = typeof previous === "object" && previous !== null ? (previous as Record<string, unknown>) : {};
96
+ return { ...prev, [def.keyName || DEFAULT_REFERENCE_KEY_NAME]: target.key };
97
+ }