@teipublisher/pb-components 2.26.1-next.3 → 3.0.0-next-4.2

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 (262) hide show
  1. package/.github/workflows/docker-cypress.yml +53 -0
  2. package/.github/workflows/node.js.yml +70 -21
  3. package/.releaserc.json +7 -2
  4. package/CHANGELOG.md +363 -11
  5. package/Dockerfile +78 -70
  6. package/README.md +112 -4
  7. package/css/components.css +5 -5
  8. package/css/gridjs/mermaid.min.css +1 -1
  9. package/css/leaflet/Control.Geocoder.css +1 -126
  10. package/css/leaflet/images/layers.png +0 -0
  11. package/css/tify/tify.css +6 -5
  12. package/css/tom-select/tom-select.bootstrap4.min.css +1 -1
  13. package/css/tom-select/tom-select.bootstrap5.min.css +1 -1
  14. package/css/tom-select/tom-select.default.min.css +1 -1
  15. package/css/tom-select/tom-select.default.min.css.map +1 -0
  16. package/css/tom-select/tom-select.min.css +1 -1
  17. package/cypress.config.js +84 -0
  18. package/dist/api.html +1 -1
  19. package/dist/css/design-system.css +607 -0
  20. package/dist/demo/bundle-test.html +4 -3
  21. package/dist/demo/components.css +46 -1
  22. package/dist/demo/design-system.html +710 -0
  23. package/dist/demo/dts-client.html +2 -2
  24. package/dist/demo/pb-autocomplete.html +23 -11
  25. package/dist/demo/pb-autocomplete2.html +66 -55
  26. package/dist/demo/pb-autocomplete3.html +17 -8
  27. package/dist/demo/pb-blacklab-highlight.html +28 -11
  28. package/dist/demo/pb-blacklab-results.html +3 -2
  29. package/dist/demo/pb-browse-docs.html +24 -24
  30. package/dist/demo/pb-browse-docs2.html +3 -3
  31. package/dist/demo/pb-clipboard.html +32 -28
  32. package/dist/demo/pb-code-editor.html +6 -6
  33. package/dist/demo/pb-code-highlight.html +63 -63
  34. package/dist/demo/pb-codepen.html +1 -1
  35. package/dist/demo/pb-collapse.html +1 -1
  36. package/dist/demo/pb-collapse2.html +2 -2
  37. package/dist/demo/pb-combo-box.html +135 -130
  38. package/dist/demo/pb-custom-form.html +64 -55
  39. package/dist/demo/pb-dialog.html +12 -6
  40. package/dist/demo/pb-document.html +1 -1
  41. package/dist/demo/pb-download.html +68 -59
  42. package/dist/demo/pb-drawer.html +67 -46
  43. package/dist/demo/pb-drawer2.html +65 -58
  44. package/dist/demo/pb-edit-app.html +2 -2
  45. package/dist/demo/pb-edit-xml.html +1 -1
  46. package/dist/demo/pb-facsimile-2.html +26 -11
  47. package/dist/demo/pb-facsimile-3.html +25 -10
  48. package/dist/demo/pb-facsimile-dedup-test-2.html +48 -0
  49. package/dist/demo/pb-facsimile-dedup-test.html +48 -0
  50. package/dist/demo/pb-facsimile.html +4 -4
  51. package/dist/demo/pb-formula.html +1 -1
  52. package/dist/demo/pb-grid.html +22 -8
  53. package/dist/demo/pb-highlight.html +2 -2
  54. package/dist/demo/pb-i18n-simple.html +1 -0
  55. package/dist/demo/pb-i18n.html +15 -5
  56. package/dist/demo/pb-image-strip-standalone.html +2 -2
  57. package/dist/demo/pb-image-strip-view.html +2 -2
  58. package/dist/demo/pb-leaflet-map.html +3 -3
  59. package/dist/demo/pb-leaflet-map2.html +2 -2
  60. package/dist/demo/pb-leaflet-map3.html +3 -3
  61. package/dist/demo/pb-link.html +1 -1
  62. package/dist/demo/pb-load.html +2 -6
  63. package/dist/demo/pb-login.html +1 -3
  64. package/dist/demo/pb-manage-odds.html +9 -4
  65. package/dist/demo/pb-markdown.html +1 -1
  66. package/dist/demo/pb-media-query.html +2 -2
  67. package/dist/demo/pb-mei.html +2 -2
  68. package/dist/demo/pb-mei2.html +2 -2
  69. package/dist/demo/pb-message.html +2 -3
  70. package/dist/demo/pb-odd-editor.html +54 -52
  71. package/dist/demo/pb-page-header.html +27 -0
  72. package/dist/demo/pb-popover.html +1 -1
  73. package/dist/demo/pb-print-preview.html +2 -2
  74. package/dist/demo/pb-progress.html +4 -4
  75. package/dist/demo/pb-repeat.html +32 -36
  76. package/dist/demo/pb-search.html +16 -5
  77. package/dist/demo/pb-search2.html +4 -4
  78. package/dist/demo/pb-search3.html +3 -3
  79. package/dist/demo/pb-search4.html +3 -3
  80. package/dist/demo/pb-select-feature.html +4 -4
  81. package/dist/demo/pb-select-feature2.html +4 -4
  82. package/dist/demo/pb-select-feature3.html +2 -2
  83. package/dist/demo/pb-select-i18n.html +58 -53
  84. package/dist/demo/pb-select-odd.html +1 -1
  85. package/dist/demo/pb-select.html +190 -75
  86. package/dist/demo/pb-select2.html +91 -37
  87. package/dist/demo/pb-select3.html +109 -41
  88. package/dist/demo/pb-svg.html +1 -1
  89. package/dist/demo/pb-table-grid.html +26 -15
  90. package/dist/demo/pb-tabs.html +15 -7
  91. package/dist/demo/pb-tify.html +7 -7
  92. package/dist/demo/pb-timeline.html +1 -1
  93. package/dist/demo/pb-timeline2.html +1 -1
  94. package/dist/demo/pb-toggle-feature.html +26 -23
  95. package/dist/demo/pb-toggle-feature2.html +4 -4
  96. package/dist/demo/pb-toggle-feature3.html +2 -2
  97. package/dist/demo/pb-toggle-feature4.html +56 -54
  98. package/dist/demo/pb-version.html +2 -2
  99. package/dist/demo/pb-view.html +78 -40
  100. package/dist/demo/pb-view2.html +69 -46
  101. package/dist/demo/pb-view3.html +53 -48
  102. package/dist/demo/pb-view4.html +70 -49
  103. package/dist/demo/pb-zoom.html +2 -2
  104. package/dist/{es-global-bridge-d8ce175d.js → es-global-bridge-D8ZcUcx_.js} +0 -4
  105. package/dist/focus-mixin-VCsFap6b.js +768 -0
  106. package/dist/images/icons.svg +217 -0
  107. package/dist/jinn-codemirror-DETLdm08.js +1 -0
  108. package/dist/lib/openseadragon.min.js +80 -0
  109. package/dist/lib/openseadragon.min.js.map +1 -0
  110. package/dist/pb-code-editor.js +25 -20
  111. package/dist/pb-component-docs.js +414 -3225
  112. package/dist/pb-components-bundle.js +3046 -4402
  113. package/dist/pb-dialog-tklYGWfc.js +121 -0
  114. package/dist/pb-edit-app.js +208 -107
  115. package/dist/pb-elements.json +716 -249
  116. package/dist/pb-facsimile.js +46 -0
  117. package/dist/pb-i18n-C0NDma4h.js +1 -0
  118. package/dist/pb-leaflet-map.js +23 -23
  119. package/dist/pb-mei.js +152 -134
  120. package/dist/pb-mixin-DHoWQheB.js +1 -0
  121. package/dist/pb-odd-editor.js +1671 -1231
  122. package/dist/pb-tify.js +1 -27
  123. package/dist/unsafe-html-D5VGo9Oq.js +1 -0
  124. package/dist/urls-BEONu_g4.js +1 -0
  125. package/eslint.config.mjs +92 -0
  126. package/gh-pages.js +5 -3
  127. package/i18n/common/en.json +6 -0
  128. package/i18n/common/pl.json +2 -2
  129. package/images/icons.svg +217 -0
  130. package/index.html +0 -5
  131. package/lib/leaflet-src.js.map +1 -0
  132. package/lib/leaflet.markercluster-src.js.map +1 -0
  133. package/lib/openseadragon.min.js +6 -6
  134. package/package.json +56 -81
  135. package/pb-elements.json +716 -249
  136. package/rollup.config.mjs +312 -0
  137. package/src/assets/components.css +5 -5
  138. package/src/assets/design-system.css +607 -0
  139. package/src/authority/airtable.js +20 -21
  140. package/src/authority/anton.js +129 -129
  141. package/src/authority/custom.js +70 -27
  142. package/src/authority/geonames.js +38 -32
  143. package/src/authority/gnd.js +50 -42
  144. package/src/authority/kbga.js +136 -134
  145. package/src/authority/metagrid.js +44 -46
  146. package/src/authority/reconciliation.js +66 -68
  147. package/src/authority/registry.js +4 -4
  148. package/src/docs/demo-utils.js +91 -0
  149. package/src/docs/pb-component-docs.js +287 -147
  150. package/src/docs/pb-component-view.js +380 -273
  151. package/src/docs/pb-components-list.js +115 -51
  152. package/src/docs/pb-demo-snippet.js +199 -174
  153. package/src/dts-client.js +306 -303
  154. package/src/dts-select-endpoint.js +125 -85
  155. package/src/parse-date-service.js +184 -135
  156. package/src/pb-ajax.js +175 -173
  157. package/src/pb-authority-lookup.js +198 -158
  158. package/src/pb-autocomplete.js +731 -313
  159. package/src/pb-blacklab-highlight.js +266 -260
  160. package/src/pb-blacklab-results.js +230 -225
  161. package/src/pb-browse-docs.js +601 -484
  162. package/src/pb-browse.js +68 -65
  163. package/src/pb-clipboard.js +97 -76
  164. package/src/pb-code-editor.js +111 -103
  165. package/src/pb-code-highlight.js +234 -204
  166. package/src/pb-codepen.js +81 -73
  167. package/src/pb-collapse.js +265 -152
  168. package/src/pb-combo-box.js +191 -191
  169. package/src/pb-components-bundle.js +1 -7
  170. package/src/pb-components.js +2 -6
  171. package/src/pb-custom-form.js +230 -141
  172. package/src/pb-dialog.js +99 -63
  173. package/src/pb-document.js +118 -91
  174. package/src/pb-download.js +214 -198
  175. package/src/pb-drawer.js +146 -149
  176. package/src/pb-edit-app.js +471 -240
  177. package/src/pb-edit-xml.js +101 -98
  178. package/src/pb-events.js +126 -107
  179. package/src/pb-facs-link.js +130 -101
  180. package/src/pb-facsimile.js +494 -410
  181. package/src/pb-fetch.js +389 -0
  182. package/src/pb-formula.js +152 -154
  183. package/src/pb-geolocation.js +130 -132
  184. package/src/pb-grid-action.js +59 -56
  185. package/src/pb-grid.js +388 -228
  186. package/src/pb-highlight.js +142 -142
  187. package/src/pb-hotkeys.js +40 -42
  188. package/src/pb-i18n.js +115 -127
  189. package/src/pb-icon-button.js +108 -0
  190. package/src/pb-icon.js +283 -0
  191. package/src/pb-image-strip.js +85 -79
  192. package/src/pb-lang.js +142 -57
  193. package/src/pb-leaflet-map.js +551 -483
  194. package/src/pb-link.js +132 -126
  195. package/src/pb-load.js +495 -428
  196. package/src/pb-login.js +303 -248
  197. package/src/pb-manage-odds.js +384 -338
  198. package/src/pb-map-icon.js +90 -90
  199. package/src/pb-map-layer.js +86 -86
  200. package/src/pb-markdown.js +107 -110
  201. package/src/pb-media-query.js +75 -73
  202. package/src/pb-mei.js +523 -303
  203. package/src/pb-message.js +144 -98
  204. package/src/pb-mixin.js +268 -265
  205. package/src/pb-navigation.js +83 -96
  206. package/src/pb-observable.js +39 -39
  207. package/src/pb-odd-editor.js +1209 -948
  208. package/src/pb-odd-elementspec-editor.js +375 -310
  209. package/src/pb-odd-model-editor.js +1189 -941
  210. package/src/pb-odd-parameter-editor.js +269 -170
  211. package/src/pb-odd-rendition-editor.js +184 -131
  212. package/src/pb-page.js +451 -422
  213. package/src/pb-paginate.js +260 -178
  214. package/src/pb-panel.js +217 -183
  215. package/src/pb-popover-themes.js +16 -9
  216. package/src/pb-popover.js +297 -288
  217. package/src/pb-print-preview.js +128 -128
  218. package/src/pb-progress.js +52 -52
  219. package/src/pb-repeat.js +141 -108
  220. package/src/pb-restricted.js +85 -78
  221. package/src/pb-search.js +258 -230
  222. package/src/pb-select-feature.js +210 -126
  223. package/src/pb-select-odd.js +184 -118
  224. package/src/pb-select-template.js +113 -78
  225. package/src/pb-select.js +330 -229
  226. package/src/pb-split-list.js +181 -176
  227. package/src/pb-svg.js +81 -80
  228. package/src/pb-table-column.js +55 -55
  229. package/src/pb-table-grid.js +334 -205
  230. package/src/pb-tabs.js +238 -61
  231. package/src/pb-tify.js +3331 -126
  232. package/src/pb-timeline.js +394 -255
  233. package/src/pb-toggle-feature.js +196 -188
  234. package/src/pb-upload.js +201 -176
  235. package/src/pb-version.js +22 -34
  236. package/src/pb-view-annotate.js +138 -102
  237. package/src/pb-view.js +1722 -1272
  238. package/src/pb-zoom.js +144 -46
  239. package/src/search-result-service.js +256 -223
  240. package/src/seed-element.js +14 -22
  241. package/src/settings.js +4 -4
  242. package/src/theming.js +98 -91
  243. package/src/urls.js +403 -289
  244. package/src/utils.js +53 -51
  245. package/vite.config.js +86 -0
  246. package/.github/workflows/main.yml +0 -24
  247. package/.github/workflows/release.js.yml +0 -34
  248. package/css/pb-styles.css +0 -51
  249. package/dist/iron-form-3b8dcaa7.js +0 -210
  250. package/dist/jinn-codemirror-da0e2d1f.js +0 -1
  251. package/dist/paper-checkbox-515a5284.js +0 -1597
  252. package/dist/paper-icon-button-b1d31571.js +0 -398
  253. package/dist/paper-listbox-a3b7175c.js +0 -1265
  254. package/dist/pb-i18n-0611135a.js +0 -1
  255. package/dist/pb-mixin-b1caa22e.js +0 -158
  256. package/dist/polymer-hack.js +0 -1
  257. package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
  258. package/lib/Control.Geocoder.min.js +0 -2
  259. package/lib/Control.Geocoder.min.js.map +0 -1
  260. package/src/assets/pb-styles.css +0 -51
  261. package/src/pb-light-dom.js +0 -41
  262. package/src/polymer-hack.js +0 -6
package/src/urls.js CHANGED
@@ -1,337 +1,451 @@
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
+
5
+ /**
6
+ * Convert path-to-regexp v6 syntax to v8 syntax
7
+ * - :param? becomes {:param} (optional parameters with braces)
8
+ * - /* becomes /*path (named wildcards)
9
+ *
10
+ * This function is idempotent - it can be called multiple times safely
11
+ * and will not double-convert already converted patterns.
12
+ */
13
+ function convertPathToRegexpSyntax(pattern) {
14
+ if (!pattern) return pattern;
15
+
16
+ // Convert optional parameters :param? to {:param} for v8 compatibility
17
+ // Only convert if not already in v8 format (avoid double conversion)
18
+ let converted = pattern.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)\?/g, '{:$1}');
19
+
20
+ // Convert unnamed wildcards /* to /*path
21
+ // Only convert if not already named (avoid double conversion)
22
+ converted = converted.replace(/\*$/g, '*path');
23
+
24
+ return converted;
25
+ }
4
26
 
5
27
  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);
28
+ args[0] = `%c<registry>%c ${args[0]}`;
29
+ args.splice(1, 0, 'font-weight: bold; color: #99FF33;', 'color: inherit; font-weight: normal');
30
+ console.log.apply(null, args);
9
31
  }
10
32
 
11
33
  /**
12
34
  * Central class for tracking state. We distinguish between
13
- *
35
+ *
14
36
  * 1. the initial state of the application as determined by the URL opened in the browser
15
37
  * 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
38
+ *
39
+ * 1) is relevant if a user accesses a particular URL by following a link, entering an address into the location bar or
18
40
  * 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
41
+ * to URL parameters and initiate specific properties of their state accordingly. Users expect that navigating to a given URL will
20
42
  * 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
43
+ * 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
44
  * the page need to be tracked in the URL.
23
- *
45
+ *
24
46
  * 2) applies while the user interacts with the application, i.e. triggers actions, which cause components to change state. Some
25
47
  * 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
48
+ * From a user's point of view this should be irrelevant: moving back or forward in browser history should consistently restore the
27
49
  * previous or following state.
28
- *
50
+ *
29
51
  * Components should thus comply with the following guidelines:
30
- *
52
+ *
31
53
  * - if the component initializes itself, it should retrieve needed parameters from `registry.state`
32
54
  * - 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
55
  * - it should register a listener with `registry.subscribe` to be informed when the user moves back in history (without reloading the page)
34
56
  * - it must call `registry.commit` after changing its current state
35
57
  */
36
58
  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;
59
+ constructor() {
60
+ this.rootPath = '';
61
+ /**
62
+ * Is the resource path part of the URL path or is it
63
+ * passed in a query parameter?
64
+ */
65
+ this.usePath = false;
66
+ /**
67
+ * Records current state as determined from parsing the URL.
68
+ * This should be used to initialize components.
69
+ */
70
+ this.state = {};
71
+ /**
72
+ * Used to record state for a given channel. Will be updated
73
+ * if a component calls commit or replace.
74
+ */
75
+ this.channelStates = {};
76
+ /**
77
+ * Records the hash part of the URL, if any
78
+ */
79
+ this.hash = null;
80
+ /**
81
+ * Should a hash in the URL be interpreted as an xml:id for loading the content?
82
+ */
83
+ this.idHash = true;
84
+ this._listeners = [];
85
+
86
+ /**
87
+ * URL pattern to use for mapping parameters into the URL path
88
+ */
89
+ this.urlPattern = null;
90
+
91
+ this.urlIgnore = new Set();
92
+ this.pathParams = new Set();
93
+
94
+ /**
95
+ * Information about the user currently logged in or null. If a user is logged in
96
+ * this will be an object with two properties: `user` and `groups`.
97
+ */
98
+ this.currentUser = null;
99
+ }
100
+
101
+ configure(usePath = true, idHash = false, rootPath = '', urlPattern, ignoredParams) {
102
+ this.rootPath = rootPath;
103
+ this.usePath = usePath;
104
+ this.idHash = idHash;
105
+ this.urlPattern = urlPattern;
106
+ if (ignoredParams) {
107
+ ignoredParams.split(/\s*,\s*/).forEach(param => this.urlIgnore.add(param));
78
108
  }
79
109
 
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
- });
110
+ if (this.urlPattern) {
111
+ // Convert v6 syntax to v8 syntax
112
+ const convertedPattern = convertPathToRegexpSyntax(this.urlPattern);
113
+
114
+ // save a list of parameter names which go into the path
115
+ const pathParams = [];
116
+ pathToRegexp(convertedPattern, pathParams);
117
+ pathParams.forEach(param => this.pathParams.add(param.name));
118
+ // compile URL pattern into a decode and encode function
119
+ this._decodePath = match(convertedPattern);
120
+ this._encodePath = compile(convertedPattern);
130
121
  }
131
122
 
132
- subscribe(component, callback) {
133
- this._listeners.push({
134
- component,
135
- callback
136
- });
123
+ // determine initial state of the registry by parsing current URL
124
+ const initialState = this._stateFromURL();
125
+ if (!initialState) {
126
+ console.error(
127
+ '<registry> failed to parse URL: %s using template %s',
128
+ window.location,
129
+ this.urlTemplate,
130
+ );
131
+ } else {
132
+ this.state = initialState;
137
133
  }
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;
134
+ window.history.replaceState(null, '');
135
+
136
+ window.addEventListener('popstate', ev => {
137
+ if (!ev.state) {
138
+ // only react to history entries triggered by components
139
+ return;
140
+ }
141
+
142
+ try {
143
+ this.channelStates = JSON.parse(ev.state);
144
+ } catch (e) {
145
+ console.error('<registry> error restoring state: %s', e.toString());
146
+ return;
147
+ }
148
+
149
+ this.state = this._stateFromURL();
150
+ log('popstate: %o', this.channelStates);
151
+
152
+ this._listeners.forEach(entry => {
153
+ entry.callback(this.getState(entry.component));
154
+ });
155
+
156
+ PbEvents.emit('pb-popstate', null, this.channelStates);
157
+ });
158
+ }
159
+
160
+ subscribe(component, callback) {
161
+ this._listeners.push({
162
+ component,
163
+ callback,
164
+ });
165
+ }
166
+
167
+ _stateFromURL() {
168
+ const params = {};
169
+ this.hash = window.location.hash;
170
+ // use the hash as an xml:id?
171
+ // hashs of the form #1.2.3.4 are internal eXist ids though and thus excluded
172
+ if (this.idHash && this.hash.length > 0 && !/^#\d+\./.test(this.hash)) {
173
+ params.id = this.hash.substring(1);
178
174
  }
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];
175
+ const relpath = window.location.pathname.replace(new RegExp(`^${this.rootPath}/?`), '');
176
+ if (this.urlPattern) {
177
+ const result = this._decodePath(relpath);
178
+ Object.assign(params, result.params);
179
+ log('decoded path %s using template %s: %o', relpath, this.urlPattern, params);
180
+ } else if (this.usePath) {
181
+ params.path = relpath;
188
182
  }
189
183
 
190
- setState(component, newState) {
191
- const channel = getSubscribedChannels(component)[0];
192
- this.channelStates[channel] = Object.assign(this.channelStates[channel], newState);
184
+ const urlParams = new URLSearchParams(window.location.search);
185
+ urlParams.forEach((value, key) => {
186
+ if ((this.urlPattern && this.pathParams.has(key)) || (this.usePath && key === 'path')) {
187
+ console.warn(
188
+ 'Found path parameter in query, but usePath is set to true. The path parameter will be ignored.',
189
+ );
190
+ return;
191
+ }
192
+ // parameter already set
193
+ if (key in params) {
194
+ return;
195
+ }
196
+ // check for multiple entries
197
+ const allValues = urlParams.getAll(key);
198
+ if (allValues.length === 1) {
199
+ params[key] = value; // single entry
200
+ } else {
201
+ params[key] = allValues; // array
202
+ }
203
+ });
204
+ return params;
205
+ }
206
+
207
+ getState(component) {
208
+ const channel = getSubscribedChannels(component)[0];
209
+ const state = this.channelStates[channel];
210
+ if (state) {
211
+ return state;
193
212
  }
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
- }
213
+ this.channelStates[channel] = {};
214
+ return this.channelStates[channel];
215
+ }
216
+
217
+ setState(component, newState) {
218
+ const channel = getSubscribedChannels(component)[0];
219
+ this.channelStates[channel] = Object.assign(this.channelStates[channel], newState);
220
+ }
221
+
222
+ clearParametersMatching(component, regex) {
223
+ const { state } = this;
224
+
225
+ for (const key of Object.keys(state)) {
226
+ if (regex.test(key)) {
227
+ state[key] = null;
228
+ }
203
229
  }
230
+ }
204
231
 
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;
232
+ get(path, defaultValue) {
233
+ if (!this.state) {
234
+ return undefined;
216
235
  }
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;
236
+ const value = path.split('.').reduce((state, component) => {
237
+ if (!state[component]) {
238
+ return undefined;
239
+ }
240
+ return state[component];
241
+ }, this.state);
242
+ return value || defaultValue;
243
+ }
244
+
245
+ set(path, value) {
246
+ if (!path.includes('.')) {
247
+ this.state[path] = value;
248
+ return;
236
249
  }
237
-
238
- commit(elem, newState, overwrite = false) {
239
- this._commit(elem, newState, overwrite, false);
250
+ const components = path.split('.');
251
+ const lastPart = components.pop();
252
+ // make sure all intermediate steps are available
253
+ const lastIntermediate = components.reduce((result, nextComponent) => {
254
+ if (!result[nextComponent]) {
255
+ result[nextComponent] = {};
256
+ }
257
+ return result[nextComponent];
258
+ }, this.state);
259
+ lastIntermediate[lastPart] = value;
260
+ }
261
+
262
+ commit(elem, newState, overwrite = false) {
263
+ // Debug: Log what component is calling registry.commit (only for commits that might reset root)
264
+ if (newState && ('root' in newState) && newState.root === null) {
265
+ const componentName = elem?.tagName?.toLowerCase() || elem?.constructor?.name || 'unknown';
266
+ console.warn('[registry] commit called with root=null by:', componentName, {
267
+ newState,
268
+ overwrite,
269
+ stack: new Error().stack
270
+ });
240
271
  }
241
-
242
- replace(elem, newState, overwrite = false) {
243
- this._commit(elem, newState, overwrite, true);
272
+ this._commit(elem, newState, overwrite, false);
273
+ }
274
+
275
+ replace(elem, newState, overwrite = false) {
276
+ // Debug: Log what component is calling registry.replace
277
+ const componentName = elem?.tagName?.toLowerCase() || elem?.constructor?.name || 'unknown';
278
+ console.warn('[registry] replace called by:', componentName, {
279
+ newState,
280
+ overwrite,
281
+ stack: new Error().stack
282
+ });
283
+ this._commit(elem, newState, overwrite, true);
284
+ }
285
+
286
+ _commit(elem, newState, overwrite, replace) {
287
+ const oldState = { ...this.state };
288
+ this.state = overwrite ? newState : { ...this.state, ...newState };
289
+ const resolved = this.urlFromState();
290
+
291
+ console.log('[registry] _commit: committing state', {
292
+ oldState,
293
+ newState,
294
+ overwrite,
295
+ replace,
296
+ mergedState: this.state,
297
+ resolvedUrl: resolved.toString(),
298
+ resolvedHash: resolved.hash,
299
+ resolvedSearch: resolved.search
300
+ });
301
+
302
+ const chs = getSubscribedChannels(elem);
303
+ chs.forEach(channel => {
304
+ if (overwrite || !this.channelStates[channel]) {
305
+ this.channelStates[channel] = newState;
306
+ } else {
307
+ Object.assign(this.channelStates[channel], newState);
308
+ }
309
+ });
310
+
311
+ const json = this.toJSON();
312
+ if (replace) {
313
+ window.history.replaceState(json, '', resolved);
314
+ log('replace %s: %o %d', resolved.toString(), this.channelStates, window.history.length);
315
+ console.log('[registry] _commit: replaced URL', { url: resolved.toString(), hash: resolved.hash, search: resolved.search });
316
+ } else {
317
+ window.history.pushState(json, '', resolved);
318
+ log('commit %s: %o %d', resolved.toString(), this.channelStates, window.history.length);
319
+ console.log('[registry] _commit: pushed URL', { url: resolved.toString(), hash: resolved.hash, search: resolved.search });
244
320
  }
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);
266
- }
321
+ }
322
+
323
+ urlFromState() {
324
+ const newUrl = new URL(window.location.href);
325
+
326
+ function setParam(value, param) {
327
+ if (value === null) {
328
+ newUrl.searchParams.delete(param);
329
+ } else if (Array.isArray(value)) {
330
+ // copy array before mutating it
331
+ const _v = Array.from(value);
332
+ // overwrite any previous value by setting the first member
333
+ newUrl.searchParams.set(param, _v.pop());
334
+ // add additional values
335
+ _v.forEach(v => newUrl.searchParams.append(param, v));
336
+ } else {
337
+ newUrl.searchParams.set(param, value);
338
+ }
267
339
  }
268
340
 
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
- }
341
+ console.log('[registry] urlFromState: building URL from state', {
342
+ state: this.state,
343
+ idHash: this.idHash,
344
+ usePath: this.usePath,
345
+ urlPattern: this.urlPattern,
346
+ urlIgnore: Array.from(this.urlIgnore),
347
+ pathParams: Array.from(this.pathParams)
348
+ });
349
+
350
+ for (const [param, value] of Object.entries(this.state)) {
351
+ if (this.urlPattern) {
352
+ // check if param should be ignored or is required by the URL template
353
+ // fill up missing parameters by stripping potential "user." prefix
354
+ const normParam = param.replace(/^(?:user\.)?(.*)$/, '$1');
355
+ const shouldIgnore = this.pathParams.has(normParam) || this.urlIgnore.has(normParam);
356
+ console.log('[registry] urlFromState: processing param (urlPattern)', { param, normParam, value, shouldIgnore, willInclude: !shouldIgnore });
357
+ if (!shouldIgnore) {
358
+ setParam(value, normParam);
285
359
  }
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
- }
302
- }
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
- }
360
+ } else if (
361
+ (param !== 'path' || !this.usePath) &&
362
+ // Always include 'id' in query params for shareable URLs (hash is set separately below)
363
+ !this.urlIgnore.has(param)
364
+ ) {
365
+ const willInclude = (param !== 'path' || !this.usePath) && !this.urlIgnore.has(param);
366
+ // Filter out unwanted default values that shouldn't be in URLs
367
+ // These are typically set by components during initialization but shouldn't pollute the URL
368
+ const isUnwantedDefault = (
369
+ (param === 'view' && value === 'single') ||
370
+ (param === 'odd' && value === 'teipublisher') ||
371
+ (param === 'panels' && typeof value === 'string' && value.split('.').length > 10) // Malformed panels (concatenated)
372
+ );
373
+ console.log('[registry] urlFromState: processing param (no urlPattern)', { param, value, willInclude, isUnwantedDefault, isPath: param === 'path', usePath: this.usePath, inUrlIgnore: this.urlIgnore.has(param) });
374
+ if (willInclude && !isUnwantedDefault) {
375
+ setParam(value, param);
376
+ } else if (isUnwantedDefault) {
377
+ console.log('[registry] urlFromState: filtering out unwanted default value', { param, value, reason: 'unwanted default' });
320
378
  }
379
+ } else {
380
+ console.log('[registry] urlFromState: skipping param', { param, value, reason: param === 'path' && this.usePath ? 'path param with usePath=true' : 'in urlIgnore' });
381
+ }
382
+ }
321
383
 
322
- if (this.state.id && !this.urlPattern) {
323
- newUrl.hash = `#${this.state.id}`;
384
+ if (this.state.path && this.state.path.length > 0) {
385
+ if (this.urlPattern) {
386
+ // path parameters should not be the empty string
387
+ const normState = {};
388
+ for (const [key, value] of Object.entries(this.state)) {
389
+ if (this.pathParams.has(key) && value === '') {
390
+ normState[key] = null;
391
+ } else {
392
+ normState[key] = value;
393
+ }
324
394
  }
325
-
326
- return newUrl;
395
+ const encoded = this._encodePath(normState);
396
+ newUrl.pathname = `${this.rootPath}/${encoded}`;
397
+ } else if (this.usePath) {
398
+ newUrl.pathname = `${this.rootPath}/${this.state.path}`;
399
+ }
327
400
  }
328
401
 
329
- toJSON() {
330
- return JSON.stringify(this.channelStates);
402
+ if (this.state.id && !this.urlPattern) {
403
+ newUrl.hash = `#${this.state.id}`;
404
+ console.log('[registry] urlFromState: set hash from state.id', { id: this.state.id, hash: newUrl.hash });
331
405
  }
406
+
407
+ console.log('[registry] urlFromState: final URL', {
408
+ url: newUrl.toString(),
409
+ search: newUrl.search,
410
+ hash: newUrl.hash,
411
+ hasIdParam: newUrl.searchParams.has('id'),
412
+ idParamValue: newUrl.searchParams.get('id'),
413
+ hasRootParam: newUrl.searchParams.has('root'),
414
+ rootParamValue: newUrl.searchParams.get('root')
415
+ });
416
+
417
+ return newUrl;
418
+ }
419
+
420
+ toJSON() {
421
+ return JSON.stringify(this.channelStates);
422
+ }
332
423
  }
333
424
 
334
425
  export const registry = new Registry();
335
- if (!window.pbRegistry) {
336
- window.pbRegistry = registry;
337
- }
426
+
427
+ // Expose the registry under both historical names and keep them in sync
428
+ if (typeof window !== 'undefined') {
429
+ if (!window.pbRegistry) window.pbRegistry = registry;
430
+ if (!window.PB) window.PB = {};
431
+
432
+ // Define PB.pbRegistry as a live alias of window.pbRegistry so reads/writes stay in sync
433
+ try {
434
+ const desc = Object.getOwnPropertyDescriptor(window.PB, 'pbRegistry');
435
+ if (!desc || typeof desc.get !== 'function') {
436
+ Object.defineProperty(window.PB, 'pbRegistry', {
437
+ configurable: true,
438
+ enumerable: true,
439
+ get() {
440
+ return window.pbRegistry;
441
+ },
442
+ set(val) {
443
+ window.pbRegistry = val;
444
+ },
445
+ });
446
+ }
447
+ } catch (e) {
448
+ // Fallback if defineProperty is blocked or pbRegistry already exists as a data property
449
+ if (!window.PB.pbRegistry) window.PB.pbRegistry = window.pbRegistry;
450
+ }
451
+ }