UNPKG

react-weekline

Version:
438 lines (437 loc) 15.1 kB
import ae, { useMemo as P, useState as oe, useEffect as Q, useRef as ee } from "react"; var W = { exports: {} }, C = {}; /** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var re; function le() { if (re) return C; re = 1; var t = Symbol.for("react.transitional.element"), f = Symbol.for("react.fragment"); function o(m, c, d) { var _ = null; if (d !== void 0 && (_ = "" + d), c.key !== void 0 && (_ = "" + c.key), "key" in c) { d = {}; for (var R in c) R !== "key" && (d[R] = c[R]); } else d = c; return c = d.ref, { $$typeof: t, type: m, key: _, ref: c !== void 0 ? c : null, props: d }; } return C.Fragment = f, C.jsx = o, C.jsxs = o, C; } var D = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var te; function ce() { return te || (te = 1, process.env.NODE_ENV !== "production" && (function() { function t(e) { if (e == null) return null; if (typeof e == "function") return e.$$typeof === x ? null : e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case b: return "Fragment"; case E: return "Profiler"; case L: return "StrictMode"; case z: return "Suspense"; case G: return "SuspenseList"; case $: return "Activity"; } if (typeof e == "object") switch (typeof e.tag == "number" && console.error( "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue." ), e.$$typeof) { case F: return "Portal"; case q: return e.displayName || "Context"; case T: return (e._context.displayName || "Context") + ".Consumer"; case J: var r = e.render; return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e; case X: return r = e.displayName || null, r !== null ? r : t(e.type) || "Memo"; case S: r = e._payload, e = e._init; try { return t(e(r)); } catch { } } return null; } function f(e) { return "" + e; } function o(e) { try { f(e); var r = !1; } catch { r = !0; } if (r) { r = console; var a = r.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object"; return a.call( r, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i ), f(e); } } function m(e) { if (e === b) return "<>"; if (typeof e == "object" && e !== null && e.$$typeof === S) return "<...>"; try { var r = t(e); return r ? "<" + r + ">" : "<...>"; } catch { return "<...>"; } } function c() { var e = N.A; return e === null ? null : e.getOwner(); } function d() { return Error("react-stack-top-frame"); } function _(e) { if (A.call(e, "key")) { var r = Object.getOwnPropertyDescriptor(e, "key").get; if (r && r.isReactWarning) return !1; } return e.key !== void 0; } function R(e, r) { function a() { s || (s = !0, console.error( "%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://react.dev/link/special-props)", r )); } a.isReactWarning = !0, Object.defineProperty(e, "key", { get: a, configurable: !0 }); } function I() { var e = t(this.type); return k[e] || (k[e] = !0, console.error( "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release." )), e = this.props.ref, e !== void 0 ? e : null; } function p(e, r, a, i, U, H) { var u = a.ref; return e = { $$typeof: g, type: e, key: r, props: a, _owner: i }, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", { enumerable: !1, get: I }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: 0 }), Object.defineProperty(e, "_debugInfo", { configurable: !1, enumerable: !1, writable: !0, value: null }), Object.defineProperty(e, "_debugStack", { configurable: !1, enumerable: !1, writable: !0, value: U }), Object.defineProperty(e, "_debugTask", { configurable: !1, enumerable: !1, writable: !0, value: H }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e; } function Y(e, r, a, i, U, H) { var u = r.children; if (u !== void 0) if (i) if (B(u)) { for (i = 0; i < u.length; i++) M(u[i]); Object.freeze && Object.freeze(u); } else console.error( "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 M(u); if (A.call(r, "key")) { u = t(e); var j = Object.keys(r).filter(function(se) { return se !== "key"; }); i = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", w[u + i] || (j = 0 < j.length ? "{" + j.join(": ..., ") + ": ...}" : "{}", console.error( `A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, i, u, j, u ), w[u + i] = !0); } if (u = null, a !== void 0 && (o(a), u = "" + a), _(r) && (o(r.key), u = "" + r.key), "key" in r) { a = {}; for (var Z in r) Z !== "key" && (a[Z] = r[Z]); } else a = r; return u && R( a, typeof e == "function" ? e.displayName || e.name || "Unknown" : e ), p( e, u, a, c(), U, H ); } function M(e) { y(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === S && (e._payload.status === "fulfilled" ? y(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1)); } function y(e) { return typeof e == "object" && e !== null && e.$$typeof === g; } var h = ae, g = Symbol.for("react.transitional.element"), F = Symbol.for("react.portal"), b = Symbol.for("react.fragment"), L = Symbol.for("react.strict_mode"), E = Symbol.for("react.profiler"), T = Symbol.for("react.consumer"), q = Symbol.for("react.context"), J = Symbol.for("react.forward_ref"), z = Symbol.for("react.suspense"), G = Symbol.for("react.suspense_list"), X = Symbol.for("react.memo"), S = Symbol.for("react.lazy"), $ = Symbol.for("react.activity"), x = Symbol.for("react.client.reference"), N = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, A = Object.prototype.hasOwnProperty, B = Array.isArray, O = console.createTask ? console.createTask : function() { return null; }; h = { react_stack_bottom_frame: function(e) { return e(); } }; var s, k = {}, l = h.react_stack_bottom_frame.bind( h, d )(), v = O(m(d)), w = {}; D.Fragment = b, D.jsx = function(e, r, a) { var i = 1e4 > N.recentlyCreatedOwnerStacks++; return Y( e, r, a, !1, i ? Error("react-stack-top-frame") : l, i ? O(m(e)) : v ); }, D.jsxs = function(e, r, a) { var i = 1e4 > N.recentlyCreatedOwnerStacks++; return Y( e, r, a, !0, i ? Error("react-stack-top-frame") : l, i ? O(m(e)) : v ); }; })()), D; } var ne; function ie() { return ne || (ne = 1, process.env.NODE_ENV === "production" ? W.exports = le() : W.exports = ce()), W.exports; } var n = ie(); const ue = ["일", "월", "화", "수", "목", "금", "토"], fe = ["월", "화", "수", "목", "금", "토", "일"]; function de(t, f) { const o = new Date(t), m = o.getDay(), c = f === "mon" ? (m + 6) % 7 : m; return o.setDate(o.getDate() - c), o.setHours(0, 0, 0, 0), o; } function V(t, f) { const o = new Date(t); return o.setDate(o.getDate() + f), o; } function me(t, f) { return t.getFullYear() === f.getFullYear() && t.getMonth() === f.getMonth() && t.getDate() === f.getDate(); } function K(t) { return t.toString().padStart(2, "0"); } function ke(t) { return t.getFullYear() + "." + K(t.getMonth() + 1); } function ve(t) { const f = ["일", "월", "화", "수", "목", "금", "토"][t.getDay()]; return t.getFullYear() + "." + K(t.getMonth() + 1) + "." + K(t.getDate()) + " (" + f + ")"; } const we = () => /* @__PURE__ */ n.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ n.jsx( "path", { d: "M15 18L9 12L15 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" } ) }), he = () => /* @__PURE__ */ n.jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ n.jsx( "path", { d: "M9 18L15 12L9 6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" } ) }); function be({ leftHeader: t, rightHeader: f, initialDate: o, renderDayContent: m, startOfWeek: c = "sun", onWeekChange: d, onDateClick: _, showEmptyDays: R = !0, emptyWeekData: I, anchorDateProp: p, onAnchorDateChange: Y, scrollToDateOnClick: M = !0 }) { const y = P(() => /* @__PURE__ */ new Date(), []), h = p !== void 0, [g, F] = oe( p ? new Date(p) : o ? new Date(o) : y ), b = P( () => h ? new Date(p) : g, [h, p, g] ), L = (s) => { h ? Y?.(s) : F(s); }; Q(() => { if (h || !o) return; const s = new Date(o); g.getTime() !== s.getTime() && F(s); }, [o, h, g]); const E = P( () => de(b, c), [b, c] ), T = P( () => Array.from({ length: 7 }, (s, k) => V(E, k)), [E] ), q = c === "mon" ? fe : ue, J = c === "sun" ? 0 : 6, z = c === "sun" ? 6 : 5, G = T[3], X = ke(G), S = P(() => V(E, 6), [E]), $ = ee(d); Q(() => { $.current = d; }, [d]), Q(() => { $.current?.(E, S); }, [E, S]); const x = ee(/* @__PURE__ */ new Map()), N = (s) => { const k = s.toISOString(), l = x.current.get(k); if (l) l.scrollIntoView({ behavior: "smooth", block: "start" }); else { const v = Array.from(x.current.keys()).map((w) => new Date(w)).sort( (w, e) => Math.abs(w.getTime() - s.getTime()) - Math.abs(e.getTime() - s.getTime()) ); v.length > 0 && x.current.get(v[0].toISOString())?.scrollIntoView({ behavior: "smooth", block: "start" }); } }, A = (s) => { _?.(s), M && N(s); }, B = () => L(V(b, -7)), O = () => L(V(b, 7)); return /* @__PURE__ */ n.jsxs("div", { className: "wk-wrapper", children: [ /* @__PURE__ */ n.jsxs("div", { className: "wk-header", children: [ /* @__PURE__ */ n.jsx("div", { className: "wk-header-side wk-left", children: t }), /* @__PURE__ */ n.jsxs("div", { className: "wk-header-center", children: [ /* @__PURE__ */ n.jsx("button", { className: "wk-nav-btn", "aria-label": "이전 주", onClick: B, children: /* @__PURE__ */ n.jsx(we, {}) }), /* @__PURE__ */ n.jsx("span", { className: "wk-year-month", children: X }), /* @__PURE__ */ n.jsx("button", { className: "wk-nav-btn", "aria-label": "다음 주", onClick: O, children: /* @__PURE__ */ n.jsx(he, {}) }) ] }), /* @__PURE__ */ n.jsx("div", { className: "wk-header-side wk-right", children: f }) ] }), /* @__PURE__ */ n.jsx("div", { className: "wk-weekbar", children: q.map((s, k) => { const l = k === J, v = k === z, w = "wk-weekbar-col " + (v ? "wk-sat" : l ? "wk-sun" : ""), e = "wk-weekbar-date " + (me(T[k], y) ? "wk-today " : "") + (v ? "wk-sat" : l ? " wk-sun" : ""); return /* @__PURE__ */ n.jsxs("div", { className: w, children: [ /* @__PURE__ */ n.jsx("div", { className: "wk-weekbar-label", children: s }), /* @__PURE__ */ n.jsx( "div", { className: e + (_ ? " wk-clickable" : ""), onClick: () => A(T[k]), role: "button", tabIndex: 0, "aria-label": "Select date", children: T[k].getDate() } ) ] }, s); }) }), /* @__PURE__ */ n.jsx("div", { className: "wk-weeklist", children: (() => { const s = T.map((l) => ({ date: l, content: m ? m(l) : /* @__PURE__ */ n.jsx("div", { children: "sample html" }) })); return !!m && s.every( (l) => l.content === null || l.content === void 0 ) && I ? /* @__PURE__ */ n.jsx("div", { className: "wk-weeklist-empty", children: I }) : s.map(({ date: l, content: v }) => !R && m && v == null ? null : /* @__PURE__ */ n.jsxs( "div", { className: "wk-weeklist-row", ref: (w) => { w ? x.current.set(l.toISOString(), w) : x.current.delete(l.toISOString()); }, children: [ /* @__PURE__ */ n.jsxs( "div", { className: "wk-weeklist-date-row", onClick: () => A(l), children: [ /* @__PURE__ */ n.jsx("div", { className: "wk-weeklist-date-text", children: ve(l) }), /* @__PURE__ */ n.jsx("div", { className: "wk-divider", "aria-hidden": "true" }) ] } ), /* @__PURE__ */ n.jsx("div", { className: "wk-weeklist-content", children: v ?? null }) ] }, l.toISOString() )); })() }) ] }); } export { be as W }; //# sourceMappingURL=WeekCalendar-CNR_pvr9.js.map