@soei/flyweight 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/Flyweight.cjs +1 -1
- package/dist/Flyweight.js +63 -58
- package/dist/style.css +1 -1
- package/package.json +4 -2
- package/src/Flyweight.vue +11 -2
package/README.md
CHANGED
|
@@ -9,6 +9,20 @@
|
|
|
9
9
|
|
|
10
10
|
### 更新日志
|
|
11
11
|
|
|
12
|
+
### `0.0.7`
|
|
13
|
+
|
|
14
|
+
- #### 新增 `:auto`, 默认值: `false`
|
|
15
|
+
|
|
16
|
+
当 `auto` 为 `true` 时, `:width` 赋值会被视为 `最小值`, 剩余空间自动填充
|
|
17
|
+
|
|
18
|
+
```html
|
|
19
|
+
<s-flyweight :auto="true" :width="100"></s-flyweight>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### `0.0.6`
|
|
23
|
+
|
|
24
|
+
- #### 优化 `flys` 初始化赋值,不改变时,获取 length 问题
|
|
25
|
+
|
|
12
26
|
### `0.0.5`
|
|
13
27
|
|
|
14
28
|
- #### 扩展 `width` 赋值
|
package/dist/Flyweight.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("@soei/util"),o=require("vue");const b=(e,t)=>{const l=e.__vccOpts||e;for(const[n,i]of t)l[n]=i;return l};let z=e=>e==null||e==null,T=/(\d+|[+\-\*/]|%)/g,x={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,l)=>parseFloat(e)/100*l},_=(e,t)=>{let l;if(l=a.runer("match",e,T)){let n=l.length,i,s=0,h,r=[];for(;n--;)s=l.shift(),s in x?(i&&r.push(i),s==="%"&&(r.length=2),h=s):+s&&r.push(+s),r.length==2&&(r.push(t),i=x[h].apply(null,r),r.length=0);+i||(i=+r.pop()),e=i>>0}return e},H=(...e)=>{console.info("::::FLYWEIGHT",...e)};const N={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}},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,l)=>{e[t]=l}),this.setindex(this.index);try{new ResizeObserver(()=>{this.re(),this.$emit("resize")}).observe(this.flyweight)}catch(e){H(e)}},methods:{trigger(e){this.lazyrun(()=>this.$emit(e,!0))},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){a.runer([this.cheackflys,t=>{t=t||{};let l=t.index||a.each(this.flys,(n,i,s,h)=>{if(i[s]==h)return n},t.picker,t.id);z(l)||this.setindex(l)}],this,e)},setindex(e){a.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let l=t/this.column>>0,n=this.fwheight;(this.flyweight.scrollTop/n>>0)+this.row-l-1>0||(this.flyweight.scrollTop=l*n,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{a.runer(e)},t||this.lazy)},run(e){let t=a.picker(e.target,"scrollTop=>top");a.each(this.flyweights,(l,n,i,s,h,r,u,f)=>{if(i=l/h>>0,u=i+s*(+(i<r%s)+(r/s>>0)),f=u*h+l%h,f>=this.count){this.trigger("onend");return}n.index=u,n.top=u*this.fwheight,n.data=this.flys[f]},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 l=this.flyweight,n=a.picker(l,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let i=this.auto===!0,[s,h]=this.offset,r=n.width,u=n.height,f=(_(this.width,r)||r)+s,g=_(this.height,u)+h;this.realW=f-s,this.realH=g-h;let c=r/f>>0||1,d=u/g>>0;this.row=d+2,this.column=c,this.fwheight=g;let m=r%f/(c-1*+!i)>>0;i&&(f=this.realW=(r/c>>0)-s,m=s),this.Height=Math.ceil(e/c)*g;let p=Math.min(e,c*this.row),w=p-1,y,k;for(;p-- >0;)y=w-p,k=this.flys[y],l=t[y],d=y/c>>0,this.$set(t,y,{data:k,top:d*g,left:y%c*(f+m),index:d});t.length=w+1,u/g>w&&this.trigger("onend"),this.scroll()})}}},S=["data"];function B(e,t,l,n,i,s){return o.openBlock(),o.createElementBlock("div",{ref:"flyweight",class:o.normalizeClass(["flyweight",{"flyweight-active":i.actice}]),style:o.normalizeStyle({"--width":i.realW+"px","--height":i.realH+"px"}),onScroll:t[0]||(t[0]=(...h)=>s.scroll&&s.scroll(...h))},[o.createElementVNode("div",{class:"flyweight-all",style:o.normalizeStyle({"--flyweight-height":i.Height+"px"})},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(i.flyweights,(h,r)=>(o.openBlock(),o.createElementBlock("div",{key:r,data:h.top,style:o.normalizeStyle({top:h.top+"px",left:h.left+"px"})},[o.renderSlot(e.$slots,"default",{data:h.data,index:h.index},void 0,!0)],12,S))),128))],4),i.flyweights.length?o.renderSlot(e.$slots,"end",{key:0},void 0,!0):o.createCommentVNode("",!0)],38)}const v=b(N,[["render",B],["__scopeId","data-v-144a29f8"]]),F=[v],$={install(e){F.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=v;exports.default=$;
|
package/dist/Flyweight.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { runer as
|
|
2
|
-
import { openBlock as
|
|
3
|
-
const
|
|
1
|
+
import { runer as y, each as v, picker as b } from "@soei/util";
|
|
2
|
+
import { openBlock as w, createElementBlock as m, normalizeClass as N, normalizeStyle as x, createElementVNode as $, Fragment as F, renderList as L, renderSlot as z, createCommentVNode as O } from "vue";
|
|
3
|
+
const W = (t, e) => {
|
|
4
4
|
const s = t.__vccOpts || t;
|
|
5
5
|
for (const [n, i] of e)
|
|
6
6
|
s[n] = i;
|
|
7
7
|
return s;
|
|
8
8
|
};
|
|
9
|
-
let E = (t) => t == null || t == null,
|
|
9
|
+
let E = (t) => t == null || t == null, S = /(\d+|[+\-\*/]|%)/g, T = {
|
|
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
14
|
"%": (t, e, s) => parseFloat(t) / 100 * s
|
|
15
|
-
},
|
|
15
|
+
}, H = (t, e) => {
|
|
16
16
|
let s;
|
|
17
|
-
if (s =
|
|
18
|
-
let n = s.length, i,
|
|
17
|
+
if (s = y("match", t, S)) {
|
|
18
|
+
let n = s.length, i, l = 0, h, r = [];
|
|
19
19
|
for (; n--; )
|
|
20
|
-
|
|
20
|
+
l = s.shift(), l in T ? (i && r.push(i), l === "%" && (r.length = 2), h = l) : +l && r.push(+l), r.length == 2 && (r.push(e), i = T[h].apply(null, r), r.length = 0);
|
|
21
21
|
+i || (i = +r.pop()), t = i >> 0;
|
|
22
22
|
}
|
|
23
23
|
return t;
|
|
24
|
-
},
|
|
24
|
+
}, B = (...t) => {
|
|
25
25
|
console.info("::::FLYWEIGHT", ...t);
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const C = {
|
|
28
28
|
name: "Flyweight",
|
|
29
29
|
props: {
|
|
30
30
|
flys: {
|
|
@@ -62,6 +62,10 @@ const I = {
|
|
|
62
62
|
left: {
|
|
63
63
|
type: Number,
|
|
64
64
|
default: !1
|
|
65
|
+
},
|
|
66
|
+
auto: {
|
|
67
|
+
type: [Boolean, String],
|
|
68
|
+
default: !1
|
|
65
69
|
}
|
|
66
70
|
},
|
|
67
71
|
computed: {
|
|
@@ -116,7 +120,7 @@ const I = {
|
|
|
116
120
|
this.re(), this.$emit("resize");
|
|
117
121
|
}).observe(this.flyweight);
|
|
118
122
|
} catch (t) {
|
|
119
|
-
|
|
123
|
+
B(t);
|
|
120
124
|
}
|
|
121
125
|
},
|
|
122
126
|
methods: {
|
|
@@ -128,17 +132,17 @@ const I = {
|
|
|
128
132
|
return t && this.task.push(t), !0;
|
|
129
133
|
},
|
|
130
134
|
setview(t) {
|
|
131
|
-
|
|
135
|
+
y([this.cheackflys, (e) => {
|
|
132
136
|
e = e || {};
|
|
133
|
-
let s = e.index ||
|
|
134
|
-
if (i[
|
|
137
|
+
let s = e.index || v(this.flys, (n, i, l, h) => {
|
|
138
|
+
if (i[l] == h)
|
|
135
139
|
return n;
|
|
136
140
|
}, e.picker, e.id);
|
|
137
141
|
E(s) || this.setindex(s);
|
|
138
142
|
}], this, t);
|
|
139
143
|
},
|
|
140
144
|
setindex(t) {
|
|
141
|
-
|
|
145
|
+
y([this.cheackflys, ({ index: e }) => {
|
|
142
146
|
this.$nextTick(() => {
|
|
143
147
|
let s = e / this.column >> 0, n = this.fwheight;
|
|
144
148
|
(this.flyweight.scrollTop / n >> 0) + this.row - s - 1 > 0 || (this.flyweight.scrollTop = s * n, this.scroll());
|
|
@@ -147,16 +151,16 @@ const I = {
|
|
|
147
151
|
},
|
|
148
152
|
lazyrun(t, e) {
|
|
149
153
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
150
|
-
|
|
154
|
+
y(t);
|
|
151
155
|
}, e || this.lazy);
|
|
152
156
|
},
|
|
153
157
|
run(t) {
|
|
154
|
-
let e =
|
|
155
|
-
|
|
158
|
+
let e = b(t.target, "scrollTop=>top");
|
|
159
|
+
v(
|
|
156
160
|
this.flyweights,
|
|
157
|
-
(s, n, i,
|
|
158
|
-
if (i = s /
|
|
159
|
-
(+(i < r %
|
|
161
|
+
(s, n, i, l, h, r, f, o) => {
|
|
162
|
+
if (i = s / h >> 0, f = i + l * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
163
|
+
(+(i < r % l) + (r / l >> 0)), o = f * h + s % h, o >= this.count) {
|
|
160
164
|
this.trigger("onend");
|
|
161
165
|
return;
|
|
162
166
|
}
|
|
@@ -176,70 +180,71 @@ const I = {
|
|
|
176
180
|
let t = this.count || this.flys.length, e = this.flyweights;
|
|
177
181
|
if (!t)
|
|
178
182
|
return e.length = t;
|
|
179
|
-
|
|
183
|
+
this.count = t;
|
|
184
|
+
let s = this.flyweight, n = b(s, "clientHeight=>height,clientWidth=>width");
|
|
180
185
|
this.$nextTick(() => {
|
|
181
|
-
let
|
|
182
|
-
this.realW =
|
|
183
|
-
let a =
|
|
184
|
-
this.row =
|
|
185
|
-
let
|
|
186
|
-
this.Height = Math.ceil(t / a) *
|
|
187
|
-
let
|
|
188
|
-
for (;
|
|
189
|
-
c =
|
|
190
|
-
data:
|
|
191
|
-
top:
|
|
192
|
-
left: c % a * (
|
|
193
|
-
index:
|
|
186
|
+
let i = this.auto === !0, [l, h] = this.offset, r = n.width, f = n.height, o = (H(this.width, r) || r) + l, u = H(this.height, f) + h;
|
|
187
|
+
this.realW = o - l, this.realH = u - h;
|
|
188
|
+
let a = r / o >> 0 || 1, g = f / u >> 0;
|
|
189
|
+
this.row = g + 2, this.column = a, this.fwheight = u;
|
|
190
|
+
let _ = r % o / (a - 1 * +!i) >> 0;
|
|
191
|
+
i && (o = this.realW = (r / a >> 0) - l, _ = l), this.Height = Math.ceil(t / a) * u;
|
|
192
|
+
let d = Math.min(t, a * this.row), p = d - 1, c, k;
|
|
193
|
+
for (; d-- > 0; )
|
|
194
|
+
c = p - d, k = this.flys[c], s = e[c], g = c / a >> 0, this.$set(e, c, {
|
|
195
|
+
data: k,
|
|
196
|
+
top: g * u,
|
|
197
|
+
left: c % a * (o + _),
|
|
198
|
+
index: g
|
|
194
199
|
});
|
|
195
|
-
e.length =
|
|
200
|
+
e.length = p + 1, f / u > p && this.trigger("onend"), this.scroll();
|
|
196
201
|
});
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
|
-
},
|
|
200
|
-
function A(t, e, s, n, i,
|
|
201
|
-
return
|
|
204
|
+
}, I = ["data"];
|
|
205
|
+
function A(t, e, s, n, i, l) {
|
|
206
|
+
return w(), m("div", {
|
|
202
207
|
ref: "flyweight",
|
|
203
|
-
class:
|
|
208
|
+
class: N(["flyweight", {
|
|
204
209
|
"flyweight-active": i.actice
|
|
205
210
|
}]),
|
|
206
|
-
style:
|
|
211
|
+
style: x({
|
|
207
212
|
"--width": i.realW + "px",
|
|
208
213
|
"--height": i.realH + "px"
|
|
209
214
|
}),
|
|
210
|
-
onScroll: e[0] || (e[0] = (...
|
|
215
|
+
onScroll: e[0] || (e[0] = (...h) => l.scroll && l.scroll(...h))
|
|
211
216
|
}, [
|
|
212
|
-
|
|
217
|
+
$("div", {
|
|
213
218
|
class: "flyweight-all",
|
|
214
|
-
style:
|
|
219
|
+
style: x({
|
|
215
220
|
"--flyweight-height": i.Height + "px"
|
|
216
221
|
})
|
|
217
222
|
}, [
|
|
218
|
-
(
|
|
223
|
+
(w(!0), m(F, null, L(i.flyweights, (h, r) => (w(), m("div", {
|
|
219
224
|
key: r,
|
|
220
|
-
data:
|
|
221
|
-
style:
|
|
222
|
-
top:
|
|
223
|
-
left:
|
|
225
|
+
data: h.top,
|
|
226
|
+
style: x({
|
|
227
|
+
top: h.top + "px",
|
|
228
|
+
left: h.left + "px"
|
|
224
229
|
})
|
|
225
230
|
}, [
|
|
226
|
-
|
|
227
|
-
data:
|
|
228
|
-
index:
|
|
231
|
+
z(t.$slots, "default", {
|
|
232
|
+
data: h.data,
|
|
233
|
+
index: h.index
|
|
229
234
|
}, void 0, !0)
|
|
230
|
-
], 12,
|
|
235
|
+
], 12, I))), 128))
|
|
231
236
|
], 4),
|
|
232
|
-
i.flyweights.length ?
|
|
237
|
+
i.flyweights.length ? z(t.$slots, "end", { key: 0 }, void 0, !0) : O("", !0)
|
|
233
238
|
], 38);
|
|
234
239
|
}
|
|
235
|
-
const
|
|
240
|
+
const M = /* @__PURE__ */ W(C, [["render", A], ["__scopeId", "data-v-144a29f8"]]), R = [M], U = {
|
|
236
241
|
install(t) {
|
|
237
|
-
|
|
242
|
+
R.forEach((e) => {
|
|
238
243
|
t.component("s-" + e.name.toLowerCase(), e);
|
|
239
244
|
});
|
|
240
245
|
}
|
|
241
246
|
};
|
|
242
247
|
export {
|
|
243
|
-
|
|
244
|
-
|
|
248
|
+
M as Flyweight,
|
|
249
|
+
U as default
|
|
245
250
|
};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.flyweight[data-v-
|
|
1
|
+
.flyweight[data-v-144a29f8]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-144a29f8]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-144a29f8]>*{width:calc(var(--width));height:var(--height);position:absolute}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@soei/flyweight",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "Vue组件, 列表de享元模式~减少DOM节点 flyweight",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.7",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/Flyweight.cjs",
|
|
8
8
|
"module": "dist/Flyweight.js",
|
|
@@ -25,5 +25,7 @@
|
|
|
25
25
|
"享元模式",
|
|
26
26
|
"List",
|
|
27
27
|
"列表展示"
|
|
28
|
-
]
|
|
28
|
+
],
|
|
29
|
+
"author": "soei | alwbg@163.com",
|
|
30
|
+
"license": "ISC"
|
|
29
31
|
}
|
package/src/Flyweight.vue
CHANGED
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
|
|
22
22
|
<script>
|
|
23
23
|
import { each, picker, runer } from '@soei/util';
|
|
24
|
-
|
|
25
24
|
let isNil = (data) => {
|
|
26
25
|
return data == null || data == undefined;
|
|
27
26
|
}
|
|
@@ -101,6 +100,10 @@ export default {
|
|
|
101
100
|
left: {
|
|
102
101
|
type: Number,
|
|
103
102
|
default: false
|
|
103
|
+
},
|
|
104
|
+
auto: {
|
|
105
|
+
type: [Boolean, String],
|
|
106
|
+
default: false
|
|
104
107
|
}
|
|
105
108
|
},
|
|
106
109
|
computed: {
|
|
@@ -242,9 +245,11 @@ export default {
|
|
|
242
245
|
let size = this.count || this.flys.length;
|
|
243
246
|
let fws = this.flyweights;
|
|
244
247
|
if (!size) return fws.length = size;
|
|
248
|
+
this.count = size;
|
|
245
249
|
let flyweight = this.flyweight;
|
|
246
250
|
let wh = picker(flyweight, 'clientHeight=>height,clientWidth=>width');
|
|
247
251
|
this.$nextTick(() => {
|
|
252
|
+
let auto = this.auto === true;
|
|
248
253
|
let [x, y] = this.offset, W = wh.width, H = wh.height;
|
|
249
254
|
let width = (computer(this.width, W) || W) + x;
|
|
250
255
|
let height = computer(this.height, H) + y/* 偏移量填充宽度 */;
|
|
@@ -257,7 +262,11 @@ export default {
|
|
|
257
262
|
this.fwheight = height;
|
|
258
263
|
let offset = W % width;
|
|
259
264
|
/* 偏移量 */
|
|
260
|
-
let margin = offset / (column - 1) >> 0;
|
|
265
|
+
let margin = offset / (column - 1 * +!auto) >> 0;
|
|
266
|
+
if (auto) {
|
|
267
|
+
width = this.realW = (W / column >> 0) - x;
|
|
268
|
+
margin = x;
|
|
269
|
+
}
|
|
261
270
|
/* 总高度 */
|
|
262
271
|
this.Height = Math.ceil(size / column) * height;
|
|
263
272
|
/* 计算数量 */
|