@umbraci/jsmind 0.10.15 → 0.10.17

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.
@@ -5,5 +5,5 @@
5
5
  * Project Home:
6
6
  * https://github.com/hizzgdev/jsmind/
7
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;
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 A(t,e){return m(t.valueOf(),e.valueOf())}function q(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 K(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 z=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:A,areRegExpsEqual:q,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=K(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(!z(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?!z(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}=r,h=B(t,{fields:n,idKey:i,childrenKey:o,includeStructure:s}),c=B(e,{fields:n,idKey:i,childrenKey:o,includeStructure:s}),u=[],d=[],l=[];for(const[t,e]of c){if(!h.has(t)){u.push(e);continue}const r=h.get(t);if(!H(r,e)){const n=U(r,e);d.push({id:t,before:r,after:e,changes:n})}}for(const[t,e]of h)c.has(t)||l.push(e);let f=!1;const p=u.length+d.length+l.length;if(p>a){f=!0;const t=Math.max(0,a),e=Math.min(u.length,Math.floor(t*(u.length/p))),r=Math.min(d.length,Math.floor(t*(d.length/p))),n=Math.min(l.length,Math.max(0,t-e-r));u.length=e,d.length=r,l.length=n}if(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}}(d,h,c);return{created:u,deleted:l,truncated:f,moved:t.moved,modified:t.modified,movedAndModified:t.movedAndModified}}return{created:u,deleted:l,moved:[],modified:d,movedAndModified:[],truncated:f}}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;
9
9
  //# sourceMappingURL=jsmind.history.js.map