mp-taro-kit 0.0.1 → 0.0.4
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/README.md +3 -3
- package/dist/core/configure.cjs +75 -0
- package/dist/core/configure.d.ts +18 -0
- package/dist/core/configure.js +69 -0
- package/dist/core/faces.cjs +2 -0
- package/dist/core/faces.d.ts +42 -0
- package/dist/core/faces.js +1 -0
- package/dist/core/index.cjs +32 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +5 -0
- package/dist/core/request.cjs +60 -0
- package/dist/core/request.d.ts +27 -0
- package/dist/core/request.js +51 -0
- package/dist/core/router.cjs +71 -0
- package/dist/core/router.d.ts +11 -0
- package/dist/core/router.js +63 -0
- package/dist/core/storage.cjs +63 -0
- package/dist/core/storage.d.ts +6 -0
- package/dist/core/storage.js +57 -0
- package/dist/core/weapp.cjs +37 -0
- package/dist/core/weapp.d.ts +7 -0
- package/dist/core/weapp.js +32 -0
- package/dist/design/index.cjs +2 -0
- package/dist/design/index.d.ts +1 -0
- package/dist/design/index.js +1 -0
- package/dist/design/tokens.css +60 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/runtime/index.cjs +15 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.js +6 -0
- package/dist/runtime/loading-slot.cjs +44 -0
- package/dist/runtime/loading-slot.d.ts +15 -0
- package/dist/runtime/loading-slot.js +41 -0
- package/dist/runtime/notify.cjs +52 -0
- package/dist/runtime/notify.d.ts +19 -0
- package/dist/runtime/notify.js +49 -0
- package/dist/runtime/overlay-stack.cjs +49 -0
- package/dist/runtime/overlay-stack.d.ts +17 -0
- package/dist/runtime/overlay-stack.js +46 -0
- package/dist/runtime/singleton.cjs +17 -0
- package/dist/runtime/singleton.d.ts +6 -0
- package/dist/runtime/singleton.js +14 -0
- package/dist/runtime/thenable.cjs +17 -0
- package/dist/runtime/thenable.d.ts +7 -0
- package/dist/runtime/thenable.js +13 -0
- package/dist/styles/tokens.css +60 -0
- package/dist/ui/actions/Button.cjs +32 -0
- package/dist/ui/actions/Button.d.ts +13 -0
- package/dist/ui/actions/Button.js +29 -0
- package/dist/ui/actions/index.cjs +5 -0
- package/dist/ui/actions/index.d.ts +1 -0
- package/dist/ui/actions/index.js +1 -0
- package/dist/ui/actions/style/index.css +22 -0
- package/dist/ui/commands.cjs +86 -0
- package/dist/ui/commands.d.ts +21 -0
- package/dist/ui/commands.js +73 -0
- package/dist/ui/display/Badge.cjs +10 -0
- package/dist/ui/display/Badge.d.ts +9 -0
- package/dist/ui/display/Badge.js +7 -0
- package/dist/ui/display/Divider.cjs +9 -0
- package/dist/ui/display/Divider.d.ts +5 -0
- package/dist/ui/display/Divider.js +6 -0
- package/dist/ui/display/index.cjs +7 -0
- package/dist/ui/display/index.d.ts +2 -0
- package/dist/ui/display/index.js +2 -0
- package/dist/ui/display/style/index.css +30 -0
- package/dist/ui/feedback/Dialog.cjs +12 -0
- package/dist/ui/feedback/Dialog.d.ts +15 -0
- package/dist/ui/feedback/Dialog.js +9 -0
- package/dist/ui/feedback/Loading.cjs +12 -0
- package/dist/ui/feedback/Loading.d.ts +7 -0
- package/dist/ui/feedback/Loading.js +9 -0
- package/dist/ui/feedback/Toast.cjs +12 -0
- package/dist/ui/feedback/Toast.d.ts +9 -0
- package/dist/ui/feedback/Toast.js +9 -0
- package/dist/ui/feedback/index.cjs +9 -0
- package/dist/ui/feedback/index.d.ts +3 -0
- package/dist/ui/feedback/index.js +3 -0
- package/dist/ui/feedback/style/index.css +67 -0
- package/dist/ui/index.cjs +17 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +2 -0
- package/dist/ui/infra/OverlayHost.cjs +33 -0
- package/dist/ui/infra/OverlayHost.d.ts +8 -0
- package/dist/ui/infra/OverlayHost.js +30 -0
- package/dist/ui/infra/SafeArea.cjs +10 -0
- package/dist/ui/infra/SafeArea.d.ts +8 -0
- package/dist/ui/infra/SafeArea.js +7 -0
- package/dist/ui/infra/index.cjs +11 -0
- package/dist/ui/infra/index.d.ts +3 -0
- package/dist/ui/infra/index.js +3 -0
- package/dist/ui/infra/style/index.css +83 -0
- package/dist/ui/infra/use-store.cjs +17 -0
- package/dist/ui/infra/use-store.d.ts +8 -0
- package/dist/ui/infra/use-store.js +12 -0
- package/dist/ui/layout/Mask.cjs +12 -0
- package/dist/ui/layout/Mask.d.ts +7 -0
- package/dist/ui/layout/Mask.js +9 -0
- package/dist/ui/layout/Overlay.cjs +11 -0
- package/dist/ui/layout/Overlay.d.ts +8 -0
- package/dist/ui/layout/Overlay.js +8 -0
- package/dist/ui/layout/Popup.cjs +13 -0
- package/dist/ui/layout/Popup.d.ts +11 -0
- package/dist/ui/layout/Popup.js +10 -0
- package/dist/ui/layout/index.cjs +9 -0
- package/dist/ui/layout/index.d.ts +3 -0
- package/dist/ui/layout/index.js +3 -0
- package/dist/ui/layout/style/index.css +51 -0
- package/dist/ui/navigation/Drawer.cjs +12 -0
- package/dist/ui/navigation/Drawer.d.ts +11 -0
- package/dist/ui/navigation/Drawer.js +9 -0
- package/dist/ui/navigation/Dropdown.cjs +12 -0
- package/dist/ui/navigation/Dropdown.d.ts +9 -0
- package/dist/ui/navigation/Dropdown.js +9 -0
- package/dist/ui/navigation/index.cjs +7 -0
- package/dist/ui/navigation/index.d.ts +2 -0
- package/dist/ui/navigation/index.js +2 -0
- package/dist/ui/navigation/style/index.css +42 -0
- package/dist/ui/state.cjs +20 -0
- package/dist/ui/state.d.ts +25 -0
- package/dist/ui/state.js +17 -0
- package/dist/utils/date.cjs +98 -0
- package/dist/utils/date.d.ts +18 -0
- package/dist/utils/date.js +89 -0
- package/dist/utils/i18n.cjs +31 -0
- package/dist/utils/i18n.d.ts +11 -0
- package/dist/utils/i18n.js +25 -0
- package/dist/utils/index.cjs +30 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/messages.zh.cjs +13 -0
- package/dist/utils/messages.zh.d.ts +1 -0
- package/dist/utils/messages.zh.js +10 -0
- package/dist/utils/number.cjs +38 -0
- package/dist/utils/number.d.ts +6 -0
- package/dist/utils/number.js +33 -0
- package/dist/utils/path.cjs +33 -0
- package/dist/utils/path.d.ts +8 -0
- package/dist/utils/path.js +27 -0
- package/dist/utils/string.cjs +55 -0
- package/dist/utils/string.d.ts +8 -0
- package/dist/utils/string.js +50 -0
- package/package.json +68 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isThenable = isThenable;
|
|
4
|
+
exports.isSuccess = isSuccess;
|
|
5
|
+
/** Promise 化交互的判定器:只判定,不 await、不吞错、不改原值。 */
|
|
6
|
+
function isThenable(value) {
|
|
7
|
+
if (value === null || value === undefined)
|
|
8
|
+
return false;
|
|
9
|
+
return typeof value.then === 'function';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 回调的返回值算不算「这次成了」:仅显式 false 表示没成(弹窗据此保持不关、让人重试)。
|
|
13
|
+
* true / undefined / 其他值一律算成,消费方不必在调用点包 try/catch。
|
|
14
|
+
*/
|
|
15
|
+
function isSuccess(value) {
|
|
16
|
+
return value !== false;
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Promise 化交互的判定器:只判定,不 await、不吞错、不改原值。 */
|
|
2
|
+
export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* 回调的返回值算不算「这次成了」:仅显式 false 表示没成(弹窗据此保持不关、让人重试)。
|
|
5
|
+
* true / undefined / 其他值一律算成,消费方不必在调用点包 try/catch。
|
|
6
|
+
*/
|
|
7
|
+
export declare function isSuccess(value: unknown): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Promise 化交互的判定器:只判定,不 await、不吞错、不改原值。 */
|
|
2
|
+
export function isThenable(value) {
|
|
3
|
+
if (value === null || value === undefined)
|
|
4
|
+
return false;
|
|
5
|
+
return typeof value.then === 'function';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 回调的返回值算不算「这次成了」:仅显式 false 表示没成(弹窗据此保持不关、让人重试)。
|
|
9
|
+
* true / undefined / 其他值一律算成,消费方不必在调用点包 try/catch。
|
|
10
|
+
*/
|
|
11
|
+
export function isSuccess(value) {
|
|
12
|
+
return value !== false;
|
|
13
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* mp-taro-kit 对外样式变量唯一真源。宿主 import 'mp-taro-kit/styles/tokens' 后覆盖同名变量即可整体换肤;
|
|
2
|
+
组件侧只写 var(--mptk-*),不自带兜底值、不在别处复制数值。命名按 dsh-plugin-core 通用层对齐。
|
|
3
|
+
边框色沿用其 4% / 10% / 12% 档,写成 rgba 字面量以避开小程序端 8 位 hex 的兼容问题。
|
|
4
|
+
待实机验证:page 挂载与 px 单位在 Skyline / WebView 双端的实际表现,须宿主 demo 确认。 */
|
|
5
|
+
page {
|
|
6
|
+
/* 文字 */
|
|
7
|
+
--mptk-fg: #1f2328;
|
|
8
|
+
--mptk-fg-2: #5c6370;
|
|
9
|
+
--mptk-fg-3: #767d87;
|
|
10
|
+
--mptk-fg-4: #9aa1ab;
|
|
11
|
+
|
|
12
|
+
/* 面 */
|
|
13
|
+
--mptk-surface-1: #fff;
|
|
14
|
+
--mptk-surface-2: #fff;
|
|
15
|
+
--mptk-surface-3: #fff;
|
|
16
|
+
--mptk-surface-base: #fff;
|
|
17
|
+
|
|
18
|
+
/* 描边 */
|
|
19
|
+
--mptk-border-faint: rgba(0, 0, 0, .04);
|
|
20
|
+
--mptk-border: rgba(0, 0, 0, .10);
|
|
21
|
+
--mptk-border-strong: rgba(0, 0, 0, .12);
|
|
22
|
+
|
|
23
|
+
/* 语义色 */
|
|
24
|
+
--mptk-business: #3b5bdb;
|
|
25
|
+
--mptk-success: #22c55e;
|
|
26
|
+
--mptk-warning: #f59e0b;
|
|
27
|
+
--mptk-danger: #ec1313;
|
|
28
|
+
|
|
29
|
+
/* 圆角 */
|
|
30
|
+
--mptk-radius-xs: 4px;
|
|
31
|
+
--mptk-radius-sm: 8px;
|
|
32
|
+
--mptk-radius-md: 12px;
|
|
33
|
+
--mptk-radius-lg: 16px;
|
|
34
|
+
--mptk-radius-xl: 20px;
|
|
35
|
+
--mptk-radius-pill: 999px;
|
|
36
|
+
|
|
37
|
+
/* 间距(4px 等差) */
|
|
38
|
+
--mptk-space-1: 4px;
|
|
39
|
+
--mptk-space-2: 8px;
|
|
40
|
+
--mptk-space-3: 12px;
|
|
41
|
+
--mptk-space-4: 16px;
|
|
42
|
+
|
|
43
|
+
/* 字号 / 行高成对 */
|
|
44
|
+
--mptk-font-xs: 11px;
|
|
45
|
+
--mptk-font-sm: 12px;
|
|
46
|
+
--mptk-font-md: 13px;
|
|
47
|
+
--mptk-font-lg: 14px;
|
|
48
|
+
--mptk-font-xl: 16px;
|
|
49
|
+
--mptk-line-xs: 14px;
|
|
50
|
+
--mptk-line-sm: 18px;
|
|
51
|
+
--mptk-line-md: 20px;
|
|
52
|
+
--mptk-line-lg: 22px;
|
|
53
|
+
--mptk-line-xl: 24px;
|
|
54
|
+
|
|
55
|
+
/* 动画 */
|
|
56
|
+
--mptk-dur: .2s;
|
|
57
|
+
--mptk-dur-fast: .12s;
|
|
58
|
+
--mptk-dur-run: 500ms;
|
|
59
|
+
--mptk-ease: cubic-bezier(.4, 0, .2, 1);
|
|
60
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Button = Button;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const components_1 = require("@tarojs/components");
|
|
7
|
+
const thenable_js_1 = require("../../runtime/thenable.cjs");
|
|
8
|
+
function Button({ children, disabled = false, loadingText, className, onClick, onFailed, }) {
|
|
9
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
10
|
+
const inFlight = (0, react_1.useRef)(false);
|
|
11
|
+
const handleClick = () => {
|
|
12
|
+
if (disabled || loading || inFlight.current)
|
|
13
|
+
return;
|
|
14
|
+
const result = onClick?.();
|
|
15
|
+
if (!(0, thenable_js_1.isThenable)(result))
|
|
16
|
+
return;
|
|
17
|
+
inFlight.current = true;
|
|
18
|
+
setLoading(true);
|
|
19
|
+
void Promise.resolve(result).then((value) => {
|
|
20
|
+
inFlight.current = false;
|
|
21
|
+
setLoading(false);
|
|
22
|
+
if (!(0, thenable_js_1.isSuccess)(value))
|
|
23
|
+
onFailed?.();
|
|
24
|
+
}, (error) => {
|
|
25
|
+
inFlight.current = false;
|
|
26
|
+
setLoading(false);
|
|
27
|
+
throw error;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const names = ['mptk-btn', disabled ? 'mptk-btn--disabled' : '', loading ? 'mptk-btn--loading' : '', className];
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(components_1.View, { className: names.filter(Boolean).join(' '), onClick: handleClick, children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: loading && loadingText !== undefined ? loadingText : children }) }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface ButtonProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
/** 异步期间显示的文案;锁宽防跳由样式负责。 */
|
|
6
|
+
loadingText?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
/** 返回 Promise 即自动 loading + 防连点;同步返回值不转圈。 */
|
|
9
|
+
onClick?: () => unknown;
|
|
10
|
+
/** 显式返回 false(或 Promise<false>)时回调,表示操作没成。 */
|
|
11
|
+
onFailed?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function Button({ children, disabled, loadingText, className, onClick, onFailed, }: ButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import { View, Text } from '@tarojs/components';
|
|
4
|
+
import { isThenable, isSuccess } from '../../runtime/thenable.js';
|
|
5
|
+
export function Button({ children, disabled = false, loadingText, className, onClick, onFailed, }) {
|
|
6
|
+
const [loading, setLoading] = useState(false);
|
|
7
|
+
const inFlight = useRef(false);
|
|
8
|
+
const handleClick = () => {
|
|
9
|
+
if (disabled || loading || inFlight.current)
|
|
10
|
+
return;
|
|
11
|
+
const result = onClick?.();
|
|
12
|
+
if (!isThenable(result))
|
|
13
|
+
return;
|
|
14
|
+
inFlight.current = true;
|
|
15
|
+
setLoading(true);
|
|
16
|
+
void Promise.resolve(result).then((value) => {
|
|
17
|
+
inFlight.current = false;
|
|
18
|
+
setLoading(false);
|
|
19
|
+
if (!isSuccess(value))
|
|
20
|
+
onFailed?.();
|
|
21
|
+
}, (error) => {
|
|
22
|
+
inFlight.current = false;
|
|
23
|
+
setLoading(false);
|
|
24
|
+
throw error;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const names = ['mptk-btn', disabled ? 'mptk-btn--disabled' : '', loading ? 'mptk-btn--loading' : '', className];
|
|
28
|
+
return (_jsx(View, { className: names.filter(Boolean).join(' '), onClick: handleClick, children: _jsx(Text, { children: loading && loadingText !== undefined ? loadingText : children }) }));
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Button, type ButtonProps } from './Button.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Button } from './Button.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.mptk-btn {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
background-color: var(--mptk-business);
|
|
6
|
+
border-radius: var(--mptk-radius-md);
|
|
7
|
+
padding-top: var(--mptk-space-2);
|
|
8
|
+
padding-right: var(--mptk-space-4);
|
|
9
|
+
padding-bottom: var(--mptk-space-2);
|
|
10
|
+
padding-left: var(--mptk-space-4);
|
|
11
|
+
color: var(--mptk-surface-1);
|
|
12
|
+
font-size: var(--mptk-font-lg);
|
|
13
|
+
line-height: var(--mptk-line-lg);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.mptk-btn--disabled {
|
|
17
|
+
background-color: var(--mptk-fg-4);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.mptk-btn--loading {
|
|
21
|
+
background-color: var(--mptk-fg-3);
|
|
22
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.markOverlayHostMounted = markOverlayHostMounted;
|
|
4
|
+
exports.markOverlayHostUnmounted = markOverlayHostUnmounted;
|
|
5
|
+
exports.isOverlayHostMounted = isOverlayHostMounted;
|
|
6
|
+
exports.showToast = showToast;
|
|
7
|
+
exports.hideToast = hideToast;
|
|
8
|
+
exports.clearToasts = clearToasts;
|
|
9
|
+
exports.showLoading = showLoading;
|
|
10
|
+
exports.hideLoading = hideLoading;
|
|
11
|
+
exports.alert = alert;
|
|
12
|
+
exports.confirm = confirm;
|
|
13
|
+
exports.resetUIForTests = resetUIForTests;
|
|
14
|
+
const state_js_1 = require("./state.cjs");
|
|
15
|
+
const NOT_MOUNTED = '[mp-taro-kit/ui] 未挂载 <OverlayHost />;请在页面基座挂一次(mp-taro-kit/ui/infra)';
|
|
16
|
+
/** 开发者契约违例:没挂宿主就想用命令式能力,每次都抛并直给修复动作。 */
|
|
17
|
+
function ensureMounted() {
|
|
18
|
+
if (!(0, state_js_1.uiState)().mounted)
|
|
19
|
+
throw new Error(NOT_MOUNTED);
|
|
20
|
+
}
|
|
21
|
+
/** 供 <OverlayHost /> 在挂载 / 卸载时调用;业务代码不要碰。 */
|
|
22
|
+
function markOverlayHostMounted() {
|
|
23
|
+
(0, state_js_1.uiState)().mounted = true;
|
|
24
|
+
}
|
|
25
|
+
function markOverlayHostUnmounted() {
|
|
26
|
+
(0, state_js_1.uiState)().mounted = false;
|
|
27
|
+
}
|
|
28
|
+
function isOverlayHostMounted() {
|
|
29
|
+
return (0, state_js_1.uiState)().mounted;
|
|
30
|
+
}
|
|
31
|
+
function showToast(text, tone = 'info') {
|
|
32
|
+
ensureMounted();
|
|
33
|
+
return (0, state_js_1.uiState)().notices.show(text, tone);
|
|
34
|
+
}
|
|
35
|
+
function hideToast(id) {
|
|
36
|
+
return (0, state_js_1.uiState)().notices.dismiss(id);
|
|
37
|
+
}
|
|
38
|
+
function clearToasts() {
|
|
39
|
+
return (0, state_js_1.uiState)().notices.clear();
|
|
40
|
+
}
|
|
41
|
+
function showLoading() {
|
|
42
|
+
ensureMounted();
|
|
43
|
+
const state = (0, state_js_1.uiState)();
|
|
44
|
+
const id = state.loading.show();
|
|
45
|
+
state.loadingHandles.add(id);
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
function hideLoading(id) {
|
|
49
|
+
const state = (0, state_js_1.uiState)();
|
|
50
|
+
state.loadingHandles.delete(id);
|
|
51
|
+
return state.loading.hide(id);
|
|
52
|
+
}
|
|
53
|
+
function pushDialog(kind, message, options, resolve) {
|
|
54
|
+
(0, state_js_1.uiState)().overlays.push({
|
|
55
|
+
kind,
|
|
56
|
+
title: options.title,
|
|
57
|
+
message,
|
|
58
|
+
confirmText: options.confirmText ?? '确定',
|
|
59
|
+
cancelText: options.cancelText ?? '取消',
|
|
60
|
+
resolve,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** 解析即关闭;不返回用户选择。 */
|
|
64
|
+
function alert(message, options = {}) {
|
|
65
|
+
ensureMounted();
|
|
66
|
+
return new Promise((resolve) => {
|
|
67
|
+
pushDialog('alert', message, options, () => resolve());
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** 解析 true = 确认、false = 取消;resolve(false) 也可由业务拿来「不关、重试」。 */
|
|
71
|
+
function confirm(message, options = {}) {
|
|
72
|
+
ensureMounted();
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
pushDialog('confirm', message, options, resolve);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** 仅供单测清空全局状态;产品代码不要调用。 */
|
|
78
|
+
function resetUIForTests() {
|
|
79
|
+
const state = (0, state_js_1.uiState)();
|
|
80
|
+
for (const id of state.loadingHandles)
|
|
81
|
+
state.loading.hide(id);
|
|
82
|
+
state.loadingHandles.clear();
|
|
83
|
+
state.overlays.clear();
|
|
84
|
+
state.notices.clear();
|
|
85
|
+
state.mounted = false;
|
|
86
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Notice, NoticeTone } from '../runtime/notify.js';
|
|
2
|
+
/** 供 <OverlayHost /> 在挂载 / 卸载时调用;业务代码不要碰。 */
|
|
3
|
+
export declare function markOverlayHostMounted(): void;
|
|
4
|
+
export declare function markOverlayHostUnmounted(): void;
|
|
5
|
+
export declare function isOverlayHostMounted(): boolean;
|
|
6
|
+
export declare function showToast(text: string, tone?: NoticeTone): number;
|
|
7
|
+
export declare function hideToast(id: number): boolean;
|
|
8
|
+
export declare function clearToasts(): Notice[];
|
|
9
|
+
export declare function showLoading(): number;
|
|
10
|
+
export declare function hideLoading(id: number): boolean;
|
|
11
|
+
export interface DialogOptions {
|
|
12
|
+
title?: string;
|
|
13
|
+
confirmText?: string;
|
|
14
|
+
cancelText?: string;
|
|
15
|
+
}
|
|
16
|
+
/** 解析即关闭;不返回用户选择。 */
|
|
17
|
+
export declare function alert(message: string, options?: DialogOptions): Promise<void>;
|
|
18
|
+
/** 解析 true = 确认、false = 取消;resolve(false) 也可由业务拿来「不关、重试」。 */
|
|
19
|
+
export declare function confirm(message: string, options?: DialogOptions): Promise<boolean>;
|
|
20
|
+
/** 仅供单测清空全局状态;产品代码不要调用。 */
|
|
21
|
+
export declare function resetUIForTests(): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { uiState } from './state.js';
|
|
2
|
+
const NOT_MOUNTED = '[mp-taro-kit/ui] 未挂载 <OverlayHost />;请在页面基座挂一次(mp-taro-kit/ui/infra)';
|
|
3
|
+
/** 开发者契约违例:没挂宿主就想用命令式能力,每次都抛并直给修复动作。 */
|
|
4
|
+
function ensureMounted() {
|
|
5
|
+
if (!uiState().mounted)
|
|
6
|
+
throw new Error(NOT_MOUNTED);
|
|
7
|
+
}
|
|
8
|
+
/** 供 <OverlayHost /> 在挂载 / 卸载时调用;业务代码不要碰。 */
|
|
9
|
+
export function markOverlayHostMounted() {
|
|
10
|
+
uiState().mounted = true;
|
|
11
|
+
}
|
|
12
|
+
export function markOverlayHostUnmounted() {
|
|
13
|
+
uiState().mounted = false;
|
|
14
|
+
}
|
|
15
|
+
export function isOverlayHostMounted() {
|
|
16
|
+
return uiState().mounted;
|
|
17
|
+
}
|
|
18
|
+
export function showToast(text, tone = 'info') {
|
|
19
|
+
ensureMounted();
|
|
20
|
+
return uiState().notices.show(text, tone);
|
|
21
|
+
}
|
|
22
|
+
export function hideToast(id) {
|
|
23
|
+
return uiState().notices.dismiss(id);
|
|
24
|
+
}
|
|
25
|
+
export function clearToasts() {
|
|
26
|
+
return uiState().notices.clear();
|
|
27
|
+
}
|
|
28
|
+
export function showLoading() {
|
|
29
|
+
ensureMounted();
|
|
30
|
+
const state = uiState();
|
|
31
|
+
const id = state.loading.show();
|
|
32
|
+
state.loadingHandles.add(id);
|
|
33
|
+
return id;
|
|
34
|
+
}
|
|
35
|
+
export function hideLoading(id) {
|
|
36
|
+
const state = uiState();
|
|
37
|
+
state.loadingHandles.delete(id);
|
|
38
|
+
return state.loading.hide(id);
|
|
39
|
+
}
|
|
40
|
+
function pushDialog(kind, message, options, resolve) {
|
|
41
|
+
uiState().overlays.push({
|
|
42
|
+
kind,
|
|
43
|
+
title: options.title,
|
|
44
|
+
message,
|
|
45
|
+
confirmText: options.confirmText ?? '确定',
|
|
46
|
+
cancelText: options.cancelText ?? '取消',
|
|
47
|
+
resolve,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** 解析即关闭;不返回用户选择。 */
|
|
51
|
+
export function alert(message, options = {}) {
|
|
52
|
+
ensureMounted();
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
pushDialog('alert', message, options, () => resolve());
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** 解析 true = 确认、false = 取消;resolve(false) 也可由业务拿来「不关、重试」。 */
|
|
58
|
+
export function confirm(message, options = {}) {
|
|
59
|
+
ensureMounted();
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
pushDialog('confirm', message, options, resolve);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** 仅供单测清空全局状态;产品代码不要调用。 */
|
|
65
|
+
export function resetUIForTests() {
|
|
66
|
+
const state = uiState();
|
|
67
|
+
for (const id of state.loadingHandles)
|
|
68
|
+
state.loading.hide(id);
|
|
69
|
+
state.loadingHandles.clear();
|
|
70
|
+
state.overlays.clear();
|
|
71
|
+
state.notices.clear();
|
|
72
|
+
state.mounted = false;
|
|
73
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Badge = Badge;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const components_1 = require("@tarojs/components");
|
|
6
|
+
/** 徽标:数字 / 小红点,宿主只给数值,不进业务逻辑。 */
|
|
7
|
+
function Badge({ count, dot = false, children, className }) {
|
|
8
|
+
const names = ['mptk-badge', className];
|
|
9
|
+
return ((0, jsx_runtime_1.jsxs)(components_1.View, { className: names.filter(Boolean).join(' '), children: [children, dot ? ((0, jsx_runtime_1.jsx)(components_1.View, { className: "mptk-badge__dot" })) : count === undefined ? null : ((0, jsx_runtime_1.jsx)(components_1.View, { className: "mptk-badge__count", children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: count }) }))] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface BadgeProps {
|
|
3
|
+
count?: number | string;
|
|
4
|
+
dot?: boolean;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
/** 徽标:数字 / 小红点,宿主只给数值,不进业务逻辑。 */
|
|
9
|
+
export declare function Badge({ count, dot, children, className }: BadgeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View, Text } from '@tarojs/components';
|
|
3
|
+
/** 徽标:数字 / 小红点,宿主只给数值,不进业务逻辑。 */
|
|
4
|
+
export function Badge({ count, dot = false, children, className }) {
|
|
5
|
+
const names = ['mptk-badge', className];
|
|
6
|
+
return (_jsxs(View, { className: names.filter(Boolean).join(' '), children: [children, dot ? (_jsx(View, { className: "mptk-badge__dot" })) : count === undefined ? null : (_jsx(View, { className: "mptk-badge__count", children: _jsx(Text, { children: count }) }))] }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Divider = Divider;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const components_1 = require("@tarojs/components");
|
|
6
|
+
/** 分隔线:纯展示,无业务内容。 */
|
|
7
|
+
function Divider({ className }) {
|
|
8
|
+
return (0, jsx_runtime_1.jsx)(components_1.View, { className: ['mptk-divider', className].filter(Boolean).join(' ') });
|
|
9
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Badge = exports.Divider = void 0;
|
|
4
|
+
var Divider_js_1 = require("./Divider.cjs");
|
|
5
|
+
Object.defineProperty(exports, "Divider", { enumerable: true, get: function () { return Divider_js_1.Divider; } });
|
|
6
|
+
var Badge_js_1 = require("./Badge.cjs");
|
|
7
|
+
Object.defineProperty(exports, "Badge", { enumerable: true, get: function () { return Badge_js_1.Badge; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.mptk-divider {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 1px;
|
|
4
|
+
background-color: var(--mptk-border);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.mptk-badge {
|
|
8
|
+
position: relative;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.mptk-badge__dot {
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 0;
|
|
14
|
+
right: 0;
|
|
15
|
+
width: var(--mptk-space-2);
|
|
16
|
+
height: var(--mptk-space-2);
|
|
17
|
+
border-radius: var(--mptk-radius-pill);
|
|
18
|
+
background-color: var(--mptk-danger);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.mptk-badge__count {
|
|
22
|
+
position: absolute;
|
|
23
|
+
top: 0;
|
|
24
|
+
right: 0;
|
|
25
|
+
border-radius: var(--mptk-radius-pill);
|
|
26
|
+
background-color: var(--mptk-danger);
|
|
27
|
+
color: var(--mptk-surface-1);
|
|
28
|
+
font-size: var(--mptk-font-xs);
|
|
29
|
+
line-height: var(--mptk-line-xs);
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Dialog = Dialog;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const components_1 = require("@tarojs/components");
|
|
6
|
+
/** 声明式 Dialog;命令式 confirm()/alert() 走 <OverlayHost /> 渲染。 */
|
|
7
|
+
function Dialog({ open, title, children, confirmText = '确定', cancelText = '取消', showCancel = true, onConfirm, onCancel, className, }) {
|
|
8
|
+
if (!open)
|
|
9
|
+
return null;
|
|
10
|
+
const names = ['mptk-fb-dialog', className];
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(components_1.View, { className: names.filter(Boolean).join(' '), children: (0, jsx_runtime_1.jsxs)(components_1.View, { className: "mptk-fb-dialog__panel", children: [title === undefined ? null : ((0, jsx_runtime_1.jsx)(components_1.View, { className: "mptk-fb-dialog__title", children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: title }) })), (0, jsx_runtime_1.jsx)(components_1.View, { className: "mptk-fb-dialog__body", children: children }), (0, jsx_runtime_1.jsxs)(components_1.View, { className: "mptk-fb-dialog__actions", children: [showCancel ? ((0, jsx_runtime_1.jsx)(components_1.View, { className: "mptk-fb-dialog__action--cancel", onClick: () => onCancel?.(), children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: cancelText }) })) : null, (0, jsx_runtime_1.jsx)(components_1.View, { className: "mptk-fb-dialog__action--confirm", onClick: () => onConfirm?.(), children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: confirmText }) })] })] }) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface DialogProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
title?: string;
|
|
5
|
+
/** 内容由宿主注入,库只提供容器与按钮。 */
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
confirmText?: string;
|
|
8
|
+
cancelText?: string;
|
|
9
|
+
showCancel?: boolean;
|
|
10
|
+
onConfirm?: () => void;
|
|
11
|
+
onCancel?: () => void;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/** 声明式 Dialog;命令式 confirm()/alert() 走 <OverlayHost /> 渲染。 */
|
|
15
|
+
export declare function Dialog({ open, title, children, confirmText, cancelText, showCancel, onConfirm, onCancel, className, }: DialogProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View, Text } from '@tarojs/components';
|
|
3
|
+
/** 声明式 Dialog;命令式 confirm()/alert() 走 <OverlayHost /> 渲染。 */
|
|
4
|
+
export function Dialog({ open, title, children, confirmText = '确定', cancelText = '取消', showCancel = true, onConfirm, onCancel, className, }) {
|
|
5
|
+
if (!open)
|
|
6
|
+
return null;
|
|
7
|
+
const names = ['mptk-fb-dialog', className];
|
|
8
|
+
return (_jsx(View, { className: names.filter(Boolean).join(' '), children: _jsxs(View, { className: "mptk-fb-dialog__panel", children: [title === undefined ? null : (_jsx(View, { className: "mptk-fb-dialog__title", children: _jsx(Text, { children: title }) })), _jsx(View, { className: "mptk-fb-dialog__body", children: children }), _jsxs(View, { className: "mptk-fb-dialog__actions", children: [showCancel ? (_jsx(View, { className: "mptk-fb-dialog__action--cancel", onClick: () => onCancel?.(), children: _jsx(Text, { children: cancelText }) })) : null, _jsx(View, { className: "mptk-fb-dialog__action--confirm", onClick: () => onConfirm?.(), children: _jsx(Text, { children: confirmText }) })] })] }) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Loading = Loading;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const components_1 = require("@tarojs/components");
|
|
6
|
+
/** 声明式 Loading;全局唯一 loading 槽由 <OverlayHost /> 消费。 */
|
|
7
|
+
function Loading({ visible = true, text = '加载中', className }) {
|
|
8
|
+
if (!visible)
|
|
9
|
+
return null;
|
|
10
|
+
const names = ['mptk-fb-loading', className];
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(components_1.View, { className: names.filter(Boolean).join(' '), children: (0, jsx_runtime_1.jsx)(components_1.Text, { className: "mptk-fb-loading__text", children: text }) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { View, Text } from '@tarojs/components';
|
|
3
|
+
/** 声明式 Loading;全局唯一 loading 槽由 <OverlayHost /> 消费。 */
|
|
4
|
+
export function Loading({ visible = true, text = '加载中', className }) {
|
|
5
|
+
if (!visible)
|
|
6
|
+
return null;
|
|
7
|
+
const names = ['mptk-fb-loading', className];
|
|
8
|
+
return (_jsx(View, { className: names.filter(Boolean).join(' '), children: _jsx(Text, { className: "mptk-fb-loading__text", children: text }) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Toast = Toast;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const components_1 = require("@tarojs/components");
|
|
6
|
+
/** 声明式 Toast;自动消失与队列交给命令式 API 与 runtime 的通知中心。 */
|
|
7
|
+
function Toast({ text, tone = 'info', visible = true, className }) {
|
|
8
|
+
if (!visible)
|
|
9
|
+
return null;
|
|
10
|
+
const names = ['mptk-fb-toast', `mptk-fb-toast--${tone}`, className];
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(components_1.View, { className: names.filter(Boolean).join(' '), children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: text }) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NoticeTone } from '../../runtime/notify.js';
|
|
2
|
+
export interface ToastProps {
|
|
3
|
+
text: string;
|
|
4
|
+
tone?: NoticeTone;
|
|
5
|
+
visible?: boolean;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
/** 声明式 Toast;自动消失与队列交给命令式 API 与 runtime 的通知中心。 */
|
|
9
|
+
export declare function Toast({ text, tone, visible, className }: ToastProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { View, Text } from '@tarojs/components';
|
|
3
|
+
/** 声明式 Toast;自动消失与队列交给命令式 API 与 runtime 的通知中心。 */
|
|
4
|
+
export function Toast({ text, tone = 'info', visible = true, className }) {
|
|
5
|
+
if (!visible)
|
|
6
|
+
return null;
|
|
7
|
+
const names = ['mptk-fb-toast', `mptk-fb-toast--${tone}`, className];
|
|
8
|
+
return (_jsx(View, { className: names.filter(Boolean).join(' '), children: _jsx(Text, { children: text }) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Dialog = exports.Loading = exports.Toast = void 0;
|
|
4
|
+
var Toast_js_1 = require("./Toast.cjs");
|
|
5
|
+
Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return Toast_js_1.Toast; } });
|
|
6
|
+
var Loading_js_1 = require("./Loading.cjs");
|
|
7
|
+
Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return Loading_js_1.Loading; } });
|
|
8
|
+
var Dialog_js_1 = require("./Dialog.cjs");
|
|
9
|
+
Object.defineProperty(exports, "Dialog", { enumerable: true, get: function () { return Dialog_js_1.Dialog; } });
|