@itera-web/react-ui-datepicker 1.37.0 → 1.38.1
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/es/index.js +1 -1
- package/package.json +9 -9
package/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"date-fns";import*as t from"react";import*as n from"@itera-web/react-ui-button";import*as a from"@itera-web/react-ui-calendar";import*as r from"@itera-web/react-ui-popover";import*as o from"@itera-web/react-ui-select";import*as i from"@itera-web/utils-cn";import*as l from"@itera-web/utils-locale-toggle";import*as u from"@itera-web/hooks-setstate";var s={d:(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},c={};s.d(c,{M:()=>z,T:()=>R});const d=(e=>{var t={};return s.d(t,e),t})({format:()=>e.format,parse:()=>e.parse}),m={lessThanXSeconds:{one:"不到 1 秒",other:"不到 {{count}} 秒"},xSeconds:{one:"1 秒",other:"{{count}} 秒"},halfAMinute:"半分钟",lessThanXMinutes:{one:"不到 1 分钟",other:"不到 {{count}} 分钟"},xMinutes:{one:"1 分钟",other:"{{count}} 分钟"},xHours:{one:"1 小时",other:"{{count}} 小时"},aboutXHours:{one:"大约 1 小时",other:"大约 {{count}} 小时"},xDays:{one:"1 天",other:"{{count}} 天"},aboutXWeeks:{one:"大约 1 个星期",other:"大约 {{count}} 个星期"},xWeeks:{one:"1 个星期",other:"{{count}} 个星期"},aboutXMonths:{one:"大约 1 个月",other:"大约 {{count}} 个月"},xMonths:{one:"1 个月",other:"{{count}} 个月"},aboutXYears:{one:"大约 1 年",other:"大约 {{count}} 年"},xYears:{one:"1 年",other:"{{count}} 年"},overXYears:{one:"超过 1 年",other:"超过 {{count}} 年"},almostXYears:{one:"将近 1 年",other:"将近 {{count}} 年"}};function f(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const p={date:f({formats:{full:"y'年'M'月'd'日' EEEE",long:"y'年'M'月'd'日'",medium:"yyyy-MM-dd",short:"yy-MM-dd"},defaultWidth:"full"}),time:f({formats:{full:"zzzz a h:mm:ss",long:"z a h:mm:ss",medium:"a h:mm:ss",short:"a h:mm"},defaultWidth:"full"}),dateTime:f({formats:{full:"{{date}} {{time}}",long:"{{date}} {{time}}",medium:"{{date}} {{time}}",short:"{{date}} {{time}}"},defaultWidth:"full"})};function h(e){const t=Object.prototype.toString.call(e);return e instanceof Date||"object"==typeof e&&"[object Date]"===t?new e.constructor(+e):"number"==typeof e||"[object Number]"===t||"string"==typeof e||"[object String]"===t?new Date(e):new Date(NaN)}let g={};function v(){return g}function y(e,t){const n=v(),a=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,r=h(e),o=r.getDay(),i=(o<a?7:0)+o-a;return r.setDate(r.getDate()-i),r.setHours(0,0,0,0),r}function b(e,t,n){return+y(e,n)===+y(t,n)}function w(e,t,n){const a="eeee p";return b(e,t,n)?a:e.getTime()>t.getTime()?"'下个'"+a:"'上个'"+a}const x={lastWeek:w,yesterday:"'昨天' p",today:"'今天' p",tomorrow:"'明天' p",nextWeek:w,other:"PP p"};function P(e){return(t,n)=>{let a;if("formatting"===(n?.context?String(n.context):"standalone")&&e.formattingValues){const t=e.defaultFormattingWidth||e.defaultWidth,r=n?.width?String(n.width):t;a=e.formattingValues[r]||e.formattingValues[t]}else{const t=e.defaultWidth,r=n?.width?String(n.width):e.defaultWidth;a=e.values[r]||e.values[t]}return a[e.argumentCallback?e.argumentCallback(t):t]}}function S(e){return(t,n={})=>{const a=n.width,r=a&&e.matchPatterns[a]||e.matchPatterns[e.defaultMatchWidth],o=t.match(r);if(!o)return null;const i=o[0],l=a&&e.parsePatterns[a]||e.parsePatterns[e.defaultParseWidth],u=Array.isArray(l)?function(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n;return}(l,e=>e.test(i)):function(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n;return}(l,e=>e.test(i));let s;s=e.valueCallback?e.valueCallback(u):u,s=n.valueCallback?n.valueCallback(s):s;return{value:s,rest:t.slice(i.length)}}}var C;const E={code:"zh-CN",formatDistance:(e,t,n)=>{let a;const r=m[e];return a="string"==typeof r?r:1===t?r.one:r.other.replace("{{count}}",String(t)),n?.addSuffix?n.comparison&&n.comparison>0?a+"内":a+"前":a},formatLong:p,formatRelative:(e,t,n,a)=>{const r=x[e];return"function"==typeof r?r(t,n,a):r},localize:{ordinalNumber:(e,t)=>{const n=Number(e);switch(t?.unit){case"date":return n.toString()+"日";case"hour":return n.toString()+"时";case"minute":return n.toString()+"分";case"second":return n.toString()+"秒";default:return"第 "+n.toString()}},era:P({values:{narrow:["前","公元"],abbreviated:["前","公元"],wide:["公元前","公元"]},defaultWidth:"wide"}),quarter:P({values:{narrow:["1","2","3","4"],abbreviated:["第一季","第二季","第三季","第四季"],wide:["第一季度","第二季度","第三季度","第四季度"]},defaultWidth:"wide",argumentCallback:e=>e-1}),month:P({values:{narrow:["一","二","三","四","五","六","七","八","九","十","十一","十二"],abbreviated:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],wide:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]},defaultWidth:"wide"}),day:P({values:{narrow:["日","一","二","三","四","五","六"],short:["日","一","二","三","四","五","六"],abbreviated:["周日","周一","周二","周三","周四","周五","周六"],wide:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]},defaultWidth:"wide"}),dayPeriod:P({values:{narrow:{am:"上",pm:"下",midnight:"凌晨",noon:"午",morning:"早",afternoon:"下午",evening:"晚",night:"夜"},abbreviated:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"},wide:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"}},defaultWidth:"wide",formattingValues:{narrow:{am:"上",pm:"下",midnight:"凌晨",noon:"午",morning:"早",afternoon:"下午",evening:"晚",night:"夜"},abbreviated:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"},wide:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(C={matchPattern:/^(第\s*)?\d+(日|时|分|秒)?/i,parsePattern:/\d+/i,valueCallback:e=>parseInt(e,10)},(e,t={})=>{const n=e.match(C.matchPattern);if(!n)return null;const a=n[0],r=e.match(C.parsePattern);if(!r)return null;let o=C.valueCallback?C.valueCallback(r[0]):r[0];return o=t.valueCallback?t.valueCallback(o):o,{value:o,rest:e.slice(a.length)}}),era:S({matchPatterns:{narrow:/^(前)/i,abbreviated:/^(前)/i,wide:/^(公元前|公元)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^(前)/i,/^(公元)/i]},defaultParseWidth:"any"}),quarter:S({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^第[一二三四]刻/i,wide:/^第[一二三四]刻钟/i},defaultMatchWidth:"wide",parsePatterns:{any:[/(1|一)/i,/(2|二)/i,/(3|三)/i,/(4|四)/i]},defaultParseWidth:"any",valueCallback:e=>e+1}),month:S({matchPatterns:{narrow:/^(一|二|三|四|五|六|七|八|九|十[二一])/i,abbreviated:/^(一|二|三|四|五|六|七|八|九|十[二一]|\d|1[12])月/i,wide:/^(一|二|三|四|五|六|七|八|九|十[二一])月/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^一/i,/^二/i,/^三/i,/^四/i,/^五/i,/^六/i,/^七/i,/^八/i,/^九/i,/^十(?!(一|二))/i,/^十一/i,/^十二/i],any:[/^一|1/i,/^二|2/i,/^三|3/i,/^四|4/i,/^五|5/i,/^六|6/i,/^七|7/i,/^八|8/i,/^九|9/i,/^十(?!(一|二))|10/i,/^十一|11/i,/^十二|12/i]},defaultParseWidth:"any"}),day:S({matchPatterns:{narrow:/^[一二三四五六日]/i,short:/^[一二三四五六日]/i,abbreviated:/^周[一二三四五六日]/i,wide:/^星期[一二三四五六日]/i},defaultMatchWidth:"wide",parsePatterns:{any:[/日/i,/一/i,/二/i,/三/i,/四/i,/五/i,/六/i]},defaultParseWidth:"any"}),dayPeriod:S({matchPatterns:{any:/^(上午?|下午?|午夜|[中正]午|早上?|下午|晚上?|凌晨|)/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^上午?/i,pm:/^下午?/i,midnight:/^午夜/i,noon:/^[中正]午/i,morning:/^早上/i,afternoon:/^下午/i,evening:/^晚上?/i,night:/^凌晨/i}},defaultParseWidth:"any"})},options:{weekStartsOn:1,firstWeekContainsDate:4}};const N=(e=>{var t={};return s.d(t,e),t})({createElement:()=>t.createElement,default:()=>t.default,forwardRef:()=>t.forwardRef,useEffect:()=>t.useEffect,useImperativeHandle:()=>t.useImperativeHandle,useState:()=>t.useState});const D=(e=>{var t={};return s.d(t,e),t})({Button:()=>n.Button});const k=(e=>{var t={};return s.d(t,e),t})({Calendar:()=>a.Calendar});const O=(e=>{var t={};return s.d(t,e),t})({Popover:()=>r.Popover,PopoverContent:()=>r.PopoverContent,PopoverTrigger:()=>r.PopoverTrigger});const M=(e=>{var t={};return s.d(t,e),t})({Select:()=>o.Select});const W=(e=>{var t={};return s.d(t,e),t})({cn:()=>i.cn});const j=(e=>{var t={};return s.d(t,e),t})({Intl:()=>l.Intl});var H=function(e){var t=e.className;return N.createElement("svg",{className:t,fill:"none",height:"24",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg"},N.createElement("path",{d:"M8 2v4"}),N.createElement("path",{d:"M16 2v4"}),N.createElement("rect",{height:"18",rx:"2",width:"18",x:"3",y:"4"}),N.createElement("path",{d:"M3 10h18"}))},T=function(){return T=Object.assign||function(e){for(var t,n=1,a=arguments.length;n<a;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},T.apply(this,arguments)},I=function(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(a=Object.getOwnPropertySymbols(e);r<a.length;r++)t.indexOf(a[r])<0&&Object.prototype.propertyIsEnumerable.call(e,a[r])&&(n[a[r]]=e[a[r]])}return n},z=N.forwardRef(function(e,t){var n,a=e.value,r=e.onChange,o=e.id,i=e.showTime,l=void 0!==i&&i,u=e.showClear,s=void 0!==u&&u,c=e.format,m=void 0===c?"":c,f=e.className,p=void 0===f?"":f,h=e.placeholder,g=e.noIcon,v=e.noBorder,y=e.inputTextCenter,b=e.inputClassName,w=void 0===b?"":b,x=I(e,["value","onChange","id","showTime","showClear","format","className","placeholder","noIcon","noBorder","inputTextCenter","inputClassName"]),P=(0,N.useState)(!1),S=P[0],C=P[1];var z=function(e){return(t=e)instanceof Date&&!isNaN(t.getTime())?(0,d.format)(e,l?m||"yyyy-MM-dd HH:mm:ss":m||"yyyy-MM-dd",{locale:E}):null;var t},q=function(e){return e?"string"==typeof e?(0,d.parse)(e,l?m||"yyyy-MM-dd HH:mm:ss":m||"yyyy-MM-dd",new Date):e:null},B=(0,N.useState)(null!==(n=q(a))&&void 0!==n?n:null),X=B[0],R=B[1],A=X,V=(0,N.useState)(A?null==A?void 0:A.getHours():0),L=V[0],Y=V[1],F=(0,N.useState)(A?null==A?void 0:A.getMinutes():0),G=F[0],J=F[1],K=(0,N.useState)(A?null==A?void 0:A.getSeconds():0),Q=K[0],U=K[1],Z=Array.from({length:24}).map(function(e,t){return{label:String(t).padStart(2,"0"),value:t}}),$=Array.from({length:60}).map(function(e,t){return{label:String(t).padStart(2,"0"),value:t}}),_=Array.from({length:60}).map(function(e,t){return{label:String(t).padStart(2,"0"),value:t}}),ee=function(e,t,n,a){void 0===t&&(t=L),void 0===n&&(n=G),void 0===a&&(a=Q);var o=new Date(e);l?o.setHours(t,n,a,0):o.setHours(0,0,0,0),R(o),null==r||r(z(o))},te=function(){R(null),Y(0),J(0),U(0),null==r||r(null)};return(0,N.useEffect)(function(){if(a){var e=a;"string"==typeof a&&(e=q(a)),R(e),Y(e.getHours()),J(e.getMinutes()),U(e.getSeconds())}else te()},[a]),N.createElement("div",{className:(0,W.cn)("relative w-full",p)},N.createElement(O.Popover,{onOpenChange:C,open:S},N.createElement(O.PopoverTrigger,{asChild:!0},N.createElement("div",{className:(0,W.cn)("relative w-full group cursor-pointer")},N.createElement("div",{className:(0,W.cn)("flex items-center")},N.createElement("div",{className:(0,W.cn)("flex items-center h-10 w-full bg-background disabled:cursor-not-allowed disabled:opacity-50 rounded-md",v?"border-0 focus-within:ring-0 focus-within:outline-none":"border focus-within:ring-1 focus-within:ring-ring focus-within:ring-offset-0 ring-offset-background",p)},!g&&N.createElement("span",{className:"ml-2 text-font"},N.createElement(H,{className:"mr-1 h-4"})),v&&S&&N.createElement("span",{className:"absolute bottom-0 left-0 h-[2px] w-full bg-primary focus-within:bg-ring transition-all duration-200"}),N.createElement("input",{className:(0,W.cn)("flex-1 bg-transparent text-font border-none outline-none px-3 py-2 text-base placeholder:text-font/80 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm placeholder:overflow-hidden placeholder:text-ellipsis placeholder:whitespace-nowrap",!A&&"text-font",y&&"text-center",w),id:o,onClick:function(e){e.preventDefault(),e.stopPropagation(),C(!0)},placeholder:j.Intl.v(h||"选择日期".concat(l?"时间":"")),readOnly:!0,ref:t,type:"text",value:A?z(A):""}))),s&&null!=a&&N.createElement("button",{className:"ml-2 absolute right-3 top-1/2 -translate-y-1/2 flex h-4 w-4 items-center justify-center rounded-full bg-gray-200 text-gray-700 hover:bg-gray-300 opacity-0 group-hover:opacity-100 transition-opacity duration-200",onClick:function(e){e.preventDefault(),e.stopPropagation(),null==te||te()},type:"button"},"×"))),N.createElement(O.PopoverContent,{className:"w-auto p-2 text-font z-[100]"},N.createElement("div",{className:"flex flex-col gap-2"},N.createElement(k.Calendar,T({initialFocus:!0},x,{locale:E,mode:"single",onSelect:function(e){e&&ee(e,L,G,Q)},selected:A})),l&&N.createElement("div",{className:"flex gap-2 justify-center"},N.createElement("div",{className:"w-[80px]"},N.createElement(M.Select,{className:"h-7",onChange:function(e){e&&(Y(e.value),ee(A,e.value,G,Q))},options:Z,placeholder:"HH",value:Z.find(function(e){return e.value===L})||null})),N.createElement("div",{className:"w-[80px]"},N.createElement(M.Select,{className:"h-7",onChange:function(e){e&&(J(e.value),ee(A,L,e.value,Q))},options:$,placeholder:"mm",value:$.find(function(e){return e.value===G})||null})),N.createElement("div",{className:"w-[80px]"},N.createElement(M.Select,{className:"h-7",onChange:function(e){e&&(U(e.value),ee(A,L,G,e.value))},options:_,placeholder:"ss",value:_.find(function(e){return e.value===Q})||null}))),N.createElement("div",{className:"flex justify-center mt-2 items-center gap-2"},N.createElement(D.Button,{color:"primary",onClick:function(){var e=new Date;R(e),Y(e.getHours()),J(e.getMinutes()),U(e.getSeconds()),null==r||r(z(e)),C(!1)},size:"sm",type:"button",variant:"text"},"此刻"),N.createElement(D.Button,{color:"primary",onClick:function(){return C(!1)},size:"sm",type:"button",variant:"outline"},"确定"))))))});const q=(e=>{var t={};return s.d(t,e),t})({useSetState:()=>u.useSetState});var B=function(){return B=Object.assign||function(e){for(var t,n=1,a=arguments.length;n<a;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},B.apply(this,arguments)},X=function(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(a=Object.getOwnPropertySymbols(e);r<a.length;r++)t.indexOf(a[r])<0&&Object.prototype.propertyIsEnumerable.call(e,a[r])&&(n[a[r]]=e[a[r]])}return n},R=(0,N.forwardRef)(function(e,t){var n=e.value,a=e.onChange,r=void 0===a?function(){}:a,o=(e.placeholder,e.className),i=e.concat,l=e.concatDom,u=e.showClear,s=X(e,["value","onChange","placeholder","className","concat","concatDom","showClear"]),c=(0,q.useSetState)(n||{startDate:null,endDate:null}),d=c[0],m=c[1],f=c[2],p=(0,N.useState)(!1),h=p[0],g=p[1];return(0,N.useImperativeHandle)(t,function(){return{getValue:function(){return f()},setValue:function(e){return m(e)},reset:function(){return m({startDate:null,endDate:null})}}}),N.default.createElement("div",{className:(0,W.cn)("relative flex gap-1 items-center",o,i&&"border border-border rounded-[8px] overflow-hidden bg-background"),onMouseEnter:function(){return g(!0)},onMouseLeave:function(){return g(!1)}},N.default.createElement(z,B({className:(0,W.cn)(i&&"border-0"),inputClassName:"p-0",inputTextCenter:!0,noBorder:i,onChange:function(e){var t={startDate:e,endDate:null};m(t),r(t)},placeholder:"开始日期",value:d.startDate?new Date(d.startDate):null},s,{showClear:!1})),i&&l?l:N.default.createElement("span",{className:"text-font"},"-"),N.default.createElement(z,B({className:(0,W.cn)(i&&"border-0"),fromDate:d.startDate?new Date(d.startDate):null,inputClassName:"pl-0",inputTextCenter:!0,noBorder:i,noIcon:i,onChange:function(e){var t=B(B({},f()),{endDate:e});m(t),r(t)},placeholder:"结束日期",value:d.endDate?new Date(d.endDate):null},s,{showClear:!1})),u&&(d.startDate||d.endDate)&&N.default.createElement("button",{className:(0,W.cn)("ml-2 absolute right-3 top-1/2 -translate-y-1/2 flex h-4 w-4 items-center justify-center rounded-full bg-gray-200 text-gray-700 hover:bg-gray-300 opacity-0 group-hover:opacity-100 transition-opacity duration-200",h&&"opacity-100"),onClick:function(e){e.preventDefault(),e.stopPropagation(),m({startDate:null,endDate:null})},type:"button"},"×"))});R.displayName="DateRangPicker";var A=c.M,V=c.T;export{A as DatePicker,V as DateRangPicker};
|
|
1
|
+
import*as e from"date-fns";import*as t from"react";import*as n from"@itera-web/react-ui-button";import*as a from"@itera-web/react-ui-calendar";import*as r from"@itera-web/react-ui-popover";import*as o from"@itera-web/react-ui-select";import*as i from"@itera-web/utils-cn";import*as l from"@itera-web/utils-locale-toggle";import*as u from"@itera-web/hooks-setstate";var s={d:(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},c={};s.d(c,{M:()=>z,T:()=>A});const d=(e=>{var t={};return s.d(t,e),t})({format:()=>e.format,parse:()=>e.parse}),m={lessThanXSeconds:{one:"不到 1 秒",other:"不到 {{count}} 秒"},xSeconds:{one:"1 秒",other:"{{count}} 秒"},halfAMinute:"半分钟",lessThanXMinutes:{one:"不到 1 分钟",other:"不到 {{count}} 分钟"},xMinutes:{one:"1 分钟",other:"{{count}} 分钟"},xHours:{one:"1 小时",other:"{{count}} 小时"},aboutXHours:{one:"大约 1 小时",other:"大约 {{count}} 小时"},xDays:{one:"1 天",other:"{{count}} 天"},aboutXWeeks:{one:"大约 1 个星期",other:"大约 {{count}} 个星期"},xWeeks:{one:"1 个星期",other:"{{count}} 个星期"},aboutXMonths:{one:"大约 1 个月",other:"大约 {{count}} 个月"},xMonths:{one:"1 个月",other:"{{count}} 个月"},aboutXYears:{one:"大约 1 年",other:"大约 {{count}} 年"},xYears:{one:"1 年",other:"{{count}} 年"},overXYears:{one:"超过 1 年",other:"超过 {{count}} 年"},almostXYears:{one:"将近 1 年",other:"将近 {{count}} 年"}};function f(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const p={date:f({formats:{full:"y'年'M'月'd'日' EEEE",long:"y'年'M'月'd'日'",medium:"yyyy-MM-dd",short:"yy-MM-dd"},defaultWidth:"full"}),time:f({formats:{full:"zzzz a h:mm:ss",long:"z a h:mm:ss",medium:"a h:mm:ss",short:"a h:mm"},defaultWidth:"full"}),dateTime:f({formats:{full:"{{date}} {{time}}",long:"{{date}} {{time}}",medium:"{{date}} {{time}}",short:"{{date}} {{time}}"},defaultWidth:"full"})};function h(e){const t=Object.prototype.toString.call(e);return e instanceof Date||"object"==typeof e&&"[object Date]"===t?new e.constructor(+e):"number"==typeof e||"[object Number]"===t||"string"==typeof e||"[object String]"===t?new Date(e):new Date(NaN)}let g={};function v(){return g}function y(e,t){const n=v(),a=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,r=h(e),o=r.getDay(),i=(o<a?7:0)+o-a;return r.setDate(r.getDate()-i),r.setHours(0,0,0,0),r}function b(e,t,n){return+y(e,n)===+y(t,n)}function w(e,t,n){const a="eeee p";return b(e,t,n)?a:e.getTime()>t.getTime()?"'下个'"+a:"'上个'"+a}const x={lastWeek:w,yesterday:"'昨天' p",today:"'今天' p",tomorrow:"'明天' p",nextWeek:w,other:"PP p"};function P(e){return(t,n)=>{let a;if("formatting"===(n?.context?String(n.context):"standalone")&&e.formattingValues){const t=e.defaultFormattingWidth||e.defaultWidth,r=n?.width?String(n.width):t;a=e.formattingValues[r]||e.formattingValues[t]}else{const t=e.defaultWidth,r=n?.width?String(n.width):e.defaultWidth;a=e.values[r]||e.values[t]}return a[e.argumentCallback?e.argumentCallback(t):t]}}function S(e){return(t,n={})=>{const a=n.width,r=a&&e.matchPatterns[a]||e.matchPatterns[e.defaultMatchWidth],o=t.match(r);if(!o)return null;const i=o[0],l=a&&e.parsePatterns[a]||e.parsePatterns[e.defaultParseWidth],u=Array.isArray(l)?function(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n;return}(l,e=>e.test(i)):function(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n;return}(l,e=>e.test(i));let s;s=e.valueCallback?e.valueCallback(u):u,s=n.valueCallback?n.valueCallback(s):s;return{value:s,rest:t.slice(i.length)}}}var C;const E={code:"zh-CN",formatDistance:(e,t,n)=>{let a;const r=m[e];return a="string"==typeof r?r:1===t?r.one:r.other.replace("{{count}}",String(t)),n?.addSuffix?n.comparison&&n.comparison>0?a+"内":a+"前":a},formatLong:p,formatRelative:(e,t,n,a)=>{const r=x[e];return"function"==typeof r?r(t,n,a):r},localize:{ordinalNumber:(e,t)=>{const n=Number(e);switch(t?.unit){case"date":return n.toString()+"日";case"hour":return n.toString()+"时";case"minute":return n.toString()+"分";case"second":return n.toString()+"秒";default:return"第 "+n.toString()}},era:P({values:{narrow:["前","公元"],abbreviated:["前","公元"],wide:["公元前","公元"]},defaultWidth:"wide"}),quarter:P({values:{narrow:["1","2","3","4"],abbreviated:["第一季","第二季","第三季","第四季"],wide:["第一季度","第二季度","第三季度","第四季度"]},defaultWidth:"wide",argumentCallback:e=>e-1}),month:P({values:{narrow:["一","二","三","四","五","六","七","八","九","十","十一","十二"],abbreviated:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],wide:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]},defaultWidth:"wide"}),day:P({values:{narrow:["日","一","二","三","四","五","六"],short:["日","一","二","三","四","五","六"],abbreviated:["周日","周一","周二","周三","周四","周五","周六"],wide:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]},defaultWidth:"wide"}),dayPeriod:P({values:{narrow:{am:"上",pm:"下",midnight:"凌晨",noon:"午",morning:"早",afternoon:"下午",evening:"晚",night:"夜"},abbreviated:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"},wide:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"}},defaultWidth:"wide",formattingValues:{narrow:{am:"上",pm:"下",midnight:"凌晨",noon:"午",morning:"早",afternoon:"下午",evening:"晚",night:"夜"},abbreviated:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"},wide:{am:"上午",pm:"下午",midnight:"凌晨",noon:"中午",morning:"早晨",afternoon:"中午",evening:"晚上",night:"夜间"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(C={matchPattern:/^(第\s*)?\d+(日|时|分|秒)?/i,parsePattern:/\d+/i,valueCallback:e=>parseInt(e,10)},(e,t={})=>{const n=e.match(C.matchPattern);if(!n)return null;const a=n[0],r=e.match(C.parsePattern);if(!r)return null;let o=C.valueCallback?C.valueCallback(r[0]):r[0];return o=t.valueCallback?t.valueCallback(o):o,{value:o,rest:e.slice(a.length)}}),era:S({matchPatterns:{narrow:/^(前)/i,abbreviated:/^(前)/i,wide:/^(公元前|公元)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^(前)/i,/^(公元)/i]},defaultParseWidth:"any"}),quarter:S({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^第[一二三四]刻/i,wide:/^第[一二三四]刻钟/i},defaultMatchWidth:"wide",parsePatterns:{any:[/(1|一)/i,/(2|二)/i,/(3|三)/i,/(4|四)/i]},defaultParseWidth:"any",valueCallback:e=>e+1}),month:S({matchPatterns:{narrow:/^(一|二|三|四|五|六|七|八|九|十[二一])/i,abbreviated:/^(一|二|三|四|五|六|七|八|九|十[二一]|\d|1[12])月/i,wide:/^(一|二|三|四|五|六|七|八|九|十[二一])月/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^一/i,/^二/i,/^三/i,/^四/i,/^五/i,/^六/i,/^七/i,/^八/i,/^九/i,/^十(?!(一|二))/i,/^十一/i,/^十二/i],any:[/^一|1/i,/^二|2/i,/^三|3/i,/^四|4/i,/^五|5/i,/^六|6/i,/^七|7/i,/^八|8/i,/^九|9/i,/^十(?!(一|二))|10/i,/^十一|11/i,/^十二|12/i]},defaultParseWidth:"any"}),day:S({matchPatterns:{narrow:/^[一二三四五六日]/i,short:/^[一二三四五六日]/i,abbreviated:/^周[一二三四五六日]/i,wide:/^星期[一二三四五六日]/i},defaultMatchWidth:"wide",parsePatterns:{any:[/日/i,/一/i,/二/i,/三/i,/四/i,/五/i,/六/i]},defaultParseWidth:"any"}),dayPeriod:S({matchPatterns:{any:/^(上午?|下午?|午夜|[中正]午|早上?|下午|晚上?|凌晨|)/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^上午?/i,pm:/^下午?/i,midnight:/^午夜/i,noon:/^[中正]午/i,morning:/^早上/i,afternoon:/^下午/i,evening:/^晚上?/i,night:/^凌晨/i}},defaultParseWidth:"any"})},options:{weekStartsOn:1,firstWeekContainsDate:4}};const N=(e=>{var t={};return s.d(t,e),t})({createElement:()=>t.createElement,default:()=>t.default,forwardRef:()=>t.forwardRef,useEffect:()=>t.useEffect,useImperativeHandle:()=>t.useImperativeHandle,useState:()=>t.useState});const D=(e=>{var t={};return s.d(t,e),t})({Button:()=>n.Button});const k=(e=>{var t={};return s.d(t,e),t})({Calendar:()=>a.Calendar});const O=(e=>{var t={};return s.d(t,e),t})({Popover:()=>r.Popover,PopoverContent:()=>r.PopoverContent,PopoverTrigger:()=>r.PopoverTrigger});const M=(e=>{var t={};return s.d(t,e),t})({Select:()=>o.Select});const W=(e=>{var t={};return s.d(t,e),t})({cn:()=>i.cn});const j=(e=>{var t={};return s.d(t,e),t})({Intl:()=>l.Intl});var H=function(e){var t=e.className;return N.createElement("svg",{className:t,fill:"none",height:"24",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg"},N.createElement("path",{d:"M8 2v4"}),N.createElement("path",{d:"M16 2v4"}),N.createElement("rect",{height:"18",rx:"2",width:"18",x:"3",y:"4"}),N.createElement("path",{d:"M3 10h18"}))},T=function(){return T=Object.assign||function(e){for(var t,n=1,a=arguments.length;n<a;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},T.apply(this,arguments)},I=function(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(a=Object.getOwnPropertySymbols(e);r<a.length;r++)t.indexOf(a[r])<0&&Object.prototype.propertyIsEnumerable.call(e,a[r])&&(n[a[r]]=e[a[r]])}return n},z=N.forwardRef(function(e,t){var n,a=e.value,r=e.onChange,o=e.id,i=e.showTime,l=void 0!==i&&i,u=e.showClear,s=void 0!==u&&u,c=e.format,m=void 0===c?"":c,f=e.className,p=void 0===f?"":f,h=e.placeholder,g=e.noIcon,v=e.noBorder,y=e.inputTextCenter,b=e.inputClassName,w=void 0===b?"":b,x=I(e,["value","onChange","id","showTime","showClear","format","className","placeholder","noIcon","noBorder","inputTextCenter","inputClassName"]),P=(0,N.useState)(!1),S=P[0],C=P[1];var z=function(e){return(t=e)instanceof Date&&!isNaN(t.getTime())?(0,d.format)(e,l?m||"yyyy-MM-dd HH:mm:ss":m||"yyyy-MM-dd",{locale:E}):null;var t},B=function(e){return e?"string"==typeof e?(0,d.parse)(e,l?m||"yyyy-MM-dd HH:mm:ss":m||"yyyy-MM-dd",new Date):e:null},X=(0,N.useState)(null!==(n=B(a))&&void 0!==n?n:null),R=X[0],A=X[1],V=R,L=(0,N.useState)(V?null==V?void 0:V.getHours():0),Y=L[0],F=L[1],q=(0,N.useState)(V?null==V?void 0:V.getMinutes():0),G=q[0],J=q[1],K=(0,N.useState)(V?null==V?void 0:V.getSeconds():0),Q=K[0],U=K[1],Z=Array.from({length:24}).map(function(e,t){return{label:String(t).padStart(2,"0"),value:t}}),$=Array.from({length:60}).map(function(e,t){return{label:String(t).padStart(2,"0"),value:t}}),_=Array.from({length:60}).map(function(e,t){return{label:String(t).padStart(2,"0"),value:t}}),ee=function(e,t,n,a){void 0===t&&(t=Y),void 0===n&&(n=G),void 0===a&&(a=Q);var o=new Date(e);l?o.setHours(t,n,a,0):o.setHours(0,0,0,0),A(o),null==r||r(z(o))},te=function(){A(null),F(0),J(0),U(0),null==r||r(null)};return(0,N.useEffect)(function(){if(a){var e=a;"string"==typeof a&&(e=B(a)),A(e),F(e.getHours()),J(e.getMinutes()),U(e.getSeconds())}else te()},[a]),N.createElement("div",{className:(0,W.cn)("relative w-full",p)},N.createElement(O.Popover,{onOpenChange:C,open:S},N.createElement(O.PopoverTrigger,{asChild:!0},N.createElement("div",{className:(0,W.cn)("relative w-full group cursor-pointer")},N.createElement("div",{className:(0,W.cn)("flex items-center")},N.createElement("div",{className:(0,W.cn)("flex items-center h-10 w-full bg-background disabled:cursor-not-allowed disabled:opacity-50 rounded-md",v?"border-0 focus-within:ring-0 focus-within:outline-none":"border focus-within:ring-1 focus-within:ring-ring focus-within:ring-offset-0 ring-offset-background",p)},!g&&N.createElement("span",{className:"ml-2 text-font"},N.createElement(H,{className:"mr-1 h-4"})),v&&S&&N.createElement("span",{className:"absolute bottom-0 left-0 h-[2px] w-full bg-primary focus-within:bg-ring transition-all duration-200"}),N.createElement("input",{className:(0,W.cn)("flex-1 bg-transparent text-font border-none outline-none px-3 py-2 text-base placeholder:text-font/80 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm placeholder:overflow-hidden placeholder:text-ellipsis placeholder:whitespace-nowrap",!V&&"text-font",y&&"text-center",w),id:o,onClick:function(e){e.preventDefault(),e.stopPropagation(),C(!0)},placeholder:j.Intl.v(h||"选择日期".concat(l?"时间":"")),readOnly:!0,ref:t,type:"text",value:V?z(V):""}))),s&&null!=a&&N.createElement("button",{className:"ml-2 absolute right-3 top-1/2 -translate-y-1/2 flex h-4 w-4 items-center justify-center rounded-full bg-gray-200 text-gray-700 hover:bg-gray-300 opacity-0 group-hover:opacity-100 transition-opacity duration-200",onClick:function(e){e.preventDefault(),e.stopPropagation(),null==te||te()},type:"button"},"×"))),N.createElement(O.PopoverContent,{className:"w-auto p-2 text-font z-[100]"},N.createElement("div",{className:"flex flex-col gap-2"},N.createElement(k.Calendar,T({initialFocus:!0},x,{locale:E,mode:"single",onSelect:function(e){e&&ee(e,Y,G,Q)},selected:V})),l&&N.createElement("div",{className:"flex gap-2 justify-center"},N.createElement("div",{className:"w-[80px]"},N.createElement(M.Select,{className:"h-7",onChange:function(e){e&&(F(e.value),ee(V,e.value,G,Q))},options:Z,placeholder:"HH",value:Z.find(function(e){return e.value===Y})||null})),N.createElement("div",{className:"w-[80px]"},N.createElement(M.Select,{className:"h-7",onChange:function(e){e&&(J(e.value),ee(V,Y,e.value,Q))},options:$,placeholder:"mm",value:$.find(function(e){return e.value===G})||null})),N.createElement("div",{className:"w-[80px]"},N.createElement(M.Select,{className:"h-7",onChange:function(e){e&&(U(e.value),ee(V,Y,G,e.value))},options:_,placeholder:"ss",value:_.find(function(e){return e.value===Q})||null}))),N.createElement("div",{className:"flex justify-center mt-2 items-center gap-2"},N.createElement(D.Button,{color:"primary",onClick:function(){var e=new Date;A(e),F(e.getHours()),J(e.getMinutes()),U(e.getSeconds()),null==r||r(z(e)),C(!1)},size:"sm",type:"button",variant:"text"},"此刻"),N.createElement(D.Button,{color:"primary",onClick:function(){return C(!1)},size:"sm",type:"button",variant:"outline"},"确定"))))))});const B=(e=>{var t={};return s.d(t,e),t})({useSetState:()=>u.useSetState});var X=function(){return X=Object.assign||function(e){for(var t,n=1,a=arguments.length;n<a;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},X.apply(this,arguments)},R=function(e,t){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(n[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(a=Object.getOwnPropertySymbols(e);r<a.length;r++)t.indexOf(a[r])<0&&Object.prototype.propertyIsEnumerable.call(e,a[r])&&(n[a[r]]=e[a[r]])}return n},A=(0,N.forwardRef)(function(e,t){var n=e.value,a=e.onChange,r=void 0===a?function(){}:a,o=(e.placeholder,e.className),i=e.concat,l=e.concatDom,u=e.showClear,s=R(e,["value","onChange","placeholder","className","concat","concatDom","showClear"]),c=(0,B.useSetState)(n||{startDate:null,endDate:null}),d=c[0],m=c[1],f=c[2],p=(0,N.useState)(!1),h=p[0],g=p[1];return(0,N.useImperativeHandle)(t,function(){return{getValue:function(){return f()},setValue:function(e){return m(e)},reset:function(){return m({startDate:null,endDate:null})}}}),N.default.createElement("div",{className:(0,W.cn)("relative flex gap-1 items-center",o,i&&"border border-border rounded-[8px] overflow-hidden bg-background"),onMouseEnter:function(){return g(!0)},onMouseLeave:function(){return g(!1)}},N.default.createElement(z,X({className:(0,W.cn)(i&&"border-0"),inputClassName:"p-0",inputTextCenter:!0,noBorder:i,onChange:function(e){var t={startDate:e,endDate:null};m(t),r(t)},placeholder:"开始日期",value:d.startDate?new Date(d.startDate):null},s,{showClear:!1})),i&&l?l:N.default.createElement("span",{className:"text-font"},"-"),N.default.createElement(z,X({className:(0,W.cn)(i&&"border-0"),fromDate:d.startDate?new Date(d.startDate):null,inputClassName:"pl-0",inputTextCenter:!0,noBorder:i,noIcon:i,onChange:function(e){var t=X(X({},f()),{endDate:e});m(t),r(t)},placeholder:"结束日期",value:d.endDate?new Date(d.endDate):null},s,{showClear:!1})),u&&(d.startDate||d.endDate)&&N.default.createElement("button",{className:(0,W.cn)("ml-2 absolute right-3 top-1/2 -translate-y-1/2 flex h-4 w-4 items-center justify-center rounded-full bg-gray-200 text-gray-700 hover:bg-gray-300 opacity-0 group-hover:opacity-100 transition-opacity duration-200",h&&"opacity-100"),onClick:function(e){e.preventDefault(),e.stopPropagation(),m({startDate:null,endDate:null})},type:"button"},"×"))});A.displayName="DateRangPicker";var V=c.M,L=c.T;export{V as DatePicker,L as DateRangPicker};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itera-web/react-ui-datepicker",
|
|
3
3
|
"description": "日历",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.38.1",
|
|
5
5
|
"main": "es/index.js",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"up": "npm publish"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@itera-web/hooks-setstate": "^1.
|
|
17
|
-
"@itera-web/react-ui-calendar": "^1.
|
|
18
|
-
"@itera-web/react-ui-popover": "^1.
|
|
19
|
-
"@itera-web/react-ui-select": "^1.
|
|
20
|
-
"@itera-web/utils-cn": "^1.
|
|
21
|
-
"@itera-web/utils-locale-toggle": "^1.
|
|
16
|
+
"@itera-web/hooks-setstate": "^1.22.0",
|
|
17
|
+
"@itera-web/react-ui-calendar": "^1.27.1",
|
|
18
|
+
"@itera-web/react-ui-popover": "^1.21.0",
|
|
19
|
+
"@itera-web/react-ui-select": "^1.31.0",
|
|
20
|
+
"@itera-web/utils-cn": "^1.22.0",
|
|
21
|
+
"@itera-web/utils-locale-toggle": "^1.22.0",
|
|
22
22
|
"date-fns": "^3.6.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react-dom": ">=17.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@itera-web/cli": "^1.1.
|
|
29
|
+
"@itera-web/cli": "^1.1.54"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "80f3ea01ee72fa2c94e4863e50ff4715166e50d5"
|
|
32
32
|
}
|