geekin-devtoys 0.4.1 → 0.4.3
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/lib/GButton/index.js +1 -1
- package/lib/GButton/index.mjs +1 -1
- package/lib/GButton/style.css +1 -1
- package/lib/GDropdown/index.js +1 -0
- package/lib/GDropdown/index.mjs +278 -0
- package/lib/GDropdown/style.css +1 -0
- package/lib/GDropdown.d.ts +1 -0
- package/lib/GPicker/index.js +1 -1
- package/lib/GPicker/index.mjs +37 -37
- package/lib/GPicker/style.css +1 -1
- package/lib/GPluginVideo/index.js +1 -1
- package/lib/GPluginVideo/index.mjs +59 -58
- package/lib/GToast/index.js +1 -1
- package/lib/GToast/index.mjs +23 -23
- package/lib/GToast/style.css +1 -1
- package/lib/components/GDropdown/index.d.ts +59 -0
- package/lib/components/GScroller/index.d.ts +1 -1
- package/lib/components/GShinyText/index.d.ts +1 -1
- package/lib/components/GToast/store.d.ts +1 -0
- package/lib/components/GToast/types.d.ts +9 -0
- package/lib/components/GTree/index.d.ts +4 -2
- package/lib/index/index.js +1 -1
- package/lib/index/index.mjs +30 -27
- package/lib/index/style.css +5 -3
- package/lib/index.d.ts +3 -1
- package/package.json +13 -5
package/lib/GButton/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),d=require("motion-v"),b=require("../GBranched-BtF7heMk.js"),B=["type","disabled"],h={key:0,class:"g-button__loading"},
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),d=require("motion-v"),b=require("../GBranched-BtF7heMk.js"),B=["type","disabled"],h={key:0,class:"g-button__loading"},f={key:1,class:"g-button__icon"},_={key:2,class:"g-button__text"},v=e.defineComponent({name:"GButton",__name:"index",props:{type:{},size:{},loading:{type:Boolean},disabled:{type:Boolean},block:{type:Boolean},nativeType:{}},emits:["click"],setup(i,{emit:r}){const s=i,u=r,p=t=>{if(!(s.disabled||s.loading)){if(s.type!=="link"&&!g.value){const o=t.currentTarget.getBoundingClientRect(),c=t.clientX!==0||t.clientY!==0,k={id:++m,x:c?t.clientX-o.left:o.width/2,y:c?t.clientY-o.top:o.height/2,size:Math.hypot(o.width,o.height)*2};l.value.push(k)}u("click",t)}},l=e.ref([]);let m=0;const y=t=>{l.value=l.value.filter(a=>a.id!==t)},g=d.useReducedMotion();return(t,a)=>(e.openBlock(),e.createElementBlock("button",{class:e.normalizeClass(["g-button",["g-button--"+t.type,"g-button--"+t.size,{"is-block":t.block,"is-loading":t.loading,"is-disabled":t.disabled}]]),type:t.nativeType,disabled:t.disabled||t.loading,onClick:p},[t.loading?(e.openBlock(),e.createElementBlock("span",h)):e.createCommentVNode("",!0),t.$slots.icon?(e.openBlock(),e.createElementBlock("span",f,[e.renderSlot(t.$slots,"icon",{},void 0,!0)])):e.createCommentVNode("",!0),t.$slots.default?(e.openBlock(),e.createElementBlock("span",_,[e.renderSlot(t.$slots,"default",{},void 0,!0)])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.value,o=>(e.openBlock(),e.createBlock(e.unref(d.motion).span,{key:o.id,class:"g-button__wave",initial:{x:"-50%",y:"-50%",scale:0,opacity:.2},animate:{x:"-50%",y:"-50%",scale:1,opacity:0},transition:{duration:.6,ease:"easeOut"},style:e.normalizeStyle({left:o.x+"px",top:o.y+"px",width:o.size+"px",height:o.size+"px"}),onAnimationComplete:c=>y(o.id)},null,8,["style","onAnimationComplete"]))),128))],10,B))}}),n=b._export_sfc(v,[["__scopeId","data-v-7de4f689"]]);n.install=i=>{i.component(n.name,n)};exports.GButton=n;exports.default=n;
|
package/lib/GButton/index.mjs
CHANGED
|
@@ -74,7 +74,7 @@ const G = ["type", "disabled"], I = {
|
|
|
74
74
|
}, null, 8, ["style", "onAnimationComplete"]))), 128))
|
|
75
75
|
], 10, G));
|
|
76
76
|
}
|
|
77
|
-
}), c = /* @__PURE__ */ A(X, [["__scopeId", "data-v-
|
|
77
|
+
}), c = /* @__PURE__ */ A(X, [["__scopeId", "data-v-7de4f689"]]);
|
|
78
78
|
c.install = (s) => {
|
|
79
79
|
s.component(c.name, c);
|
|
80
80
|
};
|
package/lib/GButton/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@charset "UTF-8";.g-button[data-v-
|
|
1
|
+
@charset "UTF-8";.g-button[data-v-7de4f689]{--g-button-wave-color: currentcolor;position:relative;display:inline-flex;align-items:center;justify-content:center;gap:6px;height:var(--g-size-middle-height, 32px);padding:0 15px;font-size:var(--g-button-font-size, 14px);line-height:1;white-space:nowrap;cursor:pointer;-webkit-user-select:none;user-select:none;overflow:hidden;color:var(--g-text-color, rgba(0, 0, 0, .88));background:var(--g-button-bg-color, var(--g-button-default-color, #e8e8eb));border:none;border-radius:var(--g-button-radius, 6px);outline:none;transition:all .2s cubic-bezier(.645,.045,.355,1)}.g-button[data-v-7de4f689]:not(.is-disabled):hover,.g-button[data-v-7de4f689]:not(.is-disabled):focus-visible{border-color:var(--g-primary-color, #039be5);color:var(--g-primary-color, #039be5)}.g-button[data-v-7de4f689]:not(.is-disabled):active{border-color:color-mix(in srgb,var(--g-primary-color, #039be5) 70%,#000);color:color-mix(in srgb,var(--g-primary-color, #039be5) 70%,#000)}.g-button.is-block[data-v-7de4f689]{display:flex;width:100%}.g-button.is-disabled[data-v-7de4f689]{cursor:not-allowed;opacity:.5}.g-button--large[data-v-7de4f689]{height:var(--g-size-large-height, 40px);padding:0 20px;font-size:var(--g-size-large-font-size, 16px);border-radius:calc(var(--g-button-radius, 6px) + 2px)}.g-button--small[data-v-7de4f689]{height:var(--g-size-small-height, 24px);padding:0 7px;font-size:var(--g-size-small-font-size, 12px);border-radius:calc(var(--g-button-radius, 6px) - 2px)}.g-button--primary[data-v-7de4f689]{--g-button-wave-color: #fff;color:#fff;background:var(--g-primary-color, #039be5);border-color:var(--g-primary-color, #039be5)}.g-button--primary[data-v-7de4f689]:not(.is-disabled):hover,.g-button--primary[data-v-7de4f689]:not(.is-disabled):focus-visible{color:#fff;background:color-mix(in srgb,var(--g-primary-color, #039be5) 85%,#fff)}.g-button--primary[data-v-7de4f689]:not(.is-disabled):active{color:#fff;background:color-mix(in srgb,var(--g-primary-color, #039be5) 70%,#000)}.g-button--success[data-v-7de4f689],.g-button--warning[data-v-7de4f689],.g-button--danger[data-v-7de4f689]{--g-button-wave-color: #fff;color:#fff}.g-button--success[data-v-7de4f689]:not(.is-disabled):hover,.g-button--success[data-v-7de4f689]:not(.is-disabled):focus-visible,.g-button--warning[data-v-7de4f689]:not(.is-disabled):hover,.g-button--warning[data-v-7de4f689]:not(.is-disabled):focus-visible,.g-button--danger[data-v-7de4f689]:not(.is-disabled):hover,.g-button--danger[data-v-7de4f689]:not(.is-disabled):focus-visible{color:#fff;background:color-mix(in srgb,var(--g-button-type-color) 85%,#fff)}.g-button--success[data-v-7de4f689]:not(.is-disabled):active,.g-button--warning[data-v-7de4f689]:not(.is-disabled):active,.g-button--danger[data-v-7de4f689]:not(.is-disabled):active{color:#fff;background:color-mix(in srgb,var(--g-button-type-color) 70%,#000)}.g-button--success[data-v-7de4f689]{--g-button-type-color: var(--g-success-color, #50c189);background:var(--g-button-type-color);border-color:var(--g-button-type-color)}.g-button--warning[data-v-7de4f689]{--g-button-type-color: var(--g-warning-color, #f78716);background:var(--g-button-type-color);border-color:var(--g-button-type-color)}.g-button--danger[data-v-7de4f689]{--g-button-type-color: var(--g-danger-color, #e1594d);background:var(--g-button-type-color);border-color:var(--g-button-type-color)}.g-button--emphasis[data-v-7de4f689]{--g-button-wave-color: var(--g-emphasis-text-color, #fff);color:var(--g-emphasis-text-color, #fff);background:var(--g-emphasis-color, #000)}.g-button--emphasis[data-v-7de4f689]:not(.is-disabled):hover,.g-button--emphasis[data-v-7de4f689]:not(.is-disabled):focus-visible{color:var(--g-emphasis-text-color, #fff);background:color-mix(in srgb,var(--g-emphasis-color, #000) 85%,var(--g-emphasis-text-color, #fff))}.g-button--emphasis[data-v-7de4f689]:not(.is-disabled):active{color:var(--g-emphasis-text-color, #fff);background:color-mix(in srgb,var(--g-emphasis-color, #000) 70%,var(--g-emphasis-text-color, #fff))}.g-button--link[data-v-7de4f689]{height:auto;padding:2px 5px;background:transparent;border-color:transparent}.g-button--link[data-v-7de4f689]:not(.is-disabled):hover,.g-button--link[data-v-7de4f689]:not(.is-disabled):focus-visible{color:color-mix(in srgb,var(--g-primary-color, #039be5) 85%,#fff);background:transparent}.g-button__loading[data-v-7de4f689]{width:1em;height:1em;border:2px solid currentcolor;border-top-color:transparent;border-radius:50%;animation:g-button-spin-7de4f689 .6s linear infinite}.g-button__icon[data-v-7de4f689]{display:inline-flex;align-items:center}.g-button__icon[data-v-7de4f689] svg{width:1em;height:1em;display:block}.g-button__wave[data-v-7de4f689]{position:absolute;border-radius:50%;background:var(--g-button-wave-color);opacity:.2;pointer-events:none}@keyframes g-button-spin-7de4f689{to{transform:rotate(360deg)}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),W=["data-size","data-disabled"],q=["aria-expanded","aria-controls","aria-activedescendant","aria-label","disabled"],F=["data-empty"],Z=["data-side","data-align"],J=["id","aria-label","data-live"],Q=["id","aria-selected","data-index"],X={class:"g-dropdown__option-label"},ee={key:0,class:"g-dropdown__option-tag"},te=["data-on"],oe=4,ne=1,ae=6,g=t.defineComponent({__name:"index",props:{options:{default:()=>["One","Two","Three"]},value:{default:void 0},defaultValue:{default:void 0},placeholder:{default:"Select…"},showTags:{type:Boolean,default:!0},accentColor:{default:"#f5f5f5"},surfaceColor:{default:"#27272a"},highlightColor:{default:"#3f3f46"},textColor:{default:"#f5f5f5"},size:{default:"md"},radius:{default:10},menuWidth:{default:176},placement:{default:"bottom"},align:{default:"left"},popDuration:{default:180},glideDuration:{default:220},rememberPosition:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},ariaLabel:{default:"Select"},className:{default:""}},emits:["change"],setup(_,{emit:A}){const $={sm:{chip:28,row:26,font:12},md:{chip:32,row:30,font:13},lg:{chip:44,row:40,font:14}},M=e=>typeof e=="string"?{value:e,label:e}:e,R=(e,o,n)=>{const r=n.toLowerCase(),u=e.length;for(let i=1;i<=u;i++){const V=(o+i)%u;if(e[V].label.toLowerCase().startsWith(r))return V}return o},a=_,I=A,f=t.computed(()=>a.options.map(M)),N=t.ref(a.defaultValue??""),k=t.computed(()=>a.value??N.value),c=t.computed(()=>f.value.findIndex(e=>e.value===k.value)),s=t.ref("closed"),l=t.ref(null),E=t.ref(a.placement),p=t.ref(null),T=t.ref(null),D=t.ref(null),x=t.ref(null);let v=!1,h,d=null;const w=t.useId(),y=t.computed(()=>$[a.size]??$.md),b=t.computed(()=>y.value.row+ne),L=t.computed(()=>Math.round(a.popDuration*2/3));t.watch(s,e=>{if(e!=="open")return;const o=D.value,n=p.value;if(!o||!n)return;const r=n.getBoundingClientRect(),u=o.offsetHeight+ae;E.value=a.placement==="bottom"&&r.bottom+u>window.innerHeight?"top":a.placement==="top"&&r.top-u<0?"bottom":a.placement,o.style.transitionDuration=v?"0ms":"",o.dataset.state="closed",o.offsetHeight,o.dataset.state="open";const i=x.value;i&&(i.style.transition="none",i.style.transform=`translateY(${Math.max(0,c.value)*b.value}px)`,i.style.opacity="0",i.offsetHeight,i.style.transition="")},{flush:"post"}),t.watch([l,s,b],()=>{const e=x.value;if(!e||s.value!=="open")return;if(l.value===null){e.style.opacity="0";return}const o=v||e.style.opacity!=="1";e.style.transitionDuration=o?"0ms, 150ms":"",e.style.transform=`translateY(${l.value*b.value}px)`,e.style.opacity="1",v=!1},{flush:"post"});const P=e=>{a.disabled||(clearTimeout(h),v=!0,l.value=c.value>=0?c.value:e?0:null,s.value="open")},m=e=>{l.value=null,clearTimeout(h);const o=D.value;if(e==="instant"||!o){s.value="closed";return}o.style.transitionDuration="",o.dataset.state="closed",s.value="closing",h=setTimeout(()=>s.value="closed",L.value+20)},S=(e,o)=>{const n=f.value[e];if(!n){m("instant");return}n.value!==k.value&&(a.value===void 0&&(N.value=n.value),I("change",n.value,n),!o&&p.value&&(p.value.dataset.swap="")),m("instant"),T.value?.focus({preventScroll:!0})},z=e=>{const o=e.key,n=f.value.length,r=l.value??Math.max(0,c.value);if(s.value!=="open"){(o==="Enter"||o===" "||o==="ArrowDown"||o==="ArrowUp")&&(e.preventDefault(),P(!0));return}const u=i=>{e.preventDefault(),v=!0,l.value=Math.min(n-1,Math.max(0,i))};o==="ArrowDown"||o==="ArrowUp"?u(l.value===null?r:r+(o==="ArrowDown"?1:-1)):o==="Home"||o==="End"?u(o==="Home"?0:n-1):o==="Enter"||o===" "?(e.preventDefault(),S(r,!0)):o==="Escape"||o==="Tab"?(o==="Escape"&&e.preventDefault(),m("instant")):o.length===1&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&u(R(f.value,r,o))},H=e=>{e.button!==0||a.disabled||(e.currentTarget.focus({preventScroll:!0}),s.value==="open"?m("pop"):P(!1))};t.watch(s,(e,o,n)=>{if(e==="closed")return;const r=u=>{p.value&&!p.value.contains(u.target)&&m("pop")};document.addEventListener("pointerdown",r,!0),n(()=>document.removeEventListener("pointerdown",r,!0))}),t.watch(()=>a.disabled,e=>{e&&s.value!=="closed"&&m("instant")}),t.onUnmounted(()=>clearTimeout(h));const B=e=>{const o=d;if(!o)return null;const n=Math.floor((e-o.top-oe)/b.value);return n>=0&&n<f.value.length?n:null},K=e=>{if(d)return;const o=e.currentTarget;try{o.setPointerCapture(e.pointerId)}catch{}d={id:e.pointerId,top:o.getBoundingClientRect().top},v=!0,l.value=B(e.clientY)},U=e=>{if(!d||d.id!==e.pointerId)return;const o=B(e.clientY);o!==l.value&&(l.value=o)},C=e=>{if(!d||d.id!==e.pointerId)return;const o=e.type==="pointerup"?B(e.clientY):null;d=null,o!==null?S(o,!1):a.rememberPosition||(l.value=null)},Y=e=>{if(e.pointerType==="touch"||d)return;const o=e.target.closest("[data-index]");if(!o)return;const n=Number(o.dataset.index);n!==l.value&&(l.value=n)},j=()=>{!d&&!a.rememberPosition&&(l.value=null)},O=e=>{e.animationName==="gs-swap"&&p.value&&delete p.value.dataset.swap},G=t.computed(()=>({"--gs-accent":a.accentColor,"--gs-surface":a.surfaceColor,"--gs-highlight":a.highlightColor,"--gs-text":a.textColor,"--gs-radius":`${a.radius}px`,"--gs-inner-radius":`${Math.max(3,a.radius-4)}px`,"--gs-chip":`${y.value.chip}px`,"--gs-row":`${y.value.row}px`,"--gs-font":`${y.value.font}px`,"--gs-menu-w":`${a.menuWidth}px`,"--gs-pop":`${a.popDuration}ms`,"--gs-pop-out":`${L.value}ms`,"--gs-glide":`${a.glideDuration}ms`,"--gs-origin":`${E.value==="bottom"?"top":"bottom"} ${a.align}`}));return(e,o)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootRef",ref:p,class:t.normalizeClass(["g-dropdown",e.className]),"data-size":e.size,"data-disabled":e.disabled?"":void 0,style:t.normalizeStyle(G.value),onAnimationend:O},[t.createElementVNode("button",{ref_key:"triggerRef",ref:T,type:"button",role:"combobox","aria-haspopup":"listbox","aria-expanded":s.value==="open","aria-controls":`${t.unref(w)}-list`,"aria-activedescendant":l.value!==null?`${t.unref(w)}-${l.value}`:void 0,"aria-label":e.ariaLabel,disabled:e.disabled,class:"g-dropdown__trigger",onPointerdown:H,onKeydown:z},[(t.openBlock(),t.createElementBlock("span",{key:k.value,class:"g-dropdown__label","data-empty":c.value<0?"":void 0},t.toDisplayString(c.value>=0?f.value[c.value].label:e.placeholder),9,F)),o[0]||(o[0]=t.createElementVNode("span",{class:"g-dropdown__arrow","aria-hidden":"true"},[t.createElementVNode("svg",{viewBox:"0 0 24 24",width:"12",height:"12",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"},[t.createElementVNode("path",{d:"m6 9 6 6 6-6"})])],-1))],40,q),s.value!=="closed"?(t.openBlock(),t.createElementBlock("div",{key:0,ref_key:"menuRef",ref:D,class:"g-dropdown__menu","data-state":"open","data-side":E.value,"data-align":e.align},[t.createElementVNode("div",{id:`${t.unref(w)}-list`,role:"listbox","aria-label":e.ariaLabel,class:"g-dropdown__list","data-live":l.value!==null?"":void 0,onPointerover:Y,onPointerleave:j,onPointerdown:K,onPointermove:U,onPointerup:C,onPointercancel:C,onLostpointercapture:C},[t.createElementVNode("span",{ref_key:"pillRef",ref:x,class:"g-dropdown__pill","aria-hidden":"true"},null,512),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(f.value,(n,r)=>(t.openBlock(),t.createElementBlock("div",{id:`${t.unref(w)}-${r}`,key:n.value,role:"option","aria-selected":r===c.value,"data-index":r,class:"g-dropdown__option"},[t.createElementVNode("span",X,t.toDisplayString(n.label),1),e.showTags&&n.tag?(t.openBlock(),t.createElementBlock("span",ee,t.toDisplayString(n.tag),1)):t.createCommentVNode("",!0),t.createElementVNode("span",{class:"g-dropdown__option-check","data-on":r===c.value?"":void 0,"aria-hidden":"true"},o[1]||(o[1]=[t.createElementVNode("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor","stroke-width":"2.5","stroke-linecap":"round","stroke-linejoin":"round"},[t.createElementVNode("path",{d:"m5 12 5 5 9-9"})],-1)]),8,te)],8,Q))),128))],40,J)],8,Z)):t.createCommentVNode("",!0)],46,W))}});g.install=_=>{_.component(g.name,g)};exports.GDropdown=g;exports.default=g;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { defineComponent as te, computed as m, ref as f, useId as oe, watch as D, onUnmounted as ae, createElementBlock as w, openBlock as y, normalizeStyle as ne, normalizeClass as le, createElementVNode as d, createCommentVNode as Y, unref as $, toDisplayString as S, Fragment as se, renderList as ie } from "vue";
|
|
2
|
+
const re = ["data-size", "data-disabled"], ue = ["aria-expanded", "aria-controls", "aria-activedescendant", "aria-label", "disabled"], de = ["data-empty"], ce = ["data-side", "data-align"], pe = ["id", "aria-label", "data-live"], fe = ["id", "aria-selected", "data-index"], ve = { class: "g-dropdown__option-label" }, me = {
|
|
3
|
+
key: 0,
|
|
4
|
+
class: "g-dropdown__option-tag"
|
|
5
|
+
}, ge = ["data-on"], he = 4, we = 1, ye = 6, B = /* @__PURE__ */ te({
|
|
6
|
+
__name: "index",
|
|
7
|
+
props: {
|
|
8
|
+
options: { default: () => ["One", "Two", "Three"] },
|
|
9
|
+
value: { default: void 0 },
|
|
10
|
+
defaultValue: { default: void 0 },
|
|
11
|
+
placeholder: { default: "Select…" },
|
|
12
|
+
showTags: { type: Boolean, default: !0 },
|
|
13
|
+
accentColor: { default: "#f5f5f5" },
|
|
14
|
+
surfaceColor: { default: "#27272a" },
|
|
15
|
+
highlightColor: { default: "#3f3f46" },
|
|
16
|
+
textColor: { default: "#f5f5f5" },
|
|
17
|
+
size: { default: "md" },
|
|
18
|
+
radius: { default: 10 },
|
|
19
|
+
menuWidth: { default: 176 },
|
|
20
|
+
placement: { default: "bottom" },
|
|
21
|
+
align: { default: "left" },
|
|
22
|
+
popDuration: { default: 180 },
|
|
23
|
+
glideDuration: { default: 220 },
|
|
24
|
+
rememberPosition: { type: Boolean, default: !0 },
|
|
25
|
+
disabled: { type: Boolean, default: !1 },
|
|
26
|
+
ariaLabel: { default: "Select" },
|
|
27
|
+
className: { default: "" }
|
|
28
|
+
},
|
|
29
|
+
emits: ["change"],
|
|
30
|
+
setup(C, { emit: V }) {
|
|
31
|
+
const M = {
|
|
32
|
+
sm: { chip: 28, row: 26, font: 12 },
|
|
33
|
+
md: { chip: 32, row: 30, font: 13 },
|
|
34
|
+
lg: { chip: 44, row: 40, font: 14 }
|
|
35
|
+
}, j = (e) => typeof e == "string" ? { value: e, label: e } : e, G = (e, t, o) => {
|
|
36
|
+
const l = o.toLowerCase(), r = e.length;
|
|
37
|
+
for (let i = 1; i <= r; i++) {
|
|
38
|
+
const U = (t + i) % r;
|
|
39
|
+
if (e[U].label.toLowerCase().startsWith(l)) return U;
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
}, a = C, O = V, v = m(() => a.options.map(j)), I = f(a.defaultValue ?? ""), L = m(() => a.value ?? I.value), c = m(() => v.value.findIndex((e) => e.value === L.value)), s = f("closed"), n = f(null), T = f(a.placement), p = f(null), z = f(null), P = f(null), E = f(null);
|
|
43
|
+
let g = !1, b, u = null;
|
|
44
|
+
const _ = oe(), k = m(() => M[a.size] ?? M.md), x = m(() => k.value.row + we), N = m(() => Math.round(a.popDuration * 2 / 3));
|
|
45
|
+
D(
|
|
46
|
+
s,
|
|
47
|
+
(e) => {
|
|
48
|
+
if (e !== "open") return;
|
|
49
|
+
const t = P.value, o = p.value;
|
|
50
|
+
if (!t || !o) return;
|
|
51
|
+
const l = o.getBoundingClientRect(), r = t.offsetHeight + ye;
|
|
52
|
+
T.value = a.placement === "bottom" && l.bottom + r > window.innerHeight ? "top" : a.placement === "top" && l.top - r < 0 ? "bottom" : a.placement, t.style.transitionDuration = g ? "0ms" : "", t.dataset.state = "closed", t.offsetHeight, t.dataset.state = "open";
|
|
53
|
+
const i = E.value;
|
|
54
|
+
i && (i.style.transition = "none", i.style.transform = `translateY(${Math.max(0, c.value) * x.value}px)`, i.style.opacity = "0", i.offsetHeight, i.style.transition = "");
|
|
55
|
+
},
|
|
56
|
+
{ flush: "post" }
|
|
57
|
+
), D(
|
|
58
|
+
[n, s, x],
|
|
59
|
+
() => {
|
|
60
|
+
const e = E.value;
|
|
61
|
+
if (!e || s.value !== "open") return;
|
|
62
|
+
if (n.value === null) {
|
|
63
|
+
e.style.opacity = "0";
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const t = g || e.style.opacity !== "1";
|
|
67
|
+
e.style.transitionDuration = t ? "0ms, 150ms" : "", e.style.transform = `translateY(${n.value * x.value}px)`, e.style.opacity = "1", g = !1;
|
|
68
|
+
},
|
|
69
|
+
{ flush: "post" }
|
|
70
|
+
);
|
|
71
|
+
const H = (e) => {
|
|
72
|
+
a.disabled || (clearTimeout(b), g = !0, n.value = c.value >= 0 ? c.value : e ? 0 : null, s.value = "open");
|
|
73
|
+
}, h = (e) => {
|
|
74
|
+
n.value = null, clearTimeout(b);
|
|
75
|
+
const t = P.value;
|
|
76
|
+
if (e === "instant" || !t) {
|
|
77
|
+
s.value = "closed";
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
t.style.transitionDuration = "", t.dataset.state = "closed", s.value = "closing", b = setTimeout(() => s.value = "closed", N.value + 20);
|
|
81
|
+
}, K = (e, t) => {
|
|
82
|
+
const o = v.value[e];
|
|
83
|
+
if (!o) {
|
|
84
|
+
h("instant");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
o.value !== L.value && (a.value === void 0 && (I.value = o.value), O("change", o.value, o), !t && p.value && (p.value.dataset.swap = "")), h("instant"), z.value?.focus({ preventScroll: !0 });
|
|
88
|
+
}, W = (e) => {
|
|
89
|
+
const t = e.key, o = v.value.length, l = n.value ?? Math.max(0, c.value);
|
|
90
|
+
if (s.value !== "open") {
|
|
91
|
+
(t === "Enter" || t === " " || t === "ArrowDown" || t === "ArrowUp") && (e.preventDefault(), H(!0));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const r = (i) => {
|
|
95
|
+
e.preventDefault(), g = !0, n.value = Math.min(o - 1, Math.max(0, i));
|
|
96
|
+
};
|
|
97
|
+
t === "ArrowDown" || t === "ArrowUp" ? r(n.value === null ? l : l + (t === "ArrowDown" ? 1 : -1)) : t === "Home" || t === "End" ? r(t === "Home" ? 0 : o - 1) : t === "Enter" || t === " " ? (e.preventDefault(), K(l, !0)) : t === "Escape" || t === "Tab" ? (t === "Escape" && e.preventDefault(), h("instant")) : t.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey && r(G(v.value, l, t));
|
|
98
|
+
}, F = (e) => {
|
|
99
|
+
e.button !== 0 || a.disabled || (e.currentTarget.focus({ preventScroll: !0 }), s.value === "open" ? h("pop") : H(!1));
|
|
100
|
+
};
|
|
101
|
+
D(s, (e, t, o) => {
|
|
102
|
+
if (e === "closed") return;
|
|
103
|
+
const l = (r) => {
|
|
104
|
+
p.value && !p.value.contains(r.target) && h("pop");
|
|
105
|
+
};
|
|
106
|
+
document.addEventListener("pointerdown", l, !0), o(() => document.removeEventListener("pointerdown", l, !0));
|
|
107
|
+
}), D(
|
|
108
|
+
() => a.disabled,
|
|
109
|
+
(e) => {
|
|
110
|
+
e && s.value !== "closed" && h("instant");
|
|
111
|
+
}
|
|
112
|
+
), ae(() => clearTimeout(b));
|
|
113
|
+
const A = (e) => {
|
|
114
|
+
const t = u;
|
|
115
|
+
if (!t) return null;
|
|
116
|
+
const o = Math.floor((e - t.top - he) / x.value);
|
|
117
|
+
return o >= 0 && o < v.value.length ? o : null;
|
|
118
|
+
}, Z = (e) => {
|
|
119
|
+
if (u) return;
|
|
120
|
+
const t = e.currentTarget;
|
|
121
|
+
try {
|
|
122
|
+
t.setPointerCapture(e.pointerId);
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
125
|
+
u = { id: e.pointerId, top: t.getBoundingClientRect().top }, g = !0, n.value = A(e.clientY);
|
|
126
|
+
}, q = (e) => {
|
|
127
|
+
if (!u || u.id !== e.pointerId) return;
|
|
128
|
+
const t = A(e.clientY);
|
|
129
|
+
t !== n.value && (n.value = t);
|
|
130
|
+
}, R = (e) => {
|
|
131
|
+
if (!u || u.id !== e.pointerId) return;
|
|
132
|
+
const t = e.type === "pointerup" ? A(e.clientY) : null;
|
|
133
|
+
u = null, t !== null ? K(t, !1) : a.rememberPosition || (n.value = null);
|
|
134
|
+
}, J = (e) => {
|
|
135
|
+
if (e.pointerType === "touch" || u) return;
|
|
136
|
+
const t = e.target.closest("[data-index]");
|
|
137
|
+
if (!t) return;
|
|
138
|
+
const o = Number(t.dataset.index);
|
|
139
|
+
o !== n.value && (n.value = o);
|
|
140
|
+
}, Q = () => {
|
|
141
|
+
!u && !a.rememberPosition && (n.value = null);
|
|
142
|
+
}, X = (e) => {
|
|
143
|
+
e.animationName === "gs-swap" && p.value && delete p.value.dataset.swap;
|
|
144
|
+
}, ee = m(
|
|
145
|
+
() => ({
|
|
146
|
+
"--gs-accent": a.accentColor,
|
|
147
|
+
"--gs-surface": a.surfaceColor,
|
|
148
|
+
"--gs-highlight": a.highlightColor,
|
|
149
|
+
"--gs-text": a.textColor,
|
|
150
|
+
"--gs-radius": `${a.radius}px`,
|
|
151
|
+
"--gs-inner-radius": `${Math.max(3, a.radius - 4)}px`,
|
|
152
|
+
"--gs-chip": `${k.value.chip}px`,
|
|
153
|
+
"--gs-row": `${k.value.row}px`,
|
|
154
|
+
"--gs-font": `${k.value.font}px`,
|
|
155
|
+
"--gs-menu-w": `${a.menuWidth}px`,
|
|
156
|
+
"--gs-pop": `${a.popDuration}ms`,
|
|
157
|
+
"--gs-pop-out": `${N.value}ms`,
|
|
158
|
+
"--gs-glide": `${a.glideDuration}ms`,
|
|
159
|
+
"--gs-origin": `${T.value === "bottom" ? "top" : "bottom"} ${a.align}`
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
return (e, t) => (y(), w("div", {
|
|
163
|
+
ref_key: "rootRef",
|
|
164
|
+
ref: p,
|
|
165
|
+
class: le(["g-dropdown", e.className]),
|
|
166
|
+
"data-size": e.size,
|
|
167
|
+
"data-disabled": e.disabled ? "" : void 0,
|
|
168
|
+
style: ne(ee.value),
|
|
169
|
+
onAnimationend: X
|
|
170
|
+
}, [
|
|
171
|
+
d("button", {
|
|
172
|
+
ref_key: "triggerRef",
|
|
173
|
+
ref: z,
|
|
174
|
+
type: "button",
|
|
175
|
+
role: "combobox",
|
|
176
|
+
"aria-haspopup": "listbox",
|
|
177
|
+
"aria-expanded": s.value === "open",
|
|
178
|
+
"aria-controls": `${$(_)}-list`,
|
|
179
|
+
"aria-activedescendant": n.value !== null ? `${$(_)}-${n.value}` : void 0,
|
|
180
|
+
"aria-label": e.ariaLabel,
|
|
181
|
+
disabled: e.disabled,
|
|
182
|
+
class: "g-dropdown__trigger",
|
|
183
|
+
onPointerdown: F,
|
|
184
|
+
onKeydown: W
|
|
185
|
+
}, [
|
|
186
|
+
(y(), w("span", {
|
|
187
|
+
key: L.value,
|
|
188
|
+
class: "g-dropdown__label",
|
|
189
|
+
"data-empty": c.value < 0 ? "" : void 0
|
|
190
|
+
}, S(c.value >= 0 ? v.value[c.value].label : e.placeholder), 9, de)),
|
|
191
|
+
t[0] || (t[0] = d("span", {
|
|
192
|
+
class: "g-dropdown__arrow",
|
|
193
|
+
"aria-hidden": "true"
|
|
194
|
+
}, [
|
|
195
|
+
d("svg", {
|
|
196
|
+
viewBox: "0 0 24 24",
|
|
197
|
+
width: "12",
|
|
198
|
+
height: "12",
|
|
199
|
+
fill: "none",
|
|
200
|
+
stroke: "currentColor",
|
|
201
|
+
"stroke-width": "2.5",
|
|
202
|
+
"stroke-linecap": "round",
|
|
203
|
+
"stroke-linejoin": "round"
|
|
204
|
+
}, [
|
|
205
|
+
d("path", { d: "m6 9 6 6 6-6" })
|
|
206
|
+
])
|
|
207
|
+
], -1))
|
|
208
|
+
], 40, ue),
|
|
209
|
+
s.value !== "closed" ? (y(), w("div", {
|
|
210
|
+
key: 0,
|
|
211
|
+
ref_key: "menuRef",
|
|
212
|
+
ref: P,
|
|
213
|
+
class: "g-dropdown__menu",
|
|
214
|
+
"data-state": "open",
|
|
215
|
+
"data-side": T.value,
|
|
216
|
+
"data-align": e.align
|
|
217
|
+
}, [
|
|
218
|
+
d("div", {
|
|
219
|
+
id: `${$(_)}-list`,
|
|
220
|
+
role: "listbox",
|
|
221
|
+
"aria-label": e.ariaLabel,
|
|
222
|
+
class: "g-dropdown__list",
|
|
223
|
+
"data-live": n.value !== null ? "" : void 0,
|
|
224
|
+
onPointerover: J,
|
|
225
|
+
onPointerleave: Q,
|
|
226
|
+
onPointerdown: Z,
|
|
227
|
+
onPointermove: q,
|
|
228
|
+
onPointerup: R,
|
|
229
|
+
onPointercancel: R,
|
|
230
|
+
onLostpointercapture: R
|
|
231
|
+
}, [
|
|
232
|
+
d("span", {
|
|
233
|
+
ref_key: "pillRef",
|
|
234
|
+
ref: E,
|
|
235
|
+
class: "g-dropdown__pill",
|
|
236
|
+
"aria-hidden": "true"
|
|
237
|
+
}, null, 512),
|
|
238
|
+
(y(!0), w(se, null, ie(v.value, (o, l) => (y(), w("div", {
|
|
239
|
+
id: `${$(_)}-${l}`,
|
|
240
|
+
key: o.value,
|
|
241
|
+
role: "option",
|
|
242
|
+
"aria-selected": l === c.value,
|
|
243
|
+
"data-index": l,
|
|
244
|
+
class: "g-dropdown__option"
|
|
245
|
+
}, [
|
|
246
|
+
d("span", ve, S(o.label), 1),
|
|
247
|
+
e.showTags && o.tag ? (y(), w("span", me, S(o.tag), 1)) : Y("", !0),
|
|
248
|
+
d("span", {
|
|
249
|
+
class: "g-dropdown__option-check",
|
|
250
|
+
"data-on": l === c.value ? "" : void 0,
|
|
251
|
+
"aria-hidden": "true"
|
|
252
|
+
}, t[1] || (t[1] = [
|
|
253
|
+
d("svg", {
|
|
254
|
+
viewBox: "0 0 24 24",
|
|
255
|
+
width: "13",
|
|
256
|
+
height: "13",
|
|
257
|
+
fill: "none",
|
|
258
|
+
stroke: "currentColor",
|
|
259
|
+
"stroke-width": "2.5",
|
|
260
|
+
"stroke-linecap": "round",
|
|
261
|
+
"stroke-linejoin": "round"
|
|
262
|
+
}, [
|
|
263
|
+
d("path", { d: "m5 12 5 5 9-9" })
|
|
264
|
+
], -1)
|
|
265
|
+
]), 8, ge)
|
|
266
|
+
], 8, fe))), 128))
|
|
267
|
+
], 40, pe)
|
|
268
|
+
], 8, ce)) : Y("", !0)
|
|
269
|
+
], 46, re));
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
B.install = (C) => {
|
|
273
|
+
C.component(B.name, B);
|
|
274
|
+
};
|
|
275
|
+
export {
|
|
276
|
+
B as GDropdown,
|
|
277
|
+
B as default
|
|
278
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.g-dropdown{position:relative;display:inline-block}.g-dropdown[data-disabled]{opacity:.5}.g-dropdown__trigger{position:relative;display:inline-flex;align-items:center;gap:6px;height:var(--gs-chip);margin:0;padding:0 8px 0 10px;border:0;border-radius:var(--gs-inner-radius);outline:none;background:var(--gs-surface);color:var(--gs-text);font-family:inherit;font-size:var(--gs-font);font-weight:500;line-height:1;cursor:pointer;-webkit-user-select:none;user-select:none;touch-action:manipulation;-webkit-tap-highlight-color:transparent;transition:background-color .1s ease,transform .16s cubic-bezier(.23,1,.32,1)}.g-dropdown__trigger:disabled{cursor:default}.g-dropdown__trigger:not(:disabled):active{transform:scale(.97)}.g-dropdown__trigger[aria-expanded=true]{background:color-mix(in srgb,var(--gs-highlight) 60%,var(--gs-surface))}@media(hover:hover)and (pointer:fine){.g-dropdown__trigger:not(:disabled):hover{background:color-mix(in srgb,var(--gs-highlight) 60%,var(--gs-surface))}}.g-dropdown__label[data-empty]{opacity:.6}.g-dropdown[data-swap] .g-dropdown__label{animation:gs-swap .16s ease}.g-dropdown__arrow{display:inline-flex;color:color-mix(in srgb,var(--gs-text) 55%,transparent);transition:transform .2s cubic-bezier(.23,1,.32,1)}.g-dropdown__trigger[aria-expanded=true] .g-dropdown__arrow{transform:rotate(180deg)}.g-dropdown__menu{position:absolute;z-index:20;top:calc(100% + 6px);left:0;min-width:100%;width:var(--gs-menu-w);padding:4px;border-radius:var(--gs-radius);background:var(--gs-surface);box-shadow:0 4px 16px color-mix(in srgb,#000 22%,transparent);transform:scale(.95);transform-origin:var(--gs-origin);opacity:0;pointer-events:none;transition:opacity var(--gs-pop) cubic-bezier(.23,1,.32,1),transform var(--gs-pop) cubic-bezier(.23,1,.32,1)}.g-dropdown__menu[data-side=top]{top:auto;bottom:calc(100% + 6px)}.g-dropdown__menu[data-align=right]{left:auto;right:0}.g-dropdown__menu[data-state=open]{transform:scale(1);opacity:1;pointer-events:auto}.g-dropdown__menu[data-state=closed]{transition-duration:var(--gs-pop-out);pointer-events:none}.g-dropdown__list{position:relative;display:grid;gap:1px;touch-action:none}.g-dropdown__pill{position:absolute;top:0;right:0;left:0;height:var(--gs-row);border-radius:var(--gs-inner-radius);background:var(--gs-highlight);opacity:0;pointer-events:none;transition:transform var(--gs-glide) cubic-bezier(.23,1,.32,1),opacity .15s ease}.g-dropdown__option{position:relative;z-index:1;display:flex;align-items:center;gap:8px;height:var(--gs-row);padding:0 8px 0 10px;border-radius:var(--gs-inner-radius);color:var(--gs-text);font-size:var(--gs-font);cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;transition:background-color .15s ease}.g-dropdown__option[aria-selected=true]{background:color-mix(in srgb,var(--gs-highlight) 60%,transparent)}.g-dropdown__list[data-live] .g-dropdown__option[aria-selected=true]{background:transparent}.g-dropdown__option-label{flex:1 1 0%;min-width:0;overflow:hidden;font-weight:500;text-overflow:ellipsis;white-space:nowrap}.g-dropdown__option-tag{flex-shrink:0;color:color-mix(in srgb,var(--gs-text) 55%,transparent);font-size:calc(var(--gs-font) - 2px)}.g-dropdown__option-check{display:inline-flex;flex-shrink:0;visibility:hidden;color:var(--gs-accent)}.g-dropdown__option-check[data-on]{visibility:visible}@keyframes gs-swap{0%{opacity:.6;filter:blur(2px)}}@media(prefers-reduced-motion:reduce){.g-dropdown__trigger{transition:background-color .1s ease}.g-dropdown__trigger:not(:disabled):active{transform:none}.g-dropdown[data-swap] .g-dropdown__label{animation:none}.g-dropdown__arrow{transition:none}.g-dropdown__menu{transform:none!important;transition:opacity var(--gs-pop) ease}.g-dropdown__menu[data-state=closed]{transition-duration:var(--gs-pop-out)}.g-dropdown__pill{transition:opacity .15s ease}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/lib/GPicker/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),ve=require("../GInput/index.js"),me=require("../GTag/index.js"),be=require("../GTree/index.js"),O=require("
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),ve=require("../GInput/index.js"),me=require("../GTag/index.js"),be=require("../GTree/index.js"),O=require("../GToast/index.js"),x=require("motion-v"),ge=require("../GBranched-BtF7heMk.js"),he={key:0,class:"g-picker__tags"},ye=t.defineComponent({__name:"index",props:{modelValue:{default:()=>[]},data:{default:()=>[]},props:{default:()=>({})},echoProps:{},nodeKey:{default:"id"},placeholder:{default:"请输入关键字搜索"},width:{default:320},popperMaxHeight:{default:320},popperZIndex:{default:2e3},popperOffset:{default:4},defaultExpandAll:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},clearable:{type:Boolean,default:!0},closable:{type:Boolean,default:!0},tagType:{default:"primary"},tagVariant:{default:"filled"},clearInputAfterSelect:{type:Boolean,default:!0},enterToAdd:{type:Boolean,default:!0},valueFormat:{default:"value"},selectable:{},filterMethod:{},duplicateMessage:{default:"该项已添加"},notFoundMessage:{default:"未找到匹配项"}},emits:["update:modelValue","change","add","remove","node-click","duplicate","not-found"],setup(E,{expose:R,emit:$}){const a=E,r=$,H=t.computed(()=>({label:a.props.label||"label",children:a.props.children||"children",disabled:a.props.disabled})),q=t.computed(()=>a.props.value||a.nodeKey||"id"),G=t.computed(()=>a.props.label||"label"),j=t.computed(()=>a.props.children||"children"),S=t.computed(()=>a.props.isLeaf),K=t.computed(()=>a.echoProps?.value||"value"),U=t.computed(()=>a.echoProps?.label||"label"),v=e=>e?e[q.value]:void 0,c=e=>e?e[G.value]:"",M=e=>e?e[j.value]:void 0,Z=e=>e?.[K.value]??e?.value,W=e=>e?.[U.value]??e?.label,d=e=>{if(!e)return!1;if(typeof a.selectable=="function")return a.selectable(e);if(S.value&&e[S.value]!==void 0)return!!e[S.value];const o=M(e);return!o||!o.length},C=t.computed(()=>{const e=new Map,o=(l=[])=>{l.forEach(n=>{d(n)&&e.set(v(n),n);const s=M(n);s?.length&&o(s)})};return o(a.data||[]),e}),i=t.computed(()=>(a.modelValue||[]).map(o=>{const l=a.valueFormat==="object"?Z(o):o,n=C.value.get(l),s=a.valueFormat==="object"?W(o):void 0;return{value:l,label:n?c(n):s??String(l??""),raw:n??(a.valueFormat==="object"?o:void 0)}})),y=e=>i.value.some(o=>o.value===e),w=t.ref(""),u=t.ref(!1),N=t.ref(null),I=t.ref(null),T=t.ref(null),p=t.ref(null),J=e=>{if(!e){p.value=null;return}p.value=e.$el??(e instanceof HTMLElement?e:null)},L=t.ref({}),m=t.ref("bottom"),Q=t.computed(()=>({opacity:0,scale:.95,y:m.value==="bottom"?-8:8})),X={opacity:1,scale:1,y:0},Y=t.computed(()=>({opacity:0,scale:.95,y:m.value==="bottom"?-8:8})),D={duration:.2,ease:"easeOut"},ee=t.computed(()=>({...L.value,transformOrigin:m.value==="bottom"?"top center":"bottom center"})),te={opacity:0,scale:.8},oe={opacity:1,scale:1},le={opacity:0,scale:.8},ae={duration:.2,ease:"easeOut"},ne=t.computed(()=>typeof a.width=="number"?`${a.width}px`:a.width),_=()=>{a.disabled||(u.value=!0)},k=()=>{if(!u.value)return;const e=T.value,o=p.value;if(!e||!o)return;const l=e.getBoundingClientRect(),n=o.offsetHeight||a.popperMaxHeight,B=window.innerHeight-l.bottom-a.popperOffset,pe=l.top-a.popperOffset,z=B>=n||B>=pe?"bottom":"top";m.value=z;const fe=z==="bottom"?l.bottom+a.popperOffset:l.top-n-a.popperOffset;L.value={position:"fixed",top:`${fe}px`,left:`${l.left}px`,width:`${l.width}px`,zIndex:String(a.popperZIndex)}};let f=null;const b=()=>{u.value&&(f&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{f=null,k()}))};let g=null;const re=()=>{typeof ResizeObserver>"u"||!p.value||(g?.disconnect(),g=new ResizeObserver(()=>b()),g.observe(p.value))},P=()=>{g?.disconnect(),g=null};t.watch(u,async e=>{if(!e){P();return}await t.nextTick(),k(),requestAnimationFrame(k),re()});const A=e=>{if(!u.value)return;const o=e.target;I.value?.contains(o)||p.value?.contains(o)||(u.value=!1)};t.onMounted(()=>{document.addEventListener("mousedown",A,!0),window.addEventListener("scroll",b,!0),window.addEventListener("resize",b)}),t.onBeforeUnmount(()=>{document.removeEventListener("mousedown",A,!0),window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b),f&&cancelAnimationFrame(f),P()});const se=e=>{u.value=!0,N.value?.filter(e),t.nextTick(k)},ie=(e,o)=>e?typeof a.filterMethod=="function"?a.filterMethod(e,o):String(c(o)??"").toLowerCase().includes(String(e).toLowerCase()):!0,ue=e=>{r("node-click",e),d(e)&&(F(e),u.value=!1)},ce=e=>a.valueFormat==="object"?{value:e.value,label:e.label,raw:e.raw}:e.value,F=e=>{const o=v(e);if(o==null||o==="")return;if(y(o)){const s={value:o,label:c(e),raw:e};r("duplicate",s),a.duplicateMessage&&O.toast.warning(a.duplicateMessage,{position:"top-center"});return}const l={value:o,label:c(e),raw:e},n=[...a.modelValue||[],ce(l)];r("update:modelValue",n),r("add",l),r("change",n,[...i.value,l]),a.clearInputAfterSelect&&(w.value="")},de=()=>{if(!a.enterToAdd)return;const e=(w.value||"").trim();if(!e)return;let o=null;for(const l of C.value.values())if(c(l)===e){o=l;break}if(!o){r("not-found",e),a.notFoundMessage&&O.toast.warning(a.notFoundMessage,{position:"top-center"});return}F(o)},V=e=>{if(e<0||e>=i.value.length)return;const o=i.value[e],l=[...a.modelValue||[]];l.splice(e,1),r("update:modelValue",l),o&&r("remove",o,e);const n=i.value.filter((s,B)=>B!==e);r("change",l,n)};return R({open:_,close:()=>u.value=!1,clear:()=>{r("update:modelValue",[]),r("change",[],[])},addByValue:e=>{const o=C.value.get(e);o&&F(o)},removeByIndex:e=>{V(e)},removeByValue:e=>{const o=i.value.findIndex(l=>l.value===e);o>-1&&V(o)},getSelectedItems:()=>i.value}),(e,o)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(["g-picker",{"is-disabled":e.disabled}])},[t.createElementVNode("div",{class:"g-picker__wrap",ref_key:"wrapRef",ref:I},[t.createElementVNode("div",{class:"g-picker__input-box",ref_key:"inputBoxRef",ref:T,style:t.normalizeStyle({width:ne.value})},[t.createVNode(t.unref(ve.default),{modelValue:w.value,"onUpdate:modelValue":o[0]||(o[0]=l=>w.value=l),placeholder:e.placeholder,clearable:e.clearable,disabled:e.disabled,block:"",class:"g-picker__input",onFocus:_,onClick:_,onInput:se,onKeyup:t.withKeys(de,["enter"])},null,8,["modelValue","placeholder","clearable","disabled"])],4),(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.createVNode(t.unref(x.AnimatePresence),null,{default:t.withCtx(()=>[u.value?(t.openBlock(),t.createBlock(t.unref(x.motion).div,{key:0,ref:J,class:t.normalizeClass(["g-picker__popover",`is-${m.value}`]),style:t.normalizeStyle(ee.value),initial:Q.value,animate:X,exit:Y.value,transition:D,onMousedown:o[1]||(o[1]=t.withModifiers(()=>{},["prevent"]))},{default:t.withCtx(()=>[t.createElementVNode("div",{class:"g-picker__tree-wrap",style:t.normalizeStyle({maxHeight:e.popperMaxHeight+"px"})},[t.createVNode(t.unref(be.default),{ref_key:"treeRef",ref:N,data:e.data,props:H.value,"node-key":e.nodeKey,"filter-method":ie,"default-expand-all":e.defaultExpandAll,"highlight-current":!1,onNodeClick:ue},{default:t.withCtx(({data:l,level:n,expanded:s})=>[t.renderSlot(e.$slots,"tree-node",{data:l,node:{level:n,expanded:s},selectable:d(l),selected:y(v(l))},()=>[l?(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["g-picker__node",{"is-selectable":d(l),"is-selected":d(l)&&y(v(l))}])},[t.renderSlot(e.$slots,"leaf-icon",{data:l,selectable:d(l),selected:y(v(l))},void 0,!0),t.createTextVNode(" "+t.toDisplayString(c(l)),1)],2)):t.createCommentVNode("",!0)],!0)]),_:3},8,["data","props","node-key","default-expand-all"])],4)]),_:3},8,["class","style","initial","exit"])):t.createCommentVNode("",!0)]),_:3})])),i.value.length?(t.openBlock(),t.createElementBlock("div",he,[t.renderSlot(e.$slots,"tags",{items:i.value,remove:V},()=>[t.createVNode(t.unref(x.AnimatePresence),{mode:"popLayout"},{default:t.withCtx(()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(i.value,(l,n)=>(t.openBlock(),t.createBlock(t.unref(x.motion).div,{key:l.value,layout:!0,class:"g-picker__tag-motion",initial:te,animate:oe,exit:le,transition:ae},{default:t.withCtx(()=>[t.createVNode(t.unref(me.default),{class:"g-picker__tag",type:e.tagType,variant:e.tagVariant,closable:e.closable&&!e.disabled,onClose:s=>V(n)},{default:t.withCtx(()=>[t.renderSlot(e.$slots,"tag",{item:l,index:n},()=>[t.createTextVNode(t.toDisplayString(l.label),1)],!0)]),_:2},1032,["type","variant","closable","onClose"])]),_:2},1024))),128))]),_:3})],!0)])):t.createCommentVNode("",!0)],512)],2))}}),h=ge._export_sfc(ye,[["__scopeId","data-v-92c90ec0"]]);h.install=E=>{E.component(h.name,h)};exports.GPicker=h;exports.default=h;
|
package/lib/GPicker/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as Le, computed as n, ref as c, watch as Se, nextTick as J, onMounted as Ae, onBeforeUnmount as Ce, createElementBlock as
|
|
1
|
+
import { defineComponent as Le, computed as n, ref as c, watch as Se, nextTick as J, onMounted as Ae, onBeforeUnmount as Ce, createElementBlock as I, openBlock as p, normalizeClass as T, createElementVNode as O, createBlock as R, createCommentVNode as N, normalizeStyle as $, createVNode as V, unref as d, withKeys as Pe, Teleport as Te, withCtx as g, withModifiers as Oe, renderSlot as M, createTextVNode as Q, toDisplayString as X, Fragment as Re, renderList as Ne } from "vue";
|
|
2
2
|
import $e from "../GInput/index.mjs";
|
|
3
3
|
import ze from "../GTag/index.mjs";
|
|
4
4
|
import He from "../GTree/index.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { toast as Y } from "../GToast/index.mjs";
|
|
6
6
|
import { AnimatePresence as D, motion as ee } from "motion-v";
|
|
7
7
|
import { _ as Ke } from "../GBranched-vnLlYOl9.mjs";
|
|
8
8
|
const je = {
|
|
@@ -63,7 +63,7 @@ const je = {
|
|
|
63
63
|
label: a ? f(a) : s ?? String(l ?? ""),
|
|
64
64
|
raw: a ?? (o.valueFormat === "object" ? t : void 0)
|
|
65
65
|
};
|
|
66
|
-
})),
|
|
66
|
+
})), F = (e) => i.value.some((t) => t.value === e), _ = c(""), u = c(!1), K = c(null), j = c(null), G = c(null), m = c(null), pe = (e) => {
|
|
67
67
|
if (!e) {
|
|
68
68
|
m.value = null;
|
|
69
69
|
return;
|
|
@@ -84,16 +84,16 @@ const je = {
|
|
|
84
84
|
() => typeof o.width == "number" ? `${o.width}px` : o.width
|
|
85
85
|
), C = () => {
|
|
86
86
|
o.disabled || (u.value = !0);
|
|
87
|
-
},
|
|
87
|
+
}, E = () => {
|
|
88
88
|
if (!u.value) return;
|
|
89
89
|
const e = G.value, t = m.value;
|
|
90
90
|
if (!e || !t) return;
|
|
91
|
-
const l = e.getBoundingClientRect(), a = t.offsetHeight || o.popperMaxHeight,
|
|
91
|
+
const l = e.getBoundingClientRect(), a = t.offsetHeight || o.popperMaxHeight, B = window.innerHeight - l.bottom - o.popperOffset, Ie = l.top - o.popperOffset, W = B >= a || B >= Ie ? "bottom" : "top";
|
|
92
92
|
y.value = W;
|
|
93
|
-
const
|
|
93
|
+
const Me = W === "bottom" ? l.bottom + o.popperOffset : l.top - a - o.popperOffset;
|
|
94
94
|
U.value = {
|
|
95
95
|
position: "fixed",
|
|
96
|
-
top: `${
|
|
96
|
+
top: `${Me}px`,
|
|
97
97
|
left: `${l.left}px`,
|
|
98
98
|
width: `${l.width}px`,
|
|
99
99
|
zIndex: String(o.popperZIndex)
|
|
@@ -102,7 +102,7 @@ const je = {
|
|
|
102
102
|
let b = null;
|
|
103
103
|
const w = () => {
|
|
104
104
|
u.value && (b && cancelAnimationFrame(b), b = requestAnimationFrame(() => {
|
|
105
|
-
b = null,
|
|
105
|
+
b = null, E();
|
|
106
106
|
}));
|
|
107
107
|
};
|
|
108
108
|
let k = null;
|
|
@@ -116,7 +116,7 @@ const je = {
|
|
|
116
116
|
q();
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
await J(),
|
|
119
|
+
await J(), E(), requestAnimationFrame(E), Ve();
|
|
120
120
|
});
|
|
121
121
|
const Z = (e) => {
|
|
122
122
|
if (!u.value) return;
|
|
@@ -128,23 +128,23 @@ const je = {
|
|
|
128
128
|
}), Ce(() => {
|
|
129
129
|
document.removeEventListener("mousedown", Z, !0), window.removeEventListener("scroll", w, !0), window.removeEventListener("resize", w), b && cancelAnimationFrame(b), q();
|
|
130
130
|
});
|
|
131
|
-
const
|
|
132
|
-
u.value = !0, K.value?.filter(e), J(
|
|
133
|
-
},
|
|
131
|
+
const Fe = (e) => {
|
|
132
|
+
u.value = !0, K.value?.filter(e), J(E);
|
|
133
|
+
}, _e = (e, t) => e ? typeof o.filterMethod == "function" ? o.filterMethod(e, t) : String(f(t) ?? "").toLowerCase().includes(String(e).toLowerCase()) : !0, Ee = (e) => {
|
|
134
134
|
r("node-click", e), v(e) && (P(e), u.value = !1);
|
|
135
135
|
}, xe = (e) => o.valueFormat === "object" ? { value: e.value, label: e.label, raw: e.raw } : e.value, P = (e) => {
|
|
136
136
|
const t = h(e);
|
|
137
137
|
if (t == null || t === "") return;
|
|
138
|
-
if (
|
|
138
|
+
if (F(t)) {
|
|
139
139
|
const s = { value: t, label: f(e), raw: e };
|
|
140
|
-
r("duplicate", s), o.duplicateMessage && Y.warning(o.duplicateMessage);
|
|
140
|
+
r("duplicate", s), o.duplicateMessage && Y.warning(o.duplicateMessage, { position: "top-center" });
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
const l = { value: t, label: f(e), raw: e }, a = [...o.modelValue || [], xe(l)];
|
|
144
|
-
r("update:modelValue", a), r("add", l), r("change", a, [...i.value, l]), o.clearInputAfterSelect && (
|
|
145
|
-
},
|
|
144
|
+
r("update:modelValue", a), r("add", l), r("change", a, [...i.value, l]), o.clearInputAfterSelect && (_.value = "");
|
|
145
|
+
}, Be = () => {
|
|
146
146
|
if (!o.enterToAdd) return;
|
|
147
|
-
const e = (
|
|
147
|
+
const e = (_.value || "").trim();
|
|
148
148
|
if (!e) return;
|
|
149
149
|
let t = null;
|
|
150
150
|
for (const l of A.value.values())
|
|
@@ -153,7 +153,7 @@ const je = {
|
|
|
153
153
|
break;
|
|
154
154
|
}
|
|
155
155
|
if (!t) {
|
|
156
|
-
r("not-found", e), o.notFoundMessage && Y.warning(o.notFoundMessage);
|
|
156
|
+
r("not-found", e), o.notFoundMessage && Y.warning(o.notFoundMessage, { position: "top-center" });
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
159
|
P(t);
|
|
@@ -161,7 +161,7 @@ const je = {
|
|
|
161
161
|
if (e < 0 || e >= i.value.length) return;
|
|
162
162
|
const t = i.value[e], l = [...o.modelValue || []];
|
|
163
163
|
l.splice(e, 1), r("update:modelValue", l), t && r("remove", t, e);
|
|
164
|
-
const a = i.value.filter((s,
|
|
164
|
+
const a = i.value.filter((s, B) => B !== e);
|
|
165
165
|
r("change", l, a);
|
|
166
166
|
};
|
|
167
167
|
return te({
|
|
@@ -189,7 +189,7 @@ const je = {
|
|
|
189
189
|
},
|
|
190
190
|
/** 获取当前归一化后的已选项 */
|
|
191
191
|
getSelectedItems: () => i.value
|
|
192
|
-
}), (e, t) => (p(),
|
|
192
|
+
}), (e, t) => (p(), I("div", {
|
|
193
193
|
class: T(["g-picker", { "is-disabled": e.disabled }])
|
|
194
194
|
}, [
|
|
195
195
|
O("div", {
|
|
@@ -204,8 +204,8 @@ const je = {
|
|
|
204
204
|
style: $({ width: ke.value })
|
|
205
205
|
}, [
|
|
206
206
|
V(d($e), {
|
|
207
|
-
modelValue:
|
|
208
|
-
"onUpdate:modelValue": t[0] || (t[0] = (l) =>
|
|
207
|
+
modelValue: _.value,
|
|
208
|
+
"onUpdate:modelValue": t[0] || (t[0] = (l) => _.value = l),
|
|
209
209
|
placeholder: e.placeholder,
|
|
210
210
|
clearable: e.clearable,
|
|
211
211
|
disabled: e.disabled,
|
|
@@ -213,8 +213,8 @@ const je = {
|
|
|
213
213
|
class: "g-picker__input",
|
|
214
214
|
onFocus: C,
|
|
215
215
|
onClick: C,
|
|
216
|
-
onInput:
|
|
217
|
-
onKeyup: Pe(
|
|
216
|
+
onInput: Fe,
|
|
217
|
+
onKeyup: Pe(Be, ["enter"])
|
|
218
218
|
}, null, 8, ["modelValue", "placeholder", "clearable", "disabled"])
|
|
219
219
|
], 4),
|
|
220
220
|
(p(), R(Te, { to: "body" }, [
|
|
@@ -243,32 +243,32 @@ const je = {
|
|
|
243
243
|
data: e.data,
|
|
244
244
|
props: oe.value,
|
|
245
245
|
"node-key": e.nodeKey,
|
|
246
|
-
"filter-method":
|
|
246
|
+
"filter-method": _e,
|
|
247
247
|
"default-expand-all": e.defaultExpandAll,
|
|
248
248
|
"highlight-current": !1,
|
|
249
|
-
onNodeClick:
|
|
249
|
+
onNodeClick: Ee
|
|
250
250
|
}, {
|
|
251
251
|
default: g(({ data: l, level: a, expanded: s }) => [
|
|
252
|
-
|
|
252
|
+
M(e.$slots, "tree-node", {
|
|
253
253
|
data: l,
|
|
254
254
|
node: { level: a, expanded: s },
|
|
255
255
|
selectable: v(l),
|
|
256
|
-
selected:
|
|
256
|
+
selected: F(h(l))
|
|
257
257
|
}, () => [
|
|
258
|
-
l ? (p(),
|
|
258
|
+
l ? (p(), I("span", {
|
|
259
259
|
key: 0,
|
|
260
260
|
class: T([
|
|
261
261
|
"g-picker__node",
|
|
262
262
|
{
|
|
263
263
|
"is-selectable": v(l),
|
|
264
|
-
"is-selected": v(l) &&
|
|
264
|
+
"is-selected": v(l) && F(h(l))
|
|
265
265
|
}
|
|
266
266
|
])
|
|
267
267
|
}, [
|
|
268
|
-
|
|
268
|
+
M(e.$slots, "leaf-icon", {
|
|
269
269
|
data: l,
|
|
270
270
|
selectable: v(l),
|
|
271
|
-
selected:
|
|
271
|
+
selected: F(h(l))
|
|
272
272
|
}, void 0, !0),
|
|
273
273
|
Q(" " + X(f(l)), 1)
|
|
274
274
|
], 2)) : N("", !0)
|
|
@@ -284,14 +284,14 @@ const je = {
|
|
|
284
284
|
_: 3
|
|
285
285
|
})
|
|
286
286
|
])),
|
|
287
|
-
i.value.length ? (p(),
|
|
288
|
-
|
|
287
|
+
i.value.length ? (p(), I("div", je, [
|
|
288
|
+
M(e.$slots, "tags", {
|
|
289
289
|
items: i.value,
|
|
290
290
|
remove: x
|
|
291
291
|
}, () => [
|
|
292
292
|
V(d(D), { mode: "popLayout" }, {
|
|
293
293
|
default: g(() => [
|
|
294
|
-
(p(!0),
|
|
294
|
+
(p(!0), I(Re, null, Ne(i.value, (l, a) => (p(), R(d(ee).div, {
|
|
295
295
|
key: l.value,
|
|
296
296
|
layout: !0,
|
|
297
297
|
class: "g-picker__tag-motion",
|
|
@@ -309,7 +309,7 @@ const je = {
|
|
|
309
309
|
onClose: (s) => x(a)
|
|
310
310
|
}, {
|
|
311
311
|
default: g(() => [
|
|
312
|
-
|
|
312
|
+
M(e.$slots, "tag", {
|
|
313
313
|
item: l,
|
|
314
314
|
index: a
|
|
315
315
|
}, () => [
|
|
@@ -329,7 +329,7 @@ const je = {
|
|
|
329
329
|
], 512)
|
|
330
330
|
], 2));
|
|
331
331
|
}
|
|
332
|
-
}), z = /* @__PURE__ */ Ke(Ge, [["__scopeId", "data-v-
|
|
332
|
+
}), z = /* @__PURE__ */ Ke(Ge, [["__scopeId", "data-v-92c90ec0"]]);
|
|
333
333
|
z.install = (L) => {
|
|
334
334
|
L.component(z.name, z);
|
|
335
335
|
};
|
package/lib/GPicker/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@charset "UTF-8";.g-picker[data-v-
|
|
1
|
+
@charset "UTF-8";.g-picker[data-v-92c90ec0]{width:100%}.g-picker__wrap[data-v-92c90ec0]{display:flex;flex-direction:column;align-items:flex-start;gap:8px;width:100%}.g-picker__tags[data-v-92c90ec0]{display:flex;flex-wrap:wrap;gap:8px;width:100%}.g-picker__tag-motion[data-v-92c90ec0]{display:inline-flex}.g-picker__tag[data-v-92c90ec0]{margin:0}.g-picker.is-disabled[data-v-92c90ec0]{cursor:not-allowed}.g-picker__popover{box-sizing:border-box;background:var(--g-bg-color, #fff);border:1px solid var(--g-border-color, #dcdfe3);border-radius:4px;box-shadow:0 0 12px #0000001f;padding:8px 0}.g-picker__popover .g-picker__tree-wrap{overflow:auto}.g-picker__popover .g-picker__node{display:inline-flex;align-items:center;gap:4px;font-size:13px}.g-picker__popover .g-picker__node.is-selectable{cursor:pointer;color:var(--g-text-color, rgba(0, 0, 0, .88))}.g-picker__popover .g-picker__node.is-selected{color:var(--g-primary-color, #039be5)}
|