@umbraci/jsmind 0.10.15 → 0.10.18

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,9 +1,982 @@
1
1
  /**
2
- * @license BSD-3-Clause
3
- * @copyright 2014-2025 hizzgdev@163.com
4
- *
5
- * Project Home:
6
- * https://github.com/hizzgdev/jsmind/
7
- */
8
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jsMindHistory={})}(this,function(t){"use strict";"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(t){return this.slice(0,t.length)===t});const e=1,r=3,n=6,i=1,o=2,s=3,a=4;var c=function(){};let h="undefined"==typeof console?{level:c,log:c,debug:c,info:c,warn:c,error:c}:{level:function(t){h.debug=t>i?c:console.debug;h.info=t>o?c:console.info;h.warn=t>s?c:console.warn;h.error=t>a?c:console.error},log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};class u{static instanceName="";static preload=!1;constructor({jm:t,pluginOpt:e}){this.jm=t,this.options=e||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}var d=Object.getOwnPropertyNames,l=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty;function p(t,e){return function(r,n,i){return t(r,n,i)&&e(r,n,i)}}function y(t){return function(e,r,n){if(!e||!r||"object"!=typeof e||"object"!=typeof r)return t(e,r,n);var i=n.cache,o=i.get(e),s=i.get(r);if(o&&s)return o===r&&s===e;i.set(e,r),i.set(r,e);var a=t(e,r,n);return i.delete(e),i.delete(r),a}}function g(t){return d(t).concat(l(t))}var m=Object.hasOwn||function(t,e){return f.call(t,e)};function _(t,e){return t===e||!t&&!e&&t!=t&&e!=e}var b=Object.getOwnPropertyDescriptor,v=Object.keys;function x(t,e,r){var n=t.length;if(e.length!==n)return!1;for(;n-- >0;)if(!r.equals(t[n],e[n],n,n,t,e,r))return!1;return!0}function j(t,e){return _(t.getTime(),e.getTime())}function S(t,e){return t.name===e.name&&t.message===e.message&&t.cause===e.cause&&t.stack===e.stack}function w(t,e){return t===e}function k(t,e,r){var n=t.size;if(n!==e.size)return!1;if(!n)return!0;for(var i,o,s=new Array(n),a=t.entries(),c=0;(i=a.next())&&!i.done;){for(var h=e.entries(),u=!1,d=0;(o=h.next())&&!o.done;)if(s[d])d++;else{var l=i.value,f=o.value;if(r.equals(l[0],f[0],c,d,t,e,r)&&r.equals(l[1],f[1],l[0],f[0],t,e,r)){u=s[d]=!0;break}d++}if(!u)return!1;c++}return!0}var M=_;function O(t,e,r){var n=v(t),i=n.length;if(v(e).length!==i)return!1;for(;i-- >0;)if(!T(t,e,r,n[i]))return!1;return!0}function q(t,e,r){var n,i,o,s=g(t),a=s.length;if(g(e).length!==a)return!1;for(;a-- >0;){if(!T(t,e,r,n=s[a]))return!1;if(i=b(t,n),o=b(e,n),(i||o)&&(!i||!o||i.configurable!==o.configurable||i.enumerable!==o.enumerable||i.writable!==o.writable))return!1}return!0}function A(t,e){return _(t.valueOf(),e.valueOf())}function E(t,e){return t.source===e.source&&t.flags===e.flags}function C(t,e,r){var n=t.size;if(n!==e.size)return!1;if(!n)return!0;for(var i,o,s=new Array(n),a=t.values();(i=a.next())&&!i.done;){for(var c=e.values(),h=!1,u=0;(o=c.next())&&!o.done;){if(!s[u]&&r.equals(i.value,o.value,i.value,o.value,t,e,r)){h=s[u]=!0;break}u++}if(!h)return!1}return!0}function P(t,e){var r=t.length;if(e.length!==r)return!1;for(;r-- >0;)if(t[r]!==e[r])return!1;return!0}function N(t,e){return t.hostname===e.hostname&&t.pathname===e.pathname&&t.protocol===e.protocol&&t.port===e.port&&t.hash===e.hash&&t.username===e.username&&t.password===e.password}function T(t,e,r,n){return!("_owner"!==n&&"__o"!==n&&"__v"!==n||!t.$$typeof&&!e.$$typeof)||m(e,n)&&r.equals(t[n],e[n],n,n,t,e,r)}var D=Array.isArray,I="function"==typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView:null,F=Object.assign,z=Object.prototype.toString.call.bind(Object.prototype.toString);function K(t){var e=t.areArraysEqual,r=t.areDatesEqual,n=t.areErrorsEqual,i=t.areFunctionsEqual,o=t.areMapsEqual,s=t.areNumbersEqual,a=t.areObjectsEqual,c=t.arePrimitiveWrappersEqual,h=t.areRegExpsEqual,u=t.areSetsEqual,d=t.areTypedArraysEqual,l=t.areUrlsEqual,f=t.unknownTagComparators;return function(t,p,y){if(t===p)return!0;if(null==t||null==p)return!1;var g=typeof t;if(g!==typeof p)return!1;if("object"!==g)return"number"===g?s(t,p,y):"function"===g&&i(t,p,y);var m=t.constructor;if(m!==p.constructor)return!1;if(m===Object)return a(t,p,y);if(D(t))return e(t,p,y);if(null!=I&&I(t))return d(t,p,y);if(m===Date)return r(t,p,y);if(m===RegExp)return h(t,p,y);if(m===Map)return o(t,p,y);if(m===Set)return u(t,p,y);var _,b=z(t);if("[object Date]"===b)return r(t,p,y);if("[object RegExp]"===b)return h(t,p,y);if("[object Map]"===b)return o(t,p,y);if("[object Set]"===b)return u(t,p,y);if("[object Object]"===b)return"function"!=typeof t.then&&"function"!=typeof p.then&&a(t,p,y);if("[object URL]"===b)return l(t,p,y);if("[object Error]"===b)return n(t,p,y);if("[object Arguments]"===b)return a(t,p,y);if("[object Boolean]"===b||"[object Number]"===b||"[object String]"===b)return c(t,p,y);if(f){var v=f[b];if(!v){var x=null!=(_=t)?_[Symbol.toStringTag]:void 0;x&&(v=f[x])}if(v)return v(t,p,y)}return!1}}var R=B();function B(t){void 0===t&&(t={});var e,r=t.circular,n=void 0!==r&&r,i=t.createInternalComparator,o=t.createState,s=t.strict,a=void 0!==s&&s,c=function(t){var e=t.circular,r=t.createCustomConfig,n=t.strict,i={areArraysEqual:n?q:x,areDatesEqual:j,areErrorsEqual:S,areFunctionsEqual:w,areMapsEqual:n?p(k,q):k,areNumbersEqual:M,areObjectsEqual:n?q:O,arePrimitiveWrappersEqual:A,areRegExpsEqual:E,areSetsEqual:n?p(C,q):C,areTypedArraysEqual:n?q:P,areUrlsEqual:N,unknownTagComparators:void 0};if(r&&(i=F({},i,r(i))),e){var o=y(i.areArraysEqual),s=y(i.areMapsEqual),a=y(i.areObjectsEqual),c=y(i.areSetsEqual);i=F({},i,{areArraysEqual:o,areMapsEqual:s,areObjectsEqual:a,areSetsEqual:c})}return i}(t),h=K(c);return function(t){var e=t.circular,r=t.comparator,n=t.createState,i=t.equals,o=t.strict;if(n)return function(t,s){var a=n(),c=a.cache,h=void 0===c?e?new WeakMap:void 0:c,u=a.meta;return r(t,s,{cache:h,equals:i,meta:u,strict:o})};if(e)return function(t,e){return r(t,e,{cache:new WeakMap,equals:i,meta:void 0,strict:o})};var s={cache:void 0,equals:i,meta:void 0,strict:o};return function(t,e){return r(t,e,s)}}({circular:n,comparator:h,createState:o,equals:i?i(h):(e=h,function(t,r,n,i,o,s,a){return e(t,r,a)}),strict:a})}function H(t,e){const r=function(t){return(e=t)&&"object"==typeof e&&"data"in e?t.data:t;var e}(t),n=e&&Array.isArray(e.fields)?e.fields:["topic","data","id"],i=e&&e.idKey?e.idKey:"id",o=e&&e.childrenKey?e.childrenKey:"children",s=!e||!1!==e.includeStructure,a=new Map;return r&&r[i]&&function t(e,r,c){const h=function(t){const e={};i in t&&(e[i]=t[i]);const r=new Set([i,o,"direction","expanded","parentid","index","isroot"]);n.includes("data");for(const o of n)if("data"===o){const i={};let o=!1;for(const e in t)r.has(e)||n.includes(e)||(i[e]=t[e],o=!0);o&&(e.data=i)}else o in t&&o!==i&&(e[o]=t[o]);return e}(e),u=e[i];s&&(h.parentid=r||null,h.index="number"==typeof c?c:0),a.set(u,h);const d=e[o];d&&Array.isArray(d)&&d.forEach((e,r)=>t(e,u,r))}(r,null,0),a}function U(t,e){if(t===e)return!0;if(!t||!e)return!1;const r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(const n of r){const r=t[n],i=e[n];if(r===i)continue;if(r&&i&&"object"==typeof r&&"object"==typeof i){if(!R(r,i))return!1}else if(r!==i)return!1}return!0}function W(t,e){const r=[];if(!t||!e)return r;const n=new Set([...Object.keys(t),...Object.keys(e)]);n.delete("id");for(const i of n){const n=t[i],o=e[i];if(n===o)continue;(n&&o&&"object"==typeof n&&"object"==typeof o?!R(n,o):n!==o)&&r.push({key:i,before:n,after:o})}return r}function $(t){let e=!1,r=!1;for(const n of t)"parentid"===n.key&&(e=!0),"index"===n.key&&(r=!0);return{moved:e||r,parentChanged:e,orderChanged:r}}function J(t){const e=new Map;for(const[r,n]of t){const t=n.parentid;e.has(t)||e.set(t,[]),e.get(t).push({id:r,index:n.index})}for(const t of e.values())t.sort((t,e)=>t.index-e.index);return e}function Y(t,e,r){const n=new Set,i=new Map;e.forEach((t,e)=>i.set(t.id,e));const o=[],s=[];for(const e of t)i.has(e.id)&&(o.push(e.id),s.push(i.get(e.id)));if(o.length<=1)return n;const a=function(t){const e=t.slice(),r=[0];let n,i,o,s,a;const c=t.length;for(n=0;n<c;n++){const c=t[n];if(0!==c||0===n){if(i=r[r.length-1],t[i]<c){e[n]=i,r.push(n);continue}for(o=0,s=r.length-1;o<s;)a=o+s>>1,t[r[a]]<c?o=a+1:s=a;c<t[r[o]]&&(o>0&&(e[n]=r[o-1]),r[o]=n)}}for(o=r.length,s=r[o-1];o-- >0;)r[o]=s,s=e[s];return r}(s),c=new Set(a);return o.forEach((t,e)=>{c.has(e)||n.add(t)}),n}function V(t,e,r={}){const{fields:n,idKey:i,childrenKey:o,includeStructure:s=!0,maxSize:a=5e3,categorize:c=!1}=r,h=H(t,{fields:n,idKey:i,childrenKey:o,includeStructure:s}),u=H(e,{fields:n,idKey:i,childrenKey:o,includeStructure:s}),d=[],l=[],f=[];for(const[t,e]of u){if(!h.has(t)){d.push(e);continue}const r=h.get(t);if(!U(r,e)){const n=W(r,e);l.push({id:t,before:r,after:e,changes:n})}}for(const[t,e]of h)u.has(t)||f.push(e);let p=!1;const y=d.length+l.length+f.length;if(y>a){p=!0;const t=Math.max(0,a),e=Math.min(d.length,Math.floor(t*(d.length/y))),r=Math.min(l.length,Math.floor(t*(l.length/y))),n=Math.min(f.length,Math.max(0,t-e-r));d.length=e,l.length=r,f.length=n}if(c&&s){const t=function(t,e,r){const n=[],i=[],o=[],s=new Set,a=J(e),c=J(r);for(const[t,e]of c){const r=Y(a.get(t)||[],e);for(const t of r)s.add(t)}for(const e of t){const{id:t,before:r,after:a,changes:c}=e,h=$(c),u=h.parentChanged,d=!u&&h.orderChanged&&s.has(t);if(u||d){const e={moveType:u?"cross-parent":"reorder",parentChanged:h.parentChanged,orderChanged:h.orderChanged,fromParent:r.parentid,toParent:a.parentid,fromOrder:r.index,toOrder:a.index},i=c.filter(t=>"parentid"!==t.key&&"index"!==t.key);i.length>0?o.push({id:t,before:r,after:a,changes:i,moveInfo:e}):n.push({id:t,before:r,after:a,moveInfo:e})}else if(h.orderChanged){const e=c.filter(t=>"parentid"!==t.key&&"index"!==t.key);e.length>0&&i.push({id:t,before:r,after:a,changes:e})}else i.push({id:t,before:r,after:a,changes:c})}return{moved:n,modified:i,movedAndModified:o}}(l,h,u);return{created:d,updated:l,deleted:f,truncated:p,moved:t.moved,modified:t.modified,movedAndModified:t.movedAndModified}}return{created:d,updated:l,deleted:f,truncated:p}}B({strict:!0}),B({circular:!0}),B({circular:!0,strict:!0}),B({createInternalComparator:function(){return _}}),B({strict:!0,createInternalComparator:function(){return _}}),B({circular:!0,createInternalComparator:function(){return _}}),B({circular:!0,createInternalComparator:function(){return _},strict:!0});const L={enabled:!0,throttleMs:100,maxHistory:500,storageMode:"object",autoSwitchThreshold:0,keymap:{enabled:!1,redoUsesY:!1},detail:{enabled:!1},diff:{flat:!0,fields:void 0,maxSize:5e3}};class G extends u{static instanceName="historyPlugin";static preload=!0;constructor({jm:t,pluginOpt:e}){super({jm:t,pluginOpt:e}),this.options=function(t){const e=Object.assign({},L,t||{});return e.keymap||(e.keymap={enabled:!1,redoUsesY:!1}),e.detail||(e.detail={enabled:!1}),e.diff||(e.diff={flat:!0,fields:void 0,maxSize:5e3}),e}(e),this._mounted=!1,this._core=null,this._mountAPI(),this._initCore()}beforePluginDestroy(){h.debug("[history] beforePluginDestroy: clearing history stack"),this._core&&this._core.clear()}_initCore(){const t=this.jm,n=this.options;n.keymap&&n.keymap.enabled&&t.options&&t.options.shortcut&&this._injectShortcuts(t.options.shortcut,!!n.keymap.redoUsesY);const i=new Q(t,n);this._core=i,t.history&&(t.history.add=(t,e)=>i.add(t,e),t.history.pause=()=>i.pause(),t.history.resume=t=>i.resume(!!t),t.history.clear=()=>i.clear(),t.history.canBack=()=>i.canBack(),t.history.canForward=()=>i.canForward(),t.history.back=t=>i.back("number"==typeof t?t:1),t.history.forward=t=>i.forward("number"==typeof t?t:1),t.history.length=()=>i.length(),t.history.index=()=>i.index(),t.history.setMax=t=>i.setMax(t),t.history.setThrottle=t=>i.setThrottle(t),t.history.exportSnapshot=()=>i.exportSnapshot(),t.history.importSnapshot=(t,e)=>i.importSnapshot(t,e),t.history.getStack=()=>i.getStackMeta(),t.history.diff=(t,e,r)=>{const n=this.jm.options.fieldNames,i=n?.id||"id";return V(t,e,{fields:[n?.topic||"topic","data",i],idKey:i,childrenKey:n?.children||"children",...r})},this._listener=(t,n)=>{try{if(t===e&&n&&"data"in n){let t=null;const e=n.data&&n.data[0];if(e)if(e.data)if(Array.isArray(e.data)){const r=e.data.find(t=>t.isroot);t=r&&r.id}else t=e.data.id;else e.id&&(t=e.id);return void(t&&t!==i._lastRootId&&(h.debug("[history] root id changed, clearing stack and pausing"),i.clear(),i._lastRootId=t,setTimeout(()=>{try{h.debug("[history] adding bootstrap snapshot after show"),i._addNow&&i._addNow("bootstrap"),h.debug("[history] resuming history recording")}catch(t){h.warn("[history] failed to add bootstrap snapshot",t)}},100)))}t===r&&n&&n.evt&&i.add(n.evt,n)}catch(t){h.warn("[history] listener error",t)}},t.add_event_listener(this._listener))}_injectShortcuts(t,e){const r=[4186,8282],n=e?[4185,8281]:[5210,9306];t.handles.history_back=(t,e)=>{t.history&&t.history.back()&&(e.preventDefault(),e.stopPropagation&&e.stopPropagation())},t.handles.history_forward=(t,e)=>{t.history&&t.history.forward()&&(e.preventDefault(),e.stopPropagation&&e.stopPropagation())},t.mapping.history_back=r,t.mapping.history_forward=n}_mountAPI(){if(this._mounted)return;const t=this.jm,e={add:()=>{},pause:()=>{},resume:t=>{},clear:()=>{},canBack:()=>!1,canForward:()=>!1,back:t=>!1,forward:t=>!1,length:()=>0,index:()=>-1,setMax:t=>{},setThrottle:t=>{},exportSnapshot:()=>null,importSnapshot:(t,e)=>{},getStack:()=>({items:[],index:-1}),diff:(t,e,r)=>{const n=this.jm.options.fieldNames,i=n?.id||"id";return V(t,e,{fields:[n?.topic||"topic","data",i],idKey:i,childrenKey:n?.children||"children",...r})},getOptions:()=>Object.assign({},this.options)};Object.defineProperty(t,"history",{value:e,configurable:!0,enumerable:!1,writable:!1}),this._mounted=!0,h.info("[history] API mounted (preload).")}beforePluginRemove(){try{if(this._listener&&this.jm&&Array.isArray(this.jm.event_handles)){const t=this.jm.event_handles.indexOf(this._listener);t>=0&&this.jm.event_handles.splice(t,1)}this.jm&&Object.prototype.hasOwnProperty.call(this.jm,"history")&&delete this.jm.history,this._mounted=!1}catch(t){h.error("[history] remove failed:",t)}}beforePluginDestroy(){h.error("beforePluginDestroy"),this.beforePluginRemove()}}class Q{constructor(t,e){this.jm=t,this.options=e,this.enabled=!!e.enabled,this.maxHistory=Math.max(1,0|e.maxHistory),this.throttleMs=Math.max(0,0|e.throttleMs),this.storageMode=e.storageMode||"object",this.autoSwitchThreshold=Math.max(0,0|e.autoSwitchThreshold),this._history=[],this._idx=-1,this._paused=!1,this._lastAddAt=0,this._timer=0,this._pending=!1,this._pendingMeta=void 0,this._lastSig=null,this._lastRootId=null}add(t="manual",e){if(!this.enabled||this._paused)return;const r=Date.now()-this._lastAddAt;if(r>=this.throttleMs)return this._addNow(t,e),void(this._lastAddAt=Date.now());if(this._pending=!0,this._pendingMeta=e,this._timer)return;const n=Math.max(0,this.throttleMs-r);this._timer=setTimeout(()=>{this._timer=0,!this._paused&&this.enabled&&(this._addNow(t,this._pendingMeta),this._lastAddAt=Date.now()),this._pending=!1,this._pendingMeta=void 0},n)}pause(){this._paused=!0}resume(t=!1){this._paused=!1,t&&this._pending&&(clearTimeout(this._timer),this._timer=0,this._addNow("resume-flush",this._pendingMeta),this._lastAddAt=Date.now(),this._pending=!1,this._pendingMeta=void 0)}clear(){this._history=[],this._idx=-1,this._lastSig=null,this._notifyChange()}canBack(){return this._idx>0}canForward(){return this._idx>=0&&this._idx<this._history.length-1}back(t=1){if((!Number.isFinite(t)||t<=0)&&(t=1),this._idx-t<0)return!1;this._idx-=t;const e=this._applyIndex();return e&&this._notifyChange(),e}forward(t=1){if((!Number.isFinite(t)||t<=0)&&(t=1),this._idx+t>=this._history.length)return!1;this._idx+=t;const e=this._applyIndex();return e&&this._notifyChange(),e}length(){return this._history.length}index(){return this._idx}setMax(t){this.maxHistory=Math.max(1,0|t)}setThrottle(t){this.throttleMs=Math.max(0,0|t)}exportSnapshot(){return this._takeSnapshot()}importSnapshot(t,e){return this._applySnapshot(t,e)}getStackMeta(){return{items:this._history.slice(),index:this._idx}}_notifyChange(){try{this.jm.invoke_event_handle(n,{index:this._idx,length:this._history.length,canBack:this.canBack(),canForward:this.canForward()})}catch(t){h.warn("[history] failed to notify change",t)}}_addNow(t,e){const r=this._takeSnapshot();let n=this.storageMode;if(this.autoSwitchThreshold>0&&"object"===n){const t=this._countNodes(r);t>this.autoSwitchThreshold&&(n="string",h.debug(`[history] auto-switched to string mode (${t} nodes > ${this.autoSwitchThreshold})`))}let i=null;try{i=JSON.stringify(r)}catch{}if(!i||!this._lastSig||i!==this._lastSig){if(this._idx<this._history.length-1&&(this._history=this._history.slice(0,this._idx+1)),this._history.length>=this.maxHistory&&(this._history.shift(),this._idx=Math.max(-1,this._idx-1)),"string"===n)this._history.push(i);else{const t=this._deepFreeze(r);this._history.push(t)}this._idx=this._history.length-1,this._lastSig=i,this._notifyChange()}}_applyIndex(){const t=this._history[this._idx];if(!t)return!1;try{let e;if("string"==typeof t)e=JSON.parse(t),this._lastSig=t;else{e=this._cloneSnapshot(t);try{this._lastSig=JSON.stringify(t)}catch{this._lastSig=null}}return this._applySnapshot(e,{skipCentering:!0}),!0}catch(t){return h.error("[history] apply snapshot failed",t),!1}}_takeSnapshot(){return this.jm.get_data("node_tree")}_applySnapshot(t,e){const r=!(!e||!e.skipCentering);return this.jm.show(t,r),!0}_countNodes(t){let e=0;return function t(r){if(r&&(e++,r.children&&Array.isArray(r.children)))for(const e of r.children)t(e)}(t&&t.data?t.data:t),e}_deepFreeze(t){if(!t||"object"!=typeof t)return t;if(Object.isFrozen(t))return t;if(Object.freeze(t),Array.isArray(t))for(const e of t)this._deepFreeze(e);else for(const e of Object.keys(t))this._deepFreeze(t[e]);return t}_cloneSnapshot(t){if("function"==typeof structuredClone)try{return structuredClone(t)}catch{}try{return JSON.parse(JSON.stringify(t))}catch{return t}}}t.HistoryPlugin=G,t.default=G,Object.defineProperty(t,"__esModule",{value:!0})});
2
+ * @license BSD-3-Clause
3
+ * @copyright 2014-2025 hizzgdev@163.com
4
+ *
5
+ * Project Home:
6
+ * https://github.com/hizzgdev/jsmind/
7
+ */
8
+ !(function (t, e) {
9
+ 'object' == typeof exports && 'undefined' != typeof module
10
+ ? e(exports)
11
+ : 'function' == typeof define && define.amd
12
+ ? define(['exports'], e)
13
+ : e(((t = 'undefined' != typeof globalThis ? globalThis : t || self).jsMindHistory = {}));
14
+ })(this, function (t) {
15
+ 'use strict';
16
+ 'function' != typeof String.prototype.startsWith &&
17
+ (String.prototype.startsWith = function (t) {
18
+ return this.slice(0, t.length) === t;
19
+ });
20
+ const e = 1,
21
+ r = 3,
22
+ n = 6,
23
+ i = 1,
24
+ o = 2,
25
+ s = 3,
26
+ a = 4;
27
+ var c = function () {};
28
+ let u =
29
+ 'undefined' == typeof console
30
+ ? { level: c, log: c, debug: c, info: c, warn: c, error: c }
31
+ : {
32
+ level: function (t) {
33
+ u.debug = t > i ? c : console.debug;
34
+ u.info = t > o ? c : console.info;
35
+ u.warn = t > s ? c : console.warn;
36
+ u.error = t > a ? c : console.error;
37
+ },
38
+ log: console.log,
39
+ debug: console.debug,
40
+ info: console.info,
41
+ warn: console.warn,
42
+ error: console.error,
43
+ };
44
+ class h {
45
+ static instanceName = '';
46
+ static preload = !1;
47
+ constructor({ jm: t, pluginOpt: e }) {
48
+ (this.jm = t), (this.options = e || {});
49
+ }
50
+ beforePluginRemove() {}
51
+ beforePluginDestroy() {
52
+ this.beforePluginRemove();
53
+ }
54
+ }
55
+ var d = Object.getOwnPropertyNames,
56
+ l = Object.getOwnPropertySymbols,
57
+ f = Object.prototype.hasOwnProperty;
58
+ function p(t, e) {
59
+ return function (r, n, i) {
60
+ return t(r, n, i) && e(r, n, i);
61
+ };
62
+ }
63
+ function y(t) {
64
+ return function (e, r, n) {
65
+ if (!e || !r || 'object' != typeof e || 'object' != typeof r) return t(e, r, n);
66
+ var i = n.cache,
67
+ o = i.get(e),
68
+ s = i.get(r);
69
+ if (o && s) return o === r && s === e;
70
+ i.set(e, r), i.set(r, e);
71
+ var a = t(e, r, n);
72
+ return i.delete(e), i.delete(r), a;
73
+ };
74
+ }
75
+ function g(t) {
76
+ return d(t).concat(l(t));
77
+ }
78
+ var m =
79
+ Object.hasOwn ||
80
+ function (t, e) {
81
+ return f.call(t, e);
82
+ };
83
+ function _(t, e) {
84
+ return t === e || (!t && !e && t != t && e != e);
85
+ }
86
+ var b = Object.getOwnPropertyDescriptor,
87
+ v = Object.keys;
88
+ function x(t, e, r) {
89
+ var n = t.length;
90
+ if (e.length !== n) return !1;
91
+ for (; n-- > 0; ) if (!r.equals(t[n], e[n], n, n, t, e, r)) return !1;
92
+ return !0;
93
+ }
94
+ function j(t, e) {
95
+ return _(t.getTime(), e.getTime());
96
+ }
97
+ function S(t, e) {
98
+ return (
99
+ t.name === e.name &&
100
+ t.message === e.message &&
101
+ t.cause === e.cause &&
102
+ t.stack === e.stack
103
+ );
104
+ }
105
+ function w(t, e) {
106
+ return t === e;
107
+ }
108
+ function M(t, e, r) {
109
+ var n = t.size;
110
+ if (n !== e.size) return !1;
111
+ if (!n) return !0;
112
+ for (var i, o, s = new Array(n), a = t.entries(), c = 0; (i = a.next()) && !i.done; ) {
113
+ for (var u = e.entries(), h = !1, d = 0; (o = u.next()) && !o.done; )
114
+ if (s[d]) d++;
115
+ else {
116
+ var l = i.value,
117
+ f = o.value;
118
+ if (
119
+ r.equals(l[0], f[0], c, d, t, e, r) &&
120
+ r.equals(l[1], f[1], l[0], f[0], t, e, r)
121
+ ) {
122
+ h = s[d] = !0;
123
+ break;
124
+ }
125
+ d++;
126
+ }
127
+ if (!h) return !1;
128
+ c++;
129
+ }
130
+ return !0;
131
+ }
132
+ var k = _;
133
+ function O(t, e, r) {
134
+ var n = v(t),
135
+ i = n.length;
136
+ if (v(e).length !== i) return !1;
137
+ for (; i-- > 0; ) if (!T(t, e, r, n[i])) return !1;
138
+ return !0;
139
+ }
140
+ function A(t, e, r) {
141
+ var n,
142
+ i,
143
+ o,
144
+ s = g(t),
145
+ a = s.length;
146
+ if (g(e).length !== a) return !1;
147
+ for (; a-- > 0; ) {
148
+ if (!T(t, e, r, (n = s[a]))) return !1;
149
+ if (
150
+ ((i = b(t, n)),
151
+ (o = b(e, n)),
152
+ (i || o) &&
153
+ (!i ||
154
+ !o ||
155
+ i.configurable !== o.configurable ||
156
+ i.enumerable !== o.enumerable ||
157
+ i.writable !== o.writable))
158
+ )
159
+ return !1;
160
+ }
161
+ return !0;
162
+ }
163
+ function q(t, e) {
164
+ return _(t.valueOf(), e.valueOf());
165
+ }
166
+ function E(t, e) {
167
+ return t.source === e.source && t.flags === e.flags;
168
+ }
169
+ function C(t, e, r) {
170
+ var n = t.size;
171
+ if (n !== e.size) return !1;
172
+ if (!n) return !0;
173
+ for (var i, o, s = new Array(n), a = t.values(); (i = a.next()) && !i.done; ) {
174
+ for (var c = e.values(), u = !1, h = 0; (o = c.next()) && !o.done; ) {
175
+ if (!s[h] && r.equals(i.value, o.value, i.value, o.value, t, e, r)) {
176
+ u = s[h] = !0;
177
+ break;
178
+ }
179
+ h++;
180
+ }
181
+ if (!u) return !1;
182
+ }
183
+ return !0;
184
+ }
185
+ function P(t, e) {
186
+ var r = t.length;
187
+ if (e.length !== r) return !1;
188
+ for (; r-- > 0; ) if (t[r] !== e[r]) return !1;
189
+ return !0;
190
+ }
191
+ function N(t, e) {
192
+ return (
193
+ t.hostname === e.hostname &&
194
+ t.pathname === e.pathname &&
195
+ t.protocol === e.protocol &&
196
+ t.port === e.port &&
197
+ t.hash === e.hash &&
198
+ t.username === e.username &&
199
+ t.password === e.password
200
+ );
201
+ }
202
+ function T(t, e, r, n) {
203
+ return (
204
+ !(('_owner' !== n && '__o' !== n && '__v' !== n) || (!t.$$typeof && !e.$$typeof)) ||
205
+ (m(e, n) && r.equals(t[n], e[n], n, n, t, e, r))
206
+ );
207
+ }
208
+ var F = Array.isArray,
209
+ D = 'function' == typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView : null,
210
+ I = Object.assign,
211
+ K = Object.prototype.toString.call.bind(Object.prototype.toString);
212
+ function z(t) {
213
+ var e = t.areArraysEqual,
214
+ r = t.areDatesEqual,
215
+ n = t.areErrorsEqual,
216
+ i = t.areFunctionsEqual,
217
+ o = t.areMapsEqual,
218
+ s = t.areNumbersEqual,
219
+ a = t.areObjectsEqual,
220
+ c = t.arePrimitiveWrappersEqual,
221
+ u = t.areRegExpsEqual,
222
+ h = t.areSetsEqual,
223
+ d = t.areTypedArraysEqual,
224
+ l = t.areUrlsEqual,
225
+ f = t.unknownTagComparators;
226
+ return function (t, p, y) {
227
+ if (t === p) return !0;
228
+ if (null == t || null == p) return !1;
229
+ var g = typeof t;
230
+ if (g !== typeof p) return !1;
231
+ if ('object' !== g) return 'number' === g ? s(t, p, y) : 'function' === g && i(t, p, y);
232
+ var m = t.constructor;
233
+ if (m !== p.constructor) return !1;
234
+ if (m === Object) return a(t, p, y);
235
+ if (F(t)) return e(t, p, y);
236
+ if (null != D && D(t)) return d(t, p, y);
237
+ if (m === Date) return r(t, p, y);
238
+ if (m === RegExp) return u(t, p, y);
239
+ if (m === Map) return o(t, p, y);
240
+ if (m === Set) return h(t, p, y);
241
+ var _,
242
+ b = K(t);
243
+ if ('[object Date]' === b) return r(t, p, y);
244
+ if ('[object RegExp]' === b) return u(t, p, y);
245
+ if ('[object Map]' === b) return o(t, p, y);
246
+ if ('[object Set]' === b) return h(t, p, y);
247
+ if ('[object Object]' === b)
248
+ return 'function' != typeof t.then && 'function' != typeof p.then && a(t, p, y);
249
+ if ('[object URL]' === b) return l(t, p, y);
250
+ if ('[object Error]' === b) return n(t, p, y);
251
+ if ('[object Arguments]' === b) return a(t, p, y);
252
+ if ('[object Boolean]' === b || '[object Number]' === b || '[object String]' === b)
253
+ return c(t, p, y);
254
+ if (f) {
255
+ var v = f[b];
256
+ if (!v) {
257
+ var x = null != (_ = t) ? _[Symbol.toStringTag] : void 0;
258
+ x && (v = f[x]);
259
+ }
260
+ if (v) return v(t, p, y);
261
+ }
262
+ return !1;
263
+ };
264
+ }
265
+ var R = B();
266
+ function B(t) {
267
+ void 0 === t && (t = {});
268
+ var e,
269
+ r = t.circular,
270
+ n = void 0 !== r && r,
271
+ i = t.createInternalComparator,
272
+ o = t.createState,
273
+ s = t.strict,
274
+ a = void 0 !== s && s,
275
+ c = (function (t) {
276
+ var e = t.circular,
277
+ r = t.createCustomConfig,
278
+ n = t.strict,
279
+ i = {
280
+ areArraysEqual: n ? A : x,
281
+ areDatesEqual: j,
282
+ areErrorsEqual: S,
283
+ areFunctionsEqual: w,
284
+ areMapsEqual: n ? p(M, A) : M,
285
+ areNumbersEqual: k,
286
+ areObjectsEqual: n ? A : O,
287
+ arePrimitiveWrappersEqual: q,
288
+ areRegExpsEqual: E,
289
+ areSetsEqual: n ? p(C, A) : C,
290
+ areTypedArraysEqual: n ? A : P,
291
+ areUrlsEqual: N,
292
+ unknownTagComparators: void 0,
293
+ };
294
+ if ((r && (i = I({}, i, r(i))), e)) {
295
+ var o = y(i.areArraysEqual),
296
+ s = y(i.areMapsEqual),
297
+ a = y(i.areObjectsEqual),
298
+ c = y(i.areSetsEqual);
299
+ i = I({}, i, {
300
+ areArraysEqual: o,
301
+ areMapsEqual: s,
302
+ areObjectsEqual: a,
303
+ areSetsEqual: c,
304
+ });
305
+ }
306
+ return i;
307
+ })(t),
308
+ u = z(c);
309
+ return (function (t) {
310
+ var e = t.circular,
311
+ r = t.comparator,
312
+ n = t.createState,
313
+ i = t.equals,
314
+ o = t.strict;
315
+ if (n)
316
+ return function (t, s) {
317
+ var a = n(),
318
+ c = a.cache,
319
+ u = void 0 === c ? (e ? new WeakMap() : void 0) : c,
320
+ h = a.meta;
321
+ return r(t, s, { cache: u, equals: i, meta: h, strict: o });
322
+ };
323
+ if (e)
324
+ return function (t, e) {
325
+ return r(t, e, { cache: new WeakMap(), equals: i, meta: void 0, strict: o });
326
+ };
327
+ var s = { cache: void 0, equals: i, meta: void 0, strict: o };
328
+ return function (t, e) {
329
+ return r(t, e, s);
330
+ };
331
+ })({
332
+ circular: n,
333
+ comparator: u,
334
+ createState: o,
335
+ equals: i
336
+ ? i(u)
337
+ : ((e = u),
338
+ function (t, r, n, i, o, s, a) {
339
+ return e(t, r, a);
340
+ }),
341
+ strict: a,
342
+ });
343
+ }
344
+ function H(t, e) {
345
+ const r = (function (t) {
346
+ return (e = t) && 'object' == typeof e && 'data' in e ? t.data : t;
347
+ var e;
348
+ })(t),
349
+ n = e && Array.isArray(e.fields) ? e.fields : ['topic', 'data', 'id'],
350
+ i = e && Array.isArray(e.excludeFields) ? e.excludeFields : [],
351
+ o = e && e.idKey ? e.idKey : 'id',
352
+ s = e && e.childrenKey ? e.childrenKey : 'children',
353
+ a = !e || !1 !== e.includeStructure,
354
+ c = new Map();
355
+ return (
356
+ r &&
357
+ r[o] &&
358
+ (function t(e, r, u) {
359
+ const h = (function (t) {
360
+ const e = {};
361
+ o in t && (e[o] = t[o]);
362
+ const r = new Set([
363
+ o,
364
+ s,
365
+ 'direction',
366
+ 'expanded',
367
+ 'parentid',
368
+ 'index',
369
+ 'isroot',
370
+ ]),
371
+ a = new Set(i);
372
+ n.includes('data');
373
+ for (const i of n)
374
+ if ('data' === i) {
375
+ const i = {};
376
+ let o = !1;
377
+ for (const e in t)
378
+ r.has(e) ||
379
+ n.includes(e) ||
380
+ a.has(e) ||
381
+ ((i[e] = t[e]), (o = !0));
382
+ o && (e.data = i);
383
+ } else i in t && i !== o && !a.has(i) && (e[i] = t[i]);
384
+ return e;
385
+ })(e),
386
+ d = e[o];
387
+ a && ((h.parentid = r || null), (h.index = 'number' == typeof u ? u : 0)),
388
+ c.set(d, h);
389
+ const l = e[s];
390
+ l && Array.isArray(l) && l.forEach((e, r) => t(e, d, r));
391
+ })(r, null, 0),
392
+ c
393
+ );
394
+ }
395
+ function U(t, e) {
396
+ if (t === e) return !0;
397
+ if (!t || !e) return !1;
398
+ const r = Object.keys(t),
399
+ n = Object.keys(e);
400
+ if (r.length !== n.length) return !1;
401
+ for (const n of r) {
402
+ const r = t[n],
403
+ i = e[n];
404
+ if (r === i) continue;
405
+ if (r && i && 'object' == typeof r && 'object' == typeof i) {
406
+ if (!R(r, i)) return !1;
407
+ } else if (r !== i) return !1;
408
+ }
409
+ return !0;
410
+ }
411
+ function W(t, e) {
412
+ const r = [];
413
+ if (!t || !e) return r;
414
+ const n = new Set([...Object.keys(t), ...Object.keys(e)]);
415
+ n.delete('id');
416
+ for (const i of n) {
417
+ const n = t[i],
418
+ o = e[i];
419
+ if (n === o) continue;
420
+ (n && o && 'object' == typeof n && 'object' == typeof o ? !R(n, o) : n !== o) &&
421
+ r.push({ key: i, before: n, after: o });
422
+ }
423
+ return r;
424
+ }
425
+ function $(t) {
426
+ let e = !1,
427
+ r = !1;
428
+ for (const n of t) 'parentid' === n.key && (e = !0), 'index' === n.key && (r = !0);
429
+ return { moved: e || r, parentChanged: e, orderChanged: r };
430
+ }
431
+ function J(t) {
432
+ const e = new Map();
433
+ for (const [r, n] of t) {
434
+ const t = n.parentid;
435
+ e.has(t) || e.set(t, []), e.get(t).push({ id: r, index: n.index });
436
+ }
437
+ for (const t of e.values()) t.sort((t, e) => t.index - e.index);
438
+ return e;
439
+ }
440
+ function Y(t, e, r) {
441
+ const n = new Set(),
442
+ i = new Map();
443
+ e.forEach((t, e) => i.set(t.id, e));
444
+ const o = [],
445
+ s = [];
446
+ for (const e of t) i.has(e.id) && (o.push(e.id), s.push(i.get(e.id)));
447
+ if (o.length <= 1) return n;
448
+ const a = (function (t) {
449
+ const e = t.slice(),
450
+ r = [0];
451
+ let n, i, o, s, a;
452
+ const c = t.length;
453
+ for (n = 0; n < c; n++) {
454
+ const c = t[n];
455
+ if (0 !== c || 0 === n) {
456
+ if (((i = r[r.length - 1]), t[i] < c)) {
457
+ (e[n] = i), r.push(n);
458
+ continue;
459
+ }
460
+ for (o = 0, s = r.length - 1; o < s; )
461
+ (a = (o + s) >> 1), t[r[a]] < c ? (o = a + 1) : (s = a);
462
+ c < t[r[o]] && (o > 0 && (e[n] = r[o - 1]), (r[o] = n));
463
+ }
464
+ }
465
+ for (o = r.length, s = r[o - 1]; o-- > 0; ) (r[o] = s), (s = e[s]);
466
+ return r;
467
+ })(s),
468
+ c = new Set(a);
469
+ return (
470
+ o.forEach((t, e) => {
471
+ c.has(e) || n.add(t);
472
+ }),
473
+ n
474
+ );
475
+ }
476
+ function V(t, e, r = {}) {
477
+ const {
478
+ fields: n,
479
+ excludeFields: i,
480
+ idKey: o,
481
+ childrenKey: s,
482
+ includeStructure: a = !0,
483
+ maxSize: c = 5e3,
484
+ } = r,
485
+ u = H(t, {
486
+ fields: n,
487
+ excludeFields: i,
488
+ idKey: o,
489
+ childrenKey: s,
490
+ includeStructure: a,
491
+ }),
492
+ h = H(e, {
493
+ fields: n,
494
+ excludeFields: i,
495
+ idKey: o,
496
+ childrenKey: s,
497
+ includeStructure: a,
498
+ }),
499
+ d = [],
500
+ l = [],
501
+ f = [];
502
+ for (const [t, e] of h) {
503
+ if (!u.has(t)) {
504
+ d.push(e);
505
+ continue;
506
+ }
507
+ const r = u.get(t);
508
+ if (!U(r, e)) {
509
+ const n = W(r, e);
510
+ l.push({ id: t, before: r, after: e, changes: n });
511
+ }
512
+ }
513
+ for (const [t, e] of u) h.has(t) || f.push(e);
514
+ let p = !1;
515
+ const y = d.length + l.length + f.length;
516
+ if (y > c) {
517
+ p = !0;
518
+ const t = Math.max(0, c),
519
+ e = Math.min(d.length, Math.floor(t * (d.length / y))),
520
+ r = Math.min(l.length, Math.floor(t * (l.length / y))),
521
+ n = Math.min(f.length, Math.max(0, t - e - r));
522
+ (d.length = e), (l.length = r), (f.length = n);
523
+ }
524
+ if (a) {
525
+ const t = (function (t, e, r) {
526
+ const n = [],
527
+ i = [],
528
+ o = [],
529
+ s = new Set(),
530
+ a = J(e),
531
+ c = J(r);
532
+ for (const [t, e] of c) {
533
+ const r = Y(a.get(t) || [], e);
534
+ for (const t of r) s.add(t);
535
+ }
536
+ for (const e of t) {
537
+ const { id: t, before: r, after: a, changes: c } = e,
538
+ u = $(c),
539
+ h = u.parentChanged,
540
+ d = !h && u.orderChanged && s.has(t);
541
+ if (h || d) {
542
+ const e = {
543
+ moveType: h ? 'cross-parent' : 'reorder',
544
+ parentChanged: u.parentChanged,
545
+ orderChanged: u.orderChanged,
546
+ fromParent: r.parentid,
547
+ toParent: a.parentid,
548
+ fromOrder: r.index,
549
+ toOrder: a.index,
550
+ },
551
+ i = c.filter(t => 'parentid' !== t.key && 'index' !== t.key);
552
+ i.length > 0
553
+ ? o.push({ id: t, before: r, after: a, changes: i, moveInfo: e })
554
+ : n.push({ id: t, before: r, after: a, moveInfo: e });
555
+ } else if (u.orderChanged) {
556
+ const e = c.filter(t => 'parentid' !== t.key && 'index' !== t.key);
557
+ e.length > 0 && i.push({ id: t, before: r, after: a, changes: e });
558
+ } else i.push({ id: t, before: r, after: a, changes: c });
559
+ }
560
+ return { moved: n, modified: i, movedAndModified: o };
561
+ })(l, u, h);
562
+ return {
563
+ created: d,
564
+ deleted: f,
565
+ truncated: p,
566
+ moved: t.moved,
567
+ modified: t.modified,
568
+ movedAndModified: t.movedAndModified,
569
+ };
570
+ }
571
+ return {
572
+ created: d,
573
+ deleted: f,
574
+ moved: [],
575
+ modified: l,
576
+ movedAndModified: [],
577
+ truncated: p,
578
+ };
579
+ }
580
+ B({ strict: !0 }),
581
+ B({ circular: !0 }),
582
+ B({ circular: !0, strict: !0 }),
583
+ B({
584
+ createInternalComparator: function () {
585
+ return _;
586
+ },
587
+ }),
588
+ B({
589
+ strict: !0,
590
+ createInternalComparator: function () {
591
+ return _;
592
+ },
593
+ }),
594
+ B({
595
+ circular: !0,
596
+ createInternalComparator: function () {
597
+ return _;
598
+ },
599
+ }),
600
+ B({
601
+ circular: !0,
602
+ createInternalComparator: function () {
603
+ return _;
604
+ },
605
+ strict: !0,
606
+ });
607
+ const L = {
608
+ enabled: !0,
609
+ throttleMs: 100,
610
+ maxHistory: 500,
611
+ storageMode: 'object',
612
+ autoSwitchThreshold: 0,
613
+ keymap: { enabled: !1, redoUsesY: !1 },
614
+ detail: { enabled: !1 },
615
+ diff: { flat: !0, fields: void 0, maxSize: 5e3 },
616
+ };
617
+ class G extends h {
618
+ static instanceName = 'historyPlugin';
619
+ static preload = !0;
620
+ constructor({ jm: t, pluginOpt: e }) {
621
+ super({ jm: t, pluginOpt: e }),
622
+ (this.options = (function (t) {
623
+ const e = Object.assign({}, L, t || {});
624
+ return (
625
+ e.keymap || (e.keymap = { enabled: !1, redoUsesY: !1 }),
626
+ e.detail || (e.detail = { enabled: !1 }),
627
+ e.diff || (e.diff = { flat: !0, fields: void 0, maxSize: 5e3 }),
628
+ e
629
+ );
630
+ })(e)),
631
+ (this._mounted = !1),
632
+ (this._core = null),
633
+ this._mountAPI(),
634
+ this._initCore();
635
+ }
636
+ beforePluginDestroy() {
637
+ u.debug('[history] beforePluginDestroy: clearing history stack'),
638
+ this._core && this._core.clear();
639
+ }
640
+ _initCore() {
641
+ const t = this.jm,
642
+ n = this.options;
643
+ n.keymap &&
644
+ n.keymap.enabled &&
645
+ t.options &&
646
+ t.options.shortcut &&
647
+ this._injectShortcuts(t.options.shortcut, !!n.keymap.redoUsesY);
648
+ const i = new Q(t, n);
649
+ (this._core = i),
650
+ t.history &&
651
+ ((t.history.add = (t, e) => i.add(t, e)),
652
+ (t.history.pause = () => i.pause()),
653
+ (t.history.resume = t => i.resume(!!t)),
654
+ (t.history.clear = () => i.clear()),
655
+ (t.history.canBack = () => i.canBack()),
656
+ (t.history.canForward = () => i.canForward()),
657
+ (t.history.back = t => i.back('number' == typeof t ? t : 1)),
658
+ (t.history.forward = t => i.forward('number' == typeof t ? t : 1)),
659
+ (t.history.length = () => i.length()),
660
+ (t.history.index = () => i.index()),
661
+ (t.history.setMax = t => i.setMax(t)),
662
+ (t.history.setThrottle = t => i.setThrottle(t)),
663
+ (t.history.exportSnapshot = () => i.exportSnapshot()),
664
+ (t.history.importSnapshot = (t, e) => i.importSnapshot(t, e)),
665
+ (t.history.getStack = () => i.getStackMeta()),
666
+ (t.history.diff = (t, e, r) => {
667
+ const n = this.jm.options.fieldNames,
668
+ i = n?.id || 'id';
669
+ return V(t, e, {
670
+ fields: [n?.topic || 'topic', 'data', i],
671
+ idKey: i,
672
+ childrenKey: n?.children || 'children',
673
+ ...r,
674
+ });
675
+ }),
676
+ (this._listener = (t, n) => {
677
+ try {
678
+ if (t === e && n && 'data' in n) {
679
+ let t = null;
680
+ const e = n.data && n.data[0];
681
+ if (e)
682
+ if (e.data)
683
+ if (Array.isArray(e.data)) {
684
+ const r = e.data.find(t => t.isroot);
685
+ t = r && r.id;
686
+ } else t = e.data.id;
687
+ else e.id && (t = e.id);
688
+ return void (
689
+ t &&
690
+ t !== i._lastRootId &&
691
+ (u.debug(
692
+ '[history] root id changed, clearing stack and pausing'
693
+ ),
694
+ i.clear(),
695
+ (i._lastRootId = t),
696
+ setTimeout(() => {
697
+ try {
698
+ u.debug(
699
+ '[history] adding bootstrap snapshot after show'
700
+ ),
701
+ i._addNow && i._addNow('bootstrap'),
702
+ u.debug('[history] resuming history recording');
703
+ } catch (t) {
704
+ u.warn('[history] failed to add bootstrap snapshot', t);
705
+ }
706
+ }, 100))
707
+ );
708
+ }
709
+ t === r && n && n.evt && i.add(n.evt, n);
710
+ } catch (t) {
711
+ u.warn('[history] listener error', t);
712
+ }
713
+ }),
714
+ t.add_event_listener(this._listener));
715
+ }
716
+ _injectShortcuts(t, e) {
717
+ const r = [4186, 8282],
718
+ n = e ? [4185, 8281] : [5210, 9306];
719
+ (t.handles.history_back = (t, e) => {
720
+ t.history &&
721
+ t.history.back() &&
722
+ (e.preventDefault(), e.stopPropagation && e.stopPropagation());
723
+ }),
724
+ (t.handles.history_forward = (t, e) => {
725
+ t.history &&
726
+ t.history.forward() &&
727
+ (e.preventDefault(), e.stopPropagation && e.stopPropagation());
728
+ }),
729
+ (t.mapping.history_back = r),
730
+ (t.mapping.history_forward = n);
731
+ }
732
+ _mountAPI() {
733
+ if (this._mounted) return;
734
+ const t = this.jm,
735
+ e = {
736
+ add: () => {},
737
+ pause: () => {},
738
+ resume: t => {},
739
+ clear: () => {},
740
+ canBack: () => !1,
741
+ canForward: () => !1,
742
+ back: t => !1,
743
+ forward: t => !1,
744
+ length: () => 0,
745
+ index: () => -1,
746
+ setMax: t => {},
747
+ setThrottle: t => {},
748
+ exportSnapshot: () => null,
749
+ importSnapshot: (t, e) => {},
750
+ getStack: () => ({ items: [], index: -1 }),
751
+ diff: (t, e, r) => {
752
+ const n = this.jm.options.fieldNames,
753
+ i = n?.id || 'id';
754
+ return V(t, e, {
755
+ fields: [n?.topic || 'topic', 'data', i],
756
+ idKey: i,
757
+ childrenKey: n?.children || 'children',
758
+ ...r,
759
+ });
760
+ },
761
+ getOptions: () => Object.assign({}, this.options),
762
+ };
763
+ Object.defineProperty(t, 'history', {
764
+ value: e,
765
+ configurable: !0,
766
+ enumerable: !1,
767
+ writable: !1,
768
+ }),
769
+ (this._mounted = !0),
770
+ u.info('[history] API mounted (preload).');
771
+ }
772
+ beforePluginRemove() {
773
+ try {
774
+ if (this._listener && this.jm && Array.isArray(this.jm.event_handles)) {
775
+ const t = this.jm.event_handles.indexOf(this._listener);
776
+ t >= 0 && this.jm.event_handles.splice(t, 1);
777
+ }
778
+ this.jm &&
779
+ Object.prototype.hasOwnProperty.call(this.jm, 'history') &&
780
+ delete this.jm.history,
781
+ (this._mounted = !1);
782
+ } catch (t) {
783
+ u.error('[history] remove failed:', t);
784
+ }
785
+ }
786
+ beforePluginDestroy() {
787
+ u.error('beforePluginDestroy'), this.beforePluginRemove();
788
+ }
789
+ }
790
+ class Q {
791
+ constructor(t, e) {
792
+ (this.jm = t),
793
+ (this.options = e),
794
+ (this.enabled = !!e.enabled),
795
+ (this.maxHistory = Math.max(1, 0 | e.maxHistory)),
796
+ (this.throttleMs = Math.max(0, 0 | e.throttleMs)),
797
+ (this.storageMode = e.storageMode || 'object'),
798
+ (this.autoSwitchThreshold = Math.max(0, 0 | e.autoSwitchThreshold)),
799
+ (this._history = []),
800
+ (this._idx = -1),
801
+ (this._paused = !1),
802
+ (this._lastAddAt = 0),
803
+ (this._timer = 0),
804
+ (this._pending = !1),
805
+ (this._pendingMeta = void 0),
806
+ (this._lastSig = null),
807
+ (this._lastRootId = null);
808
+ }
809
+ add(t = 'manual', e) {
810
+ if (!this.enabled || this._paused) return;
811
+ const r = Date.now() - this._lastAddAt;
812
+ if (r >= this.throttleMs)
813
+ return this._addNow(t, e), void (this._lastAddAt = Date.now());
814
+ if (((this._pending = !0), (this._pendingMeta = e), this._timer)) return;
815
+ const n = Math.max(0, this.throttleMs - r);
816
+ this._timer = setTimeout(() => {
817
+ (this._timer = 0),
818
+ !this._paused &&
819
+ this.enabled &&
820
+ (this._addNow(t, this._pendingMeta), (this._lastAddAt = Date.now())),
821
+ (this._pending = !1),
822
+ (this._pendingMeta = void 0);
823
+ }, n);
824
+ }
825
+ pause() {
826
+ this._paused = !0;
827
+ }
828
+ resume(t = !1) {
829
+ (this._paused = !1),
830
+ t &&
831
+ this._pending &&
832
+ (clearTimeout(this._timer),
833
+ (this._timer = 0),
834
+ this._addNow('resume-flush', this._pendingMeta),
835
+ (this._lastAddAt = Date.now()),
836
+ (this._pending = !1),
837
+ (this._pendingMeta = void 0));
838
+ }
839
+ clear() {
840
+ (this._history = []), (this._idx = -1), (this._lastSig = null), this._notifyChange();
841
+ }
842
+ canBack() {
843
+ return this._idx > 0;
844
+ }
845
+ canForward() {
846
+ return this._idx >= 0 && this._idx < this._history.length - 1;
847
+ }
848
+ back(t = 1) {
849
+ if (((!Number.isFinite(t) || t <= 0) && (t = 1), this._idx - t < 0)) return !1;
850
+ this._idx -= t;
851
+ const e = this._applyIndex();
852
+ return e && this._notifyChange(), e;
853
+ }
854
+ forward(t = 1) {
855
+ if (((!Number.isFinite(t) || t <= 0) && (t = 1), this._idx + t >= this._history.length))
856
+ return !1;
857
+ this._idx += t;
858
+ const e = this._applyIndex();
859
+ return e && this._notifyChange(), e;
860
+ }
861
+ length() {
862
+ return this._history.length;
863
+ }
864
+ index() {
865
+ return this._idx;
866
+ }
867
+ setMax(t) {
868
+ this.maxHistory = Math.max(1, 0 | t);
869
+ }
870
+ setThrottle(t) {
871
+ this.throttleMs = Math.max(0, 0 | t);
872
+ }
873
+ exportSnapshot() {
874
+ return this._takeSnapshot();
875
+ }
876
+ importSnapshot(t, e) {
877
+ return this._applySnapshot(t, e);
878
+ }
879
+ getStackMeta() {
880
+ return { items: this._history.slice(), index: this._idx };
881
+ }
882
+ _notifyChange() {
883
+ try {
884
+ this.jm.invoke_event_handle(n, {
885
+ index: this._idx,
886
+ length: this._history.length,
887
+ canBack: this.canBack(),
888
+ canForward: this.canForward(),
889
+ });
890
+ } catch (t) {
891
+ u.warn('[history] failed to notify change', t);
892
+ }
893
+ }
894
+ _addNow(t, e) {
895
+ const r = this._takeSnapshot();
896
+ let n = this.storageMode;
897
+ if (this.autoSwitchThreshold > 0 && 'object' === n) {
898
+ const t = this._countNodes(r);
899
+ t > this.autoSwitchThreshold &&
900
+ ((n = 'string'),
901
+ u.debug(
902
+ `[history] auto-switched to string mode (${t} nodes > ${this.autoSwitchThreshold})`
903
+ ));
904
+ }
905
+ let i = null;
906
+ try {
907
+ i = JSON.stringify(r);
908
+ } catch {}
909
+ if (!i || !this._lastSig || i !== this._lastSig) {
910
+ if (
911
+ (this._idx < this._history.length - 1 &&
912
+ (this._history = this._history.slice(0, this._idx + 1)),
913
+ this._history.length >= this.maxHistory &&
914
+ (this._history.shift(), (this._idx = Math.max(-1, this._idx - 1))),
915
+ 'string' === n)
916
+ )
917
+ this._history.push(i);
918
+ else {
919
+ const t = this._deepFreeze(r);
920
+ this._history.push(t);
921
+ }
922
+ (this._idx = this._history.length - 1), (this._lastSig = i), this._notifyChange();
923
+ }
924
+ }
925
+ _applyIndex() {
926
+ const t = this._history[this._idx];
927
+ if (!t) return !1;
928
+ try {
929
+ let e;
930
+ if ('string' == typeof t) (e = JSON.parse(t)), (this._lastSig = t);
931
+ else {
932
+ e = this._cloneSnapshot(t);
933
+ try {
934
+ this._lastSig = JSON.stringify(t);
935
+ } catch {
936
+ this._lastSig = null;
937
+ }
938
+ }
939
+ return this._applySnapshot(e, { skipCentering: !0 }), !0;
940
+ } catch (t) {
941
+ return u.error('[history] apply snapshot failed', t), !1;
942
+ }
943
+ }
944
+ _takeSnapshot() {
945
+ return this.jm.get_data('node_tree');
946
+ }
947
+ _applySnapshot(t, e) {
948
+ const r = !(!e || !e.skipCentering);
949
+ return this.jm.show(t, r), !0;
950
+ }
951
+ _countNodes(t) {
952
+ let e = 0;
953
+ return (
954
+ (function t(r) {
955
+ if (r && (e++, r.children && Array.isArray(r.children)))
956
+ for (const e of r.children) t(e);
957
+ })(t && t.data ? t.data : t),
958
+ e
959
+ );
960
+ }
961
+ _deepFreeze(t) {
962
+ if (!t || 'object' != typeof t) return t;
963
+ if (Object.isFrozen(t)) return t;
964
+ if ((Object.freeze(t), Array.isArray(t))) for (const e of t) this._deepFreeze(e);
965
+ else for (const e of Object.keys(t)) this._deepFreeze(t[e]);
966
+ return t;
967
+ }
968
+ _cloneSnapshot(t) {
969
+ if ('function' == typeof structuredClone)
970
+ try {
971
+ return structuredClone(t);
972
+ } catch {}
973
+ try {
974
+ return JSON.parse(JSON.stringify(t));
975
+ } catch {
976
+ return t;
977
+ }
978
+ }
979
+ }
980
+ (t.HistoryPlugin = G), (t.default = G), Object.defineProperty(t, '__esModule', { value: !0 });
981
+ });
9
982
  //# sourceMappingURL=jsmind.history.js.map