@okam/next-component 2.0.2 → 2.1.0

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 (39) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/hooks/useLink/interface.d.ts +4 -1
  3. package/{providers/DraftMode/index.mjs → index-Ber8Ecgv.mjs} +2 -3
  4. package/{providers/DraftMode/index.js → index-DV6W6v68.js} +0 -2
  5. package/index.js +590 -18
  6. package/index.mjs +587 -15
  7. package/package.json +3 -4
  8. package/server.js +31 -7
  9. package/server.mjs +30 -6
  10. package/components/AdminBar/index.js +0 -14
  11. package/components/AdminBar/index.mjs +0 -15
  12. package/components/Filter/index.js +0 -54
  13. package/components/Filter/index.mjs +0 -55
  14. package/components/Img/index.js +0 -29
  15. package/components/Img/index.mjs +0 -30
  16. package/components/Link/index.js +0 -39
  17. package/components/Link/index.mjs +0 -40
  18. package/hooks/useFilterState/index.js +0 -50
  19. package/hooks/useFilterState/index.mjs +0 -50
  20. package/hooks/useHash/index.js +0 -25
  21. package/hooks/useHash/index.mjs +0 -25
  22. package/hooks/useLink/index.js +0 -99
  23. package/hooks/useLink/index.mjs +0 -99
  24. package/lib/createServerContext/index.js +0 -12
  25. package/lib/createServerContext/index.mjs +0 -12
  26. package/providers/AdminBar/index.js +0 -17
  27. package/providers/AdminBar/index.mjs +0 -17
  28. package/providers/DraftMode/server.js +0 -10
  29. package/providers/DraftMode/server.mjs +0 -11
  30. package/theme/AdminBar/index.js +0 -120
  31. package/theme/AdminBar/index.mjs +0 -120
  32. package/theme/Button/index.js +0 -75
  33. package/theme/Button/index.mjs +0 -76
  34. package/theme/Filter/index.js +0 -72
  35. package/theme/Filter/index.mjs +0 -73
  36. package/theme/Typography/index.js +0 -43
  37. package/theme/Typography/index.mjs +0 -44
  38. package/theme/index.js +0 -16
  39. package/theme/index.mjs +0 -17
package/index.mjs CHANGED
@@ -1,21 +1,593 @@
1
- import { default as default2 } from "./components/Filter/index.mjs";
2
- import { default as default3 } from "./components/Img/index.mjs";
3
- import { default as default4 } from "./components/Link/index.mjs";
4
- import { useFilterState } from "./hooks/useFilterState/index.mjs";
5
- import { useHash } from "./hooks/useHash/index.mjs";
6
- import { useLink } from "./hooks/useLink/index.mjs";
7
- import { AdminBarContextProvider, useAdminBar } from "./providers/AdminBar/index.mjs";
8
- import { DraftModeContextProvider, useDraftMode } from "./providers/DraftMode/index.mjs";
9
- import { default as default5 } from "./theme/index.mjs";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Box, PopoverButton, TagGroup, useThemeContext, Anchor, createThemeProvider, makeTheme } from "@okam/stack-ui";
3
+ import { parseAsArrayOf, parseAsString, useQueryState } from "nuqs";
4
+ import { isEqual } from "radashi";
5
+ import { useMemo, useState, useRef, useCallback, useEffect, memo } from "react";
6
+ import { useListState } from "react-stately";
7
+ import { useUpdateEffect, useEvent } from "react-use";
8
+ import Image from "next/image";
9
+ import NextLink from "next/link";
10
+ import { usePathname, useSearchParams, useParams } from "next/navigation";
11
+ import { useLocale } from "react-aria";
12
+ import { createCtx } from "@okam/react-utils";
13
+ import { D, u } from "./index-Ber8Ecgv.mjs";
14
+ import { tv } from "tailwind-variants";
15
+ function useFilterState(props) {
16
+ const {
17
+ id,
18
+ defaultSelectedKeys: defaultSelectedKeysProp = [],
19
+ onSelectionChange,
20
+ selectionMode = "multiple",
21
+ parser = parseAsArrayOf(parseAsString),
22
+ children,
23
+ items,
24
+ options,
25
+ ...rest
26
+ } = props;
27
+ const defaultValue = Array.from(defaultSelectedKeysProp).map((key) => key.toString());
28
+ const queryStateOptions = useMemo(
29
+ () => parser.withOptions(options ?? {}).withDefault(defaultValue),
30
+ [parser, options, defaultValue]
31
+ );
32
+ const [selectedKeys, setSelectedKeys] = useQueryState(id, queryStateOptions);
33
+ const onSelectedKeysChange = (keys) => {
34
+ onSelectionChange?.(keys);
35
+ const stringKeys = Array.from(keys).map((key) => key.toString());
36
+ void setSelectedKeys(stringKeys);
37
+ };
38
+ const defaultSelectedKeys = /* @__PURE__ */ new Set([...defaultSelectedKeysProp, ...selectedKeys ?? []]);
39
+ const state = useListState({
40
+ ...rest,
41
+ children,
42
+ items,
43
+ selectionMode,
44
+ defaultSelectedKeys,
45
+ onSelectionChange: onSelectedKeysChange
46
+ });
47
+ useUpdateEffect(() => {
48
+ const next = [...state.selectionManager.selectedKeys].map(String);
49
+ if (isEqual(next, selectedKeys)) {
50
+ return;
51
+ }
52
+ void setSelectedKeys(next);
53
+ }, [state.selectionManager.selectedKeys]);
54
+ return { ...state, onSelectionChange: onSelectedKeysChange, selectedKeys: selectedKeys ?? void 0, defaultSelectedKeys };
55
+ }
56
+ function Filter(props) {
57
+ const {
58
+ // TagGroup-specific props
59
+ children,
60
+ items,
61
+ defaultSelectedKeys,
62
+ selectedKeys,
63
+ selectionBehavior,
64
+ selectionMode = "multiple",
65
+ options,
66
+ description,
67
+ disabledKeys,
68
+ disallowEmptySelection,
69
+ errorMessage,
70
+ onRemove,
71
+ onSelectionChange,
72
+ // Common props
73
+ themeName = "filter",
74
+ tokens,
75
+ customTheme,
76
+ // PopoverButton props with defaults
77
+ type = "dialog",
78
+ placement = "bottom",
79
+ // Remaining PopoverButton props
80
+ ...popoverButtonProps
81
+ } = props;
82
+ const tagGroupProps = {
83
+ items,
84
+ selectionBehavior,
85
+ selectionMode,
86
+ description,
87
+ disallowEmptySelection,
88
+ errorMessage,
89
+ onRemove
90
+ };
91
+ const state = useFilterState({ ...props, selectionMode });
92
+ return /* @__PURE__ */ jsx(Box, { themeName: `${themeName}.wrapper`, tokens, customTheme, children: /* @__PURE__ */ jsx(
93
+ PopoverButton,
94
+ {
95
+ themeName: `${themeName}.popover`,
96
+ tokens,
97
+ type,
98
+ placement,
99
+ ...popoverButtonProps,
100
+ children: /* @__PURE__ */ jsx(TagGroup, { themeName: `${themeName}.tagGroup`, tokens, ...tagGroupProps, ...state, children })
101
+ }
102
+ ) });
103
+ }
104
+ function Img(props) {
105
+ const { src, width, height, themeName = "img", tokens, customTheme, ...rest } = props;
106
+ const theme = useThemeContext(themeName, tokens, customTheme);
107
+ if (typeof src === "object") {
108
+ const { blurWidth, blurHeight, width: srcWidth, height: srcHeight, ...withoutBlurDimensions } = src;
109
+ const blur = {
110
+ blurwidth: blurWidth,
111
+ blurheight: blurHeight
112
+ };
113
+ return /* @__PURE__ */ jsx(
114
+ Image,
115
+ {
116
+ className: theme,
117
+ ...withoutBlurDimensions,
118
+ ...rest,
119
+ ...blur,
120
+ width: srcWidth ?? width,
121
+ height: srcHeight ?? height
122
+ }
123
+ );
124
+ }
125
+ return /* @__PURE__ */ jsx(Image, { width, height, className: theme, src, ...rest });
126
+ }
127
+ function getHash() {
128
+ if (typeof window === "undefined")
129
+ return "";
130
+ return window.location.hash;
131
+ }
132
+ function useHash() {
133
+ const defaultHash = getHash();
134
+ const [hash, setHash] = useState(defaultHash);
135
+ const handleHashChangeEvent = ({ newURL }) => {
136
+ if (!URL.canParse(newURL))
137
+ return;
138
+ const { hash: newHash } = new URL(newURL);
139
+ if (!newHash || newHash === hash)
140
+ return;
141
+ setHash(newHash);
142
+ };
143
+ useEvent("hashchange", handleHashChangeEvent);
144
+ return hash;
145
+ }
146
+ function scrollToTop(behavior) {
147
+ window?.scrollTo?.({ top: 0, behavior });
148
+ }
149
+ function getParamsLocale(params) {
150
+ const { locale } = params ?? {};
151
+ if (Array.isArray(locale))
152
+ return locale[0];
153
+ return locale;
154
+ }
155
+ function useLinkLocale(props) {
156
+ const { locale } = props;
157
+ const params = useParams();
158
+ const paramsLocale = getParamsLocale(params);
159
+ const { locale: ctxLocale } = useLocale();
160
+ return locale ?? ctxLocale ?? paramsLocale ?? false;
161
+ }
162
+ function localizeHref(href, locale) {
163
+ const hrefString = href.toString();
164
+ const isAnchor = hrefString.startsWith("#");
165
+ const isExternal = /^[a-z]+:\/\//i.test(hrefString) || hrefString.startsWith("//");
166
+ if (isExternal || isAnchor)
167
+ return hrefString;
168
+ if (locale != null && locale !== false) {
169
+ return `/${locale}${hrefString}`;
170
+ }
171
+ return hrefString;
172
+ }
173
+ function useLink(props) {
174
+ const {
175
+ scroll = true,
176
+ onMouseEnter,
177
+ onTouchStart,
178
+ onClick,
179
+ onNavigate,
180
+ onPathnameChange,
181
+ onHashChange,
182
+ onSearchParamsChange,
183
+ href,
184
+ urlDecorator,
185
+ replace,
186
+ prefetch,
187
+ shallow,
188
+ passHref,
189
+ legacyBehavior,
190
+ behavior = "instant"
191
+ } = props;
192
+ const locale = useLinkLocale(props);
193
+ const localizedHref = localizeHref(href, locale);
194
+ const pathname = usePathname();
195
+ const searchParams = useSearchParams();
196
+ const hash = useHash();
197
+ const hasWarnedOnPathnameChangeRef = useRef(false);
198
+ const isNextScroll = typeof scroll === "boolean";
199
+ const nextScroll = isNextScroll ? scroll : false;
200
+ const handleScroll = useCallback(() => {
201
+ if (isNextScroll)
202
+ return;
203
+ scrollToTop(behavior);
204
+ }, [behavior, isNextScroll]);
205
+ const handleClick = (event) => {
206
+ onClick?.(event);
207
+ handleScroll();
208
+ };
209
+ const handleTouchStart = (event) => {
210
+ onTouchStart?.(event);
211
+ handleScroll();
212
+ };
213
+ useEffect(() => {
214
+ if (process.env.NODE_ENV === "production" || onPathnameChange == null || hasWarnedOnPathnameChangeRef.current)
215
+ return;
216
+ console.warn("[next-component/Link] `onPathnameChange` is deprecated and will be removed in the next major version. Use `onNavigate` from next/link instead.");
217
+ hasWarnedOnPathnameChangeRef.current = true;
218
+ }, [onPathnameChange]);
219
+ useEffect(() => {
220
+ onPathnameChange?.(pathname);
221
+ }, [onPathnameChange, pathname]);
222
+ useEffect(() => {
223
+ onSearchParamsChange?.(searchParams);
224
+ }, [onSearchParamsChange, searchParams]);
225
+ useEffect(() => {
226
+ onHashChange?.(hash);
227
+ }, [onHashChange, hash]);
228
+ return {
229
+ href: localizedHref.toString(),
230
+ as: urlDecorator,
231
+ replace,
232
+ prefetch,
233
+ shallow,
234
+ onClick: handleClick,
235
+ onNavigate,
236
+ onTouchStart: handleTouchStart,
237
+ onMouseEnter,
238
+ scroll: nextScroll,
239
+ passHref,
240
+ legacyBehavior
241
+ };
242
+ }
243
+ function Link({ ref, ...props }) {
244
+ const {
245
+ themeName = "link",
246
+ tokens,
247
+ customTheme,
248
+ as = NextLink,
249
+ children,
250
+ locale,
251
+ scroll,
252
+ onPathnameChange,
253
+ onSearchParamsChange,
254
+ onHashChange,
255
+ behavior,
256
+ urlDecorator: urlDecoratorProp,
257
+ href: hrefProp,
258
+ ...rest
259
+ } = props;
260
+ const linkProps = useLink(props);
261
+ return /* @__PURE__ */ jsx(
262
+ Anchor,
263
+ {
264
+ ref,
265
+ ...rest,
266
+ nextLinkProps: linkProps,
267
+ as,
268
+ themeName,
269
+ tokens,
270
+ customTheme,
271
+ children
272
+ }
273
+ );
274
+ }
275
+ Link.displayName = "Link";
276
+ const adminBarCtx = createCtx();
277
+ const useAdminBar = adminBarCtx[0];
278
+ const AdminBarProvider = adminBarCtx[1];
279
+ function AdminBarContextProvider(props) {
280
+ const { children } = props;
281
+ const [error, setError] = useState();
282
+ const value = useMemo(() => ({ error, setError }), [error]);
283
+ return /* @__PURE__ */ jsx(AdminBarProvider, { value, children });
284
+ }
285
+ const adminBarContainer = tv({
286
+ base: "w-full bg-gray-100 py-2 px-4 border-gray-200 fixed left-0 right-0 z-50",
287
+ variants: {
288
+ position: {
289
+ top: "top-0 border-b",
290
+ bottom: "bottom-0 border-t"
291
+ },
292
+ fullWidth: {
293
+ true: "max-w-full"
294
+ },
295
+ background: {
296
+ grey: "bg-gray-100",
297
+ dark: "bg-gray-800 text-white",
298
+ light: "bg-white"
299
+ },
300
+ padding: {
301
+ small: "py-1 px-2",
302
+ medium: "py-2 px-4",
303
+ large: "py-3 px-6"
304
+ }
305
+ },
306
+ defaultVariants: {
307
+ position: "top",
308
+ background: "grey",
309
+ padding: "medium"
310
+ }
311
+ });
312
+ const adminBarContent = tv({
313
+ base: "flex items-center",
314
+ variants: {
315
+ justify: {
316
+ start: "justify-start",
317
+ center: "justify-center",
318
+ end: "justify-end",
319
+ between: "justify-between",
320
+ around: "justify-around",
321
+ evenly: "justify-evenly"
322
+ },
323
+ gap: {
324
+ small: "gap-2",
325
+ medium: "gap-4",
326
+ large: "gap-6"
327
+ },
328
+ wrap: {
329
+ true: "flex-wrap",
330
+ false: "flex-nowrap"
331
+ }
332
+ },
333
+ defaultVariants: {
334
+ justify: "between",
335
+ gap: "medium",
336
+ wrap: false
337
+ }
338
+ });
339
+ const adminBarButton = tv({
340
+ base: "px-3 py-1 rounded text-sm font-medium transition-colors",
341
+ variants: {
342
+ variant: {
343
+ primary: "bg-blue-600 text-white hover:bg-blue-700",
344
+ secondary: "bg-gray-200 text-gray-800 hover:bg-gray-300",
345
+ danger: "bg-red-600 text-white hover:bg-red-700"
346
+ },
347
+ size: {
348
+ small: "text-xs px-2 py-0.5",
349
+ medium: "text-sm px-3 py-1",
350
+ large: "text-base px-4 py-2"
351
+ }
352
+ },
353
+ defaultVariants: {
354
+ variant: "secondary",
355
+ size: "medium"
356
+ }
357
+ });
358
+ const adminBarError = tv({
359
+ base: "flex items-center justify-center bg-red-50 text-red-700 px-3 py-1 rounded-md text-sm",
360
+ variants: {
361
+ severity: {
362
+ low: "bg-yellow-50 text-yellow-700",
363
+ medium: "bg-red-50 text-red-700",
364
+ high: "bg-red-100 text-red-800 font-bold"
365
+ },
366
+ hasBorder: {
367
+ true: "border border-red-300",
368
+ false: ""
369
+ }
370
+ },
371
+ defaultVariants: {
372
+ severity: "medium",
373
+ hasBorder: true
374
+ }
375
+ });
376
+ const adminBarErrorTypography = tv({
377
+ base: "text-red-700 text-sm font-medium",
378
+ variants: {
379
+ severity: {
380
+ low: "text-yellow-700",
381
+ medium: "text-red-700",
382
+ high: "text-red-800 font-bold"
383
+ }
384
+ },
385
+ defaultVariants: {
386
+ severity: "medium"
387
+ }
388
+ });
389
+ const adminBarTheme = {
390
+ container: adminBarContainer,
391
+ content: adminBarContent,
392
+ button: adminBarButton,
393
+ error: adminBarError,
394
+ errorTypography: adminBarErrorTypography
395
+ };
396
+ const button = tv({
397
+ base: `
398
+ flex
399
+ items-center
400
+ justify-center
401
+ gap-4
402
+ transition
403
+ duration-300
404
+ ease-in-out
405
+ disabled:pointer-events-none
406
+ disabled:opacity-30
407
+ focus-ring-black
408
+ `,
409
+ defaultVariants: {
410
+ buttonStyle: "default",
411
+ type: "button",
412
+ size: "default",
413
+ shape: "rounded"
414
+ },
415
+ variants: {
416
+ type: {
417
+ button: "",
418
+ menu: "text-2xl"
419
+ },
420
+ buttonStyle: {
421
+ default: `
422
+ px-4
423
+ py-2
424
+ text-white
425
+ !bg-color-1-500
426
+ hover:!bg-color-1-400
427
+ active:!bg-color-1-400
428
+ `,
429
+ outline: `
430
+ px-4
431
+ py-2
432
+ bg-transparent
433
+ !border-color-1-500
434
+ border-2
435
+ text-color-1-500
436
+ hover:bg-color-1-500
437
+ hover:text-white
438
+ active:bg-color-1-500
439
+ active:text-white
440
+ `,
441
+ hollow: `
442
+ px-2
443
+ bg-transparent
444
+ text-color-1-500
445
+ hover:border-b-color-1-500
446
+ active:border-b-color-1-500
447
+ focus:border-b-color-1-500
448
+ `
449
+ },
450
+ intent: {
451
+ error: `
452
+ !bg-error
453
+ text-white
454
+ pointer-events-none
455
+ !border-error
456
+ `
457
+ },
458
+ size: {
459
+ default: `min-w-12 min-h-6`,
460
+ large: `min-w-36 min-h-18`
461
+ },
462
+ shape: {
463
+ rounded: `rounded-md`,
464
+ circular: `rounded-full`
465
+ }
466
+ }
467
+ });
468
+ const typography = tv({
469
+ variants: {
470
+ size: {
471
+ h1: `text-5xl`,
472
+ h2: `text-4xl`,
473
+ h3: `text-3xl`,
474
+ h4: `text-2xl`,
475
+ h5: `text-xl`,
476
+ h6: `text-lg`,
477
+ leading: `text-md font-bold leading-normal`,
478
+ paragraph: `text-md inline`,
479
+ footnotes: `text-sm`,
480
+ xs: `text-xs`
481
+ },
482
+ font: {
483
+ body: `font-body`
484
+ },
485
+ weight: {
486
+ normal: `font-normal`,
487
+ light: `font-light`,
488
+ bold: "font-bold"
489
+ },
490
+ color: {
491
+ gray: `text-gray-500`,
492
+ white: `text-white`
493
+ },
494
+ isError: {
495
+ true: "text-sm text-error py-3"
496
+ },
497
+ align: {
498
+ center: "text-center",
499
+ left: "text-left",
500
+ right: "text-right"
501
+ }
502
+ },
503
+ defaultVariants: {
504
+ size: "paragraph",
505
+ font: "body"
506
+ }
507
+ });
508
+ const filterTagGroupWrapper = tv({
509
+ base: "w-full flex flex-col gap-2"
510
+ });
511
+ const filterTagGroupTags = tv({
512
+ base: "flex flex-col gap-2 max-w-[150px] items-center mx-auto"
513
+ });
514
+ const filterTagGroupLabel = tv({
515
+ extend: typography,
516
+ defaultVariants: { size: "h4" }
517
+ });
518
+ const filterTagGroupDescription = tv({
519
+ extend: typography,
520
+ base: "block",
521
+ defaultVariants: { size: "footnotes" }
522
+ });
523
+ const filterTagGroupErrorMessage = tv({
524
+ extend: typography,
525
+ base: "block",
526
+ defaultVariants: { isError: true }
527
+ });
528
+ const filterTagGroupTagWrapper = tv({
529
+ base: [
530
+ button({ buttonStyle: "outline" }),
531
+ `
532
+ focus-visible:outline
533
+ focus-visible:outline-offset-2
534
+ focus-visible:outline-2
535
+ focus-visible:outline-black
536
+ `
537
+ ],
538
+ variants: {
539
+ isSelected: {
540
+ true: [button({ buttonStyle: "default" })]
541
+ },
542
+ isDisabled: {
543
+ true: "pointer-events-none opacity-30"
544
+ }
545
+ }
546
+ });
547
+ const filterTagGroupTagContainer = tv({
548
+ extend: typography,
549
+ base: "flex items-center justify-center"
550
+ });
551
+ const filterPopoverButton = tv({
552
+ extend: button,
553
+ base: "!min-w-[200px]"
554
+ });
555
+ const filterPopoverPopover = tv({
556
+ base: "w-[var(--filter-popover-container-width)] bg-gray-300 rounded-md p-4"
557
+ });
558
+ const filterTheme = {
559
+ popover: {
560
+ button: filterPopoverButton,
561
+ popover: filterPopoverPopover
562
+ },
563
+ tagGroup: {
564
+ wrapper: filterTagGroupWrapper,
565
+ tags: filterTagGroupTags,
566
+ label: filterTagGroupLabel,
567
+ description: filterTagGroupDescription,
568
+ errorMessage: filterTagGroupErrorMessage,
569
+ tag: {
570
+ wrapper: filterTagGroupTagWrapper,
571
+ container: filterTagGroupTagContainer
572
+ }
573
+ }
574
+ };
575
+ const BaseTheme = makeTheme({
576
+ filter: filterTheme,
577
+ button,
578
+ typography,
579
+ adminBar: adminBarTheme
580
+ });
581
+ const index = memo(createThemeProvider(BaseTheme));
10
582
  export {
11
583
  AdminBarContextProvider,
12
- DraftModeContextProvider,
13
- default2 as Filter,
14
- default3 as Img,
15
- default4 as Link,
16
- default5 as ThemeProvider,
584
+ D as DraftModeContextProvider,
585
+ Filter,
586
+ Img,
587
+ Link,
588
+ index as ThemeProvider,
17
589
  useAdminBar,
18
- useDraftMode,
590
+ u as useDraftMode,
19
591
  useFilterState,
20
592
  useHash,
21
593
  useLink
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okam/next-component",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "repository": {
5
5
  "url": "https://github.com/OKAMca/stack.git"
6
6
  },
@@ -37,15 +37,14 @@
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@react-stately/selection": "^3.20.0",
40
- "next": "^15.1.0 || ^16.0.0",
40
+ "next": ">=15.5.13 <16.0.0 || ^16.1.7",
41
41
  "nuqs": "^2.4.0",
42
42
  "react": "^18.0.0 || ^19.0.0",
43
43
  "react-stately": "^3.43.0"
44
44
  },
45
45
  "dependencies": {
46
46
  "@okam/react-utils": "0.0.1",
47
- "@okam/stack-ui": "2.0.1",
48
- "next": "^15.1.0 || ^16.0.0",
47
+ "@okam/stack-ui": "2.0.3",
49
48
  "nuqs": "^2.4.3",
50
49
  "radashi": "^12.3.0",
51
50
  "react-aria": "^3.39.0",
package/server.js CHANGED
@@ -1,9 +1,33 @@
1
- "use server";
1
+ require("server-only");
2
2
  "use strict";
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const index = require("./components/AdminBar/index.js");
5
- const index$1 = require("./lib/createServerContext/index.js");
6
- const server = require("./providers/DraftMode/server.js");
7
- exports.AdminBar = index;
8
- exports.createServerContext = index$1.createServerContext;
9
- exports.DraftModeServerContextProvider = server;
4
+ const jsxRuntime = require("react/jsx-runtime");
5
+ const stackUi = require("@okam/stack-ui");
6
+ const headers = require("next/headers");
7
+ const react = require("react");
8
+ const index = require("./index-DV6W6v68.js");
9
+ async function AdminBar({
10
+ children,
11
+ themeName = "adminBar",
12
+ tokens,
13
+ customTheme
14
+ }) {
15
+ const { isEnabled } = await headers.draftMode();
16
+ return isEnabled && /* @__PURE__ */ jsxRuntime.jsx(stackUi.Box, { themeName: `${themeName}.container`, tokens, customTheme, children: /* @__PURE__ */ jsxRuntime.jsx(stackUi.Box, { themeName: `${themeName}.content`, tokens, children }) });
17
+ }
18
+ function createServerContext(defaultValue) {
19
+ const getRef = react.cache(() => ({ current: defaultValue }));
20
+ const getValue = () => getRef().current;
21
+ const setValue = (value) => {
22
+ getRef().current = value;
23
+ };
24
+ return [getValue, setValue];
25
+ }
26
+ async function DraftModeServerContextProvider(props) {
27
+ const { children, ...rest } = props;
28
+ const { isEnabled } = await headers.draftMode();
29
+ return /* @__PURE__ */ jsxRuntime.jsx(index.DraftModeContextProvider, { isEnabled, ...rest, children });
30
+ }
31
+ exports.AdminBar = AdminBar;
32
+ exports.DraftModeServerContextProvider = DraftModeServerContextProvider;
33
+ exports.createServerContext = createServerContext;
package/server.mjs CHANGED
@@ -1,9 +1,33 @@
1
- "use server";
2
- import { default as default2 } from "./components/AdminBar/index.mjs";
3
- import { createServerContext } from "./lib/createServerContext/index.mjs";
4
- import { default as default3 } from "./providers/DraftMode/server.mjs";
1
+ import "server-only";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { Box } from "@okam/stack-ui";
4
+ import { draftMode } from "next/headers";
5
+ import { cache } from "react";
6
+ import { D as DraftModeContextProvider } from "./index-Ber8Ecgv.mjs";
7
+ async function AdminBar({
8
+ children,
9
+ themeName = "adminBar",
10
+ tokens,
11
+ customTheme
12
+ }) {
13
+ const { isEnabled } = await draftMode();
14
+ return isEnabled && /* @__PURE__ */ jsx(Box, { themeName: `${themeName}.container`, tokens, customTheme, children: /* @__PURE__ */ jsx(Box, { themeName: `${themeName}.content`, tokens, children }) });
15
+ }
16
+ function createServerContext(defaultValue) {
17
+ const getRef = cache(() => ({ current: defaultValue }));
18
+ const getValue = () => getRef().current;
19
+ const setValue = (value) => {
20
+ getRef().current = value;
21
+ };
22
+ return [getValue, setValue];
23
+ }
24
+ async function DraftModeServerContextProvider(props) {
25
+ const { children, ...rest } = props;
26
+ const { isEnabled } = await draftMode();
27
+ return /* @__PURE__ */ jsx(DraftModeContextProvider, { isEnabled, ...rest, children });
28
+ }
5
29
  export {
6
- default2 as AdminBar,
7
- default3 as DraftModeServerContextProvider,
30
+ AdminBar,
31
+ DraftModeServerContextProvider,
8
32
  createServerContext
9
33
  };