@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,44 @@
|
|
|
1
|
+
// Flow-test check for UI configuration (Kit UI protocol section 9), run from Node with Playwright:
|
|
2
|
+
// every control in a kit's chrome (top bar, command row or ribbon, drop-down panels, Focus bar,
|
|
3
|
+
// options bar, tool rail, panels, workspace frames) sits in an element with an id, and every id drawn is one the editor lists in
|
|
4
|
+
// `ui/elements`.
|
|
5
|
+
//
|
|
6
|
+
// import { checkUiIds } from '@kition/kit-dev-host/check-ui-ids'
|
|
7
|
+
// const problems = await checkUiIds(frame, await page.evaluate(() => window.devHost.connection().elements()))
|
|
8
|
+
//
|
|
9
|
+
// With `{ strict: true }`, a panel's own id does not cover the controls inside its content: a
|
|
10
|
+
// `WorkspaceLayout` frame (`.kui-ws-frame`) and a `panel:` `KitElement` still cover their tab
|
|
11
|
+
// strip, but each control in a panel's body (`.kui-ws-body`) needs an id of its own, closer than
|
|
12
|
+
// the panel's (`control:…`, `tool:…`). A workspace's gutters are not controls and carry no id; a
|
|
13
|
+
// kit maps upstream's `dock.gutter.*` to their test ids (`<testId>-gutter-<path>`). The frame's
|
|
14
|
+
// structural buttons are not controls either and carry no id: a scrolled row's scroll buttons and
|
|
15
|
+
// a Single line group's chevron (or its one button), which only open the group's popover.
|
|
16
|
+
|
|
17
|
+
/** Answers the problems found in `frame` (a Playwright Frame of the kit); empty when none. */
|
|
18
|
+
export async function checkUiIds(frame, elements, options = {}) {
|
|
19
|
+
return frame.evaluate(
|
|
20
|
+
({ known, strict }) => {
|
|
21
|
+
const scope = '.kui-frame-top, .kui-ribbon-body, .kui-line, .kui-drop-panel, .kui-focus-bar, .kui-options-bar, .kui-tool-rail, .kui-panel, .kui-workspace'
|
|
22
|
+
/** An id that names the whole panel, which in strict mode does not cover its body's controls. */
|
|
23
|
+
const panelWide = (element) => element.classList.contains('kui-ws-frame') || (element.classList.contains('kui-element') && element.getAttribute('data-kit-ui-id').startsWith('panel:'))
|
|
24
|
+
const structural = '.kui-ribbon-scroll, .kui-line-more, .kui-line-collapsed'
|
|
25
|
+
const problems = []
|
|
26
|
+
for (const control of document.querySelectorAll(`:is(${scope}) :is(button, input, select, textarea, [role="menuitem"])`)) {
|
|
27
|
+
if (control.matches(structural)) continue
|
|
28
|
+
let owner = control.closest('[data-kit-ui-id]')
|
|
29
|
+
if (strict && control.closest('.kui-ws-body')) {
|
|
30
|
+
while (owner && panelWide(owner)) owner = owner.parentElement?.closest('[data-kit-ui-id]') ?? null
|
|
31
|
+
// Past the panel's own ids there is nothing in the body to cover the control.
|
|
32
|
+
if (owner && !owner.closest('.kui-ws-body')) owner = null
|
|
33
|
+
}
|
|
34
|
+
if (!owner) problems.push(`no id: ${control.outerHTML.slice(0, 120)}`)
|
|
35
|
+
}
|
|
36
|
+
for (const element of document.querySelectorAll('[data-kit-ui-id]')) {
|
|
37
|
+
const id = element.getAttribute('data-kit-ui-id')
|
|
38
|
+
if (!id.startsWith('host:') && !known.includes(id)) problems.push(`not declared: ${id}`)
|
|
39
|
+
}
|
|
40
|
+
return problems
|
|
41
|
+
},
|
|
42
|
+
{ known: elements.map((element) => element.id), strict: options.strict === true },
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { fileError as I, mountKit as le } from "../kit-host/index.js";
|
|
2
|
+
import { KitRpcError as A } from "../kit-ui-protocol/index.js";
|
|
3
|
+
const fe = /* @__PURE__ */ new Set(["purpose", "title"]), ue = /* @__PURE__ */ new Set(["mime"]), de = /^(application|audio|example|font|haptics|image|message|model|multipart|text|video)\/[a-z0-9][a-z0-9!#$&^_.+-]{0,126}(\s*;\s*[a-z0-9!#$&^_.+-]+=("[^"\\/]*"|[^\s;"\\/]+))*$/i, he = /(^|[\s"'(=])(\/(?:Users|home|root|var|tmp|private|Volumes|mnt|media|etc|opt|srv|data|workspace)\b|[A-Za-z]:[\\/]|\\\\[^\\\s]|~[\\/]|file:)/i;
|
|
4
|
+
function X(e, s = !1) {
|
|
5
|
+
return he.test(e) ? !0 : !s && (/[\\/]/.test(e) || /^\.\.?$/.test(e));
|
|
6
|
+
}
|
|
7
|
+
function pe(e) {
|
|
8
|
+
return de.test(e);
|
|
9
|
+
}
|
|
10
|
+
function R(e, s, c, r, h = 0) {
|
|
11
|
+
if (typeof e == "string") {
|
|
12
|
+
(c === "mime" ? !pe(e) && X(e) : X(e, c === "free")) && r.push({ at: s, value: e });
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!(e === null || typeof e != "object" || h > 8 || e instanceof ArrayBuffer || ArrayBuffer.isView(e)))
|
|
16
|
+
if (Array.isArray(e)) e.forEach((o, i) => R(o, `${s}[${i}]`, c, r, h + 1));
|
|
17
|
+
else for (const [o, i] of Object.entries(e)) R(i, s ? `${s}.${o}` : o, fe.has(o) ? "free" : ue.has(o) ? "mime" : "name", r, h + 1);
|
|
18
|
+
}
|
|
19
|
+
function me(e) {
|
|
20
|
+
const s = [];
|
|
21
|
+
for (const { method: c, params: r } of e) {
|
|
22
|
+
if (!c.startsWith("files/")) continue;
|
|
23
|
+
const h = [];
|
|
24
|
+
R(r, "", "name", h);
|
|
25
|
+
for (const o of h) s.push({ method: c, ...o });
|
|
26
|
+
}
|
|
27
|
+
return s;
|
|
28
|
+
}
|
|
29
|
+
const ge = { pdf: "application/pdf", png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp", svg: "image/svg+xml", txt: "text/plain", json: "application/json" }, U = (e) => e.split("/").some((s) => s.startsWith(".") || s === ""), M = (e) => e.includes("/") ? e.slice(0, e.lastIndexOf("/")) : "";
|
|
30
|
+
function ye(e, s, c = /* @__PURE__ */ new Set()) {
|
|
31
|
+
const r = (o) => c.has(o) || [...e.keys()].some((i) => i.startsWith(`${o}/`));
|
|
32
|
+
return {
|
|
33
|
+
stat: (o) => {
|
|
34
|
+
if (U(o)) return null;
|
|
35
|
+
const i = e.get(o);
|
|
36
|
+
if (i) {
|
|
37
|
+
const l = ge[o.split(".").pop()?.toLowerCase() ?? ""];
|
|
38
|
+
return { kind: "file", size: i.bytes.byteLength, version: String(i.version), ...l ? { mime: l } : {} };
|
|
39
|
+
}
|
|
40
|
+
return r(o) ? { kind: "folder", version: null } : null;
|
|
41
|
+
},
|
|
42
|
+
read: async (o, i, l) => {
|
|
43
|
+
const a = U(o) ? void 0 : e.get(o);
|
|
44
|
+
if (!a) throw I("file-not-granted", "the file is gone");
|
|
45
|
+
const d = l === void 0 ? a.bytes.byteLength : Math.min(a.bytes.byteLength, i + l);
|
|
46
|
+
return { bytes: a.bytes.slice(i, d), version: String(a.version), size: a.bytes.byteLength };
|
|
47
|
+
},
|
|
48
|
+
list: (o) => {
|
|
49
|
+
const i = /* @__PURE__ */ new Set();
|
|
50
|
+
for (const l of [...e.keys(), ...c]) {
|
|
51
|
+
if (!l.startsWith(`${o}/`) || U(l)) continue;
|
|
52
|
+
const a = l.slice(o.length + 1);
|
|
53
|
+
i.add(`${o}/${a.split("/")[0]}`);
|
|
54
|
+
}
|
|
55
|
+
return [...i].sort();
|
|
56
|
+
},
|
|
57
|
+
child: (o, i) => {
|
|
58
|
+
const l = o ?? s();
|
|
59
|
+
return l ? `${l}/${i}` : i;
|
|
60
|
+
},
|
|
61
|
+
commit: async (o, i, l) => {
|
|
62
|
+
const a = e.get(o);
|
|
63
|
+
if (l.mode === "create" && (a || r(o))) throw I("conflict", "a file with this name exists");
|
|
64
|
+
if (l.mode === "replace" && (!a || String(a.version) !== l.expected)) throw I("conflict", "the file changed since it was read");
|
|
65
|
+
!r(M(o)) && M(o) !== "" && c.add(M(o));
|
|
66
|
+
const d = (a?.version ?? 0) + 1;
|
|
67
|
+
return e.set(o, { bytes: i.buffer.slice(i.byteOffset, i.byteOffset + i.byteLength), version: d }), { version: String(d) };
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const Z = {
|
|
72
|
+
light: { colorScheme: "light", tokens: { "--kit-primary": "#5645d4", "--kit-surface": "#ffffff", "--kit-surface-muted": "#fafaf9", "--kit-canvas": "#f6f5f4", "--kit-text": "#1a1a1a", "--kit-text-muted": "#5d5b54", "--kit-border": "#e5e3df" } },
|
|
73
|
+
dark: { colorScheme: "dark", tokens: { "--kit-primary": "#8b7ff0", "--kit-surface": "#1b1e23", "--kit-surface-muted": "#22262c", "--kit-canvas": "#15171b", "--kit-text": "#eceff1", "--kit-text-muted": "#a9b0ba", "--kit-border": "#33373e" } }
|
|
74
|
+
};
|
|
75
|
+
function Q(e, s) {
|
|
76
|
+
const c = s.split(".").pop()?.toLowerCase() ?? "";
|
|
77
|
+
return !e?.length || e.some((r) => r.replace(/^\./, "").toLowerCase() === c);
|
|
78
|
+
}
|
|
79
|
+
function we(e) {
|
|
80
|
+
return e !== "viewer" && e !== "commenter" ? {} : { readOnly: !0, comments: { me: `dev-${e}`, name: e === "viewer" ? "Viewer" : "Commenter", canComment: e === "commenter", othersReadOnly: !1 } };
|
|
81
|
+
}
|
|
82
|
+
function ee(e) {
|
|
83
|
+
const s = [];
|
|
84
|
+
for (const c of e.split("/"))
|
|
85
|
+
if (!(!c || c === "."))
|
|
86
|
+
if (c === "..") {
|
|
87
|
+
if (!s.length) return null;
|
|
88
|
+
s.pop();
|
|
89
|
+
} else s.push(c);
|
|
90
|
+
return s.join("/");
|
|
91
|
+
}
|
|
92
|
+
function ke(e, s, c) {
|
|
93
|
+
const r = s.includes("/") ? s.slice(0, s.lastIndexOf("/")) : "";
|
|
94
|
+
if (e.path) {
|
|
95
|
+
const d = ee(e.path.startsWith("/") ? e.path : `${r}/${e.path}`);
|
|
96
|
+
return d ? { path: d, exists: c.has(d) } : null;
|
|
97
|
+
}
|
|
98
|
+
if (!e.name || e.name.includes("/")) return null;
|
|
99
|
+
const h = s.includes(".") ? s.slice(s.lastIndexOf(".")) : "", o = (d) => (d.split("/").pop() ?? "").replace(/\.[^.]*$/, "").toLowerCase(), i = [...c.keys()].filter((d) => o(d) === e.name.toLowerCase()), l = i.find((d) => d.endsWith(h)) ?? i[0];
|
|
100
|
+
if (l) return { path: l, exists: !0 };
|
|
101
|
+
const a = ee(`${r}/${e.name}${h}`);
|
|
102
|
+
return a ? { path: a, exists: !1 } : null;
|
|
103
|
+
}
|
|
104
|
+
const te = ["menus", "line", "classic", "focus"];
|
|
105
|
+
function ve(e) {
|
|
106
|
+
const s = [];
|
|
107
|
+
for (const c of (e ?? "").split(",").map((r) => r.trim()).filter(Boolean))
|
|
108
|
+
te.includes(c) ? s.push(c) : console.warn(`kit-dev-host: ?modes= names an unknown display mode "${c}" (one of ${te.join(", ")})`);
|
|
109
|
+
return s.length ? { allowed: s, default: s[0] } : void 0;
|
|
110
|
+
}
|
|
111
|
+
function Se(e = {}) {
|
|
112
|
+
const s = /* @__PURE__ */ new Map(), c = document.getElementById("kit"), r = document.getElementById("status"), h = document.getElementById("file"), o = [], i = e.entry ?? "./index.html", l = e.pickable ?? /\.(png|jpe?g|gif|svg|webp)$/i;
|
|
113
|
+
let a = null;
|
|
114
|
+
const d = e.presence === !0 || new URLSearchParams(location.search).get("presence") === "1", j = [], B = [];
|
|
115
|
+
let $ = [];
|
|
116
|
+
const z = /* @__PURE__ */ new Set(), N = [], T = [], S = [], H = [], ne = e.generate === !0 || new URLSearchParams(location.search).get("generate") === "1", W = [], D = [], se = e.open === !0 || new URLSearchParams(location.search).get("open") === "1", x = [], q = [], F = [];
|
|
117
|
+
let y = "";
|
|
118
|
+
const J = `kit-dev-host:personal:${location.pathname}`, _ = [];
|
|
119
|
+
let L = new URLSearchParams(location.search).get("scheme") === "dark" ? "dark" : "light";
|
|
120
|
+
const C = ve(new URLSearchParams(location.search).get("modes"));
|
|
121
|
+
let E = C ? { modes: C } : {};
|
|
122
|
+
const oe = () => {
|
|
123
|
+
try {
|
|
124
|
+
return JSON.parse(localStorage.getItem(J) ?? "[]");
|
|
125
|
+
} catch {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
}, K = () => ({ ...E, personal: { hide: oe() } }), w = document.createElement("details");
|
|
129
|
+
w.innerHTML = '<summary>UI configuration</summary><textarea rows="6" cols="60" spellcheck="false">{}</textarea><button type="button">Apply</button><select><option value="light">Light</option><option value="dark">Dark</option></select>', r.parentElement?.append(w);
|
|
130
|
+
const V = w.querySelector("textarea"), v = w.querySelector("select");
|
|
131
|
+
v.value = L, w.querySelector("button").addEventListener("click", () => {
|
|
132
|
+
try {
|
|
133
|
+
G(JSON.parse(V.value));
|
|
134
|
+
} catch (n) {
|
|
135
|
+
r.textContent = `configuration: ${n instanceof Error ? n.message : String(n)}`;
|
|
136
|
+
}
|
|
137
|
+
}), v.addEventListener("change", () => Y(v.value === "dark" ? "dark" : "light"));
|
|
138
|
+
function G(n) {
|
|
139
|
+
E = { hide: n.hide, disable: n.disable, add: n.add, modes: n.modes ?? C }, V.value = JSON.stringify(E, null, 2), a?.configure(K());
|
|
140
|
+
}
|
|
141
|
+
function Y(n) {
|
|
142
|
+
L = n, v.value = n, a?.setTheme(Z[n]);
|
|
143
|
+
}
|
|
144
|
+
async function P(n, p, m = {}) {
|
|
145
|
+
a?.close(), y = n, s.set(n, { bytes: p, version: 1 }), r.textContent = `opening ${n}…`, c.src = `${i}?${Date.now()}`;
|
|
146
|
+
const b = s.get(n);
|
|
147
|
+
try {
|
|
148
|
+
a = await le(c, {
|
|
149
|
+
origin: location.origin,
|
|
150
|
+
host: { name: "Development host", version: "1" },
|
|
151
|
+
document: {
|
|
152
|
+
path: n,
|
|
153
|
+
name: n.split("/").pop() ?? n,
|
|
154
|
+
bytes: b.bytes.slice(0),
|
|
155
|
+
version: String(b.version),
|
|
156
|
+
lend: e.lend ? { root: new URL(e.lend.root, location.href).href, folder: e.lend.folder } : void 0,
|
|
157
|
+
...we(new URLSearchParams(location.search).get("role")),
|
|
158
|
+
...m.view ? { view: m.view } : {}
|
|
159
|
+
},
|
|
160
|
+
theme: Z[L],
|
|
161
|
+
locale: new URLSearchParams(location.search).get("locale") ?? navigator.language,
|
|
162
|
+
shortcuts: ["Cmd+W", "Cmd+N", "Cmd+O", "Cmd+,"],
|
|
163
|
+
ui: K(),
|
|
164
|
+
handlers: {
|
|
165
|
+
read: ({ path: t, offset: f, length: g }) => {
|
|
166
|
+
const u = s.get(t);
|
|
167
|
+
if (!u) throw new Error(`${t} is not in the workspace`);
|
|
168
|
+
const k = f ?? 0;
|
|
169
|
+
return { bytes: f != null || g != null ? u.bytes.slice(k, g != null ? k + g : void 0) : u.bytes.slice(0), version: String(u.version), size: u.bytes.byteLength };
|
|
170
|
+
},
|
|
171
|
+
stamp: ({ path: t }) => ({ version: s.has(t) ? String(s.get(t).version) : null }),
|
|
172
|
+
write: ({ path: t, bytes: f, mode: g }) => {
|
|
173
|
+
let u = t;
|
|
174
|
+
if (g !== "save") for (let O = 2; s.has(u); O += 1) u = t.replace(/(\.[^./]+)?$/, ` ${O}$1`);
|
|
175
|
+
const k = (s.get(u)?.version ?? 0) + 1;
|
|
176
|
+
return s.set(u, { bytes: f, version: k }), { path: u, version: String(k) };
|
|
177
|
+
},
|
|
178
|
+
// The first workspace file the host may answer with and the kit accepts (`accept` lists extensions).
|
|
179
|
+
pick: ({ accept: t }) => ({ path: [...s.keys()].find((f) => l.test(f) && Q(t, f)) ?? null }),
|
|
180
|
+
// Files to link, in place (UI-N2): mountKit makes them document-relative links.
|
|
181
|
+
pickLinks: (t) => {
|
|
182
|
+
F.push(t);
|
|
183
|
+
const f = q.shift();
|
|
184
|
+
return (f ? typeof f == "function" ? f(t) : f : [...s.keys()].filter((u) => u !== n && l.test(u) && Q(t.accept, u))).filter((u) => s.has(u)).map((u) => ({ path: u, version: String(s.get(u).version) }));
|
|
185
|
+
},
|
|
186
|
+
openAgent: () => {
|
|
187
|
+
r.textContent = "the editor asked for the agent";
|
|
188
|
+
},
|
|
189
|
+
changed: (t) => {
|
|
190
|
+
o.push(t), r.textContent = `${n}: revision ${t.revision}${t.dirty ? ", unsaved" : ""}`;
|
|
191
|
+
},
|
|
192
|
+
notify: (t) => {
|
|
193
|
+
r.textContent = `${t.level}: ${t.title}`;
|
|
194
|
+
},
|
|
195
|
+
shortcut: (t) => {
|
|
196
|
+
r.textContent = `host shortcut ${t.key}`;
|
|
197
|
+
},
|
|
198
|
+
customize: ({ personal: t }) => {
|
|
199
|
+
localStorage.setItem(J, JSON.stringify(t.hide));
|
|
200
|
+
},
|
|
201
|
+
action: (t) => {
|
|
202
|
+
_.push(t), r.textContent = `host button ${t.id}`;
|
|
203
|
+
},
|
|
204
|
+
schema: (t) => {
|
|
205
|
+
B.push(t);
|
|
206
|
+
},
|
|
207
|
+
...d ? { presence: (t) => void j.push(t) } : {},
|
|
208
|
+
...ne ? { generate: (t) => re(t) } : {},
|
|
209
|
+
...se ? { open: (t) => ie(t), openUrl: (t) => ce(t) } : {}
|
|
210
|
+
},
|
|
211
|
+
...e.kitFiles ? {
|
|
212
|
+
files: {
|
|
213
|
+
storage: ye(s, () => y.includes("/") ? y.slice(0, y.lastIndexOf("/")) : "", z),
|
|
214
|
+
kit: "dev-kit",
|
|
215
|
+
principal: "dev-person",
|
|
216
|
+
manifest: e.kitFiles,
|
|
217
|
+
pick: async (t) => {
|
|
218
|
+
const f = N.shift();
|
|
219
|
+
return typeof f == "function" ? f(t) : f ?? [];
|
|
220
|
+
},
|
|
221
|
+
print: async ({ bytes: t, title: f }) => (H.push({ title: f, size: t.byteLength }), window.devHost.printAnswer),
|
|
222
|
+
log: (t) => void T.push(t),
|
|
223
|
+
trace: (t, f) => void S.push({ method: t, params: f })
|
|
224
|
+
}
|
|
225
|
+
} : {}
|
|
226
|
+
}), d && $.length && a.peersChanged($), r.textContent = `${n} open in ${a.kit.id} ${a.kit.version}`;
|
|
227
|
+
} catch (t) {
|
|
228
|
+
r.textContent = `could not open ${n}: ${t instanceof Error ? t.message : String(t)}`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async function re(n) {
|
|
232
|
+
W.push(n), r.textContent = `the editor asked to generate for ${n.purpose}`;
|
|
233
|
+
const p = D.shift() ?? { refuse: "unavailable" }, m = typeof p == "function" ? await p(n) : p;
|
|
234
|
+
if ("refuse" in m) throw new A(-32e3, `the development host refused: ${m.refuse}`, { reason: m.refuse });
|
|
235
|
+
return m;
|
|
236
|
+
}
|
|
237
|
+
async function ie(n) {
|
|
238
|
+
x.push({ method: "host/open", params: n }), r.textContent = `the editor asked to open ${JSON.stringify(n.link)}`;
|
|
239
|
+
const p = ke(n.link, y, s);
|
|
240
|
+
if (!p) throw new A(-32e3, "the link is not in the workspace", { reason: "not-found" });
|
|
241
|
+
if (!p.exists) {
|
|
242
|
+
if (!n.create) throw new A(-32e3, `${p.path} is not in the workspace`, { reason: "not-found" });
|
|
243
|
+
s.set(p.path, { bytes: new ArrayBuffer(0), version: 1 });
|
|
244
|
+
}
|
|
245
|
+
return { opened: window.devHost.openAnswer };
|
|
246
|
+
}
|
|
247
|
+
async function ce(n) {
|
|
248
|
+
return x.push({ method: "host/openUrl", params: n }), r.textContent = `the editor asked to open ${n.url}`, { opened: window.devHost.openAnswer };
|
|
249
|
+
}
|
|
250
|
+
function ae(n) {
|
|
251
|
+
$ = n, d && a?.peersChanged(n);
|
|
252
|
+
}
|
|
253
|
+
window.devHost = {
|
|
254
|
+
files: s,
|
|
255
|
+
connection: () => a,
|
|
256
|
+
open: P,
|
|
257
|
+
changes: o,
|
|
258
|
+
configure: G,
|
|
259
|
+
actions: _,
|
|
260
|
+
setScheme: Y,
|
|
261
|
+
presences: j,
|
|
262
|
+
setPeers: ae,
|
|
263
|
+
schemas: B,
|
|
264
|
+
folders: z,
|
|
265
|
+
scriptPick: (...n) => void N.push(...n),
|
|
266
|
+
grants: T,
|
|
267
|
+
fileRequests: S,
|
|
268
|
+
prints: H,
|
|
269
|
+
printAnswer: !0,
|
|
270
|
+
checkNoPaths: () => me(S),
|
|
271
|
+
generated: W,
|
|
272
|
+
scriptGenerate: (...n) => void D.push(...n),
|
|
273
|
+
opens: x,
|
|
274
|
+
openAnswer: !0,
|
|
275
|
+
scriptLinkPick: (...n) => void q.push(...n),
|
|
276
|
+
linkPicks: F
|
|
277
|
+
}, h?.addEventListener("change", async () => {
|
|
278
|
+
const n = h.files?.[0];
|
|
279
|
+
n && await P(n.name, await n.arrayBuffer());
|
|
280
|
+
}), (async () => {
|
|
281
|
+
for (const [m, b] of Object.entries(e.files ?? {})) {
|
|
282
|
+
const t = await fetch(b).catch(() => null);
|
|
283
|
+
t?.ok && s.set(m, { bytes: await t.arrayBuffer(), version: 1 });
|
|
284
|
+
}
|
|
285
|
+
if (!e.sample) {
|
|
286
|
+
r.textContent = "choose a file";
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const n = await fetch(e.sample).catch(() => null);
|
|
290
|
+
if (!n?.ok) {
|
|
291
|
+
r.textContent = "choose a file";
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const p = decodeURIComponent(e.sample.split("/").pop() ?? "Sample");
|
|
295
|
+
await P(e.lend?.folder ? `${e.lend.folder}/${p}` : p, await n.arrayBuffer());
|
|
296
|
+
})();
|
|
297
|
+
}
|
|
298
|
+
export {
|
|
299
|
+
Q as accepts,
|
|
300
|
+
me as checkNoPaths,
|
|
301
|
+
pe as isMimeType,
|
|
302
|
+
X as isPathShaped,
|
|
303
|
+
ye as memoryFilesStorage,
|
|
304
|
+
ve as modesInit,
|
|
305
|
+
ke as resolveLink,
|
|
306
|
+
we as roleInit,
|
|
307
|
+
Se as startDevHost
|
|
308
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// What Single line's row (kit-editor's EditorFrame in `line` mode) shows, read in the kit's page:
|
|
2
|
+
// the enabled buttons drawn inline (not a group's chevron, a collapsed group's one button, or a
|
|
3
|
+
// popover) and inside the row's box, the buttons cut off outside it, the inline fields, and which of `primary` (test ids) are drawn inline. It must stay
|
|
4
|
+
// self-contained: Playwright copies its source into the page (`frame.evaluate(lineRowReport, ids)`).
|
|
5
|
+
|
|
6
|
+
/** Answers `{ buttons, clipped, fields, found, missing }` for the row in this document: `clipped` names buttons drawn outside the row's box, which `buttons` does not count. */
|
|
7
|
+
export function lineRowReport(primary) {
|
|
8
|
+
const visible = (element) => (typeof element.checkVisibility === 'function' ? element.checkVisibility() : true)
|
|
9
|
+
const disabled = (button) => button.disabled || button.closest('fieldset[disabled]') != null
|
|
10
|
+
const row = document.querySelector('.kui-line')
|
|
11
|
+
const inline = row ? [...row.querySelectorAll('.kui-line-inline')].filter((part) => !part.hidden) : []
|
|
12
|
+
const within = (selector) => inline.flatMap((part) => [...part.querySelectorAll(selector)]).filter(visible)
|
|
13
|
+
const ids = new Set(within('[data-testid]').map((element) => element.getAttribute('data-testid')))
|
|
14
|
+
// A button drawn outside the row's box (a grid's other rows) is cut off, whatever it reports.
|
|
15
|
+
const box = row?.getBoundingClientRect()
|
|
16
|
+
const outside = (element) => {
|
|
17
|
+
const at = element.getBoundingClientRect()
|
|
18
|
+
return box != null && box.height > 0 && at.height > 0 && (at.top < box.top - 1 || at.bottom > box.bottom + 1)
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
buttons: within('button').filter((button) => !disabled(button) && !outside(button)).length,
|
|
22
|
+
clipped: within('button').filter(outside).map((button) => button.getAttribute('data-testid') ?? button.getAttribute('aria-label') ?? 'button'),
|
|
23
|
+
fields: within('select, input').length,
|
|
24
|
+
found: primary.filter((id) => ids.has(id)),
|
|
25
|
+
missing: primary.filter((id) => !ids.has(id)),
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The kit's controls the Focus bar (kit-editor's EditorFrame in `focus` mode) covers in this
|
|
31
|
+
* document: visible buttons, fields, tabs, and sliders outside the bar whose box meets the bar's,
|
|
32
|
+
* by test id, else name, else tag. Answers `['no Focus bar']` when the bar is missing.
|
|
33
|
+
*/
|
|
34
|
+
export function focusBarReport() {
|
|
35
|
+
const bar = document.querySelector('.kui-focus-bar')
|
|
36
|
+
if (!bar) return ['no Focus bar']
|
|
37
|
+
const visible = (element) => (typeof element.checkVisibility === 'function' ? element.checkVisibility() : true)
|
|
38
|
+
const area = bar.getBoundingClientRect()
|
|
39
|
+
const covered = []
|
|
40
|
+
for (const element of document.querySelectorAll('button, input, select, textarea, [role="tab"], [role="slider"], [role="button"]')) {
|
|
41
|
+
if (bar.contains(element) || !visible(element)) continue
|
|
42
|
+
const box = element.getBoundingClientRect()
|
|
43
|
+
if (box.width === 0 || box.height === 0) continue
|
|
44
|
+
if (box.right > area.left && box.left < area.right && box.bottom > area.top && box.top < area.bottom) covered.push(element.getAttribute('data-testid') ?? element.getAttribute('aria-label') ?? element.tagName.toLowerCase())
|
|
45
|
+
}
|
|
46
|
+
return covered
|
|
47
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// A smoke test of a kit's editor in each display mode (kit-editor's EditorFrame), through the kit's
|
|
2
|
+
// development host. For Menus, Single line, and Classic it opens dev.html with only that mode and
|
|
3
|
+
// Focus allowed (`?modes=<mode>,focus`), checks the frame shows that mode, enters Focus with
|
|
4
|
+
// Cmd/Ctrl+\, leaves it with Escape, enters it again from the mode menu (whose row then
|
|
5
|
+
// unmounts) and leaves it with Escape, checks Single line's row mounts no test id twice (with a
|
|
6
|
+
// group's popover closed and open), and reports page errors. The kit passes Playwright's
|
|
7
|
+
// browser type and Vite's createServer (it has them installed):
|
|
8
|
+
//
|
|
9
|
+
// import { chromium, webkit } from 'playwright'
|
|
10
|
+
// import { createServer } from 'vite'
|
|
11
|
+
// import { runModeSmoke } from '@kition/kit-dev-host/mode-smoke'
|
|
12
|
+
// await runModeSmoke({ kit: 'kit.doc', config: new URL('../vite.config.ts', import.meta.url).pathname, browser: process.argv[2] === 'webkit' ? webkit : chromium, createServer })
|
|
13
|
+
//
|
|
14
|
+
// With `line: { tab, primary, min }` it also opens the editor with Single line chosen and Menus
|
|
15
|
+
// allowed (`?modes=line,menus,classic,focus`) at 1440 and 1024 px wide, selects `tab`, and
|
|
16
|
+
// checks that the row still fits (the frame did not step down to Menus), shows at least `min`
|
|
17
|
+
// (default 6) enabled buttons, and draws every test id in `primary` inline. With KUI_SHOTS set to
|
|
18
|
+
// a folder it saves `<kit>-line-<width>.png` there.
|
|
19
|
+
//
|
|
20
|
+
// At the editor widths Kition gives a kit (1165 and 749 px: 1440 and 1024 px windows less its
|
|
21
|
+
// sidebar) it opens the editor in Classic with every mode allowed (`?modes=classic,line,menus,focus`)
|
|
22
|
+
// and checks that Classic still shows (its ribbon gives way in steps, so the frame does not step
|
|
23
|
+
// down), then enters Focus and checks that the Focus bar covers none of the kit's controls (a bar
|
|
24
|
+
// a kit draws at the bottom, such as a timeline, must be in `FrameChrome`). With KUI_SHOTS it
|
|
25
|
+
// saves `<kit>-classic-<width>.png` and `<kit>-focus-<width>.png`.
|
|
26
|
+
//
|
|
27
|
+
// An editor whose tabs come from the engine's commands draws them a moment after the file opens:
|
|
28
|
+
// each step waits for the frame's tabs (up to 5 s) before reading the mode. An editor without tabs
|
|
29
|
+
// shows Menus whatever mode is chosen, and its mode button enters Focus itself; the smoke expects
|
|
30
|
+
// that of it.
|
|
31
|
+
//
|
|
32
|
+
// Prints PASS or FAIL per step; sets a failing exit code when a step failed.
|
|
33
|
+
|
|
34
|
+
import { mkdir } from 'node:fs/promises'
|
|
35
|
+
import { focusBarReport, lineRowReport } from './lineRow.mjs'
|
|
36
|
+
|
|
37
|
+
/** Whether the kit's frame draws tabs (or menus), waiting up to 5 s for tabs built from the engine's commands. */
|
|
38
|
+
async function hasTabs(frame) {
|
|
39
|
+
try {
|
|
40
|
+
await frame.locator('.kui-frame-top [role="tab"], .kui-frame-top .kui-menu-bar-item').first().waitFor({ state: 'attached', timeout: 5000 })
|
|
41
|
+
return true
|
|
42
|
+
} catch {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The frame's shown mode once it is `wanted` (or after 3 s, whatever it is then). */
|
|
48
|
+
async function modeOnce(page, wanted) {
|
|
49
|
+
const kitFrame = await (await page.$('#kit')).contentFrame()
|
|
50
|
+
await kitFrame.waitForFunction((mode) => document.querySelector('.kui-app')?.getAttribute('data-mode') === mode, wanted, { timeout: 3000 }).catch(() => undefined)
|
|
51
|
+
return kitFrame.evaluate(() => document.querySelector('.kui-app')?.getAttribute('data-mode') ?? null)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Runs the smoke; `locale` is the dev page's `?locale=`. */
|
|
55
|
+
|
|
56
|
+
// The modifier the editor reads for Mod+\ (kit-editor's isMac tests navigator.platform). Not
|
|
57
|
+
// Playwright's ControlOrMeta, which follows the OS running the test: Playwright's WebKit reports a
|
|
58
|
+
// Mac platform on Linux too, so there the editor expects Meta while ControlOrMeta presses Control.
|
|
59
|
+
const primaryModifier = async (page) => ((await page.evaluate(() => /Mac|iPhone|iPad/i.test(navigator.platform))) ? 'Meta' : 'Control')
|
|
60
|
+
export async function runModeSmoke({ kit, config, browser: type, createServer, locale = 'en-US', line = null }) {
|
|
61
|
+
const server = await createServer({ configFile: config, server: { port: 0, host: '127.0.0.1' }, logLevel: 'error' })
|
|
62
|
+
await server.listen()
|
|
63
|
+
const origin = `http://127.0.0.1:${server.httpServer.address().port}`
|
|
64
|
+
const browser = await type.launch()
|
|
65
|
+
let failures = 0
|
|
66
|
+
const step = (name, ok, detail = '') => {
|
|
67
|
+
if (!ok) failures += 1
|
|
68
|
+
console.log(`${ok ? 'PASS' : 'FAIL'} ${kit} ${name}${detail ? ` - ${detail}` : ''}`)
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
for (const mode of ['menus', 'line', 'classic']) {
|
|
72
|
+
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } })
|
|
73
|
+
const page = await context.newPage()
|
|
74
|
+
const errors = []
|
|
75
|
+
page.on('pageerror', (error) => errors.push(error.message))
|
|
76
|
+
await page.goto(`${origin}/dev.html?modes=${mode},focus&locale=${locale}`)
|
|
77
|
+
await page.waitForFunction(() => document.getElementById('status')?.textContent?.includes(' open in '), null, { timeout: 90000 })
|
|
78
|
+
const frame = page.frameLocator('#kit')
|
|
79
|
+
const app = frame.locator('.kui-app')
|
|
80
|
+
// Without tabs every mode draws as Menus, and the mode button is a Focus button.
|
|
81
|
+
const tabs = await hasTabs(frame)
|
|
82
|
+
const expected = tabs ? mode : 'menus'
|
|
83
|
+
const shown = await modeOnce(page, expected)
|
|
84
|
+
step(`${mode}: shows ${expected}${tabs ? '' : ' (no tabs)'}`, shown === expected, shown ?? 'no frame')
|
|
85
|
+
await app.focus()
|
|
86
|
+
await page.keyboard.press(`${await primaryModifier(page)}+Backslash`)
|
|
87
|
+
step(`${mode}: Cmd+\\ enters Focus`, (await app.getAttribute('data-mode')) === 'focus' && (await frame.locator('.kui-focus-bar').count()) === 1)
|
|
88
|
+
await page.keyboard.press('Escape')
|
|
89
|
+
step(`${mode}: Escape leaves Focus`, (await app.getAttribute('data-mode')) === expected)
|
|
90
|
+
const modeButton = frame.locator('.kui-mode-button')
|
|
91
|
+
if (await modeButton.count()) {
|
|
92
|
+
await modeButton.click()
|
|
93
|
+
if (tabs) await frame.locator('[data-testid$="-mode-focus"]').click()
|
|
94
|
+
step(`${mode}: the mode ${tabs ? 'menu' : 'button'} enters Focus`, (await app.getAttribute('data-mode')) === 'focus')
|
|
95
|
+
await page.keyboard.press('Escape')
|
|
96
|
+
step(`${mode}: Escape leaves Focus entered from the ${tabs ? 'menu' : 'button'}`, (await app.getAttribute('data-mode')) === expected)
|
|
97
|
+
}
|
|
98
|
+
if (mode === 'line') {
|
|
99
|
+
const kitFrame = await (await page.$('#kit')).contentFrame()
|
|
100
|
+
const repeated = () =>
|
|
101
|
+
kitFrame.evaluate(() => {
|
|
102
|
+
const ids = [...document.querySelectorAll('.kui-line [data-testid]')].map((element) => element.getAttribute('data-testid'))
|
|
103
|
+
return [...new Set(ids.filter((id, index) => ids.indexOf(id) !== index))]
|
|
104
|
+
})
|
|
105
|
+
const closed = await repeated()
|
|
106
|
+
step('line: no test id twice in the row', closed.length === 0, closed.join(', '))
|
|
107
|
+
const opener = frame.locator('.kui-line-more, .kui-line-collapsed').first()
|
|
108
|
+
if (await opener.count()) {
|
|
109
|
+
await opener.click()
|
|
110
|
+
const open = await repeated()
|
|
111
|
+
step('line: no test id twice with a popover open', open.length === 0, open.join(', '))
|
|
112
|
+
await page.keyboard.press('Escape')
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
step(`${mode}: no page errors`, errors.length === 0, errors.join('; '))
|
|
116
|
+
await context.close()
|
|
117
|
+
}
|
|
118
|
+
const shots = process.env.KUI_SHOTS
|
|
119
|
+
if (shots) await mkdir(shots, { recursive: true })
|
|
120
|
+
for (const width of [1165, 749]) {
|
|
121
|
+
const context = await browser.newContext({ viewport: { width, height: 900 } })
|
|
122
|
+
const page = await context.newPage()
|
|
123
|
+
const errors = []
|
|
124
|
+
page.on('pageerror', (error) => errors.push(error.message))
|
|
125
|
+
await page.goto(`${origin}/dev.html?modes=classic,line,menus,focus&locale=${locale}`)
|
|
126
|
+
await page.waitForFunction(() => document.getElementById('status')?.textContent?.includes(' open in '), null, { timeout: 90000 })
|
|
127
|
+
const frame = page.frameLocator('#kit')
|
|
128
|
+
const app = frame.locator('.kui-app')
|
|
129
|
+
const tabs = await hasTabs(frame)
|
|
130
|
+
// The ribbon gives way a step per drawing, and the frame steps down after that.
|
|
131
|
+
await page.waitForTimeout(800)
|
|
132
|
+
const shown = await modeOnce(page, tabs ? 'classic' : 'menus')
|
|
133
|
+
if (tabs) step(`classic ${width}: Classic fits (the ribbon gives way, the frame does not step down)`, shown === 'classic', shown ?? 'no frame')
|
|
134
|
+
else step(`classic ${width}: an editor without tabs shows Menus`, shown === 'menus', shown ?? 'no frame')
|
|
135
|
+
if (shots) await page.screenshot({ path: `${shots}/${kit}-classic-${width}.png` })
|
|
136
|
+
await app.focus()
|
|
137
|
+
await page.keyboard.press(`${await primaryModifier(page)}+Backslash`)
|
|
138
|
+
await page.waitForTimeout(300)
|
|
139
|
+
const kitFrame = await (await page.$('#kit')).contentFrame()
|
|
140
|
+
const covered = await kitFrame.evaluate(focusBarReport)
|
|
141
|
+
step(`focus ${width}: the Focus bar covers none of the kit's controls`, covered.length === 0, covered.join(', '))
|
|
142
|
+
if (shots) await page.screenshot({ path: `${shots}/${kit}-focus-${width}.png` })
|
|
143
|
+
step(`classic and focus ${width}: no page errors`, errors.length === 0, errors.join('; '))
|
|
144
|
+
await context.close()
|
|
145
|
+
}
|
|
146
|
+
if (line) {
|
|
147
|
+
for (const width of [1440, 1024]) {
|
|
148
|
+
const context = await browser.newContext({ viewport: { width, height: 900 } })
|
|
149
|
+
const page = await context.newPage()
|
|
150
|
+
const errors = []
|
|
151
|
+
page.on('pageerror', (error) => errors.push(error.message))
|
|
152
|
+
await page.goto(`${origin}/dev.html?modes=line,menus,classic,focus&locale=${locale}`)
|
|
153
|
+
await page.waitForFunction(() => document.getElementById('status')?.textContent?.includes(' open in '), null, { timeout: 90000 })
|
|
154
|
+
const frame = page.frameLocator('#kit')
|
|
155
|
+
const app = frame.locator('.kui-app')
|
|
156
|
+
await page.waitForTimeout(300)
|
|
157
|
+
if (line.tab && (await app.getAttribute('data-mode')) === 'line') await frame.getByTestId(`ribbon-tab-${line.tab}`).click()
|
|
158
|
+
// The frame measures the row after drawing it, and steps down after that.
|
|
159
|
+
await page.waitForTimeout(500)
|
|
160
|
+
const shown = await app.getAttribute('data-mode')
|
|
161
|
+
step(`line ${width}: ${line.tab ?? 'the first tab'} fits in Single line`, shown === 'line', shown ?? 'no frame')
|
|
162
|
+
const kitFrame = await (await page.$('#kit')).contentFrame()
|
|
163
|
+
const report = await kitFrame.evaluate(lineRowReport, line.primary ?? [])
|
|
164
|
+
const min = line.min ?? 6
|
|
165
|
+
step(`line ${width}: at least ${min} enabled buttons in the row`, report.buttons >= min, `${report.buttons} buttons, ${report.fields} fields`)
|
|
166
|
+
step(`line ${width}: the primary items are in the row`, report.missing.length === 0, report.missing.join(', '))
|
|
167
|
+
step(`line ${width}: no button is cut off outside the row`, report.clipped.length === 0, report.clipped.join(', '))
|
|
168
|
+
if (shots) await page.screenshot({ path: `${shots}/${kit}-line-${width}.png` })
|
|
169
|
+
step(`line ${width}: no page errors`, errors.length === 0, errors.join('; '))
|
|
170
|
+
await context.close()
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} finally {
|
|
174
|
+
await browser.close()
|
|
175
|
+
await server.close()
|
|
176
|
+
}
|
|
177
|
+
if (failures) process.exitCode = 1
|
|
178
|
+
}
|