@hesprs/sync-engine-sdk 3.0.6 → 3.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.
@@ -1 +1 @@
1
- import e from"./render-progress.js";import t from"../utils/round-percent.js";import n from"../utils/to-error-message.js";import{Modal as r,Notice as i,Setting as a}from"obsidian";var o=class extends r{ctx;options;cleanupCallbacks=[];constructor(e,t){super(e.app),this.ctx=e,this.options=t}onOpen(){let{contentEl:e,options:{content:t,apply:n}}=this,{translate:r}=this.ctx;e.empty(),e.addClass(`markdown-rendered`),this.setTitle(r(`remoteMigration`)),typeof t==`string`?e.createEl(`p`,{cls:`whitespace-pre-wrap`,text:t}):e.append(t),e.createEl(`p`,{cls:`whitespace-pre-wrap`,text:r(`migrationDescription`)}),new a(e).addButton(e=>e.setButtonText(r(`cancel`)).onClick(this.close.bind(this))).addButton(e=>e.setButtonText(r(`toggleWithoutMigration`)).onClick(async()=>{await n(),this.close()})).addButton(e=>e.setButtonText(r(`startMigration`)).setCta().onClick(this.handleMigration))}handleMigration=()=>{let{on:n,translate:r,dispatch:i}=this.ctx;this.contentEl.empty(),this.setTitle(r(`migrationProcess`));let{left:o,right:s,bar:c}=e(this.contentEl,`mb-3`),l,u=e=>{l?.remove(),l=new a(this.contentEl).addButton(t=>t.setButtonText(r(e)).onClick(this.close.bind(this))).settingEl};u(`hide`),this.cleanupCallbacks.push(n(`migrationProgress`,({total:e,completed:n,current:a})=>{n===0&&i(`logGeneral`,`Migration started.`);let l=t(n,e);s.setText(`${n}/${e} ${r(`completed`)}`),a&&o.setText(a),c.setValue(l),l===100&&u(`done`)}),n(`migrationFailed`,()=>{i(`errorGeneral`,`Migration failed.`),o.setText(r(`migrationFailed`)),u(`done`)})),this.migrate()};migrate=async()=>{let{dispatch:e,requestSync:t,initializeSync:r,translate:a,memoryDB:o}=this.ctx;e(`migrationProgress`,{completed:0,current:a(`migrationPhase1Description`),total:3});let s=(await t(`migration`)).result;if(s===`cancelled`||s===`failed`){e(`migrationFailed`,`phase 1 failed`);return}e(`migrationProgress`,{completed:1,current:a(`migrationPhase2Description`),total:3});try{let{record:e,remoteFs:t}=r();await Promise.all([e.clear(),this.options.apply(),...o.getStore(`remoteContext20000`).entries().sort(([e],[t])=>t.length-e.length).map(([e])=>t.delete(e))])}catch(t){let r=n(t);new i(`${a(`migrationFailed`)}: ${r}`),e(`migrationFailed`,r);return}e(`migrationProgress`,{completed:2,current:a(`migrationPhase3Description`),total:3});let c=(await t(`migration`)).result;if(c===`cancelled`||c===`failed`){e(`migrationFailed`,`phase 3 failed`);return}e(`migrationProgress`,{completed:3,current:a(`completed`),total:3})};onClose(){this.cleanupCallbacks.splice(0).forEach(e=>e()),this.contentEl.empty()}};function s(e,{toggle:t,needMigration:n,content:r,apply:i}){let a=!1;t.onChange(s=>{if(a){a=!1;return}let c=async n=>{n?(a=!0,t.setValue(!s),new o(e,{apply:async()=>{await i(s),a=!0,t.setValue(s)},content:r(s)}).open()):await i(s)},l=n?.(s)??!0;l instanceof Promise?l.then(c):c(l)})}export{s as default};
1
+ import e from"./render-progress.js";import t from"../utils/round-percent.js";import n from"../utils/to-error-message.js";import{Modal as r,Notice as i,Setting as a}from"obsidian";var o=class extends r{ctx;options;cleanupCallbacks=[];constructor(e,t){super(e.app),this.ctx=e,this.options=t,this.contentEl.addClass(`markdown-rendered`),this.setTitle(e.translate(`remoteMigration`))}onOpen(){let{contentEl:e,options:{content:t,apply:n}}=this,{translate:r}=this.ctx;e.empty(),typeof t==`string`?e.createEl(`p`,{cls:`whitespace-pre-wrap`,text:t}):e.append(t),e.createEl(`p`,{cls:`whitespace-pre-wrap`,text:r(`migrationDescription`)}),new a(e).addButton(e=>e.setButtonText(r(`cancel`)).onClick(this.close.bind(this))).addButton(e=>e.setButtonText(r(`toggleWithoutMigration`)).onClick(async()=>{await n(),this.close()})).addButton(e=>e.setButtonText(r(`startMigration`)).setCta().onClick(this.handleMigration))}handleMigration=()=>{let{on:n,translate:r,dispatch:i}=this.ctx;this.contentEl.empty(),this.setTitle(r(`migrationProcess`));let{left:o,right:s,bar:c}=e(this.contentEl,`mb-3`),l,u=e=>{l?.remove(),l=new a(this.contentEl).addButton(t=>t.setButtonText(r(e)).onClick(this.close.bind(this))).settingEl};u(`hide`),this.cleanupCallbacks.push(n(`migrationProgress`,({total:e,completed:n,current:a})=>{n===0&&i(`logGeneral`,`Migration started.`);let l=t(n,e);s.setText(`${n}/${e} ${r(`completed`)}`),a&&o.setText(a),c.setValue(l),l===100&&u(`done`)}),n(`migrationFailed`,()=>{i(`errorGeneral`,`Migration failed.`),o.setText(r(`migrationFailed`)),u(`done`)})),this.migrate()};migrate=async()=>{let{dispatch:e,requestSync:t,initializeSync:r,translate:a,memoryDB:o}=this.ctx;e(`migrationProgress`,{completed:0,current:a(`migrationPhase1Description`),total:3});let s=(await t(`migration`)).result;if(s===`cancelled`||s===`failed`){e(`migrationFailed`,`phase 1 failed`);return}e(`migrationProgress`,{completed:1,current:a(`migrationPhase2Description`),total:3});try{let{record:e,remoteFs:t}=r();await Promise.all([e.clear(),this.options.apply(),...o.getStore(`remoteContext20000`).entries().sort(([e],[t])=>t.length-e.length).map(([e])=>t.delete(e))])}catch(t){let r=n(t);new i(`${a(`migrationFailed`)}: ${r}`),e(`migrationFailed`,r);return}e(`migrationProgress`,{completed:2,current:a(`migrationPhase3Description`),total:3});let c=(await t(`migration`)).result;if(c===`cancelled`||c===`failed`){e(`migrationFailed`,`phase 3 failed`);return}e(`migrationProgress`,{completed:3,current:a(`completed`),total:3})};onClose(){this.cleanupCallbacks.splice(0).forEach(e=>e()),this.contentEl.empty()}};function s(e,{toggle:t,needMigration:n,content:r,apply:i}){let a=!1;t.onChange(s=>{if(a){a=!1;return}let c=async n=>{n?(a=!0,t.setValue(!s),new o(e,{apply:async()=>{await i(s),a=!0,t.setValue(s)},content:r(s)}).open()):await i(s)},l=n?.(s)??!0;l instanceof Promise?l.then(c):c(l)})}export{s as default};
@@ -0,0 +1 @@
1
+ import"obsidian";function e(e,t){return t?Object.assign(e,t):e}export{e as s};
package/dist/transform.js CHANGED
@@ -1 +1 @@
1
- function e(){return{name:`sync-engine-transform`,renderChunk(e){let t=e.replaceAll(/^\s*import\s+(?<name>[A-Za-z_$][\w$]*)\s+from\s+(?<quote>['"])obsidian\k<quote>\s*;?\s*$/gmv,(e,t)=>`const ${t} = window.syncEngineApiBridge;`).replaceAll(/^\s*import\s+\*\s+as\s+(?<name>[A-Za-z_$][\w$]*)\s+from\s+(?<quote>['"])obsidian\k<quote>\s*;?\s*$/gmv,(e,t)=>`const ${t} = window.syncEngineApiBridge;`).replaceAll(/^\s*import\s+(?!(?:type\b|\*\s+as\s+))(?<name>.+?)\s+from\s+(?<quote>['"])obsidian\k<quote>\s*;?\s*$/gmv,(e,t)=>`const ${t} = window.syncEngineApiBridge;`);return t===e?void 0:{code:t}},tsdownConfig(e){e.deps??={};let{neverBundle:t}=e.deps;t!==!0&&(typeof t==`function`?e.deps.neverBundle=(e,n,r)=>e===`obsidian`||t(e,n,r):Array.isArray(t)?t.push(`obsidian`):t?e.deps.neverBundle=[t,`obsidian`]:e.deps.neverBundle=[`obsidian`])}}}export{e as default};
1
+ function e(){return{name:`sync-engine-transform`,renderChunk(e){let t=e.replaceAll(/^[ \t]*import\s+['"]obsidian['"]\s*;?[ \t]*$/gmu,``).replaceAll(/^\s*import\s+(?<name>[A-Za-z_$][\w$]*)\s+from\s+(?<quote>['"])obsidian\k<quote>\s*;?\s*$/gmu,(e,t)=>`const ${t} = window.syncEngineApiBridge;`).replaceAll(/^\s*import\s+\*\s+as\s+(?<name>[A-Za-z_$][\w$]*)\s+from\s+(?<quote>['"])obsidian\k<quote>\s*;?\s*$/gmu,(e,t)=>`const ${t} = window.syncEngineApiBridge;`).replaceAll(/^\s*import\s+(?!(?:type\b|\*\s+as\s+))(?<name>.+?)\s+from\s+(?<quote>['"])obsidian\k<quote>\s*;?\s*$/gmu,(e,t)=>`const ${t} = window.syncEngineApiBridge;`);return t===e?void 0:{code:t}},tsdownConfig(e){e.deps??={};let{neverBundle:t}=e.deps;t!==!0&&(typeof t==`function`?e.deps.neverBundle=(e,n,r)=>e===`obsidian`||t(e,n,r):Array.isArray(t)?t.push(`obsidian`):t?e.deps.neverBundle=[t,`obsidian`]:e.deps.neverBundle=[`obsidian`])}}}export{e as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hesprs/sync-engine-sdk",
3
- "version": "3.0.6",
3
+ "version": "3.1.0",
4
4
  "description": "Official SDK for developing modules targeting Sync Engine, the extensible Obsidian syncing plugin.",
5
5
  "keywords": [
6
6
  "obsidian-plugin",
@@ -42,10 +42,10 @@
42
42
  "provenance": true
43
43
  },
44
44
  "scripts": {
45
- "dev:plugin": "MODE=dev BUILD=plugin tsdown",
46
- "build:plugin": "BUILD=plugin tsdown",
47
- "dev": "MODE=dev PASS=dts tsdown && MODE=dev tsdown",
48
- "compile": "PASS=dts tsdown && tsdown",
45
+ "dev:plugin": "MODE=dev BUILD=plugin bun --bun tsdown",
46
+ "build:plugin": "BUILD=plugin bun --bun tsdown",
47
+ "dev": "MODE=dev PASS=dts bun --bun tsdown && MODE=dev bun --bun tsdown",
48
+ "compile": "PASS=dts bun --bun tsdown && bun --bun tsdown",
49
49
  "fix": "oxlint --silent --fix && oxfmt",
50
50
  "check": "tsc && oxlint && oxfmt --check",
51
51
  "tests": "bun --preload=./test/mocks test"