obsidian-dev-utils 91.0.1 → 92.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 92.0.0
4
+
5
+ - test(modals): click the mock modal backdrop instead of a hand-built one
6
+ - feat(demo-vault): warn that the demo vault is a sandbox and enforce the authoring convention
7
+ - feat(modals): minimize a minimizable modal on a background click
8
+ - chore: update libs
9
+ - docs: describe the three test layers instead of claiming unit tests only
10
+
3
11
  ## 91.0.1
4
12
 
5
13
  - fix(modals): report prompt validity only once touched
@@ -447,6 +447,9 @@ __export(main_exports, {
447
447
  default: () => DemoVaultHelperPlugin
448
448
  });
449
449
  module.exports = __toCommonJS(main_exports);
450
+ var import_obsidian3 = require("obsidian");
451
+
452
+ // src/obsidian/demo-vault-helper.ts
450
453
  var import_obsidian2 = require("obsidian");
451
454
 
452
455
  // src/path.ts
@@ -457,6 +460,20 @@ function noop() {
457
460
  }
458
461
  var noopAsyncSingletonPromise = Promise.resolve();
459
462
 
463
+ // src/type-guards.ts
464
+ function assertNonNullable(value, errorOrMessage) {
465
+ if (value !== null && value !== void 0) {
466
+ return;
467
+ }
468
+ errorOrMessage ??= value === null ? "Value is null" : "Value is undefined";
469
+ const error = typeof errorOrMessage === "string" ? new Error(errorOrMessage) : errorOrMessage;
470
+ throw error;
471
+ }
472
+ function ensureNonNullable(value, errorOrMessage) {
473
+ assertNonNullable(value, errorOrMessage);
474
+ return value;
475
+ }
476
+
460
477
  // src/string.ts
461
478
  var ESCAPE_MAP = {
462
479
  "\n": String.raw`\n`,
@@ -649,13 +666,19 @@ async function resolveCommunityPluginId(reference) {
649
666
  var CODE_SCRIPT_TOOLKIT_PLUGIN_ID = "fix-require-modules";
650
667
  var CODE_SCRIPT_TOOLKIT_MODULES_ROOT = "_assets/CodeScriptToolkit";
651
668
  var CODE_SCRIPT_TOOLKIT_SETTINGS = {
669
+ defaultCodeButtonConfig: "---\nsourceVisibility: collapsed\n---",
652
670
  invocableScriptsFolder: "Invocables",
653
671
  modulesRoot: CODE_SCRIPT_TOOLKIT_MODULES_ROOT,
654
672
  shouldHandleProtocolUrls: true,
655
673
  startupScriptPath: "startup.ts"
656
674
  };
675
+ var DEMO_VAULT_HELPER_PLUGIN_ID = "demo-vault-helper";
676
+ var PLUGINS_FOLDER_NAME = "plugins";
677
+ var OPEN_DEMO_VAULT_COMMAND_NAME = "Open demo vault";
678
+ var SANDBOX_NOTICE_DURATION_IN_MILLISECONDS = 0;
657
679
  async function bootstrapDemoVault(params) {
658
680
  const { app } = params;
681
+ const demoedPluginId = await getDemoedPluginId(app);
659
682
  await installCommunityPlugin({ app, pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID });
660
683
  const result = await configureCommunityPlugin({
661
684
  app,
@@ -669,6 +692,26 @@ async function bootstrapDemoVault(params) {
669
692
  await disableCommunityPlugin({ app, pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID });
670
693
  await enableCommunityPlugin({ app, pluginId: CODE_SCRIPT_TOOLKIT_PLUGIN_ID });
671
694
  }
695
+ showSandboxNotice(app, demoedPluginId);
696
+ }
697
+ function buildSandboxNoticeFragment(pluginName, basePath) {
698
+ return createFragment((fragment) => {
699
+ if (pluginName === null) {
700
+ fragment.appendText("This is a demo vault.");
701
+ } else {
702
+ fragment.appendText("This is a demo vault for ");
703
+ fragment.createEl("b", { text: pluginName });
704
+ fragment.appendText(".");
705
+ }
706
+ fragment.appendText(" It is a temporary sandbox");
707
+ if (basePath !== null) {
708
+ fragment.appendText(" at ");
709
+ fragment.createEl("code", { text: basePath });
710
+ }
711
+ fragment.appendText(", cleaned up automatically about a day after you last use it \u2014 copy anything you want to keep into your own vault. Running ");
712
+ fragment.createEl("b", { text: pluginName === null ? OPEN_DEMO_VAULT_COMMAND_NAME : `${pluginName}: ${OPEN_DEMO_VAULT_COMMAND_NAME}` });
713
+ fragment.appendText(" again creates a new copy with the latest plugin version, so your notes will not appear in it.");
714
+ });
672
715
  }
673
716
  async function ensureInvocableScriptsFolder(app) {
674
717
  const invocableScriptsFolderPath = join(CODE_SCRIPT_TOOLKIT_MODULES_ROOT, CODE_SCRIPT_TOOLKIT_SETTINGS.invocableScriptsFolder);
@@ -676,9 +719,29 @@ async function ensureInvocableScriptsFolder(app) {
676
719
  await app.vault.adapter.mkdir(invocableScriptsFolderPath);
677
720
  }
678
721
  }
722
+ async function getDemoedPluginId(app) {
723
+ const pluginsFolderPath = join(app.vault.configDir, PLUGINS_FOLDER_NAME);
724
+ if (!await app.vault.adapter.exists(pluginsFolderPath)) {
725
+ return null;
726
+ }
727
+ const listedFiles = await app.vault.adapter.list(pluginsFolderPath);
728
+ const demoedPluginIds = listedFiles.folders.map((folderPath) => basename(folderPath)).filter((pluginId) => pluginId !== DEMO_VAULT_HELPER_PLUGIN_ID);
729
+ return demoedPluginIds.length === 1 ? ensureNonNullable(demoedPluginIds[0]) : null;
730
+ }
731
+ function getVaultBasePath(app) {
732
+ return isBasePathAdapter(app.vault.adapter) ? app.vault.adapter.getBasePath() : null;
733
+ }
734
+ function isBasePathAdapter(adapter) {
735
+ return typeof Reflect.get(adapter, "getBasePath") === "function";
736
+ }
737
+ function showSandboxNotice(app, demoedPluginId) {
738
+ const pluginName = demoedPluginId === null ? null : app.plugins.manifests[demoedPluginId]?.name ?? demoedPluginId;
739
+ const fragment = buildSandboxNoticeFragment(pluginName, getVaultBasePath(app));
740
+ new import_obsidian2.Notice(fragment, SANDBOX_NOTICE_DURATION_IN_MILLISECONDS);
741
+ }
679
742
 
680
743
  // demo-vault-helper/main.ts
681
- var DemoVaultHelperPlugin = class extends import_obsidian2.Plugin {
744
+ var DemoVaultHelperPlugin = class extends import_obsidian3.Plugin {
682
745
  onload() {
683
746
  this.app.workspace.onLayoutReady(() => {
684
747
  void this.bootstrap();
@@ -688,7 +751,7 @@ var DemoVaultHelperPlugin = class extends import_obsidian2.Plugin {
688
751
  try {
689
752
  await bootstrapDemoVault({ app: this.app });
690
753
  } catch (error) {
691
- new import_obsidian2.Notice(`Demo Vault Helper failed to bootstrap: ${String(error)}`);
754
+ new import_obsidian3.Notice(`Demo Vault Helper failed to bootstrap: ${String(error)}`);
692
755
  console.error(error);
693
756
  }
694
757
  }