@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.
Files changed (154) hide show
  1. package/.github/workflows/main.yml +3 -3
  2. package/.github/workflows/node.js.yml +3 -3
  3. package/.github/workflows/release.js.yml +4 -4
  4. package/.releaserc.json +2 -2
  5. package/CHANGELOG.md +267 -9
  6. package/Dockerfile +78 -70
  7. package/css/components.css +5 -5
  8. package/css/leaflet/images/layers.png +0 -0
  9. package/dist/demo/components.css +46 -1
  10. package/dist/demo/pb-browse-docs2.html +1 -1
  11. package/dist/demo/pb-dialog.html +3 -5
  12. package/dist/demo/pb-drawer2.html +1 -1
  13. package/dist/demo/pb-facsimile.html +2 -2
  14. package/dist/demo/pb-grid.html +19 -6
  15. package/dist/demo/pb-leaflet-map.html +1 -1
  16. package/dist/demo/pb-login.html +0 -2
  17. package/dist/demo/pb-message.html +1 -2
  18. package/dist/demo/pb-progress.html +2 -2
  19. package/dist/demo/pb-repeat.html +1 -3
  20. package/dist/demo/pb-search.html +7 -4
  21. package/dist/demo/pb-search3.html +1 -1
  22. package/dist/demo/pb-search4.html +2 -2
  23. package/dist/demo/pb-view3.html +1 -1
  24. package/dist/{iron-form-3b8dcaa7.js → iron-form-dfb3e3b1.js} +95 -95
  25. package/dist/paper-checkbox-645e1077.js +200 -0
  26. package/dist/{paper-icon-button-b1d31571.js → paper-icon-button-984162bd.js} +1 -1
  27. package/dist/{paper-checkbox-515a5284.js → paper-inky-focus-behavior-fa16796b.js} +58 -247
  28. package/dist/{paper-listbox-a3b7175c.js → paper-listbox-5f5d1cec.js} +152 -162
  29. package/dist/pb-code-editor.js +25 -20
  30. package/dist/pb-component-docs.js +68 -64
  31. package/dist/pb-components-bundle.js +1983 -2293
  32. package/dist/pb-edit-app.js +167 -107
  33. package/dist/pb-elements.json +176 -120
  34. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  35. package/dist/pb-leaflet-map.js +23 -23
  36. package/dist/pb-mei.js +56 -41
  37. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  38. package/dist/pb-odd-editor.js +1023 -782
  39. package/dist/pb-tify.js +2 -2
  40. package/dist/vaadin-element-mixin-beb74ffd.js +545 -0
  41. package/gh-pages.js +5 -3
  42. package/i18n/common/en.json +6 -0
  43. package/i18n/common/pl.json +2 -2
  44. package/lib/openseadragon.min.js +6 -6
  45. package/package.json +3 -3
  46. package/pb-elements.json +176 -120
  47. package/src/assets/components.css +5 -5
  48. package/src/authority/airtable.js +20 -21
  49. package/src/authority/anton.js +129 -129
  50. package/src/authority/custom.js +23 -21
  51. package/src/authority/geonames.js +38 -32
  52. package/src/authority/gnd.js +50 -42
  53. package/src/authority/kbga.js +137 -134
  54. package/src/authority/metagrid.js +44 -46
  55. package/src/authority/reconciliation.js +66 -67
  56. package/src/authority/registry.js +4 -4
  57. package/src/docs/pb-component-docs.js +2 -2
  58. package/src/docs/pb-component-view.js +5 -5
  59. package/src/docs/pb-components-list.js +2 -2
  60. package/src/docs/pb-demo-snippet.js +2 -2
  61. package/src/dts-client.js +299 -297
  62. package/src/dts-select-endpoint.js +90 -82
  63. package/src/parse-date-service.js +184 -135
  64. package/src/pb-ajax.js +158 -171
  65. package/src/pb-authority-lookup.js +191 -156
  66. package/src/pb-autocomplete.js +292 -280
  67. package/src/pb-blacklab-highlight.js +264 -259
  68. package/src/pb-blacklab-results.js +236 -221
  69. package/src/pb-browse-docs.js +540 -475
  70. package/src/pb-browse.js +68 -65
  71. package/src/pb-clipboard.js +79 -76
  72. package/src/pb-code-editor.js +110 -102
  73. package/src/pb-code-highlight.js +209 -204
  74. package/src/pb-codepen.js +79 -72
  75. package/src/pb-collapse.js +211 -151
  76. package/src/pb-combo-box.js +190 -190
  77. package/src/pb-components-bundle.js +1 -1
  78. package/src/pb-components.js +1 -0
  79. package/src/pb-custom-form.js +173 -153
  80. package/src/pb-dialog.js +98 -62
  81. package/src/pb-document.js +89 -90
  82. package/src/pb-download.js +212 -196
  83. package/src/pb-drawer.js +145 -148
  84. package/src/pb-edit-app.js +301 -229
  85. package/src/pb-edit-xml.js +100 -97
  86. package/src/pb-events.js +114 -107
  87. package/src/pb-facs-link.js +104 -102
  88. package/src/pb-facsimile.js +474 -410
  89. package/src/pb-formula.js +151 -153
  90. package/src/pb-geolocation.js +129 -131
  91. package/src/pb-grid-action.js +53 -56
  92. package/src/pb-grid.js +231 -228
  93. package/src/pb-highlight.js +140 -140
  94. package/src/pb-hotkeys.js +40 -42
  95. package/src/pb-i18n.js +101 -104
  96. package/src/pb-image-strip.js +84 -78
  97. package/src/pb-lang.js +142 -57
  98. package/src/pb-leaflet-map.js +488 -485
  99. package/src/pb-link.js +126 -124
  100. package/src/pb-load.js +431 -429
  101. package/src/pb-login.js +299 -244
  102. package/src/pb-manage-odds.js +352 -336
  103. package/src/pb-map-icon.js +89 -89
  104. package/src/pb-map-layer.js +85 -85
  105. package/src/pb-markdown.js +90 -99
  106. package/src/pb-media-query.js +74 -72
  107. package/src/pb-mei.js +306 -295
  108. package/src/pb-message.js +139 -97
  109. package/src/pb-mixin.js +269 -264
  110. package/src/pb-navigation.js +80 -95
  111. package/src/pb-observable.js +38 -38
  112. package/src/pb-odd-editor.js +1054 -958
  113. package/src/pb-odd-elementspec-editor.js +349 -298
  114. package/src/pb-odd-model-editor.js +1075 -909
  115. package/src/pb-odd-parameter-editor.js +200 -178
  116. package/src/pb-odd-rendition-editor.js +136 -124
  117. package/src/pb-page.js +431 -422
  118. package/src/pb-paginate.js +228 -179
  119. package/src/pb-panel.js +198 -182
  120. package/src/pb-popover-themes.js +15 -8
  121. package/src/pb-popover.js +296 -287
  122. package/src/pb-print-preview.js +127 -127
  123. package/src/pb-progress.js +51 -51
  124. package/src/pb-repeat.js +105 -104
  125. package/src/pb-restricted.js +84 -77
  126. package/src/pb-search.js +256 -228
  127. package/src/pb-select-feature.js +127 -120
  128. package/src/pb-select-odd.js +132 -124
  129. package/src/pb-select-template.js +89 -78
  130. package/src/pb-select.js +251 -227
  131. package/src/pb-split-list.js +179 -174
  132. package/src/pb-svg.js +80 -79
  133. package/src/pb-table-column.js +54 -54
  134. package/src/pb-table-grid.js +221 -203
  135. package/src/pb-tabs.js +61 -63
  136. package/src/pb-tify.js +154 -154
  137. package/src/pb-timeline.js +382 -249
  138. package/src/pb-toggle-feature.js +195 -187
  139. package/src/pb-upload.js +184 -174
  140. package/src/pb-version.js +30 -30
  141. package/src/pb-view-annotate.js +135 -98
  142. package/src/pb-view.js +1282 -1270
  143. package/src/pb-zoom.js +127 -45
  144. package/src/polymer-hack.js +1 -1
  145. package/src/search-result-service.js +256 -223
  146. package/src/seed-element.js +13 -20
  147. package/src/settings.js +4 -4
  148. package/src/theming.js +98 -91
  149. package/src/urls.js +289 -289
  150. package/src/utils.js +53 -51
  151. package/css/pb-styles.css +0 -51
  152. package/dist/vaadin-element-mixin-6e4cee3a.js +0 -527
  153. package/src/assets/pb-styles.css +0 -51
  154. package/src/pb-light-dom.js +0 -40
package/src/urls.js CHANGED
@@ -1,337 +1,337 @@
1
- import { match, compile, pathToRegexp } from "path-to-regexp";
2
- import { PbEvents } from "./pb-events.js";
3
- import { getSubscribedChannels } from "./pb-mixin.js";
1
+ import { match, compile, pathToRegexp } from 'path-to-regexp';
2
+ import { PbEvents } from './pb-events.js';
3
+ import { getSubscribedChannels } from './pb-mixin.js';
4
4
 
5
5
  function log(...args) {
6
- args[0] = `%c<registry>%c ${args[0]}`;
7
- args.splice(1, 0, 'font-weight: bold; color: #99FF33;', 'color: inherit; font-weight: normal');
8
- console.log.apply(null, args);
6
+ args[0] = `%c<registry>%c ${args[0]}`;
7
+ args.splice(1, 0, 'font-weight: bold; color: #99FF33;', 'color: inherit; font-weight: normal');
8
+ console.log.apply(null, args);
9
9
  }
10
10
 
11
11
  /**
12
12
  * Central class for tracking state. We distinguish between
13
- *
13
+ *
14
14
  * 1. the initial state of the application as determined by the URL opened in the browser
15
15
  * 2. state changes in components occurring while the user interacts with the page
16
- *
17
- * 1) is relevant if a user accesses a particular URL by following a link, entering an address into the location bar or
16
+ *
17
+ * 1) is relevant if a user accesses a particular URL by following a link, entering an address into the location bar or
18
18
  * opening a bookmark. In this case the components on the page will be in a fresh, empty state. However, they may react
19
- * to URL parameters and initiate specific properties of their state accordingly. Users expect that navigating to a given URL will
19
+ * to URL parameters and initiate specific properties of their state accordingly. Users expect that navigating to a given URL will
20
20
  * consistently result in the same display (i.e. restore a certain state). If users bookmark a specific page of a document shown in
21
- * TEI Publisher's pb-view, they expect that the same page is displayed when they open the bookmark again. Thus the document path and
21
+ * TEI Publisher's pb-view, they expect that the same page is displayed when they open the bookmark again. Thus the document path and
22
22
  * the page need to be tracked in the URL.
23
- *
23
+ *
24
24
  * 2) applies while the user interacts with the application, i.e. triggers actions, which cause components to change state. Some
25
25
  * actions may lead to a new page load, but many – like navigating pages in a `pb-view` – will only change the state of one or more components.
26
- * From a user's point of view this should be irrelevant: moving back or forward in browser history should consistently restore the
26
+ * From a user's point of view this should be irrelevant: moving back or forward in browser history should consistently restore the
27
27
  * previous or following state.
28
- *
28
+ *
29
29
  * Components should thus comply with the following guidelines:
30
- *
30
+ *
31
31
  * - if the component initializes itself, it should retrieve needed parameters from `registry.state`
32
32
  * - it may call `registry.replace` to make sure that all parameters required to later restore its initial state are present in the current URL
33
33
  * - it should register a listener with `registry.subscribe` to be informed when the user moves back in history (without reloading the page)
34
34
  * - it must call `registry.commit` after changing its current state
35
35
  */
36
36
  class Registry {
37
-
38
- constructor() {
39
- this.rootPath = '';
40
- /**
41
- * Is the resource path part of the URL path or is it
42
- * passed in a query parameter?
43
- */
44
- this.usePath = false;
45
- /**
46
- * Records current state as determined from parsing the URL.
47
- * This should be used to initialize components.
48
- */
49
- this.state = {};
50
- /**
51
- * Used to record state for a given channel. Will be updated
52
- * if a component calls commit or replace.
53
- */
54
- this.channelStates = {};
55
- /**
56
- * Records the hash part of the URL, if any
57
- */
58
- this.hash = null;
59
- /**
60
- * Should a hash in the URL be interpreted as an xml:id for loading the content?
61
- */
62
- this.idHash = true;
63
- this._listeners = [];
64
-
65
- /**
66
- * URL pattern to use for mapping parameters into the URL path
67
- */
68
- this.urlPattern = null;
69
-
70
- this.urlIgnore = new Set();
71
- this.pathParams = new Set();
72
-
73
- /**
74
- * Information about the user currently logged in or null. If a user is logged in
75
- * this will be an object with two properties: `user` and `groups`.
76
- */
77
- this.currentUser = null;
37
+ constructor() {
38
+ this.rootPath = '';
39
+ /**
40
+ * Is the resource path part of the URL path or is it
41
+ * passed in a query parameter?
42
+ */
43
+ this.usePath = false;
44
+ /**
45
+ * Records current state as determined from parsing the URL.
46
+ * This should be used to initialize components.
47
+ */
48
+ this.state = {};
49
+ /**
50
+ * Used to record state for a given channel. Will be updated
51
+ * if a component calls commit or replace.
52
+ */
53
+ this.channelStates = {};
54
+ /**
55
+ * Records the hash part of the URL, if any
56
+ */
57
+ this.hash = null;
58
+ /**
59
+ * Should a hash in the URL be interpreted as an xml:id for loading the content?
60
+ */
61
+ this.idHash = true;
62
+ this._listeners = [];
63
+
64
+ /**
65
+ * URL pattern to use for mapping parameters into the URL path
66
+ */
67
+ this.urlPattern = null;
68
+
69
+ this.urlIgnore = new Set();
70
+ this.pathParams = new Set();
71
+
72
+ /**
73
+ * Information about the user currently logged in or null. If a user is logged in
74
+ * this will be an object with two properties: `user` and `groups`.
75
+ */
76
+ this.currentUser = null;
77
+ }
78
+
79
+ configure(usePath = true, idHash = false, rootPath = '', urlPattern, ignoredParams) {
80
+ this.rootPath = rootPath;
81
+ this.usePath = usePath;
82
+ this.idHash = idHash;
83
+ this.urlPattern = urlPattern;
84
+ if (ignoredParams) {
85
+ ignoredParams.split(/\s*,\s*/).forEach(param => this.urlIgnore.add(param));
78
86
  }
79
87
 
80
- configure(usePath = true, idHash = false, rootPath = '', urlPattern, ignoredParams) {
81
- this.rootPath = rootPath;
82
- this.usePath = usePath;
83
- this.idHash = idHash;
84
- this.urlPattern = urlPattern;
85
- if (ignoredParams) {
86
- ignoredParams.split(/\s*,\s*/).forEach(param => this.urlIgnore.add(param));
87
- }
88
-
89
- if (this.urlPattern) {
90
- // save a list of parameter names which go into the path
91
- const pathParams = [];
92
- pathToRegexp(this.urlPattern, pathParams);
93
- pathParams.forEach((param) => this.pathParams.add(param.name));
94
- // compile URL pattern into a decode and encode function
95
- this._decodePath = match(this.urlPattern);
96
- this._encodePath = compile(this.urlPattern);
97
- }
98
-
99
- // determine initial state of the registry by parsing current URL
100
- const initialState = this._stateFromURL();
101
- if (!initialState) {
102
- console.error('<registry> failed to parse URL: %s using template %s', window.location, this.urlTemplate);
103
- } else {
104
- this.state = initialState;
105
- }
106
- window.history.replaceState(null, '');
107
-
108
- window.addEventListener('popstate', (ev) => {
109
- if (!ev.state) {
110
- // only react to history entries triggered by components
111
- return;
112
- }
113
-
114
- try {
115
- this.channelStates = JSON.parse(ev.state);
116
- } catch (e) {
117
- console.error('<registry> error restoring state: %s', e.toString());
118
- return;
119
- }
120
-
121
- this.state = this._stateFromURL();
122
- log('popstate: %o', this.channelStates);
123
-
124
- this._listeners.forEach((entry) => {
125
- entry.callback(this.getState(entry.component));
126
- });
127
-
128
- PbEvents.emit('pb-popstate', null, this.channelStates);
129
- });
88
+ if (this.urlPattern) {
89
+ // save a list of parameter names which go into the path
90
+ const pathParams = [];
91
+ pathToRegexp(this.urlPattern, pathParams);
92
+ pathParams.forEach(param => this.pathParams.add(param.name));
93
+ // compile URL pattern into a decode and encode function
94
+ this._decodePath = match(this.urlPattern);
95
+ this._encodePath = compile(this.urlPattern);
130
96
  }
131
97
 
132
- subscribe(component, callback) {
133
- this._listeners.push({
134
- component,
135
- callback
136
- });
98
+ // determine initial state of the registry by parsing current URL
99
+ const initialState = this._stateFromURL();
100
+ if (!initialState) {
101
+ console.error(
102
+ '<registry> failed to parse URL: %s using template %s',
103
+ window.location,
104
+ this.urlTemplate,
105
+ );
106
+ } else {
107
+ this.state = initialState;
137
108
  }
138
-
139
- _stateFromURL() {
140
- const params = {};
141
- this.hash = window.location.hash;
142
- // use the hash as an xml:id?
143
- // hashs of the form #1.2.3.4 are internal eXist ids though and thus excluded
144
- if (this.idHash && this.hash.length > 0 && (!/^#\d+\./.test(this.hash))) {
145
- params.id = this.hash.substring(1);
146
- }
147
- const relpath = window.location.pathname.replace(new RegExp(`^${this.rootPath}/?`), '');
148
- if (this.urlPattern) {
149
- const result = this._decodePath(relpath);
150
- Object.assign(params, result.params);
151
- log('decoded path %s using template %s: %o', relpath, this.urlPattern, params);
152
- } else if (this.usePath) {
153
- params.path = relpath;
154
- }
155
-
156
- const urlParams = new URLSearchParams(window.location.search);
157
- urlParams.forEach((value, key) => {
158
- if (
159
- (this.urlPattern && this.pathParams.has(key)) ||
160
- (this.usePath && key === 'path')
161
- ) {
162
- console.warn("Found path parameter in query, but usePath is set to true. The path parameter will be ignored.");
163
- return;
164
- }
165
- // parameter already set
166
- if ((key in params)) {
167
- return;
168
- }
169
- // check for multiple entries
170
- const allValues = urlParams.getAll(key);
171
- if (allValues.length === 1) {
172
- params[key] = value; // single entry
173
- } else {
174
- params[key] = allValues; // array
175
- }
176
- });
177
- return params;
109
+ window.history.replaceState(null, '');
110
+
111
+ window.addEventListener('popstate', ev => {
112
+ if (!ev.state) {
113
+ // only react to history entries triggered by components
114
+ return;
115
+ }
116
+
117
+ try {
118
+ this.channelStates = JSON.parse(ev.state);
119
+ } catch (e) {
120
+ console.error('<registry> error restoring state: %s', e.toString());
121
+ return;
122
+ }
123
+
124
+ this.state = this._stateFromURL();
125
+ log('popstate: %o', this.channelStates);
126
+
127
+ this._listeners.forEach(entry => {
128
+ entry.callback(this.getState(entry.component));
129
+ });
130
+
131
+ PbEvents.emit('pb-popstate', null, this.channelStates);
132
+ });
133
+ }
134
+
135
+ subscribe(component, callback) {
136
+ this._listeners.push({
137
+ component,
138
+ callback,
139
+ });
140
+ }
141
+
142
+ _stateFromURL() {
143
+ const params = {};
144
+ this.hash = window.location.hash;
145
+ // use the hash as an xml:id?
146
+ // hashs of the form #1.2.3.4 are internal eXist ids though and thus excluded
147
+ if (this.idHash && this.hash.length > 0 && !/^#\d+\./.test(this.hash)) {
148
+ params.id = this.hash.substring(1);
178
149
  }
179
-
180
- getState(component) {
181
- const channel = getSubscribedChannels(component)[0];
182
- const state = this.channelStates[channel];
183
- if (state) {
184
- return state;
185
- }
186
- this.channelStates[channel] = {};
187
- return this.channelStates[channel];
150
+ const relpath = window.location.pathname.replace(new RegExp(`^${this.rootPath}/?`), '');
151
+ if (this.urlPattern) {
152
+ const result = this._decodePath(relpath);
153
+ Object.assign(params, result.params);
154
+ log('decoded path %s using template %s: %o', relpath, this.urlPattern, params);
155
+ } else if (this.usePath) {
156
+ params.path = relpath;
188
157
  }
189
158
 
190
- setState(component, newState) {
191
- const channel = getSubscribedChannels(component)[0];
192
- this.channelStates[channel] = Object.assign(this.channelStates[channel], newState);
159
+ const urlParams = new URLSearchParams(window.location.search);
160
+ urlParams.forEach((value, key) => {
161
+ if ((this.urlPattern && this.pathParams.has(key)) || (this.usePath && key === 'path')) {
162
+ console.warn(
163
+ 'Found path parameter in query, but usePath is set to true. The path parameter will be ignored.',
164
+ );
165
+ return;
166
+ }
167
+ // parameter already set
168
+ if (key in params) {
169
+ return;
170
+ }
171
+ // check for multiple entries
172
+ const allValues = urlParams.getAll(key);
173
+ if (allValues.length === 1) {
174
+ params[key] = value; // single entry
175
+ } else {
176
+ params[key] = allValues; // array
177
+ }
178
+ });
179
+ return params;
180
+ }
181
+
182
+ getState(component) {
183
+ const channel = getSubscribedChannels(component)[0];
184
+ const state = this.channelStates[channel];
185
+ if (state) {
186
+ return state;
193
187
  }
194
-
195
- clearParametersMatching (component, regex) {
196
- const {state} = this
197
-
198
- for (const key of Object.keys(state)) {
199
- if (regex.test(key)) {
200
- state[key] = null
201
- }
202
- }
188
+ this.channelStates[channel] = {};
189
+ return this.channelStates[channel];
190
+ }
191
+
192
+ setState(component, newState) {
193
+ const channel = getSubscribedChannels(component)[0];
194
+ this.channelStates[channel] = Object.assign(this.channelStates[channel], newState);
195
+ }
196
+
197
+ clearParametersMatching(component, regex) {
198
+ const { state } = this;
199
+
200
+ for (const key of Object.keys(state)) {
201
+ if (regex.test(key)) {
202
+ state[key] = null;
203
+ }
203
204
  }
205
+ }
204
206
 
205
- get(path, defaultValue) {
206
- if (!this.state) {
207
- return undefined;
208
- }
209
- const value = path.split('.').reduce((state, component) => {
210
- if (!state[component]) {
211
- return undefined;
212
- }
213
- return state[component];
214
- }, this.state);
215
- return value || defaultValue;
207
+ get(path, defaultValue) {
208
+ if (!this.state) {
209
+ return undefined;
216
210
  }
217
-
218
- set(path, value) {
219
- if (!path.contains('.')) {
220
- this.state[path] = value;
221
- return;
222
- }
223
- const components = path.split('.');
224
- const lastPart = components.pop()
225
- // make sure all intermediate steps are available
226
- const lastIntermediate = components.reduce((result, nextComponent) => {
227
- if (!result[nextComponent]) {
228
- // eslint-disable-next-line no-param-reassign
229
- result[nextComponent] = {};
230
- }
231
- return result[nextComponent];
232
- },
233
- this.state
234
- );
235
- lastIntermediate[lastPart] = value;
211
+ const value = path.split('.').reduce((state, component) => {
212
+ if (!state[component]) {
213
+ return undefined;
214
+ }
215
+ return state[component];
216
+ }, this.state);
217
+ return value || defaultValue;
218
+ }
219
+
220
+ set(path, value) {
221
+ if (!path.contains('.')) {
222
+ this.state[path] = value;
223
+ return;
236
224
  }
237
-
238
- commit(elem, newState, overwrite = false) {
239
- this._commit(elem, newState, overwrite, false);
225
+ const components = path.split('.');
226
+ const lastPart = components.pop();
227
+ // make sure all intermediate steps are available
228
+ const lastIntermediate = components.reduce((result, nextComponent) => {
229
+ if (!result[nextComponent]) {
230
+ // eslint-disable-next-line no-param-reassign
231
+ result[nextComponent] = {};
232
+ }
233
+ return result[nextComponent];
234
+ }, this.state);
235
+ lastIntermediate[lastPart] = value;
236
+ }
237
+
238
+ commit(elem, newState, overwrite = false) {
239
+ this._commit(elem, newState, overwrite, false);
240
+ }
241
+
242
+ replace(elem, newState, overwrite = false) {
243
+ this._commit(elem, newState, overwrite, true);
244
+ }
245
+
246
+ _commit(elem, newState, overwrite, replace) {
247
+ this.state = overwrite ? newState : { ...this.state, ...newState };
248
+ const resolved = this.urlFromState();
249
+
250
+ const chs = getSubscribedChannels(elem);
251
+ chs.forEach(channel => {
252
+ if (overwrite || !this.channelStates[channel]) {
253
+ this.channelStates[channel] = newState;
254
+ } else {
255
+ Object.assign(this.channelStates[channel], newState);
256
+ }
257
+ });
258
+
259
+ const json = this.toJSON();
260
+ if (replace) {
261
+ window.history.replaceState(json, '', resolved);
262
+ log('replace %s: %o %d', resolved.toString(), this.channelStates, window.history.length);
263
+ } else {
264
+ window.history.pushState(json, '', resolved);
265
+ log('commit %s: %o %d', resolved.toString(), this.channelStates, window.history.length);
240
266
  }
241
-
242
- replace(elem, newState, overwrite = false) {
243
- this._commit(elem, newState, overwrite, true);
267
+ }
268
+
269
+ urlFromState() {
270
+ const newUrl = new URL(window.location.href);
271
+
272
+ function setParam(value, param) {
273
+ if (value === null) {
274
+ newUrl.searchParams.delete(param);
275
+ } else if (Array.isArray(value)) {
276
+ // copy array before mutating it
277
+ const _v = Array.from(value);
278
+ // overwrite any previous value by setting the first member
279
+ newUrl.searchParams.set(param, _v.pop());
280
+ // add additional values
281
+ _v.forEach(v => newUrl.searchParams.append(param, v));
282
+ } else {
283
+ newUrl.searchParams.set(param, value);
284
+ }
244
285
  }
245
286
 
246
- _commit(elem, newState, overwrite, replace) {
247
- this.state = overwrite ? newState : ({ ...this.state, ...newState});
248
- const resolved = this.urlFromState();
249
-
250
- const chs = getSubscribedChannels(elem);
251
- chs.forEach((channel) => {
252
- if (overwrite || !this.channelStates[channel]) {
253
- this.channelStates[channel] = newState;
254
- } else {
255
- Object.assign(this.channelStates[channel], newState);
256
- }
257
- });
258
-
259
- const json = this.toJSON();
260
- if (replace) {
261
- window.history.replaceState(json, '', resolved);
262
- log('replace %s: %o %d', resolved.toString(), this.channelStates, window.history.length);
263
- } else {
264
- window.history.pushState(json, '', resolved);
265
- log('commit %s: %o %d', resolved.toString(), this.channelStates, window.history.length);
287
+ for (const [param, value] of Object.entries(this.state)) {
288
+ if (this.urlPattern) {
289
+ // check if param should be ignored or is required by the URL template
290
+ // fill up missing parameters by stripping potential "user." prefix
291
+ const normParam = param.replace(/^(?:user\.)?(.*)$/, '$1');
292
+ if (!(this.pathParams.has(normParam) || this.urlIgnore.has(normParam))) {
293
+ setParam(value, normParam);
266
294
  }
295
+ } else if (
296
+ (param !== 'path' || !this.usePath) &&
297
+ (param !== 'id' || !this.idHash) &&
298
+ !this.urlIgnore.has(param)
299
+ ) {
300
+ setParam(value, param);
301
+ }
267
302
  }
268
303
 
269
- urlFromState() {
270
- const newUrl = new URL(window.location.href);
271
-
272
- function setParam(value, param) {
273
- if (value === null) {
274
- newUrl.searchParams.delete(param);
275
- } else if (Array.isArray(value)) {
276
- // copy array before mutating it
277
- const _v = Array.from(value);
278
- // overwrite any previous value by setting the first member
279
- newUrl.searchParams.set(param, _v.pop());
280
- // add additional values
281
- _v.forEach(v => newUrl.searchParams.append(param, v));
282
- } else {
283
- newUrl.searchParams.set(param, value);
284
- }
285
- }
286
-
287
- for (const [param, value] of Object.entries(this.state)) {
288
- if (this.urlPattern) {
289
- // check if param should be ignored or is required by the URL template
290
- // fill up missing parameters by stripping potential "user." prefix
291
- const normParam = param.replace(/^(?:user\.)?(.*)$/, '$1');
292
- if (!(this.pathParams.has(normParam) || this.urlIgnore.has(normParam))) {
293
- setParam(value, normParam);
294
- }
295
- } else if (
296
- (param !== 'path' || !this.usePath) &&
297
- (param !== 'id' || !this.idHash) &&
298
- (!this.urlIgnore.has(param))
299
- ) {
300
- setParam(value, param);
301
- }
304
+ if (this.state.path && this.state.path.length > 0) {
305
+ if (this.urlPattern) {
306
+ // path parameters should not be the empty string
307
+ const normState = {};
308
+ for (const [key, value] of Object.entries(this.state)) {
309
+ if (this.pathParams.has(key) && value === '') {
310
+ normState[key] = null;
311
+ } else {
312
+ normState[key] = value;
313
+ }
302
314
  }
303
-
304
- if (this.state.path && this.state.path.length > 0) {
305
- if (this.urlPattern) {
306
- // path parameters should not be the empty string
307
- const normState = {};
308
- for (const [key, value] of Object.entries(this.state)) {
309
- if (this.pathParams.has(key) && value === '') {
310
- normState[key] = null;
311
- } else {
312
- normState[key] = value;
313
- }
314
- }
315
- const encoded = this._encodePath(normState);
316
- newUrl.pathname = `${this.rootPath}/${encoded}`;
317
- } else if (this.usePath) {
318
- newUrl.pathname = `${this.rootPath}/${this.state.path}`;
319
- }
320
- }
321
-
322
- if (this.state.id && !this.urlPattern) {
323
- newUrl.hash = `#${this.state.id}`;
324
- }
325
-
326
- return newUrl;
315
+ const encoded = this._encodePath(normState);
316
+ newUrl.pathname = `${this.rootPath}/${encoded}`;
317
+ } else if (this.usePath) {
318
+ newUrl.pathname = `${this.rootPath}/${this.state.path}`;
319
+ }
327
320
  }
328
321
 
329
- toJSON() {
330
- return JSON.stringify(this.channelStates);
322
+ if (this.state.id && !this.urlPattern) {
323
+ newUrl.hash = `#${this.state.id}`;
331
324
  }
325
+
326
+ return newUrl;
327
+ }
328
+
329
+ toJSON() {
330
+ return JSON.stringify(this.channelStates);
331
+ }
332
332
  }
333
333
 
334
334
  export const registry = new Registry();
335
335
  if (!window.pbRegistry) {
336
- window.pbRegistry = registry;
337
- }
336
+ window.pbRegistry = registry;
337
+ }