@soei/flyweight 0.1.0 → 0.1.2
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 +57 -51
- package/README.md +12 -4
- 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 i=e.__vccOpts||e;for(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[r,l]of t)i[r]=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 r=i.length,l,s=0,n,h=[];for(;r--;)s=i.shift(),s in b?(l&&h.push(l),s==="%"&&(h.length=2),n=s):+s&&h.push(+s),h.length==2&&(h.push(t),l=b[n].apply(null,h),h.length=0);+l||(l=+h.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,r)=>{this.$emit(r[0],_(r[1])?!0:r[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,(r,l,s,n)=>{if(l[s]==n)return r},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,r=this.fwheight;(this.flyweight.scrollTop/r>>0)+this.row-i-1>0||(this.flyweight.scrollTop=i*r,this.scroll())})}],this,{index:e})},lazyrun(e,t){clearTimeout(this.time),this.time=setTimeout(()=>{f.runer(e)},t||this.lazy)},run(e){let t=[],i=f.picker(e.target,"scrollTop=>top");f.merge(i,{height:this.realH,width:this.realW,index:i.top/this.fwheight>>0},this.space,"mix"),e.from||t.push(["onscroll",i]),f.each(this.flyweights,(r,l,s,n,h,g,c,a)=>{if(s=r/h>>0,c=s+n*(+(s<g%n)+(g/n>>0)),a=c*h+r%h,a>=this.count){t.push(["onend"]);return}l.index=c,l.top=c*this.fwheight,l.data=this.flys[a]},null,this.row,this.column,i.index),this.trigger(t),t=null},scroll(e){this.run(e||{target:this.flyweight,from:"space"})},re(){let e=this.count||this.flys.length,t=this.flyweights;if(!e)return t.length=e;this.count=e;let i=this.flyweight,r=f.picker(i,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let l=this.auto===!0,[s,n]=this.offset,h=r.width,g=r.height,c=(v(this.width,h)||h)+s,a=v(this.height,g)+n;this.realH=a-n;let u=h/c>>0||1,y=g/a>>0;this.row=y+2,this.column=u,this.fwheight=a;let w;l?(c=(h/u>>0)-s/u*(u-1),w=s):w=h%c/(u-1)>>0,this.realW=c,this.Height=Math.ceil(e/u)*a;let m=Math.min(e,u*this.row),d=m-1,p,k;for(;m-- >0;)p=d-m,k=this.flys[p],i=t[p],y=p/u>>0,this.$set(t,p,{data:k,top:y*a,left:p%u*(c+w),index:y});t.length=d+1;let x=[];g/a>d/u&&x.push(["onend"]),this.scroll(),x.push(["update:space",{row:(d/u>>0)+1,column:u,showrow:this.row,showcolumn:this.column}]),this.trigger(x)})}}};function B(e,t,i,r,l,s){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)=>s.scroll&&s.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,h)=>(o.openBlock(),o.createElementBlock("div",{key:h,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-924b4e98"]]),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,12 +1,12 @@
|
|
|
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
|
|
3
|
-
const
|
|
1
|
+
import { isArray as F, each as x, runer as y, picker as z, merge as O } from "@soei/util";
|
|
2
|
+
import { openBlock as _, createElementBlock as b, normalizeClass as L, normalizeStyle as k, createElementVNode as W, Fragment as E, renderList as S, renderSlot as T, createCommentVNode as A } from "vue";
|
|
3
|
+
const B = (t, e) => {
|
|
4
4
|
const i = t.__vccOpts || t;
|
|
5
|
-
for (const [
|
|
6
|
-
i[
|
|
5
|
+
for (const [r, s] of e)
|
|
6
|
+
i[r] = s;
|
|
7
7
|
return i;
|
|
8
8
|
};
|
|
9
|
-
let H = (t) => t == null || t == null,
|
|
9
|
+
let H = (t) => t == null || t == null, C = /(\d+|[+\-\*/]|%)/g, N = {
|
|
10
10
|
"+": (t, e) => t + e,
|
|
11
11
|
"-": (t, e) => t - e,
|
|
12
12
|
"*": (t, e) => t * e,
|
|
@@ -14,17 +14,17 @@ let H = (t) => t == null || t == null, B = /(\d+|[+\-\*/]|%)/g, N = {
|
|
|
14
14
|
"%": (t, e, i) => parseFloat(t) / 100 * i
|
|
15
15
|
}, $ = (t, e) => {
|
|
16
16
|
let i;
|
|
17
|
-
if (i = y("match", t,
|
|
18
|
-
let
|
|
19
|
-
for (;
|
|
20
|
-
|
|
21
|
-
+s || (s = +
|
|
17
|
+
if (i = y("match", t, C)) {
|
|
18
|
+
let r = i.length, s, l = 0, n, h = [];
|
|
19
|
+
for (; r--; )
|
|
20
|
+
l = i.shift(), l in N ? (s && h.push(s), l === "%" && (h.length = 2), n = l) : +l && h.push(+l), h.length == 2 && (h.push(e), s = N[n].apply(null, h), h.length = 0);
|
|
21
|
+
+s || (s = +h.pop()), t = s >> 0;
|
|
22
22
|
}
|
|
23
23
|
return t;
|
|
24
|
-
},
|
|
24
|
+
}, I = (...t) => {
|
|
25
25
|
console.info("::::FLYWEIGHT", ...t);
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const j = {
|
|
28
28
|
name: "Flyweight",
|
|
29
29
|
props: {
|
|
30
30
|
flys: {
|
|
@@ -124,14 +124,14 @@ const I = {
|
|
|
124
124
|
this.re(), this.$emit("resize");
|
|
125
125
|
}).observe(this.flyweight);
|
|
126
126
|
} catch (t) {
|
|
127
|
-
|
|
127
|
+
I(t);
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
methods: {
|
|
131
131
|
trigger(t, e) {
|
|
132
132
|
this.lazyrun(() => {
|
|
133
|
-
F(t) || (t = [[t, e]]), x(t, (i,
|
|
134
|
-
this.$emit(
|
|
133
|
+
F(t) || (t = [[t, e]]), x(t, (i, r) => {
|
|
134
|
+
this.$emit(r[0], H(r[1]) ? !0 : r[1]);
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
},
|
|
@@ -142,9 +142,9 @@ const I = {
|
|
|
142
142
|
setview(t) {
|
|
143
143
|
y([this.cheackflys, (e) => {
|
|
144
144
|
e = e || {};
|
|
145
|
-
let i = e.index || x(this.flys, (
|
|
146
|
-
if (s[
|
|
147
|
-
return
|
|
145
|
+
let i = e.index || x(this.flys, (r, s, l, n) => {
|
|
146
|
+
if (s[l] == n)
|
|
147
|
+
return r;
|
|
148
148
|
}, e.picker, e.id);
|
|
149
149
|
H(i) || this.setindex(i);
|
|
150
150
|
}], this, t);
|
|
@@ -152,8 +152,8 @@ const I = {
|
|
|
152
152
|
setindex(t) {
|
|
153
153
|
y([this.cheackflys, ({ index: e }) => {
|
|
154
154
|
this.$nextTick(() => {
|
|
155
|
-
let i = e / this.column >> 0,
|
|
156
|
-
(this.flyweight.scrollTop /
|
|
155
|
+
let i = e / this.column >> 0, r = this.fwheight;
|
|
156
|
+
(this.flyweight.scrollTop / r >> 0) + this.row - i - 1 > 0 || (this.flyweight.scrollTop = i * r, this.scroll());
|
|
157
157
|
});
|
|
158
158
|
}], this, { index: t });
|
|
159
159
|
},
|
|
@@ -163,80 +163,86 @@ const I = {
|
|
|
163
163
|
}, e || this.lazy);
|
|
164
164
|
},
|
|
165
165
|
run(t) {
|
|
166
|
-
let e = z(t.target, "scrollTop=>top");
|
|
167
|
-
|
|
166
|
+
let e = [], i = z(t.target, "scrollTop=>top");
|
|
167
|
+
O(i, {
|
|
168
|
+
height: this.realH,
|
|
169
|
+
width: this.realW,
|
|
170
|
+
/* 显示区域第一行的索引 */
|
|
171
|
+
index: i.top / this.fwheight >> 0
|
|
172
|
+
// ...this
|
|
173
|
+
}, this.space, "mix"), t.from || e.push(["onscroll", i]), x(
|
|
168
174
|
this.flyweights,
|
|
169
|
-
(
|
|
170
|
-
if (
|
|
171
|
-
(+(
|
|
172
|
-
|
|
175
|
+
(r, s, l, n, h, c, f, u) => {
|
|
176
|
+
if (l = r / h >> 0, f = l + n * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
177
|
+
(+(l < c % n) + (c / n >> 0)), u = f * h + r % h, u >= this.count) {
|
|
178
|
+
e.push(["onend"]);
|
|
173
179
|
return;
|
|
174
180
|
}
|
|
175
|
-
|
|
181
|
+
s.index = f, s.top = f * this.fwheight, s.data = this.flys[u];
|
|
176
182
|
},
|
|
177
183
|
null,
|
|
178
184
|
this.row,
|
|
179
185
|
this.column,
|
|
180
186
|
/* 显示区域第一行的索引 */
|
|
181
|
-
|
|
182
|
-
);
|
|
187
|
+
i.index
|
|
188
|
+
), this.trigger(e), e = null;
|
|
183
189
|
},
|
|
184
190
|
scroll(t) {
|
|
185
|
-
this.run(t || { target: this.flyweight });
|
|
191
|
+
this.run(t || { target: this.flyweight, from: "space" });
|
|
186
192
|
},
|
|
187
193
|
re() {
|
|
188
194
|
let t = this.count || this.flys.length, e = this.flyweights;
|
|
189
195
|
if (!t)
|
|
190
196
|
return e.length = t;
|
|
191
197
|
this.count = t;
|
|
192
|
-
let i = this.flyweight,
|
|
198
|
+
let i = this.flyweight, r = z(i, "clientHeight=>height,clientWidth=>width");
|
|
193
199
|
this.$nextTick(() => {
|
|
194
|
-
let s = this.auto === !0, [
|
|
195
|
-
this.realH =
|
|
196
|
-
let o =
|
|
197
|
-
this.row = g + 2, this.column = o, this.fwheight =
|
|
200
|
+
let s = this.auto === !0, [l, n] = this.offset, h = r.width, c = r.height, f = ($(this.width, h) || h) + l, u = $(this.height, c) + n;
|
|
201
|
+
this.realH = u - n;
|
|
202
|
+
let o = h / f >> 0 || 1, g = c / u >> 0;
|
|
203
|
+
this.row = g + 2, this.column = o, this.fwheight = u;
|
|
198
204
|
let d;
|
|
199
|
-
s ? (f = (
|
|
205
|
+
s ? (f = (h / o >> 0) - l / o * (o - 1), d = l) : d = h % f / (o - 1) >> 0, this.realW = f, this.Height = Math.ceil(t / o) * u;
|
|
200
206
|
let w = Math.min(t, o * this.row), p = w - 1, a, v;
|
|
201
207
|
for (; w-- > 0; )
|
|
202
208
|
a = p - w, v = this.flys[a], i = e[a], g = a / o >> 0, this.$set(e, a, {
|
|
203
209
|
data: v,
|
|
204
|
-
top: g *
|
|
210
|
+
top: g * u,
|
|
205
211
|
left: a % o * (f + d),
|
|
206
212
|
index: g
|
|
207
213
|
});
|
|
208
214
|
e.length = p + 1;
|
|
209
215
|
let m = [];
|
|
210
|
-
|
|
216
|
+
c / u > p / o && m.push(["onend"]), this.scroll(), m.push(["update:space", {
|
|
211
217
|
row: (p / o >> 0) + 1,
|
|
212
218
|
column: o,
|
|
213
219
|
showrow: this.row,
|
|
214
|
-
|
|
220
|
+
showcolumn: this.column
|
|
215
221
|
}]), this.trigger(m);
|
|
216
222
|
});
|
|
217
223
|
}
|
|
218
224
|
}
|
|
219
225
|
};
|
|
220
|
-
function
|
|
226
|
+
function M(t, e, i, r, s, l) {
|
|
221
227
|
return _(), b("div", {
|
|
222
228
|
ref: "flyweight",
|
|
223
|
-
class:
|
|
229
|
+
class: L(["flyweight", {
|
|
224
230
|
"flyweight-active": s.actice
|
|
225
231
|
}]),
|
|
226
232
|
style: k({
|
|
227
233
|
"--width": s.realW + "px",
|
|
228
234
|
"--height": s.realH + "px"
|
|
229
235
|
}),
|
|
230
|
-
onScroll: e[0] || (e[0] = (...n) =>
|
|
236
|
+
onScroll: e[0] || (e[0] = (...n) => l.scroll && l.scroll(...n))
|
|
231
237
|
}, [
|
|
232
|
-
|
|
238
|
+
W("div", {
|
|
233
239
|
class: "flyweight-all",
|
|
234
240
|
style: k({
|
|
235
241
|
"--flyweight-height": s.Height + "px"
|
|
236
242
|
})
|
|
237
243
|
}, [
|
|
238
|
-
(_(!0), b(E, null, S(s.flyweights, (n,
|
|
239
|
-
key:
|
|
244
|
+
(_(!0), b(E, null, S(s.flyweights, (n, h) => (_(), b("div", {
|
|
245
|
+
key: h,
|
|
240
246
|
style: k({
|
|
241
247
|
top: n.top + "px",
|
|
242
248
|
left: n.left + "px"
|
|
@@ -248,17 +254,17 @@ function j(t, e, i, l, s, h) {
|
|
|
248
254
|
}, void 0, !0)
|
|
249
255
|
], 4))), 128))
|
|
250
256
|
], 4),
|
|
251
|
-
s.flyweights.length ? T(t.$slots, "end", { key: 0 }, void 0, !0) :
|
|
257
|
+
s.flyweights.length ? T(t.$slots, "end", { key: 0 }, void 0, !0) : A("", !0)
|
|
252
258
|
], 38);
|
|
253
259
|
}
|
|
254
|
-
const
|
|
260
|
+
const R = /* @__PURE__ */ B(j, [["render", M], ["__scopeId", "data-v-924b4e98"]]), V = [R], Y = {
|
|
255
261
|
install(t) {
|
|
256
|
-
|
|
262
|
+
V.forEach((e) => {
|
|
257
263
|
t.component("s-" + e.name.toLowerCase(), e);
|
|
258
264
|
});
|
|
259
265
|
}
|
|
260
266
|
};
|
|
261
267
|
export {
|
|
262
|
-
|
|
263
|
-
|
|
268
|
+
R as Flyweight,
|
|
269
|
+
Y as default
|
|
264
270
|
};
|
package/README.md
CHANGED
|
@@ -2,26 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
# 享元模式 [](https://npmjs.com/package/@soei/flyweight) [](LICENSE.md) [](https://www.npmjs.com/package/@soei/flyweight) 
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
5
|

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

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