awesome-timeline-react 0.1.7 → 0.1.9
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/README.md +13 -4
- package/dist/_tsup-dts-rollup.d.mts +307 -0
- package/dist/_tsup-dts-rollup.d.ts +19 -2
- package/dist/index.css +196 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +1846 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1829 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/index.d.mts +1 -0
- package/package.json +63 -60
package/dist/index.js
CHANGED
|
@@ -1,2 +1,1847 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var st=Object.defineProperty;var Ee=Object.getOwnPropertySymbols;var at=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var Te=(e,t,r)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,De=(e,t)=>{for(var r in t||(t={}))at.call(t,r)&&Te(e,r,t[r]);if(Ee)for(var r of Ee(t))ct.call(t,r)&&Te(e,r,t[r]);return e};var _react = require('react'); var _react2 = _interopRequireDefault(_react);var lt=e=>{let t=null;switch(e){case 0:t="Jan";break;case 1:t="Feb";break;case 2:t="Mar";break;case 3:t="Apr";break;case 4:t="May";break;case 5:t="Jun";break;case 6:t="Jul";break;case 7:t="Aug";break;case 8:t="Sep";break;case 9:t="Oct";break;case 10:t="Nov";break;case 11:t="Dec";break;default:t="Jan"}return t},le=lt;var ut=e=>{let t=null;switch(e){case 0:t="Mon";break;case 1:t="Tue";break;case 2:t="Wed";break;case 3:t="Thu";break;case 4:t="Fri";break;case 5:t="Sat";break;case 6:t="Sun";break;default:t="Mon"}return t},ue=ut;var dt=({windowTime:e,tick:t,contentWidth:r,blockWidth:n})=>{let{dayBlocks:o,hourBlocks:i}=_react.useMemo.call(void 0, ()=>{let s=e[0],a=[],l=[];if(t===null||r===null)return{dayBlocks:[],hourBlocks:[]};let u=r,d=1;for(;;){let p=new Date(s*1e3),y=new Date(p.getFullYear(),p.getMonth(),p.getDate(),23,59,59),f=(y.getTime()-p.getTime())/1e3/t;if(u-=f,Math.round(u)<0){let m=Math.round((f+u)/n);for(let g=0;g<m;g++)l.push(_react2.default.createElement("div",{className:"hour-block",key:`${p.getDate()}_hour_${g}`},g<10?`0${g}:00`:`${g}:00`));a.push(_react2.default.createElement("div",{className:"day-block",key:`${p.getDate()} ${p.getMonth()}`,style:{gridColumn:`${d} / ${d+m}`}},ue(p.getDay())," ",p.getDate()," ",le(p.getMonth()))),d+=m;break}let b=Math.round(f/n);for(let m=24-b;m<24;m++)l.push(_react2.default.createElement("div",{className:"hour-block",key:`${p.getDate()}_hour_${m}`},m<10?`0${m}:00`:`${m}:00`));if(a.push(_react2.default.createElement("div",{className:"day-block",key:`${p.getDate()} ${p.getMonth()}`,style:{gridColumn:`${d} / ${d+b}`}},ue(p.getDay())," ",p.getDate()," ",le(p.getMonth()))),d+=b,Math.round(u)===0)break;s=(y.getTime()+1e3)/1e3}return{dayBlocks:a,hourBlocks:l}},[t,e,r]);return{dayBlocks:o,hourBlocks:i}},Re=dt;var mt=({windowTime:e,contentWidth:t})=>{let r=_react.useMemo.call(void 0, ()=>(e[1]-e[0])/3600,[e]),n=t?t/r:0;return{numberOfHourBlocks:r,blockWidth:n}},V=mt;var gt=({windowTime:e,tick:t,contentWidth:r,scrollWidth:n,additionalClassNames:o})=>{let i=_react.useRef.call(void 0, null),{blockWidth:s}=V({windowTime:e,contentWidth:r}),{dayBlocks:a,hourBlocks:l}=Re({windowTime:e,tick:t,contentWidth:r,blockWidth:s}),u=o!=null&&o.timeBar?"time-bar "+o.timeBar:"time-bar",d=o!=null&&o.dayRow?"day-row "+o.dayRow:"day-row",p=o!=null&&o.hourRow?"hour-row "+o.hourRow:"hour-row";return _react2.default.createElement("div",{className:u},_react2.default.createElement("div",{className:"empty-block"}),_react2.default.createElement("div",{className:"time-content",ref:i,style:{minWidth:r||0}},_react2.default.createElement("div",{className:d,style:{gridTemplateColumns:`repeat(auto-fill, minmax(${s}px, 1fr))`}},a.map(y=>y)),_react2.default.createElement("div",{className:p,style:{gridTemplateColumns:`repeat(auto-fill, minmax(${s}px, 1fr))`}},l.map(y=>y))),n?_react2.default.createElement("div",{style:{width:n,height:"100%",boxSizing:"border-box",borderLeft:"1px solid yellow"}}):null)},Se=gt;var P=_react.createContext.call(void 0, null);var wt=({name:e,id:t})=>{let r=_react.useContext.call(void 0, P),n=r&&r.rowsHeight&&r.rowsHeight[t]?r.rowsHeight[t].minHeight:40;return _react2.default.createElement("div",{className:"row-header",style:{minHeight:n}},e)},Pe=wt;var vt=({rows:e,className:t})=>{let r=t?"rows-header-wrapper "+t:"rows-header-wrapper";return _react2.default.createElement("div",{className:r},e.map(n=>_react2.default.createElement(Pe,{key:`row_header_${n.id}`,id:n.id,name:n.name})))},ke=vt;var xt=({contentWidth:e,cellWidth:t,lineClassName:r})=>{let n=_react.useMemo.call(void 0, ()=>{let i=[],s=r?"line "+r:"line";if(e)for(let a=t;a<e;a=a+t)i.push(_react2.default.createElement("div",{key:`line_${a}`,className:s}));return i},[t,e]),o=_react.useMemo.call(void 0, ()=>e?e-n.length*t:0,[e,t,n]);return _react2.default.createElement("div",{className:o<1?"lines-canvas hide-last-line":"lines-canvas",style:o<1?{gridTemplateColumns:`repeat(auto-fill, minmax(${t}px, 1fr))`}:{gridTemplateColumns:`repeat(auto-fill, minmax(${o}px, ${t}px))`}},n)},Oe=xt;var Tt=({id:e,startPosition:t,width:r,top:n,height:o})=>_react2.default.createElement("div",{id:`static_event_${e}`,key:`static_event_${e}`,className:"static-event",onDrop:i=>i.stopPropagation(),style:{left:t,width:r,top:n,minHeight:o}}),ze=Tt;var Fe=Symbol.for("immer-nothing"),Ae=Symbol.for("immer-draftable"),E=Symbol.for("immer-state"),Dt=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function x(e,...t){if(process.env.NODE_ENV!=="production"){let r=Dt[e],n=typeof r=="function"?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var L=Object.getPrototypeOf;function F(e){return!!e&&!!e[E]}function N(e){var t;return e?Be(e)||Array.isArray(e)||!!e[Ae]||!!((t=e.constructor)!=null&&t[Ae])||te(e)||re(e):!1}var Rt=Object.prototype.constructor.toString();function Be(e){if(!e||typeof e!="object")return!1;let t=L(e);if(t===null)return!0;let r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object?!0:typeof r=="function"&&Function.toString.call(r)===Rt}function q(e,t){ee(e)===0?Reflect.ownKeys(e).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function ee(e){let t=e[E];return t?t.type_:Array.isArray(e)?1:te(e)?2:re(e)?3:0}function pe(e,t){return ee(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function We(e,t,r){let n=ee(e);n===2?e.set(t,r):n===3?e.add(r):e[t]=r}function St(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function te(e){return e instanceof Map}function re(e){return e instanceof Set}function A(e){return e.copy_||e.base_}function me(e,t){if(te(e))return new Map(e);if(re(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let r=Be(e);if(t===!0||t==="class_only"&&!r){let n=Object.getOwnPropertyDescriptors(e);delete n[E];let o=Reflect.ownKeys(n);for(let i=0;i<o.length;i++){let s=o[i],a=n[s];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(n[s]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[s]})}return Object.create(L(e),n)}else{let n=L(e);if(n!==null&&r)return De({},e);let o=Object.create(n);return Object.assign(o,e)}}function _e(e,t=!1){return ne(e)||F(e)||!N(e)||(ee(e)>1&&(e.set=e.add=e.clear=e.delete=Pt),Object.freeze(e),t&&Object.entries(e).forEach(([r,n])=>_e(n,!0))),e}function Pt(){x(2)}function ne(e){return Object.isFrozen(e)}var Mt={};function I(e){let t=Mt[e];return t||x(0,e),t}var U;function Ge(){return U}function kt(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Ne(e,t){t&&(I("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function he(e){ge(e),e.drafts_.forEach(Ct),e.drafts_=null}function ge(e){e===U&&(U=e.parent_)}function Ie(e){return U=kt(U,e)}function Ct(e){let t=e[E];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function $e(e,t){t.unfinalizedDrafts_=t.drafts_.length;let r=t.drafts_[0];return e!==void 0&&e!==r?(r[E].modified_&&(he(t),x(4)),N(e)&&(e=Q(t,e),t.parent_||Z(t,e)),t.patches_&&I("Patches").generateReplacementPatches_(r[E].base_,e,t.patches_,t.inversePatches_)):e=Q(t,r,[]),he(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Fe?e:void 0}function Q(e,t,r){if(ne(t))return t;let n=t[E];if(!n)return q(t,(o,i)=>Le(e,n,t,o,i,r)),t;if(n.scope_!==e)return t;if(!n.modified_)return Z(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;let o=n.copy_,i=o,s=!1;n.type_===3&&(i=new Set(o),o.clear(),s=!0),q(i,(a,l)=>Le(e,n,o,a,l,r,s)),Z(e,o,!1),r&&e.patches_&&I("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function Le(e,t,r,n,o,i,s){if(process.env.NODE_ENV!=="production"&&o===r&&x(5),F(o)){let a=i&&t&&t.type_!==3&&!pe(t.assigned_,n)?i.concat(n):void 0,l=Q(e,o,a);if(We(r,n,l),F(l))e.canAutoFreeze_=!1;else return}else s&&r.add(o);if(N(o)&&!ne(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;Q(e,o),(!t||!t.scope_.parent_)&&typeof n!="symbol"&&Object.prototype.propertyIsEnumerable.call(r,n)&&Z(e,o)}}function Z(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&_e(t,r)}function Ht(e,t){let r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:Ge(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=n,i=we;r&&(o=[n],i=X);let{revoke:s,proxy:a}=Proxy.revocable(o,i);return n.draft_=a,n.revoke_=s,a}var we={get(e,t){if(t===E)return e;let r=A(e);if(!pe(r,t))return Ot(e,r,t);let n=r[t];return e.finalized_||!N(n)?n:n===fe(e.base_,t)?(de(e),e.copy_[t]=be(n,e)):n},has(e,t){return t in A(e)},ownKeys(e){return Reflect.ownKeys(A(e))},set(e,t,r){let n=Je(A(e),t);if(n!=null&&n.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){let o=fe(A(e),t),i=o==null?void 0:o[E];if(i&&i.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(St(r,o)&&(r!==void 0||pe(e.base_,t)))return!0;de(e),ye(e)}return e.copy_[t]===r&&(r!==void 0||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty(e,t){return fe(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,de(e),ye(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let r=A(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:n.enumerable,value:r[t]}},defineProperty(){x(11)},getPrototypeOf(e){return L(e.base_)},setPrototypeOf(){x(12)}},X={};q(we,(e,t)=>{X[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});X.deleteProperty=function(e,t){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(t))&&x(13),X.set.call(this,e,t,void 0)};X.set=function(e,t,r){return process.env.NODE_ENV!=="production"&&t!=="length"&&isNaN(parseInt(t))&&x(14),we.set.call(this,e[0],t,r,e[0])};function fe(e,t){let r=e[E];return(r?A(r):e)[t]}function Ot(e,t,r){var o;let n=Je(t,r);return n?"value"in n?n.value:(o=n.get)==null?void 0:o.call(e.draft_):void 0}function Je(e,t){if(!(t in e))return;let r=L(e);for(;r;){let n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=L(r)}}function ye(e){e.modified_||(e.modified_=!0,e.parent_&&ye(e.parent_))}function de(e){e.copy_||(e.copy_=me(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var zt=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(t,r,n)=>{if(typeof t=="function"&&typeof r!="function"){let i=r;r=t;let s=this;return function(l=i,...u){return s.produce(l,d=>r.call(this,d,...u))}}typeof r!="function"&&x(6),n!==void 0&&typeof n!="function"&&x(7);let o;if(N(t)){let i=Ie(this),s=be(t,void 0),a=!0;try{o=r(s),a=!1}finally{a?he(i):ge(i)}return Ne(i,n),$e(o,i)}else if(!t||typeof t!="object"){if(o=r(t),o===void 0&&(o=t),o===Fe&&(o=void 0),this.autoFreeze_&&_e(o,!0),n){let i=[],s=[];I("Patches").generateReplacementPatches_(t,o,i,s),n(i,s)}return o}else x(1,t)},this.produceWithPatches=(t,r)=>{if(typeof t=="function")return(s,...a)=>this.produceWithPatches(s,l=>t(l,...a));let n,o;return[this.produce(t,r,(s,a)=>{n=s,o=a}),n,o]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){N(e)||x(8),F(e)&&(e=At(e));let t=Ie(this),r=be(e,void 0);return r[E].isManual_=!0,ge(t),r}finishDraft(e,t){let r=e&&e[E];(!r||!r.isManual_)&&x(9);let{scope_:n}=r;return Ne(n,t),$e(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){let o=t[r];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}r>-1&&(t=t.slice(r+1));let n=I("Patches").applyPatches_;return F(e)?n(e,t):this.produce(e,o=>n(o,t))}};function be(e,t){let r=te(e)?I("MapSet").proxyMap_(e,t):re(e)?I("MapSet").proxySet_(e,t):Ht(e,t);return(t?t.scope_:Ge()).drafts_.push(r),r}function At(e){return F(e)||x(10,e),Ue(e)}function Ue(e){if(!N(e)||ne(e))return e;let t=e[E],r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=me(e,t.scope_.immer_.useStrictShallowCopy_)}else r=me(e,!0);return q(r,(n,o)=>{We(r,n,Ue(o))}),t&&(t.finalized_=!1),r}var T=new zt,Xe=T.produce,Ur=T.produceWithPatches.bind(T),Xr=T.setAutoFreeze.bind(T),jr=T.setUseStrictShallowCopy.bind(T),Yr=T.applyPatches.bind(T),Kr=T.createDraft.bind(T),Vr=T.finishDraft.bind(T);var B=_react.createContext.call(void 0, {dragStarted:!1,setDragStarted:()=>{}});var oe=_react.createContext.call(void 0, {});var $t=(e,t)=>e.startTime-t.startTime<0||e.startTime===t.startTime&&e.endTime<t.endTime?-1:1,ie=$t;var Wt=_react.forwardRef.call(void 0, (e,t)=>{let{setEvents:r,tick:n,id:o,windowTime:i,cellWidth:s,children:a}=e,{dragStarted:l,setDragStarted:u}=_react.useContext.call(void 0, B),{onDrop:d}=_react.useContext.call(void 0, oe),p=_react.useCallback.call(void 0, f=>{f.preventDefault();let b=f.target,{left:m}=b.getBoundingClientRect(),g=f.dataTransfer.getData("eventId"),_=Math.round((f.clientX-m)/s),S=s*_;r(Xe(k=>{let c=k.find(v=>v.id===g);if(c&&n){let v=i[0]+S*n,C=c.endTime-c.startTime,R=i[0]+C+S*n;d&&d({eventId:c.id,oldRowId:c.rowId,newRowId:e.id,startTime:v,endTime:R}),c.startTime=v,c.endTime=R,c.rowId=e.id}k.sort(ie)})),u(!1)},[r,n,i,s]),y=_react.useContext.call(void 0, P),D=y&&y.rowsHeight&&y.rowsHeight[o]?y.rowsHeight[o].minHeight:40;return _react2.default.createElement("div",{id:`row_${o}`,ref:t,onDragOver:f=>f.preventDefault(),onDrop:p,className:l?"row-content not-clickable":"row-content","data-index":o,style:{minHeight:D}},a)}),je=Wt;var Jt=({id:e,startPosition:t,width:r,top:n,props:o})=>{let{setDragStarted:i}=_react.useContext.call(void 0, B),s=_react.useCallback.call(void 0, u=>{u.stopPropagation(),u.dataTransfer.setData("eventId",e),setTimeout(()=>i(!0),0);let d=u.target;d.style.opacity="50%"},[i]),a=_react.useCallback.call(void 0, u=>{u.stopPropagation(),i(!1);let d=u.target;d.style.opacity="100%"},[i]),l=o!=null&&o.classNames?"event "+o.classNames.join(" "):"event";return _react2.default.createElement("div",{id:`event_${e}`,key:`event_${e}`,className:l,draggable:!(o!=null&&o.isLocked),onDragStart:s,onDragEnd:a,onMouseDown:u=>u.stopPropagation(),onMouseMove:u=>u.stopPropagation(),onDrop:u=>u.stopPropagation(),style:{left:t,width:r,top:n,cursor:o!=null&&o.isLocked?"not-allowed":"pointer"}},_react2.default.createElement("div",{className:"event-content"},o!=null&&o.content?o.content:null))},Ve=Jt;var jt=({bodyRef:e,rowsContentRef:t})=>{let r=_react.useCallback.call(void 0, o=>{o.forEach(i=>{i.isIntersecting?i.target.classList.remove("row-hidden"):i.target.classList.add("row-hidden")})},[]),n=new IntersectionObserver(r,{root:e.current});_react.useEffect.call(void 0, ()=>(t.current&&t.current.forEach(o=>{n.observe(o)}),()=>n.disconnect()),[n])},qe=jt;var qt=({rows:e,windowTime:t,tick:r,events:n,staticEvents:o,cellWidth:i,setEvents:s,bodyRef:a})=>{let l=_react.useContext.call(void 0, P),u=_react.useRef.call(void 0, null),d=_react.useRef.call(void 0, []),[p,y]=_react.useMemo.call(void 0, ()=>{let D=0;return[e.map((f,b)=>{let m=0,g=[],_=0,S=r?n.filter(c=>c.rowId===f.id).map(c=>{if(c.endTime>=t[0]&&c.startTime<=t[1]){let v=0,C=!0;for(let R=0;R<=m;R++)if(g&&g[R]&&g[R].endTime>c.startTime)v+=1;else{m>_&&(_=m),m=0,C=!1;break}return C&&(m=v),g[v]=c,_react2.default.createElement(Ve,{key:`event_${c.id}`,id:c.id,startPosition:(c.startTime-t[0])/r,width:(c.endTime-c.startTime)/r,top:10+22*v,props:c.props})}}):null;m>_&&(_=m),u.current===null?u.current={[f.id]:{minHeight:40+_*22}}:u.current[f.id]={minHeight:40+_*22},D+=40+_*22;let k=r&&o?o.filter(c=>c.rowId===f.id).map(c=>{if(c.endTime>=t[0]&&c.startTime<=t[1])return _react2.default.createElement(ze,{key:`static_event_${c.id}`,id:c.id,startPosition:(c.startTime-t[0])/r,width:(c.endTime-c.startTime)/r,top:10,height:20+_*22})}):null;return _react2.default.createElement(_react2.default.Fragment,{key:`row_content_${f.id}`},_react2.default.createElement(je,{id:f.id,ref:c=>{d.current&&d.current[b]&&c?d.current[b]=c:d.current&&c&&d.current.push(c)},setEvents:s,tick:r,windowTime:t,cellWidth:i},S,k))}),D]},[e,n,r,t,i]);return qe({rowsContentRef:d,bodyRef:a}),_react.useEffect.call(void 0, ()=>{l&&(l.setRowsHeight(u.current),l.setAllRowsHeight(y))},[p,y]),p},Ze=qt;var rr=_react.forwardRef.call(void 0, ({rows:e,events:t,staticEvents:r,setEvents:n,tick:o,windowTime:i,cellWidth:s,setWindowTime:a,contentWidth:l,setCellWidth:u,bodyRef:d,lineClassName:p},y)=>{let[D,f]=_react.useState.call(void 0, !1),b=_react.useRef.call(void 0, null),[m,g]=_react.useState.call(void 0, !1),{blockWidth:_}=V({windowTime:i,contentWidth:l}),S=_react.useContext.call(void 0, P),k=_react.useCallback.call(void 0, h=>{if(h.preventDefault(),!D)return;let w=h.target,{left:z}=w.getBoundingClientRect(),H=h.clientX-z,Y=o?Math.floor(o*_):0;b.current&&b.current-H>=_?(b.current=H,a(J=>[J[0]+Y,J[1]+Y])):b.current&&H-b.current>=_&&(b.current=H,a(J=>[J[0]-Y,J[1]-Y]))},[_,a,D]),c=_react.useCallback.call(void 0, h=>{f(!0),h.button===1&&h.preventDefault();let w=h.target,{left:z}=w.getBoundingClientRect();b.current=h.clientX-z},[f]),v=_react.useCallback.call(void 0, ()=>{f(!1)},[f]),C=_react.useCallback.call(void 0, ()=>f(!1),[f]),R=Ze({rows:e,windowTime:i,tick:o,events:t,staticEvents:r,cellWidth:s,setEvents:n,bodyRef:d}),ae=_react.useCallback.call(void 0, h=>{h.preventDefault(),h.button===1&&g(w=>!w)},[]),ce=_react.useCallback.call(void 0, h=>{let w=o?900/o:0;m&&u(z=>{let H=h.deltaY>0?z+w:z-w;return H<w||H>w*12?z:H})},[m,s,o]);return _react.useEffect.call(void 0, ()=>{d.current&&(d.current.style.overflow=m?"hidden":"auto")},[m]),_react2.default.createElement("div",{key:"content",ref:y,className:"content-wrapper",onMouseDown:c,onMouseUp:v,onMouseMove:k,onMouseLeave:C,onAuxClick:ae,onWheel:ce,style:{cursor:D?"grabbing":"grab",height:S==null?void 0:S.allRowsHeight}},_react2.default.createElement(Oe,{contentWidth:l,cellWidth:s,lineClassName:p}),R)}),rt=rr;var sr=({windowTime:e,setTick:t,setCellWidth:r,contentRef:n})=>{let o=_react.useRef.call(void 0, 0),i=_react.useMemo.call(void 0, ()=>new ResizeObserver(s=>{var a;for(let l of s){let u=(a=l.borderBoxSize)==null?void 0:a[0].inlineSize;if(typeof u=="number"&&u!==o.current){o.current=u;let d=e[1]-e[0],p=d/3600;t(d/l.contentRect.width),r(l.contentRect.width/p)}}}),[e]);_react.useEffect.call(void 0, ()=>(n.current&&i.observe(n.current,{box:"border-box"}),()=>i.disconnect()),[i])},nt=sr;var lr=({tick:e,windowTime:t})=>{let[r,n]=_react.useState.call(void 0, new Date().getTime()/1e3),[o,i]=_react.useState.call(void 0, 0),s=_react.useRef.call(void 0, null);return _react.useEffect.call(void 0, ()=>{if(e){let a=r-t[0];i(Math.round(a/e)),s.current!==null&&clearInterval(s.current);let l=setInterval(()=>{n(new Date().getTime()/1e3)},e*1e3);s.current=l}},[e,t,r]),_react2.default.createElement(_react2.default.Fragment,null,t[0]<=r&&r<=t[1]&&_react2.default.createElement(_react2.default.Fragment,null,_react2.default.createElement("div",{className:"rt-arrow",style:{left:86+o}}),_react2.default.createElement("div",{className:"rt-line",style:{left:100+o}})))},it=lr;var Qn=({rows:e,events:t,staticEvents:r,onDrop:n,startDate:o,endDate:i,additionalClassNames:s,showRTIndicator:a=!0})=>{let[l,u]=_react.useState.call(void 0, [new Date(o.getFullYear(),o.getMonth(),o.getDate(),o.getHours(),0,0).getTime()/1e3,new Date(i.getFullYear(),i.getMonth(),i.getDate(),i.getHours(),0,0).getTime()/1e3]),[d,p]=_react.useState.call(void 0, 0),[y,D]=_react.useState.call(void 0, []),f=_react.useRef.call(void 0, null),b=_react.useRef.call(void 0, null),m=_react.useRef.call(void 0, null),[g,_]=_react.useState.call(void 0, null),[S,k]=_react.useState.call(void 0, 0),[c,v]=_react.useState.call(void 0, null),[C,R]=_react.useState.call(void 0, 0);_react.useEffect.call(void 0, ()=>{if(f.current){let h=l[1]-l[0],w=h/3600;_(h/f.current.getBoundingClientRect().width),p(f.current.getBoundingClientRect().width/w)}},[]),_react.useEffect.call(void 0, ()=>{m.current&&k(m.current.getBoundingClientRect().width-m.current.scrollWidth)},[]),_react.useEffect.call(void 0, ()=>{D(t.sort(ie))},[t]);let[ae,ce]=_react.useState.call(void 0, !1);return _react.useEffect.call(void 0, ()=>{let h=null;e.forEach(w=>{h===null?h={[w.id]:{minHeight:40}}:h[w.id]={minHeight:40}}),v(h)},[e]),nt({contentRef:f,setCellWidth:p,setTick:_,windowTime:l}),_react2.default.createElement("div",{className:"main-wrapper",ref:b},a&&_react2.default.createElement(it,{tick:g,windowTime:l}),_react2.default.createElement(Se,{windowTime:l,tick:g,contentWidth:f.current?f.current.getBoundingClientRect().width:null,scrollWidth:S}),_react2.default.createElement("div",{className:"body-wrapper",ref:m},_react2.default.createElement(P.Provider,{value:{rowsHeight:c,setRowsHeight:v,allRowsHeight:C,setAllRowsHeight:R}},_react2.default.createElement(ke,{rows:e,className:s==null?void 0:s.rowsHeader}),_react2.default.createElement(B.Provider,{value:{dragStarted:ae,setDragStarted:ce}},_react2.default.createElement(oe.Provider,{value:{onDrop:n}},_react2.default.createElement(rt,{events:y,staticEvents:r,rows:e,setEvents:D,tick:g,windowTime:l,cellWidth:d,setWindowTime:u,ref:f,setCellWidth:p,contentWidth:f.current?f.current.getBoundingClientRect().width:null,bodyRef:m,lineClassName:s==null?void 0:s.gridLine}))))))};exports.Timeline = Qn;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
+
mod
|
|
41
|
+
));
|
|
42
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
|
+
|
|
44
|
+
// src/index.ts
|
|
45
|
+
var src_exports = {};
|
|
46
|
+
__export(src_exports, {
|
|
47
|
+
Timeline: () => Timeline
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(src_exports);
|
|
50
|
+
|
|
51
|
+
// src/timeline.tsx
|
|
52
|
+
var import_react21 = __toESM(require("react"));
|
|
53
|
+
|
|
54
|
+
// src/components/time-bar.tsx
|
|
55
|
+
var import_react4 = __toESM(require("react"));
|
|
56
|
+
|
|
57
|
+
// src/hooks/use-generate-blocks.tsx
|
|
58
|
+
var import_react = __toESM(require("react"));
|
|
59
|
+
var import_react2 = require("react");
|
|
60
|
+
|
|
61
|
+
// src/helpers/get-month-name.ts
|
|
62
|
+
var getMonthName = (monthIndex) => {
|
|
63
|
+
let monthName = null;
|
|
64
|
+
switch (monthIndex) {
|
|
65
|
+
case 0:
|
|
66
|
+
monthName = "Jan";
|
|
67
|
+
break;
|
|
68
|
+
case 1:
|
|
69
|
+
monthName = "Feb";
|
|
70
|
+
break;
|
|
71
|
+
case 2:
|
|
72
|
+
monthName = "Mar";
|
|
73
|
+
break;
|
|
74
|
+
case 3:
|
|
75
|
+
monthName = "Apr";
|
|
76
|
+
break;
|
|
77
|
+
case 4:
|
|
78
|
+
monthName = "May";
|
|
79
|
+
break;
|
|
80
|
+
case 5:
|
|
81
|
+
monthName = "Jun";
|
|
82
|
+
break;
|
|
83
|
+
case 6:
|
|
84
|
+
monthName = "Jul";
|
|
85
|
+
break;
|
|
86
|
+
case 7:
|
|
87
|
+
monthName = "Aug";
|
|
88
|
+
break;
|
|
89
|
+
case 8:
|
|
90
|
+
monthName = "Sep";
|
|
91
|
+
break;
|
|
92
|
+
case 9:
|
|
93
|
+
monthName = "Oct";
|
|
94
|
+
break;
|
|
95
|
+
case 10:
|
|
96
|
+
monthName = "Nov";
|
|
97
|
+
break;
|
|
98
|
+
case 11:
|
|
99
|
+
monthName = "Dec";
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
monthName = "Jan";
|
|
103
|
+
}
|
|
104
|
+
return monthName;
|
|
105
|
+
};
|
|
106
|
+
var get_month_name_default = getMonthName;
|
|
107
|
+
|
|
108
|
+
// src/helpers/get-week-day-name.ts
|
|
109
|
+
var getWeekDayName = (dayIndex) => {
|
|
110
|
+
let dayName = null;
|
|
111
|
+
switch (dayIndex) {
|
|
112
|
+
case 0:
|
|
113
|
+
dayName = "Mon";
|
|
114
|
+
break;
|
|
115
|
+
case 1:
|
|
116
|
+
dayName = "Tue";
|
|
117
|
+
break;
|
|
118
|
+
case 2:
|
|
119
|
+
dayName = "Wed";
|
|
120
|
+
break;
|
|
121
|
+
case 3:
|
|
122
|
+
dayName = "Thu";
|
|
123
|
+
break;
|
|
124
|
+
case 4:
|
|
125
|
+
dayName = "Fri";
|
|
126
|
+
break;
|
|
127
|
+
case 5:
|
|
128
|
+
dayName = "Sat";
|
|
129
|
+
break;
|
|
130
|
+
case 6:
|
|
131
|
+
dayName = "Sun";
|
|
132
|
+
break;
|
|
133
|
+
default:
|
|
134
|
+
dayName = "Mon";
|
|
135
|
+
}
|
|
136
|
+
return dayName;
|
|
137
|
+
};
|
|
138
|
+
var get_week_day_name_default = getWeekDayName;
|
|
139
|
+
|
|
140
|
+
// src/hooks/use-generate-blocks.tsx
|
|
141
|
+
var useGenerateBlocks = ({
|
|
142
|
+
windowTime,
|
|
143
|
+
tick,
|
|
144
|
+
contentWidth,
|
|
145
|
+
blockWidth
|
|
146
|
+
}) => {
|
|
147
|
+
const { dayBlocks, hourBlocks } = (0, import_react2.useMemo)(() => {
|
|
148
|
+
let timePoint = windowTime[0];
|
|
149
|
+
const dayBlocks2 = [];
|
|
150
|
+
const hourBlocks2 = [];
|
|
151
|
+
if (tick === null || contentWidth === null) {
|
|
152
|
+
return { dayBlocks: [], hourBlocks: [] };
|
|
153
|
+
}
|
|
154
|
+
let widthLeft = contentWidth;
|
|
155
|
+
let prevNumBlocks = 1;
|
|
156
|
+
while (1) {
|
|
157
|
+
let datePoint = new Date(timePoint * 1e3);
|
|
158
|
+
const endDatePoint = new Date(
|
|
159
|
+
datePoint.getFullYear(),
|
|
160
|
+
datePoint.getMonth(),
|
|
161
|
+
datePoint.getDate(),
|
|
162
|
+
23,
|
|
163
|
+
59,
|
|
164
|
+
59
|
|
165
|
+
);
|
|
166
|
+
const dateDuration = endDatePoint.getTime() - datePoint.getTime();
|
|
167
|
+
const dateWidth = dateDuration / 1e3 / tick;
|
|
168
|
+
widthLeft -= dateWidth;
|
|
169
|
+
if (Math.round(widthLeft) < 0) {
|
|
170
|
+
const numBlocks2 = Math.round((dateWidth + widthLeft) / blockWidth);
|
|
171
|
+
for (let i = 0; i < numBlocks2; i++) {
|
|
172
|
+
hourBlocks2.push(
|
|
173
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
174
|
+
"div",
|
|
175
|
+
{
|
|
176
|
+
className: "hour-block",
|
|
177
|
+
key: `${datePoint.getDate()}_hour_${i}`
|
|
178
|
+
},
|
|
179
|
+
i < 10 ? `0${i}:00` : `${i}:00`
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
dayBlocks2.push(
|
|
184
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
185
|
+
"div",
|
|
186
|
+
{
|
|
187
|
+
className: "day-block",
|
|
188
|
+
key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
|
|
189
|
+
style: {
|
|
190
|
+
gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks2}`
|
|
191
|
+
// width: dateWidth + widthLeft,
|
|
192
|
+
// minWidth: dateWidth + widthLeft,
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
get_week_day_name_default(datePoint.getDay()),
|
|
196
|
+
" ",
|
|
197
|
+
datePoint.getDate(),
|
|
198
|
+
" ",
|
|
199
|
+
get_month_name_default(datePoint.getMonth())
|
|
200
|
+
)
|
|
201
|
+
);
|
|
202
|
+
prevNumBlocks += numBlocks2;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
const numBlocks = Math.round(dateWidth / blockWidth);
|
|
206
|
+
for (let i = 24 - numBlocks; i < 24; i++) {
|
|
207
|
+
hourBlocks2.push(
|
|
208
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: "hour-block", key: `${datePoint.getDate()}_hour_${i}` }, i < 10 ? `0${i}:00` : `${i}:00`)
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
dayBlocks2.push(
|
|
212
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
213
|
+
"div",
|
|
214
|
+
{
|
|
215
|
+
className: "day-block",
|
|
216
|
+
key: `${datePoint.getDate()} ${datePoint.getMonth()}`,
|
|
217
|
+
style: {
|
|
218
|
+
gridColumn: `${prevNumBlocks} / ${prevNumBlocks + numBlocks}`
|
|
219
|
+
// width: dateWidth,
|
|
220
|
+
// minWidth: dateWidth,
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
get_week_day_name_default(datePoint.getDay()),
|
|
224
|
+
" ",
|
|
225
|
+
datePoint.getDate(),
|
|
226
|
+
" ",
|
|
227
|
+
get_month_name_default(datePoint.getMonth())
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
prevNumBlocks += numBlocks;
|
|
231
|
+
if (Math.round(widthLeft) === 0) {
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
timePoint = (endDatePoint.getTime() + 1e3) / 1e3;
|
|
235
|
+
}
|
|
236
|
+
return { dayBlocks: dayBlocks2, hourBlocks: hourBlocks2 };
|
|
237
|
+
}, [tick, windowTime, contentWidth]);
|
|
238
|
+
return { dayBlocks, hourBlocks };
|
|
239
|
+
};
|
|
240
|
+
var use_generate_blocks_default = useGenerateBlocks;
|
|
241
|
+
|
|
242
|
+
// src/hooks/use-get-block-properties.ts
|
|
243
|
+
var import_react3 = require("react");
|
|
244
|
+
var useGetBlockProperties = ({
|
|
245
|
+
windowTime,
|
|
246
|
+
contentWidth
|
|
247
|
+
}) => {
|
|
248
|
+
const numberOfHourBlocks = (0, import_react3.useMemo)(
|
|
249
|
+
() => (windowTime[1] - windowTime[0]) / 3600,
|
|
250
|
+
[windowTime]
|
|
251
|
+
);
|
|
252
|
+
const blockWidth = contentWidth ? contentWidth / numberOfHourBlocks : 0;
|
|
253
|
+
return { numberOfHourBlocks, blockWidth };
|
|
254
|
+
};
|
|
255
|
+
var use_get_block_properties_default = useGetBlockProperties;
|
|
256
|
+
|
|
257
|
+
// src/components/time-bar.tsx
|
|
258
|
+
var TimeBar = ({
|
|
259
|
+
windowTime,
|
|
260
|
+
tick,
|
|
261
|
+
contentWidth,
|
|
262
|
+
scrollWidth,
|
|
263
|
+
additionalClassNames
|
|
264
|
+
}) => {
|
|
265
|
+
const timeContentRef = (0, import_react4.useRef)(null);
|
|
266
|
+
const { blockWidth } = use_get_block_properties_default({
|
|
267
|
+
windowTime,
|
|
268
|
+
contentWidth
|
|
269
|
+
});
|
|
270
|
+
const { dayBlocks, hourBlocks } = use_generate_blocks_default({
|
|
271
|
+
windowTime,
|
|
272
|
+
tick,
|
|
273
|
+
contentWidth,
|
|
274
|
+
blockWidth
|
|
275
|
+
});
|
|
276
|
+
const timeBarClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.timeBar) ? "time-bar " + additionalClassNames.timeBar : "time-bar";
|
|
277
|
+
const dayRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.dayRow) ? "day-row " + additionalClassNames.dayRow : "day-row";
|
|
278
|
+
const hourRowClassNames = (additionalClassNames == null ? void 0 : additionalClassNames.hourRow) ? "hour-row " + additionalClassNames.hourRow : "hour-row";
|
|
279
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", { className: timeBarClassNames }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "empty-block" }), /* @__PURE__ */ import_react4.default.createElement(
|
|
280
|
+
"div",
|
|
281
|
+
{
|
|
282
|
+
className: "time-content",
|
|
283
|
+
ref: timeContentRef,
|
|
284
|
+
style: { minWidth: contentWidth ? contentWidth : 0 }
|
|
285
|
+
},
|
|
286
|
+
/* @__PURE__ */ import_react4.default.createElement(
|
|
287
|
+
"div",
|
|
288
|
+
{
|
|
289
|
+
className: dayRowClassNames,
|
|
290
|
+
style: {
|
|
291
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
dayBlocks.map((block) => block)
|
|
295
|
+
),
|
|
296
|
+
/* @__PURE__ */ import_react4.default.createElement(
|
|
297
|
+
"div",
|
|
298
|
+
{
|
|
299
|
+
className: hourRowClassNames,
|
|
300
|
+
style: {
|
|
301
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${blockWidth}px, 1fr))`
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
hourBlocks.map((block) => block)
|
|
305
|
+
)
|
|
306
|
+
), scrollWidth ? /* @__PURE__ */ import_react4.default.createElement(
|
|
307
|
+
"div",
|
|
308
|
+
{
|
|
309
|
+
style: {
|
|
310
|
+
width: scrollWidth,
|
|
311
|
+
height: "100%",
|
|
312
|
+
boxSizing: "border-box",
|
|
313
|
+
borderLeft: "1px solid yellow"
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
) : null);
|
|
317
|
+
};
|
|
318
|
+
var time_bar_default = TimeBar;
|
|
319
|
+
|
|
320
|
+
// src/components/rows-header.tsx
|
|
321
|
+
var import_react7 = __toESM(require("react"));
|
|
322
|
+
|
|
323
|
+
// src/components/row-header.tsx
|
|
324
|
+
var import_react6 = __toESM(require("react"));
|
|
325
|
+
|
|
326
|
+
// src/contexts/row-height-context.ts
|
|
327
|
+
var import_react5 = require("react");
|
|
328
|
+
var RowsHeightContext = (0, import_react5.createContext)(
|
|
329
|
+
null
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
// src/components/row-header.tsx
|
|
333
|
+
var RowHeader = ({ name, id }) => {
|
|
334
|
+
const rowsHeightContext = (0, import_react6.useContext)(RowsHeightContext);
|
|
335
|
+
const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
|
|
336
|
+
return /* @__PURE__ */ import_react6.default.createElement("div", { className: "row-header", style: { minHeight } }, name);
|
|
337
|
+
};
|
|
338
|
+
var row_header_default = RowHeader;
|
|
339
|
+
|
|
340
|
+
// src/components/rows-header.tsx
|
|
341
|
+
var RowsHeader = ({
|
|
342
|
+
rows,
|
|
343
|
+
className
|
|
344
|
+
}) => {
|
|
345
|
+
const classNames = className ? "rows-header-wrapper " + className : "rows-header-wrapper";
|
|
346
|
+
return /* @__PURE__ */ import_react7.default.createElement("div", { className: classNames }, rows.map((row) => /* @__PURE__ */ import_react7.default.createElement(
|
|
347
|
+
row_header_default,
|
|
348
|
+
{
|
|
349
|
+
key: `row_header_${row.id}`,
|
|
350
|
+
id: row.id,
|
|
351
|
+
name: row.name
|
|
352
|
+
}
|
|
353
|
+
)));
|
|
354
|
+
};
|
|
355
|
+
var rows_header_default = RowsHeader;
|
|
356
|
+
|
|
357
|
+
// src/components/content.tsx
|
|
358
|
+
var import_react18 = __toESM(require("react"));
|
|
359
|
+
|
|
360
|
+
// src/components/lines-canvas.tsx
|
|
361
|
+
var import_react8 = __toESM(require("react"));
|
|
362
|
+
var import_react9 = require("react");
|
|
363
|
+
var LinesCanvas = ({
|
|
364
|
+
contentWidth,
|
|
365
|
+
cellWidth,
|
|
366
|
+
lineClassName
|
|
367
|
+
}) => {
|
|
368
|
+
const lines = (0, import_react9.useMemo)(() => {
|
|
369
|
+
const lines2 = [];
|
|
370
|
+
const classNames = lineClassName ? "line " + lineClassName : "line";
|
|
371
|
+
if (contentWidth) {
|
|
372
|
+
for (let i = cellWidth; i < contentWidth; i = i + cellWidth) {
|
|
373
|
+
lines2.push(/* @__PURE__ */ import_react8.default.createElement("div", { key: `line_${i}`, className: classNames }));
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return lines2;
|
|
377
|
+
}, [cellWidth, contentWidth]);
|
|
378
|
+
const minWidth = (0, import_react9.useMemo)(() => {
|
|
379
|
+
return contentWidth ? contentWidth - lines.length * cellWidth : 0;
|
|
380
|
+
}, [contentWidth, cellWidth, lines]);
|
|
381
|
+
return /* @__PURE__ */ import_react8.default.createElement(
|
|
382
|
+
"div",
|
|
383
|
+
{
|
|
384
|
+
className: minWidth < 1 ? "lines-canvas hide-last-line" : "lines-canvas",
|
|
385
|
+
style: minWidth < 1 ? {
|
|
386
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${cellWidth}px, 1fr))`
|
|
387
|
+
} : {
|
|
388
|
+
gridTemplateColumns: `repeat(auto-fill, minmax(${minWidth}px, ${cellWidth}px))`
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
lines
|
|
392
|
+
);
|
|
393
|
+
};
|
|
394
|
+
var lines_canvas_default = LinesCanvas;
|
|
395
|
+
|
|
396
|
+
// src/hooks/use-produce-content.tsx
|
|
397
|
+
var import_react16 = require("react");
|
|
398
|
+
var import_react17 = __toESM(require("react"));
|
|
399
|
+
|
|
400
|
+
// src/components/static-event.tsx
|
|
401
|
+
var import_react10 = __toESM(require("react"));
|
|
402
|
+
var StaticEvent = ({
|
|
403
|
+
id,
|
|
404
|
+
startPosition,
|
|
405
|
+
width,
|
|
406
|
+
top,
|
|
407
|
+
height
|
|
408
|
+
}) => {
|
|
409
|
+
return /* @__PURE__ */ import_react10.default.createElement(
|
|
410
|
+
"div",
|
|
411
|
+
{
|
|
412
|
+
id: `static_event_${id}`,
|
|
413
|
+
key: `static_event_${id}`,
|
|
414
|
+
className: "static-event",
|
|
415
|
+
onDrop: (event) => event.stopPropagation(),
|
|
416
|
+
style: {
|
|
417
|
+
left: startPosition,
|
|
418
|
+
width,
|
|
419
|
+
top,
|
|
420
|
+
minHeight: height
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
};
|
|
425
|
+
var static_event_default = StaticEvent;
|
|
426
|
+
|
|
427
|
+
// src/components/row-content.tsx
|
|
428
|
+
var import_react13 = __toESM(require("react"));
|
|
429
|
+
|
|
430
|
+
// node_modules/immer/dist/immer.mjs
|
|
431
|
+
var NOTHING = Symbol.for("immer-nothing");
|
|
432
|
+
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
433
|
+
var DRAFT_STATE = Symbol.for("immer-state");
|
|
434
|
+
var errors = process.env.NODE_ENV !== "production" ? [
|
|
435
|
+
// All error codes, starting by 0:
|
|
436
|
+
function(plugin) {
|
|
437
|
+
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
438
|
+
},
|
|
439
|
+
function(thing) {
|
|
440
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
441
|
+
},
|
|
442
|
+
"This object has been frozen and should not be mutated",
|
|
443
|
+
function(data) {
|
|
444
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
445
|
+
},
|
|
446
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
447
|
+
"Immer forbids circular references",
|
|
448
|
+
"The first or second argument to `produce` must be a function",
|
|
449
|
+
"The third argument to `produce` must be a function or undefined",
|
|
450
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
451
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
452
|
+
function(thing) {
|
|
453
|
+
return `'current' expects a draft, got: ${thing}`;
|
|
454
|
+
},
|
|
455
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
456
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
457
|
+
"Immer only supports deleting array indices",
|
|
458
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
459
|
+
function(thing) {
|
|
460
|
+
return `'original' expects a draft, got: ${thing}`;
|
|
461
|
+
}
|
|
462
|
+
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
463
|
+
// See Patches.ts for additional errors
|
|
464
|
+
] : [];
|
|
465
|
+
function die(error, ...args) {
|
|
466
|
+
if (process.env.NODE_ENV !== "production") {
|
|
467
|
+
const e = errors[error];
|
|
468
|
+
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
469
|
+
throw new Error(`[Immer] ${msg}`);
|
|
470
|
+
}
|
|
471
|
+
throw new Error(
|
|
472
|
+
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
476
|
+
function isDraft(value) {
|
|
477
|
+
return !!value && !!value[DRAFT_STATE];
|
|
478
|
+
}
|
|
479
|
+
function isDraftable(value) {
|
|
480
|
+
var _a;
|
|
481
|
+
if (!value)
|
|
482
|
+
return false;
|
|
483
|
+
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_a = value.constructor) == null ? void 0 : _a[DRAFTABLE]) || isMap(value) || isSet(value);
|
|
484
|
+
}
|
|
485
|
+
var objectCtorString = Object.prototype.constructor.toString();
|
|
486
|
+
function isPlainObject(value) {
|
|
487
|
+
if (!value || typeof value !== "object")
|
|
488
|
+
return false;
|
|
489
|
+
const proto = getPrototypeOf(value);
|
|
490
|
+
if (proto === null) {
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
494
|
+
if (Ctor === Object)
|
|
495
|
+
return true;
|
|
496
|
+
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
497
|
+
}
|
|
498
|
+
function each(obj, iter) {
|
|
499
|
+
if (getArchtype(obj) === 0) {
|
|
500
|
+
Reflect.ownKeys(obj).forEach((key) => {
|
|
501
|
+
iter(key, obj[key], obj);
|
|
502
|
+
});
|
|
503
|
+
} else {
|
|
504
|
+
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
function getArchtype(thing) {
|
|
508
|
+
const state = thing[DRAFT_STATE];
|
|
509
|
+
return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
510
|
+
}
|
|
511
|
+
function has(thing, prop) {
|
|
512
|
+
return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
513
|
+
}
|
|
514
|
+
function set(thing, propOrOldValue, value) {
|
|
515
|
+
const t = getArchtype(thing);
|
|
516
|
+
if (t === 2)
|
|
517
|
+
thing.set(propOrOldValue, value);
|
|
518
|
+
else if (t === 3) {
|
|
519
|
+
thing.add(value);
|
|
520
|
+
} else
|
|
521
|
+
thing[propOrOldValue] = value;
|
|
522
|
+
}
|
|
523
|
+
function is(x, y) {
|
|
524
|
+
if (x === y) {
|
|
525
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
526
|
+
} else {
|
|
527
|
+
return x !== x && y !== y;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function isMap(target) {
|
|
531
|
+
return target instanceof Map;
|
|
532
|
+
}
|
|
533
|
+
function isSet(target) {
|
|
534
|
+
return target instanceof Set;
|
|
535
|
+
}
|
|
536
|
+
function latest(state) {
|
|
537
|
+
return state.copy_ || state.base_;
|
|
538
|
+
}
|
|
539
|
+
function shallowCopy(base, strict) {
|
|
540
|
+
if (isMap(base)) {
|
|
541
|
+
return new Map(base);
|
|
542
|
+
}
|
|
543
|
+
if (isSet(base)) {
|
|
544
|
+
return new Set(base);
|
|
545
|
+
}
|
|
546
|
+
if (Array.isArray(base))
|
|
547
|
+
return Array.prototype.slice.call(base);
|
|
548
|
+
const isPlain = isPlainObject(base);
|
|
549
|
+
if (strict === true || strict === "class_only" && !isPlain) {
|
|
550
|
+
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
551
|
+
delete descriptors[DRAFT_STATE];
|
|
552
|
+
let keys = Reflect.ownKeys(descriptors);
|
|
553
|
+
for (let i = 0; i < keys.length; i++) {
|
|
554
|
+
const key = keys[i];
|
|
555
|
+
const desc = descriptors[key];
|
|
556
|
+
if (desc.writable === false) {
|
|
557
|
+
desc.writable = true;
|
|
558
|
+
desc.configurable = true;
|
|
559
|
+
}
|
|
560
|
+
if (desc.get || desc.set)
|
|
561
|
+
descriptors[key] = {
|
|
562
|
+
configurable: true,
|
|
563
|
+
writable: true,
|
|
564
|
+
// could live with !!desc.set as well here...
|
|
565
|
+
enumerable: desc.enumerable,
|
|
566
|
+
value: base[key]
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
return Object.create(getPrototypeOf(base), descriptors);
|
|
570
|
+
} else {
|
|
571
|
+
const proto = getPrototypeOf(base);
|
|
572
|
+
if (proto !== null && isPlain) {
|
|
573
|
+
return __spreadValues({}, base);
|
|
574
|
+
}
|
|
575
|
+
const obj = Object.create(proto);
|
|
576
|
+
return Object.assign(obj, base);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function freeze(obj, deep = false) {
|
|
580
|
+
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
581
|
+
return obj;
|
|
582
|
+
if (getArchtype(obj) > 1) {
|
|
583
|
+
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
|
|
584
|
+
}
|
|
585
|
+
Object.freeze(obj);
|
|
586
|
+
if (deep)
|
|
587
|
+
Object.entries(obj).forEach(([key, value]) => freeze(value, true));
|
|
588
|
+
return obj;
|
|
589
|
+
}
|
|
590
|
+
function dontMutateFrozenCollections() {
|
|
591
|
+
die(2);
|
|
592
|
+
}
|
|
593
|
+
function isFrozen(obj) {
|
|
594
|
+
return Object.isFrozen(obj);
|
|
595
|
+
}
|
|
596
|
+
var plugins = {};
|
|
597
|
+
function getPlugin(pluginKey) {
|
|
598
|
+
const plugin = plugins[pluginKey];
|
|
599
|
+
if (!plugin) {
|
|
600
|
+
die(0, pluginKey);
|
|
601
|
+
}
|
|
602
|
+
return plugin;
|
|
603
|
+
}
|
|
604
|
+
var currentScope;
|
|
605
|
+
function getCurrentScope() {
|
|
606
|
+
return currentScope;
|
|
607
|
+
}
|
|
608
|
+
function createScope(parent_, immer_) {
|
|
609
|
+
return {
|
|
610
|
+
drafts_: [],
|
|
611
|
+
parent_,
|
|
612
|
+
immer_,
|
|
613
|
+
// Whenever the modified draft contains a draft from another scope, we
|
|
614
|
+
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
615
|
+
canAutoFreeze_: true,
|
|
616
|
+
unfinalizedDrafts_: 0
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function usePatchesInScope(scope, patchListener) {
|
|
620
|
+
if (patchListener) {
|
|
621
|
+
getPlugin("Patches");
|
|
622
|
+
scope.patches_ = [];
|
|
623
|
+
scope.inversePatches_ = [];
|
|
624
|
+
scope.patchListener_ = patchListener;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function revokeScope(scope) {
|
|
628
|
+
leaveScope(scope);
|
|
629
|
+
scope.drafts_.forEach(revokeDraft);
|
|
630
|
+
scope.drafts_ = null;
|
|
631
|
+
}
|
|
632
|
+
function leaveScope(scope) {
|
|
633
|
+
if (scope === currentScope) {
|
|
634
|
+
currentScope = scope.parent_;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function enterScope(immer2) {
|
|
638
|
+
return currentScope = createScope(currentScope, immer2);
|
|
639
|
+
}
|
|
640
|
+
function revokeDraft(draft) {
|
|
641
|
+
const state = draft[DRAFT_STATE];
|
|
642
|
+
if (state.type_ === 0 || state.type_ === 1)
|
|
643
|
+
state.revoke_();
|
|
644
|
+
else
|
|
645
|
+
state.revoked_ = true;
|
|
646
|
+
}
|
|
647
|
+
function processResult(result, scope) {
|
|
648
|
+
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
649
|
+
const baseDraft = scope.drafts_[0];
|
|
650
|
+
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
651
|
+
if (isReplaced) {
|
|
652
|
+
if (baseDraft[DRAFT_STATE].modified_) {
|
|
653
|
+
revokeScope(scope);
|
|
654
|
+
die(4);
|
|
655
|
+
}
|
|
656
|
+
if (isDraftable(result)) {
|
|
657
|
+
result = finalize(scope, result);
|
|
658
|
+
if (!scope.parent_)
|
|
659
|
+
maybeFreeze(scope, result);
|
|
660
|
+
}
|
|
661
|
+
if (scope.patches_) {
|
|
662
|
+
getPlugin("Patches").generateReplacementPatches_(
|
|
663
|
+
baseDraft[DRAFT_STATE].base_,
|
|
664
|
+
result,
|
|
665
|
+
scope.patches_,
|
|
666
|
+
scope.inversePatches_
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
} else {
|
|
670
|
+
result = finalize(scope, baseDraft, []);
|
|
671
|
+
}
|
|
672
|
+
revokeScope(scope);
|
|
673
|
+
if (scope.patches_) {
|
|
674
|
+
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
675
|
+
}
|
|
676
|
+
return result !== NOTHING ? result : void 0;
|
|
677
|
+
}
|
|
678
|
+
function finalize(rootScope, value, path) {
|
|
679
|
+
if (isFrozen(value))
|
|
680
|
+
return value;
|
|
681
|
+
const state = value[DRAFT_STATE];
|
|
682
|
+
if (!state) {
|
|
683
|
+
each(
|
|
684
|
+
value,
|
|
685
|
+
(key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path)
|
|
686
|
+
);
|
|
687
|
+
return value;
|
|
688
|
+
}
|
|
689
|
+
if (state.scope_ !== rootScope)
|
|
690
|
+
return value;
|
|
691
|
+
if (!state.modified_) {
|
|
692
|
+
maybeFreeze(rootScope, state.base_, true);
|
|
693
|
+
return state.base_;
|
|
694
|
+
}
|
|
695
|
+
if (!state.finalized_) {
|
|
696
|
+
state.finalized_ = true;
|
|
697
|
+
state.scope_.unfinalizedDrafts_--;
|
|
698
|
+
const result = state.copy_;
|
|
699
|
+
let resultEach = result;
|
|
700
|
+
let isSet2 = false;
|
|
701
|
+
if (state.type_ === 3) {
|
|
702
|
+
resultEach = new Set(result);
|
|
703
|
+
result.clear();
|
|
704
|
+
isSet2 = true;
|
|
705
|
+
}
|
|
706
|
+
each(
|
|
707
|
+
resultEach,
|
|
708
|
+
(key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2)
|
|
709
|
+
);
|
|
710
|
+
maybeFreeze(rootScope, result, false);
|
|
711
|
+
if (path && rootScope.patches_) {
|
|
712
|
+
getPlugin("Patches").generatePatches_(
|
|
713
|
+
state,
|
|
714
|
+
path,
|
|
715
|
+
rootScope.patches_,
|
|
716
|
+
rootScope.inversePatches_
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return state.copy_;
|
|
721
|
+
}
|
|
722
|
+
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
723
|
+
if (process.env.NODE_ENV !== "production" && childValue === targetObject)
|
|
724
|
+
die(5);
|
|
725
|
+
if (isDraft(childValue)) {
|
|
726
|
+
const path = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
|
|
727
|
+
!has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
|
|
728
|
+
const res = finalize(rootScope, childValue, path);
|
|
729
|
+
set(targetObject, prop, res);
|
|
730
|
+
if (isDraft(res)) {
|
|
731
|
+
rootScope.canAutoFreeze_ = false;
|
|
732
|
+
} else
|
|
733
|
+
return;
|
|
734
|
+
} else if (targetIsSet) {
|
|
735
|
+
targetObject.add(childValue);
|
|
736
|
+
}
|
|
737
|
+
if (isDraftable(childValue) && !isFrozen(childValue)) {
|
|
738
|
+
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
finalize(rootScope, childValue);
|
|
742
|
+
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop))
|
|
743
|
+
maybeFreeze(rootScope, childValue);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function maybeFreeze(scope, value, deep = false) {
|
|
747
|
+
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
748
|
+
freeze(value, deep);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function createProxyProxy(base, parent) {
|
|
752
|
+
const isArray = Array.isArray(base);
|
|
753
|
+
const state = {
|
|
754
|
+
type_: isArray ? 1 : 0,
|
|
755
|
+
// Track which produce call this is associated with.
|
|
756
|
+
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
757
|
+
// True for both shallow and deep changes.
|
|
758
|
+
modified_: false,
|
|
759
|
+
// Used during finalization.
|
|
760
|
+
finalized_: false,
|
|
761
|
+
// Track which properties have been assigned (true) or deleted (false).
|
|
762
|
+
assigned_: {},
|
|
763
|
+
// The parent draft state.
|
|
764
|
+
parent_: parent,
|
|
765
|
+
// The base state.
|
|
766
|
+
base_: base,
|
|
767
|
+
// The base proxy.
|
|
768
|
+
draft_: null,
|
|
769
|
+
// set below
|
|
770
|
+
// The base copy with any updated values.
|
|
771
|
+
copy_: null,
|
|
772
|
+
// Called by the `produce` function.
|
|
773
|
+
revoke_: null,
|
|
774
|
+
isManual_: false
|
|
775
|
+
};
|
|
776
|
+
let target = state;
|
|
777
|
+
let traps = objectTraps;
|
|
778
|
+
if (isArray) {
|
|
779
|
+
target = [state];
|
|
780
|
+
traps = arrayTraps;
|
|
781
|
+
}
|
|
782
|
+
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
783
|
+
state.draft_ = proxy;
|
|
784
|
+
state.revoke_ = revoke;
|
|
785
|
+
return proxy;
|
|
786
|
+
}
|
|
787
|
+
var objectTraps = {
|
|
788
|
+
get(state, prop) {
|
|
789
|
+
if (prop === DRAFT_STATE)
|
|
790
|
+
return state;
|
|
791
|
+
const source = latest(state);
|
|
792
|
+
if (!has(source, prop)) {
|
|
793
|
+
return readPropFromProto(state, source, prop);
|
|
794
|
+
}
|
|
795
|
+
const value = source[prop];
|
|
796
|
+
if (state.finalized_ || !isDraftable(value)) {
|
|
797
|
+
return value;
|
|
798
|
+
}
|
|
799
|
+
if (value === peek(state.base_, prop)) {
|
|
800
|
+
prepareCopy(state);
|
|
801
|
+
return state.copy_[prop] = createProxy(value, state);
|
|
802
|
+
}
|
|
803
|
+
return value;
|
|
804
|
+
},
|
|
805
|
+
has(state, prop) {
|
|
806
|
+
return prop in latest(state);
|
|
807
|
+
},
|
|
808
|
+
ownKeys(state) {
|
|
809
|
+
return Reflect.ownKeys(latest(state));
|
|
810
|
+
},
|
|
811
|
+
set(state, prop, value) {
|
|
812
|
+
const desc = getDescriptorFromProto(latest(state), prop);
|
|
813
|
+
if (desc == null ? void 0 : desc.set) {
|
|
814
|
+
desc.set.call(state.draft_, value);
|
|
815
|
+
return true;
|
|
816
|
+
}
|
|
817
|
+
if (!state.modified_) {
|
|
818
|
+
const current2 = peek(latest(state), prop);
|
|
819
|
+
const currentState = current2 == null ? void 0 : current2[DRAFT_STATE];
|
|
820
|
+
if (currentState && currentState.base_ === value) {
|
|
821
|
+
state.copy_[prop] = value;
|
|
822
|
+
state.assigned_[prop] = false;
|
|
823
|
+
return true;
|
|
824
|
+
}
|
|
825
|
+
if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
|
|
826
|
+
return true;
|
|
827
|
+
prepareCopy(state);
|
|
828
|
+
markChanged(state);
|
|
829
|
+
}
|
|
830
|
+
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
831
|
+
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
832
|
+
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
833
|
+
return true;
|
|
834
|
+
state.copy_[prop] = value;
|
|
835
|
+
state.assigned_[prop] = true;
|
|
836
|
+
return true;
|
|
837
|
+
},
|
|
838
|
+
deleteProperty(state, prop) {
|
|
839
|
+
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
840
|
+
state.assigned_[prop] = false;
|
|
841
|
+
prepareCopy(state);
|
|
842
|
+
markChanged(state);
|
|
843
|
+
} else {
|
|
844
|
+
delete state.assigned_[prop];
|
|
845
|
+
}
|
|
846
|
+
if (state.copy_) {
|
|
847
|
+
delete state.copy_[prop];
|
|
848
|
+
}
|
|
849
|
+
return true;
|
|
850
|
+
},
|
|
851
|
+
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
852
|
+
// the same guarantee in ES5 mode.
|
|
853
|
+
getOwnPropertyDescriptor(state, prop) {
|
|
854
|
+
const owner = latest(state);
|
|
855
|
+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
856
|
+
if (!desc)
|
|
857
|
+
return desc;
|
|
858
|
+
return {
|
|
859
|
+
writable: true,
|
|
860
|
+
configurable: state.type_ !== 1 || prop !== "length",
|
|
861
|
+
enumerable: desc.enumerable,
|
|
862
|
+
value: owner[prop]
|
|
863
|
+
};
|
|
864
|
+
},
|
|
865
|
+
defineProperty() {
|
|
866
|
+
die(11);
|
|
867
|
+
},
|
|
868
|
+
getPrototypeOf(state) {
|
|
869
|
+
return getPrototypeOf(state.base_);
|
|
870
|
+
},
|
|
871
|
+
setPrototypeOf() {
|
|
872
|
+
die(12);
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
var arrayTraps = {};
|
|
876
|
+
each(objectTraps, (key, fn) => {
|
|
877
|
+
arrayTraps[key] = function() {
|
|
878
|
+
arguments[0] = arguments[0][0];
|
|
879
|
+
return fn.apply(this, arguments);
|
|
880
|
+
};
|
|
881
|
+
});
|
|
882
|
+
arrayTraps.deleteProperty = function(state, prop) {
|
|
883
|
+
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
884
|
+
die(13);
|
|
885
|
+
return arrayTraps.set.call(this, state, prop, void 0);
|
|
886
|
+
};
|
|
887
|
+
arrayTraps.set = function(state, prop, value) {
|
|
888
|
+
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
|
|
889
|
+
die(14);
|
|
890
|
+
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
891
|
+
};
|
|
892
|
+
function peek(draft, prop) {
|
|
893
|
+
const state = draft[DRAFT_STATE];
|
|
894
|
+
const source = state ? latest(state) : draft;
|
|
895
|
+
return source[prop];
|
|
896
|
+
}
|
|
897
|
+
function readPropFromProto(state, source, prop) {
|
|
898
|
+
var _a;
|
|
899
|
+
const desc = getDescriptorFromProto(source, prop);
|
|
900
|
+
return desc ? `value` in desc ? desc.value : (
|
|
901
|
+
// This is a very special case, if the prop is a getter defined by the
|
|
902
|
+
// prototype, we should invoke it with the draft as context!
|
|
903
|
+
(_a = desc.get) == null ? void 0 : _a.call(state.draft_)
|
|
904
|
+
) : void 0;
|
|
905
|
+
}
|
|
906
|
+
function getDescriptorFromProto(source, prop) {
|
|
907
|
+
if (!(prop in source))
|
|
908
|
+
return void 0;
|
|
909
|
+
let proto = getPrototypeOf(source);
|
|
910
|
+
while (proto) {
|
|
911
|
+
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
912
|
+
if (desc)
|
|
913
|
+
return desc;
|
|
914
|
+
proto = getPrototypeOf(proto);
|
|
915
|
+
}
|
|
916
|
+
return void 0;
|
|
917
|
+
}
|
|
918
|
+
function markChanged(state) {
|
|
919
|
+
if (!state.modified_) {
|
|
920
|
+
state.modified_ = true;
|
|
921
|
+
if (state.parent_) {
|
|
922
|
+
markChanged(state.parent_);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
function prepareCopy(state) {
|
|
927
|
+
if (!state.copy_) {
|
|
928
|
+
state.copy_ = shallowCopy(
|
|
929
|
+
state.base_,
|
|
930
|
+
state.scope_.immer_.useStrictShallowCopy_
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
var Immer2 = class {
|
|
935
|
+
constructor(config) {
|
|
936
|
+
this.autoFreeze_ = true;
|
|
937
|
+
this.useStrictShallowCopy_ = false;
|
|
938
|
+
this.produce = (base, recipe, patchListener) => {
|
|
939
|
+
if (typeof base === "function" && typeof recipe !== "function") {
|
|
940
|
+
const defaultBase = recipe;
|
|
941
|
+
recipe = base;
|
|
942
|
+
const self = this;
|
|
943
|
+
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
944
|
+
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
if (typeof recipe !== "function")
|
|
948
|
+
die(6);
|
|
949
|
+
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
950
|
+
die(7);
|
|
951
|
+
let result;
|
|
952
|
+
if (isDraftable(base)) {
|
|
953
|
+
const scope = enterScope(this);
|
|
954
|
+
const proxy = createProxy(base, void 0);
|
|
955
|
+
let hasError = true;
|
|
956
|
+
try {
|
|
957
|
+
result = recipe(proxy);
|
|
958
|
+
hasError = false;
|
|
959
|
+
} finally {
|
|
960
|
+
if (hasError)
|
|
961
|
+
revokeScope(scope);
|
|
962
|
+
else
|
|
963
|
+
leaveScope(scope);
|
|
964
|
+
}
|
|
965
|
+
usePatchesInScope(scope, patchListener);
|
|
966
|
+
return processResult(result, scope);
|
|
967
|
+
} else if (!base || typeof base !== "object") {
|
|
968
|
+
result = recipe(base);
|
|
969
|
+
if (result === void 0)
|
|
970
|
+
result = base;
|
|
971
|
+
if (result === NOTHING)
|
|
972
|
+
result = void 0;
|
|
973
|
+
if (this.autoFreeze_)
|
|
974
|
+
freeze(result, true);
|
|
975
|
+
if (patchListener) {
|
|
976
|
+
const p = [];
|
|
977
|
+
const ip = [];
|
|
978
|
+
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
979
|
+
patchListener(p, ip);
|
|
980
|
+
}
|
|
981
|
+
return result;
|
|
982
|
+
} else
|
|
983
|
+
die(1, base);
|
|
984
|
+
};
|
|
985
|
+
this.produceWithPatches = (base, recipe) => {
|
|
986
|
+
if (typeof base === "function") {
|
|
987
|
+
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
988
|
+
}
|
|
989
|
+
let patches, inversePatches;
|
|
990
|
+
const result = this.produce(base, recipe, (p, ip) => {
|
|
991
|
+
patches = p;
|
|
992
|
+
inversePatches = ip;
|
|
993
|
+
});
|
|
994
|
+
return [result, patches, inversePatches];
|
|
995
|
+
};
|
|
996
|
+
if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean")
|
|
997
|
+
this.setAutoFreeze(config.autoFreeze);
|
|
998
|
+
if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean")
|
|
999
|
+
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
1000
|
+
}
|
|
1001
|
+
createDraft(base) {
|
|
1002
|
+
if (!isDraftable(base))
|
|
1003
|
+
die(8);
|
|
1004
|
+
if (isDraft(base))
|
|
1005
|
+
base = current(base);
|
|
1006
|
+
const scope = enterScope(this);
|
|
1007
|
+
const proxy = createProxy(base, void 0);
|
|
1008
|
+
proxy[DRAFT_STATE].isManual_ = true;
|
|
1009
|
+
leaveScope(scope);
|
|
1010
|
+
return proxy;
|
|
1011
|
+
}
|
|
1012
|
+
finishDraft(draft, patchListener) {
|
|
1013
|
+
const state = draft && draft[DRAFT_STATE];
|
|
1014
|
+
if (!state || !state.isManual_)
|
|
1015
|
+
die(9);
|
|
1016
|
+
const { scope_: scope } = state;
|
|
1017
|
+
usePatchesInScope(scope, patchListener);
|
|
1018
|
+
return processResult(void 0, scope);
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
1022
|
+
*
|
|
1023
|
+
* By default, auto-freezing is enabled.
|
|
1024
|
+
*/
|
|
1025
|
+
setAutoFreeze(value) {
|
|
1026
|
+
this.autoFreeze_ = value;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Pass true to enable strict shallow copy.
|
|
1030
|
+
*
|
|
1031
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
1032
|
+
*/
|
|
1033
|
+
setUseStrictShallowCopy(value) {
|
|
1034
|
+
this.useStrictShallowCopy_ = value;
|
|
1035
|
+
}
|
|
1036
|
+
applyPatches(base, patches) {
|
|
1037
|
+
let i;
|
|
1038
|
+
for (i = patches.length - 1; i >= 0; i--) {
|
|
1039
|
+
const patch = patches[i];
|
|
1040
|
+
if (patch.path.length === 0 && patch.op === "replace") {
|
|
1041
|
+
base = patch.value;
|
|
1042
|
+
break;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
if (i > -1) {
|
|
1046
|
+
patches = patches.slice(i + 1);
|
|
1047
|
+
}
|
|
1048
|
+
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
1049
|
+
if (isDraft(base)) {
|
|
1050
|
+
return applyPatchesImpl(base, patches);
|
|
1051
|
+
}
|
|
1052
|
+
return this.produce(
|
|
1053
|
+
base,
|
|
1054
|
+
(draft) => applyPatchesImpl(draft, patches)
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
function createProxy(value, parent) {
|
|
1059
|
+
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
1060
|
+
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
1061
|
+
scope.drafts_.push(draft);
|
|
1062
|
+
return draft;
|
|
1063
|
+
}
|
|
1064
|
+
function current(value) {
|
|
1065
|
+
if (!isDraft(value))
|
|
1066
|
+
die(10, value);
|
|
1067
|
+
return currentImpl(value);
|
|
1068
|
+
}
|
|
1069
|
+
function currentImpl(value) {
|
|
1070
|
+
if (!isDraftable(value) || isFrozen(value))
|
|
1071
|
+
return value;
|
|
1072
|
+
const state = value[DRAFT_STATE];
|
|
1073
|
+
let copy;
|
|
1074
|
+
if (state) {
|
|
1075
|
+
if (!state.modified_)
|
|
1076
|
+
return state.base_;
|
|
1077
|
+
state.finalized_ = true;
|
|
1078
|
+
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
1079
|
+
} else {
|
|
1080
|
+
copy = shallowCopy(value, true);
|
|
1081
|
+
}
|
|
1082
|
+
each(copy, (key, childValue) => {
|
|
1083
|
+
set(copy, key, currentImpl(childValue));
|
|
1084
|
+
});
|
|
1085
|
+
if (state) {
|
|
1086
|
+
state.finalized_ = false;
|
|
1087
|
+
}
|
|
1088
|
+
return copy;
|
|
1089
|
+
}
|
|
1090
|
+
var immer = new Immer2();
|
|
1091
|
+
var produce = immer.produce;
|
|
1092
|
+
var produceWithPatches = immer.produceWithPatches.bind(
|
|
1093
|
+
immer
|
|
1094
|
+
);
|
|
1095
|
+
var setAutoFreeze = immer.setAutoFreeze.bind(immer);
|
|
1096
|
+
var setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer);
|
|
1097
|
+
var applyPatches = immer.applyPatches.bind(immer);
|
|
1098
|
+
var createDraft = immer.createDraft.bind(immer);
|
|
1099
|
+
var finishDraft = immer.finishDraft.bind(immer);
|
|
1100
|
+
|
|
1101
|
+
// src/contexts/drag-started-context.ts
|
|
1102
|
+
var import_react11 = require("react");
|
|
1103
|
+
var DragStartedContext = (0, import_react11.createContext)({
|
|
1104
|
+
dragStarted: false,
|
|
1105
|
+
setDragStarted: () => {
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
// src/contexts/external-properties-context.ts
|
|
1110
|
+
var import_react12 = require("react");
|
|
1111
|
+
var ExternalPropertiesContext = (0, import_react12.createContext)(
|
|
1112
|
+
{}
|
|
1113
|
+
);
|
|
1114
|
+
|
|
1115
|
+
// src/helpers/sort-events.ts
|
|
1116
|
+
var sortEvents = (eventA, eventB) => {
|
|
1117
|
+
if (eventA.startTime - eventB.startTime < 0) return -1;
|
|
1118
|
+
if (eventA.startTime === eventB.startTime) {
|
|
1119
|
+
if (eventA.endTime < eventB.endTime) {
|
|
1120
|
+
return -1;
|
|
1121
|
+
} else {
|
|
1122
|
+
return 1;
|
|
1123
|
+
}
|
|
1124
|
+
} else {
|
|
1125
|
+
return 1;
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
var sort_events_default = sortEvents;
|
|
1129
|
+
|
|
1130
|
+
// src/components/row-content.tsx
|
|
1131
|
+
var RowContent = (0, import_react13.forwardRef)((props, ref) => {
|
|
1132
|
+
const { setEvents, tick, id, windowTime, cellWidth, children } = props;
|
|
1133
|
+
const { dragStarted, setDragStarted } = (0, import_react13.useContext)(DragStartedContext);
|
|
1134
|
+
const { onDrop } = (0, import_react13.useContext)(ExternalPropertiesContext);
|
|
1135
|
+
const handleOnDrop = (0, import_react13.useCallback)(
|
|
1136
|
+
(event) => {
|
|
1137
|
+
event.preventDefault();
|
|
1138
|
+
const element = event.target;
|
|
1139
|
+
const { left } = element.getBoundingClientRect();
|
|
1140
|
+
const draggedEventId = event.dataTransfer.getData("eventId");
|
|
1141
|
+
const closestCell = Math.round((event.clientX - left) / cellWidth);
|
|
1142
|
+
const newPosition = cellWidth * closestCell;
|
|
1143
|
+
setEvents(
|
|
1144
|
+
produce((draft) => {
|
|
1145
|
+
const event2 = draft.find((event3) => event3.id === draggedEventId);
|
|
1146
|
+
if (event2 && tick) {
|
|
1147
|
+
const newStartTime = windowTime[0] + newPosition * tick;
|
|
1148
|
+
const eventDuration = event2.endTime - event2.startTime;
|
|
1149
|
+
const newEndTime = windowTime[0] + eventDuration + newPosition * tick;
|
|
1150
|
+
if (onDrop) {
|
|
1151
|
+
onDrop({
|
|
1152
|
+
eventId: event2.id,
|
|
1153
|
+
oldRowId: event2.rowId,
|
|
1154
|
+
newRowId: props.id,
|
|
1155
|
+
startTime: newStartTime,
|
|
1156
|
+
endTime: newEndTime
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
event2.startTime = newStartTime;
|
|
1160
|
+
event2.endTime = newEndTime;
|
|
1161
|
+
event2.rowId = props.id;
|
|
1162
|
+
}
|
|
1163
|
+
draft.sort(sort_events_default);
|
|
1164
|
+
})
|
|
1165
|
+
);
|
|
1166
|
+
setDragStarted(false);
|
|
1167
|
+
},
|
|
1168
|
+
[setEvents, tick, windowTime, cellWidth]
|
|
1169
|
+
);
|
|
1170
|
+
const rowsHeightContext = (0, import_react13.useContext)(RowsHeightContext);
|
|
1171
|
+
const minHeight = rowsHeightContext && rowsHeightContext.rowsHeight && rowsHeightContext.rowsHeight[id] ? rowsHeightContext.rowsHeight[id].minHeight : 40;
|
|
1172
|
+
return /* @__PURE__ */ import_react13.default.createElement(
|
|
1173
|
+
"div",
|
|
1174
|
+
{
|
|
1175
|
+
id: `row_${id}`,
|
|
1176
|
+
ref,
|
|
1177
|
+
onDragOver: (event) => event.preventDefault(),
|
|
1178
|
+
onDrop: handleOnDrop,
|
|
1179
|
+
className: dragStarted ? "row-content not-clickable" : "row-content",
|
|
1180
|
+
"data-index": id,
|
|
1181
|
+
style: {
|
|
1182
|
+
minHeight
|
|
1183
|
+
// background: `linear-gradient(to left, white, white 1px, transparent 0, transparent 100%), repeating-linear-gradient(
|
|
1184
|
+
// to left,
|
|
1185
|
+
// #aaaaaa,
|
|
1186
|
+
// #aaaaaa 1px,
|
|
1187
|
+
// transparent 0px,
|
|
1188
|
+
// transparent ${cellWidth}px
|
|
1189
|
+
// )`,
|
|
1190
|
+
}
|
|
1191
|
+
},
|
|
1192
|
+
children
|
|
1193
|
+
);
|
|
1194
|
+
});
|
|
1195
|
+
var row_content_default = RowContent;
|
|
1196
|
+
|
|
1197
|
+
// src/components/event.tsx
|
|
1198
|
+
var import_react14 = __toESM(require("react"));
|
|
1199
|
+
|
|
1200
|
+
// src/assets/grip-lines-vertical-solid.svg
|
|
1201
|
+
var React8 = __toESM(require("react"));
|
|
1202
|
+
var SvgGripLinesVerticalSolid = (props) => /* @__PURE__ */ React8.createElement("svg", __spreadValues({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 192 512" }, props), /* @__PURE__ */ React8.createElement("path", { d: "M64 64c0-17.7-14.3-32-32-32S0 46.3 0 64L0 448c0 17.7 14.3 32 32 32s32-14.3 32-32L64 64zm128 0c0-17.7-14.3-32-32-32s-32 14.3-32 32l0 384c0 17.7 14.3 32 32 32s32-14.3 32-32l0-384z" }));
|
|
1203
|
+
var grip_lines_vertical_solid_default = SvgGripLinesVerticalSolid;
|
|
1204
|
+
|
|
1205
|
+
// src/components/event.tsx
|
|
1206
|
+
var Event = ({
|
|
1207
|
+
id,
|
|
1208
|
+
startPosition,
|
|
1209
|
+
width,
|
|
1210
|
+
top,
|
|
1211
|
+
props,
|
|
1212
|
+
setEvents,
|
|
1213
|
+
tick
|
|
1214
|
+
}) => {
|
|
1215
|
+
const { setDragStarted } = (0, import_react14.useContext)(DragStartedContext);
|
|
1216
|
+
const { onResize, eventsResize } = (0, import_react14.useContext)(ExternalPropertiesContext);
|
|
1217
|
+
const initialPositionForResizeRef = (0, import_react14.useRef)(0);
|
|
1218
|
+
const handleOnDragStart = (0, import_react14.useCallback)(
|
|
1219
|
+
(event) => {
|
|
1220
|
+
event.stopPropagation();
|
|
1221
|
+
event.dataTransfer.setData("eventId", id);
|
|
1222
|
+
setTimeout(() => setDragStarted(true), 0);
|
|
1223
|
+
const target = event.target;
|
|
1224
|
+
target.style.opacity = "50%";
|
|
1225
|
+
},
|
|
1226
|
+
[setDragStarted]
|
|
1227
|
+
);
|
|
1228
|
+
const handleOnDragEnd = (0, import_react14.useCallback)(
|
|
1229
|
+
(event) => {
|
|
1230
|
+
event.stopPropagation();
|
|
1231
|
+
setDragStarted(false);
|
|
1232
|
+
const target = event.target;
|
|
1233
|
+
target.style.opacity = "100%";
|
|
1234
|
+
},
|
|
1235
|
+
[setDragStarted]
|
|
1236
|
+
);
|
|
1237
|
+
const classNames = (props == null ? void 0 : props.classNames) ? "event " + props.classNames.join(" ") : "event";
|
|
1238
|
+
const [draggableEvent, setDraggableEvent] = (0, import_react14.useState)(true);
|
|
1239
|
+
const [resizeOffset, setResizeOffset] = (0, import_react14.useState)(0);
|
|
1240
|
+
const resizeOffsetRef = (0, import_react14.useRef)(0);
|
|
1241
|
+
const [resizeStarted, setResizeStarted] = (0, import_react14.useState)(false);
|
|
1242
|
+
const resizeDirectionRef = (0, import_react14.useRef)(null);
|
|
1243
|
+
const handleDocumentOnMouseMoveResize = (0, import_react14.useCallback)(
|
|
1244
|
+
(event) => {
|
|
1245
|
+
const offset = event.clientX - initialPositionForResizeRef.current;
|
|
1246
|
+
setResizeOffset(
|
|
1247
|
+
resizeDirectionRef.current === "left" ? offset * -1 : offset
|
|
1248
|
+
);
|
|
1249
|
+
resizeOffsetRef.current = offset;
|
|
1250
|
+
},
|
|
1251
|
+
[setResizeOffset]
|
|
1252
|
+
);
|
|
1253
|
+
const handleDocumentOnMouseUp = (0, import_react14.useCallback)(
|
|
1254
|
+
(event, resizeDirection) => {
|
|
1255
|
+
initialPositionForResizeRef.current = 0;
|
|
1256
|
+
setResizeStarted(false);
|
|
1257
|
+
document.removeEventListener(
|
|
1258
|
+
"mousemove",
|
|
1259
|
+
handleDocumentOnMouseMoveResize
|
|
1260
|
+
);
|
|
1261
|
+
const lockedStyle = document.getElementById("lock-cursor");
|
|
1262
|
+
if (lockedStyle) {
|
|
1263
|
+
lockedStyle.remove();
|
|
1264
|
+
}
|
|
1265
|
+
setEvents(
|
|
1266
|
+
produce((draft) => {
|
|
1267
|
+
const event2 = draft.find((event3) => event3.id === id);
|
|
1268
|
+
if (event2 && tick) {
|
|
1269
|
+
if (resizeDirection === "left") {
|
|
1270
|
+
const newStartTime = Math.round(
|
|
1271
|
+
event2.startTime + resizeOffsetRef.current * tick
|
|
1272
|
+
);
|
|
1273
|
+
event2.startTime = newStartTime;
|
|
1274
|
+
} else {
|
|
1275
|
+
const newEndTime = Math.round(
|
|
1276
|
+
event2.endTime + resizeOffsetRef.current * tick
|
|
1277
|
+
);
|
|
1278
|
+
event2.endTime = newEndTime;
|
|
1279
|
+
}
|
|
1280
|
+
if (onResize) {
|
|
1281
|
+
onResize({
|
|
1282
|
+
eventId: event2.id,
|
|
1283
|
+
startTime: event2.startTime,
|
|
1284
|
+
endTime: event2.endTime
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
draft.sort(sort_events_default);
|
|
1289
|
+
resizeOffsetRef.current = 0;
|
|
1290
|
+
setResizeOffset(0);
|
|
1291
|
+
})
|
|
1292
|
+
);
|
|
1293
|
+
},
|
|
1294
|
+
[
|
|
1295
|
+
handleDocumentOnMouseMoveResize,
|
|
1296
|
+
setEvents,
|
|
1297
|
+
tick,
|
|
1298
|
+
setResizeOffset,
|
|
1299
|
+
sort_events_default
|
|
1300
|
+
]
|
|
1301
|
+
);
|
|
1302
|
+
const handleOnMouseDownEventResizer = (0, import_react14.useCallback)(
|
|
1303
|
+
(event, resizeDirection) => {
|
|
1304
|
+
event.stopPropagation();
|
|
1305
|
+
resizeDirectionRef.current = resizeDirection;
|
|
1306
|
+
setResizeStarted(true);
|
|
1307
|
+
const style = document.createElement("style");
|
|
1308
|
+
style.id = "lock-cursor";
|
|
1309
|
+
style.innerHTML = "* { cursor: e-resize !important; }";
|
|
1310
|
+
document.head.appendChild(style);
|
|
1311
|
+
document.addEventListener("mousemove", handleDocumentOnMouseMoveResize);
|
|
1312
|
+
document.addEventListener(
|
|
1313
|
+
"mouseup",
|
|
1314
|
+
(event2) => handleDocumentOnMouseUp(event2, resizeDirection),
|
|
1315
|
+
{ once: true }
|
|
1316
|
+
);
|
|
1317
|
+
initialPositionForResizeRef.current = event.clientX;
|
|
1318
|
+
},
|
|
1319
|
+
[handleDocumentOnMouseMoveResize, handleDocumentOnMouseUp]
|
|
1320
|
+
);
|
|
1321
|
+
const handleOnMouseMove = (0, import_react14.useCallback)(
|
|
1322
|
+
(event) => {
|
|
1323
|
+
if (!resizeStarted) {
|
|
1324
|
+
event.stopPropagation();
|
|
1325
|
+
}
|
|
1326
|
+
},
|
|
1327
|
+
[resizeStarted]
|
|
1328
|
+
);
|
|
1329
|
+
return /* @__PURE__ */ import_react14.default.createElement(
|
|
1330
|
+
"div",
|
|
1331
|
+
{
|
|
1332
|
+
id: `event_${id}`,
|
|
1333
|
+
key: `event_${id}`,
|
|
1334
|
+
className: classNames,
|
|
1335
|
+
draggable: (props == null ? void 0 : props.isLocked) ? false : draggableEvent,
|
|
1336
|
+
onDragStart: handleOnDragStart,
|
|
1337
|
+
onDragEnd: handleOnDragEnd,
|
|
1338
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
1339
|
+
onMouseMove: handleOnMouseMove,
|
|
1340
|
+
onDrop: (event) => event.stopPropagation(),
|
|
1341
|
+
style: {
|
|
1342
|
+
left: resizeDirectionRef.current === "left" ? startPosition - resizeOffset : startPosition,
|
|
1343
|
+
width: width + resizeOffset,
|
|
1344
|
+
top,
|
|
1345
|
+
cursor: (props == null ? void 0 : props.isLocked) ? "not-allowed" : "pointer"
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
/* @__PURE__ */ import_react14.default.createElement("div", { className: "event-content" }, !(props == null ? void 0 : props.isLocked) && (eventsResize || (props == null ? void 0 : props.isResizable)) && /* @__PURE__ */ import_react14.default.createElement(
|
|
1349
|
+
"img",
|
|
1350
|
+
{
|
|
1351
|
+
className: "event-resize",
|
|
1352
|
+
style: resizeStarted ? { opacity: "100%" } : void 0,
|
|
1353
|
+
src: grip_lines_vertical_solid_default,
|
|
1354
|
+
alt: "resize-icon",
|
|
1355
|
+
draggable: false,
|
|
1356
|
+
onMouseEnter: () => setDraggableEvent(false),
|
|
1357
|
+
onMouseLeave: () => setDraggableEvent(true),
|
|
1358
|
+
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "left")
|
|
1359
|
+
}
|
|
1360
|
+
), (props == null ? void 0 : props.content) ? props.content : null, !(props == null ? void 0 : props.isLocked) && (eventsResize || (props == null ? void 0 : props.isResizable)) && /* @__PURE__ */ import_react14.default.createElement(
|
|
1361
|
+
"img",
|
|
1362
|
+
{
|
|
1363
|
+
className: "event-resize",
|
|
1364
|
+
style: resizeStarted ? { opacity: "100%" } : void 0,
|
|
1365
|
+
src: grip_lines_vertical_solid_default,
|
|
1366
|
+
alt: "resize-icon",
|
|
1367
|
+
draggable: false,
|
|
1368
|
+
onMouseEnter: () => setDraggableEvent(false),
|
|
1369
|
+
onMouseLeave: () => setDraggableEvent(true),
|
|
1370
|
+
onMouseDown: (event) => handleOnMouseDownEventResizer(event, "right")
|
|
1371
|
+
}
|
|
1372
|
+
))
|
|
1373
|
+
);
|
|
1374
|
+
};
|
|
1375
|
+
var event_default = Event;
|
|
1376
|
+
|
|
1377
|
+
// src/hooks/use-intersection-observer.ts
|
|
1378
|
+
var import_react15 = require("react");
|
|
1379
|
+
var useIntersectionObserver = ({
|
|
1380
|
+
bodyRef,
|
|
1381
|
+
rowsContentRef
|
|
1382
|
+
}) => {
|
|
1383
|
+
const callback = (0, import_react15.useCallback)((entries) => {
|
|
1384
|
+
entries.forEach((entry) => {
|
|
1385
|
+
if (entry.isIntersecting) {
|
|
1386
|
+
entry.target.classList.remove("row-hidden");
|
|
1387
|
+
} else {
|
|
1388
|
+
entry.target.classList.add("row-hidden");
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
}, []);
|
|
1392
|
+
const observer = new IntersectionObserver(callback, {
|
|
1393
|
+
root: bodyRef.current
|
|
1394
|
+
});
|
|
1395
|
+
(0, import_react15.useEffect)(() => {
|
|
1396
|
+
if (rowsContentRef.current) {
|
|
1397
|
+
rowsContentRef.current.forEach((row) => {
|
|
1398
|
+
observer.observe(row);
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
return () => observer.disconnect();
|
|
1402
|
+
}, [observer]);
|
|
1403
|
+
};
|
|
1404
|
+
var use_intersection_observer_default = useIntersectionObserver;
|
|
1405
|
+
|
|
1406
|
+
// src/hooks/use-produce-content.tsx
|
|
1407
|
+
var useProduceContent = ({
|
|
1408
|
+
rows,
|
|
1409
|
+
windowTime,
|
|
1410
|
+
tick,
|
|
1411
|
+
events,
|
|
1412
|
+
staticEvents,
|
|
1413
|
+
cellWidth,
|
|
1414
|
+
setEvents,
|
|
1415
|
+
bodyRef
|
|
1416
|
+
}) => {
|
|
1417
|
+
const rowsHeightContext = (0, import_react16.useContext)(RowsHeightContext);
|
|
1418
|
+
const tempRowsHeightRef = (0, import_react16.useRef)(null);
|
|
1419
|
+
const rowsContentRef = (0, import_react16.useRef)([]);
|
|
1420
|
+
const [content, internalAllRowsHeight] = (0, import_react16.useMemo)(() => {
|
|
1421
|
+
let internalAllRowsHeight2 = 0;
|
|
1422
|
+
return [
|
|
1423
|
+
rows.map((row, i) => {
|
|
1424
|
+
let eventOrder = 0;
|
|
1425
|
+
let prevEvent = [];
|
|
1426
|
+
let highestEventOrder = 0;
|
|
1427
|
+
const rowEvents = tick ? events.filter((event) => event.rowId === row.id).map((event) => {
|
|
1428
|
+
if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
|
|
1429
|
+
let tempEventOrder = 0;
|
|
1430
|
+
let assignEventOrder = true;
|
|
1431
|
+
for (let i2 = 0; i2 <= eventOrder; i2++) {
|
|
1432
|
+
if (prevEvent && prevEvent[i2] && prevEvent[i2].endTime > event.startTime) {
|
|
1433
|
+
tempEventOrder += 1;
|
|
1434
|
+
} else {
|
|
1435
|
+
if (eventOrder > highestEventOrder) {
|
|
1436
|
+
highestEventOrder = eventOrder;
|
|
1437
|
+
}
|
|
1438
|
+
eventOrder = 0;
|
|
1439
|
+
assignEventOrder = false;
|
|
1440
|
+
break;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
if (assignEventOrder) {
|
|
1444
|
+
eventOrder = tempEventOrder;
|
|
1445
|
+
}
|
|
1446
|
+
prevEvent[tempEventOrder] = event;
|
|
1447
|
+
return /* @__PURE__ */ import_react17.default.createElement(
|
|
1448
|
+
event_default,
|
|
1449
|
+
{
|
|
1450
|
+
key: `event_${event.id}`,
|
|
1451
|
+
id: event.id,
|
|
1452
|
+
startPosition: (event.startTime - windowTime[0]) / tick,
|
|
1453
|
+
width: (event.endTime - event.startTime) / tick,
|
|
1454
|
+
top: 10 + 22 * tempEventOrder,
|
|
1455
|
+
props: event.props,
|
|
1456
|
+
setEvents,
|
|
1457
|
+
tick
|
|
1458
|
+
}
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
}) : null;
|
|
1462
|
+
if (eventOrder > highestEventOrder) {
|
|
1463
|
+
highestEventOrder = eventOrder;
|
|
1464
|
+
}
|
|
1465
|
+
if (tempRowsHeightRef.current === null) {
|
|
1466
|
+
tempRowsHeightRef.current = {
|
|
1467
|
+
[row.id]: { minHeight: 40 + highestEventOrder * 22 }
|
|
1468
|
+
};
|
|
1469
|
+
} else {
|
|
1470
|
+
tempRowsHeightRef.current[row.id] = {
|
|
1471
|
+
minHeight: 40 + highestEventOrder * 22
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
internalAllRowsHeight2 += 40 + highestEventOrder * 22;
|
|
1475
|
+
const rowStaticEvents = tick && staticEvents ? staticEvents.filter((event) => event.rowId === row.id).map((event) => {
|
|
1476
|
+
if (event.endTime >= windowTime[0] && event.startTime <= windowTime[1]) {
|
|
1477
|
+
return /* @__PURE__ */ import_react17.default.createElement(
|
|
1478
|
+
static_event_default,
|
|
1479
|
+
{
|
|
1480
|
+
key: `static_event_${event.id}`,
|
|
1481
|
+
id: event.id,
|
|
1482
|
+
startPosition: (event.startTime - windowTime[0]) / tick,
|
|
1483
|
+
width: (event.endTime - event.startTime) / tick,
|
|
1484
|
+
top: 10,
|
|
1485
|
+
height: 20 + highestEventOrder * 22
|
|
1486
|
+
}
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
}) : null;
|
|
1490
|
+
return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, { key: `row_content_${row.id}` }, /* @__PURE__ */ import_react17.default.createElement(
|
|
1491
|
+
row_content_default,
|
|
1492
|
+
{
|
|
1493
|
+
id: row.id,
|
|
1494
|
+
ref: (el) => {
|
|
1495
|
+
if (rowsContentRef.current && rowsContentRef.current[i] && el) {
|
|
1496
|
+
rowsContentRef.current[i] = el;
|
|
1497
|
+
} else if (rowsContentRef.current && el) {
|
|
1498
|
+
rowsContentRef.current.push(el);
|
|
1499
|
+
}
|
|
1500
|
+
},
|
|
1501
|
+
setEvents,
|
|
1502
|
+
tick,
|
|
1503
|
+
windowTime,
|
|
1504
|
+
cellWidth
|
|
1505
|
+
},
|
|
1506
|
+
rowEvents,
|
|
1507
|
+
rowStaticEvents
|
|
1508
|
+
));
|
|
1509
|
+
}),
|
|
1510
|
+
internalAllRowsHeight2
|
|
1511
|
+
];
|
|
1512
|
+
}, [rows, events, tick, windowTime, cellWidth]);
|
|
1513
|
+
use_intersection_observer_default({
|
|
1514
|
+
rowsContentRef,
|
|
1515
|
+
bodyRef
|
|
1516
|
+
});
|
|
1517
|
+
(0, import_react16.useEffect)(() => {
|
|
1518
|
+
if (rowsHeightContext) {
|
|
1519
|
+
rowsHeightContext.setRowsHeight(tempRowsHeightRef.current);
|
|
1520
|
+
rowsHeightContext.setAllRowsHeight(internalAllRowsHeight);
|
|
1521
|
+
}
|
|
1522
|
+
}, [content, internalAllRowsHeight]);
|
|
1523
|
+
return content;
|
|
1524
|
+
};
|
|
1525
|
+
var use_produce_content_default = useProduceContent;
|
|
1526
|
+
|
|
1527
|
+
// src/components/content.tsx
|
|
1528
|
+
var Content = (0, import_react18.forwardRef)(
|
|
1529
|
+
({
|
|
1530
|
+
rows,
|
|
1531
|
+
events,
|
|
1532
|
+
staticEvents,
|
|
1533
|
+
setEvents,
|
|
1534
|
+
tick,
|
|
1535
|
+
windowTime,
|
|
1536
|
+
cellWidth,
|
|
1537
|
+
setWindowTime,
|
|
1538
|
+
contentWidth,
|
|
1539
|
+
setCellWidth,
|
|
1540
|
+
bodyRef,
|
|
1541
|
+
lineClassName
|
|
1542
|
+
}, ref) => {
|
|
1543
|
+
const [mouseDown, setMouseDown] = (0, import_react18.useState)(false);
|
|
1544
|
+
const startMovePosition = (0, import_react18.useRef)(null);
|
|
1545
|
+
const [changeGrid, setChangeGrid] = (0, import_react18.useState)(false);
|
|
1546
|
+
const { blockWidth } = use_get_block_properties_default({ windowTime, contentWidth });
|
|
1547
|
+
const rowsHeightContext = (0, import_react18.useContext)(RowsHeightContext);
|
|
1548
|
+
const handleOnMouseMove = (0, import_react18.useCallback)(
|
|
1549
|
+
(event) => {
|
|
1550
|
+
event.preventDefault();
|
|
1551
|
+
if (!mouseDown) {
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
const element = event.target;
|
|
1555
|
+
const { left } = element.getBoundingClientRect();
|
|
1556
|
+
const movePosition = event.clientX - left;
|
|
1557
|
+
const moveTimestamp = tick ? Math.floor(tick * blockWidth) : 0;
|
|
1558
|
+
if (startMovePosition.current && startMovePosition.current - movePosition >= blockWidth) {
|
|
1559
|
+
startMovePosition.current = movePosition;
|
|
1560
|
+
setWindowTime((prev) => [
|
|
1561
|
+
prev[0] + moveTimestamp,
|
|
1562
|
+
prev[1] + moveTimestamp
|
|
1563
|
+
]);
|
|
1564
|
+
} else if (startMovePosition.current && movePosition - startMovePosition.current >= blockWidth) {
|
|
1565
|
+
startMovePosition.current = movePosition;
|
|
1566
|
+
setWindowTime((prev) => [
|
|
1567
|
+
prev[0] - moveTimestamp,
|
|
1568
|
+
prev[1] - moveTimestamp
|
|
1569
|
+
]);
|
|
1570
|
+
}
|
|
1571
|
+
},
|
|
1572
|
+
[blockWidth, setWindowTime, mouseDown]
|
|
1573
|
+
);
|
|
1574
|
+
const handleOnMouseDown = (0, import_react18.useCallback)(
|
|
1575
|
+
(event) => {
|
|
1576
|
+
setMouseDown(true);
|
|
1577
|
+
if (event.button === 1) {
|
|
1578
|
+
event.preventDefault();
|
|
1579
|
+
}
|
|
1580
|
+
const element = event.target;
|
|
1581
|
+
const { left } = element.getBoundingClientRect();
|
|
1582
|
+
startMovePosition.current = event.clientX - left;
|
|
1583
|
+
},
|
|
1584
|
+
[setMouseDown]
|
|
1585
|
+
);
|
|
1586
|
+
const handleOnMouseUp = (0, import_react18.useCallback)(() => {
|
|
1587
|
+
setMouseDown(false);
|
|
1588
|
+
}, [setMouseDown]);
|
|
1589
|
+
const handleOnMouseLeave = (0, import_react18.useCallback)(
|
|
1590
|
+
() => setMouseDown(false),
|
|
1591
|
+
[setMouseDown]
|
|
1592
|
+
);
|
|
1593
|
+
const content = use_produce_content_default({
|
|
1594
|
+
rows,
|
|
1595
|
+
windowTime,
|
|
1596
|
+
tick,
|
|
1597
|
+
events,
|
|
1598
|
+
staticEvents,
|
|
1599
|
+
cellWidth,
|
|
1600
|
+
setEvents,
|
|
1601
|
+
bodyRef
|
|
1602
|
+
});
|
|
1603
|
+
const handleAuxClick = (0, import_react18.useCallback)(
|
|
1604
|
+
(event) => {
|
|
1605
|
+
event.preventDefault();
|
|
1606
|
+
if (event.button === 1) {
|
|
1607
|
+
setChangeGrid((prev) => !prev);
|
|
1608
|
+
}
|
|
1609
|
+
},
|
|
1610
|
+
[]
|
|
1611
|
+
);
|
|
1612
|
+
const handleOnWheel = (0, import_react18.useCallback)(
|
|
1613
|
+
(event) => {
|
|
1614
|
+
const pixelsToCalculate = tick ? 900 / tick : 0;
|
|
1615
|
+
if (changeGrid) {
|
|
1616
|
+
setCellWidth((cellWidth2) => {
|
|
1617
|
+
const newCellWidth = event.deltaY > 0 ? cellWidth2 + pixelsToCalculate : cellWidth2 - pixelsToCalculate;
|
|
1618
|
+
if (newCellWidth < pixelsToCalculate || newCellWidth > pixelsToCalculate * 12) {
|
|
1619
|
+
return cellWidth2;
|
|
1620
|
+
}
|
|
1621
|
+
return newCellWidth;
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
},
|
|
1625
|
+
[changeGrid, cellWidth, tick]
|
|
1626
|
+
);
|
|
1627
|
+
(0, import_react18.useEffect)(() => {
|
|
1628
|
+
if (bodyRef.current) {
|
|
1629
|
+
bodyRef.current.style.overflow = changeGrid ? "hidden" : "auto";
|
|
1630
|
+
}
|
|
1631
|
+
}, [changeGrid]);
|
|
1632
|
+
return /* @__PURE__ */ import_react18.default.createElement(
|
|
1633
|
+
"div",
|
|
1634
|
+
{
|
|
1635
|
+
key: "content",
|
|
1636
|
+
ref,
|
|
1637
|
+
className: "content-wrapper",
|
|
1638
|
+
onMouseDown: handleOnMouseDown,
|
|
1639
|
+
onMouseUp: handleOnMouseUp,
|
|
1640
|
+
onMouseMove: handleOnMouseMove,
|
|
1641
|
+
onMouseLeave: handleOnMouseLeave,
|
|
1642
|
+
onAuxClick: handleAuxClick,
|
|
1643
|
+
onWheel: handleOnWheel,
|
|
1644
|
+
style: {
|
|
1645
|
+
cursor: mouseDown ? "grabbing" : "grab",
|
|
1646
|
+
height: rowsHeightContext == null ? void 0 : rowsHeightContext.allRowsHeight
|
|
1647
|
+
}
|
|
1648
|
+
},
|
|
1649
|
+
/* @__PURE__ */ import_react18.default.createElement(
|
|
1650
|
+
lines_canvas_default,
|
|
1651
|
+
{
|
|
1652
|
+
contentWidth,
|
|
1653
|
+
cellWidth,
|
|
1654
|
+
lineClassName
|
|
1655
|
+
}
|
|
1656
|
+
),
|
|
1657
|
+
content
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
);
|
|
1661
|
+
var content_default = Content;
|
|
1662
|
+
|
|
1663
|
+
// src/hooks/use-resize-observer.ts
|
|
1664
|
+
var import_react19 = require("react");
|
|
1665
|
+
var useResizeObserver = ({
|
|
1666
|
+
windowTime,
|
|
1667
|
+
setTick,
|
|
1668
|
+
setCellWidth,
|
|
1669
|
+
contentRef
|
|
1670
|
+
}) => {
|
|
1671
|
+
const prevWidthRef = (0, import_react19.useRef)(0);
|
|
1672
|
+
const resizeObserver = (0, import_react19.useMemo)(() => {
|
|
1673
|
+
return new ResizeObserver((entries) => {
|
|
1674
|
+
var _a;
|
|
1675
|
+
for (const entry of entries) {
|
|
1676
|
+
const width = (_a = entry.borderBoxSize) == null ? void 0 : _a[0].inlineSize;
|
|
1677
|
+
if (typeof width === "number" && width !== prevWidthRef.current) {
|
|
1678
|
+
prevWidthRef.current = width;
|
|
1679
|
+
const windowDuration = windowTime[1] - windowTime[0];
|
|
1680
|
+
const numberOfHourBlocks = windowDuration / 3600;
|
|
1681
|
+
setTick(windowDuration / entry.contentRect.width);
|
|
1682
|
+
setCellWidth(entry.contentRect.width / numberOfHourBlocks);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
}, [windowTime]);
|
|
1687
|
+
(0, import_react19.useEffect)(() => {
|
|
1688
|
+
if (contentRef.current) {
|
|
1689
|
+
resizeObserver.observe(contentRef.current, { box: "border-box" });
|
|
1690
|
+
}
|
|
1691
|
+
return () => resizeObserver.disconnect();
|
|
1692
|
+
}, [resizeObserver]);
|
|
1693
|
+
};
|
|
1694
|
+
var use_resize_observer_default = useResizeObserver;
|
|
1695
|
+
|
|
1696
|
+
// src/components/rt-indicator.tsx
|
|
1697
|
+
var import_react20 = __toESM(require("react"));
|
|
1698
|
+
var RTIndicator = ({
|
|
1699
|
+
tick,
|
|
1700
|
+
windowTime
|
|
1701
|
+
}) => {
|
|
1702
|
+
const [currentTime, setCurrentTime] = (0, import_react20.useState)((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1703
|
+
const [leftOffset, setLeftOffset] = (0, import_react20.useState)(0);
|
|
1704
|
+
const intervalIdRef = (0, import_react20.useRef)(null);
|
|
1705
|
+
(0, import_react20.useEffect)(() => {
|
|
1706
|
+
if (tick) {
|
|
1707
|
+
const leftOffsetTime = currentTime - windowTime[0];
|
|
1708
|
+
setLeftOffset(Math.round(leftOffsetTime / tick));
|
|
1709
|
+
if (intervalIdRef.current !== null) {
|
|
1710
|
+
clearInterval(intervalIdRef.current);
|
|
1711
|
+
}
|
|
1712
|
+
const intervalId = setInterval(() => {
|
|
1713
|
+
setCurrentTime((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1714
|
+
}, tick * 1e3);
|
|
1715
|
+
intervalIdRef.current = intervalId;
|
|
1716
|
+
}
|
|
1717
|
+
}, [tick, windowTime, currentTime]);
|
|
1718
|
+
return /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, null, windowTime[0] <= currentTime && currentTime <= windowTime[1] && /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, null, /* @__PURE__ */ import_react20.default.createElement("div", { className: "rt-arrow", style: { left: 86 + leftOffset } }), /* @__PURE__ */ import_react20.default.createElement("div", { className: "rt-line", style: { left: 100 + leftOffset } })));
|
|
1719
|
+
};
|
|
1720
|
+
var rt_indicator_default = RTIndicator;
|
|
1721
|
+
|
|
1722
|
+
// src/timeline.tsx
|
|
1723
|
+
var Timeline = ({
|
|
1724
|
+
rows,
|
|
1725
|
+
events,
|
|
1726
|
+
staticEvents,
|
|
1727
|
+
onDrop,
|
|
1728
|
+
onResize,
|
|
1729
|
+
startDate,
|
|
1730
|
+
endDate,
|
|
1731
|
+
additionalClassNames,
|
|
1732
|
+
showRTIndicator = true,
|
|
1733
|
+
eventsResize = true
|
|
1734
|
+
}) => {
|
|
1735
|
+
const [windowTime, setWindowTime] = (0, import_react21.useState)([
|
|
1736
|
+
new Date(
|
|
1737
|
+
startDate.getFullYear(),
|
|
1738
|
+
startDate.getMonth(),
|
|
1739
|
+
startDate.getDate(),
|
|
1740
|
+
startDate.getHours(),
|
|
1741
|
+
0,
|
|
1742
|
+
0
|
|
1743
|
+
).getTime() / 1e3,
|
|
1744
|
+
new Date(
|
|
1745
|
+
endDate.getFullYear(),
|
|
1746
|
+
endDate.getMonth(),
|
|
1747
|
+
endDate.getDate(),
|
|
1748
|
+
endDate.getHours(),
|
|
1749
|
+
0,
|
|
1750
|
+
0
|
|
1751
|
+
).getTime() / 1e3
|
|
1752
|
+
]);
|
|
1753
|
+
const [cellWidth, setCellWidth] = (0, import_react21.useState)(0);
|
|
1754
|
+
const [internalEvents, setInternalEvents] = (0, import_react21.useState)([]);
|
|
1755
|
+
const contentRef = (0, import_react21.useRef)(null);
|
|
1756
|
+
const mainRef = (0, import_react21.useRef)(null);
|
|
1757
|
+
const bodyRef = (0, import_react21.useRef)(null);
|
|
1758
|
+
const [tick, setTick] = (0, import_react21.useState)(null);
|
|
1759
|
+
const [scrollWidth, setScrollWidth] = (0, import_react21.useState)(0);
|
|
1760
|
+
const [rowsHeight, setRowsHeight] = (0, import_react21.useState)(null);
|
|
1761
|
+
const [allRowsHeight, setAllRowsHeight] = (0, import_react21.useState)(0);
|
|
1762
|
+
(0, import_react21.useEffect)(() => {
|
|
1763
|
+
if (contentRef.current) {
|
|
1764
|
+
const windowDuration = windowTime[1] - windowTime[0];
|
|
1765
|
+
const numberOfHourBlocks = windowDuration / 3600;
|
|
1766
|
+
setTick(
|
|
1767
|
+
windowDuration / contentRef.current.getBoundingClientRect().width
|
|
1768
|
+
);
|
|
1769
|
+
setCellWidth(
|
|
1770
|
+
contentRef.current.getBoundingClientRect().width / numberOfHourBlocks
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
}, []);
|
|
1774
|
+
(0, import_react21.useEffect)(() => {
|
|
1775
|
+
if (bodyRef.current) {
|
|
1776
|
+
setScrollWidth(
|
|
1777
|
+
bodyRef.current.getBoundingClientRect().width - bodyRef.current.scrollWidth
|
|
1778
|
+
);
|
|
1779
|
+
}
|
|
1780
|
+
}, []);
|
|
1781
|
+
(0, import_react21.useEffect)(() => {
|
|
1782
|
+
setInternalEvents(events.sort(sort_events_default));
|
|
1783
|
+
}, [events]);
|
|
1784
|
+
const [dragStarted, setDragStarted] = (0, import_react21.useState)(false);
|
|
1785
|
+
(0, import_react21.useEffect)(() => {
|
|
1786
|
+
let tempRowsHeight = null;
|
|
1787
|
+
rows.forEach((row) => {
|
|
1788
|
+
if (tempRowsHeight === null) {
|
|
1789
|
+
tempRowsHeight = { [row.id]: { minHeight: 40 } };
|
|
1790
|
+
} else {
|
|
1791
|
+
tempRowsHeight[row.id] = { minHeight: 40 };
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
setRowsHeight(tempRowsHeight);
|
|
1795
|
+
}, [rows]);
|
|
1796
|
+
use_resize_observer_default({ contentRef, setCellWidth, setTick, windowTime });
|
|
1797
|
+
return /* @__PURE__ */ import_react21.default.createElement("div", { className: "main-wrapper", ref: mainRef }, showRTIndicator && /* @__PURE__ */ import_react21.default.createElement(rt_indicator_default, { tick, windowTime }), /* @__PURE__ */ import_react21.default.createElement(
|
|
1798
|
+
time_bar_default,
|
|
1799
|
+
{
|
|
1800
|
+
windowTime,
|
|
1801
|
+
tick,
|
|
1802
|
+
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
1803
|
+
scrollWidth
|
|
1804
|
+
}
|
|
1805
|
+
), /* @__PURE__ */ import_react21.default.createElement("div", { className: "body-wrapper", ref: bodyRef }, /* @__PURE__ */ import_react21.default.createElement(
|
|
1806
|
+
RowsHeightContext.Provider,
|
|
1807
|
+
{
|
|
1808
|
+
value: { rowsHeight, setRowsHeight, allRowsHeight, setAllRowsHeight }
|
|
1809
|
+
},
|
|
1810
|
+
/* @__PURE__ */ import_react21.default.createElement(
|
|
1811
|
+
rows_header_default,
|
|
1812
|
+
{
|
|
1813
|
+
rows,
|
|
1814
|
+
className: additionalClassNames == null ? void 0 : additionalClassNames.rowsHeader
|
|
1815
|
+
}
|
|
1816
|
+
),
|
|
1817
|
+
/* @__PURE__ */ import_react21.default.createElement(DragStartedContext.Provider, { value: { dragStarted, setDragStarted } }, /* @__PURE__ */ import_react21.default.createElement(
|
|
1818
|
+
ExternalPropertiesContext.Provider,
|
|
1819
|
+
{
|
|
1820
|
+
value: { onDrop, onResize, eventsResize }
|
|
1821
|
+
},
|
|
1822
|
+
/* @__PURE__ */ import_react21.default.createElement(
|
|
1823
|
+
content_default,
|
|
1824
|
+
{
|
|
1825
|
+
events: internalEvents,
|
|
1826
|
+
staticEvents,
|
|
1827
|
+
rows,
|
|
1828
|
+
setEvents: setInternalEvents,
|
|
1829
|
+
tick,
|
|
1830
|
+
windowTime,
|
|
1831
|
+
cellWidth,
|
|
1832
|
+
setWindowTime,
|
|
1833
|
+
ref: contentRef,
|
|
1834
|
+
setCellWidth,
|
|
1835
|
+
contentWidth: contentRef.current ? contentRef.current.getBoundingClientRect().width : null,
|
|
1836
|
+
bodyRef,
|
|
1837
|
+
lineClassName: additionalClassNames == null ? void 0 : additionalClassNames.gridLine
|
|
1838
|
+
}
|
|
1839
|
+
)
|
|
1840
|
+
))
|
|
1841
|
+
)));
|
|
1842
|
+
};
|
|
1843
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1844
|
+
0 && (module.exports = {
|
|
1845
|
+
Timeline
|
|
1846
|
+
});
|
|
2
1847
|
//# sourceMappingURL=index.js.map
|