@bgord/ui 0.7.5 → 0.7.8
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-exit-action.d.ts +1 -1
- package/dist/hooks/use-mutation.d.ts +26 -0
- package/dist/index.js +1 -1
- package/dist/services/head.d.ts +22 -0
- package/dist/services/index.d.ts +1 -0
- package/package.json +1 -1
- package/readme.md +2 -0
package/dist/hooks/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./use-file";
|
|
|
5
5
|
export * from "./use-focus-shortcut";
|
|
6
6
|
export * from "./use-hover";
|
|
7
7
|
export * from "./use-meta-enter-submit";
|
|
8
|
+
export * from "./use-mutation";
|
|
8
9
|
export * from "./use-number-field";
|
|
9
10
|
export * from "./use-scroll-lock";
|
|
10
11
|
export * from "./use-shortcuts";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum MutationState {
|
|
2
|
+
idle = "idle",
|
|
3
|
+
loading = "loading",
|
|
4
|
+
error = "error",
|
|
5
|
+
done = "done"
|
|
6
|
+
}
|
|
7
|
+
type MutationErrorType = unknown;
|
|
8
|
+
type UseMutationOptions = {
|
|
9
|
+
perform: () => Promise<Response>;
|
|
10
|
+
onSuccess?: (response: Response) => void | Promise<void>;
|
|
11
|
+
onError?: (error: MutationErrorType) => void | Promise<void>;
|
|
12
|
+
autoResetDelayMs?: number;
|
|
13
|
+
};
|
|
14
|
+
type UseMutationReturnType = {
|
|
15
|
+
state: MutationState;
|
|
16
|
+
error: MutationErrorType;
|
|
17
|
+
isIdle: boolean;
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
isError: boolean;
|
|
20
|
+
isDone: boolean;
|
|
21
|
+
mutate: () => Promise<Response | undefined>;
|
|
22
|
+
handleSubmit: React.FormEventHandler<HTMLFormElement>;
|
|
23
|
+
reset: () => void;
|
|
24
|
+
};
|
|
25
|
+
export declare function useMutation(options: UseMutationOptions): UseMutationReturnType;
|
|
26
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as Z,useRef as G}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 fe(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 he(e){let[t,n]=M.useState("idle"),r=(a)=>{if(a.preventDefault(),t==="idle")n("exiting")},o=async(a)=>{if(a.animationName!==e.animation)return;n("gone"),await e.action()},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 Fe(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 ve(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 He(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 Pe(){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 Ke(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{useEffect as J,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 J(()=>{o(t.get())},[e.defaultValue]),{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 N}from"react/jsx-runtime";function ut(e){let t=e.locked??!1,{toggle:n,rest:r}=C(e),o=G(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),N("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 xt={email:{inputMode:"email",autoComplete:"email",autoCapitalize:"none",spellCheck:"false"},password:{new:{autoComplete:"new-password"},current:{autoComplete:"current-password"}},off:{autoComplete:"off",spellCheck:!1}};class Q{static async copy(e){let t=e.onSuccess??g;if(!navigator.clipboard)return;await navigator.clipboard.writeText(e.text),t()}}import ee from"js-cookie";class te{static extractFrom(e){return e.headers.get("cookie")??""}static set(e,t){ee.set(e,t)}}class ne{static fromRevision(e){return{"if-match":String(e)}}}function St(e){return function(){for(let t of e)t()}}class re{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 oe{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 vt(){if(typeof window>"u")return;return window}import{polishPlurals as ie}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 ie(e.singular,String(e.plural),String(e.genitive),t)}return console.warn(`[@bgord/frontend] missing pluralization function for language: ${e.language}.`),e.singular}function At(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 ae{static get(){return{"time-zone-offset":new Date().getTimezoneOffset().toString()}}}import{createContext as se,use as b,useCallback as le}from"react";var R=se({translations:{},language:"en",supportedLanguages:{en:"en"}});function Pt(){let e=b(R);if(e===void 0)throw Error("useTranslations must be used within the TranslationsContext");return le((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 pe(){let e=b(R);if(e===void 0)throw Error("useLanguage must be used within the TranslationsContext");return e.language}function Wt(){let e=b(R);if(e===void 0)throw Error("useSupportedLanguages must be used within the TranslationsContext");return e.supportedLanguages}function qt(){let e=pe();return(t)=>I({...t,language:e})}class ce{static fromRevision(e){return{"if-match":`W/${e}`}}}export{Pt as useTranslations,D as useToggle,Ze as useTextField,Wt as useSupportedLanguages,E as useShortcuts,V as useScrollLock,qt as usePluralize,Ke as useNumberField,Pe as useMetaEnterSubmit,pe as useLanguage,He as useHover,ve as useFocusKeyboardShortcut,Fe as useFile,he as useExitAction,fe as useDateField,S as useClickOutside,I as pluralize,g as noop,vt as getSafeWindow,C as extractUseToggle,St as exec,ce as WeakETag,k as UseFileState,R as TranslationsContext,ae as TimeZoneOffset,u as TextField,At as Rhythm,d as NumberField,oe as Form,re as Fields,ne as ETag,ut as Dialog,m as DateField,te as Cookies,Q as Clipboard,xt as Autocomplete};
|
|
1
|
+
import{useEffect as Q,useRef as ee}from"react";import{useEffect as H}from"react";function w(e,t){H(()=>{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:a,right:i,top:l,bottom:s}=o.getBoundingClientRect(),p=r instanceof MouseEvent?r.clientX:r.touches[0].clientX,y=r instanceof MouseEvent?r.clientY:r.touches[0].clientY;if(p>=a&&p<=i&&y>=l&&y<=s)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 D}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||e===""}static compare(e,t){if(d.isEmpty(e)&&d.isEmpty(t))return!0;return e===t}}function Ee(e){let t=new d(e.defaultValue),[n,r]=D(t.get()),[o,a]=D(d.isEmpty(t.get())?"":t.get()),i=(s)=>{let p=new d(s).get();r(p),a(d.isEmpty(p)?"":String(p))},l=(s)=>{let p=s.currentTarget,y=p.value;if(a(y),y==="")return r(d.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:i,handleChange:l,clear:()=>i(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:o,onChange:l}},changed:!d.compare(n,t.get()),unchanged:d.compare(n,t.get()),empty:d.isEmpty(n)}}import k from"react";function Fe(e){let[t,n]=k.useState("idle"),r=(i)=>{if(i.preventDefault(),t==="idle")n("exiting")},o=async(i)=>{if(i.animationName!==e.animation)return;n("gone"),await e.action()},a=t==="exiting"?{"data-animation":e.animation,onAnimationEnd:o}:void 0;return{visible:t!=="gone",attach:a,trigger:r}}import{useMemo as P,useState as F}from"react";var O;((r)=>{r.idle="idle";r.selected="selected";r.error="error"})(O||={});function Re(e,t){let n=t?.maxSizeBytes??Number.POSITIVE_INFINITY,[r,o]=F(0),[a,i]=F("idle"),[l,s]=F(null);function p(f){let x=f.currentTarget.files;if(!x?.[0])return;let E=x[0];if(E.size>n){i("error");return}if(!t.mimeTypes.includes(E.type)){i("error");return}return s(E),i("selected"),E}function y(){o((f)=>f+1),s(null),i("idle")}let T=P(()=>l?URL.createObjectURL(l):void 0,[l]);function A(f){return f.some((x)=>x===a)}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:A};if(a==="idle")return{data:null,isError:!1,isIdle:!0,isSelected:!1,state:a,...U};if(a==="selected")return{data:l,isError:!1,isIdle:!1,isSelected:!0,preview:T,state:a,...U};return{data:null,isError:!0,isIdle:!1,isSelected:!1,state:a,...U}}import{useCallback as X,useMemo as B,useRef as K}from"react";import{useEffect as W}from"react";import{tinykeys as q}from"tinykeys";function h(e,t){let n=t?.enabled??!0;W(()=>{if(!n)return;let r=q(window,e);return()=>r()},[e,n])}function Le(e){let t=K(null),n=X(()=>{if(t.current)t.current.focus()},[]);return h({[e]:n}),B(()=>({ref:t}),[])}import{useCallback as _,useRef as $}from"react";import{useState as Y}from"react";function v({name:e,defaultValue:t=!1}){let[n,r]=Y(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 M(e){let{on:t,off:n,enable:r,disable:o,toggle:a,props:i,...l}=e;return{toggle:{on:t,off:n,enable:r,disable:o,toggle:a,props:i},rest:l}}function Oe(e){let t=e?.enabled??!0,n=v({name:"_internal"}),r=$(null),o=typeof window<"u"&&"PointerEvent"in window?"pointerenter":"mouseenter",a=typeof window<"u"&&"PointerEvent"in window?"pointerleave":"mouseleave";return{attach:{ref:_((l)=>{let s=r.current;if(s)s.removeEventListener(o,n.enable),s.removeEventListener(a,n.disable);if(r.current=l,l&&t)l.addEventListener(o,n.enable),l.addEventListener(a,n.disable)},[o,a,t,n.enable,n.disable])},hovering:n.on&&t}}import{useCallback as J}from"react";function Xe(){return{onKeyDown:J((t)=>{if(!t.metaKey||t.key!=="Enter")return;t.preventDefault(),t.currentTarget.form?.requestSubmit()},[])}}import{useCallback as S,useState as C}from"react";var j;((o)=>{o.idle="idle";o.loading="loading";o.error="error";o.done="done"})(j||={});function Ye(e){let[t,n]=C("idle"),[r,o]=C(null),a=S(()=>{o(null),n("idle")},[]),i=S(async()=>{if(t==="loading")return;o(null),n("loading");try{let s=await e.perform();if(!s.ok){n("error"),o(null),await e.onError?.(null);return}if(n("done"),await e.onSuccess?.(s),e.autoResetDelayMs)setTimeout(()=>n("idle"),e.autoResetDelayMs);return s}catch(s){n("error"),o(s),await e.onError?.(s)}},[t,e]),l=S(async(s)=>{s.preventDefault(),await i()},[i]);return{state:t,error:r,isIdle:t==="idle",isLoading:t==="loading",isError:t==="error",isDone:t==="done",mutate:i,handleSubmit:l,reset:a}}import{useState as V}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 ze(e){let t=new c(e.defaultValue),[n,r]=V(t.get()),[o,a]=V(c.isEmpty(t.get())?"":String(t.get())),i=(s)=>{let p=new c(s).get();r(p),a(c.isEmpty(p)?"":String(p))},l=(s)=>{let p=s.currentTarget,y=p.value;if(a(y),y==="")return r(c.EMPTY);let T=p.valueAsNumber;if(!Number.isFinite(T))return;if(!s.currentTarget.validity.valid)return;r(T)};return{defaultValue:t.get(),value:n,set:i,handleChange:l,clear:()=>i(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:o,onChange:l}},changed:!c.compare(n,t.get()),unchanged:c.compare(n,t.get()),empty:c.isEmpty(n)}}import{useEffect as z}from"react";function L(e=!0){z(()=>{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{useEffect as Z,useState as G}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 nt(e){let t=new m(e.defaultValue),[n,r]=G(t.get()),o=(i)=>r(new m(i).get()),a=(i)=>o(i.currentTarget.value);return Z(()=>{o(t.get())},[e.defaultValue]),{defaultValue:t.get(),value:n,set:o,handleChange:a,clear:()=>o(t.get()),label:{props:{htmlFor:e.name}},input:{props:{id:e.name,name:e.name,value:m.isEmpty(n)?"":n,onChange:a}},changed:!m.compare(n,t.get()),unchanged:m.compare(n,t.get()),empty:m.isEmpty(n)}}function g(){}import{jsxDEV as te}from"react/jsx-dev-runtime";function ht(e){let{locked:t,...n}=e,r=t??!1,{toggle:o,rest:a}=M(n),i=ee(null);return Q(()=>{if(e.on)i.current?.showModal();else i.current?.close()},[e.on]),h({Escape:r?g:o.disable}),L(e.on),w(i,r?g:o.disable),te("dialog",{ref:i,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",...a},void 0,!1,void 0,this)}var Rt={email:{inputMode:"email",autoComplete:"email",autoCapitalize:"none",spellCheck:"false"},password:{new:{autoComplete:"new-password"},current:{autoComplete:"current-password"}},off:{autoComplete:"off",spellCheck:!1}};class ne{static async copy(e){let t=e.onSuccess??g;if(!navigator.clipboard)return;await navigator.clipboard.writeText(e.text),t()}}import re from"js-cookie";class oe{static extractFrom(e){return e.headers.get("cookie")??""}static set(e,t){re.set(e,t)}}class ie{static fromRevision(e){return{"if-match":String(e)}}}function Lt(e){return function(){for(let t of e)t()}}class ae{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 se{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 kt(){if(typeof window>"u")return;return window}var Ot=(e)=>[{rel:"preload",as:"style",href:e},{rel:"stylesheet",href:e}],Wt=(e)=>({type:"module",src:e}),qt=[{charSet:"utf-8"},{name:"viewport",content:"width=device-width, initial-scale=1"}];import{polishPlurals as le}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 le(e.singular,String(e.plural),String(e.genitive),t)}return console.warn(`[@bgord/frontend] missing pluralization function for language: ${e.language}.`),e.singular}function Yt(e=12){return{times(t){let n=e*t,r={height:{height:u(n)},minHeight:{minHeight:u(n)},maxHeight:{maxHeight:u(n)},width:{width:u(n)},minWidth:{minWidth:u(n)},maxWidth:{maxWidth:u(n)},square:{height:u(n),width:u(n)}},o={height:{style:{height:u(n)}},minHeight:{style:{minHeight:u(n)}},maxHeight:{style:{maxHeight:u(n)}},width:{style:{width:u(n)}},minWidth:{style:{minWidth:u(n)}},maxWidth:{style:{maxWidth:u(n)}},square:{style:{height:u(n),width:u(n)}}};return{px:u(n),raw:n,style:o,...r}}}}function u(e){return`${e}px`}class pe{static get(){return{"time-zone-offset":new Date().getTimezoneOffset().toString()}}}import{createContext as ue,use as b,useCallback as de}from"react";var R=ue({translations:{},language:"en",supportedLanguages:{en:"en"}});function zt(){let e=b(R);if(e===void 0)throw Error("useTranslations must be used within the TranslationsContext");return de((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((a,[i,l])=>{let s=new RegExp(`{{${i}}}`,"g");return a.replace(s,String(l))},o)},[e.translations])}function ce(){let e=b(R);if(e===void 0)throw Error("useLanguage must be used within the TranslationsContext");return e.language}function Zt(){let e=b(R);if(e===void 0)throw Error("useSupportedLanguages must be used within the TranslationsContext");return e.supportedLanguages}function Gt(){let e=ce();return(t)=>I({...t,language:e})}class me{static fromRevision(e){return{"if-match":`W/${e}`}}}export{zt as useTranslations,v as useToggle,nt as useTextField,Zt as useSupportedLanguages,h as useShortcuts,L as useScrollLock,Gt as usePluralize,ze as useNumberField,Ye as useMutation,Xe as useMetaEnterSubmit,ce as useLanguage,Oe as useHover,Le as useFocusKeyboardShortcut,Re as useFile,Fe as useExitAction,Ee as useDateField,w as useClickOutside,I as pluralize,g as noop,kt as getSafeWindow,M as extractUseToggle,Lt as exec,me as WeakETag,O as UseFileState,R as TranslationsContext,pe as TimeZoneOffset,m as TextField,Yt as Rhythm,c as NumberField,j as MutationState,qt as META,Wt as JS,se as Form,ae as Fields,ie as ETag,ht as Dialog,d as DateField,oe as Cookies,ne as Clipboard,Ot as CSS,Rt as Autocomplete};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const CSS: (href: string) => ({
|
|
2
|
+
rel: string;
|
|
3
|
+
as: string;
|
|
4
|
+
href: string;
|
|
5
|
+
} | {
|
|
6
|
+
rel: string;
|
|
7
|
+
href: string;
|
|
8
|
+
as?: undefined;
|
|
9
|
+
})[];
|
|
10
|
+
export declare const JS: (src: string) => {
|
|
11
|
+
type: string;
|
|
12
|
+
src: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const META: ({
|
|
15
|
+
charSet: string;
|
|
16
|
+
name?: undefined;
|
|
17
|
+
content?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
name: string;
|
|
20
|
+
content: string;
|
|
21
|
+
charSet?: undefined;
|
|
22
|
+
})[];
|
package/dist/services/index.d.ts
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -34,6 +34,7 @@ src/
|
|
|
34
34
|
│ ├── use-focus-shortcut.ts
|
|
35
35
|
│ ├── use-hover.ts
|
|
36
36
|
│ ├── use-meta-enter-submit.ts
|
|
37
|
+
│ ├── use-mutation.ts
|
|
37
38
|
│ ├── use-number-field.ts
|
|
38
39
|
│ ├── use-scroll-lock.ts
|
|
39
40
|
│ ├── use-shortcuts.ts
|
|
@@ -49,6 +50,7 @@ src/
|
|
|
49
50
|
├── fields.ts
|
|
50
51
|
├── form.ts
|
|
51
52
|
├── get-safe-window.ts
|
|
53
|
+
├── head.ts
|
|
52
54
|
├── noop.ts
|
|
53
55
|
├── number-field.ts
|
|
54
56
|
├── pluralize.ts
|