obsidian-dev-utils 92.1.0 → 93.1.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/demo-vault-helper/main.js +46 -44
  3. package/dist/integration-test-plugin/main.js +10042 -9739
  4. package/dist/lib/cjs/__merged.cjs +9 -1
  5. package/dist/lib/cjs/__merged.d.cts +2 -2
  6. package/dist/lib/cjs/generated-during-build.cjs +1 -1
  7. package/dist/lib/cjs/obsidian/community-plugins.cjs +18 -1
  8. package/dist/lib/cjs/obsidian/community-plugins.d.cts +23 -7
  9. package/dist/lib/cjs/obsidian/components/plugin-notice-component.cjs +118 -36
  10. package/dist/lib/cjs/obsidian/components/plugin-notice-component.d.cts +88 -19
  11. package/dist/lib/cjs/obsidian/demo-vault-helper-settings.cjs +120 -0
  12. package/dist/lib/cjs/obsidian/demo-vault-helper-settings.d.cts +29 -0
  13. package/dist/lib/cjs/obsidian/demo-vault-helper.cjs +31 -32
  14. package/dist/lib/cjs/obsidian/demo-vault-helper.d.cts +7 -3
  15. package/dist/lib/cjs/obsidian/desktop-demo-vault-opener.cjs +4 -2
  16. package/dist/lib/cjs/obsidian/index.cjs +4 -1
  17. package/dist/lib/cjs/obsidian/index.d.cts +1 -0
  18. package/dist/lib/cjs/obsidian/workspace.cjs +28 -3
  19. package/dist/lib/cjs/obsidian/workspace.d.cts +50 -0
  20. package/dist/lib/cjs/script-utils/demo-vault.cjs +8 -3
  21. package/dist/lib/esm/__merged.d.mts +2 -2
  22. package/dist/lib/esm/__merged.mjs +13 -3
  23. package/dist/lib/esm/generated-during-build.mjs +1 -1
  24. package/dist/lib/esm/obsidian/community-plugins.d.mts +23 -7
  25. package/dist/lib/esm/obsidian/community-plugins.mjs +18 -1
  26. package/dist/lib/esm/obsidian/components/plugin-notice-component.d.mts +88 -19
  27. package/dist/lib/esm/obsidian/components/plugin-notice-component.mjs +116 -35
  28. package/dist/lib/esm/obsidian/demo-vault-helper-settings.d.mts +29 -0
  29. package/dist/lib/esm/obsidian/demo-vault-helper-settings.mjs +24 -0
  30. package/dist/lib/esm/obsidian/demo-vault-helper.d.mts +7 -3
  31. package/dist/lib/esm/obsidian/demo-vault-helper.mjs +32 -36
  32. package/dist/lib/esm/obsidian/desktop-demo-vault-opener.mjs +4 -2
  33. package/dist/lib/esm/obsidian/index.d.mts +1 -0
  34. package/dist/lib/esm/obsidian/index.mjs +3 -1
  35. package/dist/lib/esm/obsidian/workspace.d.mts +50 -0
  36. package/dist/lib/esm/obsidian/workspace.mjs +24 -2
  37. package/dist/lib/esm/script-utils/demo-vault.mjs +10 -4
  38. package/obsidian/demo-vault-helper-settings/package.json +6 -0
  39. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 93.1.0
4
+
5
+ - feat(community-plugins)!: apply settings through a running plugin instead of data.json
6
+
7
+ ## 93.0.0
8
+
9
+ - feat(demo-vault)!: name the demonstrated plugin in the helper settings
10
+ - fix(demo-vault): keep the opener progress notice out of the shared slot
11
+ - feat(notices)!: replace isReusable with a notice mode, adding append
12
+ - feat(workspace): add main-window helpers and scoped window switching
13
+
3
14
  ## 92.1.0
4
15
 
5
16
  - docs: missing descriptions
@@ -460,21 +460,8 @@ function noop() {
460
460
  }
461
461
  var noopAsyncSingletonPromise = Promise.resolve();
462
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
-
477
463
  // src/string.ts
464
+ var EMPTY = "";
478
465
  var ESCAPE_MAP = {
479
466
  "\n": String.raw`\n`,
480
467
  "\r": String.raw`\r`,
@@ -574,6 +561,13 @@ var DATA_JSON_INDENT = 2;
574
561
  async function configureCommunityPlugin(params) {
575
562
  const { app, settings } = params;
576
563
  const pluginId = await resolveCommunityPluginId(params);
564
+ const settingsComponent = getSettingsComponent(app.plugins.plugins[pluginId]);
565
+ if (checkHasEditAndSave(settingsComponent)) {
566
+ await settingsComponent.editAndSave((pluginSettings) => {
567
+ Object.assign(pluginSettings, settings);
568
+ });
569
+ return "appliedLive" /* AppliedLive */;
570
+ }
577
571
  const dataPath = `${app.vault.configDir}/plugins/${pluginId}/data.json`;
578
572
  let data = {};
579
573
  if (await app.vault.adapter.exists(dataPath)) {
@@ -632,6 +626,9 @@ async function installCommunityPlugin(params) {
632
626
  const manifest = await getPluginManifest(repo, version);
633
627
  await app.plugins.installPlugin(repo, version, manifest);
634
628
  }
629
+ function checkHasEditAndSave(settingsComponent) {
630
+ return typeof settingsComponent === "object" && settingsComponent !== null && "editAndSave" in settingsComponent && typeof settingsComponent.editAndSave === "function";
631
+ }
635
632
  async function fetchCommunityPluginEntries() {
636
633
  const response = await (0, import_obsidian.requestUrl)(COMMUNITY_PLUGINS_URL);
637
634
  return response.json;
@@ -650,6 +647,12 @@ async function getPluginManifest(repo, version) {
650
647
  const response = await (0, import_obsidian.requestUrl)(`https://github.com/${repo}/releases/download/${version}/manifest.json`);
651
648
  return response.json;
652
649
  }
650
+ function getSettingsComponent(plugin) {
651
+ if (typeof plugin !== "object" || plugin === null || !("pluginSettingsComponent" in plugin)) {
652
+ return null;
653
+ }
654
+ return plugin.pluginSettingsComponent;
655
+ }
653
656
  async function resolveCommunityPluginId(reference) {
654
657
  if ("pluginId" in reference) {
655
658
  return reference.pluginId;
@@ -674,6 +677,8 @@ var CODE_SCRIPT_TOOLKIT_SETTINGS = {
674
677
  };
675
678
  var DEMO_VAULT_HELPER_PLUGIN_ID = "demo-vault-helper";
676
679
  var PLUGINS_FOLDER_NAME = "plugins";
680
+ var DATA_JSON_FILE_NAME = "data.json";
681
+ var INVALID_DEMO_VAULT_ERROR_MESSAGE = "Invalid demo vault";
677
682
  var OPEN_DEMO_VAULT_COMMAND_NAME = "Open demo vault";
678
683
  var SANDBOX_NOTICE_DURATION_IN_MILLISECONDS = 0;
679
684
  async function bootstrapDemoVault(params) {
@@ -694,23 +699,17 @@ async function bootstrapDemoVault(params) {
694
699
  }
695
700
  showSandboxNotice(app, demoedPluginId);
696
701
  }
697
- function buildSandboxNoticeFragment(pluginName, basePath) {
702
+ function buildSandboxNoticeFragment(pluginName) {
698
703
  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.");
704
+ fragment.appendText("This is a demo vault for ");
705
+ fragment.createEl("b", { text: pluginName });
706
+ fragment.appendText(".");
707
+ fragment.createEl("br");
708
+ fragment.appendText("It is a temporary sandbox, cleaned up automatically about a day after you last use it.");
709
+ fragment.createEl("br");
710
+ fragment.appendText("Executing ");
711
+ fragment.createEl("b", { text: `${pluginName}: ${OPEN_DEMO_VAULT_COMMAND_NAME}` });
712
+ fragment.appendText(" command again creates a new copy with the latest plugin version, so your notes will not appear in it.");
714
713
  });
715
714
  }
716
715
  async function ensureInvocableScriptsFolder(app) {
@@ -720,23 +719,26 @@ async function ensureInvocableScriptsFolder(app) {
720
719
  }
721
720
  }
722
721
  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;
722
+ const settingsPath = join(app.vault.configDir, PLUGINS_FOLDER_NAME, DEMO_VAULT_HELPER_PLUGIN_ID, DATA_JSON_FILE_NAME);
723
+ if (!await app.vault.adapter.exists(settingsPath)) {
724
+ throw new Error(INVALID_DEMO_VAULT_ERROR_MESSAGE);
726
725
  }
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";
726
+ let parsed;
727
+ try {
728
+ parsed = JSON.parse(await app.vault.adapter.read(settingsPath));
729
+ } catch (error) {
730
+ throw new Error(INVALID_DEMO_VAULT_ERROR_MESSAGE, { cause: error });
731
+ }
732
+ const demoedPluginId = parsed?.demoedPluginId;
733
+ if (typeof demoedPluginId !== "string" || demoedPluginId === EMPTY) {
734
+ throw new Error(INVALID_DEMO_VAULT_ERROR_MESSAGE);
735
+ }
736
+ return demoedPluginId;
736
737
  }
737
738
  function showSandboxNotice(app, demoedPluginId) {
738
- const pluginName = demoedPluginId === null ? null : app.plugins.manifests[demoedPluginId]?.name ?? demoedPluginId;
739
- const fragment = buildSandboxNoticeFragment(pluginName, getVaultBasePath(app));
739
+ const pluginName = app.plugins.manifests[demoedPluginId]?.name ?? demoedPluginId;
740
+ const fragment = buildSandboxNoticeFragment(pluginName);
741
+ app.setting.close();
740
742
  new import_obsidian2.Notice(fragment, SANDBOX_NOTICE_DURATION_IN_MILLISECONDS);
741
743
  }
742
744