- -
-
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 00000000..c2925fb8
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: jbaysolutions
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
new file mode 100644
index 00000000..a6d9d440
--- /dev/null
+++ b/.github/workflows/build-test.yml
@@ -0,0 +1,32 @@
+name: Build and Test
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ node-version: [10.x, 12.x, 14.x, 15.x]
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Use Node.js ${{ matrix.node-version }}
+ uses: actions/setup-node@v1
+ with:
+ node-version: ${{ matrix.node-version }}
+ - name: Install dependency
+ run: yarn
+ - name: Lint check
+ run: yarn lint
+ - name: Build
+ run: yarn build
+ - name: Unit test
+ run: yarn test:unit
diff --git a/.github/workflows/vuepress-deploy.yml b/.github/workflows/vuepress-deploy.yml
index 4b19a5e3..a936b2b7 100644
--- a/.github/workflows/vuepress-deploy.yml
+++ b/.github/workflows/vuepress-deploy.yml
@@ -1,5 +1,8 @@
-name: Build and Deploy vuepress
-on: [push]
+name: Deploy vuepress website
+on:
+ push:
+ branches:
+ - master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
@@ -7,6 +10,10 @@ jobs:
- name: Checkout
uses: actions/checkout@master
+ - uses: actions/setup-node@v2
+ with:
+ node-version: '16'
+
- name: vuepress-deploy
uses: jenkey2011/vuepress-deploy@master
env:
diff --git a/.gitignore b/.gitignore
index 2cee15a2..83dfe282 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,7 +21,6 @@ yarn-error.log*
*.sln
*.sw*
-yarn.lock
yarn-error.log
website/docs/dist
diff --git a/README-zh_CN.md b/README-zh_CN.md
index 76ce8396..e940b464 100644
--- a/README-zh_CN.md
+++ b/README-zh_CN.md
@@ -6,10 +6,10 @@
vue-grid-layout是一个类似于[Gridster](http://dsmorse.github.io/gridster.js/)的栅格布局系统, 适用于Vue.js。 **灵感源自于 [React-Grid-Layout](https://github.com/STRML/react-grid-layout)**
-### **当前版本:** 2.3.8 (支持 Vue 2.2+)
+### **当前版本:** 2.4.0 (支持 Vue 2.2+)
### **Vue 2.1.10 及以下请使用 [2.1.3](https://github.com/jbaysolutions/vue-grid-layout/tree/2.1.3)**
-### **Vue 1 请使用 [1.0.3](https://github.com/jbaysolutions/vue-grid-layout/tree/1.0.3)**
+### **Vue 1 请使用 [1.0.3](https://github.com/jbaysolutions/vue-grid-layout/tree/1.0.3)**
@@ -39,8 +39,8 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
#### 成功案例
+- [DocsFold](https://www.docsfold.com/?utm_source=github&utm_medium=web&utm_campaign=vue-grid-layout)
- [Draxed](https://www.draxed.com/?utm_source=github&utm_medium=web&utm_campaign=vue-grid-layout)
-- [cryptotiles](https://www.cryptotiles.io/?utm_source=github&utm_medium=web&utm_campaign=vue-grid-layout)
- [Data Providers](https://www.dataproviders.io/?utm_source=github&utm_medium=web&utm_campaign=vue-grid-layout)
- [Cataholic](https://cataholic.glitch.me/)
@@ -64,10 +64,10 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
#### npm
- # 使用 npm
+ # 使用 npm
npm install vue-grid-layout --save
-
- # 使用 yarn
+
+ # 使用 yarn
yarn add vue-grid-layout
@@ -77,7 +77,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
import VueGridLayout from 'vue-grid-layout';
```
-加入到 Vue 组件
+加入到 Vue 组件
```javascript
export default {
@@ -87,8 +87,8 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
},
// ... data, methods, mounted (), etc.
}
-
-```
+
+```
#### 浏览器
@@ -123,14 +123,14 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
{"x":0,"y":9,"w":2,"h":3,"i":"18"},
{"x":2,"y":6,"w":2,"h":2,"i":"19"}
];
-
+
new Vue({
el: '#app',
data: {
layout: testLayout,
},
});
-```
+```
```html
@@ -167,14 +167,22 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
##### GridLayout
* **layout**
-
+
* type: `Array`
* required: `true`
数据源。值必须为 `Array`,其数据项为 `Object`。 每条数据项必须有 `i`, `x`, `y`, `w` 和 `h` 属性。 请参考下面的 `GridItem`。
+* **responsiveLayouts**
+
+ * type: `Object`
+ * required: `false`
+ * default: `{}`
+
+ 如果 `responsive` 设置为 `true`,该配置将作为栅格中每个断点的初始布局。键值是断点名称,每项的值都是类似 `layout` 属性定义的数据结构,值必须为 `Array`,其数据项为 `Object`。例如: `{lg: [layout items], md: [layout items]}`。需要注意的是,在创建栅格布局后设置该属性无效。
+
* **colNum**
-
+
* type: `Number`
* required: `false`
* default: `12`
@@ -182,7 +190,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
定义栅格系统的列数,其值需为自然数。
* **rowHeight**
-
+
* type: `Number`
* required: `false`
* default: `150`
@@ -190,7 +198,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
每行的高度,单位像素。
* **maxRows**
-
+
* type: `Number`
* required: `false`
* default: `Infinity`
@@ -198,7 +206,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
定义最大行数。
* **margin**
-
+
* type: `Array`
* required: `false`
* default: `[10, 10]`
@@ -208,7 +216,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
值必须是包含两个 `Number`的数组,数组中第一个元素表示水平边距,第二个表示垂直边距,单位为像素。
* **isDraggable**
-
+
* type: `Boolean`
* required: `false`
* default: `true`
@@ -216,7 +224,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识栅格中的元素是否可拖拽。
* **isResizable**
-
+
* type: `Boolean`
* required: `false`
* default: `true`
@@ -224,7 +232,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识栅格中的元素是否可调整大小。
* **isMirrored**
-
+
* type: `Boolean`
* required: `false`
* default: `false`
@@ -232,7 +240,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识栅格中的元素是否可镜像反转。
* **autoSize**
-
+
* type: `Boolean`
* required: `false`
* default: `true`
@@ -240,7 +248,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识容器是否自动调整大小。
* **verticalCompact**
-
+
* type: `Boolean`
* required: `false`
* default: `true`
@@ -248,7 +256,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识布局是否垂直压缩。
* **useCssTransforms**
-
+
* type: `Boolean`
* required: `false`
* default: `true`
@@ -256,7 +264,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识是否使用CSS属性 `transition-property: transform;`。
* **responsive**
-
+
* type: `Boolean`
* required: `false`
* default: `false`
@@ -269,7 +277,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
* required: `false`
* default: { lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }
- 为响应式布局设置断点。
+ 为响应式布局设置断点,其中参数代表不同设备的宽度:lg(large),md(medium),sm(small),xs(extra small)。
* **cols**
@@ -279,86 +287,100 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
设置每个断点对应的列数。
+* **useStyleCursor**
+
+ * type: `Boolean`
+ * required: `false`
+ * default: `true`
+
+ 标识是否使用动态鼠标指针样式。当拖动出现卡顿时,将此值设为 `false`也许可以缓解布局问题。
+
+ * **preventCollision**
+
+ * type: `Boolean`
+ * default: `false`
+
+ 值设置为ture时,栅格只能拖动至空白处。
##### GridItem
* **i**
-
+
* type: `String`
* required: `true`
栅格中元素的ID。
* **x**
-
+
* type: `Number`
* required: `true`
标识栅格元素位于第几列,需为自然数。
* **y**
-
+
* type: `Number`
* required: `true`
标识栅格元素位于第几行,需为自然数。
* **w**
-
+
* type: `Number`
* required: `true`
标识栅格元素的初始宽度,值为`colWidth`的倍数。
* **h**
-
+
* type: `Number`
* required: `true`
标识栅格元素的初始高度,值为`rowHeight`的倍数。
* **minW**
-
+
* type: `Number`
* required: `false`
* default: `1`
栅格元素的最小宽度,值为`colWidth`的倍数。
-
+
如果`w`小于`minW`,则`minW`的值会被`w`覆盖。
* **minH**
-
+
* type: `Number`
* required: `false`
* default: `1`
栅格元素的最小高度,值为`rowHeight`的倍数。
-
+
如果`h`小于`minH`,则`minH`的值会被`h`覆盖。
* **maxW**
-
+
* type: `Number`
* required: `false`
* default: `Infinity`
栅格元素的最大宽度,值为`colWidth`的倍数。
-
+
如果`w`大于`maxW`,则`maxW`的值会被`w`覆盖。
* **maxH**
-
+
* type: `Number`
* required: `false`
* default: `Infinity`
栅格元素的最大高度,值为`rowHeight`的倍数。
-
+
如果`h`大于`maxH`,则`maxH`的值会被`h`覆盖。
* **isDraggable**
-
+
* type: `Boolean`
* required: `false`
* default: `null`
@@ -366,7 +388,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识栅格元素是否可拖拽。如果值为`null`则取决于父容器。
* **isResizable**
-
+
* type: `Boolean`
* required: `false`
* default: `null`
@@ -374,7 +396,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识栅格元素是否可调整大小。如果值为`null`则取决于父容器。
* **static**
-
+
* type: `Boolean`
* required: `false`
* default: `false`
@@ -382,7 +404,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
标识栅格元素是否为静态的(无法拖拽、调整大小或被其他元素移动)。
* **dragIgnoreFrom**
-
+
* type: `String`
* required: `false`
* default: `'a, button'`
@@ -392,7 +414,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
请参考 [interact.js docs](http://interactjs.io/docs/#ignorable-selectors)中的`ignoreFrom`。
* **dragAllowFrom**
-
+
* type: `String`
* required: `false`
* default: `null`
@@ -404,7 +426,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
请参考 [interact.js docs](http://interactjs.io/docs/#ignorable-selectors)中的`allowFrom`。
* **resizeIgnoreFrom**
-
+
* type: `String`
* required: `false`
* default: `'a, button'`
@@ -419,7 +441,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
每一个栅格元素`grid-item`上都可以添加监听器,用于监听移动和调整大小事件,这样父级Vue对象就可以收到通知。
- [示例](https://jbaysolutions.github.io/vue-grid-layout/examples/02-events.html)
+ [示例](https://jbaysolutions.github.io/vue-grid-layout/examples/02-events.html)
````html
@@ -453,7 +475,7 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
{{item.i}}
-````
+````
* **layoutCreatedEvent**
@@ -518,12 +540,12 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
* **resizeEvent**
调整大小时的事件
-
+
```javascript
resizeEvent: function(i, newH, newW, newHPx, newWPx){
console.log("RESIZE i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx);
},
-```
+```
* **movedEvent**
@@ -538,21 +560,21 @@ Also check https://cli.vuejs.org/guide/build-targets.html#library
* **resizedEvent**
调整大小后的事件
-
+
```javascript
/**
- *
+ *
* @param i the item id/index
- * @param newH new height in grid rows
+ * @param newH new height in grid rows
* @param newW new width in grid columns
* @param newHPx new height in pixels
* @param newWPx new width in pixels
- *
+ *
*/
resizedEvent: function(i, newH, newW, newHPx, newWPx){
console.log("RESIZED i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx);
},
-```
+```
## 如何贡献
diff --git a/README.md b/README.md
index 9aa10cbb..540b2231 100644
--- a/README.md
+++ b/README.md
@@ -1,50 +1,26 @@
+
h.y&&e.y-h.y>h.h/4||(t=h.static?v(t,h,e,i):v(t,e,h,i)))}return t}function v(t,e,n,r){var i=!1;if(r){var o={x:n.x,y:n.y,w:n.w,h:n.h,i:"-1"};if(o.y=Math.max(e.y-n.h,0),!f(t,o))return h(t,n,void 0,o.y,i)}return h(t,n,void 0,n.y+1,i)}function g(t,e,n,r){var i="translate3d("+e+"px,"+t+"px, 0)";return{transform:i,WebkitTransform:i,MozTransform:i,msTransform:i,OTransform:i,width:n+"px",height:r+"px",position:"absolute"}}function y(t,e,n,r){var i="translate3d("+-1*e+"px,"+t+"px, 0)";return{transform:i,WebkitTransform:i,MozTransform:i,msTransform:i,OTransform:i,width:n+"px",height:r+"px",position:"absolute"}}function m(t,e,n,r){return{top:t+"px",left:e+"px",width:n+"px",height:r+"px",position:"absolute"}}function b(t,e,n,r){return{top:t+"px",right:e+"px",width:n+"px",height:r+"px",position:"absolute"}}function x(t){return[].concat(t).sort((function(t,e){return t.y===e.y&&t.x===e.x?0:t.y>e.y||t.y===e.y&&t.x>e.x?1:-1}))}function w(t,e){e=e||"Layout";var n=["x","y","w","h"];if(!Array.isArray(t))throw new Error(e+" must be an array!");for(var r=0,i=t.length;r]*>)/g,p=/\$([$&`']|\d\d?)/g,h=function(t){return void 0===t?t:String(t)};n("214f")("replace",2,(function(t,e,n,v){return[function(r,i){var o=t(this),a=void 0==r?void 0:r[e];return void 0!==a?a.call(r,o,i):n.call(String(o),r,i)},function(t,e){var i=v(n,t,this,e);if(i.done)return i.value;var f=r(t),d=String(this),p="function"===typeof e;p||(e=String(e));var y=f.global;if(y){var m=f.unicode;f.lastIndex=0}var b=[];while(1){var x=u(f,d);if(null===x)break;if(b.push(x),!y)break;var w=String(x[0]);""===w&&(f.lastIndex=s(d,o(f.lastIndex),m))}for(var S="",O=0,_=0;_ , or missing {t.autoStartHoldTimer=null},"autoStart:prepared":({interaction:t})=>{const e=Ve(t);e>0&&(t.autoStartHoldTimer=setTimeout(()=>{t.start(t.prepared,t.interactable,t.element)},e))},"interactions:move":({interaction:t,duplicate:e})=>{t.autoStartHoldTimer&&t.pointerWasMoved&&!e&&(clearTimeout(t.autoStartHoldTimer),t.autoStartHoldTimer=null)},"autoStart:before-start":({interaction:t})=>{const e=Ve(t);e>0&&(t.prepared.name=null)}},getHoldDuration:Ve};var Ze=Ue,Ke={id:"auto-start",install(t){t.usePlugin(Fe),t.usePlugin(Ze),t.usePlugin(Ye)}};function Je(t){const{defaults:e,actions:n}=t;t.autoScroll=Qe,Qe.now=()=>t.now(),n.phaselessTypes.autoscroll=!0,e.perAction.autoScroll=Qe.defaults}"object"===typeof window&&window&&Ee(window),Se.use(Ke);const Qe={defaults:{enabled:!1,margin:60,container:null,speed:300},now:Date.now,interaction:null,i:0,x:0,y:0,isScrolling:!1,prevTime:0,margin:0,speed:0,start(t){Qe.isScrolling=!0,V.cancel(Qe.i),t.autoScroll=Qe,Qe.interaction=t,Qe.prevTime=Qe.now(),Qe.i=V.request(Qe.scroll)},stop(){Qe.isScrolling=!1,Qe.interaction&&(Qe.interaction.autoScroll=null),V.cancel(Qe.i)},scroll(){const{interaction:t}=Qe,{interactable:e,element:n}=t,i=t.prepared.name,r=e.options[i].autoScroll,o=tn(r.container,e,n),s=Qe.now(),a=(s-Qe.prevTime)/1e3,c=r.speed*a;if(c>=1){const i={x:Qe.x*c,y:Qe.y*c};if(i.x||i.y){const r=en(o);R.window(o)?o.scrollBy(i.x,i.y):o&&(o.scrollLeft+=i.x,o.scrollTop+=i.y);const s=en(o),a={x:s.x-r.x,y:s.y-r.y};(a.x||a.y)&&e.fire({type:"autoscroll",target:n,interactable:e,delta:a,interaction:t,container:o})}Qe.prevTime=s}Qe.isScrolling&&(V.cancel(Qe.i),Qe.i=V.request(Qe.scroll))},check(t,e){var n;const i=t.options;return null==(n=i[e].autoScroll)?void 0:n.enabled},onInteractionMove({interaction:t,pointer:e}){if(!t.interacting()||!Qe.check(t.interactable,t.prepared.name))return;if(t.simulation)return void(Qe.x=Qe.y=0);let n,i,r,o;const{interactable:s,element:a}=t,c=t.prepared.name,l=s.options[c].autoScroll,u=tn(l.container,s,a);if(R.window(u))o=e.clientXVue Grid Layout Example 1 - Basic
-
- View project on Github
-
- Next example: Move and resize events
-
- [x, y, w, h]
:
-
- Vue Grid Layout Example 2 - Move and resize events
-
- View project on Github
-
- Previous example: Basic
-
- Next example: Multiple grids
-
- [x, y, w, h]
:
- Vue Grid Layout Example 3 - Multiple grids
-
-View project on Github
-
-Previous example: Move and resize events
-
-Next example: Drag allow/ignore elements
-
-
-Grid 1
- [x, y, w, h]
:
-
-Grid 2
- [x, y, w, h]
:
- Vue Grid Layout Example 4 - Drag allow/ignore elements
-
-View project on Github
-
-Previous example: Multiple grids
-
-Next example: Mirrored grid layout
-
-
-
- Ignore drag on certain elements and allow on on others.
-
- Click and drag the dots on the corner of each item to reposition
- [x, y, w, h]
:
-
-
- Vue Grid Layout Example 5 - Mirrored grid layout
-
-View project on Github
-
-Previous example: Drag allow/ignore elements
-
-Next example: Responsive
-
-
-[x, y, w, h]
:
-
- Vue Grid Layout Example 6 - Responsive
-
- View project on Github
-
- Previous example: Mirrored grid layout
-
- Next example: Prevent collision
-
- [x, y, w, h]
:
-
- Vue Grid Layout Example 7 - Prevent Collision
-
- View project on Github
-
- Previous example: Responsive
-
- Next example: Responsive - predefined layouts
-
- [x, y, w, h]
:
-
- Vue Grid Layout Example 8 - Responsive with predefined layouts
-
- View project on Github
-
- Previous example: Prevent collision
-
- Next example: Dynamic Add/Remove
-
- [x, y, w, h]
:
-
- Vue Grid Layout Example 9 - Dynamic Add/Remove
-
- View project on Github
-
- Previous example: Responsive - predefined layouts
-
- Next example: Drag from outside
-
- [x, y, w, h]
:
-
- Vue Grid Layout Example 09 - Drag From Outside
-
- View project on Github
-
- Previous example: Dynamic Add/Remove
-
-
-
-
- This demo shows what happens when an item is added from outside of the grid.
-
-
- Once you drop the item within the grid you'll get its coordinates/properties and can perform actions with it accordingly.
-
-
-
- [x, y, w, h]
:
-
-
[x, y, w, h]
:
+ diff --git a/website/docs/.vuepress/public/examples/09-dynamic-add-remove.html b/website/docs/.vuepress/public/examples/09-dynamic-add-remove.html index e112a7e0..6d390aff 100644 --- a/website/docs/.vuepress/public/examples/09-dynamic-add-remove.html +++ b/website/docs/.vuepress/public/examples/09-dynamic-add-remove.html @@ -65,7 +65,7 @@ - + diff --git a/website/docs/.vuepress/public/examples/09-dynamic-add-remove.js b/website/docs/.vuepress/public/examples/09-dynamic-add-remove.js index c50f506a..3001a9be 100644 --- a/website/docs/.vuepress/public/examples/09-dynamic-add-remove.js +++ b/website/docs/.vuepress/public/examples/09-dynamic-add-remove.js @@ -40,7 +40,8 @@ new Vue({ this.index++; }, removeItem: function (val) { - this.layout = this.layout.filter((item) => item.i !== val); + const index = this.layout.map(item => item.i).indexOf(val); + this.layout.splice(index, 1); }, }, }); diff --git a/website/docs/.vuepress/public/examples/10-drag-from-outside.html b/website/docs/.vuepress/public/examples/10-drag-from-outside.html index fe53563a..5ccedf00 100644 --- a/website/docs/.vuepress/public/examples/10-drag-from-outside.html +++ b/website/docs/.vuepress/public/examples/10-drag-from-outside.html @@ -25,7 +25,7 @@
-
+ Next example: Bounded
This demo shows what happens when an item is added from outside of the grid.
diff --git a/website/docs/.vuepress/public/examples/11-bounded.html b/website/docs/.vuepress/public/examples/11-bounded.html
new file mode 100644
index 00000000..e5bb1eef
--- /dev/null
+++ b/website/docs/.vuepress/public/examples/11-bounded.html
@@ -0,0 +1,64 @@
+
+
+
+
+ +
+ + + + + +
+ +