@mdbase-dev/ui 0.1.0-beta.159 → 0.1.0-beta.161

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 (39) hide show
  1. package/README.md +3 -2
  2. package/css/collections.css +19 -1
  3. package/css/controls.css +3 -7
  4. package/css/motion.css +8 -0
  5. package/dist/AppSwitcher.js +0 -9
  6. package/dist/CommandPalette.js +2 -2
  7. package/dist/Dialog.js +16 -1
  8. package/dist/Menu.js +10 -0
  9. package/dist/apps.d.ts +2 -2
  10. package/dist/apps.js +5 -5
  11. package/dist/brand.js +1 -1
  12. package/dist/collections/CollectionGate.js +73 -7
  13. package/dist/collections/CollectionSwitcher.js +3 -3
  14. package/dist/collections/SetupReview.d.ts +2 -1
  15. package/dist/collections/SetupReview.js +11 -3
  16. package/dist/collections/UnsyncedWork.d.ts +26 -0
  17. package/dist/collections/UnsyncedWork.js +160 -0
  18. package/dist/collections/copy.d.ts +20 -0
  19. package/dist/collections/copy.js +210 -0
  20. package/dist/collections/model.d.ts +9 -0
  21. package/dist/collections/model.js +13 -1
  22. package/dist/collections/unsynced.d.ts +56 -0
  23. package/dist/collections/unsynced.js +18 -0
  24. package/dist/collections/use-collection-ui.d.ts +26 -1
  25. package/dist/collections/use-collection-ui.js +113 -4
  26. package/dist/collections.d.ts +3 -1
  27. package/dist/collections.js +1 -0
  28. package/dist/locales/de/messages.json +1 -1
  29. package/dist/locales/en/messages.json +1 -1
  30. package/dist/locales/es/messages.json +1 -1
  31. package/dist/locales/fr/messages.json +1 -1
  32. package/dist/locales/it/messages.json +1 -1
  33. package/dist/locales/ja/messages.json +1 -1
  34. package/dist/locales/ko/messages.json +1 -1
  35. package/dist/locales/pt/messages.json +1 -1
  36. package/dist/locales/ru/messages.json +1 -1
  37. package/dist/locales/zh/messages.json +1 -1
  38. package/dist/overlay.js +9 -5
  39. package/package.json +3 -3
@@ -0,0 +1,160 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext, useState, useSyncExternalStore } from "react";
3
+ import { ConfirmDialog } from "../ConfirmDialog.js";
4
+ import { useLocaleRevision } from "../i18n.js";
5
+ import { CollectionMdbaseContext } from "./CollectionSaveWarning.js";
6
+ import { defaultCollectionCopy } from "./copy.js";
7
+ import { ActionButton, NoticeBlock } from "./parts.js";
8
+ import { unsyncedPhase } from "./unsynced.js";
9
+ const savedLabel = ui => {
10
+ const options = ui.options.unsynced;
11
+ return typeof options === "object" && options.storage === "device" ? ui.copy.unsyncedSavedDevice : ui.copy.unsyncedSavedBrowser;
12
+ };
13
+ /**
14
+ * The one quiet, persistent line while the app works in its unsynced
15
+ * collection and something has been saved there: where it is kept, and the
16
+ * way to connect it.
17
+ */
18
+ export function UnsyncedLine({
19
+ ui
20
+ }) {
21
+ if (ui.view.kind !== "unsynced" || !ui.view.unsyncedWork) return null;
22
+ return _jsxs("div", {
23
+ className: "mdbase-collections mdbase-collections-unsynced",
24
+ children: [_jsx("p", {
25
+ className: "mdbase-collections-unsynced-status",
26
+ children: savedLabel(ui)
27
+ }), _jsx(ActionButton, {
28
+ tone: "quiet",
29
+ inert: ui.busy !== null,
30
+ progress: ui.busy === "sign_in" || ui.busy === "add" ? ui.copy.addingCollection : null,
31
+ onClick: ui.actions.connect,
32
+ children: ui.copy.unsyncedConnect
33
+ })]
34
+ });
35
+ }
36
+ /**
37
+ * With a collection open and work saved before connecting: offer to bring it
38
+ * in (asking first when names or types change), or to discard it. Afterwards,
39
+ * how it went.
40
+ */
41
+ export function BringInBanner({
42
+ ui,
43
+ variant = "banner"
44
+ }) {
45
+ const [discarding, setDiscarding] = useState(false);
46
+ const {
47
+ view,
48
+ copy,
49
+ busy,
50
+ actions
51
+ } = ui;
52
+ if (view.kind !== "ready") return null;
53
+ const name = view.current?.name ?? view.heading;
54
+ const notice = ui.unsyncedNotice;
55
+ const review = ui.unsyncedReview;
56
+ if (!notice && !view.unsyncedWork && !ui.error) return null;
57
+ const consequence = review ? [review.counts.renamed > 0 ? copy.unsyncedReviewRenamed : null, (review.counts.changed ?? 0) > 0 ? copy.unsyncedReviewChanged : null, review.addTypes?.length ? ui.say("unsyncedReviewTypes", {
58
+ types: review.addTypes.join(", ")
59
+ }) : null, review.missingTypes.length > 0 ? copy.unsyncedReviewMissing : null].filter(Boolean).join(" ") : undefined;
60
+ return _jsxs("div", {
61
+ className: "mdbase-collections",
62
+ children: [ui.error && _jsx(NoticeBlock, {
63
+ notice: ui.error,
64
+ ui: ui,
65
+ variant: variant
66
+ }), !notice && !view.unsyncedWork ? null : notice ? _jsxs("div", {
67
+ className: `mdbase-collections-notice is-${variant}`,
68
+ "data-tone": notice.tone,
69
+ role: notice.tone === "info" ? "status" : "alert",
70
+ children: [_jsx("div", {
71
+ className: "mdbase-collections-notice-copy",
72
+ children: _jsx("p", {
73
+ className: "mdbase-collections-notice-message",
74
+ children: notice.message
75
+ })
76
+ }), _jsxs("div", {
77
+ className: "mdbase-collections-notice-actions",
78
+ children: [notice.key !== "unsynced_brought_in" && view.unsyncedWork && _jsx(ActionButton, {
79
+ tone: "primary",
80
+ inert: busy !== null,
81
+ progress: busy === "bring_in" ? copy.unsyncedBringingIn : null,
82
+ onClick: actions.bringIn,
83
+ children: copy.unsyncedBringIn
84
+ }), _jsx(ActionButton, {
85
+ tone: "quiet",
86
+ onClick: actions.dismissUnsyncedNotice,
87
+ children: copy.close
88
+ })]
89
+ })]
90
+ }) : _jsxs("div", {
91
+ className: `mdbase-collections-notice is-${variant}`,
92
+ "data-tone": "info",
93
+ role: "status",
94
+ children: [_jsx("div", {
95
+ className: "mdbase-collections-notice-copy",
96
+ children: _jsx("p", {
97
+ className: "mdbase-collections-notice-message",
98
+ children: ui.say("unsyncedBringInLead", {
99
+ collection: name
100
+ })
101
+ })
102
+ }), _jsxs("div", {
103
+ className: "mdbase-collections-notice-actions",
104
+ children: [_jsx(ActionButton, {
105
+ tone: "primary",
106
+ inert: busy !== null,
107
+ progress: busy === "bring_in" ? copy.unsyncedBringingIn : null,
108
+ onClick: actions.bringIn,
109
+ children: copy.unsyncedBringIn
110
+ }), _jsx(ActionButton, {
111
+ tone: "quiet",
112
+ inert: busy !== null,
113
+ onClick: () => setDiscarding(true),
114
+ children: copy.unsyncedDiscard
115
+ })]
116
+ })]
117
+ }), _jsx(ConfirmDialog, {
118
+ open: review !== null,
119
+ tone: "default",
120
+ initialFocus: "confirm",
121
+ title: ui.say("unsyncedReviewTitle", {
122
+ collection: name
123
+ }),
124
+ ...(consequence ? {
125
+ consequence
126
+ } : {}),
127
+ confirmLabel: copy.unsyncedBringIn,
128
+ pendingLabel: copy.unsyncedBringingIn,
129
+ onClose: actions.dismissBringIn,
130
+ onConfirm: actions.confirmBringIn
131
+ }), _jsx(ConfirmDialog, {
132
+ open: discarding,
133
+ title: copy.unsyncedDiscardTitle,
134
+ consequence: ui.say("unsyncedDiscardBody"),
135
+ confirmLabel: copy.unsyncedDiscardConfirm,
136
+ pendingLabel: copy.unsyncedDiscarding,
137
+ busy: busy === "discard_unsynced",
138
+ onClose: () => setDiscarding(false),
139
+ onConfirm: () => {
140
+ setDiscarding(false);
141
+ actions.discardUnsynced();
142
+ }
143
+ })]
144
+ });
145
+ }
146
+ const emptySubscribe = () => () => {};
147
+ const emptySnapshot = () => null;
148
+ /**
149
+ * The save label for the app's own save notice while it works in its unsynced
150
+ * collection ("Saved only in this browser" instead of "Saved"), or null
151
+ * otherwise. Inside the gate it finds the entry by itself.
152
+ */
153
+ export function useUnsyncedSavedLabel(supplied, storage = "browser") {
154
+ useLocaleRevision();
155
+ const inherited = useContext(CollectionMdbaseContext);
156
+ const mdbase = supplied ?? inherited;
157
+ const phase = useSyncExternalStore(mdbase?.subscribe ?? emptySubscribe, () => mdbase?.getSnapshot().phase ?? null, emptySnapshot);
158
+ if (!phase || !unsyncedPhase(phase)) return null;
159
+ return storage === "device" ? defaultCollectionCopy.unsyncedSavedDevice : defaultCollectionCopy.unsyncedSavedBrowser;
160
+ }
@@ -92,6 +92,26 @@ export declare const defaultCollectionCopy: {
92
92
  readonly deleteConfirm: string;
93
93
  readonly deleting: string;
94
94
  readonly signOutAnyway: string;
95
+ readonly unsyncedSavedBrowser: string;
96
+ readonly unsyncedSavedDevice: string;
97
+ readonly unsyncedConnect: string;
98
+ readonly continueWithoutConnecting: string;
99
+ readonly unsyncedBringInLead: string;
100
+ readonly unsyncedBringIn: string;
101
+ readonly unsyncedBringingIn: string;
102
+ readonly unsyncedBroughtIn: string;
103
+ readonly unsyncedBroughtInOpen: string;
104
+ readonly unsyncedBringInFailed: string;
105
+ readonly unsyncedReviewTitle: string;
106
+ readonly unsyncedReviewRenamed: string;
107
+ readonly unsyncedReviewTypes: string;
108
+ readonly unsyncedReviewChanged: string;
109
+ readonly unsyncedReviewMissing: string;
110
+ readonly unsyncedDiscard: string;
111
+ readonly unsyncedDiscardTitle: string;
112
+ readonly unsyncedDiscardBody: string;
113
+ readonly unsyncedDiscardConfirm: string;
114
+ readonly unsyncedDiscarding: string;
95
115
  readonly close: string;
96
116
  };
97
117
  export type CollectionCopyKey = keyof typeof defaultCollectionCopy;
@@ -921,6 +921,216 @@ export const defaultCollectionCopy = {
921
921
  context: "Collection access interface"
922
922
  });
923
923
  },
924
+ get unsyncedSavedBrowser() {
925
+ return i18n._(
926
+ /** i18n */
927
+ {
928
+ id: "JhrsQK",
929
+ message: "Saved only in this browser",
930
+ context: "Collection access interface"
931
+ });
932
+ },
933
+ get unsyncedSavedDevice() {
934
+ return i18n._(
935
+ /** i18n */
936
+ {
937
+ id: "J-tjpL",
938
+ message: "Saved only on this device",
939
+ context: "Collection access interface"
940
+ });
941
+ },
942
+ get unsyncedConnect() {
943
+ return i18n._(
944
+ /** i18n */
945
+ {
946
+ id: "noD4R_",
947
+ message: "Connect to sync your work",
948
+ context: "Collection access interface"
949
+ });
950
+ },
951
+ get continueWithoutConnecting() {
952
+ return i18n._(
953
+ /** i18n */
954
+ {
955
+ id: "S3F0VP",
956
+ message: "Continue without connecting",
957
+ context: "Collection access interface"
958
+ });
959
+ },
960
+ get unsyncedBringInLead() {
961
+ return i18n._({
962
+ ...
963
+ /** i18n */
964
+ {
965
+ id: "s1Ck-j",
966
+ message: "You have work that isn't in {collection} yet.",
967
+ context: "Collection access interface"
968
+ },
969
+ values: {
970
+ collection: "{collection}"
971
+ }
972
+ });
973
+ },
974
+ get unsyncedBringIn() {
975
+ return i18n._(
976
+ /** i18n */
977
+ {
978
+ id: "F3WtMc",
979
+ message: "Bring it in",
980
+ context: "Collection access interface"
981
+ });
982
+ },
983
+ get unsyncedBringingIn() {
984
+ return i18n._(
985
+ /** i18n */
986
+ {
987
+ id: "nLO4R9",
988
+ message: "Bringing in\u2026",
989
+ context: "Collection access interface"
990
+ });
991
+ },
992
+ get unsyncedBroughtIn() {
993
+ return i18n._({
994
+ ...
995
+ /** i18n */
996
+ {
997
+ id: "22raEF",
998
+ message: "Your work is now in {collection}.",
999
+ context: "Collection access interface"
1000
+ },
1001
+ values: {
1002
+ collection: "{collection}"
1003
+ }
1004
+ });
1005
+ },
1006
+ get unsyncedBroughtInOpen() {
1007
+ return i18n._({
1008
+ ...
1009
+ /** i18n */
1010
+ {
1011
+ id: "YFAS9T",
1012
+ message: "Your work is now in {collection}. If it's still open in another tab, close it there, then bring it in again.",
1013
+ context: "Collection access interface"
1014
+ },
1015
+ values: {
1016
+ collection: "{collection}"
1017
+ }
1018
+ });
1019
+ },
1020
+ get unsyncedBringInFailed() {
1021
+ return i18n._(
1022
+ /** i18n */
1023
+ {
1024
+ id: "YeTn-r",
1025
+ message: "Some of your work couldn't be brought in. Try again.",
1026
+ context: "Collection access interface"
1027
+ });
1028
+ },
1029
+ get unsyncedReviewTitle() {
1030
+ return i18n._({
1031
+ ...
1032
+ /** i18n */
1033
+ {
1034
+ id: "RAaA7k",
1035
+ message: "Bring your work into {collection}?",
1036
+ context: "Collection access interface"
1037
+ },
1038
+ values: {
1039
+ collection: "{collection}"
1040
+ }
1041
+ });
1042
+ },
1043
+ get unsyncedReviewRenamed() {
1044
+ return i18n._(
1045
+ /** i18n */
1046
+ {
1047
+ id: "gpOX_m",
1048
+ message: "Some items get a new name because their names are already taken.",
1049
+ context: "Collection access interface"
1050
+ });
1051
+ },
1052
+ get unsyncedReviewTypes() {
1053
+ return i18n._({
1054
+ ...
1055
+ /** i18n */
1056
+ {
1057
+ id: "1m_O5B",
1058
+ message: "These types are added: {types}.",
1059
+ context: "Collection access interface"
1060
+ },
1061
+ values: {
1062
+ types: "{types}"
1063
+ }
1064
+ });
1065
+ },
1066
+ get unsyncedReviewChanged() {
1067
+ return i18n._(
1068
+ /** i18n */
1069
+ {
1070
+ id: "vJnf00",
1071
+ message: "Some items changed after they were brought in. Their newer versions are added beside them.",
1072
+ context: "Collection access interface"
1073
+ });
1074
+ },
1075
+ get unsyncedReviewMissing() {
1076
+ return i18n._(
1077
+ /** i18n */
1078
+ {
1079
+ id: "E5Yg13",
1080
+ message: "Some items use types this collection doesn't have. They're brought in as they are.",
1081
+ context: "Collection access interface"
1082
+ });
1083
+ },
1084
+ get unsyncedDiscard() {
1085
+ return i18n._(
1086
+ /** i18n */
1087
+ {
1088
+ id: "nuwdSX",
1089
+ message: "Discard\u2026",
1090
+ context: "Collection access interface"
1091
+ });
1092
+ },
1093
+ get unsyncedDiscardTitle() {
1094
+ return i18n._(
1095
+ /** i18n */
1096
+ {
1097
+ id: "O_A3T7",
1098
+ message: "Discard work that isn't in a collection?",
1099
+ context: "Collection access interface"
1100
+ });
1101
+ },
1102
+ get unsyncedDiscardBody() {
1103
+ return i18n._({
1104
+ ...
1105
+ /** i18n */
1106
+ {
1107
+ id: "Eo7hjG",
1108
+ message: "It's erased from {app} on this device. This can't be undone.",
1109
+ context: "Collection access interface"
1110
+ },
1111
+ values: {
1112
+ app: "{app}"
1113
+ }
1114
+ });
1115
+ },
1116
+ get unsyncedDiscardConfirm() {
1117
+ return i18n._(
1118
+ /** i18n */
1119
+ {
1120
+ id: "BtShoJ",
1121
+ message: "Discard",
1122
+ context: "Collection access interface"
1123
+ });
1124
+ },
1125
+ get unsyncedDiscarding() {
1126
+ return i18n._(
1127
+ /** i18n */
1128
+ {
1129
+ id: "_9_0zY",
1130
+ message: "Discarding\u2026",
1131
+ context: "Collection access interface"
1132
+ });
1133
+ },
924
1134
  get close() {
925
1135
  return i18n._(
926
1136
  /** i18n */
@@ -7,6 +7,7 @@ import "../i18n.js";
7
7
  */
8
8
  import type { MdbaseLinks, MdbasePhase, MdbaseProblem, MdbaseSnapshot } from "@mdbase-dev/sdk";
9
9
  import { type CollectionCopy } from "./copy.js";
10
+ import { type UnsyncedPhase } from "./unsynced.js";
10
11
  export type CollectionRole = "owner" | "editor" | "viewer";
11
12
  /** One approved collection, ready to render as a list row. */
12
13
  export interface CollectionRow {
@@ -81,6 +82,8 @@ interface Common {
81
82
  readonly links: MdbaseLinks | null;
82
83
  /** True when "Choose a different collection" leaves something open or requested. */
83
84
  readonly canChooseAnother: boolean;
85
+ /** Work saved before connecting that is not in a collection yet. */
86
+ readonly unsyncedWork: boolean;
84
87
  }
85
88
  export type CollectionView = Common & ({
86
89
  readonly kind: "starting";
@@ -116,6 +119,12 @@ export type CollectionView = Common & ({
116
119
  kind: "ready";
117
120
  }>;
118
121
  readonly notice: CollectionNotice | null;
122
+ }
123
+ /** The app's unsynced collection is open: render the app, saved only on this device. */
124
+ | {
125
+ readonly kind: "unsynced";
126
+ readonly collectionId: string;
127
+ readonly phase: UnsyncedPhase;
119
128
  } | {
120
129
  readonly kind: "unavailable";
121
130
  readonly notice: CollectionNotice;
@@ -2,6 +2,7 @@ import { i18n as _i18n } from "@lingui/core";
2
2
  import "../i18n.js";
3
3
  import { describeError } from "@mdbase-dev/sdk/describe";
4
4
  import { defaultCollectionCopy, fill } from "./copy.js";
5
+ import { hasUnsyncedWork, unsyncedPhase } from "./unsynced.js";
5
6
  /** Map an SDK snapshot to the screen to show. */
6
7
  export function collectionView(snapshot, options) {
7
8
  const copy = {
@@ -25,7 +26,18 @@ export function collectionView(snapshot, options) {
25
26
  collections,
26
27
  current,
27
28
  links: snapshot.links ?? null,
28
- canChooseAnother: signedIn && (currentId !== null || (snapshot.selection.requested.collectionId ?? null) !== null)
29
+ canChooseAnother: signedIn && (currentId !== null || (snapshot.selection.requested.collectionId ?? null) !== null),
30
+ unsyncedWork: hasUnsyncedWork(snapshot)
31
+ };
32
+ // Not part of every SDK's phase union yet (see unsynced.ts).
33
+ const unsynced = unsyncedPhase(phase);
34
+ if (unsynced) return {
35
+ ...common,
36
+ kind: "unsynced",
37
+ collectionId: unsynced.collectionId,
38
+ phase: unsynced,
39
+ heading: app,
40
+ lead: null
29
41
  };
30
42
  switch (phase.kind) {
31
43
  case "starting":
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Work before connecting: the SDK's `unsynced` phase, `snapshot.unsyncedWork`
3
+ * and `mdbase.unsynced`, read structurally so this package keeps building
4
+ * against SDK releases that predate them (where they are simply absent).
5
+ */
6
+ import type { CreateInput, Mdbase, MdbaseApplicationConnection, MdbasePhase, RecordView } from "@mdbase-dev/sdk";
7
+ /** The tab shows the app's unsynced collection: saved only on this device. */
8
+ export interface UnsyncedPhase {
9
+ readonly kind: "unsynced";
10
+ readonly collectionId: string;
11
+ readonly connection: MdbaseApplicationConnection;
12
+ readonly rechecking: boolean;
13
+ }
14
+ /** Reshape or leave out (null) a record when bringing work in; it must keep its ID. */
15
+ export type UnsyncedTransferMap = (record: RecordView) => CreateInput | null | Promise<CreateInput | null>;
16
+ export interface UnsyncedPlan {
17
+ readonly destination: string;
18
+ readonly counts: Readonly<{
19
+ create: number;
20
+ present: number;
21
+ skipped: number;
22
+ renamed: number;
23
+ changed?: number;
24
+ }>;
25
+ readonly missingTypes: readonly string[];
26
+ readonly addTypes?: readonly string[];
27
+ }
28
+ export interface UnsyncedResult {
29
+ readonly failed: readonly unknown[];
30
+ readonly failedTypes?: readonly unknown[];
31
+ readonly retired?: boolean;
32
+ }
33
+ interface UnsyncedApi {
34
+ open(options?: {
35
+ signal?: AbortSignal;
36
+ }): Promise<unknown>;
37
+ planTransfer(options?: {
38
+ map?: UnsyncedTransferMap;
39
+ addTypes?: boolean;
40
+ signal?: AbortSignal;
41
+ }): Promise<UnsyncedPlan>;
42
+ transfer(plan: UnsyncedPlan, options?: {
43
+ signal?: AbortSignal;
44
+ }): Promise<UnsyncedResult>;
45
+ discard(options?: {
46
+ signal?: AbortSignal;
47
+ }): Promise<unknown>;
48
+ }
49
+ /** `mdbase.unsynced`, or null on an SDK without it. */
50
+ export declare function unsyncedApi(mdbase: Mdbase): UnsyncedApi | null;
51
+ export declare function unsyncedPhase(phase: MdbasePhase): UnsyncedPhase | null;
52
+ /** Something has been saved in the unsynced collection and not yet brought in. */
53
+ export declare function hasUnsyncedWork(snapshot: object): boolean;
54
+ /** Whether bringing this plan in has something for the person to decide first. */
55
+ export declare function planNeedsReview(plan: UnsyncedPlan): boolean;
56
+ export {};
@@ -0,0 +1,18 @@
1
+ /** `mdbase.unsynced`, or null on an SDK without it. */
2
+ export function unsyncedApi(mdbase) {
3
+ const api = mdbase.unsynced;
4
+ return api && typeof api.open === "function" && typeof api.planTransfer === "function" && typeof api.transfer === "function" && typeof api.discard === "function" ? api : null;
5
+ }
6
+ export function unsyncedPhase(phase) {
7
+ const value = phase;
8
+ return value.kind === "unsynced" && typeof value.collectionId === "string" && value.connection ? value : null;
9
+ }
10
+ /** Something has been saved in the unsynced collection and not yet brought in. */
11
+ export function hasUnsyncedWork(snapshot) {
12
+ const work = snapshot.unsyncedWork;
13
+ return typeof work === "object" && work !== null;
14
+ }
15
+ /** Whether bringing this plan in has something for the person to decide first. */
16
+ export function planNeedsReview(plan) {
17
+ return plan.counts.renamed > 0 || (plan.counts.changed ?? 0) > 0 || (plan.addTypes?.length ?? 0) > 0 || plan.missingTypes.length > 0;
18
+ }
@@ -2,12 +2,20 @@ import type { Mdbase, MdbaseProblem } from "@mdbase-dev/sdk";
2
2
  import { type ReactNode } from "react";
3
3
  import { type CollectionCopy } from "./copy.js";
4
4
  import { type CollectionNotice, type CollectionRow, type CollectionView, type ProblemControl } from "./model.js";
5
+ import { type UnsyncedPlan, type UnsyncedTransferMap } from "./unsynced.js";
5
6
  /** The only app-specific input: what the app is called, and its mark. */
6
7
  export interface CollectionAppIdentity {
7
8
  readonly name: string;
8
9
  readonly mark?: ReactNode;
9
10
  }
10
11
  export type LeaveIntent = "switch" | "add" | "choose_another" | "sign_out";
12
+ /** Work before connecting: the app created its entry with `{unsynced: true}`. */
13
+ export interface CollectionUnsyncedOptions {
14
+ /** Where that work is kept: "Saved only in this browser" (default) or, in a native shell, "on this device". */
15
+ readonly storage?: "browser" | "device" | undefined;
16
+ /** Reshape or leave out records when bringing the work into a collection. Default: as they are. */
17
+ readonly map?: UnsyncedTransferMap | undefined;
18
+ }
11
19
  /** A collection the app lists itself (one the SDK doesn't), in an app section. */
12
20
  export interface CollectionSectionItem {
13
21
  readonly id: string;
@@ -85,9 +93,11 @@ export interface CollectionUiOptions {
85
93
  readonly sections?: readonly CollectionSection[] | undefined;
86
94
  /** A second line for an SDK collection row (where it lives, which account), from the row and its SDK entry. */
87
95
  readonly rowDetail?: ((row: CollectionRow) => string | null | undefined) | undefined;
96
+ /** Work before connecting: "Continue without connecting" when signed out, the "Saved only in this browser" line, and bringing that work into the collection the person opens. */
97
+ readonly unsynced?: CollectionUnsyncedOptions | boolean | undefined;
88
98
  }
89
99
  /** `add_private` remains available to legacy track callers; both add APIs now emit `add`. */
90
- export type CollectionActionName = "sign_in" | "add" | "add_private" | "approve" | "select" | "choose_another" | "assess" | "start" | "sign_out" | "setup";
100
+ export type CollectionActionName = "sign_in" | "add" | "add_private" | "approve" | "select" | "choose_another" | "assess" | "start" | "sign_out" | "setup" | "open_unsynced" | "bring_in" | "discard_unsynced";
91
101
  export interface CollectionUi {
92
102
  readonly view: CollectionView;
93
103
  readonly copy: CollectionCopy;
@@ -101,6 +111,10 @@ export interface CollectionUi {
101
111
  readonly signOutPrompt: MdbaseProblem | null;
102
112
  /** The open app section item, which takes the place of the SDK's current collection. */
103
113
  readonly appOpen: OpenSectionItem | null;
114
+ /** A plan to bring unsynced work in that has something to confirm (renames, types). */
115
+ readonly unsyncedReview: UnsyncedPlan | null;
116
+ /** How bringing unsynced work in ended, until dismissed or the screen changes. */
117
+ readonly unsyncedNotice: CollectionNotice | null;
104
118
  readonly actions: CollectionActions;
105
119
  }
106
120
  export interface CollectionActions {
@@ -127,6 +141,17 @@ export interface CollectionActions {
127
141
  perform(control: ProblemControl, onSetUp?: () => void): void;
128
142
  /** Track an app-ui call that is not a button above (setup), so errors show the same way. */
129
143
  track(name: CollectionActionName, call: () => Promise<unknown>): Promise<unknown>;
144
+ /** "Connect to sync your work": sign in, or choose a collection when signed in. */
145
+ connect(): void;
146
+ /** Open the app's unsynced collection (work before connecting). */
147
+ continueWithoutConnecting(): void;
148
+ /** Bring unsynced work into the open collection; asks first (`unsyncedReview`) when there is something to confirm. */
149
+ bringIn(): void;
150
+ confirmBringIn(): void;
151
+ dismissBringIn(): void;
152
+ /** Erase the unsynced work. Only after the person confirmed it. */
153
+ discardUnsynced(): void;
154
+ dismissUnsyncedNotice(): void;
130
155
  }
131
156
  /** The first current item across the app's sections. */
132
157
  export declare function appOpenItem(sections: readonly CollectionSection[] | undefined): OpenSectionItem | null;