rpg-westreiche/RPG/.obsidian/plugins/manual-sorting/main.js

2 lines
18 KiB
JavaScript
Raw Normal View History

2026-03-04 22:28:24 +01:00
let e=require(`obsidian`);var t=class e{static logLevel=`silent`;style;prefix;constructor(e,t){this.scope=e,this.color=t,this.style=`color: ${this.color}; background: #21202a; padding: 1px 5px; border-radius: 5px; font-family: consolas, monospace; font-size: 11px; border: 1px solid ${this.color}50;`,this.prefix=`%cMS|${this.scope}`}info=(...e)=>this.log(`log`,...e);warn=(...e)=>this.log(`warn`,...e);error=(...e)=>this.log(`error`,...e);infoCompact=(t,...n)=>{e.logLevel!==`silent`&&(console.groupCollapsed(this.prefix,this.style,t),console.log(...n),console.groupEnd())};log(t=`log`,...n){e.logLevel!==`silent`&&console[t](this.prefix,this.style,...n)}},n=class extends e.PluginSettingTab{constructor(e,t){super(e,t),this.plugin=t}display(){this.containerEl.empty(),new e.Setting(this.containerEl).setName(`New item placement`).setDesc(`Default new item placement.`).addDropdown(e=>e.addOption(`top`,`Top`).addOption(`bottom`,`Bottom`).setValue(this.plugin.settings.newItemPlacement).onChange(async e=>{this.plugin.settings.newItemPlacement=e,await this.plugin.saveSettings()})),new e.Setting(this.containerEl).setName(`Debug Mode`).setDesc(`Show debug logs in the console.`).addToggle(e=>e.setValue(this.plugin.settings.debugMode).onChange(async e=>{this.plugin.settings.debugMode=e,t.logLevel=e?`debug`:`silent`,await this.plugin.saveSettings()}))}},r=class extends e.Modal{constructor(t,n){super(t),this.setTitle(`Manual Sorting`),this.modalEl.addClass(`manual-sorting-modal`,`mod-form`);let r=this.contentEl.createEl(`div`);r.createEl(`p`,{text:`Reset custom order?`});let i=r.createEl(`div`,{cls:`modal-button-container`});new e.ButtonComponent(i).setButtonText(`Yep`).setCta().onClick(()=>{this.close(),n()}),new e.ButtonComponent(i).setButtonText(`Nope`).onClick(()=>this.close())}},i=class{log=new t(`DND-MANAGER`,`#a6ff00`);explorerEl;dragStartHandler=null;mouseDownHandler=null;mouseUpHandler=null;dragStartEventType=e.Platform.isMobile?`touchstart`:`dragstart`;dragEventType=e.Platform.isMobile?`touchmove`:`drag`;dropEventType=e.Platform.isMobile?`touchend`:`dragend`;rafId=0;folderExpandTimeout=null;pendingExpandFolder=null;scrollRafId=null;scrollZone=50;scrollSpeed=5;dropZonesActivationDelay=250;dropZonesActivationTimeout=null;dragZoneWidth=36;constructor(e){this.plugin=e}async enable(){this.explorerEl=await this.plugin.explorerManager.waitForExplorerElement(!0);let t=null,n=`before`;this.dragStartHandler=r=>{let i=r.target.closest(`.tree-item-self`);if(!i)return;let a=r instanceof DragEvent?r:r.touches[0],o=i.getBoundingClientRect().right-a.clientX;if(e.Platform.isMobile){if(o>this.dragZoneWidth)return;r.preventDefault()}this.log.info(`Drag started`);let s=this.explorerEl.getBoundingClientRect(),c=!1;this.explorerEl.dataset.dragActive=``,i.dataset.isBeingDragged=``;let l=new Set(this.plugin.getFileExplorerView().tree.selectedDoms),u=r=>{e.Platform.isMobile&&(r.stopPropagation(),r.preventDefault()),cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.log.info(`Dragging...`);let e=r instanceof DragEvent?r:r.touches[0];if(c=e.clientX<s.left||e.clientX>s.right||e.clientY<s.top||e.clientY>s.bottom,c){this.clearDropIndicators();return}this.collapseDraggedFolder(i),{futureSibling:t,dropPosition:n}=this.findDropTarget(e.clientY),this.updateDropIndicators(t,n),this.handleAutoScroll(e.clientY,s)})};i.addEventListener(this.dragEventType,u),i.addEventListener(this.dropEventType,()=>{if(this.log.info(`Item dropped`),cancelAnimationFrame(this.rafId),i.removeEventListener(this.dragEventType,u),this.clearDropIndicators(),this.stopAutoScroll(),delete this.explorerEl.dataset.dragActive,c)return;let e=i.dataset.path,r=this.plugin.getFileExplorerView().fileItems[e];if(!t)return;let a=t.querySelector(`.tree-item-self`)?.dataset.path??``,o=t.classList.contains(`temp-child`);this.plugin.orderManager.reconcileOrder(),l.has(r)?this.moveSelectedItems(l,a,o,n):this.moveItem(r,a,n,o),t=null},{once:!0})},this.mouseDownHandler=e=>{e.button===0&&(this.dropZonesActivationTimeout=window.setTimeout(()=>{this.explorerEl.dataset.dragActive===void 0&&
/* nosourcemap */