rockin 0.0.39 → 0.0.40

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.
Files changed (165) hide show
  1. package/dist/chunk-4ILCWFOE.js +18 -0
  2. package/dist/chunk-GL2CQ5TR.js +78 -0
  3. package/dist/{chunk-6JS62NO4.js → chunk-ILKXRTV2.js} +2 -2
  4. package/dist/chunk-UZGJXAFX.js +41 -0
  5. package/dist/{chunk-G3RYS466.js → chunk-YA5PSI7E.js} +6 -2
  6. package/dist/hooks/index.d.ts +5 -1
  7. package/dist/hooks/index.js +257 -18
  8. package/dist/index.d.ts +38 -0
  9. package/dist/index.js +2 -2
  10. package/dist/layout.js +2 -5
  11. package/dist/lib/index.d.ts +43 -1
  12. package/dist/lib/index.js +5 -1
  13. package/dist/provider.d.ts +0 -1
  14. package/dist/provider.js +3 -3
  15. package/dist/sdk/accordion.js +1 -0
  16. package/dist/sdk/agent.js +1 -0
  17. package/dist/sdk/alert-dialog.js +1 -0
  18. package/dist/sdk/async-options.js +1 -0
  19. package/dist/sdk/autocomplete.js +1 -0
  20. package/dist/sdk/avatar.js +1 -0
  21. package/dist/sdk/button.js +1 -0
  22. package/dist/sdk/calendar.js +1 -0
  23. package/dist/sdk/carousel.js +1 -0
  24. package/dist/sdk/checkbox.js +1 -0
  25. package/dist/sdk/collapsible.js +1 -0
  26. package/dist/sdk/color-picker.js +1 -0
  27. package/dist/sdk/color.js +1 -0
  28. package/dist/sdk/combobox.js +1 -0
  29. package/dist/sdk/command.js +1 -0
  30. package/dist/sdk/core/accordion.js +1 -0
  31. package/dist/sdk/core/agent.js +1 -0
  32. package/dist/sdk/core/alert-dialog.js +1 -0
  33. package/dist/sdk/core/async-options.js +1 -0
  34. package/dist/sdk/core/autocomplete.js +1 -0
  35. package/dist/sdk/core/avatar.js +1 -0
  36. package/dist/sdk/core/button.js +1 -0
  37. package/dist/sdk/core/calendar.js +1 -0
  38. package/dist/sdk/core/carousel.js +1 -0
  39. package/dist/sdk/core/checkbox.js +1 -0
  40. package/dist/sdk/core/collapsible.js +1 -0
  41. package/dist/sdk/core/color-picker.js +1 -0
  42. package/dist/sdk/core/color.js +1 -0
  43. package/dist/sdk/core/combobox.js +1 -0
  44. package/dist/sdk/core/command.js +1 -0
  45. package/dist/sdk/core/date-input.js +1 -0
  46. package/dist/sdk/core/date-picker.js +1 -0
  47. package/dist/sdk/core/date.js +1 -0
  48. package/dist/sdk/core/dialog.js +1 -0
  49. package/dist/sdk/core/drawer.js +1 -0
  50. package/dist/sdk/core/field.js +1 -0
  51. package/dist/sdk/core/file-input.js +1 -0
  52. package/dist/sdk/core/gesture.js +1 -0
  53. package/dist/sdk/core/history.js +1 -0
  54. package/dist/sdk/core/hover-card.js +1 -0
  55. package/dist/sdk/core/image-cropper.js +1 -0
  56. package/dist/sdk/core/image.js +1 -0
  57. package/dist/sdk/core/input.js +1 -0
  58. package/dist/sdk/core/label.js +1 -0
  59. package/dist/sdk/core/listbox.js +1 -0
  60. package/dist/sdk/core/menu.js +1 -0
  61. package/dist/sdk/core/menubar.js +1 -0
  62. package/dist/sdk/core/meter.js +1 -0
  63. package/dist/sdk/core/navigation-menu.js +1 -0
  64. package/dist/sdk/core/number-input.js +1 -0
  65. package/dist/sdk/core/number.js +1 -0
  66. package/dist/sdk/core/observe.js +1 -0
  67. package/dist/sdk/core/otp-input.js +1 -0
  68. package/dist/sdk/core/overlays.js +1 -0
  69. package/dist/sdk/core/pagination.js +1 -0
  70. package/dist/sdk/core/password-input.js +1 -0
  71. package/dist/sdk/core/popover.js +1 -0
  72. package/dist/sdk/core/progress.js +1 -0
  73. package/dist/sdk/core/radio.js +1 -0
  74. package/dist/sdk/core/rating.js +1 -0
  75. package/dist/sdk/core/renderer.js +1 -0
  76. package/dist/sdk/core/resizable.js +1 -0
  77. package/dist/sdk/core/scroll-area.js +1 -0
  78. package/dist/sdk/core/segmented-control.js +1 -0
  79. package/dist/sdk/core/select.js +1 -0
  80. package/dist/sdk/core/separator.js +1 -0
  81. package/dist/sdk/core/shortcuts.js +1 -0
  82. package/dist/sdk/core/slider.js +1 -0
  83. package/dist/sdk/core/switch.js +1 -0
  84. package/dist/sdk/core/tabs.js +1 -0
  85. package/dist/sdk/core/testing.js +1 -0
  86. package/dist/sdk/core/text-match.js +1 -0
  87. package/dist/sdk/core/time-input.js +1 -0
  88. package/dist/sdk/core/timeline.js +1 -0
  89. package/dist/sdk/core/toast.js +1 -0
  90. package/dist/sdk/core/toggle.js +1 -0
  91. package/dist/sdk/core/token-input.js +1 -0
  92. package/dist/sdk/core/toolbar.js +1 -0
  93. package/dist/sdk/core/tooltip.js +1 -0
  94. package/dist/sdk/core/tree.js +1 -0
  95. package/dist/sdk/core/trigger-menu.js +1 -0
  96. package/dist/sdk/core/waterfall.js +1 -0
  97. package/dist/sdk/core.js +1 -0
  98. package/dist/sdk/date-input.js +1 -0
  99. package/dist/sdk/date-picker.js +1 -0
  100. package/dist/sdk/date.js +1 -0
  101. package/dist/sdk/dialog.js +1 -0
  102. package/dist/sdk/drawer.js +1 -0
  103. package/dist/sdk/field.js +1 -0
  104. package/dist/sdk/file-input.js +1 -0
  105. package/dist/sdk/gesture.js +1 -0
  106. package/dist/sdk/history.js +1 -0
  107. package/dist/sdk/hover-card.js +1 -0
  108. package/dist/sdk/image-cropper.js +1 -0
  109. package/dist/sdk/image.js +1 -0
  110. package/dist/sdk/input.js +1 -0
  111. package/dist/sdk/label.js +1 -0
  112. package/dist/sdk/listbox.js +1 -0
  113. package/dist/sdk/menu.js +1 -0
  114. package/dist/sdk/menubar.js +1 -0
  115. package/dist/sdk/meter.js +1 -0
  116. package/dist/sdk/navigation-menu.js +1 -0
  117. package/dist/sdk/number-input.js +1 -0
  118. package/dist/sdk/number.js +1 -0
  119. package/dist/sdk/observe.js +1 -0
  120. package/dist/sdk/otp-input.js +1 -0
  121. package/dist/sdk/overlays.js +1 -0
  122. package/dist/sdk/pagination.js +1 -0
  123. package/dist/sdk/password-input.js +1 -0
  124. package/dist/sdk/popover.js +1 -0
  125. package/dist/sdk/preferences.js +1 -0
  126. package/dist/sdk/primitive.js +1 -0
  127. package/dist/sdk/progress.js +1 -0
  128. package/dist/sdk/radio.js +1 -0
  129. package/dist/sdk/rating.js +1 -0
  130. package/dist/sdk/resizable.js +1 -0
  131. package/dist/sdk/scroll-area.js +1 -0
  132. package/dist/sdk/segmented-control.js +1 -0
  133. package/dist/sdk/select.js +1 -0
  134. package/dist/sdk/separator.js +1 -0
  135. package/dist/sdk/shortcuts.js +1 -0
  136. package/dist/sdk/slider.js +1 -0
  137. package/dist/sdk/switch.js +1 -0
  138. package/dist/sdk/tabs.js +1 -0
  139. package/dist/sdk/text-match.js +1 -0
  140. package/dist/sdk/textarea.js +1 -0
  141. package/dist/sdk/time-input.js +1 -0
  142. package/dist/sdk/timeline.js +1 -0
  143. package/dist/sdk/toast.js +1 -0
  144. package/dist/sdk/toggle.js +1 -0
  145. package/dist/sdk/token-input.js +1 -0
  146. package/dist/sdk/toolbar.js +1 -0
  147. package/dist/sdk/tooltip.js +1 -0
  148. package/dist/sdk/tree.js +1 -0
  149. package/dist/sdk/trigger-menu.js +1 -0
  150. package/dist/sdk/waterfall.js +1 -0
  151. package/dist/ui/bridge.js +1 -1
  152. package/dist/ui/code-block.js +2 -2
  153. package/dist/ui/drawer-dialog.js +411 -0
  154. package/dist/ui/farmer/div.js +4 -2
  155. package/dist/ui/index.d.ts +61 -1
  156. package/dist/ui/index.js +1 -0
  157. package/dist/ui/sonner.js +2 -2
  158. package/dist/ui/sortable.js +29 -64
  159. package/dist/ui/tabs.js +1 -1
  160. package/dist/ui/theme-switcher.js +3 -3
  161. package/dist/ui/theme-toggle.js +2 -2
  162. package/package.json +5 -4
  163. package/dist/chunk-G233W3IR.js +0 -17
  164. package/dist/chunk-JPOAXESG.js +0 -250
  165. package/dist/chunk-X56ZEDOW.js +0 -46
@@ -1,4 +1,7 @@
1
1
  "use client";
2
+ import {
3
+ useComposedRefs
4
+ } from "../chunk-UZGJXAFX.js";
2
5
 
3
6
  // src/ui/sortable.tsx
4
7
  import { mergeProps } from "@base-ui/react/merge-props";
@@ -29,51 +32,13 @@ import {
29
32
  verticalListSortingStrategy
30
33
  } from "@dnd-kit/sortable";
31
34
  import { CSS } from "@dnd-kit/utilities";
32
- import * as React3 from "react";
35
+ import * as React2 from "react";
33
36
  import * as ReactDOM from "react-dom";
34
37
 
35
38
  // src/hooks/use-isomorphic-layout-effect.ts
36
39
  import * as React from "react";
37
40
  var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
38
41
 
39
- // src/lib/compose-refs.ts
40
- import * as React2 from "react";
41
- function setRef(ref, value) {
42
- if (typeof ref === "function") {
43
- return ref(value);
44
- }
45
- if (ref !== null && ref !== void 0) {
46
- ref.current = value;
47
- }
48
- }
49
- function composeRefs(...refs) {
50
- return (node) => {
51
- let hasCleanup = false;
52
- const cleanups = refs.map((ref) => {
53
- const cleanup = setRef(ref, node);
54
- if (!hasCleanup && typeof cleanup === "function") {
55
- hasCleanup = true;
56
- }
57
- return cleanup;
58
- });
59
- if (hasCleanup) {
60
- return () => {
61
- for (let i = 0; i < cleanups.length; i++) {
62
- const cleanup = cleanups[i];
63
- if (typeof cleanup === "function") {
64
- cleanup();
65
- } else {
66
- setRef(refs[i], null);
67
- }
68
- }
69
- };
70
- }
71
- };
72
- }
73
- function useComposedRefs(...refs) {
74
- return React2.useCallback(composeRefs(...refs), refs);
75
- }
76
-
77
42
  // src/ui/sortable.tsx
78
43
  import { cn } from "cn";
79
44
  import { jsx } from "react/jsx-runtime";
@@ -99,9 +64,9 @@ var CONTENT_NAME = "SortableContent";
99
64
  var ITEM_NAME = "SortableItem";
100
65
  var ITEM_HANDLE_NAME = "SortableItemHandle";
101
66
  var OVERLAY_NAME = "SortableOverlay";
102
- var SortableRootContext = React3.createContext(null);
67
+ var SortableRootContext = React2.createContext(null);
103
68
  function useSortableContext(consumerName) {
104
- const context = React3.useContext(SortableRootContext);
69
+ const context = React2.useContext(SortableRootContext);
105
70
  if (!context) {
106
71
  throw new Error(`\`${consumerName}\` must be used within \`${ROOT_NAME}\``);
107
72
  }
@@ -121,8 +86,8 @@ function Sortable(props) {
121
86
  accessibility,
122
87
  ...sortableProps
123
88
  } = props;
124
- const id = React3.useId();
125
- const [activeId, setActiveId] = React3.useState(null);
89
+ const id = React2.useId();
90
+ const [activeId, setActiveId] = React2.useState(null);
126
91
  const sensors = useSensors(
127
92
  useSensor(MouseSensor),
128
93
  useSensor(TouchSensor),
@@ -130,11 +95,11 @@ function Sortable(props) {
130
95
  coordinateGetter: sortableKeyboardCoordinates
131
96
  })
132
97
  );
133
- const config = React3.useMemo(
98
+ const config = React2.useMemo(
134
99
  () => orientationConfig[orientation],
135
100
  [orientation]
136
101
  );
137
- const getItemValue = React3.useCallback(
102
+ const getItemValue = React2.useCallback(
138
103
  (item) => {
139
104
  if (typeof item === "object" && !getItemValueProp) {
140
105
  throw new Error(
@@ -145,10 +110,10 @@ function Sortable(props) {
145
110
  },
146
111
  [getItemValueProp]
147
112
  );
148
- const items = React3.useMemo(() => {
113
+ const items = React2.useMemo(() => {
149
114
  return value.map((item) => getItemValue(item));
150
115
  }, [value, getItemValue]);
151
- const onDragStart = React3.useCallback(
116
+ const onDragStart = React2.useCallback(
152
117
  (event) => {
153
118
  sortableProps.onDragStart?.(event);
154
119
  if (event.activatorEvent.defaultPrevented) return;
@@ -156,7 +121,7 @@ function Sortable(props) {
156
121
  },
157
122
  [sortableProps.onDragStart]
158
123
  );
159
- const onDragEnd = React3.useCallback(
124
+ const onDragEnd = React2.useCallback(
160
125
  (event) => {
161
126
  sortableProps.onDragEnd?.(event);
162
127
  if (event.activatorEvent.defaultPrevented) return;
@@ -178,7 +143,7 @@ function Sortable(props) {
178
143
  },
179
144
  [value, onValueChange, onMove, getItemValue, sortableProps.onDragEnd]
180
145
  );
181
- const onDragCancel = React3.useCallback(
146
+ const onDragCancel = React2.useCallback(
182
147
  (event) => {
183
148
  sortableProps.onDragCancel?.(event);
184
149
  if (event.activatorEvent.defaultPrevented) return;
@@ -186,7 +151,7 @@ function Sortable(props) {
186
151
  },
187
152
  [sortableProps.onDragCancel]
188
153
  );
189
- const announcements = React3.useMemo(
154
+ const announcements = React2.useMemo(
190
155
  () => ({
191
156
  onDragStart({ active }) {
192
157
  const activeValue = active.id.toString();
@@ -228,7 +193,7 @@ function Sortable(props) {
228
193
  }),
229
194
  [value]
230
195
  );
231
- const screenReaderInstructions = React3.useMemo(
196
+ const screenReaderInstructions = React2.useMemo(
232
197
  () => ({
233
198
  draggable: `
234
199
  To pick up a sortable item, press space or enter.
@@ -238,7 +203,7 @@ function Sortable(props) {
238
203
  }),
239
204
  [orientation]
240
205
  );
241
- const contextValue = React3.useMemo(
206
+ const contextValue = React2.useMemo(
242
207
  () => ({
243
208
  id,
244
209
  items,
@@ -286,7 +251,7 @@ function Sortable(props) {
286
251
  }
287
252
  );
288
253
  }
289
- var SortableContentContext = React3.createContext(false);
254
+ var SortableContentContext = React2.createContext(false);
290
255
  function SortableContent(props) {
291
256
  const {
292
257
  strategy: strategyProp,
@@ -323,9 +288,9 @@ function SortableContent(props) {
323
288
  }
324
289
  ) });
325
290
  }
326
- var SortableItemContext = React3.createContext(null);
291
+ var SortableItemContext = React2.createContext(null);
327
292
  function useSortableItemContext(consumerName) {
328
- const context = React3.useContext(SortableItemContext);
293
+ const context = React2.useContext(SortableItemContext);
329
294
  if (!context) {
330
295
  throw new Error(`\`${consumerName}\` must be used within \`${ITEM_NAME}\``);
331
296
  }
@@ -342,8 +307,8 @@ function SortableItem(props) {
342
307
  ref,
343
308
  ...itemProps
344
309
  } = props;
345
- const inSortableContent = React3.useContext(SortableContentContext);
346
- const inSortableOverlay = React3.useContext(SortableOverlayContext);
310
+ const inSortableContent = React2.useContext(SortableContentContext);
311
+ const inSortableOverlay = React2.useContext(SortableOverlayContext);
347
312
  if (!inSortableContent && !inSortableOverlay) {
348
313
  throw new Error(
349
314
  `\`${ITEM_NAME}\` must be used within \`${CONTENT_NAME}\` or \`${OVERLAY_NAME}\``
@@ -353,7 +318,7 @@ function SortableItem(props) {
353
318
  throw new Error(`\`${ITEM_NAME}\` value cannot be an empty string`);
354
319
  }
355
320
  const context = useSortableContext(ITEM_NAME);
356
- const id = React3.useId();
321
+ const id = React2.useId();
357
322
  const {
358
323
  attributes,
359
324
  listeners,
@@ -363,7 +328,7 @@ function SortableItem(props) {
363
328
  transition,
364
329
  isDragging
365
330
  } = useSortable({ id: value, disabled });
366
- const onNodeRefChange = React3.useCallback(
331
+ const onNodeRefChange = React2.useCallback(
367
332
  (node) => {
368
333
  if (disabled) return;
369
334
  setNodeRef(node);
@@ -372,14 +337,14 @@ function SortableItem(props) {
372
337
  [disabled, asHandle, setNodeRef, setActivatorNodeRef]
373
338
  );
374
339
  const composedRef = useComposedRefs(ref, onNodeRefChange);
375
- const composedStyle = React3.useMemo(() => {
340
+ const composedStyle = React2.useMemo(() => {
376
341
  return {
377
342
  transform: CSS.Translate.toString(transform),
378
343
  transition,
379
344
  ...style
380
345
  };
381
346
  }, [transform, transition, style]);
382
- const itemContext = React3.useMemo(
347
+ const itemContext = React2.useMemo(
383
348
  () => ({
384
349
  id,
385
350
  attributes,
@@ -429,7 +394,7 @@ function SortableItemHandle(props) {
429
394
  const itemContext = useSortableItemContext(ITEM_HANDLE_NAME);
430
395
  const isDisabled = disabled ?? itemContext.disabled;
431
396
  const { setActivatorNodeRef } = itemContext;
432
- const onActivatorNodeRef = React3.useCallback(
397
+ const onActivatorNodeRef = React2.useCallback(
433
398
  (node) => {
434
399
  if (isDisabled) return;
435
400
  setActivatorNodeRef(node);
@@ -463,7 +428,7 @@ function SortableItemHandle(props) {
463
428
  }
464
429
  });
465
430
  }
466
- var SortableOverlayContext = React3.createContext(false);
431
+ var SortableOverlayContext = React2.createContext(false);
467
432
  var dropAnimation = {
468
433
  sideEffects: defaultDropAnimationSideEffects({
469
434
  styles: {
@@ -476,7 +441,7 @@ var dropAnimation = {
476
441
  function SortableOverlay(props) {
477
442
  const { container: containerProp, children, ...overlayProps } = props;
478
443
  const context = useSortableContext(OVERLAY_NAME);
479
- const [mounted, setMounted] = React3.useState(false);
444
+ const [mounted, setMounted] = React2.useState(false);
480
445
  useIsomorphicLayoutEffect(() => setMounted(true), []);
481
446
  const container = containerProp ?? (mounted ? globalThis.document?.body : null);
482
447
  if (!container) return null;
package/dist/ui/tabs.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  TabsTab,
8
8
  createTabsController,
9
9
  tabsVariants
10
- } from "../chunk-6JS62NO4.js";
10
+ } from "../chunk-ILKXRTV2.js";
11
11
  export {
12
12
  Tabs,
13
13
  TabsIcon,
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  Tabs
4
- } from "../chunk-6JS62NO4.js";
4
+ } from "../chunk-ILKXRTV2.js";
5
5
  import {
6
6
  useTheme
7
- } from "../chunk-G3RYS466.js";
8
- import "../chunk-X56ZEDOW.js";
7
+ } from "../chunk-YA5PSI7E.js";
8
+ import "../chunk-GL2CQ5TR.js";
9
9
 
10
10
  // src/ui/theme-switcher.tsx
11
11
  import { Display, Moon, Sun } from "@gravity-ui/icons";
@@ -4,8 +4,8 @@ import {
4
4
  } from "../chunk-DVNTJNDP.js";
5
5
  import {
6
6
  useTheme
7
- } from "../chunk-G3RYS466.js";
8
- import "../chunk-X56ZEDOW.js";
7
+ } from "../chunk-YA5PSI7E.js";
8
+ import "../chunk-GL2CQ5TR.js";
9
9
 
10
10
  // src/ui/theme-toggle.tsx
11
11
  import { cn } from "cn";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rockin",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "description": "Reusable React UI components, hooks, icons, utilities, and styles for Rock Star projects.",
5
5
  "keywords": [
6
6
  "react",
@@ -90,6 +90,10 @@
90
90
  "types": "./dist/utils/parms-client.d.ts",
91
91
  "import": "./dist/utils/parms-client.js"
92
92
  },
93
+ "./sdk/*": {
94
+ "types": "./dist/sdk/*.d.ts",
95
+ "import": "./dist/sdk/*.js"
96
+ },
93
97
  "./styles.css": "./dist/styles.css",
94
98
  "./package.json": "./package.json"
95
99
  },
@@ -165,9 +169,6 @@
165
169
  "devDependencies": {
166
170
  "@types/node": "^20.19.43",
167
171
  "@types/qrcode": "^1.5.6",
168
- "@types/react": "^19",
169
- "@types/react-dom": "^19",
170
- "next": "^16.0.0",
171
172
  "prettier": "^3.8.3",
172
173
  "prettier-plugin-tailwindcss": "^0.8.0",
173
174
  "tsup": "^8.5.0",
@@ -1,17 +0,0 @@
1
- // src/hooks/useMediaQuery.ts
2
- import { useEffect, useState } from "react";
3
- function useMediaQuery(query) {
4
- const [matches, setMatches] = useState(false);
5
- useEffect(() => {
6
- const mediaQuery = window.matchMedia(query);
7
- const handleChange = () => setMatches(mediaQuery.matches);
8
- handleChange();
9
- mediaQuery.addEventListener("change", handleChange);
10
- return () => mediaQuery.removeEventListener("change", handleChange);
11
- }, [query]);
12
- return matches;
13
- }
14
-
15
- export {
16
- useMediaQuery
17
- };
@@ -1,250 +0,0 @@
1
- import {
2
- buildFlagSearchParamHref,
3
- hasFlagSearchParam,
4
- searchParamKeys,
5
- searchParams
6
- } from "./chunk-M5NHRP6W.js";
7
-
8
- // src/hooks/useSearchParams.ts
9
- import {
10
- useSearchParams as useNextSearchParams,
11
- usePathname,
12
- useRouter
13
- } from "next/navigation";
14
- import {
15
- debounce,
16
- useQueryStates
17
- } from "nuqs";
18
- import { NuqsAdapter } from "nuqs/adapters/next/app";
19
- import * as React from "react";
20
- var SEARCH_DELAY = 300;
21
- var QUERY_SEARCH_DELAY = 300;
22
- function isSearchPath(pathname) {
23
- return pathname === "/" || pathname === "/pos" || pathname === "/orders" || pathname === "/bin" || pathname.startsWith("/pos/") || pathname.startsWith("/orders/") || pathname.startsWith("/bin/");
24
- }
25
- var pendingSearchFocus = false;
26
- function searchFocus() {
27
- if (!pendingSearchFocus) return false;
28
- pendingSearchFocus = false;
29
- return true;
30
- }
31
- function searchHref(query) {
32
- const params = new URLSearchParams();
33
- if (query) params.set(searchParamKeys.query, query);
34
- const search = params.toString();
35
- return search ? `/?${search}` : "/";
36
- }
37
- function useSearchParams() {
38
- const pathname = usePathname();
39
- const router = useRouter();
40
- const nativeSearchParams = useNextSearchParams();
41
- const [isPending, startTransition] = React.useTransition();
42
- const [params, setParams] = useQueryStates(searchParams, {
43
- urlKeys: searchParamKeys,
44
- history: "replace",
45
- shallow: false,
46
- scroll: false,
47
- startTransition
48
- });
49
- const productQueryRef = React.useRef(params.query);
50
- const productNavigationQueuedRef = React.useRef(false);
51
- const onSearchPath = isSearchPath(pathname);
52
- const cart = hasFlagSearchParam(nativeSearchParams, "cart");
53
- const notification = hasFlagSearchParam(nativeSearchParams, "notification");
54
- const updateParams = React.useCallback(
55
- (values, options) => {
56
- void setParams(values, options);
57
- },
58
- [setParams]
59
- );
60
- const setQuery = React.useCallback(
61
- (value) => {
62
- const update = setParams(
63
- { query: value, page: 1 },
64
- {
65
- history: "replace",
66
- scroll: false,
67
- shallow: !onSearchPath,
68
- limitUrlUpdates: debounce(QUERY_SEARCH_DELAY)
69
- }
70
- );
71
- if (onSearchPath) return;
72
- productQueryRef.current = value;
73
- if (productNavigationQueuedRef.current) return;
74
- productNavigationQueuedRef.current = true;
75
- void update.then(() => {
76
- productNavigationQueuedRef.current = false;
77
- const query = productQueryRef.current.trim();
78
- if (!query) return;
79
- pendingSearchFocus = true;
80
- router.push(searchHref(query), { scroll: true });
81
- });
82
- },
83
- [onSearchPath, router, setParams]
84
- );
85
- const commitQuery = React.useCallback(() => {
86
- const query = params.query.trim();
87
- if (!query || onSearchPath) return;
88
- pendingSearchFocus = true;
89
- router.push(searchHref(query), { scroll: true });
90
- }, [onSearchPath, params.query, router]);
91
- const setCategory = React.useCallback(
92
- (value) => {
93
- updateParams(
94
- { category: value, page: 1 },
95
- { history: "push", shallow: false, scroll: true }
96
- );
97
- },
98
- [updateParams]
99
- );
100
- const setProductStatus = React.useCallback(
101
- (value) => {
102
- updateParams(
103
- { productStatus: value, page: 1 },
104
- { history: "push", shallow: false, scroll: true }
105
- );
106
- },
107
- [updateParams]
108
- );
109
- const setUser = React.useCallback(
110
- (value) => {
111
- updateParams(
112
- { user: value },
113
- {
114
- history: "replace",
115
- shallow: false,
116
- scroll: false,
117
- limitUrlUpdates: debounce(SEARCH_DELAY)
118
- }
119
- );
120
- },
121
- [updateParams]
122
- );
123
- const setPage = React.useCallback(
124
- (value) => {
125
- updateParams(
126
- { page: value },
127
- { history: "replace", shallow: true, scroll: false }
128
- );
129
- },
130
- [updateParams]
131
- );
132
- const setUserTransaction = React.useCallback(
133
- (value) => {
134
- updateParams(
135
- { user: value, transaction: "", transactionPage: 1 },
136
- { history: "replace", shallow: false, scroll: false }
137
- );
138
- },
139
- [updateParams]
140
- );
141
- const setTransactionDetail = React.useCallback(
142
- (value) => {
143
- updateParams(
144
- { transaction: value },
145
- { history: "replace", shallow: false, scroll: false }
146
- );
147
- },
148
- [updateParams]
149
- );
150
- const clearTransactionDetail = React.useCallback(() => {
151
- updateParams(
152
- { transaction: "" },
153
- { history: "replace", shallow: false, scroll: false }
154
- );
155
- }, [updateParams]);
156
- const clearUserTransaction = React.useCallback(() => {
157
- updateParams(
158
- { user: "", transaction: "", transactionPage: 1 },
159
- { history: "replace", shallow: false, scroll: false }
160
- );
161
- }, [updateParams]);
162
- const clearAll = React.useCallback(() => {
163
- updateParams(
164
- {
165
- query: "",
166
- category: "",
167
- productStatus: "active",
168
- user: "",
169
- transaction: "",
170
- page: 1,
171
- transactionPage: 1
172
- },
173
- {
174
- history: "replace",
175
- shallow: false,
176
- scroll: true
177
- }
178
- );
179
- }, [updateParams]);
180
- const setCart = React.useCallback(
181
- (value) => {
182
- window.history.replaceState(
183
- null,
184
- "",
185
- buildFlagSearchParamHref(pathname, nativeSearchParams, "cart", value)
186
- );
187
- },
188
- [nativeSearchParams, pathname]
189
- );
190
- const toggleCart = React.useCallback(() => {
191
- setCart(!cart);
192
- }, [cart, setCart]);
193
- const setNotification = React.useCallback(
194
- (value) => {
195
- window.history.replaceState(
196
- null,
197
- "",
198
- buildFlagSearchParamHref(
199
- pathname,
200
- nativeSearchParams,
201
- "notification",
202
- value
203
- )
204
- );
205
- },
206
- [nativeSearchParams, pathname]
207
- );
208
- return {
209
- ...params,
210
- cart,
211
- setCart,
212
- openCart: () => setCart(true),
213
- closeCart: () => setCart(false),
214
- toggleCart,
215
- notification,
216
- setNotification,
217
- openNotification: () => setNotification(true),
218
- closeNotification: () => setNotification(false),
219
- toggleNotification: () => setNotification(!notification),
220
- setQuery,
221
- setCategory,
222
- setProductStatus,
223
- setUser,
224
- setPage,
225
- setUserTransaction,
226
- setTransactionDetail,
227
- commitQuery,
228
- clearQuery: () => setQuery(""),
229
- clearCategory: () => setCategory(""),
230
- clearProductStatus: () => setProductStatus("active"),
231
- clearUser: () => setUser(""),
232
- clearTransactionDetail,
233
- clearUserTransaction,
234
- clearPage: () => setPage(1),
235
- clearAll,
236
- isQueryPending: isPending,
237
- isCategoryPending: isPending,
238
- isUserPending: isPending,
239
- setTab: (value) => updateParams(
240
- { tab: value },
241
- { history: "replace", shallow: false, scroll: false }
242
- )
243
- };
244
- }
245
-
246
- export {
247
- NuqsAdapter,
248
- searchFocus,
249
- useSearchParams
250
- };
@@ -1,46 +0,0 @@
1
- // src/lib/preferences.ts
2
- import {
3
- createColorScheme,
4
- createCookieStorage,
5
- createPreference
6
- } from "@ui-sdk/core";
7
- var ACCENTS = ["slate", "violet", "mint", "gold"];
8
- var PREFERENCE_COOKIES = {
9
- colorScheme: "color-scheme",
10
- accent: "accent"
11
- };
12
- function createAppPreferences(cookie) {
13
- return {
14
- colorScheme: createColorScheme({
15
- global: true,
16
- storage: createCookieStorage(PREFERENCE_COOKIES.colorScheme, { cookie })
17
- }),
18
- accent: createPreference({
19
- values: ACCENTS,
20
- defaultValue: "slate",
21
- attribute: "data-accent",
22
- global: true,
23
- storage: createCookieStorage(PREFERENCE_COOKIES.accent, { cookie })
24
- })
25
- };
26
- }
27
- function preferenceAttributes(cookie) {
28
- const { colorScheme, accent } = createAppPreferences(cookie);
29
- return {
30
- [colorScheme.attribute]: colorScheme.initialState.value,
31
- [accent.attribute]: accent.initialState.value
32
- };
33
- }
34
- function preferencesScript(cookie) {
35
- return `(()=>{const r=document.documentElement;for(const[k,v]of Object.entries(${JSON.stringify(
36
- preferenceAttributes(cookie)
37
- )}))r.setAttribute(k,v)})()`;
38
- }
39
-
40
- export {
41
- ACCENTS,
42
- PREFERENCE_COOKIES,
43
- createAppPreferences,
44
- preferenceAttributes,
45
- preferencesScript
46
- };