@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.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/CHANGELOG.md +67 -0
- package/LICENSE +21 -0
- package/README.md +179 -2
- package/THIRD_PARTY_NOTICES.md +19 -0
- package/dist/ActionSheet.d.ts +45 -0
- package/dist/ActionSheet.jsx +37 -0
- package/dist/AnchoredBubble.d.ts +36 -0
- package/dist/AnchoredBubble.jsx +120 -0
- package/dist/Avatar.d.ts +35 -0
- package/dist/Avatar.jsx +29 -0
- package/dist/Backtop.d.ts +22 -0
- package/dist/Backtop.jsx +18 -0
- package/dist/Badge.d.ts +19 -0
- package/dist/Badge.jsx +11 -0
- package/dist/BarCode.d.ts +20 -0
- package/dist/BarCode.jsx +38 -0
- package/dist/Button.d.ts +21 -0
- package/dist/Button.jsx +19 -0
- package/dist/Calendar.d.ts +90 -0
- package/dist/Calendar.jsx +164 -0
- package/dist/CalendarView.d.ts +51 -0
- package/dist/CalendarView.jsx +136 -0
- package/dist/Card.d.ts +21 -0
- package/dist/Card.jsx +21 -0
- package/dist/Cascader.d.ts +75 -0
- package/dist/Cascader.jsx +212 -0
- package/dist/Cell.d.ts +34 -0
- package/dist/Cell.jsx +37 -0
- package/dist/Checkbox.d.ts +50 -0
- package/dist/Checkbox.jsx +74 -0
- package/dist/Circle.d.ts +19 -0
- package/dist/Circle.jsx +35 -0
- package/dist/Collapse.d.ts +31 -0
- package/dist/Collapse.jsx +61 -0
- package/dist/ConfigProvider.d.ts +15 -0
- package/dist/ConfigProvider.jsx +20 -0
- package/dist/CountDown.d.ts +20 -0
- package/dist/CountDown.jsx +15 -0
- package/dist/CountTo.d.ts +28 -0
- package/dist/CountTo.jsx +27 -0
- package/dist/Curtain.d.ts +29 -0
- package/dist/Curtain.jsx +51 -0
- package/dist/DatetimePicker.d.ts +46 -0
- package/dist/DatetimePicker.jsx +138 -0
- package/dist/DatetimePickerView.d.ts +38 -0
- package/dist/DatetimePickerView.jsx +36 -0
- package/dist/Dialog.d.ts +64 -0
- package/dist/Dialog.jsx +105 -0
- package/dist/Divider.d.ts +16 -0
- package/dist/Divider.jsx +9 -0
- package/dist/DropMenu.d.ts +55 -0
- package/dist/DropMenu.jsx +210 -0
- package/dist/Empty.d.ts +14 -0
- package/dist/Empty.jsx +14 -0
- package/dist/EmptyState.d.ts +6 -0
- package/dist/EmptyState.jsx +9 -0
- package/dist/Fab.d.ts +30 -0
- package/dist/Fab.jsx +127 -0
- package/dist/FloatingPanel.d.ts +21 -0
- package/dist/FloatingPanel.jsx +102 -0
- package/dist/Form.d.ts +63 -0
- package/dist/Form.jsx +108 -0
- package/dist/FormFieldRow.d.ts +56 -0
- package/dist/FormFieldRow.jsx +63 -0
- package/dist/Gap.d.ts +10 -0
- package/dist/Gap.jsx +14 -0
- package/dist/Grid.d.ts +47 -0
- package/dist/Grid.jsx +31 -0
- package/dist/Icon.d.ts +11 -0
- package/dist/Icon.jsx +12 -0
- package/dist/ImagePreview.d.ts +62 -0
- package/dist/ImagePreview.jsx +78 -0
- package/dist/Img.d.ts +28 -0
- package/dist/Img.jsx +59 -0
- package/dist/ImgCropper.d.ts +74 -0
- package/dist/ImgCropper.jsx +114 -0
- package/dist/IndexBar.d.ts +36 -0
- package/dist/IndexBar.jsx +149 -0
- package/dist/Input.d.ts +11 -0
- package/dist/Input.jsx +3 -0
- package/dist/InputNumber.d.ts +32 -0
- package/dist/InputNumber.jsx +165 -0
- package/dist/Keyboard.d.ts +37 -0
- package/dist/Keyboard.jsx +130 -0
- package/dist/Layout.d.ts +31 -0
- package/dist/Layout.jsx +14 -0
- package/dist/Loading.d.ts +18 -0
- package/dist/Loading.jsx +15 -0
- package/dist/Loadmore.d.ts +18 -0
- package/dist/Loadmore.jsx +16 -0
- package/dist/Navbar.d.ts +35 -0
- package/dist/Navbar.jsx +50 -0
- package/dist/NoticeBar.d.ts +30 -0
- package/dist/NoticeBar.jsx +86 -0
- package/dist/Notify.d.ts +34 -0
- package/dist/Notify.jsx +52 -0
- package/dist/NumberStepper.d.ts +11 -0
- package/dist/NumberStepper.jsx +41 -0
- package/dist/Overlay.d.ts +16 -0
- package/dist/Overlay.jsx +12 -0
- package/dist/PagedList.d.ts +13 -0
- package/dist/PagedList.jsx +36 -0
- package/dist/Pagination.d.ts +29 -0
- package/dist/Pagination.jsx +33 -0
- package/dist/PasswordInput.d.ts +16 -0
- package/dist/PasswordInput.jsx +20 -0
- package/dist/Picker.d.ts +61 -0
- package/dist/Picker.jsx +80 -0
- package/dist/PickerView.d.ts +43 -0
- package/dist/PickerView.jsx +142 -0
- package/dist/Popover.d.ts +23 -0
- package/dist/Popover.jsx +35 -0
- package/dist/Popup.d.ts +30 -0
- package/dist/Popup.jsx +32 -0
- package/dist/Progress.d.ts +17 -0
- package/dist/Progress.jsx +45 -0
- package/dist/QrCode.d.ts +46 -0
- package/dist/QrCode.jsx +67 -0
- package/dist/Radio.d.ts +21 -0
- package/dist/Radio.jsx +34 -0
- package/dist/Rate.d.ts +25 -0
- package/dist/Rate.jsx +39 -0
- package/dist/Resize.d.ts +17 -0
- package/dist/Resize.jsx +17 -0
- package/dist/RichText.d.ts +133 -0
- package/dist/RichText.jsx +288 -0
- package/dist/RootPortal.d.ts +11 -0
- package/dist/RootPortal.jsx +19 -0
- package/dist/Search.d.ts +39 -0
- package/dist/Search.jsx +94 -0
- package/dist/Segmented.d.ts +18 -0
- package/dist/Segmented.jsx +35 -0
- package/dist/SelectPicker.d.ts +54 -0
- package/dist/SelectPicker.jsx +136 -0
- package/dist/Sidebar.d.ts +34 -0
- package/dist/Sidebar.jsx +43 -0
- package/dist/Signature.d.ts +46 -0
- package/dist/Signature.jsx +203 -0
- package/dist/Skeleton.d.ts +27 -0
- package/dist/Skeleton.jsx +29 -0
- package/dist/SlideVerify.d.ts +27 -0
- package/dist/SlideVerify.jsx +138 -0
- package/dist/Slider.d.ts +21 -0
- package/dist/Slider.jsx +131 -0
- package/dist/SortButton.d.ts +16 -0
- package/dist/SortButton.jsx +19 -0
- package/dist/Steps.d.ts +23 -0
- package/dist/Steps.jsx +25 -0
- package/dist/Sticky.d.ts +17 -0
- package/dist/Sticky.jsx +69 -0
- package/dist/SwipeAction.d.ts +27 -0
- package/dist/SwipeAction.jsx +187 -0
- package/dist/Swiper.d.ts +54 -0
- package/dist/Swiper.jsx +94 -0
- package/dist/SwiperNav.d.ts +18 -0
- package/dist/SwiperNav.jsx +10 -0
- package/dist/Switch.d.ts +31 -0
- package/dist/Switch.jsx +46 -0
- package/dist/SyncedInput.d.ts +12 -0
- package/dist/SyncedInput.jsx +18 -0
- package/dist/SyncedTextarea.d.ts +11 -0
- package/dist/SyncedTextarea.jsx +18 -0
- package/dist/Tabbar.d.ts +37 -0
- package/dist/Tabbar.jsx +46 -0
- package/dist/Table.d.ts +51 -0
- package/dist/Table.jsx +125 -0
- package/dist/Tabs.d.ts +65 -0
- package/dist/Tabs.jsx +132 -0
- package/dist/Tag.d.ts +33 -0
- package/dist/Tag.jsx +63 -0
- package/dist/Text.d.ts +19 -0
- package/dist/Text.jsx +7 -0
- package/dist/TextField.d.ts +89 -0
- package/dist/TextField.jsx +149 -0
- package/dist/Textarea.d.ts +22 -0
- package/dist/Textarea.jsx +3 -0
- package/dist/Toast.d.ts +36 -0
- package/dist/Toast.jsx +30 -0
- package/dist/Tooltip.d.ts +8 -0
- package/dist/Tooltip.jsx +5 -0
- package/dist/Tour.d.ts +85 -0
- package/dist/Tour.jsx +150 -0
- package/dist/Transition.d.ts +32 -0
- package/dist/Transition.jsx +43 -0
- package/dist/Upload.d.ts +64 -0
- package/dist/Upload.jsx +163 -0
- package/dist/VideoPreview.d.ts +47 -0
- package/dist/VideoPreview.jsx +59 -0
- package/dist/Watermark.d.ts +36 -0
- package/dist/Watermark.jsx +18 -0
- package/dist/action-sheet.css +19 -0
- package/dist/avatar.css +23 -0
- package/dist/avatarModel.d.ts +8 -0
- package/dist/avatarModel.js +17 -0
- package/dist/backtop.css +6 -0
- package/dist/badge.css +15 -0
- package/dist/badgeModel.d.ts +2 -0
- package/dist/badgeModel.js +18 -0
- package/dist/bar-code.css +5 -0
- package/dist/barCodeModel.d.ts +80 -0
- package/dist/barCodeModel.js +99 -0
- package/dist/brand/logo.svg +8 -0
- package/dist/bubble.css +14 -0
- package/dist/bubblePosition.d.ts +19 -0
- package/dist/bubblePosition.js +41 -0
- package/dist/button.css +56 -0
- package/dist/calendar.css +56 -0
- package/dist/calendarModel.d.ts +62 -0
- package/dist/calendarModel.js +141 -0
- package/dist/card.css +8 -0
- package/dist/cascader.css +16 -0
- package/dist/cascaderModel.d.ts +21 -0
- package/dist/cascaderModel.js +32 -0
- package/dist/cell.css +41 -0
- package/dist/choice.css +27 -0
- package/dist/choice.d.ts +28 -0
- package/dist/choice.jsx +16 -0
- package/dist/circle.css +4 -0
- package/dist/circleModel.d.ts +15 -0
- package/dist/circleModel.js +31 -0
- package/dist/config-provider.css +2 -0
- package/dist/configContext.d.ts +23 -0
- package/dist/configContext.js +24 -0
- package/dist/configTheme.d.ts +3 -0
- package/dist/configTheme.js +22 -0
- package/dist/count-down.css +2 -0
- package/dist/count-to.css +8 -0
- package/dist/countDownModel.d.ts +11 -0
- package/dist/countDownModel.js +7 -0
- package/dist/countToModel.d.ts +3 -0
- package/dist/countToModel.js +3 -0
- package/dist/curtain.css +10 -0
- package/dist/datetime-picker.css +11 -0
- package/dist/datetimePickerModel.d.ts +47 -0
- package/dist/datetimePickerModel.js +128 -0
- package/dist/dialog.css +23 -0
- package/dist/divider.css +14 -0
- package/dist/drop-menu.css +28 -0
- package/dist/empty.css +7 -0
- package/dist/fab.css +23 -0
- package/dist/fabModel.d.ts +26 -0
- package/dist/fabModel.js +16 -0
- package/dist/floating-panel.css +6 -0
- package/dist/floatingPanelModel.d.ts +3 -0
- package/dist/floatingPanelModel.js +10 -0
- package/dist/form.css +10 -0
- package/dist/formContext.d.ts +7 -0
- package/dist/formContext.js +2 -0
- package/dist/formModel.d.ts +38 -0
- package/dist/formModel.js +16 -0
- package/dist/gap.css +1 -0
- package/dist/grid.css +17 -0
- package/dist/icon.css +8 -0
- package/dist/icons/LICENSE.tabler +21 -0
- package/dist/icons/paths.d.ts +309 -0
- package/dist/icons/paths.js +310 -0
- package/dist/icons/render.d.ts +2 -0
- package/dist/icons/render.js +5 -0
- package/dist/image-preview.css +8 -0
- package/dist/img-cropper.css +1 -0
- package/dist/img.css +5 -0
- package/dist/imgCropperModel.d.ts +55 -0
- package/dist/imgCropperModel.js +41 -0
- package/dist/imgModel.d.ts +13 -0
- package/dist/imgModel.js +22 -0
- package/dist/index-bar.css +12 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +99 -0
- package/dist/indexBarModel.d.ts +19 -0
- package/dist/indexBarModel.js +37 -0
- package/dist/input-number.css +24 -0
- package/dist/inputNumberModel.d.ts +23 -0
- package/dist/inputNumberModel.js +40 -0
- package/dist/keyboard.css +26 -0
- package/dist/keyboardModel.d.ts +11 -0
- package/dist/keyboardModel.js +34 -0
- package/dist/layout.css +2 -0
- package/dist/legacy/RadioGroup.d.ts +13 -0
- package/dist/legacy/RadioGroup.jsx +13 -0
- package/dist/legacy-controls.css +87 -0
- package/dist/loading.css +31 -0
- package/dist/loadingModel.d.ts +2 -0
- package/dist/loadingModel.js +21 -0
- package/dist/loadmore.css +5 -0
- package/dist/navbar.css +16 -0
- package/dist/notice-bar.css +19 -0
- package/dist/notify.css +14 -0
- package/dist/overlay.css +2 -0
- package/dist/pagination.css +12 -0
- package/dist/paginationModel.d.ts +6 -0
- package/dist/paginationModel.js +7 -0
- package/dist/password-input.css +14 -0
- package/dist/passwordInputModel.d.ts +6 -0
- package/dist/passwordInputModel.js +11 -0
- package/dist/picker.css +42 -0
- package/dist/pickerModel.d.ts +32 -0
- package/dist/pickerModel.js +49 -0
- package/dist/popover.css +5 -0
- package/dist/popup.css +17 -0
- package/dist/progress.css +16 -0
- package/dist/progressModel.d.ts +12 -0
- package/dist/progressModel.js +19 -0
- package/dist/qr-code.css +4 -0
- package/dist/qrCodeModel.d.ts +36 -0
- package/dist/qrCodeModel.js +61 -0
- package/dist/rate.css +20 -0
- package/dist/rateModel.d.ts +4 -0
- package/dist/rateModel.js +38 -0
- package/dist/resize.css +2 -0
- package/dist/rich-text.css +19 -0
- package/dist/richTextMedia.d.ts +28 -0
- package/dist/richTextMedia.js +3 -0
- package/dist/richTextModel.d.ts +52 -0
- package/dist/richTextModel.js +195 -0
- package/dist/root-portal.css +1 -0
- package/dist/router/RouterView.d.ts +21 -0
- package/dist/router/RouterView.jsx +120 -0
- package/dist/router/core.d.ts +85 -0
- package/dist/router/core.js +255 -0
- package/dist/router/hooks.d.ts +17 -0
- package/dist/router/hooks.jsx +71 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.js +3 -0
- package/dist/router/location.d.ts +8 -0
- package/dist/router/location.js +46 -0
- package/dist/router/router.css +7 -0
- package/dist/router/runtime.d.ts +1 -0
- package/dist/router/runtime.js +25 -0
- package/dist/search.css +23 -0
- package/dist/segmented.css +19 -0
- package/dist/segmentedModel.d.ts +10 -0
- package/dist/segmentedModel.js +8 -0
- package/dist/sidebar.css +18 -0
- package/dist/sidebarModel.d.ts +8 -0
- package/dist/sidebarModel.js +27 -0
- package/dist/signature.css +5 -0
- package/dist/signatureModel.d.ts +23 -0
- package/dist/signatureModel.js +80 -0
- package/dist/skeleton.css +16 -0
- package/dist/slide-verify.css +7 -0
- package/dist/slider.css +49 -0
- package/dist/sliderModel.d.ts +10 -0
- package/dist/sliderModel.js +27 -0
- package/dist/sort-button.css +12 -0
- package/dist/steps.css +35 -0
- package/dist/sticky.css +7 -0
- package/dist/styles.css +136 -0
- package/dist/styles.d.ts +1 -0
- package/dist/swipe-action.css +6 -0
- package/dist/swiper.css +27 -0
- package/dist/swiperAnimation.d.ts +3 -0
- package/dist/swiperAnimation.js +6 -0
- package/dist/swiperModel.d.ts +2 -0
- package/dist/swiperModel.js +3 -0
- package/dist/switch.css +12 -0
- package/dist/tabbar.css +17 -0
- package/dist/tabbarModel.d.ts +8 -0
- package/dist/tabbarModel.js +27 -0
- package/dist/table.css +21 -0
- package/dist/tableModel.d.ts +10 -0
- package/dist/tableModel.js +17 -0
- package/dist/tabs.css +31 -0
- package/dist/tabsModel.d.ts +7 -0
- package/dist/tabsModel.js +14 -0
- package/dist/tag.css +66 -0
- package/dist/text-field.css +15 -0
- package/dist/text.css +7 -0
- package/dist/textModel.d.ts +3 -0
- package/dist/textModel.js +24 -0
- package/dist/toast.css +13 -0
- package/dist/tokens.d.ts +34 -0
- package/dist/tokens.js +10 -0
- package/dist/tour.css +8 -0
- package/dist/transition.css +12 -0
- package/dist/upload.css +11 -0
- package/dist/useCountDown.d.ts +14 -0
- package/dist/useCountDown.js +73 -0
- package/dist/useDialog.d.ts +9 -0
- package/dist/useDialog.js +33 -0
- package/dist/useImagePreview.d.ts +7 -0
- package/dist/useImagePreview.js +17 -0
- package/dist/useNotify.d.ts +9 -0
- package/dist/useNotify.js +26 -0
- package/dist/usePressState.d.ts +6 -0
- package/dist/usePressState.js +17 -0
- package/dist/useToast.d.ts +11 -0
- package/dist/useToast.js +23 -0
- package/dist/useVideoPreview.d.ts +7 -0
- package/dist/useVideoPreview.js +17 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +4 -0
- package/dist/video-preview.css +7 -0
- package/dist/watermark.css +6 -0
- package/dist/web/imgCropperElement.d.ts +2 -0
- package/dist/web/imgCropperElement.js +309 -0
- package/dist/web/index.d.ts +6 -0
- package/dist/web/index.js +6 -0
- package/dist/web/qrCodeExportElement.d.ts +4 -0
- package/dist/web/qrCodeExportElement.js +70 -0
- package/dist/web/richTextMediaElement.d.ts +2 -0
- package/dist/web/richTextMediaElement.js +276 -0
- package/package.json +98 -4
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { FormFieldContext } from './formContext.js';
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
const textValue = (value) => value === undefined ? '' : String(value);
|
|
5
|
+
const nonnegative = (n, fallback) => Number.isFinite(n) ? Math.max(0, n) : fallback;
|
|
6
|
+
const node = (content) => typeof content === 'string' || typeof content === 'number' ? <text>{content}</text> : content;
|
|
7
|
+
/** Shared native editing/synchronization; browser APIs belong only in the H5 host. */
|
|
8
|
+
export const TextField = forwardRef(function TextField({ value, defaultValue = '', onChange, onInput, placeholder = '请输入...', maxlength = -1, disabled: disabledProp, readonly = false, clearable = false, clearTrigger = 'always', focusWhenClear = true, error: errorProp, compact: compactProp, alignRight = false, prefixIcon, suffixIcon, prefix, suffix, showWordLimit = false, focus, confirmType = 'done', confirmHold = false, avoidKeyboard = true, cursorSpacing = 0, softInputMode = 'nothing', holdKeyboard = false, selectionStart, selectionEnd, placeholderColor, inputFilter, showSoftInputOnFocus = true, ignoreCompositionEvent = true, onFocus, onBlur, onConfirm, onClear, onClickPrefixIcon, onClickSuffixIcon, onTap, onKeyboardHeightChange, className = '', inputClassName = '', style, multiline = false, type = 'text', textAlign, showPassword = false, autoHeight = false, height = 150, minHeight = 20, maxHeight, maxlines = 2147483647, onLineChange }, ref) {
|
|
9
|
+
const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false, error = errorProp ?? field?.error ?? false, compact = compactProp ?? field?.compact ?? false;
|
|
10
|
+
const [inner, setInner] = useState(textValue(defaultValue)), [focused, setFocused] = useState(false), [visiblePassword, setVisiblePassword] = useState(false);
|
|
11
|
+
const [composing, setComposing] = useState(false), [measuredHeight, setMeasuredHeight] = useState(20);
|
|
12
|
+
// Even an identical rejected edit/clear must reconcile the native editor.
|
|
13
|
+
const [editVersion, setEditVersion] = useState(0);
|
|
14
|
+
const text = composing ? inner : textValue(value ?? inner);
|
|
15
|
+
const initial = useRef(text), native = useRef(null), nativeValue = useRef(null);
|
|
16
|
+
const blurTimer = useRef();
|
|
17
|
+
const blocked = disabled || readonly;
|
|
18
|
+
const writeNative = (next) => {
|
|
19
|
+
'background only';
|
|
20
|
+
nativeValue.current = next;
|
|
21
|
+
native.current?.invoke({ method: 'setValue', params: { value: next } }).exec();
|
|
22
|
+
};
|
|
23
|
+
const requestFocus = () => {
|
|
24
|
+
'background only';
|
|
25
|
+
if (!disabled)
|
|
26
|
+
native.current?.invoke({ method: 'focus' }).exec();
|
|
27
|
+
};
|
|
28
|
+
const requestBlur = () => {
|
|
29
|
+
'background only';
|
|
30
|
+
native.current?.invoke({ method: 'blur' }).exec();
|
|
31
|
+
};
|
|
32
|
+
const setSelection = (start, end) => {
|
|
33
|
+
'background only';
|
|
34
|
+
const from = Math.max(0, Math.min(text.length, Math.trunc(start))), to = Math.max(from, Math.min(text.length, Math.trunc(end)));
|
|
35
|
+
if (Number.isFinite(from) && Number.isFinite(to))
|
|
36
|
+
native.current?.invoke({ method: 'setSelectionRange', params: { selectionStart: from, selectionEnd: to } }).exec();
|
|
37
|
+
};
|
|
38
|
+
useImperativeHandle(ref, () => ({ focus: requestFocus, blur: requestBlur, setSelectionRange: setSelection }), [disabled, text]);
|
|
39
|
+
useEffect(() => { if (!composing && nativeValue.current !== text)
|
|
40
|
+
writeNative(text); }, [text, inner, composing, editVersion]);
|
|
41
|
+
useEffect(() => { if (focus === true)
|
|
42
|
+
requestFocus();
|
|
43
|
+
else if (focus === false)
|
|
44
|
+
requestBlur(); }, [focus, disabled]);
|
|
45
|
+
useEffect(() => { if (selectionStart !== undefined && selectionEnd !== undefined)
|
|
46
|
+
setSelection(selectionStart, selectionEnd); }, [selectionStart, selectionEnd, text]);
|
|
47
|
+
useEffect(() => () => clearTimeout(blurTimer.current), []);
|
|
48
|
+
const change = (event) => {
|
|
49
|
+
'background only';
|
|
50
|
+
if (blocked)
|
|
51
|
+
return;
|
|
52
|
+
const detail = event.detail;
|
|
53
|
+
nativeValue.current = detail.value;
|
|
54
|
+
setInner(detail.value);
|
|
55
|
+
setEditVersion(version => version + 1);
|
|
56
|
+
setComposing(!!detail.isComposing);
|
|
57
|
+
if (ignoreCompositionEvent && detail.isComposing)
|
|
58
|
+
return;
|
|
59
|
+
onInput?.(detail);
|
|
60
|
+
onChange?.(detail.value);
|
|
61
|
+
};
|
|
62
|
+
const clear = () => {
|
|
63
|
+
'background only';
|
|
64
|
+
if (blocked || !text)
|
|
65
|
+
return;
|
|
66
|
+
clearTimeout(blurTimer.current);
|
|
67
|
+
setComposing(false);
|
|
68
|
+
setInner('');
|
|
69
|
+
setEditVersion(version => version + 1);
|
|
70
|
+
writeNative('');
|
|
71
|
+
onInput?.({ value: '' });
|
|
72
|
+
onChange?.('');
|
|
73
|
+
onClear?.();
|
|
74
|
+
if (focusWhenClear)
|
|
75
|
+
requestFocus();
|
|
76
|
+
};
|
|
77
|
+
const showClear = clearable && !blocked && text.length > 0 && (clearTrigger === 'always' || focused);
|
|
78
|
+
const count = showWordLimit && Number.isFinite(maxlength) && maxlength >= 0;
|
|
79
|
+
const textareaHeight = autoHeight ? Math.min(maxHeight === undefined ? Infinity : nonnegative(maxHeight, Infinity), Math.max(nonnegative(minHeight, 20), measuredHeight)) : nonnegative(height, 150);
|
|
80
|
+
const common = {
|
|
81
|
+
ref: native, 'default-value': initial.current, placeholder, maxlength: Number.isFinite(maxlength) ? Math.max(-1, Math.trunc(maxlength)) : -1, disabled, readonly,
|
|
82
|
+
'input-filter': inputFilter, 'confirm-type': confirmType, 'confirm-enter': confirmHold, 'hold-keyboard': holdKeyboard,
|
|
83
|
+
'show-soft-input-on-focus': showSoftInputOnFocus, 'set-soft-input-mode': softInputMode, 'avoid-keyboard': avoidKeyboard, 'avoid-keyboard-spacing': `${nonnegative(cursorSpacing, 0)}px`,
|
|
84
|
+
bindinput: change,
|
|
85
|
+
bindfocus: (event) => {
|
|
86
|
+
'background only';
|
|
87
|
+
clearTimeout(blurTimer.current);
|
|
88
|
+
setFocused(true);
|
|
89
|
+
onFocus?.(event.detail);
|
|
90
|
+
},
|
|
91
|
+
bindblur: (event) => {
|
|
92
|
+
'background only';
|
|
93
|
+
clearTimeout(blurTimer.current);
|
|
94
|
+
if (clearTrigger === 'focus' && clearable)
|
|
95
|
+
blurTimer.current = setTimeout(() => setFocused(false), 120);
|
|
96
|
+
else
|
|
97
|
+
setFocused(false);
|
|
98
|
+
onBlur?.(event.detail);
|
|
99
|
+
field?.onBlur();
|
|
100
|
+
},
|
|
101
|
+
bindconfirm: (event) => {
|
|
102
|
+
'background only';
|
|
103
|
+
if (!blocked)
|
|
104
|
+
onConfirm?.(event.detail);
|
|
105
|
+
},
|
|
106
|
+
bindkeyboardheightchange: (event) => {
|
|
107
|
+
'background only';
|
|
108
|
+
onKeyboardHeightChange?.(event.detail);
|
|
109
|
+
},
|
|
110
|
+
className: `ui-textfield-native ${inputClassName}`,
|
|
111
|
+
};
|
|
112
|
+
// Native line is documented by Lynx; @lynx-js/types 4.1 omits this event.
|
|
113
|
+
const lineBinding = { bindline: (event) => {
|
|
114
|
+
'background only';
|
|
115
|
+
onLineChange?.({ lineCount: event.detail.line });
|
|
116
|
+
} };
|
|
117
|
+
return <view className={`ui-textfield ui-${multiline ? 'textarea' : 'input'} ${compact ? 'ui-textfield-compact' : ''} ${disabled ? 'ui-textfield-disabled' : ''} ${readonly ? 'ui-textfield-readonly' : ''} ${error ? 'ui-textfield-error' : ''} ${className}`} style={{ ...style, ...(placeholderColor ? { '--ui-textfield-placeholder': placeholderColor } : {}) }} bindtap={() => {
|
|
118
|
+
'background only';
|
|
119
|
+
if (!disabled)
|
|
120
|
+
onTap?.();
|
|
121
|
+
}}>
|
|
122
|
+
<view className="ui-textfield-body">
|
|
123
|
+
{prefix !== undefined ? <view className="ui-textfield-prefix">{node(prefix)}</view> : prefixIcon ? <view className="ui-textfield-prefix" bindtap={() => {
|
|
124
|
+
'background only';
|
|
125
|
+
if (!disabled)
|
|
126
|
+
onClickPrefixIcon?.();
|
|
127
|
+
}}><Icon name={prefixIcon} size={18}/></view> : null}
|
|
128
|
+
<view className="ui-textfield-editor">
|
|
129
|
+
{multiline ? <textarea {...common} type={type === 'password' ? 'text' : type} maxlines={maxlines} style={{ height: `${textareaHeight}px`, textAlign: textAlign ?? (alignRight ? 'right' : 'left') }} {...lineBinding}/> : <input {...common} type={showPassword ? visiblePassword ? 'text' : 'password' : type} style={{ textAlign: textAlign ?? (alignRight ? 'right' : 'left') }}/>}
|
|
130
|
+
{multiline && autoHeight ? <view className="ui-textfield-mirror" user-interaction-enabled={false} accessibility-elements-hidden bindlayoutchange={event => {
|
|
131
|
+
'background only';
|
|
132
|
+
setMeasuredHeight(event.detail.height);
|
|
133
|
+
}}>{text.split('\n').map((line, i) => <text key={i} className="ui-textfield-mirror-line">{line || '\u200b'}</text>)}</view> : null}
|
|
134
|
+
</view>
|
|
135
|
+
{showClear ? <view className="ui-textfield-clear" catchtap={clear} accessibility-element accessibility-traits="button" accessibility-label="清空输入"><Icon name="close-circle" size={18}/></view> : null}
|
|
136
|
+
{!multiline && showPassword && !disabled ? <view className="ui-textfield-eye" catchtap={() => {
|
|
137
|
+
'background only';
|
|
138
|
+
setVisiblePassword(v => !v);
|
|
139
|
+
}} accessibility-element accessibility-traits="button" accessibility-label={visiblePassword ? '隐藏密码' : '显示密码'}><Icon name={visiblePassword ? 'eye' : 'eye-invisible'} size={18}/></view> : null}
|
|
140
|
+
{suffix !== undefined ? <view className="ui-textfield-suffix">{node(suffix)}</view> : suffixIcon ? <view className="ui-textfield-suffix" bindtap={() => {
|
|
141
|
+
'background only';
|
|
142
|
+
if (!disabled)
|
|
143
|
+
onClickSuffixIcon?.();
|
|
144
|
+
}}><Icon name={suffixIcon} size={18}/></view> : null}
|
|
145
|
+
{!multiline && count ? <text className="ui-textfield-count">{text.length}/{maxlength}</text> : null}
|
|
146
|
+
</view>
|
|
147
|
+
{multiline && count ? <text className="ui-textfield-count">{text.length}/{maxlength}</text> : null}
|
|
148
|
+
</view>;
|
|
149
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TextFieldProps, TextFieldRef } from "./TextField.jsx";
|
|
2
|
+
export type TextareaProps = Omit<TextFieldProps, 'suffixIcon' | 'suffix'> & {
|
|
3
|
+
autoHeight?: boolean;
|
|
4
|
+
height?: number;
|
|
5
|
+
minHeight?: number;
|
|
6
|
+
maxHeight?: number;
|
|
7
|
+
maxlines?: number;
|
|
8
|
+
onLineChange?: (event: {
|
|
9
|
+
lineCount: number;
|
|
10
|
+
}) => void;
|
|
11
|
+
};
|
|
12
|
+
export type TextareaRef = TextFieldRef;
|
|
13
|
+
export declare const Textarea: (props: Omit<TextFieldProps, "suffix" | "suffixIcon"> & {
|
|
14
|
+
autoHeight?: boolean;
|
|
15
|
+
height?: number;
|
|
16
|
+
minHeight?: number;
|
|
17
|
+
maxHeight?: number;
|
|
18
|
+
maxlines?: number;
|
|
19
|
+
onLineChange?: (event: {
|
|
20
|
+
lineCount: number;
|
|
21
|
+
}) => void;
|
|
22
|
+
} & import("react").RefAttributes<TextFieldRef>) => React.ReactElement | null;
|
package/dist/Toast.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type ToastIconType = 'success' | 'error' | 'warning' | 'loading' | 'info';
|
|
4
|
+
export type ToastDirection = 'horizontal' | 'vertical';
|
|
5
|
+
export type ToastPosition = 'top' | 'middle-top' | 'middle' | 'bottom';
|
|
6
|
+
export type ToastLoadingType = 'circular' | 'spinner' | 'dots';
|
|
7
|
+
export type ToastOptions = {
|
|
8
|
+
msg?: string;
|
|
9
|
+
duration?: number;
|
|
10
|
+
direction?: ToastDirection;
|
|
11
|
+
iconName?: ToastIconType;
|
|
12
|
+
iconSize?: number;
|
|
13
|
+
loadingType?: ToastLoadingType;
|
|
14
|
+
loadingColor?: string;
|
|
15
|
+
loadingSize?: number;
|
|
16
|
+
iconColor?: string;
|
|
17
|
+
position?: ToastPosition;
|
|
18
|
+
zIndex?: number;
|
|
19
|
+
cover?: boolean;
|
|
20
|
+
/** A public Icon name or image URL, rather than an iconfont class. */
|
|
21
|
+
iconClass?: string;
|
|
22
|
+
iconNode?: ReactNode;
|
|
23
|
+
opened?: () => void;
|
|
24
|
+
closed?: () => void;
|
|
25
|
+
};
|
|
26
|
+
export type ToastProps = ToastOptions & {
|
|
27
|
+
show?: boolean;
|
|
28
|
+
onChange?: (show: boolean) => void;
|
|
29
|
+
/** Call options override the defaults provided directly as component props. */
|
|
30
|
+
options?: ToastOptions;
|
|
31
|
+
requestKey?: number;
|
|
32
|
+
rootPortal?: boolean;
|
|
33
|
+
className?: string;
|
|
34
|
+
style?: CSSProperties;
|
|
35
|
+
};
|
|
36
|
+
export declare function Toast({ show, onChange, options, requestKey, rootPortal, className, style, ...defaults }: ToastProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Toast.jsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useRef } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { Loading } from "./Loading.jsx";
|
|
4
|
+
import { Overlay } from "./Overlay.jsx";
|
|
5
|
+
import { RootPortal } from "./RootPortal.jsx";
|
|
6
|
+
import { Transition } from "./Transition.jsx";
|
|
7
|
+
const icons = { success: 'check-circle', error: 'close-circle', warning: 'exclamation-circle', info: 'info-circle' };
|
|
8
|
+
export function Toast({ show = false, onChange, options, requestKey = 0, rootPortal = false, className = '', style, ...defaults }) {
|
|
9
|
+
const settings = { ...defaults, ...options };
|
|
10
|
+
const { msg = '', duration = 2000, direction = 'horizontal', iconName, iconClass, iconNode, iconSize = 24, loadingType = 'circular', loadingColor = '#ffffff', loadingSize = 24, iconColor = '#ffffff', position = 'middle', zIndex = 100, cover = false, opened, closed } = settings;
|
|
11
|
+
const callbacks = useRef({ onChange, opened, closed });
|
|
12
|
+
callbacks.current = { onChange, opened, closed };
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!show || !Number.isFinite(duration) || duration <= 0)
|
|
15
|
+
return;
|
|
16
|
+
const timer = setTimeout(() => callbacks.current.onChange?.(false), duration);
|
|
17
|
+
return () => clearTimeout(timer);
|
|
18
|
+
}, [show, requestKey, duration]);
|
|
19
|
+
const icon = iconNode ?? (iconClass ? <Icon name={iconClass} size={iconSize} color={iconColor}/> : iconName === 'loading' ? <Loading size={loadingSize} type={loadingType} color={loadingColor}/> : iconName ? <Icon name={icons[iconName]} size={iconSize} color={iconColor}/> : null);
|
|
20
|
+
const layer = <>
|
|
21
|
+
{cover ? <Overlay show={show} duration={200} zIndex={zIndex} style={{ backgroundColor: 'transparent' }}/> : null}
|
|
22
|
+
<view className={`ui-toast-position ui-toast-position-${position}`} style={{ zIndex: zIndex + 1 }} event-through>
|
|
23
|
+
<Transition show={show} name="fade" duration={200} lazyRender destroy={false} className={`ui-toast ui-toast-${direction} ${icon ? 'ui-toast-with-icon' : ''} ${className}`} style={style} onAfterEnter={() => callbacks.current.opened?.()} onAfterLeave={() => callbacks.current.closed?.()}>
|
|
24
|
+
{icon ? <view className="ui-toast-icon">{icon}</view> : null}
|
|
25
|
+
{msg ? <text className="ui-toast-msg" accessibility-element accessibility-label={msg}>{msg}</text> : null}
|
|
26
|
+
</Transition>
|
|
27
|
+
</view>
|
|
28
|
+
</>;
|
|
29
|
+
return rootPortal ? <RootPortal>{layer}</RootPortal> : layer;
|
|
30
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AnchoredBubbleProps, BubbleRef } from "./AnchoredBubble.jsx";
|
|
2
|
+
export type TooltipRef = BubbleRef;
|
|
3
|
+
export type TooltipProps = Omit<AnchoredBubbleProps, 'kind'> & {
|
|
4
|
+
content?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const Tooltip: (props: Omit<AnchoredBubbleProps, "kind"> & {
|
|
7
|
+
content?: string;
|
|
8
|
+
} & import("react").RefAttributes<BubbleRef>) => React.ReactElement | null;
|
package/dist/Tooltip.jsx
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { forwardRef } from '@lynx-js/react';
|
|
2
|
+
import { AnchoredBubble } from "./AnchoredBubble.jsx";
|
|
3
|
+
export const Tooltip = forwardRef(function Tooltip({ content = '', contentNode, ...props }, ref) {
|
|
4
|
+
return <AnchoredBubble {...props} ref={ref} kind="tooltip" contentNode={contentNode ?? <text className="ui-bubble-text">{content}</text>}/>;
|
|
5
|
+
});
|
package/dist/Tour.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
import type { BubbleRect } from './bubblePosition.js';
|
|
4
|
+
export type TourStep = {
|
|
5
|
+
element: string;
|
|
6
|
+
content: string;
|
|
7
|
+
padding?: number;
|
|
8
|
+
offset?: number;
|
|
9
|
+
placement?: 'auto' | 'top' | 'bottom' | 'left' | 'right';
|
|
10
|
+
};
|
|
11
|
+
export type TourStepEvent = {
|
|
12
|
+
prevCurrent: number;
|
|
13
|
+
current: number;
|
|
14
|
+
total: number;
|
|
15
|
+
isElementInTop: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type TourEndEvent = {
|
|
18
|
+
current: number;
|
|
19
|
+
total: number;
|
|
20
|
+
};
|
|
21
|
+
export type TourRenderState = {
|
|
22
|
+
current: number;
|
|
23
|
+
total: number;
|
|
24
|
+
step: TourStep;
|
|
25
|
+
elementInfo: BubbleRect;
|
|
26
|
+
prev: () => void;
|
|
27
|
+
next: () => void;
|
|
28
|
+
skip: () => void;
|
|
29
|
+
finish: () => void;
|
|
30
|
+
};
|
|
31
|
+
export type TourRef = {
|
|
32
|
+
handlePrev: () => void;
|
|
33
|
+
handleNext: () => void;
|
|
34
|
+
handleSkip: () => void;
|
|
35
|
+
handleFinish: () => void;
|
|
36
|
+
updatePosition: () => void;
|
|
37
|
+
};
|
|
38
|
+
export type TourProps = {
|
|
39
|
+
show?: boolean;
|
|
40
|
+
onShowChange?: (show: boolean) => void;
|
|
41
|
+
steps: readonly TourStep[];
|
|
42
|
+
current?: number;
|
|
43
|
+
defaultCurrent?: number;
|
|
44
|
+
onCurrentChange?: (current: number) => void;
|
|
45
|
+
onChange?: (event: {
|
|
46
|
+
current: number;
|
|
47
|
+
}) => void;
|
|
48
|
+
mask?: boolean;
|
|
49
|
+
maskColor?: string;
|
|
50
|
+
offset?: number;
|
|
51
|
+
duration?: number;
|
|
52
|
+
borderRadius?: number;
|
|
53
|
+
padding?: number;
|
|
54
|
+
prevText?: string;
|
|
55
|
+
nextText?: string;
|
|
56
|
+
skipText?: string;
|
|
57
|
+
finishText?: string;
|
|
58
|
+
highlightStyle?: CSSProperties;
|
|
59
|
+
clickMaskNext?: boolean;
|
|
60
|
+
zIndex?: number;
|
|
61
|
+
showTourButtons?: boolean;
|
|
62
|
+
rootPortal?: boolean;
|
|
63
|
+
missingStrategy?: 'skip' | 'stop' | 'hide';
|
|
64
|
+
/** Await host/scroll-view positioning before native target measurement. */
|
|
65
|
+
scrollToTarget?: (step: TourStep, index: number) => void | Promise<void>;
|
|
66
|
+
/** Optional scoped native measurement, e.g. a NodesRef from the caller. */
|
|
67
|
+
getTargetRect?: (step: TourStep, index: number) => BubbleRect | null | Promise<BubbleRect | null>;
|
|
68
|
+
onPrev?: (event: TourStepEvent) => void;
|
|
69
|
+
onNext?: (event: TourStepEvent) => void;
|
|
70
|
+
onFinish?: (event: TourEndEvent) => void;
|
|
71
|
+
onSkip?: (event: TourEndEvent) => void;
|
|
72
|
+
onError?: (event: {
|
|
73
|
+
message: string;
|
|
74
|
+
element: string;
|
|
75
|
+
}) => void;
|
|
76
|
+
renderContent?: (state: TourRenderState) => ReactNode;
|
|
77
|
+
renderHighlight?: (state: TourRenderState) => ReactNode;
|
|
78
|
+
renderPrev?: (state: TourRenderState) => ReactNode;
|
|
79
|
+
renderNext?: (state: TourRenderState) => ReactNode;
|
|
80
|
+
renderSkip?: (state: TourRenderState) => ReactNode;
|
|
81
|
+
renderFinish?: (state: TourRenderState) => ReactNode;
|
|
82
|
+
className?: string;
|
|
83
|
+
style?: CSSProperties;
|
|
84
|
+
};
|
|
85
|
+
export declare const Tour: (props: TourProps & import("react").RefAttributes<TourRef>) => React.ReactElement | null;
|
package/dist/Tour.jsx
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Button } from "./Button.jsx";
|
|
3
|
+
import { RootPortal } from "./RootPortal.jsx";
|
|
4
|
+
import { Transition } from "./Transition.jsx";
|
|
5
|
+
import { bubblePosition } from './bubblePosition.js';
|
|
6
|
+
const validRect = (r) => r && [r.left, r.top, r.width, r.height].every(Number.isFinite) && r.width > 0 && r.height > 0;
|
|
7
|
+
const positive = (n) => Number.isFinite(n) ? Math.max(0, n) : 0;
|
|
8
|
+
export const Tour = forwardRef(function Tour({ show = false, onShowChange, steps, current, defaultCurrent = 0, onCurrentChange, onChange, mask = true, maskColor = 'rgba(0,0,0,.55)', offset = 20, duration = 300, borderRadius = 4, padding = 8, prevText = '上一步', nextText = '下一步', skipText = '跳过', finishText = '完成', highlightStyle, clickMaskNext = false, zIndex = 999, showTourButtons = true, rootPortal = false, missingStrategy = 'stop', scrollToTarget, getTargetRect, onPrev, onNext, onFinish, onSkip, onError, renderContent, renderHighlight, renderPrev, renderNext, renderSkip, renderFinish, className = '', style }, ref) {
|
|
9
|
+
const [inner, setInner] = useState(defaultCurrent), [revision, setRevision] = useState(0);
|
|
10
|
+
const [geometry, setGeometry] = useState(null);
|
|
11
|
+
const [panelSize, setPanelSize] = useState({ width: 224, height: 100 });
|
|
12
|
+
const [actionsWidth, setActionsWidth] = useState(0);
|
|
13
|
+
const viewport = useRef(null), generation = useRef(0), ended = useRef(false);
|
|
14
|
+
const callbacks = useRef({ scrollToTarget, getTargetRect, onError, onCurrentChange, onChange, onShowChange });
|
|
15
|
+
useEffect(() => { callbacks.current = { scrollToTarget, getTargetRect, onError, onCurrentChange, onChange, onShowChange }; });
|
|
16
|
+
const selected = Math.max(0, Math.min(Math.max(0, steps.length - 1), Number.isFinite(current ?? inner) ? Math.trunc(current ?? inner) : 0));
|
|
17
|
+
const step = steps[selected];
|
|
18
|
+
const identity = JSON.stringify(steps.map(s => [s.element, s.padding, s.offset, s.placement]));
|
|
19
|
+
const setIndex = (index) => {
|
|
20
|
+
'background only';
|
|
21
|
+
if (current === undefined)
|
|
22
|
+
setInner(index);
|
|
23
|
+
onCurrentChange?.(index);
|
|
24
|
+
onChange?.({ current: index });
|
|
25
|
+
};
|
|
26
|
+
const close = (reason) => {
|
|
27
|
+
'background only';
|
|
28
|
+
if (!show || ended.current)
|
|
29
|
+
return;
|
|
30
|
+
ended.current = true;
|
|
31
|
+
generation.current++;
|
|
32
|
+
setGeometry(null);
|
|
33
|
+
onShowChange?.(false);
|
|
34
|
+
(reason === 'finish' ? onFinish : onSkip)?.({ current: selected, total: steps.length });
|
|
35
|
+
};
|
|
36
|
+
const navigate = (direction) => {
|
|
37
|
+
'background only';
|
|
38
|
+
if (!show || ended.current || !step)
|
|
39
|
+
return;
|
|
40
|
+
const next = selected + direction;
|
|
41
|
+
if (next >= steps.length) {
|
|
42
|
+
close('finish');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (next < 0)
|
|
46
|
+
return;
|
|
47
|
+
const event = { prevCurrent: selected, current: next, total: steps.length, isElementInTop: !!geometry && geometry.target.top < geometry.viewport.top + geometry.viewport.height / 2 };
|
|
48
|
+
setIndex(next);
|
|
49
|
+
(direction < 0 ? onPrev : onNext)?.(event);
|
|
50
|
+
};
|
|
51
|
+
const updatePosition = () => {
|
|
52
|
+
'background only';
|
|
53
|
+
setRevision(n => n + 1);
|
|
54
|
+
};
|
|
55
|
+
useImperativeHandle(ref, () => ({ handlePrev: () => navigate(-1), handleNext: () => navigate(1), handleSkip: () => close('skip'), handleFinish: () => close('finish'), updatePosition }), [show, selected, steps, geometry, onShowChange, onCurrentChange, onChange, onPrev, onNext, onSkip, onFinish]);
|
|
56
|
+
useEffect(() => { if (show)
|
|
57
|
+
ended.current = false; }, [show]);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const token = ++generation.current;
|
|
60
|
+
let cancelled = false;
|
|
61
|
+
if (!show || !step || ended.current) {
|
|
62
|
+
setGeometry(null);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const read = (node) => new Promise(resolve => {
|
|
66
|
+
'background only';
|
|
67
|
+
if (!node) {
|
|
68
|
+
resolve(null);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
node.invoke({ method: 'boundingClientRect', params: { androidEnableTransformProps: true, iosEnableTransformProps: true }, success: value => resolve(value), fail: () => resolve(null) }).exec();
|
|
72
|
+
});
|
|
73
|
+
const measure = async () => {
|
|
74
|
+
'background only';
|
|
75
|
+
try {
|
|
76
|
+
await callbacks.current.scrollToTarget?.(step, selected);
|
|
77
|
+
if (cancelled || token !== generation.current)
|
|
78
|
+
return;
|
|
79
|
+
const [target, bounds] = await Promise.all([callbacks.current.getTargetRect ? callbacks.current.getTargetRect(step, selected) : read(lynx.createSelectorQuery().select(step.element)), read(viewport.current)]);
|
|
80
|
+
if (cancelled || token !== generation.current)
|
|
81
|
+
return;
|
|
82
|
+
if (!validRect(target) || !validRect(bounds)) {
|
|
83
|
+
setGeometry(null);
|
|
84
|
+
callbacks.current.onError?.({ message: `无法定位引导元素:${step.element}`, element: step.element });
|
|
85
|
+
if (missingStrategy === 'skip' && selected < steps.length - 1) {
|
|
86
|
+
if (current === undefined)
|
|
87
|
+
setInner(selected + 1);
|
|
88
|
+
callbacks.current.onCurrentChange?.(selected + 1);
|
|
89
|
+
callbacks.current.onChange?.({ current: selected + 1 });
|
|
90
|
+
}
|
|
91
|
+
else if (missingStrategy === 'hide' || missingStrategy === 'skip') {
|
|
92
|
+
ended.current = true;
|
|
93
|
+
callbacks.current.onShowChange?.(false);
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
setGeometry({ index: selected, target: target, viewport: bounds });
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (!cancelled && token === generation.current) {
|
|
101
|
+
setGeometry(null);
|
|
102
|
+
callbacks.current.onError?.({ message: String(error), element: step.element });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const frame = setTimeout(() => { void measure(); }, 32);
|
|
107
|
+
return () => { cancelled = true; generation.current++; clearTimeout(frame); };
|
|
108
|
+
}, [show, selected, identity, revision, missingStrategy]);
|
|
109
|
+
const ready = show && !!step && !!geometry;
|
|
110
|
+
const target = geometry?.target ?? { left: 0, top: 0, width: 0, height: 0 };
|
|
111
|
+
const bounds = geometry?.viewport ?? { left: 0, top: 0, width: 0, height: 0 };
|
|
112
|
+
const pad = positive(step?.padding ?? padding);
|
|
113
|
+
const hole = { left: target.left - pad, top: target.top - pad, width: target.width + pad * 2, height: target.height + pad * 2 };
|
|
114
|
+
const placement = step?.placement === 'auto' || !step?.placement ? hole.top + hole.height / 2 < bounds.top + bounds.height / 2 ? 'bottom' : 'top' : step.placement;
|
|
115
|
+
// The gap is measured from the original target; padding expands the highlight.
|
|
116
|
+
const position = bubblePosition(target, { left: 0, top: 0, ...panelSize }, { left: bounds.left + 12, top: bounds.top + 12, width: Math.max(0, bounds.width - 24), height: Math.max(0, bounds.height - 24) }, placement, positive(step?.offset ?? offset) - 6, false);
|
|
117
|
+
const state = { current: selected, total: steps.length, step: step, elementInfo: hole, prev: () => navigate(-1), next: () => navigate(1), skip: () => close('skip'), finish: () => close('finish') };
|
|
118
|
+
const layer = <>
|
|
119
|
+
<view ref={viewport} className="ui-tour-viewport" flatten={false} user-interaction-enabled={false} bindlayoutchange={() => {
|
|
120
|
+
'background only';
|
|
121
|
+
if (show)
|
|
122
|
+
updatePosition();
|
|
123
|
+
}}/>
|
|
124
|
+
<Transition show={ready} lazyRender destroy={false} duration={positive(duration)} name="fade" className={`ui-tour ${className}`} style={{ zIndex, ...style }} onTap={() => {
|
|
125
|
+
'background only';
|
|
126
|
+
if (clickMaskNext)
|
|
127
|
+
navigate(1);
|
|
128
|
+
}}>
|
|
129
|
+
<view className="ui-tour-blocker" consume-slide-event={[[-180, 180]]} catchtouchmove={() => { }}/>
|
|
130
|
+
<view className="ui-tour-highlight" catchtap={() => { }} style={{ left: `${hole.left}px`, top: `${hole.top}px`, width: `${hole.width}px`, height: `${hole.height}px`, borderRadius: `${positive(borderRadius)}px`, boxShadow: mask ? `0 0 0 ${Math.max(bounds.width, bounds.height) * 2}px ${maskColor}` : undefined, transitionDuration: `${positive(duration)}ms`, ...highlightStyle }}>{ready && renderHighlight ? renderHighlight(state) : null}</view>
|
|
131
|
+
<view className="ui-tour-popover" flatten={false} catchtap={() => { }} style={{ left: `${position.x}px`, top: `${position.y}px`, width: `${Math.min(Math.max(224, actionsWidth + 24), Math.max(0, bounds.width - 24))}px` }} bindlayoutchange={e => {
|
|
132
|
+
'background only';
|
|
133
|
+
const { width, height } = e.detail;
|
|
134
|
+
setPanelSize(old => old.width === width && old.height === height ? old : { width, height });
|
|
135
|
+
}}>
|
|
136
|
+
{ready ? <>{renderContent ? renderContent(state) : <text className="ui-tour-info">{step.content}</text>}
|
|
137
|
+
{showTourButtons ? <view className="ui-tour-buttons" bindlayoutchange={e => {
|
|
138
|
+
'background only';
|
|
139
|
+
setActionsWidth(e.detail.width);
|
|
140
|
+
}}>
|
|
141
|
+
{selected > 0 ? renderPrev ? renderPrev(state) : <Button size="mini" variant="text" label={prevText} onTap={state.prev}/> : null}
|
|
142
|
+
{renderSkip ? renderSkip(state) : <Button size="mini" variant="text" label={skipText} onTap={state.skip}/>}
|
|
143
|
+
{selected === steps.length - 1 ? renderFinish ? renderFinish(state) : <Button size="mini" label={finishText} onTap={state.finish}/> : renderNext ? renderNext(state) : <Button size="mini" label={`${nextText}(${selected + 1}/${steps.length})`} onTap={state.next}/>}
|
|
144
|
+
</view> : null}
|
|
145
|
+
</> : null}
|
|
146
|
+
</view>
|
|
147
|
+
</Transition>
|
|
148
|
+
</>;
|
|
149
|
+
return rootPortal ? <RootPortal>{layer}</RootPortal> : layer;
|
|
150
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type TransitionName = 'fade' | 'fade-up' | 'fade-down' | 'fade-left' | 'fade-right' | 'slide-up' | 'slide-down' | 'slide-left' | 'slide-right' | 'zoom-in' | 'zoom-out';
|
|
4
|
+
export type TransitionProps = {
|
|
5
|
+
show: boolean;
|
|
6
|
+
name?: TransitionName | readonly TransitionName[];
|
|
7
|
+
duration?: number | boolean | {
|
|
8
|
+
enter: number;
|
|
9
|
+
leave: number;
|
|
10
|
+
};
|
|
11
|
+
lazyRender?: boolean;
|
|
12
|
+
destroy?: boolean;
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: CSSProperties;
|
|
15
|
+
/** Keep a modal's hit target until its leave animation has finished. */
|
|
16
|
+
interactiveDuringLeave?: boolean;
|
|
17
|
+
enterClassName?: string;
|
|
18
|
+
enterActiveClassName?: string;
|
|
19
|
+
enterToClassName?: string;
|
|
20
|
+
leaveClassName?: string;
|
|
21
|
+
leaveActiveClassName?: string;
|
|
22
|
+
leaveToClassName?: string;
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
onBeforeEnter?: () => void;
|
|
25
|
+
onEnter?: () => void;
|
|
26
|
+
onAfterEnter?: () => void;
|
|
27
|
+
onBeforeLeave?: () => void;
|
|
28
|
+
onLeave?: () => void;
|
|
29
|
+
onAfterLeave?: () => void;
|
|
30
|
+
onTap?: () => void;
|
|
31
|
+
};
|
|
32
|
+
export declare function Transition({ show, name, duration, lazyRender, destroy, className, style, interactiveDuringLeave, enterClassName, enterActiveClassName, enterToClassName, leaveClassName, leaveActiveClassName, leaveToClassName, children, onBeforeEnter, onEnter, onAfterEnter, onBeforeLeave, onLeave, onAfterLeave, onTap }: TransitionProps): import("@lynx-js/react").JSX.Element | null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
export function Transition({ show, name = 'fade', duration = 300, lazyRender = false, destroy = true, className = '', style, interactiveDuringLeave = false, enterClassName = '', enterActiveClassName = '', enterToClassName = '', leaveClassName = '', leaveActiveClassName = '', leaveToClassName = '', children, onBeforeEnter, onEnter, onAfterEnter, onBeforeLeave, onLeave, onAfterLeave, onTap }) {
|
|
3
|
+
const [state, setState] = useState({ rendered: !lazyRender || show, phase: 'hidden' });
|
|
4
|
+
const shown = useRef(false);
|
|
5
|
+
const callbacks = useRef({ onBeforeEnter, onEnter, onAfterEnter, onBeforeLeave, onLeave, onAfterLeave });
|
|
6
|
+
useEffect(() => { callbacks.current = { onBeforeEnter, onEnter, onAfterEnter, onBeforeLeave, onLeave, onAfterLeave }; });
|
|
7
|
+
const milliseconds = (enter) => {
|
|
8
|
+
const value = typeof duration === 'object' ? duration[enter ? 'enter' : 'leave'] : typeof duration === 'boolean' ? duration ? 300 : 0 : duration;
|
|
9
|
+
return Number.isFinite(value) ? Math.max(0, value) : 300;
|
|
10
|
+
};
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!show && !shown.current)
|
|
13
|
+
return;
|
|
14
|
+
shown.current = show;
|
|
15
|
+
let cancelled = false;
|
|
16
|
+
let completion;
|
|
17
|
+
const events = callbacks.current;
|
|
18
|
+
(show ? events.onBeforeEnter : events.onBeforeLeave)?.();
|
|
19
|
+
setState({ rendered: true, phase: show ? 'enter-from' : 'leave-from' });
|
|
20
|
+
const frame = setTimeout(() => {
|
|
21
|
+
if (cancelled)
|
|
22
|
+
return;
|
|
23
|
+
setState({ rendered: true, phase: show ? 'enter-to' : 'leave-to' });
|
|
24
|
+
(show ? callbacks.current.onEnter : callbacks.current.onLeave)?.();
|
|
25
|
+
completion = setTimeout(() => {
|
|
26
|
+
if (cancelled)
|
|
27
|
+
return;
|
|
28
|
+
setState({ rendered: show || !destroy, phase: show ? 'entered' : 'hidden' });
|
|
29
|
+
(show ? callbacks.current.onAfterEnter : callbacks.current.onAfterLeave)?.();
|
|
30
|
+
}, milliseconds(show));
|
|
31
|
+
}, 32);
|
|
32
|
+
return () => { cancelled = true; clearTimeout(frame); clearTimeout(completion); };
|
|
33
|
+
}, [show]);
|
|
34
|
+
if (!state.rendered)
|
|
35
|
+
return null;
|
|
36
|
+
const names = typeof name === 'string' ? [name] : name;
|
|
37
|
+
const entering = state.phase.startsWith('enter-');
|
|
38
|
+
const leaving = state.phase.startsWith('leave-');
|
|
39
|
+
const from = state.phase.endsWith('-from');
|
|
40
|
+
const custom = entering ? `${from ? enterClassName : enterToClassName} ${enterActiveClassName}` : leaving ? `${from ? leaveClassName : leaveToClassName} ${leaveActiveClassName}` : '';
|
|
41
|
+
const classes = names.map(item => `ui-transition-${item}-${state.phase}`).join(' ');
|
|
42
|
+
return <view className={`ui-transition ${classes} ${custom} ${className}`} style={{ ...style, display: state.phase === 'hidden' ? 'none' : 'flex', transitionDuration: `${from ? 0 : milliseconds(entering)}ms` }} user-interaction-enabled={(!leaving || interactiveDuringLeave) && state.phase !== 'hidden'} bindtap={onTap}>{children}</view>;
|
|
43
|
+
}
|
package/dist/Upload.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
3
|
+
import type { LoadingProps } from "./Loading.jsx";
|
|
4
|
+
export type UploadFile = {
|
|
5
|
+
url: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
status?: 'success' | 'loading' | 'fail';
|
|
9
|
+
message?: string;
|
|
10
|
+
percent?: number;
|
|
11
|
+
};
|
|
12
|
+
/** Selection, credentials, validation and transport belong to the adapter/host. */
|
|
13
|
+
export type UploadAdapter = {
|
|
14
|
+
chooseAndUpload: (onProgress: (progress: number) => void) => Promise<UploadFile | null>;
|
|
15
|
+
preview?: (files: readonly UploadFile[], index: number) => void | Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export type UploadProps = {
|
|
18
|
+
fileList?: readonly UploadFile[];
|
|
19
|
+
onChange?: (event: {
|
|
20
|
+
fileList: UploadFile[];
|
|
21
|
+
}) => void;
|
|
22
|
+
adapter?: UploadAdapter;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
readonly?: boolean;
|
|
25
|
+
limit?: number;
|
|
26
|
+
size?: number;
|
|
27
|
+
deletable?: boolean;
|
|
28
|
+
showLimitNum?: boolean;
|
|
29
|
+
reupload?: boolean;
|
|
30
|
+
previewFullImage?: boolean;
|
|
31
|
+
imageMode?: 'aspectFit' | 'aspectFill' | 'scaleToFill' | 'center';
|
|
32
|
+
uploadIcon?: string;
|
|
33
|
+
uploadText?: string;
|
|
34
|
+
loadingType?: LoadingProps['type'];
|
|
35
|
+
loadingSize?: number;
|
|
36
|
+
loadingColor?: string;
|
|
37
|
+
beforeChoose?: (event: {
|
|
38
|
+
fileList: readonly UploadFile[];
|
|
39
|
+
reuploadIndex?: number;
|
|
40
|
+
}) => boolean | Promise<boolean>;
|
|
41
|
+
beforePreview?: (file: UploadFile, index: number) => boolean | Promise<boolean>;
|
|
42
|
+
beforeRemove?: (file: UploadFile, index: number) => boolean | Promise<boolean>;
|
|
43
|
+
onSuccess?: (file: UploadFile) => void;
|
|
44
|
+
onFail?: (error: Error) => void;
|
|
45
|
+
onProgress?: (progress: number) => void;
|
|
46
|
+
onPreview?: (event: {
|
|
47
|
+
file: UploadFile;
|
|
48
|
+
index: number;
|
|
49
|
+
}) => void;
|
|
50
|
+
onRemove?: (event: {
|
|
51
|
+
file: UploadFile;
|
|
52
|
+
index: number;
|
|
53
|
+
}) => void;
|
|
54
|
+
renderPreviewCover?: (event: {
|
|
55
|
+
file: UploadFile;
|
|
56
|
+
index: number;
|
|
57
|
+
}) => ReactNode;
|
|
58
|
+
className?: string;
|
|
59
|
+
evokeClassName?: string;
|
|
60
|
+
previewClassName?: string;
|
|
61
|
+
style?: CSSProperties;
|
|
62
|
+
children?: ReactNode;
|
|
63
|
+
};
|
|
64
|
+
export declare function Upload({ fileList, onChange, adapter, disabled: disabledProp, readonly, limit, size, deletable, showLimitNum, reupload, previewFullImage, imageMode, uploadIcon, uploadText, loadingType, loadingSize, loadingColor, beforeChoose, beforePreview, beforeRemove, onSuccess, onFail, onProgress, onPreview, onRemove, renderPreviewCover, className, evokeClassName, previewClassName, style, children }: UploadProps): import("@lynx-js/react").JSX.Element;
|