@knockout-js/layout 0.0.4-beta.0 → 0.1.0
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/es2017/components/_util/index.d.ts +40 -0
- package/es2017/components/_util/index.js +69 -0
- package/es2017/components/_util/index.js.map +1 -0
- package/es2017/components/aggregate-menu/index.d.ts +37 -0
- package/es2017/components/aggregate-menu/index.js +372 -0
- package/es2017/components/aggregate-menu/index.js.map +1 -0
- package/es2017/components/aggregate-menu/index.module.css +190 -0
- package/es2017/components/aggregate-menu/locale/en_US.d.ts +3 -0
- package/es2017/components/{gather-menu → aggregate-menu}/locale/en_US.js +3 -1
- package/es2017/components/aggregate-menu/locale/en_US.js.map +1 -0
- package/es2017/components/aggregate-menu/locale/zh_CN.d.ts +3 -0
- package/es2017/components/{gather-menu → aggregate-menu}/locale/zh_CN.js +3 -1
- package/es2017/components/aggregate-menu/locale/zh_CN.js.map +1 -0
- package/es2017/components/collect-providers/index.d.ts +9 -1
- package/es2017/components/collect-providers/index.js +5 -3
- package/es2017/components/collect-providers/index.js.map +1 -1
- package/es2017/components/i18n-dropdown/index.d.ts +1 -1
- package/es2017/components/i18n-dropdown/index.js +2 -2
- package/es2017/components/i18n-dropdown/index.js.map +1 -1
- package/es2017/components/index.d.ts +7 -2
- package/es2017/components/index.js +8 -2
- package/es2017/components/index.js.map +1 -1
- package/es2017/components/layout/index.d.ts +12 -6
- package/es2017/components/layout/index.js +26 -39
- package/es2017/components/layout/index.js.map +1 -1
- package/es2017/components/locale/en_US.js +4 -2
- package/es2017/components/locale/en_US.js.map +1 -1
- package/es2017/components/locale/index.d.ts +4 -17
- package/es2017/components/locale/index.js +3 -23
- package/es2017/components/locale/index.js.map +1 -1
- package/es2017/components/locale/zh_CN.js +4 -2
- package/es2017/components/locale/zh_CN.js.map +1 -1
- package/es2017/components/provider/index.d.ts +33 -0
- package/es2017/components/provider/index.js +49 -0
- package/es2017/components/provider/index.js.map +1 -0
- package/es2017/components/tenant-dropdown/index.js +1 -1
- package/es2017/components/tenant-dropdown/index.js.map +1 -1
- package/es2017/components/upload-file/index.d.ts +57 -0
- package/es2017/components/upload-file/index.js +3 -0
- package/es2017/components/upload-file/index.js.map +1 -0
- package/es2017/components/upload-file/index.module.css +13 -0
- package/es2017/components/upload-file/locale/en_US.d.ts +3 -0
- package/es2017/components/upload-file/locale/en_US.js +14 -0
- package/es2017/components/upload-file/locale/en_US.js.map +1 -0
- package/es2017/components/upload-file/locale/zh_CN.d.ts +3 -0
- package/es2017/components/upload-file/locale/zh_CN.js +14 -0
- package/es2017/components/upload-file/locale/zh_CN.js.map +1 -0
- package/es2017/components/upload-file/uploadAvatar.d.ts +4 -0
- package/es2017/components/upload-file/uploadAvatar.js +93 -0
- package/es2017/components/upload-file/uploadAvatar.js.map +1 -0
- package/es2017/components/upload-file/uploadMultiple.d.ts +4 -0
- package/es2017/components/upload-file/uploadMultiple.js +155 -0
- package/es2017/components/upload-file/uploadMultiple.js.map +1 -0
- package/es2017/components/upload-file/uploadTemp.d.ts +9 -0
- package/es2017/components/upload-file/uploadTemp.js +167 -0
- package/es2017/components/upload-file/uploadTemp.js.map +1 -0
- package/esm/components/_util/index.d.ts +40 -0
- package/esm/components/_util/index.js +75 -0
- package/esm/components/_util/index.js.map +1 -0
- package/esm/components/aggregate-menu/index.d.ts +37 -0
- package/esm/components/aggregate-menu/index.js +521 -0
- package/esm/components/aggregate-menu/index.js.map +1 -0
- package/esm/components/aggregate-menu/index.module.css +190 -0
- package/esm/components/aggregate-menu/locale/en_US.d.ts +3 -0
- package/esm/components/{gather-menu → aggregate-menu}/locale/en_US.js +3 -1
- package/esm/components/aggregate-menu/locale/en_US.js.map +1 -0
- package/esm/components/aggregate-menu/locale/zh_CN.d.ts +3 -0
- package/esm/components/{gather-menu → aggregate-menu}/locale/zh_CN.js +3 -1
- package/esm/components/aggregate-menu/locale/zh_CN.js.map +1 -0
- package/esm/components/collect-providers/index.d.ts +9 -1
- package/esm/components/collect-providers/index.js +5 -3
- package/esm/components/collect-providers/index.js.map +1 -1
- package/esm/components/i18n-dropdown/index.d.ts +1 -1
- package/esm/components/i18n-dropdown/index.js +2 -2
- package/esm/components/i18n-dropdown/index.js.map +1 -1
- package/esm/components/index.d.ts +7 -2
- package/esm/components/index.js +8 -2
- package/esm/components/index.js.map +1 -1
- package/esm/components/layout/index.d.ts +12 -6
- package/esm/components/layout/index.js +26 -44
- package/esm/components/layout/index.js.map +1 -1
- package/esm/components/locale/en_US.js +4 -2
- package/esm/components/locale/en_US.js.map +1 -1
- package/esm/components/locale/index.d.ts +4 -17
- package/esm/components/locale/index.js +3 -23
- package/esm/components/locale/index.js.map +1 -1
- package/esm/components/locale/zh_CN.js +4 -2
- package/esm/components/locale/zh_CN.js.map +1 -1
- package/esm/components/provider/index.d.ts +33 -0
- package/esm/components/provider/index.js +49 -0
- package/esm/components/provider/index.js.map +1 -0
- package/esm/components/tenant-dropdown/index.js +1 -1
- package/esm/components/tenant-dropdown/index.js.map +1 -1
- package/esm/components/upload-file/index.d.ts +57 -0
- package/esm/components/upload-file/index.js +3 -0
- package/esm/components/upload-file/index.js.map +1 -0
- package/esm/components/upload-file/index.module.css +13 -0
- package/esm/components/upload-file/locale/en_US.d.ts +3 -0
- package/esm/components/upload-file/locale/en_US.js +14 -0
- package/esm/components/upload-file/locale/en_US.js.map +1 -0
- package/esm/components/upload-file/locale/zh_CN.d.ts +3 -0
- package/esm/components/upload-file/locale/zh_CN.js +14 -0
- package/esm/components/upload-file/locale/zh_CN.js.map +1 -0
- package/esm/components/upload-file/uploadAvatar.d.ts +4 -0
- package/esm/components/upload-file/uploadAvatar.js +191 -0
- package/esm/components/upload-file/uploadAvatar.js.map +1 -0
- package/esm/components/upload-file/uploadMultiple.d.ts +4 -0
- package/esm/components/upload-file/uploadMultiple.js +308 -0
- package/esm/components/upload-file/uploadMultiple.js.map +1 -0
- package/esm/components/upload-file/uploadTemp.d.ts +9 -0
- package/esm/components/upload-file/uploadTemp.js +293 -0
- package/esm/components/upload-file/uploadTemp.js.map +1 -0
- package/package.json +8 -4
- package/es2017/components/gather-menu/index.d.ts +0 -34
- package/es2017/components/gather-menu/index.js +0 -278
- package/es2017/components/gather-menu/index.js.map +0 -1
- package/es2017/components/gather-menu/index.module.css +0 -120
- package/es2017/components/gather-menu/locale/en_US.d.ts +0 -3
- package/es2017/components/gather-menu/locale/en_US.js.map +0 -1
- package/es2017/components/gather-menu/locale/zh_CN.d.ts +0 -3
- package/es2017/components/gather-menu/locale/zh_CN.js.map +0 -1
- package/esm/components/gather-menu/index.d.ts +0 -34
- package/esm/components/gather-menu/index.js +0 -320
- package/esm/components/gather-menu/index.js.map +0 -1
- package/esm/components/gather-menu/index.module.css +0 -120
- package/esm/components/gather-menu/locale/en_US.d.ts +0 -3
- package/esm/components/gather-menu/locale/en_US.js.map +0 -1
- package/esm/components/gather-menu/locale/zh_CN.d.ts +0 -3
- package/esm/components/gather-menu/locale/zh_CN.js.map +0 -1
|
@@ -2,14 +2,16 @@ import ThemeSwitch from "../theme-switch/locale/en_US";
|
|
|
2
2
|
import LeavePrompt from "../leave-prompt/locale/en_US";
|
|
3
3
|
import AvatarDropdown from "../avatar-dropdown/locale/en_US";
|
|
4
4
|
import TenantDropdown from "../tenant-dropdown/locale/en_US";
|
|
5
|
-
import
|
|
5
|
+
import AggregateMenu from "../aggregate-menu/locale/en_US";
|
|
6
|
+
import UploadFile from "../upload-file/locale/en_US";
|
|
6
7
|
var localeValues = {
|
|
7
8
|
locale: "en-us",
|
|
8
9
|
ThemeSwitch: ThemeSwitch,
|
|
9
10
|
LeavePrompt: LeavePrompt,
|
|
10
11
|
AvatarDropdown: AvatarDropdown,
|
|
11
12
|
TenantDropdown: TenantDropdown,
|
|
12
|
-
|
|
13
|
+
AggregateMenu: AggregateMenu,
|
|
14
|
+
UploadFile: UploadFile
|
|
13
15
|
};
|
|
14
16
|
export default localeValues;
|
|
15
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\locale\\en_US.ts"],"sourcesContent":["import { Locale } from \".\";\r\nimport ThemeSwitch from \"../theme-switch/locale/en_US\";\r\nimport LeavePrompt from \"../leave-prompt/locale/en_US\";\r\nimport AvatarDropdown from \"../avatar-dropdown/locale/en_US\";\r\nimport TenantDropdown from \"../tenant-dropdown/locale/en_US\";\r\nimport
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\locale\\en_US.ts"],"sourcesContent":["import { Locale } from \".\";\r\nimport ThemeSwitch from \"../theme-switch/locale/en_US\";\r\nimport LeavePrompt from \"../leave-prompt/locale/en_US\";\r\nimport AvatarDropdown from \"../avatar-dropdown/locale/en_US\";\r\nimport TenantDropdown from \"../tenant-dropdown/locale/en_US\";\r\nimport AggregateMenu from \"../aggregate-menu/locale/en_US\";\r\nimport UploadFile from \"../upload-file/locale/en_US\";\r\n\r\nconst localeValues: Locale = {\r\n locale: 'en-us',\r\n ThemeSwitch,\r\n LeavePrompt,\r\n AvatarDropdown,\r\n TenantDropdown,\r\n AggregateMenu,\r\n UploadFile,\r\n}\r\n\r\nexport default localeValues\r\n"],"names":["ThemeSwitch","LeavePrompt","AvatarDropdown","TenantDropdown","AggregateMenu","UploadFile","localeValues","locale"],"mappings":"AACA,OAAOA,iBAAiB,+BAA+B;AACvD,OAAOC,iBAAiB,+BAA+B;AACvD,OAAOC,oBAAoB,kCAAkC;AAC7D,OAAOC,oBAAoB,kCAAkC;AAC7D,OAAOC,mBAAmB,iCAAiC;AAC3D,OAAOC,gBAAgB,8BAA8B;AAErD,IAAMC,eAAuB;IAC3BC,QAAQ;IACRP,aAAAA;IACAC,aAAAA;IACAC,gBAAAA;IACAC,gBAAAA;IACAC,eAAAA;IACAC,YAAAA;AACF;AAEA,eAAeC,aAAY"}
|
|
@@ -1,31 +1,18 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { TenantDropdownLocale } from '../tenant-dropdown';
|
|
3
2
|
import { ThemeSwitchLocale } from '../theme-switch';
|
|
4
3
|
import { LeavePromptLocale } from '../leave-prompt';
|
|
5
4
|
import { AvatarDropdownLocale } from '../avatar-dropdown';
|
|
6
|
-
import {
|
|
5
|
+
import { AggregateMenuLocale } from "../aggregate-menu";
|
|
6
|
+
import { UploadFileLocale } from "../upload-file";
|
|
7
7
|
export interface Locale {
|
|
8
8
|
locale: string;
|
|
9
9
|
ThemeSwitch: ThemeSwitchLocale;
|
|
10
10
|
LeavePrompt: LeavePromptLocale;
|
|
11
11
|
AvatarDropdown: AvatarDropdownLocale;
|
|
12
12
|
TenantDropdown: TenantDropdownLocale;
|
|
13
|
-
|
|
13
|
+
AggregateMenu: AggregateMenuLocale;
|
|
14
|
+
UploadFile: UploadFileLocale;
|
|
14
15
|
}
|
|
15
|
-
export declare enum LocaleType {
|
|
16
|
-
zhCN = "zh-CN",
|
|
17
|
-
enUS = "en-US"
|
|
18
|
-
}
|
|
19
|
-
export interface BasicProviderProps {
|
|
20
|
-
locale: LocaleType;
|
|
21
|
-
children?: React.ReactNode;
|
|
22
|
-
}
|
|
23
|
-
export declare const BasicContext: import("react").Context<BasicProviderProps>;
|
|
24
|
-
/**
|
|
25
|
-
* 组件上使用
|
|
26
|
-
*/
|
|
27
|
-
declare const _default: (props: BasicProviderProps) => JSX.Element;
|
|
28
|
-
export default _default;
|
|
29
16
|
export type LocaleComponentName = Exclude<keyof Locale, 'locale'>;
|
|
30
17
|
/**
|
|
31
18
|
* hook
|
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { createContext, useContext } from "react";
|
|
2
|
+
import { useContext } from "react";
|
|
4
3
|
import zhCN from "./zh_CN";
|
|
5
4
|
import enUS from "./en_US";
|
|
6
|
-
|
|
7
|
-
(function(LocaleType) {
|
|
8
|
-
LocaleType["zhCN"] = "zh-CN";
|
|
9
|
-
LocaleType["enUS"] = "en-US";
|
|
10
|
-
})(LocaleType || (LocaleType = {}));
|
|
11
|
-
// 定义语言上下文
|
|
12
|
-
export var BasicContext = /*#__PURE__*/ createContext({
|
|
13
|
-
locale: LocaleType.zhCN
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* 组件上使用
|
|
17
|
-
*/ export default function(props) {
|
|
18
|
-
var locale = props.locale, children = props.children;
|
|
19
|
-
return /*#__PURE__*/ _jsx(BasicContext.Provider, {
|
|
20
|
-
value: {
|
|
21
|
-
locale: locale
|
|
22
|
-
},
|
|
23
|
-
children: children
|
|
24
|
-
});
|
|
25
|
-
};
|
|
5
|
+
import { Context, LocaleType } from "../provider/index";
|
|
26
6
|
/**
|
|
27
7
|
* hook
|
|
28
8
|
* @param componentName
|
|
29
9
|
* @returns
|
|
30
10
|
*/ export var useLocale = function(componentName) {
|
|
31
|
-
var ctx = useContext(
|
|
11
|
+
var ctx = useContext(Context);
|
|
32
12
|
if (ctx.locale === LocaleType.enUS) return _object_spread({}, enUS[componentName]);
|
|
33
13
|
// 默认zhCN
|
|
34
14
|
return _object_spread({}, zhCN[componentName]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\locale\\index.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\locale\\index.tsx"],"sourcesContent":["import { useContext } from \"react\";\r\nimport zhCN from \"./zh_CN\";\r\nimport enUS from \"./en_US\";\r\nimport { TenantDropdownLocale } from '../tenant-dropdown';\r\nimport { ThemeSwitchLocale } from '../theme-switch';\r\nimport { LeavePromptLocale } from '../leave-prompt';\r\nimport { AvatarDropdownLocale } from '../avatar-dropdown';\r\nimport { AggregateMenuLocale } from \"../aggregate-menu\";\r\nimport { Context, LocaleType, ProviderProps } from \"../provider\";\r\nimport { UploadFileLocale } from \"../upload-file\";\r\n\r\nexport interface Locale {\r\n locale: string;\r\n ThemeSwitch: ThemeSwitchLocale;\r\n LeavePrompt: LeavePromptLocale;\r\n AvatarDropdown: AvatarDropdownLocale;\r\n TenantDropdown: TenantDropdownLocale;\r\n AggregateMenu: AggregateMenuLocale;\r\n UploadFile: UploadFileLocale;\r\n}\r\n\r\n\r\n\r\nexport type LocaleComponentName = Exclude<keyof Locale, 'locale'>;\r\n\r\n/**\r\n * hook\r\n * @param componentName\r\n * @returns\r\n */\r\nexport const useLocale = <C extends LocaleComponentName>(componentName: C) => {\r\n const ctx = useContext<ProviderProps>(Context);\r\n if (ctx.locale === LocaleType.enUS) {\r\n return { ...enUS[componentName] }\r\n }\r\n // 默认zhCN\r\n return { ...zhCN[componentName] }\r\n}\r\n"],"names":["useContext","zhCN","enUS","Context","LocaleType","useLocale","componentName","ctx","locale"],"mappings":";AAAA,SAASA,UAAU,QAAQ,QAAQ;AACnC,OAAOC,UAAU,UAAU;AAC3B,OAAOC,UAAU,UAAU;AAM3B,SAASC,OAAO,EAAEC,UAAU,QAAuB,oBAAc;AAiBjE;;;;CAIC,GACD,OAAO,IAAMC,YAAY,SAAgCC,eAAqB;IAC5E,IAAMC,MAAMP,WAA0BG;IACtC,IAAII,IAAIC,MAAM,KAAKJ,WAAWF,IAAI,EAChC,OAAO,mBAAKA,IAAI,CAACI,cAAc;IAEjC,SAAS;IACT,OAAO,mBAAKL,IAAI,CAACK,cAAc;AACjC,EAAC"}
|
|
@@ -2,14 +2,16 @@ import ThemeSwitch from "../theme-switch/locale/zh_CN";
|
|
|
2
2
|
import LeavePrompt from "../leave-prompt/locale/zh_CN";
|
|
3
3
|
import AvatarDropdown from "../avatar-dropdown/locale/zh_CN";
|
|
4
4
|
import TenantDropdown from "../tenant-dropdown/locale/zh_CN";
|
|
5
|
-
import
|
|
5
|
+
import AggregateMenu from "../aggregate-menu/locale/zh_CN";
|
|
6
|
+
import UploadFile from "../upload-file/locale/zh_CN";
|
|
6
7
|
var localeValues = {
|
|
7
8
|
locale: "zh-cn",
|
|
8
9
|
ThemeSwitch: ThemeSwitch,
|
|
9
10
|
LeavePrompt: LeavePrompt,
|
|
10
11
|
AvatarDropdown: AvatarDropdown,
|
|
11
12
|
TenantDropdown: TenantDropdown,
|
|
12
|
-
|
|
13
|
+
AggregateMenu: AggregateMenu,
|
|
14
|
+
UploadFile: UploadFile
|
|
13
15
|
};
|
|
14
16
|
export default localeValues;
|
|
15
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\locale\\zh_CN.ts"],"sourcesContent":["import { Locale } from \".\";\r\nimport ThemeSwitch from \"../theme-switch/locale/zh_CN\";\r\nimport LeavePrompt from \"../leave-prompt/locale/zh_CN\";\r\nimport AvatarDropdown from \"../avatar-dropdown/locale/zh_CN\";\r\nimport TenantDropdown from \"../tenant-dropdown/locale/zh_CN\";\r\nimport
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\locale\\zh_CN.ts"],"sourcesContent":["import { Locale } from \".\";\r\nimport ThemeSwitch from \"../theme-switch/locale/zh_CN\";\r\nimport LeavePrompt from \"../leave-prompt/locale/zh_CN\";\r\nimport AvatarDropdown from \"../avatar-dropdown/locale/zh_CN\";\r\nimport TenantDropdown from \"../tenant-dropdown/locale/zh_CN\";\r\nimport AggregateMenu from \"../aggregate-menu/locale/zh_CN\";\r\nimport UploadFile from \"../upload-file/locale/zh_CN\";\r\n\r\nconst localeValues: Locale = {\r\n locale: 'zh-cn',\r\n ThemeSwitch,\r\n LeavePrompt,\r\n AvatarDropdown,\r\n TenantDropdown,\r\n AggregateMenu,\r\n UploadFile,\r\n}\r\n\r\nexport default localeValues\r\n"],"names":["ThemeSwitch","LeavePrompt","AvatarDropdown","TenantDropdown","AggregateMenu","UploadFile","localeValues","locale"],"mappings":"AACA,OAAOA,iBAAiB,+BAA+B;AACvD,OAAOC,iBAAiB,+BAA+B;AACvD,OAAOC,oBAAoB,kCAAkC;AAC7D,OAAOC,oBAAoB,kCAAkC;AAC7D,OAAOC,mBAAmB,iCAAiC;AAC3D,OAAOC,gBAAgB,8BAA8B;AAErD,IAAMC,eAAuB;IAC3BC,QAAQ;IACRP,aAAAA;IACAC,aAAAA;IACAC,gBAAAA;IACAC,gBAAAA;IACAC,eAAAA;IACAC,YAAAA;AACF;AAEA,eAAeC,aAAY"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare enum LocaleType {
|
|
3
|
+
zhCN = "zh-CN",
|
|
4
|
+
enUS = "en-US"
|
|
5
|
+
}
|
|
6
|
+
export interface ProviderProps {
|
|
7
|
+
locale?: LocaleType;
|
|
8
|
+
appCode?: string;
|
|
9
|
+
tenantId?: string;
|
|
10
|
+
dark?: boolean;
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare const Context: import("react").Context<ProviderProps>;
|
|
14
|
+
/**
|
|
15
|
+
* 组件上使用
|
|
16
|
+
*/
|
|
17
|
+
declare const _default: (props: ProviderProps) => JSX.Element;
|
|
18
|
+
export default _default;
|
|
19
|
+
/**
|
|
20
|
+
* hook
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare const useTenantId: () => string;
|
|
24
|
+
/**
|
|
25
|
+
* hook
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare const useAppCode: () => string;
|
|
29
|
+
/**
|
|
30
|
+
* hook
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
export declare const useDark: () => boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
|
|
2
|
+
import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs";
|
|
3
|
+
import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
export var LocaleType;
|
|
6
|
+
(function(LocaleType) {
|
|
7
|
+
LocaleType["zhCN"] = "zh-CN";
|
|
8
|
+
LocaleType["enUS"] = "en-US";
|
|
9
|
+
})(LocaleType || (LocaleType = {}));
|
|
10
|
+
// 定义上下文
|
|
11
|
+
export var Context = /*#__PURE__*/ createContext({
|
|
12
|
+
locale: LocaleType.zhCN,
|
|
13
|
+
dark: false
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* 组件上使用
|
|
17
|
+
*/ export default function(props) {
|
|
18
|
+
var children = props.children, resProps = _object_without_properties(props, [
|
|
19
|
+
"children"
|
|
20
|
+
]);
|
|
21
|
+
return /*#__PURE__*/ _jsx(Context.Provider, {
|
|
22
|
+
value: _object_spread({}, resProps),
|
|
23
|
+
children: children
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* hook
|
|
28
|
+
* @returns
|
|
29
|
+
*/ export var useTenantId = function() {
|
|
30
|
+
var ctx = useContext(Context);
|
|
31
|
+
return ctx.tenantId;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* hook
|
|
35
|
+
* @returns
|
|
36
|
+
*/ export var useAppCode = function() {
|
|
37
|
+
var ctx = useContext(Context);
|
|
38
|
+
return ctx.appCode;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* hook
|
|
42
|
+
* @returns
|
|
43
|
+
*/ export var useDark = function() {
|
|
44
|
+
var ctx = useContext(Context);
|
|
45
|
+
var _ctx_dark;
|
|
46
|
+
return (_ctx_dark = ctx.dark) !== null && _ctx_dark !== void 0 ? _ctx_dark : false;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=D:\codeing\git\github\knockout-js\packages\layout\esm\components\provider\index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\provider\\index.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\r\n\r\nexport enum LocaleType {\r\n zhCN = \"zh-CN\",\r\n enUS = \"en-US\",\r\n}\r\n\r\nexport interface ProviderProps {\r\n locale?: LocaleType;\r\n appCode?: string;\r\n tenantId?: string;\r\n dark?: boolean;\r\n children?: React.ReactNode;\r\n}\r\n\r\n// 定义上下文\r\nexport const Context = createContext<ProviderProps>({\r\n locale: LocaleType.zhCN,\r\n dark: false\r\n});\r\n\r\n/**\r\n * 组件上使用\r\n */\r\nexport default (props: ProviderProps) => {\r\n const { children, ...resProps } = props;\r\n return <Context.Provider value={{ ...resProps }}>{children}</Context.Provider>\r\n}\r\n\r\n\r\n/**\r\n * hook\r\n * @returns\r\n */\r\nexport const useTenantId = () => {\r\n const ctx = useContext<ProviderProps>(Context);\r\n return ctx.tenantId\r\n}\r\n\r\n\r\n/**\r\n * hook\r\n * @returns\r\n */\r\nexport const useAppCode = () => {\r\n const ctx = useContext<ProviderProps>(Context);\r\n return ctx.appCode\r\n}\r\n\r\n/**\r\n * hook\r\n * @returns\r\n */\r\nexport const useDark = () => {\r\n const ctx = useContext<ProviderProps>(Context);\r\n return ctx.dark ?? false\r\n}\r\n"],"names":["createContext","useContext","LocaleType","zhCN","enUS","Context","locale","dark","props","children","resProps","Provider","value","useTenantId","ctx","tenantId","useAppCode","appCode","useDark"],"mappings":";;;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAQ;WAE3C;UAAKC,UAAU;IAAVA,WACVC,UAAO;IADGD,WAEVE,UAAO;GAFGF,eAAAA;AAaZ,QAAQ;AACR,OAAO,IAAMG,wBAAUL,cAA6B;IAClDM,QAAQJ,WAAWC,IAAI;IACvBI,MAAM,KAAK;AACb,GAAG;AAEH;;CAEC,GACD,eAAe,SAACC,OAAyB;IACvC,IAAM,AAAEC,WAA0BD,MAA1BC,UAAaC,sCAAaF;QAA1BC;;IACR,qBAAO,KAACJ,QAAQM,QAAQ;QAACC,OAAO,mBAAKF;kBAAaD;;AACpD,EAAC;AAGD;;;CAGC,GACD,OAAO,IAAMI,cAAc,WAAM;IAC/B,IAAMC,MAAMb,WAA0BI;IACtC,OAAOS,IAAIC,QAAQ;AACrB,EAAC;AAGD;;;CAGC,GACD,OAAO,IAAMC,aAAa,WAAM;IAC9B,IAAMF,MAAMb,WAA0BI;IACtC,OAAOS,IAAIG,OAAO;AACpB,EAAC;AAED;;;CAGC,GACD,OAAO,IAAMC,UAAU,WAAM;IAC3B,IAAMJ,MAAMb,WAA0BI;QAC/BS;IAAP,OAAOA,CAAAA,YAAAA,IAAIP,IAAI,cAARO,uBAAAA,YAAY,KAAK;AAC1B,EAAC"}
|
|
@@ -65,7 +65,7 @@ export default function(props) {
|
|
|
65
65
|
});
|
|
66
66
|
}, []);
|
|
67
67
|
useEffect(function() {
|
|
68
|
-
if (document.hidden) {
|
|
68
|
+
if (document.hidden && info && info.id != props.value) {
|
|
69
69
|
var tipStr = locale.switchTipTitle;
|
|
70
70
|
document.title = tipStr;
|
|
71
71
|
document.body.innerHTML = '<div style="width:370px;margin:40px auto 0 auto;">'.concat(tipStr, "</div>");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\tenant-dropdown\\index.tsx"],"sourcesContent":["import { Dropdown, MenuProps, Modal } from 'antd';\r\nimport { useCallback, useEffect, useState } from 'react';\r\nimport styles from './index.module.css';\r\nimport { useLocale } from '../locale';\r\nimport { Org, UserRootOrgsQuery, UserRootOrgsQueryVariables } from '@knockout-js/api';\r\nimport { gql, query } from '@knockout-js/ice-urql/request';\r\nimport { iceUrqlInstance } from '..';\r\n\r\nexport interface TenantDropdownLocale {\r\n switchTipTitle: string;\r\n confirmTitle: string;\r\n confirmContent: string;\r\n}\r\n\r\nexport interface TenantDropdownProps {\r\n /**\r\n * 当前 tenantId\r\n */\r\n value: string;\r\n /**\r\n * 数据源\r\n */\r\n dataSource?: Org[]
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\tenant-dropdown\\index.tsx"],"sourcesContent":["import { Dropdown, MenuProps, Modal } from 'antd';\r\nimport { useCallback, useEffect, useState } from 'react';\r\nimport styles from './index.module.css';\r\nimport { useLocale } from '../locale';\r\nimport { Org, UserRootOrgsQuery, UserRootOrgsQueryVariables } from '@knockout-js/api';\r\nimport { gql, query } from '@knockout-js/ice-urql/request';\r\nimport { iceUrqlInstance } from '..';\r\n\r\nexport interface TenantDropdownLocale {\r\n switchTipTitle: string;\r\n confirmTitle: string;\r\n confirmContent: string;\r\n}\r\n\r\nexport interface TenantDropdownProps {\r\n /**\r\n * 当前 tenantId\r\n */\r\n value: string;\r\n /**\r\n * 数据源\r\n */\r\n dataSource?: Org[];\r\n /**\r\n * value变更事件 (value: string) => void;\r\n */\r\n onChange: (value: string) => void;\r\n}\r\n\r\nconst userRootOrgListQuery = gql(/* GraphQL */`query userRootOrgs{\r\n userRootOrgs{\r\n id,parentID,kind,domain,code,name,status,path,displaySort,countryCode,timezone\r\n }\r\n}`);\r\n\r\nexport default (props: TenantDropdownProps) => {\r\n const locale = useLocale('TenantDropdown'),\r\n [list, setList] = useState<Array<Org>>([]),\r\n [info, setInfo] = useState<Org | undefined>(undefined),\r\n [menu, setMenu] = useState<MenuProps | undefined>(undefined);\r\n\r\n const\r\n getRequest = async () => {\r\n const result = await query<UserRootOrgsQuery, UserRootOrgsQueryVariables>(userRootOrgListQuery, {}, { instanceName: iceUrqlInstance.ucenter });\r\n if (result.data?.userRootOrgs.length) {\r\n const orgList = result.data.userRootOrgs as Org[]\r\n setList(orgList)\r\n }\r\n },\r\n setValue = () => {\r\n setInfo(list.find(item => item.id == props.value));\r\n setMenu({\r\n items: list.filter(item => item?.id != props.value).map(item => {\r\n return {\r\n key: item.id,\r\n label: item.name,\r\n onClick: menuItemClick\r\n };\r\n }),\r\n });\r\n },\r\n menuItemClick = useCallback(({ key }: { key: string }) => {\r\n Modal.confirm({\r\n title: locale.confirmTitle,\r\n content: locale.confirmContent,\r\n onOk: () => {\r\n props.onChange(key)\r\n },\r\n });\r\n }, []);\r\n\r\n useEffect(() => {\r\n if (document.hidden && (info && info.id != props.value)) {\r\n const tipStr = locale.switchTipTitle;\r\n document.title = tipStr;\r\n document.body.innerHTML = `<div style=\"width:370px;margin:40px auto 0 auto;\">${tipStr}</div>`;\r\n window.close();\r\n } else {\r\n setValue()\r\n }\r\n }, [props.value]);\r\n\r\n useEffect(() => {\r\n setValue()\r\n }, [list]);\r\n\r\n useEffect(() => {\r\n if (props.dataSource) {\r\n setList(props.dataSource)\r\n } else {\r\n getRequest();\r\n }\r\n }, [, props.dataSource]);\r\n\r\n return info ? <Dropdown menu={menu} disabled={menu?.items?.length === 0}>\r\n <span className={styles.action}>\r\n <span>{info.name}</span>\r\n </span>\r\n </Dropdown> : <></>;\r\n};\r\n"],"names":["Dropdown","Modal","useCallback","useEffect","useState","styles","useLocale","gql","query","iceUrqlInstance","userRootOrgListQuery","props","menu","locale","list","setList","undefined","info","setInfo","setMenu","getRequest","result","orgList","instanceName","ucenter","data","userRootOrgs","length","setValue","find","item","id","value","items","filter","map","key","label","name","onClick","menuItemClick","confirm","title","confirmTitle","content","confirmContent","onOk","onChange","document","hidden","tipStr","switchTipTitle","body","innerHTML","window","close","dataSource","disabled","span","className","action"],"mappings":";;;;AAAA,SAASA,QAAQ,EAAaC,KAAK,QAAQ,OAAO;AAClD,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AACzD,OAAOC,YAAY,qBAAqB;AACxC,SAASC,SAAS,QAAQ,kBAAY;AAEtC,SAASC,GAAG,EAAEC,KAAK,QAAQ,gCAAgC;AAC3D,SAASC,eAAe,QAAQ,WAAK;AAuBrC,IAAMC,uBAAuBH,IAAkB;AAM/C,eAAe,SAACI,OAA+B;QA2DCC;IA1D9C,IAAMC,SAASP,UAAU,mBACLF,6BAAAA,SAAqB,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MkB,SAASrC,OAAOsC,cAAc;YACpCH,SAASN,KAAK,GAAGQ;YACjBF,SAASI,IAAI,CAACC,SAAS,GAAG,AAAC,qDAA2D,OAAPH,QAAO;YACtFI,OAAOC,KAAK;QACd,OACE3B;IAEJ,GAAG;QAACjB,MAAMqB,KAAK;KAAC;IAEhB7B,UAAU,WAAM;QACdyB;IACF,GAAG;QAACd;KAAK;IAETX,UAAU,WAAM;QACd,IAAIQ,MAAM6C,UAAU,EAClBzC,QAAQJ,MAAM6C,UAAU;aAExBpC;IAEJ,GAAG;;QAAGT,MAAM6C,UAAU;KAAC;IAEvB,OAAOvC,qBAAO,KAACjB;QAASY,MAAMA;QAAM6C,UAAU7C,CAAAA,iBAAAA,kBAAAA,KAAAA,IAAAA,CAAAA,cAAAA,KAAMqB,KAAK,cAAXrB,yBAAAA,KAAAA,IAAAA,YAAae,MAAF,AAAD,MAAc;kBACpE,cAAA,KAAC+B;YAAKC,WAAWtD,OAAOuD,MAAM;sBAC5B,cAAA,KAACF;0BAAMzC,KAAKqB,IAAI;;;uBAEN,mBAAK;AACrB,EAAE"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type UploadFileLocale = {
|
|
2
|
+
fileSizeTip: string;
|
|
3
|
+
del: string;
|
|
4
|
+
confirmDel: string;
|
|
5
|
+
clickOrDragUpload: string;
|
|
6
|
+
supportExtension: string;
|
|
7
|
+
errSupportExtension: string;
|
|
8
|
+
fileUpload: string;
|
|
9
|
+
tempViewer: string;
|
|
10
|
+
tempDown: string;
|
|
11
|
+
};
|
|
12
|
+
export interface UploadFileProps<T> {
|
|
13
|
+
/**
|
|
14
|
+
* bucket
|
|
15
|
+
*/
|
|
16
|
+
bucket?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 应用code
|
|
19
|
+
*/
|
|
20
|
+
appCode?: string;
|
|
21
|
+
/**
|
|
22
|
+
* tenantId
|
|
23
|
+
*/
|
|
24
|
+
tenantId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* 目录格式 xxx/ss
|
|
27
|
+
*/
|
|
28
|
+
directory?: string;
|
|
29
|
+
/**
|
|
30
|
+
* 强制使用目录当前缀
|
|
31
|
+
*/
|
|
32
|
+
forceDirectory?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 限制文件大小
|
|
35
|
+
*/
|
|
36
|
+
maxSize?: number;
|
|
37
|
+
/**
|
|
38
|
+
* 限制弹框选择
|
|
39
|
+
*/
|
|
40
|
+
accept?: string;
|
|
41
|
+
/**
|
|
42
|
+
* 文件 id
|
|
43
|
+
*/
|
|
44
|
+
value?: T;
|
|
45
|
+
/**
|
|
46
|
+
* 返回文件id
|
|
47
|
+
* @param value
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
onChange?: (value?: T) => void;
|
|
51
|
+
/**
|
|
52
|
+
* 返回文件path
|
|
53
|
+
* @param path
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
onChangePath?: (path?: T) => void;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\upload-file\\index.ts"],"sourcesContent":["export type UploadFileLocale = {\r\n // 文件大小必须小于:\r\n fileSizeTip: string;\r\n del: string;\r\n confirmDel: string;\r\n // 点击或拖拽文件上传\r\n clickOrDragUpload: string;\r\n // 支持扩展名\r\n supportExtension: string;\r\n errSupportExtension: string;\r\n fileUpload: string;\r\n tempViewer: string;\r\n tempDown: string;\r\n}\r\n\r\nexport interface UploadFileProps<T> {\r\n /**\r\n * bucket\r\n */\r\n bucket?: string;\r\n /**\r\n * 应用code\r\n */\r\n appCode?: string;\r\n /**\r\n * tenantId\r\n */\r\n tenantId?: string;\r\n /**\r\n * 目录格式 xxx/ss\r\n */\r\n directory?: string;\r\n /**\r\n * 强制使用目录当前缀\r\n */\r\n forceDirectory?: boolean;\r\n /**\r\n * 限制文件大小\r\n */\r\n maxSize?: number;\r\n /**\r\n * 限制弹框选择\r\n */\r\n accept?: string;\r\n /**\r\n * 文件 id\r\n */\r\n value?: T;\r\n /**\r\n * 返回文件id\r\n * @param value\r\n * @returns\r\n */\r\n onChange?: (value?: T) => void;\r\n /**\r\n * 返回文件path\r\n * @param path\r\n * @returns\r\n */\r\n onChangePath?: (path?: T) => void;\r\n}\r\n"],"names":[],"mappings":"AAAA,WA4DC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var locale = {
|
|
2
|
+
fileSizeTip: "The file size cannot be less than",
|
|
3
|
+
del: "delete",
|
|
4
|
+
confirmDel: "Confirm deletion",
|
|
5
|
+
clickOrDragUpload: "Click or drag the file to upload",
|
|
6
|
+
supportExtension: "Support extension",
|
|
7
|
+
errSupportExtension: "Only the extension name is supported",
|
|
8
|
+
fileUpload: "File upload",
|
|
9
|
+
tempViewer: "Template preview",
|
|
10
|
+
tempDown: "Template download"
|
|
11
|
+
};
|
|
12
|
+
export default locale;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=D:\codeing\git\github\knockout-js\packages\layout\esm\components\upload-file\locale\en_US.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\upload-file\\locale\\en_US.ts"],"sourcesContent":["import { UploadFileLocale } from \"../index\";\r\n\r\nconst locale: UploadFileLocale = {\r\n fileSizeTip: \"The file size cannot be less than\",\r\n del: \"delete\",\r\n confirmDel: \"Confirm deletion\",\r\n clickOrDragUpload: \"Click or drag the file to upload\",\r\n supportExtension: \"Support extension\",\r\n errSupportExtension: \"Only the extension name is supported\",\r\n fileUpload: \"File upload\",\r\n tempViewer: \"Template preview\",\r\n tempDown: \"Template download\",\r\n};\r\n\r\nexport default locale\r\n"],"names":["locale","fileSizeTip","del","confirmDel","clickOrDragUpload","supportExtension","errSupportExtension","fileUpload","tempViewer","tempDown"],"mappings":"AAEA,IAAMA,SAA2B;IAC/BC,aAAa;IACbC,KAAK;IACLC,YAAY;IACZC,mBAAmB;IACnBC,kBAAkB;IAClBC,qBAAqB;IACrBC,YAAY;IACZC,YAAY;IACZC,UAAU;AACZ;AAEA,eAAeT,OAAM"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var locale = {
|
|
2
|
+
fileSizeTip: "文件大小不能小于",
|
|
3
|
+
del: "删除",
|
|
4
|
+
confirmDel: "确认删除",
|
|
5
|
+
clickOrDragUpload: "点击或拖拽文件上传",
|
|
6
|
+
supportExtension: "支持扩展名",
|
|
7
|
+
errSupportExtension: "只支持扩展名",
|
|
8
|
+
fileUpload: "文件上传",
|
|
9
|
+
tempViewer: "模板预览",
|
|
10
|
+
tempDown: "模板下载"
|
|
11
|
+
};
|
|
12
|
+
export default locale;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=D:\codeing\git\github\knockout-js\packages\layout\esm\components\upload-file\locale\zh_CN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\upload-file\\locale\\zh_CN.ts"],"sourcesContent":["import { UploadFileLocale } from \"../index\";\r\n\r\nconst locale: UploadFileLocale = {\r\n fileSizeTip: \"文件大小不能小于\",\r\n del: \"删除\",\r\n confirmDel: \"确认删除\",\r\n clickOrDragUpload: \"点击或拖拽文件上传\",\r\n supportExtension: \"支持扩展名\",\r\n errSupportExtension: \"只支持扩展名\",\r\n fileUpload: \"文件上传\",\r\n tempViewer: \"模板预览\",\r\n tempDown: \"模板下载\",\r\n};\r\n\r\nexport default locale\r\n"],"names":["locale","fileSizeTip","del","confirmDel","clickOrDragUpload","supportExtension","errSupportExtension","fileUpload","tempViewer","tempDown"],"mappings":"AAEA,IAAMA,SAA2B;IAC/BC,aAAa;IACbC,KAAK;IACLC,YAAY;IACZC,mBAAmB;IACnBC,kBAAkB;IAClBC,qBAAqB;IACrBC,YAAY;IACZC,YAAY;IACZC,UAAU;AACZ;AAEA,eAAeT,OAAM"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
|
|
2
|
+
import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
|
|
3
|
+
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@ice/jsx-runtime/jsx-runtime";
|
|
5
|
+
import { PlusOutlined } from "@ant-design/icons";
|
|
6
|
+
import { Spin, Upload, message } from "antd";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { files as fileApi } from "@knockout-js/api";
|
|
9
|
+
import { useAppCode, useTenantId } from "../provider/index";
|
|
10
|
+
import { useLocale } from "../locale/index";
|
|
11
|
+
import { formatFileSize, randomId } from "../_util/index";
|
|
12
|
+
export default function(props) {
|
|
13
|
+
var _props_bucket, _props_appCode, _props_tenantId;
|
|
14
|
+
var bucket = (_props_bucket = props.bucket) !== null && _props_bucket !== void 0 ? _props_bucket : "local", appCode = (_props_appCode = props.appCode) !== null && _props_appCode !== void 0 ? _props_appCode : useAppCode(), tenantId = (_props_tenantId = props.tenantId) !== null && _props_tenantId !== void 0 ? _props_tenantId : useTenantId(), locale = useLocale("UploadFile"), _message_useMessage = _sliced_to_array(message.useMessage(), 1), messageApi = _message_useMessage[0], _useState = _sliced_to_array(useState(false), 2), loading = _useState[0], setLoading = _useState[1], _useState1 = _sliced_to_array(useState(), 2), imgsrc = _useState1[0], setImgsrc = _useState1[1];
|
|
15
|
+
var getUploadKey = function(file) {
|
|
16
|
+
var suffix = file.name.split(".").pop(), keys = [];
|
|
17
|
+
if (props.forceDirectory && props.directory) keys.push(props.directory);
|
|
18
|
+
else {
|
|
19
|
+
if (appCode) keys.push(appCode);
|
|
20
|
+
if (tenantId) keys.push(tenantId);
|
|
21
|
+
if (props.directory) keys.push(props.directory);
|
|
22
|
+
}
|
|
23
|
+
keys.push("".concat(randomId(16), ".").concat(suffix));
|
|
24
|
+
return "/".concat(keys.join("/")).replace("//", "/");
|
|
25
|
+
}, updateFile = function() {
|
|
26
|
+
var _ref = _async_to_generator(function(file) {
|
|
27
|
+
var key, result, _props_onChange, _props_onChangePath, error;
|
|
28
|
+
return _ts_generator(this, function(_state) {
|
|
29
|
+
switch(_state.label){
|
|
30
|
+
case 0:
|
|
31
|
+
key = getUploadKey(file);
|
|
32
|
+
setLoading(true);
|
|
33
|
+
if (!(bucket === "local")) return [
|
|
34
|
+
3,
|
|
35
|
+
4
|
|
36
|
+
];
|
|
37
|
+
_state.label = 1;
|
|
38
|
+
case 1:
|
|
39
|
+
_state.trys.push([
|
|
40
|
+
1,
|
|
41
|
+
3,
|
|
42
|
+
,
|
|
43
|
+
4
|
|
44
|
+
]);
|
|
45
|
+
return [
|
|
46
|
+
4,
|
|
47
|
+
fileApi.updateFiles({
|
|
48
|
+
key: key,
|
|
49
|
+
bucket: bucket,
|
|
50
|
+
file: file
|
|
51
|
+
})
|
|
52
|
+
];
|
|
53
|
+
case 2:
|
|
54
|
+
result = _state.sent();
|
|
55
|
+
if (result) {
|
|
56
|
+
;
|
|
57
|
+
(_props_onChange = props.onChange) === null || _props_onChange === void 0 ? void 0 : _props_onChange.call(props, result);
|
|
58
|
+
(_props_onChangePath = props.onChangePath) === null || _props_onChangePath === void 0 ? void 0 : _props_onChangePath.call(props, key);
|
|
59
|
+
}
|
|
60
|
+
return [
|
|
61
|
+
3,
|
|
62
|
+
4
|
|
63
|
+
];
|
|
64
|
+
case 3:
|
|
65
|
+
error = _state.sent();
|
|
66
|
+
return [
|
|
67
|
+
3,
|
|
68
|
+
4
|
|
69
|
+
];
|
|
70
|
+
case 4:
|
|
71
|
+
setLoading(false);
|
|
72
|
+
return [
|
|
73
|
+
2
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return function updateFile(file) {
|
|
79
|
+
return _ref.apply(this, arguments);
|
|
80
|
+
};
|
|
81
|
+
}(), getValueFile = function() {
|
|
82
|
+
var _ref = _async_to_generator(function() {
|
|
83
|
+
var result;
|
|
84
|
+
return _ts_generator(this, function(_state) {
|
|
85
|
+
switch(_state.label){
|
|
86
|
+
case 0:
|
|
87
|
+
if (!props.value) return [
|
|
88
|
+
3,
|
|
89
|
+
3
|
|
90
|
+
];
|
|
91
|
+
if (!(bucket === "local")) return [
|
|
92
|
+
3,
|
|
93
|
+
2
|
|
94
|
+
];
|
|
95
|
+
return [
|
|
96
|
+
4,
|
|
97
|
+
fileApi.getFilesRaw(props.value, "url")
|
|
98
|
+
];
|
|
99
|
+
case 1:
|
|
100
|
+
result = _state.sent();
|
|
101
|
+
if (typeof result === "string") setImgsrc(result);
|
|
102
|
+
_state.label = 2;
|
|
103
|
+
case 2:
|
|
104
|
+
return [
|
|
105
|
+
3,
|
|
106
|
+
4
|
|
107
|
+
];
|
|
108
|
+
case 3:
|
|
109
|
+
setImgsrc(undefined);
|
|
110
|
+
_state.label = 4;
|
|
111
|
+
case 4:
|
|
112
|
+
return [
|
|
113
|
+
2
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
return function getValueFile() {
|
|
119
|
+
return _ref.apply(this, arguments);
|
|
120
|
+
};
|
|
121
|
+
}();
|
|
122
|
+
useEffect(function() {
|
|
123
|
+
getValueFile();
|
|
124
|
+
}, [
|
|
125
|
+
props.value
|
|
126
|
+
]);
|
|
127
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
128
|
+
style: {
|
|
129
|
+
display: "inline-block"
|
|
130
|
+
},
|
|
131
|
+
children: /*#__PURE__*/ _jsx(Spin, {
|
|
132
|
+
spinning: loading,
|
|
133
|
+
children: /*#__PURE__*/ _jsx(Upload, {
|
|
134
|
+
accept: props.accept,
|
|
135
|
+
listType: "picture-card",
|
|
136
|
+
showUploadList: false,
|
|
137
|
+
beforeUpload: function() {
|
|
138
|
+
var _ref = _async_to_generator(function(file) {
|
|
139
|
+
var maxSize;
|
|
140
|
+
return _ts_generator(this, function(_state) {
|
|
141
|
+
switch(_state.label){
|
|
142
|
+
case 0:
|
|
143
|
+
maxSize = props.maxSize || 5242880;
|
|
144
|
+
if (file.size > maxSize) {
|
|
145
|
+
messageApi.error("".concat(locale.fileSizeTip, ": ").concat(formatFileSize(maxSize)));
|
|
146
|
+
return [
|
|
147
|
+
2,
|
|
148
|
+
false
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
return [
|
|
152
|
+
4,
|
|
153
|
+
updateFile(file)
|
|
154
|
+
];
|
|
155
|
+
case 1:
|
|
156
|
+
_state.sent();
|
|
157
|
+
return [
|
|
158
|
+
2,
|
|
159
|
+
false
|
|
160
|
+
];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
return function(file) {
|
|
165
|
+
return _ref.apply(this, arguments);
|
|
166
|
+
};
|
|
167
|
+
}(),
|
|
168
|
+
children: imgsrc ? /*#__PURE__*/ _jsx("img", {
|
|
169
|
+
src: imgsrc,
|
|
170
|
+
alt: "avatar",
|
|
171
|
+
style: {
|
|
172
|
+
width: "100%"
|
|
173
|
+
}
|
|
174
|
+
}) : /*#__PURE__*/ _jsxs(_Fragment, {
|
|
175
|
+
children: [
|
|
176
|
+
/*#__PURE__*/ _jsx(PlusOutlined, {
|
|
177
|
+
rev: undefined
|
|
178
|
+
}),
|
|
179
|
+
/*#__PURE__*/ _jsx("div", {
|
|
180
|
+
style: {
|
|
181
|
+
marginTop: 8
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
]
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
//# sourceMappingURL=D:\codeing\git\github\knockout-js\packages\layout\esm\components\upload-file\uploadAvatar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["D:\\codeing\\git\\github\\knockout-js\\packages\\layout\\src\\components\\upload-file\\uploadAvatar.tsx"],"sourcesContent":["import { PlusOutlined } from \"@ant-design/icons\";\r\nimport { Spin, Upload, message } from \"antd\"\r\nimport { RcFile } from \"antd/es/upload\";\r\nimport { useEffect, useState } from \"react\";\r\nimport { files as fileApi } from \"@knockout-js/api\";\r\nimport { useAppCode, useTenantId } from \"../provider\";\r\nimport { UploadFileProps } from \".\";\r\nimport { useLocale } from \"../locale\";\r\nimport { formatFileSize, randomId } from \"../_util\";\r\n\r\nexport default (props: UploadFileProps<string>) => {\r\n const\r\n bucket = props.bucket ?? 'local',\r\n appCode = props.appCode ?? useAppCode(),\r\n tenantId = props.tenantId ?? useTenantId(),\r\n locale = useLocale(\"UploadFile\"),\r\n [messageApi] = message.useMessage(),\r\n [loading, setLoading] = useState(false),\r\n [imgsrc, setImgsrc] = useState<string>();\r\n\r\n const\r\n getUploadKey = (file: RcFile) => {\r\n const suffix = file.name.split('.').pop(),\r\n keys: string[] = [];\r\n if (props.forceDirectory && props.directory) {\r\n keys.push(props.directory)\r\n } else {\r\n if (appCode) {\r\n keys.push(appCode)\r\n }\r\n if (tenantId) {\r\n keys.push(tenantId)\r\n }\r\n if (props.directory) {\r\n keys.push(props.directory)\r\n }\r\n }\r\n keys.push(`${randomId(16)}.${suffix}`);\r\n return `/${keys.join('/')}`.replace('//', '/');\r\n },\r\n updateFile = async (file: RcFile) => {\r\n const key = getUploadKey(file);\r\n setLoading(true);\r\n if (bucket === 'local') {\r\n try {\r\n const result = await fileApi.updateFiles({\r\n key,\r\n bucket,\r\n file,\r\n })\r\n if (result) {\r\n props.onChange?.(result)\r\n props.onChangePath?.(key);\r\n }\r\n } catch (error) {\r\n\r\n }\r\n }\r\n setLoading(false)\r\n },\r\n getValueFile = async () => {\r\n if (props.value) {\r\n if (bucket === 'local') {\r\n const result = await fileApi.getFilesRaw(props.value, 'url');\r\n if (typeof result === 'string') {\r\n setImgsrc(result)\r\n }\r\n }\r\n } else {\r\n setImgsrc(undefined)\r\n }\r\n }\r\n\r\n useEffect(() => {\r\n getValueFile()\r\n }, [props.value])\r\n\r\n return <div style={{ display: \"inline-block\" }}>\r\n <Spin spinning={loading} >\r\n <Upload\r\n accept={props.accept}\r\n listType=\"picture-card\"\r\n showUploadList={false}\r\n beforeUpload={async (file) => {\r\n const maxSize = props.maxSize || (1024 * 1024 * 5);\r\n\r\n if (file.size > maxSize) {\r\n messageApi.error(`${locale.fileSizeTip}: ${formatFileSize(maxSize)}`);\r\n return false;\r\n }\r\n\r\n await updateFile(file);\r\n return false;\r\n }}\r\n >\r\n {\r\n imgsrc ? <img\r\n src={imgsrc} alt=\"avatar\" style={{ width: '100%' }}\r\n /> : <>\r\n <PlusOutlined rev={undefined} />\r\n <div style={{ marginTop: 8 }}></div>\r\n </>\r\n }\r\n </Upload>\r\n </Spin>\r\n </div>\r\n}\r\n"],"names":["PlusOutlined","Spin","Upload","message","useEffect","useState","files","fileApi","useAppCode","useTenantId","useLocale","formatFileSize","randomId","props","bucket","appCode","tenantId","locale","useMessage","messageApi","loading","setLoading","imgsrc","setImgsrc","getUploadKey","file","suffix","name","split","pop","keys","forceDirectory","directory","push","join","replace","updateFile","key","result","error","updateFiles","onChange","onChangePath","getValueFile","value","getFilesRaw","undefined","div","style","display","spinning","accept","listType","showUploadList","beforeUpload","maxSize","size","fileSizeTip","img","src","alt","width","rev","marginTop"],"mappings":";;;;AAAA,SAASA,YAAY,QAAQ,oBAAoB;AACjD,SAASC,IAAI,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAM;AAE5C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAC5C,SAASC,SAASC,OAAO,QAAQ,mBAAmB;AACpD,SAASC,UAAU,EAAEC,WAAW,QAAQ,oBAAc;AAEtD,SAASC,SAAS,QAAQ,kBAAY;AACtC,SAASC,cAAc,EAAEC,QAAQ,QAAQ,iBAAW;AAEpD,eAAe,SAACC,OAAmC;QAEtCA,eACCA,gBACCA;IAHb,IACEC,S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