@lasterp/shared 1.0.0-beta.10 → 1.0.0-beta.11
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.cjs +34 -12
- package/dist/index.d.cts +36 -1
- package/dist/index.d.ts +36 -1
- package/dist/index.js +24 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,7 @@ __export(exports_src, {
|
|
|
50
50
|
useFrappePutCall: () => useFrappePutCall,
|
|
51
51
|
useFrappePrefetchDoc: () => useFrappePrefetchDoc,
|
|
52
52
|
useFrappePostCall: () => useFrappePostCall,
|
|
53
|
+
useFrappeGetMeta: () => useFrappeGetMeta,
|
|
53
54
|
useFrappeGetDocList: () => useFrappeGetDocList,
|
|
54
55
|
useFrappeGetDocCount: () => useFrappeGetDocCount,
|
|
55
56
|
useFrappeGetDoc: () => useFrappeGetDoc,
|
|
@@ -536,8 +537,29 @@ var useFrappeUpdateDoc = () => {
|
|
|
536
537
|
reset
|
|
537
538
|
};
|
|
538
539
|
};
|
|
539
|
-
// src/hooks/
|
|
540
|
+
// src/frappe/hooks/meta.ts
|
|
540
541
|
var import_react14 = require("react");
|
|
542
|
+
var import_react_query11 = require("@tanstack/react-query");
|
|
543
|
+
var useFrappeGetMeta = (doctype, options) => {
|
|
544
|
+
const { url, call } = import_react14.useContext(FrappeContext);
|
|
545
|
+
const queryKey = ["meta", url, doctype];
|
|
546
|
+
const { data, error, isLoading, isFetching, refetch } = import_react_query11.useQuery({
|
|
547
|
+
queryKey: ["meta", url, doctype],
|
|
548
|
+
queryFn: () => call.get("lasterp.api.get_meta", { doctype }),
|
|
549
|
+
enabled: !!doctype,
|
|
550
|
+
staleTime: options?.staleTime ?? Infinity,
|
|
551
|
+
retry: options?.retry ?? false
|
|
552
|
+
});
|
|
553
|
+
return {
|
|
554
|
+
data,
|
|
555
|
+
error,
|
|
556
|
+
isLoading,
|
|
557
|
+
isFetching,
|
|
558
|
+
refetch
|
|
559
|
+
};
|
|
560
|
+
};
|
|
561
|
+
// src/hooks/use-variant-selector/hook.ts
|
|
562
|
+
var import_react15 = require("react");
|
|
541
563
|
|
|
542
564
|
// src/hooks/use-variant-selector/utils.ts
|
|
543
565
|
function findVariant(variants, specs, caseInsensitive) {
|
|
@@ -570,21 +592,21 @@ function findVariants(variants, specs, caseInsensitive) {
|
|
|
570
592
|
// src/hooks/use-variant-selector/hook.ts
|
|
571
593
|
var useVariantSelector = (props) => {
|
|
572
594
|
const { variants, attributes, defaultId } = props;
|
|
573
|
-
const [selectedSpecs, setSelectedSpecs] =
|
|
595
|
+
const [selectedSpecs, setSelectedSpecs] = import_react15.useState(() => {
|
|
574
596
|
if (defaultId) {
|
|
575
597
|
const variant = variants.find((v) => v.id === defaultId);
|
|
576
598
|
return variant?.specs || {};
|
|
577
599
|
}
|
|
578
600
|
return {};
|
|
579
601
|
});
|
|
580
|
-
const variantId =
|
|
602
|
+
const variantId = import_react15.useMemo(() => {
|
|
581
603
|
const complete = attributes.every((attr) => selectedSpecs[attr.key]);
|
|
582
604
|
if (!complete)
|
|
583
605
|
return;
|
|
584
606
|
const variant = findVariant(variants, selectedSpecs);
|
|
585
607
|
return variant?.id;
|
|
586
608
|
}, [variants, selectedSpecs, attributes]);
|
|
587
|
-
const options =
|
|
609
|
+
const options = import_react15.useMemo(() => {
|
|
588
610
|
const result = {};
|
|
589
611
|
attributes.forEach((attr, attrIndex) => {
|
|
590
612
|
const constraints = {};
|
|
@@ -607,7 +629,7 @@ var useVariantSelector = (props) => {
|
|
|
607
629
|
});
|
|
608
630
|
return result;
|
|
609
631
|
}, [variants, attributes, selectedSpecs]);
|
|
610
|
-
const onOptionSelect =
|
|
632
|
+
const onOptionSelect = import_react15.useCallback((key, value) => {
|
|
611
633
|
setSelectedSpecs((prev) => {
|
|
612
634
|
const newSpecs = { ...prev, [key]: value };
|
|
613
635
|
const attrIndex = attributes.findIndex((a) => a.key === key);
|
|
@@ -642,7 +664,7 @@ var useVariantSelector = (props) => {
|
|
|
642
664
|
};
|
|
643
665
|
};
|
|
644
666
|
// src/locale/provider.tsx
|
|
645
|
-
var
|
|
667
|
+
var import_react16 = require("react");
|
|
646
668
|
var jsx_runtime2 = require("react/jsx-runtime");
|
|
647
669
|
function translate(message, replace, messages = {}) {
|
|
648
670
|
let translated = messages[message] ?? message;
|
|
@@ -651,15 +673,15 @@ function translate(message, replace, messages = {}) {
|
|
|
651
673
|
});
|
|
652
674
|
return translated;
|
|
653
675
|
}
|
|
654
|
-
var LocaleContext =
|
|
676
|
+
var LocaleContext = import_react16.createContext((message) => message);
|
|
655
677
|
function LocaleProvider({
|
|
656
678
|
method,
|
|
657
679
|
language,
|
|
658
680
|
storage,
|
|
659
681
|
children
|
|
660
682
|
}) {
|
|
661
|
-
const [messages, setMessages] =
|
|
662
|
-
|
|
683
|
+
const [messages, setMessages] = import_react16.useState({});
|
|
684
|
+
import_react16.useEffect(() => {
|
|
663
685
|
if (!storage)
|
|
664
686
|
return;
|
|
665
687
|
const key = `locale:${language}`;
|
|
@@ -669,13 +691,13 @@ function LocaleProvider({
|
|
|
669
691
|
}).catch(() => {});
|
|
670
692
|
}, [language, storage]);
|
|
671
693
|
const { data, isLoading } = useFrappeGetCall(method, { lang: language }, { staleTime: Infinity });
|
|
672
|
-
|
|
694
|
+
import_react16.useEffect(() => {
|
|
673
695
|
if (!data?.message)
|
|
674
696
|
return;
|
|
675
697
|
setMessages(data.message);
|
|
676
698
|
storage?.setItem(`locale:${language}`, JSON.stringify(data.message));
|
|
677
699
|
}, [data, language, storage]);
|
|
678
|
-
const __ =
|
|
700
|
+
const __ = import_react16.useCallback((message, replace) => translate(message, replace, messages), [messages]);
|
|
679
701
|
if (isLoading && Object.keys(messages).length === 0)
|
|
680
702
|
return null;
|
|
681
703
|
return /* @__PURE__ */ jsx_runtime2.jsx(LocaleContext.Provider, {
|
|
@@ -684,7 +706,7 @@ function LocaleProvider({
|
|
|
684
706
|
});
|
|
685
707
|
}
|
|
686
708
|
function useLocale() {
|
|
687
|
-
const __ =
|
|
709
|
+
const __ = import_react16.useContext(LocaleContext);
|
|
688
710
|
return { __ };
|
|
689
711
|
}
|
|
690
712
|
// src/utils/char.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -97,6 +97,15 @@ interface Page {
|
|
|
97
97
|
hero?: Hero;
|
|
98
98
|
blocks: Block[];
|
|
99
99
|
}
|
|
100
|
+
interface WorkspaceSidebar {
|
|
101
|
+
label: string;
|
|
102
|
+
header_icon: string;
|
|
103
|
+
items: WorkspaceSidebarItem[];
|
|
104
|
+
}
|
|
105
|
+
interface WorkspaceSidebarItem {
|
|
106
|
+
label: string;
|
|
107
|
+
link_to: string;
|
|
108
|
+
}
|
|
100
109
|
import { FrappeApp, FrappeAuth, FrappeCall } from "frappe-js-sdk";
|
|
101
110
|
import { FrappeDB } from "frappe-js-sdk/lib/db";
|
|
102
111
|
import { FrappeFileUpload } from "frappe-js-sdk/lib/file";
|
|
@@ -586,6 +595,32 @@ declare const useFrappeUpdateDoc: <T = any>() => {
|
|
|
586
595
|
isCompleted: boolean;
|
|
587
596
|
reset: () => void;
|
|
588
597
|
};
|
|
598
|
+
interface FrappeMeta {
|
|
599
|
+
fields: FrappeMetaField[];
|
|
600
|
+
permissions: {
|
|
601
|
+
can_select: boolean;
|
|
602
|
+
can_read: boolean;
|
|
603
|
+
can_write: boolean;
|
|
604
|
+
can_create: boolean;
|
|
605
|
+
can_delete: boolean;
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
interface FrappeMetaField {
|
|
609
|
+
label: string;
|
|
610
|
+
fieldname: string;
|
|
611
|
+
read_only: boolean;
|
|
612
|
+
set_only_once: boolean;
|
|
613
|
+
}
|
|
614
|
+
declare const useFrappeGetMeta: <FrappeMeta>(doctype: string, options?: {
|
|
615
|
+
staleTime?: number;
|
|
616
|
+
retry?: boolean | number;
|
|
617
|
+
}) => {
|
|
618
|
+
data: FrappeMeta | undefined;
|
|
619
|
+
error: FrappeError | null;
|
|
620
|
+
isLoading: boolean;
|
|
621
|
+
isFetching: boolean;
|
|
622
|
+
refetch: () => void;
|
|
623
|
+
};
|
|
589
624
|
interface VariantSelectorProps<T extends {
|
|
590
625
|
id: string;
|
|
591
626
|
specs: Record<string, string>;
|
|
@@ -657,4 +692,4 @@ interface ProductContext {
|
|
|
657
692
|
}
|
|
658
693
|
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
659
694
|
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
660
|
-
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, ItemVariant, Item, Hero, Header, Globals, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
|
695
|
+
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, ItemVariant, Item, Hero, Header, Globals, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
package/dist/index.d.ts
CHANGED
|
@@ -97,6 +97,15 @@ interface Page {
|
|
|
97
97
|
hero?: Hero;
|
|
98
98
|
blocks: Block[];
|
|
99
99
|
}
|
|
100
|
+
interface WorkspaceSidebar {
|
|
101
|
+
label: string;
|
|
102
|
+
header_icon: string;
|
|
103
|
+
items: WorkspaceSidebarItem[];
|
|
104
|
+
}
|
|
105
|
+
interface WorkspaceSidebarItem {
|
|
106
|
+
label: string;
|
|
107
|
+
link_to: string;
|
|
108
|
+
}
|
|
100
109
|
import { FrappeApp, FrappeAuth, FrappeCall } from "frappe-js-sdk";
|
|
101
110
|
import { FrappeDB } from "frappe-js-sdk/lib/db";
|
|
102
111
|
import { FrappeFileUpload } from "frappe-js-sdk/lib/file";
|
|
@@ -586,6 +595,32 @@ declare const useFrappeUpdateDoc: <T = any>() => {
|
|
|
586
595
|
isCompleted: boolean;
|
|
587
596
|
reset: () => void;
|
|
588
597
|
};
|
|
598
|
+
interface FrappeMeta {
|
|
599
|
+
fields: FrappeMetaField[];
|
|
600
|
+
permissions: {
|
|
601
|
+
can_select: boolean;
|
|
602
|
+
can_read: boolean;
|
|
603
|
+
can_write: boolean;
|
|
604
|
+
can_create: boolean;
|
|
605
|
+
can_delete: boolean;
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
interface FrappeMetaField {
|
|
609
|
+
label: string;
|
|
610
|
+
fieldname: string;
|
|
611
|
+
read_only: boolean;
|
|
612
|
+
set_only_once: boolean;
|
|
613
|
+
}
|
|
614
|
+
declare const useFrappeGetMeta: <FrappeMeta>(doctype: string, options?: {
|
|
615
|
+
staleTime?: number;
|
|
616
|
+
retry?: boolean | number;
|
|
617
|
+
}) => {
|
|
618
|
+
data: FrappeMeta | undefined;
|
|
619
|
+
error: FrappeError | null;
|
|
620
|
+
isLoading: boolean;
|
|
621
|
+
isFetching: boolean;
|
|
622
|
+
refetch: () => void;
|
|
623
|
+
};
|
|
589
624
|
interface VariantSelectorProps<T extends {
|
|
590
625
|
id: string;
|
|
591
626
|
specs: Record<string, string>;
|
|
@@ -657,4 +692,4 @@ interface ProductContext {
|
|
|
657
692
|
}
|
|
658
693
|
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
659
694
|
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
660
|
-
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, ItemVariant, Item, Hero, Header, Globals, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
|
695
|
+
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, LocaleProvider, ItemVariant, Item, Hero, Header, Globals, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
package/dist/index.js
CHANGED
|
@@ -465,6 +465,27 @@ var useFrappeUpdateDoc = () => {
|
|
|
465
465
|
reset
|
|
466
466
|
};
|
|
467
467
|
};
|
|
468
|
+
// src/frappe/hooks/meta.ts
|
|
469
|
+
import { useContext as useContext12 } from "react";
|
|
470
|
+
import { useQuery as useQuery6 } from "@tanstack/react-query";
|
|
471
|
+
var useFrappeGetMeta = (doctype, options) => {
|
|
472
|
+
const { url, call } = useContext12(FrappeContext);
|
|
473
|
+
const queryKey = ["meta", url, doctype];
|
|
474
|
+
const { data, error, isLoading, isFetching, refetch } = useQuery6({
|
|
475
|
+
queryKey: ["meta", url, doctype],
|
|
476
|
+
queryFn: () => call.get("lasterp.api.get_meta", { doctype }),
|
|
477
|
+
enabled: !!doctype,
|
|
478
|
+
staleTime: options?.staleTime ?? Infinity,
|
|
479
|
+
retry: options?.retry ?? false
|
|
480
|
+
});
|
|
481
|
+
return {
|
|
482
|
+
data,
|
|
483
|
+
error,
|
|
484
|
+
isLoading,
|
|
485
|
+
isFetching,
|
|
486
|
+
refetch
|
|
487
|
+
};
|
|
488
|
+
};
|
|
468
489
|
// src/hooks/use-variant-selector/hook.ts
|
|
469
490
|
import { useCallback as useCallback4, useMemo as useMemo2, useState as useState5 } from "react";
|
|
470
491
|
|
|
@@ -574,7 +595,7 @@ var useVariantSelector = (props) => {
|
|
|
574
595
|
import {
|
|
575
596
|
createContext as createContext2,
|
|
576
597
|
useCallback as useCallback5,
|
|
577
|
-
useContext as
|
|
598
|
+
useContext as useContext13,
|
|
578
599
|
useEffect as useEffect4,
|
|
579
600
|
useState as useState6
|
|
580
601
|
} from "react";
|
|
@@ -619,7 +640,7 @@ function LocaleProvider({
|
|
|
619
640
|
});
|
|
620
641
|
}
|
|
621
642
|
function useLocale() {
|
|
622
|
-
const __ =
|
|
643
|
+
const __ = useContext13(LocaleContext);
|
|
623
644
|
return { __ };
|
|
624
645
|
}
|
|
625
646
|
// src/utils/char.ts
|
|
@@ -635,6 +656,7 @@ export {
|
|
|
635
656
|
useFrappePutCall,
|
|
636
657
|
useFrappePrefetchDoc,
|
|
637
658
|
useFrappePostCall,
|
|
659
|
+
useFrappeGetMeta,
|
|
638
660
|
useFrappeGetDocList,
|
|
639
661
|
useFrappeGetDocCount,
|
|
640
662
|
useFrappeGetDoc,
|