@soei/flyweight 0.0.11 → 0.1.0
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/Flyweight.cjs +1 -1
- package/Flyweight.js +73 -69
- package/README.md +16 -0
- package/package.json +1 -1
- package/style.css +1 -1
package/Flyweight.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("@soei/util"),o=require("vue");const T=(e,t)=>{const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("@soei/util"),o=require("vue");const T=(e,t)=>{const i=e.__vccOpts||e;for(const[s,l]of t)i[s]=l;return i};let _=e=>e==null||e==null,H=/(\d+|[+\-\*/]|%)/g,b={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,i)=>parseFloat(e)/100*i},v=(e,t)=>{let i;if(i=f.runer("match",e,H)){let s=i.length,l,h=0,n,r=[];for(;s--;)h=i.shift(),h in b?(l&&r.push(l),h==="%"&&(r.length=2),n=h):+h&&r.push(+h),r.length==2&&(r.push(t),l=b[n].apply(null,r),r.length=0);+l||(l=+r.pop()),e=l>>0}return e},N=(...e)=>{console.info("::::FLYWEIGHT",...e)};const S={name:"Flyweight",props:{flys:{type:Array,default:()=>[]},width:{type:Number,default:0},height:{type:Number,default:100},offset:{type:Array,default:()=>[0,0]},lazy:{type:Number,default:100},view:{type:Object,default:()=>null},index:{type:Number,default:0},top:{type:Number,default:!1},left:{type:Number,default:!1},auto:{type:[Boolean,String],default:!1},space:{type:Object,default:()=>null}},computed:{flyweight(){return this.$refs.flyweight}},data(){return{flyweights:[],actice:!1,Height:null,column:1,row:1,fwheight:10,count:0,task:[],realW:0,realH:0}},watch:{flys(e){this.count=e.length,this.re();let t=this.task.shift();t&&this.$nextTick(()=>{this.setview(t)})},view:{handler(e){this.setview(e)},immediate:!0},index(e){this.setindex(e)},top(e){this.flyweight.scrollTop=e},left(e){this.flyweight.scrollLeft=e}},mounted(){this.flyweights=[],this.$set||(this.$set=(e,t,i)=>{e[t]=i}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){N(e)}},methods:{trigger(e,t){this.lazyrun(()=>{f.isArray(e)||(e=[[e,t]]),f.each(e,(i,s)=>{this.$emit(s[0],_(s[1])?!0:s[1])})})},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){f.runer([this.cheackflys,t=>{t=t||{};let i=t.index||f.each(this.flys,(s,l,h,n)=>{if(l[h]==n)return s},t.picker,t.id);_(i)||this.setindex(i)}],this,e)},setindex(e){f.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let i=t/this.column>>0,s=this.fwheight;(this.flyweight.scrollTop/s>>0)+this.row-i-1>0||(this.flyweight.scrollTop=i*s,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{f.runer(e)},t||this.lazy)},run(e){let t=f.picker(e.target,"scrollTop=>top");f.each(this.flyweights,(i,s,l,h,n,r,a,c)=>{if(l=i/n>>0,a=l+h*(+(l<r%h)+(r/h>>0)),c=a*n+i%n,c>=this.count){this.trigger("onend");return}s.index=a,s.top=a*this.fwheight,s.data=this.flys[c]},null,this.row,this.column,t.top/this.fwheight>>0)},scroll(e){this.run(e||{target:this.flyweight})},re(){let e=this.count||this.flys.length,t=this.flyweights;if(!e)return t.length=e;this.count=e;let i=this.flyweight,s=f.picker(i,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let l=this.auto===!0,[h,n]=this.offset,r=s.width,a=s.height,c=(v(this.width,r)||r)+h,g=v(this.height,a)+n;this.realH=g-n;let u=r/c>>0||1,p=a/g>>0;this.row=p+2,this.column=u,this.fwheight=g;let w;l?(c=(r/u>>0)-h/u*(u-1),w=h):w=r%c/(u-1)>>0,this.realW=c,this.Height=Math.ceil(e/u)*g;let m=Math.min(e,u*this.row),d=m-1,y,k;for(;m-- >0;)y=d-m,k=this.flys[y],i=t[y],p=y/u>>0,this.$set(t,y,{data:k,top:p*g,left:y%u*(c+w),index:p});t.length=d+1;let x=[];a/g>d/u&&x.push(["onend"]),this.scroll(),x.push(["update:space",{row:(d/u>>0)+1,column:u,showrow:this.row,showcloumn:this.column}]),this.trigger(x)})}}};function B(e,t,i,s,l,h){return o.openBlock(),o.createElementBlock("div",{ref:"flyweight",class:o.normalizeClass(["flyweight",{"flyweight-active":l.actice}]),style:o.normalizeStyle({"--width":l.realW+"px","--height":l.realH+"px"}),onScroll:t[0]||(t[0]=(...n)=>h.scroll&&h.scroll(...n))},[o.createElementVNode("div",{class:"flyweight-all",style:o.normalizeStyle({"--flyweight-height":l.Height+"px"})},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(l.flyweights,(n,r)=>(o.openBlock(),o.createElementBlock("div",{key:r,style:o.normalizeStyle({top:n.top+"px",left:n.left+"px"})},[o.renderSlot(e.$slots,"default",{data:n.data,index:n.index},void 0,!0)],4))),128))],4),l.flyweights.length?o.renderSlot(e.$slots,"end",{key:0},void 0,!0):o.createCommentVNode("",!0)],38)}const z=T(S,[["render",B],["__scopeId","data-v-489f03db"]]),F=[z],O={install(e){F.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=z;exports.default=O;
|
package/Flyweight.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { isArray as F, each as
|
|
2
|
-
import { openBlock as
|
|
1
|
+
import { isArray as F, each as x, runer as y, picker as z } from "@soei/util";
|
|
2
|
+
import { openBlock as _, createElementBlock as b, normalizeClass as O, normalizeStyle as k, createElementVNode as L, Fragment as E, renderList as S, renderSlot as T, createCommentVNode as W } from "vue";
|
|
3
3
|
const A = (t, e) => {
|
|
4
|
-
const
|
|
5
|
-
for (const [
|
|
6
|
-
|
|
7
|
-
return
|
|
4
|
+
const i = t.__vccOpts || t;
|
|
5
|
+
for (const [l, s] of e)
|
|
6
|
+
i[l] = s;
|
|
7
|
+
return i;
|
|
8
8
|
};
|
|
9
9
|
let H = (t) => t == null || t == null, B = /(\d+|[+\-\*/]|%)/g, N = {
|
|
10
10
|
"+": (t, e) => t + e,
|
|
11
11
|
"-": (t, e) => t - e,
|
|
12
12
|
"*": (t, e) => t * e,
|
|
13
13
|
"/": (t, e) => t / e,
|
|
14
|
-
"%": (t, e,
|
|
14
|
+
"%": (t, e, i) => parseFloat(t) / 100 * i
|
|
15
15
|
}, $ = (t, e) => {
|
|
16
|
-
let
|
|
17
|
-
if (
|
|
18
|
-
let
|
|
19
|
-
for (;
|
|
20
|
-
|
|
21
|
-
+
|
|
16
|
+
let i;
|
|
17
|
+
if (i = y("match", t, B)) {
|
|
18
|
+
let l = i.length, s, h = 0, n, r = [];
|
|
19
|
+
for (; l--; )
|
|
20
|
+
h = i.shift(), h in N ? (s && r.push(s), h === "%" && (r.length = 2), n = h) : +h && r.push(+h), r.length == 2 && (r.push(e), s = N[n].apply(null, r), r.length = 0);
|
|
21
|
+
+s || (s = +r.pop()), t = s >> 0;
|
|
22
22
|
}
|
|
23
23
|
return t;
|
|
24
24
|
}, C = (...t) => {
|
|
@@ -116,8 +116,8 @@ const I = {
|
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
118
|
mounted() {
|
|
119
|
-
this.flyweights = [], this.$set || (this.$set = (t, e,
|
|
120
|
-
t[e] =
|
|
119
|
+
this.flyweights = [], this.$set || (this.$set = (t, e, i) => {
|
|
120
|
+
t[e] = i;
|
|
121
121
|
}), this.setindex(this.index);
|
|
122
122
|
try {
|
|
123
123
|
new ResizeObserver(() => {
|
|
@@ -130,8 +130,8 @@ const I = {
|
|
|
130
130
|
methods: {
|
|
131
131
|
trigger(t, e) {
|
|
132
132
|
this.lazyrun(() => {
|
|
133
|
-
F(t) || (t = [[t, e]]),
|
|
134
|
-
this.$emit(
|
|
133
|
+
F(t) || (t = [[t, e]]), x(t, (i, l) => {
|
|
134
|
+
this.$emit(l[0], H(l[1]) ? !0 : l[1]);
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
},
|
|
@@ -140,39 +140,39 @@ const I = {
|
|
|
140
140
|
return t && this.task.push(t), !0;
|
|
141
141
|
},
|
|
142
142
|
setview(t) {
|
|
143
|
-
|
|
143
|
+
y([this.cheackflys, (e) => {
|
|
144
144
|
e = e || {};
|
|
145
|
-
let
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
145
|
+
let i = e.index || x(this.flys, (l, s, h, n) => {
|
|
146
|
+
if (s[h] == n)
|
|
147
|
+
return l;
|
|
148
148
|
}, e.picker, e.id);
|
|
149
|
-
H(
|
|
149
|
+
H(i) || this.setindex(i);
|
|
150
150
|
}], this, t);
|
|
151
151
|
},
|
|
152
152
|
setindex(t) {
|
|
153
|
-
|
|
153
|
+
y([this.cheackflys, ({ index: e }) => {
|
|
154
154
|
this.$nextTick(() => {
|
|
155
|
-
let
|
|
156
|
-
(this.flyweight.scrollTop /
|
|
155
|
+
let i = e / this.column >> 0, l = this.fwheight;
|
|
156
|
+
(this.flyweight.scrollTop / l >> 0) + this.row - i - 1 > 0 || (this.flyweight.scrollTop = i * l, this.scroll());
|
|
157
157
|
});
|
|
158
158
|
}], this, { index: t });
|
|
159
159
|
},
|
|
160
160
|
lazyrun(t, e) {
|
|
161
161
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
162
|
-
|
|
162
|
+
y(t);
|
|
163
163
|
}, e || this.lazy);
|
|
164
164
|
},
|
|
165
165
|
run(t) {
|
|
166
166
|
let e = z(t.target, "scrollTop=>top");
|
|
167
|
-
|
|
167
|
+
x(
|
|
168
168
|
this.flyweights,
|
|
169
|
-
(
|
|
170
|
-
if (
|
|
171
|
-
(+(
|
|
169
|
+
(i, l, s, h, n, r, u, f) => {
|
|
170
|
+
if (s = i / n >> 0, u = s + h * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
171
|
+
(+(s < r % h) + (r / h >> 0)), f = u * n + i % n, f >= this.count) {
|
|
172
172
|
this.trigger("onend");
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
l.index = u, l.top = u * this.fwheight, l.data = this.flys[f];
|
|
176
176
|
},
|
|
177
177
|
null,
|
|
178
178
|
this.row,
|
|
@@ -189,72 +189,76 @@ const I = {
|
|
|
189
189
|
if (!t)
|
|
190
190
|
return e.length = t;
|
|
191
191
|
this.count = t;
|
|
192
|
-
let
|
|
192
|
+
let i = this.flyweight, l = z(i, "clientHeight=>height,clientWidth=>width");
|
|
193
193
|
this.$nextTick(() => {
|
|
194
|
-
let
|
|
195
|
-
this.
|
|
196
|
-
let
|
|
197
|
-
this.row = g + 2, this.column =
|
|
198
|
-
let
|
|
199
|
-
|
|
200
|
-
let
|
|
201
|
-
for (;
|
|
202
|
-
|
|
194
|
+
let s = this.auto === !0, [h, n] = this.offset, r = l.width, u = l.height, f = ($(this.width, r) || r) + h, c = $(this.height, u) + n;
|
|
195
|
+
this.realH = c - n;
|
|
196
|
+
let o = r / f >> 0 || 1, g = u / c >> 0;
|
|
197
|
+
this.row = g + 2, this.column = o, this.fwheight = c;
|
|
198
|
+
let d;
|
|
199
|
+
s ? (f = (r / o >> 0) - h / o * (o - 1), d = h) : d = r % f / (o - 1) >> 0, this.realW = f, this.Height = Math.ceil(t / o) * c;
|
|
200
|
+
let w = Math.min(t, o * this.row), p = w - 1, a, v;
|
|
201
|
+
for (; w-- > 0; )
|
|
202
|
+
a = p - w, v = this.flys[a], i = e[a], g = a / o >> 0, this.$set(e, a, {
|
|
203
203
|
data: v,
|
|
204
|
-
top: g *
|
|
205
|
-
left:
|
|
204
|
+
top: g * c,
|
|
205
|
+
left: a % o * (f + d),
|
|
206
206
|
index: g
|
|
207
207
|
});
|
|
208
208
|
e.length = p + 1;
|
|
209
|
-
let
|
|
210
|
-
u /
|
|
209
|
+
let m = [];
|
|
210
|
+
u / c > p / o && m.push(["onend"]), this.scroll(), m.push(["update:space", {
|
|
211
|
+
row: (p / o >> 0) + 1,
|
|
212
|
+
column: o,
|
|
213
|
+
showrow: this.row,
|
|
214
|
+
showcloumn: this.column
|
|
215
|
+
}]), this.trigger(m);
|
|
211
216
|
});
|
|
212
217
|
}
|
|
213
218
|
}
|
|
214
|
-
}
|
|
215
|
-
function
|
|
216
|
-
return
|
|
219
|
+
};
|
|
220
|
+
function j(t, e, i, l, s, h) {
|
|
221
|
+
return _(), b("div", {
|
|
217
222
|
ref: "flyweight",
|
|
218
223
|
class: O(["flyweight", {
|
|
219
|
-
"flyweight-active":
|
|
224
|
+
"flyweight-active": s.actice
|
|
220
225
|
}]),
|
|
221
|
-
style:
|
|
222
|
-
"--width":
|
|
223
|
-
"--height":
|
|
226
|
+
style: k({
|
|
227
|
+
"--width": s.realW + "px",
|
|
228
|
+
"--height": s.realH + "px"
|
|
224
229
|
}),
|
|
225
|
-
onScroll: e[0] || (e[0] = (...
|
|
230
|
+
onScroll: e[0] || (e[0] = (...n) => h.scroll && h.scroll(...n))
|
|
226
231
|
}, [
|
|
227
232
|
L("div", {
|
|
228
233
|
class: "flyweight-all",
|
|
229
|
-
style:
|
|
230
|
-
"--flyweight-height":
|
|
234
|
+
style: k({
|
|
235
|
+
"--flyweight-height": s.Height + "px"
|
|
231
236
|
})
|
|
232
237
|
}, [
|
|
233
|
-
(
|
|
234
|
-
key:
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
left: r.left + "px"
|
|
238
|
+
(_(!0), b(E, null, S(s.flyweights, (n, r) => (_(), b("div", {
|
|
239
|
+
key: r,
|
|
240
|
+
style: k({
|
|
241
|
+
top: n.top + "px",
|
|
242
|
+
left: n.left + "px"
|
|
239
243
|
})
|
|
240
244
|
}, [
|
|
241
245
|
T(t.$slots, "default", {
|
|
242
|
-
data:
|
|
243
|
-
index:
|
|
246
|
+
data: n.data,
|
|
247
|
+
index: n.index
|
|
244
248
|
}, void 0, !0)
|
|
245
|
-
],
|
|
249
|
+
], 4))), 128))
|
|
246
250
|
], 4),
|
|
247
|
-
|
|
251
|
+
s.flyweights.length ? T(t.$slots, "end", { key: 0 }, void 0, !0) : W("", !0)
|
|
248
252
|
], 38);
|
|
249
253
|
}
|
|
250
|
-
const
|
|
254
|
+
const M = /* @__PURE__ */ A(I, [["render", j], ["__scopeId", "data-v-489f03db"]]), R = [M], U = {
|
|
251
255
|
install(t) {
|
|
252
|
-
|
|
256
|
+
R.forEach((e) => {
|
|
253
257
|
t.component("s-" + e.name.toLowerCase(), e);
|
|
254
258
|
});
|
|
255
259
|
}
|
|
256
260
|
};
|
|
257
261
|
export {
|
|
258
|
-
|
|
259
|
-
|
|
262
|
+
M as Flyweight,
|
|
263
|
+
U as default
|
|
260
264
|
};
|
package/README.md
CHANGED
|
@@ -14,7 +14,23 @@
|
|
|
14
14
|

|
|
15
15
|
|
|
16
16
|
### 更新日志
|
|
17
|
+
### `0.1.0`
|
|
17
18
|
|
|
19
|
+
- #### 新增 `v-model:space` 中字段
|
|
20
|
+
```javascript
|
|
21
|
+
{
|
|
22
|
+
// --- 新增 ---
|
|
23
|
+
// 总行数
|
|
24
|
+
showrow,
|
|
25
|
+
// 总列数
|
|
26
|
+
showcolumn,
|
|
27
|
+
|
|
28
|
+
// --- 原有 ---
|
|
29
|
+
row, // 数据填充行数
|
|
30
|
+
column, // 数据填前列数
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
- #### 修复了 多列数据时 `@onend` 回调函数问题
|
|
18
34
|
### `0.0.9`
|
|
19
35
|
|
|
20
36
|
- #### 问题修复 `v-model:space` 和 onend 冲突问题处理
|
package/package.json
CHANGED
package/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.flyweight[data-v-
|
|
1
|
+
.flyweight[data-v-489f03db]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-489f03db]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-489f03db]>*{width:calc(var(--width));height:var(--height);position:absolute}
|