@teipublisher/pb-components 2.26.1-next.3 → 3.0.0
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/.github/workflows/main.yml +3 -3
- package/.github/workflows/node.js.yml +3 -3
- package/.github/workflows/release.js.yml +4 -4
- package/.releaserc.json +2 -2
- package/CHANGELOG.md +262 -11
- package/Dockerfile +78 -70
- package/css/components.css +5 -5
- package/css/leaflet/images/layers.png +0 -0
- package/dist/demo/components.css +46 -1
- package/dist/demo/pb-browse-docs2.html +1 -1
- package/dist/demo/pb-dialog.html +3 -5
- package/dist/demo/pb-drawer2.html +1 -1
- package/dist/demo/pb-facsimile.html +2 -2
- package/dist/demo/pb-grid.html +19 -6
- package/dist/demo/pb-leaflet-map.html +1 -1
- package/dist/demo/pb-login.html +0 -2
- package/dist/demo/pb-message.html +1 -2
- package/dist/demo/pb-progress.html +2 -2
- package/dist/demo/pb-repeat.html +1 -3
- package/dist/demo/pb-search.html +7 -4
- package/dist/demo/pb-search3.html +1 -1
- package/dist/demo/pb-search4.html +2 -2
- package/dist/demo/pb-view3.html +1 -1
- package/dist/{iron-form-3b8dcaa7.js → iron-form-dfb3e3b1.js} +95 -95
- package/dist/paper-checkbox-645e1077.js +200 -0
- package/dist/{paper-icon-button-b1d31571.js → paper-icon-button-984162bd.js} +1 -1
- package/dist/{paper-checkbox-515a5284.js → paper-inky-focus-behavior-fa16796b.js} +58 -247
- package/dist/{paper-listbox-a3b7175c.js → paper-listbox-5f5d1cec.js} +152 -162
- package/dist/pb-code-editor.js +25 -20
- package/dist/pb-component-docs.js +68 -64
- package/dist/pb-components-bundle.js +1983 -2293
- package/dist/pb-edit-app.js +167 -107
- package/dist/pb-elements.json +176 -120
- package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
- package/dist/pb-leaflet-map.js +23 -23
- package/dist/pb-mei.js +56 -41
- package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
- package/dist/pb-odd-editor.js +1023 -782
- package/dist/pb-tify.js +2 -2
- package/dist/vaadin-element-mixin-beb74ffd.js +545 -0
- package/gh-pages.js +5 -3
- package/i18n/common/en.json +6 -0
- package/i18n/common/pl.json +2 -2
- package/lib/openseadragon.min.js +6 -6
- package/package.json +3 -3
- package/pb-elements.json +176 -120
- package/src/assets/components.css +5 -5
- package/src/authority/airtable.js +20 -21
- package/src/authority/anton.js +129 -129
- package/src/authority/custom.js +23 -21
- package/src/authority/geonames.js +38 -32
- package/src/authority/gnd.js +50 -42
- package/src/authority/kbga.js +137 -134
- package/src/authority/metagrid.js +44 -46
- package/src/authority/reconciliation.js +66 -67
- package/src/authority/registry.js +4 -4
- package/src/docs/pb-component-docs.js +2 -2
- package/src/docs/pb-component-view.js +5 -5
- package/src/docs/pb-components-list.js +2 -2
- package/src/docs/pb-demo-snippet.js +2 -2
- package/src/dts-client.js +299 -297
- package/src/dts-select-endpoint.js +90 -82
- package/src/parse-date-service.js +184 -135
- package/src/pb-ajax.js +158 -171
- package/src/pb-authority-lookup.js +191 -156
- package/src/pb-autocomplete.js +292 -280
- package/src/pb-blacklab-highlight.js +264 -259
- package/src/pb-blacklab-results.js +236 -221
- package/src/pb-browse-docs.js +540 -475
- package/src/pb-browse.js +68 -65
- package/src/pb-clipboard.js +79 -76
- package/src/pb-code-editor.js +110 -102
- package/src/pb-code-highlight.js +209 -204
- package/src/pb-codepen.js +79 -72
- package/src/pb-collapse.js +211 -151
- package/src/pb-combo-box.js +190 -190
- package/src/pb-components-bundle.js +1 -1
- package/src/pb-components.js +1 -0
- package/src/pb-custom-form.js +173 -153
- package/src/pb-dialog.js +98 -62
- package/src/pb-document.js +89 -90
- package/src/pb-download.js +212 -196
- package/src/pb-drawer.js +145 -148
- package/src/pb-edit-app.js +301 -229
- package/src/pb-edit-xml.js +100 -97
- package/src/pb-events.js +114 -107
- package/src/pb-facs-link.js +104 -102
- package/src/pb-facsimile.js +474 -410
- package/src/pb-formula.js +151 -153
- package/src/pb-geolocation.js +129 -131
- package/src/pb-grid-action.js +53 -56
- package/src/pb-grid.js +231 -228
- package/src/pb-highlight.js +140 -140
- package/src/pb-hotkeys.js +40 -42
- package/src/pb-i18n.js +101 -104
- package/src/pb-image-strip.js +84 -78
- package/src/pb-lang.js +142 -57
- package/src/pb-leaflet-map.js +488 -485
- package/src/pb-link.js +126 -124
- package/src/pb-load.js +431 -429
- package/src/pb-login.js +299 -244
- package/src/pb-manage-odds.js +352 -336
- package/src/pb-map-icon.js +89 -89
- package/src/pb-map-layer.js +85 -85
- package/src/pb-markdown.js +90 -99
- package/src/pb-media-query.js +74 -72
- package/src/pb-mei.js +306 -295
- package/src/pb-message.js +139 -97
- package/src/pb-mixin.js +269 -264
- package/src/pb-navigation.js +80 -95
- package/src/pb-observable.js +38 -38
- package/src/pb-odd-editor.js +1054 -958
- package/src/pb-odd-elementspec-editor.js +349 -298
- package/src/pb-odd-model-editor.js +1075 -909
- package/src/pb-odd-parameter-editor.js +200 -178
- package/src/pb-odd-rendition-editor.js +136 -124
- package/src/pb-page.js +431 -422
- package/src/pb-paginate.js +228 -179
- package/src/pb-panel.js +198 -182
- package/src/pb-popover-themes.js +15 -8
- package/src/pb-popover.js +296 -287
- package/src/pb-print-preview.js +127 -127
- package/src/pb-progress.js +51 -51
- package/src/pb-repeat.js +105 -104
- package/src/pb-restricted.js +84 -77
- package/src/pb-search.js +256 -228
- package/src/pb-select-feature.js +127 -120
- package/src/pb-select-odd.js +132 -124
- package/src/pb-select-template.js +89 -78
- package/src/pb-select.js +251 -227
- package/src/pb-split-list.js +179 -174
- package/src/pb-svg.js +80 -79
- package/src/pb-table-column.js +54 -54
- package/src/pb-table-grid.js +221 -203
- package/src/pb-tabs.js +61 -63
- package/src/pb-tify.js +154 -154
- package/src/pb-timeline.js +382 -249
- package/src/pb-toggle-feature.js +195 -187
- package/src/pb-upload.js +184 -174
- package/src/pb-version.js +30 -30
- package/src/pb-view-annotate.js +135 -98
- package/src/pb-view.js +1282 -1270
- package/src/pb-zoom.js +127 -45
- package/src/polymer-hack.js +1 -1
- package/src/search-result-service.js +256 -223
- package/src/seed-element.js +13 -20
- package/src/settings.js +4 -4
- package/src/theming.js +98 -91
- package/src/urls.js +289 -289
- package/src/utils.js +53 -51
- package/css/pb-styles.css +0 -51
- package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
- package/src/assets/pb-styles.css +0 -51
- package/src/pb-light-dom.js +0 -41
package/src/pb-grid-action.js
CHANGED
|
@@ -1,72 +1,69 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit-element';
|
|
2
2
|
import { pbMixin } from './pb-mixin.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* an action component to execute an 'add panel' or 'remove panel' action on a pb-grid.
|
|
7
6
|
*
|
|
8
7
|
* @slot - default unnamed slot for content
|
|
9
|
-
*
|
|
8
|
+
*
|
|
10
9
|
*/
|
|
11
10
|
export class PbGridAction extends pbMixin(LitElement) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
static get properties() {
|
|
12
|
+
return {
|
|
13
|
+
...super.properties,
|
|
14
|
+
/**
|
|
15
|
+
* the type of action. Can be either `add` or `remove`
|
|
16
|
+
*
|
|
17
|
+
* Defaults to `add`
|
|
18
|
+
*/
|
|
19
|
+
action: {
|
|
20
|
+
type: String,
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* reference to a pb-grid element
|
|
24
|
+
*/
|
|
25
|
+
grid: {
|
|
26
|
+
type: String,
|
|
27
|
+
},
|
|
28
|
+
initial: {
|
|
29
|
+
type: Number,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
constructor() {
|
|
35
|
+
super();
|
|
36
|
+
this.action = 'add';
|
|
37
|
+
this.initial = 0;
|
|
38
|
+
}
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
connectedCallback() {
|
|
41
|
+
super.connectedCallback();
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
`;
|
|
49
|
-
}
|
|
44
|
+
render() {
|
|
45
|
+
return html` <a @click="${this._click}"><slot></slot></a> `;
|
|
46
|
+
}
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
static get styles() {
|
|
49
|
+
return css`
|
|
50
|
+
:host {
|
|
51
|
+
display: block;
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
56
|
+
_click() {
|
|
57
|
+
// todo: grid must be in lightDOM to be discovered. What is expected for this.grid? A string like '#myId'?
|
|
58
|
+
const grid = document.querySelector(this.grid);
|
|
59
|
+
if (!(grid && grid.addPanel)) {
|
|
60
|
+
return console.error('<pb-grid-action> grid not found: %s', this.grid);
|
|
61
|
+
}
|
|
62
|
+
if (this.action === 'add') {
|
|
63
|
+
grid.addPanel(this.initial);
|
|
64
|
+
} else {
|
|
65
|
+
grid.removePanel(this.closest('pb-panel,pb-grid'));
|
|
70
66
|
}
|
|
67
|
+
}
|
|
71
68
|
}
|
|
72
|
-
customElements.define('pb-grid-action', PbGridAction);
|
|
69
|
+
customElements.define('pb-grid-action', PbGridAction);
|
package/src/pb-grid.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit-element';
|
|
2
2
|
import { pbMixin } from './pb-mixin.js';
|
|
3
|
-
import { registry } from
|
|
3
|
+
import { registry } from './urls.js';
|
|
4
4
|
import './pb-panel.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -15,265 +15,268 @@ import './pb-panel.js';
|
|
|
15
15
|
* @cssprop --pb-grid-column-gap - Width of the gap between columns
|
|
16
16
|
*/
|
|
17
17
|
export class PbGrid extends pbMixin(LitElement) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
18
|
+
static get properties() {
|
|
19
|
+
return {
|
|
20
|
+
...super.properties,
|
|
21
|
+
/**
|
|
22
|
+
* an array of panel items to display when the component is loaded. It should contain a
|
|
23
|
+
* number for each panel to show, indicating the ordinal position of the template within the `<pb-panel>`
|
|
24
|
+
* to initialize. For example, if you have two templates in `<pb-panel>`: "transcription" and "translation",
|
|
25
|
+
* setting `panels="[0, 1]"` will show two columns, one with the transcription, the other with the translation.
|
|
26
|
+
*
|
|
27
|
+
* Passing in a browser parameter `panels` with a comma-separated list will set this property as well.
|
|
28
|
+
*/
|
|
29
|
+
panels: {
|
|
30
|
+
type: Array,
|
|
31
|
+
},
|
|
32
|
+
direction: {
|
|
33
|
+
type: String,
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* the number of columns
|
|
37
|
+
*/
|
|
38
|
+
_columns: {
|
|
39
|
+
type: Number,
|
|
40
|
+
},
|
|
41
|
+
/**
|
|
42
|
+
* CSS Selektor to choose elements to animate. If not specified all 'pb-view' elements will be animated by default.
|
|
43
|
+
*/
|
|
44
|
+
animated: {
|
|
45
|
+
type: String,
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* wether to animate the view when new page is loaded. Defaults to 'false' meaning that no
|
|
49
|
+
* animation takes place.
|
|
50
|
+
*/
|
|
51
|
+
animation: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
constructor() {
|
|
58
|
+
super();
|
|
59
|
+
this.panels = [];
|
|
60
|
+
this.direction = 'ltr';
|
|
61
|
+
this.animated = 'pb-view';
|
|
62
|
+
this.animation = false;
|
|
63
|
+
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
connectedCallback() {
|
|
66
|
+
super.connectedCallback();
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
this.subscribeTo('pb-panel', ev => {
|
|
69
|
+
const idx = this._getPanelIndex(ev.detail.panel);
|
|
70
|
+
if (idx < 0) {
|
|
71
|
+
return; // panel not found
|
|
72
|
+
}
|
|
73
|
+
console.log('<pb-grid> Updating panel %d to show %s', idx, ev.detail.active);
|
|
74
|
+
this.panels[this.direction === 'rtl' ? this.panels.length - idx - 1 : idx] = ev.detail.active;
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
registry.commit(this, this._getState());
|
|
77
|
+
});
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
this.subscribeTo('pb-zoom', ev => {
|
|
80
|
+
this.zoom(ev.detail.direction);
|
|
81
|
+
});
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
registry.subscribe(this, (state) => {
|
|
89
|
-
const newState = state.panels ? state.panels.split('.') : [];
|
|
90
|
-
this.panels = newState;
|
|
91
|
-
this.innerHTML=''; // hard reset of child DOM
|
|
92
|
-
this.panels.forEach(panelNum => this._insertPanel(panelNum));
|
|
93
|
-
this._update();
|
|
94
|
-
});
|
|
95
|
-
this._columns = this.panels.length;
|
|
96
|
-
this.template = this.querySelector('template');
|
|
83
|
+
const panelsParam = registry.get('panels');
|
|
84
|
+
if (panelsParam) {
|
|
85
|
+
this.panels = panelsParam.split('.').map(param => parseInt(param));
|
|
97
86
|
}
|
|
98
87
|
|
|
99
|
-
|
|
88
|
+
registry.subscribe(this, state => {
|
|
89
|
+
const newState = state.panels ? state.panels.split('.') : [];
|
|
90
|
+
this.panels = newState;
|
|
91
|
+
this.innerHTML = ''; // hard reset of child DOM
|
|
92
|
+
this.panels.forEach(panelNum => this._insertPanel(panelNum));
|
|
93
|
+
this._update();
|
|
94
|
+
});
|
|
95
|
+
this._columns = this.panels.length;
|
|
96
|
+
this.template = this.querySelector('template');
|
|
97
|
+
}
|
|
100
98
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
firstUpdated() {
|
|
100
|
+
this.panels.forEach(panelNum => this._insertPanel(panelNum));
|
|
101
|
+
registry.commit(this, this._getState());
|
|
102
|
+
this._animate();
|
|
103
|
+
this._update();
|
|
105
104
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
this.addEventListener('pb-drop', ev => {
|
|
106
|
+
const draggedPanelIdx = parseInt(ev.detail.panel);
|
|
107
|
+
const targetPanelIdx = this._getPanelIndex(ev.detail.target);
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
console.log(
|
|
110
|
+
'<pb-grid> Insert panel %d at %d in %s',
|
|
111
|
+
draggedPanelIdx,
|
|
112
|
+
targetPanelIdx,
|
|
113
|
+
this.panels,
|
|
114
|
+
);
|
|
115
|
+
this.querySelectorAll('._grid_panel').forEach(panel => {
|
|
116
|
+
panel.classList.remove('dragover');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
this.panels.splice(targetPanelIdx, 0, this.panels.splice(draggedPanelIdx, 1)[0]);
|
|
120
|
+
this.innerHTML = ''; // hard reset of child DOM
|
|
121
|
+
this.panels.forEach(panelNum => this._insertPanel(panelNum));
|
|
122
|
+
registry.commit(this, this._getState());
|
|
123
|
+
this._update();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* slides in all panels from left to right with a slight delay between the panels. If animejs is not
|
|
129
|
+
* loaded nothing happens and content is displayed as usual.
|
|
130
|
+
*/
|
|
131
|
+
_animate() {
|
|
132
|
+
if (this.animation) {
|
|
133
|
+
if (typeof anime && 'anime' in window) {
|
|
134
|
+
// console.log('animated elements', document.querySelectorAll('pb-panel'));
|
|
135
|
+
const animated = document.querySelectorAll(this.animated);
|
|
136
|
+
const anim = anime.timeline({
|
|
137
|
+
easing: 'linear',
|
|
138
|
+
duration: 400,
|
|
139
|
+
});
|
|
140
|
+
anim.add({
|
|
141
|
+
targets: animated,
|
|
142
|
+
opacity: {
|
|
143
|
+
value: [0, 0.6],
|
|
144
|
+
duration: 200,
|
|
145
|
+
delay: 100,
|
|
146
|
+
easing: 'linear',
|
|
147
|
+
},
|
|
148
|
+
translateX: [2000, 0],
|
|
149
|
+
duration: 400,
|
|
150
|
+
delay: anime.stagger(100, { start: 100 }),
|
|
151
|
+
});
|
|
152
|
+
anim.add({
|
|
153
|
+
targets: animated,
|
|
154
|
+
opacity: [0.6, 1],
|
|
155
|
+
duration: 200,
|
|
156
|
+
delay: anime.stagger(50),
|
|
120
157
|
});
|
|
158
|
+
anim.play();
|
|
159
|
+
}
|
|
121
160
|
}
|
|
161
|
+
}
|
|
122
162
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
targets: animated,
|
|
138
|
-
opacity: {
|
|
139
|
-
value: [0, 0.6],
|
|
140
|
-
duration: 200,
|
|
141
|
-
delay: 100,
|
|
142
|
-
easing: 'linear'
|
|
143
|
-
},
|
|
144
|
-
translateX: [2000, 0],
|
|
145
|
-
duration: 400,
|
|
146
|
-
delay: anime.stagger(100, { start: 100 })
|
|
147
|
-
});
|
|
148
|
-
anim.add({
|
|
149
|
-
targets: animated,
|
|
150
|
-
opacity: [0.6, 1],
|
|
151
|
-
duration: 200,
|
|
152
|
-
delay: anime.stagger(50)
|
|
153
|
-
});
|
|
154
|
-
anim.play();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
163
|
+
/**
|
|
164
|
+
* Add a panel. Defaults to opening 'the next' panel if the `initial` parameter is omitted: if
|
|
165
|
+
* panels 1,6,3 are open, panel 7 will be added
|
|
166
|
+
*
|
|
167
|
+
* @param {number} [initial] The panel number of the panel to add.
|
|
168
|
+
*/
|
|
169
|
+
addPanel(initial) {
|
|
170
|
+
let value = initial;
|
|
171
|
+
if (initial === undefined && !this.panels.length) {
|
|
172
|
+
value = 0;
|
|
173
|
+
}
|
|
174
|
+
if (initial === undefined && this.panels.length) {
|
|
175
|
+
const max = this.panels.reduce((result, next) => Math.max(result, next), 0);
|
|
176
|
+
value = max + 1;
|
|
157
177
|
}
|
|
158
178
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
* panels 1,6,3 are open, panel 7 will be added
|
|
162
|
-
*
|
|
163
|
-
* @param {number} [initial] The panel number of the panel to add.
|
|
164
|
-
*/
|
|
165
|
-
addPanel(initial) {
|
|
166
|
-
let value = initial;
|
|
167
|
-
if (initial === undefined && !this.panels.length) {
|
|
168
|
-
value = 0;
|
|
169
|
-
}
|
|
170
|
-
if (initial === undefined && this.panels.length) {
|
|
171
|
-
const max = this.panels.reduce((result, next) => Math.max(result, next), 0);
|
|
172
|
-
value = max + 1;
|
|
173
|
-
}
|
|
179
|
+
this._columns += 1;
|
|
180
|
+
this.panels.push(value);
|
|
174
181
|
|
|
175
|
-
|
|
176
|
-
|
|
182
|
+
this._insertPanel(value);
|
|
183
|
+
registry.commit(this, this._getState());
|
|
184
|
+
this._update();
|
|
185
|
+
this.emitTo('pb-refresh');
|
|
186
|
+
}
|
|
177
187
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Remove a panel from the grid
|
|
190
|
+
*
|
|
191
|
+
* @param {HTMLElement|number} panel the pb-panel element or the panel number
|
|
192
|
+
*/
|
|
193
|
+
removePanel(panel) {
|
|
194
|
+
let idx;
|
|
195
|
+
let container;
|
|
196
|
+
if (typeof panel === 'number') {
|
|
197
|
+
idx = this.panels.indexOf(panel);
|
|
198
|
+
container = this.querySelector(`[active="${panel}"]`);
|
|
199
|
+
} else {
|
|
200
|
+
container = panel;
|
|
201
|
+
idx = this._getPanelIndex(panel);
|
|
182
202
|
}
|
|
203
|
+
console.log('<pb-grid> Removing panel %d', idx);
|
|
204
|
+
this.panels.splice(this.direction === 'rtl' ? this.panels.length - idx - 1 : idx, 1);
|
|
183
205
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
let idx;
|
|
191
|
-
let container;
|
|
192
|
-
if (typeof panel === 'number') {
|
|
193
|
-
idx = this.panels.indexOf(panel);
|
|
194
|
-
container = this.querySelector(`[active="${panel}"]`);
|
|
195
|
-
} else {
|
|
196
|
-
container = panel;
|
|
197
|
-
idx = this._getPanelIndex(panel);
|
|
198
|
-
}
|
|
199
|
-
console.log('<pb-grid> Removing panel %d', idx);
|
|
200
|
-
this.panels.splice(this.direction === 'rtl' ? this.panels.length - idx - 1 : idx, 1);
|
|
206
|
+
container.parentNode.removeChild(container);
|
|
207
|
+
this._columns -= 1;
|
|
208
|
+
registry.commit(this, this._getState());
|
|
209
|
+
this._assignPanelIds();
|
|
210
|
+
this._update();
|
|
211
|
+
}
|
|
201
212
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
213
|
+
_insertPanel(active) {
|
|
214
|
+
const clone = document.importNode(this.template.content.firstElementChild, true);
|
|
215
|
+
clone.setAttribute('active', active);
|
|
216
|
+
if (this.direction === 'ltr' || this.querySelectorAll('._grid_panel').length === 0) {
|
|
217
|
+
this.appendChild(clone);
|
|
218
|
+
} else {
|
|
219
|
+
this.insertBefore(clone, this.firstElementChild);
|
|
207
220
|
}
|
|
221
|
+
clone.classList.add('_grid_panel');
|
|
222
|
+
this._assignPanelIds();
|
|
223
|
+
}
|
|
208
224
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
225
|
+
_update() {
|
|
226
|
+
const widths = Array.from(this.children)
|
|
227
|
+
.filter(child => !(child instanceof HTMLTemplateElement))
|
|
228
|
+
.map(child => {
|
|
229
|
+
const styles = window.getComputedStyle(child);
|
|
230
|
+
const width = styles.getPropertyValue('max-width');
|
|
231
|
+
if (width && width !== 'none') {
|
|
232
|
+
return width;
|
|
216
233
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
234
|
+
return '1fr';
|
|
235
|
+
});
|
|
236
|
+
this.style.setProperty('--pb-computed-column-widths', widths.join(' '));
|
|
237
|
+
}
|
|
220
238
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const styles = window.getComputedStyle(child);
|
|
226
|
-
const width = styles.getPropertyValue('max-width');
|
|
227
|
-
if (width && width !== 'none') {
|
|
228
|
-
return width;
|
|
229
|
-
}
|
|
230
|
-
return '1fr';
|
|
231
|
-
});
|
|
232
|
-
this.style.setProperty('--pb-computed-column-widths', widths.join(' '));
|
|
233
|
-
}
|
|
239
|
+
_getPanelIndex(panel) {
|
|
240
|
+
const panels = Array.from(this.querySelectorAll('._grid_panel'));
|
|
241
|
+
return panels.indexOf(panel);
|
|
242
|
+
}
|
|
234
243
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
244
|
+
_assignPanelIds() {
|
|
245
|
+
this.querySelectorAll('._grid_panel').forEach((panel, idx) => {
|
|
246
|
+
panel.position = idx;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
239
249
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
});
|
|
244
|
-
}
|
|
250
|
+
_getState() {
|
|
251
|
+
return { panels: this.panels.join('.') };
|
|
252
|
+
}
|
|
245
253
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
render() {
|
|
251
|
-
return html`<slot></slot>`;
|
|
252
|
-
}
|
|
254
|
+
render() {
|
|
255
|
+
return html`<slot></slot>`;
|
|
256
|
+
}
|
|
253
257
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
258
|
+
static get styles() {
|
|
259
|
+
return css`
|
|
260
|
+
:host {
|
|
261
|
+
display: grid;
|
|
262
|
+
grid-template-columns: var(--pb-grid-column-widths, var(--pb-computed-column-widths));
|
|
263
|
+
grid-column-gap: var(--pb-grid-column-gap, 20px);
|
|
264
|
+
justify-content: space-between;
|
|
265
|
+
}
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
264
268
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
269
|
+
zoom(direction) {
|
|
270
|
+
const fontSize = window.getComputedStyle(this).getPropertyValue('font-size');
|
|
271
|
+
const size = parseInt(fontSize.replace(/^(\d+)px/, '$1'));
|
|
268
272
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
273
|
+
if (direction === 'in') {
|
|
274
|
+
this.style.fontSize = `${size + 1}px`;
|
|
275
|
+
} else {
|
|
276
|
+
this.style.fontSize = `${size - 1}px`;
|
|
274
277
|
}
|
|
275
|
-
|
|
278
|
+
}
|
|
276
279
|
}
|
|
277
280
|
if (!customElements.get('pb-grid')) {
|
|
278
|
-
|
|
281
|
+
customElements.define('pb-grid', PbGrid);
|
|
279
282
|
}
|