@soei/flyweight 0.0.8 → 0.0.10
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 +11 -1
- package/dist/Flyweight.cjs +1 -1
- package/dist/Flyweight.js +80 -74
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/Flyweight.vue +12 -4
package/README.md
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
+
# 享元模式 [](https://npmjs.com/package/@soei/flyweight) [](LICENSE.md) [](https://www.npmjs.com/package/@soei/flyweight) 
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+

|
|
3
8
|
```html
|
|
4
9
|
<div style="height:100px;width:300px;">
|
|
5
10
|
<!-- 确认父容器 宽 高 存在, 依赖父容器 `宽`, `高` 计算 -->
|
|
6
11
|
<s-flyweight ...></s-flyweight>
|
|
7
12
|
</div>
|
|
8
13
|
```
|
|
14
|
+

|
|
9
15
|
|
|
10
16
|
### 更新日志
|
|
11
17
|
|
|
18
|
+
### `0.0.9`
|
|
19
|
+
|
|
20
|
+
- #### 问题修复 `v-model:space` 和 onend 冲突问题处理
|
|
21
|
+
|
|
12
22
|
### `0.0.8`
|
|
13
23
|
|
|
14
24
|
- #### 新增 `v-model:space`, 计算空间显示 `行` 与 `列`
|
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 f=require("@soei/util"),o=require("vue");const T=(e,t)=>{const l=e.__vccOpts||e;for(const[h,i]of t)l[h]=i;return l};let k=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,l)=>parseFloat(e)/100*l},v=(e,t)=>{let l;if(l=f.runer("match",e,H)){let h=l.length,i,s=0,r,n=[];for(;h--;)s=l.shift(),s in b?(i&&n.push(i),s==="%"&&(n.length=2),r=s):+s&&n.push(+s),n.length==2&&(n.push(t),i=b[r].apply(null,n),n.length=0);+i||(i=+n.pop()),e=i>>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,l)=>{e[t]=l}),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,(l,h)=>{this.$emit(h[0],k(h[1])?!0:h[1])})})},cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){f.runer([this.cheackflys,t=>{t=t||{};let l=t.index||f.each(this.flys,(h,i,s,r)=>{if(i[s]==r)return h},t.picker,t.id);k(l)||this.setindex(l)}],this,e)},setindex(e){f.runer([this.cheackflys,({index:t})=>{this.$nextTick(()=>{let l=t/this.column>>0,h=this.fwheight;(this.flyweight.scrollTop/h>>0)+this.row-l-1>0||(this.flyweight.scrollTop=l*h,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,(l,h,i,s,r,n,a,u)=>{if(i=l/r>>0,a=i+s*(+(i<n%s)+(n/s>>0)),u=a*r+l%r,u>=this.count){this.trigger("onend");return}h.index=a,h.top=a*this.fwheight,h.data=this.flys[u]},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,h=f.picker(l,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let i=this.auto===!0,[s,r]=this.offset,n=h.width,a=h.height,u=(v(this.width,n)||n)+s,g=v(this.height,a)+r;this.realW=u-s,this.realH=g-r;let c=n/u>>0||1,y=a/g>>0;this.row=y+2,this.column=c,this.fwheight=g;let x=n%u/(c-1*+!i)>>0;i&&(u=this.realW=(n/c>>0)-s,x=s),this.Height=Math.ceil(e/c)*g;let w=Math.min(e,c*this.row),p=w-1,d,_;for(;w-- >0;)d=p-w,_=this.flys[d],l=t[d],y=d/c>>0,this.$set(t,d,{data:_,top:y*g,left:d%c*(u+x),index:y});t.length=p+1;let m=[];a/g>p&&m.push(["onend"]),this.scroll(),m.push(["update:space",{row:(p/c>>0)+1,column:c}]),this.trigger(m)})}}},B=["data"];function F(e,t,l,h,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]=(...r)=>s.scroll&&s.scroll(...r))},[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,(r,n)=>(o.openBlock(),o.createElementBlock("div",{key:n,data:r.top,style:o.normalizeStyle({top:r.top+"px",left:r.left+"px"})},[o.renderSlot(e.$slots,"default",{data:r.data,index:r.index},void 0,!0)],12,B))),128))],4),i.flyweights.length?o.renderSlot(e.$slots,"end",{key:0},void 0,!0):o.createCommentVNode("",!0)],38)}const z=T(S,[["render",F],["__scopeId","data-v-1342d2cb"]]),O=[z],$={install(e){O.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=z;exports.default=$;
|
package/dist/Flyweight.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { openBlock as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
for (const [
|
|
6
|
-
|
|
7
|
-
return
|
|
1
|
+
import { isArray as F, each as m, runer as d, picker as z } from "@soei/util";
|
|
2
|
+
import { openBlock as x, createElementBlock as _, normalizeClass as O, normalizeStyle as b, createElementVNode as L, Fragment as W, renderList as E, renderSlot as T, createCommentVNode as S } from "vue";
|
|
3
|
+
const A = (t, e) => {
|
|
4
|
+
const s = t.__vccOpts || t;
|
|
5
|
+
for (const [h, i] of e)
|
|
6
|
+
s[h] = i;
|
|
7
|
+
return s;
|
|
8
8
|
};
|
|
9
|
-
let
|
|
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,
|
|
15
|
-
},
|
|
16
|
-
let
|
|
17
|
-
if (
|
|
18
|
-
let
|
|
19
|
-
for (;
|
|
20
|
-
|
|
21
|
-
+i || (i = +
|
|
14
|
+
"%": (t, e, s) => parseFloat(t) / 100 * s
|
|
15
|
+
}, $ = (t, e) => {
|
|
16
|
+
let s;
|
|
17
|
+
if (s = d("match", t, B)) {
|
|
18
|
+
let h = s.length, i, l = 0, r, n = [];
|
|
19
|
+
for (; h--; )
|
|
20
|
+
l = s.shift(), l in N ? (i && n.push(i), l === "%" && (n.length = 2), r = l) : +l && n.push(+l), n.length == 2 && (n.push(e), i = N[r].apply(null, n), n.length = 0);
|
|
21
|
+
+i || (i = +n.pop()), t = i >> 0;
|
|
22
22
|
}
|
|
23
23
|
return t;
|
|
24
|
-
},
|
|
24
|
+
}, C = (...t) => {
|
|
25
25
|
console.info("::::FLYWEIGHT", ...t);
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const I = {
|
|
28
28
|
name: "Flyweight",
|
|
29
29
|
props: {
|
|
30
30
|
flys: {
|
|
@@ -116,59 +116,63 @@ const C = {
|
|
|
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, s) => {
|
|
120
|
+
t[e] = s;
|
|
121
121
|
}), this.setindex(this.index);
|
|
122
122
|
try {
|
|
123
123
|
new ResizeObserver(() => {
|
|
124
124
|
this.re(), this.$emit("resize");
|
|
125
125
|
}).observe(this.flyweight);
|
|
126
126
|
} catch (t) {
|
|
127
|
-
|
|
127
|
+
C(t);
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
methods: {
|
|
131
131
|
trigger(t, e) {
|
|
132
|
-
this.lazyrun(() =>
|
|
132
|
+
this.lazyrun(() => {
|
|
133
|
+
F(t) || (t = [[t, e]]), m(t, (s, h) => {
|
|
134
|
+
this.$emit(h[0], H(h[1]) ? !0 : h[1]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
133
137
|
},
|
|
134
138
|
cheackflys(t) {
|
|
135
139
|
if (!this.flys.length)
|
|
136
140
|
return t && this.task.push(t), !0;
|
|
137
141
|
},
|
|
138
142
|
setview(t) {
|
|
139
|
-
|
|
143
|
+
d([this.cheackflys, (e) => {
|
|
140
144
|
e = e || {};
|
|
141
|
-
let
|
|
142
|
-
if (i[
|
|
143
|
-
return
|
|
145
|
+
let s = e.index || m(this.flys, (h, i, l, r) => {
|
|
146
|
+
if (i[l] == r)
|
|
147
|
+
return h;
|
|
144
148
|
}, e.picker, e.id);
|
|
145
|
-
|
|
149
|
+
H(s) || this.setindex(s);
|
|
146
150
|
}], this, t);
|
|
147
151
|
},
|
|
148
152
|
setindex(t) {
|
|
149
|
-
|
|
153
|
+
d([this.cheackflys, ({ index: e }) => {
|
|
150
154
|
this.$nextTick(() => {
|
|
151
|
-
let
|
|
152
|
-
(this.flyweight.scrollTop /
|
|
155
|
+
let s = e / this.column >> 0, h = this.fwheight;
|
|
156
|
+
(this.flyweight.scrollTop / h >> 0) + this.row - s - 1 > 0 || (this.flyweight.scrollTop = s * h, this.scroll());
|
|
153
157
|
});
|
|
154
158
|
}], this, { index: t });
|
|
155
159
|
},
|
|
156
160
|
lazyrun(t, e) {
|
|
157
161
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
158
|
-
|
|
162
|
+
d(t);
|
|
159
163
|
}, e || this.lazy);
|
|
160
164
|
},
|
|
161
165
|
run(t) {
|
|
162
|
-
let e =
|
|
163
|
-
|
|
166
|
+
let e = z(t.target, "scrollTop=>top");
|
|
167
|
+
m(
|
|
164
168
|
this.flyweights,
|
|
165
|
-
(
|
|
166
|
-
if (i =
|
|
167
|
-
(+(i <
|
|
169
|
+
(s, h, i, l, r, n, u, o) => {
|
|
170
|
+
if (i = s / r >> 0, u = i + l * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
171
|
+
(+(i < n % l) + (n / l >> 0)), o = u * r + s % r, o >= this.count) {
|
|
168
172
|
this.trigger("onend");
|
|
169
173
|
return;
|
|
170
174
|
}
|
|
171
|
-
|
|
175
|
+
h.index = u, h.top = u * this.fwheight, h.data = this.flys[o];
|
|
172
176
|
},
|
|
173
177
|
null,
|
|
174
178
|
this.row,
|
|
@@ -185,70 +189,72 @@ const C = {
|
|
|
185
189
|
if (!t)
|
|
186
190
|
return e.length = t;
|
|
187
191
|
this.count = t;
|
|
188
|
-
let
|
|
192
|
+
let s = this.flyweight, h = z(s, "clientHeight=>height,clientWidth=>width");
|
|
189
193
|
this.$nextTick(() => {
|
|
190
|
-
let i = this.auto === !0, [
|
|
191
|
-
this.realW = o -
|
|
192
|
-
let f =
|
|
193
|
-
this.row = g + 2, this.column = f, this.fwheight =
|
|
194
|
-
let
|
|
195
|
-
i && (o = this.realW = (
|
|
196
|
-
let
|
|
197
|
-
for (;
|
|
198
|
-
c =
|
|
199
|
-
data:
|
|
200
|
-
top: g *
|
|
201
|
-
left: c % f * (o +
|
|
194
|
+
let i = this.auto === !0, [l, r] = this.offset, n = h.width, u = h.height, o = ($(this.width, n) || n) + l, a = $(this.height, u) + r;
|
|
195
|
+
this.realW = o - l, this.realH = a - r;
|
|
196
|
+
let f = n / o >> 0 || 1, g = u / a >> 0;
|
|
197
|
+
this.row = g + 2, this.column = f, this.fwheight = a;
|
|
198
|
+
let k = n % o / (f - 1 * +!i) >> 0;
|
|
199
|
+
i && (o = this.realW = (n / f >> 0) - l, k = l), this.Height = Math.ceil(t / f) * a;
|
|
200
|
+
let y = Math.min(t, f * this.row), p = y - 1, c, v;
|
|
201
|
+
for (; y-- > 0; )
|
|
202
|
+
c = p - y, v = this.flys[c], s = e[c], g = c / f >> 0, this.$set(e, c, {
|
|
203
|
+
data: v,
|
|
204
|
+
top: g * a,
|
|
205
|
+
left: c % f * (o + k),
|
|
202
206
|
index: g
|
|
203
207
|
});
|
|
204
|
-
e.length =
|
|
208
|
+
e.length = p + 1;
|
|
209
|
+
let w = [];
|
|
210
|
+
u / a > p && w.push(["onend"]), this.scroll(), w.push(["update:space", { row: (p / f >> 0) + 1, column: f }]), this.trigger(w);
|
|
205
211
|
});
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
|
-
},
|
|
209
|
-
function
|
|
210
|
-
return
|
|
214
|
+
}, j = ["data"];
|
|
215
|
+
function M(t, e, s, h, i, l) {
|
|
216
|
+
return x(), _("div", {
|
|
211
217
|
ref: "flyweight",
|
|
212
|
-
class:
|
|
218
|
+
class: O(["flyweight", {
|
|
213
219
|
"flyweight-active": i.actice
|
|
214
220
|
}]),
|
|
215
|
-
style:
|
|
221
|
+
style: b({
|
|
216
222
|
"--width": i.realW + "px",
|
|
217
223
|
"--height": i.realH + "px"
|
|
218
224
|
}),
|
|
219
|
-
onScroll: e[0] || (e[0] = (...
|
|
225
|
+
onScroll: e[0] || (e[0] = (...r) => l.scroll && l.scroll(...r))
|
|
220
226
|
}, [
|
|
221
|
-
|
|
227
|
+
L("div", {
|
|
222
228
|
class: "flyweight-all",
|
|
223
|
-
style:
|
|
229
|
+
style: b({
|
|
224
230
|
"--flyweight-height": i.Height + "px"
|
|
225
231
|
})
|
|
226
232
|
}, [
|
|
227
|
-
(
|
|
228
|
-
key:
|
|
229
|
-
data:
|
|
230
|
-
style:
|
|
231
|
-
top:
|
|
232
|
-
left:
|
|
233
|
+
(x(!0), _(W, null, E(i.flyweights, (r, n) => (x(), _("div", {
|
|
234
|
+
key: n,
|
|
235
|
+
data: r.top,
|
|
236
|
+
style: b({
|
|
237
|
+
top: r.top + "px",
|
|
238
|
+
left: r.left + "px"
|
|
233
239
|
})
|
|
234
240
|
}, [
|
|
235
|
-
|
|
236
|
-
data:
|
|
237
|
-
index:
|
|
241
|
+
T(t.$slots, "default", {
|
|
242
|
+
data: r.data,
|
|
243
|
+
index: r.index
|
|
238
244
|
}, void 0, !0)
|
|
239
|
-
], 12,
|
|
245
|
+
], 12, j))), 128))
|
|
240
246
|
], 4),
|
|
241
|
-
i.flyweights.length ?
|
|
247
|
+
i.flyweights.length ? T(t.$slots, "end", { key: 0 }, void 0, !0) : S("", !0)
|
|
242
248
|
], 38);
|
|
243
249
|
}
|
|
244
|
-
const
|
|
250
|
+
const R = /* @__PURE__ */ A(I, [["render", M], ["__scopeId", "data-v-1342d2cb"]]), V = [R], q = {
|
|
245
251
|
install(t) {
|
|
246
|
-
|
|
252
|
+
V.forEach((e) => {
|
|
247
253
|
t.component("s-" + e.name.toLowerCase(), e);
|
|
248
254
|
});
|
|
249
255
|
}
|
|
250
256
|
};
|
|
251
257
|
export {
|
|
252
|
-
|
|
253
|
-
|
|
258
|
+
R as Flyweight,
|
|
259
|
+
q as default
|
|
254
260
|
};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.flyweight[data-v-
|
|
1
|
+
.flyweight[data-v-1342d2cb]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-1342d2cb]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-1342d2cb]>*{width:calc(var(--width));height:var(--height);position:absolute}
|
package/package.json
CHANGED
package/src/Flyweight.vue
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
</template>
|
|
21
21
|
|
|
22
22
|
<script>
|
|
23
|
-
import { each, picker, runer } from '@soei/util';
|
|
23
|
+
import { each, picker, runer, isArray } from '@soei/util';
|
|
24
24
|
let isNil = (data) => {
|
|
25
25
|
return data == null || data == undefined;
|
|
26
26
|
}
|
|
@@ -176,7 +176,12 @@ export default {
|
|
|
176
176
|
},
|
|
177
177
|
methods: {
|
|
178
178
|
trigger(key, data) {
|
|
179
|
-
this.lazyrun(() =>
|
|
179
|
+
this.lazyrun(() => {
|
|
180
|
+
if (!isArray(key)) key = [[key, data]];
|
|
181
|
+
each(key, (k, v) => {
|
|
182
|
+
this.$emit(v[0], isNil(v[1]) ? true : v[1]);
|
|
183
|
+
})
|
|
184
|
+
});
|
|
180
185
|
},
|
|
181
186
|
cheackflys(data) {
|
|
182
187
|
let length = this.flys.length;
|
|
@@ -291,10 +296,13 @@ export default {
|
|
|
291
296
|
})
|
|
292
297
|
}
|
|
293
298
|
fws.length = length + 1;
|
|
294
|
-
|
|
299
|
+
let triggers = [];
|
|
300
|
+
if (H / height > length) triggers.push(['onend']);
|
|
295
301
|
this.scroll();
|
|
296
302
|
/* 计算占用空间 */
|
|
297
|
-
|
|
303
|
+
triggers.push(['update:space', { row: (length / column >> 0) + 1, column: column }]);
|
|
304
|
+
|
|
305
|
+
this.trigger(triggers);
|
|
298
306
|
});
|
|
299
307
|
}
|
|
300
308
|
}
|