@marimo-team/marimo-export 0.0.5 → 0.0.7
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/{export-DHoEAsST.mjs → export-I-cltoel.mjs} +1 -1
- package/dist/{index-DXgOo60T.d.mts → index-BANdm_iS.d.mts} +7 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -3
- package/dist/loader/anywidget.d.mts +1 -46
- package/dist/loader/anywidget.mjs +2 -325
- package/dist/prepared/index.mjs +23 -5
- package/dist/{src-BL2Hd1uM.mjs → src-KJppsrIe.mjs} +54 -1
- package/package.json +4 -2
|
@@ -820,4 +820,4 @@ function equalBytes(left, right) {
|
|
|
820
820
|
return left.byteLength === right.byteLength && left.every((byte, index) => byte === right[index]);
|
|
821
821
|
}
|
|
822
822
|
//#endregion
|
|
823
|
-
export { normalizeBase as n, openExport as t };
|
|
823
|
+
export { normalizeBase as n, isAbortError as r, openExport as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as NotebookExport, I as ScalarValue, O as OpenExportOptions, b as MediaType, j as OutputLoader, k as OutputCodec, m as ExportOutput, o as BlobAssetLoadInput, s as BlobAssetLoader, t as AnyOutputLoader, x as MountableValue } from "./types-D52GHn1Q.mjs";
|
|
1
|
+
import { C as NotebookExport, I as ScalarValue, O as OpenExportOptions, _ as LoadOptions, b as MediaType, h as ExportState, j as OutputLoader, k as OutputCodec, m as ExportOutput, o as BlobAssetLoadInput, s as BlobAssetLoader, t as AnyOutputLoader, x as MountableValue } from "./types-D52GHn1Q.mjs";
|
|
2
2
|
import { h as MarimoReplayResources, m as MarimoOutputSnapshot, o as MarimoCellSnapshot } from "./marimo-snapshot-Df66Xan0.mjs";
|
|
3
3
|
//#region src/loader.d.ts
|
|
4
4
|
declare function defineOutputLoader<C extends OutputCodec, T>(loader: OutputLoader<C, T>): OutputLoader<C, T>;
|
|
@@ -13,8 +13,13 @@ declare function imageLoader(): BlobAssetLoader<MountableValue>;
|
|
|
13
13
|
//#region src/export.d.ts
|
|
14
14
|
declare function openExport(base: string | URL, options?: OpenExportOptions): Promise<NotebookExport>;
|
|
15
15
|
//#endregion
|
|
16
|
+
//#region src/load-outputs.d.ts
|
|
17
|
+
type LoadedOutputs<Loaders extends Readonly<Record<string, AnyOutputLoader>>> = { readonly [Name in keyof Loaders]: Awaited<ReturnType<Loaders[Name]["load"]>>; };
|
|
18
|
+
/** Load a state's selected outputs and settle sibling requests after a failure. */
|
|
19
|
+
declare function loadOutputs<const Loaders extends Readonly<Record<string, AnyOutputLoader>>>(state: ExportState, loaders: Loaders, options?: LoadOptions): Promise<LoadedOutputs<Loaders>>;
|
|
20
|
+
//#endregion
|
|
16
21
|
//#region src/replay-resources.d.ts
|
|
17
22
|
/** Compose snapshot resources while preserving every source's replay order. */
|
|
18
23
|
declare function mergeMarimoReplayResources(snapshots: readonly (MarimoOutputSnapshot | MarimoCellSnapshot)[]): MarimoReplayResources;
|
|
19
24
|
//#endregion
|
|
20
|
-
export {
|
|
25
|
+
export { defineOutputLoader as a, scalarLoader as c, defineBlobAssetLoader as i, loadOutputs as n, imageLoader as o, openExport as r, resolveOutputLoader as s, mergeMarimoReplayResources as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { A as OutputDescriptor, B as JsonObject, C as NotebookExport, D as NumpyDescriptor, E as NotebookProvenance, F as ScalarDescriptor, H as JsonValue, I as ScalarValue, L as VerificationResult, M as OutputPayloadMap, N as ProducerProvenance, O as OpenExportOptions, P as Provenance, R as VerifyOptions, S as MountedView, T as NotebookExportErrorCode, V as JsonPrimitive, _ as LoadOptions, a as BlobAssetDescriptor, b as MediaType, c as ControlBinding, d as ControlKeyStep, f as ControlPathStep, g as JsonDescriptor, h as ExportState, i as BlobAsset, j as OutputLoader, k as OutputCodec, l as ControlElementStep, m as ExportOutput, n as ArrowDescriptor, o as BlobAssetLoadInput, p as DescriptorFor, r as AssetDescriptor, s as BlobAssetLoader, t as AnyOutputLoader, u as ControlIndexStep, v as MarimoCellDescriptor, w as NotebookExportError, x as MountableValue, y as MarimoOutputDescriptor, z as isNotebookExportError } from "./types-D52GHn1Q.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as defineOutputLoader, c as scalarLoader, i as defineBlobAssetLoader, n as loadOutputs, o as imageLoader, r as openExport, s as resolveOutputLoader, t as mergeMarimoReplayResources } from "./index-BANdm_iS.mjs";
|
|
3
3
|
import { _ as parseMarimoOutputSnapshot, a as MarimoCellOutput, c as MarimoModelCloseMessage, d as MarimoModelLifecycleNotification, f as MarimoModelOpenMessage, g as parseMarimoCellSnapshot, h as MarimoReplayResources, i as MarimoCellIdentity, l as MarimoModelCustomMessage, m as MarimoOutputSnapshot, n as MarimoBufferPathToken, o as MarimoCellSnapshot, p as MarimoModelUpdateMessage, r as MarimoCellChannel, s as MarimoEsmSpec, t as MarimoBufferPath, u as MarimoModelLifecycleMessage } from "./marimo-snapshot-Df66Xan0.mjs";
|
|
4
|
-
export { type AnyOutputLoader, type ArrowDescriptor, type AssetDescriptor, type BlobAsset, type BlobAssetDescriptor, type BlobAssetLoadInput, type BlobAssetLoader, type ControlBinding, type ControlElementStep, type ControlIndexStep, type ControlKeyStep, type ControlPathStep, type DescriptorFor, type ExportOutput, type ExportState, type JsonDescriptor, type JsonObject, type JsonPrimitive, type JsonValue, type LoadOptions, type MarimoBufferPath, type MarimoBufferPathToken, type MarimoCellChannel, type MarimoCellDescriptor, type MarimoCellIdentity, type MarimoCellOutput, type MarimoCellSnapshot, type MarimoEsmSpec, type MarimoModelCloseMessage, type MarimoModelCustomMessage, type MarimoModelLifecycleMessage, type MarimoModelLifecycleNotification, type MarimoModelOpenMessage, type MarimoModelUpdateMessage, type MarimoOutputDescriptor, type MarimoOutputSnapshot, type MarimoReplayResources, type MediaType, type MountableValue, type MountedView, type NotebookExport, NotebookExportError, type NotebookExportErrorCode, type NotebookProvenance, type NumpyDescriptor, type OpenExportOptions, type OutputCodec, type OutputDescriptor, type OutputLoader, type OutputPayloadMap, type ProducerProvenance, type Provenance, type ScalarDescriptor, type ScalarValue, type VerificationResult, type VerifyOptions, defineBlobAssetLoader, defineOutputLoader, imageLoader, isNotebookExportError, mergeMarimoReplayResources, openExport, parseMarimoCellSnapshot, parseMarimoOutputSnapshot, resolveOutputLoader, scalarLoader };
|
|
4
|
+
export { type AnyOutputLoader, type ArrowDescriptor, type AssetDescriptor, type BlobAsset, type BlobAssetDescriptor, type BlobAssetLoadInput, type BlobAssetLoader, type ControlBinding, type ControlElementStep, type ControlIndexStep, type ControlKeyStep, type ControlPathStep, type DescriptorFor, type ExportOutput, type ExportState, type JsonDescriptor, type JsonObject, type JsonPrimitive, type JsonValue, type LoadOptions, type MarimoBufferPath, type MarimoBufferPathToken, type MarimoCellChannel, type MarimoCellDescriptor, type MarimoCellIdentity, type MarimoCellOutput, type MarimoCellSnapshot, type MarimoEsmSpec, type MarimoModelCloseMessage, type MarimoModelCustomMessage, type MarimoModelLifecycleMessage, type MarimoModelLifecycleNotification, type MarimoModelOpenMessage, type MarimoModelUpdateMessage, type MarimoOutputDescriptor, type MarimoOutputSnapshot, type MarimoReplayResources, type MediaType, type MountableValue, type MountedView, type NotebookExport, NotebookExportError, type NotebookExportErrorCode, type NotebookProvenance, type NumpyDescriptor, type OpenExportOptions, type OutputCodec, type OutputDescriptor, type OutputLoader, type OutputPayloadMap, type ProducerProvenance, type Provenance, type ScalarDescriptor, type ScalarValue, type VerificationResult, type VerifyOptions, defineBlobAssetLoader, defineOutputLoader, imageLoader, isNotebookExportError, loadOutputs, mergeMarimoReplayResources, openExport, parseMarimoCellSnapshot, parseMarimoOutputSnapshot, resolveOutputLoader, scalarLoader };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as scalarLoader, c as isNotebookExportError, i as resolveOutputLoader, n as defineOutputLoader, r as imageLoader, s as NotebookExportError, t as defineBlobAssetLoader } from "./loader-BTeU85BE.mjs";
|
|
2
|
-
import { t as openExport } from "./export-
|
|
2
|
+
import { t as openExport } from "./export-I-cltoel.mjs";
|
|
3
|
+
import { n as loadOutputs, t as mergeMarimoReplayResources } from "./src-KJppsrIe.mjs";
|
|
3
4
|
import { n as parseMarimoOutputSnapshot, t as parseMarimoCellSnapshot } from "./marimo-snapshot-B2eNp-aW.mjs";
|
|
4
|
-
|
|
5
|
-
export { NotebookExportError, defineBlobAssetLoader, defineOutputLoader, imageLoader, isNotebookExportError, mergeMarimoReplayResources, openExport, parseMarimoCellSnapshot, parseMarimoOutputSnapshot, resolveOutputLoader, scalarLoader };
|
|
5
|
+
export { NotebookExportError, defineBlobAssetLoader, defineOutputLoader, imageLoader, isNotebookExportError, loadOutputs, mergeMarimoReplayResources, openExport, parseMarimoCellSnapshot, parseMarimoOutputSnapshot, resolveOutputLoader, scalarLoader };
|
|
@@ -12,51 +12,6 @@ interface AnyWidgetMountOptions {
|
|
|
12
12
|
readonly signal?: AbortSignal;
|
|
13
13
|
}
|
|
14
14
|
//#endregion
|
|
15
|
-
//#region ../loader-anywidget/src/runtime/prepared-graph.d.ts
|
|
16
|
-
interface PreparedWidgetGraphSnapshot<Record> {
|
|
17
|
-
readonly files: Readonly<{
|
|
18
|
-
[path: string]: string;
|
|
19
|
-
}>;
|
|
20
|
-
readonly records: ReadonlyMap<string, Record>;
|
|
21
|
-
}
|
|
22
|
-
declare const preparedWidgetGraphCheckpoint: unique symbol;
|
|
23
|
-
interface PreparedWidgetGraphCheckpoint<Record> {
|
|
24
|
-
readonly [preparedWidgetGraphCheckpoint]: Record;
|
|
25
|
-
}
|
|
26
|
-
interface PreparedWidgetGraphPort<Record, LiveState> {
|
|
27
|
-
id(record: Record): string;
|
|
28
|
-
active(record: Record): boolean;
|
|
29
|
-
same(left: Record, right: Record): boolean;
|
|
30
|
-
changesModule(previous: Record, next: Record): boolean;
|
|
31
|
-
capture(id: string): LiveState;
|
|
32
|
-
merge(record: Record, state: LiveState): Record;
|
|
33
|
-
replay(records: readonly Record[], signal?: AbortSignal): Promise<void>;
|
|
34
|
-
restore(id: string, state: LiveState): void | Promise<void>;
|
|
35
|
-
close(id: string): Promise<void>;
|
|
36
|
-
setFiles(files: Readonly<{
|
|
37
|
-
[path: string]: string;
|
|
38
|
-
}>): void;
|
|
39
|
-
validate?(record: Record, signal?: AbortSignal): Promise<void>;
|
|
40
|
-
preflight?(record: Record, signal?: AbortSignal): Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
interface PreparedWidgetGraphReplacement<Record> {
|
|
43
|
-
readonly mutated: boolean;
|
|
44
|
-
readonly remount: boolean;
|
|
45
|
-
commit(): Promise<PreparedWidgetGraphSnapshot<Record> | undefined>;
|
|
46
|
-
rollback(): Promise<void>;
|
|
47
|
-
}
|
|
48
|
-
declare class PreparedWidgetGraphReplacementError extends Error {
|
|
49
|
-
readonly remount = true;
|
|
50
|
-
constructor(cause: Error);
|
|
51
|
-
}
|
|
52
|
-
declare class PreparedWidgetGraph<Record, LiveState> {
|
|
53
|
-
#private;
|
|
54
|
-
constructor(port: PreparedWidgetGraphPort<Record, LiveState>, initial?: PreparedWidgetGraphSnapshot<Record>);
|
|
55
|
-
checkpoint(): PreparedWidgetGraphCheckpoint<Record>;
|
|
56
|
-
replace(target: PreparedWidgetGraphSnapshot<Record> | PreparedWidgetGraphCheckpoint<Record>, signal?: AbortSignal): Promise<PreparedWidgetGraphReplacement<Record>>;
|
|
57
|
-
dispose(): Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
15
|
//#region ../loader-anywidget/src/index.d.ts
|
|
61
16
|
type AnyWidgetStateShape<State> = ModelShape<State>;
|
|
62
17
|
interface MountedAnyWidget<State extends AnyWidgetStateShape<State> = ModelState, Exports extends object | undefined = object | undefined> {
|
|
@@ -73,4 +28,4 @@ interface LoadedAnyWidget<State extends AnyWidgetStateShape<State> = ModelState,
|
|
|
73
28
|
/** Decode an exported AnyWidget value and prepare it for browser mounting. */
|
|
74
29
|
declare const anyWidgetLoader: <State extends AnyWidgetStateShape<State> = ModelState, Exports extends object | undefined = object | undefined>() => BlobAssetLoader<LoadedAnyWidget<State, Exports>>;
|
|
75
30
|
//#endregion
|
|
76
|
-
export { type AnyModel, type AnyWidgetMountOptions, type AnyWidgetStateShape, type LoadedAnyWidget, type ModelState, type MountedAnyWidget,
|
|
31
|
+
export { type AnyModel, type AnyWidgetMountOptions, type AnyWidgetStateShape, type LoadedAnyWidget, type ModelState, type MountedAnyWidget, anyWidgetLoader };
|
|
@@ -50,7 +50,7 @@ function parseAnyWidgetPayload(value) {
|
|
|
50
50
|
"files",
|
|
51
51
|
"modelNotifications"
|
|
52
52
|
], "payload");
|
|
53
|
-
if (payload.schema !==
|
|
53
|
+
if (payload.schema !== ANYWIDGET_SCHEMA) throw new TypeError(`AnyWidget payload schema must be ${JSON.stringify(ANYWIDGET_SCHEMA)}.`);
|
|
54
54
|
const rootModelId = nonEmptyString(payload.rootModelId, "rootModelId");
|
|
55
55
|
if (rootModelId !== "model-0") throw new TypeError("AnyWidget payload rootModelId must be \"model-0\".");
|
|
56
56
|
const files = parseFiles(payload.files);
|
|
@@ -1214,329 +1214,6 @@ function assertBrowserElement(element) {
|
|
|
1214
1214
|
if (globalThis.document === void 0 || globalThis.window === void 0 || !isPropertyOwner(element) || element.nodeType !== 1 || !("replaceChildren" in element)) throw new TypeError("AnyWidget mount requires a browser element.");
|
|
1215
1215
|
}
|
|
1216
1216
|
//#endregion
|
|
1217
|
-
//#region ../loader-anywidget/src/runtime/prepared-graph.ts
|
|
1218
|
-
var PreparedWidgetGraphReplacementError = class extends Error {
|
|
1219
|
-
remount = true;
|
|
1220
|
-
constructor(cause) {
|
|
1221
|
-
super("Prepared AnyWidget graph replacement requires a full remount", { cause });
|
|
1222
|
-
this.name = "PreparedWidgetGraphReplacementError";
|
|
1223
|
-
}
|
|
1224
|
-
};
|
|
1225
|
-
const emptyGraph = () => ({
|
|
1226
|
-
files: Object.freeze({}),
|
|
1227
|
-
records: /* @__PURE__ */ new Map()
|
|
1228
|
-
});
|
|
1229
|
-
const graphFailure = (cause) => cause instanceof Error ? cause : new Error(String(cause));
|
|
1230
|
-
const sameFiles = (left, right) => {
|
|
1231
|
-
const leftNames = Object.keys(left);
|
|
1232
|
-
const rightNames = Object.keys(right);
|
|
1233
|
-
return leftNames.length === rightNames.length && leftNames.every((name) => Object.hasOwn(right, name) && left[name] === right[name]);
|
|
1234
|
-
};
|
|
1235
|
-
const snapshotCopy = (snapshot, port) => {
|
|
1236
|
-
const records = /* @__PURE__ */ new Map();
|
|
1237
|
-
snapshot.records.forEach((record, key) => {
|
|
1238
|
-
const id = port.id(record);
|
|
1239
|
-
if (id !== key) throw new Error(`Prepared AnyWidget graph record ${JSON.stringify(key)} has identity ${JSON.stringify(id)}`);
|
|
1240
|
-
records.set(id, record);
|
|
1241
|
-
});
|
|
1242
|
-
return Object.freeze({
|
|
1243
|
-
files: Object.freeze({ ...snapshot.files }),
|
|
1244
|
-
records
|
|
1245
|
-
});
|
|
1246
|
-
};
|
|
1247
|
-
const changesFor = (previous, next, port) => {
|
|
1248
|
-
const additions = [];
|
|
1249
|
-
const stableUpdates = [];
|
|
1250
|
-
const replacements = [];
|
|
1251
|
-
next.records.forEach((record, id) => {
|
|
1252
|
-
if (!port.active(record)) return;
|
|
1253
|
-
const current = previous.records.get(id);
|
|
1254
|
-
if (current === void 0 || !port.active(current)) {
|
|
1255
|
-
additions.push(record);
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
if (port.same(current, record)) return;
|
|
1259
|
-
if (port.changesModule(current, record)) replacements.push(record);
|
|
1260
|
-
else stableUpdates.push(record);
|
|
1261
|
-
});
|
|
1262
|
-
return {
|
|
1263
|
-
additions,
|
|
1264
|
-
stableUpdates,
|
|
1265
|
-
replacements,
|
|
1266
|
-
removals: []
|
|
1267
|
-
};
|
|
1268
|
-
};
|
|
1269
|
-
const currentRecordActive = (next, id, port) => {
|
|
1270
|
-
const record = next.records.get(id);
|
|
1271
|
-
return record !== void 0 && port.active(record);
|
|
1272
|
-
};
|
|
1273
|
-
const plannedChanges = (previous, next, port) => {
|
|
1274
|
-
return {
|
|
1275
|
-
...changesFor(previous, next, port),
|
|
1276
|
-
removals: [...previous.records.entries()].filter(([id, record]) => port.active(record) && !currentRecordActive(next, id, port)).map(([, record]) => record)
|
|
1277
|
-
};
|
|
1278
|
-
};
|
|
1279
|
-
const captureStates = (changes, port) => {
|
|
1280
|
-
const capture = (records) => new Map(records.map((record) => [port.id(record), port.capture(port.id(record))]));
|
|
1281
|
-
return {
|
|
1282
|
-
stable: capture(changes.stableUpdates),
|
|
1283
|
-
replacements: capture(changes.replacements),
|
|
1284
|
-
removals: capture(changes.removals)
|
|
1285
|
-
};
|
|
1286
|
-
};
|
|
1287
|
-
const attempt = async (errors, action) => {
|
|
1288
|
-
try {
|
|
1289
|
-
await action();
|
|
1290
|
-
} catch (error) {
|
|
1291
|
-
errors.push(graphFailure(error));
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
const eachSequential = async (values, action) => {
|
|
1295
|
-
for (const value of values) await action(value);
|
|
1296
|
-
};
|
|
1297
|
-
const throwCleanup = (errors, message) => {
|
|
1298
|
-
if (errors.length === 1) throw errors[0];
|
|
1299
|
-
if (errors.length > 1) throw new AggregateError(errors, message);
|
|
1300
|
-
};
|
|
1301
|
-
const settledReplacement = (mutated, remount, settle) => {
|
|
1302
|
-
let committed = false;
|
|
1303
|
-
let commitFailure;
|
|
1304
|
-
let commitTask;
|
|
1305
|
-
let rollbackTask;
|
|
1306
|
-
return Object.freeze({
|
|
1307
|
-
mutated,
|
|
1308
|
-
remount,
|
|
1309
|
-
commit() {
|
|
1310
|
-
if (rollbackTask !== void 0) return rollbackTask.then(() => void 0);
|
|
1311
|
-
commitTask ??= Promise.resolve().then(() => settle(true)).then((result) => {
|
|
1312
|
-
committed = true;
|
|
1313
|
-
return result;
|
|
1314
|
-
}).catch((cause) => {
|
|
1315
|
-
commitFailure = graphFailure(cause);
|
|
1316
|
-
throw cause;
|
|
1317
|
-
});
|
|
1318
|
-
return commitTask;
|
|
1319
|
-
},
|
|
1320
|
-
rollback() {
|
|
1321
|
-
rollbackTask ??= (commitTask ?? Promise.resolve()).catch(() => {}).then(async () => {
|
|
1322
|
-
if (committed) return;
|
|
1323
|
-
try {
|
|
1324
|
-
await settle(false);
|
|
1325
|
-
} catch (error) {
|
|
1326
|
-
throw new PreparedWidgetGraphReplacementError(commitFailure === void 0 ? graphFailure(error) : new AggregateError([commitFailure, graphFailure(error)], "Prepared AnyWidget graph commit and rollback failed"));
|
|
1327
|
-
}
|
|
1328
|
-
});
|
|
1329
|
-
return rollbackTask;
|
|
1330
|
-
}
|
|
1331
|
-
});
|
|
1332
|
-
};
|
|
1333
|
-
var PreparedWidgetGraph = class {
|
|
1334
|
-
#checkpoints = /* @__PURE__ */ new WeakMap();
|
|
1335
|
-
#port;
|
|
1336
|
-
#current;
|
|
1337
|
-
#active;
|
|
1338
|
-
#operation;
|
|
1339
|
-
#pending;
|
|
1340
|
-
#disposed = false;
|
|
1341
|
-
#disposal;
|
|
1342
|
-
constructor(port, initial = emptyGraph()) {
|
|
1343
|
-
this.#port = port;
|
|
1344
|
-
this.#current = snapshotCopy(initial, port);
|
|
1345
|
-
this.#port.setFiles(this.#current.files);
|
|
1346
|
-
}
|
|
1347
|
-
checkpoint() {
|
|
1348
|
-
this.#requireIdle();
|
|
1349
|
-
const records = new Map(this.#current.records);
|
|
1350
|
-
this.#current.records.forEach((record, id) => {
|
|
1351
|
-
if (this.#port.active(record)) records.set(id, this.#port.merge(record, this.#port.capture(id)));
|
|
1352
|
-
});
|
|
1353
|
-
const snapshot = snapshotCopy({
|
|
1354
|
-
files: this.#current.files,
|
|
1355
|
-
records
|
|
1356
|
-
}, this.#port);
|
|
1357
|
-
const checkpoint = Object.freeze({});
|
|
1358
|
-
this.#checkpoints.set(checkpoint, {
|
|
1359
|
-
snapshot,
|
|
1360
|
-
source: this.#current
|
|
1361
|
-
});
|
|
1362
|
-
return checkpoint;
|
|
1363
|
-
}
|
|
1364
|
-
replace(target, signal) {
|
|
1365
|
-
if (signal?.aborted) return Promise.reject(abortReason(signal, "Prepared AnyWidget graph replacement aborted"));
|
|
1366
|
-
if (this.#disposed) return Promise.resolve(settledReplacement(false, false, () => void 0));
|
|
1367
|
-
this.#requireIdle();
|
|
1368
|
-
const controller = new AbortController();
|
|
1369
|
-
const abort = () => {
|
|
1370
|
-
if (signal !== void 0) controller.abort(abortReason(signal, "Prepared AnyWidget graph replacement aborted"));
|
|
1371
|
-
};
|
|
1372
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
1373
|
-
if (signal?.aborted) abort();
|
|
1374
|
-
this.#active = controller;
|
|
1375
|
-
const operation = this.#replace(target, controller.signal);
|
|
1376
|
-
this.#operation = operation;
|
|
1377
|
-
return operation.finally(() => {
|
|
1378
|
-
signal?.removeEventListener("abort", abort);
|
|
1379
|
-
if (this.#active === controller) this.#active = void 0;
|
|
1380
|
-
if (this.#operation === operation) this.#operation = void 0;
|
|
1381
|
-
});
|
|
1382
|
-
}
|
|
1383
|
-
dispose() {
|
|
1384
|
-
this.#disposal ??= this.#dispose();
|
|
1385
|
-
return this.#disposal;
|
|
1386
|
-
}
|
|
1387
|
-
async #replace(target, signal) {
|
|
1388
|
-
const checkpoint = this.#checkpoints.get(target);
|
|
1389
|
-
const value = checkpoint === void 0 ? target : checkpoint.snapshot;
|
|
1390
|
-
const next = snapshotCopy(value, this.#port);
|
|
1391
|
-
const adopt = checkpoint?.source ?? next;
|
|
1392
|
-
const previous = this.#current;
|
|
1393
|
-
const changes = plannedChanges(previous, next, this.#port);
|
|
1394
|
-
if (!(!sameFiles(previous.files, next.files) || changes.additions.length > 0 || changes.stableUpdates.length > 0 || changes.replacements.length > 0 || changes.removals.length > 0)) return this.#replacement(false, false, () => {
|
|
1395
|
-
this.#current = adopt;
|
|
1396
|
-
return adopt;
|
|
1397
|
-
});
|
|
1398
|
-
return this.#stage(previous, next, adopt, changes, signal);
|
|
1399
|
-
}
|
|
1400
|
-
async #stage(previous, next, adopt, changes, signal) {
|
|
1401
|
-
this.#port.setFiles({
|
|
1402
|
-
...previous.files,
|
|
1403
|
-
...next.files
|
|
1404
|
-
});
|
|
1405
|
-
try {
|
|
1406
|
-
await this.#preflight(changes, signal);
|
|
1407
|
-
} catch (error) {
|
|
1408
|
-
this.#port.setFiles(previous.files);
|
|
1409
|
-
throw error;
|
|
1410
|
-
}
|
|
1411
|
-
let live;
|
|
1412
|
-
try {
|
|
1413
|
-
live = captureStates(changes, this.#port);
|
|
1414
|
-
} catch (error) {
|
|
1415
|
-
this.#port.setFiles(previous.files);
|
|
1416
|
-
throw error;
|
|
1417
|
-
}
|
|
1418
|
-
const added = /* @__PURE__ */ new Set();
|
|
1419
|
-
const replaced = /* @__PURE__ */ new Set();
|
|
1420
|
-
const removed = /* @__PURE__ */ new Set();
|
|
1421
|
-
const rollback = () => this.#rollback(previous, changes, live, added, replaced, removed);
|
|
1422
|
-
let remount = false;
|
|
1423
|
-
try {
|
|
1424
|
-
const replay = /* @__PURE__ */ new Map();
|
|
1425
|
-
await eachSequential(changes.replacements, async (record) => {
|
|
1426
|
-
signal.throwIfAborted();
|
|
1427
|
-
const id = this.#port.id(record);
|
|
1428
|
-
const state = live.replacements.get(id);
|
|
1429
|
-
replaced.add(id);
|
|
1430
|
-
remount = true;
|
|
1431
|
-
await this.#port.close(id);
|
|
1432
|
-
replay.set(id, this.#port.merge(record, state));
|
|
1433
|
-
});
|
|
1434
|
-
changes.additions.forEach((record) => {
|
|
1435
|
-
const id = this.#port.id(record);
|
|
1436
|
-
added.add(id);
|
|
1437
|
-
replay.set(id, record);
|
|
1438
|
-
});
|
|
1439
|
-
changes.stableUpdates.forEach((record) => replay.set(this.#port.id(record), record));
|
|
1440
|
-
signal.throwIfAborted();
|
|
1441
|
-
const records = [...next.records.keys()].flatMap((id) => {
|
|
1442
|
-
const record = replay.get(id);
|
|
1443
|
-
return record === void 0 ? [] : [record];
|
|
1444
|
-
});
|
|
1445
|
-
if (records.length > 0) await this.#port.replay(records, signal);
|
|
1446
|
-
signal.throwIfAborted();
|
|
1447
|
-
} catch (error) {
|
|
1448
|
-
const failure = graphFailure(error);
|
|
1449
|
-
try {
|
|
1450
|
-
await rollback();
|
|
1451
|
-
} catch (rollbackError) {
|
|
1452
|
-
throw new PreparedWidgetGraphReplacementError(new AggregateError([failure, graphFailure(rollbackError)], "Prepared AnyWidget graph replacement and rollback failed"));
|
|
1453
|
-
}
|
|
1454
|
-
if (remount) throw new PreparedWidgetGraphReplacementError(failure);
|
|
1455
|
-
throw failure;
|
|
1456
|
-
}
|
|
1457
|
-
return this.#replacement(true, changes.replacements.length > 0, async (commit) => {
|
|
1458
|
-
if (!commit) {
|
|
1459
|
-
await rollback();
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
|
-
await eachSequential(changes.removals, async (record) => {
|
|
1463
|
-
const id = this.#port.id(record);
|
|
1464
|
-
removed.add(id);
|
|
1465
|
-
await this.#port.close(id);
|
|
1466
|
-
});
|
|
1467
|
-
this.#port.setFiles(next.files);
|
|
1468
|
-
this.#current = adopt;
|
|
1469
|
-
return adopt;
|
|
1470
|
-
});
|
|
1471
|
-
}
|
|
1472
|
-
async #preflight(changes, signal) {
|
|
1473
|
-
await eachSequential([
|
|
1474
|
-
...changes.additions,
|
|
1475
|
-
...changes.stableUpdates,
|
|
1476
|
-
...changes.replacements
|
|
1477
|
-
], async (record) => {
|
|
1478
|
-
signal.throwIfAborted();
|
|
1479
|
-
await this.#port.validate?.(record, signal);
|
|
1480
|
-
});
|
|
1481
|
-
await eachSequential([...changes.additions, ...changes.replacements], async (record) => {
|
|
1482
|
-
signal.throwIfAborted();
|
|
1483
|
-
await this.#port.preflight?.(record, signal);
|
|
1484
|
-
});
|
|
1485
|
-
signal.throwIfAborted();
|
|
1486
|
-
}
|
|
1487
|
-
async #rollback(previous, changes, live, added, replaced, removed) {
|
|
1488
|
-
this.#port.setFiles(previous.files);
|
|
1489
|
-
const errors = [];
|
|
1490
|
-
await eachSequential(added, (id) => attempt(errors, () => this.#port.close(id)));
|
|
1491
|
-
await eachSequential(live.stable, ([id, state]) => attempt(errors, () => this.#port.restore(id, state)));
|
|
1492
|
-
await this.#replayPrevious(errors, previous, new Map([...live.replacements, ...live.removals]), /* @__PURE__ */ new Set([...replaced, ...removed]));
|
|
1493
|
-
throwCleanup(errors, "Prepared AnyWidget graph rollback failed");
|
|
1494
|
-
}
|
|
1495
|
-
async #replayPrevious(errors, previous, states, ids) {
|
|
1496
|
-
await eachSequential(ids, (id) => attempt(errors, () => this.#port.close(id)));
|
|
1497
|
-
const records = [];
|
|
1498
|
-
previous.records.forEach((record, id) => {
|
|
1499
|
-
const state = states.get(id);
|
|
1500
|
-
if (!ids.has(id) || state === void 0) return;
|
|
1501
|
-
try {
|
|
1502
|
-
records.push(this.#port.merge(record, state));
|
|
1503
|
-
} catch (error) {
|
|
1504
|
-
errors.push(graphFailure(error));
|
|
1505
|
-
}
|
|
1506
|
-
});
|
|
1507
|
-
if (records.length > 0) await attempt(errors, () => this.#port.replay(records));
|
|
1508
|
-
}
|
|
1509
|
-
#replacement(mutated, remount, settle) {
|
|
1510
|
-
const replacement = settledReplacement(mutated, remount, async (commit) => {
|
|
1511
|
-
let settled = false;
|
|
1512
|
-
try {
|
|
1513
|
-
const result = await settle(commit);
|
|
1514
|
-
settled = true;
|
|
1515
|
-
return result;
|
|
1516
|
-
} finally {
|
|
1517
|
-
if (settled && this.#pending === replacement) this.#pending = void 0;
|
|
1518
|
-
}
|
|
1519
|
-
});
|
|
1520
|
-
this.#pending = replacement;
|
|
1521
|
-
return replacement;
|
|
1522
|
-
}
|
|
1523
|
-
#requireIdle() {
|
|
1524
|
-
if (this.#disposed) throw new Error("Prepared AnyWidget graph is disposed");
|
|
1525
|
-
if (this.#operation !== void 0 || this.#pending !== void 0) throw new Error("A prepared AnyWidget graph replacement is already active");
|
|
1526
|
-
}
|
|
1527
|
-
async #dispose() {
|
|
1528
|
-
this.#disposed = true;
|
|
1529
|
-
this.#active?.abort(new DOMException("Prepared AnyWidget graph disposed", "AbortError"));
|
|
1530
|
-
const errors = [];
|
|
1531
|
-
if (this.#operation !== void 0) await attempt(errors, () => this.#operation?.then(() => {}));
|
|
1532
|
-
if (this.#pending !== void 0) await attempt(errors, () => this.#pending?.rollback());
|
|
1533
|
-
await eachSequential(this.#current.records, ([id, record]) => this.#port.active(record) ? attempt(errors, () => this.#port.close(id)) : void 0);
|
|
1534
|
-
await attempt(errors, () => this.#port.setFiles({}));
|
|
1535
|
-
this.#current = emptyGraph();
|
|
1536
|
-
throwCleanup(errors, "Prepared AnyWidget graph disposal failed");
|
|
1537
|
-
}
|
|
1538
|
-
};
|
|
1539
|
-
//#endregion
|
|
1540
1217
|
//#region ../loader-anywidget/src/index.ts
|
|
1541
1218
|
/** Decode exported AnyWidget bytes and prepare them for browser mounting. */
|
|
1542
1219
|
async function loadAnyWidget(data, signal) {
|
|
@@ -1564,4 +1241,4 @@ const anyWidgetLoader = () => defineBlobAssetLoader({
|
|
|
1564
1241
|
load: ({ payload, signal }) => loadAnyWidget(payload.data, signal)
|
|
1565
1242
|
});
|
|
1566
1243
|
//#endregion
|
|
1567
|
-
export {
|
|
1244
|
+
export { anyWidgetLoader };
|
package/dist/prepared/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as portableJsonValue, c as isNotebookExportError, d as isJsonNumber, f as isJsonString, g as portableJsonObject, h as isStringValue, m as isRecordValue, p as isPropertyOwner } from "../loader-BTeU85BE.mjs";
|
|
2
2
|
import { i as parsePortableJson } from "../schema-BOtMEPzp.mjs";
|
|
3
|
-
import { n as normalizeBase, t as openExport } from "../export-
|
|
3
|
+
import { n as normalizeBase, t as openExport } from "../export-I-cltoel.mjs";
|
|
4
4
|
//#region src/prepared/cancellation.ts
|
|
5
5
|
const preparedAbortReason = (reason, message = "Prepared export operation aborted") => {
|
|
6
6
|
if (reason instanceof Error || reason instanceof DOMException) return reason;
|
|
@@ -399,12 +399,31 @@ var PreparedStateTransitions = class {
|
|
|
399
399
|
}
|
|
400
400
|
async restoreAfter(primary) {
|
|
401
401
|
try {
|
|
402
|
-
await this
|
|
402
|
+
await this.#restoreCurrent();
|
|
403
403
|
} catch (cleanup) {
|
|
404
404
|
throw new AggregateError([primary, cleanup], "Prepared state transition and restoration failed.");
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
|
-
|
|
407
|
+
reject(primary) {
|
|
408
|
+
const operation = this.#queueRestore(() => this.restoreAfter(primary)).then(() => {
|
|
409
|
+
throw primary;
|
|
410
|
+
});
|
|
411
|
+
this.#operation = operation;
|
|
412
|
+
return operation;
|
|
413
|
+
}
|
|
414
|
+
restore() {
|
|
415
|
+
return this.#queueRestore(() => this.#restoreCurrent());
|
|
416
|
+
}
|
|
417
|
+
#queueRestore(restore) {
|
|
418
|
+
this.cancel(new DOMException("Prepared state transition superseded", "AbortError"));
|
|
419
|
+
const generation = this.#generation;
|
|
420
|
+
const operation = this.#operation.catch(() => {}).then(async () => {
|
|
421
|
+
if (generation === this.#generation && !this.#closed) await restore();
|
|
422
|
+
});
|
|
423
|
+
this.#operation = operation;
|
|
424
|
+
return operation;
|
|
425
|
+
}
|
|
426
|
+
async #restoreCurrent() {
|
|
408
427
|
if (this.#current !== void 0) await this.port.restore?.(this.#current);
|
|
409
428
|
}
|
|
410
429
|
cancel(reason) {
|
|
@@ -507,8 +526,7 @@ var PreparedStateController = class {
|
|
|
507
526
|
next = withPreparedState(source, source.notebookExport.resolve(requested));
|
|
508
527
|
} catch (error) {
|
|
509
528
|
if (!isPreparedStateUnavailable(error)) this.#pendingInputs = void 0;
|
|
510
|
-
|
|
511
|
-
throw error;
|
|
529
|
+
return this.#transitions.reject(error);
|
|
512
530
|
}
|
|
513
531
|
try {
|
|
514
532
|
await this.#apply(next, "state", signal);
|
|
@@ -1,5 +1,58 @@
|
|
|
1
|
+
import { c as isNotebookExportError, l as isCallableValue, s as NotebookExportError } from "./loader-BTeU85BE.mjs";
|
|
1
2
|
import { t as canonicalJson } from "./schema-BOtMEPzp.mjs";
|
|
3
|
+
import { r as isAbortError } from "./export-I-cltoel.mjs";
|
|
2
4
|
import { r as parseResources } from "./marimo-snapshot-B2eNp-aW.mjs";
|
|
5
|
+
//#region src/load-outputs.ts
|
|
6
|
+
/** Load a state's selected outputs and settle sibling requests after a failure. */
|
|
7
|
+
async function loadOutputs(state, loaders, options = {}) {
|
|
8
|
+
const controller = new AbortController();
|
|
9
|
+
const abort = () => controller.abort(options.signal?.reason);
|
|
10
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
11
|
+
if (options.signal?.aborted) abort();
|
|
12
|
+
let failure;
|
|
13
|
+
try {
|
|
14
|
+
requireActive(controller.signal);
|
|
15
|
+
const outputs = Object.entries(loaders).map(([name, loader]) => ({
|
|
16
|
+
name,
|
|
17
|
+
output: state.output(name),
|
|
18
|
+
loader
|
|
19
|
+
}));
|
|
20
|
+
const results = await Promise.allSettled(outputs.map(async ({ name, output, loader }) => {
|
|
21
|
+
try {
|
|
22
|
+
return [name, await output.load(loader, {
|
|
23
|
+
...options,
|
|
24
|
+
signal: controller.signal
|
|
25
|
+
})];
|
|
26
|
+
} catch (cause) {
|
|
27
|
+
if (failure === void 0) {
|
|
28
|
+
failure = { cause };
|
|
29
|
+
controller.abort(cause);
|
|
30
|
+
}
|
|
31
|
+
throw cause;
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
if (failure !== void 0) {
|
|
35
|
+
const primary = failure.cause;
|
|
36
|
+
const others = results.flatMap((result) => result.status === "rejected" && result.reason !== primary && !aborted(result.reason) ? [result.reason] : []);
|
|
37
|
+
if (others.length > 0) throw new AggregateError([primary, ...new Set(others)], "Export output loading failed.");
|
|
38
|
+
throw primary;
|
|
39
|
+
}
|
|
40
|
+
requireActive(controller.signal);
|
|
41
|
+
const entries = results.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
|
|
42
|
+
const loaded = Object.fromEntries(entries);
|
|
43
|
+
if (isCallableValue(loaded.then)) throw new NotebookExportError("decode_failed", "Output \"then\" is callable. Load it individually with ExportOutput.load().", { details: { output: "then" } });
|
|
44
|
+
return Object.freeze(loaded);
|
|
45
|
+
} finally {
|
|
46
|
+
options.signal?.removeEventListener("abort", abort);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function requireActive(signal) {
|
|
50
|
+
if (signal.aborted) throw new NotebookExportError("abort", "Export output loading was aborted.", { cause: signal.reason });
|
|
51
|
+
}
|
|
52
|
+
function aborted(cause) {
|
|
53
|
+
return isAbortError(cause) || isNotebookExportError(cause) && cause.code === "abort";
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
3
56
|
//#region src/replay-resources.ts
|
|
4
57
|
const notificationValue = (notification) => {
|
|
5
58
|
const message = notification.message;
|
|
@@ -88,4 +141,4 @@ function mergeMarimoReplayResources(snapshots) {
|
|
|
88
141
|
});
|
|
89
142
|
}
|
|
90
143
|
//#endregion
|
|
91
|
-
export { mergeMarimoReplayResources as t };
|
|
144
|
+
export { loadOutputs as n, mergeMarimoReplayResources as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marimo-team/marimo-export",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Open and load verified marimo notebook exports in browser applications",
|
|
5
5
|
"homepage": "https://marimo-team.github.io/marimo-export/",
|
|
6
6
|
"bugs": {
|
|
@@ -82,9 +82,11 @@
|
|
|
82
82
|
"@uwdata/flechette": "^2.5.0",
|
|
83
83
|
"hyparquet": "^1.29.2",
|
|
84
84
|
"lz4js": "0.2.0",
|
|
85
|
+
"picomatch": "4.0.7",
|
|
85
86
|
"typescript": "^6.0.3",
|
|
86
87
|
"vega-embed": "^7.2.0",
|
|
87
|
-
"vite-plus": "0.3.0"
|
|
88
|
+
"vite-plus": "0.3.0",
|
|
89
|
+
"yaml": "2.9.0"
|
|
88
90
|
},
|
|
89
91
|
"peerDependencies": {
|
|
90
92
|
"@anywidget/types": "^0.4.0",
|