@widgetic/editor 4.1.10 → 4.1.12
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/components/WidgetPreview.svelte +1 -1
- package/dist/components/editors/CompositionEditorApp.svelte +229 -2
- package/dist/components/editors/CompositionEditorApp.svelte.d.ts +27 -2
- package/dist/components/editors/EditLeaseNotice.svelte +150 -0
- package/dist/components/editors/EditLeaseNotice.svelte.d.ts +25 -0
- package/dist/composition/compositionApi.d.ts +80 -1
- package/dist/composition/compositionApi.js +132 -7
- package/dist/composition/compositionEditorController.d.ts +106 -6
- package/dist/composition/compositionEditorController.js +211 -27
- package/dist/composition/compositionHelpers.d.ts +10 -0
- package/dist/composition/compositionHelpers.js +23 -0
- package/dist/composition/editLeaseController.d.ts +157 -0
- package/dist/composition/editLeaseController.js +441 -0
- package/dist/i18n/language.d.ts +28 -0
- package/dist/i18n/messages.d.ts +56 -0
- package/dist/i18n/messages.js +58 -0
- package/dist/i18n/translate.d.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/package.json +1 -1
|
@@ -1156,7 +1156,7 @@
|
|
|
1156
1156
|
width: 28px;
|
|
1157
1157
|
height: 8px;
|
|
1158
1158
|
left: 50%;
|
|
1159
|
-
margin-left: -14px;
|
|
1159
|
+
margin-left: -14px; /* rtl-ok: centres the handle on the middle of its edge (left: 50% and half its width), which is the same in both directions */
|
|
1160
1160
|
}
|
|
1161
1161
|
.preview-resize-handle-n { top: -5px; cursor: ns-resize; } /* rtl-ok: top edge, above the top bar */
|
|
1162
1162
|
.preview-resize-handle-s { bottom: -5px; cursor: ns-resize; }
|
|
@@ -14,10 +14,26 @@
|
|
|
14
14
|
* error { during, failure, fatal } during is 'load', 'schemas' or 'save'
|
|
15
15
|
* deviceView { deviceView } the preview is looked at as 'desktop' or 'mobile' now (a button of the
|
|
16
16
|
* preview, a size the user gave it, or `setDeviceView`)
|
|
17
|
+
* conflict { conflict } a save was refused because somebody else saved the composition after it was
|
|
18
|
+
* loaded. Nothing is lost and nothing more is sent: the editor asks the person
|
|
19
|
+
* which version stays (a card of its own), and the page may show its own
|
|
20
|
+
* controls with `keepMyChanges` and `loadLatestVersion`
|
|
21
|
+
* conflictResolved { resolution } the person chose: 'keepMine' (their edits are saved on top of the newer
|
|
22
|
+
* version; `saved`, `conflict` or `error` tell how that went) or 'loadLatest'
|
|
23
|
+
* (their edits were dropped and the newer version is on the screen)
|
|
24
|
+
* presence { phase, holder, editsBlocked } (only with the `presence` prop) who is editing this composition:
|
|
25
|
+
* `phase` is 'off' (nothing to show), 'editing' (this tab holds the editing),
|
|
26
|
+
* 'blocked' (a teammate holds it: a card asks the person to take it over or only look)
|
|
27
|
+
* or 'readOnly' (the person chose to look). While `editsBlocked` the editor takes no new
|
|
28
|
+
* edit, and a page with screens of its own that save the composition should keep them
|
|
29
|
+
* still too. It is presence, never a lock: no save is refused because of it
|
|
17
30
|
*
|
|
18
31
|
* A page with controls of its own for what the editor shows can use `setDeviceView` (the same toggle as the
|
|
19
32
|
* preview's buttons) and, when it saved the composition's embed settings itself, `adoptEmbedSettings`.
|
|
20
33
|
*
|
|
34
|
+
* A save sends only what changed (the settings and items, or the size of the preview) and never the name: this
|
|
35
|
+
* editor cannot rename, and a name it sent back could undo a rename made in the meantime.
|
|
36
|
+
*
|
|
21
37
|
* Closing it: `await flush()` first, then remove the component. Removing it cancels whatever is on its way,
|
|
22
38
|
* and edits that were not saved are lost.
|
|
23
39
|
*
|
|
@@ -33,15 +49,28 @@
|
|
|
33
49
|
import type { PartnerPickFileFn } from '../../pickFileContext.js';
|
|
34
50
|
import type { StoreFileUrlFn } from '../../fileStorageUrlContext.js';
|
|
35
51
|
import PropsEditor from './PropsEditor.svelte';
|
|
52
|
+
import EditLeaseNotice from './EditLeaseNotice.svelte';
|
|
36
53
|
import WidgetPreview from '../WidgetPreview.svelte';
|
|
37
54
|
import { setGoogleFontsApiKey } from '../../config';
|
|
38
55
|
import FontManager from '../../utils/FontManager';
|
|
39
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
createCompositionApi,
|
|
58
|
+
type EditLeaseHolder,
|
|
59
|
+
type TokenReason
|
|
60
|
+
} from '../../composition/compositionApi.js';
|
|
61
|
+
import {
|
|
62
|
+
EditLeaseController,
|
|
63
|
+
NO_PRESENCE,
|
|
64
|
+
type PresencePhase,
|
|
65
|
+
type PresenceState
|
|
66
|
+
} from '../../composition/editLeaseController.js';
|
|
40
67
|
import {
|
|
41
68
|
CompositionEditorController,
|
|
42
69
|
failureMessage,
|
|
43
70
|
type CompositionEditorEvent,
|
|
44
71
|
type CompositionEditorState,
|
|
72
|
+
type ConflictResolution,
|
|
73
|
+
type EditorConflict,
|
|
45
74
|
type EditorFailure,
|
|
46
75
|
type PreviewMessage,
|
|
47
76
|
type PropertyChange
|
|
@@ -53,6 +82,9 @@
|
|
|
53
82
|
saved: { composition: Record<string, unknown>; savedAt: number };
|
|
54
83
|
error: { during: 'load' | 'schemas' | 'save'; failure: EditorFailure; fatal: boolean };
|
|
55
84
|
deviceView: { deviceView: 'desktop' | 'mobile' };
|
|
85
|
+
conflict: { conflict: EditorConflict };
|
|
86
|
+
conflictResolved: { resolution: ConflictResolution };
|
|
87
|
+
presence: { phase: PresencePhase; holder: EditLeaseHolder | null; editsBlocked: boolean };
|
|
56
88
|
}>();
|
|
57
89
|
|
|
58
90
|
let className = '';
|
|
@@ -85,6 +117,14 @@
|
|
|
85
117
|
* height saved with the composition.
|
|
86
118
|
*/
|
|
87
119
|
export let lockPreviewSize = false;
|
|
120
|
+
/**
|
|
121
|
+
* When true, the editor tells the API that this tab is editing the composition and shows who else is: a card asks
|
|
122
|
+
* before a teammate's editing is overwritten (take it over, or only look). It is for a page that signs the person in
|
|
123
|
+
* as themselves (the Widgetic site); the API refuses these requests to an editor session or a managed user's token, and
|
|
124
|
+
* the editor then shows nothing, so a partner's page leaves it off. Presence is advice, never a lock: it can only pause
|
|
125
|
+
* new edits in this tab, and no save is ever refused because of it. Read once, when the editor starts.
|
|
126
|
+
*/
|
|
127
|
+
export let presence = false;
|
|
88
128
|
/** The key the font pickers list Google Fonts with. Without one only the fonts that need no key are listed. */
|
|
89
129
|
export let googleFontsApiKey = '';
|
|
90
130
|
/** Wait this long after the last change before saving by itself; `0` turns saving by itself off. Read once, when the editor starts. */
|
|
@@ -187,9 +227,72 @@
|
|
|
187
227
|
case 'error':
|
|
188
228
|
dispatch('error', { during: event.during, failure: event.failure, fatal: event.fatal });
|
|
189
229
|
break;
|
|
230
|
+
case 'conflict':
|
|
231
|
+
dispatch('conflict', { conflict: event.conflict });
|
|
232
|
+
break;
|
|
233
|
+
case 'conflictResolved':
|
|
234
|
+
dispatch('conflictResolved', { resolution: event.resolution });
|
|
235
|
+
break;
|
|
190
236
|
}
|
|
191
237
|
});
|
|
192
238
|
|
|
239
|
+
// --- who else is editing ----------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
// Only for a page that asks for it (`presence`). It starts once the editor is on the screen (`onMount`): a server renders
|
|
242
|
+
// nothing of it. It can only pause NEW edits in this tab (`setEditsBlocked`); it never fails or holds back a save.
|
|
243
|
+
let presenceState: PresenceState = NO_PRESENCE;
|
|
244
|
+
let leaseController: EditLeaseController | null = null;
|
|
245
|
+
let stopWatchingPresence: (() => void) | null = null;
|
|
246
|
+
|
|
247
|
+
/** What a page needs to know about presence, as one string: it is told when this changes, not on every renewal. */
|
|
248
|
+
function presenceKey(next: PresenceState): string {
|
|
249
|
+
return `${next.phase}|${next.holder?.id ?? ''}|${next.editsBlocked}`;
|
|
250
|
+
}
|
|
251
|
+
// The state the page was last told about, so it hears of a change once, whoever made it.
|
|
252
|
+
let announcedPresence = presenceKey(NO_PRESENCE);
|
|
253
|
+
|
|
254
|
+
function startPresence() {
|
|
255
|
+
if (!presence || leaseController) return;
|
|
256
|
+
try {
|
|
257
|
+
const lease = new EditLeaseController({
|
|
258
|
+
port: {
|
|
259
|
+
acquire: (sessionId, options) => api.acquireEditLease(compositionId, sessionId, options),
|
|
260
|
+
takeOver: (sessionId, options) => api.takeOverEditLease(compositionId, sessionId, options),
|
|
261
|
+
peek: (options) => api.peekEditLease(compositionId, options),
|
|
262
|
+
release: (sessionId, options) => api.releaseEditLease(compositionId, sessionId, options)
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
leaseController = lease;
|
|
266
|
+
stopWatchingPresence = lease.subscribe((next) => {
|
|
267
|
+
presenceState = next;
|
|
268
|
+
const key = presenceKey(next);
|
|
269
|
+
if (key === announcedPresence) return;
|
|
270
|
+
announcedPresence = key;
|
|
271
|
+
log('Presence changed', {
|
|
272
|
+
phase: next.phase,
|
|
273
|
+
holder: next.holder?.id ?? null,
|
|
274
|
+
editsBlocked: next.editsBlocked
|
|
275
|
+
});
|
|
276
|
+
dispatch('presence', {
|
|
277
|
+
phase: next.phase,
|
|
278
|
+
holder: next.holder,
|
|
279
|
+
editsBlocked: next.editsBlocked
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
lease.start();
|
|
283
|
+
log('Presence started', { tab: lease.tabId });
|
|
284
|
+
} catch (error) {
|
|
285
|
+
// A page that cannot have presence is not a page that cannot edit.
|
|
286
|
+
console.error(
|
|
287
|
+
'[CompositionEditorApp] Presence could not start; the editor goes on without it:',
|
|
288
|
+
error
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// A teammate's editing pauses new edits here; what was edited before is saved as usual.
|
|
294
|
+
$: controller.setEditsBlocked(presenceState.editsBlocked);
|
|
295
|
+
|
|
193
296
|
// --- what the page can ask of it ------------------------------------------------------------------
|
|
194
297
|
|
|
195
298
|
/** Saves what is unsaved now. Resolves `true` when nothing is left unsaved afterwards. */
|
|
@@ -212,11 +315,33 @@
|
|
|
212
315
|
return controller.getState();
|
|
213
316
|
}
|
|
214
317
|
|
|
318
|
+
/**
|
|
319
|
+
* Whether the editor takes no new edit now because a teammate is editing (or the person chose to only look): see the
|
|
320
|
+
* `presence` event. A page with screens of its own that save the composition can ask before opening one.
|
|
321
|
+
*/
|
|
322
|
+
export function isEditsBlocked(): boolean {
|
|
323
|
+
return controller.getState().editsBlocked;
|
|
324
|
+
}
|
|
325
|
+
|
|
215
326
|
/** Loads the composition again. Edits that are not saved are lost. */
|
|
216
327
|
export function reload(): Promise<void> {
|
|
217
328
|
return controller.load();
|
|
218
329
|
}
|
|
219
330
|
|
|
331
|
+
/**
|
|
332
|
+
* After a `conflict` event: saves the person's edits on top of the newer version (read again first, so a third person's
|
|
333
|
+
* save in the meantime asks again instead of being replaced unseen). Resolves `true` when nothing is left unsaved.
|
|
334
|
+
* Does nothing, and resolves `false`, when there is no conflict.
|
|
335
|
+
*/
|
|
336
|
+
export function keepMyChanges(): Promise<boolean> {
|
|
337
|
+
return controller.keepMyChanges();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** After a `conflict` event: drops the person's edits and shows the newer version. Does nothing when there is no conflict. */
|
|
341
|
+
export function loadLatestVersion(): Promise<void> {
|
|
342
|
+
return controller.loadLatestVersion();
|
|
343
|
+
}
|
|
344
|
+
|
|
220
345
|
/**
|
|
221
346
|
* Looks at the preview as a phone (`'mobile'`) or at the size that is saved (`'desktop'`): what the preview's own
|
|
222
347
|
* buttons do. Nothing becomes unsaved. Does nothing before the editor is ready.
|
|
@@ -346,6 +471,28 @@
|
|
|
346
471
|
// It is placed again when the screen turns around, because the pair is the mirror of itself.
|
|
347
472
|
$: if (editorVisible && $textDirection) requestDock();
|
|
348
473
|
|
|
474
|
+
// While a teammate is editing, the settings panel stays on the screen but cannot be used.
|
|
475
|
+
$: applyPanelBlock(presenceState.editsBlocked, editorVisible);
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* `inert` takes the settings panel out of reach of the pointer and the keyboard. The props editor has no read-only mode of
|
|
479
|
+
* its own, and a panel that still let a field be typed in would show a value that nothing saves (the controller refuses the
|
|
480
|
+
* edit all the same, so this is for the person's sake, not the data's). Done on the panel's element, after the screen has
|
|
481
|
+
* been updated, because the panel is made again whenever the settings are reloaded.
|
|
482
|
+
*/
|
|
483
|
+
async function applyPanelBlock(blocked: boolean, visible: boolean) {
|
|
484
|
+
if (!blocked && !visible) return;
|
|
485
|
+
await tick();
|
|
486
|
+
try {
|
|
487
|
+
const panel = editorShellEl?.querySelector<HTMLElement>('.composition-props-editor');
|
|
488
|
+
if (!panel) return;
|
|
489
|
+
if (blocked) panel.setAttribute('inert', '');
|
|
490
|
+
else panel.removeAttribute('inert');
|
|
491
|
+
} catch (error) {
|
|
492
|
+
console.error('[CompositionEditorApp] The settings panel could not be paused or resumed:', error);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
349
496
|
function log(message: string, details?: unknown) {
|
|
350
497
|
if (!debug) return;
|
|
351
498
|
if (details === undefined) console.log(`[CompositionEditorApp] ${message}`);
|
|
@@ -406,6 +553,8 @@
|
|
|
406
553
|
|
|
407
554
|
onMount(() => {
|
|
408
555
|
void controller.load();
|
|
556
|
+
// (Beside the load, not after it: the claim is about the composition, and a composition that cannot be loaded says so to this too.)
|
|
557
|
+
startPresence();
|
|
409
558
|
|
|
410
559
|
window.addEventListener('resize', syncFloatingEditorHeight);
|
|
411
560
|
if (editorShellEl && typeof ResizeObserver !== 'undefined') {
|
|
@@ -421,6 +570,9 @@
|
|
|
421
570
|
shellObserver?.disconnect();
|
|
422
571
|
stopWatchingState();
|
|
423
572
|
stopWatchingEvents();
|
|
573
|
+
// Gives the editing up (with a request that outlives the page), so a teammate does not wait for it to run out.
|
|
574
|
+
stopWatchingPresence?.();
|
|
575
|
+
leaseController?.dispose();
|
|
424
576
|
controller.dispose();
|
|
425
577
|
// The font stylesheets the editor put in the page's <head> go with it (a page of somebody else's is left as found)
|
|
426
578
|
FontManager.releasePageResources();
|
|
@@ -546,7 +698,68 @@
|
|
|
546
698
|
/>
|
|
547
699
|
{/if}
|
|
548
700
|
|
|
549
|
-
{#if state.phase === 'ready' && state.
|
|
701
|
+
{#if state.phase === 'ready' && state.conflict}
|
|
702
|
+
<!--
|
|
703
|
+
Somebody else saved the composition after this editor loaded it, so the save was refused and nothing more is sent until the
|
|
704
|
+
person chooses a version. Each choice says what it does to the other version: keeping the edits replaces the newer one, and
|
|
705
|
+
using the newer one drops the edits. (It takes the place of the save error: no save is made while this is on the screen.)
|
|
706
|
+
-->
|
|
707
|
+
<div
|
|
708
|
+
role="alert"
|
|
709
|
+
class="composition-editor-conflict absolute bottom-4 start-4 z-30 flex max-w-sm flex-col gap-3 rounded-lg border border-amber-300 bg-white p-4 shadow-sm"
|
|
710
|
+
>
|
|
711
|
+
<div class="flex flex-col gap-1">
|
|
712
|
+
<p class="text-sm font-medium text-gray-900">{$t('editor.conflict.title')}</p>
|
|
713
|
+
<p class="text-xs text-gray-600">
|
|
714
|
+
{#if state.conflict.lastEditedBy?.name}
|
|
715
|
+
{$t('editor.conflict.bodyNamed', { name: state.conflict.lastEditedBy.name })}
|
|
716
|
+
{:else}
|
|
717
|
+
{$t('editor.conflict.body')}
|
|
718
|
+
{/if}
|
|
719
|
+
</p>
|
|
720
|
+
</div>
|
|
721
|
+
{#if state.conflict.resolveError}
|
|
722
|
+
<p class="composition-editor-conflict-error text-xs text-red-600">
|
|
723
|
+
{state.conflict.resolveError.sessionEnded
|
|
724
|
+
? failureMessage(state.conflict.resolveError, 'save', $t)
|
|
725
|
+
: $t('editor.conflict.resolveFailed')}
|
|
726
|
+
</p>
|
|
727
|
+
{/if}
|
|
728
|
+
{#if state.conflict.resolving}
|
|
729
|
+
<p role="status" class="composition-editor-conflict-working text-xs text-gray-500">
|
|
730
|
+
{$t('editor.conflict.working')}
|
|
731
|
+
</p>
|
|
732
|
+
{/if}
|
|
733
|
+
<div class="flex flex-col gap-2">
|
|
734
|
+
<div class="flex flex-col items-start gap-1">
|
|
735
|
+
<button
|
|
736
|
+
type="button"
|
|
737
|
+
disabled={state.conflict.resolving}
|
|
738
|
+
class="keep-my-changes-btn w-fit cursor-pointer rounded-lg bg-blue-100 px-2 py-1 text-xs text-blue-700 hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 disabled:cursor-not-allowed disabled:opacity-50"
|
|
739
|
+
on:click={() => {
|
|
740
|
+
void controller.keepMyChanges();
|
|
741
|
+
}}
|
|
742
|
+
>
|
|
743
|
+
{$t('editor.conflict.keepMine')}
|
|
744
|
+
</button>
|
|
745
|
+
<span class="text-xs text-gray-500">{$t('editor.conflict.keepMineHint')}</span>
|
|
746
|
+
</div>
|
|
747
|
+
<div class="flex flex-col items-start gap-1">
|
|
748
|
+
<button
|
|
749
|
+
type="button"
|
|
750
|
+
disabled={state.conflict.resolving}
|
|
751
|
+
class="load-latest-btn w-fit cursor-pointer rounded-lg border border-gray-200 bg-white px-2 py-1 text-xs text-gray-700 hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 disabled:cursor-not-allowed disabled:opacity-50"
|
|
752
|
+
on:click={() => {
|
|
753
|
+
void controller.loadLatestVersion();
|
|
754
|
+
}}
|
|
755
|
+
>
|
|
756
|
+
{$t('editor.conflict.loadLatest')}
|
|
757
|
+
</button>
|
|
758
|
+
<span class="text-xs text-gray-500">{$t('editor.conflict.loadLatestHint')}</span>
|
|
759
|
+
</div>
|
|
760
|
+
</div>
|
|
761
|
+
</div>
|
|
762
|
+
{:else if state.phase === 'ready' && state.saveError}
|
|
550
763
|
<div
|
|
551
764
|
role="alert"
|
|
552
765
|
class="composition-editor-save-error absolute bottom-4 start-4 z-30 flex max-w-sm flex-col gap-2 rounded-lg border border-red-200 bg-white p-4 shadow-sm"
|
|
@@ -563,6 +776,16 @@
|
|
|
563
776
|
</button>
|
|
564
777
|
</div>
|
|
565
778
|
{/if}
|
|
779
|
+
|
|
780
|
+
{#if presence && state.phase === 'ready'}
|
|
781
|
+
<!-- Says who else is editing, and asks before their work is overwritten; shows nothing when nobody is. -->
|
|
782
|
+
<EditLeaseNotice
|
|
783
|
+
presence={presenceState}
|
|
784
|
+
on:takeOver={() => leaseController?.takeOver()}
|
|
785
|
+
on:lookOnly={() => leaseController?.openReadOnly()}
|
|
786
|
+
on:startEditing={() => leaseController?.startEditing()}
|
|
787
|
+
/>
|
|
788
|
+
{/if}
|
|
566
789
|
</div>
|
|
567
790
|
|
|
568
791
|
<style>
|
|
@@ -581,4 +804,8 @@
|
|
|
581
804
|
text-overflow: unset;
|
|
582
805
|
white-space: nowrap;
|
|
583
806
|
}
|
|
807
|
+
/* The panel is paused while a teammate is editing (see `applyPanelBlock`): shown, but plainly out of use. */
|
|
808
|
+
.composition-editor-ct :global(.composition-props-editor[inert]) {
|
|
809
|
+
opacity: 0.55;
|
|
810
|
+
}
|
|
584
811
|
</style>
|
|
@@ -3,8 +3,9 @@ import type { MessageOverrides } from '@widgetic/design-system/i18n';
|
|
|
3
3
|
import { type TextDirection } from '@widgetic/design-system/components/textDirection';
|
|
4
4
|
import type { PartnerPickFileFn } from '../../pickFileContext.js';
|
|
5
5
|
import type { StoreFileUrlFn } from '../../fileStorageUrlContext.js';
|
|
6
|
-
import { type TokenReason } from '../../composition/compositionApi.js';
|
|
7
|
-
import { type
|
|
6
|
+
import { type EditLeaseHolder, type TokenReason } from '../../composition/compositionApi.js';
|
|
7
|
+
import { type PresencePhase } from '../../composition/editLeaseController.js';
|
|
8
|
+
import { type CompositionEditorState, type ConflictResolution, type EditorConflict, type EditorFailure } from '../../composition/compositionEditorController.js';
|
|
8
9
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
9
10
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
10
11
|
$$bindings?: Bindings;
|
|
@@ -40,6 +41,13 @@ declare const CompositionEditorApp: $$__sveltets_2_IsomorphicComponent<{
|
|
|
40
41
|
* When true, dragging or typing a preview size changes the preview on screen but does not change the embed width and
|
|
41
42
|
* height saved with the composition.
|
|
42
43
|
*/ lockPreviewSize?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* When true, the editor tells the API that this tab is editing the composition and shows who else is: a card asks
|
|
46
|
+
* before a teammate's editing is overwritten (take it over, or only look). It is for a page that signs the person in
|
|
47
|
+
* as themselves (the Widgetic site); the API refuses these requests to an editor session or a managed user's token, and
|
|
48
|
+
* the editor then shows nothing, so a partner's page leaves it off. Presence is advice, never a lock: it can only pause
|
|
49
|
+
* new edits in this tab, and no save is ever refused because of it. Read once, when the editor starts.
|
|
50
|
+
*/ presence?: boolean;
|
|
43
51
|
/** The key the font pickers list Google Fonts with. Without one only the fonts that need no key are listed. */ googleFontsApiKey?: string;
|
|
44
52
|
/** Wait this long after the last change before saving by itself; `0` turns saving by itself off. Read once, when the editor starts. */ autosaveDelayMs?: number | undefined;
|
|
45
53
|
/** Writes what the layout does to the console. */ debug?: boolean;
|
|
@@ -65,7 +73,10 @@ declare const CompositionEditorApp: $$__sveltets_2_IsomorphicComponent<{
|
|
|
65
73
|
flush?: () => Promise<boolean>;
|
|
66
74
|
isDirty?: () => boolean;
|
|
67
75
|
getState?: () => CompositionEditorState;
|
|
76
|
+
isEditsBlocked?: () => boolean;
|
|
68
77
|
reload?: () => Promise<void>;
|
|
78
|
+
keepMyChanges?: () => Promise<boolean>;
|
|
79
|
+
loadLatestVersion?: () => Promise<void>;
|
|
69
80
|
setDeviceView?: (deviceView: "desktop" | "mobile") => void;
|
|
70
81
|
adoptEmbedSettings?: (settings: Record<string, unknown>) => void;
|
|
71
82
|
adoptName?: (name: string) => void;
|
|
@@ -89,6 +100,17 @@ declare const CompositionEditorApp: $$__sveltets_2_IsomorphicComponent<{
|
|
|
89
100
|
deviceView: CustomEvent<{
|
|
90
101
|
deviceView: "desktop" | "mobile";
|
|
91
102
|
}>;
|
|
103
|
+
conflict: CustomEvent<{
|
|
104
|
+
conflict: EditorConflict;
|
|
105
|
+
}>;
|
|
106
|
+
conflictResolved: CustomEvent<{
|
|
107
|
+
resolution: ConflictResolution;
|
|
108
|
+
}>;
|
|
109
|
+
presence: CustomEvent<{
|
|
110
|
+
phase: PresencePhase;
|
|
111
|
+
holder: EditLeaseHolder | null;
|
|
112
|
+
editsBlocked: boolean;
|
|
113
|
+
}>;
|
|
92
114
|
} & {
|
|
93
115
|
[evt: string]: CustomEvent<any>;
|
|
94
116
|
}, {}, {
|
|
@@ -96,7 +118,10 @@ declare const CompositionEditorApp: $$__sveltets_2_IsomorphicComponent<{
|
|
|
96
118
|
flush: () => Promise<boolean>;
|
|
97
119
|
isDirty: () => boolean;
|
|
98
120
|
getState: () => CompositionEditorState;
|
|
121
|
+
isEditsBlocked: () => boolean;
|
|
99
122
|
reload: () => Promise<void>;
|
|
123
|
+
keepMyChanges: () => Promise<boolean>;
|
|
124
|
+
loadLatestVersion: () => Promise<void>;
|
|
100
125
|
setDeviceView: (deviceView: "desktop" | "mobile") => void;
|
|
101
126
|
adoptEmbedSettings: (settings: Record<string, unknown>) => void;
|
|
102
127
|
adoptName: (name: string) => void;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* What a person is told when a teammate is editing the composition they opened, and what they can do about it.
|
|
4
|
+
*
|
|
5
|
+
* - `blocked`: a card in the middle of the editor, over a veil that covers the settings and the preview, because a
|
|
6
|
+
* decision is waiting: take the editing over (a teammate's editor pauses, what they saved stays) or only look.
|
|
7
|
+
* The card says who, in the person's own words: a named teammate, "you" in another window, or "someone".
|
|
8
|
+
* - `readOnly`: a slim bar at the foot of the editor for a person who chose to look, with the way back (take over, or
|
|
9
|
+
* start editing once nobody is).
|
|
10
|
+
* - anything else: nothing at all.
|
|
11
|
+
*
|
|
12
|
+
* It only shows what `EditLeaseController` knows and reports the person's choices (`takeOver`, `lookOnly`,
|
|
13
|
+
* `startEditing`); the editor decides what they do. Every word is in the editor's catalog (`editor.presence.*`).
|
|
14
|
+
*/
|
|
15
|
+
import { createEventDispatcher } from 'svelte';
|
|
16
|
+
import { useEditorLanguage } from '../../i18n/language';
|
|
17
|
+
import type { PresenceState } from '../../composition/editLeaseController.js';
|
|
18
|
+
|
|
19
|
+
// The words of the editor in the language of the page: the editor above this one chose it (see `provideEditorLanguage`).
|
|
20
|
+
const { t } = useEditorLanguage();
|
|
21
|
+
|
|
22
|
+
const dispatch = createEventDispatcher<{
|
|
23
|
+
takeOver: void;
|
|
24
|
+
lookOnly: void;
|
|
25
|
+
startEditing: void;
|
|
26
|
+
}>();
|
|
27
|
+
|
|
28
|
+
/** Where the tab is: only `blocked` and `readOnly` show anything. */
|
|
29
|
+
export let presence: PresenceState;
|
|
30
|
+
|
|
31
|
+
// Who holds the editing, as the person is to read it: this person's own other window ("you"), a named teammate, or nobody named.
|
|
32
|
+
$: holderIsYou = presence.holder?.isYou === true;
|
|
33
|
+
$: holderName = presence.holder?.name ?? null;
|
|
34
|
+
|
|
35
|
+
// The title of the card. A claim that was this tab's and was taken says so; a tab that arrived to find it held does not.
|
|
36
|
+
$: cardTitle = presence.lostIt
|
|
37
|
+
? holderIsYou
|
|
38
|
+
? $t('editor.presence.lostTitleYou')
|
|
39
|
+
: holderName
|
|
40
|
+
? $t('editor.presence.lostTitleNamed', { name: holderName })
|
|
41
|
+
: $t('editor.presence.lostTitle')
|
|
42
|
+
: holderIsYou
|
|
43
|
+
? $t('editor.presence.blockedTitleYou')
|
|
44
|
+
: holderName
|
|
45
|
+
? $t('editor.presence.blockedTitleNamed', { name: holderName })
|
|
46
|
+
: $t('editor.presence.blockedTitle');
|
|
47
|
+
$: cardBody = presence.lostIt
|
|
48
|
+
? $t('editor.presence.lostBody')
|
|
49
|
+
: $t('editor.presence.blockedBody');
|
|
50
|
+
|
|
51
|
+
// The line of the bar: who is editing, or that nobody is any more.
|
|
52
|
+
$: barText = presence.nobodyIsEditing
|
|
53
|
+
? $t('editor.presence.readOnlyFree')
|
|
54
|
+
: holderIsYou
|
|
55
|
+
? $t('editor.presence.readOnlyYou')
|
|
56
|
+
: holderName
|
|
57
|
+
? $t('editor.presence.readOnlyNamed', { name: holderName })
|
|
58
|
+
: $t('editor.presence.readOnly');
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
{#if presence.phase === 'blocked'}
|
|
62
|
+
<!-- A choice is waiting, so the settings and the preview are covered until the person makes it. -->
|
|
63
|
+
<div
|
|
64
|
+
class="composition-editor-presence-veil absolute inset-0 z-30 flex items-center justify-center bg-white/60 p-4"
|
|
65
|
+
>
|
|
66
|
+
<div
|
|
67
|
+
role="alert"
|
|
68
|
+
class="composition-editor-presence flex w-full max-w-sm flex-col gap-3 rounded-lg border border-amber-300 bg-white p-4 shadow-sm"
|
|
69
|
+
>
|
|
70
|
+
<div class="flex flex-col gap-1">
|
|
71
|
+
<p class="composition-editor-presence-title break-words text-sm font-medium text-gray-900">
|
|
72
|
+
{cardTitle}
|
|
73
|
+
</p>
|
|
74
|
+
<p class="text-xs text-gray-600">{cardBody}</p>
|
|
75
|
+
</div>
|
|
76
|
+
{#if presence.actionFailed}
|
|
77
|
+
<p class="composition-editor-presence-error text-xs text-red-600">
|
|
78
|
+
{$t('editor.presence.actionFailed')}
|
|
79
|
+
</p>
|
|
80
|
+
{/if}
|
|
81
|
+
{#if presence.working}
|
|
82
|
+
<p role="status" class="composition-editor-presence-working text-xs text-gray-500">
|
|
83
|
+
{$t('editor.presence.working')}
|
|
84
|
+
</p>
|
|
85
|
+
{/if}
|
|
86
|
+
<div class="flex flex-col gap-2">
|
|
87
|
+
<div class="flex flex-col items-start gap-1">
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
disabled={presence.working}
|
|
91
|
+
class="take-over-btn w-fit cursor-pointer rounded-lg bg-blue-100 px-2 py-1 text-xs text-blue-700 hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 disabled:cursor-not-allowed disabled:opacity-50"
|
|
92
|
+
on:click={() => dispatch('takeOver')}
|
|
93
|
+
>
|
|
94
|
+
{$t('editor.presence.takeOver')}
|
|
95
|
+
</button>
|
|
96
|
+
<span class="text-xs text-gray-500">{$t('editor.presence.takeOverHint')}</span>
|
|
97
|
+
</div>
|
|
98
|
+
<div class="flex flex-col items-start gap-1">
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
disabled={presence.working}
|
|
102
|
+
class="look-only-btn w-fit cursor-pointer rounded-lg border border-gray-200 bg-white px-2 py-1 text-xs text-gray-700 hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 disabled:cursor-not-allowed disabled:opacity-50"
|
|
103
|
+
on:click={() => dispatch('lookOnly')}
|
|
104
|
+
>
|
|
105
|
+
{$t('editor.presence.lookOnly')}
|
|
106
|
+
</button>
|
|
107
|
+
<span class="text-xs text-gray-500">{$t('editor.presence.lookOnlyHint')}</span>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
{:else if presence.phase === 'readOnly'}
|
|
113
|
+
<div
|
|
114
|
+
role="status"
|
|
115
|
+
class="composition-editor-presence-bar absolute bottom-4 left-1/2 z-30 flex w-max max-w-[calc(100%-2rem)] -translate-x-1/2 flex-wrap items-center justify-center gap-x-3 gap-y-1 rounded-lg border border-amber-300 bg-white px-4 py-2 shadow-sm"
|
|
116
|
+
>
|
|
117
|
+
<span class="composition-editor-presence-bar-text break-words text-xs text-gray-700"
|
|
118
|
+
>{barText}</span
|
|
119
|
+
>
|
|
120
|
+
{#if presence.actionFailed}
|
|
121
|
+
<span class="composition-editor-presence-error text-xs text-red-600">
|
|
122
|
+
{$t('editor.presence.actionFailed')}
|
|
123
|
+
</span>
|
|
124
|
+
{/if}
|
|
125
|
+
{#if presence.working}
|
|
126
|
+
<span class="composition-editor-presence-working text-xs text-gray-500">
|
|
127
|
+
{$t('editor.presence.working')}
|
|
128
|
+
</span>
|
|
129
|
+
{/if}
|
|
130
|
+
{#if presence.nobodyIsEditing}
|
|
131
|
+
<button
|
|
132
|
+
type="button"
|
|
133
|
+
disabled={presence.working}
|
|
134
|
+
class="start-editing-btn w-fit cursor-pointer rounded-lg bg-blue-100 px-2 py-1 text-xs text-blue-700 hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 disabled:cursor-not-allowed disabled:opacity-50"
|
|
135
|
+
on:click={() => dispatch('startEditing')}
|
|
136
|
+
>
|
|
137
|
+
{$t('editor.presence.startEditing')}
|
|
138
|
+
</button>
|
|
139
|
+
{:else}
|
|
140
|
+
<button
|
|
141
|
+
type="button"
|
|
142
|
+
disabled={presence.working}
|
|
143
|
+
class="take-over-btn w-fit cursor-pointer rounded-lg bg-blue-100 px-2 py-1 text-xs text-blue-700 hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 disabled:cursor-not-allowed disabled:opacity-50"
|
|
144
|
+
on:click={() => dispatch('takeOver')}
|
|
145
|
+
>
|
|
146
|
+
{$t('editor.presence.takeOver')}
|
|
147
|
+
</button>
|
|
148
|
+
{/if}
|
|
149
|
+
</div>
|
|
150
|
+
{/if}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PresenceState } from '../../composition/editLeaseController.js';
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: Props & {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
declare const EditLeaseNotice: $$__sveltets_2_IsomorphicComponent<{
|
|
16
|
+
/** Where the tab is: only `blocked` and `readOnly` show anything. */ presence: PresenceState;
|
|
17
|
+
}, {
|
|
18
|
+
takeOver: CustomEvent<void>;
|
|
19
|
+
lookOnly: CustomEvent<void>;
|
|
20
|
+
startEditing: CustomEvent<void>;
|
|
21
|
+
} & {
|
|
22
|
+
[evt: string]: CustomEvent<any>;
|
|
23
|
+
}, {}, {}, string>;
|
|
24
|
+
type EditLeaseNotice = InstanceType<typeof EditLeaseNotice>;
|
|
25
|
+
export default EditLeaseNotice;
|