@cellarnode/ui 0.187.0 → 0.189.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/brand/brand-assets-api.d.ts +65 -0
- package/dist/brand/brand-assets-api.d.ts.map +1 -0
- package/dist/brand/brand-assets-api.js +172 -0
- package/dist/brand/brand-assets-api.js.map +1 -0
- package/dist/brand/brand-assets-section-copy.d.ts +63 -0
- package/dist/brand/brand-assets-section-copy.d.ts.map +1 -0
- package/dist/brand/brand-assets-section-copy.js +56 -0
- package/dist/brand/brand-assets-section-copy.js.map +1 -0
- package/dist/brand/brand-assets-section.d.ts +62 -0
- package/dist/brand/brand-assets-section.d.ts.map +1 -0
- package/dist/brand/brand-assets-section.js +172 -0
- package/dist/brand/brand-assets-section.js.map +1 -0
- package/dist/brand/brand-font-family.d.ts +37 -0
- package/dist/brand/brand-font-family.d.ts.map +1 -0
- package/dist/brand/brand-font-family.js +83 -0
- package/dist/brand/brand-font-family.js.map +1 -0
- package/dist/brand/brand-font-upload.d.ts +17 -0
- package/dist/brand/brand-font-upload.d.ts.map +1 -0
- package/dist/brand/brand-font-upload.js +42 -0
- package/dist/brand/brand-font-upload.js.map +1 -0
- package/dist/brand/brand-generation-client.d.ts +8 -0
- package/dist/brand/brand-generation-client.d.ts.map +1 -1
- package/dist/brand/brand-generation-client.js +1 -1
- package/dist/brand/brand-generation-client.js.map +1 -1
- package/dist/brand/brand-generation-start.d.ts +49 -0
- package/dist/brand/brand-generation-start.d.ts.map +1 -0
- package/dist/brand/brand-generation-start.js +48 -0
- package/dist/brand/brand-generation-start.js.map +1 -0
- package/dist/brand/brand-image-chooser.d.ts +3 -1
- package/dist/brand/brand-image-chooser.d.ts.map +1 -1
- package/dist/brand/brand-image-chooser.js +7 -1
- package/dist/brand/brand-image-chooser.js.map +1 -1
- package/dist/brand/brand-image-choosers.d.ts +37 -0
- package/dist/brand/brand-image-choosers.d.ts.map +1 -0
- package/dist/brand/brand-image-choosers.js +76 -0
- package/dist/brand/brand-image-choosers.js.map +1 -0
- package/dist/brand/brand-workspace-change-notice.d.ts +20 -0
- package/dist/brand/brand-workspace-change-notice.d.ts.map +1 -0
- package/dist/brand/brand-workspace-change-notice.js +19 -0
- package/dist/brand/brand-workspace-change-notice.js.map +1 -0
- package/dist/brand/index.d.ts +23 -0
- package/dist/brand/index.d.ts.map +1 -1
- package/dist/brand/index.js +21 -0
- package/dist/brand/index.js.map +1 -1
- package/dist/brand/scan-page-banner.d.ts +21 -0
- package/dist/brand/scan-page-banner.d.ts.map +1 -0
- package/dist/brand/scan-page-banner.js +48 -0
- package/dist/brand/scan-page-banner.js.map +1 -0
- package/dist/brand/use-brand-image-operation-result.d.ts +43 -0
- package/dist/brand/use-brand-image-operation-result.d.ts.map +1 -0
- package/dist/brand/use-brand-image-operation-result.js +162 -0
- package/dist/brand/use-brand-image-operation-result.js.map +1 -0
- package/dist/brand/use-brand-profile-acceptance.d.ts +38 -0
- package/dist/brand/use-brand-profile-acceptance.d.ts.map +1 -0
- package/dist/brand/use-brand-profile-acceptance.js +84 -0
- package/dist/brand/use-brand-profile-acceptance.js.map +1 -0
- package/dist/brand/use-brand-public-visibility.d.ts +59 -0
- package/dist/brand/use-brand-public-visibility.d.ts.map +1 -0
- package/dist/brand/use-brand-public-visibility.js +69 -0
- package/dist/brand/use-brand-public-visibility.js.map +1 -0
- package/dist/brand/use-brand-workspace-concurrency.d.ts +131 -0
- package/dist/brand/use-brand-workspace-concurrency.d.ts.map +1 -0
- package/dist/brand/use-brand-workspace-concurrency.js +251 -0
- package/dist/brand/use-brand-workspace-concurrency.js.map +1 -0
- package/dist/brand/use-brand-workspace-image-candidates.d.ts +19 -0
- package/dist/brand/use-brand-workspace-image-candidates.d.ts.map +1 -0
- package/dist/brand/use-brand-workspace-image-candidates.js +39 -0
- package/dist/brand/use-brand-workspace-image-candidates.js.map +1 -0
- package/dist/moderation/focus-upload-control.d.ts +15 -0
- package/dist/moderation/focus-upload-control.d.ts.map +1 -0
- package/dist/moderation/focus-upload-control.js +21 -0
- package/dist/moderation/focus-upload-control.js.map +1 -0
- package/dist/moderation/index.d.ts +1 -0
- package/dist/moderation/index.d.ts.map +1 -1
- package/dist/moderation/index.js +1 -0
- package/dist/moderation/index.js.map +1 -1
- package/dist/moderation/moderation-event.d.ts +2 -0
- package/dist/moderation/moderation-event.d.ts.map +1 -1
- package/dist/moderation/moderation-event.js +7 -0
- package/dist/moderation/moderation-event.js.map +1 -1
- package/dist/moderation/moderation-scope.d.ts +31 -0
- package/dist/moderation/moderation-scope.d.ts.map +1 -0
- package/dist/moderation/moderation-scope.js +109 -0
- package/dist/moderation/moderation-scope.js.map +1 -0
- package/dist/moderation/moderation-store.d.ts.map +1 -1
- package/dist/moderation/moderation-store.js +4 -2
- package/dist/moderation/moderation-store.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
import { isTerminalStatus } from "./brand-generation-keys.js";
|
|
3
|
+
export const DEFAULT_BRAND_PROFILE_ACCEPTANCE_COPY = {
|
|
4
|
+
acceptFailed: "Failed to accept profile",
|
|
5
|
+
acceptEarlyRequested: "Wrapping up the current run",
|
|
6
|
+
acceptRunIncomplete: "This run did not finish, so there is no new profile to accept. Retry generation.",
|
|
7
|
+
accepted: "Profile accepted",
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* CEL-2127 — "Accept profile" for a generated draft, shared by producer and
|
|
11
|
+
* importer. While the run is still going it asks the backend to wrap up
|
|
12
|
+
* (early accept); once completed it approves the draft and resets the flow.
|
|
13
|
+
* Either path is single-flight per org and never reports into another org's
|
|
14
|
+
* session after an org switch.
|
|
15
|
+
*/
|
|
16
|
+
export function useBrandProfileAcceptance({ orgId, brandGeneration, approve, notify, copy, }) {
|
|
17
|
+
const text = { ...DEFAULT_BRAND_PROFILE_ACCEPTANCE_COPY, ...copy };
|
|
18
|
+
const [signalPendingState, setSignalPendingState] = useState(null);
|
|
19
|
+
const pendingActionRef = useRef(null);
|
|
20
|
+
const currentOrgIdRef = useRef(orgId);
|
|
21
|
+
currentOrgIdRef.current = orgId;
|
|
22
|
+
const signalPending = signalPendingState?.orgId === orgId;
|
|
23
|
+
const beginPendingAction = () => {
|
|
24
|
+
if (pendingActionRef.current?.orgId === orgId)
|
|
25
|
+
return null;
|
|
26
|
+
const action = { orgId };
|
|
27
|
+
pendingActionRef.current = action;
|
|
28
|
+
setSignalPendingState(action);
|
|
29
|
+
return action;
|
|
30
|
+
};
|
|
31
|
+
const finishPendingAction = (action) => {
|
|
32
|
+
if (pendingActionRef.current === action)
|
|
33
|
+
pendingActionRef.current = null;
|
|
34
|
+
setSignalPendingState((pending) => (pending === action ? null : pending));
|
|
35
|
+
};
|
|
36
|
+
const stillCurrent = (action) => currentOrgIdRef.current === action.orgId;
|
|
37
|
+
const accept = () => {
|
|
38
|
+
const job = brandGeneration.job;
|
|
39
|
+
if (job && !isTerminalStatus(job.status)) {
|
|
40
|
+
const action = beginPendingAction();
|
|
41
|
+
if (!action)
|
|
42
|
+
return;
|
|
43
|
+
brandGeneration
|
|
44
|
+
.accept()
|
|
45
|
+
.then((accepted) => {
|
|
46
|
+
if (!stillCurrent(action))
|
|
47
|
+
return;
|
|
48
|
+
if (accepted === false)
|
|
49
|
+
notify?.({ tone: "error", message: text.acceptFailed });
|
|
50
|
+
else
|
|
51
|
+
notify?.({ tone: "info", message: text.acceptEarlyRequested });
|
|
52
|
+
})
|
|
53
|
+
.catch(() => {
|
|
54
|
+
if (stillCurrent(action))
|
|
55
|
+
notify?.({ tone: "error", message: text.acceptFailed });
|
|
56
|
+
})
|
|
57
|
+
.finally(() => finishPendingAction(action));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (job && job.status !== "completed") {
|
|
61
|
+
notify?.({ tone: "error", message: text.acceptRunIncomplete });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const action = beginPendingAction();
|
|
65
|
+
if (!action)
|
|
66
|
+
return;
|
|
67
|
+
approve({
|
|
68
|
+
onSuccess: () => {
|
|
69
|
+
finishPendingAction(action);
|
|
70
|
+
if (!stillCurrent(action))
|
|
71
|
+
return;
|
|
72
|
+
notify?.({ tone: "success", message: text.accepted });
|
|
73
|
+
brandGeneration.reset();
|
|
74
|
+
},
|
|
75
|
+
onError: () => {
|
|
76
|
+
finishPendingAction(action);
|
|
77
|
+
if (stillCurrent(action))
|
|
78
|
+
notify?.({ tone: "error", message: text.acceptFailed });
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
return { accept, signalPending };
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=use-brand-profile-acceptance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-brand-profile-acceptance.js","sourceRoot":"","sources":["../../src/brand/use-brand-profile-acceptance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAe3D,MAAM,CAAC,MAAM,qCAAqC,GAA+B;IAC/E,YAAY,EAAE,0BAA0B;IACxC,oBAAoB,EAAE,6BAA6B;IACnD,mBAAmB,EACjB,kFAAkF;IACpF,QAAQ,EAAE,kBAAkB;CAC7B,CAAC;AAgBF;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,EACxC,KAAK,EACL,eAAe,EACf,OAAO,EACP,MAAM,EACN,IAAI,GAC6B;IACjC,MAAM,IAAI,GAAG,EAAE,GAAG,qCAAqC,EAAE,GAAG,IAAI,EAAE,CAAC;IACnE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,QAAQ,CAAuB,IAAI,CAAC,CAAC;IACzF,MAAM,gBAAgB,GAAG,MAAM,CAAuB,IAAI,CAAC,CAAC;IAC5D,MAAM,eAAe,GAAG,MAAM,CA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AAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;YACpF,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { BrandWorkspaceTarget } from "./use-brand-workspace-concurrency.js";
|
|
2
|
+
import type { BrandPublicField } from "./brand-profile-review.js";
|
|
3
|
+
/** The profile a visibility write is compare-and-swapped against. */
|
|
4
|
+
export interface BrandVisibilityProfile {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly status: string;
|
|
7
|
+
readonly revision?: number | null;
|
|
8
|
+
}
|
|
9
|
+
export interface BrandPublicVisibilityWrite {
|
|
10
|
+
readonly expectedProfileId: string;
|
|
11
|
+
readonly expectedStatus: string;
|
|
12
|
+
readonly expectedRevision: number | undefined;
|
|
13
|
+
readonly publicVisibility: Readonly<Partial<Record<BrandPublicField, boolean>>>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The injected data layer: persist one field's visibility on the approved
|
|
17
|
+
* profile or on the generated draft, resolving with the saved profile.
|
|
18
|
+
*/
|
|
19
|
+
export interface BrandPublicVisibilityApi {
|
|
20
|
+
save: (write: BrandPublicVisibilityWrite, target: BrandWorkspaceTarget) => Promise<{
|
|
21
|
+
readonly revision?: number | null;
|
|
22
|
+
} | null | undefined | void>;
|
|
23
|
+
}
|
|
24
|
+
export type BrandPublicVisibilityEvent = {
|
|
25
|
+
readonly kind: "reload-before-saving";
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: "wait-for-save";
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: "save-failed";
|
|
30
|
+
};
|
|
31
|
+
export interface UseBrandPublicVisibilityOptions {
|
|
32
|
+
readonly orgId: string | null;
|
|
33
|
+
readonly api: BrandPublicVisibilityApi;
|
|
34
|
+
/** The approved profile. */
|
|
35
|
+
readonly profile: BrandVisibilityProfile | null | undefined;
|
|
36
|
+
/** The generated draft under review; wins over `profile` when present. */
|
|
37
|
+
readonly generatedDraftProfile: BrandVisibilityProfile | null | undefined;
|
|
38
|
+
/** `requiresReload` from `useBrandWorkspaceConcurrency`. */
|
|
39
|
+
readonly requiresReload: boolean;
|
|
40
|
+
/** A profile write (save, approve, discard) in flight. */
|
|
41
|
+
readonly profileWritePending: boolean;
|
|
42
|
+
/** A 409 REVISION_CONFLICT / TARGET_MISMATCH: wire to `markServerChanged`. */
|
|
43
|
+
readonly onConflict: () => void;
|
|
44
|
+
/** Wire to `noteOwnWrite` so the refetch is not read as a remote change. */
|
|
45
|
+
readonly onOwnWrite?: (saved: {
|
|
46
|
+
readonly revision?: number | null;
|
|
47
|
+
} | null | undefined) => void;
|
|
48
|
+
readonly notify?: (event: BrandPublicVisibilityEvent) => void;
|
|
49
|
+
/** Same duck-typed check as the concurrency hook's default classifier. */
|
|
50
|
+
readonly isConflict?: (error: unknown) => boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* CEL-2127 — the public-visibility toggle handler for the brand workspace.
|
|
54
|
+
* One in-flight write per org+field; refuses while a reload is required or a
|
|
55
|
+
* profile write is pending; a CAS conflict marks the server as changed rather
|
|
56
|
+
* than retrying (the user must see the latest values first).
|
|
57
|
+
*/
|
|
58
|
+
export declare function useBrandPublicVisibility(options: UseBrandPublicVisibilityOptions): (field: BrandPublicField, next: boolean) => void;
|
|
59
|
+
//# sourceMappingURL=use-brand-public-visibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-brand-public-visibility.d.ts","sourceRoot":"","sources":["../../src/brand/use-brand-public-visibility.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,qEAAqE;AACrE,MAAM,WAAW,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C5D,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;IAChC,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC;IAChG,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAC9D,0EAA0E;IAC1E,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACnD;AAQD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,+BAA+B,GACvC,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAmElD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
function defaultIsConflict(error) {
|
|
3
|
+
if (error === null || typeof error !== "object")
|
|
4
|
+
return false;
|
|
5
|
+
const code = error.code;
|
|
6
|
+
return code === "REVISION_CONFLICT" || code === "TARGET_MISMATCH";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* CEL-2127 — the public-visibility toggle handler for the brand workspace.
|
|
10
|
+
* One in-flight write per org+field; refuses while a reload is required or a
|
|
11
|
+
* profile write is pending; a CAS conflict marks the server as changed rather
|
|
12
|
+
* than retrying (the user must see the latest values first).
|
|
13
|
+
*/
|
|
14
|
+
export function useBrandPublicVisibility(options) {
|
|
15
|
+
const pendingKeysRef = useRef(new Set());
|
|
16
|
+
const optionsRef = useRef(options);
|
|
17
|
+
optionsRef.current = options;
|
|
18
|
+
return (field, next) => {
|
|
19
|
+
const { orgId, api, profile, generatedDraftProfile, requiresReload, profileWritePending, onConflict, onOwnWrite, notify, isConflict = defaultIsConflict, } = optionsRef.current;
|
|
20
|
+
const reviewed = generatedDraftProfile ?? profile;
|
|
21
|
+
if (!orgId || !reviewed)
|
|
22
|
+
return;
|
|
23
|
+
if (requiresReload) {
|
|
24
|
+
notify?.({ kind: "reload-before-saving" });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (profileWritePending) {
|
|
28
|
+
notify?.({ kind: "wait-for-save" });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const pendingKey = `${orgId}:${field}`;
|
|
32
|
+
// Results of a write started in org A must never act in org B.
|
|
33
|
+
const stillCurrent = () => optionsRef.current.orgId === orgId;
|
|
34
|
+
if (pendingKeysRef.current.has(pendingKey))
|
|
35
|
+
return;
|
|
36
|
+
pendingKeysRef.current.add(pendingKey);
|
|
37
|
+
const target = generatedDraftProfile ? "draft" : "approved";
|
|
38
|
+
let attempt;
|
|
39
|
+
try {
|
|
40
|
+
attempt = api.save({
|
|
41
|
+
expectedProfileId: reviewed.id,
|
|
42
|
+
expectedStatus: reviewed.status,
|
|
43
|
+
expectedRevision: reviewed.revision ?? undefined,
|
|
44
|
+
publicVisibility: { [field]: next },
|
|
45
|
+
}, target);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
attempt = Promise.reject(error);
|
|
49
|
+
}
|
|
50
|
+
void attempt
|
|
51
|
+
.then((saved) => {
|
|
52
|
+
if (stillCurrent())
|
|
53
|
+
onOwnWrite?.(saved ?? undefined);
|
|
54
|
+
}, (error) => {
|
|
55
|
+
if (!stillCurrent())
|
|
56
|
+
return;
|
|
57
|
+
if (isConflict(error)) {
|
|
58
|
+
onConflict();
|
|
59
|
+
notify?.({ kind: "reload-before-saving" });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
notify?.({ kind: "save-failed" });
|
|
63
|
+
})
|
|
64
|
+
.finally(() => {
|
|
65
|
+
pendingKeysRef.current.delete(pendingKey);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=use-brand-public-visibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-brand-public-visibility.js","sourceRoot":"","sources":["../../src/brand/use-brand-public-visibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAsD/B,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,IAAI,GAAI,KAA4B,CAAC,IAAI,CAAC;IAChD,OAAO,IAAI,KAAK,mBAAmB,IAAI,IAAI,KAAK,iBAAiB,CAAC;AACpE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAwC;IAExC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,GAAG,EAAU,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,MAAM,EACJ,KAAK,EACL,GAAG,EACH,OAAO,EACP,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,MAAM,EACN,UAAU,GAAG,iBAAiB,GAC/B,GAAG,UAAU,CAAC,OAAO,CAAC;QACvB,MAAM,QAAQ,GAAG,qBAAqB,IAAI,OAAO,CAAC;QAClD,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ;YAAE,OAAO;QAChC,IAAI,cAAc,EAAE,CAAC;YACnB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,CAAC;YAC3C,OAAO;QACT,CAAC;QACD,IAA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E,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,CAAC;gBAC3C,OAAO;YACT,CAAC;YACD,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;QACpC,CAAC,CACF;aACA,OAAO,CAAC,GAAG,EAAE;YACZ,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { BrandProfileConflict } from "./brand-profile-form.js";
|
|
2
|
+
/**
|
|
3
|
+
* CEL-2127 — the ONE implementation of brand-workspace write concurrency.
|
|
4
|
+
*
|
|
5
|
+
* It owns what producer's `BrandContentController` and importer's
|
|
6
|
+
* `BrandProfileContent` each did by hand, with producer's semantics:
|
|
7
|
+
*
|
|
8
|
+
* - `409 REVISION_CONFLICT` surfaces as {@link UseBrandWorkspaceConcurrencyResult.conflict}
|
|
9
|
+
* on the form. The user then chooses, explicitly:
|
|
10
|
+
* - **reload** re-reads the server and remounts the form on the fresh values
|
|
11
|
+
* (the form key changes, so nothing of the stale edit survives);
|
|
12
|
+
* - **keep mine** re-submits the SAME sparse patch against the revision the
|
|
13
|
+
* conflict reported. It only ever runs from that explicit user action,
|
|
14
|
+
* never automatically, and the server still compare-and-swaps it, so a
|
|
15
|
+
* third write in between conflicts again instead of being overwritten.
|
|
16
|
+
* - `409 TARGET_MISMATCH` (the row this edit targeted is no longer the current
|
|
17
|
+
* target, e.g. the draft was approved elsewhere) has no revision to retry
|
|
18
|
+
* with: it reloads and closes the editor, and shows the change notice if
|
|
19
|
+
* that reload fails.
|
|
20
|
+
* - A server revision that moves underneath an open workspace, and is not our
|
|
21
|
+
* own write, raises `serverChanged` (render {@link BrandWorkspaceChangeNotice}).
|
|
22
|
+
*
|
|
23
|
+
* The data layer is injected: the hook never imports a client.
|
|
24
|
+
*/
|
|
25
|
+
/** What the hook needs to know about the profile the workspace is editing. */
|
|
26
|
+
export interface BrandWorkspaceSnapshot {
|
|
27
|
+
readonly id?: string | null;
|
|
28
|
+
readonly revision?: number | null;
|
|
29
|
+
readonly updatedAt?: string | null;
|
|
30
|
+
readonly status?: string | null;
|
|
31
|
+
readonly profileData?: unknown;
|
|
32
|
+
}
|
|
33
|
+
export type BrandWorkspaceTarget = "approved" | "draft";
|
|
34
|
+
/** The parts of a write body the hook reads or rewrites. */
|
|
35
|
+
export interface BrandWorkspaceWriteBody {
|
|
36
|
+
expectedRevision?: number;
|
|
37
|
+
}
|
|
38
|
+
/** How a failed save is classified. {@link classifyBrandProfileApiError} is the default. */
|
|
39
|
+
export type BrandWorkspaceSaveFailure = {
|
|
40
|
+
readonly kind: "revision-conflict";
|
|
41
|
+
readonly currentRevision: number;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: "target-mismatch";
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "validation";
|
|
46
|
+
readonly fieldErrors: Readonly<Record<string, string>>;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: "other";
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Duck-typed classifier for the brand-profile API error both dashboards use
|
|
52
|
+
* (`status`, `code`, `currentRevision`, `fieldErrors`). It deliberately does
|
|
53
|
+
* not `instanceof` a consumer class, so one classifier serves every client.
|
|
54
|
+
*/
|
|
55
|
+
export declare function classifyBrandProfileApiError(error: unknown): BrandWorkspaceSaveFailure;
|
|
56
|
+
/** Events the consumer turns into its own (translated) toast. The hook has no strings. */
|
|
57
|
+
export type BrandWorkspaceEvent = {
|
|
58
|
+
readonly kind: "saved";
|
|
59
|
+
} | {
|
|
60
|
+
readonly kind: "save-failed";
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: "target-mismatch";
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "reload-failed";
|
|
65
|
+
} | {
|
|
66
|
+
readonly kind: "reload-before-saving";
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: "wait-for-save";
|
|
69
|
+
};
|
|
70
|
+
export interface UseBrandWorkspaceConcurrencyOptions<TBody extends BrandWorkspaceWriteBody> {
|
|
71
|
+
readonly orgId: string;
|
|
72
|
+
/** The profile (approved or generated draft) the workspace is editing. */
|
|
73
|
+
readonly workspaceProfile: BrandWorkspaceSnapshot | null | undefined;
|
|
74
|
+
/** Whether a form is open on `workspaceProfile`; changes only matter then. */
|
|
75
|
+
readonly workspaceVisible: boolean;
|
|
76
|
+
/** Any write of this workspace in flight (save, visibility, approve, discard). */
|
|
77
|
+
readonly localWritePending: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Performs the write. Resolve with the saved profile. Its `revision` is
|
|
80
|
+
* REQUIRED for exact own-write detection: the refetch is "ours" only when
|
|
81
|
+
* the profile's revision equals it; without a revision the refetch raises
|
|
82
|
+
* the change notice (a safe false positive, never a swallowed remote edit).
|
|
83
|
+
* Reject with the transport error.
|
|
84
|
+
*/
|
|
85
|
+
readonly save: (body: TBody, target: BrandWorkspaceTarget) => Promise<{
|
|
86
|
+
readonly revision?: number | null;
|
|
87
|
+
} | null | undefined | void>;
|
|
88
|
+
/**
|
|
89
|
+
* Forces a re-read of everything the workspace derives from. MUST reject on
|
|
90
|
+
* failure so a failed reload never unlocks writes against a stale target.
|
|
91
|
+
* Resolve with the fresh workspace profile when known: it becomes the
|
|
92
|
+
* baseline, so the re-read is not reported back as a remote change.
|
|
93
|
+
*/
|
|
94
|
+
readonly reload: () => Promise<BrandWorkspaceSnapshot | null | undefined | void>;
|
|
95
|
+
readonly classifyError?: (error: unknown) => BrandWorkspaceSaveFailure;
|
|
96
|
+
/** Called after a successful save (close the editor here). */
|
|
97
|
+
readonly onSaved?: () => void;
|
|
98
|
+
/** Called after a successful reload; `closeEditor` is true for conflict resolution. */
|
|
99
|
+
readonly onReloaded?: (info: {
|
|
100
|
+
readonly closeEditor: boolean;
|
|
101
|
+
}) => void;
|
|
102
|
+
readonly notify?: (event: BrandWorkspaceEvent) => void;
|
|
103
|
+
}
|
|
104
|
+
export interface UseBrandWorkspaceConcurrencyResult<TBody extends BrandWorkspaceWriteBody> {
|
|
105
|
+
/** Pass to `BrandProfileForm`/`BrandProfileWorkspace`/`BrandGenerationSurface`. */
|
|
106
|
+
readonly conflict: BrandProfileConflict | null;
|
|
107
|
+
readonly fieldErrors: Readonly<Record<string, string>> | undefined;
|
|
108
|
+
/** The server changed underneath an open workspace; render the change notice. */
|
|
109
|
+
readonly serverChanged: boolean;
|
|
110
|
+
readonly reloadPending: boolean;
|
|
111
|
+
/** True while a write must wait for the user to reload (changed, reloading or conflicted). */
|
|
112
|
+
readonly requiresReload: boolean;
|
|
113
|
+
/** Pass as `key` on the form: it changes on every successful reload, remounting on fresh values. */
|
|
114
|
+
readonly workspaceKey: string;
|
|
115
|
+
/** Guarded submit: refuses while a reload is required or a write is pending. */
|
|
116
|
+
readonly submit: (body: TBody, target: BrandWorkspaceTarget) => void;
|
|
117
|
+
/** Conflict action: discard local edits, reload, close the editor. */
|
|
118
|
+
readonly reloadConflict: () => void;
|
|
119
|
+
/** Conflict action: deliberately re-submit the last patch against the reported revision. */
|
|
120
|
+
readonly keepMine: () => void;
|
|
121
|
+
/** Change-notice action: reload and keep the editor open. */
|
|
122
|
+
readonly reloadLatest: () => void;
|
|
123
|
+
/** Record a write made OUTSIDE `submit` (e.g. visibility) so its refetch is not a remote change. */
|
|
124
|
+
readonly noteOwnWrite: (saved: {
|
|
125
|
+
readonly revision?: number | null;
|
|
126
|
+
} | null | undefined) => void;
|
|
127
|
+
/** Mark the server as changed (e.g. a visibility write hit a conflict). */
|
|
128
|
+
readonly markServerChanged: () => void;
|
|
129
|
+
}
|
|
130
|
+
export declare function useBrandWorkspaceConcurrency<TBody extends BrandWorkspaceWriteBody>(options: UseBrandWorkspaceConcurrencyOptions<TBody>): UseBrandWorkspaceConcurrencyResult<TBody>;
|
|
131
|
+
//# sourceMappingURL=use-brand-workspace-concurrency.d.ts.map
|
|
@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AAO,EAAE,mCAAmC,CAAC,KAAK,CAAC,GAClD,kCAAkC,CAAC,KAAK,CAAC,CAsN3C"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { mapBrandBackendFieldErrors } from "./brand-profile-form-field-errors.js";
|
|
3
|
+
import { useOrgScopedState } from "./use-org-scoped-state.js";
|
|
4
|
+
/**
|
|
5
|
+
* Duck-typed classifier for the brand-profile API error both dashboards use
|
|
6
|
+
* (`status`, `code`, `currentRevision`, `fieldErrors`). It deliberately does
|
|
7
|
+
* not `instanceof` a consumer class, so one classifier serves every client.
|
|
8
|
+
*/
|
|
9
|
+
export function classifyBrandProfileApiError(error) {
|
|
10
|
+
if (error === null || typeof error !== "object")
|
|
11
|
+
return { kind: "other" };
|
|
12
|
+
const e = error;
|
|
13
|
+
if (e.code === "TARGET_MISMATCH")
|
|
14
|
+
return { kind: "target-mismatch" };
|
|
15
|
+
if (e.code === "REVISION_CONFLICT" && typeof e.currentRevision === "number") {
|
|
16
|
+
return { kind: "revision-conflict", currentRevision: e.currentRevision };
|
|
17
|
+
}
|
|
18
|
+
if (e.status === 422 &&
|
|
19
|
+
e.code === "VALIDATION_ERROR" &&
|
|
20
|
+
e.fieldErrors !== null &&
|
|
21
|
+
typeof e.fieldErrors === "object") {
|
|
22
|
+
return { kind: "validation", fieldErrors: e.fieldErrors };
|
|
23
|
+
}
|
|
24
|
+
return { kind: "other" };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The fields whose movement means "the server changed".
|
|
28
|
+
*
|
|
29
|
+
* `version` is deliberately NOT part of the key. The backend's `version` is a
|
|
30
|
+
* constant `"1"` that nothing ever bumps, so it can never signal a change;
|
|
31
|
+
* `revision` is the row's compare-and-swap counter and is what moves on every
|
|
32
|
+
* write (including a regeneration or backfill).
|
|
33
|
+
*/
|
|
34
|
+
function snapshotKey(orgId, profile) {
|
|
35
|
+
return JSON.stringify({
|
|
36
|
+
orgId,
|
|
37
|
+
id: profile?.id ?? null,
|
|
38
|
+
revision: profile?.revision ?? null,
|
|
39
|
+
updatedAt: profile?.updatedAt ?? null,
|
|
40
|
+
status: profile?.status ?? null,
|
|
41
|
+
profileData: profile?.profileData ?? null,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function useBrandWorkspaceConcurrency(options) {
|
|
45
|
+
const { orgId, workspaceProfile, workspaceVisible, localWritePending } = options;
|
|
46
|
+
const optionsRef = useRef(options);
|
|
47
|
+
optionsRef.current = options;
|
|
48
|
+
const orgIdRef = useRef(orgId);
|
|
49
|
+
orgIdRef.current = orgId;
|
|
50
|
+
const [conflict, setConflict] = useOrgScopedState(orgId, null);
|
|
51
|
+
const [fieldErrors, setFieldErrors] = useOrgScopedState(orgId, undefined);
|
|
52
|
+
const [serverChanged, setServerChanged] = useOrgScopedState(orgId, false);
|
|
53
|
+
const [reloadKey, , updateReloadKey] = useOrgScopedState(orgId, 0);
|
|
54
|
+
// Every piece of state below is scoped to `orgId`: switching org mid-reload
|
|
55
|
+
// or mid-write must not leak a pending flag, a retry patch or an own-write
|
|
56
|
+
// marker from one org into the next.
|
|
57
|
+
const [reloadPending, setReloadPending] = useOrgScopedState(orgId, false);
|
|
58
|
+
const reloadingOrgRef = useRef(null);
|
|
59
|
+
// A conflict retry reuses the exact sparse patch the user submitted.
|
|
60
|
+
// Recomputing it against a refetched profile could turn untouched, stale
|
|
61
|
+
// form values into writes.
|
|
62
|
+
const lastSubmitRef = useRef(null);
|
|
63
|
+
const currentKey = snapshotKey(orgId, workspaceProfile);
|
|
64
|
+
const observedRef = useRef({ orgId, key: currentKey });
|
|
65
|
+
// Own-write detection is EXACT. A write of our own bumps the revision, and
|
|
66
|
+
// the mutation settles before (or after) the refetched read lands, so the
|
|
67
|
+
// bump must not read as a remote change. The write reports the revision it
|
|
68
|
+
// produced; a server change is "own" only when the profile's revision equals
|
|
69
|
+
// it. Any other revision (a remote edit, including one that lands while our
|
|
70
|
+
// write is still in flight) raises the change notice. Until the write has
|
|
71
|
+
// reported its revision the observed baseline is NOT advanced, so nothing
|
|
72
|
+
// that arrives meanwhile is swallowed.
|
|
73
|
+
const ownWriteRef = useRef(null);
|
|
74
|
+
// The org whose write is in flight (org-scoped like the rest of the state).
|
|
75
|
+
const writeInFlightOrgRef = useRef(null);
|
|
76
|
+
const writeInFlight = () => writeInFlightOrgRef.current === orgIdRef.current;
|
|
77
|
+
const [settledTick, setSettledTick] = useState(0);
|
|
78
|
+
const noteOwnWrite = useCallback((saved) => {
|
|
79
|
+
ownWriteRef.current = { orgId: orgIdRef.current, revision: saved?.revision ?? null };
|
|
80
|
+
setSettledTick((tick) => tick + 1);
|
|
81
|
+
}, []);
|
|
82
|
+
const currentRevision = workspaceProfile?.revision ?? null;
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const observed = observedRef.current;
|
|
85
|
+
if (observed.orgId !== orgId || !workspaceVisible) {
|
|
86
|
+
observedRef.current = { orgId, key: currentKey };
|
|
87
|
+
ownWriteRef.current = null;
|
|
88
|
+
setServerChanged(false);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (observed.key === currentKey)
|
|
92
|
+
return;
|
|
93
|
+
const own = ownWriteRef.current;
|
|
94
|
+
if (own && own.orgId === orgId && own.revision !== null && own.revision === currentRevision) {
|
|
95
|
+
observedRef.current = { orgId, key: currentKey };
|
|
96
|
+
ownWriteRef.current = null;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// A write is still settling and has not reported its revision: decide once
|
|
100
|
+
// it has (this effect re-runs on `settledTick` and `localWritePending`).
|
|
101
|
+
if (localWritePending || writeInFlightOrgRef.current === orgId)
|
|
102
|
+
return;
|
|
103
|
+
observedRef.current = { orgId, key: currentKey };
|
|
104
|
+
setServerChanged(true);
|
|
105
|
+
}, [
|
|
106
|
+
currentKey,
|
|
107
|
+
currentRevision,
|
|
108
|
+
localWritePending,
|
|
109
|
+
orgId,
|
|
110
|
+
setServerChanged,
|
|
111
|
+
settledTick,
|
|
112
|
+
workspaceVisible,
|
|
113
|
+
]);
|
|
114
|
+
const notify = (event) => optionsRef.current.notify?.(event);
|
|
115
|
+
const reloadWorkspace = async (closeEditor) => {
|
|
116
|
+
const startedOrg = orgIdRef.current;
|
|
117
|
+
if (reloadingOrgRef.current === startedOrg)
|
|
118
|
+
return;
|
|
119
|
+
reloadingOrgRef.current = startedOrg;
|
|
120
|
+
setReloadPending(true);
|
|
121
|
+
try {
|
|
122
|
+
const fresh = await optionsRef.current.reload();
|
|
123
|
+
if (orgIdRef.current !== startedOrg)
|
|
124
|
+
return;
|
|
125
|
+
setConflict(null);
|
|
126
|
+
setFieldErrors(undefined);
|
|
127
|
+
lastSubmitRef.current = null;
|
|
128
|
+
// The freshly read profile is the new baseline: its arrival is the
|
|
129
|
+
// reload itself, not a remote change.
|
|
130
|
+
if (fresh)
|
|
131
|
+
observedRef.current = { orgId: startedOrg, key: snapshotKey(startedOrg, fresh) };
|
|
132
|
+
optionsRef.current.onReloaded?.({ closeEditor });
|
|
133
|
+
updateReloadKey((current) => current + 1);
|
|
134
|
+
setServerChanged(false);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
if (orgIdRef.current === startedOrg)
|
|
138
|
+
notify({ kind: "reload-failed" });
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
if (reloadingOrgRef.current === startedOrg)
|
|
142
|
+
reloadingOrgRef.current = null;
|
|
143
|
+
setReloadPending(false);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const perform = (body, target) => {
|
|
147
|
+
const startedOrg = orgIdRef.current;
|
|
148
|
+
setConflict(null);
|
|
149
|
+
setFieldErrors(undefined);
|
|
150
|
+
lastSubmitRef.current = { orgId: startedOrg, body, target };
|
|
151
|
+
writeInFlightOrgRef.current = startedOrg;
|
|
152
|
+
const classify = optionsRef.current.classifyError ?? classifyBrandProfileApiError;
|
|
153
|
+
let attempt;
|
|
154
|
+
try {
|
|
155
|
+
attempt = optionsRef.current.save(body, target);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
attempt = Promise.reject(error);
|
|
159
|
+
}
|
|
160
|
+
void attempt.then((saved) => {
|
|
161
|
+
// Clear only the guard of the org that started this write.
|
|
162
|
+
if (writeInFlightOrgRef.current === startedOrg)
|
|
163
|
+
writeInFlightOrgRef.current = null;
|
|
164
|
+
if (orgIdRef.current !== startedOrg) {
|
|
165
|
+
setSettledTick((tick) => tick + 1);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
noteOwnWrite(saved ?? undefined);
|
|
169
|
+
setConflict(null);
|
|
170
|
+
setFieldErrors(undefined);
|
|
171
|
+
notify({ kind: "saved" });
|
|
172
|
+
optionsRef.current.onSaved?.();
|
|
173
|
+
}, (error) => {
|
|
174
|
+
// Clear only the guard of the org that started this write.
|
|
175
|
+
if (writeInFlightOrgRef.current === startedOrg)
|
|
176
|
+
writeInFlightOrgRef.current = null;
|
|
177
|
+
setSettledTick((tick) => tick + 1);
|
|
178
|
+
if (orgIdRef.current !== startedOrg)
|
|
179
|
+
return;
|
|
180
|
+
const failure = classify(error);
|
|
181
|
+
if (failure.kind === "revision-conflict") {
|
|
182
|
+
// Keep the form open on its current (unsaved) values: the user
|
|
183
|
+
// decides reload vs keep-mine, nothing is discarded yet.
|
|
184
|
+
setConflict({ code: "REVISION_CONFLICT", currentRevision: failure.currentRevision });
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (failure.kind === "target-mismatch") {
|
|
188
|
+
// There is no revision to retry with: this can only be resolved by
|
|
189
|
+
// reloading, so do exactly that and show the real current state.
|
|
190
|
+
notify({ kind: "target-mismatch" });
|
|
191
|
+
setServerChanged(true);
|
|
192
|
+
void reloadWorkspace(true);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (failure.kind === "validation") {
|
|
196
|
+
setFieldErrors(failure.fieldErrors);
|
|
197
|
+
// Pointers the form cannot place on a control still land in its
|
|
198
|
+
// form-level summary; the toast covers the case it cannot.
|
|
199
|
+
if (mapBrandBackendFieldErrors(failure.fieldErrors).length !==
|
|
200
|
+
Object.keys(failure.fieldErrors).length)
|
|
201
|
+
notify({ kind: "save-failed" });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
notify({ kind: "save-failed" });
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
const submit = (body, target) => {
|
|
208
|
+
if (serverChanged || reloadPending || reloadingOrgRef.current === orgIdRef.current) {
|
|
209
|
+
notify({ kind: "reload-before-saving" });
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// `writeInFlightOrgRef` is synchronous: a second submit in the same render
|
|
213
|
+
// (before `localWritePending` can reflect the first) must not double-fire.
|
|
214
|
+
if (localWritePending || writeInFlight()) {
|
|
215
|
+
notify({ kind: "wait-for-save" });
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
perform(body, target);
|
|
219
|
+
};
|
|
220
|
+
const keepMine = () => {
|
|
221
|
+
const last = lastSubmitRef.current;
|
|
222
|
+
if (!last || last.orgId !== orgIdRef.current || !conflict)
|
|
223
|
+
return;
|
|
224
|
+
if (reloadPending || localWritePending || writeInFlight())
|
|
225
|
+
return;
|
|
226
|
+
if (reloadingOrgRef.current === orgIdRef.current)
|
|
227
|
+
return;
|
|
228
|
+
if (conflict.code === "TARGET_MISMATCH") {
|
|
229
|
+
// No revision to retry with: the only safe resolution is a reload.
|
|
230
|
+
void reloadWorkspace(true);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
// Deliberate, user-initiated: same patch, fresh revision.
|
|
234
|
+
perform({ ...last.body, expectedRevision: conflict.currentRevision }, last.target);
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
conflict,
|
|
238
|
+
fieldErrors,
|
|
239
|
+
serverChanged,
|
|
240
|
+
reloadPending,
|
|
241
|
+
requiresReload: serverChanged || reloadPending || conflict !== null,
|
|
242
|
+
workspaceKey: `${orgId}:${reloadKey}`,
|
|
243
|
+
submit,
|
|
244
|
+
reloadConflict: () => void reloadWorkspace(true),
|
|
245
|
+
keepMine,
|
|
246
|
+
reloadLatest: () => void reloadWorkspace(false),
|
|
247
|
+
noteOwnWrite,
|
|
248
|
+
markServerChanged: () => setServerChanged(true),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=use-brand-workspace-concurrency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-brand-workspace-concurrency.js","sourceRoot":"","sources":["../../src/brand/use-brand-workspace-concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAiD3D;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAc;IACzD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC1E,MAAM,CAAC,GAAG,KAKT,CAAC;IACF,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB;QAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IACrE,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,IAAI,OAAO,CAAC,CAAC,eAAe,KAAK,QAAQ,EAAE,CAAC;QAC5E,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC;IAC3E,CAAC;IACD,IACE,CAAC,CAAC,MAAM,KAAK,GAAG;QAChB,CAAC,CAAC,IAAI,KAAK,kBAAkB;QAC7B,CAAC,CAAC,WAAW,KAAK,IAAI;QACtB,OAAO,CAA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