react-weekview
Version:
Week view component and hook for React
995 lines (991 loc) • 33.4 kB
JavaScript
import Me, { useState as pr } from "react";
import { startOfWeek as Pe, startOfDay as te, eachDayOfInterval as hr, addDays as ne, isToday as gr, format as j, eachMinuteOfInterval as br, endOfDay as xr, isSameYear as yr, isSameMonth as Rr, getUnixTime as ae, getMinutes as Y, isSameWeek as $e, getHours as De, getDay as Er } from "date-fns";
function wr({
initialDate: b,
minuteStep: h = 30,
weekStartsOn: x = 1,
locale: o,
disabledCell: v,
disabledDay: m,
disabledWeek: p
} = {}) {
const [s, c] = pr(
Pe(te(b || /* @__PURE__ */ new Date()), { weekStartsOn: x })
), T = () => {
const g = ne(s, 7);
p && p(g) || c(g);
}, w = () => {
const g = ne(s, -7);
p && p(g) || c(g);
}, _ = () => {
c(Pe(te(/* @__PURE__ */ new Date()), { weekStartsOn: x }));
}, d = hr({
start: s,
end: ne(s, 6)
}).map((g) => ({
date: g,
isToday: gr(g),
name: j(g, "EEEE", { locale: o }),
shortName: j(g, "EEE", { locale: o }),
dayOfMonth: j(g, "d", { locale: o }),
dayOfMonthWithZero: j(g, "dd", { locale: o }),
dayOfMonthWithSuffix: j(g, "do", { locale: o }),
disabled: m ? m(g) : !1,
cells: br(
{
start: te(g),
end: xr(g)
},
{
step: h
}
).map((y) => ({
date: y,
hour: j(y, "HH", { locale: o }),
minute: j(y, "mm", { locale: o }),
hourAndMinute: j(y, "HH:mm", { locale: o }),
disabled: v ? v(y) : !1
}))
})), D = yr(d[0].date, d[d.length - 1].date), M = Rr(d[0].date, d[d.length - 1].date);
let k = "";
M ? k = j(d[0].date, "MMMM yyyy", { locale: o }) : D ? k = `${j(d[0].date, "MMM", { locale: o })} - ${j(
d[d.length - 1].date,
"MMM",
{ locale: o }
)} ${j(d[0].date, "yyyy", { locale: o })}` : k = `${j(d[0].date, "MMM yyyy", { locale: o })} - ${j(
d[d.length - 1].date,
"MMM yyyy",
{ locale: o }
)}`;
const H = j(d[0].date, "w", { locale: o });
return {
nextWeek: T,
previousWeek: w,
goToToday: _,
days: d,
weekNumber: H,
viewTitle: k
};
}
var ie = { exports: {} }, I = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ke;
function _r() {
if (ke)
return I;
ke = 1;
var b = Me, h = Symbol.for("react.element"), x = Symbol.for("react.fragment"), o = Object.prototype.hasOwnProperty, v = b.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, m = { key: !0, ref: !0, __self: !0, __source: !0 };
function p(s, c, T) {
var w, _ = {}, d = null, D = null;
T !== void 0 && (d = "" + T), c.key !== void 0 && (d = "" + c.key), c.ref !== void 0 && (D = c.ref);
for (w in c)
o.call(c, w) && !m.hasOwnProperty(w) && (_[w] = c[w]);
if (s && s.defaultProps)
for (w in c = s.defaultProps, c)
_[w] === void 0 && (_[w] = c[w]);
return { $$typeof: h, type: s, key: d, ref: D, props: _, _owner: v.current };
}
return I.Fragment = x, I.jsx = p, I.jsxs = p, I;
}
var L = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Ne;
function jr() {
return Ne || (Ne = 1, process.env.NODE_ENV !== "production" && function() {
var b = Me, h = Symbol.for("react.element"), x = Symbol.for("react.portal"), o = Symbol.for("react.fragment"), v = Symbol.for("react.strict_mode"), m = Symbol.for("react.profiler"), p = Symbol.for("react.provider"), s = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), w = Symbol.for("react.suspense_list"), _ = Symbol.for("react.memo"), d = Symbol.for("react.lazy"), D = Symbol.for("react.offscreen"), M = Symbol.iterator, k = "@@iterator";
function H(e) {
if (e === null || typeof e != "object")
return null;
var r = M && e[M] || e[k];
return typeof r == "function" ? r : null;
}
var g = b.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function y(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
We("error", e, t);
}
}
function We(e, r, t) {
{
var n = g.ReactDebugCurrentFrame, u = n.getStackAddendum();
u !== "" && (r += "%s", t = t.concat([u]));
var f = t.map(function(l) {
return String(l);
});
f.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, f);
}
}
var Ae = !1, Fe = !1, Ie = !1, Le = !1, Ye = !1, oe;
oe = Symbol.for("react.module.reference");
function Ve(e) {
return !!(typeof e == "string" || typeof e == "function" || e === o || e === m || Ye || e === v || e === T || e === w || Le || e === D || Ae || Fe || Ie || typeof e == "object" && e !== null && (e.$$typeof === d || e.$$typeof === _ || e.$$typeof === p || e.$$typeof === s || e.$$typeof === c || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === oe || e.getModuleId !== void 0));
}
function Ue(e, r, t) {
var n = e.displayName;
if (n)
return n;
var u = r.displayName || r.name || "";
return u !== "" ? t + "(" + u + ")" : t;
}
function se(e) {
return e.displayName || "Context";
}
function S(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case o:
return "Fragment";
case x:
return "Portal";
case m:
return "Profiler";
case v:
return "StrictMode";
case T:
return "Suspense";
case w:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case s:
var r = e;
return se(r) + ".Consumer";
case p:
var t = e;
return se(t._context) + ".Provider";
case c:
return Ue(e, e.render, "ForwardRef");
case _:
var n = e.displayName || null;
return n !== null ? n : S(e.type) || "Memo";
case d: {
var u = e, f = u._payload, l = u._init;
try {
return S(l(f));
} catch {
return null;
}
}
}
return null;
}
var N = Object.assign, A = 0, le, ue, fe, ce, de, ve, me;
function pe() {
}
pe.__reactDisabledLog = !0;
function Be() {
{
if (A === 0) {
le = console.log, ue = console.info, fe = console.warn, ce = console.error, de = console.group, ve = console.groupCollapsed, me = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: pe,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
A++;
}
}
function Ge() {
{
if (A--, A === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: N({}, e, {
value: le
}),
info: N({}, e, {
value: ue
}),
warn: N({}, e, {
value: fe
}),
error: N({}, e, {
value: ce
}),
group: N({}, e, {
value: de
}),
groupCollapsed: N({}, e, {
value: ve
}),
groupEnd: N({}, e, {
value: me
})
});
}
A < 0 && y("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var J = g.ReactCurrentDispatcher, z;
function V(e, r, t) {
{
if (z === void 0)
try {
throw Error();
} catch (u) {
var n = u.stack.trim().match(/\n( *(at )?)/);
z = n && n[1] || "";
}
return `
` + z + e;
}
}
var Z = !1, U;
{
var qe = typeof WeakMap == "function" ? WeakMap : Map;
U = new qe();
}
function he(e, r) {
if (!e || Z)
return "";
{
var t = U.get(e);
if (t !== void 0)
return t;
}
var n;
Z = !0;
var u = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var f;
f = J.current, J.current = null, Be();
try {
if (r) {
var l = function() {
throw Error();
};
if (Object.defineProperty(l.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(l, []);
} catch (P) {
n = P;
}
Reflect.construct(e, [], l);
} else {
try {
l.call();
} catch (P) {
n = P;
}
e.call(l.prototype);
}
} else {
try {
throw Error();
} catch (P) {
n = P;
}
e();
}
} catch (P) {
if (P && n && typeof P.stack == "string") {
for (var i = P.stack.split(`
`), O = n.stack.split(`
`), R = i.length - 1, E = O.length - 1; R >= 1 && E >= 0 && i[R] !== O[E]; )
E--;
for (; R >= 1 && E >= 0; R--, E--)
if (i[R] !== O[E]) {
if (R !== 1 || E !== 1)
do
if (R--, E--, E < 0 || i[R] !== O[E]) {
var C = `
` + i[R].replace(" at new ", " at ");
return e.displayName && C.includes("<anonymous>") && (C = C.replace("<anonymous>", e.displayName)), typeof e == "function" && U.set(e, C), C;
}
while (R >= 1 && E >= 0);
break;
}
}
} finally {
Z = !1, J.current = f, Ge(), Error.prepareStackTrace = u;
}
var W = e ? e.displayName || e.name : "", Se = W ? V(W) : "";
return typeof e == "function" && U.set(e, Se), Se;
}
function He(e, r, t) {
return he(e, !1);
}
function Je(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function B(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return he(e, Je(e));
if (typeof e == "string")
return V(e);
switch (e) {
case T:
return V("Suspense");
case w:
return V("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case c:
return He(e.render);
case _:
return B(e.type, r, t);
case d: {
var n = e, u = n._payload, f = n._init;
try {
return B(f(u), r, t);
} catch {
}
}
}
return "";
}
var G = Object.prototype.hasOwnProperty, ge = {}, be = g.ReactDebugCurrentFrame;
function q(e) {
if (e) {
var r = e._owner, t = B(e.type, e._source, r ? r.type : null);
be.setExtraStackFrame(t);
} else
be.setExtraStackFrame(null);
}
function ze(e, r, t, n, u) {
{
var f = Function.call.bind(G);
for (var l in e)
if (f(e, l)) {
var i = void 0;
try {
if (typeof e[l] != "function") {
var O = Error((n || "React class") + ": " + t + " type `" + l + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[l] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw O.name = "Invariant Violation", O;
}
i = e[l](r, l, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (R) {
i = R;
}
i && !(i instanceof Error) && (q(u), y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, l, typeof i), q(null)), i instanceof Error && !(i.message in ge) && (ge[i.message] = !0, q(u), y("Failed %s type: %s", t, i.message), q(null));
}
}
}
var Ze = Array.isArray;
function K(e) {
return Ze(e);
}
function Ke(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function Xe(e) {
try {
return xe(e), !1;
} catch {
return !0;
}
}
function xe(e) {
return "" + e;
}
function ye(e) {
if (Xe(e))
return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ke(e)), xe(e);
}
var F = g.ReactCurrentOwner, Qe = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Re, Ee, X;
X = {};
function er(e) {
if (G.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function rr(e) {
if (G.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function tr(e, r) {
if (typeof e.ref == "string" && F.current && r && F.current.stateNode !== r) {
var t = S(F.current.type);
X[t] || (y('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', S(F.current.type), e.ref), X[t] = !0);
}
}
function nr(e, r) {
{
var t = function() {
Re || (Re = !0, y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function ar(e, r) {
{
var t = function() {
Ee || (Ee = !0, y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var ir = function(e, r, t, n, u, f, l) {
var i = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: h,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: l,
// Record the component responsible for creating this element.
_owner: f
};
return i._store = {}, Object.defineProperty(i._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(i, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: n
}), Object.defineProperty(i, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: u
}), Object.freeze && (Object.freeze(i.props), Object.freeze(i)), i;
};
function or(e, r, t, n, u) {
{
var f, l = {}, i = null, O = null;
t !== void 0 && (ye(t), i = "" + t), rr(r) && (ye(r.key), i = "" + r.key), er(r) && (O = r.ref, tr(r, u));
for (f in r)
G.call(r, f) && !Qe.hasOwnProperty(f) && (l[f] = r[f]);
if (e && e.defaultProps) {
var R = e.defaultProps;
for (f in R)
l[f] === void 0 && (l[f] = R[f]);
}
if (i || O) {
var E = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
i && nr(l, E), O && ar(l, E);
}
return ir(e, i, O, u, n, F.current, l);
}
}
var Q = g.ReactCurrentOwner, we = g.ReactDebugCurrentFrame;
function $(e) {
if (e) {
var r = e._owner, t = B(e.type, e._source, r ? r.type : null);
we.setExtraStackFrame(t);
} else
we.setExtraStackFrame(null);
}
var ee;
ee = !1;
function re(e) {
return typeof e == "object" && e !== null && e.$$typeof === h;
}
function _e() {
{
if (Q.current) {
var e = S(Q.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function sr(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var je = {};
function lr(e) {
{
var r = _e();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function Te(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = lr(r);
if (je[t])
return;
je[t] = !0;
var n = "";
e && e._owner && e._owner !== Q.current && (n = " It was passed a child from " + S(e._owner.type) + "."), $(e), y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), $(null);
}
}
function Oe(e, r) {
{
if (typeof e != "object")
return;
if (K(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
re(n) && Te(n, r);
}
else if (re(e))
e._store && (e._store.validated = !0);
else if (e) {
var u = H(e);
if (typeof u == "function" && u !== e.entries)
for (var f = u.call(e), l; !(l = f.next()).done; )
re(l.value) && Te(l.value, r);
}
}
}
function ur(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === c || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === _))
t = r.propTypes;
else
return;
if (t) {
var n = S(r);
ze(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !ee) {
ee = !0;
var u = S(r);
y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function fr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
$(e), y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), $(null);
break;
}
}
e.ref !== null && ($(e), y("Invalid attribute `ref` supplied to `React.Fragment`."), $(null));
}
}
function Ce(e, r, t, n, u, f) {
{
var l = Ve(e);
if (!l) {
var i = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (i += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var O = sr(u);
O ? i += O : i += _e();
var R;
e === null ? R = "null" : K(e) ? R = "array" : e !== void 0 && e.$$typeof === h ? (R = "<" + (S(e.type) || "Unknown") + " />", i = " Did you accidentally export a JSX literal instead of a component?") : R = typeof e, y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", R, i);
}
var E = or(e, r, t, u, f);
if (E == null)
return E;
if (l) {
var C = r.children;
if (C !== void 0)
if (n)
if (K(C)) {
for (var W = 0; W < C.length; W++)
Oe(C[W], e);
Object.freeze && Object.freeze(C);
} else
y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Oe(C, e);
}
return e === o ? fr(E) : ur(E), E;
}
}
function cr(e, r, t) {
return Ce(e, r, t, !0);
}
function dr(e, r, t) {
return Ce(e, r, t, !1);
}
var vr = dr, mr = cr;
L.Fragment = o, L.jsx = vr, L.jsxs = mr;
}()), L;
}
process.env.NODE_ENV === "production" ? ie.exports = _r() : ie.exports = jr();
var a = ie.exports;
function Tr({
title: b,
showTodayButton: h = !0,
todayButton: x,
onToday: o,
showPrevButton: v = !0,
prevButton: m,
onPrev: p,
showNextButton: s = !0,
nextButton: c,
onNext: T
}) {
return /* @__PURE__ */ a.jsxs("header", { className: "flex items-center justify-between bg-slate-50 border-b px-6 py-4 h-16", children: [
/* @__PURE__ */ a.jsxs("h1", { className: "flex items-center gap-3 text-base font-semibold text-slate-600", children: [
b,
h && (x ? x({ onToday: o }) : /* @__PURE__ */ a.jsx(
"button",
{
className: "inline-flex items-center justify-center text-xs transition-colors font-normal border border-slate-200 bg-white hover:bg-slate-50 h-8 rounded-md px-3",
onClick: o,
children: "Today"
}
))
] }),
/* @__PURE__ */ a.jsx("div", { className: "flex items-center space-x-5", children: /* @__PURE__ */ a.jsxs("div", { className: "flex space-x-1", children: [
v && (m ? m({ onPrev: p }) : /* @__PURE__ */ a.jsx(
"button",
{
className: "inline-flex items-center justify-center text-xs transition-colors font-normal border border-slate-200 bg-white hover:bg-slate-50 h-8 w-8 rounded-md",
onClick: p,
children: /* @__PURE__ */ a.jsx(
"svg",
{
width: "16",
height: "16",
viewBox: "0 0 15 15",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
children: /* @__PURE__ */ a.jsx(
"path",
{
d: "M8.84182 3.13514C9.04327 3.32401 9.05348 3.64042 8.86462 3.84188L5.43521 7.49991L8.86462 11.1579C9.05348 11.3594 9.04327 11.6758 8.84182 11.8647C8.64036 12.0535 8.32394 12.0433 8.13508 11.8419L4.38508 7.84188C4.20477 7.64955 4.20477 7.35027 4.38508 7.15794L8.13508 3.15794C8.32394 2.95648 8.64036 2.94628 8.84182 3.13514Z",
fill: "currentColor",
fillRule: "evenodd",
clipRule: "evenodd"
}
)
}
)
}
)),
s && (c ? c({ onNext: T }) : /* @__PURE__ */ a.jsx(
"button",
{
className: "inline-flex items-center justify-center text-xs transition-colors font-normal border border-slate-200 bg-white hover:bg-slate-50 h-8 w-8 rounded-md",
onClick: T,
children: /* @__PURE__ */ a.jsx(
"svg",
{
width: "16",
height: "16",
viewBox: "0 0 15 15",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
children: /* @__PURE__ */ a.jsx(
"path",
{
d: "M6.1584 3.13508C6.35985 2.94621 6.67627 2.95642 6.86514 3.15788L10.6151 7.15788C10.7954 7.3502 10.7954 7.64949 10.6151 7.84182L6.86514 11.8418C6.67627 12.0433 6.35985 12.0535 6.1584 11.8646C5.95694 11.6757 5.94673 11.3593 6.1356 11.1579L9.565 7.49985L6.1356 3.84182C5.94673 3.64036 5.95694 3.32394 6.1584 3.13508Z",
fill: "currentColor",
fillRule: "evenodd",
clipRule: "evenodd"
}
)
}
)
}
))
] }) })
] });
}
function Or({ days: b }) {
return /* @__PURE__ */ a.jsx("div", { className: "sticky top-0 z-30 flex-none bg-white shadow", children: /* @__PURE__ */ a.jsx("div", { className: "grid grid-cols-7 text-sm leading-6 text-slate-500", children: b.map((h, x) => /* @__PURE__ */ a.jsx(
"div",
{
className: `
flex items-center justify-center h-14 border-l border-gray-100
${x === 0 && "border-l-0"}
`,
children: /* @__PURE__ */ a.jsxs("span", { className: h.isToday ? "flex items-center" : "", children: [
h.shortName,
" ",
/* @__PURE__ */ a.jsx(
"span",
{
className: `
font-semibold text-slate-900
${h.isToday && "flex items-center justify-center rounded-full w-8 h-8 ml-1.5 text-white bg-indigo-600"}
`,
children: h.dayOfMonthWithZero
}
)
] })
},
ae(h.date)
)) }) });
}
function Cr({
days: b,
rowHeight: h,
CellContent: x,
onCellClick: o
}) {
return /* @__PURE__ */ a.jsxs(
"div",
{
style: {
display: "grid",
gridTemplateColumns: `repeat(${b.length}, minmax(0, 1fr))`,
gridTemplateRows: `repeat(${b[0].cells.length}, minmax(${h}px, 1fr))`
},
children: [
b.map(
(v, m) => v.cells.map((p, s) => /* @__PURE__ */ a.jsx(
"button",
{
className: "relative border-t border-l border-gray-100 transition-colors cursor-pointer hover:bg-slate-100 disabled:bg-slate-50",
style: {
gridRowStart: s + 1,
gridRowEnd: s + 2,
gridColumnStart: m + 1,
gridColumnEnd: m + 2
},
disabled: p.disabled,
onClick: () => o == null ? void 0 : o(p),
children: x && x(p)
},
ae(p.date)
))
),
/* @__PURE__ */ a.jsx(
"div",
{
className: "sticky left-0 grid pointer-events-none",
style: {
display: "grid",
gridRowStart: 1,
gridRowEnd: -1,
gridColumnStart: 1,
gridTemplateRows: `repeat(${b[0].cells.length}, minmax(${h}px, 1fr))`
},
children: b[0].cells.map(
(v, m) => Y(v.date) === 0 && /* @__PURE__ */ a.jsx(
"div",
{
className: "relative flex items-center justify-center border-t border-gray-100",
style: {
gridRowStart: m + 1,
gridRowEnd: m + 2
},
children: /* @__PURE__ */ a.jsx("span", { className: "absolute top-0 left-0 text-xs text-slate-400 px-1", children: v.hourAndMinute })
},
ae(v.date)
)
)
}
)
]
}
);
}
function Sr({
days: b,
events: h,
weekStartsOn: x,
locale: o,
minuteStep: v,
rowHeight: m,
onEventClick: p
}) {
return /* @__PURE__ */ a.jsx(
"div",
{
style: {
display: "grid",
gridTemplateColumns: `repeat(${b.length}, minmax(0, 1fr))`,
gridTemplateRows: `repeat(${b[0].cells.length}, minmax(${m}px, 1fr))`
},
children: (h || []).filter((s) => $e(b[0].date, s.startDate)).map((s) => {
const c = De(s.startDate) * 2 + 1 + Math.floor(Y(s.startDate) / v), T = De(s.endDate) * 2 + 1 + Math.ceil(Y(s.endDate) / v), w = Y(s.startDate) % v / v * m, _ = (m - Y(s.endDate) % v / v * m) % m;
return /* @__PURE__ */ a.jsx(
"div",
{
className: "relative flex mt-[1px] transition-all",
style: {
gridRowStart: c,
gridRowEnd: T,
gridColumnStart: Er(s.startDate) - x + 1,
gridColumnEnd: "span 1"
},
children: /* @__PURE__ */ a.jsxs(
"span",
{
className: "absolute inset-1 flex flex-col overflow-y-auto rounded-md p-2 text-xs leading-5 bg-blue-50 border border-transparent border-dashed hover:bg-blue-100 transition cursor-pointer",
style: {
top: w + 4,
bottom: _ + 4
},
onClick: () => p == null ? void 0 : p(s),
children: [
/* @__PURE__ */ a.jsxs("p", { className: "text-blue-500 leading-4", children: [
j(new Date(s.startDate), "H:mm", {
weekStartsOn: x,
locale: o
}),
"-",
j(new Date(s.endDate), "H:mm", {
weekStartsOn: x,
locale: o
})
] }),
/* @__PURE__ */ a.jsx("p", { className: "font-semibold text-blue-700", children: s.title })
]
}
)
},
s.id
);
})
}
);
}
function kr({
initialDate: b,
minuteStep: h = 30,
weekStartsOn: x = 1,
locale: o,
rowHeight: v = 56,
disabledCell: m,
disabledDay: p,
disabledWeek: s,
events: c,
onCellClick: T,
onEventClick: w
}) {
const { days: _, nextWeek: d, previousWeek: D, goToToday: M, viewTitle: k } = wr({
initialDate: b,
minuteStep: h,
weekStartsOn: x,
locale: o,
disabledCell: m,
disabledDay: p,
disabledWeek: s
});
return /* @__PURE__ */ a.jsxs("div", { className: "flex flex-col h-full overflow-hidden", children: [
/* @__PURE__ */ a.jsx(
Tr,
{
title: k,
onNext: d,
onPrev: D,
onToday: M,
showTodayButton: !$e(_[0].date, /* @__PURE__ */ new Date())
}
),
/* @__PURE__ */ a.jsx("div", { className: "flex flex-col flex-1 overflow-hidden select-none", children: /* @__PURE__ */ a.jsx("div", { className: "flex flex-col flex-1 isolate overflow-auto", children: /* @__PURE__ */ a.jsxs("div", { className: "flex flex-col flex-none min-w-[700px]", children: [
/* @__PURE__ */ a.jsx(Or, { days: _ }),
/* @__PURE__ */ a.jsxs("div", { className: "grid grid-cols-1 grid-rows-1", children: [
/* @__PURE__ */ a.jsx("div", { className: "row-start-1 col-start-1", children: /* @__PURE__ */ a.jsx(
Cr,
{
days: _,
rowHeight: v,
onCellClick: T
}
) }),
/* @__PURE__ */ a.jsx("div", { className: "row-start-1 col-start-1", children: /* @__PURE__ */ a.jsx(
Sr,
{
days: _,
events: c,
weekStartsOn: x,
locale: o,
minuteStep: h,
rowHeight: v,
onEventClick: w
}
) })
] })
] }) }) })
] });
}
export {
kr as WeekView,
Or as WeekViewDaysHeader,
Cr as WeekViewGrid,
Tr as WeekViewHeader,
wr as useWeekView
};