@soei/flyweight 0.0.2 → 0.0.3
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 +15 -0
- package/dist/Flyweight.cjs +1 -1
- package/dist/Flyweight.js +40 -26
- package/dist/style.css +1 -1
- package/package.json +8 -8
- package/src/Flyweight.vue +14 -0
package/README.md
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
# 享元模式
|
|
2
2
|
|
|
3
|
+
```html
|
|
4
|
+
<div style="height:100px;width:300px;">
|
|
5
|
+
<!-- 确认父容器 宽 高 存在, 依赖父容器 `宽`, `高` 计算 -->
|
|
6
|
+
<s-flyweight ...></s-flyweight>
|
|
7
|
+
</div>
|
|
8
|
+
```
|
|
9
|
+
|
|
3
10
|
### 更新日志
|
|
4
11
|
|
|
12
|
+
### `0.0.3`
|
|
13
|
+
|
|
14
|
+
- #### 新增 `:top`
|
|
15
|
+
|
|
16
|
+
```html
|
|
17
|
+
<s-flyweight :top="滚动高度"></s-flyweight>
|
|
18
|
+
```
|
|
19
|
+
|
|
5
20
|
### `0.0.2`
|
|
6
21
|
|
|
7
22
|
- #### 优化了 `Vue3` 的 `兼容` 问题
|
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 c=require("@soei/util"),h=require("vue");const p=(e,t)=>{const i=e.__vccOpts||e;for(const[r,l]of t)i[r]=l;return i};let m=e=>e==null||e==null,x=(...e)=>{console.info("::::FLYWEIGHT",...e)};const k={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}},computed:{flyweight(){return this.$refs.flyweight}},data(){return{flyweights:[],actice:!1,Height:null,column:1,row:1,fwheight:10,count:0,task:[]}},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){x(e)}},methods:{cheackflys(e){if(!this.flys.length)return e&&this.task.push(e),!0},setview(e){c.runer([this.cheackflys,t=>{t=t||{};let i=t.index||c.each(this.flys,(r,l,n,s)=>{if(l[n]==s)return r},t.picker,t.id);m(i)||this.setindex(i)}],this,e)},setindex(e){c.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(()=>{c.runer(e)},t||this.lazy)},run(e){let t=c.picker(e.target,"scrollTop=>top");c.each(this.flyweights,(i,r,l,n,s,o,u,y)=>{if(l=i/s>>0,u=l+n*(+(l<o%n)+(o/n>>0)),y=u*s+i%s,y>=this.count){this.lazyrun(()=>this.$emit("onend",!0));return}r.index=u,r.top=r.index*this.fwheight,r.data=this.flys[y]},null,this.row,this.column,t.top/this.fwheight>>0)},scroll(e){this.run(e||{target:this.flyweight})},re(){let e=this.flyweight,t=c.picker(e,"clientHeight=>height,clientWidth=>width");this.$nextTick(()=>{let[i,r]=this.offset,l=this.width;l==0&&(l=t.width);let n=l+i,s=this.height+r,o=t.width/n>>0,u=t.height/s>>0;this.row=u+2,this.column=o,this.fwheight=s;let y=t.width%n/(o-1)>>0;this.Height=Math.ceil(this.count/o)*s;let d=Math.min(this.count,o*this.row),a=d-1,f,g;for(;d-- >0;)f=a-d,g=this.flys[f],e=this.flyweights[f],this.$set(this.flyweights,f,{data:g,top:(f/o>>0)*s,left:f%o*(n+y),index:f/o>>0});this.flyweights.length=a+1,this.scroll()})}}};function _(e,t,i,r,l,n){return h.openBlock(),h.createElementBlock("div",{ref:"flyweight",class:h.normalizeClass(["flyweight",{"flyweight-active":l.actice}]),style:h.normalizeStyle({"--width":i.width?i.width+"px":"100%","--height":i.height+"px"}),onScroll:t[0]||(t[0]=(...s)=>n.scroll&&n.scroll(...s))},[h.createElementVNode("div",{class:"flyweight-all",style:h.normalizeStyle({"--flyweight-height":l.Height+"px"})},[(h.openBlock(!0),h.createElementBlock(h.Fragment,null,h.renderList(l.flyweights,(s,o)=>(h.openBlock(),h.createElementBlock("div",{key:o,style:h.normalizeStyle({top:s.top+"px",left:s.left+"px"})},[h.renderSlot(e.$slots,"default",{data:s.data,index:s.index},void 0,!0)],4))),128))],4),l.flyweights.length?h.renderSlot(e.$slots,"end",{key:0},void 0,!0):h.createCommentVNode("",!0)],38)}const w=p(k,[["render",_],["__scopeId","data-v-075d9b23"]]),v=[w],b={install(e){v.forEach(t=>{e.component("s-"+t.name.toLowerCase(),t)})}};exports.Flyweight=w;exports.default=b;
|
package/dist/Flyweight.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { runer as
|
|
2
|
-
import { openBlock as
|
|
1
|
+
import { runer as y, each as m, picker as x } from "@soei/util";
|
|
2
|
+
import { openBlock as d, createElementBlock as g, normalizeClass as k, normalizeStyle as w, createElementVNode as v, Fragment as b, renderList as z, renderSlot as _, createCommentVNode as T } from "vue";
|
|
3
3
|
const N = (t, e) => {
|
|
4
4
|
const i = t.__vccOpts || t;
|
|
5
5
|
for (const [l, s] of e)
|
|
@@ -39,6 +39,14 @@ const H = {
|
|
|
39
39
|
index: {
|
|
40
40
|
type: Number,
|
|
41
41
|
default: 0
|
|
42
|
+
},
|
|
43
|
+
top: {
|
|
44
|
+
type: Number,
|
|
45
|
+
default: !1
|
|
46
|
+
},
|
|
47
|
+
left: {
|
|
48
|
+
type: Number,
|
|
49
|
+
default: !1
|
|
42
50
|
}
|
|
43
51
|
},
|
|
44
52
|
computed: {
|
|
@@ -74,6 +82,12 @@ const H = {
|
|
|
74
82
|
},
|
|
75
83
|
index(t) {
|
|
76
84
|
this.setindex(t);
|
|
85
|
+
},
|
|
86
|
+
top(t) {
|
|
87
|
+
this.flyweight.scrollTop = t;
|
|
88
|
+
},
|
|
89
|
+
left(t) {
|
|
90
|
+
this.flyweight.scrollLeft = t;
|
|
77
91
|
}
|
|
78
92
|
},
|
|
79
93
|
mounted() {
|
|
@@ -94,17 +108,17 @@ const H = {
|
|
|
94
108
|
return t && this.task.push(t), !0;
|
|
95
109
|
},
|
|
96
110
|
setview(t) {
|
|
97
|
-
|
|
111
|
+
y([this.cheackflys, (e) => {
|
|
98
112
|
e = e || {};
|
|
99
|
-
let i = e.index || m(this.flys, (l, s,
|
|
100
|
-
if (s[
|
|
113
|
+
let i = e.index || m(this.flys, (l, s, r, h) => {
|
|
114
|
+
if (s[r] == h)
|
|
101
115
|
return l;
|
|
102
116
|
}, e.picker, e.id);
|
|
103
117
|
$(i) || this.setindex(i);
|
|
104
118
|
}], this, t);
|
|
105
119
|
},
|
|
106
120
|
setindex(t) {
|
|
107
|
-
|
|
121
|
+
y([this.cheackflys, ({ index: e }) => {
|
|
108
122
|
this.$nextTick(() => {
|
|
109
123
|
let i = e / this.column >> 0, l = this.fwheight;
|
|
110
124
|
(this.flyweight.scrollTop / l >> 0) + this.row - i - 1 > 0 || (this.flyweight.scrollTop = i * l, this.scroll());
|
|
@@ -113,16 +127,16 @@ const H = {
|
|
|
113
127
|
},
|
|
114
128
|
lazyrun(t, e) {
|
|
115
129
|
clearTimeout(this.time), this.time = setTimeout(() => {
|
|
116
|
-
|
|
130
|
+
y(t);
|
|
117
131
|
}, e || this.lazy);
|
|
118
132
|
},
|
|
119
133
|
run(t) {
|
|
120
134
|
let e = x(t.target, "scrollTop=>top");
|
|
121
135
|
m(
|
|
122
136
|
this.flyweights,
|
|
123
|
-
(i, l, s,
|
|
124
|
-
if (s = i / h >> 0, f = s +
|
|
125
|
-
(+(s <
|
|
137
|
+
(i, l, s, r, h, n, f, c) => {
|
|
138
|
+
if (s = i / h >> 0, f = s + r * /* 偏移量, 如果超出顶部 + 1轮,排列到列队后, 否则保持在当前*/
|
|
139
|
+
(+(s < n % r) + (n / r >> 0)), c = f * h + i % h, c >= this.count) {
|
|
126
140
|
this.lazyrun(() => this.$emit("onend", !0));
|
|
127
141
|
return;
|
|
128
142
|
}
|
|
@@ -143,25 +157,25 @@ const H = {
|
|
|
143
157
|
this.$nextTick(() => {
|
|
144
158
|
let [i, l] = this.offset, s = this.width;
|
|
145
159
|
s == 0 && (s = e.width);
|
|
146
|
-
let
|
|
147
|
-
this.row = f + 2, this.column =
|
|
148
|
-
let c = e.width %
|
|
149
|
-
this.Height = Math.ceil(this.count /
|
|
150
|
-
let u = Math.min(this.count,
|
|
160
|
+
let r = s + i, h = this.height + l, n = e.width / r >> 0, f = e.height / h >> 0;
|
|
161
|
+
this.row = f + 2, this.column = n, this.fwheight = h;
|
|
162
|
+
let c = e.width % r / (n - 1) >> 0;
|
|
163
|
+
this.Height = Math.ceil(this.count / n) * h;
|
|
164
|
+
let u = Math.min(this.count, n * this.row), a = u - 1, o, p;
|
|
151
165
|
for (; u-- > 0; )
|
|
152
166
|
o = a - u, p = this.flys[o], t = this.flyweights[o], this.$set(this.flyweights, o, {
|
|
153
167
|
data: p,
|
|
154
|
-
top: (o /
|
|
155
|
-
left: o %
|
|
156
|
-
index: o /
|
|
168
|
+
top: (o / n >> 0) * h,
|
|
169
|
+
left: o % n * (r + c),
|
|
170
|
+
index: o / n >> 0
|
|
157
171
|
});
|
|
158
172
|
this.flyweights.length = a + 1, this.scroll();
|
|
159
173
|
});
|
|
160
174
|
}
|
|
161
175
|
}
|
|
162
176
|
};
|
|
163
|
-
function
|
|
164
|
-
return
|
|
177
|
+
function L(t, e, i, l, s, r) {
|
|
178
|
+
return d(), g("div", {
|
|
165
179
|
ref: "flyweight",
|
|
166
180
|
class: k(["flyweight", {
|
|
167
181
|
"flyweight-active": s.actice
|
|
@@ -170,7 +184,7 @@ function O(t, e, i, l, s, n) {
|
|
|
170
184
|
"--width": i.width ? i.width + "px" : "100%",
|
|
171
185
|
"--height": i.height + "px"
|
|
172
186
|
}),
|
|
173
|
-
onScroll: e[0] || (e[0] = (...h) =>
|
|
187
|
+
onScroll: e[0] || (e[0] = (...h) => r.scroll && r.scroll(...h))
|
|
174
188
|
}, [
|
|
175
189
|
v("div", {
|
|
176
190
|
class: "flyweight-all",
|
|
@@ -178,8 +192,8 @@ function O(t, e, i, l, s, n) {
|
|
|
178
192
|
"--flyweight-height": s.Height + "px"
|
|
179
193
|
})
|
|
180
194
|
}, [
|
|
181
|
-
(
|
|
182
|
-
key:
|
|
195
|
+
(d(!0), g(b, null, z(s.flyweights, (h, n) => (d(), g("div", {
|
|
196
|
+
key: n,
|
|
183
197
|
style: w({
|
|
184
198
|
top: h.top + "px",
|
|
185
199
|
left: h.left + "px"
|
|
@@ -194,14 +208,14 @@ function O(t, e, i, l, s, n) {
|
|
|
194
208
|
s.flyweights.length ? _(t.$slots, "end", { key: 0 }, void 0, !0) : T("", !0)
|
|
195
209
|
], 38);
|
|
196
210
|
}
|
|
197
|
-
const
|
|
211
|
+
const O = /* @__PURE__ */ N(H, [["render", L], ["__scopeId", "data-v-075d9b23"]]), E = [O], S = {
|
|
198
212
|
install(t) {
|
|
199
|
-
|
|
213
|
+
E.forEach((e) => {
|
|
200
214
|
t.component("s-" + e.name.toLowerCase(), e);
|
|
201
215
|
});
|
|
202
216
|
}
|
|
203
217
|
};
|
|
204
218
|
export {
|
|
205
|
-
|
|
219
|
+
O as Flyweight,
|
|
206
220
|
S as default
|
|
207
221
|
};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.flyweight[data-v-
|
|
1
|
+
.flyweight[data-v-075d9b23]{height:100%;width:100%;overflow:auto;position:relative}.flyweight .flyweight-all[data-v-075d9b23]{height:var(--flyweight-height)}.flyweight .flyweight-all[data-v-075d9b23]>*{width: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.3",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/Flyweight.cjs",
|
|
8
8
|
"module": "dist/Flyweight.js",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"preview": "vite preview"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@soei/util": "^1.1.1"
|
|
20
|
-
"vue": "^3.3.4"
|
|
19
|
+
"@soei/util": "^1.1.1"
|
|
21
20
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
21
|
+
"keywords": [
|
|
22
|
+
"Flyweight",
|
|
23
|
+
"享元模式",
|
|
24
|
+
"List",
|
|
25
|
+
"列表展示"
|
|
26
|
+
]
|
|
27
27
|
}
|
package/src/Flyweight.vue
CHANGED
|
@@ -60,6 +60,14 @@ export default {
|
|
|
60
60
|
index: {
|
|
61
61
|
type: Number,
|
|
62
62
|
default: 0
|
|
63
|
+
},
|
|
64
|
+
top: {
|
|
65
|
+
type: Number,
|
|
66
|
+
default: false
|
|
67
|
+
},
|
|
68
|
+
left: {
|
|
69
|
+
type: Number,
|
|
70
|
+
default: false
|
|
63
71
|
}
|
|
64
72
|
},
|
|
65
73
|
computed: {
|
|
@@ -99,6 +107,12 @@ export default {
|
|
|
99
107
|
},
|
|
100
108
|
index(index) {
|
|
101
109
|
this.setindex(index);
|
|
110
|
+
},
|
|
111
|
+
top(top) {
|
|
112
|
+
this.flyweight.scrollTop = top;
|
|
113
|
+
},
|
|
114
|
+
left(left) {
|
|
115
|
+
this.flyweight.scrollLeft = left;
|
|
102
116
|
}
|
|
103
117
|
},
|
|
104
118
|
mounted() {
|