obsidian-plugin-dev-kit 0.0.0-stage → 0.3.2
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/LICENSE +21 -0
- package/README.md +223 -2
- package/bin/opdk.js +34 -0
- package/dist/build/args.d.ts +10 -0
- package/dist/build/args.js +45 -0
- package/dist/build/bundle-check.d.ts +17 -0
- package/dist/build/bundle-check.js +42 -0
- package/dist/build/bundle-file.d.ts +4 -0
- package/dist/build/bundle-file.js +29 -0
- package/dist/build/commands.d.ts +5 -0
- package/dist/build/commands.js +109 -0
- package/dist/build/config.d.ts +3 -0
- package/dist/build/config.js +103 -0
- package/dist/build/css-imports.d.ts +23 -0
- package/dist/build/css-imports.js +50 -0
- package/dist/build/css-step.d.ts +10 -0
- package/dist/build/css-step.js +27 -0
- package/dist/build/css.d.ts +24 -0
- package/dist/build/css.js +47 -0
- package/dist/build/options.d.ts +55 -0
- package/dist/build/options.js +70 -0
- package/dist/build/release.d.ts +5 -0
- package/dist/build/release.js +34 -0
- package/dist/build/report.d.ts +7 -0
- package/dist/build/report.js +16 -0
- package/dist/build/vault.d.ts +26 -0
- package/dist/build/vault.js +290 -0
- package/dist/build-info.json +1 -0
- package/dist/cli/argv.d.ts +14 -0
- package/dist/cli/argv.js +18 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/commands.js +7 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +23 -0
- package/dist/cli/process-reporter.d.ts +5 -0
- package/dist/cli/process-reporter.js +15 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.js +15 -0
- package/dist/cli/reporter.d.ts +53 -0
- package/dist/cli/reporter.js +100 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.js +61 -0
- package/dist/cli/types.d.ts +27 -0
- package/dist/cli/types.js +1 -0
- package/dist/cli/version.d.ts +13 -0
- package/dist/cli/version.js +61 -0
- package/dist/config/define-config.d.ts +3 -0
- package/dist/config/define-config.js +4 -0
- package/dist/config/load-config.d.ts +6 -0
- package/dist/config/load-config.js +70 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +72 -0
- package/dist/config/types.d.ts +146 -0
- package/dist/config/types.js +23 -0
- package/dist/demo/args.d.ts +4 -0
- package/dist/demo/args.js +13 -0
- package/dist/demo/checks.d.ts +56 -0
- package/dist/demo/checks.js +124 -0
- package/dist/demo/commands.d.ts +3 -0
- package/dist/demo/commands.js +65 -0
- package/dist/demo/config.d.ts +57 -0
- package/dist/demo/config.js +337 -0
- package/dist/demo/ffmpeg-run.d.ts +18 -0
- package/dist/demo/ffmpeg-run.js +59 -0
- package/dist/demo/ffmpeg.d.ts +63 -0
- package/dist/demo/ffmpeg.js +111 -0
- package/dist/demo/films.d.ts +46 -0
- package/dist/demo/films.js +134 -0
- package/dist/demo/phone-layout.d.ts +38 -0
- package/dist/demo/phone-layout.js +98 -0
- package/dist/demo/phone-render.d.ts +28 -0
- package/dist/demo/phone-render.js +124 -0
- package/dist/demo/published.d.ts +16 -0
- package/dist/demo/published.js +72 -0
- package/dist/demo/run.d.ts +31 -0
- package/dist/demo/run.js +397 -0
- package/dist/demo/stills.d.ts +21 -0
- package/dist/demo/stills.js +62 -0
- package/dist/e2e/artifacts.d.ts +27 -0
- package/dist/e2e/artifacts.js +90 -0
- package/dist/e2e/cleanup.d.ts +54 -0
- package/dist/e2e/cleanup.js +109 -0
- package/dist/e2e/config.d.ts +9 -0
- package/dist/e2e/config.js +42 -0
- package/dist/e2e/create-test.d.ts +37 -0
- package/dist/e2e/create-test.js +109 -0
- package/dist/e2e/demo/clip.d.ts +21 -0
- package/dist/e2e/demo/clip.js +44 -0
- package/dist/e2e/demo/create-demo.d.ts +42 -0
- package/dist/e2e/demo/create-demo.js +439 -0
- package/dist/e2e/demo/manifest.d.ts +76 -0
- package/dist/e2e/demo/manifest.js +168 -0
- package/dist/e2e/demo/names.d.ts +18 -0
- package/dist/e2e/demo/names.js +44 -0
- package/dist/e2e/demo/options.d.ts +22 -0
- package/dist/e2e/demo/options.js +59 -0
- package/dist/e2e/demo/ownership.d.ts +27 -0
- package/dist/e2e/demo/ownership.js +65 -0
- package/dist/e2e/demo/page-scripts.d.ts +82 -0
- package/dist/e2e/demo/page-scripts.js +250 -0
- package/dist/e2e/demo/png.d.ts +8 -0
- package/dist/e2e/demo/png.js +23 -0
- package/dist/e2e/demo/presets.d.ts +43 -0
- package/dist/e2e/demo/presets.js +20 -0
- package/dist/e2e/demo/privacy.d.ts +18 -0
- package/dist/e2e/demo/privacy.js +30 -0
- package/dist/e2e/demo/still-options.d.ts +22 -0
- package/dist/e2e/demo/still-options.js +68 -0
- package/dist/e2e/demo/types.d.ts +184 -0
- package/dist/e2e/demo/types.js +1 -0
- package/dist/e2e/electron-binary.d.ts +15 -0
- package/dist/e2e/electron-binary.js +30 -0
- package/dist/e2e/fixtures.d.ts +62 -0
- package/dist/e2e/fixtures.js +68 -0
- package/dist/e2e/gate.d.ts +4 -0
- package/dist/e2e/gate.js +8 -0
- package/dist/e2e/global-setup.d.ts +11 -0
- package/dist/e2e/global-setup.js +17 -0
- package/dist/e2e/helpers/commands.d.ts +14 -0
- package/dist/e2e/helpers/commands.js +56 -0
- package/dist/e2e/helpers/create-helpers.d.ts +24 -0
- package/dist/e2e/helpers/create-helpers.js +582 -0
- package/dist/e2e/helpers/device-metrics.d.ts +21 -0
- package/dist/e2e/helpers/device-metrics.js +25 -0
- package/dist/e2e/helpers/ime.d.ts +13 -0
- package/dist/e2e/helpers/ime.js +19 -0
- package/dist/e2e/helpers/layout-page-scripts.d.ts +103 -0
- package/dist/e2e/helpers/layout-page-scripts.js +224 -0
- package/dist/e2e/helpers/layout.d.ts +83 -0
- package/dist/e2e/helpers/layout.js +148 -0
- package/dist/e2e/helpers/mobile.d.ts +31 -0
- package/dist/e2e/helpers/mobile.js +26 -0
- package/dist/e2e/helpers/page-scripts.d.ts +194 -0
- package/dist/e2e/helpers/page-scripts.js +467 -0
- package/dist/e2e/helpers/settings.d.ts +8 -0
- package/dist/e2e/helpers/settings.js +16 -0
- package/dist/e2e/helpers/settle.d.ts +28 -0
- package/dist/e2e/helpers/settle.js +33 -0
- package/dist/e2e/helpers/types.d.ts +193 -0
- package/dist/e2e/helpers/types.js +1 -0
- package/dist/e2e/helpers/view-mode.d.ts +23 -0
- package/dist/e2e/helpers/view-mode.js +35 -0
- package/dist/e2e/index.d.ts +14 -0
- package/dist/e2e/index.js +4 -0
- package/dist/e2e/internals.d.ts +155 -0
- package/dist/e2e/internals.js +8 -0
- package/dist/e2e/obsidian-path.d.ts +17 -0
- package/dist/e2e/obsidian-path.js +31 -0
- package/dist/e2e/options.d.ts +123 -0
- package/dist/e2e/options.js +244 -0
- package/dist/e2e/page-scripts.d.ts +45 -0
- package/dist/e2e/page-scripts.js +53 -0
- package/dist/e2e/peers.d.ts +9 -0
- package/dist/e2e/peers.js +19 -0
- package/dist/e2e/plugins.d.ts +32 -0
- package/dist/e2e/plugins.js +119 -0
- package/dist/e2e/process-tree.d.ts +33 -0
- package/dist/e2e/process-tree.js +133 -0
- package/dist/e2e/readiness.d.ts +23 -0
- package/dist/e2e/readiness.js +63 -0
- package/dist/e2e/seed.d.ts +34 -0
- package/dist/e2e/seed.js +122 -0
- package/dist/e2e/session.d.ts +71 -0
- package/dist/e2e/session.js +266 -0
- package/dist/e2e/vault.d.ts +52 -0
- package/dist/e2e/vault.js +146 -0
- package/dist/e2e/version.d.ts +25 -0
- package/dist/e2e/version.js +40 -0
- package/dist/eslint/index.d.ts +2 -0
- package/dist/eslint/index.js +1 -0
- package/dist/eslint/obsidian-plugin.d.ts +49 -0
- package/dist/eslint/obsidian-plugin.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/kit/args.d.ts +7 -0
- package/dist/kit/args.js +21 -0
- package/dist/kit/commands.d.ts +3 -0
- package/dist/kit/commands.js +52 -0
- package/dist/kit/files.d.ts +3 -0
- package/dist/kit/files.js +24 -0
- package/dist/kit/pins.d.ts +89 -0
- package/dist/kit/pins.js +178 -0
- package/dist/kit/remote.d.ts +13 -0
- package/dist/kit/remote.js +33 -0
- package/dist/kit/runners.d.ts +11 -0
- package/dist/kit/runners.js +53 -0
- package/dist/kit/terminal-text.d.ts +6 -0
- package/dist/kit/terminal-text.js +20 -0
- package/dist/kit/upgrade.d.ts +26 -0
- package/dist/kit/upgrade.js +162 -0
- package/dist/peers/resolve.d.ts +8 -0
- package/dist/peers/resolve.js +28 -0
- package/dist/peers/versions.d.ts +30 -0
- package/dist/peers/versions.js +32 -0
- package/dist/release/api-check.d.ts +27 -0
- package/dist/release/api-check.js +119 -0
- package/dist/release/args.d.ts +40 -0
- package/dist/release/args.js +120 -0
- package/dist/release/assets.d.ts +21 -0
- package/dist/release/assets.js +35 -0
- package/dist/release/build-check.d.ts +43 -0
- package/dist/release/build-check.js +184 -0
- package/dist/release/build-script.d.ts +12 -0
- package/dist/release/build-script.js +30 -0
- package/dist/release/build-tagged.d.ts +26 -0
- package/dist/release/build-tagged.js +52 -0
- package/dist/release/bump.d.ts +24 -0
- package/dist/release/bump.js +58 -0
- package/dist/release/changelog.d.ts +25 -0
- package/dist/release/changelog.js +148 -0
- package/dist/release/check.d.ts +38 -0
- package/dist/release/check.js +150 -0
- package/dist/release/commands.d.ts +3 -0
- package/dist/release/commands.js +154 -0
- package/dist/release/committed-tree.d.ts +63 -0
- package/dist/release/committed-tree.js +118 -0
- package/dist/release/config.d.ts +3 -0
- package/dist/release/config.js +28 -0
- package/dist/release/gh-access.d.ts +14 -0
- package/dist/release/gh-access.js +45 -0
- package/dist/release/gh.d.ts +10 -0
- package/dist/release/gh.js +33 -0
- package/dist/release/git.d.ts +49 -0
- package/dist/release/git.js +111 -0
- package/dist/release/interrupt.d.ts +30 -0
- package/dist/release/interrupt.js +60 -0
- package/dist/release/json.d.ts +33 -0
- package/dist/release/json.js +81 -0
- package/dist/release/kit-check.d.ts +8 -0
- package/dist/release/kit-check.js +51 -0
- package/dist/release/manifest-rules.d.ts +23 -0
- package/dist/release/manifest-rules.js +255 -0
- package/dist/release/preflight.d.ts +10 -0
- package/dist/release/preflight.js +65 -0
- package/dist/release/problems.d.ts +24 -0
- package/dist/release/problems.js +11 -0
- package/dist/release/project-files.d.ts +14 -0
- package/dist/release/project-files.js +16 -0
- package/dist/release/publish-command.d.ts +21 -0
- package/dist/release/publish-command.js +83 -0
- package/dist/release/publish-git.d.ts +37 -0
- package/dist/release/publish-git.js +108 -0
- package/dist/release/publish-state.d.ts +29 -0
- package/dist/release/publish-state.js +70 -0
- package/dist/release/publish-verify.d.ts +41 -0
- package/dist/release/publish-verify.js +112 -0
- package/dist/release/publish-wait.d.ts +25 -0
- package/dist/release/publish-wait.js +56 -0
- package/dist/release/publish.d.ts +35 -0
- package/dist/release/publish.js +181 -0
- package/dist/release/release-assets.d.ts +39 -0
- package/dist/release/release-assets.js +68 -0
- package/dist/release/release.d.ts +37 -0
- package/dist/release/release.js +179 -0
- package/dist/release/remote.d.ts +12 -0
- package/dist/release/remote.js +15 -0
- package/dist/release/reproducible.d.ts +16 -0
- package/dist/release/reproducible.js +34 -0
- package/dist/release/run-tests.d.ts +5 -0
- package/dist/release/run-tests.js +17 -0
- package/dist/release/semver.d.ts +8 -0
- package/dist/release/semver.js +60 -0
- package/dist/release/version-rules.d.ts +28 -0
- package/dist/release/version-rules.js +63 -0
- package/dist/release/versions-json.d.ts +15 -0
- package/dist/release/versions-json.js +88 -0
- package/dist/release/workflow-run.d.ts +44 -0
- package/dist/release/workflow-run.js +71 -0
- package/dist/scanner/code-checks.d.ts +41 -0
- package/dist/scanner/code-checks.js +82 -0
- package/dist/scanner/commands.d.ts +3 -0
- package/dist/scanner/commands.js +43 -0
- package/dist/scanner/config.d.ts +7 -0
- package/dist/scanner/config.js +25 -0
- package/dist/scanner/css-check.d.ts +26 -0
- package/dist/scanner/css-check.js +63 -0
- package/dist/scanner/eslint-nesting.d.ts +16 -0
- package/dist/scanner/eslint-nesting.js +45 -0
- package/dist/scanner/findings.d.ts +23 -0
- package/dist/scanner/findings.js +21 -0
- package/dist/scanner/git-files.d.ts +16 -0
- package/dist/scanner/git-files.js +73 -0
- package/dist/scanner/lint.d.ts +47 -0
- package/dist/scanner/lint.js +163 -0
- package/dist/scanner/meta-checks.d.ts +8 -0
- package/dist/scanner/meta-checks.js +22 -0
- package/dist/scanner/outside-project.d.ts +19 -0
- package/dist/scanner/outside-project.js +20 -0
- package/dist/scanner/run.d.ts +19 -0
- package/dist/scanner/run.js +78 -0
- package/dist/scanner/scanner-config.d.ts +114 -0
- package/dist/scanner/scanner-config.js +207 -0
- package/dist/scanner/typescript-gate.d.ts +30 -0
- package/dist/scanner/typescript-gate.js +73 -0
- package/dist/vitest/build-config.d.ts +17 -0
- package/dist/vitest/build-config.js +106 -0
- package/dist/vitest/define-unit-config.d.ts +27 -0
- package/dist/vitest/define-unit-config.js +45 -0
- package/dist/vitest/dom/elements.d.ts +87 -0
- package/dist/vitest/dom/elements.js +291 -0
- package/dist/vitest/dom/index.d.ts +1 -0
- package/dist/vitest/dom/index.js +1 -0
- package/dist/vitest/dom/install.d.ts +8 -0
- package/dist/vitest/dom/install.js +261 -0
- package/dist/vitest/dom/setup.d.ts +1 -0
- package/dist/vitest/dom/setup.js +3 -0
- package/dist/vitest/index.d.ts +3 -0
- package/dist/vitest/index.js +2 -0
- package/dist/vitest/options.d.ts +92 -0
- package/dist/vitest/options.js +136 -0
- package/dist/vitest/peers.d.ts +10 -0
- package/dist/vitest/peers.js +51 -0
- package/dist/vitest/workspace-root.d.ts +7 -0
- package/dist/vitest/workspace-root.js +39 -0
- package/docs/build.md +232 -0
- package/docs/ci.md +182 -0
- package/docs/demo.md +364 -0
- package/docs/e2e.md +563 -0
- package/docs/release.md +374 -0
- package/docs/scanner.md +204 -0
- package/docs/unit.md +291 -0
- package/package.json +100 -4
- package/plugins/opdk/skills/audit/SKILL.md +81 -0
- package/plugins/opdk/skills/build/SKILL.md +79 -0
- package/plugins/opdk/skills/demo/SKILL.md +102 -0
- package/plugins/opdk/skills/e2e/SKILL.md +132 -0
- package/plugins/opdk/skills/release/SKILL.md +84 -0
- package/plugins/opdk/skills/scanner/SKILL.md +60 -0
- package/plugins/opdk/skills/unit/SKILL.md +90 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { waitForReady } from "../readiness.js";
|
|
2
|
+
import { commandDeclinedMessage, commandNotFoundMessage, toPlaywrightKeys } from "./commands.js";
|
|
3
|
+
import { planComposition } from "./ime.js";
|
|
4
|
+
import { findOverflow, findSmallTargets, focusWalkStart, MAX_FINDINGS_PER_CHECK, pixelStep, readFocusStop, rootExists } from "./layout-page-scripts.js";
|
|
5
|
+
import { capProblems, focusStartMessage, layoutFailureMessage, noChecksMessage, resolveLayoutOptions, rootMissingMessage } from "./layout.js";
|
|
6
|
+
import { createDeviceMetricsTracker } from "./device-metrics.js";
|
|
7
|
+
import { deviceMetrics, isReloadRejection } from "./mobile.js";
|
|
8
|
+
import { applyTheme, areSidebarsCollapsed, closeSettingsModal, editorTextChanged, enabledPluginIds, hasInnerWidth, hasSettingTab, hideNoteProperties, installFake, isEditorEmpty, isEditorSettled, isFocusInside, isMetadataCacheComplete, isMobileApplied, isReloaded, isPageSettled, isSchemeApplied, listSettingTabIds, markBeforeReload, metadataCacheState, openFileInMode, openSettingsModal, placeEditorCursor, readActiveFilePath, readConfig, readEditorSelection, readEditorText, readFakeCalls, reloadApp, removeFake, removeNotices, runCommandById, runWithApp, saveWorkspaceLayout, scrollThroughElement, setSidebarsCollapsed, stopPageWatch, switchMobileEmulation, unsettledReasons, watchPageChanges, } from "./page-scripts.js";
|
|
9
|
+
import { resolveSettleOptions, settleRootMissingMessage, settleTimeoutMessage } from "./settle.js";
|
|
10
|
+
import { settingsNotOpenedMessage, settingsTabNotFoundMessage } from "./settings.js";
|
|
11
|
+
import { viewModeFailureMessage, viewModeMatches, viewModeSelector, viewModeState } from "./view-mode.js";
|
|
12
|
+
/** How long the window may take to get a width it was told to have, or the `is-mobile` class, after a CDP or Obsidian call. */
|
|
13
|
+
const MOBILE_STATE_TIMEOUT_MS = 5_000;
|
|
14
|
+
const VIEW_MODE_ATTEMPTS = 5;
|
|
15
|
+
const POLL_MS = 50;
|
|
16
|
+
/**
|
|
17
|
+
* The one fixed delay between key presses: the typing speed of `editor().type()`, not a wait for a condition. A
|
|
18
|
+
* listener that reacts to a key can only be tested if keys do not arrive faster than it runs; a plugin's hotstring
|
|
19
|
+
* expander needed this, and 15 ms was enough there. (`scrollThrough` has a 100 ms fallback per step, in the page,
|
|
20
|
+
* for a window that draws no frames.)
|
|
21
|
+
*/
|
|
22
|
+
const KEY_DELAY_MS = 15;
|
|
23
|
+
/** Per key press, on top of the delay: Playwright's own work for one key. The budget of a typing call is `ui` plus this for each. */
|
|
24
|
+
const TYPING_SLACK_MS = 50;
|
|
25
|
+
/**
|
|
26
|
+
* The selectors below, and the ones in the helpers (`.modal.mod-settings`, `.vertical-tab-content`, `.prompt-input`,
|
|
27
|
+
* `.prompt-results`, `.notice`), name Obsidian-internal DOM. They were verified on Obsidian 1.14.5. When a newer
|
|
28
|
+
* Obsidian renames one, the helper that uses it fails with its own message, and the selector is the first suspect.
|
|
29
|
+
*
|
|
30
|
+
* The editor is not scoped to `.mod-active`: Obsidian briefly drops that class from the leaf while a modal is open
|
|
31
|
+
* (found with the command palette), and a selector that needs it matches nothing right after the modal
|
|
32
|
+
* closes. The first markdown editor in the workspace is the active one unless the layout is split.
|
|
33
|
+
*/
|
|
34
|
+
const EDITOR_SELECTOR = '.workspace-leaf-content[data-type="markdown"] .cm-content[contenteditable=true]';
|
|
35
|
+
const READING_VIEW_SELECTOR = ".workspace-leaf.mod-active .markdown-preview-view";
|
|
36
|
+
const NO_EDITOR = "There is no active editor. Open a note first, with openFile(), and make sure it is in source or live mode.";
|
|
37
|
+
/** Runs `action`; a failure is rethrown as `message` (what went wrong and what to do), with the original as `cause`. */
|
|
38
|
+
async function orFail(action, message) {
|
|
39
|
+
try {
|
|
40
|
+
return await action();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new Error(message, { cause: error });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Builds the helpers of one test, bound to its window. Everything that waits polls state; none sleeps. */
|
|
47
|
+
export function createHelpers(win, options) {
|
|
48
|
+
const { timeouts } = options;
|
|
49
|
+
let cdp;
|
|
50
|
+
let fakeCount = 0;
|
|
51
|
+
/** One CDP session per window, shared by the IME and mobile helpers: it works in both launch modes. */
|
|
52
|
+
async function session() {
|
|
53
|
+
cdp ??= await win.context().newCDPSession(win);
|
|
54
|
+
return cdp;
|
|
55
|
+
}
|
|
56
|
+
const metricsTracker = createDeviceMetricsTracker(session);
|
|
57
|
+
const press = async (keys) => {
|
|
58
|
+
await win.keyboard.press(toPlaywrightKeys(keys));
|
|
59
|
+
};
|
|
60
|
+
async function openSettings(tab) {
|
|
61
|
+
if (tab !== undefined) {
|
|
62
|
+
try {
|
|
63
|
+
await win.waitForFunction(hasSettingTab, tab, { polling: 100, timeout: timeouts.settings });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const registered = await win.evaluate(listSettingTabIds);
|
|
67
|
+
throw new Error(settingsTabNotFoundMessage(tab, registered, timeouts.settings), { cause: error });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
await win.evaluate(openSettingsModal, tab ?? null);
|
|
71
|
+
const content = win.locator(".modal.mod-settings .vertical-tab-content");
|
|
72
|
+
try {
|
|
73
|
+
await content.waitFor({ state: "visible", timeout: timeouts.ui });
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const popout = await win.evaluate(readConfig, "settingsPopoutWindow");
|
|
77
|
+
throw new Error(settingsNotOpenedMessage({ popoutConfigured: popout === true, windows: win.context().pages().length, timeoutMs: timeouts.ui }), { cause: error });
|
|
78
|
+
}
|
|
79
|
+
return content;
|
|
80
|
+
}
|
|
81
|
+
async function closeSettings() {
|
|
82
|
+
await win.evaluate(closeSettingsModal);
|
|
83
|
+
await orFail(() => win.locator(".modal.mod-settings").waitFor({ state: "detached", timeout: timeouts.ui }), `The settings modal was still open ${String(timeouts.ui)} ms after closeSettings(). Is a dialog on top of it asking a question?`);
|
|
84
|
+
}
|
|
85
|
+
async function runCommand(id) {
|
|
86
|
+
const result = await win.evaluate(runCommandById, id);
|
|
87
|
+
if (result.state === "missing") {
|
|
88
|
+
throw new Error(commandNotFoundMessage(id, result.ids));
|
|
89
|
+
}
|
|
90
|
+
if (result.state === "declined") {
|
|
91
|
+
throw new Error(commandDeclinedMessage(id));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function openCommandPalette() {
|
|
95
|
+
await press("Mod+P");
|
|
96
|
+
const input = win.locator(".prompt-input");
|
|
97
|
+
try {
|
|
98
|
+
await input.waitFor({ state: "visible", timeout: timeouts.ui });
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw new Error(`The command palette did not open within ${String(timeouts.ui)} ms after Mod+P. Is the command-palette core plugin enabled in the seed vault's .obsidian/core-plugins.json?`, { cause: error });
|
|
102
|
+
}
|
|
103
|
+
return input;
|
|
104
|
+
}
|
|
105
|
+
async function runCommandFromPalette(name) {
|
|
106
|
+
const input = await openCommandPalette();
|
|
107
|
+
await orFail(() => input.fill(name, { timeout: timeouts.ui }), `Could not type "${name}" into the command palette within ${String(timeouts.ui)} ms. Did another dialog take the focus?`);
|
|
108
|
+
// The list updates after the input does; Enter before the entry is selected would run the previous first entry.
|
|
109
|
+
const entry = win.locator(".prompt-results .suggestion-item.is-selected", { hasText: name }).first();
|
|
110
|
+
try {
|
|
111
|
+
await entry.waitFor({ state: "visible", timeout: timeouts.ui });
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw new Error(`The command palette has no selected entry containing "${name}" after ${String(timeouts.ui)} ms. Check the command's name, and that its plugin is enabled.`, { cause: error });
|
|
115
|
+
}
|
|
116
|
+
await press("Enter");
|
|
117
|
+
await orFail(() => input.waitFor({ state: "hidden", timeout: timeouts.ui }), `The command palette was still open ${String(timeouts.ui)} ms after Enter. The command may need an argument or open a dialog of its own.`);
|
|
118
|
+
}
|
|
119
|
+
async function openFile(path, openOptions = {}) {
|
|
120
|
+
const { mode } = openOptions;
|
|
121
|
+
const opened = async (wanted) => {
|
|
122
|
+
const result = await win.evaluate(openFileInMode, { path, wanted });
|
|
123
|
+
if (!result.found) {
|
|
124
|
+
throw new Error(`${path} is not in the vault. Give the path relative to the vault root, for example "Notes/Today.md".`);
|
|
125
|
+
}
|
|
126
|
+
return result.view;
|
|
127
|
+
};
|
|
128
|
+
if (mode === undefined) {
|
|
129
|
+
await opened(null);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let last = null;
|
|
133
|
+
// Setting the state of a note that is already open can be overtaken by the open itself, so ask again.
|
|
134
|
+
for (let attempt = 1; attempt <= VIEW_MODE_ATTEMPTS; attempt++) {
|
|
135
|
+
last = await opened(viewModeState(mode));
|
|
136
|
+
if (viewModeMatches(last, mode)) {
|
|
137
|
+
await orFail(() => win.locator(viewModeSelector(mode)).first().waitFor({ state: "visible", timeout: timeouts.ui }), `${path} reports ${mode} mode, but its view did not appear within ${String(timeouts.ui)} ms. Is a modal covering the workspace?`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
throw new Error(viewModeFailureMessage(path, mode, last, VIEW_MODE_ATTEMPTS));
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Clicks the editor to focus it, but only when focus is not already inside it (see `EditorHelpers.type`). Waits
|
|
145
|
+
* for the editor first: right after a modal closes the editor may not be back in the DOM yet, and a focus check
|
|
146
|
+
* made before that would see "not focused" and click, moving the cursor.
|
|
147
|
+
*/
|
|
148
|
+
async function focusEditor() {
|
|
149
|
+
const editor = win.locator(EDITOR_SELECTOR).first();
|
|
150
|
+
await orFail(() => editor.waitFor({ state: "visible", timeout: timeouts.ui }), `${NO_EDITOR} No editor appeared within ${String(timeouts.ui)} ms.`);
|
|
151
|
+
if (!(await win.evaluate(isFocusInside, EDITOR_SELECTOR))) {
|
|
152
|
+
await orFail(() => editor.click({ timeout: timeouts.ui }), `Could not click the editor within ${String(timeouts.ui)} ms. Is a modal or a popover covering it?`);
|
|
153
|
+
}
|
|
154
|
+
return editor;
|
|
155
|
+
}
|
|
156
|
+
async function editorText() {
|
|
157
|
+
const text = await win.evaluate(readEditorText);
|
|
158
|
+
if (text === null) {
|
|
159
|
+
throw new Error(NO_EDITOR);
|
|
160
|
+
}
|
|
161
|
+
return text;
|
|
162
|
+
}
|
|
163
|
+
async function compose(text, composeOptions = {}) {
|
|
164
|
+
if (text === "") {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const steps = planComposition(text, composeOptions.chunking ?? "word");
|
|
168
|
+
await focusEditor();
|
|
169
|
+
const before = await editorText();
|
|
170
|
+
const cdpSession = await session();
|
|
171
|
+
for (const step of steps) {
|
|
172
|
+
for (const progress of step.progress) {
|
|
173
|
+
await cdpSession.send("Input.imeSetComposition", {
|
|
174
|
+
text: progress,
|
|
175
|
+
selectionStart: progress.length,
|
|
176
|
+
selectionEnd: progress.length,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
await cdpSession.send("Input.insertText", { text: step.commit });
|
|
180
|
+
try {
|
|
181
|
+
await win.waitForFunction(isEditorSettled, undefined, { polling: 20, timeout: timeouts.compose });
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
throw new Error(`CodeMirror was still composing ${String(timeouts.compose)} ms after "${step.commit}" was committed. Raise timeouts.helpers.compose if the editor is slow, or check for a plugin that holds the composition.`, { cause: error });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
await win.waitForFunction(editorTextChanged, before, { polling: 20, timeout: timeouts.compose });
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw new Error(`The document did not change within ${String(timeouts.compose)} ms after the composition. The editor may be read-only, or a plugin undid the text.`, { cause: error });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const editor = () => ({
|
|
195
|
+
type: async (text) => {
|
|
196
|
+
const locator = await focusEditor();
|
|
197
|
+
await orFail(() => locator.pressSequentially(text, { delay: KEY_DELAY_MS, timeout: timeouts.ui + text.length * (KEY_DELAY_MS + TYPING_SLACK_MS) }), "Typing into the editor failed. Is the editor read-only, or did a modal take the focus?");
|
|
198
|
+
},
|
|
199
|
+
text: editorText,
|
|
200
|
+
clear: async () => {
|
|
201
|
+
if ((await win.evaluate(readEditorText)) === null) {
|
|
202
|
+
throw new Error(NO_EDITOR);
|
|
203
|
+
}
|
|
204
|
+
await focusEditor();
|
|
205
|
+
await press("Mod+A");
|
|
206
|
+
await press("Delete");
|
|
207
|
+
await orFail(() => win.waitForFunction(isEditorEmpty, undefined, { polling: POLL_MS, timeout: timeouts.ui }), `The document was not empty ${String(timeouts.ui)} ms after select-all and delete. Is the editor read-only, or does a plugin restore the text?`);
|
|
208
|
+
},
|
|
209
|
+
setCursor: async (line, ch) => {
|
|
210
|
+
if (!Number.isInteger(line) || !Number.isInteger(ch) || line < 0 || ch < 0) {
|
|
211
|
+
throw new RangeError(`setCursor(${String(line)}, ${String(ch)}): line and ch must be integers from 0.`);
|
|
212
|
+
}
|
|
213
|
+
if (!(await win.evaluate(placeEditorCursor, { line, ch }))) {
|
|
214
|
+
throw new Error(NO_EDITOR);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
selection: async () => {
|
|
218
|
+
const selection = await win.evaluate(readEditorSelection);
|
|
219
|
+
if (selection === null) {
|
|
220
|
+
throw new Error(NO_EDITOR);
|
|
221
|
+
}
|
|
222
|
+
return selection;
|
|
223
|
+
},
|
|
224
|
+
compose,
|
|
225
|
+
});
|
|
226
|
+
async function setTheme(themeOptions) {
|
|
227
|
+
// A spec in plain JavaScript, or a cast, can pass anything.
|
|
228
|
+
const given = themeOptions.mode;
|
|
229
|
+
if (given !== "light" && given !== "dark") {
|
|
230
|
+
throw new Error(`setTheme(): mode must be "light" or "dark", got ${JSON.stringify(given)}.`);
|
|
231
|
+
}
|
|
232
|
+
// Obsidian's names for the two colour schemes.
|
|
233
|
+
const scheme = themeOptions.mode === "dark" ? "obsidian" : "moonstone";
|
|
234
|
+
const result = await win.evaluate(applyTheme, { scheme, theme: themeOptions.theme ?? null });
|
|
235
|
+
if (!result.ok) {
|
|
236
|
+
const installed = result.themes.length > 0 ? result.themes.join(", ") : "none";
|
|
237
|
+
throw new Error(`setTheme(): the theme "${String(themeOptions.theme)}" is not installed. Installed community themes: ${installed}. Check the name, or put the theme in the seed vault's .obsidian/themes.`);
|
|
238
|
+
}
|
|
239
|
+
await orFail(() => win.waitForFunction(isSchemeApplied, scheme, { polling: POLL_MS, timeout: timeouts.theme }), `setTheme(): the page did not get the ${themeOptions.mode} theme class within ${String(timeouts.theme)} ms. Raise timeouts.helpers.theme if the theme is slow to load.`);
|
|
240
|
+
}
|
|
241
|
+
async function waitForMetadataCache() {
|
|
242
|
+
try {
|
|
243
|
+
await win.waitForFunction(isMetadataCacheComplete, undefined, { polling: 100, timeout: timeouts.metadataCache });
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
const state = await win.evaluate(metadataCacheState);
|
|
247
|
+
throw new Error(`Obsidian had indexed ${String(state.cached)} of ${String(state.total)} markdown files after ${String(timeouts.metadataCache)} ms. ` +
|
|
248
|
+
"Raise timeouts.helpers.metadataCache (and the test timeout, 60 s by default) for a big vault, or check the vault for a file Obsidian cannot parse.", { cause: error });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async function scrollThrough(selector = READING_VIEW_SELECTOR) {
|
|
252
|
+
if (!(await win.evaluate(scrollThroughElement, selector))) {
|
|
253
|
+
throw new Error(`scrollThrough(): nothing matches "${selector}". Is the note open in reading view?`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async function readingView(path) {
|
|
257
|
+
const target = path ?? (await win.evaluate(readActiveFilePath));
|
|
258
|
+
if (target === null) {
|
|
259
|
+
throw new Error("readingView(): no path given and no note is active. Pass a path, or open a note first with openFile().");
|
|
260
|
+
}
|
|
261
|
+
await openFile(target, { mode: "preview" });
|
|
262
|
+
}
|
|
263
|
+
async function settle(settleOptions = {}) {
|
|
264
|
+
const { quietMs, root } = resolveSettleOptions(settleOptions, timeouts.ui);
|
|
265
|
+
if (!(await win.evaluate(watchPageChanges, root))) {
|
|
266
|
+
throw new Error(root === null ? "settle(): the page has no <body> to watch or cannot observe DOM changes." : settleRootMissingMessage(root));
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
await win.waitForFunction(isPageSettled, quietMs, { polling: POLL_MS, timeout: timeouts.ui });
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
let reasons;
|
|
273
|
+
try {
|
|
274
|
+
reasons = await win.evaluate(unsettledReasons, quietMs);
|
|
275
|
+
}
|
|
276
|
+
catch (readError) {
|
|
277
|
+
// The window can be gone by now (a reload, a crash); the timeout is still what the caller needs to hear about.
|
|
278
|
+
reasons = [`the page could not be read: ${readError instanceof Error ? readError.message : String(readError)}`];
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
try {
|
|
282
|
+
await win.evaluate(stopPageWatch);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// Only the cleanup failed, and a page that cannot be read has no watch left to stop.
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
throw new Error(settleTimeoutMessage({ budgetMs: timeouts.ui, quietMs, root, reasons }), { cause: error });
|
|
289
|
+
}
|
|
290
|
+
await win.evaluate(stopPageWatch);
|
|
291
|
+
}
|
|
292
|
+
/** Collapses or expands both side panels and waits until they are in that state (they animate). */
|
|
293
|
+
async function setSidebars(collapsed) {
|
|
294
|
+
const verb = collapsed ? "collapseSidebars" : "expandSidebars";
|
|
295
|
+
if (!(await win.evaluate(setSidebarsCollapsed, collapsed))) {
|
|
296
|
+
throw new Error(`${verb}(): this Obsidian has no workspace.leftSplit / rightSplit with collapse() and expand(). The helper was verified on Obsidian 1.14.5.`);
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
await win.waitForFunction(areSidebarsCollapsed, collapsed, { polling: 50, timeout: timeouts.ui });
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
throw new Error(`The side panels were not ${collapsed ? "collapsed" : "expanded"} ${String(timeouts.ui)} ms after ${verb}(). Raise timeouts.helpers.ui if the window is slow.`, { cause: error });
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
await win.evaluate(saveWorkspaceLayout);
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
throw new Error(`${verb}(): saving the workspace layout failed, so a reload() would bring the side panels back.`, { cause: error });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Runs `start`, which reloads the window, and waits until the new page is up. The call that starts a reload
|
|
313
|
+
* never returns; that rejection is the only one accepted. The flag set before the call tells the old page from
|
|
314
|
+
* the new one, and then the phase 1 readiness wait makes sure every plugin has loaded again.
|
|
315
|
+
*/
|
|
316
|
+
async function reloadWindow(start, timeoutMessage) {
|
|
317
|
+
const ids = await win.evaluate(enabledPluginIds);
|
|
318
|
+
await win.evaluate(markBeforeReload);
|
|
319
|
+
try {
|
|
320
|
+
await start();
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
if (!isReloadRejection(error)) {
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
await orFail(() => win.waitForFunction(isReloaded, undefined, { polling: POLL_MS, timeout: options.readyTimeoutMs }), timeoutMessage);
|
|
328
|
+
await waitForReady(win, ids, options.readyTimeoutMs);
|
|
329
|
+
}
|
|
330
|
+
/** Switches the emulation (`emulateMobile()` reloads the window) and waits for the reload and the body class. */
|
|
331
|
+
async function switchEmulation(on) {
|
|
332
|
+
await reloadWindow(() => win.evaluate(switchMobileEmulation, on), `The window did not reload within ${String(options.readyTimeoutMs)} ms after the mobile emulation was switched ${on ? "on" : "off"}. Raise timeouts.ready, or check that app.emulateMobile exists in this Obsidian.`);
|
|
333
|
+
await orFail(() => win.waitForFunction(isMobileApplied, on, { polling: POLL_MS, timeout: MOBILE_STATE_TIMEOUT_MS }), `The window reloaded, but its body ${on ? "lacks" : "still has"} the is-mobile class after ${String(MOBILE_STATE_TIMEOUT_MS)} ms.`);
|
|
334
|
+
}
|
|
335
|
+
async function reload() {
|
|
336
|
+
await reloadWindow(async () => {
|
|
337
|
+
const outcome = await win.evaluate(reloadApp);
|
|
338
|
+
if (outcome === "missing") {
|
|
339
|
+
throw new Error("reload(): this Obsidian has no app:reload command. The helper was verified on Obsidian 1.14.5.");
|
|
340
|
+
}
|
|
341
|
+
if (outcome === "refused") {
|
|
342
|
+
throw new Error("reload(): Obsidian refused to run the app:reload command (executeCommandById returned false). Check that the command is available in this window.");
|
|
343
|
+
}
|
|
344
|
+
}, `The window did not reload within ${String(options.readyTimeoutMs)} ms after reload(). Raise timeouts.ready, or check that the app:reload command works in this Obsidian.`);
|
|
345
|
+
}
|
|
346
|
+
async function runLayoutChecks(layoutOptions) {
|
|
347
|
+
const resolved = resolveLayoutOptions(layoutOptions);
|
|
348
|
+
// The root is looked up once, before any check: a missing root fails even when every check is off.
|
|
349
|
+
if (!(await win.evaluate(rootExists, resolved.root))) {
|
|
350
|
+
throw new Error(rootMissingMessage(resolved.root));
|
|
351
|
+
}
|
|
352
|
+
const touch = resolved.touch.enabled ?? (await win.evaluate(isMobileApplied, true));
|
|
353
|
+
if (!resolved.overflow.enabled && !touch && !resolved.focus.enabled) {
|
|
354
|
+
throw new Error(noChecksMessage());
|
|
355
|
+
}
|
|
356
|
+
const found = [];
|
|
357
|
+
const totals = [];
|
|
358
|
+
const collect = (check, result) => {
|
|
359
|
+
if (!result.rootFound) {
|
|
360
|
+
throw new Error(rootMissingMessage(resolved.root));
|
|
361
|
+
}
|
|
362
|
+
found.push(...result.findings.map((finding) => ({ check, ...finding })));
|
|
363
|
+
if (result.total > result.findings.length) {
|
|
364
|
+
totals.push({ check, total: result.total });
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
if (resolved.overflow.enabled) {
|
|
368
|
+
collect("overflow", await win.evaluate(findOverflow, { root: resolved.root, ignore: resolved.overflow.ignore, limit: MAX_FINDINGS_PER_CHECK }));
|
|
369
|
+
}
|
|
370
|
+
if (touch) {
|
|
371
|
+
collect("touch-target", await win.evaluate(findSmallTargets, {
|
|
372
|
+
root: resolved.root,
|
|
373
|
+
targets: resolved.touch.selector,
|
|
374
|
+
ignore: resolved.touch.ignore,
|
|
375
|
+
minSize: resolved.touch.minSize,
|
|
376
|
+
limit: MAX_FINDINGS_PER_CHECK,
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
if (resolved.focus.enabled) {
|
|
380
|
+
const capped = capProblems(await walkFocus(resolved.root, resolved.focus), MAX_FINDINGS_PER_CHECK);
|
|
381
|
+
found.push(...capped.problems);
|
|
382
|
+
totals.push(...capped.cuts);
|
|
383
|
+
}
|
|
384
|
+
return { problems: found, cuts: totals, minSize: resolved.touch.minSize };
|
|
385
|
+
}
|
|
386
|
+
async function layoutProblems(layoutOptions) {
|
|
387
|
+
return (await runLayoutChecks(layoutOptions)).problems;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* For a control whose ring is drawn on a vendor pseudo-element that cannot be read as a style (the thumb of a
|
|
391
|
+
* range input): whether the pixels around it change when it loses focus. The element ends up focused again.
|
|
392
|
+
*/
|
|
393
|
+
async function ringShowsInPixels(box) {
|
|
394
|
+
const pad = 6;
|
|
395
|
+
const x = Math.max(0, Math.floor(box.x) - pad);
|
|
396
|
+
const y = Math.max(0, Math.floor(box.y) - pad);
|
|
397
|
+
const clip = { x, y, width: Math.ceil(box.width) + 2 * pad, height: Math.ceil(box.height) + 2 * pad };
|
|
398
|
+
if (!(await win.evaluate(pixelStep, "begin"))) {
|
|
399
|
+
throw new Error("checkLayout(): the pixel comparison of a focus ring could not start: nothing has focus.");
|
|
400
|
+
}
|
|
401
|
+
let differs = false;
|
|
402
|
+
let failure;
|
|
403
|
+
try {
|
|
404
|
+
const focused = await win.screenshot({ clip, animations: "disabled" });
|
|
405
|
+
await win.evaluate(pixelStep, "blur");
|
|
406
|
+
const plain = await win.screenshot({ clip, animations: "disabled" });
|
|
407
|
+
differs = !focused.equals(plain);
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
failure = error instanceof Error ? error : new Error(String(error));
|
|
411
|
+
}
|
|
412
|
+
// Always give focus back and remove the page's style, also after a failed screenshot.
|
|
413
|
+
const back = await win.evaluate(pixelStep, "end");
|
|
414
|
+
if (failure !== undefined) {
|
|
415
|
+
throw failure;
|
|
416
|
+
}
|
|
417
|
+
if (!back) {
|
|
418
|
+
throw new Error("checkLayout(): the element did not take focus back after the pixel comparison of its focus ring, so the Tab walk cannot go on. Add it to focusRing.ignore.");
|
|
419
|
+
}
|
|
420
|
+
return differs;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Tabs through `root` and reports every stop that shows no focus ring (and, with `stayInside`, the Tab that leaves
|
|
424
|
+
* it). The walk ends when focus leaves `root`, comes back to a stop it already visited (a trap) or after `maxStops`
|
|
425
|
+
* presses. It is an error, never a pass, when it cannot start inside `root` or sees no stop at all.
|
|
426
|
+
*/
|
|
427
|
+
async function walkFocus(root, focus) {
|
|
428
|
+
// Chromium matches :focus-visible on a script focus only when the last input was the keyboard. After a mouse
|
|
429
|
+
// click it does not, and the first stop would read as a missing ring. A modifier key switches the heuristic
|
|
430
|
+
// and does nothing else (Escape or Tab would close a dialog or move focus).
|
|
431
|
+
await win.keyboard.press("Shift");
|
|
432
|
+
const start = await win.evaluate(focusWalkStart, { root, from: focus.from });
|
|
433
|
+
if (start === "no-root") {
|
|
434
|
+
throw new Error(rootMissingMessage(root));
|
|
435
|
+
}
|
|
436
|
+
if (start !== "ok") {
|
|
437
|
+
throw new Error(focusStartMessage(start, root, focus.from));
|
|
438
|
+
}
|
|
439
|
+
const problems = [];
|
|
440
|
+
const reported = new Set();
|
|
441
|
+
for (let stop = 0; stop <= focus.maxStops; stop++) {
|
|
442
|
+
if (stop > 0) {
|
|
443
|
+
await win.keyboard.press("Tab");
|
|
444
|
+
}
|
|
445
|
+
let current = await win.evaluate(readFocusStop, { root, ignore: focus.ignore });
|
|
446
|
+
if (current !== null && current.pixelBox !== null) {
|
|
447
|
+
current = { ...current, hasRing: await ringShowsInPixels(current.pixelBox), pixelBox: null };
|
|
448
|
+
}
|
|
449
|
+
if (current === null || (stop === 0 && !current.inRoot)) {
|
|
450
|
+
throw new Error(`checkLayout(): the Tab walk found no stop inside ${JSON.stringify(root)}: focus is not on an element of the root after it was set. Check that the root stays on the page.`);
|
|
451
|
+
}
|
|
452
|
+
if (!current.inRoot) {
|
|
453
|
+
if (focus.stayInside) {
|
|
454
|
+
problems.push({ check: "focus-escape", where: current.where, detail: `Tab ${String(stop)} moved focus out of ${JSON.stringify(root)}` });
|
|
455
|
+
}
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
if (current.repeat) {
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
const key = `${current.where}|${current.detail}`;
|
|
462
|
+
if (!current.hasRing && !reported.has(key)) {
|
|
463
|
+
reported.add(key);
|
|
464
|
+
problems.push({ check: "focus-ring", where: current.where, detail: current.detail });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return problems;
|
|
468
|
+
}
|
|
469
|
+
async function checkLayout(layoutOptions) {
|
|
470
|
+
const run = await runLayoutChecks(layoutOptions);
|
|
471
|
+
if (run.problems.length > 0) {
|
|
472
|
+
throw new Error(layoutFailureMessage(layoutOptions.root, run.problems, run.minSize, run.cuts));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/** The window width the last `mobile()` call applied; the layout (phone or tablet) was decided from it. */
|
|
476
|
+
let mobileWidth;
|
|
477
|
+
async function waitForWidth(width) {
|
|
478
|
+
await orFail(() => win.waitForFunction(hasInnerWidth, width, { polling: POLL_MS, timeout: MOBILE_STATE_TIMEOUT_MS }), `The window width did not become ${String(width)} within ${String(MOBILE_STATE_TIMEOUT_MS)} ms after the device metrics override.`);
|
|
479
|
+
}
|
|
480
|
+
async function mobile(mobileOptions = {}) {
|
|
481
|
+
const metrics = deviceMetrics(mobileOptions);
|
|
482
|
+
// The size first: whether Obsidian shows the phone or the tablet layout is decided when it loads, from the
|
|
483
|
+
// viewport at that moment. The window may be larger than the screen allows, the override is not.
|
|
484
|
+
await metricsTracker.set(metrics);
|
|
485
|
+
await waitForWidth(metrics.width);
|
|
486
|
+
// Also when the window is mobile already but with another size (or one this helper did not set): the layout
|
|
487
|
+
// class follows the size only at load, so it has to load again.
|
|
488
|
+
if (!(await win.evaluate(isMobileApplied, true)) || mobileWidth !== metrics.width) {
|
|
489
|
+
await switchEmulation(true);
|
|
490
|
+
}
|
|
491
|
+
// The override survives the reload; sending it again costs nothing and does not rely on that. Sent plainly:
|
|
492
|
+
// the tracker already holds these metrics, and a clear before a set of the same ones would be noise here.
|
|
493
|
+
await (await session()).send("Emulation.setDeviceMetricsOverride", metrics);
|
|
494
|
+
await waitForWidth(metrics.width);
|
|
495
|
+
mobileWidth = metrics.width;
|
|
496
|
+
}
|
|
497
|
+
async function desktop() {
|
|
498
|
+
if (await win.evaluate(isMobileApplied, true)) {
|
|
499
|
+
await switchEmulation(false);
|
|
500
|
+
}
|
|
501
|
+
await metricsTracker.clear();
|
|
502
|
+
}
|
|
503
|
+
async function evaluate(fn, arg) {
|
|
504
|
+
const result = await win.evaluate(runWithApp, { source: fn.toString(), arg });
|
|
505
|
+
if (!result.ok) {
|
|
506
|
+
throw new Error(`evaluate(): ${result.reason}. The function runs in the page, so it cannot use variables of the test; pass them as the second argument.`);
|
|
507
|
+
}
|
|
508
|
+
// The page returned whatever `fn` returned; the type parameter is the caller's statement about it.
|
|
509
|
+
return result.value;
|
|
510
|
+
}
|
|
511
|
+
async function replace(pluginId, propertyPath, impl, arg) {
|
|
512
|
+
fakeCount += 1;
|
|
513
|
+
const id = `opdk-fake-${String(fakeCount)}`;
|
|
514
|
+
const result = await win.evaluate(installFake, { id, pluginId, path: propertyPath, source: impl.toString(), arg });
|
|
515
|
+
if (!result.ok) {
|
|
516
|
+
throw new Error(`replace(${pluginId}, ${propertyPath}): ${result.reason}. Use the plugin id from manifest.json and a property that exists on the loaded plugin; ` +
|
|
517
|
+
"the factory runs in the page, so it cannot use variables of the test.");
|
|
518
|
+
}
|
|
519
|
+
let finalCalls;
|
|
520
|
+
const calls = async () => {
|
|
521
|
+
if (finalCalls !== undefined) {
|
|
522
|
+
return finalCalls;
|
|
523
|
+
}
|
|
524
|
+
const recorded = await win.evaluate(readFakeCalls, id);
|
|
525
|
+
if (recorded === null) {
|
|
526
|
+
throw new Error(`The replacement of ${pluginId}.${propertyPath} is gone: the window was reloaded since replace().`);
|
|
527
|
+
}
|
|
528
|
+
return recorded;
|
|
529
|
+
};
|
|
530
|
+
return {
|
|
531
|
+
calls,
|
|
532
|
+
restore: async () => {
|
|
533
|
+
if (finalCalls !== undefined) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const recorded = await calls();
|
|
537
|
+
await win.evaluate(removeFake, id);
|
|
538
|
+
finalCalls = recorded;
|
|
539
|
+
},
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
cdpSession: session,
|
|
544
|
+
deviceMetrics: metricsTracker,
|
|
545
|
+
helpers: {
|
|
546
|
+
openSettings,
|
|
547
|
+
closeSettings,
|
|
548
|
+
runCommand,
|
|
549
|
+
openCommandPalette,
|
|
550
|
+
runCommandFromPalette,
|
|
551
|
+
openFile,
|
|
552
|
+
editor,
|
|
553
|
+
press,
|
|
554
|
+
setTheme,
|
|
555
|
+
waitForMetadataCache,
|
|
556
|
+
clearNotices: () => win.evaluate(removeNotices),
|
|
557
|
+
checkLayout,
|
|
558
|
+
layoutProblems,
|
|
559
|
+
hideProperties: async () => {
|
|
560
|
+
if (!(await win.evaluate(hideNoteProperties))) {
|
|
561
|
+
throw new Error("hideProperties(): this Obsidian has no app.vault.setConfig / saveConfig. The helper was verified on Obsidian 1.14.5.");
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
scrollThrough,
|
|
565
|
+
readingView,
|
|
566
|
+
settle,
|
|
567
|
+
collapseSidebars: () => setSidebars(true),
|
|
568
|
+
expandSidebars: () => setSidebars(false),
|
|
569
|
+
mobile,
|
|
570
|
+
reload,
|
|
571
|
+
desktop,
|
|
572
|
+
evaluate,
|
|
573
|
+
replace,
|
|
574
|
+
},
|
|
575
|
+
dispose: async () => {
|
|
576
|
+
// A window that has closed took its session with it; there is nothing left to detach.
|
|
577
|
+
if (cdp !== undefined && !win.isClosed()) {
|
|
578
|
+
await cdp.detach();
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
};
|
|
582
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CDPSession } from "@playwright/test";
|
|
2
|
+
import type { DeviceMetrics } from "./mobile.js";
|
|
3
|
+
/**
|
|
4
|
+
* The device metrics override of the window's one CDP session, and what that session last sent. `mobile()`, `desktop()`
|
|
5
|
+
* and the demo's shots all go through it, so they agree on what the session counts as active.
|
|
6
|
+
*/
|
|
7
|
+
export interface DeviceMetricsTracker {
|
|
8
|
+
/**
|
|
9
|
+
* Sets the override. Sends `Emulation.clearDeviceMetricsOverride` first when `metrics` equal the last override this
|
|
10
|
+
* session sent: Playwright's own `page.screenshot()` drops the override from the page (Chromium captures beyond the
|
|
11
|
+
* viewport), but the session still counts it as active, and Chromium ignores a set that repeats it.
|
|
12
|
+
*/
|
|
13
|
+
set(metrics: DeviceMetrics): Promise<void>;
|
|
14
|
+
/** Clears the override and forgets it. */
|
|
15
|
+
clear(): Promise<void>;
|
|
16
|
+
/** The last override this session sent and did not clear, or undefined when there is none. */
|
|
17
|
+
last(): DeviceMetrics | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** `mobile` is always false in `DeviceMetrics`, so it is not compared. */
|
|
20
|
+
export declare function isSameMetrics(a: DeviceMetrics, b: DeviceMetrics): boolean;
|
|
21
|
+
export declare function createDeviceMetricsTracker(getSession: () => Promise<CDPSession>): DeviceMetricsTracker;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** `mobile` is always false in `DeviceMetrics`, so it is not compared. */
|
|
2
|
+
export function isSameMetrics(a, b) {
|
|
3
|
+
return a.width === b.width && a.height === b.height && a.deviceScaleFactor === b.deviceScaleFactor;
|
|
4
|
+
}
|
|
5
|
+
export function createDeviceMetricsTracker(getSession) {
|
|
6
|
+
let last;
|
|
7
|
+
return {
|
|
8
|
+
set: async (metrics) => {
|
|
9
|
+
const session = await getSession();
|
|
10
|
+
if (last !== undefined && isSameMetrics(last, metrics)) {
|
|
11
|
+
await session.send("Emulation.clearDeviceMetricsOverride");
|
|
12
|
+
// Cleared, so a failing set below leaves nothing remembered.
|
|
13
|
+
last = undefined;
|
|
14
|
+
}
|
|
15
|
+
await session.send("Emulation.setDeviceMetricsOverride", { ...metrics });
|
|
16
|
+
last = metrics;
|
|
17
|
+
},
|
|
18
|
+
clear: async () => {
|
|
19
|
+
const session = await getSession();
|
|
20
|
+
await session.send("Emulation.clearDeviceMetricsOverride");
|
|
21
|
+
last = undefined;
|
|
22
|
+
},
|
|
23
|
+
last: () => last,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** How the text is split into compositions: one per word (with its trailing space), or one per character. */
|
|
2
|
+
export type CompositionChunking = "word" | "character";
|
|
3
|
+
/** One composition: the strings shown while it is in progress, then the text that commits it. */
|
|
4
|
+
export interface CompositionStep {
|
|
5
|
+
readonly progress: readonly string[];
|
|
6
|
+
readonly commit: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Splits `text` into the compositions an input method would produce. Each composition grows one character at a
|
|
10
|
+
* time (`h`, `he`, `hel`...) and is committed with the whole chunk. A word's trailing whitespace belongs to its
|
|
11
|
+
* commit, the way a keyboard commits a word together with its space; whitespace on its own is a chunk too.
|
|
12
|
+
*/
|
|
13
|
+
export declare function planComposition(text: string, chunking: CompositionChunking): CompositionStep[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits `text` into the compositions an input method would produce. Each composition grows one character at a
|
|
3
|
+
* time (`h`, `he`, `hel`...) and is committed with the whole chunk. A word's trailing whitespace belongs to its
|
|
4
|
+
* commit, the way a keyboard commits a word together with its space; whitespace on its own is a chunk too.
|
|
5
|
+
*/
|
|
6
|
+
export function planComposition(text, chunking) {
|
|
7
|
+
const chunks = text.match(chunking === "character" ? /./gsu : /\S+\s*|\s+/gu) ?? [];
|
|
8
|
+
return chunks.map((chunk) => {
|
|
9
|
+
// The trailing space is committed, not composed; a chunk that is only whitespace is composed as it is.
|
|
10
|
+
const composed = chunk.trimEnd() || chunk;
|
|
11
|
+
const progress = [];
|
|
12
|
+
let prefix = "";
|
|
13
|
+
for (const character of composed) {
|
|
14
|
+
prefix += character;
|
|
15
|
+
progress.push(prefix);
|
|
16
|
+
}
|
|
17
|
+
return { progress, commit: chunk };
|
|
18
|
+
});
|
|
19
|
+
}
|