gantt-source_management 3.37.5 → 3.37.8

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,26 +1,798 @@
1
- /**
2
- * TimelinePointer plugin
3
- *
4
- * @copyright NEURONET - Rafal Pospiech
5
- * @author Rafal Pospiech <neuronet.io@gmail.com>
6
- * @module gantt-schedule-timeline-calendar
7
- * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
8
- * @link https://gantt-schedule-timeline-calendar.neuronet.io
9
- * @version 3.37.5
10
- * @released 2024-07-19
11
- * @license SEE LICENSE IN LICENSE FILE
12
- */
13
- const t="chart-timeline-grid-row-cell",e="chart-timeline-items-row-item";const i="config.plugin.Selection";function s(i){return Object.assign({enabled:!0,showOverlay:!0,isSelecting:!1,pointerState:"up",selectKey:"",multiKey:"shift",multipleSelection:!0,targetType:"",targetData:null,initialPosition:{x:0,y:0},currentPosition:{x:0,y:0},selectionAreaLocal:{x:0,y:0,width:0,height:0},selectionAreaGlobal:{x:0,y:0,width:0,height:0},selecting:{[e]:[],[t]:[]},selected:{[e]:[],[t]:[]},lastSelected:{[e]:[],[t]:[]},lastSelecting:{[e]:[],[t]:[]},automaticallySelected:{[e]:[],[t]:[]},events:{onStart(){},onSelecting:t=>t,onEnd:t=>t},pointerEvents:{down:null,move:null,up:null}},i)}class a{constructor(a,l){this.onDestroy=[],this.started=!1,this.lastAllEvents={down:null,move:null,up:null},this.vido=a,this.state=a.state,this.api=a.api,this.merge=this.state.get("config.merge"),this.state.update(i,s(l)),this.data=s(l),this.slotClassName=this.api.getClass("chart-selection"),this.slotStyleMap=new a.StyleMap({display:"none"}),this.html=a.html,this.slot=this.slot.bind(this),this.destroy=this.destroy.bind(this),this.setSlot(),this.onCellCreate=this.onCellCreate.bind(this),this.apiGetSelection=this.apiGetSelection.bind(this),this.apiGetSelecting=this.apiGetSelecting.bind(this),this.apiGetSelected=this.apiGetSelected.bind(this),this.apiSetSelection=this.apiSetSelection.bind(this),this.apiSelectCells=this.apiSelectCells.bind(this),this.apiSelectItems=this.apiSelectItems.bind(this),this.api.plugins.Selection={ITEM:e,CELL:t,getSelection:this.apiGetSelection,getSelected:this.apiGetSelected,getSelecting:this.apiGetSelecting,setSelection:this.apiSetSelection,selectCells:this.apiSelectCells,selectItems:this.apiSelectItems},this.state.update("config.chart.grid.cell.onCreate",(t=>(t.includes(this.onCellCreate)||t.push(this.onCellCreate),t))),this.updateData(),this.onDestroy.push(this.state.subscribe(i,(t=>{this.data=t}))),this.updateSelectionClassName=this.updateSelectionClassName.bind(this),this.selectedAction=this.selectedAction.bind(this),this.state.update("config.actions.chart-timeline-grid-row-cell",(t=>(t.includes(this.selectedAction)||t.push(this.selectedAction),t))),this.state.update("config.actions.chart-timeline-items-row-item",(t=>(t.includes(this.selectedAction)||t.push(this.selectedAction),t))),this.onDestroy.push(this.state.subscribe("config.chart.items.*;",(()=>{const t=this.api.getAllItems();this.data.selected[e]=this.data.selected[e].filter((e=>!!t[e])),this.data.selecting[e]=this.data.selecting[e].filter((e=>!!t[e]));const i=this.api.getItemsData();for(const t in i){const s=i[t];s.selected=this.data.selected[e].includes(t),s.selecting=this.data.selecting[e].includes(t)}}),{bulk:!0,bulkValue:!1})),this.onTimelinePointerDown=this.onTimelinePointerDown.bind(this),this.onTimelinePointerMove=this.onTimelinePointerMove.bind(this),this.onTimelinePointerUp=this.onTimelinePointerUp.bind(this),this.api.plugins.TimelinePointer.addPointerListener("move",this.onTimelinePointerMove),this.api.plugins.TimelinePointer.addPointerListener("down",this.onTimelinePointerDown),this.api.plugins.TimelinePointer.addPointerListener("up",this.onTimelinePointerUp)}setSlot(){this.state.update("config.slots.chart-timeline-items.outer",(t=>(t.includes(this.slot)||t.push(this.slot),t)))}destroy(){this.api.plugins.TimelinePointer.removePointerListener("move",this.onTimelinePointerMove),this.api.plugins.TimelinePointer.removePointerListener("down",this.onTimelinePointerDown),this.api.plugins.TimelinePointer.removePointerListener("up",this.onTimelinePointerUp),this.state.update("config.slots.chart-timeline-items.outer",(t=>t.filter((t=>t!==this.slot)))),this.state.update("config.actions.chart-timeline-grid-row-cell",(t=>t.filter((t=>t!==this.selectedAction)))),this.state.update("config.actions.chart-timeline-items-row-item",(t=>t.filter((t=>t!==this.selectedAction)))),this.state.update("config.chart.grid.cell.onCreate",(t=>t.filter((t=>t!==this.onCellCreate)))),this.onDestroy.forEach((t=>t()))}updateData(){this.state.update(i,Object.assign({},this.data)),this.vido.update()}apiSetSelection(t){this.data.selected=this.api.mergeDeep({},t);let e=this.state.multi(!0);e=this.updateCells(e),e=this.updateItems(e),e.done(),this.updateData()}apiSelectCells(e){this.data.selected[t]=[...e];let i=this.state.multi(!0);i=this.updateCells(i),i.done(),this.updateData()}apiSelectItems(t){this.data.selected[e]=[...t];let i=this.state.multi(!0);i=this.updateItems(i),i.done(),this.updateData()}apiGetSelection(){return{selecting:this.getSelectionWithData(this.data.selecting),selected:this.getSelectionWithData(this.data.selected)}}apiGetSelecting(){return this.getSelectionWithData(this.data.selecting)}apiGetSelected(){return this.getSelectionWithData(this.data.selected)}modKeyPressed(t,e){switch(t){case"shift":return e.shiftKey;case"alt":return e.altKey;case"ctrl":return e.ctrlKey}}canSelect(){let t=this.data.enabled;const e=this.lastAllEvents.down;return e&&this.data.selectKey&&(t=t&&this.modKeyPressed(this.data.selectKey,e)),t&&(this.data.cells||this.data.items)}getSelectionAreaLocal(t){const e={x:0,y:0,width:0,height:0},i=Object.assign({},t.initialPosition),s=Object.assign({},t.currentPosition),a=s.x-i.x,l=s.y-i.y;return a>=0?(e.x=i.x,e.width=a):(e.x=s.x,e.width=Math.abs(a)),l>=0?(e.y=i.y,e.height=l):(e.y=s.y,e.height=Math.abs(l)),e}translateAreaLocalToGlobal(t){const e=this.state.get("$data.chart.time.leftPx"),i=this.state.get("$data.scroll.vertical.absolutePosPx");return Object.assign(Object.assign({},t),{x:t.x+e,y:t.y+i})}collectLinkedItems(t,e=this.api.getItemsData()){if(!e[t])throw console.error('"config.chart.items"',this.state.get("config.chart.items")),console.error('"$data.chart.items"',this.state.get("$data.chart.items")),new Error(`Item with id "${t}" does not exists in "$data.chart.items".`);return[t,...e[t].linkedWith]}getSelectedItem(t){let i,s=this.data.automaticallySelected[e].slice();const a=this.collectLinkedItems(t.id);if(this.data.selected[e].find((e=>e===t.id)))if(i=this.data.selected[e],s.find((e=>e===t.id))){const e=s,a=i.find((i=>t.linkedWith.includes(i)&&!e.includes(i)));s=s.filter((e=>e!==t.id)),s.push(a)}else s=this.data.automaticallySelected[e];else i=this.isMulti()?Array.from(new Set([...this.data.selected[e],...a])):a,s=a.filter((e=>e!==t.id));return i=i.map((e=>(t=this.api.getItem(e),e))),{selected:i,automaticallySelected:s}}isItemVerticallyInsideArea(t,e){if(!e.width||!e.height)return!1;const i=e.y+e.height,s=t.position.viewTop,a=s+t.actualHeight;return s>=e.y&&s<=i||a>=e.y&&a<=i||s>=e.y&&a<=i||s<=e.y&&a>=i}isItemHorizontallyInsideArea(t,e){if(!e.width||!e.height)return!1;const i=e.x+e.width;return t.position.actualLeft>=e.x&&t.position.actualLeft<=i||t.position.actualRight>=e.x&&t.position.actualRight<=i||t.position.actualLeft<=e.x&&t.position.actualRight>=i||t.position.actualLeft>=e.x&&t.position.actualRight<=i}isMulti(){const t=this.lastAllEvents.move;return t&&this.data.multiKey&&this.modKeyPressed(this.data.multiKey,t)}getItemsUnderSelectionArea(t){const e=this.state.get("$data.chart.visibleItems"),i=this.api.getItems(e),s=[],a=[];for(let e of i){e=this.merge({},e);const i=this.api.getItemData(e.id);if(this.isItemVerticallyInsideArea(i,t)&&this.isItemHorizontallyInsideArea(i,t)){s.find((t=>t===e.id))||s.push(e.id);const t=this.collectLinkedItems(e.id);for(const e of t){const t=this.api.getItem(e);s.find((e=>e===t.id))||(s.push(t.id),a.push(t.id))}}}return{selectedItems:s,automaticallySelectedItems:a}}isCellVerticallyInsideArea(t,e){if(!e.width||!e.height)return!1;const i=e.y+e.height,s=t.top,a=s+t.rowData.actualHeight;return s>=e.y&&s<=i||a>=e.y&&a<=i||s>=e.y&&a<=i||s<=e.y&&a>=i}isCellHorizontallyInsideArea(t,e){if(!e.width||!e.height)return!1;const i=e.x+e.width,s=t.time.currentView.leftPx,a=t.time.currentView.rightPx;return s>=e.x&&s<=i||a>=e.x&&a<=i||s<=e.x&&a>=i||s>=e.x&&a<=i}getCellsUnderSelectionArea(t){const e=this.state.get("$data.chart.grid.cells"),i=[];for(const s in e){const a=e[s];this.isCellVerticallyInsideArea(a,t)&&this.isCellHorizontallyInsideArea(a,t)&&(i.find((t=>t===a.id))||i.push(a.id))}return{selectedCells:i}}updateItems(t){if(!this.data.items)return t;const i=this.api.getAllItems(),s=Array.from(new Set([...this.data.selecting[e],...this.data.selected[e]]));return t=t.update("$data.chart.items",(t=>{for(const a in t)if(a in i)if(s.includes(a)){const i=this.data.selecting[e].includes(a),s=this.data.selected[e].includes(a);t[a].selected=s,t[a].selecting=i}else t[a].selected=!1,t[a].selecting=!1;return t}),{data:"selection"})}updateCurrentItems(t){if(!this.data.items)return t;const i=this.state.get("$data.chart.items"),s=Array.from(new Set([...this.data.lastSelecting[e],...this.data.selecting[e],...this.data.selected[e]]));for(const t of s)i[t].selecting=this.data.selecting[e].includes(t),i[t].selected=this.data.selected[e].includes(t);return t}updateCells(e){if(!this.data.cells)return e;const i=this.api.getAllGridCells();return e.update("$data.chart.grid.cells",(e=>{for(const s in e){if(!(s in i))continue;const a=e[s];a&&(a.selected=this.data.selected[t].includes(a.id),a.selecting=this.data.selecting[t].includes(a.id))}return e})),e}updateCurrentCells(e){if(!this.data.items)return e;const i=Array.from(new Set([...this.data.lastSelecting[t],...this.data.selecting[t],...this.data.selected[t]]));for(const s of i){this.state.get(`$data.chart.grid.cells.${s}`)&&(e=e.update(`$data.chart.grid.cells.${s}`,(e=>(e.selected=this.data.selected[t].includes(s),e.selecting=this.data.selecting[t].includes(s),e))))}return e}deselectItems(){if(!this.data.items)return;this.data.selected[e].length=0,this.data.selecting[e].length=0;let t=this.state.multi(!0);t=this.updateItems(t),t.done()}deselectCells(){if(!this.data.cells)return;this.data.selecting[t].length=0,this.data.selected[t].length=0;let e=this.state.multi(!0);e=this.updateCells(e),e.done()}getSelectionWithData(i){const s=this.state.get("config.chart.items"),a=this.state.get("$data.chart.grid.cells");return{[t]:i[t].map((t=>a[t]?a[t]:t)),[e]:i[e].map((t=>s[t]?s[t]:t))}}onSelecting(i,s){const a=this.getSelectionWithData(i),l=this.getSelectionWithData(s);this.started||(this.data.events.onStart(l),this.started=!0,this.api.muteMethod("fullReload"),this.api.muteMethod("prepareExpanded"),this.api.muteMethod("calculateRowsHeight"),this.api.muteMethod("recalculateRowPercents"),this.api.muteMethod("getLastPageRowsHeight"),this.api.muteMethod("calculateVerticalScrollArea"),this.api.muteMethod("calculateVisibleRowsHeights"),this.api.muteMethod("generateVisibleRowsAndItems"),this.api.muteMethod("recalculateTimes"),this.api.muteMethod("heightChange"));const n=this.data.events.onSelecting(a,l);return{[t]:n[t].map((t=>"string"!=typeof t?t.id:t)),[e]:n[e].map((t=>"string"!=typeof t?t.id:t))}}onSelected(i,s){const a=this.getSelectionWithData(i),l=this.getSelectionWithData(s),n=this.data.events.onEnd(a,l);return this.started=!1,this.api.unmuteMethod("heightChange"),this.api.unmuteMethod("recalculateTimes"),this.api.unmuteMethod("generateVisibleRowsAndItems"),this.api.unmuteMethod("calculateVisibleRowsHeights"),this.api.unmuteMethod("calculateVerticalScrollArea"),this.api.unmuteMethod("getLastPageRowsHeight"),this.api.unmuteMethod("recalculateRowPercents"),this.api.unmuteMethod("calculateRowsHeight"),this.api.unmuteMethod("prepareExpanded"),this.api.unmuteMethod("fullReload"),{[t]:n[t].map((t=>"string"!=typeof t?t.id:t)),[e]:n[e].map((t=>"string"!=typeof t?t.id:t))}}updateBodyClass(){this.data.isSelecting?document.body.classList.add(this.data.bodySelectingClassName):document.body.classList.remove(this.data.bodySelectingClassName),this.data.selected[t].length||this.data.selected[e].length?document.body.classList.add(this.data.bodySelectedClassName):document.body.classList.remove(this.data.bodySelectedClassName)}selectMultipleCellsAndItems(i){if(!this.canSelect())return;if(!this.data.multipleSelection)return this.deselectItems(),this.deselectCells(),void this.updateData();this.data.isSelecting=!0,this.data.selectionAreaLocal=this.getSelectionAreaLocal(i),this.data.selectionAreaGlobal=this.translateAreaLocalToGlobal(this.data.selectionAreaLocal);const s={[t]:[],[e]:[]},a=this.isMulti();if(this.data.cells){const{selectedCells:e}=this.getCellsUnderSelectionArea(this.data.selectionAreaLocal);0===e.length?(s[t].length=0,a||(this.data.selected[t].length=0)):s[t]=e}if(this.data.items){const{selectedItems:t,automaticallySelectedItems:i}=this.getItemsUnderSelectionArea(this.data.selectionAreaLocal);this.data.automaticallySelected[e]=i,0===t.length?(s[e].length=0,a||(this.data.selected[e].length=0)):s[e]=t}if(this.data.cells||this.data.items){this.data.lastSelecting={[e]:[...this.data.selecting[e]],[t]:[...this.data.selecting[t]]},this.data.selecting=this.onSelecting(s,this.api.mergeDeep({},this.data.lastSelected));let i=this.state.multi(!0);this.data.cells&&(i=this.updateCurrentCells(i)),this.data.items&&(i=this.updateCurrentItems(i)),i.done()}}selectItemsIndividually(i){if(this.data.isSelecting=!1,this.data.selectionAreaLocal=this.getSelectionAreaLocal(i),this.data.currentPosition=i.currentPosition,this.data.initialPosition=i.initialPosition,!this.data.items)return;if(!this.canSelect())return;if(!i.targetData)return;const s=this.merge({},i.targetData),a=this.api.getItemData(s.id);if(!a)throw console.error('"config.chart.items"',this.state.get("config.chart.items")),console.error('"$data.chart.items"',this.state.get("$data.chart.items")),new Error(`Item with id "${s.id}" does not exists in "$data.chart.items". TIP: For performance reasons, state is mutable, so try not to modify items from the "state.get" method before you copy them (with "gstc.api.clone(items)" for example).`);if(this.data.selected[e].includes(s.id))return;let{selected:l,automaticallySelected:n}=this.getSelectedItem(s);l.length>1&&!this.data.multipleSelection&&(l=[s.id],n=[]),this.isMulti()?a.selected?this.data.selected[e]=l.filter((t=>t!==s.id&&!n.includes(t))):this.data.selected[e]=l:(this.data.selected[e]=l,this.data.selected[t].length=0),this.data.automaticallySelected[e]=n,this.data.lastSelecting={[e]:[...this.data.selected[e]],[t]:[...this.data.selected[t]]},this.data.selected=this.onSelected(this.api.mergeDeep({},this.data.selected),this.api.mergeDeep({},this.data.lastSelected));let c=this.state.multi(!0);c=this.updateCells(c),c=this.updateItems(c),c.done()}removeMultiUnselected(t){const e=this.data.selected[t].filter((e=>this.data.selecting[t].includes(e))),i=[...this.data.selected[t],...this.data.selecting[t]];return Array.from(new Set(i.filter((t=>!e.includes(t)))))}finishSelection(){if(!this.canSelect())return;let i;i=this.isMulti()?{[t]:this.data.cells?this.removeMultiUnselected(t):[],[e]:this.data.items?this.removeMultiUnselected(e):[]}:{[t]:this.data.cells?[...this.data.selecting[t]]:[],[e]:this.data.items?[...this.data.selecting[e]]:[]},this.data.selected=this.onSelected(i,this.api.mergeDeep({},this.data.lastSelected)),this.data.lastSelected=this.api.mergeDeep({},this.data.selected),this.data.cells&&(this.data.selecting[t].length=0),this.data.items&&(this.data.selecting[e].length=0);let s=this.state.multi(!0);s=this.updateItems(s),s=this.updateCells(s),s.done()}onPointerData(i){if(this.lastAllEvents=i.allEvents,i.isMoving&&i.targetType===t&&this.data.rectangularSelection?this.selectMultipleCellsAndItems(i):i.isMoving&&i.targetType===t&&!this.data.rectangularSelection?this.deselectItems():i.targetType===e?this.selectItemsIndividually(i):i.isMoving||(this.data.isSelecting&&this.finishSelection(),this.data.isSelecting=!1),i.isMoving&&i.targetType!==t&&i.targetType!==e&&this.deselectItems(),this.data.pointerState=i.type,this.data.targetType=i.targetType,this.data.targetData=i.targetData,"down"===this.data.pointerState){let t=this.state.multi(!0);t=this.updateItems(t),t=this.updateCells(t),t.done()}this.updateData(),this.updateBodyClass()}onTimelinePointerDown(t){this.data.enabled&&this.onPointerData(t)}onTimelinePointerMove(t){this.data.enabled&&this.onPointerData(t)}onTimelinePointerUp(t){this.data.enabled&&this.onPointerData(t)}slot(){let t,e=!0;return i=>(e=!0,this.canSelect()&&this.data.isSelecting&&this.data.showOverlay&&this.data.multipleSelection&&this.data.rectangularSelection&&(this.slotStyleMap.style.display="block",this.slotStyleMap.style.left=this.data.selectionAreaLocal.x+"px",this.slotStyleMap.style.top=this.data.selectionAreaLocal.y+"px",this.slotStyleMap.style.width=this.data.selectionAreaLocal.width+"px",this.slotStyleMap.style.height=this.data.selectionAreaLocal.height+"px",e=!1),t=this.html`<div class=${this.slotClassName} style=${this.slotStyleMap.directive()}></div>`,this.html`${i}${e?null:t}`)}updateSelectionClassName(t,e){if(!e&&!e.itemData)return;const i="boolean"==typeof e.selected?e.selected:e.itemData.selected,s="boolean"==typeof e.selecting?e.selecting:e.itemData.selecting;i?(t.classList.contains(this.data.selectedClassName)||t.classList.add(this.data.selectedClassName),t.classList.contains(this.data.selectingClassName)&&t.classList.remove(this.data.selectingClassName)):t.classList.contains(this.data.selectedClassName)&&t.classList.remove(this.data.selectedClassName),s?(t.classList.contains(this.data.selectingClassName)||t.classList.add(this.data.selectingClassName),t.classList.contains(this.data.selectedClassName)&&t.classList.remove(this.data.selectedClassName)):t.classList.contains(this.data.selectingClassName)&&t.classList.remove(this.data.selectingClassName)}selectedAction(t,e){this.updateSelectionClassName(t,e);const i=this;return{update(t,e){i.updateSelectionClassName(t,e)},destroy(t,e){i.updateSelectionClassName(t,e)}}}onCellCreate(e){return e.selected=!!this.data.selected[t].find((t=>t===e.id)),e.selecting=!!this.data.selecting[t].find((t=>t===e.id)),e.content}}function l(t={}){return t=function(t){!
14
- /**
15
- * Selection plugin
16
- *
17
- * @copyright NEURONET - Rafal Pospiech
18
- * @author Rafal Pospiech <neuronet.io@gmail.com>
19
- * @module gantt-schedule-timeline-calendar
20
- * @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
21
- * @link https://gantt-schedule-timeline-calendar.neuronet.io
22
- * @version 3.37.5
23
- * @released 2024-07-19
24
- * @license SEE LICENSE IN LICENSE FILE
25
- */
26
- function(t){t.events||(t.events={}),t.onStart&&(t.events.onStart=t.onStart),t.onSelecting&&(t.events.onSelecting=t.onSelecting),t.onSelected&&(t.events.onEnd=t.onSelected)}(t);const e={enabled:!0,cells:!0,items:!0,showOverlay:!0,rectangularSelection:!0,multipleSelection:!0,selectedClassName:"gstc__selected",selectingClassName:"gstc__selecting",bodySelectedClassName:"gstc__is-selected",bodySelectingClassName:"gstc__is-selecting",events:{onStart(){},onSelecting:t=>t,onEnd:t=>t}};return t.events=Object.assign(Object.assign({},e.events),t.events),Object.assign(Object.assign({},e),t)}(t),function(e){const s=e.api.mergeDeep,l=e.api;if(!l.isPluginInitialized("TimelinePointer"))throw new Error("TimelinePointer plugin must be initialized before Selection plugin.");const n=e.state.get(i);n&&(t=s({},t,n));const c=new a(e,t);return l.pluginInitialized("Selection"),c.destroy}}export{l as Plugin};
1
+ const t = "chart-timeline-grid-row-cell",
2
+ e = "chart-timeline-items-row-item";
3
+ const i = "config.plugin.Selection";
4
+ function s(i) {
5
+ return Object.assign(
6
+ {
7
+ enabled: !0,
8
+ showOverlay: !0,
9
+ isSelecting: !1,
10
+ pointerState: "up",
11
+ selectKey: "",
12
+ multiKey: "shift",
13
+ multipleSelection: !0,
14
+ targetType: "",
15
+ targetData: null,
16
+ initialPosition: { x: 0, y: 0 },
17
+ currentPosition: { x: 0, y: 0 },
18
+ selectionAreaLocal: { x: 0, y: 0, width: 0, height: 0 },
19
+ selectionAreaGlobal: { x: 0, y: 0, width: 0, height: 0 },
20
+ selecting: { [e]: [], [t]: [] },
21
+ selected: { [e]: [], [t]: [] },
22
+ lastSelected: { [e]: [], [t]: [] },
23
+ lastSelecting: { [e]: [], [t]: [] },
24
+ automaticallySelected: { [e]: [], [t]: [] },
25
+ events: { onStart() {}, onSelecting: (t) => t, onEnd: (t) => t },
26
+ pointerEvents: { down: null, move: null, up: null },
27
+ },
28
+ i,
29
+ );
30
+ }
31
+ class a {
32
+ constructor(a, l) {
33
+ (this.onDestroy = []),
34
+ (this.started = !1),
35
+ (this.lastAllEvents = { down: null, move: null, up: null }),
36
+ (this.vido = a),
37
+ (this.state = a.state),
38
+ (this.api = a.api),
39
+ (this.merge = this.state.get("config.merge")),
40
+ this.state.update(i, s(l)),
41
+ (this.data = s(l)),
42
+ (this.slotClassName = this.api.getClass("chart-selection")),
43
+ (this.slotStyleMap = new a.StyleMap({ display: "none" })),
44
+ (this.html = a.html),
45
+ (this.slot = this.slot.bind(this)),
46
+ (this.destroy = this.destroy.bind(this)),
47
+ this.setSlot(),
48
+ (this.onCellCreate = this.onCellCreate.bind(this)),
49
+ (this.apiGetSelection = this.apiGetSelection.bind(this)),
50
+ (this.apiGetSelecting = this.apiGetSelecting.bind(this)),
51
+ (this.apiGetSelected = this.apiGetSelected.bind(this)),
52
+ (this.apiSetSelection = this.apiSetSelection.bind(this)),
53
+ (this.apiSelectCells = this.apiSelectCells.bind(this)),
54
+ (this.apiSelectItems = this.apiSelectItems.bind(this)),
55
+ (this.api.plugins.Selection = {
56
+ ITEM: e,
57
+ CELL: t,
58
+ getSelection: this.apiGetSelection,
59
+ getSelected: this.apiGetSelected,
60
+ getSelecting: this.apiGetSelecting,
61
+ setSelection: this.apiSetSelection,
62
+ selectCells: this.apiSelectCells,
63
+ selectItems: this.apiSelectItems,
64
+ }),
65
+ this.state.update(
66
+ "config.chart.grid.cell.onCreate",
67
+ (t) => (t.includes(this.onCellCreate) || t.push(this.onCellCreate), t),
68
+ ),
69
+ this.updateData(),
70
+ this.onDestroy.push(
71
+ this.state.subscribe(i, (t) => {
72
+ this.data = t;
73
+ }),
74
+ ),
75
+ (this.updateSelectionClassName =
76
+ this.updateSelectionClassName.bind(this)),
77
+ (this.selectedAction = this.selectedAction.bind(this)),
78
+ this.state.update(
79
+ "config.actions.chart-timeline-grid-row-cell",
80
+ (t) => (
81
+ t.includes(this.selectedAction) || t.push(this.selectedAction), t
82
+ ),
83
+ ),
84
+ this.state.update(
85
+ "config.actions.chart-timeline-items-row-item",
86
+ (t) => (
87
+ t.includes(this.selectedAction) || t.push(this.selectedAction), t
88
+ ),
89
+ ),
90
+ this.onDestroy.push(
91
+ this.state.subscribe(
92
+ "config.chart.items.*;",
93
+ () => {
94
+ const t = this.api.getAllItems();
95
+ (this.data.selected[e] = this.data.selected[e].filter(
96
+ (e) => !!t[e],
97
+ )),
98
+ (this.data.selecting[e] = this.data.selecting[e].filter(
99
+ (e) => !!t[e],
100
+ ));
101
+ const i = this.api.getItemsData();
102
+ for (const t in i) {
103
+ const s = i[t];
104
+ (s.selected = this.data.selected[e].includes(t)),
105
+ (s.selecting = this.data.selecting[e].includes(t));
106
+ }
107
+ },
108
+ { bulk: !0, bulkValue: !1 },
109
+ ),
110
+ ),
111
+ (this.onTimelinePointerDown = this.onTimelinePointerDown.bind(this)),
112
+ (this.onTimelinePointerMove = this.onTimelinePointerMove.bind(this)),
113
+ (this.onTimelinePointerUp = this.onTimelinePointerUp.bind(this)),
114
+ this.api.plugins.TimelinePointer.addPointerListener(
115
+ "move",
116
+ this.onTimelinePointerMove,
117
+ ),
118
+ this.api.plugins.TimelinePointer.addPointerListener(
119
+ "down",
120
+ this.onTimelinePointerDown,
121
+ ),
122
+ this.api.plugins.TimelinePointer.addPointerListener(
123
+ "up",
124
+ this.onTimelinePointerUp,
125
+ );
126
+ }
127
+ setSlot() {
128
+ this.state.update(
129
+ "config.slots.chart-timeline-items.outer",
130
+ (t) => (t.includes(this.slot) || t.push(this.slot), t),
131
+ );
132
+ }
133
+ destroy() {
134
+ this.api.plugins.TimelinePointer.removePointerListener(
135
+ "move",
136
+ this.onTimelinePointerMove,
137
+ ),
138
+ this.api.plugins.TimelinePointer.removePointerListener(
139
+ "down",
140
+ this.onTimelinePointerDown,
141
+ ),
142
+ this.api.plugins.TimelinePointer.removePointerListener(
143
+ "up",
144
+ this.onTimelinePointerUp,
145
+ ),
146
+ this.state.update("config.slots.chart-timeline-items.outer", (t) =>
147
+ t.filter((t) => t !== this.slot),
148
+ ),
149
+ this.state.update("config.actions.chart-timeline-grid-row-cell", (t) =>
150
+ t.filter((t) => t !== this.selectedAction),
151
+ ),
152
+ this.state.update("config.actions.chart-timeline-items-row-item", (t) =>
153
+ t.filter((t) => t !== this.selectedAction),
154
+ ),
155
+ this.state.update("config.chart.grid.cell.onCreate", (t) =>
156
+ t.filter((t) => t !== this.onCellCreate),
157
+ ),
158
+ this.onDestroy.forEach((t) => t());
159
+ }
160
+ updateData() {
161
+ this.state.update(i, Object.assign({}, this.data)), this.vido.update();
162
+ }
163
+ apiSetSelection(t) {
164
+ this.data.selected = this.api.mergeDeep({}, t);
165
+ let e = this.state.multi(!0);
166
+ (e = this.updateCells(e)),
167
+ (e = this.updateItems(e)),
168
+ e.done(),
169
+ this.updateData();
170
+ }
171
+ apiSelectCells(e) {
172
+ this.data.selected[t] = [...e];
173
+ let i = this.state.multi(!0);
174
+ (i = this.updateCells(i)), i.done(), this.updateData();
175
+ }
176
+ apiSelectItems(t) {
177
+ this.data.selected[e] = [...t];
178
+ let i = this.state.multi(!0);
179
+ (i = this.updateItems(i)), i.done(), this.updateData();
180
+ }
181
+ apiGetSelection() {
182
+ return {
183
+ selecting: this.getSelectionWithData(this.data.selecting),
184
+ selected: this.getSelectionWithData(this.data.selected),
185
+ };
186
+ }
187
+ apiGetSelecting() {
188
+ return this.getSelectionWithData(this.data.selecting);
189
+ }
190
+ apiGetSelected() {
191
+ return this.getSelectionWithData(this.data.selected);
192
+ }
193
+ modKeyPressed(t, e) {
194
+ switch (t) {
195
+ case "shift":
196
+ return e.shiftKey;
197
+ case "alt":
198
+ return e.altKey;
199
+ case "ctrl":
200
+ return e.ctrlKey;
201
+ }
202
+ }
203
+ canSelect() {
204
+ let t = this.data.enabled;
205
+ const e = this.lastAllEvents.down;
206
+ return (
207
+ e &&
208
+ this.data.selectKey &&
209
+ (t = t && this.modKeyPressed(this.data.selectKey, e)),
210
+ t && (this.data.cells || this.data.items)
211
+ );
212
+ }
213
+ getSelectionAreaLocal(t) {
214
+ const e = { x: 0, y: 0, width: 0, height: 0 },
215
+ i = Object.assign({}, t.initialPosition),
216
+ s = Object.assign({}, t.currentPosition),
217
+ a = s.x - i.x,
218
+ l = s.y - i.y;
219
+ return (
220
+ a >= 0
221
+ ? ((e.x = i.x), (e.width = a))
222
+ : ((e.x = s.x), (e.width = Math.abs(a))),
223
+ l >= 0
224
+ ? ((e.y = i.y), (e.height = l))
225
+ : ((e.y = s.y), (e.height = Math.abs(l))),
226
+ e
227
+ );
228
+ }
229
+ translateAreaLocalToGlobal(t) {
230
+ const e = this.state.get("$data.chart.time.leftPx"),
231
+ i = this.state.get("$data.scroll.vertical.absolutePosPx");
232
+ return Object.assign(Object.assign({}, t), { x: t.x + e, y: t.y + i });
233
+ }
234
+ collectLinkedItems(t, e = this.api.getItemsData()) {
235
+ if (!e[t])
236
+ throw (
237
+ (console.error(
238
+ '"config.chart.items"',
239
+ this.state.get("config.chart.items"),
240
+ ),
241
+ console.error(
242
+ '"$data.chart.items"',
243
+ this.state.get("$data.chart.items"),
244
+ ),
245
+ new Error(`Item with id"${t}"does not exists in"$data.chart.items".`))
246
+ );
247
+ return [t, ...e[t].linkedWith];
248
+ }
249
+ getSelectedItem(t) {
250
+ let i,
251
+ s = this.data.automaticallySelected[e].slice();
252
+ const a = this.collectLinkedItems(t.id);
253
+ if (this.data.selected[e].find((e) => e === t.id))
254
+ if (((i = this.data.selected[e]), s.find((e) => e === t.id))) {
255
+ const e = s,
256
+ a = i.find((i) => t.linkedWith.includes(i) && !e.includes(i));
257
+ (s = s.filter((e) => e !== t.id)), s.push(a);
258
+ } else s = this.data.automaticallySelected[e];
259
+ else
260
+ (i = this.isMulti()
261
+ ? Array.from(new Set([...this.data.selected[e], ...a]))
262
+ : a),
263
+ (s = a.filter((e) => e !== t.id));
264
+ return (
265
+ (i = i.map((e) => ((t = this.api.getItem(e)), e))),
266
+ { selected: i, automaticallySelected: s }
267
+ );
268
+ }
269
+ isItemVerticallyInsideArea(t, e) {
270
+ if (!e.width || !e.height) return !1;
271
+ const i = e.y + e.height,
272
+ s = t.position.viewTop,
273
+ a = s + t.actualHeight;
274
+ return (
275
+ (s >= e.y && s <= i) ||
276
+ (a >= e.y && a <= i) ||
277
+ (s >= e.y && a <= i) ||
278
+ (s <= e.y && a >= i)
279
+ );
280
+ }
281
+ isItemHorizontallyInsideArea(t, e) {
282
+ if (!e.width || !e.height) return !1;
283
+ const i = e.x + e.width;
284
+ return (
285
+ (t.position.actualLeft >= e.x && t.position.actualLeft <= i) ||
286
+ (t.position.actualRight >= e.x && t.position.actualRight <= i) ||
287
+ (t.position.actualLeft <= e.x && t.position.actualRight >= i) ||
288
+ (t.position.actualLeft >= e.x && t.position.actualRight <= i)
289
+ );
290
+ }
291
+ isMulti() {
292
+ const t = this.lastAllEvents.move;
293
+ return t && this.data.multiKey && this.modKeyPressed(this.data.multiKey, t);
294
+ }
295
+ getItemsUnderSelectionArea(t) {
296
+ const e = this.state.get("$data.chart.visibleItems"),
297
+ i = this.api.getItems(e),
298
+ s = [],
299
+ a = [];
300
+ for (let e of i) {
301
+ e = this.merge({}, e);
302
+ const i = this.api.getItemData(e.id);
303
+ if (
304
+ this.isItemVerticallyInsideArea(i, t) &&
305
+ this.isItemHorizontallyInsideArea(i, t)
306
+ ) {
307
+ s.find((t) => t === e.id) || s.push(e.id);
308
+ const t = this.collectLinkedItems(e.id);
309
+ for (const e of t) {
310
+ const t = this.api.getItem(e);
311
+ s.find((e) => e === t.id) || (s.push(t.id), a.push(t.id));
312
+ }
313
+ }
314
+ }
315
+ return { selectedItems: s, automaticallySelectedItems: a };
316
+ }
317
+ isCellVerticallyInsideArea(t, e) {
318
+ if (!e.width || !e.height) return !1;
319
+ const i = e.y + e.height,
320
+ s = t.top,
321
+ a = s + t.rowData.actualHeight;
322
+ return (
323
+ (s >= e.y && s <= i) ||
324
+ (a >= e.y && a <= i) ||
325
+ (s >= e.y && a <= i) ||
326
+ (s <= e.y && a >= i)
327
+ );
328
+ }
329
+ isCellHorizontallyInsideArea(t, e) {
330
+ if (!e.width || !e.height) return !1;
331
+ const i = e.x + e.width,
332
+ s = t.time.currentView.leftPx,
333
+ a = t.time.currentView.rightPx;
334
+ return (
335
+ (s >= e.x && s <= i) ||
336
+ (a >= e.x && a <= i) ||
337
+ (s <= e.x && a >= i) ||
338
+ (s >= e.x && a <= i)
339
+ );
340
+ }
341
+ getCellsUnderSelectionArea(t) {
342
+ const e = this.state.get("$data.chart.grid.cells"),
343
+ i = [];
344
+ for (const s in e) {
345
+ const a = e[s];
346
+ this.isCellVerticallyInsideArea(a, t) &&
347
+ this.isCellHorizontallyInsideArea(a, t) &&
348
+ (i.find((t) => t === a.id) || i.push(a.id));
349
+ }
350
+ return { selectedCells: i };
351
+ }
352
+ updateItems(t) {
353
+ if (!this.data.items) return t;
354
+ const i = this.api.getAllItems(),
355
+ s = Array.from(
356
+ new Set([...this.data.selecting[e], ...this.data.selected[e]]),
357
+ );
358
+ return (t = t.update(
359
+ "$data.chart.items",
360
+ (t) => {
361
+ for (const a in t)
362
+ if (a in i)
363
+ if (s.includes(a)) {
364
+ const i = this.data.selecting[e].includes(a),
365
+ s = this.data.selected[e].includes(a);
366
+ (t[a].selected = s), (t[a].selecting = i);
367
+ } else (t[a].selected = !1), (t[a].selecting = !1);
368
+ return t;
369
+ },
370
+ { data: "selection" },
371
+ ));
372
+ }
373
+ updateCurrentItems(t) {
374
+ if (!this.data.items) return t;
375
+ const i = this.state.get("$data.chart.items"),
376
+ s = Array.from(
377
+ new Set([
378
+ ...this.data.lastSelecting[e],
379
+ ...this.data.selecting[e],
380
+ ...this.data.selected[e],
381
+ ]),
382
+ );
383
+ for (const t of s)
384
+ (i[t].selecting = this.data.selecting[e].includes(t)),
385
+ (i[t].selected = this.data.selected[e].includes(t));
386
+ return t;
387
+ }
388
+ updateCells(e) {
389
+ if (!this.data.cells) return e;
390
+ const i = this.api.getAllGridCells();
391
+ return (
392
+ e.update("$data.chart.grid.cells", (e) => {
393
+ for (const s in e) {
394
+ if (!(s in i)) continue;
395
+ const a = e[s];
396
+ a &&
397
+ ((a.selected = this.data.selected[t].includes(a.id)),
398
+ (a.selecting = this.data.selecting[t].includes(a.id)));
399
+ }
400
+ return e;
401
+ }),
402
+ e
403
+ );
404
+ }
405
+ updateCurrentCells(e) {
406
+ if (!this.data.items) return e;
407
+ const i = Array.from(
408
+ new Set([
409
+ ...this.data.lastSelecting[t],
410
+ ...this.data.selecting[t],
411
+ ...this.data.selected[t],
412
+ ]),
413
+ );
414
+ for (const s of i) {
415
+ this.state.get(`$data.chart.grid.cells.${s}`) &&
416
+ (e = e.update(
417
+ `$data.chart.grid.cells.${s}`,
418
+ (e) => (
419
+ (e.selected = this.data.selected[t].includes(s)),
420
+ (e.selecting = this.data.selecting[t].includes(s)),
421
+ e
422
+ ),
423
+ ));
424
+ }
425
+ return e;
426
+ }
427
+ deselectItems() {
428
+ if (!this.data.items) return;
429
+ (this.data.selected[e].length = 0), (this.data.selecting[e].length = 0);
430
+ let t = this.state.multi(!0);
431
+ (t = this.updateItems(t)), t.done();
432
+ }
433
+ deselectCells() {
434
+ if (!this.data.cells) return;
435
+ (this.data.selecting[t].length = 0), (this.data.selected[t].length = 0);
436
+ let e = this.state.multi(!0);
437
+ (e = this.updateCells(e)), e.done();
438
+ }
439
+ getSelectionWithData(i) {
440
+ const s = this.state.get("config.chart.items"),
441
+ a = this.state.get("$data.chart.grid.cells");
442
+ return {
443
+ [t]: i[t].map((t) => (a[t] ? a[t] : t)),
444
+ [e]: i[e].map((t) => (s[t] ? s[t] : t)),
445
+ };
446
+ }
447
+ onSelecting(i, s) {
448
+ const a = this.getSelectionWithData(i),
449
+ l = this.getSelectionWithData(s);
450
+ this.started ||
451
+ (this.data.events.onStart(l),
452
+ (this.started = !0),
453
+ this.api.muteMethod("fullReload"),
454
+ this.api.muteMethod("prepareExpanded"),
455
+ this.api.muteMethod("calculateRowsHeight"),
456
+ this.api.muteMethod("recalculateRowPercents"),
457
+ this.api.muteMethod("getLastPageRowsHeight"),
458
+ this.api.muteMethod("calculateVerticalScrollArea"),
459
+ this.api.muteMethod("calculateVisibleRowsHeights"),
460
+ this.api.muteMethod("generateVisibleRowsAndItems"),
461
+ this.api.muteMethod("recalculateTimes"),
462
+ this.api.muteMethod("heightChange"));
463
+ const n = this.data.events.onSelecting(a, l);
464
+ return {
465
+ [t]: n[t].map((t) => ("string" != typeof t ? t.id : t)),
466
+ [e]: n[e].map((t) => ("string" != typeof t ? t.id : t)),
467
+ };
468
+ }
469
+ onSelected(i, s) {
470
+ const a = this.getSelectionWithData(i),
471
+ l = this.getSelectionWithData(s),
472
+ n = this.data.events.onEnd(a, l);
473
+ return (
474
+ (this.started = !1),
475
+ this.api.unmuteMethod("heightChange"),
476
+ this.api.unmuteMethod("recalculateTimes"),
477
+ this.api.unmuteMethod("generateVisibleRowsAndItems"),
478
+ this.api.unmuteMethod("calculateVisibleRowsHeights"),
479
+ this.api.unmuteMethod("calculateVerticalScrollArea"),
480
+ this.api.unmuteMethod("getLastPageRowsHeight"),
481
+ this.api.unmuteMethod("recalculateRowPercents"),
482
+ this.api.unmuteMethod("calculateRowsHeight"),
483
+ this.api.unmuteMethod("prepareExpanded"),
484
+ this.api.unmuteMethod("fullReload"),
485
+ {
486
+ [t]: n[t].map((t) => ("string" != typeof t ? t.id : t)),
487
+ [e]: n[e].map((t) => ("string" != typeof t ? t.id : t)),
488
+ }
489
+ );
490
+ }
491
+ updateBodyClass() {
492
+ this.data.isSelecting
493
+ ? document.body.classList.add(this.data.bodySelectingClassName)
494
+ : document.body.classList.remove(this.data.bodySelectingClassName),
495
+ this.data.selected[t].length || this.data.selected[e].length
496
+ ? document.body.classList.add(this.data.bodySelectedClassName)
497
+ : document.body.classList.remove(this.data.bodySelectedClassName);
498
+ }
499
+ selectMultipleCellsAndItems(i) {
500
+ if (!this.canSelect()) return;
501
+ if (!this.data.multipleSelection)
502
+ return this.deselectItems(), this.deselectCells(), void this.updateData();
503
+ (this.data.isSelecting = !0),
504
+ (this.data.selectionAreaLocal = this.getSelectionAreaLocal(i)),
505
+ (this.data.selectionAreaGlobal = this.translateAreaLocalToGlobal(
506
+ this.data.selectionAreaLocal,
507
+ ));
508
+ const s = { [t]: [], [e]: [] },
509
+ a = this.isMulti();
510
+ if (this.data.cells) {
511
+ const { selectedCells: e } = this.getCellsUnderSelectionArea(
512
+ this.data.selectionAreaLocal,
513
+ );
514
+ 0 === e.length
515
+ ? ((s[t].length = 0), a || (this.data.selected[t].length = 0))
516
+ : (s[t] = e);
517
+ }
518
+ if (this.data.items) {
519
+ const { selectedItems: t, automaticallySelectedItems: i } =
520
+ this.getItemsUnderSelectionArea(this.data.selectionAreaLocal);
521
+ (this.data.automaticallySelected[e] = i),
522
+ 0 === t.length
523
+ ? ((s[e].length = 0), a || (this.data.selected[e].length = 0))
524
+ : (s[e] = t);
525
+ }
526
+ if (this.data.cells || this.data.items) {
527
+ (this.data.lastSelecting = {
528
+ [e]: [...this.data.selecting[e]],
529
+ [t]: [...this.data.selecting[t]],
530
+ }),
531
+ (this.data.selecting = this.onSelecting(
532
+ s,
533
+ this.api.mergeDeep({}, this.data.lastSelected),
534
+ ));
535
+ let i = this.state.multi(!0);
536
+ this.data.cells && (i = this.updateCurrentCells(i)),
537
+ this.data.items && (i = this.updateCurrentItems(i)),
538
+ i.done();
539
+ }
540
+ }
541
+ selectItemsIndividually(i) {
542
+ if (
543
+ ((this.data.isSelecting = !1),
544
+ (this.data.selectionAreaLocal = this.getSelectionAreaLocal(i)),
545
+ (this.data.currentPosition = i.currentPosition),
546
+ (this.data.initialPosition = i.initialPosition),
547
+ !this.data.items || i.type !== 'down'
548
+ )
549
+ )
550
+ return;
551
+ if (!this.canSelect()) return;
552
+ if (!i.targetData) return;
553
+ const s = this.merge({}, i.targetData),
554
+ a = this.api.getItemData(s.id);
555
+ if (!a)
556
+ throw (
557
+ (console.error(
558
+ '"config.chart.items"',
559
+ this.state.get("config.chart.items"),
560
+ ),
561
+ console.error(
562
+ '"$data.chart.items"',
563
+ this.state.get("$data.chart.items"),
564
+ ),
565
+ new Error(
566
+ `Item with id"${s.id}"does not exists in"$data.chart.items".TIP:For performance reasons,state is mutable,so try not to modify items from the"state.get"method before you copy them(with"gstc.api.clone(items)"for example).`,
567
+ ))
568
+ );
569
+ if (this.data.selected[e].includes(s.id)){
570
+
571
+ if (this.isMulti()) {
572
+ // 多选模式下,从已选择列表中移除该项目
573
+ this.data.selected[e] = this.data.selected[e].filter((itemId) => itemId !== s.id);
574
+ this.data.automaticallySelected[e] = this.data.automaticallySelected[e].filter((itemId) => itemId !== s.id);
575
+ } else {
576
+ // 单选模式下,清空已选择列表
577
+ this.data.selected[e] = [];
578
+ this.data.selected[t] = [];
579
+ this.data.automaticallySelected[e] = [];
580
+ }
581
+ // 记录最后一次选择的状态
582
+ this.data.lastSelecting = {
583
+ [e]: [...this.data.selected[e]],
584
+ [t]: [...this.data.selected[t]],
585
+ };
586
+
587
+
588
+ // 更新状态
589
+ let c = this.state.multi(true);
590
+ c = this.updateCells(c);
591
+ c = this.updateItems(c);
592
+ c.done();
593
+
594
+ return;
595
+ }
596
+ let { selected: l, automaticallySelected: n } = this.getSelectedItem(s);
597
+ l.length > 1 && !this.data.multipleSelection && ((l = [s.id]), (n = [])),
598
+ this.isMulti()
599
+ ? a.selected
600
+ ? (this.data.selected[e] = l.filter(
601
+ (t) => t !== s.id && !n.includes(t),
602
+ ))
603
+ : (this.data.selected[e] = l)
604
+ : ((this.data.selected[e] = l), (this.data.selected[t].length = 0)),
605
+ (this.data.automaticallySelected[e] = n),
606
+ (this.data.lastSelecting = {
607
+ [e]: [],
608
+ [t]: [],
609
+ }),
610
+ (this.data.selected = this.onSelected(
611
+ this.api.mergeDeep({}, this.data.selected),
612
+ this.api.mergeDeep({}, this.data.lastSelected),
613
+ )
614
+ );
615
+ //
616
+ this.data.selected[e] = [];
617
+ this.data.selected[t] = [];
618
+ this.data.automaticallySelected[e] = [];
619
+ ////////
620
+ let c = this.state.multi(!0);
621
+ (c = this.updateCells(c)), (c = this.updateItems(c)), c.done();
622
+ }
623
+ removeMultiUnselected(t) {
624
+ const e = this.data.selected[t].filter((e) =>
625
+ this.data.selecting[t].includes(e),
626
+ ),
627
+ i = [...this.data.selected[t], ...this.data.selecting[t]];
628
+ return Array.from(new Set(i.filter((t) => !e.includes(t))));
629
+ }
630
+ finishSelection() {
631
+ if (!this.canSelect()) return;
632
+ let i;
633
+ (i = this.isMulti()
634
+ ? {
635
+ [t]: this.data.cells ? this.removeMultiUnselected(t) : [],
636
+ [e]: this.data.items ? this.removeMultiUnselected(e) : [],
637
+ }
638
+ : {
639
+ [t]: this.data.cells ? [...this.data.selecting[t]] : [],
640
+ [e]: this.data.items ? [...this.data.selecting[e]] : [],
641
+ }),
642
+ (this.data.selected = this.onSelected(
643
+ i,
644
+ this.api.mergeDeep({}, this.data.lastSelected),
645
+ )),
646
+ (this.data.lastSelected = this.api.mergeDeep({}, this.data.selected)),
647
+ this.data.cells && (this.data.selecting[t].length = 0),
648
+ this.data.items && (this.data.selecting[e].length = 0);
649
+ let s = this.state.multi(!0);
650
+ (s = this.updateItems(s)), (s = this.updateCells(s)), s.done();
651
+ }
652
+ onPointerData(i) {
653
+ if (this.eventsCheck(i) && ((this.lastAllEvents = i.allEvents),
654
+ i.isMoving && i.targetType === t && this.data.rectangularSelection
655
+ ? this.selectMultipleCellsAndItems(i)
656
+ : i.isMoving && i.targetType === t && !this.data.rectangularSelection
657
+ ? this.deselectItems()
658
+ : i.targetType === e
659
+ ? this.selectItemsIndividually(i)
660
+ : i.isMoving ||
661
+ (this.data.isSelecting && this.finishSelection(),
662
+ (this.data.isSelecting = !1)),
663
+ i.isMoving &&
664
+ i.targetType !== t &&
665
+ i.targetType !== e &&
666
+ this.deselectItems(),
667
+ (this.data.pointerState = i.type),
668
+ (this.data.targetType = i.targetType),
669
+ (this.data.targetData = i.targetData),
670
+ "down" === this.data.pointerState)
671
+ ) {
672
+ let t = this.state.multi(!0);
673
+ (t = this.updateItems(t)), (t = this.updateCells(t)), t.done();
674
+ }
675
+ this.updateData(), this.updateBodyClass();
676
+ }
677
+
678
+ eventsCheck(i) {
679
+ if (i && i.allEvents) {
680
+ if (i.allEvents.down && i.allEvents.down.button === 2) {
681
+ return false;
682
+ }
683
+ }
684
+ return true;
685
+ }
686
+ onTimelinePointerDown(t) {
687
+ this.data.enabled && this.onPointerData(t);
688
+ }
689
+ onTimelinePointerMove(t) {
690
+ this.data.enabled && this.onPointerData(t);
691
+ }
692
+ onTimelinePointerUp(t) {
693
+ this.data.enabled && this.onPointerData(t);
694
+ }
695
+ slot() {
696
+ let t,
697
+ e = !0;
698
+ return (i) => (
699
+ (e = !0),
700
+ this.canSelect() &&
701
+ this.data.isSelecting &&
702
+ this.data.showOverlay &&
703
+ this.data.multipleSelection &&
704
+ this.data.rectangularSelection &&
705
+ ((this.slotStyleMap.style.display = "block"),
706
+ (this.slotStyleMap.style.left = this.data.selectionAreaLocal.x + "px"),
707
+ (this.slotStyleMap.style.top = this.data.selectionAreaLocal.y + "px"),
708
+ (this.slotStyleMap.style.width =
709
+ this.data.selectionAreaLocal.width + "px"),
710
+ (this.slotStyleMap.style.height =
711
+ this.data.selectionAreaLocal.height + "px"),
712
+ (e = !1)),
713
+ (t = this
714
+ .html`<div class=${this.slotClassName}style=${this.slotStyleMap.directive()}></div>`),
715
+ this.html`${i}${e ? null : t}`
716
+ );
717
+ }
718
+ updateSelectionClassName(t, e) {
719
+ if (!e && !e.itemData) return;
720
+ const i = "boolean" == typeof e.selected ? e.selected : e.itemData.selected,
721
+ s = "boolean" == typeof e.selecting ? e.selecting : e.itemData.selecting;
722
+ i
723
+ ? (t.classList.contains(this.data.selectedClassName) ||
724
+ t.classList.add(this.data.selectedClassName),
725
+ t.classList.contains(this.data.selectingClassName) &&
726
+ t.classList.remove(this.data.selectingClassName))
727
+ : t.classList.contains(this.data.selectedClassName) &&
728
+ t.classList.remove(this.data.selectedClassName),
729
+ s
730
+ ? (t.classList.contains(this.data.selectingClassName) ||
731
+ t.classList.add(this.data.selectingClassName),
732
+ t.classList.contains(this.data.selectedClassName) &&
733
+ t.classList.remove(this.data.selectedClassName))
734
+ : t.classList.contains(this.data.selectingClassName) &&
735
+ t.classList.remove(this.data.selectingClassName);
736
+ }
737
+ selectedAction(t, e) {
738
+ this.updateSelectionClassName(t, e);
739
+ const i = this;
740
+ return {
741
+ update(t, e) {
742
+ i.updateSelectionClassName(t, e);
743
+ },
744
+ destroy(t, e) {
745
+ i.updateSelectionClassName(t, e);
746
+ },
747
+ };
748
+ }
749
+ onCellCreate(e) {
750
+ return (
751
+ (e.selected = !!this.data.selected[t].find((t) => t === e.id)),
752
+ (e.selecting = !!this.data.selecting[t].find((t) => t === e.id)),
753
+ e.content
754
+ );
755
+ }
756
+ }
757
+ function l(t = {}) {
758
+ return (
759
+ (t = (function (t) {
760
+ !(function (t) {
761
+ t.events || (t.events = {}),
762
+ t.onStart && (t.events.onStart = t.onStart),
763
+ t.onSelecting && (t.events.onSelecting = t.onSelecting),
764
+ t.onSelected && (t.events.onEnd = t.onSelected);
765
+ })(t);
766
+ const e = {
767
+ enabled: !0,
768
+ cells: !0,
769
+ items: !0,
770
+ showOverlay: !0,
771
+ rectangularSelection: !0,
772
+ multipleSelection: !0,
773
+ selectedClassName: "gstc__selected",
774
+ selectingClassName: "gstc__selecting",
775
+ bodySelectedClassName: "gstc__is-selected",
776
+ bodySelectingClassName: "gstc__is-selecting",
777
+ events: { onStart() {}, onSelecting: (t) => t, onEnd: (t) => t },
778
+ };
779
+ return (
780
+ (t.events = Object.assign(Object.assign({}, e.events), t.events)),
781
+ Object.assign(Object.assign({}, e), t)
782
+ );
783
+ })(t)),
784
+ function (e) {
785
+ const s = e.api.mergeDeep,
786
+ l = e.api;
787
+ if (!l.isPluginInitialized("TimelinePointer"))
788
+ throw new Error(
789
+ "TimelinePointer plugin must be initialized before Selection plugin.",
790
+ );
791
+ const n = e.state.get(i);
792
+ n && (t = s({}, t, n));
793
+ const c = new a(e, t);
794
+ return l.pluginInitialized("Selection"), c.destroy;
795
+ }
796
+ );
797
+ }
798
+ export { l as Plugin };