@soei/flyweight 0.1.0 → 0.1.1
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 +11 -11
- 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
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=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,v={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"%":(e,t,i)=>parseFloat(e)/100*i},b=(e,t)=>{let i;if(i=u.runer("match",e,H)){let s=i.length,l,h=0,n,r=[];for(;s--;)h=i.shift(),h in v?(l&&r.push(l),h==="%"&&(r.length=2),n=h):+h&&r.push(+h),r.length==2&&(r.push(t),l=v[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(()=>{u.isArray(e)||(e=[[e,t]]),u.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){u.runer([this.cheackflys,t=>{t=t||{};let i=t.index||u.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){u.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(()=>{u.runer(e)},t||this.lazy)},run(e){let t=u.picker(e.target,"scrollTop=>top");u.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=u.picker(i,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let l=this.auto===!0,[h,n]=this.offset,r=s.width,a=s.height,c=(b(this.width,r)||r)+h,g=b(this.height,a)+n;this.realH=g-n;let f=r/c>>0||1,p=a/g>>0;this.row=p+2,this.column=f,this.fwheight=g;let w;l?(c=(r/f>>0)-h/f*(f-1),w=h):w=r%c/(f-1)>>0,this.realW=c,this.Height=Math.ceil(e/f)*g;let m=Math.min(e,f*this.row),d=m-1,y,k;for(;m-- >0;)y=d-m,k=this.flys[y],i=t[y],p=y/f>>0,this.$set(t,y,{data:k,top:p*g,left:y%f*(c+w),index:p});t.length=d+1;let x=[];a/g>d/f&&x.push(["onend"]),this.scroll(),x.push(["update:space",{row:(d/f>>0)+1,column:f,showrow:this.row,showcolumn: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-f7462fc9"]]),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,5 +1,5 @@
|
|
|
1
1
|
import { isArray as F, each as x, runer as y, picker as z } from "@soei/util";
|
|
2
|
-
import { openBlock as _, createElementBlock as
|
|
2
|
+
import { openBlock as _, createElementBlock as k, normalizeClass as O, normalizeStyle as v, createElementVNode as L, Fragment as E, renderList as S, renderSlot as T, createCommentVNode as W } from "vue";
|
|
3
3
|
const A = (t, e) => {
|
|
4
4
|
const i = t.__vccOpts || t;
|
|
5
5
|
for (const [l, s] of e)
|
|
@@ -197,10 +197,10 @@ const I = {
|
|
|
197
197
|
this.row = g + 2, this.column = o, this.fwheight = c;
|
|
198
198
|
let d;
|
|
199
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,
|
|
200
|
+
let w = Math.min(t, o * this.row), p = w - 1, a, b;
|
|
201
201
|
for (; w-- > 0; )
|
|
202
|
-
a = p - w,
|
|
203
|
-
data:
|
|
202
|
+
a = p - w, b = this.flys[a], i = e[a], g = a / o >> 0, this.$set(e, a, {
|
|
203
|
+
data: b,
|
|
204
204
|
top: g * c,
|
|
205
205
|
left: a % o * (f + d),
|
|
206
206
|
index: g
|
|
@@ -211,19 +211,19 @@ const I = {
|
|
|
211
211
|
row: (p / o >> 0) + 1,
|
|
212
212
|
column: o,
|
|
213
213
|
showrow: this.row,
|
|
214
|
-
|
|
214
|
+
showcolumn: this.column
|
|
215
215
|
}]), this.trigger(m);
|
|
216
216
|
});
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
};
|
|
220
220
|
function j(t, e, i, l, s, h) {
|
|
221
|
-
return _(),
|
|
221
|
+
return _(), k("div", {
|
|
222
222
|
ref: "flyweight",
|
|
223
223
|
class: O(["flyweight", {
|
|
224
224
|
"flyweight-active": s.actice
|
|
225
225
|
}]),
|
|
226
|
-
style:
|
|
226
|
+
style: v({
|
|
227
227
|
"--width": s.realW + "px",
|
|
228
228
|
"--height": s.realH + "px"
|
|
229
229
|
}),
|
|
@@ -231,13 +231,13 @@ function j(t, e, i, l, s, h) {
|
|
|
231
231
|
}, [
|
|
232
232
|
L("div", {
|
|
233
233
|
class: "flyweight-all",
|
|
234
|
-
style:
|
|
234
|
+
style: v({
|
|
235
235
|
"--flyweight-height": s.Height + "px"
|
|
236
236
|
})
|
|
237
237
|
}, [
|
|
238
|
-
(_(!0),
|
|
238
|
+
(_(!0), k(E, null, S(s.flyweights, (n, r) => (_(), k("div", {
|
|
239
239
|
key: r,
|
|
240
|
-
style:
|
|
240
|
+
style: v({
|
|
241
241
|
top: n.top + "px",
|
|
242
242
|
left: n.left + "px"
|
|
243
243
|
})
|
|
@@ -251,7 +251,7 @@ function j(t, e, i, l, s, h) {
|
|
|
251
251
|
s.flyweights.length ? T(t.$slots, "end", { key: 0 }, void 0, !0) : W("", !0)
|
|
252
252
|
], 38);
|
|
253
253
|
}
|
|
254
|
-
const M = /* @__PURE__ */ A(I, [["render", j], ["__scopeId", "data-v-
|
|
254
|
+
const M = /* @__PURE__ */ A(I, [["render", j], ["__scopeId", "data-v-f7462fc9"]]), R = [M], U = {
|
|
255
255
|
install(t) {
|
|
256
256
|
R.forEach((e) => {
|
|
257
257
|
t.component("s-" + e.name.toLowerCase(), e);
|
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-f7462fc9]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-f7462fc9]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-f7462fc9]>*{width:calc(var(--width));height:var(--height);position:absolute}
|