@soppiya/app-bridge 1.0.0 → 1.0.4

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,2 +1,3 @@
1
1
  export { Media } from "./media";
2
2
  export { SaveBar } from "./savebar";
3
+ export { VariantsPicker } from "./variants-picker";
@@ -1,3 +1,4 @@
1
1
  import { Media } from "./media/index.js";
2
2
  import { SaveBar } from "./savebar/index.js";
3
- export { Media, SaveBar };
3
+ import { VariantsPicker } from "./variants-picker/index.js";
4
+ export { Media, SaveBar, VariantsPicker };
@@ -108,7 +108,7 @@ const MediaPreview_MediaPreview = ({ media, onClose })=>{
108
108
  weight: "medium",
109
109
  color: "info",
110
110
  children: [
111
- "\u2022",
111
+ "",
112
112
  formatToBytes(Number(media?.size), 2)
113
113
  ]
114
114
  }),
@@ -0,0 +1,7 @@
1
+ export declare const variantsQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../../shared/graphql/graphql").VariantsQuery, import("../../../shared/graphql/graphql").Exact<{
2
+ after?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
3
+ before?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
4
+ first?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
5
+ last?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
6
+ query?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["String"]["input"]>;
7
+ }>>;
@@ -0,0 +1,30 @@
1
+ import { graphql } from "../../../shared/graphql/index.js";
2
+ const variantsQuery = graphql(`
3
+ query Variants($after: ID, $before: ID, $first: Int, $last: Int, $query: String) {
4
+ variants(after: $after, before: $before, first: $first, last: $last, query: $query) {
5
+ pageInfo {
6
+ endCursor
7
+ hasNextPage
8
+ hasPreviousPage
9
+ startCursor
10
+ }
11
+ edges {
12
+ node {
13
+ _id
14
+ option1
15
+ option2
16
+ option3
17
+ image {
18
+ _id
19
+ url
20
+ }
21
+ product {
22
+ _id
23
+ title
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ `);
30
+ export { variantsQuery };
@@ -0,0 +1 @@
1
+ export { default as VariantsPicker } from "./ui/VariantsPicker";
@@ -0,0 +1,2 @@
1
+ import VariantsPicker from "./ui/VariantsPicker.js";
2
+ export { VariantsPicker };
@@ -0,0 +1,34 @@
1
+ type Props = {
2
+ first?: number;
3
+ query?: string | null;
4
+ };
5
+ export declare const useVariants: (props?: Props) => {
6
+ variants: {
7
+ __typename: "Variant";
8
+ _id?: string | null;
9
+ option1?: string | null;
10
+ option2?: string | null;
11
+ option3?: string | null;
12
+ image?: {
13
+ __typename: "Media";
14
+ _id?: string | null;
15
+ url?: string | null;
16
+ } | null;
17
+ product?: {
18
+ __typename: "Product";
19
+ _id?: string | null;
20
+ title?: string | null;
21
+ } | null;
22
+ }[];
23
+ pageInfo: {
24
+ __typename: "PageInfo";
25
+ endCursor?: string | null;
26
+ hasNextPage?: boolean | null;
27
+ hasPreviousPage?: boolean | null;
28
+ startCursor?: string | null;
29
+ } | null | undefined;
30
+ isLoadingVariants: boolean;
31
+ error: import("@apollo/client").ErrorLike | undefined;
32
+ fetchMoreVariants: () => void;
33
+ };
34
+ export {};
@@ -0,0 +1,45 @@
1
+ import { useQuery } from "@apollo/client/react";
2
+ import { useRef } from "react";
3
+ import { variantsQuery } from "../api/query.js";
4
+ const useVariants = (props = {})=>{
5
+ const { first, query } = props;
6
+ const refArray = useRef([]);
7
+ const { data, loading: isLoadingVariants, error, fetchMore } = useQuery(variantsQuery, {
8
+ variables: {
9
+ first,
10
+ query
11
+ }
12
+ });
13
+ const variants = data?.variants?.edges?.map((edge)=>edge?.node).filter((node)=>null != node) ?? refArray.current;
14
+ const pageInfo = data?.variants?.pageInfo;
15
+ const fetchMoreVariants = ()=>{
16
+ if (!pageInfo?.hasNextPage) return;
17
+ fetchMore({
18
+ variables: {
19
+ first,
20
+ query,
21
+ after: pageInfo.endCursor
22
+ },
23
+ updateQuery (prev, { fetchMoreResult }) {
24
+ if (!fetchMoreResult.variants?.edges || !prev.variants?.edges) return prev;
25
+ return {
26
+ variants: {
27
+ ...fetchMoreResult.variants,
28
+ edges: [
29
+ ...prev.variants.edges,
30
+ ...fetchMoreResult.variants.edges
31
+ ]
32
+ }
33
+ };
34
+ }
35
+ });
36
+ };
37
+ return {
38
+ variants,
39
+ pageInfo,
40
+ isLoadingVariants,
41
+ error,
42
+ fetchMoreVariants
43
+ };
44
+ };
45
+ export { useVariants };
@@ -0,0 +1,7 @@
1
+ type Props = {
2
+ initialIds?: string[];
3
+ onClose?: () => void;
4
+ onOk?: (variants: string[]) => void;
5
+ };
6
+ declare const VariantsPicker: ({ initialIds, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export default VariantsPicker;
@@ -0,0 +1,113 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { InfinityScroll } from "../../infinity-scroll/index.js";
3
+ import { useFilterQuery } from "../../../shared/lib/index.js";
4
+ import { Badge, BlockStack, Box, Button, Checkbox, Image, InlineStack, Input, Modal, Spinner, Text } from "@soppiya/elementus";
5
+ import lodash from "lodash";
6
+ import { useState } from "react";
7
+ import { useVariants } from "../model/useVariants.js";
8
+ const VariantsPicker = ({ initialIds = [], onClose, onOk })=>{
9
+ const [selectedVariant, setSelectedVariant] = useState(initialIds);
10
+ const { query, debounceQuery, onChangeQuery } = useFilterQuery();
11
+ const { variants, pageInfo, isLoadingVariants, fetchMoreVariants } = useVariants({
12
+ first: 20,
13
+ query: debounceQuery
14
+ });
15
+ const handleSelectVariant = (variantId)=>{
16
+ selectedVariant.includes(variantId) ? setSelectedVariant((prev)=>prev.filter((id)=>variantId !== id)) : setSelectedVariant((prev)=>[
17
+ ...prev,
18
+ variantId
19
+ ]);
20
+ };
21
+ const handleOk = ()=>{
22
+ if (lodash.isFunction(onOk)) onOk(selectedVariant);
23
+ };
24
+ const buttonsJSX = /*#__PURE__*/ jsx(InlineStack, {
25
+ gap: 50,
26
+ justifyContent: "end",
27
+ children: /*#__PURE__*/ jsx(Button, {
28
+ disabled: lodash.isEmpty(selectedVariant),
29
+ onClick: handleOk,
30
+ children: "Add"
31
+ })
32
+ });
33
+ return /*#__PURE__*/ jsx(Modal, {
34
+ open: true,
35
+ title: "Add inventory",
36
+ bodyPadding: 0,
37
+ buttons: buttonsJSX,
38
+ onClose: onClose,
39
+ children: /*#__PURE__*/ jsxs(BlockStack, {
40
+ children: [
41
+ /*#__PURE__*/ jsx(Box, {
42
+ className: "border-b border-b-[#ebebeb]! h",
43
+ padding: 60,
44
+ children: /*#__PURE__*/ jsx(Input, {
45
+ size: "sm",
46
+ type: "search",
47
+ value: query ?? "",
48
+ onChange: (event)=>onChangeQuery(event.target.value)
49
+ })
50
+ }),
51
+ isLoadingVariants ? /*#__PURE__*/ jsx(InlineStack, {
52
+ justifyContent: "center",
53
+ padding: 80,
54
+ children: /*#__PURE__*/ jsx(Spinner, {
55
+ size: "md"
56
+ })
57
+ }) : /*#__PURE__*/ jsxs(BlockStack, {
58
+ children: [
59
+ variants.map((variant)=>/*#__PURE__*/ jsxs(InlineStack, {
60
+ stack: "full",
61
+ className: "lg:cursor-pointer border-b border-b-[#ebebeb]!",
62
+ gapX: 60,
63
+ padding: 60,
64
+ children: [
65
+ /*#__PURE__*/ jsxs(InlineStack, {
66
+ alignItems: "center",
67
+ gapX: 60,
68
+ children: [
69
+ /*#__PURE__*/ jsx(Box, {
70
+ children: /*#__PURE__*/ jsx(Checkbox, {
71
+ checked: selectedVariant.includes(String(variant._id)),
72
+ onChange: ()=>handleSelectVariant(String(variant._id))
73
+ })
74
+ }),
75
+ /*#__PURE__*/ jsx(Box, {
76
+ children: /*#__PURE__*/ jsx(Image, {
77
+ size: "xs",
78
+ url: String(variant.image?.url)
79
+ })
80
+ })
81
+ ]
82
+ }),
83
+ /*#__PURE__*/ jsxs(BlockStack, {
84
+ gapY: 30,
85
+ children: [
86
+ /*#__PURE__*/ jsx(Text, {
87
+ size: "sm",
88
+ color: "secondary",
89
+ truncate: "truncate-1",
90
+ children: variant.product?.title
91
+ }),
92
+ /*#__PURE__*/ jsx(Badge, {
93
+ children: [
94
+ variant.option1,
95
+ variant.option2,
96
+ variant.option3
97
+ ].filter(Boolean).join(" - ") || "Default"
98
+ })
99
+ ]
100
+ })
101
+ ]
102
+ })),
103
+ pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
104
+ onFetch: fetchMoreVariants
105
+ })
106
+ ]
107
+ })
108
+ ]
109
+ })
110
+ });
111
+ };
112
+ const ui_VariantsPicker = VariantsPicker;
113
+ export { ui_VariantsPicker as default };
@@ -0,0 +1,15 @@
1
+ declare const meta: {
2
+ title: string;
3
+ component: ({ initialIds, onClose, onOk }: {
4
+ initialIds?: string[];
5
+ onClose?: () => void;
6
+ onOk?: (variants: string[]) => void;
7
+ }) => import("react/jsx-runtime").JSX.Element;
8
+ };
9
+ export default meta;
10
+ export declare const Default: {
11
+ args: {
12
+ primary: boolean;
13
+ label: string;
14
+ };
15
+ };
@@ -0,0 +1,13 @@
1
+ import VariantsPicker from "./VariantsPicker.js";
2
+ const meta = {
3
+ title: "Example/VariantsPicker",
4
+ component: VariantsPicker
5
+ };
6
+ const VariantsPicker_stories = meta;
7
+ const Default = {
8
+ args: {
9
+ primary: true,
10
+ label: "Button"
11
+ }
12
+ };
13
+ export { Default, VariantsPicker_stories as default };
@@ -17,6 +17,7 @@ type Documents = {
17
17
  "\n query MediaUsage {\n mediaUsage\n }\n": typeof types.MediaUsageDocument;
18
18
  "\n mutation AddMedias($input: [Upload!]!) {\n addMedias(input: $input) {\n _id\n file_name\n url\n size\n }\n }\n": typeof types.AddMediasDocument;
19
19
  "\n mutation DeleteMedias($cursors: [ID!]!) {\n deleteMedias(cursors: $cursors) {\n message\n }\n }\n": typeof types.DeleteMediasDocument;
20
+ "\n query Variants($after: ID, $before: ID, $first: Int, $last: Int, $query: String) {\n variants(after: $after, before: $before, first: $first, last: $last, query: $query) {\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n edges {\n node {\n _id\n option1\n option2\n option3\n image {\n _id\n url\n }\n product {\n _id\n title\n }\n }\n }\n }\n }\n": typeof types.VariantsDocument;
20
21
  };
21
22
  declare const documents: Documents;
22
23
  /**
@@ -52,5 +53,9 @@ export declare function graphql(source: "\n mutation AddMedias($input: [Upload!
52
53
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
53
54
  */
54
55
  export declare function graphql(source: "\n mutation DeleteMedias($cursors: [ID!]!) {\n deleteMedias(cursors: $cursors) {\n message\n }\n }\n"): (typeof documents)["\n mutation DeleteMedias($cursors: [ID!]!) {\n deleteMedias(cursors: $cursors) {\n message\n }\n }\n"];
56
+ /**
57
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
58
+ */
59
+ export declare function graphql(source: "\n query Variants($after: ID, $before: ID, $first: Int, $last: Int, $query: String) {\n variants(after: $after, before: $before, first: $first, last: $last, query: $query) {\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n edges {\n node {\n _id\n option1\n option2\n option3\n image {\n _id\n url\n }\n product {\n _id\n title\n }\n }\n }\n }\n }\n"): (typeof documents)["\n query Variants($after: ID, $before: ID, $first: Int, $last: Int, $query: String) {\n variants(after: $after, before: $before, first: $first, last: $last, query: $query) {\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n edges {\n node {\n _id\n option1\n option2\n option3\n image {\n _id\n url\n }\n product {\n _id\n title\n }\n }\n }\n }\n }\n"];
55
60
  export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
56
61
  export {};
@@ -1,10 +1,11 @@
1
- import { AddMediasDocument, DeleteMediasDocument, MediaUsageDocument, MediasDocument, StoragePlanDocument } from "./graphql.js";
1
+ import { AddMediasDocument, DeleteMediasDocument, MediaUsageDocument, MediasDocument, StoragePlanDocument, VariantsDocument } from "./graphql.js";
2
2
  const documents = {
3
3
  "\n query Medias(\n $after: ID\n $before: ID\n $first: Int\n $last: Int\n $query: String\n $reverse: Boolean\n $sortKey: MediaSortKeys\n $filterKeys: MediaFilterKeys\n ) {\n medias(\n after: $after\n before: $before\n first: $first\n last: $last\n query: $query\n reverse: $reverse\n sortKey: $sortKey\n filterKeys: $filterKeys\n ) {\n edges {\n node {\n _id\n file_name\n url\n size\n type\n mimetype\n }\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n }\n": MediasDocument,
4
4
  "\n query StoragePlan {\n plan {\n storage\n package {\n _id\n storage\n }\n }\n }\n": StoragePlanDocument,
5
5
  "\n query MediaUsage {\n mediaUsage\n }\n": MediaUsageDocument,
6
6
  "\n mutation AddMedias($input: [Upload!]!) {\n addMedias(input: $input) {\n _id\n file_name\n url\n size\n }\n }\n": AddMediasDocument,
7
- "\n mutation DeleteMedias($cursors: [ID!]!) {\n deleteMedias(cursors: $cursors) {\n message\n }\n }\n": DeleteMediasDocument
7
+ "\n mutation DeleteMedias($cursors: [ID!]!) {\n deleteMedias(cursors: $cursors) {\n message\n }\n }\n": DeleteMediasDocument,
8
+ "\n query Variants($after: ID, $before: ID, $first: Int, $last: Int, $query: String) {\n variants(after: $after, before: $before, first: $first, last: $last, query: $query) {\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n edges {\n node {\n _id\n option1\n option2\n option3\n image {\n _id\n url\n }\n product {\n _id\n title\n }\n }\n }\n }\n }\n": VariantsDocument
8
9
  };
9
10
  function graphql(source) {
10
11
  return documents[source] ?? {};