@widgetic/workflows 0.2.0 → 0.2.1
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/README.md +12 -1
- package/dist/api/types.d.ts +33 -0
- package/dist/api/workflowsApi.d.ts +25 -1
- package/dist/api/workflowsApi.js +106 -0
- package/dist/components/Workflows.svelte +2 -0
- package/dist/components/WorkflowsWorkspace.svelte +3 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +1 -0
- package/dist/components/editor/ConflictBanner.svelte +78 -0
- package/dist/components/editor/ConflictBanner.svelte.d.ts +3 -0
- package/dist/components/editor/EditorBanners.svelte +9 -11
- package/dist/components/editor/PresenceBanner.svelte +126 -0
- package/dist/components/editor/PresenceBanner.svelte.d.ts +3 -0
- package/dist/components/editor/SettingsTab.svelte +4 -4
- package/dist/components/editor/WorkflowEditor.svelte +14 -1
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +2 -0
- package/dist/components/panel/VersionHistory.svelte +1 -1
- package/dist/editor/editLeaseController.d.ts +162 -0
- package/dist/editor/editLeaseController.js +459 -0
- package/dist/editor/editorState.svelte.d.ts +62 -5
- package/dist/editor/editorState.svelte.js +155 -6
- package/dist/editor/keepCopy.d.ts +41 -0
- package/dist/editor/keepCopy.js +52 -0
- package/dist/editor/listState.svelte.d.ts +2 -2
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +33 -0
- package/dist/i18n/messages.js +35 -0
- package/dist/types/index.d.ts +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,6 +108,7 @@ the screen needs, the screen scrolls inside it; it never spills over what the pa
|
|
|
108
108
|
| `workflowId` | `string \| null` | the list | The workflow that is open. The page owns it (it is part of the page's address); left out, the screen keeps track by itself. |
|
|
109
109
|
| `onOpenWorkflow` | `(workflowId: string \| null) => void` | none | The person opened a workflow, or went back to the list (`null`). |
|
|
110
110
|
| `onShowEmbedCode` | `(workflowId: string) => void` | none | Shows the embed code of a workflow. The dialog is the page's (it knows how the tag is built for its Embed SDK); without it there is no button. |
|
|
111
|
+
| `presence` | `boolean` | `false` | Tells who else is editing the workflow that is open, and keeps this screen from writing over them (below). Read when a workflow is opened. |
|
|
111
112
|
| `locale` | `string \| null` | English | A BCP 47 tag (`de`, `pt-BR`): plural rules, how numbers and dates are written. Translates nothing. |
|
|
112
113
|
| `messages` | `Readonly<Record<string, unknown>> \| null` | none | Your own words, by key. A key you leave out stays English. |
|
|
113
114
|
| `dir` | `'ltr' \| 'rtl'` | the screen around it | Which way the screen is read. You decide it; it is not worked out from `locale`. |
|
|
@@ -122,7 +123,17 @@ The `message` is English, for the page's developer. It is not a sentence to show
|
|
|
122
123
|
workflow, its draft, publish, discard, versions, stats, composition options), always as the person: the token is
|
|
123
124
|
the person's, and a call the person may not make is refused by the API. The screen holds no service key (a test fails the
|
|
124
125
|
build if any code of the package that runs in a browser reads one). A change is sent with an `Idempotency-Key`, and a draft
|
|
125
|
-
with the revision the editor was given, so a draft changed somewhere else is told, not overwritten
|
|
126
|
+
with the revision the editor was given, so a draft changed somewhere else is told, not overwritten: the person is offered
|
|
127
|
+
two ways forward, to keep what is on the screen as a copy (a new workflow, named after the original) or to load the latest
|
|
128
|
+
version, and nothing is lost by accident.
|
|
129
|
+
|
|
130
|
+
**Who else is editing.** With `presence` on, the screen also asks the API for the claim on editing the open workflow
|
|
131
|
+
(`PUT /v1/edit-leases/workflow/{id}`, renewed every 20 seconds while the tab is shown, and given up with `DELETE` when the
|
|
132
|
+
workflow is closed; `POST …/take-over` and `GET` complete it). When a teammate holds the claim, the screen only looks and
|
|
133
|
+
offers two choices: take the editing over (their editing pauses, and what they saved stays) or look only. It is a courtesy,
|
|
134
|
+
never a lock: what keeps a draft from being overwritten is the revision check above, whatever `presence` says. The API
|
|
135
|
+
names a person only to a teammate of the same organization, so a personal workspace has nothing to show and `presence`
|
|
136
|
+
changes nothing there. The page decides whether to ask for it (the Widgetic site does for an organization's workspace).
|
|
126
137
|
|
|
127
138
|
## Look and feel
|
|
128
139
|
|
package/dist/api/types.d.ts
CHANGED
|
@@ -164,5 +164,38 @@ export interface WorkflowStatsQuery {
|
|
|
164
164
|
}
|
|
165
165
|
/** The state changes a workflow goes through, one request each. */
|
|
166
166
|
export type WorkflowStateAction = 'pause' | 'resume' | 'archive' | 'unarchive';
|
|
167
|
+
/**
|
|
168
|
+
* What the API says about who is editing a workflow (an "edit claim": presence, never a lock; see
|
|
169
|
+
* `readEditLeaseAnswer`):
|
|
170
|
+
*
|
|
171
|
+
* - `held`: this tab is the one editing (its claim lasts `ttlSeconds` from now and is renewed every `heartbeatSeconds`);
|
|
172
|
+
* - `held_by_other`: somebody else is editing (`holder`), in another window of the same account or in a teammate's;
|
|
173
|
+
* - `free`: nobody is editing (only a look says that: asking to edit answers `held`);
|
|
174
|
+
* - `not_applicable`: this workspace has no presence (a personal one, or the feature is off): edit freely, say nothing;
|
|
175
|
+
* - `unavailable`: the API could not tell right now: edit freely and ask again later.
|
|
176
|
+
*/
|
|
177
|
+
export type EditLeaseOutcomeName = 'held' | 'held_by_other' | 'free' | 'not_applicable' | 'unavailable';
|
|
178
|
+
/** Whoever holds an edit claim. The API gives a name only for a teammate who is a person, never an email. */
|
|
179
|
+
export interface EditLeaseHolder {
|
|
180
|
+
id: string;
|
|
181
|
+
/** The holder's name, or `null` when the API had none to give (say "Someone"). */
|
|
182
|
+
name: string | null;
|
|
183
|
+
/** The holder is the signed-in person's own account, in another window. */
|
|
184
|
+
isYou: boolean;
|
|
185
|
+
/** When the holder began editing (an ISO date), when the API said. */
|
|
186
|
+
since: string | null;
|
|
187
|
+
}
|
|
188
|
+
export interface EditLeaseAnswer {
|
|
189
|
+
outcome: EditLeaseOutcomeName;
|
|
190
|
+
/** How long a claim lasts without a renewal, in seconds. */
|
|
191
|
+
ttlSeconds?: number;
|
|
192
|
+
/** How often to renew it, in seconds. */
|
|
193
|
+
heartbeatSeconds?: number;
|
|
194
|
+
since?: string | null;
|
|
195
|
+
/** Who holds the claim, for `held_by_other` (and for `held`: this person). */
|
|
196
|
+
holder?: EditLeaseHolder;
|
|
197
|
+
/** Who the claim was taken from, when taking over displaced somebody. */
|
|
198
|
+
tookOverFrom?: EditLeaseHolder;
|
|
199
|
+
}
|
|
167
200
|
/** The token function the host gives the screen (see `AccessTokenFunction` of the ui-sdk modules). */
|
|
168
201
|
export type AccessTokenFunction = (reason: 'initial' | 'expired', refusedToken?: string) => Promise<string> | string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IssueCode, ValidationIssue, WorkflowGraph } from '@widgetic/workflows-engine';
|
|
2
|
-
import { type AccessTokenFunction, type CompositionOption, type CompositionOptionList, type CompositionOptionsQuery, type WorkflowDetail, type WorkflowList, type WorkflowListItem, type WorkflowListQuery, type WorkflowPublishResult, type WorkflowStateAction, type WorkflowStats, type WorkflowStatsQuery, type WorkflowVersion, type WorkflowVersionDetail } from './types.js';
|
|
2
|
+
import { type AccessTokenFunction, type CompositionOption, type CompositionOptionList, type CompositionOptionsQuery, type EditLeaseAnswer, type WorkflowDetail, type WorkflowList, type WorkflowListItem, type WorkflowListQuery, type WorkflowPublishResult, type WorkflowStateAction, type WorkflowStats, type WorkflowStatsQuery, type WorkflowVersion, type WorkflowVersionDetail } from './types.js';
|
|
3
3
|
/** How long a request may take before it is given up: the reads, and the writes (a publish reads every composition). */
|
|
4
4
|
export declare const READ_TIMEOUT_MS = 15000;
|
|
5
5
|
export declare const WRITE_TIMEOUT_MS = 30000;
|
|
@@ -52,6 +52,14 @@ export interface WorkflowsApiOptions {
|
|
|
52
52
|
export interface RequestOptions {
|
|
53
53
|
signal?: AbortSignal;
|
|
54
54
|
}
|
|
55
|
+
/** Options of the call that gives an edit claim up. */
|
|
56
|
+
export interface ReleaseEditLeaseOptions extends RequestOptions {
|
|
57
|
+
/**
|
|
58
|
+
* Lets the request finish after the page is gone (`fetch` `keepalive`): for the moment a tab is closed, when the
|
|
59
|
+
* claim should end at once instead of expiring a minute later.
|
|
60
|
+
*/
|
|
61
|
+
keepalive?: boolean;
|
|
62
|
+
}
|
|
55
63
|
/** The writes that must not happen twice when an answer is lost. */
|
|
56
64
|
export interface RetryableRequestOptions extends RequestOptions {
|
|
57
65
|
/**
|
|
@@ -85,6 +93,17 @@ export interface WorkflowsApi {
|
|
|
85
93
|
changeState(workflowId: string, action: WorkflowStateAction, options?: RequestOptions): Promise<WorkflowListItem>;
|
|
86
94
|
getStats(workflowId: string, query?: WorkflowStatsQuery, options?: RequestOptions): Promise<WorkflowStats>;
|
|
87
95
|
listCompositionOptions(query?: CompositionOptionsQuery, options?: RequestOptions): Promise<CompositionOptionList>;
|
|
96
|
+
/**
|
|
97
|
+
* "This tab is editing this workflow", and the renewal of that claim. Presence, never a lock: it says who else is
|
|
98
|
+
* editing and never refuses a save. An answer that cannot be read is `unavailable`.
|
|
99
|
+
*/
|
|
100
|
+
acquireEditLease(workflowId: string, sessionId: string, options?: RequestOptions): Promise<EditLeaseAnswer>;
|
|
101
|
+
/** Takes the claim from whoever holds it (the answer says who it was taken from). */
|
|
102
|
+
takeOverEditLease(workflowId: string, sessionId: string, options?: RequestOptions): Promise<EditLeaseAnswer>;
|
|
103
|
+
/** Who is editing, without claiming anything. */
|
|
104
|
+
peekEditLease(workflowId: string, options?: RequestOptions): Promise<EditLeaseAnswer>;
|
|
105
|
+
/** Gives this tab's claim up. */
|
|
106
|
+
releaseEditLease(workflowId: string, sessionId: string, options?: ReleaseEditLeaseOptions): Promise<void>;
|
|
88
107
|
}
|
|
89
108
|
/** A key the gateway accepts as an `Idempotency-Key` (`^[A-Za-z0-9_-]{8,50}$`). */
|
|
90
109
|
export declare function makeIdempotencyKey(): string;
|
|
@@ -100,6 +119,11 @@ export declare function usableImageUrl(value: unknown): string | null;
|
|
|
100
119
|
* capability model is the API's, and an answer that left a part out is treated as "this composition cannot do that".
|
|
101
120
|
*/
|
|
102
121
|
export declare function readCompositionOption(data: unknown): CompositionOption;
|
|
122
|
+
/**
|
|
123
|
+
* What the API answered about an edit claim, checked. An answer the screen cannot read is `unavailable`: presence is a
|
|
124
|
+
* convenience, so the editor goes on as if it were not there rather than failing.
|
|
125
|
+
*/
|
|
126
|
+
export declare function readEditLeaseAnswer(data: unknown): EditLeaseAnswer;
|
|
103
127
|
/** The query string of the list: only what was asked for. */
|
|
104
128
|
export declare function buildListQueryString(query: WorkflowListQuery | undefined): string;
|
|
105
129
|
export declare function buildCompositionOptionsQueryString(query: CompositionOptionsQuery | undefined): string;
|
package/dist/api/workflowsApi.js
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
* POST /workspaces/{workspaceId}/workflows/{id}/{pause|resume|archive|unarchive}
|
|
17
17
|
* GET /workspaces/{workspaceId}/workflows/{id}/stats the counts of the Runs tab
|
|
18
18
|
* GET /workspaces/{workspaceId}/workflows/composition-options the compositions to choose from, with what each can do
|
|
19
|
+
* PUT /edit-leases/workflow/{id} "I am editing this" (body: the tab's `sessionId`)
|
|
20
|
+
* POST /edit-leases/workflow/{id}/take-over take the claim from whoever holds it
|
|
21
|
+
* GET /edit-leases/workflow/{id} who is editing, without claiming
|
|
22
|
+
* DELETE /edit-leases/workflow/{id}?sessionId= give the claim up
|
|
19
23
|
*
|
|
20
24
|
* The API never gives a refusal a sentence of ours to show: a screen reads `code` (and `details`) and says it in the person's
|
|
21
25
|
* language. What the client never does: send cookies, put a token anywhere but the `Authorization` header, or keep one.
|
|
@@ -374,6 +378,59 @@ function readCompositionOptionList(data) {
|
|
|
374
378
|
offset: readWholeNumber(data, 'offset', 'the compositions')
|
|
375
379
|
};
|
|
376
380
|
}
|
|
381
|
+
/** What the API accepts as the id of an editor tab (an edit claim's `sessionId`). */
|
|
382
|
+
const EDIT_LEASE_SESSION_ID_PATTERN = /^[A-Za-z0-9_-]{8,64}$/;
|
|
383
|
+
/** True for a number of seconds worth believing: a positive, finite number. */
|
|
384
|
+
function isSeconds(value) {
|
|
385
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0;
|
|
386
|
+
}
|
|
387
|
+
/** Whoever holds an edit claim, as the API wrote it; `undefined` when what came is no holder. */
|
|
388
|
+
function readEditLeaseHolder(value) {
|
|
389
|
+
if (!isRecord(value) || typeof value.id !== 'string' || value.id === '')
|
|
390
|
+
return undefined;
|
|
391
|
+
const name = typeof value.name === 'string' ? value.name.trim() : '';
|
|
392
|
+
return {
|
|
393
|
+
id: value.id,
|
|
394
|
+
// A name is what a person wrote, so it is cut to a length a banner can hold.
|
|
395
|
+
name: name === '' ? null : name.slice(0, 120),
|
|
396
|
+
isYou: value.isYou === true,
|
|
397
|
+
since: typeof value.since === 'string' ? value.since : null
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
const EDIT_LEASE_OUTCOMES = [
|
|
401
|
+
'held',
|
|
402
|
+
'held_by_other',
|
|
403
|
+
'free',
|
|
404
|
+
'not_applicable',
|
|
405
|
+
'unavailable'
|
|
406
|
+
];
|
|
407
|
+
/**
|
|
408
|
+
* What the API answered about an edit claim, checked. An answer the screen cannot read is `unavailable`: presence is a
|
|
409
|
+
* convenience, so the editor goes on as if it were not there rather than failing.
|
|
410
|
+
*/
|
|
411
|
+
export function readEditLeaseAnswer(data) {
|
|
412
|
+
if (!isRecord(data))
|
|
413
|
+
return { outcome: 'unavailable' };
|
|
414
|
+
const outcome = EDIT_LEASE_OUTCOMES.find((name) => name === data.outcome);
|
|
415
|
+
if (!outcome)
|
|
416
|
+
return { outcome: 'unavailable' };
|
|
417
|
+
const answer = { outcome };
|
|
418
|
+
if (isSeconds(data.ttlSeconds))
|
|
419
|
+
answer.ttlSeconds = data.ttlSeconds;
|
|
420
|
+
if (isSeconds(data.heartbeatSeconds))
|
|
421
|
+
answer.heartbeatSeconds = data.heartbeatSeconds;
|
|
422
|
+
if (typeof data.since === 'string')
|
|
423
|
+
answer.since = data.since;
|
|
424
|
+
else if (data.since === null)
|
|
425
|
+
answer.since = null;
|
|
426
|
+
const holder = readEditLeaseHolder(data.holder);
|
|
427
|
+
if (holder)
|
|
428
|
+
answer.holder = holder;
|
|
429
|
+
const tookOverFrom = readEditLeaseHolder(data.tookOverFrom);
|
|
430
|
+
if (tookOverFrom)
|
|
431
|
+
answer.tookOverFrom = tookOverFrom;
|
|
432
|
+
return answer;
|
|
433
|
+
}
|
|
377
434
|
/** The error code, sentence and details of an API error answer, when it has them. */
|
|
378
435
|
function describeFailureBody(body) {
|
|
379
436
|
if (!isRecord(body))
|
|
@@ -519,6 +576,8 @@ export function createWorkflowsApi(options) {
|
|
|
519
576
|
// The token is the credential; the gateway never allows cookies on these routes.
|
|
520
577
|
credentials: 'omit',
|
|
521
578
|
mode: 'cors',
|
|
579
|
+
...(details.noStore ? { cache: 'no-store' } : {}),
|
|
580
|
+
...(details.keepalive ? { keepalive: true } : {}),
|
|
522
581
|
signal: attempt.signal
|
|
523
582
|
});
|
|
524
583
|
};
|
|
@@ -552,6 +611,20 @@ export function createWorkflowsApi(options) {
|
|
|
552
611
|
}
|
|
553
612
|
}
|
|
554
613
|
const pathOfWorkflow = (workflowId) => `${workspaceBase}/${encodeURIComponent(workflowId)}`;
|
|
614
|
+
/** The address of a workflow's edit claim, with `suffix` after it (the claim routes are not under the workspace). */
|
|
615
|
+
function leasePath(workflowId, suffix = '') {
|
|
616
|
+
if (typeof workflowId !== 'string' || workflowId.trim() === '') {
|
|
617
|
+
throw new TypeError('A workflow id is needed');
|
|
618
|
+
}
|
|
619
|
+
return `/edit-leases/workflow/${encodeURIComponent(workflowId)}${suffix}`;
|
|
620
|
+
}
|
|
621
|
+
/** The tab's own id, which the API holds to a short plain alphabet; a bad one is a bug of the caller, never sent. */
|
|
622
|
+
function checkedSessionId(sessionId) {
|
|
623
|
+
if (typeof sessionId !== 'string' || !EDIT_LEASE_SESSION_ID_PATTERN.test(sessionId)) {
|
|
624
|
+
throw new TypeError('A session id is 8 to 64 letters, digits, dashes or underscores');
|
|
625
|
+
}
|
|
626
|
+
return sessionId;
|
|
627
|
+
}
|
|
555
628
|
return {
|
|
556
629
|
async listWorkflows(query, requestOptions = {}) {
|
|
557
630
|
return readWorkflowList(await request('GET', `${workspaceBase}${buildListQueryString(query)}`, {
|
|
@@ -652,6 +725,39 @@ export function createWorkflowsApi(options) {
|
|
|
652
725
|
signal: requestOptions.signal,
|
|
653
726
|
timeoutMs: readTimeoutMs
|
|
654
727
|
}));
|
|
728
|
+
},
|
|
729
|
+
// The edit claim calls wait no longer than a read does: a claim is renewed every few seconds, and a renewal that
|
|
730
|
+
// takes longer than that has told what it will tell.
|
|
731
|
+
async acquireEditLease(workflowId, sessionId, requestOptions = {}) {
|
|
732
|
+
return readEditLeaseAnswer(await request('PUT', leasePath(workflowId), {
|
|
733
|
+
body: { sessionId: checkedSessionId(sessionId) },
|
|
734
|
+
signal: requestOptions.signal,
|
|
735
|
+
timeoutMs: readTimeoutMs,
|
|
736
|
+
noStore: true
|
|
737
|
+
}));
|
|
738
|
+
},
|
|
739
|
+
async takeOverEditLease(workflowId, sessionId, requestOptions = {}) {
|
|
740
|
+
return readEditLeaseAnswer(await request('POST', leasePath(workflowId, '/take-over'), {
|
|
741
|
+
body: { sessionId: checkedSessionId(sessionId) },
|
|
742
|
+
signal: requestOptions.signal,
|
|
743
|
+
timeoutMs: readTimeoutMs,
|
|
744
|
+
noStore: true
|
|
745
|
+
}));
|
|
746
|
+
},
|
|
747
|
+
async peekEditLease(workflowId, requestOptions = {}) {
|
|
748
|
+
return readEditLeaseAnswer(await request('GET', leasePath(workflowId), {
|
|
749
|
+
signal: requestOptions.signal,
|
|
750
|
+
timeoutMs: readTimeoutMs,
|
|
751
|
+
noStore: true
|
|
752
|
+
}));
|
|
753
|
+
},
|
|
754
|
+
async releaseEditLease(workflowId, sessionId, releaseOptions = {}) {
|
|
755
|
+
await request('DELETE', leasePath(workflowId, `?sessionId=${encodeURIComponent(checkedSessionId(sessionId))}`), {
|
|
756
|
+
signal: releaseOptions.signal,
|
|
757
|
+
timeoutMs: readTimeoutMs,
|
|
758
|
+
noStore: true,
|
|
759
|
+
keepalive: releaseOptions.keepalive
|
|
760
|
+
});
|
|
655
761
|
}
|
|
656
762
|
};
|
|
657
763
|
}
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
workflowId = null,
|
|
36
36
|
onOpenWorkflow,
|
|
37
37
|
onShowEmbedCode,
|
|
38
|
+
presence = false,
|
|
38
39
|
locale = null,
|
|
39
40
|
messages: languageMessages = null,
|
|
40
41
|
dir = undefined,
|
|
@@ -100,6 +101,7 @@
|
|
|
100
101
|
{workflowId}
|
|
101
102
|
{onOpenWorkflow}
|
|
102
103
|
{onShowEmbedCode}
|
|
104
|
+
{presence}
|
|
103
105
|
onError={reportToPage}
|
|
104
106
|
/>
|
|
105
107
|
{/key}
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
workflowId?: WorkflowsProps['workflowId'];
|
|
26
26
|
onOpenWorkflow?: WorkflowsProps['onOpenWorkflow'];
|
|
27
27
|
onShowEmbedCode?: WorkflowsProps['onShowEmbedCode'];
|
|
28
|
+
presence?: WorkflowsProps['presence'];
|
|
28
29
|
onError: (error: WorkflowsError) => void;
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
workflowId,
|
|
37
38
|
onOpenWorkflow,
|
|
38
39
|
onShowEmbedCode,
|
|
40
|
+
presence = false,
|
|
39
41
|
onError
|
|
40
42
|
}: Props = $props();
|
|
41
43
|
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
onopenworkflow={(id) => open(id)}
|
|
78
80
|
onerror={onError}
|
|
79
81
|
onshowembedcode={onShowEmbedCode}
|
|
82
|
+
{presence}
|
|
80
83
|
/>
|
|
81
84
|
{/key}
|
|
82
85
|
</div>
|
|
@@ -7,6 +7,7 @@ interface Props {
|
|
|
7
7
|
workflowId?: WorkflowsProps['workflowId'];
|
|
8
8
|
onOpenWorkflow?: WorkflowsProps['onOpenWorkflow'];
|
|
9
9
|
onShowEmbedCode?: WorkflowsProps['onShowEmbedCode'];
|
|
10
|
+
presence?: WorkflowsProps['presence'];
|
|
10
11
|
onError: (error: WorkflowsError) => void;
|
|
11
12
|
}
|
|
12
13
|
declare const WorkflowsWorkspace: import("svelte").Component<Props, {}, "">;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The line above the canvas for a draft that somebody else saved first: what this person changed last was not saved, because
|
|
3
|
+
saving it would have written over the other person's work. Two ways forward, and neither loses anything by accident.
|
|
4
|
+
|
|
5
|
+
- Keep what is on this screen as a new workflow (a copy). Then the latest version can be loaded at no cost, or the copy
|
|
6
|
+
opened to carry on in it. The line says where the changes are kept.
|
|
7
|
+
- Load the latest version, which replaces what is on this screen. While the changes are kept nowhere the person is asked
|
|
8
|
+
once; after a copy was kept there is nothing to lose and nothing to ask.
|
|
9
|
+
|
|
10
|
+
The screen only shows and asks; making the copy and loading are the editor's (`keepCopyOfChanges`, `reloadDraft`).
|
|
11
|
+
-->
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
14
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
15
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
16
|
+
import ConfirmDialog from '../ui/ConfirmDialog.svelte';
|
|
17
|
+
import Notice from '../ui/Notice.svelte';
|
|
18
|
+
|
|
19
|
+
const editor = useEditorState();
|
|
20
|
+
const { t } = useWorkflowsLanguage();
|
|
21
|
+
|
|
22
|
+
let isAskingToLoad = $state(false);
|
|
23
|
+
|
|
24
|
+
const keptCopy = $derived(editor.keptCopy);
|
|
25
|
+
const isKeepingCopy = $derived(editor.busy === 'keepingCopy');
|
|
26
|
+
|
|
27
|
+
/** Keeps a copy. The copy's name is the person's words around the workflow's name; the editor cuts it to fit. */
|
|
28
|
+
function keepCopy(): void {
|
|
29
|
+
void editor.keepCopyOfChanges((name) => $t('workflows.conflict.copyName', { name }));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Loading replaces what is on the screen: while that is kept nowhere, the person is asked first. */
|
|
33
|
+
function requestLoadLatest(): void {
|
|
34
|
+
if (keptCopy) void editor.reloadDraft();
|
|
35
|
+
else isAskingToLoad = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function loadLatest(): void {
|
|
39
|
+
isAskingToLoad = false;
|
|
40
|
+
void editor.reloadDraft();
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<!-- Once the copy exists the worry is over, so the line stops being an alarm. -->
|
|
45
|
+
<Notice tone={keptCopy ? 'info' : 'problem'}>
|
|
46
|
+
{#if keptCopy}
|
|
47
|
+
{$t('workflows.conflict.copyKept', { name: keptCopy.name })}
|
|
48
|
+
{:else}
|
|
49
|
+
{$t('workflows.banner.conflict')}
|
|
50
|
+
{/if}
|
|
51
|
+
{#snippet action()}
|
|
52
|
+
{#if keptCopy}
|
|
53
|
+
<ActionButton
|
|
54
|
+
size="small"
|
|
55
|
+
disabled={editor.busy !== null}
|
|
56
|
+
onclick={() => editor.openKeptCopy()}>{$t('workflows.conflict.openCopy')}</ActionButton
|
|
57
|
+
>
|
|
58
|
+
{:else}
|
|
59
|
+
<ActionButton size="small" disabled={editor.busy !== null} onclick={keepCopy}>
|
|
60
|
+
{isKeepingCopy ? $t('workflows.conflict.keepingCopy') : $t('workflows.conflict.keepCopy')}
|
|
61
|
+
</ActionButton>
|
|
62
|
+
{/if}
|
|
63
|
+
<ActionButton size="small" disabled={editor.busy !== null} onclick={requestLoadLatest}
|
|
64
|
+
>{$t('workflows.banner.reload')}</ActionButton
|
|
65
|
+
>
|
|
66
|
+
{/snippet}
|
|
67
|
+
</Notice>
|
|
68
|
+
|
|
69
|
+
{#if isAskingToLoad}
|
|
70
|
+
<ConfirmDialog
|
|
71
|
+
title={$t('workflows.conflict.loadTitle')}
|
|
72
|
+
message={$t('workflows.conflict.loadMessage')}
|
|
73
|
+
confirmLabel={$t('workflows.banner.reload')}
|
|
74
|
+
tone="danger"
|
|
75
|
+
onconfirm={loadLatest}
|
|
76
|
+
oncancel={() => (isAskingToLoad = false)}
|
|
77
|
+
/>
|
|
78
|
+
{/if}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
import ActionButton from '../ui/ActionButton.svelte';
|
|
12
12
|
import ConfirmDialog from '../ui/ConfirmDialog.svelte';
|
|
13
13
|
import Notice from '../ui/Notice.svelte';
|
|
14
|
+
import ConflictBanner from './ConflictBanner.svelte';
|
|
15
|
+
import PresenceBanner from './PresenceBanner.svelte';
|
|
14
16
|
|
|
15
17
|
interface Props {
|
|
16
18
|
/** The person pressed "Publish changes". */
|
|
@@ -37,6 +39,9 @@
|
|
|
37
39
|
</script>
|
|
38
40
|
|
|
39
41
|
<div class="flex flex-col gap-2">
|
|
42
|
+
<!-- First: a teammate who is editing decides what the rest of the screen lets the person do. -->
|
|
43
|
+
<PresenceBanner />
|
|
44
|
+
|
|
40
45
|
{#if editor.notice}
|
|
41
46
|
{@const notice = editor.notice}
|
|
42
47
|
<Notice tone={notice.tone}>
|
|
@@ -50,14 +55,7 @@
|
|
|
50
55
|
{/if}
|
|
51
56
|
|
|
52
57
|
{#if editor.saveState === 'conflict'}
|
|
53
|
-
<
|
|
54
|
-
{$t('workflows.banner.conflict')}
|
|
55
|
-
{#snippet action()}
|
|
56
|
-
<ActionButton size="small" onclick={() => void editor.reloadDraft()}
|
|
57
|
-
>{$t('workflows.banner.reload')}</ActionButton
|
|
58
|
-
>
|
|
59
|
-
{/snippet}
|
|
60
|
-
</Notice>
|
|
58
|
+
<ConflictBanner />
|
|
61
59
|
{:else if editor.saveState === 'failed'}
|
|
62
60
|
<Notice tone="problem">
|
|
63
61
|
{$t(editor.saveFailure ?? 'workflows.error.generic')}
|
|
@@ -84,7 +82,7 @@
|
|
|
84
82
|
{#snippet action()}
|
|
85
83
|
<ActionButton
|
|
86
84
|
size="small"
|
|
87
|
-
disabled={editor.
|
|
85
|
+
disabled={!editor.canChangeWorkflow}
|
|
88
86
|
onclick={() => void editor.changeState('unarchive')}
|
|
89
87
|
>{$t('workflows.settings.unarchive')}</ActionButton
|
|
90
88
|
>
|
|
@@ -96,7 +94,7 @@
|
|
|
96
94
|
{#snippet action()}
|
|
97
95
|
<ActionButton
|
|
98
96
|
size="small"
|
|
99
|
-
disabled={editor.
|
|
97
|
+
disabled={!editor.canChangeWorkflow}
|
|
100
98
|
onclick={() => void editor.changeState('resume')}
|
|
101
99
|
>{$t('workflows.settings.resume')}</ActionButton
|
|
102
100
|
>
|
|
@@ -110,7 +108,7 @@
|
|
|
110
108
|
{#snippet action()}
|
|
111
109
|
<ActionButton
|
|
112
110
|
size="small"
|
|
113
|
-
disabled={editor.busy !== null}
|
|
111
|
+
disabled={editor.isReadOnly || editor.busy !== null}
|
|
114
112
|
onclick={() => (isAskingToDiscard = true)}>{$t('workflows.banner.discard')}</ActionButton
|
|
115
113
|
>
|
|
116
114
|
<ActionButton
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
What a person is told when a teammate is editing the workflow they opened, and what they can do about it.
|
|
3
|
+
|
|
4
|
+
- `blocked`: a choice is waiting. Take the editing over (the teammate's editing pauses, and what they saved stays), or
|
|
5
|
+
only look. It says who, in the person's own words: a named teammate, "you" in another window, or "someone". A person
|
|
6
|
+
whose own editing was taken is told so, which is not what a person who arrived to find it held is told.
|
|
7
|
+
- `readOnly`: the person chose to look. One line, with the way back: take over, or start editing once nobody is.
|
|
8
|
+
- anything else: nothing at all.
|
|
9
|
+
|
|
10
|
+
It shows what `editor.presence` says and reports the person's choices to the editor, which decides what they do (the
|
|
11
|
+
claim on editing, what is still allowed while it is held by another). Every word is in the catalog (`presence.*`).
|
|
12
|
+
-->
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import { useEditorState } from '../../editor/editorState.svelte.js';
|
|
15
|
+
import { useWorkflowsLanguage } from '../../i18n/language.js';
|
|
16
|
+
import ActionButton from '../ui/ActionButton.svelte';
|
|
17
|
+
|
|
18
|
+
const editor = useEditorState();
|
|
19
|
+
const { t } = useWorkflowsLanguage();
|
|
20
|
+
|
|
21
|
+
const presence = $derived(editor.presence);
|
|
22
|
+
|
|
23
|
+
// Who holds the editing, as the person is to read it: their own other window ("you"), a named teammate, or nobody named.
|
|
24
|
+
const holderIsYou = $derived(presence.holder?.isYou === true);
|
|
25
|
+
const holderName = $derived(presence.holder?.name ?? null);
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
{#if presence.phase === 'blocked'}
|
|
29
|
+
<!-- A choice is waiting: the screen only looks until the person makes it. -->
|
|
30
|
+
<div
|
|
31
|
+
role="alert"
|
|
32
|
+
data-workflows-presence="blocked"
|
|
33
|
+
class="flex flex-wrap items-start justify-between gap-x-4 gap-y-3 rounded-medium border border-grey2 bg-white px-3 py-2 text-start text-sm text-ink-primary"
|
|
34
|
+
>
|
|
35
|
+
<div class="flex min-w-0 flex-1 basis-60 flex-col gap-1">
|
|
36
|
+
<p class="font-medium break-words">
|
|
37
|
+
<!-- The heading: a claim that was this tab's and was taken says so; a tab that arrived to find it held does not. -->
|
|
38
|
+
{#if presence.lostIt}
|
|
39
|
+
{#if holderIsYou}
|
|
40
|
+
{$t('workflows.presence.lostTitleYou')}
|
|
41
|
+
{:else if holderName}
|
|
42
|
+
{$t('workflows.presence.lostTitleNamed', { name: holderName })}
|
|
43
|
+
{:else}
|
|
44
|
+
{$t('workflows.presence.lostTitle')}
|
|
45
|
+
{/if}
|
|
46
|
+
{:else if holderIsYou}
|
|
47
|
+
{$t('workflows.presence.blockedTitleYou')}
|
|
48
|
+
{:else if holderName}
|
|
49
|
+
{$t('workflows.presence.blockedTitleNamed', { name: holderName })}
|
|
50
|
+
{:else}
|
|
51
|
+
{$t('workflows.presence.blockedTitle')}
|
|
52
|
+
{/if}
|
|
53
|
+
</p>
|
|
54
|
+
<p class="text-xs text-ink-muted">
|
|
55
|
+
{presence.lostIt ? $t('workflows.presence.lostBody') : $t('workflows.presence.blockedBody')}
|
|
56
|
+
</p>
|
|
57
|
+
{#if presence.actionFailed}
|
|
58
|
+
<p class="text-xs text-error">{$t('workflows.presence.actionFailed')}</p>
|
|
59
|
+
{/if}
|
|
60
|
+
{#if presence.working}
|
|
61
|
+
<p class="text-xs text-ink-muted" role="status">{$t('workflows.presence.working')}</p>
|
|
62
|
+
{/if}
|
|
63
|
+
</div>
|
|
64
|
+
<div class="flex flex-wrap items-start gap-3">
|
|
65
|
+
<div class="flex max-w-48 flex-col items-start gap-1">
|
|
66
|
+
<ActionButton
|
|
67
|
+
variant="primary"
|
|
68
|
+
size="small"
|
|
69
|
+
disabled={presence.working}
|
|
70
|
+
onclick={() => editor.takeOverEditing()}
|
|
71
|
+
>
|
|
72
|
+
{$t('workflows.presence.takeOver')}
|
|
73
|
+
</ActionButton>
|
|
74
|
+
<span class="text-xs text-ink-muted">{$t('workflows.presence.takeOverHint')}</span>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="flex max-w-48 flex-col items-start gap-1">
|
|
77
|
+
<ActionButton size="small" disabled={presence.working} onclick={() => editor.lookOnly()}>
|
|
78
|
+
{$t('workflows.presence.lookOnly')}
|
|
79
|
+
</ActionButton>
|
|
80
|
+
<span class="text-xs text-ink-muted">{$t('workflows.presence.lookOnlyHint')}</span>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
{:else if presence.phase === 'readOnly'}
|
|
85
|
+
<div
|
|
86
|
+
role="status"
|
|
87
|
+
data-workflows-presence="readOnly"
|
|
88
|
+
class="flex flex-wrap items-center gap-x-3 gap-y-2 rounded-medium border border-grey2 bg-white px-3 py-2 text-start text-sm text-ink-primary"
|
|
89
|
+
>
|
|
90
|
+
<span class="min-w-0 flex-1 basis-60 break-words">
|
|
91
|
+
{#if presence.nobodyIsEditing}
|
|
92
|
+
{$t('workflows.presence.readOnlyFree')}
|
|
93
|
+
{:else if holderIsYou}
|
|
94
|
+
{$t('workflows.presence.readOnlyYou')}
|
|
95
|
+
{:else if holderName}
|
|
96
|
+
{$t('workflows.presence.readOnlyNamed', { name: holderName })}
|
|
97
|
+
{:else}
|
|
98
|
+
{$t('workflows.presence.readOnly')}
|
|
99
|
+
{/if}
|
|
100
|
+
</span>
|
|
101
|
+
{#if presence.actionFailed}
|
|
102
|
+
<span class="text-xs text-error">{$t('workflows.presence.actionFailed')}</span>
|
|
103
|
+
{/if}
|
|
104
|
+
{#if presence.working}
|
|
105
|
+
<span class="text-xs text-ink-muted">{$t('workflows.presence.working')}</span>
|
|
106
|
+
{/if}
|
|
107
|
+
{#if presence.nobodyIsEditing}
|
|
108
|
+
<ActionButton
|
|
109
|
+
variant="primary"
|
|
110
|
+
size="small"
|
|
111
|
+
disabled={presence.working}
|
|
112
|
+
onclick={() => editor.startEditing()}
|
|
113
|
+
>
|
|
114
|
+
{$t('workflows.presence.startEditing')}
|
|
115
|
+
</ActionButton>
|
|
116
|
+
{:else}
|
|
117
|
+
<ActionButton
|
|
118
|
+
size="small"
|
|
119
|
+
disabled={presence.working}
|
|
120
|
+
onclick={() => editor.takeOverEditing()}
|
|
121
|
+
>
|
|
122
|
+
{$t('workflows.presence.takeOver')}
|
|
123
|
+
</ActionButton>
|
|
124
|
+
{/if}
|
|
125
|
+
</div>
|
|
126
|
+
{/if}
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
<ActionButton
|
|
89
89
|
size="small"
|
|
90
90
|
class="self-start"
|
|
91
|
-
disabled={editor.
|
|
91
|
+
disabled={!editor.canChangeWorkflow}
|
|
92
92
|
onclick={() => void editor.changeState(editor.status === 'paused' ? 'resume' : 'pause')}
|
|
93
93
|
>
|
|
94
94
|
{editor.status === 'paused'
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
<ActionButton
|
|
109
109
|
size="small"
|
|
110
110
|
class="self-start"
|
|
111
|
-
disabled={editor.
|
|
111
|
+
disabled={!editor.canChangeWorkflow}
|
|
112
112
|
onclick={() => void editor.changeState('unarchive')}
|
|
113
113
|
>
|
|
114
114
|
{$t('workflows.settings.unarchive')}
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
<ActionButton
|
|
119
119
|
size="small"
|
|
120
120
|
class="self-start"
|
|
121
|
-
disabled={editor.
|
|
121
|
+
disabled={!editor.canChangeWorkflow}
|
|
122
122
|
onclick={() => (asking = 'archive')}
|
|
123
123
|
>
|
|
124
124
|
{$t('workflows.settings.archive')}
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
variant="danger"
|
|
146
146
|
size="small"
|
|
147
147
|
class="self-start"
|
|
148
|
-
disabled={editor.
|
|
148
|
+
disabled={!editor.canChangeWorkflow || !canDelete}
|
|
149
149
|
onclick={() => (asking = 'delete')}
|
|
150
150
|
>
|
|
151
151
|
<Icon name="trash" />
|
|
@@ -35,9 +35,18 @@
|
|
|
35
35
|
onerror: (error: WorkflowsError) => void;
|
|
36
36
|
/** Shows the embed code of the workflow; the page that hosts the screen decides what that looks like. */
|
|
37
37
|
onshowembedcode?: (workflowId: string) => void;
|
|
38
|
+
/** Tells who else is editing, and keeps the screen from writing over them. Read when the workflow is opened. */
|
|
39
|
+
presence?: boolean;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
let {
|
|
42
|
+
let {
|
|
43
|
+
workflowId,
|
|
44
|
+
onback,
|
|
45
|
+
onopenworkflow,
|
|
46
|
+
onerror,
|
|
47
|
+
onshowembedcode,
|
|
48
|
+
presence = false
|
|
49
|
+
}: Props = $props();
|
|
41
50
|
|
|
42
51
|
const api = useWorkflowsApi();
|
|
43
52
|
const { t } = useWorkflowsLanguage();
|
|
@@ -47,6 +56,8 @@
|
|
|
47
56
|
const editor = new WorkflowEditorState({
|
|
48
57
|
api,
|
|
49
58
|
workflowId: untrack(() => workflowId),
|
|
59
|
+
// Read once, like the workflow: presence belongs to this opening of it.
|
|
60
|
+
presence: untrack(() => presence),
|
|
50
61
|
reportError: (error) => onerror(error),
|
|
51
62
|
leave: () => onback(),
|
|
52
63
|
openWorkflow: (openedId) => onopenworkflow(openedId)
|
|
@@ -86,6 +97,8 @@
|
|
|
86
97
|
|
|
87
98
|
onMount(() => {
|
|
88
99
|
void editor.load();
|
|
100
|
+
// Who else is editing is asked alongside the load (it needs only the workflow's id); nothing happens without `presence`.
|
|
101
|
+
editor.startPresence();
|
|
89
102
|
|
|
90
103
|
// A finger cannot draw a line between two small points: on a touch screen the canvas only shows (the panel edits).
|
|
91
104
|
const touchQuery = window.matchMedia('(pointer: coarse)');
|