@code-id-labs/components 1.0.0 → 1.0.1
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/dist/behaviors/app.js +1 -1
- package/dist/behaviors/form.js +1 -1
- package/dist/runtime/action-sheet/index.js +1 -1
- package/dist/runtime/action-sheet/index.wxml +1 -1
- package/dist/runtime/app/index.js +1 -1
- package/dist/runtime/checkbox-group/index.js +1 -1
- package/dist/runtime/checkbox-group/index.wxml +1 -1
- package/dist/runtime/drawer/index.js +1 -1
- package/dist/runtime/drawer/index.wxml +1 -1
- package/dist/runtime/file-upload/index.js +1 -1
- package/dist/runtime/file-upload/index.wxml +1 -1
- package/dist/runtime/form/index.js +1 -1
- package/dist/runtime/form-field/index.js +1 -1
- package/dist/runtime/input/index.js +1 -1
- package/dist/runtime/input-menu/index.js +1 -1
- package/dist/runtime/input-menu/index.wxml +1 -1
- package/dist/runtime/modal/index.js +1 -1
- package/dist/runtime/modal/index.wxml +1 -1
- package/dist/runtime/pin-input/index.js +1 -1
- package/dist/runtime/popover/index.js +1 -1
- package/dist/runtime/popover/index.wxml +1 -1
- package/dist/runtime/pull-down-refresh/index.js +1 -1
- package/dist/runtime/radio-group/index.js +1 -1
- package/dist/runtime/radio-group/index.wxml +1 -1
- package/dist/runtime/select/index.js +1 -1
- package/dist/runtime/slider/index.js +1 -1
- package/dist/runtime/swipe-cell/index.js +1 -1
- package/dist/runtime/switch/index.js +1 -1
- package/dist/runtime/tabs-item/index.js +1 -1
- package/dist/runtime/tabs-item/index.wxml +1 -1
- package/dist/runtime/textarea/index.js +1 -1
- package/dist/runtime/toast/index.js +1 -1
- package/dist/wxs/slider-gesture.wxs +1 -1
- package/package.json +23 -18
package/dist/behaviors/app.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../alien-signals.js"),t=require("../weapp-vendors/miniapp-machine.js");function n(e){return typeof Behavior<`u`?Behavior(e):{}}function r(e){return e}function i(e){if(e)try{if(typeof e.getPageId==`function`){let t=e.getPageId();if(t!=null&&t!==``)return String(t)}if(e.__wxWebviewId__!==void 0&&e.__wxWebviewId__!==null&&String(e.__wxWebviewId__)!==``)return String(e.__wxWebviewId__);if(typeof e.__page__?.getPageId==`function`){let t=e.__page__.getPageId();if(t!=null&&t!==``)return String(t)}if(typeof e.$page?.getPageId==`function`){let t=e.$page.getPageId();if(t!=null&&t!==``)return String(t)}}catch{}}var a=`*`,o=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{};o.__CODE_UI_APP_REGISTRY__||(o.__CODE_UI_APP_REGISTRY__={hosts:[],hostByInstance:new WeakMap,pageSignals:new WeakMap,pending:new Map,orderCounter:0});var s=o.__CODE_UI_APP_REGISTRY__,c=s.hosts,l=s.hostByInstance,u=s.pageSignals,d=s.pending;function f(e,t){if(!e||!t)return;t.__cuiAppParent=e,e.__cuiAppChildren||(e.__cuiAppChildren=new Set),e.__cuiAppChildren.add(t);let n=l.get(e);if(n){let e=!1;t.__cuiScaled&&t.__cuiScaleId&&(n.scales.has(t.__cuiScaleId)||(n.scales.set(t.__cuiScaleId,{id:t.__cuiScaleId,factor:t.__cuiScaleFactor,background:t.__cuiScaleBackground}),e=!0));let r=t.__cuiRegisteredSize??0,i=t.__cuiRegisteredBannerSize??0,a=r>0?r:i>0?i:0,o=t.__cuiInsetId??t.__cuiBannerInsetId;a>0&&o&&(n.insets.set(o,{id:o,edge:t.__cuiInsetEdge??t.__cuiRegisteredBannerEdge??`top`,size:a}),e=!0),E(n),e&&A(n)}}function p(e,t){if(!t)return;t.__cuiAppParent===e&&(t.__cuiAppParent=void 0),e&&e.__cuiAppChildren&&e.__cuiAppChildren.delete(t);let n=e?l.get(e):C(t);if(n){let e=!1;t.__cuiScaleId&&n.scales.delete(t.__cuiScaleId)&&(e=!0);let r=t.__cuiInsetId??t.__cuiBannerInsetId;r&&n.insets.delete(r)&&(e=!0),e&&A(n)}}var m=n({}),h=n({relations:{cuiAppParent:{type:`ancestor`,target:m,linked(e){f(e,this)},unlinked(e){p(e,this)}}}});function g(e,t,n){t===`parent`?e.cuiAppChild=r({type:`descendant`,target:h,linked(e){f(this,e),n?.linked?.(e)},unlinked(e){p(this,e),n?.unlinked?.(e)}}):e.cuiAppParent=r({type:`ancestor`,target:m,linked(e){f(e,this),n?.linked?.(e)},unlinked(e){p(e,this),n?.unlinked?.(e)}})}function _(t){let n=u.get(t);return n||(n={insets:e.signal({top:0,bottom:0}),scale:e.signal({scaled:!1,factor:1})},u.set(t,n)),n}function v(e){if(!e)return;let t=i(e);if(t!==void 0)return t;let n=e.pageId;return n!=null&&n!==``?String(n):void 0}function y(e){if(e)try{let t=e;for(let e=0;t&&e<=10;e++){let e=v(t);if(e!==void 0)return e;t=typeof t.selectOwnerComponent==`function`?t.selectOwnerComponent():null}}catch{}}function b(){if(typeof getCurrentPages==`function`)try{let e=getCurrentPages(),t=e[e.length-1];return y(t)}catch{return}}function x(e){for(let t=c.length-1;t>=0;t--){let n=c[t];if(n&&n.pageId===e)return n}}function S(){let e=b();if(e){let t=x(e);if(t)return t}let t;for(let e of c)e.visible&&(!t||e.order>t.order)&&(t=e);return t??c[c.length-1]}function C(e){if(e){let t=l.get(e);if(t)return t;if(e.__cuiAppParent){let t=l.get(e.__cuiAppParent);if(t)return t}if(typeof e.getRelationNodes==`function`)try{let t=e.getRelationNodes(`cuiAppParent`);if((!t||t.length===0)&&m&&(t=e.getRelationNodes(m)),t&&t.length>0&&t[0]){let e=l.get(t[0]);if(e)return e}}catch{}let n=y(e);if(n){let e=x(n);if(e)return e}}return S()}function w(e){return e&&y(e)||a}function T(e,t){let n=C(e);if(n){t(n);return}let r=w(e),i=d.get(r);i?i.push(t):d.set(r,[t])}function E(e){let t=[e.pageId,a];for(let n of t){let t=d.get(n);if(t){d.delete(n);for(let n of t)n(e)}}}function D(e){let t=0,n=0;return e.insets.forEach(e=>{let r=Number.isFinite(e.size)?Math.max(0,e.size):0;e.edge===`bottom`?n+=r:t+=r}),{top:t,bottom:n}}function O(e){if(e.scales.size===0)return{scaled:!1,factor:1};let t;return e.scales.forEach(e=>{t=e}),{scaled:!0,factor:t?.factor??.94,background:t?.background}}function k(e){return{insets:D(e),scale:O(e)}}function A(e){let t=k(e);e.signals.insets(t.insets),e.signals.scale(t.scale),e.adapter?.onChange?.(t)}function j(e,t){if(l.has(e))return;let n=_(e),r={instance:e,pageId:y(e)??`cui-app-${s.orderCounter+1}`,adapter:t,signals:n,insets:new Map,scales:new Map,visible:!0,order:++s.orderCounter};if(c.push(r),l.set(e,r),e.__cuiAppChildren)for(let t of e.__cuiAppChildren){t.__cuiScaled&&t.__cuiScaleId&&r.scales.set(t.__cuiScaleId,{id:t.__cuiScaleId,factor:t.__cuiScaleFactor,background:t.__cuiScaleBackground});let e=t.__cuiRegisteredSize??0,n=t.__cuiRegisteredBannerSize??0,i=e>0?e:n>0?n:0,a=t.__cuiInsetId??t.__cuiBannerInsetId;i>0&&a&&r.insets.set(a,{id:a,edge:t.__cuiInsetEdge??t.__cuiRegisteredBannerEdge??`top`,size:i})}E(r),A(r)}function M(e){let t=l.get(e);if(!t)return;l.delete(e);let n=c.indexOf(t);if(n!==-1&&c.splice(n,1),t.insets.clear(),t.scales.clear(),e.__cuiAppChildren){for(let t of e.__cuiAppChildren)t.__cuiAppParent===e&&(t.__cuiAppParent=void 0);e.__cuiAppChildren.clear()}}function N(e,t){let n=l.get(e);n&&(n.visible=t,t&&(n.order=++s.orderCounter))}function P(e,t){T(e,e=>{e.scales.set(t.id,{...t}),A(e)})}function F(e,t){let n=C(e);if(!n){let n=w(e),r=d.get(n);r&&r.push(e=>{e.scales.delete(t)&&A(e)});return}n.scales.delete(t)&&A(n)}function I(e){let t=C(e);t&&t.instance?.startScaleGesture?.()}function L(e,t){let n=C(e);n&&n.instance?.applyScaleProgress?.(t)}function R(e,t){let n=C(e);n&&n.instance?.endScaleGesture?.(t)}function z(e){let t=e;t.__cuiScaleDragging=!0,t.data?.shouldScaleBackground&&I(t)}function B(e,t){let n=e;n.data?.shouldScaleBackground&&n.__cuiScaleDragging&&(n.__cuiScaleDragOffset=t,n.__cuiScaleDragRafPending||(n.__cuiScaleDragRafPending=!0,(typeof wx<`u`&&typeof wx.nextTick==`function`?wx.nextTick:e=>e())(()=>{if(n.__cuiScaleDragRafPending=!1,n.__cuiScaleDragging){let e=Math.max((n.data?.threshold||80)*1.5,120),t=Math.min(1,Math.max(0,(n.__cuiScaleDragOffset??0)/e));L(n,t)}})))}function V(e,t){let n=e;n.__cuiScaleDragging=!1,n.__cuiScaleDragRafPending=!1,n.data?.shouldScaleBackground&&R(n,t)}function H(e,t){T(e,e=>{let n=e.insets.get(t.id);n&&n.edge===t.edge&&n.size===t.size||(e.insets.set(t.id,{...t}),A(e))})}function U(e,t){T(e,e=>{e.insets.delete(t)&&A(e)})}function W(e={}){let t=0,r=(e,t,n)=>{let r=e.data,i=t.service?.state,a=n===`open`&&!!r?.open,o=!a&&(i?.matches?.(`closed`)||i?.matches?.(`closing`)||i?.hasTag?.(`closing`))||n===`open`&&!r?.open,s=!!r?.shouldScaleBackground&&!o&&!!(a||i?.hasTag?.(`open`)||i?.matches?.(`open`)||i?.matches?.(`dragging`)),c=e.__cuiScaleId??``;c&&(s===!!e.__cuiScaled?s&&n&&(e.__cuiScaleFactor=r?.scaleFactor,e.__cuiScaleBackground=r?.scaleBackground,P(e,{id:c,factor:r?.scaleFactor,background:r?.scaleBackground})):(e.__cuiScaled=s,e.__cuiScaleFactor=r?.scaleFactor,e.__cuiScaleBackground=r?.scaleBackground,s?P(e,{id:c,factor:r?.scaleFactor,background:r?.scaleBackground}):F(e,c)))};return{name:`scale-background`,behaviors:[h,n({observers:{"shouldScaleBackground, scaleFactor, scaleBackground"(){this.__codeUiMachine&&r(this,this.__codeUiMachine,`scale`)}}})],setupRelations(e){g(e,`child`)},onAttached(n){let r=n;r.__cuiScaleId=`${e.idPrefix??`scale`}:${++t}`,r.__cuiScaled=!1},onMachineStarted(e,t){let n=e,i=()=>r(n,t);n.__cuiScaleUnsub=t.subscribe(i),i()},onPropChanged(e,t){let n=e;(t===`shouldScaleBackground`||t===`scaleFactor`||t===`scaleBackground`||t===`open`)&&n.__codeUiMachine&&r(n,n.__codeUiMachine,t)},onDetached(e){let t=e;t.__cuiScaleDragging&&(t.__cuiScaleDragging=!1,t.__cuiScaleDragRafPending=!1,t.data?.shouldScaleBackground&&R(t,!1)),t.__cuiScaleUnsub?.(),t.__cuiScaled&&t.__cuiScaleId&&(F(t,t.__cuiScaleId),t.__cuiScaled=!1)}}}function G(e={}){let r=0,i=(e,t)=>{let n=e.data,r=t.service?.state,i=!(r?.matches?.(`closed`)||r?.matches?.(`closing`)||r?.matches?.(`dismissing`)||r?.hasTag?.(`closed`)||r?.hasTag?.(`dismissing`)||n?.open===!1)&&(!!n?.open||r?.hasTag?.(`open`)||r?.matches?.(`open`)),a=n?.autoInset!==!1,o=n?.mode||(n?.placement===`inline`?`inline`:`fixed`),s=n?.placement===`bottom`?`bottom`:`top`,c=e.__cuiBannerInsetId??``;if(!i||!a||o===`inline`){e.__cuiBannerHeight=0,e.__cuiMeasureRetryTimer&&(clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=null),(e.__cuiRegisteredBannerSize??0)>0&&c&&(U(e,c),e.__cuiRegisteredBannerSize=0,e.__cuiRegisteredBannerEdge=void 0,e.__cuiRegisteredSize=0,e.__cuiInsetEdge=void 0);return}let l=Number(e.__cuiBannerHeight||0);if(l<=0&&Number(e.__cuiLastKnownHeight||0)>0&&(l=Number(e.__cuiLastKnownHeight),e.__cuiBannerHeight=l),l<=0){(e.__cuiRegisteredBannerSize??0)>0&&c&&(U(e,c),e.__cuiRegisteredBannerSize=0,e.__cuiRegisteredBannerEdge=void 0,e.__cuiRegisteredSize=0,e.__cuiInsetEdge=void 0);return}(e.__cuiRegisteredBannerEdge!==s||e.__cuiRegisteredBannerSize!==l)&&(e.__cuiRegisteredBannerSize??0)>0&&c&&U(e,c),e.__cuiRegisteredBannerEdge=s,e.__cuiRegisteredBannerSize=l,e.__cuiInsetId=c,e.__cuiInsetEdge=s,e.__cuiRegisteredSize=l,c&&H(e,{id:c,edge:s,size:l})},a=(e,n=0)=>{(typeof e?.createSelectorQuery==`function`||t.isMiniApp())&&t.queryRect(`.cui-banner-root`,e).then(t=>{let r=e.data,o=e.__codeUiMachine?.service?.state,s=!(o?.matches?.(`closed`)||o?.matches?.(`closing`)||o?.matches?.(`dismissing`)||o?.hasTag?.(`closed`)||o?.hasTag?.(`dismissing`)||r?.open===!1)&&(!!r?.open||o?.hasTag?.(`open`)||o?.matches?.(`open`));if(!t||typeof t.height!=`number`||t.height<=0){s&&n<5&&(e.__cuiMeasureRetryTimer&&clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=setTimeout(()=>{e.__cuiMeasureRetryTimer=null,a(e,n+1)},30*(n+1)));return}let c=Math.round(t.height);e.__cuiLastKnownHeight=c,(c!==e.__cuiBannerHeight||e.__cuiRegisteredBannerSize!==c)&&(e.__cuiBannerHeight=c,e.__codeUiMachine&&i(e,e.__codeUiMachine))}).catch(()=>{n<3&&(e.__cuiMeasureRetryTimer&&clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=setTimeout(()=>{e.__cuiMeasureRetryTimer=null,a(e,n+1)},40))})},o=e=>{if(e.__cuiMeasureRetryTimer&&(clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=null),e.__cuiBannerMeasureQueued){e.__cuiBannerMeasureNeedsRerun=!0;return}e.__cuiBannerMeasureQueued=!0,t.nextTick(()=>{e.__cuiBannerMeasureQueued=!1,a(e,0),e.__cuiBannerMeasureNeedsRerun&&(e.__cuiBannerMeasureNeedsRerun=!1,o(e))})};return{name:`banner-layout-inset`,behaviors:[h,n({observers:{"placement, mode, autoInset, size, title, description, caption, badge, actions, image, more, close"(){this.__cuiBannerInsetId&&(o(this),this.__codeUiMachine&&i(this,this.__codeUiMachine))}}})],setupRelations(e){g(e,`child`)},onAttached(t){let n=t;n.__cuiBannerInsetId=`${e.idPrefix??`banner`}:${++r}`,n.__cuiRegisteredBannerSize=0,n.__cuiRegisteredBannerEdge=void 0,n.__cuiBannerHeight=0,n.__cuiLastKnownHeight=0,n.__cuiBannerMeasureQueued=!1,n.__cuiBannerMeasureNeedsRerun=!1,n.__cuiMeasureRetryTimer=null},onMachineStarted(e,t){let n=e;n.__cuiBannerUnsub=t.subscribe(()=>{let e=t.service?.state;(e?.hasTag?.(`open`)||e?.matches?.(`open`))&&(Number(n.__cuiBannerHeight||0)<=0&&Number(n.__cuiLastKnownHeight||0)>0&&(n.__cuiBannerHeight=Number(n.__cuiLastKnownHeight)),o(n)),i(n,t)}),i(n,t)},onReady(e){o(e)},onPropChanged(e,t,n){let r=e;t===`open`&&(n?Number(r.__cuiLastKnownHeight||0)>0&&(r.__cuiBannerHeight=Number(r.__cuiLastKnownHeight),r.__codeUiMachine&&i(r,r.__codeUiMachine)):r.__codeUiMachine&&i(r,r.__codeUiMachine)),o(r),r.__codeUiMachine&&i(r,r.__codeUiMachine)},onDetached(e){let t=e;t.__cuiBannerUnsub?.(),t.__cuiBannerUnsub=void 0,t.__cuiBannerMeasureQueued=!1,t.__cuiBannerMeasureNeedsRerun=!1,t.__cuiMeasureRetryTimer&&(clearTimeout(t.__cuiMeasureRetryTimer),t.__cuiMeasureRetryTimer=null),(t.__cuiRegisteredBannerSize??0)>0&&t.__cuiBannerInsetId&&(U(t,t.__cuiBannerInsetId),t.__cuiRegisteredBannerSize=0,t.__cuiRegisteredBannerEdge=void 0,t.__cuiRegisteredSize=0,t.__cuiInsetEdge=void 0),t.__cuiBannerHeight=0}}}var K=32,q=4,J=null,Y=e.signal(X());function X(){let e={windowWidth:0,windowHeight:0,statusBarHeight:0,safeTop:0,safeBottom:0,menuTop:0,menuHeight:0,menuInset:0,navBarHeight:0,navHeight:0};if(typeof wx>`u`)return e;let t;try{t=typeof wx.getWindowInfo==`function`?wx.getWindowInfo():wx.getSystemInfoSync()}catch{return e}if(!t)return e;let n=t.windowWidth??0,r=t.windowHeight??0,i=t.screenHeight??r,a=t.statusBarHeight??0,o=t.safeArea,s=o?.top??a,c=o?Math.max(0,i-(o.bottom??i)):0,l;try{let e=typeof wx.getMenuButtonBoundingClientRect==`function`?wx.getMenuButtonBoundingClientRect():void 0;e&&e.height>0&&(l=e)}catch{}let u=l?.height??K,d=l?.top??a+q,f=l?Math.max(0,n-l.left):0,p=Math.max(0,d-a)*2+u;return{windowWidth:n,windowHeight:r,statusBarHeight:a,safeTop:s,safeBottom:c,menuTop:d,menuHeight:u,menuInset:f,navBarHeight:p,navHeight:a+p}}function Z(e=!1){return J&&!e?J:(J=X(),Y(J),J)}function Q(){return Z(!0)}function $(e){if(typeof getCurrentPages==`function`)try{let t=getCurrentPages(),n=t&&t[t.length-1];n&&(n.__cuiApp=e)}catch{}}function ee(e){let{detectBars:t,extractTopBarHeight:n,extractBottomBarHeight:r}=e;return Behavior({lifetimes:{attached(){this.__cuiAppAttached=!0,j(this,{onChange:e=>this.applyHostState?.(e)}),$(this)},detached(){this.__cuiAppAttached=!1,M(this)},ready(){this.detectCustomBars?.(),typeof wx<`u`&&typeof wx.nextTick==`function`&&wx.nextTick(()=>{this.__cuiAppAttached&&this.detectCustomBars?.()})}},pageLifetimes:{show(){$(this),N(this,!0),this.detectCustomBars?.()},hide(){N(this,!1)},resize(){Q(),this.detectCustomBars?.()}},methods:{noop(){},detectCustomBars(){if(this.data?.autoDetectBars&&typeof wx<`u`&&typeof wx.createSelectorQuery==`function`)try{let e=(e,t)=>{if(!this.__cuiAppAttached)return;let i={};if(e&&typeof e.height==`number`){let t=n(e);t!==this.data?.detectedTopBarHeight&&(i.detectedTopBarHeight=t)}if(t&&typeof t.height==`number`){let e=r(t);e!==this.data?.detectedBottomBarHeight&&(i.detectedBottomBarHeight=e)}Object.keys(i).length>0&&this.setData?.(i)};t(this,({topRect:t,bottomRect:n})=>{e(t,n)})}catch{}},startScaleGesture(){this._lastScaleProgress=void 0},applyScaleProgress(e){let t=this._lastScaleProgress??-1;if(Math.abs(e-t)<.008&&e>0&&e<1)return;this._lastScaleProgress=e;let n=this.data?.hostScaleFactor||this.data?.scaleFactor||.94,r=n+(1-n)*e,i=Math.round(16*(1-e)),a=Math.max(0,1-e);this.setData?.({gestureScaleStyle:`transform: scale(${Math.round(r*1e3)/1e3}) translateY(calc(var(--cui-top-offset) * ${Math.round(a*1e3)/1e3})); border-radius: ${i}px; transition: none !important;`})},endScaleGesture(e){this._lastScaleProgress=void 0;let t={gestureScaleStyle:``};e&&(t.scaled=!1),this.setData?.(t)},applyHostState(e){let t={};if(e.scale){let n=!!e.scale.scaled;n!==!!this.data?.scaled&&(t.scaled=n),e.scale.factor!==this.data?.hostScaleFactor&&(t.hostScaleFactor=e.scale.factor),e.scale.background!==this.data?.hostScaleBackground&&(t.hostScaleBackground=e.scale.background??``)}(e.insets.top!==this.data?.topInset||e.insets.bottom!==this.data?.bottomInset)&&(t.topInset=e.insets.top,t.bottomInset=e.insets.bottom),Object.keys(t).length>0&&this.setData?.(t),this.data?.autoDetectBars&&this.data?.detectedTopBarHeight===0&&this.detectCustomBars?.()}}})}exports.appMetricsSignal=Y,exports.createAppHostBehavior=ee,exports.cuiAppChildBehavior=h,exports.cuiAppParentBehavior=m,exports.notifyScaleGestureDragEnd=V,exports.notifyScaleGestureDragMove=B,exports.notifyScaleGestureDragStart=z,exports.setupAppRelations=g,exports.withAppBannerInset=G,exports.withAppScale=W;
|
|
1
|
+
const e=require("../alien-signals.js"),t=require("../weapp-vendors/miniapp-machine.js");function n(e){return typeof Behavior<`u`?Behavior(e):{}}function r(e){return e}function i(e){if(e)try{if(typeof e.getPageId==`function`){let t=e.getPageId();if(t!=null&&t!==``)return String(t)}if(e.__wxWebviewId__!==void 0&&e.__wxWebviewId__!==null&&String(e.__wxWebviewId__)!==``)return String(e.__wxWebviewId__);if(typeof e.__page__?.getPageId==`function`){let t=e.__page__.getPageId();if(t!=null&&t!==``)return String(t)}if(typeof e.$page?.getPageId==`function`){let t=e.$page.getPageId();if(t!=null&&t!==``)return String(t)}}catch{}}var a=`*`,o=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{};o.__CODE_UI_APP_REGISTRY__||(o.__CODE_UI_APP_REGISTRY__={hosts:[],hostByInstance:new WeakMap,pageSignals:new WeakMap,pending:new Map,orderCounter:0});var s=o.__CODE_UI_APP_REGISTRY__,c=s.hosts,l=s.hostByInstance,u=s.pageSignals,d=s.pending;function f(e,t){if(!e||!t)return;t.__cuiAppParent=e,e.__cuiAppChildren||(e.__cuiAppChildren=new Set),e.__cuiAppChildren.add(t);let n=l.get(e);if(n){let e=!1;t.__cuiScaled&&t.__cuiScaleId&&(n.scales.has(t.__cuiScaleId)||(n.scales.set(t.__cuiScaleId,{id:t.__cuiScaleId,factor:t.__cuiScaleFactor,background:t.__cuiScaleBackground}),e=!0));let r=t.__cuiRegisteredSize??0,i=t.__cuiRegisteredBannerSize??0,a=r>0?r:i>0?i:0,o=t.__cuiInsetId??t.__cuiBannerInsetId;a>0&&o&&(n.insets.set(o,{id:o,edge:t.__cuiInsetEdge??t.__cuiRegisteredBannerEdge??`top`,size:a}),e=!0),E(n),e&&A(n)}}function p(e,t){if(!t)return;t.__cuiAppParent===e&&(t.__cuiAppParent=void 0),e&&e.__cuiAppChildren&&e.__cuiAppChildren.delete(t);let n=e?l.get(e):C(t);if(n){let e=!1;t.__cuiScaleId&&n.scales.delete(t.__cuiScaleId)&&(e=!0);let r=t.__cuiInsetId??t.__cuiBannerInsetId;r&&n.insets.delete(r)&&(e=!0),e&&A(n)}}var m=n({}),h=n({relations:{cuiAppParent:{type:`ancestor`,target:m,linked(e){f(e,this)},unlinked(e){p(e,this)}}}});function g(e,t,n){t===`parent`?e.cuiAppChild=r({type:`descendant`,target:h,linked(e){f(this,e),n?.linked?.(e)},unlinked(e){p(this,e),n?.unlinked?.(e)}}):e.cuiAppParent=r({type:`ancestor`,target:m,linked(e){f(e,this),n?.linked?.(e)},unlinked(e){p(e,this),n?.unlinked?.(e)}})}function _(t){let n=u.get(t);return n||(n={insets:e.signal({top:0,bottom:0}),scale:e.signal({scaled:!1,factor:1})},u.set(t,n)),n}function v(e){if(!e)return;let t=i(e);if(t!==void 0)return t;let n=e.pageId;return n!=null&&n!==``?String(n):void 0}function y(e){if(e)try{let t=e;for(let e=0;t&&e<=10;e++){let e=v(t);if(e!==void 0)return e;t=typeof t.selectOwnerComponent==`function`?t.selectOwnerComponent():null}}catch{}}function b(){if(typeof getCurrentPages==`function`)try{let e=getCurrentPages(),t=e[e.length-1];return y(t)}catch{return}}function x(e){for(let t=c.length-1;t>=0;t--){let n=c[t];if(n&&n.pageId===e)return n}}function S(){let e=b();if(e){let t=x(e);if(t)return t}let t;for(let e of c)e.visible&&(!t||e.order>t.order)&&(t=e);return t??c[c.length-1]}function C(e){if(e){let t=l.get(e);if(t)return t;if(e.__cuiAppParent){let t=l.get(e.__cuiAppParent);if(t)return t}if(typeof e.getRelationNodes==`function`)try{let t=e.getRelationNodes(`cuiAppParent`);if((!t||t.length===0)&&m&&(t=e.getRelationNodes(m)),t&&t.length>0&&t[0]){let e=l.get(t[0]);if(e)return e}}catch{}let n=y(e);if(n){let e=x(n);if(e)return e}}return S()}function w(e){return e&&y(e)||a}function T(e,t){let n=C(e);if(n){t(n);return}let r=w(e),i=d.get(r);i?i.push(t):d.set(r,[t])}function E(e){let t=[e.pageId,a];for(let n of t){let t=d.get(n);if(t){d.delete(n);for(let n of t)n(e)}}}function D(e){let t=0,n=0;return e.insets.forEach(e=>{let r=Number.isFinite(e.size)?Math.max(0,e.size):0;e.edge===`bottom`?n+=r:t+=r}),{top:t,bottom:n}}function O(e){if(e.scales.size===0)return{scaled:!1,factor:1};let t;return e.scales.forEach(e=>{t=e}),{scaled:!0,factor:t?.factor??.94,background:t?.background}}function k(e){return{insets:D(e),scale:O(e)}}function A(e){let t=k(e);e.signals.insets(t.insets),e.signals.scale(t.scale),e.adapter?.onChange?.(t)}function j(e,t){if(l.has(e))return;let n=_(e),r={instance:e,pageId:y(e)??`cui-app-${s.orderCounter+1}`,adapter:t,signals:n,insets:new Map,scales:new Map,visible:!0,order:++s.orderCounter};if(c.push(r),l.set(e,r),e.__cuiAppChildren)for(let t of e.__cuiAppChildren){t.__cuiScaled&&t.__cuiScaleId&&r.scales.set(t.__cuiScaleId,{id:t.__cuiScaleId,factor:t.__cuiScaleFactor,background:t.__cuiScaleBackground});let e=t.__cuiRegisteredSize??0,n=t.__cuiRegisteredBannerSize??0,i=e>0?e:n>0?n:0,a=t.__cuiInsetId??t.__cuiBannerInsetId;i>0&&a&&r.insets.set(a,{id:a,edge:t.__cuiInsetEdge??t.__cuiRegisteredBannerEdge??`top`,size:i})}E(r),A(r)}function M(e){let t=l.get(e);if(!t)return;l.delete(e);let n=c.indexOf(t);if(n!==-1&&c.splice(n,1),t.insets.clear(),t.scales.clear(),e.__cuiAppChildren){for(let t of e.__cuiAppChildren)t.__cuiAppParent===e&&(t.__cuiAppParent=void 0);e.__cuiAppChildren.clear()}}function N(e,t){let n=l.get(e);n&&(n.visible=t,t&&(n.order=++s.orderCounter))}function P(e,t){T(e,e=>{e.scales.set(t.id,{...t}),A(e)})}function F(e,t){let n=C(e);if(!n){let n=w(e),r=d.get(n);r&&r.push(e=>{e.scales.delete(t)&&A(e)});return}n.scales.delete(t)&&A(n)}function I(e,t){let n=C(e);n&&n.instance?.endScaleGesture?.(t)}function L(e,t){T(e,e=>{let n=e.insets.get(t.id);n&&n.edge===t.edge&&n.size===t.size||(e.insets.set(t.id,{...t}),A(e))})}function R(e,t){T(e,e=>{e.insets.delete(t)&&A(e)})}function z(e={}){let t=0,r=(e,t,n)=>{let r=e.data,i=t.service?.state,a=n===`open`&&!!r?.open,o=!a&&(i?.matches?.(`closed`)||i?.matches?.(`closing`)||i?.hasTag?.(`closing`))||n===`open`&&!r?.open,s=!!r?.shouldScaleBackground&&!o&&!!(a||i?.hasTag?.(`open`)||i?.matches?.(`open`)||i?.matches?.(`dragging`)),c=e.__cuiScaleId??``;c&&(s===!!e.__cuiScaled?s&&n&&(e.__cuiScaleFactor=r?.scaleFactor,e.__cuiScaleBackground=r?.scaleBackground,P(e,{id:c,factor:r?.scaleFactor,background:r?.scaleBackground})):(e.__cuiScaled=s,e.__cuiScaleFactor=r?.scaleFactor,e.__cuiScaleBackground=r?.scaleBackground,s?P(e,{id:c,factor:r?.scaleFactor,background:r?.scaleBackground}):F(e,c)))};return{name:`scale-background`,behaviors:[h,n({observers:{"shouldScaleBackground, scaleFactor, scaleBackground"(){this.__codeUiMachine&&r(this,this.__codeUiMachine,`scale`)}}})],setupRelations(e){g(e,`child`)},onAttached(n){let r=n;r.__cuiScaleId=`${e.idPrefix??`scale`}:${++t}`,r.__cuiScaled=!1},onMachineStarted(e,t){let n=e,i=()=>r(n,t);n.__cuiScaleUnsub=t.subscribe(i),i()},onPropChanged(e,t){let n=e;(t===`shouldScaleBackground`||t===`scaleFactor`||t===`scaleBackground`||t===`open`)&&n.__codeUiMachine&&r(n,n.__codeUiMachine,t)},onDetached(e){let t=e;t.__cuiScaleDragging&&(t.__cuiScaleDragging=!1,t.__cuiScaleDragRafPending=!1,t.data?.shouldScaleBackground&&I(t,!1)),t.__cuiScaleUnsub?.(),t.__cuiScaled&&t.__cuiScaleId&&(F(t,t.__cuiScaleId),t.__cuiScaled=!1)}}}function B(e={}){let r=0,i=(e,t)=>{let n=e.data,r=t.service?.state,i=!(r?.matches?.(`closed`)||r?.matches?.(`closing`)||r?.matches?.(`dismissing`)||r?.hasTag?.(`closed`)||r?.hasTag?.(`dismissing`)||n?.open===!1)&&(!!n?.open||r?.hasTag?.(`open`)||r?.matches?.(`open`)),a=n?.autoInset!==!1,o=n?.mode||(n?.placement===`inline`?`inline`:`fixed`),s=n?.placement===`bottom`?`bottom`:`top`,c=e.__cuiBannerInsetId??``;if(!i||!a||o===`inline`){e.__cuiBannerHeight=0,e.__cuiMeasureRetryTimer&&(clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=null),(e.__cuiRegisteredBannerSize??0)>0&&c&&(R(e,c),e.__cuiRegisteredBannerSize=0,e.__cuiRegisteredBannerEdge=void 0,e.__cuiRegisteredSize=0,e.__cuiInsetEdge=void 0);return}let l=Number(e.__cuiBannerHeight||0);if(l<=0&&Number(e.__cuiLastKnownHeight||0)>0&&(l=Number(e.__cuiLastKnownHeight),e.__cuiBannerHeight=l),l<=0){(e.__cuiRegisteredBannerSize??0)>0&&c&&(R(e,c),e.__cuiRegisteredBannerSize=0,e.__cuiRegisteredBannerEdge=void 0,e.__cuiRegisteredSize=0,e.__cuiInsetEdge=void 0);return}(e.__cuiRegisteredBannerEdge!==s||e.__cuiRegisteredBannerSize!==l)&&(e.__cuiRegisteredBannerSize??0)>0&&c&&R(e,c),e.__cuiRegisteredBannerEdge=s,e.__cuiRegisteredBannerSize=l,e.__cuiInsetId=c,e.__cuiInsetEdge=s,e.__cuiRegisteredSize=l,c&&L(e,{id:c,edge:s,size:l})},a=(e,n=0)=>{(typeof e?.createSelectorQuery==`function`||t.isMiniApp())&&t.queryRect(`.cui-banner-root`,e).then(t=>{let r=e.data,o=e.__codeUiMachine?.service?.state,s=!(o?.matches?.(`closed`)||o?.matches?.(`closing`)||o?.matches?.(`dismissing`)||o?.hasTag?.(`closed`)||o?.hasTag?.(`dismissing`)||r?.open===!1)&&(!!r?.open||o?.hasTag?.(`open`)||o?.matches?.(`open`));if(!t||typeof t.height!=`number`||t.height<=0){s&&n<5&&(e.__cuiMeasureRetryTimer&&clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=setTimeout(()=>{e.__cuiMeasureRetryTimer=null,a(e,n+1)},30*(n+1)));return}let c=Math.round(t.height);e.__cuiLastKnownHeight=c,(c!==e.__cuiBannerHeight||e.__cuiRegisteredBannerSize!==c)&&(e.__cuiBannerHeight=c,e.__codeUiMachine&&i(e,e.__codeUiMachine))}).catch(()=>{n<3&&(e.__cuiMeasureRetryTimer&&clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=setTimeout(()=>{e.__cuiMeasureRetryTimer=null,a(e,n+1)},40))})},o=e=>{if(e.__cuiMeasureRetryTimer&&(clearTimeout(e.__cuiMeasureRetryTimer),e.__cuiMeasureRetryTimer=null),e.__cuiBannerMeasureQueued){e.__cuiBannerMeasureNeedsRerun=!0;return}e.__cuiBannerMeasureQueued=!0,t.nextTick(()=>{e.__cuiBannerMeasureQueued=!1,a(e,0),e.__cuiBannerMeasureNeedsRerun&&(e.__cuiBannerMeasureNeedsRerun=!1,o(e))})};return{name:`banner-layout-inset`,behaviors:[h,n({observers:{"placement, mode, autoInset, size, title, description, caption, badge, actions, image, more, close"(){this.__cuiBannerInsetId&&(o(this),this.__codeUiMachine&&i(this,this.__codeUiMachine))}}})],setupRelations(e){g(e,`child`)},onAttached(t){let n=t;n.__cuiBannerInsetId=`${e.idPrefix??`banner`}:${++r}`,n.__cuiRegisteredBannerSize=0,n.__cuiRegisteredBannerEdge=void 0,n.__cuiBannerHeight=0,n.__cuiLastKnownHeight=0,n.__cuiBannerMeasureQueued=!1,n.__cuiBannerMeasureNeedsRerun=!1,n.__cuiMeasureRetryTimer=null},onMachineStarted(e,t){let n=e;n.__cuiBannerUnsub=t.subscribe(()=>{let e=t.service?.state;(e?.hasTag?.(`open`)||e?.matches?.(`open`))&&(Number(n.__cuiBannerHeight||0)<=0&&Number(n.__cuiLastKnownHeight||0)>0&&(n.__cuiBannerHeight=Number(n.__cuiLastKnownHeight)),o(n)),i(n,t)}),i(n,t)},onReady(e){o(e)},onPropChanged(e,t,n){let r=e;t===`open`&&(n?Number(r.__cuiLastKnownHeight||0)>0&&(r.__cuiBannerHeight=Number(r.__cuiLastKnownHeight),r.__codeUiMachine&&i(r,r.__codeUiMachine)):r.__codeUiMachine&&i(r,r.__codeUiMachine)),o(r),r.__codeUiMachine&&i(r,r.__codeUiMachine)},onDetached(e){let t=e;t.__cuiBannerUnsub?.(),t.__cuiBannerUnsub=void 0,t.__cuiBannerMeasureQueued=!1,t.__cuiBannerMeasureNeedsRerun=!1,t.__cuiMeasureRetryTimer&&(clearTimeout(t.__cuiMeasureRetryTimer),t.__cuiMeasureRetryTimer=null),(t.__cuiRegisteredBannerSize??0)>0&&t.__cuiBannerInsetId&&(R(t,t.__cuiBannerInsetId),t.__cuiRegisteredBannerSize=0,t.__cuiRegisteredBannerEdge=void 0,t.__cuiRegisteredSize=0,t.__cuiInsetEdge=void 0),t.__cuiBannerHeight=0}}}var V=32,H=4,U=null,W=e.signal(G());function G(){let e={windowWidth:0,windowHeight:0,statusBarHeight:0,safeTop:0,safeBottom:0,menuTop:0,menuHeight:0,menuInset:0,navBarHeight:0,navHeight:0};if(typeof wx>`u`)return e;let t;try{t=typeof wx.getWindowInfo==`function`?wx.getWindowInfo():wx.getSystemInfoSync()}catch{return e}if(!t)return e;let n=t.windowWidth??0,r=t.windowHeight??0,i=t.screenHeight??r,a=t.statusBarHeight??0,o=t.safeArea,s=o?.top??a,c=o?Math.max(0,i-(o.bottom??i)):0,l;try{let e=typeof wx.getMenuButtonBoundingClientRect==`function`?wx.getMenuButtonBoundingClientRect():void 0;e&&e.height>0&&(l=e)}catch{}let u=l?.height??V,d=l?.top??a+H,f=l?Math.max(0,n-l.left):0,p=Math.max(0,d-a)*2+u;return{windowWidth:n,windowHeight:r,statusBarHeight:a,safeTop:s,safeBottom:c,menuTop:d,menuHeight:u,menuInset:f,navBarHeight:p,navHeight:a+p}}function K(e=!1){return U&&!e?U:(U=G(),W(U),U)}function q(){return K(!0)}function J(e){if(typeof getCurrentPages==`function`)try{let t=getCurrentPages(),n=t&&t[t.length-1];n&&(n.__cuiApp=e)}catch{}}function Y(e){let{detectBars:t,extractTopBarHeight:n,extractBottomBarHeight:r}=e;return Behavior({lifetimes:{attached(){this.__cuiAppAttached=!0,j(this,{onChange:e=>this.applyHostState?.(e)}),J(this)},detached(){this.__cuiAppAttached=!1,M(this)},ready(){this.detectCustomBars?.(),typeof wx<`u`&&typeof wx.nextTick==`function`&&wx.nextTick(()=>{this.__cuiAppAttached&&this.detectCustomBars?.()})}},pageLifetimes:{show(){J(this),N(this,!0),this.detectCustomBars?.()},hide(){N(this,!1)},resize(){q(),this.detectCustomBars?.()}},methods:{noop(){},detectCustomBars(){if(this.data?.autoDetectBars&&typeof wx<`u`&&typeof wx.createSelectorQuery==`function`)try{let e=(e,t)=>{if(!this.__cuiAppAttached)return;let i={};if(e&&typeof e.height==`number`){let t=n(e);t!==this.data?.detectedTopBarHeight&&(i.detectedTopBarHeight=t)}if(t&&typeof t.height==`number`){let e=r(t);e!==this.data?.detectedBottomBarHeight&&(i.detectedBottomBarHeight=e)}Object.keys(i).length>0&&this.setData?.(i)};t(this,({topRect:t,bottomRect:n})=>{e(t,n)})}catch{}},startScaleGesture(){this._lastScaleProgress=void 0},applyScaleProgress(e){if(e<=0&&!this.data?.gestureScaleStyle)return;let t=this._lastScaleProgress??-1;if(Math.abs(e-t)<.015&&e>0&&e<1)return;this._lastScaleProgress=e;let n=this.data?.hostScaleFactor||this.data?.scaleFactor||.94,r=Math.round((n+(1-n)*e)*1e3)/1e3,i=Math.round(Math.max(0,1-e)*1e3)/1e3,a=W().windowWidth||375,o=`translate3d(0, calc(var(--cui-top-offset) * ${i} + ${Math.round(Math.max(0,(1-r)/2*a)*100)/100}px), 0) scale3d(${r}, ${r}, 1)`;this.setData?.({gestureScaleStyle:`-webkit-transform: ${o}; transform: ${o}; transition: none !important;`})},endScaleGesture(e){this._lastScaleProgress=void 0;let t={gestureScaleStyle:``};e&&(t.scaled=!1),this.setData?.(t)},applyHostState(e){let t={};if(e.scale){let n=!!e.scale.scaled;n!==!!this.data?.scaled&&(t.scaled=n),e.scale.factor!==this.data?.hostScaleFactor&&(t.hostScaleFactor=e.scale.factor),e.scale.background!==this.data?.hostScaleBackground&&(t.hostScaleBackground=e.scale.background??``)}(e.insets.top!==this.data?.topInset||e.insets.bottom!==this.data?.bottomInset)&&(t.topInset=e.insets.top,t.bottomInset=e.insets.bottom),Object.keys(t).length>0&&this.setData?.(t),this.data?.autoDetectBars&&this.data?.detectedTopBarHeight===0&&this.detectCustomBars?.()}}})}exports.appMetricsSignal=W,exports.createAppHostBehavior=Y,exports.cuiAppChildBehavior=h,exports.cuiAppParentBehavior=m,exports.setupAppRelations=g,exports.withAppBannerInset=B,exports.withAppScale=z;
|
package/dist/behaviors/form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../alien-signals.js"),t=require("../weapp-vendors/miniapp-machine.js");function n(e){return e?.__codeUiFormHost??t.resolveServiceRef(e,`hostContext`)}function r(e){let n=t.resolveInstanceId(e);if(n)return n;let r=e.data?.name;if(typeof r==`string`&&r.trim().length>0)return r;let i=t.resolveServiceProp(e,`name`);if(typeof i==`string`&&i.trim().length>0)return i}var i=t.createBehaviorRef({}),a=t.createBehaviorRef({}),o=t.createBehaviorRef({observers:{size(){let e=d(this),n=this.__codeUiFieldChildren??[];for(let r of n)t.patchInheritedData(r,{fieldSize:e})}}});function s(e,n){let i=n.data?.form??t.resolveServiceProp(n,`form`);if(typeof i==`string`&&i.trim().length>0){let t=r(e);return t!==void 0&&i.trim()===t.trim()}if(typeof n.getRelationNodes==`function`){let t=n.getRelationNodes(`cuiFormParent`);if(t&&t.length>0)return t[0]===e}return!0}function c(e,t,n){if(n&&s(e,t)&&(t.__codeUiFormHost=n,t.__codeUiMachine?.updateProps({formContext:n}),Array.isArray(t.__codeUiFieldChildren)))for(let e of t.__codeUiFieldChildren)p(t,e)}function l(e,t){Array.isArray(e.__codeUiPendingFields)&&(e.__codeUiPendingFields=e.__codeUiPendingFields.filter(e=>e!==t));let r=n(e);t.__codeUiFormHost&&t.__codeUiFormHost===r&&(t.__codeUiFormHost=void 0,t.__codeUiMachine?.updateProps({formContext:null}))}function u(e,t){if(typeof t?.disabled==`boolean`)return t.disabled;let n=e.__codeUiMachine?.service;if(n?.context){let e=n.computed?.(`isDisabled`);return typeof e==`boolean`?e:!!n.context.get(`disabled`)}let r=e.__codeUiApi?.disabled;return typeof r==`boolean`?r:!!e.data?.disabled}function d(e){let t=e?.data?.size;return typeof t==`string`?t:``}function f(e,t){let n=e.__codeUiApi?.name,r=t?.name||e.__codeUiMachine?.service?.context?.get(`name`)||(typeof n==`string`?n:void 0)||e.data?.name;return typeof r==`string`&&r?r:void 0}function p(e,r,i){let a=u(e,i),o=d(e),s=f(e,i),c=n(e);if(t.patchInheritedData(r,{fieldSize:o}),!r.__codeUiMachine)return;let l={fieldDisabled:a};s&&!r.data?.name&&(l.name=s),c&&!r.__codeUiFormHost&&(r.__codeUiFormHost=c,l.formContext=c),r.__codeUiMachine.updateProps(l)}function m(e,t){if(t===e||t.__codeUiIsFormFieldWrapper)return;let n=e.__codeUiFieldChildren||(e.__codeUiFieldChildren=[]);n.includes(t)||n.push(t),t.__codeUiFieldWrapper=e,p(e,t)}function h(e,n){if(e.__codeUiFieldChildren){let t=e.__codeUiFieldChildren.indexOf(n);t!==-1&&e.__codeUiFieldChildren.splice(t,1)}n.__codeUiFieldWrapper===e&&(n.__codeUiFieldWrapper=void 0,t.patchInheritedData(n,{fieldSize:``}),n.__codeUiMachine?.updateProps({fieldDisabled:void 0}))}var g=t.createRelationOption({type:`ancestor`,target:i,linked(e){let t=n(e);t?c(e,this,t):(e.__codeUiPendingFields||(e.__codeUiPendingFields=[])).push(this)},unlinked(e){l(e,this)}}),_=t.createRelationOption({type:`ancestor`,target:a,linked(e){m(e,this)},unlinked(e){h(e,this)}}),v=t.createBehaviorRef({data:{fieldSize:``},relations:{cuiFormParent:g}});function y(e,r){if(typeof e.getRelationNodes==`function`){let t=e.getRelationNodes(`cuiFormParent`)?.[0];if(t){let i=n(t);i&&s(t,e)&&(r.formContext=i,e.__codeUiFormHost=i)}}let i=t.resolveParentNode(e,e.__codeUiFieldWrapper,`cuiFormFieldWrapper`);if(!i)return;r.fieldDisabled=u(i),t.patchInheritedData(e,{fieldSize:d(i)});let a=f(i);a&&!r.name&&(r.name=a);let o=n(i);o&&!r.formContext&&(r.formContext=o,e.__codeUiFormHost=o)}function b(e,r){r.formParent&&(e.cuiFormField=t.createRelationOption({type:`descendant`,target:v,linked(e){let t=n(this);if(!t){(this.__codeUiPendingFields||(this.__codeUiPendingFields=[])).push(e);return}c(this,e,t)},unlinked(e){l(this,e)}})),r.formFieldWrapper&&(e.cuiFormFieldChild=t.createRelationOption({type:`descendant`,target:v,linked(e){m(this,e)},unlinked(e){h(this,e)}})),r.formField&&(e.cuiFormParent=g,e.cuiFormFieldWrapper=_)}function x(e,t,n){if(n.formFieldWrapper){let t=e;t.__codeUiIsFormFieldWrapper=!0,t.__codeUiOnSnapshot=e=>{if(t.__codeUiFieldChildren)for(let n of t.__codeUiFieldChildren)p(t,n,e)};let n=t.getRelationNodes?.(`cuiFormFieldChild`)??[];for(let e of n)m(t,e)}if(n.formParent){let n=e,r=(t?.service?.refs)?.get?.(`hostContext`);r&&(n.__codeUiFormHost=r);let i=n.__codeUiPendingFields;if(Array.isArray(i)){for(let e of i)c(n,e,r);n.__codeUiPendingFields=[]}let a=n.getRelationNodes?.(`cuiFormField`)??[];for(let e of a)c(n,e,r)}}function S(e,t){if(!t.formParent||typeof e.getRelationNodes!=`function`)return;let r=n(e);if(!r)return;let i=e.getRelationNodes(`cuiFormField`)??[];for(let t of i)c(e,t,r)}function C(e,t){if(t.formParent){let t=e,n=t.getRelationNodes?.(`cuiFormField`)??[];for(let e of n)l(t,e);t.__codeUiFormHost=void 0,t.__codeUiPendingFields=[]}if(t.formField&&(e.__codeUiFormHost=void 0),t.formFieldWrapper){let t=e;for(let e of(t.__codeUiFieldChildren??[]).slice())h(t,e);t.__codeUiFieldChildren=[],t.__codeUiOnSnapshot=void 0}}function w(){return{name:`form-parent`,behaviors:[i],setupRelations(e){b(e,{formParent:!0})},onMachineStarted(e,t){x(e,t,{formParent:!0})},onReady(e){S(e,{formParent:!0})},onDetached(e){C(e,{formParent:!0})}}}function T(e){let t=[v];return e?.native!==!1&&t.push(`wx://form-field`),{name:`form-field`,behaviors:t,setupRelations(e){e.cuiFormParent=g,e.cuiFormFieldWrapper=_},onAttached(e,t){y(e,t)},onDetached(e){e.__codeUiFormHost=void 0}}}function E(){return{name:`form-field-wrapper`,behaviors:[a,o],setupRelations(e){b(e,{formFieldWrapper:!0})},onMachineStarted(e,t){x(e,t,{formFieldWrapper:!0})},onPropChanged(e,t){if(t!==`disabled`&&t!==`name`)return;let n=e,r=n.__codeUiFieldChildren??[];for(let e of r)p(n,e)},onDetached(e){C(e,{formFieldWrapper:!0})}}}function D(e){return Symbol(e)}var O=`cui-context-request`,k=new Map,A=new Map,j=new WeakMap,M=new Map,N=new Map;function P(e){return k.has(e)||k.set(e,new WeakMap),k.get(e)}function F(e){let t=A.get(e);return t||(t=new WeakSet,A.set(e,t)),t}function I(e){return!e||typeof e!=`object`?null:e.__codeUiInstance&&typeof e.__codeUiInstance==`object`?e.__codeUiInstance:e}function L(e,t){let n=I(e);if(n)try{if(typeof e.triggerEvent==`function`){let r={key:t,consumer:n,handled:!1};if(e.triggerEvent(O,r,{bubbles:!0,composed:!0}),r.handled&&r.provider)return r.provider}}catch{}}function R(e){try{let t=e?.getPageId?.()??e?.__wxWebviewId__;if(t!=null&&t!==``){let e=String(t),n=M.get(e);return n||(n=Object.create(null),M.set(e,n)),n}let n=typeof getCurrentPages==`function`?getCurrentPages():null;return n&&n.length>0?n[n.length-1]:null}catch{return null}}function z(e){try{let t=I(typeof e?.selectOwnerComponent==`function`?e.selectOwnerComponent():null);if(t!==null&&t!==e)return t}catch{}return null}function B(e,t,n){let r=I(e);if(!r)return;if(n!==void 0&&!j.has(r)){let r=L(e,n);if(r!==void 0&&t.has(r))return r}if(j.has(r)){let e=j.get(r),n=new Set;for(;e!==void 0&&!n.has(e);){if(n.add(e),t.has(e))return e;e=j.get(e)}return}let i=r,a=new Set;for(;i!==null&&!a.has(i);){if(a.add(i),t.has(i))return i;let e=z(i);if(e===null)break;i=e}let o=R(e);if(o!==null&&t.has(o))return o}function V(e,t,n){let r=P(t),i=F(t),a=I(e)??e;r.set(a,n),i.add(a);let o=z(a);o!==null&&!i.has(o)&&r.set(o,n);let s=R(a);s!==null&&!i.has(s)&&r.set(s,n);let c=N.get(t);if(c&&c.size>0)for(let e of Array.from(c)){let n=B(e.component,r,t);n!==void 0&&(n===a||n===o||n===s)&&e.callback(r.get(n))}}function H(e,t,n){let r=P(t),i=B(e,r,t);return i===void 0?n:r.get(i)}function U(e,t,n){let r=H(e,t);r!==void 0&&n(r);let i=N.get(t);i||(i=new Set,N.set(t,i));let a={component:e,callback:n};return i.add(a),()=>{i?.delete(a)}}var W=D(`cui:form-host`),G=new Map;function K(e){let t=e?.trim();if(!t)return W;let n=G.get(t);return n||(n=D(`cui:form-host:${t}`),G.set(t,n)),n}function q(e,t,n){V(e,W,t);let r=new Set;n?.trim()&&r.add(n.trim()),typeof e.id==`string`&&e.id.trim()&&r.add(e.id.trim());for(let n of r)V(e,K(n),t);return t}function J(e,t){return e?H(e,K(t)):void 0}function Y(t){let n=e.getActiveSub();e.setActiveSub(void 0);try{return t()}finally{e.setActiveSub(n)}}function X(t){let n=e.signal(void 0),r,i=``,a,o,s=!1,c=()=>{let e=t.getName();return e?.trim()?e:(t.getRules?.()?.length??0)>0||t.getFormId?.()?.trim()?t.id:``},l=()=>{let e=a;a=void 0,i=``,Y(()=>e?.())},u=e.effect(()=>{let e=t.getHost?t.getHost():t.host,r=K(t.getFormId?.());Y(()=>{o?.(),o=void 0,e===void 0?t.component?(n(H(t.component,r)),o=U(t.component,r,e=>{s||Y(()=>n(e))})):n(void 0):n(e??void 0)})}),d=e.effect(()=>{let e=n(),o=c();Y(()=>{(r!==e||i!==o)&&(l(),r=e,e&&o&&(i=o,a=e.register({name:o,id:t.id,getValue:t.getValue,setValue:t.setValue,resetValue:t.resetValue,focus:t.focus,getRules:t.getRules,getValidateOn:t.getValidateOn,isDisabled:t.isDisabled,component:t.component,onValidationChange:t.onValidationChange})))})}),f=(e,n)=>{if(s)return;let i=c();i&&r?.notify(e,{name:i,value:n,id:t.id})};return{get host(){return n()},emitInput:e=>f(`input`,e),emitChange:e=>f(`change`,e),emitBlur:e=>f(`blur`,e===void 0?t.getValue():e),emitFocus:e=>f(`focus`,e===void 0?t.getValue():e),dispose(){s||(s=!0,u(),d(),Y(()=>o?.()),o=void 0,l(),r=void 0,n(void 0))}}}function Z(e,t){t.get(`formField`)?.dispose();let n=!1,r=e=>{let t=n;n=!0;try{e()}finally{n=t}},i=X({...e,id:e.id??`field`,setValue:t=>r(()=>e.setValue(t)),resetValue:()=>r(e.resetValue),onValidationChange:t=>e.onValidationChange?.(t.isValid)}),a=i.emitInput,o=i.emitChange;return i.emitInput=e=>{n||a(e)},i.emitChange=e=>{n||o(e)},t.set(`formField`,i),i}function Q(e){e.get(`formField`)?.dispose(),e.set(`formField`,void 0)}function $(e,t){return e(`formContext`)??t.get(`formField`)?.host}function ee(e,t,n,r){return!!$(e,t)?.errors(e(`name`)||n.id||r).length}function te(e){let t=(t,n)=>t(`name`)||n.id||e;return{formDisabled:({prop:e,refs:t})=>$(e,t)?.disabled()??!1,formReadOnly:({prop:e,refs:t})=>$(e,t)?.readOnly()??!1,fieldDisabled:({prop:e,refs:n,scope:r})=>!!(e(`fieldDisabled`)||$(e,n)?.fieldState(t(e,r))?.disabled)}}exports.cleanupFormFieldSync=Q,exports.createFormFieldComputed=te,exports.createInjectionKey=D,exports.getFormHostKey=K,exports.hasFormFieldErrors=ee,exports.injectFormHost=J,exports.onProvide=U,exports.provideFormHost=q,exports.setupFormFieldSync=Z,exports.withFormField=T,exports.withFormFieldWrapper=E,exports.withFormParent=w;
|
|
1
|
+
const e=require("../alien-signals.js"),t=require("../weapp-vendors/miniapp-machine.js");function n(e){return e?.__codeUiFormHost??t.resolveServiceRef(e,`hostContext`)}function r(e){let n=t.resolveInstanceId(e);if(n)return n;let r=e.data?.name;if(typeof r==`string`&&r.trim().length>0)return r;let i=t.resolveServiceProp(e,`name`);if(typeof i==`string`&&i.trim().length>0)return i}var i=t.createBehaviorRef({}),a=t.createBehaviorRef({}),o=t.createBehaviorRef({observers:{size(){let e=d(this),n=this.__codeUiFieldChildren??[];for(let r of n)t.patchInheritedData(r,{fieldSize:e})}}});function s(e,n){let i=n.data?.form??t.resolveServiceProp(n,`form`);if(typeof i==`string`&&i.trim().length>0){let t=r(e);return t!==void 0&&i.trim()===t.trim()}if(typeof n.getRelationNodes==`function`){let t=n.getRelationNodes(`cuiFormParent`);if(t&&t.length>0)return t[0]===e}return!0}function c(e,t,n){if(n&&s(e,t)&&(t.__codeUiFormHost=n,t.__codeUiMachine?.updateProps({formContext:n}),Array.isArray(t.__codeUiFieldChildren)))for(let e of t.__codeUiFieldChildren)p(t,e)}function l(e,t){Array.isArray(e.__codeUiPendingFields)&&(e.__codeUiPendingFields=e.__codeUiPendingFields.filter(e=>e!==t));let r=n(e);t.__codeUiFormHost&&t.__codeUiFormHost===r&&(t.__codeUiFormHost=void 0,t.__codeUiMachine?.updateProps({formContext:null}))}function u(e,t){if(typeof t?.disabled==`boolean`)return t.disabled;let n=e.__codeUiMachine?.service;if(n?.context){let e=n.computed?.(`isDisabled`);return typeof e==`boolean`?e:!!n.context.get(`disabled`)}let r=e.__codeUiApi?.disabled;return typeof r==`boolean`?r:!!e.data?.disabled}function d(e){let t=e?.data?.size;return typeof t==`string`?t:``}function f(e,t){let n=e.__codeUiApi?.name,r=t?.name||e.__codeUiMachine?.service?.context?.get(`name`)||(typeof n==`string`?n:void 0)||e.data?.name;return typeof r==`string`&&r?r:void 0}function p(e,r,i){let a=u(e,i),o=d(e),s=f(e,i),c=n(e);if(t.patchInheritedData(r,{fieldSize:o}),!r.__codeUiMachine)return;let l={fieldDisabled:a};s&&!r.data?.name&&(l.name=s),c&&!r.__codeUiFormHost&&(r.__codeUiFormHost=c,l.formContext=c),r.__codeUiMachine.updateProps(l)}function m(e,t){if(t===e||t.__codeUiIsFormFieldWrapper)return;let n=e.__codeUiFieldChildren||(e.__codeUiFieldChildren=[]);n.includes(t)||n.push(t),t.__codeUiFieldWrapper=e,p(e,t)}function h(e,n){if(e.__codeUiFieldChildren){let t=e.__codeUiFieldChildren.indexOf(n);t!==-1&&e.__codeUiFieldChildren.splice(t,1)}n.__codeUiFieldWrapper===e&&(n.__codeUiFieldWrapper=void 0,t.patchInheritedData(n,{fieldSize:``}),n.__codeUiMachine?.updateProps({fieldDisabled:void 0}))}var g=t.createRelationOption({type:`ancestor`,target:i,linked(e){let t=n(e);t?c(e,this,t):(e.__codeUiPendingFields||(e.__codeUiPendingFields=[])).push(this)},unlinked(e){l(e,this)}}),_=t.createRelationOption({type:`ancestor`,target:a,linked(e){m(e,this)},unlinked(e){h(e,this)}}),v=t.createBehaviorRef({data:{fieldSize:``},relations:{cuiFormParent:g}});function y(e,r){if(typeof e.getRelationNodes==`function`){let t=e.getRelationNodes(`cuiFormParent`)?.[0];if(t){let i=n(t);i&&s(t,e)&&(r.formContext=i,e.__codeUiFormHost=i)}}let i=t.resolveParentNode(e,e.__codeUiFieldWrapper,`cuiFormFieldWrapper`);if(!i)return;r.fieldDisabled=u(i),t.patchInheritedData(e,{fieldSize:d(i)});let a=f(i);a&&!r.name&&(r.name=a);let o=n(i);o&&!r.formContext&&(r.formContext=o,e.__codeUiFormHost=o)}function b(e,r){r.formParent&&(e.cuiFormField=t.createRelationOption({type:`descendant`,target:v,linked(e){let t=n(this);if(!t){(this.__codeUiPendingFields||(this.__codeUiPendingFields=[])).push(e);return}c(this,e,t)},unlinked(e){l(this,e)}})),r.formFieldWrapper&&(e.cuiFormFieldChild=t.createRelationOption({type:`descendant`,target:v,linked(e){m(this,e)},unlinked(e){h(this,e)}})),r.formField&&(e.cuiFormParent=g,e.cuiFormFieldWrapper=_)}function x(e,t,n){if(n.formFieldWrapper){let t=e;t.__codeUiIsFormFieldWrapper=!0,t.__codeUiOnSnapshot=e=>{if(t.__codeUiFieldChildren)for(let n of t.__codeUiFieldChildren)p(t,n,e)};let n=t.getRelationNodes?.(`cuiFormFieldChild`)??[];for(let e of n)m(t,e)}if(n.formParent){let n=e,r=(t?.service?.refs)?.get?.(`hostContext`);r&&(n.__codeUiFormHost=r);let i=n.__codeUiPendingFields;if(Array.isArray(i)){for(let e of i)c(n,e,r);n.__codeUiPendingFields=[]}let a=n.getRelationNodes?.(`cuiFormField`)??[];for(let e of a)c(n,e,r)}}function S(e,t){if(!t.formParent||typeof e.getRelationNodes!=`function`)return;let r=n(e);if(!r)return;let i=e.getRelationNodes(`cuiFormField`)??[];for(let t of i)c(e,t,r)}function C(e,t){if(t.formParent){let t=e,n=t.getRelationNodes?.(`cuiFormField`)??[];for(let e of n)l(t,e);t.__codeUiFormHost=void 0,t.__codeUiPendingFields=[]}if(t.formField&&(e.__codeUiFormHost=void 0),t.formFieldWrapper){let t=e;for(let e of(t.__codeUiFieldChildren??[]).slice())h(t,e);t.__codeUiFieldChildren=[],t.__codeUiOnSnapshot=void 0}}function w(){return{name:`form-parent`,behaviors:[i],setupRelations(e){b(e,{formParent:!0})},onMachineStarted(e,t){x(e,t,{formParent:!0})},onReady(e){S(e,{formParent:!0})},onDetached(e){C(e,{formParent:!0})}}}function T(e){let t=[v];return e?.native!==!1&&t.push(`wx://form-field`),{name:`form-field`,behaviors:t,setupRelations(e){e.cuiFormParent=g,e.cuiFormFieldWrapper=_},onAttached(e,t){y(e,t)},onDetached(e){e.__codeUiFormHost=void 0}}}function E(){return{name:`form-field-wrapper`,behaviors:[a,o],setupRelations(e){b(e,{formFieldWrapper:!0})},onMachineStarted(e,t){x(e,t,{formFieldWrapper:!0})},onPropChanged(e,t){if(t!==`disabled`&&t!==`name`)return;let n=e,r=n.__codeUiFieldChildren??[];for(let e of r)p(n,e)},onDetached(e){C(e,{formFieldWrapper:!0})}}}function D(e){return Symbol(e)}var O=`cui-context-request`,k=new Map,A=new Map,j=new WeakMap,M=new Map,N=new Map;function P(e){return k.has(e)||k.set(e,new WeakMap),k.get(e)}function F(e){let t=A.get(e);return t||(t=new WeakSet,A.set(e,t)),t}function I(e){return!e||typeof e!=`object`?null:e.__codeUiInstance&&typeof e.__codeUiInstance==`object`?e.__codeUiInstance:e}function L(e,t){let n=I(e);if(n)try{if(typeof e.triggerEvent==`function`){let r={key:t,consumer:n,handled:!1};if(e.triggerEvent(O,r,{bubbles:!0,composed:!0}),r.handled&&r.provider)return r.provider}}catch{}}function R(e){try{let t=e?.getPageId?.()??e?.__wxWebviewId__;if(t!=null&&t!==``){let e=String(t),n=M.get(e);return n||(n=Object.create(null),M.set(e,n)),n}let n=typeof getCurrentPages==`function`?getCurrentPages():null;return n&&n.length>0?n[n.length-1]:null}catch{return null}}function z(e){try{let t=I(typeof e?.selectOwnerComponent==`function`?e.selectOwnerComponent():null);if(t!==null&&t!==e)return t}catch{}return null}function B(e,t,n){let r=I(e);if(!r)return;if(n!==void 0&&!j.has(r)){let r=L(e,n);if(r!==void 0&&t.has(r))return r}if(j.has(r)){let e=j.get(r),n=new Set;for(;e!==void 0&&!n.has(e);){if(n.add(e),t.has(e))return e;e=j.get(e)}return}let i=r,a=new Set;for(;i!==null&&!a.has(i);){if(a.add(i),t.has(i))return i;let e=z(i);if(e===null)break;i=e}let o=R(e);if(o!==null&&t.has(o))return o}function V(e,t,n){let r=P(t),i=F(t),a=I(e)??e;r.set(a,n),i.add(a);let o=z(a);o!==null&&!i.has(o)&&r.set(o,n);let s=R(a);s!==null&&!i.has(s)&&r.set(s,n);let c=N.get(t);if(c&&c.size>0)for(let e of Array.from(c)){let n=B(e.component,r,t);n!==void 0&&(n===a||n===o||n===s)&&e.callback(r.get(n))}}function H(e,t,n){let r=P(t),i=B(e,r,t);return i===void 0?n:r.get(i)}function U(e,t,n){let r=H(e,t);r!==void 0&&n(r);let i=N.get(t);i||(i=new Set,N.set(t,i));let a={component:e,callback:n};return i.add(a),()=>{i?.delete(a)}}var W=D(`cui:form-host`),G=new Map;function K(e){let t=e?.trim();if(!t)return W;let n=G.get(t);return n||(n=D(`cui:form-host:${t}`),G.set(t,n)),n}function q(e,t,n){V(e,W,t);let r=new Set;n?.trim()&&r.add(n.trim()),typeof e.id==`string`&&e.id.trim()&&r.add(e.id.trim());for(let n of r)V(e,K(n),t);return t}function J(e,t){return e?H(e,K(t)):void 0}function Y(t){let n=e.getActiveSub();e.setActiveSub(void 0);try{return t()}finally{e.setActiveSub(n)}}function X(t){let n=e.signal(void 0),r,i=``,a,o,s=!1,c=()=>{let e=t.getName();return e?.trim()?e:(t.getRules?.()?.length??0)>0||t.getFormId?.()?.trim()?t.id:``},l=()=>{let e=a;a=void 0,i=``,Y(()=>e?.())},u=e.effect(()=>{let e=t.getHost?t.getHost():t.host,r=K(t.getFormId?.());Y(()=>{o?.(),o=void 0,e===void 0?t.component?(n(H(t.component,r)),o=U(t.component,r,e=>{s||Y(()=>n(e))})):n(void 0):n(e??void 0)})}),d=e.effect(()=>{let e=n(),o=c();Y(()=>{(r!==e||i!==o)&&(l(),r=e,e&&o&&(i=o,a=e.register({name:o,id:t.id,rootId:t.rootId,getValue:t.getValue,setValue:t.setValue,resetValue:t.resetValue,focus:t.focus,getRules:t.getRules,getValidateOn:t.getValidateOn,isDisabled:t.isDisabled,component:t.component,onValidationChange:t.onValidationChange})))})}),f=(e,n)=>{if(s)return;let i=c();i&&r?.notify(e,{name:i,value:n,id:t.id})};return{get host(){return n()},emitInput:e=>f(`input`,e),emitChange:e=>f(`change`,e),emitBlur:e=>f(`blur`,e===void 0?t.getValue():e),emitFocus:e=>f(`focus`,e===void 0?t.getValue():e),dispose(){s||(s=!0,u(),d(),Y(()=>o?.()),o=void 0,l(),r=void 0,n(void 0))}}}function Z(e,t){t.get(`formField`)?.dispose();let n=!1,r=e=>{let t=n;n=!0;try{e()}finally{n=t}},i=X({...e,id:e.id??`field`,setValue:t=>r(()=>e.setValue(t)),resetValue:()=>r(e.resetValue),onValidationChange:t=>e.onValidationChange?.(t.isValid)}),a=i.emitInput,o=i.emitChange;return i.emitInput=e=>{n||a(e)},i.emitChange=e=>{n||o(e)},t.set(`formField`,i),i}function Q(e){e.get(`formField`)?.dispose(),e.set(`formField`,void 0)}function $(e,t){return e(`formContext`)??t.get(`formField`)?.host}function ee(e,t,n,r){return!!$(e,t)?.errors(e(`name`)||n.id||r).length}function te(e){let t=(t,n)=>t(`name`)||n.id||e;return{formDisabled:({prop:e,refs:t})=>$(e,t)?.disabled()??!1,formReadOnly:({prop:e,refs:t})=>$(e,t)?.readOnly()??!1,fieldDisabled:({prop:e,refs:n,scope:r})=>!!(e(`fieldDisabled`)||$(e,n)?.fieldState(t(e,r))?.disabled)}}exports.cleanupFormFieldSync=Q,exports.createFormFieldComputed=te,exports.createInjectionKey=D,exports.getFormHostKey=K,exports.hasFormFieldErrors=ee,exports.injectFormHost=J,exports.onProvide=U,exports.provideFormHost=q,exports.setupFormFieldSync=Z,exports.withFormField=T,exports.withFormFieldWrapper=E,exports.withFormParent=w;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js");var
|
|
1
|
+
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js"),r=require("../../behaviors/theme.js");var i=t=>e.partId(t,`as`,`root`,`r`),a=t=>e.partId(t,`as`,`content`,`c`),o=t=>e.partId(t,`as`,`backdrop`,`bd`),s=t=>e.optPartId(t,`closeTrigger`),c=t=>e.optPartId(t,`actions`);function l(e){let{state:t,send:n,computed:r,scope:l,context:u}=e,d=r(`isOpen`),f=r(`isVisible`),p=t.get();return{open:d,visible:f,state:p,loadingActionIndex:u.get(`loadingActionIndex`),setOpen(e){n({type:e?`OPEN`:`CLOSE`})},openActionSheet(){n({type:`OPEN`})},closeActionSheet(){n({type:`CLOSE`})},select(e){n({type:`SELECT`,index:e})},handleAction(e){n({type:`ACTION`,index:e})},rootProps:{id:i(l),"data-state":p,hidden:!f},backdropProps:{id:o(l),"data-state":d?`open`:`closed`,"aria-hidden":!0,hidden:!f},contentProps:{id:a(l),"data-state":p,"aria-role":`dialog`,"aria-modal":!0,"aria-hidden":!d,hidden:!f},closeTriggerProps:{id:s(l),"aria-role":`button`,"aria-label":`Close`},actionsProps:{id:c(l)}}}var u={open:null,defaultOpen:!1,items:[],actions:[],closeOnItem:!0,closeOnBackdropClick:!0,duration:300},d=300,f={OPEN:{target:`open`,actions:[`invokeOnOpen`]},TOGGLE:{target:`open`,actions:[`invokeOnOpen`]}},p=e.createMachine({props:({props:e})=>({...u,...e}),initialState:({prop:t})=>{let n=t(`open`);return(e.isNotNull(n)?n:t(`defaultOpen`))?`open`:`closed`},context:({bindable:e})=>({loadingActionIndex:e(()=>({defaultValue:null}))}),computed:{isOpen:({state:e})=>e.hasTag(`open`),isVisible:({state:e})=>e.hasTag(`open`)||e.hasTag(`closing`)},on:{ACTION_SETTLED:{actions:[`clearActionLoadingContext`]}},watch:({prop:t,state:n,track:r})=>{r([()=>t(`open`)],()=>{let r=t(`open`);if(!e.isNotNull(r))return;let i=!!r,a=n.hasTag(`open`);i&&!a?n.set(`open`):!i&&a&&n.set(`closing`)})},states:{closed:{tags:[`closed`],on:f},open:{tags:[`open`],on:{CLOSE:{target:`closing`,actions:[`invokeOnClose`]},TOGGLE:{target:`closing`,actions:[`invokeOnClose`]},"BACKDROP.TAP":{target:`closing`,guard:`closeOnBackdropClick`,actions:[`invokeOnClose`]},"CLOSE_TRIGGER.TAP":{target:`closing`,actions:[`invokeOnClose`]},SELECT:[{target:`closing`,guard:`shouldCloseOnItem`,actions:[`invokeOnSelect`,`invokeOnClose`]},{guard:`canSelectItem`,actions:[`invokeOnSelect`]}],ACTION:[{target:`closing`,guard:`shouldCloseOnAction`,actions:[`invokeOnAction`,`invokeOnClose`]},{guard:`canHandleAction`,actions:[`invokeOnAction`]}]}},closing:{tags:[`closing`],effects:[`waitForCloseAnimation`],on:{ANIMATION_END:{target:`closed`},...f}}},implementations:{guards:{closeOnBackdropClick:({prop:e})=>e(`closeOnBackdropClick`),canSelectItem:({prop:e,event:t})=>{if(t.type!==`SELECT`)return!1;let n=e(`items`)[t.index];return n?!n.disabled&&!n.loading:!1},shouldCloseOnItem:({prop:e,event:t})=>{if(t.type!==`SELECT`)return!1;let n=e(`items`)[t.index];return!n||n.disabled||n.loading?!1:e(`closeOnItem`)},canHandleAction:({prop:e,event:t,context:n})=>{if(t.type!==`ACTION`)return!1;let r=e(`actions`)[t.index];if(!r)return!1;let i=!!(r.loading||n.get(`loadingActionIndex`)===t.index);return!r.disabled&&!i},shouldCloseOnAction:({prop:e,event:t,context:n})=>{if(t.type!==`ACTION`)return!1;let r=e(`actions`)[t.index];if(!r)return!1;let i=!!(r.loading||n.get(`loadingActionIndex`)===t.index);return r.disabled||i?!1:r.closeOnClick!==!1}},actions:{invokeOnOpen:({prop:e})=>{e(`onOpenChange`)?.({open:!0})},invokeOnClose:({prop:e,context:t})=>{t.set(`loadingActionIndex`,null),e(`onOpenChange`)?.({open:!1}),e(`onClose`)?.()},clearActionLoadingContext:({context:e,event:t})=>{t.type===`ACTION_SETTLED`&&e.get(`loadingActionIndex`)===t.index&&e.set(`loadingActionIndex`,null)},invokeOnSelect:({prop:e,event:t})=>{if(t.type!==`SELECT`)return;let n=e(`items`)[t.index];n&&e(`onSelect`)?.({item:n,index:t.index})},invokeOnAction:({prop:t,event:n,send:r,context:i})=>{if(n.type!==`ACTION`)return;let a=t(`actions`)[n.index];if(!a)return;let o=a.onClick?.()??t(`onAction`)?.({action:a,index:n.index});e.isPromise(o)&&a.loadingAuto!==!1&&(i.set(`loadingActionIndex`,n.index),Promise.resolve(o).finally(()=>{r({type:`ACTION_SETTLED`,index:n.index})}))}},effects:{waitForCloseAnimation:({send:t,scope:n,prop:r})=>{let i,o=!1,s=()=>{o=!0,i!==void 0&&(clearTimeout(i),i=void 0)},c=e=>{o||(i=setTimeout(()=>{o||t({type:`ANIMATION_END`})},e))},l=r(`duration`);if(l>=0)return c(l),s;let u=n.component;if(!u&&!e.isMiniApp())return c(d),s;let f=`#${a(n)}`;return e.queryAnimationDuration(f,u).then(e=>{o||c(e>0?e:d)}).catch(()=>{o||c(d)}),s}}}}),m=e.tv({slots:{root:`fixed inset-0 z-action-sheet flex items-end justify-center overflow-hidden overscroll-contain box-border`,backdrop:`cui-action-sheet-backdrop-enter fixed inset-0 bg-black/40 backdrop-blur-sm transition-opacity duration-300`,content:`cui-action-sheet-content-enter relative z-10 flex flex-col w-full max-h-[85vh] bg-elevated rounded-t-lg shadow-2xl transition-transform duration-300 ease-out box-border overflow-hidden translate-y-0`,header:`relative flex flex-col items-center justify-center px-6 py-4 bg-default text-center border-b border-muted shrink-0 w-full box-border`,title:`w-full max-w-full break-words text-xs font-semibold uppercase tracking-wider text-dimmed text-center leading-snug`,description:`w-full max-w-full break-words text-xs text-muted text-center mt-1 leading-normal`,closeTrigger:`absolute right-3.5 top-3.5 z-10 inline-flex items-center justify-center w-7 h-7 rounded-full bg-elevated text-muted shrink-0 cursor-pointer active:opacity-70 transition-opacity`,closeButton:`p-0 w-full h-full rounded-full text-inherit`,closeIcon:`w-4 h-4`,body:`flex flex-col w-full bg-default overflow-y-auto max-h-[60vh] overscroll-contain box-border`,item:`relative flex items-center justify-center w-full min-h-14 md:min-h-12 px-6 py-3.5 bg-default border-t border-muted first:border-t-0 text-base cursor-pointer select-none box-border outline-none active:bg-muted transition-colors`,itemHover:`opacity-70`,itemText:`flex flex-col items-center justify-center text-center flex-1 w-full min-w-0 pointer-events-none`,itemTitle:`flex items-center justify-center gap-2 w-full`,itemLabel:`text-base font-normal text-highlighted text-center leading-snug`,itemLabelDestructive:`text-danger font-medium`,itemDescription:`text-xs text-dimmed text-center mt-1 leading-snug`,itemIcon:`w-5 h-5 shrink-0 text-muted pointer-events-none`,itemIconDestructive:`text-danger`,itemLoadingIcon:`animate-spin text-primary`,gap:`w-full h-2 bg-elevated shrink-0`,actions:`flex items-center justify-center gap-2 w-full p-3 bg-default pb-[calc(var(--spacing)_*_3_+_env(safe-area-inset-bottom))] box-border`,action:`flex-1`},variants:{open:{true:{backdrop:`opacity-100 pointer-events-auto`},false:{backdrop:`opacity-0 pointer-events-none`}},disabled:{true:{item:`cursor-not-allowed pointer-events-none`,itemTitle:`opacity-50`,itemDescription:`opacity-75`}},closable:{true:{header:`px-14 min-h-14`}}},compoundVariants:[{open:!1,class:{content:`translate-y-full`}},{open:!0,class:{content:`translate-y-0`}}],defaultVariants:{open:!1,disabled:!1,closable:!1}});function h(t,n,r,i,a){return e.resolveSlots(m({open:t,disabled:n,closable:r}),i,a)}var g=t.createMachineBehavior({machine:p,connect:l,key:`actionSheet`,exportApi:!0,exportApiKeys:[`open`,`visible`,`loadingActionIndex`,`setOpen`,`openActionSheet`,`closeActionSheet`,`select`,`handleAction`]}),_=typeof Behavior<`u`?r.createAppThemeBehavior():{};Component(n.createComponentOptions({behaviors:[_,g,n.computedBehavior],slots:{default:!1,header:!1,title:!1,description:!1,close:!1,actions:!1},computed:{portalStyle(){return this.data.portal&&this.data.themeCssVars||``},resolvedItems(){return(this.data.items||[]).map((e,t)=>({key:e.key??String(t),label:e.label,description:e.description,icon:e.icon,loadingIcon:e.loadingIcon||`loading`,color:e.color,destructive:!!e.destructive,disabled:!!e.disabled,loading:!!e.loading,openType:e.openType??``,className:e.className??``,style:e.style??``}))},resolvedClose(){let t=this.data.classes;return e.resolveTriggerButtonProps(this.data.close,{icon:`close`,color:`neutral`,variant:`ghost`,size:`xs`,ui:{icon:t?.closeIcon??``}},t?.closeButton)},resolvedActions(){let t=this.data.actions||[],n=this.data.actionSheet?.loadingActionIndex??null;return e.resolveSubcomponentList(t,{label:``,color:`neutral`,variant:`ghost`,size:`xl`,loadingIcon:`loading`,loadingAuto:!0,closeOnClick:!0,disabled:!1,loading:!1,openType:``,className:``,ui:{}},`label`,e=>(e.loading=!!(e.loading||n===e.index),e.loadingAuto=e.loadingAuto!==!1,e.closeOnClick=e.closeOnClick!==!1,e.disabled=!!e.disabled,e.ui=e.ui??{},e))},disabledClasses(){let{item:e,itemTitle:t,itemDescription:n}=h(!1,!0,!1,this.data.ui,this.data.className);return{item:e,itemTitle:t,itemDescription:n}},classes(){let e=!!this.data.actionSheet?.open,t=this.data.close;return h(e,!1,!!(this.data.slots?.close||t===!0||typeof t==`string`&&t.length>0||typeof t==`object`&&t),this.data.ui,this.data.className)}},properties:t.createProperties(u,{className:{type:String,value:``},title:{type:String,value:``},description:{type:String,value:``},close:{type:null,value:!1},portal:{type:Boolean,value:!0},ui:{type:Object,value:{}}}),methods:{noop(){},handleBackdropTap(e){this.send({type:`BACKDROP.TAP`}),this.triggerEvent(`backdropTap`,e)},handleCloseTriggerTap(e){this.send({type:`CLOSE_TRIGGER.TAP`}),this.triggerEvent(`closeTriggerTap`,e)},handleItemTap(t){let n=t.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`actionSheet`)?.select(r)},handleActionTap(t){let n=t.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`actionSheet`)?.handleAction(r)},handleGetPhoneNumber(e){this.triggerEvent(`getphonenumber`,e.detail)},handleChooseAvatar(e){this.triggerEvent(`chooseavatar`,e.detail)},handleContact(e){this.triggerEvent(`contact`,e.detail)}}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<
|
|
1
|
+
<root-portal wx:if="{{actionSheet.visible}}" enable="{{portal}}"><view class="{{portal ? themeMode : ''}}" style="{{portalStyle}}"><view id="{{actionSheet.rootProps.id}}" class="{{classes.root}}" data-scope="action-sheet" data-part="root" data-state="{{actionSheet.state}}" catchtouchmove="noop"><view id="{{actionSheet.backdropProps.id}}" class="{{classes.backdrop}}" data-scope="action-sheet" data-part="backdrop" data-state="{{actionSheet.open ? 'open' : 'closed'}}" aria-hidden="{{true}}" bindtap="handleBackdropTap"/><view id="{{actionSheet.contentProps.id}}" class="{{classes.content}}" data-scope="action-sheet" data-part="content" data-state="{{actionSheet.state}}" aria-role="dialog" aria-modal="{{true}}" aria-hidden="{{!actionSheet.open}}"><view wx:if="{{title || description || resolvedClose || slots.title || slots.description || slots.close}}" class="{{classes.header}}" data-scope="action-sheet" data-part="header"><view wx:if="{{resolvedClose || slots.close}}" id="{{actionSheet.closeTriggerProps.id}}" class="{{classes.closeTrigger}}" data-scope="action-sheet" data-part="close-trigger"><view wx:if="{{slots.close}}" class="{{classes.closeButton}}" aria-role="button" aria-label="Close" catchtap="handleCloseTriggerTap"><slot name="close"/></view><c-button wx:elif="{{resolvedClose}}" icon="{{resolvedClose.icon || ''}}" leading-icon="{{resolvedClose.leadingIcon || ''}}" trailing-icon="{{resolvedClose.trailingIcon || ''}}" label="{{resolvedClose.label || ''}}" loading="{{resolvedClose.loading || false}}" loading-icon="{{resolvedClose.loadingIcon || 'loading'}}" color="{{resolvedClose.color}}" variant="{{resolvedClose.variant}}" size="{{resolvedClose.size}}" disabled="{{resolvedClose.disabled || false}}" ui="{{resolvedClose.ui}}" className="{{resolvedClose.className}}" aria-label="Close" catch:tap="handleCloseTriggerTap"/></view><view wx:if="{{title}}" class="{{classes.title}}" data-scope="action-sheet" data-part="title">{{title}}</view><slot wx:else name="title"/><view wx:if="{{description}}" class="{{classes.description}}" data-scope="action-sheet" data-part="description">{{description}}</view><slot wx:else name="description"/></view><slot wx:else name="header"/><view class="{{classes.body}}" data-scope="action-sheet" data-part="body"><block wx:if="{{resolvedItems.length > 0}}"><button wx:for="{{resolvedItems}}" wx:key="key" class="{{item.disabled ? disabledClasses.item : classes.item}} {{item.className}}" style="{{item.style}}" data-scope="action-sheet" data-part="item" data-index="{{index}}" data-disabled="{{item.disabled ? 'true' : 'false'}}" data-loading="{{item.loading ? 'true' : 'false'}}" aria-role="button" aria-disabled="{{item.disabled ? 'true' : 'false'}}" aria-busy="{{item.loading ? 'true' : 'false'}}" plain="{{item.openType && item.disabled ? true : false}}" disabled="{{item.openType ? item.disabled : false}}" open-type="{{item.openType}}" hover-class="{{item.disabled || item.loading ? 'none' : classes.itemHover}}" catchtap="handleItemTap" bindgetphonenumber="handleGetPhoneNumber" bindchooseavatar="handleChooseAvatar" bindcontact="handleContact"><view class="{{classes.itemText}}" data-scope="action-sheet" data-part="item-text"><view class="{{item.disabled ? disabledClasses.itemTitle : classes.itemTitle}}" data-scope="action-sheet" data-part="item-title"><c-icon wx:if="{{item.loading}}" name="{{item.loadingIcon}}" className="{{classes.itemIcon}} {{classes.itemLoadingIcon}}" data-scope="action-sheet" data-part="item-icon" aria-hidden="true"/><c-icon wx:elif="{{item.icon}}" name="{{item.icon}}" className="{{classes.itemIcon}} {{item.destructive ? classes.itemIconDestructive : ''}}" data-scope="action-sheet" data-part="item-icon" aria-hidden="true"/><view class="{{classes.itemLabel}} {{item.destructive ? classes.itemLabelDestructive : ''}}" data-scope="action-sheet" data-part="item-label">{{item.label}}</view></view><view wx:if="{{item.description}}" class="{{item.disabled ? disabledClasses.itemDescription : classes.itemDescription}}" data-scope="action-sheet" data-part="item-description">{{item.description}}</view></view></button></block><slot wx:else/></view><block wx:if="{{resolvedActions.length > 0}}"><view class="{{classes.gap}}" data-scope="action-sheet" data-part="gap"/><view id="{{actionSheet.actionsProps.id}}" class="{{classes.actions}}" data-scope="action-sheet" data-part="actions"><block wx:for="{{resolvedActions}}" wx:key="index"><view class="{{classes.action}}" data-scope="action-sheet" data-part="action" data-index="{{item.index}}"><c-button data-index="{{item.index}}" block="{{true}}" label="{{item.label}}" icon="{{item.icon || ''}}" leading-icon="{{item.leadingIcon || ''}}" trailing-icon="{{item.trailingIcon || ''}}" loading="{{item.loading}}" loading-icon="{{item.loadingIcon}}" color="{{item.color}}" variant="{{item.variant}}" size="{{item.size}}" disabled="{{item.disabled}}" open-type="{{item.openType}}" ui="{{item.ui}}" className="{{item.className}}" catch:tap="handleActionTap" bindgetphonenumber="handleGetPhoneNumber" bindchooseavatar="handleChooseAvatar" bindcontact="handleContact"/></view></block></view></block><slot wx:else name="actions"/></view></view></view></root-portal>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../computed-behavior.js"),n=require("../../behaviors/
|
|
1
|
+
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../computed-behavior.js"),n=require("../../behaviors/theme.js"),r=require("../../behaviors/app.js"),i=require("../../behaviors/toast.js");var a={slots:{root:`relative flex flex-col min-h-screen box-border text-default transition-colors duration-300`,scaleWrapper:`w-full flex-1 flex flex-col box-border bg-default text-default origin-top transition-transform duration-300 ease-[cubic-bezier(0.32,0.72,0,1)]`,toaster:`fixed z-[100] pointer-events-none`},variants:{scaled:{true:{root:`bg-black`},false:{root:`bg-default`}}},defaultVariants:{scaled:!1}},o=`cui-top-bar`,s=`cui-bottom-bar`,c=`#${o}`,l=`#${s}`;function u(e){if(!e||typeof e.height!=`number`||e.height<=0)return 0;let t=Math.round(e.height),n=typeof e.top==`number`?Math.round(e.top):0,r=n>0?n+t:t;return Math.max(0,r)}function d(e){return!e||typeof e.height!=`number`||e.height<=0?0:Math.max(0,Math.round(e.height))}function f(){if(typeof getCurrentPages==`function`)try{let e=getCurrentPages(),t=e&&e[e.length-1];if(t&&typeof t.createSelectorQuery==`function`)return t.createSelectorQuery()}catch{}return typeof wx<`u`&&typeof wx.createSelectorQuery==`function`?wx.createSelectorQuery():null}function p(){if(typeof getCurrentPages==`function`)try{let e=getCurrentPages(),t=e&&e[e.length-1];if(t&&typeof t.getTabBar==`function`)return t.getTabBar()}catch{}return null}function m(e){if(!e)return null;if(typeof e.createSelectorQuery==`function`)return e.createSelectorQuery();if(typeof wx<`u`&&typeof wx.createSelectorQuery==`function`)try{return wx.createSelectorQuery().in(e)}catch{}return null}function h(e,t){if(!e||typeof e.select!=`function`){t(null);return}e.select(l).boundingClientRect(),e.exec(e=>{t(e?.[0]&&typeof e[0].height==`number`&&e[0].height>0?e[0]:null)})}function g(e,t){if(!e||typeof e.select!=`function`){t([]);return}e.select(c).boundingClientRect(),e.select(l).boundingClientRect(),e.exec(t)}function _(e,t){let n=f(),r=m(p()),i=null,a=null,o=!1,s=!r,c=()=>{o&&s&&t({topRect:i,bottomRect:a})};g(n,t=>{i=t?.[0]??null;let n=t?.[1]??null;if((!i||!n)&&e&&typeof e.createSelectorQuery==`function`)try{g(e.createSelectorQuery(),e=>{!i&&e?.[0]&&(i=e[0]),a||(a=n||e?.[1]||null),o=!0,c()});return}catch{}a||(a=n),o=!0,c()}),r&&h(r,e=>{e&&typeof e.height==`number`&&e.height>0&&(a=e),s=!0,c()})}function v(e){return`${Math.round(e*100)/100}px`}function y(e,t){return e?e===`both`||e===t:!1}function b(e){let t=e.metrics,n=e.safeArea||`none`,r=Math.max(0,Number(e.topInset)||0),i=Math.max(0,Number(e.bottomInset)||0),a=Number(e.topBarHeight||0)>0?Number(e.topBarHeight):Math.max(0,Number(e.detectedTopBarHeight||0)),o=Number(e.bottomBarHeight||0)>0?Number(e.bottomBarHeight):Math.max(0,Number(e.detectedBottomBarHeight||0)),s=y(n,`top`)?Math.max(0,t.safeTop):0,c=y(n,`bottom`)?Math.max(0,t.safeBottom):0,l=a>0?a:s,u=l+r,d=o>0?v(o):c>0?v(c):`env(safe-area-inset-bottom, 0px)`,f;return f=o>0?v(o+i):c>0?v(c+i):i>0?`calc(env(safe-area-inset-bottom, 0px) + ${v(i)})`:y(n,`bottom`)?`env(safe-area-inset-bottom, 0px)`:`0px`,{effectiveTopBarHeight:a,effectiveBottomBarHeight:o,bannerTopOffset:l,bannerBottomOffset:d,topOffset:u,bottomOffset:f,toastTopOffset:u,toastBottomOffset:f}}function x(e,t,n,r,i=``){return`--cui-status-bar-height:${v(t.statusBarHeight)};--cui-safe-top:${v(t.safeTop)};--cui-safe-bottom:${v(t.safeBottom)};--cui-menu-top:${v(t.menuTop)};--cui-menu-height:${v(t.menuHeight)};--cui-menu-inset:${v(t.menuInset)};--cui-nav-bar-height:${v(t.navBarHeight)};--cui-nav-height:${v(t.navHeight)};--cui-top-bar-height:${v(e.effectiveTopBarHeight)};--cui-bottom-bar-height:${v(e.effectiveBottomBarHeight)};--cui-top-inset:${v(n)};--cui-bottom-inset:${v(r)};--cui-top-offset:${v(e.topOffset)};--cui-bottom-offset:${e.bottomOffset};--cui-banner-top-offset:${v(e.bannerTopOffset)};--cui-banner-bottom-offset:${e.bannerBottomOffset};--cui-toast-top-offset:${v(e.toastTopOffset)};--cui-toast-bottom-offset:${e.toastBottomOffset};padding-top:var(--cui-top-offset);padding-bottom:var(--cui-bottom-offset);`+i}var S=e.tv(a),C=r.createAppHostBehavior({detectBars:_,extractTopBarHeight:u,extractBottomBarHeight:d}),w=i.createToastHostBehavior(),T=n.createAppThemeBehavior(),E={};r.setupAppRelations(E,`parent`),Component(t.createComponentOptions({behaviors:[r.cuiAppParentBehavior,C,T,w,t.computedBehavior],relations:E,slots:{default:!1},properties:{safeArea:{type:String,value:`none`},scaleBackground:{type:String,value:`bg-black`},scaleFactor:{type:Number,value:.94},ui:{type:Object,value:{}},className:{type:String,value:``},maxToasts:{type:Number,value:2},topBarHeight:{type:Number,value:0},bottomBarHeight:{type:Number,value:0},autoDetectBars:{type:Boolean,value:!0},colorMode:{type:String,value:``}},data:{toasts:[],scaled:!1,hostScaleFactor:.94,hostScaleBackground:``,topInset:0,bottomInset:0,detectedTopBarHeight:0,detectedBottomBarHeight:0,gestureScaleStyle:``,themeMode:`light`,themeCssVars:``},computed:{effectiveThemeMode(){let e=this.data.colorMode;return e===`dark`||e===`light`?e:this.data.themeMode||`light`},classes(){let t=this.data.scaled,n=S({scaled:t}),r=e.resolveSlots(n,this.data.ui,this.data.className),i=this.data.colorMode,a=i===`dark`||i===`light`?i:this.data.themeMode||`light`;if(r.root=`${r.root} ${a}`.trim(),t){let e=this.data.hostScaleBackground||this.data.scaleBackground;!e.startsWith(`#`)&&!e.startsWith(`rgb`)&&(r.root=`${r.root} ${e}`.trim())}return r},scaleWrapperStyle(){if(this.data.gestureScaleStyle)return this.data.gestureScaleStyle;if(!this.data.scaled)return``;let e=this.data.hostScaleFactor||this.data.scaleFactor,t=r.appMetricsSignal().windowWidth||375,n=`translate3d(0, calc(var(--cui-top-offset) + ${Math.max(8,Math.round((1-e)/2*t))}px), 0) scale3d(${e}, ${e}, 1)`;return`-webkit-transform: ${n}; transform: ${n};`},rootStyle(){let e=r.appMetricsSignal(),t=this.data.topInset,n=this.data.bottomInset,i=b({safeArea:this.data.safeArea,metrics:e,topBarHeight:this.data.topBarHeight,bottomBarHeight:this.data.bottomBarHeight,detectedTopBarHeight:this.data.detectedTopBarHeight,detectedBottomBarHeight:this.data.detectedBottomBarHeight,topInset:t,bottomInset:n}),a=this.data.hostScaleBackground||this.data.scaleBackground,o=x(i,e,t,n,this.data.scaled&&(a.startsWith(`#`)||a.startsWith(`rgb`))?`background-color:${a};`:``),s=this.data.themeCssVars||``;return s?o?`${o.endsWith(`;`)?o:`${o};`}${s}`:s:o}}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js"),r=require("../../behaviors/checkbox.js"),i=require("../../behaviors/form.js");var a=(t,n)=>e.itemPartId(t,`cbg`,`item`,n,`i`),
|
|
1
|
+
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js"),r=require("../../behaviors/checkbox.js"),i=require("../../behaviors/form.js");var a=t=>e.partId(t,`cbg`,`root`,`r`),o=(t,n)=>e.itemPartId(t,`cbg`,`item`,n,`i`),s=(t,n)=>e.itemPartId(t,`cbg`,`itemControl`,n,`c`),c=(t,n)=>e.itemPartId(t,`cbg`,`itemIndicator`,n,`ind`);function l(e){let{send:t,context:n,computed:r,prop:i,scope:l}=e,u=n.get(`value`),d=r(`isDisabled`),f=r(`isReadOnly`),p=r(`isInvalid`),m=e=>{let t=u.includes(e.value),n=!!(d||e.disabled);return{id:o(l,e.value),"data-state":t?`checked`:`unchecked`,"data-disabled":String(n),"data-readonly":String(f),"data-invalid":String(p)}},h=e=>{let t=u.includes(e.value),n=!!(d||e.disabled);return{id:s(l,e.value),"data-state":t?`checked`:`unchecked`,"data-disabled":String(n),"data-checked":String(t),"data-readonly":String(f),"data-invalid":String(p),"aria-role":`checkbox`,"aria-disabled":n,"aria-invalid":p,"aria-checked":t}},g=e=>{let t=u.includes(e.value),n=!!(d||e.disabled);return{id:c(l,e.value),"data-state":t?`checked`:`unchecked`,"data-disabled":String(n)}};return{value:u,setValue:e=>{t({type:`SET_VALUE`,value:e})},toggleValue:e=>{t({type:`TOGGLE_VALUE`,value:e})},selectAll:()=>{t({type:`SELECT_ALL`})},clear:()=>{t({type:`CLEAR`})},disabled:d,readOnly:f,invalid:p,items:i(`items`).map(e=>{let t=typeof e==`string`?{value:e}:e,n=t.value,r=u.includes(n),i=!!(d||t.disabled);return{value:n,disabled:i,checked:r,itemProps:m({value:n,disabled:i}),controlProps:h({value:n,disabled:i}),indicatorProps:g({value:n,disabled:i})}}),handleItemTap:e=>{t({type:`TOGGLE_VALUE`,value:e.value,checked:e.checked})},rootProps:{id:a(l)},getItemProps:m,getItemControlProps:h,getItemIndicatorProps:g}}var u={formContext:void 0,value:null,defaultValue:[],disabled:!1,readOnly:!1,required:!1,invalid:null,name:``,form:``,min:null,max:null,items:[]},d=e=>e!=null&&!Number.isNaN(Number(e))?Number(e):null,f=e.createMachine({props:({props:e})=>({...u,...e}),initialState:()=>`idle`,refs:({prop:e,context:t,computed:n,send:r})=>{let i=e(`value`),a=e(`defaultValue`);return{initialValue:Array.isArray(i)?i:Array.isArray(a)?a:[],formField:void 0,groupContext:{value:()=>t.get(`value`),disabled:()=>n(`isDisabled`),readOnly:()=>n(`isReadOnly`),invalid:()=>n(`isInvalid`),setValue:e=>r({type:`SET_VALUE`,value:e}),toggleValue:(e,t)=>r({type:`TOGGLE_VALUE`,value:e,checked:t})}}},context:({prop:t,bindable:n,getRefs:r})=>({value:n(()=>{let n=t(`value`),i=Array.isArray(n)?n:void 0,a=t(`defaultValue`);return{value:i,defaultValue:i??(Array.isArray(a)?a:[]),isEqual:e.isEqual,onChange:e=>{t(`onChange`)?.({value:e});let n=r().get(`formField`);n&&(n.emitInput(e),n.emitChange(e))}}}),invalid:n(()=>{let n=t(`invalid`);return{value:e.isNotEmpty(n)?!!n:void 0,defaultValue:!1}})}),computed:{...i.createFormFieldComputed(`checkbox-group`),isInvalid:({prop:e,refs:t,context:n,scope:r})=>!!(n.get(`invalid`)||i.hasFormFieldErrors(e,t,r,`checkbox-group`)),isDisabled:({prop:e,computed:t})=>!!(e(`disabled`)||t(`formDisabled`)||t(`fieldDisabled`)),isReadOnly:({prop:e,computed:t})=>!!(e(`readOnly`)||t(`formReadOnly`)),isInteractive:({computed:e})=>!e(`isDisabled`)&&!e(`isReadOnly`)},entry:[`setupFormField`],exit:[`cleanupFormField`],on:{SET_VALUE:{guard:`isInteractive`,actions:[`setValue`]},TOGGLE_VALUE:{guard:`canToggleValue`,actions:[`toggleValue`]},SELECT_ALL:{guard:`isInteractive`,actions:[`selectAll`]},CLEAR:{guard:`isInteractive`,actions:[`clearValue`]},SET_INVALID:{actions:[`setInvalid`]},RESET_VALUE:{target:`idle`,actions:[`resetValue`]}},states:{idle:{tags:[`idle`]}},implementations:{guards:{isInteractive:({computed:e})=>e(`isInteractive`),canToggleValue:({computed:e,event:t})=>e(`isInteractive`)&&t.type===`TOGGLE_VALUE`&&typeof t.value==`string`&&t.value!==``},actions:{setValue:({context:e,event:t})=>{`value`in t&&Array.isArray(t.value)&&e.set(`value`,t.value)},toggleValue:({context:e,prop:t,event:n})=>{if(n.type!==`TOGGLE_VALUE`)return;let r=e.get(`value`),i=n.value,a=r.includes(i),o=d(t(`min`)),s=d(t(`max`));if((n.checked===void 0?!a:n.checked)!==a){if(a){if(o!==null&&r.length<=o)return;e.set(`value`,r.filter(e=>e!==i))}else{if(s!==null&&r.length>=s)return;e.set(`value`,[...r,i])}}},selectAll:({context:e,prop:t})=>{let n=t(`items`).map(e=>typeof e==`string`?e:String(e.value??``)),r=d(t(`max`));e.set(`value`,r===null?n:n.slice(0,r))},clearValue:({context:e,prop:t})=>{let n=d(t(`min`));n!==null&&n>0||e.set(`value`,[])},resetValue:({context:e,refs:t,prop:n})=>{let r=n(`defaultValue`),i=Array.isArray(r)?r:[];e.set(`value`,t.get(`initialValue`)??i),e.set(`invalid`,!1)},setInvalid:({context:e,event:t})=>{`invalid`in t&&e.set(`invalid`,!!t.invalid)},setupFormField:({context:e,prop:t,refs:n,scope:r,computed:a})=>{i.setupFormFieldSync({component:t(`component`),getHost:()=>t(`formContext`),id:r.id??`checkbox-group`,getFormId:()=>t(`form`),getName:()=>t(`name`),getValue:()=>e.get(`value`),setValue:t=>{e.set(`value`,Array.isArray(t)?t:[])},resetValue:()=>{let r=t(`defaultValue`),i=Array.isArray(r)?r:[];e.set(`value`,n.get(`initialValue`)??i),e.set(`invalid`,!1)},focus:()=>{},getRules:()=>t(`rules`)??[],getValidateOn:()=>t(`validateOn`),isDisabled:()=>a(`isDisabled`)},n)},cleanupFormField:({refs:e})=>{i.cleanupFormFieldSync(e)}}}}),p=e.tv({slots:{root:`relative inline-flex flex-col gap-1.5`,fieldset:`flex flex-col gap-2`,legend:`block font-medium text-highlighted leading-snug select-none`},variants:{size:{xs:{legend:`text-xs`},sm:{legend:`text-xs`},md:{legend:`text-sm`},lg:{legend:`text-base`},xl:{legend:`text-lg`}},orientation:{vertical:{fieldset:`flex flex-col gap-2`},horizontal:{fieldset:`flex flex-row flex-wrap gap-4`}},required:{true:{legend:`after:content-['*'] after:ms-0.5 after:text-danger`}}},defaultVariants:{variant:`outline`,color:`primary`,size:`md`,orientation:`vertical`,disabled:!1,required:!1,invalid:!1}}),m=t.createMachineBehavior({machine:f,connect:l,key:`cCheckboxGroup`,plugins:[i.withFormField(),r.withCheckboxGroup()],exportApi:!0,exportApiKeys:[`value`,`setValue`,`toggleValue`,`selectAll`,`clear`]});Component(n.createComponentOptions({behaviors:[m,n.computedBehavior],slots:{default:!1,legend:!1},properties:t.createProperties(u,{color:{type:String,value:`primary`},size:{type:String,value:``},orientation:{type:String,value:`vertical`},variant:{type:String,value:`outline`},legend:{type:String,value:``},ui:{type:Object,value:{}},className:{type:String,value:``}}),computed:{resolvedColor(){return this.data.color||`primary`},resolvedVariant(){return this.data.variant||`outline`},resolvedSize(){return this.data.size||this.data.fieldSize||`md`},resolvedOrientation(){return this.data.orientation||`vertical`},resolvedItems(){let e=this.data.cCheckboxGroup?.items??[],t=this.data.items??[],n=this.data.resolvedSize,r=this.data.resolvedColor,i=this.data.resolvedVariant,a=this.data.ui||{};return e.map((e,o)=>{let s=t[o],c=typeof s==`string`?{value:s,label:s}:s??{};return{...e,label:String(c.label??e.value??``),description:String(c.description??``),color:c.color??r,variant:c.variant??i,size:c.size||n,ui:c.ui??a}})},classes(){let t=this.data.cCheckboxGroup,n=!!t?.invalid,r=!!t?.disabled,i=this.data.resolvedSize,a=this.data.resolvedColor,o=this.data.resolvedOrientation,s=this.data.resolvedVariant,c=!!this.data.required,l=this.data.ui,u=p({color:a,size:i,orientation:o,variant:s,disabled:r,required:c,invalid:n});return e.resolveSlots(u,l,this.data.className)}},methods:{handleItemTap(t){return e.getApi(this,`cCheckboxGroup`)?.handleItemTap?.(t.detail)}}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<view class="{{classes.root}}" data-scope="checkbox-group" data-part="root" aria-role="group" aria-disabled="{{cCheckboxGroup.disabled}}" aria-invalid="{{cCheckboxGroup.invalid}}" aria-required="{{required}}"><view wx:if="{{legend}}" class="{{classes.legend}}">{{legend}}</view><slot wx:else name="legend"/><view class="{{classes.fieldset}}"><block wx:if="{{resolvedItems.length > 0}}"><c-checkbox wx:for="{{resolvedItems}}" wx:key="value" value="{{item.value}}" label="{{item.label}}" description="{{item.description}}" disabled="{{item.disabled}}" checked="{{item.checked}}" variant="{{item.variant}}" color="{{item.color}}" size="{{item.size}}" ui="{{item.ui}}" bind:change="handleItemTap"/></block><slot/></view></view>
|
|
1
|
+
<view id="{{cCheckboxGroup.rootProps.id}}" class="{{classes.root}}" data-scope="checkbox-group" data-part="root" aria-role="group" aria-disabled="{{cCheckboxGroup.disabled}}" aria-invalid="{{cCheckboxGroup.invalid}}" aria-required="{{required}}"><view wx:if="{{legend}}" class="{{classes.legend}}">{{legend}}</view><slot wx:else name="legend"/><view class="{{classes.fieldset}}"><block wx:if="{{resolvedItems.length > 0}}"><c-checkbox wx:for="{{resolvedItems}}" wx:key="value" value="{{item.value}}" label="{{item.label}}" description="{{item.description}}" disabled="{{item.disabled}}" checked="{{item.checked}}" variant="{{item.variant}}" color="{{item.color}}" size="{{item.size}}" ui="{{item.ui}}" bind:change="handleItemTap"/></block><slot/></view></view>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js"),r=require("../../behaviors/app.js");var
|
|
1
|
+
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js"),r=require("../../behaviors/theme.js"),i=require("../../behaviors/app.js");var a=t=>e.partId(t,`dr`,`root`,`r`),o=t=>e.partId(t,`dr`,`content`,`c`),s=t=>e.partId(t,`dr`,`backdrop`,`bd`),c=t=>e.optPartId(t,`closeTrigger`),l=e=>`#${o(e)}`;function u(e){let{state:t,send:n,computed:r,context:i,scope:l}=e,u=r(`isOpen`),d=r(`isVisible`),f=t.get(),p=r(`placement`),m=i.get(`keyboardHeight`),h=m>0;return{open:u,visible:d,state:f,keyboardHeight:m,keyboardOpen:h,setOpen(e){n({type:e?`OPEN`:`CLOSE`})},openDrawer(){n({type:`OPEN`})},closeDrawer(){n({type:`CLOSE`})},handleBackdropTap(){n({type:`BACKDROP.TAP`})},handleCloseTriggerTap(){n({type:`CLOSE_TRIGGER.TAP`})},handleDragStart(e){n({type:`DRAG_START`,data:e})},handleDragMove(e){n({type:`DRAG_MOVE`,data:e})},handleDragEnd(e,t){n({type:`DRAG_END`,passed:e,data:t})},rootProps:{id:a(l),"data-state":f,"data-placement":p,"data-keyboard-open":String(h),"data-keyboard-height":m,hidden:!d,style:h?`padding-bottom: ${m}px; --keyboard-height: ${m}px;`:``},backdropProps:{id:s(l),"data-state":u?`open`:`closed`,"data-transition-state":f,"aria-hidden":!0,hidden:!d},contentProps:{id:o(l),"data-state":f,"data-placement":p,"data-keyboard-height":m,"aria-role":`dialog`,"aria-modal":!0,"aria-hidden":!u,hidden:!d,style:h?`--keyboard-height: ${m}px;`:``},closeTriggerProps:{id:c(l),"aria-label":`Close`}}}var d={open:null,defaultOpen:!1,placement:`bottom`,closeOnBackdropClick:!0,dismissible:!0,threshold:80,duration:300,shouldScaleBackground:!1,scaleFactor:.94,scaleBackground:`bg-black`},f=300;function p(){return typeof wx<`u`&&wx?wx:globalThis.wx}var m={OPEN:{target:`open`,actions:[`invokeOnOpen`]},TOGGLE:{target:`open`,actions:[`invokeOnOpen`]}},h=e.createMachine({props:({props:e})=>({...d,...e}),initialState:({prop:t})=>{let n=t(`open`);return(e.isNotNull(n)?n:t(`defaultOpen`))?`open`:`closed`},context:({bindable:e})=>({keyboardHeight:e(()=>({defaultValue:0}))}),computed:{isOpen:({state:e})=>e.hasTag(`open`),isVisible:({state:e})=>e.hasTag(`open`)||e.hasTag(`closing`),placement:({prop:e})=>e(`placement`)},effects:[`listenKeyboardHeight`],watch:({prop:t,state:n,track:r})=>{r([()=>t(`open`)],()=>{let r=t(`open`);if(!e.isNotNull(r))return;let i=!!r,a=n.hasTag(`open`);i&&!a?n.set(`open`):!i&&a&&n.set(`closing`)})},states:{closed:{tags:[`closed`],entry:[`resetKeyboardHeight`],on:m},open:{tags:[`open`],on:{CLOSE:{target:`closing`,actions:[`invokeOnClose`]},TOGGLE:{target:`closing`,actions:[`invokeOnClose`]},"BACKDROP.TAP":[{target:`closing`,guard:`closeOnBackdropClick`,actions:[`invokeOnBackdropTap`,`invokeOnClose`]},{actions:[`invokeOnBackdropTap`]}],"CLOSE_TRIGGER.TAP":{target:`closing`,actions:[`invokeOnCloseTriggerTap`,`invokeOnClose`]},DRAG_START:[{target:`dragging`,guard:`isDismissible`,actions:[`invokeOnDragStart`]},{actions:[`invokeOnDragStart`]}],DRAG_MOVE:{actions:[`invokeOnDrag`]},KEYBOARD_CHANGE:{actions:[`setKeyboardHeight`]}}},dragging:{tags:[`open`,`dragging`],on:{DRAG_MOVE:{actions:[`invokeOnDrag`]},DRAG_END:[{target:`closing`,guard:`dragPassed`,actions:[`invokeOnDragEnd`,`invokeOnClose`]},{target:`open`,actions:[`invokeOnDragEnd`]}],KEYBOARD_CHANGE:{actions:[`setKeyboardHeight`]},CLOSE:{target:`closing`,actions:[`invokeOnClose`]}}},closing:{tags:[`closing`],effects:[`waitForCloseAnimation`],on:{ANIMATION_END:{target:`closed`},...m}}},implementations:{guards:{closeOnBackdropClick:({prop:e})=>e(`closeOnBackdropClick`),isDismissible:({prop:e})=>e(`dismissible`),dragPassed:({event:e})=>e.type===`DRAG_END`&&e.passed===!0},actions:{invokeOnOpen:({prop:e})=>{e(`onOpenChange`)?.({open:!0})},invokeOnClose:({context:e,prop:t})=>{e.get(`keyboardHeight`)>0&&p()?.hideKeyboard?.(),t(`onOpenChange`)?.({open:!1}),t(`onClose`)?.()},invokeOnBackdropTap:({prop:e})=>{e(`onBackdropTap`)?.()},invokeOnCloseTriggerTap:({prop:e})=>{e(`onCloseTriggerTap`)?.()},invokeOnDragStart:({prop:e,event:t})=>{t.type===`DRAG_START`&&e(`onDragStart`)?.(t.data??{})},invokeOnDrag:({prop:e,event:t})=>{t.type===`DRAG_MOVE`&&e(`onDrag`)?.(t.data??{})},invokeOnDragEnd:({prop:e,event:t})=>{t.type===`DRAG_END`&&e(`onDragEnd`)?.(t.data??{passed:t.passed})},setKeyboardHeight:({context:e,event:t})=>{t.type===`KEYBOARD_CHANGE`&&e.set(`keyboardHeight`,Math.max(0,Number(t.height)||0))},resetKeyboardHeight:({context:e})=>{e.set(`keyboardHeight`,0)}},effects:{listenKeyboardHeight:({send:e})=>{let t=p();if(!t?.onKeyboardHeightChange)return;let n=t=>{e({type:`KEYBOARD_CHANGE`,height:Math.max(0,Number(t?.height)||0)})};return t.onKeyboardHeightChange(n),()=>{t.offKeyboardHeightChange?.(n)}},waitForCloseAnimation:({send:t,scope:n,prop:r})=>{let i,a=!1,o=()=>{a=!0,i!==void 0&&(clearTimeout(i),i=void 0)},s=e=>{a||(i=setTimeout(()=>{a||t({type:`ANIMATION_END`})},e))},c=r(`duration`);if(typeof c==`number`&&c>=0)return s(c),o;let u=n.component;return!u&&!e.isMiniApp()?(s(f),o):(e.queryAnimationDuration(l(n),u).then(e=>{a||s(e>0?e:f)}).catch(()=>{a||s(f)}),o)}}}}),g=e.tv({slots:{root:`fixed inset-0 z-drawer flex overflow-hidden overscroll-contain box-border transition-[padding-bottom] duration-150 ease-out`,backdrop:`fixed inset-0 bg-black/40 transition-opacity duration-300`,content:`relative z-10 flex bg-default shadow-2xl transition-transform duration-300 ease-out box-border overflow-hidden`,container:`flex flex-col min-w-0 min-h-0 overflow-hidden`,grabber:`flex items-center justify-center cursor-grab active:cursor-grabbing shrink-0 box-border`,grabberBar:`rounded-full bg-accented`,header:`flex items-center justify-between px-4 py-3 border-b border-muted shrink-0 box-border w-full`,headerContent:`flex-1 min-w-0`,closeTrigger:`inline-flex items-center justify-center w-8 h-8 rounded-full text-dimmed hover:text-default hover:bg-elevated transition-colors shrink-0`,closeButton:`p-0 w-full h-full rounded-full text-inherit`,closeIcon:`w-4 h-4`,body:`min-h-0 w-full box-border overflow-y-auto px-4 pt-3 pb-6 text-sm text-toned overscroll-contain`,footer:`flex items-center justify-end gap-2 px-4 py-3 border-t border-muted shrink-0 box-border w-full pb-[calc(var(--spacing)_*_3_+_env(safe-area-inset-bottom))]`},variants:{placement:{bottom:{root:`items-end justify-center`,content:`flex-col w-full max-h-[85vh] rounded-t-xl`,container:`w-full flex-initial`,body:`flex-initial max-h-[60vh]`,grabber:`w-full py-2.5`,grabberBar:`w-12 h-1.5`},top:{root:`items-start justify-center`,content:`flex-col w-full max-h-[85vh] rounded-b-xl`,container:`w-full flex-initial`,body:`flex-initial max-h-[60vh]`,grabber:`w-full py-2.5`,grabberBar:`w-12 h-1.5`,header:`pt-[calc(var(--spacing)_*_3_+_env(safe-area-inset-top))]`,footer:`pb-3`},left:{root:`items-center justify-start`,content:`flex-row h-full w-4/5 max-w-sm md:max-w-md rounded-none`,container:`flex-1 h-full`,body:`flex-1 h-0`,grabber:`h-full px-2.5`,grabberBar:`w-1.5 h-12`,header:`pt-[calc(var(--spacing)_*_3_+_env(safe-area-inset-top))]`},right:{root:`items-center justify-end`,content:`flex-row h-full w-4/5 max-w-sm md:max-w-md rounded-none`,container:`flex-1 h-full`,body:`flex-1 h-0`,grabber:`h-full px-2.5`,grabberBar:`w-1.5 h-12`,header:`pt-[calc(var(--spacing)_*_3_+_env(safe-area-inset-top))]`}},open:{true:{backdrop:`cui-drawer-backdrop-enter opacity-100 pointer-events-auto`,content:`cui-drawer-open`},false:{backdrop:`opacity-0 pointer-events-none`}},keyboardOpen:{true:{footer:`pb-3`}}},compoundVariants:[{placement:`bottom`,keyboardOpen:!0,class:{content:`max-h-[calc(100%_-_env(safe-area-inset-top))]`,body:`max-h-[calc(100vh_-_var(--keyboard-height,0px)_-_env(safe-area-inset-top,0px)_-_10rem)]`}},{placement:`top`,keyboardOpen:!0,class:{content:`max-h-full`,body:`max-h-[calc(100vh_-_var(--keyboard-height,0px)_-_env(safe-area-inset-top,0px)_-_10rem)]`}},{placement:`bottom`,open:!0,class:{content:`cui-drawer-enter-bottom`}},{placement:`top`,open:!0,class:{content:`cui-drawer-enter-top`}},{placement:`left`,open:!0,class:{content:`cui-drawer-enter-left`}},{placement:`right`,open:!0,class:{content:`cui-drawer-enter-right`}},{placement:`bottom`,open:!1,class:{content:`cui-drawer-closed-bottom`}},{placement:`top`,open:!1,class:{content:`cui-drawer-closed-top`}},{placement:`left`,open:!1,class:{content:`cui-drawer-closed-left`}},{placement:`right`,open:!1,class:{content:`cui-drawer-closed-right`}}],defaultVariants:{placement:`bottom`,open:!0,keyboardOpen:!1}}),_=t.createMachineBehavior({machine:h,connect:u,key:`drawer`,exportApi:!0,exportApiKeys:[`open`,`visible`,`setOpen`,`openDrawer`,`closeDrawer`],syncProps:[`shouldScaleBackground`,`scaleFactor`,`scaleBackground`],plugins:[i.withAppScale({idPrefix:`drawer`})]}),v=typeof Behavior<`u`?r.createAppThemeBehavior():{};Component(n.createComponentOptions({behaviors:[v,_,n.computedBehavior],slots:{default:!1,header:!1,close:!1,footer:!1},computed:{portalStyle(){return this.data.portal&&this.data.themeCssVars||``},resolvedClose(){let t=this.data.classes;return e.resolveTriggerButtonProps(this.data.close,{icon:`close`,color:`neutral`,variant:`ghost`,size:`xs`,ui:{icon:t?.closeIcon??``}},t?.closeButton)},classes(){let t=this.data.drawer,n=this.data.placement,r=!!t?.open,i=this.data.ui,a=g({placement:n,open:r,keyboardOpen:!!t?.keyboardOpen});return e.resolveSlots(a,i,this.data.className)}},properties:t.createProperties(d,{close:{type:null,value:!0},portal:{type:Boolean,value:!0},ui:{type:Object,value:{}},className:{type:String,value:``}}),methods:{noop(){},handleBackdropTap(){e.getApi(this,`drawer`)?.handleBackdropTap()},handleCloseTap(){e.getApi(this,`drawer`)?.handleCloseTriggerTap()},handleTouchStart(t){e.getApi(this,`drawer`)?.handleDragStart(t||{})},handleTouchMove(t){e.getApi(this,`drawer`)?.handleDragMove(t||{})},handleTouchEnd(t){let n=t?t.passed:!1;e.getApi(this,`drawer`)?.handleDragEnd(n,t||{passed:!1})}}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<wxs src="../../wxs/drawer-gesture.wxs" module="gesture"/><view id="{{drawer.rootProps.id}}" class="{{ classes.root }}" data-scope="drawer" data-part="root" data-state="{{drawer.state}}" data-placement="{{placement}}"
|
|
1
|
+
<wxs src="../../wxs/drawer-gesture.wxs" module="gesture"/><root-portal wx:if="{{drawer.state !== 'closed'}}" enable="{{portal}}"><view class="{{portal ? themeMode : ''}}" style="{{portalStyle}}"><view id="{{drawer.rootProps.id}}" class="{{ classes.root }}" style="{{drawer.rootProps.style}}" data-scope="drawer" data-part="root" data-state="{{drawer.state}}" data-placement="{{placement}}" data-keyboard-open="{{drawer.rootProps['data-keyboard-open']}}"><view id="{{drawer.backdropProps.id}}" class="{{ classes.backdrop }}" data-scope="drawer" data-part="backdrop" data-state="{{drawer.open ? 'open' : 'closed'}}" aria-hidden="{{true}}" bindtap="handleBackdropTap" catchtouchmove="{{gesture.preventTouchMove}}"/><view id="{{drawer.contentProps.id}}" class="{{ classes.content }}" data-scope="drawer" data-part="content" data-state="{{drawer.state}}" data-placement="{{placement}}" aria-role="dialog" aria-modal="{{true}}" aria-hidden="{{!drawer.open}}" data-keyboard-height="{{drawer.contentProps['data-keyboard-height']}}" style="{{drawer.contentProps.style}}"><view wx:if="{{placement === 'bottom' || placement === 'right'}}" class="{{ classes.grabber }}" data-scope="drawer" data-part="grabber" data-placement="{{placement}}" data-dismissible="{{dismissible}}" data-threshold="{{threshold}}" data-duration="{{duration}}" data-content-id="{{drawer.contentProps.id}}" data-backdrop-id="{{drawer.backdropProps.id}}" data-should-scale="{{shouldScaleBackground}}" data-scale-factor="{{scaleFactor}}" catchtouchstart="{{gesture.onTouchStart}}" catchtouchmove="{{gesture.onTouchMove}}" catchtouchend="{{gesture.onTouchEnd}}" catchtouchcancel="{{gesture.onTouchEnd}}"><view class="{{ classes.grabberBar }}"/></view><view class="{{ classes.container }}" data-scope="drawer" data-part="container"><view class="{{ classes.header }}" catchtouchmove="{{gesture.preventTouchMove}}"><view class="{{ classes.headerContent }}"><slot name="header"/></view><view wx:if="{{resolvedClose || slots.close}}" class="{{ classes.closeTrigger }}" data-scope="drawer" data-part="close-trigger"><view wx:if="{{slots.close}}" class="{{ classes.closeButton }}" aria-role="button" aria-label="Close" catchtap="handleCloseTap"><slot name="close"/></view><c-button wx:elif="{{resolvedClose}}" icon="{{resolvedClose.icon || ''}}" leading-icon="{{resolvedClose.leadingIcon || ''}}" trailing-icon="{{resolvedClose.trailingIcon || ''}}" label="{{resolvedClose.label || ''}}" loading="{{resolvedClose.loading || false}}" loading-icon="{{resolvedClose.loadingIcon || 'loading'}}" color="{{resolvedClose.color}}" variant="{{resolvedClose.variant}}" size="{{resolvedClose.size}}" disabled="{{resolvedClose.disabled || false}}" ui="{{resolvedClose.ui}}" className="{{resolvedClose.className}}" aria-label="Close" catch:tap="handleCloseTap"/></view></view><scroll-view scroll-y scroll-x="{{false}}" class="{{ classes.body }}" enhanced="{{true}}" bounces="{{false}}" show-scrollbar="{{false}}"><slot/></scroll-view><view wx:if="{{slots.footer}}" class="{{ classes.footer }}" catchtouchmove="{{gesture.preventTouchMove}}"><slot name="footer"/></view></view><view wx:if="{{placement === 'top' || placement === 'left'}}" class="{{ classes.grabber }}" data-scope="drawer" data-part="grabber" data-placement="{{placement}}" data-dismissible="{{dismissible}}" data-threshold="{{threshold}}" data-duration="{{duration}}" data-content-id="{{drawer.contentProps.id}}" data-backdrop-id="{{drawer.backdropProps.id}}" data-should-scale="{{shouldScaleBackground}}" data-scale-factor="{{scaleFactor}}" catchtouchstart="{{gesture.onTouchStart}}" catchtouchmove="{{gesture.onTouchMove}}" catchtouchend="{{gesture.onTouchEnd}}" catchtouchcancel="{{gesture.onTouchEnd}}"><view class="{{ classes.grabberBar }}"/></view></view></view></view></root-portal>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js"),r=require("../../behaviors/form.js");var i=t=>e.partId(t,`fu`,`root`,`r`),a=t=>e.partId(t,`fu`,`dropzone`,`dz`),o=t=>e.partId(t,`fu`,`fileList`,`fl`),s=(t,n)=>e.itemPartId(t,`fu`,`file`,n,`f`),c=(t,n)=>e.itemPartId(t,`fu`,`fileRemove`,n,`rm`),l=(t,n)=>e.itemPartId(t,`fu`,`filePreview`,n,`pv`),u=/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico|tiff|avif)$/i,d=/\.(mp4|mov|m4v|avi|mkv|webm|flv|wmv|3gp|ts)$/i,f=/\.(mp3|wav|m4a|aac|ogg|flac|wma|aiff|alac|amr|mid|midi|opus)$/i,p=/\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|md|zip|rar|7z)$/i;function m(e){if(!e)return``;let t=e.split(`?`)[0]?.split(`#`)[0]??``,n=t.lastIndexOf(`.`);return n===-1?``:t.slice(n).toLowerCase()}function h(e,t,n){return e===`image`||e?.startsWith(`image/`)?!0:u.test((t||n||``).split(`?`)[0]||``)}function g(e,t,n){return e===`video`||e?.startsWith(`video/`)?!0:d.test((t||n||``).split(`?`)[0]||``)}function _(e,t,n){return e===`audio`||e?.startsWith(`audio/`)?!0:f.test((t||n||``).split(`?`)[0]||``)}function v(e){return e?p.test(e)||/(^|,)\s*(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|zip|rar|csv)\s*(,|$)/i.test(e):!1}function y(e){return h(e.type,e.path,e.name)?`image`:g(e.type,e.path,e.name)?`video`:_(e.type,e.path,e.name)?`audio`:`file`}function b(e,t=y(e)){return e.thumb||(t===`image`?e.path:void 0)}function x(e,t){return t?`${e.id||``}::${t}`:``}var S={jpg:`image/jpeg`,jpeg:`image/jpeg`,png:`image/png`,gif:`image/gif`,webp:`image/webp`,svg:`image/svg+xml`,mp4:`video/mp4`,mov:`video/quicktime`,webm:`video/webm`,mp3:`audio/mpeg`,wav:`audio/wav`,m4a:`audio/aac`,aac:`audio/aac`,ogg:`audio/ogg`,flac:`audio/flac`,pdf:`application/pdf`,doc:`application/msword`,docx:`application/msword`,xls:`application/vnd.ms-excel`,xlsx:`application/vnd.ms-excel`,zip:`application/zip`,txt:`text/plain`};function C(e,t=`application/octet-stream`){let n=m(e).slice(1);return n&&S[n]||t}function w(e,t=1){if(e<=0)return`0 B`;let n=1024,r=t<0?0:t,i=[`B`,`KB`,`MB`,`GB`,`TB`],a=Math.floor(Math.log(e)/Math.log(n)),o=Math.min(a,i.length-1);return`${parseFloat((e/n**o).toFixed(r))} ${i[o]}`}function T(e){return e?(Array.isArray(e)?e:e.split(`,`).map(e=>e.trim())).map(e=>e.replace(/^\./,``).trim().toLowerCase()).filter(Boolean):[]}function E(e,t){if(!t)return!0;let n=Array.isArray(t)?t:t.split(`,`).map(e=>e.trim().toLowerCase());if(n.length===0)return!0;let r=(e.name||``).toLowerCase(),i=(e.path||``).toLowerCase(),a=(e.type||``).toLowerCase(),o=C(r||i,``).toLowerCase();return n.some(e=>{if(!e)return!0;let t=e.trim().toLowerCase();if(t===`*`||t===`*/*`)return!0;if(t.endsWith(`/*`)){let e=t.slice(0,-2);return a.startsWith(e)||o.startsWith(e)||e===`image`&&h(a,i,r)||e===`video`&&g(a,i,r)||e===`audio`&&_(a,i,r)}if(t.includes(`/`)){if(a===t||o===t)return!0;let e=t.split(`/`)[1];return!!(e&&(r.endsWith(`.${e}`)||i.endsWith(`.${e}`)||e===`jpeg`&&(r.endsWith(`.jpg`)||i.endsWith(`.jpg`))))}let n=t.startsWith(`.`)?t:`.${t}`;return r.endsWith(n)||i.endsWith(n)})}function D(e,t={}){let{maxSize:n=1/0,minSize:r=0,accept:i,maxFiles:a=10,multiple:o=!0,currentCount:s=0}=t,c=[],l=[];for(let t of e){let e=t.size??0;e>n?l.push({file:t,reason:`size-too-large`}):e<r?l.push({file:t,reason:`size-too-small`}):i&&!E(t,i)?l.push({file:t,reason:`type-not-allowed`}):o&&s+c.length>=a?l.push({file:t,reason:`max-files-exceeded`}):c.push(t)}if(!o&&c.length>1){let[e,...t]=c;c.length=0,e&&c.push(e);for(let e of t)l.push({file:e,reason:`max-files-exceeded`})}return{accepted:c,rejected:l}}function O(e){let{state:t,send:n,context:r,computed:u,prop:d,scope:f}=e,p=t.get(),m=r.get(`files`),h=r.get(`failedThumbs`),g=u(`isDisabled`),_=u(`isReadOnly`),v=u(`isInvalid`),S=u(`isInteractive`),C=u(`isMaxFiles`),T=u(`hasFiles`),E=u(`fileCount`),D=u(`isUploading`),O=d(`progress`),k=d(`maxFiles`),A=C?`Maximum ${k} files uploaded`:`Upload files, ${E} of ${k} files selected`,j=m.map((e,t)=>{let n=y(e),r=e.id||String(t),i=e.progress??O??null,a=b(e,n),o=x(e,a),u=!!(o&&h.includes(o));return Object.assign({},e,{index:t,thumb:a,thumbFailed:u,progress:i,formattedSize:w(e.size),fileType:n,itemProps:{id:s(f,r),"aria-role":`listitem`},removeProps:{id:c(f,r),"aria-role":`button`,"aria-label":`Remove ${e.name}`},previewProps:{id:l(f,r),"aria-role":`button`,"aria-label":`Preview ${e.name}`}})}),M=()=>new Promise(e=>{n({type:`CHOOSE`,onDone:e})});return{state:p,files:j,fileCount:E,hasFiles:T,isMaxFiles:C,isUploading:D,progress:O,disabled:g,readOnly:_,invalid:v,interactive:S,rootProps:{id:i(f),"data-state":p,"data-disabled":String(g),"data-readonly":String(_),"data-invalid":String(v),"data-max":String(C),"aria-role":`group`,"aria-disabled":g,"aria-invalid":v},dropzoneProps:{id:a(f),"data-state":p,"data-disabled":String(g||C),"data-readonly":String(_),"data-max":String(C),"aria-role":`button`,"aria-disabled":g||C,"aria-busy":D,"aria-label":A},fileListProps:{id:o(f),"aria-role":`list`,"aria-label":`Uploaded files`},chooseFiles:M,handleDropzoneTap:()=>M(),addFiles:e=>{n({type:`PICKED_RAW`,files:e})},removeFile:e=>{n({type:`REMOVE_FILE`,idOrIndex:e})},handleRemove:e=>{e>=0&&n({type:`REMOVE_FILE`,index:e})},previewFile:e=>{n({type:`PREVIEW_FILE`,idOrIndex:e})},handlePreview:e=>{e>=0&&n({type:`PREVIEW_FILE`,idOrIndex:e})},handleFileClick:e=>{e>=0&&n({type:`FILE_CLICK`,index:e})},handleImageError:e=>{e>=0&&n({type:`IMAGE_ERROR`,index:e})},clearFiles:()=>{n({type:`CLEAR_FILES`})},setFiles:e=>{n({type:`SET_VALUE`,value:e})}}}var k={formContext:void 0,value:null,defaultValue:[],name:``,form:``,invalid:null,disabled:!1,readOnly:!1,multiple:!0,maxFiles:10,maxSize:1/0,minSize:0,accept:``,mode:`auto`,sourceType:[`album`,`camera`],mediaType:[`image`,`video`],sizeType:[`original`,`compressed`],camera:`back`,maxDuration:60,interactive:!0,uploading:!1,progress:null},A=()=>globalThis.wx,j=0;function M(){return j+=1,`file-${Date.now()}-${j}`}var N=null,P=null;function F(){if(N){try{N.stop(),N.destroy()}catch{}N=null,P=null}}function I(e,t){if(typeof t.createInnerAudioContext!=`function`)return;if(N&&P===e.path){N.paused?(N.play(),t.showToast?.({title:`Playing ${e.name}`,icon:`none`,duration:1500})):(N.pause(),t.showToast?.({title:`Paused ${e.name}`,icon:`none`,duration:1500}));return}F();let n=t.createInnerAudioContext();N=n,P=e.path||``,n.src=e.path,n.autoplay=!0,n.onPlay(()=>{t.showToast?.({title:`Playing ${e.name}`,icon:`none`,duration:1500})}),n.onEnded(()=>{P=null}),n.onError(e=>{console.warn(`[file-upload] Audio playback error:`,e),t.showToast?.({title:`Audio playback error`,icon:`none`,duration:2e3})}),n.play()}function L(e){return e.map(e=>{let t=e??{},n=t.tempFilePath||t.path||``,r=t.name||n.split(`/`).pop()||`file-${Date.now()}`,i=t.size??0,a=t.fileType||t.type||(h(void 0,n,r)?`image`:g(void 0,n,r)?`video`:_(void 0,n,r)?`audio`:`file`),o=t.thumbTempFilePath||(h(a,n,r)?n:void 0);return{id:M(),name:r,size:i,type:a,path:n,thumb:o,duration:t.duration,width:t.width,height:t.height,status:`idle`}})}function R(e,t,n,r){if(!r)return t.slice(0,1);let i=Math.max(0,n-e.length);return i<=0?e:[...e,...t.slice(0,i)]}var z=e.createMachine({props:({props:e})=>({...k,...e}),initialState:({prop:e})=>e(`uploading`)?`uploading`:`idle`,refs:({prop:e})=>({initialFiles:e(`value`)??e(`defaultValue`),formField:void 0,chooseDone:void 0}),context:({prop:t,bindable:n,getRefs:r})=>({files:n(()=>{let n=t(`value`),i=t(`defaultValue`);return{value:e.isNotNull(n)?n:void 0,defaultValue:n??i,isEqual:e.isEqual,onChange:e=>{t(`onChange`)?.({value:e});let n=r().get(`formField`);n&&(n.emitInput(e),n.emitChange(e))}}}),invalid:n(()=>{let n=t(`invalid`);return{value:e.isNotEmpty(n)?!!n:void 0,defaultValue:!1}}),failedThumbs:n(()=>({defaultValue:[]}))}),computed:{...r.createFormFieldComputed(`fileUpload`),isInvalid:({prop:e,refs:t,context:n,scope:i})=>!!(n.get(`invalid`)||r.hasFormFieldErrors(e,t,i,`fileUpload`)),isDisabled:({prop:e,computed:t})=>!!(t(`formDisabled`)||t(`fieldDisabled`)||e(`disabled`)),isReadOnly:({prop:e,computed:t})=>!!(e(`readOnly`)||t(`formReadOnly`)),isInteractive:({computed:e,prop:t})=>!e(`isDisabled`)&&!e(`isReadOnly`)&&t(`interactive`),isMaxFiles:({context:e,prop:t})=>e.get(`files`).length>=t(`maxFiles`),hasFiles:({context:e})=>e.get(`files`).length>0,fileCount:({context:e})=>e.get(`files`).length,isUploading:({prop:e,state:t})=>e(`uploading`)||t.matches(`uploading`)},watch:({prop:e,state:t,track:n})=>{n([()=>e(`uploading`)],()=>{let n=e(`uploading`);n&&!t.matches(`uploading`)?t.set(`uploading`):!n&&t.matches(`uploading`)&&t.set(`idle`)})},entry:[`setupFormField`],exit:[`cleanupFormField`,`cleanupAudio`,`flushChooseCallback`],on:{SET_VALUE:{actions:[`setValue`]},ADD_FILES:{guard:`canAddFiles`,actions:[`addFiles`]},PICKED_RAW:{guard:`canAddFiles`,actions:[`ingestPickedFiles`]},REMOVE_FILE:{guard:`isInteractive`,actions:[`removeFile`]},PREVIEW_FILE:{actions:[`previewFile`]},FILE_CLICK:{actions:[`clickFile`]},IMAGE_ERROR:{actions:[`markImageError`]},CLEAR_FILES:{guard:`isInteractive`,actions:[`cleanupAudio`,`clearFiles`]},SET_UPLOADING:{actions:[`setUploading`]}},states:{idle:{tags:[`idle`],on:{CHOOSE:[{guard:`canChoose`,target:`choosing`,actions:[`setChooseCallback`]},{actions:[`resolveChooseFromEvent`]}]}},choosing:{tags:[`busy`],effects:[`pickWeChatFiles`],exit:[`flushChooseCallback`],on:{CHOOSE:{actions:[`resolveChooseFromEvent`]},CHOOSE_COMPLETE:{target:`idle`}}},uploading:{tags:[`busy`],on:{CHOOSE:{actions:[`resolveChooseFromEvent`]}}}},implementations:{guards:{isInteractive:({computed:e})=>e(`isInteractive`),canChoose:({computed:e})=>e(`isInteractive`)&&!e(`isMaxFiles`),canAddFiles:({computed:e})=>e(`isInteractive`)&&!e(`isMaxFiles`)},effects:{pickWeChatFiles:({prop:e,context:t,send:n})=>{let r=A();if(!r){n({type:`CHOOSE_COMPLETE`});return}let i=e(`multiple`),a=e(`maxFiles`),o=e(`accept`),s=e(`mode`),c=t.get(`files`),l=i?Math.max(1,a-c.length):1,u=v((Array.isArray(o)?o.join(`,`):o).toLowerCase());if((s===`messageFile`||s===`auto`&&u)&&typeof r.chooseMessageFile==`function`){let e=T(o);r.chooseMessageFile({count:l,type:e.length>0?`file`:`all`,extension:e.length>0?e:void 0,success:e=>{n({type:`PICKED_RAW`,files:e.tempFiles??[]})},fail:()=>{},complete:()=>{n({type:`CHOOSE_COMPLETE`})}});return}if(typeof r.chooseMedia==`function`){r.chooseMedia({count:l,mediaType:e(`mediaType`),sourceType:e(`sourceType`),maxDuration:e(`maxDuration`),sizeType:e(`sizeType`),camera:e(`camera`),success:e=>{n({type:`PICKED_RAW`,files:e.tempFiles??[]})},fail:()=>{},complete:()=>{n({type:`CHOOSE_COMPLETE`})}});return}if(typeof r.chooseMessageFile==`function`){r.chooseMessageFile({count:l,type:`all`,success:e=>{n({type:`PICKED_RAW`,files:e.tempFiles??[]})},fail:()=>{},complete:()=>{n({type:`CHOOSE_COMPLETE`})}});return}n({type:`CHOOSE_COMPLETE`})}},actions:{setChooseCallback:({refs:e,event:t})=>{t.type===`CHOOSE`&&e.set(`chooseDone`,t.onDone)},resolveChooseFromEvent:({event:e})=>{e.type===`CHOOSE`&&e.onDone?.()},flushChooseCallback:({refs:e})=>{let t=e.get(`chooseDone`);e.set(`chooseDone`,void 0),t&&queueMicrotask(t)},setValue:({context:e,event:t})=>{t.type===`SET_VALUE`&&(e.set(`files`,t.value),e.set(`failedThumbs`,[]))},addFiles:({context:e,event:t,prop:n})=>{if(t.type!==`ADD_FILES`)return;let r=R(e.get(`files`),t.files,n(`maxFiles`),n(`multiple`));e.set(`files`,r)},ingestPickedFiles:({context:e,event:t,prop:n})=>{if(t.type!==`PICKED_RAW`)return;let r=e.get(`files`),i=n(`maxFiles`),a=n(`multiple`),{accepted:o,rejected:s}=D(L(t.files),{maxSize:n(`maxSize`),minSize:n(`minSize`),accept:n(`accept`),maxFiles:i,multiple:a,currentCount:r.length});if(s.length>0&&n(`onReject`)?.({files:s}),o.length>0){let t=R(r,o,i,a);e.set(`files`,t),n(`onAccept`)?.({files:o})}},removeFile:({context:e,event:t,prop:n})=>{if(t.type!==`REMOVE_FILE`)return;let r=e.get(`files`),i=t.index===void 0?typeof t.idOrIndex==`number`?t.idOrIndex:r.findIndex(e=>e.id===t.idOrIndex):t.index;if(i<0||i>=r.length)return;let a=r[i];a?.path&&a.path===P&&F();let o=r.filter((e,t)=>t!==i);if(e.set(`files`,o),a){let t=x(a,b(a));if(t){let n=e.get(`failedThumbs`);n.includes(t)&&e.set(`failedThumbs`,n.filter(e=>e!==t))}n(`onRemove`)?.({file:a,index:i})}},previewFile:({context:e,event:t,prop:n})=>{if(t.type!==`PREVIEW_FILE`)return;let r=e.get(`files`),i=typeof t.idOrIndex==`number`?t.idOrIndex:r.findIndex(e=>e.id===t.idOrIndex);if(i<0)return;let a=r[i];if(!a)return;n(`onPreview`)?.({file:a,index:i});let o=A();if(!o||!a.path)return;let s=y(a);if(s===`image`){if(typeof o.previewImage==`function`){let e=r.filter(e=>y(e)===`image`&&e.path).map(e=>e.path);o.previewImage({current:a.path,urls:e.length>0?e:[a.path]})}}else s===`video`?typeof o.previewMedia==`function`&&o.previewMedia({current:0,sources:[{url:a.path,type:`video`,poster:a.thumb||``}],fail:e=>{console.warn(`[file-upload] previewMedia failed:`,e)}}):s===`audio`?I(a,o):typeof o.openDocument==`function`&&o.openDocument({filePath:a.path,showMenu:!0,fail:e=>{console.warn(`[file-upload] openDocument failed:`,e)}})},clickFile:({context:e,event:t,prop:n})=>{if(t.type!==`FILE_CLICK`)return;let r=e.get(`files`)[t.index];r&&n(`onFileClick`)?.({file:r,index:t.index})},markImageError:({context:e,event:t})=>{if(t.type!==`IMAGE_ERROR`)return;let n=e.get(`files`)[t.index];if(!n)return;let r=x(n,b(n));if(!r)return;let i=e.get(`failedThumbs`);i.includes(r)||e.set(`failedThumbs`,[...i,r])},clearFiles:({context:e})=>{e.set(`files`,[]),e.set(`failedThumbs`,[])},cleanupAudio:()=>{F()},setUploading:({state:e,event:t})=>{t.type===`SET_UPLOADING`&&(t.uploading&&!e.matches(`uploading`)?e.set(`uploading`):!t.uploading&&e.matches(`uploading`)&&e.set(`idle`))},setupFormField:({prop:e,context:t,computed:n,refs:i,scope:a})=>{r.setupFormFieldSync({component:e(`component`),getHost:()=>e(`formContext`),id:a.id??`file-upload`,getFormId:()=>e(`form`),getName:()=>e(`name`),getValue:()=>t.get(`files`),setValue:e=>{t.set(`files`,Array.isArray(e)?e:[])},resetValue:()=>{t.set(`files`,e(`defaultValue`))},getRules:()=>e(`rules`)??[],getValidateOn:()=>e(`validateOn`),isDisabled:()=>n(`isDisabled`)},i)},cleanupFormField:({refs:e})=>r.cleanupFormFieldSync(e)}}}),B=[`primary`,`secondary`,`danger`,`success`,`warning`,`info`],V={slots:{root:`relative flex flex-col gap-3 w-full`,dropzone:`relative flex flex-col items-center justify-center text-center border-2 border-dashed rounded-md transition-colors cursor-pointer select-none`,icon:`text-dimmed mb-2 shrink-0 flex items-center justify-center`,iconInner:`w-full h-full`,loadingIcon:`w-full h-full animate-spin`,content:`flex flex-col items-center justify-center gap-1`,title:`font-medium text-highlighted`,description:`text-muted`,fileList:`flex flex-col gap-2 w-full`,file:`relative flex items-center gap-3 p-3 rounded-md border border-default bg-default shadow-xs transition-colors`,fileLeading:`relative flex items-center justify-center shrink-0 rounded-lg overflow-hidden bg-elevated`,fileImage:`absolute inset-0 w-full h-full rounded-lg object-cover block`,fileContent:`flex flex-col min-w-0 flex-1 text-left`,fileName:`font-medium text-highlighted truncate`,fileSize:`text-muted shrink-0`,fileTrailing:`flex items-center shrink-0 ml-auto gap-1`,fileIcon:`w-5 h-5 text-dimmed`,fileRemove:`flex items-center justify-center rounded-lg text-dimmed hover:text-default transition-colors p-1`,fileRemoveIcon:`w-4 h-4`,fileProgress:`w-full mt-1.5`},variants:{color:{neutral:{dropzone:`focus:border-inverted focus:ring-2 focus:ring-inverted/20`},...Object.fromEntries(B.map(e=>[e,{dropzone:`focus:border-${e} focus:ring-2 focus:ring-${e}/20`}]))},variant:{outline:{dropzone:`border-default bg-muted hover:border-accented`,file:`bg-default border-default`},soft:{dropzone:`border-transparent bg-elevated hover:bg-accented`,file:`bg-elevated border-transparent`},subtle:{dropzone:`border-default bg-muted hover:bg-elevated`,file:`bg-muted border-default`},none:{dropzone:`border-transparent bg-transparent`,file:`bg-transparent border-transparent`}},size:{sm:{dropzone:`p-4 text-xs`,icon:`w-6 h-6 text-xl`,title:`text-xs font-medium`,description:`text-2xs`,file:`p-2 gap-2 text-xs`,fileLeading:`w-8 h-8 text-xs`,fileName:`text-xs`,fileSize:`text-2xs`,fileRemove:`w-5 h-5 text-xs`},md:{dropzone:`p-6 text-sm`,icon:`w-8 h-8 text-2xl`,title:`text-sm font-medium`,description:`text-xs`,file:`p-3 gap-3 text-sm`,fileLeading:`w-10 h-10 text-sm`,fileName:`text-sm`,fileSize:`text-xs`,fileRemove:`w-6 h-6 text-sm`},lg:{dropzone:`p-8 text-base`,icon:`w-10 h-10 text-3xl`,title:`text-base font-medium`,description:`text-sm`,file:`p-4 gap-3 text-base`,fileLeading:`w-12 h-12 text-base`,fileName:`text-base`,fileSize:`text-xs`,fileRemove:`w-7 h-7 text-base`},xl:{dropzone:`p-10 text-lg`,icon:`w-12 h-12 text-4xl`,title:`text-lg font-medium`,description:`text-base`,file:`p-5 gap-4 text-lg`,fileLeading:`w-14 h-14 text-lg`,fileName:`text-lg`,fileSize:`text-sm`,fileRemove:`w-8 h-8 text-lg`}},layout:{list:{fileList:`flex flex-col gap-2 w-full`},grid:{fileList:`grid grid-cols-2 gap-3 w-full`,file:`relative flex flex-col p-2.5 rounded-md border border-default bg-default shadow-xs transition-colors overflow-hidden`,fileLeading:`w-full h-24 aspect-video rounded-lg overflow-hidden bg-elevated shrink-0 relative flex items-center justify-center`,fileTrailing:`absolute top-3.5 right-3.5 z-10 flex items-center gap-1`,fileRemove:`flex items-center justify-center w-5 h-5 rounded-full bg-black/40 text-white hover:bg-black/60 transition-colors backdrop-blur-xs`,fileContent:`w-full pt-1.5 flex flex-col items-center min-w-0`,fileName:`w-full text-center font-medium text-highlighted truncate text-xs`,fileSize:`hidden`,fileProgress:`w-full mt-1`}},disabled:{true:{root:`opacity-60 pointer-events-none cursor-not-allowed`,dropzone:`cursor-not-allowed bg-elevated border-default`}},invalid:{true:{dropzone:`border-danger bg-danger/5 text-danger`}}},compoundVariants:[...B.map(e=>({color:e,disabled:!1,invalid:!1,class:{dropzone:`hover:border-${e} active:border-${e}`}})),{color:`neutral`,disabled:!1,invalid:!1,class:{dropzone:`hover:border-inverted active:border-inverted`}},{dropzone:!1,class:{dropzone:`inline-flex flex-row items-center justify-center gap-2 border border-solid rounded-lg w-fit py-1.5 px-3`,icon:`mb-0 w-4 h-4 text-base`,content:`flex-row items-center gap-1.5`}}],defaultVariants:{color:`primary`,variant:`outline`,size:`md`,layout:`list`,disabled:!1,invalid:!1}},H=e.tv(V),U=t.createMachineBehavior({machine:z,connect:O,key:`fileUpload`,plugins:[r.withFormField()],exportApi:!0,exportApiKeys:[`files`,`fileCount`,`hasFiles`,`isUploading`,`chooseFiles`,`addFiles`,`removeFile`,`previewFile`,`clearFiles`,`setFiles`]});Component(n.createComponentOptions({behaviors:[U,n.computedBehavior],slots:{default:!1,icon:!1,loadingIcon:!1,title:!1,description:!1},properties:t.createProperties(k,{dropzone:{type:Boolean,value:!0},layout:{type:String,value:`list`},title:{type:String,value:``},label:{type:String,value:``},description:{type:String,value:``},icon:{type:String,value:`upload`},loadingIcon:{type:String,value:`loading`},deleteIcon:{type:String,value:`close`},fileIcon:{type:String,value:`file`},imageIcon:{type:String,value:`image`},videoIcon:{type:String,value:`video`},audioIcon:{type:String,value:`audio`},color:{type:String,value:`primary`},size:{type:String,value:``},variant:{type:String,value:`outline`},ui:{type:Object,value:{}},className:{type:String,value:``}}),computed:{resolvedSize(){return this.data.size||this.data.fieldSize||`md`},icons(){return e.useComponentIcons({icon:this.data.icon,loading:!!this.data.fileUpload?.isUploading,loadingIcon:this.data.loadingIcon,slots:this.data.slots})},classes(){let t=this.data.fileUpload,n=H({variant:this.data.variant,color:this.data.color,size:this.data.resolvedSize,layout:this.data.layout,dropzone:!!this.data.dropzone,invalid:!!t?.invalid,disabled:!!t?.disabled});return e.resolveSlots(n,this.data.ui,this.data.className)}},methods:{handleDropzoneTap(){return e.getApi(this,`fileUpload`)?.handleDropzoneTap()},handleRemove(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handleRemove(r)},handlePreview(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handlePreview(r)},handleFileClick(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handleFileClick(r)},handleImageError(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handleImageError(r)}}}));
|
|
1
|
+
const e=require("../../weapp-vendors/miniapp-machine.js"),t=require("../../weapp-vendors/miniapp-behavior.js"),n=require("../../computed-behavior.js"),r=require("../../behaviors/form.js");var i=t=>e.partId(t,`fu`,`root`,`r`),a=t=>e.partId(t,`fu`,`dropzone`,`dz`),o=t=>e.partId(t,`fu`,`fileList`,`fl`),s=(t,n)=>e.itemPartId(t,`fu`,`file`,n,`f`),c=(t,n)=>e.itemPartId(t,`fu`,`fileRemove`,n,`rm`),l=(t,n)=>e.itemPartId(t,`fu`,`filePreview`,n,`pv`),u=/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico|tiff|avif)$/i,d=/\.(mp4|mov|m4v|avi|mkv|webm|flv|wmv|3gp|ts)$/i,f=/\.(mp3|wav|m4a|aac|ogg|flac|wma|aiff|alac|amr|mid|midi|opus)$/i,p=/\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|md|zip|rar|7z)$/i;function m(e){if(!e)return``;let t=e.split(`?`)[0]?.split(`#`)[0]??``,n=t.lastIndexOf(`.`);return n===-1?``:t.slice(n).toLowerCase()}function h(e){return!e||!/^https?:\/\//i.test(e)?!1:!/^https?:\/\/(?:tmp|usr|store)(?:\/|$)/i.test(e)}function g(e){return!e||/^data:/i.test(e)||h(e)?!1:/^[a-z][a-z0-9+.-]*:\/\//i.test(e)||/^tmp\//i.test(e)||/^\/(?:var|private|data|storage|sdcard|tmp)\//i.test(e)}function _(e,t=`image/jpeg`){return e.startsWith(`/9j/`)?`image/jpeg`:e.startsWith(`iVBOR`)?`image/png`:e.startsWith(`R0lGOD`)?`image/gif`:e.startsWith(`UklGR`)?`image/webp`:e.startsWith(`Qk`)?`image/bmp`:t.startsWith(`image/`)?t:`image/jpeg`}function v(e,t,n){if(e===`image`||e?.startsWith(`image/`))return!0;let r=t?.split(`?`)[0]||``,i=n?.split(`?`)[0]||``;return u.test(r)||u.test(i)}function y(e,t,n){if(e===`video`||e?.startsWith(`video/`))return!0;let r=t?.split(`?`)[0]||``,i=n?.split(`?`)[0]||``;return d.test(r)||d.test(i)}function b(e,t,n){if(e===`audio`||e?.startsWith(`audio/`))return!0;let r=t?.split(`?`)[0]||``,i=n?.split(`?`)[0]||``;return f.test(r)||f.test(i)}function x(e){return e?e.split(`,`).map(e=>e.trim().toLowerCase()).some(e=>p.test(e)||e.startsWith(`application/`)||e.startsWith(`text/`)||/^(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|csv|md|zip|rar|7z)$/.test(e)):!1}function S(e){return v(e.type,e.path,e.name)?`image`:y(e.type,e.path,e.name)?`video`:b(e.type,e.path,e.name)?`audio`:`file`}function C(e,t=S(e),n){let r=e.thumb||(t===`image`?e.path:void 0);if(r)return n?.[r]??r}function w(e,t){let n=e.path||e.thumb||``;return n?t?.[n]??n:``}function T(e,t){return t?`${e.id||``}::${t}`:``}var E={jpg:`image/jpeg`,jpeg:`image/jpeg`,png:`image/png`,gif:`image/gif`,webp:`image/webp`,svg:`image/svg+xml`,mp4:`video/mp4`,mov:`video/quicktime`,webm:`video/webm`,mp3:`audio/mpeg`,wav:`audio/wav`,m4a:`audio/aac`,aac:`audio/aac`,ogg:`audio/ogg`,flac:`audio/flac`,pdf:`application/pdf`,doc:`application/msword`,docx:`application/msword`,xls:`application/vnd.ms-excel`,xlsx:`application/vnd.ms-excel`,zip:`application/zip`,txt:`text/plain`};function D(e,t=`application/octet-stream`){let n=m(e).slice(1);return n&&E[n]||t}function O(e,t=1){if(e<=0)return`0 B`;let n=1024,r=t<0?0:t,i=[`B`,`KB`,`MB`,`GB`,`TB`],a=Math.floor(Math.log(e)/Math.log(n)),o=Math.min(a,i.length-1);return`${parseFloat((e/n**o).toFixed(r))} ${i[o]}`}function k(e){return e?(Array.isArray(e)?e:e.split(`,`).map(e=>e.trim())).map(e=>e.replace(/^\./,``).trim().toLowerCase()).filter(Boolean):[]}function A(e,t){if(!t)return!0;let n=Array.isArray(t)?t:t.split(`,`).map(e=>e.trim().toLowerCase());if(n.length===0)return!0;let r=(e.name||``).toLowerCase(),i=(e.path||``).toLowerCase(),a=(e.type||``).toLowerCase(),o=D(r||i,``).toLowerCase();return n.some(e=>{if(!e)return!0;let t=e.trim().toLowerCase();if(t===`*`||t===`*/*`)return!0;if(t.endsWith(`/*`)){let e=t.slice(0,-2);return a.startsWith(e)||o.startsWith(e)||e===`image`&&v(a,i,r)||e===`video`&&y(a,i,r)||e===`audio`&&b(a,i,r)}if(t.includes(`/`)){if(a===t||o===t)return!0;let e=t.split(`/`)[1];return!!(e&&(r.endsWith(`.${e}`)||i.endsWith(`.${e}`)||e===`jpeg`&&(r.endsWith(`.jpg`)||i.endsWith(`.jpg`))))}let n=t.startsWith(`.`)?t:`.${t}`;return r.endsWith(n)||i.endsWith(n)})}function j(e,t={}){let{maxSize:n=1/0,minSize:r=0,accept:i,maxFiles:a=10,multiple:o=!0,currentCount:s=0}=t,c=[],l=[];for(let t of e){let e=t.size??0;e>n?l.push({file:t,reason:`size-too-large`}):e<r?l.push({file:t,reason:`size-too-small`}):i&&!A(t,i)?l.push({file:t,reason:`type-not-allowed`}):o&&s+c.length>=a?l.push({file:t,reason:`max-files-exceeded`}):c.push(t)}if(!o&&c.length>1){let[e,...t]=c;c.length=0,e&&c.push(e);for(let e of t)l.push({file:e,reason:`max-files-exceeded`})}return{accepted:c,rejected:l}}function M(e){let{state:t,send:n,context:r,computed:u,prop:d,scope:f}=e,p=t.get(),m=r.get(`files`),h=r.get(`failedThumbs`),g=r.get(`resolvedSources`),_=r.get(`previewOpen`),v=r.get(`previewIndex`),y=u(`isDisabled`),b=u(`isReadOnly`),x=u(`isInvalid`),E=u(`isInteractive`),D=u(`isMaxFiles`),k=u(`hasFiles`),A=u(`fileCount`),j=u(`isUploading`),M=d(`progress`),N=d(`maxFiles`),P=D?`Maximum ${N} files uploaded`:`Upload files, ${A} of ${N} files selected`,F=[],I=m.map((e,t)=>{let n=S(e),r=e.id||String(t),i=e.progress??M??null,a=O(e.size),o=C(e,n,g),u=T(e,o),d=!!(u&&h.includes(u));return n===`image`&&e.path&&F.push({id:r,name:e.name,formattedSize:a,src:w(e,g),fileIndex:t}),Object.assign({},e,{index:t,thumb:o,thumbFailed:d,progress:i,formattedSize:a,fileType:n,itemProps:{id:s(f,r),"aria-role":`listitem`},removeProps:{id:c(f,r),"aria-role":`button`,"aria-label":`Remove ${e.name}`},previewProps:{id:l(f,r),"aria-role":`button`,"aria-label":`Preview ${e.name}`}})}),L=!!(_&&F.length>0),R=F.length>0?Math.max(0,Math.min(F.length-1,v)):0,z=F[R]??null,B=()=>new Promise(e=>{n({type:`CHOOSE`,onDone:e})});return{state:p,files:I,fileCount:A,hasFiles:k,isMaxFiles:D,isUploading:j,progress:M,disabled:y,readOnly:b,invalid:x,interactive:E,previewOpen:L,previewIndex:R,previewItems:F,activePreviewItem:z,rootProps:{id:i(f),"data-state":p,"data-disabled":String(y),"data-readonly":String(b),"data-invalid":String(x),"data-max":String(D),"aria-role":`group`,"aria-disabled":y,"aria-invalid":x},dropzoneProps:{id:a(f),"data-state":p,"data-disabled":String(y||D),"data-readonly":String(b),"data-max":String(D),"aria-role":`button`,"aria-disabled":y||D,"aria-busy":j,"aria-label":P},fileListProps:{id:o(f),"aria-role":`list`,"aria-label":`Uploaded files`},chooseFiles:B,handleDropzoneTap:()=>B(),addFiles:e=>{n({type:`PICKED_RAW`,files:e})},removeFile:e=>{n({type:`REMOVE_FILE`,idOrIndex:e})},handleRemove:e=>{e>=0&&n({type:`REMOVE_FILE`,index:e})},previewFile:e=>{n({type:`PREVIEW_FILE`,idOrIndex:e})},closePreview:()=>{n({type:`PREVIEW_CLOSE`})},setPreviewIndex:e=>{e>=0&&n({type:`PREVIEW_CHANGE`,index:e})},handlePreview:e=>{e>=0&&n({type:`PREVIEW_FILE`,idOrIndex:e})},handlePreviewClose:()=>{n({type:`PREVIEW_CLOSE`})},handlePreviewChange:e=>{e>=0&&n({type:`PREVIEW_CHANGE`,index:e})},handleFileClick:e=>{e>=0&&n({type:`FILE_CLICK`,index:e})},handleImageError:e=>{e>=0&&n({type:`IMAGE_ERROR`,index:e})},clearFiles:()=>{n({type:`CLEAR_FILES`})},setFiles:e=>{n({type:`SET_VALUE`,value:e})}}}var N={formContext:void 0,value:null,defaultValue:[],name:``,form:``,invalid:null,disabled:!1,readOnly:!1,multiple:!0,maxFiles:10,maxSize:1/0,minSize:0,accept:``,mode:`auto`,previewMode:`overlay`,sourceType:[`album`,`camera`],mediaType:[`image`,`video`],sizeType:[`original`,`compressed`],camera:`back`,maxDuration:60,interactive:!0,uploading:!1,progress:null},P=307200,F=6291456,I=()=>typeof wx<`u`&&wx?wx:globalThis.wx,L=0;function R(){return L+=1,`file-${Date.now()}-${L}`}var z=null,B=null;function V(){if(z){try{z.stop(),z.destroy()}catch{}z=null,B=null}}function H(e,t){if(typeof t.createInnerAudioContext!=`function`)return;if(z&&B===e.path){z.paused?(z.play(),t.showToast?.({title:`Playing ${e.name}`,icon:`none`,duration:1500})):(z.pause(),t.showToast?.({title:`Paused ${e.name}`,icon:`none`,duration:1500}));return}V();let n=t.createInnerAudioContext();z=n,B=e.path||``,n.src=e.path,n.autoplay=!0,n.onPlay(()=>{t.showToast?.({title:`Playing ${e.name}`,icon:`none`,duration:1500})}),n.onEnded(()=>{B=null}),n.onError(e=>{console.warn(`[file-upload] Audio playback error:`,e),t.showToast?.({title:`Audio playback error`,icon:`none`,duration:2e3})}),n.play()}function U(e){return e.map(e=>{let t=e??{},n=t.tempFilePath||t.path||``,r=t.name||n.split(`/`).pop()||`file-${Date.now()}`,i=t.size??0,a=t.fileType||(t.type&&t.type!==`file`?t.type:void 0)||(v(void 0,n,r)?`image`:y(void 0,n,r)?`video`:b(void 0,n,r)?`audio`:`file`),o=t.thumbTempFilePath||(v(a,n,r)?n:void 0);return{id:R(),name:r,size:i,type:a,path:n,thumb:o,duration:t.duration,width:t.width,height:t.height,status:`idle`}})}function W(e,t,n,r){if(!r)return t.slice(0,1);let i=Math.max(0,n-e.length);return i<=0?e:[...e,...t.slice(0,i)]}var G=e.createMachine({props:({props:e})=>({...N,...e}),initialState:({prop:e})=>e(`uploading`)?`uploading`:`idle`,refs:({prop:e})=>({initialFiles:e(`value`)??e(`defaultValue`),formField:void 0,chooseDone:void 0,resolvingPaths:new Set,disposed:!1}),context:({prop:t,bindable:n,getRefs:r})=>({files:n(()=>{let n=t(`value`),i=t(`defaultValue`);return{value:e.isNotNull(n)?n:void 0,defaultValue:n??i,isEqual:e.isEqual,onChange:e=>{t(`onChange`)?.({value:e});let n=r().get(`formField`);n&&(n.emitInput(e),n.emitChange(e))}}}),invalid:n(()=>{let n=t(`invalid`);return{value:e.isNotEmpty(n)?!!n:void 0,defaultValue:!1}}),failedThumbs:n(()=>({defaultValue:[]})),resolvedSources:n(()=>({defaultValue:{}})),previewOpen:n(()=>({defaultValue:!1})),previewIndex:n(()=>({defaultValue:0}))}),computed:{...r.createFormFieldComputed(`fileUpload`),isInvalid:({prop:e,refs:t,context:n,scope:i})=>!!(n.get(`invalid`)||r.hasFormFieldErrors(e,t,i,`fileUpload`)),isDisabled:({prop:e,computed:t})=>!!(t(`formDisabled`)||t(`fieldDisabled`)||e(`disabled`)),isReadOnly:({prop:e,computed:t})=>!!(e(`readOnly`)||t(`formReadOnly`)),isInteractive:({computed:e,prop:t})=>!e(`isDisabled`)&&!e(`isReadOnly`)&&t(`interactive`),isMaxFiles:({context:e,prop:t})=>e.get(`files`).length>=t(`maxFiles`),hasFiles:({context:e})=>e.get(`files`).length>0,fileCount:({context:e})=>e.get(`files`).length,isUploading:({prop:e,state:t})=>e(`uploading`)||t.matches(`uploading`)},watch:({prop:e,state:t,track:n})=>{n([()=>e(`uploading`)],()=>{let n=e(`uploading`);n&&!t.matches(`uploading`)?t.set(`uploading`):!n&&t.matches(`uploading`)&&t.set(`idle`)})},effects:[`hydrateLocalImages`],entry:[`setupFormField`],exit:[`markDisposed`,`cleanupFormField`,`cleanupAudio`,`flushChooseCallback`],on:{SET_VALUE:{actions:[`setValue`]},ADD_FILES:{guard:`canAddFiles`,actions:[`addFiles`]},PICKED_RAW:{guard:`canAddFiles`,actions:[`ingestPickedFiles`]},REMOVE_FILE:{guard:`isInteractive`,actions:[`removeFile`]},PREVIEW_FILE:{actions:[`previewFile`]},PREVIEW_CLOSE:{actions:[`closePreview`]},PREVIEW_CHANGE:{actions:[`setPreviewIndex`]},FILE_CLICK:{actions:[`clickFile`]},IMAGE_ERROR:{actions:[`markImageError`]},CLEAR_FILES:{guard:`isInteractive`,actions:[`cleanupAudio`,`clearFiles`]},SET_UPLOADING:{actions:[`setUploading`]}},states:{idle:{tags:[`idle`],on:{CHOOSE:[{guard:`canChoose`,target:`choosing`,actions:[`setChooseCallback`]},{actions:[`resolveChooseFromEvent`]}]}},choosing:{tags:[`busy`],effects:[`pickWeChatFiles`],exit:[`flushChooseCallback`],on:{CHOOSE:{actions:[`resolveChooseFromEvent`]},CHOOSE_COMPLETE:{target:`idle`}}},uploading:{tags:[`busy`],on:{CHOOSE:{actions:[`resolveChooseFromEvent`]}}}},implementations:{guards:{isInteractive:({computed:e})=>e(`isInteractive`),canChoose:({computed:e})=>e(`isInteractive`)&&!e(`isMaxFiles`),canAddFiles:({computed:e})=>e(`isInteractive`)&&!e(`isMaxFiles`)},effects:{hydrateLocalImages:({context:e,refs:t,track:n})=>{n([()=>e.get(`files`).map(e=>`${e.id??``}:${e.path??``}:${e.thumb??``}`).join(`|`)],()=>{if(t.get(`disposed`))return;let n=e.get(`files`),r=t.get(`resolvingPaths`),i=e.get(`resolvedSources`),a=new Set,o=[];for(let e of n){if(S(e)===`image`&&g(e.path)){let t=e.path;a.add(t),o.push({rawPath:t,file:e})}e.thumb&&e.thumb!==e.path&&g(e.thumb)&&(a.add(e.thumb),o.push({rawPath:e.thumb,file:e}))}let s=!1,c={};for(let e of Object.keys(i))a.has(e)?c[e]=i[e]:s=!0;for(let e of Array.from(r))a.has(e)||r.delete(e);s&&e.set(`resolvedSources`,c);let l=I();if(!l||typeof l.getFileSystemManager!=`function`)return;let u=l.getFileSystemManager();if(u&&typeof u.readFile==`function`)for(let{rawPath:n,file:a}of o){if(i[n]||r.has(n))continue;r.add(n);let o=r=>{t.get(`disposed`)||u.readFile({filePath:r,encoding:`base64`,success:r=>{if(t.get(`disposed`))return;let i=typeof r?.data==`string`?r.data:``;if(!i||i.length>F)return;let o=`data:${_(i,D(a.name||n,`image/jpeg`))};base64,${i}`,s=e.get(`resolvedSources`);if(s[n]!==o){e.set(`resolvedSources`,{...s,[n]:o});let t=T(a,n);if(t){let n=e.get(`failedThumbs`);n.includes(t)&&e.set(`failedThumbs`,n.filter(e=>e!==t))}}},fail:e=>{console.warn(`[file-upload] Failed to read local preview image:`,e)}})};(a.size>P||!a.size)&&typeof l.compressImage==`function`?l.compressImage({src:n,quality:75,compressedWidth:1280,success:e=>{o(e?.tempFilePath||n)},fail:()=>{o(n)}}):o(n)}})},pickWeChatFiles:({prop:e,context:t,send:n})=>{let r=I();if(!r){n({type:`CHOOSE_COMPLETE`});return}let i=e(`multiple`),a=e(`maxFiles`),o=e(`accept`),s=e(`mode`),c=t.get(`files`),l=i?Math.max(1,a-c.length):1,u=(Array.isArray(o)?o.join(`,`):o).toLowerCase(),d=x(u),f=()=>{if(typeof r.chooseMessageFile!=`function`){n({type:`CHOOSE_COMPLETE`});return}let e=k(o),t=e.length>0&&!u.includes(`*`);r.chooseMessageFile({count:l,type:t?`file`:`all`,...t?{extension:e}:{},success:e=>{n({type:`PICKED_RAW`,files:e.tempFiles??[]})},fail:e=>{let t=e?.errMsg??``;t&&!t.includes(`cancel`)&&(console.warn(`[file-upload] chooseMessageFile failed:`,e),r.showToast?.({title:`Unable to open file picker`,icon:`none`}))},complete:()=>{n({type:`CHOOSE_COMPLETE`})}})},p=t=>{if(typeof r.chooseMedia!=`function`){f();return}r.chooseMedia({count:l,mediaType:e(`mediaType`),sourceType:t??e(`sourceType`),maxDuration:e(`maxDuration`),sizeType:e(`sizeType`),camera:e(`camera`),success:e=>{n({type:`PICKED_RAW`,files:e.tempFiles??[]})},fail:e=>{let t=e?.errMsg??``;t&&!t.includes(`cancel`)&&console.warn(`[file-upload] chooseMedia failed:`,e)},complete:()=>{n({type:`CHOOSE_COMPLETE`})}})};if((s===`messageFile`||s===`auto`&&d)&&typeof r.chooseMessageFile==`function`){f();return}let m=e(`sourceType`),h=Array.isArray(m)&&m.includes(`album`)&&m.includes(`camera`),g=!u||u===`*`||u===`*/*`;if(s===`auto`&&typeof r.showActionSheet==`function`&&typeof r.chooseMedia==`function`){if(g&&typeof r.chooseMessageFile==`function`){r.showActionSheet({itemList:[`Photo / Video Album`,`Take Photo / Video`,`Choose Files`],success:e=>{setTimeout(()=>{e.tapIndex===2?f():p(e.tapIndex===1?[`camera`]:[`album`])},150)},fail:()=>{n({type:`CHOOSE_COMPLETE`})}});return}if(h){r.showActionSheet({itemList:[`Choose from Album`,`Take Photo / Video`],success:e=>{setTimeout(()=>{p(e.tapIndex===1?[`camera`]:[`album`])},150)},fail:()=>{n({type:`CHOOSE_COMPLETE`})}});return}}if(typeof r.chooseMedia==`function`){p();return}if(typeof r.chooseMessageFile==`function`){f();return}n({type:`CHOOSE_COMPLETE`})}},actions:{setChooseCallback:({refs:e,event:t})=>{t.type===`CHOOSE`&&e.set(`chooseDone`,t.onDone)},resolveChooseFromEvent:({event:e})=>{e.type===`CHOOSE`&&e.onDone?.()},flushChooseCallback:({refs:e})=>{let t=e.get(`chooseDone`);e.set(`chooseDone`,void 0),t&&queueMicrotask(t)},setValue:({context:e,event:t})=>{if(t.type===`SET_VALUE`&&(e.set(`files`,t.value),e.set(`failedThumbs`,[]),e.get(`previewOpen`))){let n=t.value.filter(e=>S(e)===`image`&&!!e.path).length;n===0?(e.set(`previewOpen`,!1),e.set(`previewIndex`,0)):e.get(`previewIndex`)>=n&&e.set(`previewIndex`,n-1)}},addFiles:({context:e,event:t,prop:n})=>{if(t.type!==`ADD_FILES`)return;let r=W(e.get(`files`),t.files,n(`maxFiles`),n(`multiple`));e.set(`files`,r)},ingestPickedFiles:({context:e,event:t,prop:n})=>{if(t.type!==`PICKED_RAW`)return;let r=e.get(`files`),i=n(`maxFiles`),a=n(`multiple`),{accepted:o,rejected:s}=j(U(t.files),{maxSize:n(`maxSize`),minSize:n(`minSize`),accept:n(`accept`),maxFiles:i,multiple:a,currentCount:r.length});if(s.length>0&&n(`onReject`)?.({files:s}),o.length>0){let t=W(r,o,i,a);e.set(`files`,t),n(`onAccept`)?.({files:o})}},removeFile:({context:e,event:t,prop:n})=>{if(t.type!==`REMOVE_FILE`)return;let r=e.get(`files`),i=t.index===void 0?typeof t.idOrIndex==`number`?t.idOrIndex:r.findIndex(e=>e.id===t.idOrIndex):t.index;if(i<0||i>=r.length)return;let a=r[i];a?.path&&a.path===B&&V();let o=r.filter((e,t)=>t!==i);if(e.set(`files`,o),a){let t=T(a,C(a,void 0,e.get(`resolvedSources`)));if(t){let n=e.get(`failedThumbs`);n.includes(t)&&e.set(`failedThumbs`,n.filter(e=>e!==t))}if(e.get(`previewOpen`)){let t=o.filter(e=>S(e)===`image`&&!!e.path).length;t===0?(e.set(`previewOpen`,!1),e.set(`previewIndex`,0)):e.get(`previewIndex`)>=t&&e.set(`previewIndex`,t-1)}n(`onRemove`)?.({file:a,index:i})}},previewFile:({context:e,event:t,prop:n})=>{if(t.type!==`PREVIEW_FILE`)return;let r=e.get(`files`),i=typeof t.idOrIndex==`number`?t.idOrIndex:r.findIndex(e=>e.id===t.idOrIndex);if(i<0)return;let a=r[i];if(!a)return;n(`onPreview`)?.({file:a,index:i});let o=I();if(!a.path){o?.showToast?.({title:`No file path available to preview`,icon:`none`});return}let s=S(a);if(s===`image`){if(n(`previewMode`)!==`native`){let t=r.filter(e=>S(e)===`image`&&!!e.path),n=Math.max(0,t.indexOf(a));e.set(`previewIndex`,n),e.set(`previewOpen`,!0);return}if(!o)return;let t=!h(a.path),i=r.filter(e=>S(e)===`image`&&e.path&&h(e.path)===!t).map(e=>e.path),s=i.length>0?i:[a.path],c=Math.max(0,s.indexOf(a.path)),l=e=>{if(typeof o.previewMedia!=`function`){e?.();return}o.previewMedia({current:c,sources:s.map(e=>({url:e,type:`image`})),fail:t=>{if(e){e();return}console.warn(`[file-upload] previewMedia failed:`,t),o.showToast?.({title:`Unable to preview image`,icon:`none`})}})},u=e=>{if(typeof o.previewImage!=`function`){e?.();return}o.previewImage({current:a.path,urls:s,fail:t=>{if(e){e();return}console.warn(`[file-upload] previewImage failed:`,t),o.showToast?.({title:`Unable to preview image`,icon:`none`})}})};t?l(()=>{u()}):u(()=>{l()});return}if(o){if(s===`video`)typeof o.previewMedia==`function`&&o.previewMedia({current:0,sources:[{url:a.path,type:`video`,poster:a.thumb||``}],fail:e=>{console.warn(`[file-upload] previewMedia failed:`,e)}});else if(s===`audio`)H(a,o);else if(typeof o.openDocument==`function`){let e=((a.name||a.path).split(`?`)[0]?.match(/\.(doc|docx|xls|xlsx|ppt|pptx|pdf)$/i))?.[1]?.toLowerCase(),t=(n,r=!0)=>{o.openDocument({filePath:n,...e?{fileType:e}:{},showMenu:!0,fail:i=>{let a=o.env?.USER_DATA_PATH,s=typeof o.getFileSystemManager==`function`?o.getFileSystemManager():null;if(r&&!h(n)&&typeof a==`string`&&a&&s&&typeof s.copyFile==`function`){let r=e?`.${e}`:``,c=`${a}/cui-preview-${Date.now()}${r}`;s.copyFile({srcPath:n,destPath:c,success:()=>{t(c,!1)},fail:()=>{console.warn(`[file-upload] openDocument failed:`,i),o.showToast?.({title:`Preview not supported for this file`,icon:`none`})}});return}console.warn(`[file-upload] openDocument failed:`,i),o.showToast?.({title:`Preview not supported for this file`,icon:`none`})}})};h(a.path)&&typeof o.downloadFile==`function`?o.downloadFile({url:a.path,success:e=>{e.tempFilePath&&t(e.tempFilePath,!1)},fail:e=>{console.warn(`[file-upload] downloadFile failed:`,e),o.showToast?.({title:`Failed to load file preview`,icon:`none`})}}):t(a.path,!0)}}},closePreview:({context:e})=>{e.get(`previewOpen`)&&e.set(`previewOpen`,!1)},setPreviewIndex:({context:e,event:t})=>{if(t.type!==`PREVIEW_CHANGE`)return;let n=e.get(`files`).filter(e=>S(e)===`image`&&!!e.path).length;if(n<=0){e.set(`previewIndex`,0),e.set(`previewOpen`,!1);return}let r=Math.max(0,Math.min(n-1,t.index));e.set(`previewIndex`,r)},clickFile:({context:e,event:t,prop:n})=>{if(t.type!==`FILE_CLICK`)return;let r=e.get(`files`)[t.index];r&&n(`onFileClick`)?.({file:r,index:t.index})},markImageError:({context:e,event:t})=>{if(t.type!==`IMAGE_ERROR`)return;let n=e.get(`files`)[t.index];if(!n)return;let r=T(n,C(n,void 0,e.get(`resolvedSources`)));if(!r)return;let i=e.get(`failedThumbs`);i.includes(r)||e.set(`failedThumbs`,[...i,r])},clearFiles:({context:e})=>{e.set(`files`,[]),e.set(`failedThumbs`,[]),e.set(`previewOpen`,!1),e.set(`previewIndex`,0)},cleanupAudio:()=>{V()},markDisposed:({refs:e})=>{e.set(`disposed`,!0)},setUploading:({state:e,event:t})=>{t.type===`SET_UPLOADING`&&(t.uploading&&!e.matches(`uploading`)?e.set(`uploading`):!t.uploading&&e.matches(`uploading`)&&e.set(`idle`))},setupFormField:({prop:e,context:t,computed:n,refs:a,scope:o})=>{r.setupFormFieldSync({component:e(`component`),getHost:()=>e(`formContext`),id:o.id??`file-upload`,rootId:i(o),getFormId:()=>e(`form`),getName:()=>e(`name`),getValue:()=>t.get(`files`),setValue:e=>{t.set(`files`,Array.isArray(e)?e:[])},resetValue:()=>{t.set(`files`,e(`defaultValue`))},getRules:()=>e(`rules`)??[],getValidateOn:()=>e(`validateOn`),isDisabled:()=>n(`isDisabled`)},a)},cleanupFormField:({refs:e})=>r.cleanupFormFieldSync(e)}}}),K=[`primary`,`secondary`,`danger`,`success`,`warning`,`info`],q={slots:{root:`relative flex flex-col gap-3 w-full`,dropzone:`relative flex flex-col items-center justify-center text-center border-2 border-dashed rounded-md transition-colors cursor-pointer select-none`,icon:`text-dimmed mb-2 shrink-0 flex items-center justify-center`,iconInner:`w-full h-full`,loadingIcon:`w-full h-full animate-spin`,content:`flex flex-col items-center justify-center gap-1`,title:`font-medium text-highlighted`,description:`text-muted`,fileList:`flex flex-col gap-2 w-full`,file:`relative flex items-center gap-3 p-3 rounded-md border border-default bg-default shadow-xs transition-colors`,fileLeading:`relative flex items-center justify-center shrink-0 rounded-lg overflow-hidden bg-elevated`,fileImage:`absolute inset-0 w-full h-full rounded-lg object-cover block`,fileContent:`flex flex-col min-w-0 flex-1 text-left`,fileName:`font-medium text-highlighted truncate`,fileSize:`text-muted shrink-0`,fileTrailing:`flex items-center shrink-0 ml-auto gap-1`,fileIcon:`w-5 h-5 text-dimmed`,fileRemove:`flex items-center justify-center rounded-lg text-dimmed hover:text-default transition-colors p-1`,fileRemoveIcon:`w-4 h-4`,fileProgress:`w-full mt-1.5`,previewOverlay:`fixed inset-0 z-modal bg-black/95 flex flex-col select-none`,previewHeader:`relative z-10 flex items-center justify-between px-4 pb-3 pt-[calc(var(--spacing)_*_3_+_env(safe-area-inset-top))] text-white shrink-0`,previewCounter:`text-sm font-medium text-white/90 tabular-nums px-2.5 py-1 rounded-full bg-white/15`,previewClose:`flex items-center justify-center w-9 h-9 rounded-full bg-white/15 text-white active:bg-white/25 transition-colors`,previewCloseIcon:`w-5 h-5 text-white`,previewSwiper:`flex-1 w-full h-0 min-h-0`,previewSlide:`w-full h-full flex items-center justify-center px-3 box-border`,previewImage:`w-full h-full block`,previewFooter:`relative z-10 flex flex-col gap-0.5 px-4 pt-3 pb-[calc(var(--spacing)_*_4_+_env(safe-area-inset-bottom))] text-center shrink-0 bg-black/60`,previewName:`text-sm font-medium text-white truncate`,previewMeta:`text-xs text-white/70`},variants:{color:{neutral:{dropzone:`focus:border-inverted focus:ring-2 focus:ring-inverted/20`},...Object.fromEntries(K.map(e=>[e,{dropzone:`focus:border-${e} focus:ring-2 focus:ring-${e}/20`}]))},variant:{outline:{dropzone:`border-default bg-muted hover:border-accented`,file:`bg-default border-default`},soft:{dropzone:`border-transparent bg-elevated hover:bg-accented`,file:`bg-elevated border-transparent`},subtle:{dropzone:`border-default bg-muted hover:bg-elevated`,file:`bg-muted border-default`},none:{dropzone:`border-transparent bg-transparent`,file:`bg-transparent border-transparent`}},size:{sm:{dropzone:`p-4 text-xs`,icon:`w-6 h-6 text-xl`,title:`text-xs font-medium`,description:`text-2xs`,file:`p-2 gap-2 text-xs`,fileLeading:`w-8 h-8 text-xs`,fileName:`text-xs`,fileSize:`text-2xs`,fileRemove:`w-5 h-5 text-xs`},md:{dropzone:`p-6 text-sm`,icon:`w-8 h-8 text-2xl`,title:`text-sm font-medium`,description:`text-xs`,file:`p-3 gap-3 text-sm`,fileLeading:`w-10 h-10 text-sm`,fileName:`text-sm`,fileSize:`text-xs`,fileRemove:`w-6 h-6 text-sm`},lg:{dropzone:`p-8 text-base`,icon:`w-10 h-10 text-3xl`,title:`text-base font-medium`,description:`text-sm`,file:`p-4 gap-3 text-base`,fileLeading:`w-12 h-12 text-base`,fileName:`text-base`,fileSize:`text-xs`,fileRemove:`w-7 h-7 text-base`},xl:{dropzone:`p-10 text-lg`,icon:`w-12 h-12 text-4xl`,title:`text-lg font-medium`,description:`text-base`,file:`p-5 gap-4 text-lg`,fileLeading:`w-14 h-14 text-lg`,fileName:`text-lg`,fileSize:`text-sm`,fileRemove:`w-8 h-8 text-lg`}},layout:{list:{fileList:`flex flex-col gap-2 w-full`},grid:{fileList:`grid grid-cols-2 gap-3 w-full`,file:`relative flex flex-col p-2.5 rounded-md border border-default bg-default shadow-xs transition-colors overflow-hidden`,fileLeading:`w-full h-24 aspect-video rounded-lg overflow-hidden bg-elevated shrink-0 relative flex items-center justify-center`,fileTrailing:`absolute top-3.5 right-3.5 z-10 flex items-center gap-1`,fileRemove:`flex items-center justify-center w-5 h-5 rounded-full bg-black/40 text-white hover:bg-black/60 transition-colors backdrop-blur-xs`,fileContent:`w-full pt-1.5 flex flex-col items-center min-w-0`,fileName:`w-full text-center font-medium text-highlighted truncate text-xs`,fileSize:`hidden`,fileProgress:`w-full mt-1`}},disabled:{true:{root:`opacity-60 pointer-events-none cursor-not-allowed`,dropzone:`cursor-not-allowed bg-elevated border-default`}},invalid:{true:{dropzone:`border-danger bg-danger/5 text-danger`}}},compoundVariants:[...K.map(e=>({color:e,disabled:!1,invalid:!1,class:{dropzone:`hover:border-${e} active:border-${e}`}})),{color:`neutral`,disabled:!1,invalid:!1,class:{dropzone:`hover:border-inverted active:border-inverted`}},{dropzone:!1,class:{dropzone:`inline-flex flex-row items-center justify-center gap-2 border border-solid rounded-lg w-fit py-1.5 px-3`,icon:`mb-0 w-4 h-4 text-base`,content:`flex-row items-center gap-1.5`}}],defaultVariants:{color:`primary`,variant:`outline`,size:`md`,layout:`list`,disabled:!1,invalid:!1}},J=e.tv(q),Y=t.createMachineBehavior({machine:G,connect:M,key:`fileUpload`,plugins:[r.withFormField()],exportApi:!0,exportApiKeys:[`files`,`fileCount`,`hasFiles`,`isUploading`,`chooseFiles`,`addFiles`,`removeFile`,`previewFile`,`closePreview`,`clearFiles`,`setFiles`]});Component(n.createComponentOptions({behaviors:[Y,n.computedBehavior],slots:{default:!1,icon:!1,loadingIcon:!1,title:!1,description:!1},properties:t.createProperties(N,{dropzone:{type:Boolean,value:!0},layout:{type:String,value:`list`},title:{type:String,value:``},label:{type:String,value:``},description:{type:String,value:``},icon:{type:String,value:`upload`},loadingIcon:{type:String,value:`loading`},deleteIcon:{type:String,value:`close`},fileIcon:{type:String,value:`file`},imageIcon:{type:String,value:`image`},videoIcon:{type:String,value:`video`},audioIcon:{type:String,value:`audio`},color:{type:String,value:`primary`},size:{type:String,value:``},variant:{type:String,value:`outline`},portal:{type:Boolean,value:!0},ui:{type:Object,value:{}},className:{type:String,value:``}}),computed:{resolvedSize(){return this.data.size||this.data.fieldSize||`md`},icons(){return e.useComponentIcons({icon:this.data.icon,loading:!!this.data.fileUpload?.isUploading,loadingIcon:this.data.loadingIcon,slots:this.data.slots})},classes(){let t=this.data.fileUpload,n=J({variant:this.data.variant,color:this.data.color,size:this.data.resolvedSize,layout:this.data.layout,dropzone:!!this.data.dropzone,invalid:!!t?.invalid,disabled:!!t?.disabled});return e.resolveSlots(n,this.data.ui,this.data.className)}},methods:{handleDropzoneTap(){return e.getApi(this,`fileUpload`)?.handleDropzoneTap()},handleRemove(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handleRemove(r)},handlePreview(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handlePreview(r)},handleFileClick(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handleFileClick(r)},handleImageError(t){let n=t?.currentTarget?.dataset?.index,r=n===void 0?NaN:Number(n);Number.isNaN(r)||e.getApi(this,`fileUpload`)?.handleImageError(r)},handlePreviewClose(){e.getApi(this,`fileUpload`)?.handlePreviewClose()},handlePreviewSwiperChange(t){let n=Number(t?.detail?.current??0);Number.isNaN(n)||e.getApi(this,`fileUpload`)?.handlePreviewChange(n)},noop(){}}}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<view id="{{fileUpload.rootProps.id}}" class="{{classes.root}}" data-scope="file-upload" data-part="root" data-state="{{fileUpload.state}}" data-disabled="{{fileUpload.disabled}}" data-readonly="{{fileUpload.readOnly}}" data-invalid="{{fileUpload.invalid}}" data-max="{{fileUpload.isMaxFiles}}" aria-role="group" aria-disabled="{{fileUpload.disabled}}" aria-invalid="{{fileUpload.invalid}}"><view wx:if="{{!dropzone && slots.default && !fileUpload.isMaxFiles}}" id="{{fileUpload.dropzoneProps.id}}" data-scope="file-upload" data-part="dropzone" data-state="{{fileUpload.state}}" data-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" data-readonly="{{fileUpload.readOnly}}" data-max="{{fileUpload.isMaxFiles}}" aria-role="button" aria-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" aria-busy="{{fileUpload.isUploading}}" aria-label="{{fileUpload.dropzoneProps['aria-label']}}" bindtap="handleDropzoneTap"><slot/></view><view wx:elif="{{!fileUpload.isMaxFiles}}" id="{{fileUpload.dropzoneProps.id}}" class="{{classes.dropzone}}" data-scope="file-upload" data-part="dropzone" data-state="{{fileUpload.state}}" data-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" data-readonly="{{fileUpload.readOnly}}" data-max="{{fileUpload.isMaxFiles}}" aria-role="button" aria-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" aria-busy="{{fileUpload.isUploading}}" aria-label="{{fileUpload.dropzoneProps['aria-label']}}" bindtap="handleDropzoneTap"><block wx:if="{{!slots.default}}"><view class="{{classes.icon}}" data-scope="file-upload" data-part="icon" aria-hidden="true" wx:if="{{icons.leadingLoading}}"><slot wx:if="{{icons.hasLoadingSlot}}" name="loadingIcon"/><c-icon wx:else name="{{icons.leadingIconName}}" className="{{classes.loadingIcon}}"/></view><view class="{{classes.icon}}" data-scope="file-upload" data-part="icon" aria-hidden="true" wx:elif="{{icons.isLeading}}"><slot wx:if="{{slots.icon}}" name="icon"/><c-icon wx:elif="{{icons.leadingIconName}}" name="{{icons.leadingIconName}}" className="{{classes.iconInner}}"/></view><view class="{{classes.content}}" data-scope="file-upload" data-part="content"><view wx:if="{{title || label}}" class="{{classes.title}}" data-scope="file-upload" data-part="title">{{title || label}}</view><slot name="title" wx:else/><view wx:if="{{description}}" class="{{classes.description}}" data-scope="file-upload" data-part="description">{{description}}</view><slot name="description" wx:else/></view></block><slot wx:else/></view><view wx:if="{{fileUpload.hasFiles}}" id="{{fileUpload.fileListProps.id}}" class="{{classes.fileList}}" data-scope="file-upload" data-part="file-list" data-layout="{{layout}}" aria-role="list" aria-label="Uploaded files"><block wx:for="{{fileUpload.files}}" wx:key="id"><view id="{{item.itemProps.id}}" class="{{classes.file}}" data-scope="file-upload" data-part="file" data-index="{{index}}" data-status="{{item.status}}" aria-role="listitem" bindtap="handleFileClick"><view class="{{classes.fileLeading}}" data-scope="file-upload" data-part="file-leading" data-index="{{index}}" bindtap="handlePreview" aria-role="button" aria-label="Preview {{item.name}}"><image wx:if="{{item.fileType === 'image' && item.thumb && !item.thumbFailed}}" src="{{item.thumb}}" mode="aspectFill" class="{{classes.fileImage}}" data-index="{{index}}" binderror="handleImageError"/><c-icon wx:elif="{{item.fileType === 'image' && imageIcon}}" name="{{imageIcon}}" className="{{classes.fileIcon}}"/><c-icon wx:elif="{{item.fileType === 'video' && videoIcon}}" name="{{videoIcon}}" className="{{classes.fileIcon}}"/><c-icon wx:elif="{{item.fileType === 'audio' && audioIcon}}" name="{{audioIcon}}" className="{{classes.fileIcon}}"/><c-icon wx:elif="{{fileIcon}}" name="{{fileIcon}}" className="{{classes.fileIcon}}"/></view><view class="{{classes.fileContent}}" data-scope="file-upload" data-part="file-content" data-index="{{index}}" bindtap="handlePreview"><view class="{{classes.fileName}}" data-scope="file-upload" data-part="file-name">{{item.name}}</view><view class="{{classes.fileSize}}" data-scope="file-upload" data-part="file-size">{{item.formattedSize}}</view><view wx:if="{{fileUpload.isUploading || item.progress !== null}}" class="{{classes.fileProgress}}" data-scope="file-upload" data-part="file-progress"><c-progress value="{{item.progress}}" size="2xs" color="{{color}}"/></view></view><view wx:if="{{!fileUpload.disabled && !fileUpload.readOnly}}" class="{{classes.fileTrailing}}" data-scope="file-upload" data-part="file-trailing"><view wx:if="{{deleteIcon}}" class="{{classes.fileRemove}}" data-scope="file-upload" data-part="file-remove" data-index="{{index}}" aria-role="button" aria-label="Remove {{item.name}}" catchtap="handleRemove"><c-icon name="{{deleteIcon}}" className="{{classes.fileRemoveIcon}}"/></view></view></view></block></view></view>
|
|
1
|
+
<view id="{{fileUpload.rootProps.id}}" class="{{classes.root}}" data-scope="file-upload" data-part="root" data-state="{{fileUpload.state}}" data-disabled="{{fileUpload.disabled}}" data-readonly="{{fileUpload.readOnly}}" data-invalid="{{fileUpload.invalid}}" data-max="{{fileUpload.isMaxFiles}}" aria-role="group" aria-disabled="{{fileUpload.disabled}}" aria-invalid="{{fileUpload.invalid}}"><view wx:if="{{!dropzone && slots.default && !fileUpload.isMaxFiles}}" id="{{fileUpload.dropzoneProps.id}}" data-scope="file-upload" data-part="dropzone" data-state="{{fileUpload.state}}" data-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" data-readonly="{{fileUpload.readOnly}}" data-max="{{fileUpload.isMaxFiles}}" aria-role="button" aria-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" aria-busy="{{fileUpload.isUploading}}" aria-label="{{fileUpload.dropzoneProps['aria-label']}}" bindtap="handleDropzoneTap"><slot/></view><view wx:elif="{{!fileUpload.isMaxFiles}}" id="{{fileUpload.dropzoneProps.id}}" class="{{classes.dropzone}}" data-scope="file-upload" data-part="dropzone" data-state="{{fileUpload.state}}" data-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" data-readonly="{{fileUpload.readOnly}}" data-max="{{fileUpload.isMaxFiles}}" aria-role="button" aria-disabled="{{fileUpload.disabled || fileUpload.isMaxFiles}}" aria-busy="{{fileUpload.isUploading}}" aria-label="{{fileUpload.dropzoneProps['aria-label']}}" bindtap="handleDropzoneTap"><block wx:if="{{!slots.default}}"><view class="{{classes.icon}}" data-scope="file-upload" data-part="icon" aria-hidden="true" wx:if="{{icons.leadingLoading}}"><slot wx:if="{{icons.hasLoadingSlot}}" name="loadingIcon"/><c-icon wx:else name="{{icons.leadingIconName}}" className="{{classes.loadingIcon}}"/></view><view class="{{classes.icon}}" data-scope="file-upload" data-part="icon" aria-hidden="true" wx:elif="{{icons.isLeading}}"><slot wx:if="{{slots.icon}}" name="icon"/><c-icon wx:elif="{{icons.leadingIconName}}" name="{{icons.leadingIconName}}" className="{{classes.iconInner}}"/></view><view class="{{classes.content}}" data-scope="file-upload" data-part="content"><view wx:if="{{title || label}}" class="{{classes.title}}" data-scope="file-upload" data-part="title">{{title || label}}</view><slot name="title" wx:else/><view wx:if="{{description}}" class="{{classes.description}}" data-scope="file-upload" data-part="description">{{description}}</view><slot name="description" wx:else/></view></block><slot wx:else/></view><view wx:if="{{fileUpload.hasFiles}}" id="{{fileUpload.fileListProps.id}}" class="{{classes.fileList}}" data-scope="file-upload" data-part="file-list" data-layout="{{layout}}" aria-role="list" aria-label="Uploaded files"><block wx:for="{{fileUpload.files}}" wx:key="id"><view id="{{item.itemProps.id}}" class="{{classes.file}}" data-scope="file-upload" data-part="file" data-index="{{index}}" data-status="{{item.status}}" aria-role="listitem" bindtap="handleFileClick"><view class="{{classes.fileLeading}}" data-scope="file-upload" data-part="file-leading" data-index="{{index}}" bindtap="handlePreview" aria-role="button" aria-label="Preview {{item.name}}"><image wx:if="{{item.fileType === 'image' && item.thumb && !item.thumbFailed}}" src="{{item.thumb}}" mode="aspectFill" class="{{classes.fileImage}}" data-index="{{index}}" binderror="handleImageError"/><c-icon wx:elif="{{item.fileType === 'image' && imageIcon}}" name="{{imageIcon}}" className="{{classes.fileIcon}}"/><c-icon wx:elif="{{item.fileType === 'video' && videoIcon}}" name="{{videoIcon}}" className="{{classes.fileIcon}}"/><c-icon wx:elif="{{item.fileType === 'audio' && audioIcon}}" name="{{audioIcon}}" className="{{classes.fileIcon}}"/><c-icon wx:elif="{{fileIcon}}" name="{{fileIcon}}" className="{{classes.fileIcon}}"/></view><view class="{{classes.fileContent}}" data-scope="file-upload" data-part="file-content" data-index="{{index}}" bindtap="handlePreview"><view class="{{classes.fileName}}" data-scope="file-upload" data-part="file-name">{{item.name}}</view><view class="{{classes.fileSize}}" data-scope="file-upload" data-part="file-size">{{item.formattedSize}}</view><view wx:if="{{fileUpload.isUploading || item.progress !== null}}" class="{{classes.fileProgress}}" data-scope="file-upload" data-part="file-progress"><c-progress value="{{item.progress}}" size="2xs" color="{{color}}"/></view></view><view wx:if="{{!fileUpload.disabled && !fileUpload.readOnly}}" class="{{classes.fileTrailing}}" data-scope="file-upload" data-part="file-trailing"><view wx:if="{{deleteIcon}}" class="{{classes.fileRemove}}" data-scope="file-upload" data-part="file-remove" data-index="{{index}}" aria-role="button" aria-label="Remove {{item.name}}" catchtap="handleRemove"><c-icon name="{{deleteIcon}}" className="{{classes.fileRemoveIcon}}"/></view></view></view></block></view><root-portal wx:if="{{fileUpload.previewOpen}}" enable="{{portal}}"><view class="{{classes.previewOverlay}}" data-scope="file-upload" data-part="preview-overlay" catchtouchmove="noop"><view class="{{classes.previewHeader}}" data-scope="file-upload" data-part="preview-header"><view class="{{classes.previewCounter}}" data-scope="file-upload" data-part="preview-counter">{{fileUpload.previewIndex + 1}} / {{fileUpload.previewItems.length}}</view><view class="{{classes.previewClose}}" data-scope="file-upload" data-part="preview-close" aria-role="button" aria-label="Close preview" catchtap="handlePreviewClose"><c-icon name="{{deleteIcon || 'close'}}" className="{{classes.previewCloseIcon}}"/></view></view><swiper class="{{classes.previewSwiper}}" current="{{fileUpload.previewIndex}}" duration="{{220}}" bindchange="handlePreviewSwiperChange" data-scope="file-upload" data-part="preview-swiper"><swiper-item wx:for="{{fileUpload.previewItems}}" wx:key="id" class="{{classes.previewSlide}}" data-scope="file-upload" data-part="preview-slide"><image src="{{item.src}}" mode="aspectFit" class="{{classes.previewImage}}" data-scope="file-upload" data-part="preview-image" bindtap="handlePreviewClose"/></swiper-item></swiper><view wx:if="{{fileUpload.activePreviewItem}}" class="{{classes.previewFooter}}" data-scope="file-upload" data-part="preview-footer"><text class="{{classes.previewName}}" data-scope="file-upload" data-part="preview-name">{{fileUpload.activePreviewItem.name}}</text><text class="{{classes.previewMeta}}" data-scope="file-upload" data-part="preview-meta">{{fileUpload.activePreviewItem.formattedSize}}</text></view></view></root-portal></view>
|