@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
package/dist/Popup.jsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Overlay } from "./Overlay.jsx";
|
|
2
|
+
import { Transition } from "./Transition.jsx";
|
|
3
|
+
import { RootPortal } from "./RootPortal.jsx";
|
|
4
|
+
import { Icon } from "./Icon.jsx";
|
|
5
|
+
const motions = { center: ['fade', 'zoom-in'], top: 'slide-down', right: 'slide-right', bottom: 'slide-up', left: 'slide-left' };
|
|
6
|
+
export function Popup({ show = false, onChange, onClose, onClickModal, position = 'center', transition, duration = 300, closable = false, closeOnClickModal = true, modal = true, modalStyle, zIndex = 10, lazyRender = true, lockScroll = true, rootPortal = false, round = false, safeAreaInsetBottom = false, safeAreaBottom = 0, className = '', style, children, ...lifecycle }) {
|
|
7
|
+
const close = (reason) => {
|
|
8
|
+
'background only';
|
|
9
|
+
if (!show)
|
|
10
|
+
return;
|
|
11
|
+
onChange?.(false);
|
|
12
|
+
onClose?.(reason);
|
|
13
|
+
};
|
|
14
|
+
const layer = <>
|
|
15
|
+
{modal ? <Overlay show={show} duration={duration} lockScroll={lockScroll} zIndex={zIndex} style={modalStyle} onTap={() => {
|
|
16
|
+
'background only';
|
|
17
|
+
onClickModal?.();
|
|
18
|
+
if (closeOnClickModal)
|
|
19
|
+
close('modal');
|
|
20
|
+
}}/> : null}
|
|
21
|
+
<view className={`ui-popup-anchor ui-popup-anchor-${position}`} style={{ zIndex: zIndex + 1 }}>
|
|
22
|
+
<Transition {...lifecycle} show={show} name={transition ?? motions[position]} duration={duration} lazyRender={lazyRender} destroy={false} interactiveDuringLeave className={`ui-popup ui-popup-${position} ${round ? 'ui-popup-round' : ''} ${className}`} style={style}>
|
|
23
|
+
<view className="ui-popup-body" event-through={false} consume-slide-event={lockScroll ? [[-180, 180]] : undefined} catchtouchmove={lockScroll ? () => { } : undefined} catchtap={() => { }}>
|
|
24
|
+
{children}
|
|
25
|
+
{safeAreaInsetBottom && position === 'bottom' ? <view className="ui-popup-safe-area" style={{ height: `${Math.max(0, Number.isFinite(safeAreaBottom) ? safeAreaBottom : 0)}px` }}/> : null}
|
|
26
|
+
{closable ? <view className="ui-popup-close" catchtap={() => close('close')} accessibility-element accessibility-traits="button" accessibility-label="关闭弹出层"><Icon name="close" size={24}/></view> : null}
|
|
27
|
+
</view>
|
|
28
|
+
</Transition>
|
|
29
|
+
</view>
|
|
30
|
+
</>;
|
|
31
|
+
return rootPortal ? <RootPortal>{layer}</RootPortal> : layer;
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import type { ProgressColor } from './progressModel.js';
|
|
3
|
+
export type PercentPosition = {
|
|
4
|
+
type?: 'inner' | 'outer';
|
|
5
|
+
align?: 'left' | 'center' | 'right';
|
|
6
|
+
};
|
|
7
|
+
export type ProgressProps = {
|
|
8
|
+
percentage?: number;
|
|
9
|
+
hideText?: boolean;
|
|
10
|
+
color?: ProgressColor;
|
|
11
|
+
status?: 'success' | 'danger' | 'warning';
|
|
12
|
+
duration?: number;
|
|
13
|
+
percentPosition?: PercentPosition;
|
|
14
|
+
className?: string;
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
};
|
|
17
|
+
export declare function Progress({ percentage, hideText, color, status, duration, percentPosition, className, style }: ProgressProps): import("@lynx-js/react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { progressPercentage, progressSegments, progressStops } from './progressModel.js';
|
|
4
|
+
export function Progress({ percentage = 0, hideText = false, color, status, duration = 30, percentPosition, className = '', style }) {
|
|
5
|
+
const target = progressPercentage(percentage), milliseconds = Number.isFinite(duration) ? Math.max(0, duration) : 30;
|
|
6
|
+
const [bar, setBar] = useState({ value: 0, duration: 0 });
|
|
7
|
+
const [labelWidth, setLabelWidth] = useState(36);
|
|
8
|
+
const motion = useRef({ from: 0, to: 0, started: 0, duration: 0 });
|
|
9
|
+
// A stable key permits caller-owned arrays without restarting on unrelated renders.
|
|
10
|
+
const stops = progressStops(color), stopsKey = JSON.stringify(stops);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const previous = motion.current, elapsed = Date.now() - previous.started;
|
|
13
|
+
const current = previous.duration > 0 ? previous.from + (previous.to - previous.from) * Math.min(1, Math.max(0, elapsed / previous.duration)) : previous.to;
|
|
14
|
+
const segments = progressSegments(current, target, stops);
|
|
15
|
+
let timer, cancelled = false, from = current;
|
|
16
|
+
setBar(old => ({ ...old, value: current, duration: 0 }));
|
|
17
|
+
motion.current = { from: current, to: current, started: Date.now(), duration: 0 };
|
|
18
|
+
const advance = (index) => {
|
|
19
|
+
if (cancelled)
|
|
20
|
+
return;
|
|
21
|
+
const segment = segments[index];
|
|
22
|
+
if (!segment)
|
|
23
|
+
return;
|
|
24
|
+
const time = Math.abs(segment.value - from) * milliseconds;
|
|
25
|
+
motion.current = { from, to: segment.value, started: Date.now(), duration: time };
|
|
26
|
+
setBar({ value: segment.value, duration: time, color: segment.color });
|
|
27
|
+
from = segment.value;
|
|
28
|
+
if (index + 1 < segments.length)
|
|
29
|
+
timer = setTimeout(() => advance(index + 1), time);
|
|
30
|
+
};
|
|
31
|
+
timer = setTimeout(() => advance(0), 32);
|
|
32
|
+
return () => { cancelled = true; clearTimeout(timer); };
|
|
33
|
+
}, [target, milliseconds, stopsKey]);
|
|
34
|
+
const inner = percentPosition?.type === 'inner', align = percentPosition?.align ?? 'right';
|
|
35
|
+
const icon = status === 'success' ? 'check-circle-fill' : status === 'danger' ? 'close-circle-fill' : 'exclamation-circle-fill';
|
|
36
|
+
const statusColor = status ? `var(--cso-ui-${status})` : 'var(--cso-ui-primary)';
|
|
37
|
+
// SVG glyphs use separate theme variants rather than SVG CSS-variable fills.
|
|
38
|
+
const iconColors = status === 'success' ? ['#12b886', '#20c997'] : status === 'warning' ? ['#f57f00', '#ffa94d'] : ['#f14646', '#ff6b6b'];
|
|
39
|
+
const label = hideText ? status ? <view className={`ui-progress-icon ${inner ? 'ui-progress-icon-inner' : ''}`}><Icon name={icon} size={18} color={inner ? '#fff' : typeof color === 'string' ? color : iconColors[0]} className="ui-progress-light-icon"/><Icon name={icon} size={18} color={inner ? '#fff' : typeof color === 'string' ? color : iconColors[1]} className="ui-progress-dark-icon"/></view> : null : <text className="ui-progress-label" bindlayoutchange={event => { if (inner && Number.isFinite(event.detail.width) && event.detail.width > 0)
|
|
40
|
+
setLabelWidth(event.detail.width); }}>{`${target}%`}</text>;
|
|
41
|
+
return <view className={`ui-progress ${inner ? 'ui-progress-inner' : ''} ${target === 0 ? 'ui-progress-zero' : ''} ${className}`} style={style} accessibility-element accessibility-label={`进度 ${target}%${status ? ` ${status}` : ''}`}>
|
|
42
|
+
<view className="ui-progress-track"><view className={`ui-progress-fill ui-progress-align-${align}`} style={{ width: `${bar.value}%`, transitionDuration: `${bar.duration}ms`, backgroundColor: inner && target === 0 ? undefined : bar.color ?? statusColor, minWidth: inner && label ? hideText ? '34px' : `${labelWidth}px` : undefined }}>{inner ? label : null}</view></view>
|
|
43
|
+
{!inner ? label : null}
|
|
44
|
+
</view>;
|
|
45
|
+
}
|
package/dist/QrCode.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CSSProperties, NodesRef, StandardProps } from '@lynx-js/types';
|
|
2
|
+
import type { QrCodeOptions } from './qrCodeModel.js';
|
|
3
|
+
export type QrCodeProps = QrCodeOptions & {
|
|
4
|
+
exportMode?: 'svg' | 'browser';
|
|
5
|
+
className?: string;
|
|
6
|
+
style?: CSSProperties;
|
|
7
|
+
onClick?: () => void;
|
|
8
|
+
onError?: (error: Error) => void;
|
|
9
|
+
};
|
|
10
|
+
export type QrCodeRef = {
|
|
11
|
+
exportImage: () => Promise<string>;
|
|
12
|
+
getSvg: () => string;
|
|
13
|
+
};
|
|
14
|
+
type ExportSignal = {
|
|
15
|
+
id: number;
|
|
16
|
+
url?: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
};
|
|
19
|
+
type ExportElementProps = StandardProps & {
|
|
20
|
+
ref?: {
|
|
21
|
+
current: NodesRef | null;
|
|
22
|
+
};
|
|
23
|
+
bindqrexport?: (event: {
|
|
24
|
+
detail: ExportSignal;
|
|
25
|
+
}) => void;
|
|
26
|
+
};
|
|
27
|
+
declare module '@lynx-js/types' {
|
|
28
|
+
interface IntrinsicElements {
|
|
29
|
+
'daisu-qr-export': ExportElementProps;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
declare global {
|
|
33
|
+
namespace JSX {
|
|
34
|
+
interface IntrinsicElements {
|
|
35
|
+
'daisu-qr-export': ExportElementProps;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export declare const QrCode: (props: QrCodeOptions & {
|
|
40
|
+
exportMode?: "svg" | "browser";
|
|
41
|
+
className?: string;
|
|
42
|
+
style?: CSSProperties;
|
|
43
|
+
onClick?: () => void;
|
|
44
|
+
onError?: (error: Error) => void;
|
|
45
|
+
} & import("react").RefAttributes<QrCodeRef>) => React.ReactElement | null;
|
|
46
|
+
export {};
|
package/dist/QrCode.jsx
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from '@lynx-js/react';
|
|
2
|
+
import { qrCodeLayout, qrCodeMatrix } from './qrCodeModel.js';
|
|
3
|
+
export const QrCode = forwardRef(function QrCode({ exportMode = 'svg', className = '', style, onClick, onError, ...options }, ref) {
|
|
4
|
+
const exporter = useRef(null), sequence = useRef(0), pending = useRef(new Map());
|
|
5
|
+
const { text = '', correctLevel = 'H' } = options;
|
|
6
|
+
const encoded = useMemo(() => { try {
|
|
7
|
+
return { matrix: qrCodeMatrix(text, correctLevel) };
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
return { matrix: [], error: error instanceof Error ? error : new Error(String(error)) };
|
|
11
|
+
} }, [text, correctLevel]);
|
|
12
|
+
const key = JSON.stringify(options);
|
|
13
|
+
const result = useMemo(() => { try {
|
|
14
|
+
return { layout: qrCodeLayout(encoded.matrix, options), error: encoded.error };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return { error: error instanceof Error ? error : new Error(String(error)) };
|
|
18
|
+
} }, [encoded, key]);
|
|
19
|
+
useEffect(() => { if (result.error)
|
|
20
|
+
onError?.(result.error); }, [result]);
|
|
21
|
+
useEffect(() => () => { for (const request of pending.current.values()) {
|
|
22
|
+
clearTimeout(request.timer);
|
|
23
|
+
request.reject(new Error('二维码导出已取消'));
|
|
24
|
+
} pending.current.clear(); }, [result, exportMode]);
|
|
25
|
+
useImperativeHandle(ref, () => ({ getSvg() {
|
|
26
|
+
'background only';
|
|
27
|
+
if (result.error || !text)
|
|
28
|
+
throw result.error ?? new Error('QR content is empty');
|
|
29
|
+
return result.layout.svg;
|
|
30
|
+
}, async exportImage() {
|
|
31
|
+
'background only';
|
|
32
|
+
if (result.error || !text)
|
|
33
|
+
throw result.error ?? new Error('QR content is empty');
|
|
34
|
+
if (exportMode === 'browser') {
|
|
35
|
+
if (!exporter.current)
|
|
36
|
+
throw new Error('浏览器二维码导出后端未就绪');
|
|
37
|
+
return new Promise((resolve, reject) => { const id = ++sequence.current; const timer = setTimeout(() => { pending.current.delete(id); reject(new Error('二维码导出超时,请检查浏览器组件注册')); }, 15000); pending.current.set(id, { resolve, reject, timer }); exporter.current.invoke({ method: 'exportImage', params: { id, svg: result.layout.svg, size: result.layout.options.size } }).exec(); });
|
|
38
|
+
}
|
|
39
|
+
if ([options.logo, options.backgroundImage].some(src => src && !src.startsWith('data:image/')))
|
|
40
|
+
throw new Error('包含外部图片的二维码请使用浏览器导出模式,或先将图片转为内嵌位图');
|
|
41
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(result.layout.svg)}`;
|
|
42
|
+
} }), [result, text, exportMode]);
|
|
43
|
+
const layout = result.error ? undefined : result.layout, o = layout?.options, logo = layout?.logo;
|
|
44
|
+
return <view className={`ui-qr-code ${className}`} style={{ width: `${o?.size ?? 200}px`, height: `${o?.size ?? 200}px`, backgroundColor: o?.colorLight ?? '#fff', ...style }} bindtap={onClick} accessibility-element accessibility-label={text || '二维码'}>
|
|
45
|
+
{exportMode === 'browser' ? <daisu-qr-export ref={exporter} className="ui-qr-code-export" bindqrexport={({ detail: event }) => {
|
|
46
|
+
'background only';
|
|
47
|
+
const request = pending.current.get(event.id);
|
|
48
|
+
if (!request)
|
|
49
|
+
return;
|
|
50
|
+
clearTimeout(request.timer);
|
|
51
|
+
pending.current.delete(event.id);
|
|
52
|
+
if (event.url)
|
|
53
|
+
request.resolve(event.url);
|
|
54
|
+
else
|
|
55
|
+
request.reject(new Error(event.error || '二维码导出失败'));
|
|
56
|
+
}}/> : null}
|
|
57
|
+
{o?.backgroundImage && text ? <image className="ui-qr-code-surface" src={o.backgroundImage} mode="scaleToFill" binderror={() => {
|
|
58
|
+
'background only';
|
|
59
|
+
onError?.(new Error('QR background image failed'));
|
|
60
|
+
}}/> : null}
|
|
61
|
+
{layout ? <svg className="ui-qr-code-surface" content={layout.codeSvg}/> : null}
|
|
62
|
+
{o?.logo && text && logo ? <view className="ui-qr-code-logo" style={{ left: `${logo.x - 4}px`, top: `${logo.y - 4}px`, width: `${logo.width + 8}px`, height: `${logo.height + 8}px`, borderRadius: `${o.logoRadius}px`, backgroundColor: o.logoBackgroundColor, borderWidth: `${o.logoBorderWidth}px`, borderColor: o.logoBorderColor || 'transparent' }}><image src={o.logo} mode="scaleToFill" style={{ position: 'absolute', left: `${4 - o.logoBorderWidth}px`, top: `${4 - o.logoBorderWidth}px`, width: `${logo.width}px`, height: `${logo.height}px`, borderRadius: `${logo.radius}px` }} binderror={() => {
|
|
63
|
+
'background only';
|
|
64
|
+
onError?.(new Error('QR logo failed'));
|
|
65
|
+
}}/></view> : null}
|
|
66
|
+
</view>;
|
|
67
|
+
});
|
package/dist/Radio.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ChoiceStyle, ChoiceValue } from "./choice.jsx";
|
|
2
|
+
import type { RadioOption } from "./legacy/RadioGroup.jsx";
|
|
3
|
+
export type { RadioOption } from "./legacy/RadioGroup.jsx";
|
|
4
|
+
export type RadioProps = ChoiceStyle & {
|
|
5
|
+
value: ChoiceValue;
|
|
6
|
+
};
|
|
7
|
+
export type RadioGroupProps<T extends ChoiceValue = ChoiceValue> = ChoiceStyle & {
|
|
8
|
+
value?: T | null;
|
|
9
|
+
defaultValue?: T | null;
|
|
10
|
+
onChange?: (value: T | null) => void;
|
|
11
|
+
allowUncheck?: boolean;
|
|
12
|
+
options?: RadioOption[];
|
|
13
|
+
};
|
|
14
|
+
export declare function RadioGroup(props: {
|
|
15
|
+
value: string;
|
|
16
|
+
options: RadioOption[];
|
|
17
|
+
onChange: (value: string) => void;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
}): import('@lynx-js/react').ReactNode;
|
|
20
|
+
export declare function RadioGroup<T extends ChoiceValue = ChoiceValue>(props: RadioGroupProps<T>): import('@lynx-js/react').ReactNode;
|
|
21
|
+
export declare function Radio(props: RadioProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Radio.jsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createContext, useContext, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Choice, choiceDefaults } from "./choice.jsx";
|
|
3
|
+
import { FormFieldContext } from './formContext.js';
|
|
4
|
+
import { RadioGroup as LegacyRadioGroup } from "./legacy/RadioGroup.jsx";
|
|
5
|
+
const Context = createContext(undefined);
|
|
6
|
+
export function RadioGroup(props) {
|
|
7
|
+
const { value, defaultValue, allowUncheck = false, onChange, options, children, className = '', style, direction = 'vertical' } = props;
|
|
8
|
+
const [inner, setInner] = useState(defaultValue), field = useContext(FormFieldContext), current = value === undefined ? inner : value;
|
|
9
|
+
const latest = useRef(current);
|
|
10
|
+
latest.current = current;
|
|
11
|
+
const select = (next) => {
|
|
12
|
+
'background only';
|
|
13
|
+
const changed = Object.is(latest.current, next) ? allowUncheck ? null : next : next;
|
|
14
|
+
if (changed === latest.current)
|
|
15
|
+
return;
|
|
16
|
+
if (value === undefined) {
|
|
17
|
+
latest.current = changed;
|
|
18
|
+
setInner(changed);
|
|
19
|
+
}
|
|
20
|
+
onChange?.(changed);
|
|
21
|
+
};
|
|
22
|
+
// Existing business/Popover options API retains its original appearance and callback.
|
|
23
|
+
if (options)
|
|
24
|
+
return <LegacyRadioGroup value={String(value ?? '')} options={options} disabled={!!props.disabled || !!field?.disabled} onChange={next => onChange?.(next)}/>;
|
|
25
|
+
return <Context.Provider value={{ props: { ...props, disabled: props.disabled ?? field?.disabled }, value: current, select }}><view className={`ui-choice-group ui-choice-group-${direction} ${props.type === 'button' ? 'ui-choice-group-buttons' : ''} ${className}`} style={style}>{children}</view></Context.Provider>;
|
|
26
|
+
}
|
|
27
|
+
export function Radio(props) {
|
|
28
|
+
const group = useContext(Context), field = useContext(FormFieldContext);
|
|
29
|
+
const merged = { ...choiceDefaults(group?.props), ...Object.fromEntries(Object.entries(props).filter(([, v]) => v !== undefined && v !== null)) };
|
|
30
|
+
return <Choice {...merged} disabled={field?.disabled || merged.disabled} checked={Object.is(group?.value, props.value)} onTap={() => {
|
|
31
|
+
'background only';
|
|
32
|
+
group?.select(props.value);
|
|
33
|
+
}}/>;
|
|
34
|
+
}
|
package/dist/Rate.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import type { IconName } from './icons/paths.js';
|
|
3
|
+
export type RateProps = {
|
|
4
|
+
value?: number | null;
|
|
5
|
+
defaultValue?: number;
|
|
6
|
+
onChange?: (event: {
|
|
7
|
+
value: number;
|
|
8
|
+
}) => void;
|
|
9
|
+
num?: number;
|
|
10
|
+
readonly?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
size?: number | string;
|
|
13
|
+
space?: number | string;
|
|
14
|
+
color?: string;
|
|
15
|
+
activeColor?: string | readonly string[];
|
|
16
|
+
disabledColor?: string;
|
|
17
|
+
icon?: IconName;
|
|
18
|
+
activeIcon?: IconName;
|
|
19
|
+
allowHalf?: boolean;
|
|
20
|
+
clearable?: boolean;
|
|
21
|
+
block?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: CSSProperties;
|
|
24
|
+
};
|
|
25
|
+
export declare function Rate({ value, defaultValue, onChange, num, readonly, disabled: disabledProp, size, space, color, activeColor, disabledColor, icon, activeIcon, allowHalf, clearable, block, className, style }: RateProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Rate.jsx
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { FormFieldContext } from './formContext.js';
|
|
2
|
+
import { useContext, useState } from '@lynx-js/react';
|
|
3
|
+
import { iconPaths } from './icons/paths.js';
|
|
4
|
+
import { loadingDimension } from './loadingModel.js';
|
|
5
|
+
import { nextRateValue, rateCount, rateScore, rateSvg } from './rateModel.js';
|
|
6
|
+
export function Rate({ value, defaultValue = 0, onChange, num = 5, readonly = false, disabled: disabledProp, size = 24, space = 6, color, activeColor = '#faad14', disabledColor, icon = 'star-fill', activeIcon = 'star-fill', allowHalf = false, clearable = false, block = false, className = '', style }) {
|
|
7
|
+
const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
|
|
8
|
+
const [inner, setInner] = useState(defaultValue);
|
|
9
|
+
const count = rateCount(num);
|
|
10
|
+
const score = rateScore(value === undefined ? inner : value, count);
|
|
11
|
+
const chosen = typeof activeColor === 'string' ? activeColor : activeColor[score <= count / 2 ? 0 : 1] ?? activeColor[0] ?? '#faad14';
|
|
12
|
+
const select = (next) => {
|
|
13
|
+
'background only';
|
|
14
|
+
if (readonly || disabled)
|
|
15
|
+
return;
|
|
16
|
+
const nextValue = nextRateValue(score, next, allowHalf, clearable);
|
|
17
|
+
if (nextValue === score)
|
|
18
|
+
return;
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
setInner(nextValue);
|
|
21
|
+
onChange?.({ value: nextValue });
|
|
22
|
+
};
|
|
23
|
+
const controlStyle = { '--ui-rate-size': loadingDimension(size), '--ui-rate-space': typeof space === 'number' ? `${Math.max(0, space)}px` : loadingDimension(space), ...style };
|
|
24
|
+
const idle = rateSvg(iconPaths[icon] ?? '', color ?? '#c9cbd4');
|
|
25
|
+
const filled = rateSvg(iconPaths[activeIcon] ?? '', disabled && disabledColor ? disabledColor : chosen);
|
|
26
|
+
return <view className={`ui-rate ${block ? 'ui-rate-block' : ''} ${disabled ? 'ui-rate-disabled' : ''} ${className}`} style={controlStyle}>
|
|
27
|
+
{Array.from({ length: count }, (_, index) => {
|
|
28
|
+
const fraction = Math.max(0, Math.min(1, score - index));
|
|
29
|
+
return <view className="ui-rate-item" key={index}>
|
|
30
|
+
{fraction < 1 ? <view className="ui-rate-empty" style={{ width: `${(1 - fraction) * 100}%` }}>
|
|
31
|
+
{color ? <svg className="ui-rate-glyph" content={idle}/> : <><svg className="ui-rate-glyph ui-rate-default-light" content={idle}/><svg className="ui-rate-glyph ui-rate-default-dark" content={rateSvg(iconPaths[icon] ?? '', '#6b7085')}/></>}
|
|
32
|
+
</view> : null}
|
|
33
|
+
{fraction > 0 ? <view className="ui-rate-fill" style={{ width: `${fraction * 100}%` }}><svg className="ui-rate-glyph" content={filled}/></view> : null}
|
|
34
|
+
{allowHalf ? <view className="ui-rate-hit ui-rate-hit-half" bindtap={() => select(index + .5)} accessibility-element accessibility-traits="button" accessibility-label={`${index + .5}分`}/> : null}
|
|
35
|
+
<view className={`ui-rate-hit ${allowHalf ? 'ui-rate-hit-full' : ''}`} bindtap={() => select(index + 1)} accessibility-element accessibility-traits="button" accessibility-label={`${index + 1}分`}/>
|
|
36
|
+
</view>;
|
|
37
|
+
})}
|
|
38
|
+
</view>;
|
|
39
|
+
}
|
package/dist/Resize.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
export type ResizeRect = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
top: number;
|
|
6
|
+
right: number;
|
|
7
|
+
bottom: number;
|
|
8
|
+
left: number;
|
|
9
|
+
};
|
|
10
|
+
export type ResizeProps = {
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
className?: string;
|
|
13
|
+
containerClassName?: string;
|
|
14
|
+
onResize?: (rect: ResizeRect) => void;
|
|
15
|
+
};
|
|
16
|
+
/** Reports initial geometry and subsequent size changes using native layout events. */
|
|
17
|
+
export declare function Resize({ children, className, containerClassName, onResize }: ResizeProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Resize.jsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useRef } from '@lynx-js/react';
|
|
2
|
+
/** Reports initial geometry and subsequent size changes using native layout events. */
|
|
3
|
+
export function Resize({ children, className = '', containerClassName = '', onResize }) {
|
|
4
|
+
const previous = useRef(null);
|
|
5
|
+
const handleLayout = (event) => {
|
|
6
|
+
'background only';
|
|
7
|
+
const { width, height, top, right, bottom, left } = event.detail;
|
|
8
|
+
if (![width, height, top, right, bottom, left].every(Number.isFinite))
|
|
9
|
+
return;
|
|
10
|
+
if (previous.current?.width === width && previous.current.height === height)
|
|
11
|
+
return;
|
|
12
|
+
const rect = { width, height, top, right, bottom, left };
|
|
13
|
+
previous.current = rect;
|
|
14
|
+
onResize?.(rect);
|
|
15
|
+
};
|
|
16
|
+
return <view className={`ui-resize ${className}`}><view className={`ui-resize-container ${containerClassName}`} flatten={false} bindlayoutchange={handleLayout}>{children}</view></view>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties, NodesRef, StandardProps } from '@lynx-js/types';
|
|
3
|
+
import type { RichTextHeading, RichTextParseOptions } from './richTextModel.js';
|
|
4
|
+
import type { RichTextMediaEvent, RichTextMediaSignal, RichTextMediaTimeUpdate } from './richTextMedia.js';
|
|
5
|
+
export type { RichTextMediaEvent, RichTextMediaTimeUpdate } from './richTextMedia.js';
|
|
6
|
+
export type { RichTextHeading } from './richTextModel.js';
|
|
7
|
+
export type RichTextError = {
|
|
8
|
+
source: 'parse' | 'image' | 'audio' | 'video';
|
|
9
|
+
message?: string;
|
|
10
|
+
code?: string;
|
|
11
|
+
src?: string;
|
|
12
|
+
index?: number;
|
|
13
|
+
};
|
|
14
|
+
export type RichTextRect = {
|
|
15
|
+
top: number;
|
|
16
|
+
left: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
export type RichTextRef = {
|
|
21
|
+
playMedia: (id: string) => boolean;
|
|
22
|
+
pauseMedia: (id?: string) => boolean;
|
|
23
|
+
seekMedia: (id: string, seconds: number) => boolean;
|
|
24
|
+
getText: () => string;
|
|
25
|
+
getHeadings: () => RichTextHeading[];
|
|
26
|
+
getAnchorRect: (id: string) => Promise<RichTextRect>;
|
|
27
|
+
scrollToAnchor: (id: string, options?: {
|
|
28
|
+
offset?: number;
|
|
29
|
+
duration?: number;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
export type RichTextProps = Omit<RichTextParseOptions, 'enableMedia'> & {
|
|
33
|
+
/** Browser only: first register the custom element from daisu-ui/web. */
|
|
34
|
+
mediaMode?: 'none' | 'browser';
|
|
35
|
+
onMediaPlay?: (event: RichTextMediaEvent) => void;
|
|
36
|
+
onMediaPause?: (event: RichTextMediaEvent) => void;
|
|
37
|
+
onMediaEnded?: (event: RichTextMediaEvent) => void;
|
|
38
|
+
onMediaTimeUpdate?: (event: RichTextMediaTimeUpdate) => void;
|
|
39
|
+
content?: string;
|
|
40
|
+
selectable?: boolean;
|
|
41
|
+
previewImage?: boolean;
|
|
42
|
+
loadingImage?: string;
|
|
43
|
+
errorImage?: string;
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
onLoad?: (event: {
|
|
46
|
+
imageCount: number;
|
|
47
|
+
}) => void;
|
|
48
|
+
onError?: (error: RichTextError) => void;
|
|
49
|
+
onLinkClick?: (event: {
|
|
50
|
+
href: string;
|
|
51
|
+
}) => void;
|
|
52
|
+
onImageClick?: (event: {
|
|
53
|
+
src: string;
|
|
54
|
+
index: number;
|
|
55
|
+
}) => void;
|
|
56
|
+
onImageLoad?: (event: {
|
|
57
|
+
src: string;
|
|
58
|
+
index: number;
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
}) => void;
|
|
62
|
+
/** Scroll the actual parent container using the measured viewport rect. */
|
|
63
|
+
onScrollToAnchor?: (target: {
|
|
64
|
+
id: string;
|
|
65
|
+
rect: RichTextRect;
|
|
66
|
+
offset: number;
|
|
67
|
+
duration: number;
|
|
68
|
+
}) => void | Promise<void>;
|
|
69
|
+
className?: string;
|
|
70
|
+
style?: CSSProperties;
|
|
71
|
+
};
|
|
72
|
+
type BrowserMediaProps = StandardProps & {
|
|
73
|
+
'media-config': string;
|
|
74
|
+
ref?: ((node: NodesRef | null) => void) | {
|
|
75
|
+
current: NodesRef | null;
|
|
76
|
+
};
|
|
77
|
+
bindmediaevent?: (event: {
|
|
78
|
+
detail: RichTextMediaSignal;
|
|
79
|
+
}) => void;
|
|
80
|
+
};
|
|
81
|
+
declare module '@lynx-js/types' {
|
|
82
|
+
interface IntrinsicElements {
|
|
83
|
+
'daisu-rich-media': BrowserMediaProps;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
declare global {
|
|
87
|
+
namespace JSX {
|
|
88
|
+
interface IntrinsicElements {
|
|
89
|
+
'daisu-rich-media': BrowserMediaProps;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** HTML is parsed into native views, nested text, images and the public Table. */
|
|
94
|
+
export declare const RichText: (props: Omit<RichTextParseOptions, "enableMedia"> & {
|
|
95
|
+
/** Browser only: first register the custom element from daisu-ui/web. */
|
|
96
|
+
mediaMode?: "none" | "browser";
|
|
97
|
+
onMediaPlay?: (event: RichTextMediaEvent) => void;
|
|
98
|
+
onMediaPause?: (event: RichTextMediaEvent) => void;
|
|
99
|
+
onMediaEnded?: (event: RichTextMediaEvent) => void;
|
|
100
|
+
onMediaTimeUpdate?: (event: RichTextMediaTimeUpdate) => void;
|
|
101
|
+
content?: string;
|
|
102
|
+
selectable?: boolean;
|
|
103
|
+
previewImage?: boolean;
|
|
104
|
+
loadingImage?: string;
|
|
105
|
+
errorImage?: string;
|
|
106
|
+
children?: ReactNode;
|
|
107
|
+
onLoad?: (event: {
|
|
108
|
+
imageCount: number;
|
|
109
|
+
}) => void;
|
|
110
|
+
onError?: (error: RichTextError) => void;
|
|
111
|
+
onLinkClick?: (event: {
|
|
112
|
+
href: string;
|
|
113
|
+
}) => void;
|
|
114
|
+
onImageClick?: (event: {
|
|
115
|
+
src: string;
|
|
116
|
+
index: number;
|
|
117
|
+
}) => void;
|
|
118
|
+
onImageLoad?: (event: {
|
|
119
|
+
src: string;
|
|
120
|
+
index: number;
|
|
121
|
+
width: number;
|
|
122
|
+
height: number;
|
|
123
|
+
}) => void;
|
|
124
|
+
/** Scroll the actual parent container using the measured viewport rect. */
|
|
125
|
+
onScrollToAnchor?: (target: {
|
|
126
|
+
id: string;
|
|
127
|
+
rect: RichTextRect;
|
|
128
|
+
offset: number;
|
|
129
|
+
duration: number;
|
|
130
|
+
}) => void | Promise<void>;
|
|
131
|
+
className?: string;
|
|
132
|
+
style?: CSSProperties;
|
|
133
|
+
} & import("react").RefAttributes<RichTextRef>) => React.ReactElement | null;
|