@qw-ui/core 0.3.0-next.40 → 0.3.0-next.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -37
- package/dist/action-sheet/action-sheet.d.ts +110 -0
- package/dist/action-sheet/index.d.ts +2 -0
- package/dist/action-sheet/index.js +2 -0
- package/dist/action-sheet-Cvcr1S_m.js +183 -0
- package/dist/action-sheet-Cvcr1S_m.js.map +1 -0
- package/dist/area-picker/area-picker.d.ts +113 -0
- package/dist/area-picker/index.d.ts +1 -0
- package/dist/area-picker/index.js +348 -0
- package/dist/area-picker/index.js.map +1 -0
- package/dist/aria-description-CimD2M_C.js +13 -0
- package/dist/aria-description-CimD2M_C.js.map +1 -0
- package/dist/aria-description.d.ts +2 -0
- package/dist/avatar/avatar-load.d.ts +76 -0
- package/dist/avatar/avatar.d.ts +22 -5
- package/dist/avatar/index.d.ts +1 -0
- package/dist/avatar/index.js +57 -18
- package/dist/avatar/index.js.map +1 -1
- package/dist/avatar-load-w9dq05oV.js +139 -0
- package/dist/avatar-load-w9dq05oV.js.map +1 -0
- package/dist/back-top/back-top.d.ts +77 -0
- package/dist/back-top/index.d.ts +1 -0
- package/dist/back-top/index.js +189 -0
- package/dist/back-top/index.js.map +1 -0
- package/dist/badge/badge.d.ts +9 -0
- package/dist/badge/index.js +14 -1
- package/dist/badge/index.js.map +1 -1
- package/dist/button/button.d.ts +13 -0
- package/dist/button/index.js +3 -5
- package/dist/button/index.js.map +1 -1
- package/dist/calendar/calendar.d.ts +100 -0
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +2 -0
- package/dist/calendar-CmpK3stz.js +363 -0
- package/dist/calendar-CmpK3stz.js.map +1 -0
- package/dist/card/card.d.ts +68 -0
- package/dist/card/index.d.ts +2 -0
- package/dist/card/index.js +2 -0
- package/dist/card-DRtWa6Cr.js +107 -0
- package/dist/card-DRtWa6Cr.js.map +1 -0
- package/dist/cascader/cascader.d.ts +115 -0
- package/dist/cascader/index.d.ts +1 -0
- package/dist/cascader/index.js +2 -0
- package/dist/cascader-D-xMjs7P.js +333 -0
- package/dist/cascader-D-xMjs7P.js.map +1 -0
- package/dist/cell/cell.d.ts +41 -0
- package/dist/cell/index.d.ts +1 -0
- package/dist/cell/index.js +43 -0
- package/dist/cell/index.js.map +1 -0
- package/dist/check-list/check-list.d.ts +78 -0
- package/dist/check-list/index.d.ts +2 -0
- package/dist/check-list/index.js +2 -0
- package/dist/check-list-BvZHQt5w.js +60 -0
- package/dist/check-list-BvZHQt5w.js.map +1 -0
- package/dist/checkbox/checkbox.d.ts +59 -0
- package/dist/checkbox/index.d.ts +2 -0
- package/dist/checkbox/index.js +2 -0
- package/dist/checkbox-BlndJrz5.js +127 -0
- package/dist/checkbox-BlndJrz5.js.map +1 -0
- package/dist/checkbox-group/checkbox-group.d.ts +86 -0
- package/dist/checkbox-group/index.d.ts +3 -0
- package/dist/checkbox-group/index.js +2 -0
- package/dist/checkbox-group-gGfsTv-e.js +223 -0
- package/dist/checkbox-group-gGfsTv-e.js.map +1 -0
- package/dist/choice-group-C4c9m0qe.js +373 -0
- package/dist/choice-group-C4c9m0qe.js.map +1 -0
- package/dist/circle/circle.d.ts +97 -0
- package/dist/circle/index.d.ts +1 -0
- package/dist/circle/index.js +119 -0
- package/dist/circle/index.js.map +1 -0
- package/dist/collapse/collapse.d.ts +98 -0
- package/dist/collapse/index.d.ts +2 -0
- package/dist/collapse/index.js +2 -0
- package/dist/collapse-B969h7-H.js +226 -0
- package/dist/collapse-B969h7-H.js.map +1 -0
- package/dist/countdown/countdown.d.ts +114 -0
- package/dist/countdown/index.d.ts +1 -0
- package/dist/countdown/index.js +309 -0
- package/dist/countdown/index.js.map +1 -0
- package/dist/date-picker/date-picker.d.ts +168 -0
- package/dist/date-picker/index.d.ts +1 -0
- package/dist/date-picker/index.js +401 -0
- package/dist/date-picker/index.js.map +1 -0
- package/dist/descriptions/descriptions.d.ts +69 -0
- package/dist/descriptions/index.d.ts +1 -0
- package/dist/descriptions/index.js +86 -0
- package/dist/descriptions/index.js.map +1 -0
- package/dist/dialog/dialog.d.ts +32 -3
- package/dist/dialog/index.js +58 -3
- package/dist/dialog/index.js.map +1 -1
- package/dist/divider/divider.d.ts +18 -2
- package/dist/divider/index.js +20 -2
- package/dist/divider/index.js.map +1 -1
- package/dist/dropdown/dropdown.d.ts +172 -0
- package/dist/dropdown/index.d.ts +2 -0
- package/dist/dropdown/index.js +467 -0
- package/dist/dropdown/index.js.map +1 -0
- package/dist/ellipsis/ellipsis-layout.d.ts +34 -0
- package/dist/ellipsis/ellipsis.d.ts +88 -0
- package/dist/ellipsis/index.d.ts +2 -0
- package/dist/ellipsis/index.js +320 -0
- package/dist/ellipsis/index.js.map +1 -0
- package/dist/empty/empty-illustration.d.ts +3 -0
- package/dist/empty/empty.d.ts +43 -1
- package/dist/empty/index.js +2 -21
- package/dist/empty-CAgyvhUI.js +166 -0
- package/dist/empty-CAgyvhUI.js.map +1 -0
- package/dist/field/field.d.ts +95 -0
- package/dist/field/index.d.ts +2 -0
- package/dist/field/index.js +2 -0
- package/dist/field-DMHGIMZF.js +241 -0
- package/dist/field-DMHGIMZF.js.map +1 -0
- package/dist/floating-bubble/floating-bubble.d.ts +116 -0
- package/dist/floating-bubble/index.d.ts +1 -0
- package/dist/floating-bubble/index.js +333 -0
- package/dist/floating-bubble/index.js.map +1 -0
- package/dist/floating-panel/floating-panel.d.ts +80 -0
- package/dist/floating-panel/index.d.ts +2 -0
- package/dist/floating-panel/index.js +2 -0
- package/dist/floating-panel-Cbm5njBJ.js +363 -0
- package/dist/floating-panel-Cbm5njBJ.js.map +1 -0
- package/dist/footer/footer.d.ts +94 -0
- package/dist/footer/index.d.ts +1 -0
- package/dist/footer/index.js +154 -0
- package/dist/footer/index.js.map +1 -0
- package/dist/form/connect.d.ts +6 -0
- package/dist/form/form.d.ts +100 -0
- package/dist/form/ids.d.ts +14 -0
- package/dist/form/index.d.ts +13 -0
- package/dist/form/index.js +3 -0
- package/dist/form/methods.d.ts +5 -0
- package/dist/form/model.d.ts +24 -0
- package/dist/form/native.d.ts +25 -0
- package/dist/form/rules.d.ts +40 -0
- package/dist/form/ssr.d.ts +7 -0
- package/dist/form/types.d.ts +150 -0
- package/dist/form-BAGkIEMY.js +1354 -0
- package/dist/form-BAGkIEMY.js.map +1 -0
- package/dist/format-BDUY0C_c.js +89 -0
- package/dist/format-BDUY0C_c.js.map +1 -0
- package/dist/gesture-_SRHIvBm.js +30 -0
- package/dist/gesture-_SRHIvBm.js.map +1 -0
- package/dist/grid/grid-item.d.ts +22 -0
- package/dist/grid/grid.d.ts +42 -0
- package/dist/grid/index.d.ts +2 -0
- package/dist/grid/index.js +73 -0
- package/dist/grid/index.js.map +1 -0
- package/dist/icon/icon.d.ts +37 -1
- package/dist/icon/identity.d.ts +3 -0
- package/dist/icon/index.js +2 -20
- package/dist/icon-Cgdbnk1u.js +77 -0
- package/dist/icon-Cgdbnk1u.js.map +1 -0
- package/dist/image/image-load.d.ts +24 -0
- package/dist/image/image.d.ts +45 -8
- package/dist/image/index.d.ts +1 -0
- package/dist/image/index.js +116 -14
- package/dist/image/index.js.map +1 -1
- package/dist/image-preview/image-preview.d.ts +124 -0
- package/dist/image-preview/index.d.ts +1 -0
- package/dist/image-preview/index.js +450 -0
- package/dist/image-preview/index.js.map +1 -0
- package/dist/index-bar/index-bar.d.ts +121 -0
- package/dist/index-bar/index.d.ts +1 -0
- package/dist/index-bar/index.js +386 -0
- package/dist/index-bar/index.js.map +1 -0
- package/dist/index.d.ts +107 -14
- package/dist/index.js +148 -14
- package/dist/index.js.map +1 -0
- package/dist/infinite-scroll/index.d.ts +1 -0
- package/dist/infinite-scroll/index.js +248 -0
- package/dist/infinite-scroll/index.js.map +1 -0
- package/dist/infinite-scroll/infinite-scroll.d.ts +95 -0
- package/dist/input/index.js +181 -22
- package/dist/input/index.js.map +1 -1
- package/dist/input/input.d.ts +44 -1
- package/dist/layer-IpFrl5--.js +414 -0
- package/dist/layer-IpFrl5--.js.map +1 -0
- package/dist/layout-BRSqi4AQ.js +43 -0
- package/dist/layout-BRSqi4AQ.js.map +1 -0
- package/dist/layout.d.ts +13 -0
- package/dist/list/index.d.ts +2 -0
- package/dist/list/index.js +2 -0
- package/dist/list/list.d.ts +30 -0
- package/dist/list-6-iz-Irh.js +28 -0
- package/dist/list-6-iz-Irh.js.map +1 -0
- package/dist/loading/index.js +45 -2
- package/dist/loading/index.js.map +1 -1
- package/dist/loading/loading.d.ts +45 -2
- package/dist/modal-dialog-machine-CF9_z3Dm.js +487 -0
- package/dist/modal-dialog-machine-CF9_z3Dm.js.map +1 -0
- package/dist/modal-dialog-machine.d.ts +21 -0
- package/dist/modal-dismissable-lifetime.d.ts +21 -0
- package/dist/modal-registry.d.ts +24 -0
- package/dist/modal-render-hydration.d.ts +35 -0
- package/dist/modal-render-runtime.d.ts +19 -0
- package/dist/modal-render-scope.d.ts +63 -0
- package/dist/nav-bar/index.d.ts +1 -0
- package/dist/nav-bar/index.js +115 -0
- package/dist/nav-bar/index.js.map +1 -0
- package/dist/nav-bar/nav-bar.d.ts +76 -0
- package/dist/notice-bar/index.d.ts +2 -0
- package/dist/notice-bar/index.js +2 -0
- package/dist/notice-bar/notice-bar.d.ts +103 -0
- package/dist/notice-bar-DMpwLvRb.js +231 -0
- package/dist/notice-bar-DMpwLvRb.js.map +1 -0
- package/dist/notify/index.d.ts +1 -0
- package/dist/notify/index.js +251 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/notify/notify.d.ts +123 -0
- package/dist/number-keyboard/index.d.ts +1 -0
- package/dist/number-keyboard/index.js +333 -0
- package/dist/number-keyboard/index.js.map +1 -0
- package/dist/number-keyboard/number-keyboard.d.ts +141 -0
- package/dist/page-indicator/index.d.ts +1 -0
- package/dist/page-indicator/index.js +138 -0
- package/dist/page-indicator/index.js.map +1 -0
- package/dist/page-indicator/page-indicator.d.ts +93 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +198 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/pagination/pagination.d.ts +125 -0
- package/dist/password-input/index.d.ts +1 -0
- package/dist/password-input/index.js +317 -0
- package/dist/password-input/index.js.map +1 -0
- package/dist/password-input/password-input.d.ts +144 -0
- package/dist/picker/index.d.ts +8 -0
- package/dist/picker/index.js +2 -0
- package/dist/picker/picker-machine.d.ts +80 -0
- package/dist/picker/picker.d.ts +121 -0
- package/dist/picker/platform.d.ts +84 -0
- package/dist/picker/selection-connect.d.ts +90 -0
- package/dist/picker/selection-model.d.ts +211 -0
- package/dist/picker-BykFntQN.js +1675 -0
- package/dist/picker-BykFntQN.js.map +1 -0
- package/dist/popover/index.d.ts +3 -0
- package/dist/popover/index.js +253 -0
- package/dist/popover/index.js.map +1 -0
- package/dist/popover/layer.d.ts +44 -0
- package/dist/popover/popover.d.ts +104 -0
- package/dist/popover/positioning.d.ts +132 -0
- package/dist/popup/index.d.ts +2 -0
- package/dist/popup/index.js +2 -0
- package/dist/popup/popup.d.ts +60 -0
- package/dist/popup-z5d8IYCt.js +576 -0
- package/dist/popup-z5d8IYCt.js.map +1 -0
- package/dist/portal-BHCNTWhg.js +78 -0
- package/dist/portal-BHCNTWhg.js.map +1 -0
- package/dist/portal.d.ts +61 -0
- package/dist/price/format.d.ts +19 -0
- package/dist/price/index.d.ts +1 -0
- package/dist/price/index.js +154 -0
- package/dist/price/index.js.map +1 -0
- package/dist/price/price.d.ts +88 -0
- package/dist/progress/index.d.ts +1 -0
- package/dist/progress/index.js +2 -0
- package/dist/progress/progress.d.ts +32 -0
- package/dist/progress-f3iYEfdA.js +37 -0
- package/dist/progress-f3iYEfdA.js.map +1 -0
- package/dist/pull-refresh/index.d.ts +1 -0
- package/dist/pull-refresh/index.js +414 -0
- package/dist/pull-refresh/index.js.map +1 -0
- package/dist/pull-refresh/pull-refresh.d.ts +118 -0
- package/dist/radio-group/index.d.ts +3 -0
- package/dist/radio-group/index.js +2 -0
- package/dist/radio-group/radio-group.d.ts +78 -0
- package/dist/radio-group-BOIMuqnS.js +230 -0
- package/dist/radio-group-BOIMuqnS.js.map +1 -0
- package/dist/rate/index.d.ts +1 -0
- package/dist/rate/index.js +2 -0
- package/dist/rate/rate-form.d.ts +28 -0
- package/dist/rate/rate.d.ts +144 -0
- package/dist/rate-5XsU2QkY.js +631 -0
- package/dist/rate-5XsU2QkY.js.map +1 -0
- package/dist/reorder/index.d.ts +1 -0
- package/dist/reorder/index.js +720 -0
- package/dist/reorder/index.js.map +1 -0
- package/dist/reorder/reorder.d.ts +190 -0
- package/dist/result/index.d.ts +1 -0
- package/dist/result/index.js +123 -0
- package/dist/result/index.js.map +1 -0
- package/dist/result/result.d.ts +88 -0
- package/dist/safe-area/index.d.ts +1 -0
- package/dist/safe-area/index.js +42 -0
- package/dist/safe-area/index.js.map +1 -0
- package/dist/safe-area/safe-area.d.ts +28 -0
- package/dist/search-bar/index.js +3 -1
- package/dist/search-bar/index.js.map +1 -1
- package/dist/search-bar/search-bar.d.ts +4 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.d.ts +127 -0
- package/dist/segmented-BaU38_L4.js +367 -0
- package/dist/segmented-BaU38_L4.js.map +1 -0
- package/dist/selection-form-BOM_odUk.js +88 -0
- package/dist/selection-form-BOM_odUk.js.map +1 -0
- package/dist/selection-form.d.ts +27 -0
- package/dist/selection-ivXqO1eu.js +55 -0
- package/dist/selection-ivXqO1eu.js.map +1 -0
- package/dist/selection.d.ts +29 -0
- package/dist/selector/choice-group.d.ts +114 -0
- package/dist/selector/index.d.ts +2 -0
- package/dist/selector/index.js +2 -0
- package/dist/selector/selector.d.ts +90 -0
- package/dist/selector-BU2MMJ4N.js +93 -0
- package/dist/selector-BU2MMJ4N.js.map +1 -0
- package/dist/share-sheet/index.d.ts +1 -0
- package/dist/share-sheet/index.js +138 -0
- package/dist/share-sheet/index.js.map +1 -0
- package/dist/share-sheet/share-sheet.d.ts +139 -0
- package/dist/skeleton/index.js +51 -2
- package/dist/skeleton/index.js.map +1 -1
- package/dist/skeleton/skeleton.d.ts +34 -3
- package/dist/slider/index.d.ts +1 -0
- package/dist/slider/index.js +482 -0
- package/dist/slider/index.js.map +1 -0
- package/dist/slider/slider.d.ts +174 -0
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +52 -0
- package/dist/space/index.js.map +1 -0
- package/dist/space/space.d.ts +46 -0
- package/dist/statistic/index.d.ts +1 -0
- package/dist/statistic/index.js +152 -0
- package/dist/statistic/index.js.map +1 -0
- package/dist/statistic/statistic.d.ts +101 -0
- package/dist/stepper/index.js +62 -3
- package/dist/stepper/index.js.map +1 -1
- package/dist/stepper/stepper.d.ts +44 -4
- package/dist/steps/index.d.ts +1 -0
- package/dist/steps/index.js +72 -0
- package/dist/steps/index.js.map +1 -0
- package/dist/steps/steps.d.ts +67 -0
- package/dist/sticky/index.d.ts +1 -0
- package/dist/sticky/index.js +145 -0
- package/dist/sticky/index.js.map +1 -0
- package/dist/sticky/sticky.d.ts +70 -0
- package/dist/swipe-action/index.d.ts +1 -0
- package/dist/swipe-action/index.js +417 -0
- package/dist/swipe-action/index.js.map +1 -0
- package/dist/swipe-action/swipe-action.d.ts +148 -0
- package/dist/swiper/gesture.d.ts +32 -0
- package/dist/swiper/index.d.ts +1 -0
- package/dist/swiper/index.js +2 -0
- package/dist/swiper/swiper.d.ts +177 -0
- package/dist/swiper-BKivDkHp.js +550 -0
- package/dist/swiper-BKivDkHp.js.map +1 -0
- package/dist/switch/index.js +135 -10
- package/dist/switch/index.js.map +1 -1
- package/dist/switch/switch.d.ts +93 -6
- package/dist/tabbar/index.js +46 -1
- package/dist/tabbar/index.js.map +1 -1
- package/dist/tabbar/tabbar.d.ts +50 -0
- package/dist/tabs/index.js +22 -1
- package/dist/tabs/index.js.map +1 -1
- package/dist/tabs/tabs.d.ts +12 -8
- package/dist/tag/index.js +123 -2
- package/dist/tag/index.js.map +1 -1
- package/dist/tag/tag.d.ts +67 -1
- package/dist/textarea/index.d.ts +2 -0
- package/dist/textarea/index.js +2 -242
- package/dist/textarea/platform.d.ts +22 -0
- package/dist/textarea/textarea.d.ts +165 -46
- package/dist/textarea-qbnruDUG.js +775 -0
- package/dist/textarea-qbnruDUG.js.map +1 -0
- package/dist/time-picker/index.d.ts +1 -0
- package/dist/time-picker/index.js +228 -0
- package/dist/time-picker/index.js.map +1 -0
- package/dist/time-picker/time-picker.d.ts +83 -0
- package/dist/timeline/index.d.ts +1 -0
- package/dist/timeline/index.js +131 -0
- package/dist/timeline/index.js.map +1 -0
- package/dist/timeline/timeline.d.ts +79 -0
- package/dist/toast/index.js +47 -4
- package/dist/toast/index.js.map +1 -1
- package/dist/toast/toast.d.ts +26 -3
- package/dist/top-bar/index.js +16 -2
- package/dist/top-bar/index.js.map +1 -1
- package/dist/top-bar/top-bar.d.ts +13 -2
- package/dist/tree-select/index.d.ts +1 -0
- package/dist/tree-select/index.js +512 -0
- package/dist/tree-select/index.js.map +1 -0
- package/dist/tree-select/tree-select.d.ts +215 -0
- package/dist/typography/index.d.ts +1 -0
- package/dist/typography/index.js +82 -0
- package/dist/typography/index.js.map +1 -0
- package/dist/typography/typography.d.ts +54 -0
- package/dist/upload/index.d.ts +1 -0
- package/dist/upload/index.js +458 -0
- package/dist/upload/index.js.map +1 -0
- package/dist/upload/upload.d.ts +172 -0
- package/dist/virtual-list/index.d.ts +1 -0
- package/dist/virtual-list/index.js +445 -0
- package/dist/virtual-list/index.js.map +1 -0
- package/dist/virtual-list/virtual-list.d.ts +160 -0
- package/dist/visual-manifest.d.ts +6 -0
- package/dist/watermark/index.d.ts +1 -0
- package/dist/watermark/index.js +260 -0
- package/dist/watermark/index.js.map +1 -0
- package/dist/watermark/watermark.d.ts +106 -0
- package/package.json +399 -50
- package/dist/empty/index.js.map +0 -1
- package/dist/icon/index.js.map +0 -1
- package/dist/textarea/index.js.map +0 -1
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
import { createMachine } from "@zag-js/core";
|
|
2
|
+
import { compact } from "@zag-js/utils";
|
|
3
|
+
//#region src/textarea/textarea.ts
|
|
4
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
5
|
+
function sessionOf(service) {
|
|
6
|
+
const id = service.prop("id") ?? "";
|
|
7
|
+
let session = sessions.get(id);
|
|
8
|
+
if (!session) {
|
|
9
|
+
session = {
|
|
10
|
+
epoch: 0,
|
|
11
|
+
ticket: 0,
|
|
12
|
+
ticketSeq: 0,
|
|
13
|
+
autoApplied: false,
|
|
14
|
+
writebackQueued: false,
|
|
15
|
+
service
|
|
16
|
+
};
|
|
17
|
+
sessions.set(id, session);
|
|
18
|
+
}
|
|
19
|
+
session.service = service;
|
|
20
|
+
return session;
|
|
21
|
+
}
|
|
22
|
+
function stripUndefined(props) {
|
|
23
|
+
return Object.fromEntries(Object.entries(props).filter(([, value]) => value !== void 0));
|
|
24
|
+
}
|
|
25
|
+
/** 缺省与非法 rows 收成不小于 1 的整数,缺省 4。 */
|
|
26
|
+
function normalizeRows(rows) {
|
|
27
|
+
if (typeof rows !== "number" || !Number.isFinite(rows) || rows < 1) return 4;
|
|
28
|
+
return Math.floor(rows);
|
|
29
|
+
}
|
|
30
|
+
/** 只有 floor 后仍大于 0 的有限数才成为上限或 minlength。 */
|
|
31
|
+
function positiveInt(value) {
|
|
32
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
|
|
33
|
+
const limit = Math.floor(value);
|
|
34
|
+
return limit > 0 ? limit : void 0;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 有效行数上限。非法 maxRows 表示不封顶。
|
|
38
|
+
* 小于已规范化的 rows 时抬到 rows,避免高度缩到下限以下。
|
|
39
|
+
*/
|
|
40
|
+
function effectiveRowCap(rows, maxRows) {
|
|
41
|
+
const max = positiveInt(maxRows);
|
|
42
|
+
if (max === void 0) return void 0;
|
|
43
|
+
return Math.max(rows, max);
|
|
44
|
+
}
|
|
45
|
+
/** show-actions 只有显式 false / "false" 才关闭。 */
|
|
46
|
+
function showActionsEnabled(value) {
|
|
47
|
+
return value !== false && value !== "false";
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 决议 (c) 的唯一落点:显式识别整段替换。
|
|
51
|
+
* 若改为按光标插入,只改这个函数。
|
|
52
|
+
*/
|
|
53
|
+
function recognizedNextValue(text) {
|
|
54
|
+
return text;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* UTF-16 安全截断。maxLength 为空、非有限,或 floor 后不大于 0 时原样返回。
|
|
58
|
+
*/
|
|
59
|
+
function clampUtf16(value, maxLength) {
|
|
60
|
+
const limitOrNone = positiveInt(maxLength);
|
|
61
|
+
if (limitOrNone === void 0) return value;
|
|
62
|
+
let limit = limitOrNone;
|
|
63
|
+
if (value.length <= limit) return value;
|
|
64
|
+
const boundary = value.charCodeAt(limit - 1);
|
|
65
|
+
const next = value.charCodeAt(limit);
|
|
66
|
+
if (boundary >= 55296 && boundary <= 56319 && next >= 56320 && next <= 57343) limit -= 1;
|
|
67
|
+
return value.slice(0, Math.max(0, limit));
|
|
68
|
+
}
|
|
69
|
+
function metricsUsable(metrics) {
|
|
70
|
+
if (!metrics || metrics.visible === false) return false;
|
|
71
|
+
if (!(metrics.inlineSize > 0) || !(metrics.lineHeight > 0)) return false;
|
|
72
|
+
return [
|
|
73
|
+
metrics.scrollHeight,
|
|
74
|
+
metrics.inlineSize,
|
|
75
|
+
metrics.lineHeight,
|
|
76
|
+
metrics.paddingBlockSize,
|
|
77
|
+
metrics.borderBlockSize
|
|
78
|
+
].every((value) => typeof value === "number" && Number.isFinite(value));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 自动高度像素。下限是 rows;有效 maxRows 把 border-box 再夹住。
|
|
82
|
+
* 无法度量时返回 undefined,调用方不得写成 0。不读取 DOM。
|
|
83
|
+
*/
|
|
84
|
+
function computeTextAreaHeight(input) {
|
|
85
|
+
if (!input.autoSize || !metricsUsable(input.metrics)) return void 0;
|
|
86
|
+
const metrics = input.metrics;
|
|
87
|
+
const minBorder = input.rows * metrics.lineHeight + metrics.paddingBlockSize + metrics.borderBlockSize;
|
|
88
|
+
const measuredBorder = metrics.scrollHeight + metrics.borderBlockSize;
|
|
89
|
+
let borderBox = Math.max(minBorder, measuredBorder);
|
|
90
|
+
const cap = effectiveRowCap(input.rows, input.maxRows);
|
|
91
|
+
if (cap !== void 0) {
|
|
92
|
+
const maxBorder = cap * metrics.lineHeight + metrics.paddingBlockSize + metrics.borderBlockSize;
|
|
93
|
+
borderBox = Math.min(borderBox, maxBorder);
|
|
94
|
+
}
|
|
95
|
+
const height = metrics.boxSizing === "content-box" ? Math.max(0, borderBox - metrics.paddingBlockSize - metrics.borderBlockSize) : borderBox;
|
|
96
|
+
return Math.ceil(height);
|
|
97
|
+
}
|
|
98
|
+
function readCommitted(service) {
|
|
99
|
+
const controlled = service.prop("value");
|
|
100
|
+
return controlled !== void 0 ? controlled : service.context.get("uncontrolled");
|
|
101
|
+
}
|
|
102
|
+
function isControlled(service) {
|
|
103
|
+
return service.prop("value") !== void 0;
|
|
104
|
+
}
|
|
105
|
+
function guarded(service) {
|
|
106
|
+
return !!service.prop("disabled") || !!service.prop("readOnly") || !!service.context.get("controlDisabled");
|
|
107
|
+
}
|
|
108
|
+
function defaultValueOf(service) {
|
|
109
|
+
return service.prop("defaultValue") ?? "";
|
|
110
|
+
}
|
|
111
|
+
function alignDom(service, accepted) {
|
|
112
|
+
const session = sessionOf(service);
|
|
113
|
+
const client = session.client;
|
|
114
|
+
if (!client) return;
|
|
115
|
+
const shown = readCommitted(service);
|
|
116
|
+
if (client.readControl().value === shown || !isControlled(service) || shown === accepted) {
|
|
117
|
+
client.writeValue(shown, defaultValueOf(service));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (session.writebackQueued) return;
|
|
121
|
+
session.writebackQueued = true;
|
|
122
|
+
const epoch = session.epoch;
|
|
123
|
+
queueMicrotask(() => {
|
|
124
|
+
session.writebackQueued = false;
|
|
125
|
+
if (session.epoch !== epoch || !session.client || service.context.get("composing")) return;
|
|
126
|
+
session.client.writeValue(readCommitted(service), defaultValueOf(service));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function syncHeight(service) {
|
|
130
|
+
const session = sessionOf(service);
|
|
131
|
+
const client = session.client;
|
|
132
|
+
if (!client) return;
|
|
133
|
+
if (!!!service.prop("autoSize")) {
|
|
134
|
+
if (session.autoApplied) client.writeHeight(void 0);
|
|
135
|
+
session.autoApplied = false;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
session.autoApplied = true;
|
|
139
|
+
const height = computeTextAreaHeight({
|
|
140
|
+
autoSize: true,
|
|
141
|
+
rows: normalizeRows(service.prop("rows")),
|
|
142
|
+
maxRows: service.prop("maxRows"),
|
|
143
|
+
metrics: client.measureIntrinsic()
|
|
144
|
+
});
|
|
145
|
+
if (typeof height === "number") client.writeHeight(height);
|
|
146
|
+
}
|
|
147
|
+
function publish(service, raw, source) {
|
|
148
|
+
if (source !== "reset" && guarded(service)) {
|
|
149
|
+
const current = readCommitted(service);
|
|
150
|
+
alignDom(service, current);
|
|
151
|
+
return current;
|
|
152
|
+
}
|
|
153
|
+
const accepted = clampUtf16(source === "paste" ? recognizedNextValue(raw) : raw, service.prop("maxLength"));
|
|
154
|
+
const changed = accepted !== readCommitted(service);
|
|
155
|
+
if (!isControlled(service) && changed) service.context.set("uncontrolled", accepted);
|
|
156
|
+
if (changed) {
|
|
157
|
+
service.prop("onChange")?.(accepted);
|
|
158
|
+
service.prop("onTextareaValue")?.({ value: accepted });
|
|
159
|
+
service.prop("onTextareaChange")?.({ value: accepted });
|
|
160
|
+
}
|
|
161
|
+
alignDom(service, accepted);
|
|
162
|
+
return accepted;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 决议 (b) 的唯一落点:失败只走 onPasteError / textarea-paste,不调用 onPasteRecognize。
|
|
166
|
+
*/
|
|
167
|
+
function reportPasteFailure(service, reason) {
|
|
168
|
+
service.prop("onPasteError")?.(reason);
|
|
169
|
+
service.prop("onTextareaPaste")?.({
|
|
170
|
+
value: readCommitted(service),
|
|
171
|
+
status: "unavailable",
|
|
172
|
+
reason
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function clipboardFailure(error) {
|
|
176
|
+
if (error && typeof error === "object" && "reason" in error) {
|
|
177
|
+
const reason = error.reason;
|
|
178
|
+
if (reason === "unsupported" || reason === "denied" || reason === "aborted") return reason;
|
|
179
|
+
}
|
|
180
|
+
return "denied";
|
|
181
|
+
}
|
|
182
|
+
/** 后续编辑、清空、重置或新的显式替换使进行中的读取变为 stale。不推进 epoch,避免打断受控写回。 */
|
|
183
|
+
function invalidateClipboardTicket(session) {
|
|
184
|
+
session.ticket = ++session.ticketSeq;
|
|
185
|
+
}
|
|
186
|
+
function edit(service, event) {
|
|
187
|
+
const session = sessionOf(service);
|
|
188
|
+
invalidateClipboardTicket(session);
|
|
189
|
+
if (event.type === "composition-start" || event.type === "composition-update" || event.type === "input" && service.context.get("composing")) {
|
|
190
|
+
service.context.set("composing", true);
|
|
191
|
+
service.context.set("draft", event.value);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (event.type === "composition-end") {
|
|
195
|
+
const accepted = publish(service, event.value, "input");
|
|
196
|
+
service.context.set("composing", false);
|
|
197
|
+
service.context.set("draft", "");
|
|
198
|
+
session.suppressRaw = event.value;
|
|
199
|
+
session.suppressAccepted = accepted;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (session.suppressRaw !== void 0 || session.suppressAccepted !== void 0) {
|
|
203
|
+
const raw = session.suppressRaw;
|
|
204
|
+
const accepted = session.suppressAccepted;
|
|
205
|
+
session.suppressRaw = void 0;
|
|
206
|
+
session.suppressAccepted = void 0;
|
|
207
|
+
if (event.value === raw || event.value === accepted) return;
|
|
208
|
+
}
|
|
209
|
+
publish(service, event.value, "input");
|
|
210
|
+
}
|
|
211
|
+
function clearValue(service) {
|
|
212
|
+
if (guarded(service)) {
|
|
213
|
+
alignDom(service, readCommitted(service));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
invalidateClipboardTicket(sessionOf(service));
|
|
217
|
+
publish(service, "", "clear");
|
|
218
|
+
service.prop("onClear")?.();
|
|
219
|
+
service.prop("onTextareaClear")?.({ value: "" });
|
|
220
|
+
}
|
|
221
|
+
function pasteRecognize(service, explicit) {
|
|
222
|
+
if (guarded(service)) return;
|
|
223
|
+
if (typeof explicit === "string") {
|
|
224
|
+
invalidateClipboardTicket(sessionOf(service));
|
|
225
|
+
const accepted = publish(service, explicit, "paste");
|
|
226
|
+
service.prop("onPasteRecognize")?.(accepted);
|
|
227
|
+
service.prop("onTextareaPaste")?.({
|
|
228
|
+
value: accepted,
|
|
229
|
+
status: "accepted"
|
|
230
|
+
});
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const session = sessionOf(service);
|
|
234
|
+
const client = session.client;
|
|
235
|
+
if (!client) {
|
|
236
|
+
reportPasteFailure(service, "unsupported");
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const epoch = session.epoch;
|
|
240
|
+
const ticket = ++session.ticketSeq;
|
|
241
|
+
session.ticket = ticket;
|
|
242
|
+
client.readClipboardText().then((text) => {
|
|
243
|
+
if (session.epoch !== epoch || session.ticket !== ticket || guarded(service)) {
|
|
244
|
+
reportPasteFailure(service, "stale");
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const accepted = publish(service, text, "paste");
|
|
248
|
+
service.prop("onPasteRecognize")?.(accepted);
|
|
249
|
+
service.prop("onTextareaPaste")?.({
|
|
250
|
+
value: accepted,
|
|
251
|
+
status: "accepted"
|
|
252
|
+
});
|
|
253
|
+
}, (error) => {
|
|
254
|
+
if (session.epoch !== epoch || session.ticket !== ticket) {
|
|
255
|
+
reportPasteFailure(service, "stale");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
reportPasteFailure(service, clipboardFailure(error));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function focusChanged(service, focused) {
|
|
262
|
+
if (service.context.get("focused") === focused) return;
|
|
263
|
+
service.context.set("focused", focused);
|
|
264
|
+
if (focused) service.prop("onFocus")?.();
|
|
265
|
+
else service.prop("onBlur")?.();
|
|
266
|
+
service.prop("onTextareaFocus")?.({ focused });
|
|
267
|
+
}
|
|
268
|
+
function resetValue(service, notice) {
|
|
269
|
+
if (notice.defaultPrevented) return;
|
|
270
|
+
invalidateClipboardTicket(sessionOf(service));
|
|
271
|
+
publish(service, service.prop("defaultValue") ?? "", "reset");
|
|
272
|
+
}
|
|
273
|
+
function project(service) {
|
|
274
|
+
const client = sessionOf(service).client;
|
|
275
|
+
if (!client) return;
|
|
276
|
+
service.context.set("controlDisabled", client.readControl().disabled);
|
|
277
|
+
if (!service.context.get("composing")) client.writeValue(readCommitted(service), defaultValueOf(service));
|
|
278
|
+
syncHeight(service);
|
|
279
|
+
}
|
|
280
|
+
function sinkFor(service) {
|
|
281
|
+
const session = sessionOf(service);
|
|
282
|
+
if (session.sink) return session.sink;
|
|
283
|
+
const live = () => session.service ?? service;
|
|
284
|
+
const sink = {
|
|
285
|
+
commit(client) {
|
|
286
|
+
const current = live();
|
|
287
|
+
session.client = client;
|
|
288
|
+
session.epoch += 1;
|
|
289
|
+
session.suppressRaw = void 0;
|
|
290
|
+
session.suppressAccepted = void 0;
|
|
291
|
+
current.context.set("controlDisabled", client.readControl().disabled);
|
|
292
|
+
if (!current.context.get("composing")) client.writeValue(readCommitted(current), defaultValueOf(current));
|
|
293
|
+
syncHeight(current);
|
|
294
|
+
},
|
|
295
|
+
changed() {
|
|
296
|
+
const current = live();
|
|
297
|
+
const client = session.client;
|
|
298
|
+
if (!client) return;
|
|
299
|
+
current.context.set("controlDisabled", client.readControl().disabled);
|
|
300
|
+
syncHeight(current);
|
|
301
|
+
},
|
|
302
|
+
edit(event) {
|
|
303
|
+
edit(live(), event);
|
|
304
|
+
},
|
|
305
|
+
focusChanged(focused) {
|
|
306
|
+
focusChanged(live(), focused);
|
|
307
|
+
},
|
|
308
|
+
reset(notice) {
|
|
309
|
+
resetValue(live(), notice);
|
|
310
|
+
},
|
|
311
|
+
detach() {
|
|
312
|
+
session.epoch += 1;
|
|
313
|
+
session.client = void 0;
|
|
314
|
+
session.autoApplied = false;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
session.sink = sink;
|
|
318
|
+
return sink;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* TextArea zag.js machine。
|
|
322
|
+
* 值、草稿、ticket 与高度结论都在这里;没有第二份 value watcher。
|
|
323
|
+
*/
|
|
324
|
+
const machine = createMachine({
|
|
325
|
+
props({ props }) {
|
|
326
|
+
return {
|
|
327
|
+
...stripUndefined(props),
|
|
328
|
+
defaultValue: props.defaultValue ?? "",
|
|
329
|
+
disabled: !!props.disabled,
|
|
330
|
+
readOnly: !!props.readOnly,
|
|
331
|
+
showActions: showActionsEnabled(props.showActions),
|
|
332
|
+
autoSize: !!props.autoSize,
|
|
333
|
+
rows: normalizeRows(props.rows),
|
|
334
|
+
clearLabel: props.clearLabel ?? "清除内容",
|
|
335
|
+
pasteLabel: props.pasteLabel ?? "粘贴并识别",
|
|
336
|
+
clearText: props.clearText ?? "一键清除",
|
|
337
|
+
pasteText: props.pasteText ?? "粘贴并识别"
|
|
338
|
+
};
|
|
339
|
+
},
|
|
340
|
+
initialState() {
|
|
341
|
+
return "idle";
|
|
342
|
+
},
|
|
343
|
+
context({ bindable, prop }) {
|
|
344
|
+
return {
|
|
345
|
+
uncontrolled: bindable(() => ({ defaultValue: prop("defaultValue") ?? "" })),
|
|
346
|
+
focused: bindable(() => ({ defaultValue: false })),
|
|
347
|
+
composing: bindable(() => ({ defaultValue: false })),
|
|
348
|
+
draft: bindable(() => ({ defaultValue: "" })),
|
|
349
|
+
controlDisabled: bindable(() => ({ defaultValue: false }))
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
computed: {
|
|
353
|
+
charCount({ context, prop }) {
|
|
354
|
+
if (context.get("composing")) return context.get("draft").length;
|
|
355
|
+
const controlled = prop("value");
|
|
356
|
+
return (controlled !== void 0 ? controlled : context.get("uncontrolled")).length;
|
|
357
|
+
},
|
|
358
|
+
hasMaxLength({ prop }) {
|
|
359
|
+
return positiveInt(prop("maxLength")) !== void 0;
|
|
360
|
+
},
|
|
361
|
+
showClear({ context, prop }) {
|
|
362
|
+
const controlled = prop("value");
|
|
363
|
+
return (controlled !== void 0 ? controlled : context.get("uncontrolled")).length > 0 && !prop("disabled") && !prop("readOnly") && !context.get("controlDisabled");
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
states: { idle: {} },
|
|
367
|
+
implementations: { actions: { noop() {} } }
|
|
368
|
+
});
|
|
369
|
+
function describedByValue(service, counterId, hasMaxLength) {
|
|
370
|
+
const parts = [service.prop("describedBy"), hasMaxLength ? counterId : void 0].filter((item) => !!item);
|
|
371
|
+
return parts.length > 0 ? parts.join(" ") : void 0;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* connect:把 service 接成 prop-getter。适配层不在这里之外做接受与否的判断。
|
|
375
|
+
*/
|
|
376
|
+
function connect(service, normalizeProps) {
|
|
377
|
+
sessionOf(service);
|
|
378
|
+
const { context, computed, prop } = service;
|
|
379
|
+
const value = readCommitted(service);
|
|
380
|
+
const composing = !!context.get("composing");
|
|
381
|
+
const displayValue = composing ? context.get("draft") : value;
|
|
382
|
+
const focused = !!context.get("focused");
|
|
383
|
+
const charCount = computed("charCount");
|
|
384
|
+
const hasMaxLength = !!computed("hasMaxLength");
|
|
385
|
+
const showClear = !!computed("showClear");
|
|
386
|
+
const disabled = !!prop("disabled");
|
|
387
|
+
const readOnly = !!prop("readOnly");
|
|
388
|
+
const controlDisabled = !!context.get("controlDisabled");
|
|
389
|
+
const blocked = disabled || readOnly || controlDisabled;
|
|
390
|
+
const showActions = showActionsEnabled(prop("showActions"));
|
|
391
|
+
const autoSize = !!prop("autoSize");
|
|
392
|
+
const limit = positiveInt(prop("maxLength"));
|
|
393
|
+
const minLength = positiveInt(prop("minLength"));
|
|
394
|
+
const rows = normalizeRows(prop("rows"));
|
|
395
|
+
const rowCap = autoSize ? effectiveRowCap(rows, prop("maxRows")) : void 0;
|
|
396
|
+
const id = prop("id") ?? "";
|
|
397
|
+
const fieldId = `textarea:${id}:field`;
|
|
398
|
+
const counterId = `textarea:${id}:counter`;
|
|
399
|
+
const describedBy = describedByValue(service, counterId, hasMaxLength);
|
|
400
|
+
const isEmpty = value.length === 0;
|
|
401
|
+
return {
|
|
402
|
+
value,
|
|
403
|
+
displayValue,
|
|
404
|
+
focused,
|
|
405
|
+
composing,
|
|
406
|
+
charCount,
|
|
407
|
+
hasMaxLength,
|
|
408
|
+
showClear,
|
|
409
|
+
limit,
|
|
410
|
+
showActions,
|
|
411
|
+
clearText: prop("clearText") ?? "一键清除",
|
|
412
|
+
pasteText: prop("pasteText") ?? "粘贴并识别",
|
|
413
|
+
fieldId,
|
|
414
|
+
counterId,
|
|
415
|
+
project() {
|
|
416
|
+
project(service);
|
|
417
|
+
},
|
|
418
|
+
getPlatformSink() {
|
|
419
|
+
return sinkFor(service);
|
|
420
|
+
},
|
|
421
|
+
clear() {
|
|
422
|
+
clearValue(service);
|
|
423
|
+
},
|
|
424
|
+
pasteRecognize(explicit) {
|
|
425
|
+
pasteRecognize(service, explicit);
|
|
426
|
+
},
|
|
427
|
+
getRootProps() {
|
|
428
|
+
return normalizeProps.element(compact({
|
|
429
|
+
"data-scope": "textarea",
|
|
430
|
+
"data-part": "root",
|
|
431
|
+
"data-focused": focused ? "true" : void 0,
|
|
432
|
+
"data-disabled": disabled || controlDisabled ? "true" : void 0,
|
|
433
|
+
"data-readonly": readOnly ? "true" : void 0,
|
|
434
|
+
"data-show-actions": showActions ? "true" : "false",
|
|
435
|
+
"data-auto-size": autoSize ? "true" : void 0,
|
|
436
|
+
"data-max-rows": rowCap !== void 0 ? String(rowCap) : void 0,
|
|
437
|
+
"data-empty": isEmpty ? "true" : "false"
|
|
438
|
+
}));
|
|
439
|
+
},
|
|
440
|
+
getTextareaProps() {
|
|
441
|
+
return normalizeProps.textarea(compact({
|
|
442
|
+
id: fieldId,
|
|
443
|
+
"data-scope": "textarea",
|
|
444
|
+
"data-part": "textarea",
|
|
445
|
+
placeholder: prop("placeholder"),
|
|
446
|
+
disabled: disabled ? true : void 0,
|
|
447
|
+
readOnly: readOnly ? true : void 0,
|
|
448
|
+
required: prop("required") ? true : void 0,
|
|
449
|
+
maxLength: limit,
|
|
450
|
+
minLength,
|
|
451
|
+
rows,
|
|
452
|
+
name: prop("name"),
|
|
453
|
+
form: prop("form"),
|
|
454
|
+
"aria-label": prop("accessibleLabel"),
|
|
455
|
+
"aria-labelledby": prop("labelledBy"),
|
|
456
|
+
"aria-describedby": describedBy,
|
|
457
|
+
"aria-invalid": prop("invalid") ? "true" : void 0,
|
|
458
|
+
"aria-errormessage": prop("errorId"),
|
|
459
|
+
"aria-disabled": disabled ? "true" : void 0,
|
|
460
|
+
"aria-readonly": readOnly ? "true" : void 0
|
|
461
|
+
}));
|
|
462
|
+
},
|
|
463
|
+
getBottomBarProps() {
|
|
464
|
+
return normalizeProps.element(compact({
|
|
465
|
+
"data-scope": "textarea",
|
|
466
|
+
"data-part": "bottom-bar",
|
|
467
|
+
"data-show-actions": showActions ? "true" : "false"
|
|
468
|
+
}));
|
|
469
|
+
},
|
|
470
|
+
getCounterProps() {
|
|
471
|
+
return normalizeProps.element(compact({
|
|
472
|
+
id: counterId,
|
|
473
|
+
"data-scope": "textarea",
|
|
474
|
+
"data-part": "counter",
|
|
475
|
+
"data-has-max-length": hasMaxLength ? "true" : void 0,
|
|
476
|
+
"aria-live": "polite"
|
|
477
|
+
}));
|
|
478
|
+
},
|
|
479
|
+
getClearButtonProps() {
|
|
480
|
+
return normalizeProps.button(compact({
|
|
481
|
+
"data-scope": "textarea",
|
|
482
|
+
"data-part": "clear-button",
|
|
483
|
+
type: "button",
|
|
484
|
+
disabled: !showClear || blocked ? true : void 0,
|
|
485
|
+
"aria-label": prop("clearLabel") ?? "清除内容",
|
|
486
|
+
onClick() {
|
|
487
|
+
clearValue(service);
|
|
488
|
+
}
|
|
489
|
+
}));
|
|
490
|
+
},
|
|
491
|
+
getPasteButtonProps() {
|
|
492
|
+
return normalizeProps.button(compact({
|
|
493
|
+
"data-scope": "textarea",
|
|
494
|
+
"data-part": "paste-button",
|
|
495
|
+
type: "button",
|
|
496
|
+
disabled: blocked ? true : void 0,
|
|
497
|
+
"aria-label": prop("pasteLabel") ?? "粘贴并识别",
|
|
498
|
+
onClick() {
|
|
499
|
+
pasteRecognize(service);
|
|
500
|
+
}
|
|
501
|
+
}));
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* 把 QwTextAreaProps 转成 machine props(默认值收口)。
|
|
507
|
+
* 缺省文案是 zh-CN;适配层传入的 locale 优先。
|
|
508
|
+
*/
|
|
509
|
+
function createTextAreaProps(props = {}) {
|
|
510
|
+
return {
|
|
511
|
+
...stripUndefined(props),
|
|
512
|
+
defaultValue: props.defaultValue ?? "",
|
|
513
|
+
disabled: props.disabled ?? false,
|
|
514
|
+
readOnly: props.readOnly ?? false,
|
|
515
|
+
showActions: showActionsEnabled(props.showActions),
|
|
516
|
+
autoSize: props.autoSize ?? false,
|
|
517
|
+
rows: normalizeRows(props.rows),
|
|
518
|
+
clearLabel: props.clearLabel ?? "清除内容",
|
|
519
|
+
pasteLabel: props.pasteLabel ?? "粘贴并识别",
|
|
520
|
+
clearText: props.clearText ?? "一键清除",
|
|
521
|
+
pasteText: props.pasteText ?? "粘贴并识别"
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region src/textarea/platform.ts
|
|
526
|
+
/** 平台拒绝。`stale` 只由 Core 在 ticket 过期时产生。 */
|
|
527
|
+
var TextAreaClipboardReadError = class extends Error {
|
|
528
|
+
reason;
|
|
529
|
+
constructor(reason) {
|
|
530
|
+
super(reason);
|
|
531
|
+
this.name = "TextAreaClipboardReadError";
|
|
532
|
+
this.reason = reason;
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
function controlDisabled(target) {
|
|
536
|
+
return target.matches(":disabled");
|
|
537
|
+
}
|
|
538
|
+
function px(value) {
|
|
539
|
+
const parsed = Number.parseFloat(value);
|
|
540
|
+
return Number.isFinite(parsed) ? parsed : NaN;
|
|
541
|
+
}
|
|
542
|
+
function clipboardReason(error) {
|
|
543
|
+
return (error && typeof error === "object" && "name" in error ? String(error.name) : "") === "AbortError" ? "aborted" : "denied";
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* 只做 ref 之后的监听、测量和写回。不判断接受、截断或组合。
|
|
547
|
+
* 调用方在 target 与 sink 都可用之后再进入这里。
|
|
548
|
+
*/
|
|
549
|
+
function attachTextAreaPlatform(target, getSink, host) {
|
|
550
|
+
const sink = getSink();
|
|
551
|
+
const view = target.ownerDocument.defaultView ?? globalThis;
|
|
552
|
+
let disposed = false;
|
|
553
|
+
let form = null;
|
|
554
|
+
let lastInline = target.getBoundingClientRect().width;
|
|
555
|
+
let ignoreOwnResize = false;
|
|
556
|
+
let ignoreToken = 0;
|
|
557
|
+
let callerCaptured = false;
|
|
558
|
+
let callerHeight = "";
|
|
559
|
+
let callerPriority = "";
|
|
560
|
+
let wroteNumber = false;
|
|
561
|
+
let lastWritten;
|
|
562
|
+
let wasIntersecting = target.getClientRects().length > 0;
|
|
563
|
+
const armIgnore = () => {
|
|
564
|
+
ignoreOwnResize = true;
|
|
565
|
+
const token = ++ignoreToken;
|
|
566
|
+
view.requestAnimationFrame?.(() => {
|
|
567
|
+
if (!disposed && token === ignoreToken) ignoreOwnResize = false;
|
|
568
|
+
});
|
|
569
|
+
};
|
|
570
|
+
const notify = () => {
|
|
571
|
+
if (!disposed) sink.changed();
|
|
572
|
+
};
|
|
573
|
+
const client = {
|
|
574
|
+
readControl: () => ({
|
|
575
|
+
value: target.value,
|
|
576
|
+
disabled: controlDisabled(target)
|
|
577
|
+
}),
|
|
578
|
+
measureIntrinsic() {
|
|
579
|
+
const previous = target.style.getPropertyValue("height");
|
|
580
|
+
const priority = target.style.getPropertyPriority("height");
|
|
581
|
+
armIgnore();
|
|
582
|
+
target.style.setProperty("height", "auto");
|
|
583
|
+
try {
|
|
584
|
+
const style = view.getComputedStyle(target);
|
|
585
|
+
const rect = target.getBoundingClientRect();
|
|
586
|
+
return {
|
|
587
|
+
scrollHeight: target.scrollHeight,
|
|
588
|
+
inlineSize: rect.width,
|
|
589
|
+
lineHeight: px(style.lineHeight),
|
|
590
|
+
paddingBlockSize: px(style.paddingTop) + px(style.paddingBottom),
|
|
591
|
+
borderBlockSize: px(style.borderTopWidth) + px(style.borderBottomWidth),
|
|
592
|
+
boxSizing: style.boxSizing === "border-box" ? "border-box" : "content-box",
|
|
593
|
+
visible: style.display !== "none" && rect.width > 0 && rect.height > 0
|
|
594
|
+
};
|
|
595
|
+
} finally {
|
|
596
|
+
if (previous) target.style.setProperty("height", previous, priority);
|
|
597
|
+
else target.style.removeProperty("height");
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
writeValue(value, defaultValue) {
|
|
601
|
+
target.defaultValue = defaultValue;
|
|
602
|
+
host?.trackValue?.(target, value);
|
|
603
|
+
if (target.value !== value) target.value = value;
|
|
604
|
+
},
|
|
605
|
+
writeHeight(height) {
|
|
606
|
+
if (typeof height === "number" && Number.isFinite(height)) {
|
|
607
|
+
if (wroteNumber && lastWritten === height) return;
|
|
608
|
+
if (!callerCaptured) {
|
|
609
|
+
callerHeight = target.style.getPropertyValue("height");
|
|
610
|
+
callerPriority = target.style.getPropertyPriority("height");
|
|
611
|
+
callerCaptured = true;
|
|
612
|
+
}
|
|
613
|
+
armIgnore();
|
|
614
|
+
target.style.setProperty("height", `${height}px`);
|
|
615
|
+
lastWritten = height;
|
|
616
|
+
wroteNumber = true;
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
if (!wroteNumber) return;
|
|
620
|
+
armIgnore();
|
|
621
|
+
if (callerHeight) target.style.setProperty("height", callerHeight, callerPriority);
|
|
622
|
+
else target.style.removeProperty("height");
|
|
623
|
+
callerCaptured = false;
|
|
624
|
+
wroteNumber = false;
|
|
625
|
+
lastWritten = void 0;
|
|
626
|
+
},
|
|
627
|
+
focus() {
|
|
628
|
+
target.focus();
|
|
629
|
+
},
|
|
630
|
+
blur() {
|
|
631
|
+
target.blur();
|
|
632
|
+
},
|
|
633
|
+
readClipboardText() {
|
|
634
|
+
const clipboard = view.navigator?.clipboard;
|
|
635
|
+
const readText = clipboard?.readText;
|
|
636
|
+
if (!clipboard || typeof readText !== "function") return Promise.reject(new TextAreaClipboardReadError("unsupported"));
|
|
637
|
+
return Promise.resolve().then(() => readText.call(clipboard)).then((text) => {
|
|
638
|
+
if (typeof text !== "string") throw new TextAreaClipboardReadError("denied");
|
|
639
|
+
return text;
|
|
640
|
+
}).catch((error) => {
|
|
641
|
+
if (error instanceof TextAreaClipboardReadError) throw error;
|
|
642
|
+
throw new TextAreaClipboardReadError(clipboardReason(error));
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
const onReset = (event) => {
|
|
647
|
+
const notice = event;
|
|
648
|
+
queueMicrotask(() => {
|
|
649
|
+
if (!disposed) sink.reset({ defaultPrevented: notice.defaultPrevented });
|
|
650
|
+
});
|
|
651
|
+
};
|
|
652
|
+
const syncForm = () => {
|
|
653
|
+
const next = target.form;
|
|
654
|
+
if (next === form) return;
|
|
655
|
+
form?.removeEventListener("reset", onReset);
|
|
656
|
+
form = next;
|
|
657
|
+
form?.addEventListener("reset", onReset);
|
|
658
|
+
};
|
|
659
|
+
const tree = new view.MutationObserver(() => {
|
|
660
|
+
syncForm();
|
|
661
|
+
watchTree();
|
|
662
|
+
queueMicrotask(() => {
|
|
663
|
+
if (disposed) return;
|
|
664
|
+
syncForm();
|
|
665
|
+
watchTree();
|
|
666
|
+
});
|
|
667
|
+
});
|
|
668
|
+
const fields = new view.MutationObserver(() => {
|
|
669
|
+
syncForm();
|
|
670
|
+
notify();
|
|
671
|
+
});
|
|
672
|
+
const formOwner = new view.MutationObserver(() => syncForm());
|
|
673
|
+
const watchTree = () => {
|
|
674
|
+
tree.disconnect();
|
|
675
|
+
fields.disconnect();
|
|
676
|
+
formOwner.disconnect();
|
|
677
|
+
const parent = target.parentElement;
|
|
678
|
+
if (parent) tree.observe(parent, { childList: true });
|
|
679
|
+
let node = target.parentElement;
|
|
680
|
+
while (node) {
|
|
681
|
+
if (node.tagName === "FIELDSET" || node.tagName === "FORM") fields.observe(node, {
|
|
682
|
+
attributes: true,
|
|
683
|
+
attributeFilter: ["disabled"]
|
|
684
|
+
});
|
|
685
|
+
node = node.parentElement;
|
|
686
|
+
}
|
|
687
|
+
const root = target.getRootNode();
|
|
688
|
+
const scope = root === target.ownerDocument ? target.ownerDocument.documentElement : root;
|
|
689
|
+
if (scope) formOwner.observe(scope, {
|
|
690
|
+
subtree: true,
|
|
691
|
+
attributes: true,
|
|
692
|
+
attributeFilter: ["id"]
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
const formAttribute = new view.MutationObserver(() => syncForm());
|
|
696
|
+
formAttribute.observe(target, {
|
|
697
|
+
attributes: true,
|
|
698
|
+
attributeFilter: ["form"]
|
|
699
|
+
});
|
|
700
|
+
syncForm();
|
|
701
|
+
watchTree();
|
|
702
|
+
const editTypes = {
|
|
703
|
+
input: "input",
|
|
704
|
+
compositionstart: "composition-start",
|
|
705
|
+
compositionupdate: "composition-update",
|
|
706
|
+
compositionend: "composition-end"
|
|
707
|
+
};
|
|
708
|
+
const onEdit = (event) => {
|
|
709
|
+
syncForm();
|
|
710
|
+
if (!disposed) sink.edit({
|
|
711
|
+
type: editTypes[event.type],
|
|
712
|
+
value: target.value
|
|
713
|
+
});
|
|
714
|
+
};
|
|
715
|
+
const listeners = {
|
|
716
|
+
input: onEdit,
|
|
717
|
+
compositionstart: onEdit,
|
|
718
|
+
compositionupdate: onEdit,
|
|
719
|
+
compositionend: onEdit,
|
|
720
|
+
focus: () => {
|
|
721
|
+
if (!disposed) sink.focusChanged(true);
|
|
722
|
+
},
|
|
723
|
+
blur: () => {
|
|
724
|
+
if (!disposed) sink.focusChanged(false);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
for (const [name, listener] of Object.entries(listeners)) target.addEventListener(name, listener);
|
|
728
|
+
let resize;
|
|
729
|
+
let intersect;
|
|
730
|
+
if (typeof view.ResizeObserver === "function") {
|
|
731
|
+
resize = new view.ResizeObserver((entries) => {
|
|
732
|
+
const width = entries[0]?.contentRect?.width;
|
|
733
|
+
const widthChanged = typeof width === "number" && width !== lastInline;
|
|
734
|
+
if (typeof width === "number") lastInline = width;
|
|
735
|
+
if (ignoreOwnResize) {
|
|
736
|
+
ignoreOwnResize = false;
|
|
737
|
+
if (!widthChanged) return;
|
|
738
|
+
}
|
|
739
|
+
notify();
|
|
740
|
+
});
|
|
741
|
+
resize.observe(target);
|
|
742
|
+
}
|
|
743
|
+
if (typeof view.IntersectionObserver === "function") {
|
|
744
|
+
intersect = new view.IntersectionObserver((entries) => {
|
|
745
|
+
const intersecting = entries.some((entry) => entry.isIntersecting);
|
|
746
|
+
if (intersecting === wasIntersecting) return;
|
|
747
|
+
wasIntersecting = intersecting;
|
|
748
|
+
notify();
|
|
749
|
+
});
|
|
750
|
+
intersect.observe(target);
|
|
751
|
+
}
|
|
752
|
+
const fonts = target.ownerDocument.fonts;
|
|
753
|
+
const onFonts = () => notify();
|
|
754
|
+
if (fonts && typeof fonts.addEventListener === "function") fonts.addEventListener("loadingdone", onFonts);
|
|
755
|
+
if (fonts?.ready) fonts.ready.then(onFonts);
|
|
756
|
+
sink.commit(client);
|
|
757
|
+
return () => {
|
|
758
|
+
disposed = true;
|
|
759
|
+
for (const [name, listener] of Object.entries(listeners)) target.removeEventListener(name, listener);
|
|
760
|
+
form?.removeEventListener("reset", onReset);
|
|
761
|
+
form = null;
|
|
762
|
+
formAttribute.disconnect();
|
|
763
|
+
tree.disconnect();
|
|
764
|
+
fields.disconnect();
|
|
765
|
+
formOwner.disconnect();
|
|
766
|
+
resize?.disconnect();
|
|
767
|
+
intersect?.disconnect();
|
|
768
|
+
if (fonts && typeof fonts.removeEventListener === "function") fonts.removeEventListener("loadingdone", onFonts);
|
|
769
|
+
sink.detach();
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
//#endregion
|
|
773
|
+
export { connect as a, computeTextAreaHeight as i, attachTextAreaPlatform as n, createTextAreaProps as o, clampUtf16 as r, machine as s, TextAreaClipboardReadError as t };
|
|
774
|
+
|
|
775
|
+
//# sourceMappingURL=textarea-qbnruDUG.js.map
|