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