gantt-source_management
Version:
Gantt, Schedule,
127 lines • 8.57 kB
JavaScript
/**
* ItemTypes plugin
*
* @copyright NEURONET - Rafal Pospiech
* @author Rafal Pospiech <neuronet.io@gmail.com>
* @module gantt-schedule-timeline-calendar
* @link https://github.com/neuronetio/gantt-schedule-timeline-calendar
* @link https://gantt-schedule-timeline-calendar.neuronet.io
* @version 3.37.5
* @released 2024-07-19
* @license SEE LICENSE IN LICENSE FILE
*/
const t="config.plugin.ItemTypes",e="config.templates.chart-timeline-items-row-item",i={task({className:t,labelClassName:e,cache:i,shouldDetach:s,actions:a,styleMap:l,slots:n,cutterLeft:c,cutterRight:o,getContent:$,vido:p,props:h}){const r=s||!h.item,{itemData:g,item:d}=h,m=g.position.left!==g.position.actualLeft,u=g.position.right!==g.position.actualRight,y=g.actualWidth,L=g.actualHeight,_=Math.min(8,L/2);let f=[`M ${_} ${L}`,`Q 0 ${L} 0 ${L-_}`,`L 0 ${_}`,`Q 0 0 ${_} 0`,`L ${y-_} 0`,`Q ${y} 0 ${y} ${_}`,`L ${y} ${L-_}`,`Q ${y} ${L} ${y-_} ${L}`,`L ${_} ${L}`].join(" ");m&&!u?f=["M 0 0",`L ${y-_} 0`,`Q ${y} 0 ${y} ${_}`,`L ${y} ${L-_}`,`Q ${y} ${L} ${y-_} ${L}`,`L 0 ${L}`].join(" "):m&&u?f=["M 0 0",`L ${y} 0`,`L ${y} ${L}`,`L 0 ${L}`].join(" "):!m&&u&&(f=[`M ${_} ${L}`,`Q 0 ${L} 0 ${L-_}`,`L 0 ${_}`,`Q 0 0 ${_} 0`,`L ${y} 0`,`L ${y} ${L}`,`L ${_} ${L}`].join(" "));const w=`gstc__clip-path-${d.id}`,v=`gstc__pattern-${d.id}`,j=void 0===d.progress?100:d.progress,x=g.width-g.width/100*j;let b=g.width-x;m&&(b+=g.position.left),b<0&&(b=0);const H=[`M ${b} 0`,`L ${y} 0`,`L ${y} ${L}`,`L ${b} ${L}`].join(" "),M=d.fill?d.fill:"#e74c3c",O=`gstc__item-type gstc__item-type--${d.type} `;return i(r?null:n.html("outer",p.html`
<div class=${O+t} data-gstcid=${h.item.id} data-actions=${a()} style=${l.directive()}>
${y>=0?p.svg`<svg width=${y} height=${g.actualHeight} xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id=${w}>
<path d=${f}></path>
</clipPath>
<pattern
id=${v}
width="20"
height="20"
patternTransform="rotate(45 0 0)"
patternUnits="userSpaceOnUse"
>
<line
class="gstc__item-type-progress-line"
x1="0"
y1="0"
x2="0"
y2="20"
/>
</pattern>
</defs>
<path class="gstc__item-type-item" d=${f} fill=${M} />
<path
class="gstc__item-type-progress"
clip-path="url(#${w})"
d=${H}
style="fill: url('#${v}');" />
<g clip-path="url(#${w})">
<foreignObject x="0" y="0" width="100%" height="100%">
<div class="gstc__item-type-content" xmlns="http://www.w3.org/1999/xhtml">
${n.html("inner",p.html`<div class=${O+e}>${n.html("content",$())}</div>`)}
</div>
</foreignObject>
</g>
</svg>`:null}
</div>
`))},milestone({className:t,labelClassName:e,cache:i,actions:s,styleMap:a,shouldDetach:l,slots:n,cutterLeft:c,cutterRight:o,getContent:$,vido:p,props:h}){const r=l||!h.item,{itemData:g,item:d}=h,m=16,u=g.actualWidth,y=g.actualHeight,L=g.position.left!==g.position.actualLeft,_=g.position.right!==g.position.actualRight;let f=["M 0 "+g.actualHeight/2,`L ${u>=32?m:u/2} 0`,`L ${u>=32?u-m:u/2} 0`,`L ${u} ${g.actualHeight/2}`,`L ${u>=32?u-m:u/2} ${g.actualHeight}`,`L ${u>=32?m:u/2} ${g.actualHeight}`,"L 0 "+g.actualHeight/2].join(" ");L&&!_?f=["M 0 0",`L ${u>=32?u-m:u/2} 0`,`L ${u} ${g.actualHeight/2}`,`L ${u>=32?u-m:u/2} ${g.actualHeight}`,`L 0 ${y}`].join(" "):L&&_?f=["M 0 0",`L ${u} 0`,`L ${u} ${y}`,`L 0 ${y}`].join(" "):!L&&_&&(f=["M 0 "+g.actualHeight/2,`L ${u>=32?m:u/2} 0`,`L ${u} 0`,`L ${u} ${y}`,`L ${u>=32?m:u/2} ${g.actualHeight}`,"L 0 "+g.actualHeight/2].join(" "));const w=`gstc__clip-path-${d.id}`,v=`gstc__pattern-${d.id}`,j=void 0===d.progress?100:d.progress,x=g.width-g.width/100*j;let b=g.width-x;L&&(b+=g.position.left),b<0&&(b=0);const H=[`M ${u} 0`,`L ${u} ${y}`,`L ${b} ${y}`,`L ${b} 0`].join(" "),M=d.fill?d.fill:"#e74c3c",O=`gstc__item-type gstc__item-type--${d.type} `;return i(r?null:n.html("outer",p.html`
<div class=${O+t} data-gstcid=${h.item.id} data-actions=${s()} style=${a.directive()}>
${u>=0?p.svg`<svg width=${u} height=${g.actualHeight} xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id=${w}>
<path d=${f}></path>
</clipPath>
<pattern
id=${v}
width="20"
height="20"
patternTransform="rotate(45 0 0)"
patternUnits="userSpaceOnUse"
>
<line
class="gstc__item-type-progress-line"
x1="0"
y1="0"
x2="0"
y2="20"
/>
</pattern>
</defs>
<path class="gstc__item-type-item" d=${f} stroke="none" fill=${M} />
<path
class="gstc__item-type-progress"
clip-path="url(#${w})"
d=${H}
style="fill: url('#${v}');" />
<g clip-path="url(#${w})">
<foreignObject x="0" y="0" width="100%" height="100%">
<div class="gstc__item-type-content" xmlns="http://www.w3.org/1999/xhtml">
${n.html("inner",p.html`<div class=${O+e}>${n.html("content",$())}</div>`)}
</div>
</foreignObject>
</g>
</svg>`:null}
</div>
`))},project({className:t,labelClassName:e,cache:i,shouldDetach:s,actions:a,styleMap:l,slots:n,cutterLeft:c,cutterRight:o,getContent:$,vido:p,props:h}){const r=s||!h.item,{itemData:g,item:d}=h,m=g.actualWidth,u=g.actualHeight,y=g.position.left!==g.position.actualLeft,L=["M 0 0",`L ${m} 0`,`L ${m} ${u}`,`L 0 ${u}`].join(" "),_=`gstc__clip-path-${d.id}`,f=`gstc__pattern-${d.id}`,w=void 0===d.progress?100:d.progress,v=g.width-g.width/100*w;let j=g.width-v;y&&(j+=g.position.left),j<0&&(j=0);const x=[`M ${m} 0`,`L ${m} ${u}`,`L ${j} ${u}`,`L ${j} 0`].join(" "),b=d.fill?d.fill:"#e74c3c",H=`gstc__item-type gstc__item-type--${d.type} `;return i(r?null:n.html("outer",p.html`
<div class=${H+t} data-gstcid=${h.item.id} data-actions=${a()} style=${l.directive()}>
${m>=0?p.svg`<svg width=${m} height=${g.actualHeight} xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id=${_}>
<path d=${L}></path>
</clipPath>
<pattern
id=${f}
width="20"
height="20"
patternTransform="rotate(45 0 0)"
patternUnits="userSpaceOnUse"
>
<line
class="gstc__item-type-progress-line"
x1="0"
y1="0"
x2="0"
y2="20"
/>
</pattern>
</defs>
<path class="gstc__item-type-item" d=${L} fill=${b} />
<path
class="gstc__item-type-progress"
clip-path="url(#${_})"
d=${x}
style="fill: url('#${f}');" />
<g clip-path="url(#${_})">
<foreignObject x="0" y="0" width="100%" height="100%">
<div class="gstc__item-type-content" xmlns="http://www.w3.org/1999/xhtml">
${n.html("inner",p.html`<div class=${H+e}>${n.html("content",$())}</div>`)}
</div>
</foreignObject>
</g>
</svg>`:null}
</div>
`))}};class s{constructor(s,a){this.unsub=[],this.options=function(t){return Object.assign(Object.assign({},i),t)}(s),this.vido=a,this.state=a.state,this.api=a.api,this.componentTemplate=this.componentTemplate.bind(this),this.destroy=this.destroy.bind(this),this.state.update(t,this.options),this.state.update(e,(()=>this.componentTemplate)),this.unsub.push(this.state.subscribe(t,(t=>this.options=t))),this.api.pluginInitialized("ItemTypes")}destroy(){this.unsub.forEach((t=>t())),this.state.update(e,null),this.vido.api.pluginDestroyed("ItemTypes")}componentTemplate(t){const e=t.props.item;if(!e)return null;const i=e.type;if(!i)throw new Error(`Item (${e.id}) must have a 'type' {string} property 'task', 'milestone' or 'project'.`);return this.options[i](t)}}function a(e={}){return function(i){const a=i.state.get(t);a&&(e=i.api.mergeDeep({},e,a));return new s(e,i).destroy}}export{a as Plugin,t as pluginPath,e as templatePath};