UNPKG

uiv

Version:

Bootstrap 3 components implemented by Vue.

837 lines (836 loc) 24.6 kB
import { openBlock as s, createElementBlock as y, normalizeClass as w, renderSlot as x, computed as T, unref as p, createBlock as W, resolveDynamicComponent as Z, withCtx as C, createElementVNode as l, withModifiers as _, createVNode as M, toDisplayString as B, createCommentVNode as U, Fragment as P, renderList as Y, reactive as ee, onMounted as X, ref as O, watch as te, normalizeStyle as ne, withDirectives as A, vShow as H, createTextVNode as q } from "vue"; function I(t) { return typeof t < "u" && t !== null; } function ae(t) { return typeof t == "function"; } function J(t) { return typeof t == "number"; } const le = { uiv: { datePicker: { clear: "Clear", today: "Today", month: "Month", month1: "January", month2: "February", month3: "March", month4: "April", month5: "May", month6: "June", month7: "July", month8: "August", month9: "September", month10: "October", month11: "November", month12: "December", year: "Year", week1: "Mon", week2: "Tue", week3: "Wed", week4: "Thu", week5: "Fri", week6: "Sat", week7: "Sun" }, timePicker: { am: "AM", pm: "PM" }, modal: { cancel: "Cancel", ok: "OK" }, multiSelect: { placeholder: "Select...", filterPlaceholder: "Search..." } } }; let oe = le, re = function() { return "$t" in this ? this.$t.apply(this, arguments) : null; }; const R = function(t, n) { n = n || {}; let e; try { if (e = re.apply(this, arguments), I(e) && !n.$$locale) return e; } catch { } const i = t.split("."); let f = n.$$locale || oe; for (let u = 0, m = i.length; u < m; u++) { const r = i[u]; if (e = f[r], u === m - 1) return e; if (!e) return ""; f = e; } return ""; }, ie = { __name: "BtnGroup", props: { size: { type: String, default: void 0 }, vertical: { type: Boolean, default: !1 }, justified: { type: Boolean, default: !1 } }, setup(t) { return (n, e) => (s(), y("div", { class: w({ "btn-group": !t.vertical, "btn-group-vertical": t.vertical, "btn-group-justified": t.justified, [`btn-group-${t.size}`]: t.size }), role: "group", "data-toggle": "buttons" }, [ x(n.$slots, "default") ], 2)); } }, ue = { // <a> props href: { type: String, default: void 0 }, target: { type: String, default: void 0 }, // <router-link> props to: { type: null, default: void 0 }, replace: { type: Boolean, default: !1 }, append: { type: Boolean, default: !1 }, exact: { type: Boolean, default: !1 } }, ce = ["href", "target"], se = ["type", "checked", "disabled"], de = ["type", "disabled"], fe = ["type", "disabled"], $ = { __name: "Btn", props: { ...ue, justified: { type: Boolean, default: !1 }, type: { type: String, default: "default" }, nativeType: { type: String, default: "button" }, size: { type: String, default: void 0 }, block: { type: Boolean, default: !1 }, active: { type: Boolean, default: !1 }, disabled: { type: Boolean, default: !1 }, // <input> props modelValue: { type: null, default: null }, inputValue: { type: null, default: null }, inputType: { type: String, validator(t) { return t === "checkbox" || t === "radio"; }, default: void 0 } }, emits: ["update:modelValue"], setup(t, { emit: n }) { const e = t, i = T( () => e.inputType === "checkbox" ? e.modelValue.indexOf(e.inputValue) >= 0 : e.modelValue === e.inputValue ), f = T(() => ({ btn: !0, active: e.inputType ? i.value : e.active, disabled: e.disabled, "btn-block": e.block, [`btn-${e.type}`]: !!e.type, [`btn-${e.size}`]: !!e.size })); function u(r) { e.disabled && r instanceof Event && (r.preventDefault(), r.stopPropagation()); } function m() { if (e.inputType === "checkbox") { const r = e.modelValue.slice(); i.value ? r.splice(r.indexOf(e.inputValue), 1) : r.push(e.inputValue), n("update:modelValue", r); } else n("update:modelValue", e.inputValue); } return (r, V) => r.href ? (s(), y("a", { key: 0, href: r.href, target: r.target, role: "button", class: w(p(f)), onClick: u }, [ x(r.$slots, "default") ], 10, ce)) : r.to ? (s(), W(Z("RouterLink"), { key: 1, to: r.to, class: w(p(f)), event: t.disabled ? "" : "click", replace: r.replace, append: r.append, exact: r.exact, role: "button", onClick: u }, { default: C(() => [ x(r.$slots, "default") ]), _: 3 }, 8, ["to", "class", "event", "replace", "append", "exact"])) : t.inputType ? (s(), y("label", { key: 2, class: w(p(f)), onClick: u }, [ l("input", { autocomplete: "off", type: t.inputType, checked: p(i), disabled: t.disabled, onInput: V[0] || (V[0] = _(() => { }, ["stop"])), onChange: m }, null, 40, se), x(r.$slots, "default") ], 2)) : t.justified ? (s(), W(ie, { key: 3 }, { default: C(() => [ l("button", { class: w(p(f)), type: t.nativeType, disabled: t.disabled, onClick: u }, [ x(r.$slots, "default") ], 10, de) ]), _: 3 })) : (s(), y("button", { key: 4, class: w(p(f)), type: t.nativeType, disabled: t.disabled, onClick: u }, [ x(r.$slots, "default") ], 10, fe)); } }; function K(t, n) { let e = t.toString(); for (let i = n - e.length; i > 0; i--) e = "0" + e; return e; } const ye = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; function he(t, n) { return new Date(n, t + 1, 0).getDate(); } function me(t, n) { try { const e = t.getFullYear(), i = t.getMonth() + 1, f = t.getDate(), u = ye[i - 1]; return n.replace(/yyyy/g, e).replace(/MMMM/g, u).replace(/MMM/g, u.substring(0, 3)).replace(/MM/g, K(i, 2)).replace(/dd/g, K(f, 2)).replace(/yy/g, e).replace(/M(?!a)/g, i).replace(/d/g, f); } catch { return ""; } } function Q(t) { return new Date( t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate(), t.getUTCHours(), t.getUTCMinutes(), t.getUTCSeconds() ); } function ge(t) { const n = new Date(Date.UTC(t.year, t.month, t.date)); n.setUTCDate(n.getUTCDate() + 4 - (n.getUTCDay() || 7)); const e = new Date(Date.UTC(n.getUTCFullYear(), 0, 1)); return Math.ceil(((n - e) / 864e5 + 1) / 7); } const pe = { role: "grid", style: { width: "100%" } }, ke = ["colspan"], ve = { align: "center" }, be = { key: 0 }, Ce = { class: "uiv-datepicker-week" }, we = { key: 0, class: "text-center", style: { "border-right": "1px solid #eee" } }, Me = { class: "text-muted" }, De = { __name: "DateView", props: { month: { type: Number, default: void 0 }, year: { type: Number, default: void 0 }, date: { type: Date, default: void 0 }, today: { type: Date, default: void 0 }, limit: { type: Object, default: void 0 }, weekStartsWith: { type: Number, default: void 0 }, iconControlLeft: { type: String, default: void 0 }, iconControlRight: { type: String, default: void 0 }, dateClass: { type: Function, default: void 0 }, yearMonthFormatter: { type: Function, default: void 0 }, weekNumbers: Boolean }, emits: [ "date-change", "year-change", "month-change", "view-change" ], setup(t, { emit: n }) { const e = t, i = T(() => { const a = []; let h = e.weekStartsWith; for (; a.length < 7; ) a.push(h++), h > 6 && (h = 0); return a; }), f = T(() => e.yearMonthFormatter ? e.yearMonthFormatter(e.year, e.month) : I(e.month) ? `${e.year} ${R(`uiv.datePicker.month${e.month + 1}`)}` : e.year), u = T(() => { var L, o; const a = [], h = new Date(e.year, e.month, 1), k = new Date(e.year, e.month, 0).getDate(), v = h.getDay(), N = he(e.month, e.year); let F = 0; e.weekStartsWith > v ? F = 7 - e.weekStartsWith : F = 0 - e.weekStartsWith; for (let c = 0; c < 6; c++) { a.push([]); for (let z = 0 - F; z < 7 - F; z++) { const S = c * 7 + z, b = { year: e.year, disabled: !1 }; S < v ? (b.date = k - v + S + 1, e.month > 0 ? b.month = e.month - 1 : (b.month = 11, b.year--)) : S < v + N ? (b.date = S - v + 1, b.month = e.month) : (b.date = S - v - N + 1, e.month < 11 ? b.month = e.month + 1 : (b.month = 0, b.year++)); const j = new Date(b.year, b.month, b.date); let E = !0, G = !0; (L = e.limit) != null && L.from && (E = j >= e.limit.from), (o = e.limit) != null && o.to && (G = j < e.limit.to), b.disabled = !E || !G, ae(e.dateClass) ? b.classes = e.dateClass(j, { currentMonth: e.month, currentYear: e.year }) : b.classes = "", a[c].push(b); } } return a; }); function m(a) { return R(`uiv.datePicker.week${a}`); } function r(a) { return e.date && a.date === e.date.getDate() && a.month === e.date.getMonth() && a.year === e.date.getFullYear() ? "primary" : a.date === e.today.getDate() && a.month === e.today.getMonth() && a.year === e.today.getFullYear() ? "info" : "default"; } function V(a) { n("date-change", a); } function d() { let a = e.month, h = e.year; e.month > 0 ? a-- : (a = 11, h--, n("year-change", h)), n("month-change", a); } function g() { let a = e.month, h = e.year; e.month < 11 ? a++ : (a = 0, h++, n("year-change", h)), n("month-change", a); } function D() { n("view-change", "m"); } return (a, h) => (s(), y("table", pe, [ l("thead", null, [ l("tr", null, [ l("td", null, [ M($, { class: "uiv-datepicker-pager-prev", block: "", size: "sm", style: { border: "none" }, onClick: d }, { default: C(() => [ l("i", { class: w(t.iconControlLeft) }, null, 2) ]), _: 1 }) ]), l("td", { colspan: t.weekNumbers ? 6 : 5 }, [ M($, { class: "uiv-datepicker-title", block: "", size: "sm", style: { border: "none" }, onClick: D }, { default: C(() => [ l("b", null, B(p(f)), 1) ]), _: 1 }) ], 8, ke), l("td", null, [ M($, { class: "uiv-datepicker-pager-next", block: "", size: "sm", style: { border: "none" }, onClick: g }, { default: C(() => [ l("i", { class: w(t.iconControlRight) }, null, 2) ]), _: 1 }) ]) ]), l("tr", ve, [ t.weekNumbers ? (s(), y("td", be)) : U("", !0), (s(!0), y(P, null, Y(p(i), (k, v) => (s(), y("td", { key: v, width: "14.2857142857%" }, [ l("small", Ce, B(m(k === 0 ? 7 : k)), 1) ]))), 128)) ]) ]), l("tbody", null, [ (s(!0), y(P, null, Y(p(u), (k, v) => (s(), y("tr", { key: v }, [ t.weekNumbers ? (s(), y("td", we, [ l("small", Me, B(p(ge)(k[t.weekStartsWith])), 1) ])) : U("", !0), (s(!0), y(P, null, Y(k, (N, F) => (s(), y("td", { key: `${v}_${F}` }, [ M($, { block: "", size: "sm", style: { border: "none" }, "data-action": "select", class: w(N.classes), type: r(N), disabled: N.disabled, onClick: (L) => V(N) }, { default: C(() => [ l("span", { "data-action": "select", class: w({ "text-muted": t.month !== N.month }) }, B(N.date), 3) ]), _: 2 }, 1032, ["class", "type", "disabled", "onClick"]) ]))), 128)) ]))), 128)) ]) ])); } }, $e = { role: "grid", style: { width: "100%" } }, Se = { colspan: "4" }, Ve = { __name: "MonthView", props: { month: { type: Number, default: void 0 }, year: { type: Number, default: void 0 }, iconControlLeft: { type: String, default: void 0 }, iconControlRight: { type: String, default: void 0 } }, emits: ["year-change", "month-change", "view-change"], setup(t, { emit: n }) { const e = t, i = ee([]); X(() => { for (let d = 0; d < 4; d++) { i.push([]); for (let g = 0; g < 3; g++) i[d].push(d * 3 + g + 1); } }); function f(d) { return R(`uiv.datePicker.month${d}`); } function u(d) { return d === e.month ? "primary" : "default"; } function m() { n("year-change", e.year - 1); } function r() { n("year-change", e.year + 1); } function V(d) { I(d) ? (n("month-change", d), n("view-change", "d")) : n("view-change", "y"); } return (d, g) => (s(), y("table", $e, [ l("thead", null, [ l("tr", null, [ l("td", null, [ M($, { class: "uiv-datepicker-pager-prev", block: "", size: "sm", style: { border: "none" }, onClick: m }, { default: C(() => [ l("i", { class: w(t.iconControlLeft) }, null, 2) ]), _: 1 }) ]), l("td", Se, [ M($, { class: "uiv-datepicker-title", block: "", size: "sm", style: { border: "none" }, onClick: g[0] || (g[0] = (D) => V()) }, { default: C(() => [ l("b", null, B(t.year), 1) ]), _: 1 }) ]), l("td", null, [ M($, { class: "uiv-datepicker-pager-next", block: "", size: "sm", style: { border: "none" }, onClick: r }, { default: C(() => [ l("i", { class: w(t.iconControlRight) }, null, 2) ]), _: 1 }) ]) ]) ]), l("tbody", null, [ (s(!0), y(P, null, Y(i, (D, a) => (s(), y("tr", { key: a }, [ (s(!0), y(P, null, Y(D, (h, k) => (s(), y("td", { key: `${a}_${k}`, colspan: "2", width: "33.333333%" }, [ M($, { block: "", size: "sm", style: { border: "none" }, type: u(a * 3 + k), onClick: (v) => V(a * 3 + k) }, { default: C(() => [ l("span", null, B(f(h)), 1) ]), _: 2 }, 1032, ["type", "onClick"]) ]))), 128)) ]))), 128)) ]) ])); } }, Ne = { role: "grid", style: { width: "100%" } }, Te = { colspan: "3" }, Be = { __name: "YearView", props: { year: { type: Number, default: void 0 }, iconControlLeft: { type: String, default: void 0 }, iconControlRight: { type: String, default: void 0 } }, emits: ["year-change", "view-change"], setup(t, { emit: n }) { const e = t; function i(d) { return d === e.year ? "primary" : "default"; } function f() { n("year-change", e.year - 20); } function u() { n("year-change", e.year + 20); } function m(d) { n("year-change", d), n("view-change", "m"); } const r = T(() => { const d = [], g = e.year - e.year % 20; for (let D = 0; D < 4; D++) { d.push([]); for (let a = 0; a < 5; a++) d[D].push(g + D * 5 + a); } return d; }), V = T(() => { const d = e.year - e.year % 20; return `${d} ~ ${d + 19}`; }); return (d, g) => (s(), y("table", Ne, [ l("thead", null, [ l("tr", null, [ l("td", null, [ M($, { class: "uiv-datepicker-pager-prev", block: "", size: "sm", style: { border: "none" }, onClick: f }, { default: C(() => [ l("i", { class: w(t.iconControlLeft) }, null, 2) ]), _: 1 }) ]), l("td", Te, [ M($, { class: "uiv-datepicker-title", block: "", size: "sm", style: { border: "none" } }, { default: C(() => [ l("b", null, B(p(V)), 1) ]), _: 1 }) ]), l("td", null, [ M($, { class: "uiv-datepicker-pager-next", block: "", size: "sm", style: { border: "none" }, onClick: u }, { default: C(() => [ l("i", { class: w(t.iconControlRight) }, null, 2) ]), _: 1 }) ]) ]) ]), l("tbody", null, [ (s(!0), y(P, null, Y(p(r), (D, a) => (s(), y("tr", { key: a }, [ (s(!0), y(P, null, Y(D, (h, k) => (s(), y("td", { key: `${a}_${k}`, width: "20%" }, [ M($, { block: "", size: "sm", style: { border: "none" }, type: i(h), onClick: (v) => m(h) }, { default: C(() => [ l("span", null, B(h), 1) ]), _: 2 }, 1032, ["type", "onClick"]) ]))), 128)) ]))), 128)) ]) ])); } }, Fe = { key: 0 }, ze = /* @__PURE__ */ l("br", null, null, -1), Pe = { class: "text-center" }, xe = { __name: "DatePicker", props: { modelValue: { type: null, required: !0 }, width: { type: Number, default: 270 }, todayBtn: { type: Boolean, default: !0 }, clearBtn: { type: Boolean, default: !0 }, closeOnSelected: { type: Boolean, default: !0 }, limitFrom: { type: null, default: void 0 }, limitTo: { type: null, default: void 0 }, format: { type: String, default: "yyyy-MM-dd" }, initialView: { type: String, default: "d" }, dateParser: { type: Function, default: Date.parse }, dateClass: { type: Function, default: void 0 }, yearMonthFormatter: { type: Function, default: void 0 }, weekStartsWith: { type: Number, default: 0, validator(t) { return t >= 0 && t <= 6; } }, weekNumbers: Boolean, iconControlLeft: { type: String, default: "glyphicon glyphicon-chevron-left" }, iconControlRight: { type: String, default: "glyphicon glyphicon-chevron-right" } }, emits: ["update:modelValue"], setup(t, { emit: n }) { const e = t; O(!1); const i = O(/* @__PURE__ */ new Date()), f = O(0), u = O(0), m = O("d"), r = T(() => { const o = e.dateParser(e.modelValue); if (isNaN(o)) return null; { let c = new Date(o); return c.getHours() !== 0 && (c = new Date(o + c.getTimezoneOffset() * 60 * 1e3)), c; } }), V = T(() => ({ width: e.width + "px" })), d = T(() => ({ "uiv-datepicker": !0, "uiv-datepicker-date": m.value === "d", "uiv-datepicker-month": m.value === "m", "uiv-datepicker-year": m.value === "y" })), g = T(() => { const o = {}; if (e.limitFrom) { let c = e.dateParser(e.limitFrom); isNaN(c) || (c = Q(new Date(c)), c.setHours(0, 0, 0, 0), o.from = c); } if (e.limitTo) { let c = e.dateParser(e.limitTo); isNaN(c) || (c = Q(new Date(c)), c.setHours(0, 0, 0, 0), o.to = c); } return o; }); te( () => e.modelValue, (o, c) => { D(o, c); } ), X(() => { e.modelValue ? D(e.modelValue) : (f.value = i.value.getMonth(), u.value = i.value.getFullYear(), m.value = e.initialView); }); function D(o, c) { const z = e.dateParser(o); if (!isNaN(z)) { let S = new Date(z); S.getHours() !== 0 && (S = new Date(z + S.getTimezoneOffset() * 60 * 1e3)), g.value && (g.value.from && S < g.value.from || g.value.to && S >= g.value.to) ? n("update:modelValue", c || "") : (f.value = S.getMonth(), u.value = S.getFullYear()); } } function a(o) { f.value = o; } function h(o) { u.value = o, f.value = void 0; } function k(o) { if (o && J(o.date) && J(o.month) && J(o.year)) { const c = new Date(o.year, o.month, o.date); n( "update:modelValue", e.format ? me(c, e.format) : c ), f.value = o.month, u.value = o.year; } else n("update:modelValue", ""); } function v(o) { m.value = o; } function N() { m.value = "d", k({ date: i.value.getDate(), month: i.value.getMonth(), year: i.value.getFullYear() }); } function F() { f.value = i.value.getMonth(), u.value = i.value.getFullYear(), m.value = e.initialView, k(); } function L(o) { (o.target.getAttribute("data-action") !== "select" || !e.closeOnSelected) && o.stopPropagation(); } return (o, c) => (s(), y("div", { class: w(p(d)), style: ne(p(V)), "data-role": "date-picker", onClick: L }, [ A(M(De, { month: f.value, year: u.value, date: p(r), today: i.value, limit: p(g), "week-starts-with": t.weekStartsWith, "icon-control-left": t.iconControlLeft, "icon-control-right": t.iconControlRight, "date-class": t.dateClass, "year-month-formatter": t.yearMonthFormatter, "week-numbers": t.weekNumbers, onMonthChange: a, onYearChange: h, onDateChange: k, onViewChange: v }, null, 8, ["month", "year", "date", "today", "limit", "week-starts-with", "icon-control-left", "icon-control-right", "date-class", "year-month-formatter", "week-numbers"]), [ [H, m.value === "d"] ]), A(M(Ve, { month: f.value, year: u.value, "icon-control-left": t.iconControlLeft, "icon-control-right": t.iconControlRight, onMonthChange: a, onYearChange: h, onViewChange: v }, null, 8, ["month", "year", "icon-control-left", "icon-control-right"]), [ [H, m.value === "m"] ]), A(M(Be, { year: u.value, "icon-control-left": t.iconControlLeft, "icon-control-right": t.iconControlRight, onYearChange: h, onViewChange: v }, null, 8, ["year", "icon-control-left", "icon-control-right"]), [ [H, m.value === "y"] ]), t.todayBtn || t.clearBtn ? (s(), y("div", Fe, [ ze, l("div", Pe, [ t.todayBtn ? (s(), W($, { key: 0, "data-action": "select", "data-type": "today", type: "info", size: "sm", onClick: N }, { default: C(() => [ q(B(p(R)("uiv.datePicker.today")), 1) ]), _: 1 })) : U("", !0), t.clearBtn ? (s(), W($, { key: 1, "data-action": "select", "data-type": "clear", size: "sm", onClick: F }, { default: C(() => [ q(B(p(R)("uiv.datePicker.clear")), 1) ]), _: 1 })) : U("", !0) ]) ])) : U("", !0) ], 6)); } }; export { xe as default };