@kitionstage/sdk 0.0.0-stage → 0.5.2-stage.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -2
- package/dist/LICENSE +177 -0
- package/dist/THIRD_PARTY_NOTICES +28 -0
- package/dist/lib/assets/kitEngine.worker-9haDiVHZ.js +13220 -0
- package/dist/lib/chunks/batch-BWpAyHvP.js +789 -0
- package/dist/lib/chunks/canonical-BIWfVCL-.js +87 -0
- package/dist/lib/chunks/envelope-D6MGY-ZN.js +61 -0
- package/dist/lib/chunks/replica-D8w3I4sn.js +2472 -0
- package/dist/lib/chunks/runtime-BVJHE1Pg.js +997 -0
- package/dist/lib/chunks/session-BqXC9a1-.js +281 -0
- package/dist/lib/chunks/toolIds-BCeSGHpV.js +821 -0
- package/dist/lib/chunks/workspaceTree-Destqupf.js +23 -0
- package/dist/lib/convergence/index.js +1035 -0
- package/dist/lib/convergence/node.js +8 -0
- package/dist/lib/embed-server/callbacks.js +37 -0
- package/dist/lib/embed-server/cli.js +19 -0
- package/dist/lib/embed-server/index.js +272 -0
- package/dist/lib/extensions/index.js +439 -0
- package/dist/lib/extensions/panel.html +208 -0
- package/dist/lib/extensions/runtime.js +198 -0
- package/dist/lib/extensions/sandbox.html +35 -0
- package/dist/lib/kdm/index.js +437 -0
- package/dist/lib/kit-dev-host/checkUiIds.mjs +44 -0
- package/dist/lib/kit-dev-host/index.js +308 -0
- package/dist/lib/kit-dev-host/lineRow.mjs +47 -0
- package/dist/lib/kit-dev-host/modeSmoke.mjs +178 -0
- package/dist/lib/kit-editor/index.js +6489 -0
- package/dist/lib/kit-editor/styles.css +807 -0
- package/dist/lib/kit-editor/workspaceTree.js +1 -0
- package/dist/lib/kit-engine/index.js +7 -0
- package/dist/lib/kit-host/index.js +530 -0
- package/dist/lib/kit-ui-protocol/index.js +336 -0
- package/dist/lib/node-only/embed-server-callbacks.js +2 -0
- package/dist/lib/node-only/embed-server.js +2 -0
- package/dist/lib/sync/index.js +1008 -0
- package/dist/lib/sync/openToken.js +201 -0
- package/dist/lib/sync/replicaVersions.js +51 -0
- package/dist/standalone/chunks/batch-CAGYk6m4.js +789 -0
- package/dist/standalone/chunks/client-B9xkOcvf.js +772 -0
- package/dist/standalone/chunks/collab-B5TbpTyO.js +1022 -0
- package/dist/standalone/chunks/comment-Ds9t8xSE.js +94 -0
- package/dist/standalone/chunks/comments-uVDS8Wxp.js +41 -0
- package/dist/standalone/chunks/document-CuIGSDsY.js +324 -0
- package/dist/standalone/chunks/envelope-GX4Cynkx.js +7612 -0
- package/dist/standalone/chunks/index-BEgEEnhU.js +287 -0
- package/dist/standalone/chunks/index-Blc_B6iX.js +1967 -0
- package/dist/standalone/chunks/kits-Cp51mDlw.js +9 -0
- package/dist/standalone/chunks/replica-Di2iCPiD.js +3281 -0
- package/dist/standalone/chunks/replicaVersions-C3rJxnk9.js +50 -0
- package/dist/standalone/chunks/touched-T9jKJjxn.js +78 -0
- package/dist/standalone/index.js +12 -0
- package/dist/standalone/script/index.js +339 -0
- package/dist/standalone/script/kits/board.js +5 -0
- package/dist/standalone/script/kits/cad.js +5 -0
- package/dist/standalone/script/kits/design.js +5 -0
- package/dist/standalone/script/kits/doc.js +5 -0
- package/dist/standalone/script/kits/film.js +5 -0
- package/dist/standalone/script/kits/html.js +5 -0
- package/dist/standalone/script/kits/index.js +38 -0
- package/dist/standalone/script/kits/layout.js +5 -0
- package/dist/standalone/script/kits/motion.js +5 -0
- package/dist/standalone/script/kits/note.js +5 -0
- package/dist/standalone/script/kits/pdf.js +5 -0
- package/dist/standalone/script/kits/photo.js +5 -0
- package/dist/standalone/script/kits/scene.js +5 -0
- package/dist/standalone/script/kits/sheet.js +5 -0
- package/dist/standalone/script/kits/slide.js +5 -0
- package/dist/standalone/script/kits/table.js +5 -0
- package/dist/standalone/script/kits/vector.js +5 -0
- package/dist/standalone/script/node.js +401 -0
- package/dist/standalone/script/proxy.js +254 -0
- package/dist/types/convergence/src/adapter.d.ts +131 -0
- package/dist/types/convergence/src/engine.d.ts +66 -0
- package/dist/types/convergence/src/index.d.ts +21 -0
- package/dist/types/convergence/src/net.d.ts +52 -0
- package/dist/types/convergence/src/node.d.ts +6 -0
- package/dist/types/convergence/src/report.d.ts +56 -0
- package/dist/types/convergence/src/rng.d.ts +12 -0
- package/dist/types/convergence/src/scenarios.d.ts +15 -0
- package/dist/types/convergence/src/state.d.ts +67 -0
- package/dist/types/embed/src/agent.d.ts +88 -0
- package/dist/types/embed/src/blobs.d.ts +2 -0
- package/dist/types/embed/src/collab.d.ts +250 -0
- package/dist/types/embed/src/comments.d.ts +30 -0
- package/dist/types/embed/src/errors.d.ts +24 -0
- package/dist/types/embed/src/handlers.d.ts +92 -0
- package/dist/types/embed/src/index.d.ts +20 -0
- package/dist/types/embed/src/mount.d.ts +39 -0
- package/dist/types/embed/src/replicaStore.d.ts +3 -0
- package/dist/types/embed/src/rooms.d.ts +40 -0
- package/dist/types/embed/src/schemas.d.ts +7 -0
- package/dist/types/embed/src/syncClients.d.ts +28 -0
- package/dist/types/embed/src/theme.d.ts +7 -0
- package/dist/types/embed/src/types.d.ts +596 -0
- package/dist/types/embed/src/ui.d.ts +33 -0
- package/dist/types/embed/src/version.d.ts +2 -0
- package/dist/types/embed-server/src/callbacks.d.ts +30 -0
- package/dist/types/embed-server/src/cli.d.ts +1 -0
- package/dist/types/embed-server/src/index.d.ts +19 -0
- package/dist/types/embed-server/src/page.d.ts +15 -0
- package/dist/types/embed-server/src/server.d.ts +39 -0
- package/dist/types/embed-server/src/session.d.ts +22 -0
- package/dist/types/extensions/src/gate.d.ts +17 -0
- package/dist/types/extensions/src/generated/runtime.d.ts +8 -0
- package/dist/types/extensions/src/host.d.ts +135 -0
- package/dist/types/extensions/src/index.d.ts +13 -0
- package/dist/types/extensions/src/manifest.d.ts +82 -0
- package/dist/types/extensions/src/protocol.d.ts +159 -0
- package/dist/types/extensions/src/rpc.d.ts +52 -0
- package/dist/types/extensions/src/runtime/document.d.ts +40 -0
- package/dist/types/extensions/src/runtime/index.d.ts +10 -0
- package/dist/types/extensions/src/runtime/panel.d.ts +19 -0
- package/dist/types/extensions/src/runtime/runtime.d.ts +54 -0
- package/dist/types/extensions/src/runtime/worker.d.ts +1 -0
- package/dist/types/extensions/src/sandbox.d.ts +41 -0
- package/dist/types/kdm/src/args.d.ts +12 -0
- package/dist/types/kdm/src/batch.d.ts +118 -0
- package/dist/types/kdm/src/canonical.d.ts +25 -0
- package/dist/types/kdm/src/comment.d.ts +114 -0
- package/dist/types/kdm/src/diff.d.ts +125 -0
- package/dist/types/kdm/src/envelope.d.ts +27 -0
- package/dist/types/kdm/src/errors.d.ts +28 -0
- package/dist/types/kdm/src/footprint.d.ts +21 -0
- package/dist/types/kdm/src/ids.d.ts +57 -0
- package/dist/types/kdm/src/index.d.ts +18 -0
- package/dist/types/kdm/src/marks.d.ts +32 -0
- package/dist/types/kdm/src/op.d.ts +124 -0
- package/dist/types/kdm/src/origin.d.ts +41 -0
- package/dist/types/kdm/src/overlay.d.ts +92 -0
- package/dist/types/kdm/src/projection.d.ts +29 -0
- package/dist/types/kdm/src/read.d.ts +90 -0
- package/dist/types/kdm/src/replica.d.ts +403 -0
- package/dist/types/kdm/src/schema.d.ts +185 -0
- package/dist/types/kdm/src/testing.d.ts +28 -0
- package/dist/types/kdm/src/toolIds.d.ts +61 -0
- package/dist/types/kdm/src/touched.d.ts +24 -0
- package/dist/types/kdm/src/tx.d.ts +215 -0
- package/dist/types/kdm/src/value.d.ts +23 -0
- package/dist/types/kit-dev-host/src/checkNoPaths.d.ts +19 -0
- package/dist/types/kit-dev-host/src/checkUiIds.d.mts +2 -0
- package/dist/types/kit-dev-host/src/index.d.ts +179 -0
- package/dist/types/kit-dev-host/src/lineRow.d.mts +14 -0
- package/dist/types/kit-dev-host/src/memoryFiles.d.ts +15 -0
- package/dist/types/kit-dev-host/src/modeSmoke.d.mts +8 -0
- package/dist/types/kit-editor/src/CommandDialog.d.ts +22 -0
- package/dist/types/kit-editor/src/CommentsPanel.d.ts +45 -0
- package/dist/types/kit-editor/src/CustomizeDialog.d.ts +32 -0
- package/dist/types/kit-editor/src/HostButtons.d.ts +11 -0
- package/dist/types/kit-editor/src/RenderFailure.d.ts +7 -0
- package/dist/types/kit-editor/src/TextSink.d.ts +6 -0
- package/dist/types/kit-editor/src/brand.d.ts +2 -0
- package/dist/types/kit-editor/src/catalogMenus.d.ts +27 -0
- package/dist/types/kit-editor/src/chart.d.ts +138 -0
- package/dist/types/kit-editor/src/conflicts.d.ts +12 -0
- package/dist/types/kit-editor/src/drawing.d.ts +83 -0
- package/dist/types/kit-editor/src/editor.d.ts +544 -0
- package/dist/types/kit-editor/src/engine/KitCanvas.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/backdrop.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/createKitFile.d.ts +12 -0
- package/dist/types/kit-editor/src/engine/decorations.d.ts +14 -0
- package/dist/types/kit-editor/src/engine/engineOverlays.d.ts +197 -0
- package/dist/types/kit-editor/src/engine/engineTools.d.ts +116 -0
- package/dist/types/kit-editor/src/engine/kitDraft.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/kitEngine.d.ts +390 -0
- package/dist/types/kit-editor/src/engine/kitEngine.worker.d.ts +30 -0
- package/dist/types/kit-editor/src/engine/kitHost.d.ts +41 -0
- package/dist/types/kit-editor/src/engine/kitModel.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitModelRunner.d.ts +99 -0
- package/dist/types/kit-editor/src/engine/kitModule.d.ts +185 -0
- package/dist/types/kit-editor/src/engine/kitShortcuts.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitTools.d.ts +79 -0
- package/dist/types/kit-editor/src/engine/lazyFonts.d.ts +34 -0
- package/dist/types/kit-editor/src/engine/lentFiles.d.ts +29 -0
- package/dist/types/kit-editor/src/engine/rasterViewport.d.ts +178 -0
- package/dist/types/kit-editor/src/engine/readOnly.d.ts +78 -0
- package/dist/types/kit-editor/src/engine/refusal.d.ts +39 -0
- package/dist/types/kit-editor/src/engine/replica.d.ts +23 -0
- package/dist/types/kit-editor/src/engine/useKitDocument.d.ts +154 -0
- package/dist/types/kit-editor/src/engine/workerRelay.d.ts +62 -0
- package/dist/types/kit-editor/src/files.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/EditorFrame.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/FocusBar.d.ts +10 -0
- package/dist/types/kit-editor/src/frame/MenuNodes.d.ts +20 -0
- package/dist/types/kit-editor/src/frame/MenuRibbon.d.ts +8 -0
- package/dist/types/kit-editor/src/frame/ModeButton.d.ts +7 -0
- package/dist/types/kit-editor/src/frame/menus.d.ts +64 -0
- package/dist/types/kit-editor/src/frame/modes.d.ts +51 -0
- package/dist/types/kit-editor/src/frame/useFrameLayout.d.ts +34 -0
- package/dist/types/kit-editor/src/host.d.ts +127 -0
- package/dist/types/kit-editor/src/index.d.ts +85 -0
- package/dist/types/kit-editor/src/ink.d.ts +26 -0
- package/dist/types/kit-editor/src/lease.d.ts +53 -0
- package/dist/types/kit-editor/src/oneInFlight.d.ts +7 -0
- package/dist/types/kit-editor/src/phrases.d.ts +25 -0
- package/dist/types/kit-editor/src/presence.d.ts +79 -0
- package/dist/types/kit-editor/src/strings.d.ts +6 -0
- package/dist/types/kit-editor/src/toolIcons.d.ts +32 -0
- package/dist/types/kit-editor/src/uiCatalog.d.ts +59 -0
- package/dist/types/kit-editor/src/uiConfig.d.ts +53 -0
- package/dist/types/kit-editor/src/uiContext.d.ts +65 -0
- package/dist/types/kit-editor/src/uiStore.d.ts +20 -0
- package/dist/types/kit-editor/src/useCommentAnchors.d.ts +29 -0
- package/dist/types/kit-editor/src/useKitSession.d.ts +115 -0
- package/dist/types/kit-editor/src/workspaceTree.d.ts +5 -0
- package/dist/types/kit-engine/src/contract.d.ts +154 -0
- package/dist/types/kit-engine/src/index.d.ts +2 -0
- package/dist/types/kit-engine/src/session.d.ts +133 -0
- package/dist/types/kit-host/src/files.d.ts +163 -0
- package/dist/types/kit-host/src/index.d.ts +315 -0
- package/dist/types/kit-ui-protocol/src/index.d.ts +1145 -0
- package/dist/types/loro-crdt.d.ts +9 -0
- package/dist/types/script/kits/board.d.ts +534 -0
- package/dist/types/script/kits/cad.d.ts +2937 -0
- package/dist/types/script/kits/design.d.ts +3213 -0
- package/dist/types/script/kits/doc.d.ts +2575 -0
- package/dist/types/script/kits/film.d.ts +4067 -0
- package/dist/types/script/kits/html.d.ts +38 -0
- package/dist/types/script/kits/index.d.ts +20 -0
- package/dist/types/script/kits/layout.d.ts +3483 -0
- package/dist/types/script/kits/motion.d.ts +4826 -0
- package/dist/types/script/kits/note.d.ts +631 -0
- package/dist/types/script/kits/pdf.d.ts +829 -0
- package/dist/types/script/kits/photo.d.ts +7574 -0
- package/dist/types/script/kits/scene.d.ts +2962 -0
- package/dist/types/script/kits/sheet.d.ts +2419 -0
- package/dist/types/script/kits/slide.d.ts +1894 -0
- package/dist/types/script/kits/table.d.ts +654 -0
- package/dist/types/script/kits/vector.d.ts +5167 -0
- package/dist/types/script/src/agentRelay.d.ts +48 -0
- package/dist/types/script/src/capabilities.d.ts +21 -0
- package/dist/types/script/src/document.d.ts +87 -0
- package/dist/types/script/src/drafts.d.ts +141 -0
- package/dist/types/script/src/exchange.d.ts +30 -0
- package/dist/types/script/src/headless.d.ts +190 -0
- package/dist/types/script/src/index.d.ts +15 -0
- package/dist/types/script/src/kitModel.d.ts +17 -0
- package/dist/types/script/src/kits.d.ts +8 -0
- package/dist/types/script/src/node.d.ts +42 -0
- package/dist/types/script/src/port.d.ts +89 -0
- package/dist/types/script/src/proxy.d.ts +132 -0
- package/dist/types/script/src/room.d.ts +162 -0
- package/dist/types/script/src/sources.d.ts +73 -0
- package/dist/types/sync/src/backoff.d.ts +9 -0
- package/dist/types/sync/src/blobSection.d.ts +23 -0
- package/dist/types/sync/src/capabilities.d.ts +20 -0
- package/dist/types/sync/src/client.d.ts +253 -0
- package/dist/types/sync/src/framing.d.ts +35 -0
- package/dist/types/sync/src/hash.d.ts +2 -0
- package/dist/types/sync/src/index.d.ts +19 -0
- package/dist/types/sync/src/leases.d.ts +82 -0
- package/dist/types/sync/src/openToken.d.ts +104 -0
- package/dist/types/sync/src/protocol.d.ts +484 -0
- package/dist/types/sync/src/relay.d.ts +52 -0
- package/dist/types/sync/src/replicaVersions.d.ts +17 -0
- package/dist/types/sync/src/saveMachine.d.ts +83 -0
- package/dist/types/sync/src/saveRun.d.ts +52 -0
- package/dist/types/sync/src/transport.d.ts +19 -0
- package/package.json +229 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@kition/tessera/ui/workspaceTree";
|
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { KitRpcError as b, FILE_HANDLE_PREFIX as j, HOST_ACTION_CAPABILITY_PREFIX as te, HOST_SERVICES as ne, serviceAllowed as ie, HOST_SERVICE_CAPABILITY_PREFIX as se, KIT_UI_PROTOCOL as x, linkPathFrom as oe, isReady as re, KitPeer as ae, isGeneratePurpose as ce, parseOpenParams as le, isOpenableUrl as de, isFetchableUrl as fe, FETCH_IMAGE_TYPES as ue, parseLinksPickParams as he, parseSchemaReport as me, parsePresence as B, parseServiceParams as pe, parseCommentAnchor as we } from "../kit-ui-protocol/index.js";
|
|
2
|
+
import { ACTION_ERROR_REASONS as _e, FETCH_IMAGE_ERROR_REASONS as Ce, GENERATE_ERROR_REASONS as Ne, GENERATE_PURPOSES as Pe, LEASE_HELD_REASON as $e, OPEN_ERROR_REASONS as ze, OPEN_URL_SCHEMES as xe, SERVICE_ERROR_REASONS as Te, fetchImageErrorReason as Ue, fileErrorReason as Fe, hostRequestErrorReason as He, openErrorReason as Me, parseKitView as Ge, parseLinkRef as We } from "../kit-ui-protocol/index.js";
|
|
3
|
+
function p(t, r) {
|
|
4
|
+
return new b(-32e3, r, { reason: t });
|
|
5
|
+
}
|
|
6
|
+
const P = (t) => new b(-32602, t), H = (t) => Object.prototype.toString.call(t) === "[object ArrayBuffer]";
|
|
7
|
+
function N(t) {
|
|
8
|
+
const r = t.lastIndexOf(".");
|
|
9
|
+
return r > 0 ? t.slice(r + 1).toLowerCase() : "";
|
|
10
|
+
}
|
|
11
|
+
const ge = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
|
|
12
|
+
function M(t) {
|
|
13
|
+
let i = (t.split(/[\\/]/).pop() ?? "").replace(/[\u0000-\u001f\u007f<>:"|?*]/g, "").trim().replace(/^\.+/, "").replace(/[. ]+$/, "");
|
|
14
|
+
const s = i.indexOf("."), c = s < 0 ? i : i.slice(0, s);
|
|
15
|
+
if (ge.test(c) && (i = `${c}_${i.slice(c.length)}`), i.length > 255) {
|
|
16
|
+
const u = N(i);
|
|
17
|
+
i = u ? `${i.slice(0, 254 - u.length)}.${u}` : i.slice(0, 255);
|
|
18
|
+
}
|
|
19
|
+
return i || "Untitled";
|
|
20
|
+
}
|
|
21
|
+
async function ye(t, r) {
|
|
22
|
+
const i = t.lastIndexOf("."), [s, c] = i > 0 ? [t.slice(0, i), t.slice(i)] : [t, ""];
|
|
23
|
+
for (let u = 1; u < 1e4; u += 1) {
|
|
24
|
+
const g = u === 1 ? t : `${s} ${u}${c}`;
|
|
25
|
+
if (!await r(g)) return g;
|
|
26
|
+
}
|
|
27
|
+
throw p("io-error", "no unused name is left for this file");
|
|
28
|
+
}
|
|
29
|
+
function G() {
|
|
30
|
+
const t = new Uint8Array(16);
|
|
31
|
+
return crypto.getRandomValues(t), j + Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("");
|
|
32
|
+
}
|
|
33
|
+
const ke = (t) => t.split(/[\\/]/).filter(Boolean).pop() ?? t, ve = () => globalThis.navigator?.userActivation?.isActive ?? !0, F = (t) => (t ?? []).map((r) => r.replace(/^\./, "").toLowerCase());
|
|
34
|
+
function be(t, r, i) {
|
|
35
|
+
let s = [];
|
|
36
|
+
return {
|
|
37
|
+
append: async (c) => void s.push(c),
|
|
38
|
+
commit: async () => {
|
|
39
|
+
const c = new Uint8Array(s.reduce((k, L) => k + L.byteLength, 0));
|
|
40
|
+
let u = 0;
|
|
41
|
+
for (const k of s)
|
|
42
|
+
c.set(k, u), u += k.byteLength;
|
|
43
|
+
const g = await t.commit(r(), c, i());
|
|
44
|
+
return s = [], g;
|
|
45
|
+
},
|
|
46
|
+
abort: async () => {
|
|
47
|
+
s = [];
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const Ee = ["files/pick", "files/create", "files/stat", "files/read", "files/list", "files/write", "files/release", "files/print"];
|
|
52
|
+
function Re(t) {
|
|
53
|
+
const { storage: r } = t, i = G().slice(j.length), s = { read: F(t.manifest?.read), create: F(t.manifest?.create), folders: t.manifest?.folders === !0, print: t.manifest?.print === !0 }, c = r.name ?? ke, u = t.gesture ?? ve, g = /* @__PURE__ */ new Map();
|
|
54
|
+
let k = !1, L = 0;
|
|
55
|
+
const $ = ["files", ...t.pick ? ["files-pick"] : [], ...t.print ? ["print"] : []], w = (e) => ({
|
|
56
|
+
handle: e.handle,
|
|
57
|
+
name: e.name,
|
|
58
|
+
kind: e.kind,
|
|
59
|
+
...e.size !== void 0 ? { size: e.size } : {},
|
|
60
|
+
...e.mime !== void 0 ? { mime: e.mime } : {},
|
|
61
|
+
version: e.version,
|
|
62
|
+
rights: [...e.rights]
|
|
63
|
+
}), E = (e, n, a, f, d = {}) => {
|
|
64
|
+
const h = {
|
|
65
|
+
handle: G(),
|
|
66
|
+
session: i,
|
|
67
|
+
kit: t.kit,
|
|
68
|
+
principal: t.principal,
|
|
69
|
+
flow: f,
|
|
70
|
+
rights: a,
|
|
71
|
+
kind: n?.kind ?? "file",
|
|
72
|
+
name: d.name ?? c(e),
|
|
73
|
+
ref: e,
|
|
74
|
+
folder: d.folder ?? null,
|
|
75
|
+
accept: d.accept ?? [],
|
|
76
|
+
mime: d.mime ?? n?.mime,
|
|
77
|
+
version: n?.version ?? null,
|
|
78
|
+
size: n?.size,
|
|
79
|
+
committed: !1,
|
|
80
|
+
staging: null,
|
|
81
|
+
staged: 0,
|
|
82
|
+
written: 0,
|
|
83
|
+
expected: null
|
|
84
|
+
};
|
|
85
|
+
g.set(h.handle, h);
|
|
86
|
+
const { handle: S, session: U, kit: J, principal: Z, kind: Q, name: ee } = h;
|
|
87
|
+
return t.log?.({ handle: S, session: U, kit: J, principal: Z, flow: f, rights: [...a], kind: Q, name: ee }), h;
|
|
88
|
+
}, v = (e, n, a) => {
|
|
89
|
+
if (k) throw p("file-not-granted", "the session has ended");
|
|
90
|
+
const f = typeof e == "string" ? g.get(e) : void 0;
|
|
91
|
+
if (!f) throw p("file-not-granted", "this handle was not granted to this session");
|
|
92
|
+
if (n && !f.rights.includes(n)) throw p("file-not-granted", `this handle has no ${n} right`);
|
|
93
|
+
if (a && f.kind !== a) throw p("file-not-granted", `this handle is not a ${a}`);
|
|
94
|
+
return f;
|
|
95
|
+
}, l = async (e) => {
|
|
96
|
+
try {
|
|
97
|
+
return await e();
|
|
98
|
+
} catch (n) {
|
|
99
|
+
throw n instanceof b ? n : p("io-error", "the host could not reach the file");
|
|
100
|
+
}
|
|
101
|
+
}, O = async (e) => {
|
|
102
|
+
g.delete(e.handle);
|
|
103
|
+
const n = e.staging;
|
|
104
|
+
e.staging = null, n && await n.abort().catch(() => {
|
|
105
|
+
});
|
|
106
|
+
}, q = (e) => {
|
|
107
|
+
if (!u()) throw p("no-gesture", `${e} needs a person's gesture in the kit`);
|
|
108
|
+
}, _ = async (e, n) => {
|
|
109
|
+
const a = new Set([...g.values()].filter((d) => d.rights.includes("create") && d.kind === "file" && !d.committed).map((d) => d.ref)), f = await ye(n, async (d) => {
|
|
110
|
+
const h = r.child(e, d);
|
|
111
|
+
return a.has(h) || await r.stat(h) !== null;
|
|
112
|
+
});
|
|
113
|
+
return { name: f, ref: r.child(e, f) };
|
|
114
|
+
}, C = (e, n = s.read) => {
|
|
115
|
+
const a = N(e);
|
|
116
|
+
if (!s.read.includes(a) || !n.includes(a)) throw p("not-allowed", `the kit may not read .${a || "(none)"} files`);
|
|
117
|
+
}, y = (e) => {
|
|
118
|
+
const n = N(e);
|
|
119
|
+
if (!s.create.includes(n)) throw p("not-allowed", `the kit may not create .${n || "(none)"} files`);
|
|
120
|
+
}, I = (e, n) => {
|
|
121
|
+
const a = F(e);
|
|
122
|
+
if (a.some((f) => !n.includes(f))) throw p("not-allowed", "the kit asked for a file type its manifest does not declare");
|
|
123
|
+
return a.length ? a : n;
|
|
124
|
+
}, o = async (e) => {
|
|
125
|
+
if (!t.pick) throw p("unsupported", "this host has no picker");
|
|
126
|
+
if (e?.mode !== "open" && e?.mode !== "folder" && e?.mode !== "save") throw P("mode is open, folder, or save");
|
|
127
|
+
if (q("files/pick"), e.mode === "folder" && !s.folders) throw p("not-allowed", "the kit may not ask for folders");
|
|
128
|
+
const n = I(e.accept, e.mode === "save" ? s.create : s.read);
|
|
129
|
+
e.mode === "save" && e.suggestedName != null && y(M(e.suggestedName));
|
|
130
|
+
const a = await l(() => t.pick(e)), f = [];
|
|
131
|
+
for (const d of e.mode === "open" && !e.multiple ? a.slice(0, 1) : a) {
|
|
132
|
+
const h = await l(() => r.stat(d));
|
|
133
|
+
if (e.mode === "folder") {
|
|
134
|
+
if (h?.kind !== "folder") continue;
|
|
135
|
+
const S = s.create.length ? ["read", "create"] : ["read"];
|
|
136
|
+
f.push(w(E(d, h, S, "pick", { accept: n })));
|
|
137
|
+
} else if (e.mode === "open") {
|
|
138
|
+
if (h?.kind !== "file" || !n.includes(N(c(d)))) continue;
|
|
139
|
+
f.push(w(E(d, h, ["read"], "pick")));
|
|
140
|
+
} else {
|
|
141
|
+
if (!n.includes(N(c(d)))) throw p("not-allowed", "the kit may not create this file type");
|
|
142
|
+
if (h?.kind === "folder") continue;
|
|
143
|
+
if (h && t.readOnly) throw p("not-allowed", "a read-only session replaces no file");
|
|
144
|
+
f.push(w(E(d, h, h ? ["write"] : ["create"], "pick")));
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { files: f };
|
|
149
|
+
}, m = async (e) => {
|
|
150
|
+
if (typeof e?.suggestedName != "string") throw P("suggestedName is a string");
|
|
151
|
+
const n = e.folder === void 0 ? null : v(e.folder, "create", "folder"), a = M(e.suggestedName);
|
|
152
|
+
y(a);
|
|
153
|
+
const { name: f, ref: d } = await l(() => _(n?.ref ?? null, a));
|
|
154
|
+
return w(E(d, null, ["create"], "create", { name: f, folder: n?.ref ?? null, mime: typeof e.mime == "string" ? e.mime : void 0 }));
|
|
155
|
+
}, R = async ({ handle: e, offset: n, length: a }) => {
|
|
156
|
+
const f = v(e, "read", "file"), d = n ?? 0;
|
|
157
|
+
if (!Number.isSafeInteger(d) || d < 0 || a !== void 0 && (!Number.isSafeInteger(a) || a < 0)) throw P("offset and length are whole numbers");
|
|
158
|
+
const h = await l(() => r.read(f.ref, d, a));
|
|
159
|
+
return f.version = h.version, f.size = h.size, h;
|
|
160
|
+
}, z = async ({ handle: e }) => {
|
|
161
|
+
const n = v(e, "read", "folder"), a = await l(() => r.list(n.ref)), f = [];
|
|
162
|
+
for (const d of a) {
|
|
163
|
+
if (!n.accept.includes(N(c(d))) || !s.read.includes(N(c(d)))) continue;
|
|
164
|
+
const h = await l(() => r.stat(d));
|
|
165
|
+
h?.kind === "file" && f.push(w(E(d, h, ["read"], "list")));
|
|
166
|
+
}
|
|
167
|
+
return { files: f };
|
|
168
|
+
}, T = async (e) => {
|
|
169
|
+
const n = v(e?.handle, void 0, "file"), a = n.rights.includes("create");
|
|
170
|
+
if (!a && !n.rights.includes("write")) throw p("file-not-granted", "this handle has no create or write right");
|
|
171
|
+
if (a && n.committed) throw p("already-committed", "this file was already committed");
|
|
172
|
+
if (!H(e.bytes)) throw P("bytes is an ArrayBuffer");
|
|
173
|
+
if (e.offset !== n.staged) throw P(`offset is ${n.staged}, the bytes staged so far`);
|
|
174
|
+
const f = e.bytes.byteLength;
|
|
175
|
+
if (t.quota?.perGrant !== void 0 && n.written + f > t.quota.perGrant || t.quota?.perSession !== void 0 && L + f > t.quota.perSession)
|
|
176
|
+
throw p("quota", "this write passes the host's cap");
|
|
177
|
+
if (e.final && !a) {
|
|
178
|
+
if (typeof e.expected != "string") throw p("conflict", "the final chunk carries the version it replaces");
|
|
179
|
+
if (await l(() => r.unsaved?.(n.ref) ?? !1)) throw p("unsaved-edits", "the file is open with unsaved edits");
|
|
180
|
+
n.expected = e.expected;
|
|
181
|
+
}
|
|
182
|
+
if (!n.staging) {
|
|
183
|
+
const S = () => a ? { mode: "create" } : { mode: "replace", expected: n.expected ?? "" };
|
|
184
|
+
n.staging = r.stage ? r.stage(n.ref, S) : be(r, () => n.ref, S);
|
|
185
|
+
}
|
|
186
|
+
const d = n.staging;
|
|
187
|
+
if (await l(() => d.append(new Uint8Array(e.bytes.slice(0)))), n.staged += f, n.written += f, L += f, !e.final) return {};
|
|
188
|
+
const h = await D(n, d, a);
|
|
189
|
+
return n.staging = null, n.staged = 0, n.expected = null, n.version = h.version, a && (n.committed = !0), { version: h.version };
|
|
190
|
+
}, D = async (e, n, a) => {
|
|
191
|
+
for (let f = 0; ; f += 1)
|
|
192
|
+
try {
|
|
193
|
+
return await l(() => n.commit());
|
|
194
|
+
} catch (d) {
|
|
195
|
+
const h = d instanceof b && d.data?.reason === "conflict";
|
|
196
|
+
if (!a || !h || e.flow !== "create" || r.stage || f >= 8) throw d;
|
|
197
|
+
const S = await l(() => _(e.folder, e.name));
|
|
198
|
+
e.ref = S.ref, e.name = S.name;
|
|
199
|
+
}
|
|
200
|
+
}, K = async ({ handles: e }) => {
|
|
201
|
+
for (const n of Array.isArray(e) ? e : []) {
|
|
202
|
+
const a = typeof n == "string" ? g.get(n) : void 0;
|
|
203
|
+
a && await O(a);
|
|
204
|
+
}
|
|
205
|
+
return {};
|
|
206
|
+
}, V = async (e) => {
|
|
207
|
+
if (!t.print) throw p("unsupported", "this host does not print");
|
|
208
|
+
if (!s.print) throw p("not-allowed", "the kit may not print");
|
|
209
|
+
q("files/print");
|
|
210
|
+
let n;
|
|
211
|
+
if (!e || typeof e != "object") throw P("a print takes PDF bytes or a handle");
|
|
212
|
+
if ("handle" in e) {
|
|
213
|
+
const f = v(e.handle, "read", "file");
|
|
214
|
+
if (N(f.name) !== "pdf" && f.mime !== "application/pdf") throw p("not-allowed", "only a PDF prints");
|
|
215
|
+
n = await X(f.ref);
|
|
216
|
+
} else {
|
|
217
|
+
if (e.mime !== "application/pdf" || !H(e.bytes)) throw P("a print takes PDF bytes or a handle");
|
|
218
|
+
n = new Uint8Array(e.bytes.slice(0));
|
|
219
|
+
}
|
|
220
|
+
const a = typeof e.title == "string" ? e.title : "";
|
|
221
|
+
return { printed: await l(() => t.print({ bytes: n, title: a })) === !0 };
|
|
222
|
+
}, X = async (e) => {
|
|
223
|
+
const n = [];
|
|
224
|
+
let a = 0;
|
|
225
|
+
for (; ; ) {
|
|
226
|
+
const { bytes: h, size: S } = await l(() => r.read(e, a, void 0));
|
|
227
|
+
if (n.push(new Uint8Array(h)), a += h.byteLength, a >= S || h.byteLength === 0) break;
|
|
228
|
+
}
|
|
229
|
+
const f = new Uint8Array(a);
|
|
230
|
+
let d = 0;
|
|
231
|
+
for (const h of n)
|
|
232
|
+
f.set(h, d), d += h.byteLength;
|
|
233
|
+
return f;
|
|
234
|
+
}, Y = {
|
|
235
|
+
"files/pick": o,
|
|
236
|
+
"files/create": m,
|
|
237
|
+
"files/stat": async ({ handle: e }) => {
|
|
238
|
+
const n = v(e);
|
|
239
|
+
if (n.rights.includes("create") && !n.committed && n.kind === "file") return w(n);
|
|
240
|
+
const a = await l(() => r.stat(n.ref));
|
|
241
|
+
if (!a) throw p("file-not-granted", "the file is gone");
|
|
242
|
+
return Object.assign(n, { version: a.version, size: a.size, mime: a.mime ?? n.mime }), w(n);
|
|
243
|
+
},
|
|
244
|
+
"files/read": R,
|
|
245
|
+
"files/list": z,
|
|
246
|
+
"files/write": T,
|
|
247
|
+
"files/release": K,
|
|
248
|
+
"files/print": V
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
id: i,
|
|
252
|
+
capabilities: $,
|
|
253
|
+
grant: async (e, n, { flow: a, approved: f }) => {
|
|
254
|
+
if (k) throw p("file-not-granted", "the session has ended");
|
|
255
|
+
const d = await l(() => r.stat(e)), h = c(e);
|
|
256
|
+
if (n.includes("write")) {
|
|
257
|
+
if (t.readOnly) throw p("not-allowed", "a read-only session replaces no file");
|
|
258
|
+
if (a === "agent" && f !== !0) throw p("not-allowed", "an agent replaces a file only through a draft or the person's approval");
|
|
259
|
+
if (d?.kind !== "file") throw p("not-allowed", "there is no such file to replace");
|
|
260
|
+
y(h);
|
|
261
|
+
}
|
|
262
|
+
if (n.includes("read")) {
|
|
263
|
+
if (!d) throw p("not-allowed", "there is no such file");
|
|
264
|
+
if (d.kind === "file") C(h);
|
|
265
|
+
else if (!s.folders) throw p("not-allowed", "the kit may not read folders");
|
|
266
|
+
}
|
|
267
|
+
if (n.includes("create") && (!d || d.kind === "file")) {
|
|
268
|
+
if (d) throw p("not-allowed", "a create grant never names an existing file");
|
|
269
|
+
y(h);
|
|
270
|
+
}
|
|
271
|
+
return w(E(e, d, [...new Set(n)], a, d?.kind === "folder" ? { accept: s.read } : {}));
|
|
272
|
+
},
|
|
273
|
+
revoke: async (e) => {
|
|
274
|
+
const n = [];
|
|
275
|
+
for (const a of e) {
|
|
276
|
+
const f = g.get(a);
|
|
277
|
+
f && (await O(f), n.push(a));
|
|
278
|
+
}
|
|
279
|
+
n.length && t.revoked?.(n);
|
|
280
|
+
},
|
|
281
|
+
grants: () => [...g.values()].map(({ handle: e, session: n, kit: a, principal: f, flow: d, rights: h, kind: S, name: U }) => ({ handle: e, session: n, kit: a, principal: f, flow: d, rights: [...h], kind: S, name: U })),
|
|
282
|
+
serve: async (e, n) => {
|
|
283
|
+
if (t.trace?.(e, n), k) throw p("file-not-granted", "the session has ended");
|
|
284
|
+
return Y[e](n);
|
|
285
|
+
},
|
|
286
|
+
end: async () => {
|
|
287
|
+
k = !0;
|
|
288
|
+
for (const e of [...g.values()]) await O(e);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function W(t) {
|
|
293
|
+
if (/^([A-Za-z]:)?[\\/]/.test(t)) return null;
|
|
294
|
+
const r = [];
|
|
295
|
+
for (const i of t.replace(/\\/g, "/").split("/"))
|
|
296
|
+
if (!(!i || i === "."))
|
|
297
|
+
if (i === "..") {
|
|
298
|
+
if (!r.length) return null;
|
|
299
|
+
r.pop();
|
|
300
|
+
} else r.push(i);
|
|
301
|
+
return r.length ? r.join("/") : null;
|
|
302
|
+
}
|
|
303
|
+
function Se(t, r, i) {
|
|
304
|
+
const s = W(t), c = [];
|
|
305
|
+
for (const u of i) {
|
|
306
|
+
const g = typeof u?.path == "string" ? W(u.path) : null;
|
|
307
|
+
if (!g || g === s || g.split("/").some((w) => w.startsWith("."))) continue;
|
|
308
|
+
const k = g.split("/").pop(), L = k.includes(".") ? k.slice(k.lastIndexOf(".") + 1).toLowerCase() : "";
|
|
309
|
+
if (!r.accept.includes(L)) continue;
|
|
310
|
+
const $ = { path: oe(t, g), name: k, version: typeof u.version == "string" ? u.version : null };
|
|
311
|
+
if (c.some((w) => w.path === $.path) || c.push($), !r.multiple) break;
|
|
312
|
+
}
|
|
313
|
+
return c;
|
|
314
|
+
}
|
|
315
|
+
function A(t) {
|
|
316
|
+
throw new b(-32601, `${t} is not supported by this host`);
|
|
317
|
+
}
|
|
318
|
+
function qe(t, r) {
|
|
319
|
+
const { handlers: i } = r, s = { agent: i.openAgent, "pick-file": i.pick, replica: i.replicaRead && i.replicaWrite, customize: i.customize, lease: i.leases, presence: i.presence }, c = Object.entries(s).filter(([, w]) => w).map(([w]) => w);
|
|
320
|
+
i.generate && c.push("generate"), i.open && c.push("open-file"), i.openUrl && c.push("open-url");
|
|
321
|
+
const u = r.document.readOnly === !0;
|
|
322
|
+
i.pickLinks && !u && c.push("links-pick"), i.fetchImage && !u && c.push("fetch-image");
|
|
323
|
+
const g = Object.entries(i.actions ?? {}).filter(([, w]) => typeof w == "function");
|
|
324
|
+
c.push(...g.map(([w]) => `${te}${w}`));
|
|
325
|
+
const k = Object.entries(i.services ?? {}).filter(([w, E]) => typeof E == "function" && ne.includes(w) && ie(w, r.document));
|
|
326
|
+
c.push(...k.map(([w]) => `${se}${w}`)), i.comments && c.push("comment-anchors"), r.files && c.push("files", ...r.files.pick ? ["files-pick"] : [], ...r.files.print ? ["print"] : []);
|
|
327
|
+
const L = r.timeoutMs ?? 12e4, $ = (w, E) => {
|
|
328
|
+
const v = new MessageChannel(), l = new ae(v.port1, "h");
|
|
329
|
+
let O = null;
|
|
330
|
+
l.handle("host/read", (o) => i.read(o)), l.handle("host/stamp", (o) => i.stamp(o)), l.handle("host/write", (o) => i.write(o)), l.handle("host/pick", (o) => i.pick ? i.pick(o) : A("host/pick")), l.handle("host/openAgent", async (o) => (i.openAgent || A("host/openAgent"), await i.openAgent(o), {}));
|
|
331
|
+
const { replicaRead: q, replicaWrite: _ } = i;
|
|
332
|
+
l.handle("host/replicaRead", (o) => q && _ ? q(o) : A("host/replicaRead")), l.handle("host/replicaWrite", async (o) => ((!q || !_) && A("host/replicaWrite"), await _(o), {})), l.handle("host/customize", async (o) => (i.customize || A("host/customize"), await i.customize(o), {})), l.handle("host/leaseAcquire", (o) => i.leases ? i.leases.acquire(o) : A("host/leaseAcquire")), l.handle("host/leaseRelease", async (o) => (i.leases || A("host/leaseRelease"), await i.leases.release(o), {})), l.handle("host/leases", async () => (i.leases || A("host/leases"), { leases: await i.leases.list() })), l.handle("host/generate", (o) => {
|
|
333
|
+
if (i.generate || A("host/generate"), !ce(o?.purpose, O)) throw new b(-32e3, `a kit may not generate for ${JSON.stringify(o?.purpose)}`, { reason: "not-allowed" });
|
|
334
|
+
return i.generate(o);
|
|
335
|
+
}), l.handle("host/action", (o) => {
|
|
336
|
+
const m = typeof o?.id == "string" ? g.find(([R]) => R === o.id)?.[1] : void 0;
|
|
337
|
+
if (!m) throw new b(-32e3, `this host does not serve the action ${String(o?.id)}`, { reason: "not-allowed" });
|
|
338
|
+
return m(o.params && typeof o.params == "object" ? o.params : {});
|
|
339
|
+
}), l.handle("host/open", async (o) => {
|
|
340
|
+
i.open || A("host/open");
|
|
341
|
+
const m = le(o);
|
|
342
|
+
if (!m) throw new b(-32602, "host/open needs a link with a path, a name, or a docId");
|
|
343
|
+
return { opened: (await i.open(m))?.opened !== !1 };
|
|
344
|
+
}), l.handle("host/openUrl", async (o) => {
|
|
345
|
+
if (i.openUrl || A("host/openUrl"), !de(o?.url)) throw new b(-32e3, "a host opens only https:, http:, and mailto: addresses", { reason: "not-allowed" });
|
|
346
|
+
return { opened: (await i.openUrl({ url: o.url }))?.opened !== !1 };
|
|
347
|
+
}), l.handle("host/fetchImage", async (o) => {
|
|
348
|
+
if (i.fetchImage || A("host/fetchImage"), u) throw new b(-32e3, "a read-only document fetches no pictures", { reason: "read-only" });
|
|
349
|
+
if (!fe(o?.url)) throw new b(-32e3, "a host fetches only https: and http: addresses", { reason: "not-allowed" });
|
|
350
|
+
const m = await i.fetchImage({ url: o.url });
|
|
351
|
+
if (!(m?.bytes instanceof ArrayBuffer) || !ue.includes(m.mime)) throw new b(-32e3, `${o.url} is not a picture`, { reason: "unsupported" });
|
|
352
|
+
return { bytes: m.bytes, mime: m.mime };
|
|
353
|
+
}), l.handle("links/pick", async (o) => {
|
|
354
|
+
if (i.pickLinks || A("links/pick"), u) throw new b(-32e3, "a read-only document links no files", { reason: "read-only" });
|
|
355
|
+
const m = he(o);
|
|
356
|
+
if (!m) throw new b(-32602, "links/pick needs a purpose and at least one extension without the dot");
|
|
357
|
+
return { links: Se(r.document.path, m, await i.pickLinks(m) ?? []) };
|
|
358
|
+
});
|
|
359
|
+
const C = r.files ? Re({ ...r.files, readOnly: u, revoked: (o) => l.notify("files/revoked", { handles: o }) }) : null;
|
|
360
|
+
if (C) for (const o of Ee) l.handle(o, (m) => C.serve(o, m));
|
|
361
|
+
l.on("document/conflicts", (o) => i.conflicts?.(o)), l.on("document/schema", (o) => {
|
|
362
|
+
const m = me(o);
|
|
363
|
+
m && i.schema?.(m);
|
|
364
|
+
}), l.on("draft/changed", (o) => i.draftChanged?.(o)), l.on("presence/set", (o) => {
|
|
365
|
+
const m = B(o);
|
|
366
|
+
m && i.presence?.(m);
|
|
367
|
+
}), l.on("document/changed", (o) => i.changed(o)), l.on("replica/changed", (o) => i.replicaChanged?.(o)), l.on("host/notify", (o) => i.notify?.(o)), l.on("host/shortcut", (o) => i.shortcut?.(o)), l.on("ui/action", (o) => i.action?.(o)), l.handle("host/service", (o) => {
|
|
368
|
+
const m = o?.service, R = k.find(([T]) => T === m)?.[1];
|
|
369
|
+
if (!R) throw new b(-32e3, `this host does not serve ${String(m)}`, { reason: "not-allowed" });
|
|
370
|
+
const z = pe(o);
|
|
371
|
+
if (!z) throw new b(-32602, `bad params for ${String(m)}`);
|
|
372
|
+
return R(z.params);
|
|
373
|
+
}), l.on("comments/activated", (o) => {
|
|
374
|
+
typeof o?.id == "string" && o.id && i.comments?.activated(o.id);
|
|
375
|
+
}), w.postMessage({ kitionKitUi: 1, protocol: x, id: E }, r.origin, [v.port2]);
|
|
376
|
+
const y = { ...r.document, bytes: r.document.bytes?.slice(0) }, I = l.request(
|
|
377
|
+
"ui/initialize",
|
|
378
|
+
{ protocol: x, host: r.host, document: y, theme: r.theme, locale: r.locale, shortcuts: r.shortcuts, capabilities: c, capabilitySets: r.capabilitySets ?? [], ui: r.ui },
|
|
379
|
+
{ transfer: !0 }
|
|
380
|
+
);
|
|
381
|
+
return I.then(
|
|
382
|
+
(o) => {
|
|
383
|
+
O = typeof o?.kit?.id == "string" ? o.kit.id : null;
|
|
384
|
+
},
|
|
385
|
+
() => {
|
|
386
|
+
}
|
|
387
|
+
), { peer: l, files: C, initialized: I };
|
|
388
|
+
};
|
|
389
|
+
return new Promise((w, E) => {
|
|
390
|
+
let v = null;
|
|
391
|
+
const l = (y) => {
|
|
392
|
+
y?.peer.close(), y?.files?.end();
|
|
393
|
+
}, O = () => {
|
|
394
|
+
clearTimeout(_), window.removeEventListener("message", C), r.signal?.removeEventListener("abort", q);
|
|
395
|
+
}, q = () => {
|
|
396
|
+
O(), l(v), E(new Error("the kit mount was abandoned"));
|
|
397
|
+
};
|
|
398
|
+
if (r.signal?.aborted) {
|
|
399
|
+
E(new Error("the kit mount was abandoned"));
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
r.signal?.addEventListener("abort", q);
|
|
403
|
+
const _ = setTimeout(() => {
|
|
404
|
+
O(), l(v), E(new Error("the kit did not open the document in time"));
|
|
405
|
+
}, L), C = (y) => {
|
|
406
|
+
if (y.source !== t.contentWindow || !re(y.data) || y.data.ready !== x || r.origin !== "*" && y.origin !== r.origin || v?.id === y.data.id) return;
|
|
407
|
+
l(v);
|
|
408
|
+
const { peer: I, files: o, initialized: m } = $(y.source, y.data.id);
|
|
409
|
+
v = { peer: I, files: o, id: y.data.id }, m.then(
|
|
410
|
+
(R) => {
|
|
411
|
+
v?.peer === I && (O(), w(Ae(I, R, o)));
|
|
412
|
+
},
|
|
413
|
+
(R) => {
|
|
414
|
+
v?.peer === I && (O(), o?.end(), E(R instanceof Error ? R : new Error(String(R))));
|
|
415
|
+
}
|
|
416
|
+
);
|
|
417
|
+
};
|
|
418
|
+
window.addEventListener("message", C), t.contentWindow?.postMessage({ kitionKitUi: 1, hello: x }, r.origin);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
function Ae(t, r, i) {
|
|
422
|
+
return {
|
|
423
|
+
kit: r.kit,
|
|
424
|
+
capabilities: r.capabilities,
|
|
425
|
+
state: () => t.request("document/state", {}),
|
|
426
|
+
save: () => t.request("document/save", {}),
|
|
427
|
+
fileChanged: (s) => t.notify("document/fileChanged", { version: s }),
|
|
428
|
+
fileHeld: (s) => t.notify("document/held", { version: s }),
|
|
429
|
+
setTheme: (s) => t.notify("ui/theme", { theme: s }),
|
|
430
|
+
setLocale: (s) => t.notify("ui/locale", { locale: s }),
|
|
431
|
+
focus: () => t.notify("ui/focus", {}),
|
|
432
|
+
configure: (s) => t.notify("ui/configure", { ui: s }),
|
|
433
|
+
leasesChanged: (s) => t.notify("lease/changed", { leases: s }),
|
|
434
|
+
peersChanged: (s) => t.notify("presence/peers", { peers: s }),
|
|
435
|
+
reveal: (s) => t.notify("document/reveal", { view: s }),
|
|
436
|
+
showComments: (s) => {
|
|
437
|
+
const c = s.flatMap((u) => {
|
|
438
|
+
const g = we(u.anchor);
|
|
439
|
+
return g && typeof u.id == "string" ? [{ id: u.id, anchor: g, resolved: u.resolved === !0, count: Number.isSafeInteger(u.count) ? u.count : 0 }] : [];
|
|
440
|
+
});
|
|
441
|
+
t.notify("comments/show", { threads: c });
|
|
442
|
+
},
|
|
443
|
+
locateComments: async (s) => {
|
|
444
|
+
if (!r.capabilities.includes("comment-anchors")) return s.map(() => !1);
|
|
445
|
+
const { found: c } = await t.request("comments/locate", { anchors: s });
|
|
446
|
+
return s.map((u, g) => c?.[g] === !0);
|
|
447
|
+
},
|
|
448
|
+
onPresence: (s) => t.on("presence/set", (c) => {
|
|
449
|
+
const u = B(c);
|
|
450
|
+
u && s(u);
|
|
451
|
+
}),
|
|
452
|
+
elements: () => t.request("ui/elements", {}),
|
|
453
|
+
check: async (s) => r.capabilities.includes("check") ? (await t.request("document/check", s?.draft ? { draft: !0 } : {})).diagnostics : [],
|
|
454
|
+
ai: {
|
|
455
|
+
inspect: (s) => t.request("ai/inspect", s ?? {}),
|
|
456
|
+
commands: (s) => t.request("ai/commands", { query: s }),
|
|
457
|
+
run: (s, c, u) => t.request("ai/run", {
|
|
458
|
+
steps: s,
|
|
459
|
+
save: c,
|
|
460
|
+
...u?.draft ? { draft: !0 } : {},
|
|
461
|
+
...u?.origin ? { origin: u.origin } : {},
|
|
462
|
+
...u?.originLabel != null ? { originLabel: u.originLabel } : {}
|
|
463
|
+
}),
|
|
464
|
+
preview: (s, c) => t.request("ai/preview", c?.draft ? { maxSize: s, draft: !0 } : { maxSize: s }),
|
|
465
|
+
version: async () => (await t.request("ai/version", {})).version,
|
|
466
|
+
premise: (s, c) => t.request("ai/premise", { method: s, params: c }),
|
|
467
|
+
changes: (s, c) => t.request("ai/changes", c ? { since: s, schema: c } : { since: s })
|
|
468
|
+
},
|
|
469
|
+
draft: {
|
|
470
|
+
state: () => t.request("draft/state", {}),
|
|
471
|
+
ready: () => t.request("draft/ready", {}),
|
|
472
|
+
reopen: () => t.request("draft/reopen", {}),
|
|
473
|
+
compare: (s) => t.request("draft/compare", s ?? {}),
|
|
474
|
+
merge: (s, c) => t.request("draft/merge", c ? { origin: s, schema: c } : { origin: s }),
|
|
475
|
+
discard: () => t.request("draft/discard", {})
|
|
476
|
+
},
|
|
477
|
+
replica: {
|
|
478
|
+
version: async () => (await t.request("replica/version", {})).version,
|
|
479
|
+
exportChanges: (s) => t.request("replica/export", { since: s }),
|
|
480
|
+
importChanges: (s, c) => t.request("replica/import", { changes: s, blobs: c }),
|
|
481
|
+
info: async () => (await t.request("replica/info", {})).docId,
|
|
482
|
+
onChanged: (s) => t.on("replica/changed", (c) => s(c.version))
|
|
483
|
+
},
|
|
484
|
+
model: {
|
|
485
|
+
describe: (s) => t.request("model/describe", s ? { schema: s } : {}),
|
|
486
|
+
batch: (s) => t.request("model/batch", s)
|
|
487
|
+
},
|
|
488
|
+
files: i && { grant: i.grant, revoke: i.revoke, grants: i.grants },
|
|
489
|
+
close: () => {
|
|
490
|
+
t.close(), i?.end();
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
export {
|
|
495
|
+
_e as ACTION_ERROR_REASONS,
|
|
496
|
+
Ce as FETCH_IMAGE_ERROR_REASONS,
|
|
497
|
+
ue as FETCH_IMAGE_TYPES,
|
|
498
|
+
Ee as FILES_METHODS,
|
|
499
|
+
Ne as GENERATE_ERROR_REASONS,
|
|
500
|
+
Pe as GENERATE_PURPOSES,
|
|
501
|
+
ne as HOST_SERVICES,
|
|
502
|
+
x as KIT_UI_PROTOCOL,
|
|
503
|
+
b as KitRpcError,
|
|
504
|
+
$e as LEASE_HELD_REASON,
|
|
505
|
+
ze as OPEN_ERROR_REASONS,
|
|
506
|
+
xe as OPEN_URL_SCHEMES,
|
|
507
|
+
Te as SERVICE_ERROR_REASONS,
|
|
508
|
+
N as extensionOf,
|
|
509
|
+
Ue as fetchImageErrorReason,
|
|
510
|
+
p as fileError,
|
|
511
|
+
Fe as fileErrorReason,
|
|
512
|
+
He as hostRequestErrorReason,
|
|
513
|
+
fe as isFetchableUrl,
|
|
514
|
+
ce as isGeneratePurpose,
|
|
515
|
+
de as isOpenableUrl,
|
|
516
|
+
oe as linkPathFrom,
|
|
517
|
+
qe as mountKit,
|
|
518
|
+
Me as openErrorReason,
|
|
519
|
+
Re as openFileSession,
|
|
520
|
+
we as parseCommentAnchor,
|
|
521
|
+
Ge as parseKitView,
|
|
522
|
+
We as parseLinkRef,
|
|
523
|
+
he as parseLinksPickParams,
|
|
524
|
+
le as parseOpenParams,
|
|
525
|
+
pe as parseServiceParams,
|
|
526
|
+
Se as pickedLinks,
|
|
527
|
+
M as sanitizeFileName,
|
|
528
|
+
ie as serviceAllowed,
|
|
529
|
+
ye as unusedName
|
|
530
|
+
};
|