polotno 2.2.3 → 2.2.4

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/model/history.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,o,r){void 0===r&&(r=o);var a=Object.getOwnPropertyDescriptor(t,o);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,r,a)}:function(e,t,o,r){void 0===r&&(r=o),e[r]=t[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&__createBinding(t,e,o);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UndoManager=void 0;const mobx_state_tree_1=require("mobx-state-tree"),deep_equal_1=require("../utils/deep-equal"),jsonpatch=__importStar(require("fast-json-patch"));Object.assign(mobx_state_tree_1.types),exports.UndoManager=mobx_state_tree_1.types.model("UndoManager",{history:mobx_state_tree_1.types.array(mobx_state_tree_1.types.frozen()),undoIdx:-1,targetPath:""}).views((e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}}))).actions((e=>{let t,o,r=!1,a=null,n=0,s=0;const i=()=>s>0;function d(){const e=(0,mobx_state_tree_1.getSnapshot)(t);return{pages:e.pages,width:e.width,height:e.height}}function u(e){const o=(0,mobx_state_tree_1.getSnapshot)(t.pages),r=jsonpatch.compare(o,e.pages);(0,mobx_state_tree_1.applyPatch)(t.pages,r),t.setSize(e.width,e.height)}return{startTransaction(){s++},endTransaction(e){s--,e||this.requestAddState(d())},async ignore(t,o=!1,r=!1){r&&await new Promise((e=>setTimeout(e,10))),n&&e.addUndoState();let a=i();e.startTransaction();let d=s;try{await t()}catch(e){setTimeout((()=>{throw e}))}const u=d!==s,c=!u;e.endTransaction(c),o||a||e.replaceState(),u||(clearTimeout(n),n=0)},async transaction(t){await e.ignore(t,!0),this.addUndoState()},requestAddState(e){a=e,n||i()||(r?r=!1:n=setTimeout((()=>{n=0,clearTimeout(n),i()||this.addUndoState()}),100))},addUndoState(){if(r)return void(r=!1);const t=e.history[e.undoIdx];!(0,deep_equal_1.deepEqual)(a,t)&&(clearTimeout(n),n=0,e.history.splice(e.undoIdx+1),e.history.push(a),e.undoIdx=e.history.length-1)},afterCreate(){if(t=(0,mobx_state_tree_1.resolvePath)(e,".."),!t)throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");o=(0,mobx_state_tree_1.onSnapshot)(t,(()=>{this.requestAddState(d())})),0===e.history.length&&this.requestAddState(d())},clear(){clearTimeout(n),n=0,e.history.splice(0,e.history.length),e.undoIdx=-1,e.addUndoState(d())},beforeDestroy(){o()},undo(){n&&this.addUndoState(),e.canUndo?(e.undoIdx--,r=!0,u(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){n&&this.addUndoState(),e.canRedo?(e.undoIdx++,r=!0,u(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=d()}}})),exports.default=exports.UndoManager;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UndoManager=void 0;const mobx_state_tree_1=require("mobx-state-tree"),deep_equal_1=require("../utils/deep-equal");Object.assign(mobx_state_tree_1.types),exports.UndoManager=mobx_state_tree_1.types.model("UndoManager",{history:mobx_state_tree_1.types.array(mobx_state_tree_1.types.frozen()),undoIdx:-1,targetPath:""}).views((e=>({get canUndo(){return e.undoIdx>0},get canRedo(){return e.undoIdx<e.history.length-1}}))).actions((e=>{let t,o,a=!1,r=null,n=0,s=0;const d=()=>s>0;function i(){const e=(0,mobx_state_tree_1.getSnapshot)(t);return{pages:e.pages,width:e.width,height:e.height}}function h(e){(0,mobx_state_tree_1.applySnapshot)(t.pages,e.pages),t.setSize(e.width,e.height)}return{startTransaction(){s++},endTransaction(e){s--,e||this.requestAddState(i())},async ignore(t,o=!1,a=!1){a&&await new Promise((e=>setTimeout(e,10))),n&&e.addUndoState();let r=d();e.startTransaction();let i=s;try{await t()}catch(e){setTimeout((()=>{throw e}))}const h=i!==s,u=!h;e.endTransaction(u),o||r||e.replaceState(),h||(clearTimeout(n),n=0)},async transaction(t){await e.ignore(t,!0),this.addUndoState()},requestAddState(e){r=e,n||d()||(a?a=!1:n=setTimeout((()=>{n=0,clearTimeout(n),d()||this.addUndoState()}),100))},addUndoState(){if(a)return void(a=!1);const t=e.history[e.undoIdx];!(0,deep_equal_1.deepEqual)(r,t)&&(clearTimeout(n),n=0,e.history.splice(e.undoIdx+1),e.history.push(r),e.undoIdx=e.history.length-1)},afterCreate(){if(t=(0,mobx_state_tree_1.resolvePath)(e,".."),!t)throw new Error("Failed to find target store for UndoManager. Please provide `targetPath` property, or a `targetStore` in the environment");o=(0,mobx_state_tree_1.onSnapshot)(t,(()=>{this.requestAddState(i())})),0===e.history.length&&this.requestAddState(i())},clear(){clearTimeout(n),n=0,e.history.splice(0,e.history.length),e.undoIdx=-1,e.addUndoState(i())},beforeDestroy(){o()},undo(){n&&this.addUndoState(),e.canUndo?(e.undoIdx--,a=!0,h(e.history[e.undoIdx])):console.warn("No undo history. Please check `store.history.canUndo` before calling undo action.")},redo(){n&&this.addUndoState(),e.canRedo?(e.undoIdx++,a=!0,h(e.history[e.undoIdx])):console.warn("No redo history. Please check `store.history.canRedo` before calling redo action.")},replaceState(){e.history[e.undoIdx]=i()}}})),exports.default=exports.UndoManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polotno",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Design Editor Framework",
5
5
  "author": "Anton Lavrenov",
6
6
  "keywords": [