@brushes/component-core 0.0.4 → 0.0.32

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 (47) hide show
  1. package/dist/basic-component/container/index.d.ts +23 -0
  2. package/dist/basic-component/default/index.d.ts +8 -0
  3. package/dist/basic-component/empty/index.d.ts +4 -0
  4. package/dist/basic-component/index.d.ts +3 -0
  5. package/dist/basic-component/resizer/index.d.ts +0 -0
  6. package/dist/basic-component/resizer/numToMeasurement.d.ts +7 -0
  7. package/dist/components/code.d.ts +5 -0
  8. package/dist/components/image.d.ts +5 -0
  9. package/dist/components/index.d.ts +2 -0
  10. package/dist/context/index.d.ts +6 -0
  11. package/dist/index.d.ts +7 -0
  12. package/dist/setting/basic.d.ts +7 -0
  13. package/dist/setting/index.d.ts +1 -0
  14. package/dist/setting/title.d.ts +4 -0
  15. package/dist/store/commonModule.d.ts +5 -0
  16. package/dist/store/commonStore.d.ts +56 -0
  17. package/dist/store/index.d.ts +2 -0
  18. package/dist/store/rootModule.d.ts +5 -0
  19. package/dist/store/rootStore.d.ts +35 -0
  20. package/dist/store/storeDataConfig.d.ts +0 -0
  21. package/dist/tool/combine.d.ts +1 -0
  22. package/dist/tool/fullpath.d.ts +1 -0
  23. package/dist/tool/index.d.ts +2 -0
  24. package/package.json +2 -2
  25. package/src/basic-component/container/index.tsx +228 -0
  26. package/src/basic-component/default/index.tsx +55 -0
  27. package/src/basic-component/empty/index.tsx +24 -0
  28. package/src/basic-component/index.tsx +4 -0
  29. package/src/basic-component/resizer/index.tsx +270 -0
  30. package/src/basic-component/resizer/numToMeasurement.ts +26 -0
  31. package/src/components/code.tsx +60 -0
  32. package/src/components/image.tsx +78 -0
  33. package/src/components/index.ts +2 -0
  34. package/src/context/index.tsx +10 -0
  35. package/src/index.ts +7 -0
  36. package/src/setting/basic.tsx +91 -0
  37. package/src/setting/index.ts +1 -0
  38. package/src/setting/title.tsx +14 -0
  39. package/src/store/commonModule.tsx +37 -0
  40. package/src/store/commonStore.tsx +103 -0
  41. package/src/store/index.tsx +2 -0
  42. package/src/store/rootModule.tsx +24 -0
  43. package/src/store/rootStore.tsx +56 -0
  44. package/src/store/storeDataConfig.tsx +50 -0
  45. package/src/tool/combine.ts +11 -0
  46. package/src/tool/fullpath.ts +13 -0
  47. package/src/tool/index.tsx +2 -0
@@ -0,0 +1,103 @@
1
+ import { createStore } from 'zustand';
2
+
3
+ export const goodListIntialValue = {
4
+ dataPic: '',
5
+ goodsName: '',
6
+ goodsCamount: 0,
7
+ skuName: '',
8
+ pricesetNprice: 0
9
+ };
10
+
11
+ export const initialValueOrder = {
12
+ contractSettlOpno: 0,
13
+ upmMap: {},
14
+ rebMoney: 0,
15
+ goodsCamount: 0,
16
+ shoppingCountPrice: 0,
17
+ totalDiscountPrice: 0,
18
+ accountsSumPrice: 0,
19
+ discount: 0,
20
+ freight: 0,
21
+ comDisMoney: 0,
22
+ copyComDisMoney: 0,
23
+ shoppingType: '',
24
+ promotionCode: '',
25
+ promotionCodes: ''
26
+ };
27
+
28
+ export type addressInfo = {
29
+ freight: number;
30
+ goodsReceiptMem: string;
31
+ goodsReceiptPhone: string;
32
+ goodsReceiptArrdess: string;
33
+ areaCode: string;
34
+ };
35
+
36
+ export type moduleType = {
37
+ [v: string]: any;
38
+ _ocPoints: Array<any>;
39
+ _ocDiscount: Array<any>;
40
+ _orderAddressInfo: addressInfo;
41
+ _couponList: []; // 订单优惠券列表
42
+ _selectCoupon: []; // 选中的优惠券
43
+ _shoppingList: Array<any>; // 订单商品信息
44
+ _contractGoodsList: Array<typeof goodListIntialValue>; // 确认订单支付模块
45
+ _orderDomainStr: Array<typeof initialValueOrder>; // 确认订单支付模块
46
+ _ocContractSettlList: Array<any>; // 确认订单支付模块
47
+ open?: boolean; //抽屉展示或掩藏
48
+ defaultValue?: object; // 页面模块默认值
49
+ goodNum?: number; // 选择商品数量
50
+ _skuInfo?: object; // sku商品数据
51
+ params?: object; //每个模块的请求参数
52
+ breadList?: []; //面包屑
53
+ };
54
+
55
+ export interface moduleStore {
56
+ // module_id?: number;
57
+ // current?: number;
58
+ // hotelParams?: object;
59
+ // extraParams?: object; //每个模块的扩展参数
60
+ // title?: string;
61
+ moduleStore: moduleType;
62
+ }
63
+
64
+ export interface ModuleState extends moduleStore {
65
+ setModuleStore: (e: Partial<moduleType>) => void;
66
+ }
67
+
68
+ export type ModuleStore = ReturnType<typeof createModuleStore>;
69
+
70
+ export const createModuleStore = (initProps?: Partial<moduleStore>) => {
71
+ const DEFAULT_PROPS: moduleStore = {
72
+ moduleStore: {
73
+ _ocDiscount: [],
74
+ _ocPoints: [],
75
+ _couponList: [],
76
+ _selectCoupon: [], // 选中的优惠券
77
+ _shoppingList: [], // 订单商品信息
78
+ _contractGoodsList: [],
79
+ _orderDomainStr: [],
80
+ _ocContractSettlList: [],
81
+ _orderAddressInfo: {
82
+ freight: 0,
83
+ goodsReceiptMem: '',
84
+ goodsReceiptPhone: '',
85
+ goodsReceiptArrdess: '',
86
+ areaCode: ''
87
+ },
88
+ defaultValue: void 0,
89
+ _skuInfo: {},
90
+ params: {},
91
+ breadList: [],
92
+ open: false
93
+ }
94
+ };
95
+ return createStore<ModuleState>()((set) => ({
96
+ ...DEFAULT_PROPS,
97
+ ...initProps,
98
+ setModuleStore: (store) =>
99
+ set((state) => {
100
+ return { moduleStore: Object.assign(state.moduleStore, store) };
101
+ })
102
+ }));
103
+ };
@@ -0,0 +1,2 @@
1
+ export * from './commonModule';
2
+ export * from './rootModule';
@@ -0,0 +1,24 @@
1
+ import { ModuleRootStore, createRootModuleStore, ModuleRootState, moduleRootStore } from './rootStore';
2
+ import { useRef, useContext, createContext } from 'react';
3
+ import { useStore } from 'zustand';
4
+
5
+ const ModuleContext = createContext<ModuleRootStore | null>(null);
6
+
7
+ type ModuleProviderProps = React.PropsWithChildren<Partial<moduleRootStore>>;
8
+
9
+ // Provider wrapper
10
+ export function ModuleRootProvider({ children, ...props }: ModuleProviderProps) {
11
+ const storeRef = useRef<ModuleRootStore>();
12
+
13
+ if (!storeRef.current) {
14
+ storeRef.current = createRootModuleStore(props);
15
+ }
16
+
17
+ return <ModuleContext.Provider value={storeRef.current}>{children}</ModuleContext.Provider>;
18
+ }
19
+
20
+ export function useModuleRootContext<T>(selector: (state: ModuleRootState) => T): T {
21
+ const store = useContext(ModuleContext);
22
+ if (!store) throw new Error('Missing ModuleContext.Provider in the tree');
23
+ return useStore(store, selector);
24
+ }
@@ -0,0 +1,56 @@
1
+ import { createStore } from 'zustand';
2
+ import { persist, createJSONStorage } from 'zustand/middleware';
3
+
4
+ export type moduleType = {
5
+ [v: string]: any;
6
+ _historyList: Array<any>;
7
+ _themeColor: { colorPrimary: string; colorBgTextHover: string };
8
+ _orderCount: { [v: string]: string | number }; // 订单角标
9
+ _userInfo: { [v: string]: any }; // 用户信息
10
+ _cart: number; // 购物车数据
11
+ };
12
+
13
+ export interface moduleRootStore {
14
+ // module_id?: number;
15
+ // current?: number;
16
+ // hotelParams?: object;
17
+ // extraParams?: object; //每个模块的扩展参数
18
+ // title?: string;
19
+ rootStore: moduleType;
20
+ }
21
+
22
+ export interface ModuleRootState extends moduleRootStore {
23
+ setModuleRootStore: (e: Partial<moduleType>) => void;
24
+ }
25
+
26
+ export type ModuleRootStore = ReturnType<typeof createRootModuleStore>;
27
+
28
+ export const createRootModuleStore = (initProps?: Partial<moduleRootStore>) => {
29
+ const DEFAULT_PROPS: moduleRootStore = {
30
+ rootStore: {
31
+ _userInfo: {},
32
+ _historyList: [],
33
+ _themeColor: { colorPrimary: '#1677ff', colorBgTextHover: '#e6r4ff' },
34
+ _orderCount: {},
35
+ _cart: 0,
36
+ _webStore: {},
37
+ _menuChildren: []
38
+ }
39
+ };
40
+ return createStore<ModuleRootState>()(
41
+ persist(
42
+ (set) => ({
43
+ ...DEFAULT_PROPS,
44
+ ...initProps,
45
+ setModuleRootStore: (store) =>
46
+ set((state) => {
47
+ return { rootStore: Object.assign(state.rootStore, store) };
48
+ })
49
+ }),
50
+ {
51
+ name: 'root-storage', // 存储的 key 名
52
+ storage: createJSONStorage(() => localStorage) // (optional) by default, 'localStorage' is used
53
+ }
54
+ )
55
+ );
56
+ };
@@ -0,0 +1,50 @@
1
+ // import type { FieldType } from '@brushes/form';
2
+ // import { useModuleContext } from './commonModule';
3
+ // import markdownit from 'markdown-it';
4
+ //
5
+ // const md = markdownit({
6
+ // tables: true,
7
+ // html: true, // 在源码中启用 HTML 标签
8
+ // xhtmlOut: false, // 使用 '/' 来闭合单标签 (比如 <br />)。
9
+ // // 这个选项只对完全的 CommonMark 模式兼容。
10
+ // breaks: true, // 转换段落里的 '\n' 到 <br>。
11
+ // langPrefix: 'language-', // 给围栏代码块的 CSS 语言前缀。对于额外的高亮代码非常有用。
12
+ // linkify: true, // 将类似 URL 的文本自动转换为链接。
13
+ //
14
+ // // 启用一些语言中立的替换 + 引号美化
15
+ // typographer: false,
16
+ //
17
+ // // 双 + 单引号替换对,当 typographer 启用时。
18
+ // // 或者智能引号等,可以是 String 或 Array。
19
+ // //
20
+ // // 比方说,你可以支持 '«»„“' 给俄罗斯人使用, '„“‚‘' 给德国人使用。
21
+ // // 还有 ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] 给法国人使用(包括 nbsp)。
22
+ // quotes: '“”‘’',
23
+ //
24
+ // // 高亮函数,会返回转义的HTML。
25
+ // // 或 '' 如果源字符串未更改,则应在外部进行转义。
26
+ // // 如果结果以 <pre ... 开头,内部包装器则会跳过。
27
+ // highlight: function (/*str, lang*/) {
28
+ // return '';
29
+ // }
30
+ // });
31
+ //
32
+ // const StoreJsx = () => {
33
+ // const moduleStore = useModuleContext((s) => s.moduleStore);
34
+ // return (
35
+ // <>
36
+ // <p>当前模块数据</p>
37
+ // <div className={'markdown-body 123'} dangerouslySetInnerHTML={{ __html: md.render(JSON.stringify(moduleStore)) }}></div>
38
+ // </>
39
+ // );
40
+ // };
41
+ // export const storeConfig: FieldType[] = [
42
+ // {
43
+ // label: '',
44
+ // name: '___store',
45
+ // type: 'slot',
46
+ // extraProps: {
47
+ // render: StoreJsx
48
+ // }
49
+ // }
50
+ // ];
@@ -0,0 +1,11 @@
1
+ export function combine(array: Array<any>) {
2
+ array.forEach((item) => {
3
+ try {
4
+ const { Component, setting } = item;
5
+ Component.craft = setting;
6
+ Component.craft.displayName = item.name;
7
+ } catch (e) {
8
+ console.error(e, item);
9
+ }
10
+ });
11
+ }
@@ -0,0 +1,13 @@
1
+ const baseUrl = process.env.REACT_APP_BASE_URL;
2
+ const path = process.env.REACT_IMG_PATH || '';
3
+ export const fullpath = (str: string = '') => {
4
+ let computedPath = str;
5
+ if (!str) return '';
6
+ if (str.startsWith('http')) {
7
+ return str;
8
+ }
9
+ if (!(str.startsWith(path) || str.startsWith(path.slice(1)))) {
10
+ computedPath = path + str;
11
+ }
12
+ return baseUrl + computedPath;
13
+ };
@@ -0,0 +1,2 @@
1
+ export * from './combine';
2
+ export * from './fullpath';