/* * This file is part of the TYPO3 CMS project. * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 * of the License, or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * * The TYPO3 project - inspiring people to share! */ import r from"@typo3/core/event/regular-event.js";var a;(function(t){t.primary="typo3:filelist:resource:action:primary",t.primaryContextmenu="typo3:filelist:resource:action:primaryContextmenu",t.show="typo3:filelist:resource:action:show",t.rename="typo3:filelist:resource:action:rename",t.replace="typo3:filelist:resource:action:replace",t.select="typo3:filelist:resource:action:select",t.download="typo3:filelist:resource:action:download",t.updateOnlineMedia="typo3:filelist:resource:action:updateOnlineMedia"})(a||(a={}));var n;(function(t){t.elementSelector="[data-filelist-element]",t.actionSelector="[data-filelist-action]"})(n||(n={}));class o{static createResourceFromContextDataset(e){return{type:e.filecontextType,identifier:e.filecontextIdentifier,name:e.filecontextName,hasPreview:!1,uid:e.filecontextUid?parseInt(e.filecontextUid,10):null,metaUid:e.filecontextMetaUid?parseInt(e.filecontextMetaUid,10):null,url:e.filecontextUid?e.url:null,createdAt:e.filecontextCreatedAt?parseInt(e.filecontextCreatedAt,10):null,size:e.filecontextSize?parseInt(e.filecontextSize,10):null}}static getResourceForElement(e){return{type:e.dataset.filelistType,identifier:e.dataset.filelistIdentifier,name:e.dataset.filelistName,hasPreview:"filelistPreview"in e.dataset&&e.dataset.filelistPreview.trim()==="true",uid:e.dataset.filelistUid?parseInt(e.dataset.filelistUid,10):null,metaUid:e.dataset.filelistMetaUid?parseInt(e.dataset.filelistMetaUid,10):null,url:e.dataset.filelistUrl?e.dataset.filelistUrl:null,createdAt:e.dataset.filelistCreatedAt?parseInt(e.dataset.filelistCreatedAt,10):null,size:e.dataset.filelistSize?parseInt(e.dataset.filelistSize,10):null}}}class d{constructor(){new r("contextmenu",(e,l)=>{e.preventDefault(),e.stopImmediatePropagation();const i=this.getActionDetail(e,l);switch(i.action){case"primary":document.dispatchEvent(new CustomEvent(a.primaryContextmenu,{detail:i}));break;default:break}}).delegateTo(document,n.actionSelector),new r("click",(e,l)=>{e.preventDefault();const i=this.getActionDetail(e,l);switch(i.action){case"primary":document.dispatchEvent(new CustomEvent(a.primary,{detail:i}));break;case"show":document.dispatchEvent(new CustomEvent(a.show,{detail:i}));break;case"select":document.dispatchEvent(new CustomEvent(a.select,{detail:i}));break;case"rename":document.dispatchEvent(new CustomEvent(a.rename,{detail:i}));break;case"replace":document.dispatchEvent(new CustomEvent(a.replace,{detail:i}));break;case"download":document.dispatchEvent(new CustomEvent(a.download,{detail:i}));break;case"updateOnlineMedia":document.dispatchEvent(new CustomEvent(a.updateOnlineMedia,{detail:i}));break;default:break}}).delegateTo(document,n.actionSelector)}getActionDetail(e,l){const i=l.dataset.filelistAction,s=l.closest(n.elementSelector),c=o.getResourceForElement(s);return{event:e,trigger:l,action:i,resources:[c],url:l.dataset.filelistActionUrl??null,originalAction:null}}}var u=new d;export{a as FileListActionEvent,n as FileListActionSelector,o as FileListActionUtility,u as default};