@teipublisher/pb-components 2.26.1-next.2 → 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 +267 -9
- 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-6e4cee3a.js +0 -527
- package/src/assets/pb-styles.css +0 -51
- package/src/pb-light-dom.js +0 -40
package/src/pb-highlight.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit-element';
|
|
2
2
|
import { pbMixin } from './pb-mixin';
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Link elements to each other: if the user moves the mouse over one element,
|
|
7
6
|
* the others are highlighted by changing their background color. Which elements
|
|
@@ -11,7 +10,7 @@ import { pbMixin } from './pb-mixin';
|
|
|
11
10
|
*
|
|
12
11
|
* `pb-highlight` should be output for relevant elements via ODD processing model.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
13
|
+
*
|
|
15
14
|
*
|
|
16
15
|
* @slot - default unnamed slot for highlight content
|
|
17
16
|
* @fires pb-highlight-off - Fires removal of all highlights that might have existed before
|
|
@@ -19,151 +18,152 @@ import { pbMixin } from './pb-mixin';
|
|
|
19
18
|
* @fires pb-highlight-off - When received, triggers removal of a highlight that might have been on for this element before
|
|
20
19
|
* @fires pb-highlight-on - When received, switches the highlight on if the same key was received as the current element has
|
|
21
20
|
* @cssprop --pb-highlight-color - Background color to highlight an element
|
|
22
|
-
*/
|
|
21
|
+
*/
|
|
23
22
|
export class PbHighlight extends pbMixin(LitElement) {
|
|
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
|
-
|
|
23
|
+
static get properties() {
|
|
24
|
+
return {
|
|
25
|
+
...super.properties,
|
|
26
|
+
/**
|
|
27
|
+
* The key to which this element is connected.
|
|
28
|
+
*/
|
|
29
|
+
key: {
|
|
30
|
+
type: String,
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* If set to > 0, specifies a duration (in ms) after which
|
|
34
|
+
* the highlighting will be removed again
|
|
35
|
+
*/
|
|
36
|
+
duration: {
|
|
37
|
+
type: Number,
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Scroll this element into view when it receives a highlight event
|
|
41
|
+
*/
|
|
42
|
+
scroll: {
|
|
43
|
+
type: Boolean,
|
|
44
|
+
},
|
|
45
|
+
highlightSelf: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
attribute: 'highlight-self',
|
|
48
|
+
},
|
|
49
|
+
_className: {
|
|
50
|
+
type: String,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
constructor() {
|
|
56
|
+
super();
|
|
57
|
+
this.key = null;
|
|
58
|
+
this.duration = 0;
|
|
59
|
+
this.scroll = false;
|
|
60
|
+
this.highlightSelf = false;
|
|
61
|
+
this._className = 'highlight-off';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
connectedCallback() {
|
|
65
|
+
super.connectedCallback();
|
|
66
|
+
this.subscribeTo('pb-highlight-on', this._highlightOn.bind(this));
|
|
67
|
+
this.subscribeTo('pb-highlight-off', this._highlightOff.bind(this));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
command(command, state) {
|
|
71
|
+
super.command(command, state);
|
|
72
|
+
if (this.disabled) {
|
|
73
|
+
this._className = 'highlight-off';
|
|
54
74
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_mouseOver() {
|
|
78
|
+
this.emitTo('pb-highlight-off', {
|
|
79
|
+
source: this,
|
|
80
|
+
});
|
|
81
|
+
if (this.highlightSelf) {
|
|
82
|
+
this._highlightOn({ detail: { id: this.key } });
|
|
63
83
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
84
|
+
this.emitTo('pb-highlight-on', {
|
|
85
|
+
id: this.key,
|
|
86
|
+
source: this,
|
|
87
|
+
scroll: this.scroll,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
render() {
|
|
92
|
+
if (this.disabled) {
|
|
93
|
+
return html`<slot></slot>`;
|
|
69
94
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
95
|
+
return html`<span id="content" class="${this._className}" @mouseover="${this._mouseOver}"
|
|
96
|
+
><slot></slot
|
|
97
|
+
></span>`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static get styles() {
|
|
101
|
+
return css`
|
|
102
|
+
:host {
|
|
103
|
+
display: inline;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@keyframes keyFrameBackgroundColorIn {
|
|
107
|
+
0% {
|
|
108
|
+
background-color: inherit;
|
|
75
109
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_mouseOver() {
|
|
79
|
-
this.emitTo('pb-highlight-off', {
|
|
80
|
-
source: this
|
|
81
|
-
});
|
|
82
|
-
if (this.highlightSelf) {
|
|
83
|
-
this._highlightOn({ detail: { id: this.key } });
|
|
110
|
+
100% {
|
|
111
|
+
background-color: var(--pb-highlight-color, #f9e976);
|
|
84
112
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#content {
|
|
116
|
+
display: inline;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.highlight-on {
|
|
120
|
+
background-color: var(--pb-highlight-color, #f9e976);
|
|
121
|
+
animation-name: keyFrameBackgroundColorIn;
|
|
122
|
+
animation-duration: 500ms;
|
|
123
|
+
animation-iteration-count: 1;
|
|
124
|
+
animation-timing-function: ease-in;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.highlight-off {
|
|
128
|
+
background-color: inherit;
|
|
129
|
+
}
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
_highlightOn(ev) {
|
|
134
|
+
if (ev.detail.source != this && ev.detail.id === this.key) {
|
|
135
|
+
this._className = 'highlight-on';
|
|
136
|
+
if (ev.detail.scroll && this.disabled == false) {
|
|
137
|
+
this.scrollIntoView({ block: 'center', behaviour: 'smooth' });
|
|
138
|
+
}
|
|
139
|
+
if (this.duration > 0) {
|
|
140
|
+
setTimeout(() => {
|
|
141
|
+
this._className = 'highlight-off';
|
|
142
|
+
}, this.duration);
|
|
143
|
+
}
|
|
90
144
|
}
|
|
145
|
+
}
|
|
91
146
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
return html`<span id="content" class="${this._className}" @mouseover="${this._mouseOver}"><slot></slot></span>`;
|
|
147
|
+
_highlightOff(ev) {
|
|
148
|
+
if (ev.detail.source != this) {
|
|
149
|
+
this._className = 'highlight-off';
|
|
97
150
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
display: inline;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
.highlight-on {
|
|
119
|
-
background-color: var(--pb-highlight-color, #F9E976);
|
|
120
|
-
animation-name: keyFrameBackgroundColorIn;
|
|
121
|
-
animation-duration: 500ms;
|
|
122
|
-
animation-iteration-count: 1;
|
|
123
|
-
animation-timing-function: ease-in;
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
.highlight-off {
|
|
128
|
-
background-color: inherit;
|
|
129
|
-
}
|
|
130
|
-
`;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
_highlightOn(ev) {
|
|
134
|
-
if (ev.detail.source != this && ev.detail.id === this.key) {
|
|
135
|
-
this._className = 'highlight-on';
|
|
136
|
-
if (ev.detail.scroll && this.disabled == false) {
|
|
137
|
-
this.scrollIntoView({ block: "center", behaviour: 'smooth' });
|
|
138
|
-
}
|
|
139
|
-
if (this.duration > 0) {
|
|
140
|
-
setTimeout(function () {
|
|
141
|
-
this._className = 'highlight-off';
|
|
142
|
-
}.bind(this), this.duration);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
_highlightOff(ev) {
|
|
148
|
-
if (ev.detail.source != this) {
|
|
149
|
-
this._className = 'highlight-off';
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Fired if mouse pointer enters the element
|
|
155
|
-
*
|
|
156
|
-
* @event pb-highlight-on
|
|
157
|
-
* @param {String} id key
|
|
158
|
-
* @param {Object} source this element
|
|
159
|
-
* @param {scroll} should target scroll to highlighted position
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Fired if mouse pointer leaves the element
|
|
164
|
-
*
|
|
165
|
-
* @event pb-highlight-off
|
|
166
|
-
* @param {Object} source this element
|
|
167
|
-
*/
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Fired if mouse pointer enters the element
|
|
155
|
+
*
|
|
156
|
+
* @event pb-highlight-on
|
|
157
|
+
* @param {String} id key
|
|
158
|
+
* @param {Object} source this element
|
|
159
|
+
* @param {scroll} should target scroll to highlighted position
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Fired if mouse pointer leaves the element
|
|
164
|
+
*
|
|
165
|
+
* @event pb-highlight-off
|
|
166
|
+
* @param {Object} source this element
|
|
167
|
+
*/
|
|
168
168
|
}
|
|
169
|
-
customElements.define('pb-highlight', PbHighlight);
|
|
169
|
+
customElements.define('pb-highlight', PbHighlight);
|
package/src/pb-hotkeys.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import hotkeys from 'hotkeys-js';
|
|
2
2
|
|
|
3
|
-
const EXCLUDED_TAGS = [
|
|
4
|
-
'INPUT', 'SELECT', 'TEXTAREA', 'PAPER-INPUT', 'PAPER-TEXTAREA', 'PB-SEARCH'
|
|
5
|
-
];
|
|
3
|
+
const EXCLUDED_TAGS = ['INPUT', 'SELECT', 'TEXTAREA', 'PAPER-INPUT', 'PAPER-TEXTAREA', 'PB-SEARCH'];
|
|
6
4
|
const excluded = new Set(EXCLUDED_TAGS);
|
|
7
5
|
|
|
8
6
|
// disable hotkeys for form elements
|
|
9
7
|
let firstLoad = true;
|
|
10
8
|
if (firstLoad) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
hotkeys.filter = event => {
|
|
10
|
+
const { tagName } = event.target || event.srcElement;
|
|
11
|
+
return !(tagName.isContentEditable || excluded.has(tagName));
|
|
12
|
+
};
|
|
13
|
+
firstLoad = false;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
/**
|
|
@@ -21,56 +19,56 @@ if (firstLoad) {
|
|
|
21
19
|
* can then map the symbolic name to a function by calling `registerHotkey`.
|
|
22
20
|
*
|
|
23
21
|
*/
|
|
24
|
-
export const pbHotkeys =
|
|
25
|
-
|
|
22
|
+
export const pbHotkeys = superclass =>
|
|
23
|
+
class PbHotkeys extends superclass {
|
|
26
24
|
static get properties() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
25
|
+
return {
|
|
26
|
+
...super.properties,
|
|
27
|
+
hotkeys: {
|
|
28
|
+
type: Object,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
34
32
|
|
|
35
33
|
constructor() {
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
super();
|
|
35
|
+
this.hotkeys = {};
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
/**
|
|
41
|
-
*
|
|
39
|
+
*
|
|
42
40
|
* @param {String} name symbolic name, must be defined in `this.hotkeys`
|
|
43
41
|
* @param {import('hotkeys-js').KeyHandler} callback a callback function
|
|
44
42
|
*/
|
|
45
43
|
registerHotkey(name, callback, target) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
44
|
+
if (name && this.hotkeys[name]) {
|
|
45
|
+
if (target) {
|
|
46
|
+
hotkeys(this.hotkeys[name], { element: target }, callback);
|
|
47
|
+
} else {
|
|
48
|
+
hotkeys(this.hotkeys[name], callback);
|
|
52
49
|
}
|
|
50
|
+
}
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
display(name) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
if (name && this.hotkeys[name]) {
|
|
55
|
+
const output = [];
|
|
56
|
+
const keys = this.hotkeys[name].split(/\s*,\s*/);
|
|
57
|
+
keys.forEach(key => {
|
|
58
|
+
output.push(key.replace('+', '-'));
|
|
59
|
+
});
|
|
60
|
+
return output.join(', ');
|
|
61
|
+
}
|
|
62
|
+
return '';
|
|
65
63
|
}
|
|
66
|
-
}
|
|
64
|
+
};
|
|
67
65
|
|
|
68
66
|
export function registerHotkey(name, callback, target) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
if (target) {
|
|
68
|
+
hotkeys(name, { element: target }, callback);
|
|
69
|
+
} else {
|
|
70
|
+
hotkeys(name, callback);
|
|
71
|
+
}
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
window.pbKeyboard = registerHotkey;
|
|
74
|
+
window.pbKeyboard = registerHotkey;
|
package/src/pb-i18n.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement, html } from 'lit-element';
|
|
2
|
-
import { directive, NodePart, AttributePart } from
|
|
2
|
+
import { directive, NodePart, AttributePart } from 'lit-html';
|
|
3
3
|
|
|
4
4
|
// Cache created lit-html parts, so we can update translations
|
|
5
5
|
const partCache = new Map();
|
|
@@ -7,92 +7,89 @@ const partCache = new Map();
|
|
|
7
7
|
// The currently used i18next translation function
|
|
8
8
|
let _translate;
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
11
|
* Called by pb-page before the first pb-i18n-update
|
|
12
12
|
* to make sure the translation function is set.
|
|
13
13
|
*/
|
|
14
14
|
export function initTranslation(translate) {
|
|
15
|
-
|
|
15
|
+
_translate = translate;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function isConnected(part) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
return part.element.isConnected;
|
|
19
|
+
if (part instanceof NodePart) {
|
|
20
|
+
return part.startNode.isConnected;
|
|
21
|
+
}
|
|
22
|
+
if (part instanceof AttributePart) {
|
|
23
|
+
return part.committer.element.isConnected;
|
|
24
|
+
}
|
|
25
|
+
return part.element.isConnected;
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
function removeDisconnectedParts() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
Object.keys(partCache).forEach(part => {
|
|
30
|
+
if (!isConnected(part)) {
|
|
31
|
+
partCache.delete(part);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
function whenIdle(cb) {
|
|
39
|
-
|
|
37
|
+
'requestIdleCallback' in window ? window.requestIdleCallback(cb) : setTimeout(cb);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
function updatePart(part, cb) {
|
|
41
|
+
// Grab the new value
|
|
42
|
+
const newValue = cb();
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// Only set the value if it has changed
|
|
45
|
+
if (part.value === newValue) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Set the new value
|
|
53
|
-
part.setValue(newValue);
|
|
54
|
-
part.commit();
|
|
49
|
+
// Set the new value
|
|
50
|
+
part.setValue(newValue);
|
|
51
|
+
part.commit();
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
function updateParts(options) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
_translate = options.t;
|
|
56
|
+
partCache.forEach((cb, part) => {
|
|
57
|
+
if (isConnected(part)) {
|
|
58
|
+
updatePart(part, cb);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
/**
|
|
67
64
|
* Translate the given string using i18n.
|
|
68
|
-
*
|
|
65
|
+
*
|
|
69
66
|
* @param {String} key The key to translate
|
|
70
67
|
* @param {Object} [value] Optional object containing interpolation values
|
|
71
|
-
* @returns
|
|
68
|
+
* @returns
|
|
72
69
|
*/
|
|
73
70
|
export function get(key, value) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
if (_translate) {
|
|
72
|
+
return _translate(key, value);
|
|
73
|
+
}
|
|
74
|
+
return key;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
export const langChanged = directive(
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
export const langChanged = directive(cb => part => {
|
|
78
|
+
partCache.set(part, cb);
|
|
79
|
+
updatePart(part, cb);
|
|
83
80
|
});
|
|
84
81
|
|
|
85
82
|
/**
|
|
86
83
|
* lit-html directive to translate a given key into the target language
|
|
87
84
|
* using i18next.
|
|
88
|
-
*
|
|
85
|
+
*
|
|
89
86
|
* @param {String} key The key to translate
|
|
90
87
|
* @param {Object} [value] Optional object containing interpolation values
|
|
91
88
|
*/
|
|
92
89
|
export const translate = (key, value) => langChanged(() => get(key, value));
|
|
93
90
|
|
|
94
|
-
document.addEventListener('pb-i18n-update',
|
|
95
|
-
|
|
91
|
+
document.addEventListener('pb-i18n-update', ev => {
|
|
92
|
+
updateParts(ev.detail);
|
|
96
93
|
});
|
|
97
94
|
|
|
98
95
|
// start a background task to garbage collect parts
|
|
@@ -103,65 +100,65 @@ setInterval(() => whenIdle(() => removeDisconnectedParts()), 1000 * 60);
|
|
|
103
100
|
* display the contained content.
|
|
104
101
|
*/
|
|
105
102
|
export class PbI18n extends LitElement {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
103
|
+
static get properties() {
|
|
104
|
+
return {
|
|
105
|
+
...super.properties,
|
|
106
|
+
/**
|
|
107
|
+
* The i18n key to use for looking up the translation.
|
|
108
|
+
*/
|
|
109
|
+
key: {
|
|
110
|
+
type: String,
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Optional interpolation parameters to be passed to the
|
|
114
|
+
* translation function
|
|
115
|
+
*/
|
|
116
|
+
options: {
|
|
117
|
+
type: Object,
|
|
118
|
+
},
|
|
119
|
+
_translated: {
|
|
120
|
+
type: String,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
constructor() {
|
|
126
|
+
super();
|
|
127
|
+
this.key = 'missing-key';
|
|
128
|
+
this._options = null;
|
|
129
|
+
this._translated = null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
connectedCallback() {
|
|
133
|
+
super.connectedCallback();
|
|
134
|
+
|
|
135
|
+
this._fallback = this.innerHTML;
|
|
136
|
+
|
|
137
|
+
document.addEventListener('pb-i18n-update', this._translate.bind(this));
|
|
138
|
+
|
|
139
|
+
this._translate();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
set options(value) {
|
|
143
|
+
this._options = value;
|
|
144
|
+
this._translate();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_translate() {
|
|
148
|
+
const transl = get(this.key, this._options);
|
|
149
|
+
if (transl && transl !== this.key) {
|
|
150
|
+
this._translated = transl;
|
|
151
|
+
} else {
|
|
152
|
+
this._translated = null;
|
|
143
153
|
}
|
|
154
|
+
}
|
|
144
155
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
156
|
+
render() {
|
|
157
|
+
return this._translated ? this._translated : this._fallback;
|
|
158
|
+
}
|
|
149
159
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this._translated = transl;
|
|
154
|
-
} else {
|
|
155
|
-
this._translated = null;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
render() {
|
|
160
|
-
return this._translated ? this._translated : this._fallback;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
createRenderRoot() {
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
160
|
+
createRenderRoot() {
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
166
163
|
}
|
|
167
|
-
customElements.define('pb-i18n', PbI18n);
|
|
164
|
+
customElements.define('pb-i18n', PbI18n);
|