@janbox/storefront-ui 2.0.24 → 2.0.25

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/index.js CHANGED
@@ -81,6 +81,7 @@ import { Select } from "./lib/select/select.js";
81
81
  import { StarRating } from "./lib/star-rating/star-rating.js";
82
82
  import { Step } from "./lib/stepper/step.js";
83
83
  import { Stepper } from "./lib/stepper/stepper.js";
84
+ import { SuspenseQuery } from "./lib/suspense-query/index.js";
84
85
  import { Swiper } from "./lib/swiper/swiper/swiper.js";
85
86
  import { SwiperSlide } from "./lib/swiper/swiper-slide/swiper-slide.js";
86
87
  import { Switch } from "./lib/switch/switch.js";
@@ -226,6 +227,7 @@ export {
226
227
  StarRating,
227
228
  Step,
228
229
  Stepper,
230
+ SuspenseQuery,
229
231
  Swiper,
230
232
  SwiperSlide,
231
233
  Switch,
@@ -59,4 +59,5 @@ export * from './cascader';
59
59
  export * from './primitive';
60
60
  export * from './price-label';
61
61
  export * from './avatar';
62
+ export * from './suspense-query';
62
63
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,k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,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"marquee.d.ts","sourceRoot":"","sources":["../../../../src/lib/marquee/marquee/marquee.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAiD,MAAM,SAAS,CAAC;AAUtF,eAAO,MAAM,OAAO,iCAAkC,YAAY,qDA0FjE,CAAC"}
1
+ {"version":3,"file":"marquee.d.ts","sourceRoot":"","sources":["../../../../src/lib/marquee/marquee/marquee.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAiD,MAAM,SAAS,CAAC;AAWtF,eAAO,MAAM,OAAO,iCAAkC,YAAY,qDAsFjE,CAAC"}
@@ -6,13 +6,13 @@ import useEmblaCarousel from "embla-carousel-react";
6
6
  import { getMarqueeProps } from "./helpers.js";
7
7
  import { MarqueeDataAttributes } from "./types.js";
8
8
  import { HTMLClasses } from "../../../constants/index.js";
9
- import { mediaQuery } from "../../../theme/screens.js";
10
- import "../../../theme/palette.js";
11
9
  import { flattenChildren } from "../../../utils/index.js";
10
+ import { isNumber } from "lodash-es";
12
11
  import { Icon } from "../../icon/icon.js";
12
+ import { Primitive } from "../../primitive/primitive.js";
13
13
  const Marquee = ({ children, ref, ..._props }) => {
14
- const { sx = {}, spaceBetween, sm, md, lg, autoScrollOptions, separatorIcon, ...rest } = getMarqueeProps(_props);
15
- const { sm: sxSm, md: sxMd, lg: sxLg, ...sxXs } = sx;
14
+ var _a, _b, _c;
15
+ const { spaceBetween, sm, md, lg, autoScrollOptions, separatorIcon, ...rest } = getMarqueeProps(_props);
16
16
  const rootEl = useRef(null);
17
17
  const [emblaRef, emblaApi] = useEmblaCarousel(
18
18
  {
@@ -25,8 +25,8 @@ const Marquee = ({ children, ref, ..._props }) => {
25
25
  const mergedRefs = useMergeRefs([emblaRef, ref, rootEl]);
26
26
  useEffect(() => {
27
27
  const mutationObserver = new MutationObserver((records) => {
28
- var _a;
29
- const target = (_a = records.at(0)) == null ? void 0 : _a.target;
28
+ var _a2;
29
+ const target = (_a2 = records.at(0)) == null ? void 0 : _a2.target;
30
30
  if (!target) return;
31
31
  const playState = target.getAttribute(MarqueeDataAttributes.PlayState);
32
32
  const autoScrollPlugin = emblaApi == null ? void 0 : emblaApi.plugins().autoScroll;
@@ -48,12 +48,12 @@ const Marquee = ({ children, ref, ..._props }) => {
48
48
  }, [emblaApi]);
49
49
  useEffect(() => {
50
50
  const onAutoScrollPlay = () => {
51
- var _a;
52
- (_a = rootEl.current) == null ? void 0 : _a.setAttribute(MarqueeDataAttributes.PlayState, "on");
51
+ var _a2;
52
+ (_a2 = rootEl.current) == null ? void 0 : _a2.setAttribute(MarqueeDataAttributes.PlayState, "on");
53
53
  };
54
54
  const onAutoScrollStop = () => {
55
- var _a;
56
- (_a = rootEl.current) == null ? void 0 : _a.setAttribute(MarqueeDataAttributes.PlayState, "off");
55
+ var _a2;
56
+ (_a2 = rootEl.current) == null ? void 0 : _a2.setAttribute(MarqueeDataAttributes.PlayState, "off");
57
57
  };
58
58
  emblaApi == null ? void 0 : emblaApi.on("autoScroll:play", onAutoScrollPlay);
59
59
  emblaApi == null ? void 0 : emblaApi.on("autoScroll:stop", onAutoScrollStop);
@@ -63,41 +63,46 @@ const Marquee = ({ children, ref, ..._props }) => {
63
63
  };
64
64
  }, [emblaApi]);
65
65
  return /* @__PURE__ */ jsx(
66
- "div",
66
+ Primitive,
67
67
  {
68
- css: [
69
- {
70
- overflow: "hidden",
71
- maxWidth: "100%"
72
- },
73
- createStyle({ spaceBetween }, sxXs),
74
- {
75
- [mediaQuery("sm")]: createStyle(sm, sxSm),
76
- [mediaQuery("md")]: createStyle(md, sxMd),
77
- [mediaQuery("lg")]: createStyle(lg, sxLg)
78
- }
79
- ],
80
68
  ...rest,
69
+ sx: {
70
+ overflow: "hidden",
71
+ maxWidth: "100%",
72
+ ...rest.sx,
73
+ ...createStyle({ spaceBetween }),
74
+ sm: { ...(_a = rest.sx) == null ? void 0 : _a.sm, ...createStyle(sm) },
75
+ md: { ...(_b = rest.sx) == null ? void 0 : _b.md, ...createStyle(md) },
76
+ lg: { ...(_c = rest.sx) == null ? void 0 : _c.lg, ...createStyle(lg) }
77
+ },
81
78
  ref: mergedRefs,
82
- children: /* @__PURE__ */ jsx("div", { css: { display: "flex", alignItems: "center", "& > *": { flexShrink: 0, flexGrow: 0, overflow: "hidden" } }, children: flattenChildren(children).map((child, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
83
- /* @__PURE__ */ jsx("div", { className: HTMLClasses.MARQUEE_SLIDE, children: child }),
84
- !!separatorIcon && /* @__PURE__ */ jsx("div", { className: HTMLClasses.MARQUEE_SLIDE, children: /* @__PURE__ */ jsx(Icon, { ...separatorIcon }) })
79
+ children: /* @__PURE__ */ jsx(Primitive, { sx: { display: "flex", alignItems: "center", marginLeft: `calc(var(${SPACING_VAR}, 0px) * -1)` }, children: flattenChildren(children).map((child, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
80
+ /* @__PURE__ */ jsx(MarqueeSlide, { children: child }),
81
+ !!separatorIcon && /* @__PURE__ */ jsx(MarqueeSlide, { children: /* @__PURE__ */ jsx(Icon, { ...separatorIcon }) })
85
82
  ] }, `marquee-item-${index}`)) })
86
83
  }
87
84
  );
88
85
  };
89
- const createStyle = ({ spaceBetween } = {}, sx = {}) => {
90
- const { width, height, ...css } = sx;
91
- return [
86
+ const SPACING_VAR = "--marquee-space-between";
87
+ const MarqueeSlide = ({ children }) => {
88
+ return /* @__PURE__ */ jsx(
89
+ Primitive,
92
90
  {
93
- width,
94
- height,
95
- "& > *": {
96
- columnGap: spaceBetween,
97
- ...css
98
- }
91
+ sx: {
92
+ flexShrink: 0,
93
+ flexGrow: 0,
94
+ overflow: "hidden",
95
+ paddingRight: `var(${SPACING_VAR}, 0px)`
96
+ },
97
+ className: HTMLClasses.MARQUEE_SLIDE,
98
+ children
99
99
  }
100
- ];
100
+ );
101
+ };
102
+ const createStyle = ({ spaceBetween } = {}) => {
103
+ return isNumber(spaceBetween) ? {
104
+ [SPACING_VAR]: `${spaceBetween}px`
105
+ } : {};
101
106
  };
102
107
  export {
103
108
  Marquee
@@ -0,0 +1,14 @@
1
+ import { ComponentType } from 'react';
2
+ import { FallbackProps } from 'react-error-boundary';
3
+ export type SuspenseQueryProps<A extends any[], R> = {
4
+ LoadingComponent?: ComponentType;
5
+ ErrorComponent?: ComponentType<FallbackProps>;
6
+ factory: (...args: A) => Promise<R>;
7
+ children: (data: R) => React.ReactNode;
8
+ } & (A extends [] ? {
9
+ deps?: [];
10
+ } : {
11
+ deps: A;
12
+ });
13
+ export declare function SuspenseQuery<A extends any[], R>({ factory, deps: propDeps, LoadingComponent, ErrorComponent, children, }: SuspenseQueryProps<A, R>): import("react/jsx-runtime").JSX.Element;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/suspense-query/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,OAAO,CAAC;AAG7D,OAAO,EAAiB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEpE,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,IAAI;IACnD,gBAAgB,CAAC,EAAE,aAAa,CAAC;IACjC,cAAc,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IAC9C,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACpC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;CACxC,GAAG,CAAC,CAAC,SAAS,EAAE,GAAG;IAAE,IAAI,CAAC,EAAE,EAAE,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEjD,wBAAgB,aAAa,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,EAChD,OAAO,EACP,IAAI,EAAE,QAAQ,EACd,gBAAgB,EAChB,cAAsC,EACtC,QAAQ,GACT,EAAE,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,2CAmB1B"}
@@ -0,0 +1,32 @@
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { useRef, Suspense, use } from "react";
3
+ import { isEqual } from "lodash-es";
4
+ import { ErrorBoundary } from "/Users/akashi/Work/iChiba/@janbox/storefront-ui/node_modules/.pnpm/react-error-boundary@6.1.2_react@19.2.4/node_modules/react-error-boundary/dist/react-error-boundary.js";
5
+ function SuspenseQuery({
6
+ factory,
7
+ deps: propDeps,
8
+ LoadingComponent,
9
+ ErrorComponent = DefaultErrorComponent,
10
+ children
11
+ }) {
12
+ const deps = propDeps ?? [];
13
+ const depsRef = useRef(deps);
14
+ const promiseRef = useRef(null);
15
+ const depsChanged = !isEqual(deps, depsRef.current);
16
+ if (promiseRef.current === null || depsChanged) {
17
+ depsRef.current = deps;
18
+ promiseRef.current = factory(...deps);
19
+ }
20
+ return /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent: ErrorComponent, children: /* @__PURE__ */ jsx(Suspense, { fallback: LoadingComponent ? /* @__PURE__ */ jsx(LoadingComponent, {}) : null, children: /* @__PURE__ */ jsx(Content, { promise: promiseRef.current, children }) }) });
21
+ }
22
+ function Content({ promise, children }) {
23
+ const data = use(promise);
24
+ return /* @__PURE__ */ jsx(Fragment, { children: children(data) });
25
+ }
26
+ const DefaultErrorComponent = ({ error }) => {
27
+ console.error("SuspenseQueryError", error);
28
+ return /* @__PURE__ */ jsx(Fragment, {});
29
+ };
30
+ export {
31
+ SuspenseQuery
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janbox/storefront-ui",
3
- "version": "2.0.24",
3
+ "version": "2.0.25",
4
4
  "description": "Storefront UI component library for Janbox",
5
5
  "author": "Janbox",
6
6
  "keywords": [