gantt-source_management 3.37.5 → 3.37.7
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.
- package/dist/gstc.wasm.esm.min.js +6776 -545
- package/dist/plugins/selection.esm.min.js +765 -26
- package/package.json +1 -1
|
@@ -1,26 +1,765 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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)
|
|
548
|
+
)
|
|
549
|
+
return;
|
|
550
|
+
if (!this.canSelect()) return;
|
|
551
|
+
if (!i.targetData) return;
|
|
552
|
+
const s = this.merge({}, i.targetData),
|
|
553
|
+
a = this.api.getItemData(s.id);
|
|
554
|
+
if (!a)
|
|
555
|
+
throw (
|
|
556
|
+
(console.error(
|
|
557
|
+
'"config.chart.items"',
|
|
558
|
+
this.state.get("config.chart.items"),
|
|
559
|
+
),
|
|
560
|
+
console.error(
|
|
561
|
+
'"$data.chart.items"',
|
|
562
|
+
this.state.get("$data.chart.items"),
|
|
563
|
+
),
|
|
564
|
+
new Error(
|
|
565
|
+
`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).`,
|
|
566
|
+
))
|
|
567
|
+
);
|
|
568
|
+
if (this.data.selected[e].includes(s.id)) return;
|
|
569
|
+
let { selected: l, automaticallySelected: n } = this.getSelectedItem(s);
|
|
570
|
+
l.length > 1 && !this.data.multipleSelection && ((l = [s.id]), (n = [])),
|
|
571
|
+
this.isMulti()
|
|
572
|
+
? a.selected
|
|
573
|
+
? (this.data.selected[e] = l.filter(
|
|
574
|
+
(t) => t !== s.id && !n.includes(t),
|
|
575
|
+
))
|
|
576
|
+
: (this.data.selected[e] = l)
|
|
577
|
+
: ((this.data.selected[e] = l), (this.data.selected[t].length = 0)),
|
|
578
|
+
(this.data.automaticallySelected[e] = n),
|
|
579
|
+
(this.data.lastSelecting = {
|
|
580
|
+
[e]: [...this.data.selected[e]],
|
|
581
|
+
[t]: [...this.data.selected[t]],
|
|
582
|
+
}),
|
|
583
|
+
(this.data.selected = this.onSelected(
|
|
584
|
+
this.api.mergeDeep({}, this.data.selected),
|
|
585
|
+
this.api.mergeDeep({}, this.data.lastSelected),
|
|
586
|
+
));
|
|
587
|
+
let c = this.state.multi(!0);
|
|
588
|
+
(c = this.updateCells(c)), (c = this.updateItems(c)), c.done();
|
|
589
|
+
}
|
|
590
|
+
removeMultiUnselected(t) {
|
|
591
|
+
const e = this.data.selected[t].filter((e) =>
|
|
592
|
+
this.data.selecting[t].includes(e),
|
|
593
|
+
),
|
|
594
|
+
i = [...this.data.selected[t], ...this.data.selecting[t]];
|
|
595
|
+
return Array.from(new Set(i.filter((t) => !e.includes(t))));
|
|
596
|
+
}
|
|
597
|
+
finishSelection() {
|
|
598
|
+
if (!this.canSelect()) return;
|
|
599
|
+
let i;
|
|
600
|
+
(i = this.isMulti()
|
|
601
|
+
? {
|
|
602
|
+
[t]: this.data.cells ? this.removeMultiUnselected(t) : [],
|
|
603
|
+
[e]: this.data.items ? this.removeMultiUnselected(e) : [],
|
|
604
|
+
}
|
|
605
|
+
: {
|
|
606
|
+
[t]: this.data.cells ? [...this.data.selecting[t]] : [],
|
|
607
|
+
[e]: this.data.items ? [...this.data.selecting[e]] : [],
|
|
608
|
+
}),
|
|
609
|
+
(this.data.selected = this.onSelected(
|
|
610
|
+
i,
|
|
611
|
+
this.api.mergeDeep({}, this.data.lastSelected),
|
|
612
|
+
)),
|
|
613
|
+
(this.data.lastSelected = this.api.mergeDeep({}, this.data.selected)),
|
|
614
|
+
this.data.cells && (this.data.selecting[t].length = 0),
|
|
615
|
+
this.data.items && (this.data.selecting[e].length = 0);
|
|
616
|
+
let s = this.state.multi(!0);
|
|
617
|
+
(s = this.updateItems(s)), (s = this.updateCells(s)), s.done();
|
|
618
|
+
}
|
|
619
|
+
onPointerData(i) {
|
|
620
|
+
if (this.eventsCheck(i) && ((this.lastAllEvents = i.allEvents),
|
|
621
|
+
i.isMoving && i.targetType === t && this.data.rectangularSelection
|
|
622
|
+
? this.selectMultipleCellsAndItems(i)
|
|
623
|
+
: i.isMoving && i.targetType === t && !this.data.rectangularSelection
|
|
624
|
+
? this.deselectItems()
|
|
625
|
+
: i.targetType === e
|
|
626
|
+
? this.selectItemsIndividually(i)
|
|
627
|
+
: i.isMoving ||
|
|
628
|
+
(this.data.isSelecting && this.finishSelection(),
|
|
629
|
+
(this.data.isSelecting = !1)),
|
|
630
|
+
i.isMoving &&
|
|
631
|
+
i.targetType !== t &&
|
|
632
|
+
i.targetType !== e &&
|
|
633
|
+
this.deselectItems(),
|
|
634
|
+
(this.data.pointerState = i.type),
|
|
635
|
+
(this.data.targetType = i.targetType),
|
|
636
|
+
(this.data.targetData = i.targetData),
|
|
637
|
+
"down" === this.data.pointerState)
|
|
638
|
+
) {
|
|
639
|
+
let t = this.state.multi(!0);
|
|
640
|
+
(t = this.updateItems(t)), (t = this.updateCells(t)), t.done();
|
|
641
|
+
}
|
|
642
|
+
this.updateData(), this.updateBodyClass();
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
eventsCheck(i) {
|
|
646
|
+
if (i && i.allEvents) {
|
|
647
|
+
if (i.allEvents.down && i.allEvents.down.button === 2) {
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
onTimelinePointerDown(t) {
|
|
654
|
+
this.data.enabled && this.onPointerData(t);
|
|
655
|
+
}
|
|
656
|
+
onTimelinePointerMove(t) {
|
|
657
|
+
this.data.enabled && this.onPointerData(t);
|
|
658
|
+
}
|
|
659
|
+
onTimelinePointerUp(t) {
|
|
660
|
+
this.data.enabled && this.onPointerData(t);
|
|
661
|
+
}
|
|
662
|
+
slot() {
|
|
663
|
+
let t,
|
|
664
|
+
e = !0;
|
|
665
|
+
return (i) => (
|
|
666
|
+
(e = !0),
|
|
667
|
+
this.canSelect() &&
|
|
668
|
+
this.data.isSelecting &&
|
|
669
|
+
this.data.showOverlay &&
|
|
670
|
+
this.data.multipleSelection &&
|
|
671
|
+
this.data.rectangularSelection &&
|
|
672
|
+
((this.slotStyleMap.style.display = "block"),
|
|
673
|
+
(this.slotStyleMap.style.left = this.data.selectionAreaLocal.x + "px"),
|
|
674
|
+
(this.slotStyleMap.style.top = this.data.selectionAreaLocal.y + "px"),
|
|
675
|
+
(this.slotStyleMap.style.width =
|
|
676
|
+
this.data.selectionAreaLocal.width + "px"),
|
|
677
|
+
(this.slotStyleMap.style.height =
|
|
678
|
+
this.data.selectionAreaLocal.height + "px"),
|
|
679
|
+
(e = !1)),
|
|
680
|
+
(t = this
|
|
681
|
+
.html`<div class=${this.slotClassName}style=${this.slotStyleMap.directive()}></div>`),
|
|
682
|
+
this.html`${i}${e ? null : t}`
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
updateSelectionClassName(t, e) {
|
|
686
|
+
if (!e && !e.itemData) return;
|
|
687
|
+
const i = "boolean" == typeof e.selected ? e.selected : e.itemData.selected,
|
|
688
|
+
s = "boolean" == typeof e.selecting ? e.selecting : e.itemData.selecting;
|
|
689
|
+
i
|
|
690
|
+
? (t.classList.contains(this.data.selectedClassName) ||
|
|
691
|
+
t.classList.add(this.data.selectedClassName),
|
|
692
|
+
t.classList.contains(this.data.selectingClassName) &&
|
|
693
|
+
t.classList.remove(this.data.selectingClassName))
|
|
694
|
+
: t.classList.contains(this.data.selectedClassName) &&
|
|
695
|
+
t.classList.remove(this.data.selectedClassName),
|
|
696
|
+
s
|
|
697
|
+
? (t.classList.contains(this.data.selectingClassName) ||
|
|
698
|
+
t.classList.add(this.data.selectingClassName),
|
|
699
|
+
t.classList.contains(this.data.selectedClassName) &&
|
|
700
|
+
t.classList.remove(this.data.selectedClassName))
|
|
701
|
+
: t.classList.contains(this.data.selectingClassName) &&
|
|
702
|
+
t.classList.remove(this.data.selectingClassName);
|
|
703
|
+
}
|
|
704
|
+
selectedAction(t, e) {
|
|
705
|
+
this.updateSelectionClassName(t, e);
|
|
706
|
+
const i = this;
|
|
707
|
+
return {
|
|
708
|
+
update(t, e) {
|
|
709
|
+
i.updateSelectionClassName(t, e);
|
|
710
|
+
},
|
|
711
|
+
destroy(t, e) {
|
|
712
|
+
i.updateSelectionClassName(t, e);
|
|
713
|
+
},
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
onCellCreate(e) {
|
|
717
|
+
return (
|
|
718
|
+
(e.selected = !!this.data.selected[t].find((t) => t === e.id)),
|
|
719
|
+
(e.selecting = !!this.data.selecting[t].find((t) => t === e.id)),
|
|
720
|
+
e.content
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function l(t = {}) {
|
|
725
|
+
return (
|
|
726
|
+
(t = (function (t) {
|
|
727
|
+
!(function (t) {
|
|
728
|
+
t.events || (t.events = {}),
|
|
729
|
+
t.onStart && (t.events.onStart = t.onStart),
|
|
730
|
+
t.onSelecting && (t.events.onSelecting = t.onSelecting),
|
|
731
|
+
t.onSelected && (t.events.onEnd = t.onSelected);
|
|
732
|
+
})(t);
|
|
733
|
+
const e = {
|
|
734
|
+
enabled: !0,
|
|
735
|
+
cells: !0,
|
|
736
|
+
items: !0,
|
|
737
|
+
showOverlay: !0,
|
|
738
|
+
rectangularSelection: !0,
|
|
739
|
+
multipleSelection: !0,
|
|
740
|
+
selectedClassName: "gstc__selected",
|
|
741
|
+
selectingClassName: "gstc__selecting",
|
|
742
|
+
bodySelectedClassName: "gstc__is-selected",
|
|
743
|
+
bodySelectingClassName: "gstc__is-selecting",
|
|
744
|
+
events: { onStart() {}, onSelecting: (t) => t, onEnd: (t) => t },
|
|
745
|
+
};
|
|
746
|
+
return (
|
|
747
|
+
(t.events = Object.assign(Object.assign({}, e.events), t.events)),
|
|
748
|
+
Object.assign(Object.assign({}, e), t)
|
|
749
|
+
);
|
|
750
|
+
})(t)),
|
|
751
|
+
function (e) {
|
|
752
|
+
const s = e.api.mergeDeep,
|
|
753
|
+
l = e.api;
|
|
754
|
+
if (!l.isPluginInitialized("TimelinePointer"))
|
|
755
|
+
throw new Error(
|
|
756
|
+
"TimelinePointer plugin must be initialized before Selection plugin.",
|
|
757
|
+
);
|
|
758
|
+
const n = e.state.get(i);
|
|
759
|
+
n && (t = s({}, t, n));
|
|
760
|
+
const c = new a(e, t);
|
|
761
|
+
return l.pluginInitialized("Selection"), c.destroy;
|
|
762
|
+
}
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
export { l as Plugin };
|