@soppiya/app-bridge 1.0.8 → 1.1.1

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 (116) hide show
  1. package/dist/components/articles-picker/api/query.d.ts +8 -0
  2. package/dist/components/articles-picker/api/query.js +22 -0
  3. package/dist/components/articles-picker/index.d.ts +1 -0
  4. package/dist/components/articles-picker/index.js +2 -0
  5. package/dist/components/articles-picker/model/useArticles.d.ts +30 -0
  6. package/dist/components/articles-picker/model/useArticles.js +46 -0
  7. package/dist/components/articles-picker/ui/ArticlesPicker.d.ts +9 -0
  8. package/dist/components/articles-picker/ui/ArticlesPicker.js +107 -0
  9. package/dist/components/articles-picker/ui/ProductPicker.stories.d.ts +17 -0
  10. package/dist/components/articles-picker/ui/ProductPicker.stories.js +13 -0
  11. package/dist/components/blogs-picker/api/query.d.ts +8 -0
  12. package/dist/components/blogs-picker/api/query.js +22 -0
  13. package/dist/components/blogs-picker/index.d.ts +1 -0
  14. package/dist/components/blogs-picker/index.js +2 -0
  15. package/dist/components/blogs-picker/model/useBlogs.d.ts +30 -0
  16. package/dist/components/blogs-picker/model/useBlogs.js +46 -0
  17. package/dist/components/blogs-picker/ui/BlogsPicker.d.ts +9 -0
  18. package/dist/components/blogs-picker/ui/BlogsPicker.js +107 -0
  19. package/dist/components/blogs-picker/ui/BlogsPicker.stories.d.ts +17 -0
  20. package/dist/components/blogs-picker/ui/BlogsPicker.stories.js +13 -0
  21. package/dist/components/collections-pciker/api/query.d.ts +5 -0
  22. package/dist/components/collections-pciker/api/query.js +22 -0
  23. package/dist/components/collections-pciker/index.d.ts +1 -0
  24. package/dist/components/collections-pciker/index.js +2 -0
  25. package/dist/components/collections-pciker/model/useCollections.d.ts +29 -0
  26. package/dist/components/collections-pciker/model/useCollections.js +32 -0
  27. package/dist/components/collections-pciker/ui/CollectionPicker.d.ts +9 -0
  28. package/dist/components/collections-pciker/ui/CollectionPicker.js +105 -0
  29. package/dist/components/collections-pciker/ui/CollectionPicker.stories.d.ts +17 -0
  30. package/dist/components/collections-pciker/ui/CollectionPicker.stories.js +13 -0
  31. package/dist/components/index.d.ts +9 -3
  32. package/dist/components/index.js +9 -4
  33. package/dist/components/meta-data/api/query.d.ts +4 -0
  34. package/dist/components/meta-data/api/query.js +14 -0
  35. package/dist/components/meta-data/index.d.ts +1 -0
  36. package/dist/components/meta-data/index.js +2 -0
  37. package/dist/components/meta-data/model/meta.types.d.ts +7 -0
  38. package/dist/components/meta-data/model/meta.types.js +33 -0
  39. package/dist/components/meta-data/model/schema.d.ts +0 -0
  40. package/dist/components/meta-data/model/schema.js +0 -0
  41. package/dist/components/meta-data/model/useGetMetaFields.d.ts +12 -0
  42. package/dist/components/meta-data/model/useGetMetaFields.js +18 -0
  43. package/dist/components/meta-data/ui/ArticleRefMetaField.d.ts +3 -0
  44. package/dist/components/meta-data/ui/ArticleRefMetaField.js +37 -0
  45. package/dist/components/meta-data/ui/BlogRefMetaField.d.ts +3 -0
  46. package/dist/components/meta-data/ui/BlogRefMetaField.js +37 -0
  47. package/dist/components/meta-data/ui/BooleanMetaField.d.ts +3 -0
  48. package/dist/components/meta-data/ui/BooleanMetaField.js +27 -0
  49. package/dist/components/meta-data/ui/CollectionRefMetaField.d.ts +3 -0
  50. package/dist/components/meta-data/ui/CollectionRefMetaField.js +36 -0
  51. package/dist/components/meta-data/ui/ColorMetaField.d.ts +3 -0
  52. package/dist/components/meta-data/ui/ColorMetaField.js +17 -0
  53. package/dist/components/meta-data/ui/DateAndTimeMetaField.d.ts +3 -0
  54. package/dist/components/meta-data/ui/DateAndTimeMetaField.js +34 -0
  55. package/dist/components/meta-data/ui/DateMetaField.d.ts +3 -0
  56. package/dist/components/meta-data/ui/DateMetaField.js +33 -0
  57. package/dist/components/meta-data/ui/FloatMetaField.d.ts +3 -0
  58. package/dist/components/meta-data/ui/FloatMetaField.js +23 -0
  59. package/dist/components/meta-data/ui/MetaData.d.ts +13 -0
  60. package/dist/components/meta-data/ui/MetaData.js +66 -0
  61. package/dist/components/meta-data/ui/MetaData.stories.d.ts +10 -0
  62. package/dist/components/meta-data/ui/MetaData.stories.js +136 -0
  63. package/dist/components/meta-data/ui/MetaDataItem.d.ts +16 -0
  64. package/dist/components/meta-data/ui/MetaDataItem.js +256 -0
  65. package/dist/components/meta-data/ui/MetaDataTypePopup.d.ts +11 -0
  66. package/dist/components/meta-data/ui/MetaDataTypePopup.js +70 -0
  67. package/dist/components/meta-data/ui/MultilineTextMetaField.d.ts +3 -0
  68. package/dist/components/meta-data/ui/MultilineTextMetaField.js +15 -0
  69. package/dist/components/meta-data/ui/NumberMetaField.d.ts +3 -0
  70. package/dist/components/meta-data/ui/NumberMetaField.js +19 -0
  71. package/dist/components/meta-data/ui/PageRefMetaField.d.ts +3 -0
  72. package/dist/components/meta-data/ui/PageRefMetaField.js +37 -0
  73. package/dist/components/meta-data/ui/ProductRefMetaField.d.ts +3 -0
  74. package/dist/components/meta-data/ui/ProductRefMetaField.js +37 -0
  75. package/dist/components/meta-data/ui/SingleLineTextMetaField.d.ts +3 -0
  76. package/dist/components/meta-data/ui/SingleLineTextMetaField.js +18 -0
  77. package/dist/components/meta-data/ui/VariantRefMetaField.d.ts +3 -0
  78. package/dist/components/meta-data/ui/VariantRefMetaField.js +45 -0
  79. package/dist/components/pages-picker/api/query.d.ts +8 -0
  80. package/dist/components/pages-picker/api/query.js +22 -0
  81. package/dist/components/pages-picker/index.d.ts +1 -0
  82. package/dist/components/pages-picker/index.js +2 -0
  83. package/dist/components/pages-picker/model/usePages.d.ts +30 -0
  84. package/dist/components/pages-picker/model/usePages.js +46 -0
  85. package/dist/components/pages-picker/ui/PagesPicker.d.ts +9 -0
  86. package/dist/components/pages-picker/ui/PagesPicker.js +104 -0
  87. package/dist/components/pages-picker/ui/PagesPicker.stories.d.ts +17 -0
  88. package/dist/components/pages-picker/ui/PagesPicker.stories.js +13 -0
  89. package/dist/components/products-picker/api/query.d.ts +8 -0
  90. package/dist/components/products-picker/api/query.js +24 -0
  91. package/dist/components/products-picker/index.d.ts +1 -0
  92. package/dist/components/products-picker/index.js +2 -0
  93. package/dist/components/products-picker/model/useProducts.d.ts +30 -0
  94. package/dist/components/products-picker/model/useProducts.js +46 -0
  95. package/dist/components/products-picker/ui/ProductPicker.d.ts +9 -0
  96. package/dist/components/products-picker/ui/ProductPicker.js +107 -0
  97. package/dist/components/products-picker/ui/ProductsPicker.stories.d.ts +17 -0
  98. package/dist/components/products-picker/ui/ProductsPicker.stories.js +13 -0
  99. package/dist/components/variants-picker/api/query.d.ts +1 -0
  100. package/dist/components/variants-picker/api/query.js +2 -2
  101. package/dist/components/variants-picker/model/useVariants.d.ts +3 -0
  102. package/dist/components/variants-picker/model/useVariants.js +6 -3
  103. package/dist/components/variants-picker/ui/VariantsPicker.d.ts +2 -1
  104. package/dist/components/variants-picker/ui/VariantsPicker.js +3 -2
  105. package/dist/components/variants-picker/ui/VariantsPicker.stories.d.ts +2 -1
  106. package/dist/index.d.ts +2 -2
  107. package/dist/shared/graphql/gql.d.ts +32 -2
  108. package/dist/shared/graphql/gql.js +8 -2
  109. package/dist/shared/graphql/graphql.d.ts +2296 -100
  110. package/dist/shared/graphql/graphql.js +2382 -297
  111. package/dist/shared/loading/Loading.d.ts +2 -0
  112. package/dist/shared/loading/Loading.js +11 -0
  113. package/dist/shared/loading/index.d.ts +1 -0
  114. package/dist/shared/loading/index.js +2 -0
  115. package/dist/styles.css +118 -0
  116. package/package.json +4 -2
@@ -0,0 +1,37 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useProducts } from "../../products-picker/model/useProducts.js";
3
+ import { Loading } from "../../../shared/loading/index.js";
4
+ import { Image, InlineStack, Text } from "@soppiya/elementus";
5
+ const ProductRefMetaField = ({ value, children })=>{
6
+ const { products, isLoadingProducts } = useProducts({
7
+ skip: !value,
8
+ filterKeys: {
9
+ cursors: value?.split(",")
10
+ }
11
+ });
12
+ if (isLoadingProducts) return /*#__PURE__*/ jsx(Loading, {});
13
+ return products?.map((product)=>/*#__PURE__*/ jsxs(InlineStack, {
14
+ justifyContent: "space-between",
15
+ children: [
16
+ /*#__PURE__*/ jsxs(InlineStack, {
17
+ alignItems: "center",
18
+ gapX: 70,
19
+ children: [
20
+ /*#__PURE__*/ jsx(Image, {
21
+ size: "xs",
22
+ url: product.image?.url ?? ""
23
+ }),
24
+ /*#__PURE__*/ jsx(Text, {
25
+ size: "md",
26
+ weight: "regular",
27
+ color: "blue",
28
+ children: product.title
29
+ })
30
+ ]
31
+ }),
32
+ children
33
+ ]
34
+ }, product._id));
35
+ };
36
+ const ui_ProductRefMetaField = ProductRefMetaField;
37
+ export { ui_ProductRefMetaField as default };
@@ -0,0 +1,3 @@
1
+ import { MetaDataProps } from "./MetaDataItem";
2
+ declare const SingleLineTextMetaField: ({ entry, value, children, onChange }: MetaDataProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default SingleLineTextMetaField;
@@ -0,0 +1,18 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Input } from "@soppiya/elementus";
3
+ const SingleLineTextMetaField_SingleLineTextMetaField = ({ entry, value, children, onChange })=>/*#__PURE__*/ jsxs("div", {
4
+ children: [
5
+ /*#__PURE__*/ jsx("div", {
6
+ children: /*#__PURE__*/ jsx("div", {
7
+ children: /*#__PURE__*/ jsx(Input, {
8
+ size: "sm",
9
+ value: value,
10
+ onChange: (e)=>onChange(e.target.value)
11
+ })
12
+ })
13
+ }),
14
+ "multiple" === entry && children
15
+ ]
16
+ });
17
+ const SingleLineTextMetaField = SingleLineTextMetaField_SingleLineTextMetaField;
18
+ export { SingleLineTextMetaField as default };
@@ -0,0 +1,3 @@
1
+ import { MetaDataProps } from "./MetaDataItem";
2
+ declare const VariantRefMetaField: ({ value, children }: MetaDataProps) => import("react/jsx-runtime").JSX.Element | import("react/jsx-runtime").JSX.Element[];
3
+ export default VariantRefMetaField;
@@ -0,0 +1,45 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useVariants } from "../../variants-picker/model/useVariants.js";
3
+ import { Loading } from "../../../shared/loading/index.js";
4
+ import { Image, InlineStack, Text } from "@soppiya/elementus";
5
+ const VariantRefMetaField_VariantRefMetaField = ({ value, children })=>{
6
+ const { variants, isLoadingVariants } = useVariants({
7
+ skip: !value,
8
+ filterKeys: {
9
+ cursors: value?.split(",")
10
+ }
11
+ });
12
+ if (isLoadingVariants) return /*#__PURE__*/ jsx(Loading, {});
13
+ return variants?.map((variant)=>/*#__PURE__*/ jsxs(InlineStack, {
14
+ justifyContent: "space-between",
15
+ children: [
16
+ /*#__PURE__*/ jsxs(InlineStack, {
17
+ gapX: 70,
18
+ alignItems: "center",
19
+ children: [
20
+ /*#__PURE__*/ jsx(Image, {
21
+ size: "xs",
22
+ url: variant.image?.url ?? ""
23
+ }),
24
+ /*#__PURE__*/ jsxs(Text, {
25
+ size: "md",
26
+ weight: "regular",
27
+ color: "blue",
28
+ children: [
29
+ variant.product?.title,
30
+ " ",
31
+ [
32
+ variant.option1,
33
+ variant.option2,
34
+ variant.option3
35
+ ].filter(Boolean).join(", ")
36
+ ]
37
+ })
38
+ ]
39
+ }),
40
+ children
41
+ ]
42
+ }, variant._id));
43
+ };
44
+ const VariantRefMetaField = VariantRefMetaField_VariantRefMetaField;
45
+ export { VariantRefMetaField as default };
@@ -0,0 +1,8 @@
1
+ export declare const pagesQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../../shared/graphql/graphql").PagesQuery, import("../../../shared/graphql/graphql").Exact<{
2
+ filterKeys?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").PageFilterKeys>;
3
+ after?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
4
+ before?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["ID"]["input"]>;
5
+ first?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
6
+ last?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
7
+ query?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["String"]["input"]>;
8
+ }>>;
@@ -0,0 +1,22 @@
1
+ import { graphql } from "../../../shared/graphql/index.js";
2
+ const pagesQuery = graphql(`query Pages($filterKeys: PageFilterKeys, $after: ID, $before: ID, $first: Int, $last: Int, $query: String) {
3
+ pages(filterKeys: $filterKeys, after: $after, before: $before, first: $first, last: $last, query: $query) {
4
+ pageInfo {
5
+ endCursor
6
+ hasNextPage
7
+ hasPreviousPage
8
+ startCursor
9
+ }
10
+ edges {
11
+ node {
12
+ _id
13
+ title
14
+ image {
15
+ _id
16
+ url
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }`);
22
+ export { pagesQuery };
@@ -0,0 +1 @@
1
+ export { default as PagesPicker } from "./ui/PagesPicker";
@@ -0,0 +1,2 @@
1
+ import PagesPicker from "./ui/PagesPicker.js";
2
+ export { PagesPicker };
@@ -0,0 +1,30 @@
1
+ import { PageFilterKeys } from "../../../shared/graphql/graphql";
2
+ type Props = {
3
+ skip?: boolean;
4
+ first?: number;
5
+ query?: string | null;
6
+ filterKeys?: PageFilterKeys;
7
+ };
8
+ export declare const usePages: (props?: Props) => {
9
+ pages: {
10
+ __typename: "Page";
11
+ _id?: string | null;
12
+ title?: string | null;
13
+ image?: {
14
+ __typename: "Media";
15
+ _id?: string | null;
16
+ url?: string | null;
17
+ } | null;
18
+ }[] | undefined;
19
+ isLoadingPages: boolean;
20
+ error: import("@apollo/client").ErrorLike | undefined;
21
+ fetchMorePages: () => void;
22
+ pageInfo: {
23
+ __typename: "PageInfo";
24
+ endCursor?: string | null;
25
+ hasNextPage?: boolean | null;
26
+ hasPreviousPage?: boolean | null;
27
+ startCursor?: string | null;
28
+ } | null | undefined;
29
+ };
30
+ export {};
@@ -0,0 +1,46 @@
1
+ import { useQuery } from "@apollo/client/react";
2
+ import { pagesQuery } from "../api/query.js";
3
+ const usePages = (props = {})=>{
4
+ const { skip, first, query, filterKeys } = props;
5
+ const { data, loading: isLoadingPages, error, fetchMore } = useQuery(pagesQuery, {
6
+ skip,
7
+ variables: {
8
+ first,
9
+ query,
10
+ filterKeys
11
+ }
12
+ });
13
+ const pages = data?.pages?.edges?.map((edge)=>edge?.node).filter((node)=>null != node);
14
+ const pageInfo = data?.pages?.pageInfo;
15
+ const fetchMorePages = ()=>{
16
+ if (!pageInfo?.hasNextPage) return;
17
+ fetchMore({
18
+ variables: {
19
+ first,
20
+ query,
21
+ filterKeys,
22
+ after: pageInfo.endCursor
23
+ },
24
+ updateQuery (prev, { fetchMoreResult }) {
25
+ if (!fetchMoreResult.pages?.edges || !prev.pages?.edges) return prev;
26
+ return {
27
+ pages: {
28
+ ...fetchMoreResult.pages,
29
+ edges: {
30
+ ...prev.pages.edges,
31
+ ...fetchMoreResult.pages.edges
32
+ }
33
+ }
34
+ };
35
+ }
36
+ });
37
+ };
38
+ return {
39
+ pages,
40
+ isLoadingPages,
41
+ error,
42
+ fetchMorePages,
43
+ pageInfo
44
+ };
45
+ };
46
+ export { usePages };
@@ -0,0 +1,9 @@
1
+ type Props = {
2
+ title?: string;
3
+ initialIds?: string[];
4
+ limit?: number;
5
+ onClose?: () => void;
6
+ onOk?: (pages: string[]) => void;
7
+ };
8
+ declare const PagesPicker: ({ title, initialIds, limit, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
+ export default PagesPicker;
@@ -0,0 +1,104 @@
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 { 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 { usePages } from "../model/usePages.js";
8
+ const PagesPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const [selectedPage, setSelectedPage] = useState(initialIds);
10
+ const { query, debounceQuery, onChangeQuery } = useFilterQuery();
11
+ const { pages, fetchMorePages, isLoadingPages, pageInfo } = usePages({
12
+ first: 20,
13
+ query: debounceQuery
14
+ });
15
+ const handleSelectedPage = (pageId)=>{
16
+ selectedPage.includes(pageId) ? setSelectedPage((prev)=>prev.filter((id)=>pageId !== id)) : setSelectedPage((prev)=>[
17
+ ...prev,
18
+ pageId
19
+ ]);
20
+ };
21
+ const handleOk = ()=>{
22
+ if (lodash.isFunction(onOk)) onOk(selectedPage);
23
+ };
24
+ const ButtonJSX = /*#__PURE__*/ jsx(InlineStack, {
25
+ justifyContent: "end",
26
+ children: /*#__PURE__*/ jsx(Button, {
27
+ onClick: handleOk,
28
+ children: "Add"
29
+ })
30
+ });
31
+ return /*#__PURE__*/ jsx(Modal, {
32
+ open: true,
33
+ title: title || "Pages",
34
+ buttons: ButtonJSX,
35
+ bodyPadding: 0,
36
+ onClose: onClose,
37
+ children: /*#__PURE__*/ jsxs(BlockStack, {
38
+ children: [
39
+ /*#__PURE__*/ jsx(Box, {
40
+ className: "border-b border-b-[#ebebeb]! h",
41
+ padding: 60,
42
+ children: /*#__PURE__*/ jsx(Input, {
43
+ size: "sm",
44
+ type: "search",
45
+ value: query ?? "",
46
+ onChange: (event)=>onChangeQuery(event.target.value)
47
+ })
48
+ }),
49
+ isLoadingPages ? /*#__PURE__*/ jsx(InlineStack, {
50
+ justifyContent: "center",
51
+ padding: 80,
52
+ children: /*#__PURE__*/ jsx(Spinner, {
53
+ size: "md"
54
+ })
55
+ }) : /*#__PURE__*/ jsxs(BlockStack, {
56
+ children: [
57
+ pages?.map((product)=>/*#__PURE__*/ jsxs(InlineStack, {
58
+ stack: "full",
59
+ className: "lg:cursor-pointer border-b border-b-[#ebebeb]!",
60
+ gapX: 60,
61
+ padding: 60,
62
+ onClick: ()=>handleSelectedPage(String(product._id)),
63
+ children: [
64
+ /*#__PURE__*/ jsxs(InlineStack, {
65
+ alignItems: "center",
66
+ gapX: 60,
67
+ children: [
68
+ /*#__PURE__*/ jsx(Box, {
69
+ children: /*#__PURE__*/ jsx(Checkbox, {
70
+ checked: selectedPage.includes(String(product._id)),
71
+ onChange: ()=>{}
72
+ })
73
+ }),
74
+ /*#__PURE__*/ jsx(Box, {
75
+ children: /*#__PURE__*/ jsx(Image, {
76
+ size: "xs",
77
+ url: String(product.image?.url)
78
+ })
79
+ })
80
+ ]
81
+ }),
82
+ /*#__PURE__*/ jsx(BlockStack, {
83
+ gapY: 30,
84
+ justifyContent: "center",
85
+ children: /*#__PURE__*/ jsx(Text, {
86
+ size: "sm",
87
+ color: "secondary",
88
+ truncate: "truncate-1",
89
+ children: product.title
90
+ })
91
+ })
92
+ ]
93
+ }, product._id)),
94
+ pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
95
+ onFetch: fetchMorePages
96
+ })
97
+ ]
98
+ })
99
+ ]
100
+ })
101
+ });
102
+ };
103
+ const ui_PagesPicker = PagesPicker;
104
+ export { ui_PagesPicker as default };
@@ -0,0 +1,17 @@
1
+ declare const meta: {
2
+ title: string;
3
+ component: ({ title, initialIds, limit, onClose, onOk }: {
4
+ title?: string;
5
+ initialIds?: string[];
6
+ limit?: number;
7
+ onClose?: () => void;
8
+ onOk?: (pages: string[]) => void;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ };
11
+ export default meta;
12
+ export declare const Default: {
13
+ args: {
14
+ primary: boolean;
15
+ label: string;
16
+ };
17
+ };
@@ -0,0 +1,13 @@
1
+ import PagesPicker from "./PagesPicker.js";
2
+ const meta = {
3
+ title: "Example/PagesPicker",
4
+ component: PagesPicker
5
+ };
6
+ const PagesPicker_stories = meta;
7
+ const Default = {
8
+ args: {
9
+ primary: true,
10
+ label: "Button"
11
+ }
12
+ };
13
+ export { Default, PagesPicker_stories as default };
@@ -0,0 +1,8 @@
1
+ export declare const productsQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../../shared/graphql/graphql").ProductsQuery, 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
+ filterKeys?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").ProductFilterKeys>;
8
+ }>>;
@@ -0,0 +1,24 @@
1
+ import { graphql } from "../../../shared/graphql/index.js";
2
+ const productsQuery = graphql(`
3
+ query Products($after: ID, $before: ID, $first: Int, $last: Int, $query: String,$filterKeys: ProductFilterKeys) {
4
+ products(after: $after, before: $before, first: $first, last: $last, query: $query,filterKeys: $filterKeys) {
5
+ pageInfo {
6
+ endCursor
7
+ hasNextPage
8
+ hasPreviousPage
9
+ startCursor
10
+ }
11
+ edges {
12
+ node {
13
+ _id
14
+ title
15
+ image {
16
+ _id
17
+ url
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+ `);
24
+ export { productsQuery };
@@ -0,0 +1 @@
1
+ export { default as ProductsPicker } from "./ui/ProductPicker";
@@ -0,0 +1,2 @@
1
+ import ProductPicker from "./ui/ProductPicker.js";
2
+ export { ProductPicker as ProductsPicker };
@@ -0,0 +1,30 @@
1
+ import { ProductFilterKeys } from "../../../shared/graphql/graphql";
2
+ type Props = {
3
+ skip?: boolean;
4
+ first?: number;
5
+ query?: string | null;
6
+ filterKeys?: ProductFilterKeys;
7
+ };
8
+ export declare const useProducts: (props?: Props) => {
9
+ products: {
10
+ __typename: "Product";
11
+ _id?: string | null;
12
+ title?: string | null;
13
+ image?: {
14
+ __typename: "Media";
15
+ _id?: string | null;
16
+ url?: string | null;
17
+ } | null;
18
+ }[] | undefined;
19
+ pageInfo: {
20
+ __typename: "PageInfo";
21
+ endCursor?: string | null;
22
+ hasNextPage?: boolean | null;
23
+ hasPreviousPage?: boolean | null;
24
+ startCursor?: string | null;
25
+ } | null | undefined;
26
+ isLoadingProducts: boolean;
27
+ error: import("@apollo/client").ErrorLike | undefined;
28
+ fetchMoreProducts: () => void;
29
+ };
30
+ export {};
@@ -0,0 +1,46 @@
1
+ import { useQuery } from "@apollo/client/react";
2
+ import { productsQuery } from "../api/query.js";
3
+ const useProducts = (props = {})=>{
4
+ const { first, query, filterKeys, skip } = props;
5
+ const { data, loading: isLoadingProducts, error, fetchMore } = useQuery(productsQuery, {
6
+ skip,
7
+ variables: {
8
+ first,
9
+ query,
10
+ filterKeys
11
+ }
12
+ });
13
+ const products = data?.products?.edges?.map((edge)=>edge?.node).filter((node)=>null != node);
14
+ const pageInfo = data?.products?.pageInfo;
15
+ const fetchMoreProducts = ()=>{
16
+ if (!pageInfo?.hasNextPage) return;
17
+ fetchMore({
18
+ variables: {
19
+ first,
20
+ query,
21
+ filterKeys,
22
+ after: pageInfo.endCursor
23
+ },
24
+ updateQuery (prev, { fetchMoreResult }) {
25
+ if (!fetchMoreResult.products?.edges || !prev.products?.edges) return prev;
26
+ return {
27
+ products: {
28
+ ...fetchMoreResult.products,
29
+ edges: [
30
+ ...prev.products.edges,
31
+ ...fetchMoreResult.products.edges
32
+ ]
33
+ }
34
+ };
35
+ }
36
+ });
37
+ };
38
+ return {
39
+ products,
40
+ pageInfo,
41
+ isLoadingProducts,
42
+ error,
43
+ fetchMoreProducts
44
+ };
45
+ };
46
+ export { useProducts };
@@ -0,0 +1,9 @@
1
+ type Props = {
2
+ title?: string;
3
+ initialIds?: string[];
4
+ limit?: number;
5
+ onClose?: () => void;
6
+ onOk?: (products: string[]) => void;
7
+ };
8
+ declare const ProductsPicker: ({ title, initialIds, limit, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
9
+ export default ProductsPicker;
@@ -0,0 +1,107 @@
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 { 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 { useProducts } from "../model/useProducts.js";
8
+ const ProductsPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const [selectedVariant, setSelectedVariant] = useState(initialIds);
10
+ const { query, debounceQuery, onChangeQuery } = useFilterQuery();
11
+ const { products, pageInfo, isLoadingProducts, fetchMoreProducts } = useProducts({
12
+ first: 20,
13
+ query: debounceQuery
14
+ });
15
+ const isSelected = limit === 1 / 0 ? true : 1 === limit ? 1 === selectedVariant.length : selectedVariant.length >= limit;
16
+ const handleSelectVariant = (productId)=>{
17
+ selectedVariant.includes(productId) ? setSelectedVariant((prev)=>prev.filter((id)=>productId !== id)) : setSelectedVariant((prev)=>[
18
+ ...prev,
19
+ productId
20
+ ]);
21
+ };
22
+ const handleOk = ()=>{
23
+ if (lodash.isFunction(onOk)) onOk(selectedVariant);
24
+ };
25
+ const buttonsJSX = /*#__PURE__*/ jsx(InlineStack, {
26
+ gap: 50,
27
+ justifyContent: "end",
28
+ children: /*#__PURE__*/ jsx(Button, {
29
+ disabled: lodash.isEmpty(selectedVariant) || !isSelected,
30
+ onClick: handleOk,
31
+ children: "Add"
32
+ })
33
+ });
34
+ return /*#__PURE__*/ jsx(Modal, {
35
+ open: true,
36
+ title: title || "Products",
37
+ bodyPadding: 0,
38
+ buttons: buttonsJSX,
39
+ onClose: onClose,
40
+ children: /*#__PURE__*/ jsxs(BlockStack, {
41
+ children: [
42
+ /*#__PURE__*/ jsx(Box, {
43
+ className: "border-b border-b-[#ebebeb]! h",
44
+ padding: 60,
45
+ children: /*#__PURE__*/ jsx(Input, {
46
+ size: "sm",
47
+ type: "search",
48
+ value: query ?? "",
49
+ onChange: (event)=>onChangeQuery(event.target.value)
50
+ })
51
+ }),
52
+ isLoadingProducts ? /*#__PURE__*/ jsx(InlineStack, {
53
+ justifyContent: "center",
54
+ padding: 80,
55
+ children: /*#__PURE__*/ jsx(Spinner, {
56
+ size: "md"
57
+ })
58
+ }) : /*#__PURE__*/ jsxs(BlockStack, {
59
+ children: [
60
+ products?.map((product)=>/*#__PURE__*/ jsxs(InlineStack, {
61
+ stack: "full",
62
+ className: "lg:cursor-pointer border-b border-b-[#ebebeb]!",
63
+ gapX: 60,
64
+ padding: 60,
65
+ onClick: ()=>handleSelectVariant(String(product._id)),
66
+ children: [
67
+ /*#__PURE__*/ jsxs(InlineStack, {
68
+ alignItems: "center",
69
+ gapX: 60,
70
+ children: [
71
+ /*#__PURE__*/ jsx(Box, {
72
+ children: /*#__PURE__*/ jsx(Checkbox, {
73
+ checked: selectedVariant.includes(String(product._id)),
74
+ onChange: ()=>{}
75
+ })
76
+ }),
77
+ /*#__PURE__*/ jsx(Box, {
78
+ children: /*#__PURE__*/ jsx(Image, {
79
+ size: "xs",
80
+ url: String(product.image?.url)
81
+ })
82
+ })
83
+ ]
84
+ }),
85
+ /*#__PURE__*/ jsx(BlockStack, {
86
+ gapY: 30,
87
+ justifyContent: "center",
88
+ children: /*#__PURE__*/ jsx(Text, {
89
+ size: "sm",
90
+ color: "secondary",
91
+ truncate: "truncate-1",
92
+ children: product.title
93
+ })
94
+ })
95
+ ]
96
+ }, product._id)),
97
+ pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
98
+ onFetch: fetchMoreProducts
99
+ })
100
+ ]
101
+ })
102
+ ]
103
+ })
104
+ });
105
+ };
106
+ const ProductPicker = ProductsPicker;
107
+ export { ProductPicker as default };
@@ -0,0 +1,17 @@
1
+ declare const meta: {
2
+ title: string;
3
+ component: ({ title, initialIds, limit, onClose, onOk }: {
4
+ title?: string;
5
+ initialIds?: string[];
6
+ limit?: number;
7
+ onClose?: () => void;
8
+ onOk?: (products: string[]) => void;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ };
11
+ export default meta;
12
+ export declare const Default: {
13
+ args: {
14
+ primary: boolean;
15
+ label: string;
16
+ };
17
+ };
@@ -0,0 +1,13 @@
1
+ import ProductPicker from "./ProductPicker.js";
2
+ const meta = {
3
+ title: "Example/ProductsPicker",
4
+ component: ProductPicker
5
+ };
6
+ const ProductsPicker_stories = meta;
7
+ const Default = {
8
+ args: {
9
+ primary: true,
10
+ label: "Button"
11
+ }
12
+ };
13
+ export { Default, ProductsPicker_stories as default };
@@ -4,4 +4,5 @@ export declare const variantsQuery: import("@graphql-typed-document-node/core").
4
4
  first?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
5
5
  last?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["Int"]["input"]>;
6
6
  query?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").Scalars["String"]["input"]>;
7
+ filterKeys?: import("../../../shared/graphql/graphql").InputMaybe<import("../../../shared/graphql/graphql").VariantFilterKeys>;
7
8
  }>>;