@mnaoumov/create-obsidian-plugin 0.0.0-stage → 1.0.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/LICENSE +19 -0
- package/README.md +341 -2
- package/dist/main.js +4184 -0
- package/package.json +83 -4
- package/src/main.ts +650 -0
- package/templates/default/.depcheckrc.json.ejs +19 -0
- package/templates/default/.editorconfig.ejs +11 -0
- package/templates/default/.env.ejs +1 -0
- package/templates/default/.env@vault_has-vault-false.ejs +2 -0
- package/templates/default/.env@vault_has-vault-true.ejs +1 -0
- package/templates/default/.gitattributes.ejs +7 -0
- package/templates/default/.github/FUNDING.yml.ejs +3 -0
- package/templates/default/.github/ISSUE_TEMPLATE/bug_report.yml.ejs +71 -0
- package/templates/default/.github/ISSUE_TEMPLATE/config.yml.ejs +1 -0
- package/templates/default/.github/ISSUE_TEMPLATE/feature_request.yml.ejs +61 -0
- package/templates/default/.github/workflows/attest-release-assets.yml.ejs +24 -0
- package/templates/default/.github/workflows/ci.yml.ejs +20 -0
- package/templates/default/.github/workflows/ci.yml@steps_biome-linter.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_cspell.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_dprint.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_eslint.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_jest.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_markdownlint.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_prettier.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_vitest.ejs +1 -0
- package/templates/default/.github/workflows/release.yml.ejs +27 -0
- package/templates/default/.github/workflows/update-license-year.yml.ejs +38 -0
- package/templates/default/.gitignore_common.ejs +27 -0
- package/templates/default/.gitignore_scss.ejs +1 -0
- package/templates/default/.gitignore_tailwind.ejs +3 -0
- package/templates/default/.husky/commit-msg.ejs +1 -0
- package/templates/default/.husky/pre-commit.ejs +1 -0
- package/templates/default/.markdownlint-cli2.mjs.ejs +4 -0
- package/templates/default/.nano-staged.mjs.ejs +5 -0
- package/templates/default/.npmrc.ejs +1 -0
- package/templates/default/.parcelrc.ejs +9 -0
- package/templates/default/.parcelrc@transformers_svelte.ejs +1 -0
- package/templates/default/.prettierignore.ejs +10 -0
- package/templates/default/.typesafe-i18n.json.ejs +5 -0
- package/templates/default/CONTRIBUTING.md.ejs +49 -0
- package/templates/default/CONTRIBUTING.md@demo-vault_dev-utils.ejs +15 -0
- package/templates/default/CONTRIBUTING.md@scripts_biome-formatter.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_biome-linter.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_conventional-commits.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_cspell.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_dev-utils.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_dprint.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_eslint.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_jest.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_markdownlint.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_prettier.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_vitest.ejs +1 -0
- package/templates/default/LICENSE.ejs +21 -0
- package/templates/default/README.md.ejs +28 -0
- package/templates/default/README.md@demo-vault_dev-utils.ejs +12 -0
- package/templates/default/README.md@preset_dev-utils.ejs +12 -0
- package/templates/default/README.md@support_has-funding.ejs +8 -0
- package/templates/default/babel.config.json.ejs +8 -0
- package/templates/default/babel.config.mjs.ejs +5 -0
- package/templates/default/biome.jsonc.ejs +47 -0
- package/templates/default/commitlint.config.ts.ejs +1 -0
- package/templates/default/cspell.json.ejs +67 -0
- package/templates/default/demo-vault/.gitignore.ejs +15 -0
- package/templates/default/demo-vault/.obsidian/app.json.ejs +4 -0
- package/templates/default/demo-vault/.obsidian/community-plugins.json.ejs +4 -0
- package/templates/default/demo-vault/00 Start.md.ejs +32 -0
- package/templates/default/demo-vault/00 Start.md@features_wasm.ejs +1 -0
- package/templates/default/demo-vault/01 Sample commands.md.ejs +38 -0
- package/templates/default/demo-vault/01 Sample commands.md@commands_wasm.ejs +4 -0
- package/templates/default/demo-vault/02 Settings.md.ejs +40 -0
- package/templates/default/demo-vault/03 WebAssembly.md.ejs +34 -0
- package/templates/default/demo-vault/Materials/01 Sample commands/Scratch note.md.ejs +5 -0
- package/templates/default/demo-vault/README.md.ejs +10 -0
- package/templates/default/demo-vault/_assets/CodeScriptToolkit/demoSetup.ts.ejs +88 -0
- package/templates/default/demo-vault/_assets/CodeScriptToolkit/demoSetup.ts@commands_wasm.ejs +10 -0
- package/templates/default/demo-vault/_assets/CodeScriptToolkit/startup.ts.ejs +17 -0
- package/templates/default/dprint.json_dev-utils.ejs +10 -0
- package/templates/default/dprint.json_standalone.ejs +26 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test.ejs +16 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test@lint-no-void-disable_dev-utils.ejs +3 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test@lint-no-void-enable_dev-utils.ejs +1 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test@unofficial_with-unofficial.ejs +13 -0
- package/templates/default/e2e/sample.spec.ts_wdio-obsidian.ejs +7 -0
- package/templates/default/e2e/sample.spec.ts_wdio-obsidian@unofficial_with-unofficial.ejs +15 -0
- package/templates/default/eslint.config.mts_dev-utils.ejs +1 -0
- package/templates/default/eslint.config.mts_standalone.ejs +119 -0
- package/templates/default/eslint.config.mts_standalone@extra-files_has-e2e.ejs +2 -0
- package/templates/default/jest.config.ts.ejs +57 -0
- package/templates/default/jest.config.ts@lint-root-dir_dev-utils.ejs +1 -0
- package/templates/default/jest.config.ts@ts-jest-tsconfig_solid.ejs +8 -0
- package/templates/default/linkinator.config.json.ejs +11 -0
- package/templates/default/manifest.json.ejs +11 -0
- package/templates/default/manifest.json@funding_has-funding.ejs +1 -0
- package/templates/default/manifest.json@platform_desktop-and-mobile.ejs +1 -0
- package/templates/default/manifest.json@platform_desktop-only.ejs +1 -0
- package/templates/default/package.json.ejs +32 -0
- package/templates/default/package.json@targets_parcel.ejs +36 -0
- package/templates/default/parcel-namer-obsidian.cjs.ejs +26 -0
- package/templates/default/parcel-resolver-obsidian.cjs.ejs +37 -0
- package/templates/default/parcel-transformer-inline-imports.cjs.ejs +39 -0
- package/templates/default/parcel-transformer-svelte.cjs.ejs +67 -0
- package/templates/default/pinned-versions.json.ejs +1 -0
- package/templates/default/pnpm-workspace.yaml.ejs +19 -0
- package/templates/default/postcss.config.cjs.ejs +12 -0
- package/templates/default/prettier.config.mjs.ejs +5 -0
- package/templates/default/rollup.config.mjs.ejs +7 -0
- package/templates/default/scripts/babel.config.ts_rollup.ejs +16 -0
- package/templates/default/scripts/babel.config.ts_rollup@babel-plugin_preact.ejs +1 -0
- package/templates/default/scripts/babel.config.ts_rollup@babel-preset_react.ejs +1 -0
- package/templates/default/scripts/babel.config.ts_rollup@babel-preset_solid.ejs +1 -0
- package/templates/default/scripts/build-clean.ts.ejs +4 -0
- package/templates/default/scripts/build-compile.ts.ejs +4 -0
- package/templates/default/scripts/build-styles.ts.ejs +12 -0
- package/templates/default/scripts/build.ts.ejs +6 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler.ejs +63 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@compile_svelte.ejs +4 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@fs-import_hot-reload-plugin.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@hot-reload_hot-reload-plugin.ejs +3 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@import_tailwind.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@lint-build-styles_dev-utils.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@reload_obsidian-cli.ejs +5 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_parcel.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_rollup.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_vite.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_webpack.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild.ejs +3 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@compile_svelte.ejs +4 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@dev-utils-pre-build_tailwind.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@fs-import_hot-reload-plugin.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@hot-reload_hot-reload-plugin.ejs +4 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_postcss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_scss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_solid.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_svelte.ejs +10 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_tailwind.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_vue.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@lint-build-styles_dev-utils.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@options_preact.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@options_react.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@options_wasm.ejs +5 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_postcss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_scss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_solid.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_svelte.ejs +5 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_vue.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@preset_standalone.ejs +138 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@reload_obsidian-cli.ejs +6 -0
- package/templates/default/scripts/commit.ts_dev-utils.ejs +3 -0
- package/templates/default/scripts/commit.ts_standalone.ejs +3 -0
- package/templates/default/scripts/commitlint-config.ts.ejs +5 -0
- package/templates/default/scripts/demo-vault-global-setup.ts.ejs +43 -0
- package/templates/default/scripts/dev.ts.ejs +6 -0
- package/templates/default/scripts/dev.ts@bundler_cli-bundler.ejs +8 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild.ejs +3 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@dev-utils-pre-build_tailwind.ejs +2 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@lint-build-styles_dev-utils.ejs +1 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@preset_standalone.ejs +3 -0
- package/templates/default/scripts/esbuild-plugins.ts.ejs +20 -0
- package/templates/default/scripts/esbuild-plugins.ts@dev-utils-import_vue.ejs +2 -0
- package/templates/default/scripts/esbuild-plugins.ts@dev-utils-plugin_vue.ejs +1 -0
- package/templates/default/scripts/esbuild-plugins.ts@dev-utils-plugin_wasm.ejs +13 -0
- package/templates/default/scripts/eslint-config.ts.ejs +113 -0
- package/templates/default/scripts/eslint-config.ts@extra-files_has-e2e.ejs +7 -0
- package/templates/default/scripts/find-overexposed-fix.ts.ejs +26 -0
- package/templates/default/scripts/find-overexposed.ts.ejs +15 -0
- package/templates/default/scripts/format-check.ts.ejs +4 -0
- package/templates/default/scripts/format-check.ts@tool_biome-formatter.ejs +8 -0
- package/templates/default/scripts/format-check.ts@tool_dprint.ejs +3 -0
- package/templates/default/scripts/format-check.ts@tool_dprint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/format-check.ts@tool_dprint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/format-check.ts@tool_prettier.ejs +8 -0
- package/templates/default/scripts/format.ts.ejs +4 -0
- package/templates/default/scripts/format.ts@tool_biome-formatter.ejs +8 -0
- package/templates/default/scripts/format.ts@tool_dprint.ejs +3 -0
- package/templates/default/scripts/format.ts@tool_dprint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/format.ts@tool_dprint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/format.ts@tool_prettier.ejs +8 -0
- package/templates/default/scripts/framework-component-stub.ts.ejs +46 -0
- package/templates/default/scripts/gate.ts.ejs +10 -0
- package/templates/default/scripts/lint-fix.ts.ejs +6 -0
- package/templates/default/scripts/lint-fix.ts@tool_biome-linter.ejs +8 -0
- package/templates/default/scripts/lint-fix.ts@tool_eslint.ejs +3 -0
- package/templates/default/scripts/lint-fix.ts@tool_eslint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint-fix.ts@tool_eslint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/lint-md-fix.ts_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint-md-fix.ts_standalone.ejs +37 -0
- package/templates/default/scripts/lint-md.ts_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint-md.ts_standalone.ejs +37 -0
- package/templates/default/scripts/lint.ts.ejs +6 -0
- package/templates/default/scripts/lint.ts@tool_biome-linter.ejs +8 -0
- package/templates/default/scripts/lint.ts@tool_eslint.ejs +3 -0
- package/templates/default/scripts/lint.ts@tool_eslint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint.ts@tool_eslint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/markdownlint-cli2-config.ts_dev-utils.ejs +14 -0
- package/templates/default/scripts/markdownlint-cli2-config.ts_standalone.ejs +36 -0
- package/templates/default/scripts/nano-staged-config.ts.ejs +9 -0
- package/templates/default/scripts/postcss.config.ts.ejs +1 -0
- package/templates/default/scripts/postcss.config.ts@plugins_postcss.ejs +7 -0
- package/templates/default/scripts/prepare.ts_dev-utils.ejs +3 -0
- package/templates/default/scripts/prepare.ts_standalone.ejs +3 -0
- package/templates/default/scripts/prettier.config.ts.ejs +12 -0
- package/templates/default/scripts/rollup.config.ts.ejs +129 -0
- package/templates/default/scripts/rollup.config.ts@import_rollup-babel.ejs +5 -0
- package/templates/default/scripts/rollup.config.ts@import_rollup-json.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@import_rollup-postcss.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@import_scss.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@import_svelte.ejs +2 -0
- package/templates/default/scripts/rollup.config.ts@import_vue.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@import_wasm.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@lint-out-dir_dev-utils.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_preact.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_react.ejs +5 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_rollup-json.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_rollup-postcss.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_scss.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_solid.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_wasm.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@pre-plugin_svelte.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@pre-plugin_vue.ejs +13 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_rollup-babel.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_rollup-json.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_rollup-postcss.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_scss.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_svelte.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_vue.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_wasm.ejs +1 -0
- package/templates/default/scripts/spellcheck.ts_dev-utils.ejs +7 -0
- package/templates/default/scripts/spellcheck.ts_standalone.ejs +8 -0
- package/templates/default/scripts/stylesheet-stub.ts.ejs +17 -0
- package/templates/default/scripts/test-coverage.ts.ejs +8 -0
- package/templates/default/scripts/test-e2e.ts.ejs +1 -0
- package/templates/default/scripts/test-e2e.ts@tool_obsidian-test.ejs +8 -0
- package/templates/default/scripts/test-e2e.ts@tool_wdio-obsidian.ejs +8 -0
- package/templates/default/scripts/test-integration-android.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-demo-vault.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-desktop-performance.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-desktop.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-no-app.ts.ejs +8 -0
- package/templates/default/scripts/test-integration.ts.ejs +22 -0
- package/templates/default/scripts/test-watch.ts_dev-utils.ejs +1 -0
- package/templates/default/scripts/test-watch.ts_dev-utils@tool_jest.ejs +13 -0
- package/templates/default/scripts/test-watch.ts_dev-utils@tool_vitest.ejs +8 -0
- package/templates/default/scripts/test-watch.ts_standalone.ejs +1 -0
- package/templates/default/scripts/test-watch.ts_standalone@tool_jest.ejs +13 -0
- package/templates/default/scripts/test-watch.ts_standalone@tool_vitest.ejs +8 -0
- package/templates/default/scripts/test.ts_dev-utils.ejs +1 -0
- package/templates/default/scripts/test.ts_dev-utils@tool_jest.ejs +13 -0
- package/templates/default/scripts/test.ts_dev-utils@tool_vitest.ejs +8 -0
- package/templates/default/scripts/test.ts_standalone.ejs +1 -0
- package/templates/default/scripts/test.ts_standalone@tool_jest.ejs +13 -0
- package/templates/default/scripts/test.ts_standalone@tool_vitest.ejs +8 -0
- package/templates/default/scripts/version.ts_dev-utils.ejs +10 -0
- package/templates/default/scripts/version.ts_standalone.ejs +317 -0
- package/templates/default/scripts/vite.config.ts.ejs +76 -0
- package/templates/default/scripts/vite.config.ts@import_preact.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_react.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_solid.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_svelte.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_vue.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@lint-empty-out-dir_dev-utils.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@lint-out-dir_dev-utils.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_preact.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_react.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_solid.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_svelte.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_vue.ejs +1 -0
- package/templates/default/scripts/vitest-config.ts.ejs +75 -0
- package/templates/default/scripts/vitest-config.ts@post-config_solid.ejs +67 -0
- package/templates/default/scripts/wasm-module-stub.ts.ejs +21 -0
- package/templates/default/scripts/webpack.config.ts.ejs +124 -0
- package/templates/default/scripts/webpack.config.ts@import_svelte.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@import_vue.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@import_webpack-css-extract.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@lint-webpack-default_dev-utils.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@plugin_vue.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@plugin_webpack-css-extract.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_css-modules.ejs +7 -0
- package/templates/default/scripts/webpack.config.ts@rule_css.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_postcss.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_scss.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_solid.ejs +17 -0
- package/templates/default/scripts/webpack.config.ts@rule_svelte.ejs +7 -0
- package/templates/default/scripts/webpack.config.ts@rule_tailwind.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_vue.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_wasm.ejs +8 -0
- package/templates/default/scripts/webpack.config.ts@ts-loader-compiler-options_vue.ejs +5 -0
- package/templates/default/scripts/webpack.config.ts@ts-loader-options_vue.ejs +5 -0
- package/templates/default/src/demo-vault-buttons.demo-vault.integration.test.ts.ejs +12 -0
- package/templates/default/src/demo-vault.no-app.integration.test.ts.ejs +18 -0
- package/templates/default/src/editor-extensions/sample-state-field.ts_dev-utils.ejs +56 -0
- package/templates/default/src/editor-extensions/sample-state-field.ts_standalone.ejs +60 -0
- package/templates/default/src/editor-extensions/sample-view-plugin.ts.ejs +66 -0
- package/templates/default/src/editor-extensions/sample-widget.ts.ejs +22 -0
- package/templates/default/src/editor-suggests/sample-editor-suggest.ts.ejs +42 -0
- package/templates/default/src/i18n/en/index.ts.ejs +10 -0
- package/templates/default/src/i18n/index.ts_i18next.ejs +21 -0
- package/templates/default/src/i18n/index.ts_typesafe-i18n.ejs +14 -0
- package/templates/default/src/i18n/locales/en.json.ejs +3 -0
- package/templates/default/src/lit-elements/sample-lit-element.ts.ejs +54 -0
- package/templates/default/src/main.test.ts.ejs +11 -0
- package/templates/default/src/main.test.ts@test-imports_vitest.ejs +6 -0
- package/templates/default/src/main.ts.ejs +4 -0
- package/templates/default/src/main.ts@import_css-modules.ejs +1 -0
- package/templates/default/src/main.ts@import_css.ejs +1 -0
- package/templates/default/src/main.ts@import_postcss.ejs +1 -0
- package/templates/default/src/main.ts@import_scss.ejs +1 -0
- package/templates/default/src/main.ts@import_tailwind.ejs +1 -0
- package/templates/default/src/modals/sample-form-modal.ts.ejs +35 -0
- package/templates/default/src/modals/sample-suggest-modal.ts.ejs +37 -0
- package/templates/default/src/plugin-settings-component.test.ts_demo.ejs +49 -0
- package/templates/default/src/plugin-settings-component.test.ts_demo@test-imports_vitest.ejs +5 -0
- package/templates/default/src/plugin-settings-component.test.ts_enhanced.ejs +41 -0
- package/templates/default/src/plugin-settings-component.test.ts_enhanced@test-imports_vitest.ejs +5 -0
- package/templates/default/src/plugin-settings-component.ts_demo.ejs +87 -0
- package/templates/default/src/plugin-settings-component.ts_enhanced.ejs +27 -0
- package/templates/default/src/plugin-settings-tab.ts_demo.ejs +286 -0
- package/templates/default/src/plugin-settings-tab.ts_enhanced.ejs +26 -0
- package/templates/default/src/plugin-settings.test.ts_demo.ejs +14 -0
- package/templates/default/src/plugin-settings.test.ts_demo@test-imports_vitest.ejs +6 -0
- package/templates/default/src/plugin-settings.ts_demo.ejs +64 -0
- package/templates/default/src/plugin-settings.ts_enhanced.ejs +3 -0
- package/templates/default/src/plugin.test.ts_jest.ejs +9 -0
- package/templates/default/src/plugin.test.ts_vitest.ejs +14 -0
- package/templates/default/src/plugin.ts_demo.ejs +316 -0
- package/templates/default/src/plugin.ts_demo@import_i18next.ejs +1 -0
- package/templates/default/src/plugin.ts_demo@import_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_react.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_typesafe-i18n.ejs +1 -0
- package/templates/default/src/plugin.ts_demo@import_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_wasm.ejs +1 -0
- package/templates/default/src/plugin.ts_demo@method_ui-view.ejs +7 -0
- package/templates/default/src/plugin.ts_demo@onload_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_demo@onload_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_react.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_typesafe-i18n.ejs +8 -0
- package/templates/default/src/plugin.ts_demo@onload_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_wasm.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced.ejs +72 -0
- package/templates/default/src/plugin.ts_enhanced@import2_codemirror.ejs +3 -0
- package/templates/default/src/plugin.ts_enhanced@import2_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced@import2_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_react.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_typesafe-i18n.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced@import2_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_wasm.ejs +1 -0
- package/templates/default/src/plugin.ts_enhanced@method_ui-view.ejs +7 -0
- package/templates/default/src/plugin.ts_enhanced@onload_codemirror.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced@onload_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_react.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_typesafe-i18n.ejs +8 -0
- package/templates/default/src/plugin.ts_enhanced@onload_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_wasm.ejs +2 -0
- package/templates/default/src/plugin.ts_standalone.ejs +56 -0
- package/templates/default/src/plugin.ts_standalone@import_codemirror.ejs +3 -0
- package/templates/default/src/plugin.ts_standalone@import_i18next.ejs +1 -0
- package/templates/default/src/plugin.ts_standalone@import_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_react.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_typesafe-i18n.ejs +1 -0
- package/templates/default/src/plugin.ts_standalone@import_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_wasm.ejs +1 -0
- package/templates/default/src/plugin.ts_standalone@method_ui-view.ejs +7 -0
- package/templates/default/src/plugin.ts_standalone@onload_codemirror.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_standalone@onload_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_react.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_typesafe-i18n.ejs +8 -0
- package/templates/default/src/plugin.ts_standalone@onload_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_wasm.ejs +2 -0
- package/templates/default/src/preact-components/sample-preact-component.tsx_dev-utils.ejs +47 -0
- package/templates/default/src/preact-components/sample-preact-component.tsx_standalone.ejs +47 -0
- package/templates/default/src/react-components/sample-react-component.tsx_dev-utils.ejs +35 -0
- package/templates/default/src/react-components/sample-react-component.tsx_standalone.ejs +47 -0
- package/templates/default/src/settings.ts.ejs +32 -0
- package/templates/default/src/solid-components/sample-solid-component.tsx_dev-utils.ejs +47 -0
- package/templates/default/src/solid-components/sample-solid-component.tsx_standalone.ejs +47 -0
- package/templates/default/src/styles/css-modules.d.ts.ejs +4 -0
- package/templates/default/src/styles/main.css_dev-utils.ejs +17 -0
- package/templates/default/src/styles/main.css_dev-utils@content_tailwind.ejs +1 -0
- package/templates/default/src/styles/main.css_standalone.ejs +11 -0
- package/templates/default/src/styles/main.css_standalone@content_tailwind.ejs +1 -0
- package/templates/default/src/styles/main.module.css.ejs +3 -0
- package/templates/default/src/styles/main.scss_dev-utils.ejs +16 -0
- package/templates/default/src/styles/main.scss_standalone.ejs +10 -0
- package/templates/default/src/styles/styles.d.ts.ejs +4 -0
- package/templates/default/src/svelte-components/sample-svelte-component.d.ts.ejs +7 -0
- package/templates/default/src/svelte-components/sample-svelte-component.svelte.ejs +24 -0
- package/templates/default/src/views/sample-lit-view.ts.ejs +30 -0
- package/templates/default/src/views/sample-lit-view.ts@lint-register-element_dev-utils.ejs +1 -0
- package/templates/default/src/views/sample-preact-view.tsx_dev-utils.ejs +45 -0
- package/templates/default/src/views/sample-preact-view.tsx_standalone.ejs +42 -0
- package/templates/default/src/views/sample-react-view.tsx_dev-utils.ejs +47 -0
- package/templates/default/src/views/sample-react-view.tsx_standalone.ejs +49 -0
- package/templates/default/src/views/sample-solid-view.tsx_dev-utils.ejs +46 -0
- package/templates/default/src/views/sample-solid-view.tsx_standalone.ejs +46 -0
- package/templates/default/src/views/sample-svelte-view.ts.ejs +47 -0
- package/templates/default/src/views/sample-view.ts.ejs +37 -0
- package/templates/default/src/views/sample-vue-view.ts.ejs +34 -0
- package/templates/default/src/vue-components/sample-vue-component.d.ts.ejs +6 -0
- package/templates/default/src/vue-components/sample-vue-component.vue.ejs +25 -0
- package/templates/default/src/wasm/README.md.ejs +29 -0
- package/templates/default/src/wasm/answer.ts_esbuild.ejs +23 -0
- package/templates/default/src/wasm/answer.ts_parcel.ejs +29 -0
- package/templates/default/src/wasm/answer.ts_rollup.ejs +19 -0
- package/templates/default/src/wasm/answer.ts_vite.ejs +29 -0
- package/templates/default/src/wasm/answer.ts_webpack.ejs +29 -0
- package/templates/default/src/wasm/module.wasm +0 -0
- package/templates/default/src/wasm/module.wat.ejs +12 -0
- package/templates/default/src/wasm/sample-command.ts.ejs +33 -0
- package/templates/default/src/wasm.d.ts_esbuild.ejs +12 -0
- package/templates/default/src/wasm.d.ts_parcel.ejs +7 -0
- package/templates/default/src/wasm.d.ts_rollup.ejs +8 -0
- package/templates/default/src/wasm.d.ts_vite.ejs +8 -0
- package/templates/default/src/wasm.d.ts_webpack.ejs +7 -0
- package/templates/default/tsconfig.json_dev-utils.ejs +34 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_i18next.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_lit.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_preact.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_react.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_solid.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@include_has-e2e.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@include_svelte.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@include_vue.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@types_jest.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@types_svelte.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@types_wdio-obsidian.ejs +5 -0
- package/templates/default/tsconfig.json_dev-utils@types_with-unofficial.ejs +2 -0
- package/templates/default/tsconfig.json_standalone.ejs +47 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_i18next.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_lit.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_preact.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_react.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_solid.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include-extra_preact.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include-extra_react.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include-extra_solid.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include_has-e2e.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@include_svelte.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@include_vue.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@types_jest.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@types_svelte.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@types_wdio-obsidian.ejs +5 -0
- package/templates/default/tsconfig.json_standalone@types_with-unofficial.ejs +2 -0
- package/templates/default/versions.json.ejs +3 -0
- package/templates/default/vite.config.ts.ejs +3 -0
- package/templates/default/vitest.config.ts_dev-utils.ejs +1 -0
- package/templates/default/vitest.config.ts_standalone.ejs +55 -0
- package/templates/default/vitest.config.ts_standalone@jsx_solid.ejs +11 -0
- package/templates/default/wdio.conf.ts.ejs +21 -0
- package/templates/default/webpack.config.ts.ejs +3 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ItemView } from 'obsidian';
|
|
2
|
+
// eslint-disable-next-line import-x/no-deprecated -- Only the third `replaceNode` parameter is deprecated; the two-argument form this file uses is not.
|
|
3
|
+
import { render } from 'preact';
|
|
4
|
+
|
|
5
|
+
import type { SamplePreactComponentProps } from '../preact-components/sample-preact-component.tsx';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
AppContext,
|
|
9
|
+
SamplePreactComponent
|
|
10
|
+
} from '../preact-components/sample-preact-component.tsx';
|
|
11
|
+
|
|
12
|
+
export const SAMPLE_PREACT_VIEW_TYPE = '<%= pluginId %>-SamplePreactView';
|
|
13
|
+
|
|
14
|
+
export class SamplePreactView extends ItemView {
|
|
15
|
+
public override getDisplayText(): string {
|
|
16
|
+
return 'Sample Preact view';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public override getViewType(): string {
|
|
20
|
+
return SAMPLE_PREACT_VIEW_TYPE;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public override onClose(): Promise<void> {
|
|
24
|
+
// eslint-disable-next-line import-x/no-deprecated -- See the import: the two-argument form is not deprecated.
|
|
25
|
+
render(null, this.contentEl);
|
|
26
|
+
return super.onClose();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public override onOpen(): Promise<void> {
|
|
30
|
+
const START_COUNT = 10;
|
|
31
|
+
const props: SamplePreactComponentProps = {
|
|
32
|
+
startCount: START_COUNT
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line import-x/no-deprecated -- See the import: the two-argument form is not deprecated.
|
|
36
|
+
render(
|
|
37
|
+
<AppContext.Provider value={this.app}>
|
|
38
|
+
<SamplePreactComponent {...props} />
|
|
39
|
+
</AppContext.Provider>,
|
|
40
|
+
this.contentEl
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return super.onOpen();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ItemView } from 'obsidian';
|
|
2
|
+
import { render } from 'preact';
|
|
3
|
+
|
|
4
|
+
import type { SamplePreactComponentProps } from '../preact-components/sample-preact-component.tsx';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
AppContext,
|
|
8
|
+
SamplePreactComponent
|
|
9
|
+
} from '../preact-components/sample-preact-component.tsx';
|
|
10
|
+
|
|
11
|
+
export const SAMPLE_PREACT_VIEW_TYPE = '<%= pluginId %>-SamplePreactView';
|
|
12
|
+
|
|
13
|
+
export class SamplePreactView extends ItemView {
|
|
14
|
+
public override getDisplayText(): string {
|
|
15
|
+
return 'Sample Preact view';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public override getViewType(): string {
|
|
19
|
+
return SAMPLE_PREACT_VIEW_TYPE;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public override onClose(): Promise<void> {
|
|
23
|
+
render(null, this.contentEl);
|
|
24
|
+
return super.onClose();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public override onOpen(): Promise<void> {
|
|
28
|
+
const START_COUNT = 10;
|
|
29
|
+
const props: SamplePreactComponentProps = {
|
|
30
|
+
startCount: START_COUNT
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
render(
|
|
34
|
+
<AppContext.Provider value={this.app}>
|
|
35
|
+
<SamplePreactComponent {...props} />
|
|
36
|
+
</AppContext.Provider>,
|
|
37
|
+
this.contentEl
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return super.onOpen();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Root } from 'react-dom/client';
|
|
2
|
+
|
|
3
|
+
import { ItemView } from 'obsidian';
|
|
4
|
+
import { AppContext } from 'obsidian-dev-utils/obsidian/react/app-context';
|
|
5
|
+
import { StrictMode } from 'react';
|
|
6
|
+
import { createRoot } from 'react-dom/client';
|
|
7
|
+
|
|
8
|
+
import type { SampleReactComponentProps } from '../react-components/sample-react-component.tsx';
|
|
9
|
+
|
|
10
|
+
import { SampleReactComponent } from '../react-components/sample-react-component.tsx';
|
|
11
|
+
|
|
12
|
+
export const SAMPLE_REACT_VIEW_TYPE = '<%= pluginId %>-SampleReactView';
|
|
13
|
+
|
|
14
|
+
export class SampleReactView extends ItemView {
|
|
15
|
+
private root: null | Root = null;
|
|
16
|
+
|
|
17
|
+
public override getDisplayText(): string {
|
|
18
|
+
return 'Sample React view';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public override getViewType(): string {
|
|
22
|
+
return SAMPLE_REACT_VIEW_TYPE;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public override onClose(): Promise<void> {
|
|
26
|
+
this.root?.unmount();
|
|
27
|
+
return super.onClose();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public override onOpen(): Promise<void> {
|
|
31
|
+
const START_COUNT = 10;
|
|
32
|
+
const props: SampleReactComponentProps = {
|
|
33
|
+
startCount: START_COUNT
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
this.root = createRoot(this.contentEl);
|
|
37
|
+
this.root.render(
|
|
38
|
+
<StrictMode>
|
|
39
|
+
<AppContext.Provider value={this.app}>
|
|
40
|
+
<SampleReactComponent {...props} />
|
|
41
|
+
</AppContext.Provider>
|
|
42
|
+
</StrictMode>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return super.onOpen();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Root } from 'react-dom/client';
|
|
2
|
+
|
|
3
|
+
import { ItemView } from 'obsidian';
|
|
4
|
+
import { StrictMode } from 'react';
|
|
5
|
+
import { createRoot } from 'react-dom/client';
|
|
6
|
+
|
|
7
|
+
import type { SampleReactComponentProps } from '../react-components/sample-react-component.tsx';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AppContext,
|
|
11
|
+
SampleReactComponent
|
|
12
|
+
} from '../react-components/sample-react-component.tsx';
|
|
13
|
+
|
|
14
|
+
export const SAMPLE_REACT_VIEW_TYPE = '<%= pluginId %>-SampleReactView';
|
|
15
|
+
|
|
16
|
+
export class SampleReactView extends ItemView {
|
|
17
|
+
private root: null | Root = null;
|
|
18
|
+
|
|
19
|
+
public override getDisplayText(): string {
|
|
20
|
+
return 'Sample React view';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public override getViewType(): string {
|
|
24
|
+
return SAMPLE_REACT_VIEW_TYPE;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public override onClose(): Promise<void> {
|
|
28
|
+
this.root?.unmount();
|
|
29
|
+
return super.onClose();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public override onOpen(): Promise<void> {
|
|
33
|
+
const START_COUNT = 10;
|
|
34
|
+
const props: SampleReactComponentProps = {
|
|
35
|
+
startCount: START_COUNT
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
this.root = createRoot(this.contentEl);
|
|
39
|
+
this.root.render(
|
|
40
|
+
<StrictMode>
|
|
41
|
+
<AppContext.Provider value={this.app}>
|
|
42
|
+
<SampleReactComponent {...props} />
|
|
43
|
+
</AppContext.Provider>
|
|
44
|
+
</StrictMode>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return super.onOpen();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ItemView } from 'obsidian';
|
|
2
|
+
import { render } from 'solid-js/web';
|
|
3
|
+
|
|
4
|
+
import type { SampleSolidComponentProps } from '../solid-components/sample-solid-component.tsx';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
AppContext,
|
|
8
|
+
SampleSolidComponent
|
|
9
|
+
} from '../solid-components/sample-solid-component.tsx';
|
|
10
|
+
|
|
11
|
+
export const SAMPLE_SOLID_VIEW_TYPE = '<%= pluginId %>-SampleSolidView';
|
|
12
|
+
|
|
13
|
+
export class SampleSolidView extends ItemView {
|
|
14
|
+
private dispose: (() => void) | null = null;
|
|
15
|
+
|
|
16
|
+
public override getDisplayText(): string {
|
|
17
|
+
return 'Sample Solid view';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override getViewType(): string {
|
|
21
|
+
return SAMPLE_SOLID_VIEW_TYPE;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public override onClose(): Promise<void> {
|
|
25
|
+
this.dispose?.();
|
|
26
|
+
return super.onClose();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public override onOpen(): Promise<void> {
|
|
30
|
+
const START_COUNT = 10;
|
|
31
|
+
const props: SampleSolidComponentProps = {
|
|
32
|
+
startCount: START_COUNT
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this.dispose = render(
|
|
36
|
+
() => (
|
|
37
|
+
<AppContext.Provider value={this.app}>
|
|
38
|
+
<SampleSolidComponent {...props} />
|
|
39
|
+
</AppContext.Provider>
|
|
40
|
+
),
|
|
41
|
+
this.contentEl
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return super.onOpen();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ItemView } from 'obsidian';
|
|
2
|
+
import { render } from 'solid-js/web';
|
|
3
|
+
|
|
4
|
+
import type { SampleSolidComponentProps } from '../solid-components/sample-solid-component.tsx';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
AppContext,
|
|
8
|
+
SampleSolidComponent
|
|
9
|
+
} from '../solid-components/sample-solid-component.tsx';
|
|
10
|
+
|
|
11
|
+
export const SAMPLE_SOLID_VIEW_TYPE = '<%= pluginId %>-SampleSolidView';
|
|
12
|
+
|
|
13
|
+
export class SampleSolidView extends ItemView {
|
|
14
|
+
private dispose: (() => void) | null = null;
|
|
15
|
+
|
|
16
|
+
public override getDisplayText(): string {
|
|
17
|
+
return 'Sample Solid view';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override getViewType(): string {
|
|
21
|
+
return SAMPLE_SOLID_VIEW_TYPE;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public override onClose(): Promise<void> {
|
|
25
|
+
this.dispose?.();
|
|
26
|
+
return super.onClose();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public override onOpen(): Promise<void> {
|
|
30
|
+
const START_COUNT = 10;
|
|
31
|
+
const props: SampleSolidComponentProps = {
|
|
32
|
+
startCount: START_COUNT
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this.dispose = render(
|
|
36
|
+
() => (
|
|
37
|
+
<AppContext.Provider value={this.app}>
|
|
38
|
+
<SampleSolidComponent {...props} />
|
|
39
|
+
</AppContext.Provider>
|
|
40
|
+
),
|
|
41
|
+
this.contentEl
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return super.onOpen();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ItemView } from 'obsidian';
|
|
2
|
+
import {
|
|
3
|
+
mount,
|
|
4
|
+
unmount
|
|
5
|
+
} from 'svelte';
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
SampleSvelteComponentExports,
|
|
9
|
+
SampleSvelteComponentProps
|
|
10
|
+
} from '../svelte-components/sample-svelte-component.d.ts';
|
|
11
|
+
|
|
12
|
+
import SampleSvelteComponent from '../svelte-components/sample-svelte-component.svelte';
|
|
13
|
+
|
|
14
|
+
export const SAMPLE_SVELTE_VIEW_TYPE = '<%= pluginId %>-SampleSvelteView';
|
|
15
|
+
|
|
16
|
+
export class SampleSvelteView extends ItemView {
|
|
17
|
+
private sampleSvelteComponent: null | SampleSvelteComponentExports = null;
|
|
18
|
+
|
|
19
|
+
public override getDisplayText(): string {
|
|
20
|
+
return 'Sample Svelte view';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public override getViewType(): string {
|
|
24
|
+
return SAMPLE_SVELTE_VIEW_TYPE;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public override async onClose(): Promise<void> {
|
|
28
|
+
if (this.sampleSvelteComponent) {
|
|
29
|
+
await unmount(this.sampleSvelteComponent);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public override onOpen(): Promise<void> {
|
|
34
|
+
const START_COUNT = 10;
|
|
35
|
+
const props: SampleSvelteComponentProps = {
|
|
36
|
+
startCount: START_COUNT
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.sampleSvelteComponent = mount(SampleSvelteComponent, {
|
|
40
|
+
props,
|
|
41
|
+
target: this.contentEl
|
|
42
|
+
}) as SampleSvelteComponentExports;
|
|
43
|
+
|
|
44
|
+
this.sampleSvelteComponent.increment();
|
|
45
|
+
return super.onOpen();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ItemView } from 'obsidian';
|
|
2
|
+
|
|
3
|
+
export const SAMPLE_VIEW_TYPE = '<%= pluginShortName %>-SampleView';
|
|
4
|
+
|
|
5
|
+
export class SampleView extends ItemView {
|
|
6
|
+
public override getDisplayText(): string {
|
|
7
|
+
return 'Sample view';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public override getViewType(): string {
|
|
11
|
+
return SAMPLE_VIEW_TYPE;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public override onOpen(): Promise<void> {
|
|
15
|
+
const container = this.contentEl;
|
|
16
|
+
container.empty();
|
|
17
|
+
container.createEl('h4', { text: '<%= pluginName %>' });
|
|
18
|
+
|
|
19
|
+
const vaultName = this.app.vault.getName();
|
|
20
|
+
container.createEl('p', { text: `Vault: ${vaultName}` });
|
|
21
|
+
|
|
22
|
+
const files = this.app.vault.getMarkdownFiles();
|
|
23
|
+
container.createEl('p', { text: `Markdown files: ${String(files.length)}` });
|
|
24
|
+
|
|
25
|
+
const list = container.createEl('ul');
|
|
26
|
+
const MAX_FILES = 10;
|
|
27
|
+
for (const file of files.slice(0, MAX_FILES)) {
|
|
28
|
+
list.createEl('li', { text: file.path });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (files.length > MAX_FILES) {
|
|
32
|
+
list.createEl('li', { text: `... and ${String(files.length - MAX_FILES)} more` });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return super.onOpen();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { App as VueApp } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { ItemView } from 'obsidian';
|
|
4
|
+
import { createApp } from 'vue';
|
|
5
|
+
|
|
6
|
+
import SampleVueComponent from '../vue-components/sample-vue-component.vue';
|
|
7
|
+
|
|
8
|
+
export const SAMPLE_VUE_VIEW_TYPE = '<%= pluginId %>-SampleVueView';
|
|
9
|
+
|
|
10
|
+
export class SampleVueView extends ItemView {
|
|
11
|
+
private vueApp: null | VueApp = null;
|
|
12
|
+
|
|
13
|
+
public override getDisplayText(): string {
|
|
14
|
+
return 'Sample Vue view';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public override getViewType(): string {
|
|
18
|
+
return SAMPLE_VUE_VIEW_TYPE;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public override onClose(): Promise<void> {
|
|
22
|
+
this.vueApp?.unmount();
|
|
23
|
+
return super.onClose();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public override onOpen(): Promise<void> {
|
|
27
|
+
const START_COUNT = 10;
|
|
28
|
+
this.vueApp = createApp(SampleVueComponent, {
|
|
29
|
+
startCount: START_COUNT
|
|
30
|
+
});
|
|
31
|
+
this.vueApp.mount(this.contentEl);
|
|
32
|
+
return super.onOpen();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
startCount: number;
|
|
6
|
+
}>();
|
|
7
|
+
|
|
8
|
+
const count = ref(props.startCount);
|
|
9
|
+
|
|
10
|
+
function increment(): void {
|
|
11
|
+
count.value += 1;
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<h4>Sample Vue Component!</h4>
|
|
17
|
+
|
|
18
|
+
<div>
|
|
19
|
+
<span>My number is {{ count }}!</span>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<button type="button" @click="increment">
|
|
23
|
+
Increment
|
|
24
|
+
</button>
|
|
25
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# WebAssembly
|
|
2
|
+
|
|
3
|
+
This folder holds a working WebAssembly module and the code that calls it. It is a sample: replace it with your own, and this note with what yours does.
|
|
4
|
+
|
|
5
|
+
WebAssembly is how you use code written in Rust, C, Go or AssemblyScript from a plugin. Unlike a native Node binary it runs on **mobile** too, so it is the portable route — which is why it is worth a sample rather than a paragraph of instructions.
|
|
6
|
+
|
|
7
|
+
## What is here
|
|
8
|
+
|
|
9
|
+
| File | What it is |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `module.wasm` | The compiled module: 39 bytes, one export, `answer()`, returning `42`. |
|
|
12
|
+
| `module.wat` | The same module in WebAssembly's text format, so the binary is not opaque. Documentation only — nothing in the build reads it. |
|
|
13
|
+
| `answer.ts` | Loads the module and exposes `getWasmAnswer()`. Written against the bundler you chose. |
|
|
14
|
+
|
|
15
|
+
`src/plugin.ts` registers a **Sample WASM answer** command that calls `getWasmAnswer()` and shows the result. That call is not decoration: a bundler tree-shakes an export nothing uses, so without a real call site the module would be dropped from `main.js` and the whole WebAssembly integration would be dead with the build still green.
|
|
16
|
+
|
|
17
|
+
## Replacing it with your own
|
|
18
|
+
|
|
19
|
+
1. Build a `.wasm` and put it in this folder. With Rust: install [Rust](https://www.rust-lang.org/tools/install) and [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/), `wasm-pack new my-wasm`, `wasm-pack build --target web`. With [AssemblyScript](https://www.assemblyscript.org/): `npm install assemblyscript`, then `npx asc assembly/index.ts --outFile src/wasm/module.wasm`.
|
|
20
|
+
2. Point `answer.ts` at it and name your own exports. `src/wasm.d.ts` declares what a `.wasm` import yields under this project's bundler — that differs between bundlers, which is why the file is generated rather than copied.
|
|
21
|
+
3. Keep something in `src/` calling into it, for the tree-shaking reason above.
|
|
22
|
+
|
|
23
|
+
## The one rule that is not obvious
|
|
24
|
+
|
|
25
|
+
Obsidian ships a plugin as `main.js` and `styles.css` and nothing else. A bundler that emits the module as a **separate** `.wasm` file next to the bundle produces a plugin that works in your repo and breaks the moment it is released — the file is simply not there. So the build is configured to **inline** the module into `main.js`, and every bundler needs telling that in its own way. If you swap bundlers, check that first.
|
|
26
|
+
|
|
27
|
+
## Provenance
|
|
28
|
+
|
|
29
|
+
`module.wasm` is the sample module from [CodeScript Toolkit](https://github.com/mnaoumov/obsidian-codescript-toolkit)'s demo vault, hand-written and 39 bytes long. `module.wat` is its source.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import bytes from './module.wasm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Instantiates the sample WebAssembly module and calls its one export.
|
|
5
|
+
*
|
|
6
|
+
* The signature is the same on every bundler; the two lines above and below are not. A `.wasm` import
|
|
7
|
+
* yields something different under each of them -- bytes here, a loader function under rollup, a `data:`
|
|
8
|
+
* URL under vite, webpack and parcel -- so this file is written per bundler and everything else in the
|
|
9
|
+
* plugin talks to `getWasmAnswer()`.
|
|
10
|
+
*
|
|
11
|
+
* Here the import is the module's bytes: esbuild's `binary` loader inlines the file as base64 and gives
|
|
12
|
+
* this module a `Uint8Array`.
|
|
13
|
+
*/
|
|
14
|
+
export async function getWasmAnswer(): Promise<number> {
|
|
15
|
+
// `compile` then `instantiate`, rather than `instantiate(bytes)` in one call: `WebAssembly.Module` is
|
|
16
|
+
// Declared as an EMPTY interface, so a `Uint8Array` satisfies it too and the one-call form resolves to
|
|
17
|
+
// The overload taking an already-compiled module -- whose result is a bare `Instance` with no
|
|
18
|
+
// `instance` property on it, which is TS2339 rather than anything about WebAssembly.
|
|
19
|
+
const compiled = await WebAssembly.compile(bytes);
|
|
20
|
+
const instance = await WebAssembly.instantiate(compiled);
|
|
21
|
+
const answer = instance.exports['answer'] as () => number;
|
|
22
|
+
return answer();
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import dataUrl from 'data-url:./module.wasm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Instantiates the sample WebAssembly module and calls its one export.
|
|
5
|
+
*
|
|
6
|
+
* The signature is the same on every bundler; the two lines above and below are not. A `.wasm` import
|
|
7
|
+
* yields something different under each of them -- a `data:` URL here, bytes under esbuild, a loader
|
|
8
|
+
* function under rollup -- so this file is written per bundler and everything else in the plugin talks
|
|
9
|
+
* to `getWasmAnswer()`.
|
|
10
|
+
*
|
|
11
|
+
* Parcel's `data-url:` scheme carries the module inside `main.js`, which is decoded here rather than
|
|
12
|
+
* fetched: `atob` is synchronous and needs no network stack, and it works the same in Obsidian's desktop
|
|
13
|
+
* and mobile runtimes.
|
|
14
|
+
*/
|
|
15
|
+
export async function getWasmAnswer(): Promise<number> {
|
|
16
|
+
// Percent-DECODED before it is base64-decoded, because parcel writes its data URL with the payload
|
|
17
|
+
// Percent-encoded -- `/` reaches the bundle as `%2F`, and `atob` on that throws. Base64 never contains
|
|
18
|
+
// A `%`, so this is a no-op on the plain payloads the other bundlers write.
|
|
19
|
+
const base64 = decodeURIComponent(dataUrl.slice(dataUrl.indexOf(',') + 1));
|
|
20
|
+
const bytes = Uint8Array.from(atob(base64), (character) => character.codePointAt(0) ?? 0);
|
|
21
|
+
// `compile` then `instantiate`, rather than `instantiate(bytes)` in one call: `WebAssembly.Module` is
|
|
22
|
+
// Declared as an EMPTY interface, so a `Uint8Array` satisfies it too and the one-call form resolves to
|
|
23
|
+
// The overload taking an already-compiled module -- whose result is a bare `Instance` with no
|
|
24
|
+
// `instance` property on it, which is TS2339 rather than anything about WebAssembly.
|
|
25
|
+
const compiled = await WebAssembly.compile(bytes);
|
|
26
|
+
const instance = await WebAssembly.instantiate(compiled);
|
|
27
|
+
const answer = instance.exports['answer'] as () => number;
|
|
28
|
+
return answer();
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import load from './module.wasm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Instantiates the sample WebAssembly module and calls its one export.
|
|
5
|
+
*
|
|
6
|
+
* The signature is the same on every bundler; the two lines above and below are not. A `.wasm` import
|
|
7
|
+
* yields something different under each of them -- a loader function here, bytes under esbuild, a
|
|
8
|
+
* `data:` URL under vite, webpack and parcel -- so this file is written per bundler and everything else
|
|
9
|
+
* in the plugin talks to `getWasmAnswer()`.
|
|
10
|
+
*
|
|
11
|
+
* `@rollup/plugin-wasm` replaces the import with a function that decodes the inlined base64 and
|
|
12
|
+
* instantiates it. The empty imports object is load-bearing: without an argument the plugin compiles
|
|
13
|
+
* rather than instantiates, and resolves to a module with no `exports` on it.
|
|
14
|
+
*/
|
|
15
|
+
export async function getWasmAnswer(): Promise<number> {
|
|
16
|
+
const { instance } = await load({});
|
|
17
|
+
const answer = instance.exports['answer'] as () => number;
|
|
18
|
+
return answer();
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import dataUrl from './module.wasm?url';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Instantiates the sample WebAssembly module and calls its one export.
|
|
5
|
+
*
|
|
6
|
+
* The signature is the same on every bundler; the two lines above and below are not. A `.wasm` import
|
|
7
|
+
* yields something different under each of them -- a `data:` URL here, bytes under esbuild, a loader
|
|
8
|
+
* function under rollup -- so this file is written per bundler and everything else in the plugin talks
|
|
9
|
+
* to `getWasmAnswer()`.
|
|
10
|
+
*
|
|
11
|
+
* Vite inlines the asset into `main.js` as a `data:` URL, which is decoded here rather than fetched:
|
|
12
|
+
* `atob` is synchronous and needs no network stack, and it works the same in Obsidian's desktop and
|
|
13
|
+
* mobile runtimes.
|
|
14
|
+
*/
|
|
15
|
+
export async function getWasmAnswer(): Promise<number> {
|
|
16
|
+
// Percent-DECODED before it is base64-decoded, because parcel writes its data URL with the payload
|
|
17
|
+
// Percent-encoded -- `/` reaches the bundle as `%2F`, and `atob` on that throws. Base64 never contains
|
|
18
|
+
// A `%`, so this is a no-op on the plain payloads the other bundlers write.
|
|
19
|
+
const base64 = decodeURIComponent(dataUrl.slice(dataUrl.indexOf(',') + 1));
|
|
20
|
+
const bytes = Uint8Array.from(atob(base64), (character) => character.codePointAt(0) ?? 0);
|
|
21
|
+
// `compile` then `instantiate`, rather than `instantiate(bytes)` in one call: `WebAssembly.Module` is
|
|
22
|
+
// Declared as an EMPTY interface, so a `Uint8Array` satisfies it too and the one-call form resolves to
|
|
23
|
+
// The overload taking an already-compiled module -- whose result is a bare `Instance` with no
|
|
24
|
+
// `instance` property on it, which is TS2339 rather than anything about WebAssembly.
|
|
25
|
+
const compiled = await WebAssembly.compile(bytes);
|
|
26
|
+
const instance = await WebAssembly.instantiate(compiled);
|
|
27
|
+
const answer = instance.exports['answer'] as () => number;
|
|
28
|
+
return answer();
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import dataUrl from './module.wasm';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Instantiates the sample WebAssembly module and calls its one export.
|
|
5
|
+
*
|
|
6
|
+
* The signature is the same on every bundler; the two lines above and below are not. A `.wasm` import
|
|
7
|
+
* yields something different under each of them -- a `data:` URL here, bytes under esbuild, a loader
|
|
8
|
+
* function under rollup -- so this file is written per bundler and everything else in the plugin talks
|
|
9
|
+
* to `getWasmAnswer()`.
|
|
10
|
+
*
|
|
11
|
+
* The `asset/inline` rule in `scripts/webpack.config.ts` carries the module inside `main.js` as a
|
|
12
|
+
* `data:` URL, which is decoded here rather than fetched: `atob` is synchronous and needs no network
|
|
13
|
+
* stack, and it works the same in Obsidian's desktop and mobile runtimes.
|
|
14
|
+
*/
|
|
15
|
+
export async function getWasmAnswer(): Promise<number> {
|
|
16
|
+
// Percent-DECODED before it is base64-decoded, because parcel writes its data URL with the payload
|
|
17
|
+
// Percent-encoded -- `/` reaches the bundle as `%2F`, and `atob` on that throws. Base64 never contains
|
|
18
|
+
// A `%`, so this is a no-op on the plain payloads the other bundlers write.
|
|
19
|
+
const base64 = decodeURIComponent(dataUrl.slice(dataUrl.indexOf(',') + 1));
|
|
20
|
+
const bytes = Uint8Array.from(atob(base64), (character) => character.codePointAt(0) ?? 0);
|
|
21
|
+
// `compile` then `instantiate`, rather than `instantiate(bytes)` in one call: `WebAssembly.Module` is
|
|
22
|
+
// Declared as an EMPTY interface, so a `Uint8Array` satisfies it too and the one-call form resolves to
|
|
23
|
+
// The overload taking an already-compiled module -- whose result is a bare `Instance` with no
|
|
24
|
+
// `instance` property on it, which is TS2339 rather than anything about WebAssembly.
|
|
25
|
+
const compiled = await WebAssembly.compile(bytes);
|
|
26
|
+
const instance = await WebAssembly.instantiate(compiled);
|
|
27
|
+
const answer = instance.exports['answer'] as () => number;
|
|
28
|
+
return answer();
|
|
29
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
;; The sample WebAssembly module this plugin ships, in text form.
|
|
2
|
+
;;
|
|
3
|
+
;; `module.wasm` beside this file is the 39 bytes it compiles to, and that binary is what `answer.ts`
|
|
4
|
+
;; imports. NOTHING IN THE BUILD READS THIS FILE -- it is here so the binary is not opaque. This is
|
|
5
|
+
;; what is inside it: one exported function taking nothing and returning the constant 42.
|
|
6
|
+
;;
|
|
7
|
+
;; Recompile after an edit, with wabt's `wat2wasm`:
|
|
8
|
+
;;
|
|
9
|
+
;; wat2wasm src/wasm/module.wat -o src/wasm/module.wasm
|
|
10
|
+
(module
|
|
11
|
+
(func (export "answer") (result i32)
|
|
12
|
+
i32.const 42))
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Plugin } from 'obsidian';
|
|
2
|
+
|
|
3
|
+
import { Notice } from 'obsidian';
|
|
4
|
+
|
|
5
|
+
import { getWasmAnswer } from './answer.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registers the command that calls into the sample WebAssembly module.
|
|
9
|
+
*
|
|
10
|
+
* This is not decoration, and deleting it does more than remove a command. A bundler tree-shakes an
|
|
11
|
+
* export nothing calls, so with no real call site the module drops out of `main.js` entirely -- and the
|
|
12
|
+
* build stays green while the whole WebAssembly integration is silently absent. Whatever replaces this
|
|
13
|
+
* sample, keep something in `src/` calling into the module.
|
|
14
|
+
*
|
|
15
|
+
* Bundler-independent on purpose: `answer.ts` beside it is written per bundler, and this file is what
|
|
16
|
+
* every preset's `src/plugin.ts` calls, so the per-bundler half stays one file.
|
|
17
|
+
*/
|
|
18
|
+
export function registerSampleWasmCommand(plugin: Plugin): void {
|
|
19
|
+
plugin.addCommand({
|
|
20
|
+
// `Command.callback` is typed `() => any`, so an async callback is not a misused promise -- and awaiting
|
|
21
|
+
// Here needs no `void`, which one preset's lint config bans and the other's does not.
|
|
22
|
+
callback: async () => {
|
|
23
|
+
await showWasmAnswer();
|
|
24
|
+
},
|
|
25
|
+
id: 'sample-wasm-answer',
|
|
26
|
+
name: 'Sample WASM answer'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function showWasmAnswer(): Promise<void> {
|
|
31
|
+
const answer = await getWasmAnswer();
|
|
32
|
+
new Notice(`WebAssembly says: ${String(answer)}`);
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Esbuild has no loader for `.wasm` of its own, and the ESM-integration plugin (`esbuild-plugin-wasm`)
|
|
2
|
+
// Cannot be used here: it emits a TOP-LEVEL `await`, which esbuild supports only for the `esm` output
|
|
3
|
+
// Format, and an Obsidian plugin is `cjs`. So the build turns on esbuild's built-in `binary` loader,
|
|
4
|
+
// Which inlines the file as base64 and hands the importing module its bytes.
|
|
5
|
+
declare module '*.wasm' {
|
|
6
|
+
// `Uint8Array<ArrayBuffer>` rather than a bare `Uint8Array`: that defaults to `ArrayBufferLike`, which
|
|
7
|
+
// Admits a `SharedArrayBuffer` and so is NOT assignable to `BufferSource` -- TS2345 at every
|
|
8
|
+
// `WebAssembly` call. esbuild's `binary` loader emits a plain `new Uint8Array(...)` over an ordinary
|
|
9
|
+
// Buffer, so the narrower type is also the true one.
|
|
10
|
+
const bytes: Uint8Array<ArrayBuffer>;
|
|
11
|
+
export default bytes;
|
|
12
|
+
}
|