@soppiya/app-bridge 1.1.2 → 1.1.3

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 (27) hide show
  1. package/dist/components/articles-picker/ui/ArticlesPicker.js +13 -7
  2. package/dist/components/blogs-picker/ui/BlogsPicker.js +13 -7
  3. package/dist/components/collections-pciker/ui/CollectionPicker.js +16 -10
  4. package/dist/components/collections-pciker/ui/CollectionPicker.stories.d.ts +1 -4
  5. package/dist/components/collections-pciker/ui/CollectionPicker.stories.js +1 -4
  6. package/dist/components/link-list-picker/ui/LinkListPicker.js +15 -9
  7. package/dist/components/meta-data/ui/MetaData.d.ts +2 -1
  8. package/dist/components/meta-data/ui/MetaData.js +9 -13
  9. package/dist/components/metafield-entries/api/query.d.ts +8 -0
  10. package/dist/components/metafield-entries/api/query.js +18 -0
  11. package/dist/components/metafield-entries/index.d.ts +0 -0
  12. package/dist/components/metafield-entries/index.js +0 -0
  13. package/dist/components/metafield-entries/model/useMetaobjectEntries.d.ts +25 -0
  14. package/dist/components/metafield-entries/model/useMetaobjectEntries.js +46 -0
  15. package/dist/components/metafield-entries/ui/MetaobjectEntries.d.ts +10 -0
  16. package/dist/components/metafield-entries/ui/MetaobjectEntries.js +108 -0
  17. package/dist/components/metafield-entries/ui/MetaobjectEntries.stories.d.ts +15 -0
  18. package/dist/components/metafield-entries/ui/MetaobjectEntries.stories.js +10 -0
  19. package/dist/components/pages-picker/ui/PagesPicker.js +19 -11
  20. package/dist/components/products-picker/ui/ProductPicker.js +16 -10
  21. package/dist/components/variants-picker/ui/VariantsPicker.js +13 -7
  22. package/dist/shared/graphql/gql.d.ts +5 -0
  23. package/dist/shared/graphql/gql.js +2 -1
  24. package/dist/shared/graphql/graphql.d.ts +29 -0
  25. package/dist/shared/graphql/graphql.js +299 -1
  26. package/dist/styles.css +12 -4
  27. package/package.json +1 -1
@@ -2,19 +2,23 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { InfinityScroll } from "../../infinity-scroll/index.js";
3
3
  import { useFilterQuery } from "../../../shared/lib/index.js";
4
4
  import { BlockStack, Box, Button, Checkbox, Image, InlineStack, Input, Modal, Spinner, Text } from "@soppiya/elementus";
5
+ import classnames from "classnames";
5
6
  import lodash from "lodash";
6
7
  import { useState } from "react";
7
8
  import { userArticles } from "../model/useArticles.js";
8
- const ArticlesPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const ArticlesPicker = ({ title = "Articles", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
10
  const [selectedVariant, setSelectedVariant] = useState(initialIds);
10
11
  const { query, debounceQuery, onChangeQuery } = useFilterQuery();
11
12
  const { articles, pageInfo, isLoadingArticles, fetchMoreArticles } = userArticles({
12
13
  first: 20,
13
14
  query: debounceQuery
14
15
  });
15
- const isSelected = limit === 1 / 0 ? true : 1 === limit ? 1 === selectedVariant.length : selectedVariant.length >= limit;
16
+ const isReached = limit !== 1 / 0 && selectedVariant.length >= limit;
17
+ const isDisabled = limit !== 1 / 0 && selectedVariant.length > limit;
16
18
  const handleSelectVariant = (articleId)=>{
17
- selectedVariant?.includes(articleId) ? setSelectedVariant((prev)=>prev?.filter((id)=>articleId !== id)) : setSelectedVariant((prev)=>[
19
+ if (selectedVariant?.includes(articleId)) return void setSelectedVariant((prev)=>prev?.filter((id)=>articleId !== id));
20
+ if (isReached) return;
21
+ setSelectedVariant((prev)=>[
18
22
  ...prev,
19
23
  articleId
20
24
  ]);
@@ -26,21 +30,20 @@ const ArticlesPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk }
26
30
  gap: 50,
27
31
  justifyContent: "end",
28
32
  children: /*#__PURE__*/ jsx(Button, {
29
- disabled: lodash.isEmpty(selectedVariant) || !isSelected,
33
+ disabled: lodash.isEmpty(selectedVariant) || isDisabled,
30
34
  onClick: handleOk,
31
35
  children: "Add"
32
36
  })
33
37
  });
34
38
  return /*#__PURE__*/ jsx(Modal, {
35
39
  open: true,
36
- title: title || "Articles",
40
+ title: title,
37
41
  bodyPadding: 0,
38
42
  buttons: ButtonJSX,
39
43
  onClose: onClose,
40
44
  children: /*#__PURE__*/ jsxs(BlockStack, {
41
45
  children: [
42
46
  /*#__PURE__*/ jsx(Box, {
43
- className: "border-b border-b-[#ebebeb]! h",
44
47
  padding: 60,
45
48
  children: /*#__PURE__*/ jsx(Input, {
46
49
  size: "sm",
@@ -59,7 +62,9 @@ const ArticlesPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk }
59
62
  children: [
60
63
  articles?.map((article)=>/*#__PURE__*/ jsxs(InlineStack, {
61
64
  stack: "full",
62
- className: "lg:cursor-pointer border-b border-b-[#ebebeb]!",
65
+ className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
66
+ 'bg-[#f1f1f1ab] cursor-default!': !selectedVariant.includes(article._id) && isReached
67
+ }),
63
68
  gapX: 60,
64
69
  padding: 60,
65
70
  onClick: ()=>handleSelectVariant(String(article._id)),
@@ -70,6 +75,7 @@ const ArticlesPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk }
70
75
  children: [
71
76
  /*#__PURE__*/ jsx(Box, {
72
77
  children: /*#__PURE__*/ jsx(Checkbox, {
78
+ disabled: !selectedVariant.includes(article._id) && isReached,
73
79
  checked: selectedVariant.includes(String(article._id)),
74
80
  onChange: ()=>{}
75
81
  })
@@ -2,19 +2,23 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { InfinityScroll } from "../../infinity-scroll/index.js";
3
3
  import { useFilterQuery } from "../../../shared/lib/index.js";
4
4
  import { BlockStack, Box, Button, Checkbox, Image, InlineStack, Input, Modal, Spinner, Text } from "@soppiya/elementus";
5
+ import classnames from "classnames";
5
6
  import lodash from "lodash";
6
7
  import { useState } from "react";
7
8
  import { useBlogs } from "../model/useBlogs.js";
8
- const BlogsPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const BlogsPicker = ({ title = "Blogs", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
10
  const [selectedBlog, setSelectedBlog] = useState(initialIds);
10
11
  const { query, debounceQuery, onChangeQuery } = useFilterQuery();
11
12
  const { blogs, isLoadingBlogs, fetchMoreBlogs, pageInfo } = useBlogs({
12
13
  first: 20,
13
14
  query: debounceQuery
14
15
  });
15
- const isSelected = limit === 1 / 0 ? true : 1 === limit ? 1 === selectedBlog.length : selectedBlog.length >= limit;
16
+ const isReached = limit !== 1 / 0 && selectedBlog.length >= limit;
17
+ const isDisabled = limit !== 1 / 0 && selectedBlog.length > limit;
16
18
  const handleSelectedBlog = (blogId)=>{
17
- selectedBlog.includes(blogId) ? setSelectedBlog((prev)=>prev.filter((id)=>id !== blogId)) : setSelectedBlog((prev)=>[
19
+ if (selectedBlog?.includes(blogId)) return void setSelectedBlog((prev)=>prev?.filter((id)=>blogId !== id));
20
+ if (isReached) return;
21
+ setSelectedBlog((prev)=>[
18
22
  ...prev,
19
23
  blogId
20
24
  ]);
@@ -26,20 +30,19 @@ const BlogsPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>
26
30
  justifyContent: "end",
27
31
  children: /*#__PURE__*/ jsx(Button, {
28
32
  onClick: handleOk,
29
- disabled: lodash.isEmpty(selectedBlog) || !isSelected,
33
+ disabled: lodash.isEmpty(selectedBlog) || isDisabled,
30
34
  children: "Add"
31
35
  })
32
36
  });
33
37
  return /*#__PURE__*/ jsx(Modal, {
34
38
  open: true,
35
- title: title || "Blogs",
39
+ title: title,
36
40
  buttons: ButtonJSX,
37
41
  bodyPadding: 0,
38
42
  onClose: onClose,
39
43
  children: /*#__PURE__*/ jsxs(BlockStack, {
40
44
  children: [
41
45
  /*#__PURE__*/ jsx(Box, {
42
- className: "border-b border-b-[#ebebeb]! h",
43
46
  padding: 60,
44
47
  children: /*#__PURE__*/ jsx(Input, {
45
48
  size: "sm",
@@ -58,7 +61,9 @@ const BlogsPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>
58
61
  children: [
59
62
  blogs?.map((blog)=>/*#__PURE__*/ jsxs(InlineStack, {
60
63
  stack: "full",
61
- className: "lg:cursor-pointer border-b border-b-[#ebebeb]!",
64
+ className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
65
+ 'bg-[#f1f1f1ab] cursor-default!': !selectedBlog.includes(blog._id) && isReached
66
+ }),
62
67
  gapX: 60,
63
68
  padding: 60,
64
69
  onClick: ()=>handleSelectedBlog(String(blog._id)),
@@ -69,6 +74,7 @@ const BlogsPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>
69
74
  children: [
70
75
  /*#__PURE__*/ jsx(Box, {
71
76
  children: /*#__PURE__*/ jsx(Checkbox, {
77
+ disabled: !selectedBlog.includes(blog._id) && isReached,
72
78
  checked: selectedBlog.includes(String(blog._id)),
73
79
  onChange: ()=>{}
74
80
  })
@@ -2,43 +2,46 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { InfinityScroll } from "../../infinity-scroll/index.js";
3
3
  import { useFilterQuery } from "../../../shared/lib/index.js";
4
4
  import { BlockStack, Box, Button, Checkbox, Image, InlineStack, Input, Modal, Spinner, Text } from "@soppiya/elementus";
5
+ import classnames from "classnames";
5
6
  import lodash from "lodash";
6
7
  import { useState } from "react";
7
8
  import { useCollections } from "../model/useCollections.js";
8
- const CollectionPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
- const [selectedVariant, setSelectedVariant] = useState(initialIds);
9
+ const CollectionPicker = ({ title = "Collections", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
10
+ const [selectedCollection, setSelectedCollection] = useState(initialIds);
10
11
  const { query, debounceQuery, onChangeQuery } = useFilterQuery();
11
12
  const { collections, isLoadingCollections, fetchMoreCollections, pageInfo } = useCollections({
12
13
  query: debounceQuery
13
14
  });
14
- const isSelected = limit === 1 / 0 ? true : 1 === limit ? 1 === selectedVariant.length : selectedVariant.length >= limit;
15
+ const isReached = limit !== 1 / 0 && selectedCollection.length >= limit;
16
+ const isDisabled = limit !== 1 / 0 && selectedCollection.length > limit;
15
17
  const handleSelectVariant = (productId)=>{
16
- selectedVariant.includes(productId) ? setSelectedVariant((prev)=>prev.filter((id)=>productId !== id)) : setSelectedVariant((prev)=>[
18
+ if (selectedCollection.includes(productId)) return void setSelectedCollection((prev)=>prev.filter((id)=>productId !== id));
19
+ if (isReached) return;
20
+ setSelectedCollection((prev)=>[
17
21
  ...prev,
18
22
  productId
19
23
  ]);
20
24
  };
21
25
  const handleOk = ()=>{
22
- if (lodash.isFunction(onOk)) onOk(selectedVariant);
26
+ if (lodash.isFunction(onOk)) onOk(selectedCollection);
23
27
  };
24
28
  const ButtonJSX = /*#__PURE__*/ jsx(InlineStack, {
25
29
  justifyContent: "end",
26
30
  children: /*#__PURE__*/ jsx(Button, {
27
- disabled: lodash.isEmpty(selectedVariant) || !isSelected,
31
+ disabled: lodash.isEmpty(selectedCollection) || isDisabled,
28
32
  onClick: handleOk,
29
33
  children: "Add"
30
34
  })
31
35
  });
32
36
  return /*#__PURE__*/ jsx(Modal, {
33
37
  open: true,
34
- title: title || "Collections",
38
+ title: title,
35
39
  bodyPadding: 0,
36
40
  buttons: ButtonJSX,
37
41
  onClose: onClose,
38
42
  children: /*#__PURE__*/ jsxs(BlockStack, {
39
43
  children: [
40
44
  /*#__PURE__*/ jsx(Box, {
41
- className: "border-b border-b-[#ebebeb]! h",
42
45
  padding: 60,
43
46
  children: /*#__PURE__*/ jsx(Input, {
44
47
  size: "sm",
@@ -57,7 +60,9 @@ const CollectionPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk
57
60
  children: [
58
61
  collections?.map((collection)=>/*#__PURE__*/ jsxs(InlineStack, {
59
62
  stack: "full",
60
- className: "lg:cursor-pointer border-b border-b-[#ebebeb]!",
63
+ className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
64
+ 'bg-[#f1f1f1ab] cursor-default!': !selectedCollection.includes(collection._id) && isReached
65
+ }),
61
66
  gapX: 60,
62
67
  padding: 60,
63
68
  onClick: ()=>handleSelectVariant(String(collection._id)),
@@ -68,7 +73,8 @@ const CollectionPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk
68
73
  children: [
69
74
  /*#__PURE__*/ jsx(Box, {
70
75
  children: /*#__PURE__*/ jsx(Checkbox, {
71
- checked: selectedVariant.includes(String(collection._id)),
76
+ disabled: !selectedCollection.includes(collection._id) && isReached,
77
+ checked: selectedCollection.includes(String(collection._id)),
72
78
  onChange: ()=>{}
73
79
  })
74
80
  }),
@@ -10,8 +10,5 @@ declare const meta: {
10
10
  };
11
11
  export default meta;
12
12
  export declare const Default: {
13
- args: {
14
- primary: boolean;
15
- label: string;
16
- };
13
+ args: {};
17
14
  };
@@ -5,9 +5,6 @@ const meta = {
5
5
  };
6
6
  const CollectionPicker_stories = meta;
7
7
  const Default = {
8
- args: {
9
- primary: true,
10
- label: "Button"
11
- }
8
+ args: {}
12
9
  };
13
10
  export { Default, CollectionPicker_stories as default };
@@ -2,19 +2,23 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { InfinityScroll } from "../../infinity-scroll/index.js";
3
3
  import { useFilterQuery } from "../../../shared/lib/index.js";
4
4
  import { BlockStack, Box, Button, Checkbox, InlineStack, Input, Modal, Spinner, Text } from "@soppiya/elementus";
5
+ import classnames from "classnames";
5
6
  import lodash from "lodash";
6
7
  import { useState } from "react";
7
8
  import { useLinklist } from "../model/useLinkList.js";
8
- const LinkListPicker_LinkListPicker = ({ title, initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
+ const LinkListPicker = ({ title = "Linklist", initialIds = [], limit = 1 / 0, onClose, onOk })=>{
9
10
  const [selectedLinklist, setSelectedLinklist] = useState(initialIds);
10
11
  const { query, debounceQuery, onChangeQuery } = useFilterQuery();
11
12
  const { linklists, isLoadingLinklist, fetchMoreLinklists, pageInfo } = useLinklist({
12
13
  first: 20,
13
14
  query: debounceQuery
14
15
  });
15
- const isSelected = limit === 1 / 0 ? true : 1 === limit ? 1 === selectedLinklist.length : selectedLinklist.length >= limit;
16
+ const isReached = limit !== 1 / 0 && selectedLinklist.length >= limit;
17
+ const isDisabled = limit !== 1 / 0 && selectedLinklist.length > limit;
16
18
  const handleSelectedLinklist = (linkListId)=>{
17
- selectedLinklist.includes(linkListId) ? setSelectedLinklist((prev)=>prev.filter((id)=>id !== linkListId)) : setSelectedLinklist((prev)=>[
19
+ if (selectedLinklist.includes(linkListId)) return void setSelectedLinklist((prev)=>prev.filter((id)=>id !== linkListId));
20
+ if (isReached) return;
21
+ setSelectedLinklist((prev)=>[
18
22
  ...prev,
19
23
  linkListId
20
24
  ]);
@@ -25,21 +29,20 @@ const LinkListPicker_LinkListPicker = ({ title, initialIds = [], limit = 1 / 0,
25
29
  const ButtonJSX = /*#__PURE__*/ jsx(InlineStack, {
26
30
  justifyContent: "end",
27
31
  children: /*#__PURE__*/ jsx(Button, {
28
- disabled: lodash.isEmpty(selectedLinklist) || !isSelected,
32
+ disabled: lodash.isEmpty(selectedLinklist) || isDisabled,
29
33
  onClick: handleOk,
30
34
  children: "Add"
31
35
  })
32
36
  });
33
37
  return /*#__PURE__*/ jsx(Modal, {
34
38
  open: true,
35
- title: title || "Linklist",
39
+ title: title,
36
40
  bodyPadding: 0,
37
41
  buttons: ButtonJSX,
38
42
  onClose: onClose,
39
43
  children: /*#__PURE__*/ jsxs(BlockStack, {
40
44
  children: [
41
45
  /*#__PURE__*/ jsx(Box, {
42
- className: "border-b border-b-[#ebebeb]! h",
43
46
  padding: 60,
44
47
  children: /*#__PURE__*/ jsx(Input, {
45
48
  size: "sm",
@@ -58,7 +61,9 @@ const LinkListPicker_LinkListPicker = ({ title, initialIds = [], limit = 1 / 0,
58
61
  children: [
59
62
  linklists?.map((linklist)=>/*#__PURE__*/ jsxs(InlineStack, {
60
63
  stack: "full",
61
- className: "lg:cursor-pointer border-b border-b-[#ebebeb]!",
64
+ className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
65
+ 'bg-[#f1f1f1ab] cursor-default!': !selectedLinklist.includes(linklist._id) && isReached
66
+ }),
62
67
  gapX: 60,
63
68
  padding: 60,
64
69
  onClick: ()=>handleSelectedLinklist(String(linklist._id)),
@@ -68,6 +73,7 @@ const LinkListPicker_LinkListPicker = ({ title, initialIds = [], limit = 1 / 0,
68
73
  gapX: 60,
69
74
  children: /*#__PURE__*/ jsx(Box, {
70
75
  children: /*#__PURE__*/ jsx(Checkbox, {
76
+ disabled: !selectedLinklist.includes(linklist._id) && isReached,
71
77
  checked: selectedLinklist.includes(String(linklist._id)),
72
78
  onChange: ()=>{}
73
79
  })
@@ -94,5 +100,5 @@ const LinkListPicker_LinkListPicker = ({ title, initialIds = [], limit = 1 / 0,
94
100
  })
95
101
  });
96
102
  };
97
- const LinkListPicker = LinkListPicker_LinkListPicker;
98
- export { LinkListPicker as default };
103
+ const ui_LinkListPicker = LinkListPicker;
104
+ export { ui_LinkListPicker as default };
@@ -1,4 +1,5 @@
1
1
  interface Props {
2
+ title?: string;
2
3
  scope: string;
3
4
  value?: {
4
5
  metafield: string;
@@ -9,5 +10,5 @@ interface Props {
9
10
  value: string[];
10
11
  }) => void;
11
12
  }
12
- declare const MetaData: ({ scope, value, onChange }: Props) => import("react/jsx-runtime").JSX.Element;
13
+ declare const MetaData: ({ title, scope, value, onChange }: Props) => import("react/jsx-runtime").JSX.Element;
13
14
  export default MetaData;
@@ -4,7 +4,7 @@ import { BlockStack, Card, Text } from "@soppiya/elementus";
4
4
  import { isFunction } from "lodash";
5
5
  import { useGetMetaFields } from "../model/useGetMetaFields.js";
6
6
  import MetaDataItem from "./MetaDataItem.js";
7
- const MetaData_MetaData = ({ scope = "product", value = [], onChange })=>{
7
+ const MetaData_MetaData = ({ title = "Meta fields", scope = "product", value = [], onChange })=>{
8
8
  const { metafields, loading } = useGetMetaFields([
9
9
  scope
10
10
  ]);
@@ -22,12 +22,10 @@ const MetaData_MetaData = ({ scope = "product", value = [], onChange })=>{
22
22
  children: [
23
23
  /*#__PURE__*/ jsx(BlockStack, {
24
24
  padding: 70,
25
- children: /*#__PURE__*/ jsx("div", {
26
- children: /*#__PURE__*/ jsx(Text, {
27
- size: "md",
28
- weight: "semibold",
29
- children: "Meta fields"
30
- })
25
+ children: /*#__PURE__*/ jsx(Text, {
26
+ size: "md",
27
+ weight: "semibold",
28
+ children: title
31
29
  })
32
30
  }),
33
31
  /*#__PURE__*/ jsx(BlockStack, {
@@ -46,12 +44,10 @@ const MetaData_MetaData = ({ scope = "product", value = [], onChange })=>{
46
44
  children: [
47
45
  /*#__PURE__*/ jsx(BlockStack, {
48
46
  padding: 70,
49
- children: /*#__PURE__*/ jsx("div", {
50
- children: /*#__PURE__*/ jsx(Text, {
51
- size: "md",
52
- weight: "semibold",
53
- children: "Meta fields"
54
- })
47
+ children: /*#__PURE__*/ jsx(Text, {
48
+ size: "md",
49
+ weight: "semibold",
50
+ children: title
55
51
  })
56
52
  }),
57
53
  loading && !metafields ? /*#__PURE__*/ jsx(Loading, {}) : metafields.map((metaField)=>/*#__PURE__*/ jsx(MetaDataItem, {
@@ -0,0 +1,8 @@
1
+ export declare const metaobjectEntriesQuery: import("@graphql-typed-document-node/core").TypedDocumentNode<import("../../../shared/graphql/graphql").MetaobjectEntriesQuery, 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").MetaobjectEntryFilterKeys>;
8
+ }>>;
@@ -0,0 +1,18 @@
1
+ import { graphql } from "../../../shared/graphql/index.js";
2
+ const metaobjectEntriesQuery = graphql(`query MetaobjectEntries($after: ID, $before: ID, $first: Int, $last: Int, $query: String, $filterKeys: MetaobjectEntryFilterKeys) {
3
+ metaobjectEntries(after: $after, before: $before, first: $first, last: $last, query: $query, filterKeys: $filterKeys) {
4
+ pageInfo {
5
+ endCursor
6
+ hasNextPage
7
+ hasPreviousPage
8
+ startCursor
9
+ }
10
+ edges {
11
+ node {
12
+ _id
13
+ title
14
+ }
15
+ }
16
+ }
17
+ }`);
18
+ export { metaobjectEntriesQuery };
File without changes
File without changes
@@ -0,0 +1,25 @@
1
+ import { MetaobjectEntryFilterKeys } from "../../../shared/graphql/graphql";
2
+ type Props = {
3
+ skip?: boolean;
4
+ first?: number;
5
+ query?: string | null;
6
+ filterKeys?: MetaobjectEntryFilterKeys;
7
+ };
8
+ export declare const useMetaobjectEntries: (props?: Props) => {
9
+ metaobjectEntries: {
10
+ __typename: "MetaobjectEntry";
11
+ _id?: string | null;
12
+ title?: string | null;
13
+ }[] | undefined;
14
+ isLoadingMetaobjectEntries: boolean;
15
+ error: import("@apollo/client").ErrorLike | undefined;
16
+ fetchMoreMetaobjectEntries: () => void;
17
+ pageInfo: {
18
+ __typename: "PageInfo";
19
+ endCursor?: string | null;
20
+ hasNextPage?: boolean | null;
21
+ hasPreviousPage?: boolean | null;
22
+ startCursor?: string | null;
23
+ } | null | undefined;
24
+ };
25
+ export {};
@@ -0,0 +1,46 @@
1
+ import { useQuery } from "@apollo/client/react";
2
+ import { metaobjectEntriesQuery } from "../api/query.js";
3
+ const useMetaobjectEntries = (props = {})=>{
4
+ const { skip, first, query, filterKeys } = props;
5
+ const { data, loading: isLoadingMetaobjectEntries, error, fetchMore } = useQuery(metaobjectEntriesQuery, {
6
+ skip,
7
+ variables: {
8
+ first,
9
+ query,
10
+ filterKeys
11
+ }
12
+ });
13
+ const metaobjectEntries = data?.metaobjectEntries?.edges?.map((edge)=>edge?.node).filter((node)=>null != node);
14
+ const pageInfo = data?.metaobjectEntries?.pageInfo;
15
+ const fetchMoreMetaobjectEntries = ()=>{
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.metaobjectEntries?.edges || !prev.metaobjectEntries?.edges) return prev;
26
+ return {
27
+ metaobjectEntries: {
28
+ ...fetchMoreResult.metaobjectEntries,
29
+ edges: [
30
+ ...prev.metaobjectEntries.edges,
31
+ ...fetchMoreResult.metaobjectEntries.edges
32
+ ]
33
+ }
34
+ };
35
+ }
36
+ });
37
+ };
38
+ return {
39
+ metaobjectEntries,
40
+ isLoadingMetaobjectEntries,
41
+ error,
42
+ fetchMoreMetaobjectEntries,
43
+ pageInfo
44
+ };
45
+ };
46
+ export { useMetaobjectEntries };
@@ -0,0 +1,10 @@
1
+ type Props = {
2
+ title?: string;
3
+ initialIds?: string[];
4
+ limit?: number;
5
+ metaobjects?: string[];
6
+ onClose?: () => void;
7
+ onOk?: (linklist: string[]) => void;
8
+ };
9
+ declare const MetaobjectEntries: ({ title, initialIds, limit, metaobjects, onClose, onOk }: Props) => import("react/jsx-runtime").JSX.Element;
10
+ export default MetaobjectEntries;
@@ -0,0 +1,108 @@
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, InlineStack, Input, Modal, Spinner, Text } from "@soppiya/elementus";
5
+ import classnames from "classnames";
6
+ import lodash from "lodash";
7
+ import { useState } from "react";
8
+ import { useMetaobjectEntries } from "../model/useMetaobjectEntries.js";
9
+ const MetaobjectEntries_MetaobjectEntries = ({ title = "Metaobject entries", initialIds = [], limit = 1 / 0, metaobjects = [], onClose, onOk })=>{
10
+ const [selectedMetaobjectEntries, setSelectedMetaobjectEntries] = useState(initialIds);
11
+ const { query, debounceQuery, onChangeQuery } = useFilterQuery();
12
+ const { metaobjectEntries, isLoadingMetaobjectEntries, fetchMoreMetaobjectEntries, pageInfo } = useMetaobjectEntries({
13
+ first: 20,
14
+ query: debounceQuery,
15
+ filterKeys: {
16
+ metaobjects: metaobjects ?? []
17
+ }
18
+ });
19
+ const isReached = limit !== 1 / 0 && selectedMetaobjectEntries.length >= limit;
20
+ const isDisabled = limit !== 1 / 0 && selectedMetaobjectEntries.length > limit;
21
+ const handleSelectedMetaobjectEntries = (metaobjectEntryId)=>{
22
+ if (selectedMetaobjectEntries?.includes(metaobjectEntryId)) return void setSelectedMetaobjectEntries((prev)=>prev?.filter((id)=>metaobjectEntryId !== id));
23
+ if (isReached) return;
24
+ setSelectedMetaobjectEntries((prev)=>[
25
+ ...prev,
26
+ metaobjectEntryId
27
+ ]);
28
+ };
29
+ const handleOk = ()=>{
30
+ if (lodash.isFunction(onOk)) onOk(selectedMetaobjectEntries);
31
+ };
32
+ const ButtonJSX = /*#__PURE__*/ jsx(InlineStack, {
33
+ justifyContent: "end",
34
+ children: /*#__PURE__*/ jsx(Button, {
35
+ disabled: lodash.isEmpty(selectedMetaobjectEntries) || isDisabled,
36
+ onClick: handleOk,
37
+ children: "Add"
38
+ })
39
+ });
40
+ return /*#__PURE__*/ jsx(Modal, {
41
+ open: true,
42
+ title: title,
43
+ bodyPadding: 0,
44
+ buttons: ButtonJSX,
45
+ onClose: onClose,
46
+ children: /*#__PURE__*/ jsxs(BlockStack, {
47
+ children: [
48
+ /*#__PURE__*/ jsx(Box, {
49
+ padding: 60,
50
+ children: /*#__PURE__*/ jsx(Input, {
51
+ size: "sm",
52
+ type: "search",
53
+ value: query ?? "",
54
+ onChange: (event)=>onChangeQuery(event.target.value)
55
+ })
56
+ }),
57
+ isLoadingMetaobjectEntries ? /*#__PURE__*/ jsx(InlineStack, {
58
+ justifyContent: "center",
59
+ padding: 80,
60
+ children: /*#__PURE__*/ jsx(Spinner, {
61
+ size: "md"
62
+ })
63
+ }) : /*#__PURE__*/ jsxs(BlockStack, {
64
+ children: [
65
+ metaobjectEntries?.map((metaobjectEntry)=>/*#__PURE__*/ jsxs(InlineStack, {
66
+ stack: "full",
67
+ className: classnames('lg:cursor-pointer border-t border-t-[#ebebeb]!', {
68
+ 'bg-[#f1f1f1ab] cursor-default!': !selectedMetaobjectEntries.includes(metaobjectEntry._id) && isReached
69
+ }),
70
+ gapX: 60,
71
+ padding: 60,
72
+ onClick: ()=>handleSelectedMetaobjectEntries(String(metaobjectEntry._id)),
73
+ children: [
74
+ /*#__PURE__*/ jsx(InlineStack, {
75
+ alignItems: "center",
76
+ gapX: 60,
77
+ children: /*#__PURE__*/ jsx(Box, {
78
+ children: /*#__PURE__*/ jsx(Checkbox, {
79
+ variant: "primary",
80
+ disabled: !selectedMetaobjectEntries.includes(metaobjectEntry._id) && isReached,
81
+ checked: selectedMetaobjectEntries.includes(String(metaobjectEntry._id)),
82
+ onChange: ()=>{}
83
+ })
84
+ })
85
+ }),
86
+ /*#__PURE__*/ jsx(BlockStack, {
87
+ gapY: 30,
88
+ justifyContent: "center",
89
+ children: /*#__PURE__*/ jsx(Text, {
90
+ size: "sm",
91
+ color: "secondary",
92
+ truncate: "truncate-1",
93
+ children: metaobjectEntry.title
94
+ })
95
+ })
96
+ ]
97
+ }, metaobjectEntry._id)),
98
+ pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
99
+ onFetch: fetchMoreMetaobjectEntries
100
+ })
101
+ ]
102
+ })
103
+ ]
104
+ })
105
+ });
106
+ };
107
+ const MetaobjectEntries = MetaobjectEntries_MetaobjectEntries;
108
+ export { MetaobjectEntries as default };
@@ -0,0 +1,15 @@
1
+ declare const meta: {
2
+ title: string;
3
+ component: ({ title, initialIds, limit, metaobjects, onClose, onOk }: {
4
+ title?: string;
5
+ initialIds?: string[];
6
+ limit?: number;
7
+ metaobjects?: string[];
8
+ onClose?: () => void;
9
+ onOk?: (linklist: string[]) => void;
10
+ }) => import("react/jsx-runtime").JSX.Element;
11
+ };
12
+ export default meta;
13
+ export declare const Default: {
14
+ args: {};
15
+ };
@@ -0,0 +1,10 @@
1
+ import MetaobjectEntries from "./MetaobjectEntries.js";
2
+ const meta = {
3
+ title: "Example/MetaobjectEntries",
4
+ component: MetaobjectEntries
5
+ };
6
+ const MetaobjectEntries_stories = meta;
7
+ const Default = {
8
+ args: {}
9
+ };
10
+ export { Default, MetaobjectEntries_stories as default };