@admin-layout/tailwind-ui 12.2.5-alpha.6 → 12.2.5-alpha.9

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.
@@ -1,4 +1,4 @@
1
- import {jsx}from'react/jsx-runtime';import {createContext,useState,useEffect,useMemo}from'react';import'../../hooks/useToast.js';import {useMediaQuery}from'../../hooks/useMediaQuery.js';const themes = [{
1
+ import {jsx}from'react/jsx-runtime';import {createContext,useState,useEffect,useMemo}from'react';import {useMediaQuery}from'../../hooks/useMediaQuery.js';import'../../hooks/useToast.js';const themes = [{
2
2
  value: 'default',
3
3
  label: 'Default',
4
4
  description: 'Clean and minimal design'
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useMediaQuery.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMediaQuery.test.d.ts","sourceRoot":"","sources":["../../../src/hooks/__tests__/useMediaQuery.test.tsx"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- interface MediaQueryResult {
1
+ export interface MediaQueryResult {
2
2
  width: number;
3
3
  height: number;
4
4
  isMobile: boolean;
@@ -9,6 +9,13 @@ interface MediaQueryResult {
9
9
  xl: boolean;
10
10
  '2xl': boolean;
11
11
  }
12
+ /**
13
+ * Viewport size and Tailwind breakpoint flags.
14
+ *
15
+ * Hydration-safe: while hydrating, React renders the server snapshot (desktop) so the
16
+ * markup matches what the server sent, then re-renders with the real viewport. Reading
17
+ * `window` in the first render instead made every phone-width load throw React #418 and
18
+ * discard the server HTML. Client-only mounts get the real viewport straight away.
19
+ */
12
20
  export declare const useMediaQuery: () => MediaQueryResult;
13
- export {};
14
21
  //# sourceMappingURL=useMediaQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMediaQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useMediaQuery.ts"],"names":[],"mappings":"AAEA,UAAU,gBAAgB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;CAClB;AAoBD,eAAO,MAAM,aAAa,QAAO,gBAyChC,CAAC"}
1
+ {"version":3,"file":"useMediaQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useMediaQuery.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;CAClB;AAoDD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,QAAO,gBAAmF,CAAC"}
@@ -1,4 +1,4 @@
1
- import {useState,useEffect}from'react';const breakpoints = {
1
+ import {useSyncExternalStore}from'react';const breakpoints = {
2
2
  sm: 640,
3
3
  md: 768,
4
4
  lg: 1024,
@@ -13,36 +13,44 @@ const getFlags = width => ({
13
13
  xl: width >= breakpoints.xl && width < breakpoints['2xl'],
14
14
  '2xl': width >= breakpoints['2xl']
15
15
  });
16
- const useMediaQuery = () => {
17
- const getDimensions = () => {
18
- const width = window.innerWidth;
19
- const height = window.innerHeight;
20
- const isMobile = width < breakpoints.md;
21
- const flags = getFlags(width);
22
- return {
16
+ /** The server cannot see the viewport, so it always renders the desktop layout. */
17
+ const SERVER_SNAPSHOT = Object.freeze({
18
+ width: 0,
19
+ height: 0,
20
+ isMobile: false,
21
+ xs: false,
22
+ sm: false,
23
+ md: false,
24
+ lg: false,
25
+ xl: false,
26
+ '2xl': false
27
+ });
28
+ // One cached snapshot per viewport size: useSyncExternalStore needs a stable value between changes.
29
+ let snapshot = null;
30
+ const getSnapshot = () => {
31
+ const width = window.innerWidth;
32
+ const height = window.innerHeight;
33
+ if (!snapshot || snapshot.width !== width || snapshot.height !== height) {
34
+ snapshot = {
23
35
  width,
24
36
  height,
25
- isMobile,
26
- ...flags
27
- };
28
- };
29
- const [state, setState] = useState(() => typeof window !== 'undefined' ? getDimensions() : {
30
- width: 0,
31
- height: 0,
32
- isMobile: false,
33
- xs: false,
34
- sm: false,
35
- md: false,
36
- lg: false,
37
- xl: false,
38
- '2xl': false
39
- });
40
- useEffect(() => {
41
- const handleResize = () => {
42
- setState(getDimensions());
37
+ isMobile: width < breakpoints.md,
38
+ ...getFlags(width)
43
39
  };
44
- window.addEventListener('resize', handleResize);
45
- return () => window.removeEventListener('resize', handleResize);
46
- }, []);
47
- return state;
48
- };export{useMediaQuery};//# sourceMappingURL=useMediaQuery.js.map
40
+ }
41
+ return snapshot;
42
+ };
43
+ const getServerSnapshot = () => SERVER_SNAPSHOT;
44
+ const subscribe = onChange => {
45
+ window.addEventListener('resize', onChange);
46
+ return () => window.removeEventListener('resize', onChange);
47
+ };
48
+ /**
49
+ * Viewport size and Tailwind breakpoint flags.
50
+ *
51
+ * Hydration-safe: while hydrating, React renders the server snapshot (desktop) so the
52
+ * markup matches what the server sent, then re-renders with the real viewport. Reading
53
+ * `window` in the first render instead made every phone-width load throw React #418 and
54
+ * discard the server HTML. Client-only mounts get the real viewport straight away.
55
+ */
56
+ const useMediaQuery = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);export{useMediaQuery};//# sourceMappingURL=useMediaQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMediaQuery.js","sources":["../../src/hooks/useMediaQuery.ts"],"sourcesContent":[null],"names":[],"mappings":"6CAGI,WAAa,GAAC;IAEd,EAAA,GAAA;IACA,EAAE;IACF,EAAE;IACF,EAAE;OACA;;MAEF,gBAAe,KAAA;AAClB,EAAA,EAAA,EAAA,KAAA,GAAA,WAAA,CAAA,EAAA;AAoBD,EAAA,EAAA,EAAA,KAAA,IAAO,WAAM,CAAA,EAAA,IAAA,KAAa,GAAA,WAAO,CAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useMediaQuery.js","sources":["../../src/hooks/useMediaQuery.ts"],"sourcesContent":[null],"names":[],"mappings":"+CAGI,WAAa,GAAC;IAEd,EAAA,GAAA;IACA,EAAE;IACF,EAAE;IACF,EAAE;OACA;;MAEF,gBAAe,KAAA;AAClB,EAAA,EAAA,EAAA,KAAA,GAAA,WAAA,CAAA,EAAA;AAoDD,EAAA,EAAA,EAAA,KAAA,IAAA,WAAA,CAAA,EAAA,IAAA,KAAA,GAAA,WAAA,CAAA,EAAA;;;;;;;AAOG,MAAA,eAAA,GAAA,MAAA,CAAA,MAAA,CAAA;AACH,EAAA,KAAA,EAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Viewport width and height - 0 x 0 on the server and while hydrating (see useMediaQuery),
3
+ * the real size after that. The object only changes when the size does.
4
+ */
1
5
  export declare function useWindowSize(): {
2
6
  width: number;
3
7
  height: number;
@@ -1 +1 @@
1
- {"version":3,"file":"useWindowSize.d.ts","sourceRoot":"","sources":["../../src/hooks/useWindowSize.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa;;;EAsB5B"}
1
+ {"version":3,"file":"useWindowSize.d.ts","sourceRoot":"","sources":["../../src/hooks/useWindowSize.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,aAAa;;;EAG5B"}
@@ -1,20 +1,14 @@
1
- import {useState,useEffect}from'react';function useWindowSize() {
2
- const [windowSize, setWindowSize] = useState({
3
- width: typeof window !== 'undefined' ? window.innerWidth : 0,
4
- // Check if window is defined
5
- height: typeof window !== 'undefined' ? window.innerHeight : 0 // Check if window is defined
6
- });
7
- useEffect(() => {
8
- function handleResize() {
9
- setWindowSize({
10
- width: window.innerWidth,
11
- height: window.innerHeight
12
- });
13
- }
14
- // Add event listener for window resize
15
- window.addEventListener('resize', handleResize);
16
- // Cleanup the event listener on component unmount
17
- return () => window.removeEventListener('resize', handleResize);
18
- }, []);
19
- return windowSize;
1
+ import {useMemo}from'react';import {useMediaQuery}from'./useMediaQuery.js';/**
2
+ * Viewport width and height - 0 x 0 on the server and while hydrating (see useMediaQuery),
3
+ * the real size after that. The object only changes when the size does.
4
+ */
5
+ function useWindowSize() {
6
+ const {
7
+ width,
8
+ height
9
+ } = useMediaQuery();
10
+ return useMemo(() => ({
11
+ width,
12
+ height
13
+ }), [width, height]);
20
14
  }export{useWindowSize};//# sourceMappingURL=useWindowSize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWindowSize.js","sources":["../../src/hooks/useWindowSize.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAwBC,IAAA,KAAA,EAAA,OAAA,MAAA,KAAA,WAAA,GAAA,MAAA,CAAA,UAAA,GAAA,CAAA;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useWindowSize.js","sources":["../../src/hooks/useWindowSize.ts"],"sourcesContent":[null],"names":[],"mappings":";AAMG;AACH;;;AAGC,EAAA,MAAA;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@admin-layout/tailwind-ui",
3
- "version": "12.2.5-alpha.6",
3
+ "version": "12.2.5-alpha.9",
4
4
  "description": "Sample core for higher packages to depend on",
5
5
  "license": "ISC",
6
6
  "author": "CDMBase LLC",
@@ -30,7 +30,7 @@
30
30
  "watch": "npm run build:lib:watch"
31
31
  },
32
32
  "dependencies": {
33
- "@admin-layout/client": "12.2.5-alpha.6",
33
+ "@admin-layout/client": "12.2.5-alpha.7",
34
34
  "@radix-ui/react-accordion": "^1.2.0",
35
35
  "@radix-ui/react-alert-dialog": "^1.1.1",
36
36
  "@radix-ui/react-aspect-ratio": "^1.1.0",
@@ -111,5 +111,5 @@
111
111
  "typescript": {
112
112
  "definition": "lib/index.d.ts"
113
113
  },
114
- "gitHead": "39fe142eb31f78df53a5de2963fcae009d3c9fbd"
114
+ "gitHead": "5137d74583f34c57b179f61d76cf1fe5f90efb03"
115
115
  }