Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb4aeef

Browse files
authored
Merge pull request gridstack#1525 from adumesny/develop
web component fixes
2 parents c38966c + e1f5696 commit bb4aeef

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

demo/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ <h1>Demos</h1>
1919
<li><a href="serialization.html">Serialization</a></li>
2020
<li><a href="static.html">Static</a></li>
2121
<li><a href="two.html">Two grids</a></li>
22-
<li><a href="vue2js.html">Vue2.js</a></li>
2322
<li><a href="vue3js.html">Vue3.js</a></li>
23+
<li><a href="vue2js.html">Vue2.js</a></li>
24+
<li><a href="web-comp.html">Web Component</a></li>
2425
</ul>
2526
</body>
2627
</html>

demo/web-comp.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<html>
2+
<head>
3+
<title>Web Component demo</title>
4+
<!-- Polyfills only needed for Firefox and Edge. -->
5+
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@latest/webcomponents-loader.js"></script>
6+
<link rel="stylesheet" href="demo.css"/>
7+
<script src="../dist/gridstack-h5.js"></script>
8+
</head>
9+
<body>
10+
<h1>LitElement Web Component</h1>
11+
<script type="module">
12+
import {LitElement, html, css} from 'https://unpkg.com/lit-element/lit-element.js?module';
13+
14+
class MyElement extends LitElement {
15+
static get properties() { return {} }
16+
render() { return html`<style>:host {display: block;} </style><slot></slot>`; }
17+
}
18+
customElements.define('my-element', MyElement);
19+
</script>
20+
21+
<my-element class="grid-stack"></my-element>
22+
23+
<script type="text/javascript">
24+
let items = [
25+
{x:0, y:0, w:2, content: 'item 0'},
26+
{x:0, y:1, content: 'item 1'}
27+
];
28+
let grid = GridStack.init();
29+
grid.load(items);
30+
</script>
31+
</body>
32+
</html>

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Change log
5353
- fix [1330](https://github.com/gridstack/gridstack.js/issues/1330) `maxW` does not work as intended with resizable handle `"w"`
5454
- fix [1472](https://github.com/gridstack/gridstack.js/issues/1472) support all options for new dragged in widgets (read all `gs-xyz` attributes)
5555
- fix [1511](https://github.com/gridstack/gridstack.js/issues/1511) dragging any grid item content works
56+
- fix [1438](https://github.com/gridstack/gridstack.js/issues/1438) web-component fixes & grid with 0 size initially.
5657

5758
## 3.1.0 (2020-12-4)
5859

src/gridstack-extra.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* gridstack 2.0.0 extra CSS for [2-11] columns (non default)
2+
* gridstack 3.1.0-dev extra CSS for [2-11] columns (non default)
33
* https://gridstackjs.com/
44
* (c) 2014-2020 Alain Dumesny, Dylan Weiss, Pavel Reznikov
55
* gridstack.js may be freely distributed under the MIT license.

src/gridstack.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* gridstack 2.1.0 required CSS for default 12 and 1 column Mode size. Use gridstack-extra.css for column [2-11], else see https://github.com/gridstack/gridstack.js#custom-columns-css
2+
* gridstack 3.1.0-dev required CSS for default 12 and 1 column Mode size. Use gridstack-extra.css for column [2-11], else see https://github.com/gridstack/gridstack.js#custom-columns-css
33
* https://gridstackjs.com/
44
* (c) 2014-2020 Alain Dumesny, Dylan Weiss, Pavel Reznikov
55
* gridstack.js may be freely distributed under the MIT license.

src/gridstack.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ export class GridStack {
291291
this.el.classList.add(this.opts._styleSheetClass);
292292

293293
this._setStaticClass();
294-
this._updateStyles();
295294

296295
this.engine = new GridStackEngine({
297296
column: this.opts.column,
@@ -336,7 +335,7 @@ export class GridStack {
336335
this.placeholder.classList.add(this.opts.placeholderClass, defaults.itemClass, this.opts.itemClass);
337336
this.placeholder.appendChild(placeholderChild);
338337

339-
this._updateContainerHeight();
338+
this._updateStyles();
340339

341340
this._setupDragIn();
342341
this._setupRemoveDrop();
@@ -588,7 +587,8 @@ export class GridStack {
588587
* Gets current cell width.
589588
*/
590589
public cellWidth(): number {
591-
return this.el.offsetWidth / this.opts.column;
590+
// use parent width if we're 0 (no size yet)
591+
return (this.el.offsetWidth || this.el.parentElement.offsetWidth || window.innerWidth) / this.opts.column;
592592
}
593593

594594
/**
@@ -1171,7 +1171,9 @@ export class GridStack {
11711171
}
11721172

11731173
this._updateContainerHeight();
1174-
if (!this.opts.cellHeight) { // The rest will be handled by CSS TODO: I don't understand this usage
1174+
1175+
// if user is telling us they will handle the CSS themselves by setting heights to 0. Do we need this opts really ??
1176+
if (this.opts.cellHeight === 0) {
11751177
return this;
11761178
}
11771179

@@ -1363,7 +1365,7 @@ export class GridStack {
13631365
* and remember the prev columns we used, as well as check for auto cell height (square)
13641366
*/
13651367
public onParentResize(): GridStack {
1366-
if (!this.el) {return} // return if we're gone
1368+
if (!this.el || !this.el.clientWidth) return; // return if we're gone or no size yet (will get called again)
13671369

13681370
// make the cells content (minus margin) square again
13691371
if (this._isAutoCellHeight) {

0 commit comments

Comments
 (0)