@brass-build/client 0.1.0 → 0.3.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/AGENTS.md +72 -63
- package/CHANGELOG.md +97 -0
- package/README.md +325 -235
- package/dist/auth-flow.d.ts +10 -1
- package/dist/auth-flow.d.ts.map +1 -1
- package/dist/auth-flow.js +64 -20
- package/dist/auth-flow.js.map +1 -1
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +245 -76
- package/dist/client.js.map +1 -1
- package/dist/document-checkpoints.d.ts +1 -0
- package/dist/document-checkpoints.d.ts.map +1 -1
- package/dist/document-checkpoints.js +27 -0
- package/dist/document-checkpoints.js.map +1 -1
- package/dist/document-engine.d.ts +4 -0
- package/dist/document-engine.d.ts.map +1 -0
- package/dist/document-engine.js +9 -0
- package/dist/document-engine.js.map +1 -0
- package/dist/document-signals.d.ts +31 -1
- package/dist/document-signals.d.ts.map +1 -1
- package/dist/document-signals.js +59 -0
- package/dist/document-signals.js.map +1 -1
- package/dist/document-streams.d.ts +8 -1
- package/dist/document-streams.d.ts.map +1 -1
- package/dist/document-streams.js +79 -8
- package/dist/document-streams.js.map +1 -1
- package/dist/document-thumbnail-capture.d.ts +20 -0
- package/dist/document-thumbnail-capture.d.ts.map +1 -1
- package/dist/document-thumbnail-capture.js +247 -9
- package/dist/document-thumbnail-capture.js.map +1 -1
- package/dist/documents-namespace.d.ts.map +1 -1
- package/dist/documents-namespace.js +22 -3
- package/dist/documents-namespace.js.map +1 -1
- package/dist/documents.d.ts +49 -16
- package/dist/documents.d.ts.map +1 -1
- package/dist/documents.js +981 -237
- package/dist/documents.js.map +1 -1
- package/dist/embed-protocol.d.ts +3 -0
- package/dist/embed-protocol.d.ts.map +1 -0
- package/dist/embed-protocol.js +26 -0
- package/dist/embed-protocol.js.map +1 -0
- package/dist/emitter.d.ts.map +1 -1
- package/dist/emitter.js +8 -1
- package/dist/emitter.js.map +1 -1
- package/dist/export-guest.d.ts.map +1 -1
- package/dist/export-guest.js +14 -6
- package/dist/export-guest.js.map +1 -1
- package/dist/fetch-deadline.d.ts +22 -0
- package/dist/fetch-deadline.d.ts.map +1 -0
- package/dist/fetch-deadline.js +96 -0
- package/dist/fetch-deadline.js.map +1 -0
- package/dist/fetch-retry.d.ts +1 -0
- package/dist/fetch-retry.d.ts.map +1 -1
- package/dist/fetch-retry.js +12 -5
- package/dist/fetch-retry.js.map +1 -1
- package/dist/handle-types.d.ts +150 -0
- package/dist/handle-types.d.ts.map +1 -0
- package/dist/handle-types.js +8 -0
- package/dist/handle-types.js.map +1 -0
- package/dist/handles.d.ts +48 -48
- package/dist/handles.d.ts.map +1 -1
- package/dist/handles.js +3122 -501
- package/dist/handles.js.map +1 -1
- package/dist/hosted-runtime.d.ts.map +1 -1
- package/dist/hosted-runtime.js +8 -12
- package/dist/hosted-runtime.js.map +1 -1
- package/dist/hosted-ui.d.ts +0 -1
- package/dist/hosted-ui.d.ts.map +1 -1
- package/dist/hosted-ui.js +29 -24
- package/dist/hosted-ui.js.map +1 -1
- package/dist/importer.d.ts.map +1 -1
- package/dist/importer.js +204 -8
- package/dist/importer.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/join-coverage.d.ts +12 -0
- package/dist/join-coverage.d.ts.map +1 -0
- package/dist/join-coverage.js +37 -0
- package/dist/join-coverage.js.map +1 -0
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js +5 -1
- package/dist/jwt.js.map +1 -1
- package/dist/launch-context.js +2 -2
- package/dist/launch-context.js.map +1 -1
- package/dist/mutate-batching.d.ts +25 -2
- package/dist/mutate-batching.d.ts.map +1 -1
- package/dist/mutate-batching.js +57 -10
- package/dist/mutate-batching.js.map +1 -1
- package/dist/open-document.d.ts +30 -1
- package/dist/open-document.d.ts.map +1 -1
- package/dist/open-document.js +1905 -322
- package/dist/open-document.js.map +1 -1
- package/dist/presence.d.ts +28 -0
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +149 -7
- package/dist/presence.js.map +1 -1
- package/dist/record-paging.d.ts +335 -71
- package/dist/record-paging.d.ts.map +1 -1
- package/dist/record-paging.js +590 -127
- package/dist/record-paging.js.map +1 -1
- package/dist/selection-persistence.d.ts.map +1 -1
- package/dist/selection-persistence.js +11 -1
- package/dist/selection-persistence.js.map +1 -1
- package/dist/serializer.d.ts +30 -1
- package/dist/serializer.d.ts.map +1 -1
- package/dist/session-persistence.d.ts.map +1 -1
- package/dist/session-persistence.js +9 -8
- package/dist/session-persistence.js.map +1 -1
- package/dist/session-toolbar.d.ts +0 -1
- package/dist/session-toolbar.d.ts.map +1 -1
- package/dist/session-toolbar.js +356 -83
- package/dist/session-toolbar.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +87 -18
- package/dist/session.js.map +1 -1
- package/dist/tail-ops.d.ts +14 -4
- package/dist/tail-ops.d.ts.map +1 -1
- package/dist/tail-ops.js +75 -15
- package/dist/tail-ops.js.map +1 -1
- package/dist/topic-lifecycle.d.ts +4 -0
- package/dist/topic-lifecycle.d.ts.map +1 -1
- package/dist/topic-lifecycle.js +25 -1
- package/dist/topic-lifecycle.js.map +1 -1
- package/dist/types.d.ts +47 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/undo.d.ts +2 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +11 -0
- package/dist/undo.js.map +1 -1
- package/dist/unload-guard.d.ts +5 -0
- package/dist/unload-guard.d.ts.map +1 -0
- package/dist/unload-guard.js +88 -0
- package/dist/unload-guard.js.map +1 -0
- package/dist/version-bar.d.ts +4 -3
- package/dist/version-bar.d.ts.map +1 -1
- package/dist/version-bar.js +162 -20
- package/dist/version-bar.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist/vite.d.ts +18 -2
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +133 -8
- package/dist/vite.js.map +1 -1
- package/dist/when-saved.d.ts +2 -0
- package/dist/when-saved.d.ts.map +1 -0
- package/dist/when-saved.js +70 -0
- package/dist/when-saved.js.map +1 -0
- package/dist/ws-client.d.ts +27 -3
- package/dist/ws-client.d.ts.map +1 -1
- package/dist/ws-client.js +408 -89
- package/dist/ws-client.js.map +1 -1
- package/dist/ws-frame-limit.d.ts.map +1 -1
- package/dist/ws-frame-limit.js +23 -17
- package/dist/ws-frame-limit.js.map +1 -1
- package/docs/app-manifest.md +7 -8
- package/docs/custom-chrome.md +21 -22
- package/docs/hosted-ui-advanced.md +14 -17
- package/docs/imported-documents.md +53 -197
- package/docs/presence.md +45 -21
- package/docs/schemas.md +12 -17
- package/docs/streams.md +55 -57
- package/package.json +4 -3
- package/src/auth-flow.ts +90 -23
- package/src/client.ts +262 -80
- package/src/document-checkpoints.ts +30 -0
- package/src/document-engine.ts +15 -0
- package/src/document-signals.ts +120 -8
- package/src/document-streams.ts +95 -9
- package/src/document-thumbnail-capture.ts +253 -9
- package/src/documents-namespace.ts +38 -13
- package/src/documents.ts +1103 -290
- package/src/embed-protocol.ts +25 -0
- package/src/emitter.ts +8 -1
- package/src/export-guest.ts +15 -9
- package/src/fetch-deadline.ts +119 -0
- package/src/fetch-retry.ts +14 -5
- package/src/handle-types.ts +303 -0
- package/src/handles.ts +3407 -683
- package/src/hosted-runtime.ts +8 -12
- package/src/hosted-ui.ts +28 -32
- package/src/importer.ts +216 -8
- package/src/index.ts +29 -18
- package/src/internal.ts +7 -0
- package/src/join-coverage.ts +42 -0
- package/src/jwt.ts +8 -1
- package/src/launch-context.ts +2 -2
- package/src/mutate-batching.ts +60 -11
- package/src/open-document.ts +2441 -502
- package/src/presence.ts +210 -11
- package/src/record-paging.ts +686 -137
- package/src/selection-persistence.ts +10 -1
- package/src/serializer.ts +33 -1
- package/src/session-persistence.ts +9 -8
- package/src/session-toolbar.ts +387 -89
- package/src/session.ts +91 -17
- package/src/tail-ops.ts +76 -10
- package/src/topic-lifecycle.ts +31 -1
- package/src/types.ts +56 -4
- package/src/undo.ts +13 -5
- package/src/unload-guard.ts +91 -0
- package/src/version-bar.ts +183 -26
- package/src/version.ts +1 -1
- package/src/vite.ts +175 -10
- package/src/when-saved.ts +66 -0
- package/src/ws-client.ts +461 -92
- package/src/ws-frame-limit.ts +23 -17
package/dist/version-bar.js
CHANGED
|
@@ -9,12 +9,21 @@
|
|
|
9
9
|
// grow with no SDK or app change.
|
|
10
10
|
//
|
|
11
11
|
// Bridge protocol (shared envelope `__brass_embed: 1`):
|
|
12
|
-
// host -> iframe: init{surface,params}
|
|
13
|
-
//
|
|
14
|
-
//
|
|
12
|
+
// host -> iframe: init{surface,params}
|
|
13
|
+
// | version-changed{version, requestId?, ok?}
|
|
14
|
+
// iframe -> host: ready | resize{height} | preview{version, requestId?}
|
|
15
|
+
// | return-to-head{requestId?} | fork{fromVersion} | browse
|
|
15
16
|
// | error{code,message}
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
//
|
|
18
|
+
// A navigating intent (`preview` / `return-to-head`) is CONFIRMED: the host
|
|
19
|
+
// awaits the document method it routes to and answers with the version the
|
|
20
|
+
// document actually shows afterwards, plus whether the intent was accepted.
|
|
21
|
+
// The bar moves optimistically on the click, so without that answer a refused
|
|
22
|
+
// checkout (a document pinned to a version, a materialise that failed) leaves
|
|
23
|
+
// it naming a version nothing is showing, and nothing later corrects it: the
|
|
24
|
+
// host's own re-render is driven by the session, which does not notify on a
|
|
25
|
+
// preview -> preview step.
|
|
26
|
+
import { EMBED_ENVELOPE, EMBED_PROTOCOL_VERSION } from './embed-protocol.js';
|
|
18
27
|
// Collapsed until the embed reports `ready`, so the load moment shows a
|
|
19
28
|
// themed placeholder strip rather than an empty white iframe (no flash, no
|
|
20
29
|
// layout jump: the placeholder reserves the strip's height).
|
|
@@ -26,6 +35,9 @@ function clampHeight(h) {
|
|
|
26
35
|
return READY_HEIGHT;
|
|
27
36
|
return Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, Math.round(h)));
|
|
28
37
|
}
|
|
38
|
+
// How long the embed has to say it is ready before the SDK-drawn fallback
|
|
39
|
+
// takes the strip. Matches the hosted-UI launcher's own long window.
|
|
40
|
+
const VERSION_BAR_READY_TIMEOUT_MS = 10_000;
|
|
29
41
|
export function createVersionBarFrame(root, deps) {
|
|
30
42
|
const origin = new URL(deps.dashboardBaseUrl).origin;
|
|
31
43
|
const base = deps.dashboardBaseUrl.replace(/\/$/, '');
|
|
@@ -35,6 +47,35 @@ export function createVersionBarFrame(root, deps) {
|
|
|
35
47
|
const placeholder = document.createElement('div');
|
|
36
48
|
placeholder.className = 'b-version-loading';
|
|
37
49
|
placeholder.textContent = 'Loading version controls...';
|
|
50
|
+
// Shown when the embed reports it cannot render (not signed in in this
|
|
51
|
+
// framing context, an account mismatch). The bar is the only surface that
|
|
52
|
+
// returns a document to its live head, so collapsing the strip on that
|
|
53
|
+
// failure would leave the reader in a read-only preview with nothing to
|
|
54
|
+
// leave it by; this carries the two controls that need no timeline.
|
|
55
|
+
const fallback = document.createElement('div');
|
|
56
|
+
fallback.className = 'b-version-fallback';
|
|
57
|
+
fallback.hidden = true;
|
|
58
|
+
const fallbackText = document.createElement('span');
|
|
59
|
+
fallbackText.className = 'b-version-fallback-msg';
|
|
60
|
+
const fallbackHead = document.createElement('button');
|
|
61
|
+
fallbackHead.type = 'button';
|
|
62
|
+
fallbackHead.textContent = 'Return to latest';
|
|
63
|
+
fallbackHead.onclick = () => {
|
|
64
|
+
void deps.returnToHead().catch(() => { });
|
|
65
|
+
};
|
|
66
|
+
const fallbackClose = document.createElement('button');
|
|
67
|
+
fallbackClose.type = 'button';
|
|
68
|
+
fallbackClose.textContent = 'Close';
|
|
69
|
+
fallbackClose.onclick = () => deps.close();
|
|
70
|
+
fallback.append(fallbackText, fallbackHead, fallbackClose);
|
|
71
|
+
function renderFallback() {
|
|
72
|
+
const pinned = ctx?.pinned === true;
|
|
73
|
+
const previewing = deps.currentVersion() !== null;
|
|
74
|
+
fallbackText.textContent = previewing
|
|
75
|
+
? 'Viewing an earlier version'
|
|
76
|
+
: 'Latest version';
|
|
77
|
+
fallbackHead.hidden = !previewing || pinned;
|
|
78
|
+
}
|
|
38
79
|
const iframe = document.createElement('iframe');
|
|
39
80
|
const url = new URL(`${base}/embed/version-bar`);
|
|
40
81
|
url.searchParams.set('theme', theme);
|
|
@@ -48,9 +89,46 @@ export function createVersionBarFrame(root, deps) {
|
|
|
48
89
|
colorScheme: theme === 'auto' ? 'light dark' : theme,
|
|
49
90
|
background: 'transparent',
|
|
50
91
|
});
|
|
51
|
-
root.append(placeholder, iframe);
|
|
92
|
+
root.append(placeholder, fallback, iframe);
|
|
52
93
|
let ctx = null;
|
|
53
94
|
let ready = false;
|
|
95
|
+
// Set once the embed reports it cannot render, so the fallback strip owns
|
|
96
|
+
// the surface and a later `update` does not restore the dead iframe.
|
|
97
|
+
let failed = false;
|
|
98
|
+
let destroyed = false;
|
|
99
|
+
// Armed whenever the iframe is pointed at the embed. Returning a document to
|
|
100
|
+
// its live head is this bar's exclusive capability, so an embed that never
|
|
101
|
+
// loads at all (a host CSP that refuses the frame, an offline reader, a
|
|
102
|
+
// blocking extension) would otherwise leave the placeholder up forever and
|
|
103
|
+
// the reader in a read-only preview with no control to leave it by. The
|
|
104
|
+
// `error` message covers an embed that loaded and refused; nothing covers
|
|
105
|
+
// one that never answers, which is why this is a timer rather than a
|
|
106
|
+
// handler.
|
|
107
|
+
let readyTimer;
|
|
108
|
+
// Hand the strip to the SDK-drawn fallback, which carries the two controls
|
|
109
|
+
// that need no timeline (return to latest, close).
|
|
110
|
+
function enterFallback() {
|
|
111
|
+
if (destroyed || failed)
|
|
112
|
+
return;
|
|
113
|
+
failed = true;
|
|
114
|
+
if (readyTimer !== undefined) {
|
|
115
|
+
clearTimeout(readyTimer);
|
|
116
|
+
readyTimer = undefined;
|
|
117
|
+
}
|
|
118
|
+
placeholder.style.display = 'none';
|
|
119
|
+
iframe.style.height = '0';
|
|
120
|
+
fallback.hidden = false;
|
|
121
|
+
renderFallback();
|
|
122
|
+
}
|
|
123
|
+
function armReadyTimer() {
|
|
124
|
+
if (readyTimer !== undefined)
|
|
125
|
+
clearTimeout(readyTimer);
|
|
126
|
+
readyTimer = setTimeout(() => {
|
|
127
|
+
readyTimer = undefined;
|
|
128
|
+
if (!ready)
|
|
129
|
+
enterFallback();
|
|
130
|
+
}, VERSION_BAR_READY_TIMEOUT_MS);
|
|
131
|
+
}
|
|
54
132
|
// The version last delivered to the embed (via `init` or `version-changed`).
|
|
55
133
|
// The host re-renders on many events (a commit, a saving-count bump, ...),
|
|
56
134
|
// each calling `update`, but only an ACTUAL version change should reach the
|
|
@@ -58,11 +136,10 @@ export function createVersionBarFrame(root, deps) {
|
|
|
58
136
|
// stale one clobber its optimistic state; `undefined` = nothing delivered yet.
|
|
59
137
|
let deliveredVersion = undefined;
|
|
60
138
|
function postInit() {
|
|
61
|
-
const sid = deps.getSessionToken?.();
|
|
62
139
|
if (!ctx)
|
|
63
140
|
return;
|
|
64
141
|
iframe.contentWindow?.postMessage({
|
|
65
|
-
[
|
|
142
|
+
[EMBED_ENVELOPE]: EMBED_PROTOCOL_VERSION,
|
|
66
143
|
type: 'init',
|
|
67
144
|
surface: 'version-bar',
|
|
68
145
|
params: {
|
|
@@ -70,22 +147,67 @@ export function createVersionBarFrame(root, deps) {
|
|
|
70
147
|
...(ctx.branch !== undefined ? { branch: ctx.branch } : {}),
|
|
71
148
|
version: ctx.version,
|
|
72
149
|
...(ctx.branchName !== undefined ? { branchName: ctx.branchName } : {}),
|
|
73
|
-
...(
|
|
150
|
+
...(ctx.pinned ? { pinned: true } : {}),
|
|
74
151
|
},
|
|
75
152
|
}, origin);
|
|
76
153
|
deliveredVersion = ctx.version;
|
|
77
154
|
}
|
|
155
|
+
// Answer a navigating intent with what the document shows now. `ok` is
|
|
156
|
+
// whether the intent itself was accepted, which the version alone cannot
|
|
157
|
+
// say: a checkout the server rounded down and one that was refused both
|
|
158
|
+
// report a version other than the requested one, and the bar keeps the
|
|
159
|
+
// reader's step position for the first and reverts it for the second.
|
|
160
|
+
function confirmIntent(requestId, ok) {
|
|
161
|
+
// An intent settles a turn after it was routed, by which time the bar may
|
|
162
|
+
// have been torn down (the reader closed it, the document changed). There
|
|
163
|
+
// is nothing listening then, and posting into a removed frame is an error
|
|
164
|
+
// that would surface as an unhandled rejection in the app.
|
|
165
|
+
if (!ready || destroyed)
|
|
166
|
+
return;
|
|
167
|
+
const version = deps.currentVersion();
|
|
168
|
+
deliveredVersion = version;
|
|
169
|
+
iframe.contentWindow?.postMessage({
|
|
170
|
+
[EMBED_ENVELOPE]: EMBED_PROTOCOL_VERSION,
|
|
171
|
+
type: 'version-changed',
|
|
172
|
+
version,
|
|
173
|
+
ok,
|
|
174
|
+
...(typeof requestId === 'string' ? { requestId } : {}),
|
|
175
|
+
}, origin);
|
|
176
|
+
}
|
|
177
|
+
// Intents still awaiting their answer. While one is in flight, `update()`
|
|
178
|
+
// stays quiet: the checkout it runs fires the host's subscribers before its
|
|
179
|
+
// promise resolves, so a render lands here ahead of `confirmIntent`, and an
|
|
180
|
+
// uncorrelated `version-changed` posted then reaches the embed as a phantom
|
|
181
|
+
// external move one message before the answer to its own step. The answer
|
|
182
|
+
// reads the live version at settle time, so nothing the quiet window saw is
|
|
183
|
+
// lost.
|
|
184
|
+
let intentsInFlight = 0;
|
|
185
|
+
function runIntent(requestId, intent) {
|
|
186
|
+
intentsInFlight += 1;
|
|
187
|
+
const settle = (ok) => () => {
|
|
188
|
+
// Decremented in every outcome. A count this leaves above zero silences
|
|
189
|
+
// `update()` for the life of the bar, so an external version change
|
|
190
|
+
// would never reach the embed again.
|
|
191
|
+
intentsInFlight -= 1;
|
|
192
|
+
confirmIntent(requestId, ok);
|
|
193
|
+
};
|
|
194
|
+
void intent().then(settle(true), settle(false));
|
|
195
|
+
}
|
|
78
196
|
function onMessage(event) {
|
|
79
197
|
if (event.origin !== origin)
|
|
80
198
|
return;
|
|
81
199
|
if (event.source !== iframe.contentWindow)
|
|
82
200
|
return;
|
|
83
201
|
const data = event.data;
|
|
84
|
-
if (!data || data[
|
|
202
|
+
if (!data || data[EMBED_ENVELOPE] !== EMBED_PROTOCOL_VERSION)
|
|
85
203
|
return;
|
|
86
204
|
switch (data['type']) {
|
|
87
205
|
case 'ready': {
|
|
88
206
|
ready = true;
|
|
207
|
+
if (readyTimer !== undefined) {
|
|
208
|
+
clearTimeout(readyTimer);
|
|
209
|
+
readyTimer = undefined;
|
|
210
|
+
}
|
|
89
211
|
placeholder.style.display = 'none';
|
|
90
212
|
iframe.style.height = `${READY_HEIGHT}px`;
|
|
91
213
|
postInit();
|
|
@@ -100,12 +222,12 @@ export function createVersionBarFrame(root, deps) {
|
|
|
100
222
|
case 'preview': {
|
|
101
223
|
const v = data['version'];
|
|
102
224
|
if (typeof v === 'number' && Number.isInteger(v) && v >= 0) {
|
|
103
|
-
deps.checkoutVersion(v);
|
|
225
|
+
runIntent(data['requestId'], () => deps.checkoutVersion(v));
|
|
104
226
|
}
|
|
105
227
|
break;
|
|
106
228
|
}
|
|
107
229
|
case 'return-to-head': {
|
|
108
|
-
deps.returnToHead();
|
|
230
|
+
runIntent(data['requestId'], () => deps.returnToHead());
|
|
109
231
|
break;
|
|
110
232
|
}
|
|
111
233
|
case 'fork': {
|
|
@@ -125,15 +247,16 @@ export function createVersionBarFrame(root, deps) {
|
|
|
125
247
|
break;
|
|
126
248
|
}
|
|
127
249
|
case 'error': {
|
|
128
|
-
// The embed
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
placeholder.style.display = 'none';
|
|
132
|
-
iframe.style.height = '0';
|
|
250
|
+
// The embed loaded and reported it cannot render (not signed in in
|
|
251
|
+
// this context, an account mismatch).
|
|
252
|
+
enterFallback();
|
|
133
253
|
break;
|
|
134
254
|
}
|
|
135
255
|
}
|
|
136
256
|
}
|
|
257
|
+
// Armed here rather than beside the `src` assignment above, which runs
|
|
258
|
+
// before `readyTimer` is initialised.
|
|
259
|
+
armReadyTimer();
|
|
137
260
|
window.addEventListener('message', onMessage);
|
|
138
261
|
return {
|
|
139
262
|
update(next) {
|
|
@@ -144,25 +267,44 @@ export function createVersionBarFrame(root, deps) {
|
|
|
144
267
|
// just pushes the new version down.
|
|
145
268
|
if (prev && (prev.docId !== next.docId || prev.branch !== next.branch)) {
|
|
146
269
|
// Reload the iframe: reset ready, restore the placeholder, and the
|
|
147
|
-
// new page will `ready` -> we re-`init` with the new context.
|
|
270
|
+
// new page will `ready` -> we re-`init` with the new context. A fresh
|
|
271
|
+
// page gets a fresh verdict, so the failed state resets with it.
|
|
148
272
|
ready = false;
|
|
273
|
+
failed = false;
|
|
149
274
|
deliveredVersion = undefined;
|
|
275
|
+
fallback.hidden = true;
|
|
150
276
|
placeholder.style.display = '';
|
|
151
277
|
iframe.style.height = '0';
|
|
152
278
|
iframe.src = url.toString();
|
|
279
|
+
armReadyTimer();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (failed) {
|
|
283
|
+
renderFallback();
|
|
153
284
|
return;
|
|
154
285
|
}
|
|
155
286
|
// Only an actual version change reaches the embed (dedup), so a
|
|
156
287
|
// re-render that didn't move the version can't clobber the bar's state.
|
|
157
|
-
|
|
288
|
+
// A change while an intent is in flight is that intent's own doing and
|
|
289
|
+
// is delivered by its answer instead.
|
|
290
|
+
if (ready && intentsInFlight === 0 && next.version !== deliveredVersion) {
|
|
158
291
|
deliveredVersion = next.version;
|
|
159
|
-
iframe.contentWindow?.postMessage({ [
|
|
292
|
+
iframe.contentWindow?.postMessage({ [EMBED_ENVELOPE]: EMBED_PROTOCOL_VERSION, type: 'version-changed', version: next.version }, origin);
|
|
160
293
|
}
|
|
161
294
|
},
|
|
162
295
|
destroy() {
|
|
296
|
+
destroyed = true;
|
|
297
|
+
// A bar torn down mid-intent leaves the count standing; a rebuilt bar
|
|
298
|
+
// gets a fresh closure, but this keeps the teardown total.
|
|
299
|
+
intentsInFlight = 0;
|
|
300
|
+
if (readyTimer !== undefined) {
|
|
301
|
+
clearTimeout(readyTimer);
|
|
302
|
+
readyTimer = undefined;
|
|
303
|
+
}
|
|
163
304
|
window.removeEventListener('message', onMessage);
|
|
164
305
|
iframe.remove();
|
|
165
306
|
placeholder.remove();
|
|
307
|
+
fallback.remove();
|
|
166
308
|
},
|
|
167
309
|
};
|
|
168
310
|
}
|
package/dist/version-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-bar.js","sourceRoot":"","sources":["../src/version-bar.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,uEAAuE;AACvE,2EAA2E;AAC3E,2EAA2E;AAC3E,qEAAqE;AACrE,yEAAyE;AACzE,4EAA4E;AAC5E,kCAAkC;AAClC,EAAE;AACF,wDAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"version-bar.js","sourceRoot":"","sources":["../src/version-bar.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,uEAAuE;AACvE,2EAA2E;AAC3E,2EAA2E;AAC3E,qEAAqE;AACrE,yEAAyE;AACzE,4EAA4E;AAC5E,kCAAkC;AAClC,EAAE;AACF,wDAAwD;AACxD,0CAA0C;AAC1C,iEAAiE;AACjE,2EAA2E;AAC3E,+EAA+E;AAC/E,2CAA2C;AAC3C,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,2BAA2B;AAE3B,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,wEAAwE;AACxE,2EAA2E;AAC3E,6DAA6D;AAC7D,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,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ERSION = "0.
|
|
2
|
-
export declare const SDK_CLIENT_ID = "sdk/0.
|
|
1
|
+
export declare const SDK_VERSION = "0.3.0";
|
|
2
|
+
export declare const SDK_CLIENT_ID = "sdk/0.3.0";
|
|
3
3
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
// can measure the version distribution of deployed apps and time
|
|
4
4
|
// compatibility windows against it. A unit test pins this to
|
|
5
5
|
// package.json's version; the release bump touches both together.
|
|
6
|
-
export const SDK_VERSION = '0.
|
|
6
|
+
export const SDK_VERSION = '0.3.0';
|
|
7
7
|
export const SDK_CLIENT_ID = `sdk/${SDK_VERSION}`;
|
|
8
8
|
//# sourceMappingURL=version.js.map
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
+
interface ViteAliasEntry {
|
|
2
|
+
find: string | RegExp;
|
|
3
|
+
replacement: string;
|
|
4
|
+
}
|
|
5
|
+
interface ViteBuildOptions {
|
|
6
|
+
target?: string | string[] | false;
|
|
7
|
+
}
|
|
1
8
|
interface ViteUserConfig {
|
|
9
|
+
build?: ViteBuildOptions;
|
|
10
|
+
environments?: {
|
|
11
|
+
client?: {
|
|
12
|
+
build?: ViteBuildOptions;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
resolve?: {
|
|
16
|
+
alias?: Record<string, string> | readonly ViteAliasEntry[];
|
|
17
|
+
};
|
|
2
18
|
optimizeDeps?: {
|
|
3
19
|
exclude?: string[];
|
|
4
20
|
esbuildOptions?: {
|
|
5
|
-
target?: string;
|
|
21
|
+
target?: string | string[];
|
|
6
22
|
};
|
|
7
23
|
};
|
|
8
24
|
}
|
|
9
25
|
interface VitePlugin {
|
|
10
26
|
name: string;
|
|
11
|
-
config(config: ViteUserConfig): ViteUserConfig
|
|
27
|
+
config(config: ViteUserConfig): Promise<ViteUserConfig>;
|
|
12
28
|
}
|
|
13
29
|
export declare function brassVite(): VitePlugin;
|
|
14
30
|
export {};
|
package/dist/vite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AA+CA,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,KAAK,CAAC;CACpC;AAED,UAAU,cAAc;IACtB,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAGzB,YAAY,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,gBAAgB,CAAA;SAAE,CAAA;KAAE,CAAC;IACzD,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,cAAc,EAAE,CAAC;KAC5D,CAAC;IACF,YAAY,CAAC,EAAE;QACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,cAAc,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;SAAE,CAAC;KACjD,CAAC;CACH;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACzD;AAoGD,wBAAgB,SAAS,IAAI,UAAU,CAwCtC"}
|
package/dist/vite.js
CHANGED
|
@@ -8,23 +8,148 @@
|
|
|
8
8
|
// plugin excludes the dep from prebundling (leaving it for the build-time
|
|
9
9
|
// WASM loaders) and bumps the prebundle target to es2022.
|
|
10
10
|
//
|
|
11
|
-
// `vite-plugin-wasm`
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
// installed during a migration window needs both
|
|
16
|
-
|
|
11
|
+
// `vite-plugin-wasm` remains the caller's responsibility: it must land before
|
|
12
|
+
// `brassVite()` in the plugin list.
|
|
13
|
+
// Every WASM-shipping dep the SDK pulls in, and the entry that loads it
|
|
14
|
+
// asynchronously. Add an entry rather than replacing the list: a consumer who
|
|
15
|
+
// has two installed during a migration window needs both handled, and this is
|
|
16
|
+
// the one place any of them is named, so an app's own config never is.
|
|
17
|
+
//
|
|
18
|
+
// A default browser entry fetches its module with a SYNCHRONOUS
|
|
19
|
+
// XMLHttpRequest while it evaluates, so an app freezes its main thread for the
|
|
20
|
+
// whole download before it paints, whether or not anyone opens a document, and
|
|
21
|
+
// the freeze grows with the reader's latency rather than with the app. An
|
|
22
|
+
// `asyncEntry` hands the same module to the bundler's own asset pipeline,
|
|
23
|
+
// which loads it asynchronously and leaves the main thread free. Selecting one
|
|
24
|
+
// emits a top-level await, so it is reachable only on a build target that
|
|
25
|
+
// accepts one, and the synchronous entry is what keeps every other target
|
|
26
|
+
// building.
|
|
27
|
+
const WASM_DEPS = [
|
|
28
|
+
{ specifier: 'loro-crdt', asyncEntry: 'loro-crdt/bundler' },
|
|
29
|
+
];
|
|
30
|
+
// A specifier matched whole. A string `find` matches by prefix, which would
|
|
31
|
+
// also catch the async entry the alias points AT and resolve it to itself.
|
|
32
|
+
const wholeSpecifier = (specifier) => new RegExp(`^${specifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`);
|
|
33
|
+
// Vite 8 prebundles with rolldown, which handles top-level await on its own
|
|
34
|
+
// and deprecates `optimizeDeps.esbuildOptions`. Setting it there does nothing
|
|
35
|
+
// except print a deprecation warning naming this plugin, on every `vite dev`
|
|
36
|
+
// and every `vite build` a consumer runs. Read from the running Vite rather
|
|
37
|
+
// than from the consumer's manifest, and treat an unreadable version as an
|
|
38
|
+
// older Vite, where the target bump is what makes the WASM dep load at all.
|
|
39
|
+
//
|
|
40
|
+
// The specifier is held in a variable so `tsc` does not resolve it. Vite is
|
|
41
|
+
// neither a dependency nor a peer dependency here (the config shapes above are
|
|
42
|
+
// declared for the same reason), so a literal specifier fails the build
|
|
43
|
+
// wherever Vite is absent, which includes `npm install` in this package
|
|
44
|
+
// itself. At runtime the import reaches the Vite running the build.
|
|
45
|
+
const VITE_PACKAGE = 'vite';
|
|
46
|
+
async function viteMajor() {
|
|
47
|
+
try {
|
|
48
|
+
const { version } = (await import(VITE_PACKAGE));
|
|
49
|
+
const major = Number.parseInt(version ?? '', 10);
|
|
50
|
+
return Number.isFinite(major) ? major : null;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Browser versions that first shipped top-level await, by the engine names
|
|
57
|
+
// esbuild accepts in a target string. A target naming an engine absent here is
|
|
58
|
+
// read as unsupported.
|
|
59
|
+
const TOP_LEVEL_AWAIT_SINCE = {
|
|
60
|
+
chrome: 89,
|
|
61
|
+
edge: 89,
|
|
62
|
+
firefox: 89,
|
|
63
|
+
safari: 15,
|
|
64
|
+
ios: 15,
|
|
65
|
+
opera: 75,
|
|
66
|
+
node: 14.8,
|
|
67
|
+
es: 2022,
|
|
68
|
+
hermes: Number.POSITIVE_INFINITY,
|
|
69
|
+
ie: Number.POSITIVE_INFINITY,
|
|
70
|
+
};
|
|
71
|
+
// Vite's own named targets. `modules` (the Vite 5 / 6 default) resolves to
|
|
72
|
+
// browsers predating top-level await; `baseline-widely-available` (the Vite 7 /
|
|
73
|
+
// 8 default) resolves to ones that carry it.
|
|
74
|
+
const NAMED_TARGET_SUPPORT = {
|
|
75
|
+
esnext: true,
|
|
76
|
+
'baseline-widely-available': true,
|
|
77
|
+
modules: false,
|
|
78
|
+
};
|
|
79
|
+
function targetSupportsTopLevelAwait(target) {
|
|
80
|
+
const t = target.trim().toLowerCase();
|
|
81
|
+
const named = NAMED_TARGET_SUPPORT[t];
|
|
82
|
+
if (named !== undefined)
|
|
83
|
+
return named;
|
|
84
|
+
const parsed = /^([a-z]+)([\d.]+)$/.exec(t);
|
|
85
|
+
if (!parsed)
|
|
86
|
+
return false;
|
|
87
|
+
const since = TOP_LEVEL_AWAIT_SINCE[parsed[1]];
|
|
88
|
+
if (since === undefined)
|
|
89
|
+
return false;
|
|
90
|
+
const version = Number.parseFloat(parsed[2]);
|
|
91
|
+
return Number.isFinite(version) && version >= since;
|
|
92
|
+
}
|
|
93
|
+
// Whether the build this plugin is configuring can carry a top-level await.
|
|
94
|
+
// An unreadable or unrecognised target answers `false`, so the worst a wrong
|
|
95
|
+
// reading costs is the synchronous entry a consumer already has.
|
|
96
|
+
function buildAcceptsTopLevelAwait(config, major) {
|
|
97
|
+
const target = config.environments?.client?.build?.target ?? config.build?.target;
|
|
98
|
+
// No explicit target: the answer is Vite's own default, which carries
|
|
99
|
+
// top-level await from Vite 7 (`baseline-widely-available`) and not before
|
|
100
|
+
// (`modules`).
|
|
101
|
+
if (target === undefined)
|
|
102
|
+
return major !== null && major >= 7;
|
|
103
|
+
if (target === false)
|
|
104
|
+
return false;
|
|
105
|
+
const targets = Array.isArray(target) ? target : [target];
|
|
106
|
+
return targets.length > 0 && targets.every(targetSupportsTopLevelAwait);
|
|
107
|
+
}
|
|
108
|
+
// A consumer who already resolves the WASM dep themselves owns that decision,
|
|
109
|
+
// so the plugin adds nothing that would take it over.
|
|
110
|
+
function aliasesWasmDep(config) {
|
|
111
|
+
const alias = config.resolve?.alias;
|
|
112
|
+
if (!alias)
|
|
113
|
+
return false;
|
|
114
|
+
const specifiers = WASM_DEPS.map((dep) => dep.specifier);
|
|
115
|
+
if (Array.isArray(alias)) {
|
|
116
|
+
return alias.some((entry) => specifiers.some((specifier) => typeof entry.find === 'string'
|
|
117
|
+
? entry.find === specifier
|
|
118
|
+
: entry.find.test(specifier)));
|
|
119
|
+
}
|
|
120
|
+
return Object.keys(alias).some((key) => specifiers.includes(key));
|
|
121
|
+
}
|
|
17
122
|
export function brassVite() {
|
|
18
123
|
return {
|
|
19
124
|
name: 'brass-build:vite',
|
|
20
|
-
config(config) {
|
|
125
|
+
async config(config) {
|
|
126
|
+
const major = await viteMajor();
|
|
127
|
+
const useAsyncEntry = buildAcceptsTopLevelAwait(config, major) && !aliasesWasmDep(config);
|
|
21
128
|
const existingExclude = config.optimizeDeps?.exclude ?? [];
|
|
22
|
-
const exclude = Array.from(new Set([
|
|
129
|
+
const exclude = Array.from(new Set([
|
|
130
|
+
...existingExclude,
|
|
131
|
+
...WASM_DEPS.map((dep) => dep.specifier),
|
|
132
|
+
...(useAsyncEntry ? WASM_DEPS.map((dep) => dep.asyncEntry) : []),
|
|
133
|
+
]));
|
|
134
|
+
const resolve = useAsyncEntry
|
|
135
|
+
? {
|
|
136
|
+
resolve: {
|
|
137
|
+
alias: WASM_DEPS.map((dep) => ({
|
|
138
|
+
find: wholeSpecifier(dep.specifier),
|
|
139
|
+
replacement: dep.asyncEntry,
|
|
140
|
+
})),
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
: {};
|
|
144
|
+
if (major !== null && major >= 8) {
|
|
145
|
+
return { ...resolve, optimizeDeps: { exclude } };
|
|
146
|
+
}
|
|
23
147
|
const existingTarget = config.optimizeDeps?.esbuildOptions?.target;
|
|
24
148
|
// Don't downgrade if a consumer has already pinned a newer
|
|
25
149
|
// target; only raise from the Vite default (which lacks TLA).
|
|
26
150
|
const target = existingTarget ?? 'es2022';
|
|
27
151
|
return {
|
|
152
|
+
...resolve,
|
|
28
153
|
optimizeDeps: {
|
|
29
154
|
exclude,
|
|
30
155
|
esbuildOptions: { target },
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,kEAAkE;AAClE,oBAAoB;AACpB,EAAE;AACF,4EAA4E;AAC5E,uEAAuE;AACvE,0EAA0E;AAC1E,0EAA0E;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gBACH,CAAC,CAAC,EAAE,CAAC;YACP,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACjC,OAAO,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;YACnD,CAAC;YACD,MAAM,cAAc,GAAG,MAAM,CAAC,YAAY,EAAE,cAAc,EAAE,MAAM,CAAC;YACnE,2DAA2D;YAC3D,8DAA8D;YAC9D,MAAM,MAAM,GAAG,cAAc,IAAI,QAAQ,CAAC;YAC1C,OAAO;gBACL,GAAG,OAAO;gBACV,YAAY,EAAE;oBACZ,OAAO;oBACP,cAAc,EAAE,EAAE,MAAM,EAAE;iBAC3B;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when-saved.d.ts","sourceRoot":"","sources":["../src/when-saved.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Waiting out a document's own unsaved ops.
|
|
2
|
+
//
|
|
3
|
+
// `savingCount` counts the ops this client has committed locally and the
|
|
4
|
+
// server has not acked, so a caller that needs the server to hold what the
|
|
5
|
+
// app just wrote waits on it: the import completion, and the checkpoint
|
|
6
|
+
// anchor, both of which describe a state rather than an intention.
|
|
7
|
+
// How often the wait re-checks. A closing document drops its subscribers
|
|
8
|
+
// without firing them, so this is the only thing that ends the wait for one
|
|
9
|
+
// that goes while writes are draining.
|
|
10
|
+
const SAVED_POLL_MS = 1_000;
|
|
11
|
+
// How long the OLDEST outstanding op may go unacked before the wait gives
|
|
12
|
+
// up. An op the server never received is never acked and never re-sent
|
|
13
|
+
// beyond the transport's own attempts, and `savingCount` then stays above
|
|
14
|
+
// zero for the document's life, so a wait with no bound hangs its caller
|
|
15
|
+
// forever. Read off the oldest op rather than off elapsed time, so a bulk
|
|
16
|
+
// write that takes minutes never trips it: there, every op acks promptly
|
|
17
|
+
// and the oldest is always young. Three forced-resend cycles wide (the
|
|
18
|
+
// transport forces one at 60s), so the wait outlasts the recovery it is
|
|
19
|
+
// waiting on.
|
|
20
|
+
const SAVED_STALL_MS = 180_000;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve `true` once the document has no locally-issued op waiting for its
|
|
23
|
+
* server ack; `false` when the document is no longer live, or the acks
|
|
24
|
+
* stopped arriving.
|
|
25
|
+
*
|
|
26
|
+
* `false` does not say the writes were lost, only that this wait cannot say
|
|
27
|
+
* they landed. A caller about to record something permanent against them (an
|
|
28
|
+
* import completion, a checkpoint anchor) has to stop on it.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export function whenSaved(doc) {
|
|
33
|
+
if (doc.savingCount === 0)
|
|
34
|
+
return Promise.resolve(true);
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
let off;
|
|
37
|
+
let poll;
|
|
38
|
+
const settle = (saved) => {
|
|
39
|
+
off?.();
|
|
40
|
+
if (poll !== undefined)
|
|
41
|
+
clearInterval(poll);
|
|
42
|
+
resolve(saved);
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
off = doc.subscribe(() => {
|
|
46
|
+
if (doc.savingCount === 0)
|
|
47
|
+
settle(true);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// The document closed, so nothing more is going to be acked.
|
|
52
|
+
resolve(false);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
poll = setInterval(() => {
|
|
56
|
+
if (doc.savingCount === 0)
|
|
57
|
+
return settle(true);
|
|
58
|
+
if (!doc._isLive)
|
|
59
|
+
return settle(false);
|
|
60
|
+
if (doc.diagnostics().oldestUnackedMs >= SAVED_STALL_MS)
|
|
61
|
+
settle(false);
|
|
62
|
+
}, SAVED_POLL_MS);
|
|
63
|
+
// Node keeps the process alive for a pending interval; this one is
|
|
64
|
+
// bookkeeping for a wait that ends on its own, so it must not.
|
|
65
|
+
poll.unref?.();
|
|
66
|
+
if (doc.savingCount === 0)
|
|
67
|
+
settle(true);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=when-saved.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"when-saved.js","sourceRoot":"","sources":["../src/when-saved.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,wEAAwE;AACxE,mEAAmE;AAInE,yEAAyE;AACzE,4EAA4E;AAC5E,uCAAuC;AACvC,MAAM,aAAa,GAAG,KAAK,CAAC;AAE5B,0EAA0E;AAC1E,uEAAuE;AACvE,0EAA0E;AAC1E,yEAAyE;AACzE,0EAA0E;AAC1E,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,cAAc;AACd,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,GAAa;IACrC,IAAI,GAAG,CAAC,WAAW,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,EAAE;QACtC,IAAI,GAA6B,CAAC;QAClC,IAAI,IAAgD,CAAC;QACrD,MAAM,MAAM,GAAG,CAAC,KAAc,EAAQ,EAAE;YACtC,GAAG,EAAE,EAAE,CAAC;YACR,IAAI,IAAI,KAAK,SAAS;gBAAE,aAAa,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,CAAC;QACF,IAAI,CAAC;YACH,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;gBACvB,IAAI,GAAG,CAAC,WAAW,KAAK,CAAC;oBAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,6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