@bgord/ui 0.7.1 → 0.7.3
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/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/use-date-field.d.ts +34 -0
- package/dist/index.js +1 -1
- package/dist/services/date-field.d.ts +10 -0
- package/dist/services/form.d.ts +4 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/time-zone-offset.d.ts +5 -0
- package/package.json +1 -1
- package/readme.md +3 -0
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type DateFieldValueType } from "../services/date-field";
|
|
2
|
+
type DateFieldNameType = string;
|
|
3
|
+
export type DateFieldElementType = HTMLInputElement;
|
|
4
|
+
export type UseDateFieldConfigType<T extends string = string> = {
|
|
5
|
+
name: DateFieldNameType;
|
|
6
|
+
defaultValue?: DateFieldValueType<T>;
|
|
7
|
+
};
|
|
8
|
+
export type UseDateFieldReturnType<T extends string = string> = {
|
|
9
|
+
defaultValue: DateFieldValueType<T>;
|
|
10
|
+
value: DateFieldValueType<T>;
|
|
11
|
+
set: (value: DateFieldValueType<T>) => void;
|
|
12
|
+
handleChange: (event: React.ChangeEvent<DateFieldElementType>) => void;
|
|
13
|
+
clear: () => void;
|
|
14
|
+
label: {
|
|
15
|
+
props: {
|
|
16
|
+
htmlFor: DateFieldNameType;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
input: {
|
|
20
|
+
props: {
|
|
21
|
+
id: DateFieldNameType;
|
|
22
|
+
name: DateFieldNameType;
|
|
23
|
+
value: string;
|
|
24
|
+
min?: string;
|
|
25
|
+
max?: string;
|
|
26
|
+
onChange: (event: React.ChangeEvent<DateFieldElementType>) => void;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
changed: boolean;
|
|
30
|
+
unchanged: boolean;
|
|
31
|
+
empty: boolean;
|
|
32
|
+
};
|
|
33
|
+
export declare function useDateField<T extends string = string>(config: UseDateFieldConfigType<T>): UseDateFieldReturnType<T>;
|
|
34
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as Y,useRef as j}from"react";import{useEffect as A}from"react";function F(e,t){A(()=>{if(typeof document>"u")return;function n(r){let o=e.current;if(!o)return;if(o.contains(r.target))if(r.target===o){let{left:i,right:s,top:a,bottom:l}=o.getBoundingClientRect(),u=r instanceof MouseEvent?r.clientX:r.touches[0].clientX,f=r instanceof MouseEvent?r.clientY:r.touches[0].clientY;if(u>=i&&u<=s&&f>=a&&f<=l)return}else return;t(r)}return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n)}},[e,t])}import H from"react";function ce(e){let[t,n]=H.useState("idle"),r=(s)=>{if(s.preventDefault(),t==="idle")n("exiting")},o=(s)=>{if(s.animationName!==e.animation)return;e.action(),n("gone")},i=t==="exiting"?{"data-animation":e.animation,onAnimationEnd:o}:void 0;return{visible:t!=="gone",attach:i,trigger:r}}import{useMemo as k,useState as E}from"react";var M;((r)=>{r.idle="idle";r.selected="selected";r.error="error"})(M||={});function de(e,t){let n=t?.maxSizeBytes??Number.POSITIVE_INFINITY,[r,o]=E(0),[i,s]=E("idle"),[a,l]=E(null);function u(d){let T=d.currentTarget.files;if(!T?.[0])return;let x=T[0];if(x.size>n){s("error");return}if(!t.mimeTypes.includes(x.type)){s("error");return}return l(x),s("selected"),x}function f(){o((d)=>d+1),l(null),s("idle")}let R=k(()=>a?URL.createObjectURL(a):void 0,[a]);function v(d){return d.some((T)=>T===i)}let h={actions:{selectFile:u,clearFile:f},input:{props:{id:e,name:e,multiple:!1,accept:t.mimeTypes.join(",")},key:r},label:{props:{htmlFor:e}},matches:v};if(i==="idle")return{data:null,isError:!1,isIdle:!0,isSelected:!1,state:i,...h};if(i==="selected")return{data:a,isError:!1,isIdle:!1,isSelected:!0,preview:R,state:i,...h};return{data:null,isError:!0,isIdle:!1,isSelected:!1,state:i,...h}}import{useCallback as W,useMemo as q,useRef as V}from"react";import{useEffect as O}from"react";import{tinykeys as P}from"tinykeys";function g(e,t){let n=t?.enabled??!0;O(()=>{if(!n)return;let r=P(window,e);return()=>r()},[e,n])}function Ee(e){let t=V(null),n=W(()=>{if(t.current)t.current.focus()},[]);return g({[e]:n}),q(()=>({ref:t}),[])}import{useCallback as D,useRef as B}from"react";import{useState as X}from"react";function S({name:e,defaultValue:t=!1}){let[n,r]=X(t);return{on:n,off:!n,enable:()=>r(!0),disable:()=>r(!1),toggle:()=>r((u)=>!u),props:{controller:{"aria-expanded":n?"true":"false","aria-controls":e,role:"button",tabIndex:0},target:{id:e,role:"region","aria-hidden":n?"false":"true"}}}}function w(e){let{on:t,off:n,enable:r,disable:o,toggle:i,props:s,...a}=e;return{toggle:{on:t,off:n,enable:r,disable:o,toggle:i,props:s},rest:a}}function we(e){let t=e?.enabled??!0,n=S({name:"_internal"}),r=B(null),o=typeof window<"u"&&"PointerEvent"in window?"pointerenter":"mouseenter",i=typeof window<"u"&&"PointerEvent"in window?"pointerleave":"mouseleave";return{attach:{ref:D((a)=>{let l=r.current;if(l)l.removeEventListener(o,n.enable),l.removeEventListener(i,n.disable);if(r.current=a,a&&t)a.addEventListener(o,n.enable),a.addEventListener(i,n.disable)},[o,i,t,n.enable,n.disable])},hovering:n.on&&t}}import{useCallback as K}from"react";function Ie(){return{onKeyDown:K((t)=>{if(!t.metaKey||t.key!=="Enter")return;t.preventDefault(),t.currentTarget.form?.requestSubmit()},[])}}import{useState as C}from"react";class c{static EMPTY=void 0;value=c.EMPTY;constructor(e){this.value=c.isEmpty(e)?c.EMPTY:e}get(){return this.value}isEmpty(){return c.isEmpty(this.value)}static isEmpty(e){return e===void 0||e===null||Number.isNaN(e)}static compare(e,t){if(c.isEmpty(e)&&c.isEmpty(t))return!0;return e===t}}function Me(e){let t=new c(e.defaultValue),[n,r]=C(t.get()),[o,i]=C(c.isEmpty(t.get())?"":String(t.get())),s=(l)=>{let u=new c(l).get();r(u),i(c.isEmpty(u)?"":String(u))},a=(l)=>{if(i(l.currentTarget.value),l.currentTarget.value==="")return r(c.EMPTY);let u=l.currentTarget.valueAsNumber;if(Number.isFinite(u))r(u)};return{defaultValue:t.get(),value:n,set:s,handleChange:a,clear:()=>s(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:o,onChange:a}},changed:!c.compare(n,t.get()),unchanged:c.compare(n,t.get()),empty:c.isEmpty(n)}}import{useEffect as _}from"react";function L(e=!0){_(()=>{if(typeof document>"u")return;let t=document.body.style.overflow;if(e)document.body.style.overflow="hidden";return()=>{document.body.style.overflow=t}},[e])}import{useState as $}from"react";class m{static EMPTY=void 0;value=m.EMPTY;constructor(e){this.value=m.isEmpty(e)?m.EMPTY:e}get(){return this.value}isEmpty(){return m.isEmpty(this.value)}static isEmpty(e){return e===void 0||e===""||e===null}static compare(e,t){if(m.isEmpty(e)&&m.isEmpty(t))return!0;return e===t}}function De(e){let t=new m(e.defaultValue),[n,r]=$(t.get()),o=(s)=>r(new m(s).get()),i=(s)=>o(s.currentTarget.value);return{defaultValue:t.get(),value:n,set:o,handleChange:i,clear:()=>o(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:m.isEmpty(n)?"":n,onChange:i}},changed:!m.compare(n,t.get()),unchanged:m.compare(n,t.get()),empty:m.isEmpty(n)}}function y(){}import{jsx as z}from"react/jsx-runtime";function rt(e){let t=e.locked??!1,{toggle:n,rest:r}=w(e),o=j(null);return Y(()=>{if(e.on)o.current?.showModal();else o.current?.close()},[e.on]),g({Escape:t?y:n.disable}),L(e.on),F(o,t?y:n.disable),z("dialog",{ref:o,tabIndex:0,"aria-modal":"true","data-disp":e.on?"flex":"none","data-dir":"column","data-mx":"auto","data-p":"5","data-position":"fixed","data-z":"2","data-bg":"neutral-900","data-br":"xs","data-backdrop":"stronger","data-animation":"grow-fade-in",...r})}var lt={email:{inputMode:"email",autoComplete:"email",autoCapitalize:"none",spellCheck:"false"},password:{new:{autoComplete:"new-password"},current:{autoComplete:"current-password"}},off:{autoComplete:"off",spellCheck:!1}};class G{static async copy(e){let t=e.onSuccess??y;if(!navigator.clipboard)return;await navigator.clipboard.writeText(e.text),t()}}import Q from"js-cookie";class Z{static extractFrom(e){return e.headers.get("cookie")??""}static set(e,t){Q.set(e,t)}}class N{static fromRevision(e){return{"if-match":String(e)}}}function ft(e){return function(){for(let t of e)t()}}class ee{static allUnchanged(e){return e.every((t)=>t.unchanged)}static allEmpty(e){return e.every((t)=>t.empty)}static anyEmpty(e){return e.some((t)=>t.empty)}static anyUnchanged(e){return e.some((t)=>t.unchanged)}static anyChanged(e){return e.some((t)=>t.changed)}}class te{static input(e){let t=e.required??!0;if(e.min&&!e.max)return{pattern:`.{${e.min}}`,required:t};if(e.min&&e.max)return{pattern:`.{${e.min},${e.max}}`,required:t};if(!e.min&&e.max)return{pattern:`.{,${e.max}}`,required:t};return{pattern:void 0,required:t}}static textarea(e){let t=e.required??!0;if(e.min&&!e.max)return{minLength:e.min,required:t};if(e.min&&e.max)return{minLength:e.min,maxLength:e.max,required:t};if(!e.min&&e.max)return{maxLength:e.max,required:t};return{required:t}}static exact(e){let t=e.required??!0;return{pattern:e.text,required:t}}static date={min:{today:()=>new Date().toISOString().split("T")[0]},max:{today:()=>new Date().toISOString().split("T")[0]}}}function ht(){if(typeof window>"u")return;return window}import{polishPlurals as ne}from"polish-plurals";function I(e){if(e.language==="en"){let t=e.plural??`${e.singular}s`;if(e.value===1)return e.singular;return t}if(e.language==="pl"){let t=e.value??1;if(t===1)return e.singular;return ne(e.singular,String(e.plural),String(e.genitive),t)}return console.warn(`[@bgord/frontend] missing pluralization function for language: ${e.language}.`),e.singular}function Rt(e=12){return{times(t){let n=e*t,r={height:{height:p(n)},minHeight:{minHeight:p(n)},maxHeight:{maxHeight:p(n)},width:{width:p(n)},minWidth:{minWidth:p(n)},maxWidth:{maxWidth:p(n)},square:{height:p(n),width:p(n)}},o={height:{style:{height:p(n)}},minHeight:{style:{minHeight:p(n)}},maxHeight:{style:{maxHeight:p(n)}},width:{style:{width:p(n)}},minWidth:{style:{minWidth:p(n)}},maxWidth:{style:{maxWidth:p(n)}},square:{style:{height:p(n),width:p(n)}}};return{px:p(n),raw:n,style:o,...r}}}}function p(e){return`${e}px`}import{createContext as re,use as U,useCallback as oe}from"react";var b=re({translations:{},language:"en",supportedLanguages:{en:"en"}});function Ct(){let e=U(b);if(e===void 0)throw Error("useTranslations must be used within the TranslationsContext");return oe((n,r)=>{let o=e.translations[n];if(!o)return console.warn(`[@bgord/ui] missing translation for key: ${n}`),n;if(!r)return o;return Object.entries(r).reduce((i,[s,a])=>{let l=new RegExp(`{{${s}}}`,"g");return i.replace(l,String(a))},o)},[e.translations])}function ie(){let e=U(b);if(e===void 0)throw Error("useLanguage must be used within the TranslationsContext");return e.language}function Lt(){let e=U(b);if(e===void 0)throw Error("useSupportedLanguages must be used within the TranslationsContext");return e.supportedLanguages}function It(){let e=ie();return(t)=>I({...t,language:e})}class se{static fromRevision(e){return{"if-match":`W/${e}`}}}export{Ct as useTranslations,S as useToggle,De as useTextField,Lt as useSupportedLanguages,g as useShortcuts,L as useScrollLock,It as usePluralize,Me as useNumberField,Ie as useMetaEnterSubmit,ie as useLanguage,we as useHover,Ee as useFocusKeyboardShortcut,de as useFile,ce as useExitAction,F as useClickOutside,I as pluralize,y as noop,ht as getSafeWindow,w as extractUseToggle,ft as exec,se as WeakETag,M as UseFileState,b as TranslationsContext,m as TextField,Rt as Rhythm,c as NumberField,te as Form,ee as Fields,N as ETag,rt as Dialog,Z as Cookies,G as Clipboard,lt as Autocomplete};
|
|
1
|
+
import{useEffect as z,useRef as Z}from"react";import{useEffect as A}from"react";function S(e,t){A(()=>{if(typeof document>"u")return;function n(r){let o=e.current;if(!o)return;if(o.contains(r.target))if(r.target===o){let{left:i,right:a,top:s,bottom:l}=o.getBoundingClientRect(),p=r instanceof MouseEvent?r.clientX:r.touches[0].clientX,y=r instanceof MouseEvent?r.clientY:r.touches[0].clientY;if(p>=i&&p<=a&&y>=s&&y<=l)return}else return;t(r)}return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n)}},[e,t])}import{useState as w}from"react";class m{static EMPTY=void 0;value=m.EMPTY;constructor(e){this.value=m.isEmpty(e)?m.EMPTY:e}get(){return this.value}isEmpty(){return m.isEmpty(this.value)}static isEmpty(e){return e===void 0||e===null||e===""}static compare(e,t){if(m.isEmpty(e)&&m.isEmpty(t))return!0;return e===t}}function Te(e){let t=new m(e.defaultValue),[n,r]=w(t.get()),[o,i]=w(m.isEmpty(t.get())?"":t.get()),a=(l)=>{let p=new m(l).get();r(p),i(m.isEmpty(p)?"":String(p))},s=(l)=>{let p=l.currentTarget,y=p.value;if(i(y),y==="")return r(m.EMPTY);if(!/^\d{4}-\d{2}-\d{2}$/.test(y))return;if(!p.validity.valid)return;r(y)};return{defaultValue:t.get(),value:n,set:a,handleChange:s,clear:()=>a(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:o,onChange:s}},changed:!m.compare(n,t.get()),unchanged:m.compare(n,t.get()),empty:m.isEmpty(n)}}import M from"react";function xe(e){let[t,n]=M.useState("idle"),r=(a)=>{if(a.preventDefault(),t==="idle")n("exiting")},o=(a)=>{if(a.animationName!==e.animation)return;e.action(),n("gone")},i=t==="exiting"?{"data-animation":e.animation,onAnimationEnd:o}:void 0;return{visible:t!=="gone",attach:i,trigger:r}}import{useMemo as H,useState as F}from"react";var k;((r)=>{r.idle="idle";r.selected="selected";r.error="error"})(k||={});function Ue(e,t){let n=t?.maxSizeBytes??Number.POSITIVE_INFINITY,[r,o]=F(0),[i,a]=F("idle"),[s,l]=F(null);function p(f){let x=f.currentTarget.files;if(!x?.[0])return;let h=x[0];if(h.size>n){a("error");return}if(!t.mimeTypes.includes(h.type)){a("error");return}return l(h),a("selected"),h}function y(){o((f)=>f+1),l(null),a("idle")}let T=H(()=>s?URL.createObjectURL(s):void 0,[s]);function L(f){return f.some((x)=>x===i)}let U={actions:{selectFile:p,clearFile:y},input:{props:{id:e,name:e,multiple:!1,accept:t.mimeTypes.join(",")},key:r},label:{props:{htmlFor:e}},matches:L};if(i==="idle")return{data:null,isError:!1,isIdle:!0,isSelected:!1,state:i,...U};if(i==="selected")return{data:s,isError:!1,isIdle:!1,isSelected:!0,preview:T,state:i,...U};return{data:null,isError:!0,isIdle:!1,isSelected:!1,state:i,...U}}import{useCallback as W,useMemo as q,useRef as X}from"react";import{useEffect as O}from"react";import{tinykeys as P}from"tinykeys";function E(e,t){let n=t?.enabled??!0;O(()=>{if(!n)return;let r=P(window,e);return()=>r()},[e,n])}function Ce(e){let t=X(null),n=W(()=>{if(t.current)t.current.focus()},[]);return E({[e]:n}),q(()=>({ref:t}),[])}import{useCallback as K,useRef as Y}from"react";import{useState as B}from"react";function D({name:e,defaultValue:t=!1}){let[n,r]=B(t);return{on:n,off:!n,enable:()=>r(!0),disable:()=>r(!1),toggle:()=>r((p)=>!p),props:{controller:{"aria-expanded":n?"true":"false","aria-controls":e,role:"button",tabIndex:0},target:{id:e,role:"region","aria-hidden":n?"false":"true"}}}}function C(e){let{on:t,off:n,enable:r,disable:o,toggle:i,props:a,...s}=e;return{toggle:{on:t,off:n,enable:r,disable:o,toggle:i,props:a},rest:s}}function Me(e){let t=e?.enabled??!0,n=D({name:"_internal"}),r=Y(null),o=typeof window<"u"&&"PointerEvent"in window?"pointerenter":"mouseenter",i=typeof window<"u"&&"PointerEvent"in window?"pointerleave":"mouseleave";return{attach:{ref:K((s)=>{let l=r.current;if(l)l.removeEventListener(o,n.enable),l.removeEventListener(i,n.disable);if(r.current=s,s&&t)s.addEventListener(o,n.enable),s.addEventListener(i,n.disable)},[o,i,t,n.enable,n.disable])},hovering:n.on&&t}}import{useCallback as $}from"react";function Oe(){return{onKeyDown:$((t)=>{if(!t.metaKey||t.key!=="Enter")return;t.preventDefault(),t.currentTarget.form?.requestSubmit()},[])}}import{useState as v}from"react";class d{static EMPTY=void 0;value=d.EMPTY;constructor(e){this.value=d.isEmpty(e)?d.EMPTY:e}get(){return this.value}isEmpty(){return d.isEmpty(this.value)}static isEmpty(e){return e===void 0||e===null||Number.isNaN(e)}static compare(e,t){if(d.isEmpty(e)&&d.isEmpty(t))return!0;return e===t}}function Be(e){let t=new d(e.defaultValue),[n,r]=v(t.get()),[o,i]=v(d.isEmpty(t.get())?"":String(t.get())),a=(l)=>{let p=new d(l).get();r(p),i(d.isEmpty(p)?"":String(p))},s=(l)=>{let p=l.currentTarget,y=p.value;if(i(y),y==="")return r(d.EMPTY);let T=p.valueAsNumber;if(!Number.isFinite(T))return;if(!l.currentTarget.validity.valid)return;r(T)};return{defaultValue:t.get(),value:n,set:a,handleChange:s,clear:()=>a(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:o,onChange:s}},changed:!d.compare(n,t.get()),unchanged:d.compare(n,t.get()),empty:d.isEmpty(n)}}import{useEffect as _}from"react";function V(e=!0){_(()=>{if(typeof document>"u")return;let t=document.body.style.overflow;if(e)document.body.style.overflow="hidden";return()=>{document.body.style.overflow=t}},[e])}import{useState as J}from"react";class u{static EMPTY=void 0;value=u.EMPTY;constructor(e){this.value=u.isEmpty(e)?u.EMPTY:e}get(){return this.value}isEmpty(){return u.isEmpty(this.value)}static isEmpty(e){return e===void 0||e===""||e===null}static compare(e,t){if(u.isEmpty(e)&&u.isEmpty(t))return!0;return e===t}}function ze(e){let t=new u(e.defaultValue),[n,r]=J(t.get()),o=(a)=>r(new u(a).get()),i=(a)=>o(a.currentTarget.value);return{defaultValue:t.get(),value:n,set:o,handleChange:i,clear:()=>o(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:u.isEmpty(n)?"":n,onChange:i}},changed:!u.compare(n,t.get()),unchanged:u.compare(n,t.get()),empty:u.isEmpty(n)}}function g(){}import{jsx as G}from"react/jsx-runtime";function dt(e){let t=e.locked??!1,{toggle:n,rest:r}=C(e),o=Z(null);return z(()=>{if(e.on)o.current?.showModal();else o.current?.close()},[e.on]),E({Escape:t?g:n.disable}),V(e.on),S(o,t?g:n.disable),G("dialog",{ref:o,tabIndex:0,"aria-modal":"true","data-disp":e.on?"flex":"none","data-dir":"column","data-mx":"auto","data-p":"5","data-position":"fixed","data-z":"2","data-bg":"neutral-900","data-br":"xs","data-backdrop":"stronger","data-animation":"grow-fade-in",...r})}var gt={email:{inputMode:"email",autoComplete:"email",autoCapitalize:"none",spellCheck:"false"},password:{new:{autoComplete:"new-password"},current:{autoComplete:"current-password"}},off:{autoComplete:"off",spellCheck:!1}};class N{static async copy(e){let t=e.onSuccess??g;if(!navigator.clipboard)return;await navigator.clipboard.writeText(e.text),t()}}import Q from"js-cookie";class ee{static extractFrom(e){return e.headers.get("cookie")??""}static set(e,t){Q.set(e,t)}}class te{static fromRevision(e){return{"if-match":String(e)}}}function Rt(e){return function(){for(let t of e)t()}}class ne{static allUnchanged(e){return e.every((t)=>t.unchanged)}static allEmpty(e){return e.every((t)=>t.empty)}static anyEmpty(e){return e.some((t)=>t.empty)}static anyUnchanged(e){return e.some((t)=>t.unchanged)}static anyChanged(e){return e.some((t)=>t.changed)}}class re{static input(e){let t=e.required??!0;if(e.min&&!e.max)return{pattern:`.{${e.min}}`,required:t};if(e.min&&e.max)return{pattern:`.{${e.min},${e.max}}`,required:t};if(!e.min&&e.max)return{pattern:`.{,${e.max}}`,required:t};return{pattern:void 0,required:t}}static textarea(e){let t=e.required??!0;if(e.min&&!e.max)return{minLength:e.min,required:t};if(e.min&&e.max)return{minLength:e.min,maxLength:e.max,required:t};if(!e.min&&e.max)return{maxLength:e.max,required:t};return{required:t}}static exact(e){let t=e.required??!0;return{pattern:e.text,required:t}}static date={min:{today:()=>new Date().toISOString().split("T")[0],tomorrow:()=>{let e=new Date;return new Date(e.setDate(e.getDate()+1)).toISOString().split("T")[0]},yesterday:()=>{let e=new Date;return new Date(e.setDate(e.getDate()-1)).toISOString().split("T")[0]}},max:{today:()=>new Date().toISOString().split("T")[0],tomorrow:()=>{let e=new Date;return new Date(e.setDate(e.getDate()+1)).toISOString().split("T")[0]},yesterday:()=>{let e=new Date;return new Date(e.setDate(e.getDate()-1)).toISOString().split("T")[0]}}}}function Ct(){if(typeof window>"u")return;return window}import{polishPlurals as oe}from"polish-plurals";function I(e){if(e.language==="en"){let t=e.plural??`${e.singular}s`;if(e.value===1)return e.singular;return t}if(e.language==="pl"){let t=e.value??1;if(t===1)return e.singular;return oe(e.singular,String(e.plural),String(e.genitive),t)}return console.warn(`[@bgord/frontend] missing pluralization function for language: ${e.language}.`),e.singular}function Lt(e=12){return{times(t){let n=e*t,r={height:{height:c(n)},minHeight:{minHeight:c(n)},maxHeight:{maxHeight:c(n)},width:{width:c(n)},minWidth:{minWidth:c(n)},maxWidth:{maxWidth:c(n)},square:{height:c(n),width:c(n)}},o={height:{style:{height:c(n)}},minHeight:{style:{minHeight:c(n)}},maxHeight:{style:{maxHeight:c(n)}},width:{style:{width:c(n)}},minWidth:{style:{minWidth:c(n)}},maxWidth:{style:{maxWidth:c(n)}},square:{style:{height:c(n),width:c(n)}}};return{px:c(n),raw:n,style:o,...r}}}}function c(e){return`${e}px`}class ie{static get(){return{"time-zone-offset":new Date().getTimezoneOffset().toString()}}}import{createContext as ae,use as b,useCallback as se}from"react";var R=ae({translations:{},language:"en",supportedLanguages:{en:"en"}});function Ot(){let e=b(R);if(e===void 0)throw Error("useTranslations must be used within the TranslationsContext");return se((n,r)=>{let o=e.translations[n];if(!o)return console.warn(`[@bgord/ui] missing translation for key: ${n}`),n;if(!r)return o;return Object.entries(r).reduce((i,[a,s])=>{let l=new RegExp(`{{${a}}}`,"g");return i.replace(l,String(s))},o)},[e.translations])}function le(){let e=b(R);if(e===void 0)throw Error("useLanguage must be used within the TranslationsContext");return e.language}function Pt(){let e=b(R);if(e===void 0)throw Error("useSupportedLanguages must be used within the TranslationsContext");return e.supportedLanguages}function Wt(){let e=le();return(t)=>I({...t,language:e})}class pe{static fromRevision(e){return{"if-match":`W/${e}`}}}export{Ot as useTranslations,D as useToggle,ze as useTextField,Pt as useSupportedLanguages,E as useShortcuts,V as useScrollLock,Wt as usePluralize,Be as useNumberField,Oe as useMetaEnterSubmit,le as useLanguage,Me as useHover,Ce as useFocusKeyboardShortcut,Ue as useFile,xe as useExitAction,Te as useDateField,S as useClickOutside,I as pluralize,g as noop,Ct as getSafeWindow,C as extractUseToggle,Rt as exec,pe as WeakETag,k as UseFileState,R as TranslationsContext,ie as TimeZoneOffset,u as TextField,Lt as Rhythm,d as NumberField,re as Form,ne as Fields,te as ETag,dt as Dialog,m as DateField,ee as Cookies,N as Clipboard,gt as Autocomplete};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type DateFieldValueType<T extends string = string> = T | undefined;
|
|
2
|
+
export declare class DateField<T extends string = string> {
|
|
3
|
+
static readonly EMPTY: undefined;
|
|
4
|
+
private readonly value;
|
|
5
|
+
constructor(value: DateFieldValueType<T>);
|
|
6
|
+
get(): DateFieldValueType<T>;
|
|
7
|
+
isEmpty(): boolean;
|
|
8
|
+
static isEmpty<V extends string>(value: DateFieldValueType<V> | null): boolean;
|
|
9
|
+
static compare<V extends string>(one: DateFieldValueType<V>, another: DateFieldValueType<V>): boolean;
|
|
10
|
+
}
|
package/dist/services/form.d.ts
CHANGED
|
@@ -15,9 +15,13 @@ export declare class Form {
|
|
|
15
15
|
static date: {
|
|
16
16
|
min: {
|
|
17
17
|
today: () => string;
|
|
18
|
+
tomorrow: () => string;
|
|
19
|
+
yesterday: () => string;
|
|
18
20
|
};
|
|
19
21
|
max: {
|
|
20
22
|
today: () => string;
|
|
23
|
+
tomorrow: () => string;
|
|
24
|
+
yesterday: () => string;
|
|
21
25
|
};
|
|
22
26
|
};
|
|
23
27
|
}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./autocomplete";
|
|
2
2
|
export * from "./clipboard";
|
|
3
3
|
export * from "./cookies";
|
|
4
|
+
export * from "./date-field";
|
|
4
5
|
export * from "./etag";
|
|
5
6
|
export * from "./exec";
|
|
6
7
|
export * from "./fields";
|
|
@@ -11,5 +12,6 @@ export * from "./number-field";
|
|
|
11
12
|
export * from "./pluralize";
|
|
12
13
|
export * from "./rhythm";
|
|
13
14
|
export * from "./text-field";
|
|
15
|
+
export * from "./time-zone-offset";
|
|
14
16
|
export * from "./translations";
|
|
15
17
|
export * from "./weak-etag";
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -28,6 +28,7 @@ src/
|
|
|
28
28
|
│ ├── dialog.tsx
|
|
29
29
|
├── hooks
|
|
30
30
|
│ ├── use-click-outside.ts
|
|
31
|
+
│ ├── use-date-field.ts
|
|
31
32
|
│ ├── use-exit-action.ts
|
|
32
33
|
│ ├── use-file.ts
|
|
33
34
|
│ ├── use-focus-shortcut.ts
|
|
@@ -42,6 +43,7 @@ src/
|
|
|
42
43
|
├── autocomplete.ts
|
|
43
44
|
├── clipboard.ts
|
|
44
45
|
├── cookies.ts
|
|
46
|
+
├── date-field.ts
|
|
45
47
|
├── etag.ts
|
|
46
48
|
├── exec.ts
|
|
47
49
|
├── fields.ts
|
|
@@ -52,6 +54,7 @@ src/
|
|
|
52
54
|
├── pluralize.ts
|
|
53
55
|
├── rhythm.ts
|
|
54
56
|
├── text-field.ts
|
|
57
|
+
├── time-zone-offset.ts
|
|
55
58
|
├── translations.tsx
|
|
56
59
|
└── weak-etag.ts
|
|
57
60
|
```
|