@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.
- package/.github/workflows/docker-cypress.yml +53 -0
- package/.github/workflows/node.js.yml +70 -21
- package/.releaserc.json +7 -2
- package/CHANGELOG.md +363 -11
- package/Dockerfile +78 -70
- package/README.md +112 -4
- package/css/components.css +5 -5
- package/css/gridjs/mermaid.min.css +1 -1
- package/css/leaflet/Control.Geocoder.css +1 -126
- package/css/leaflet/images/layers.png +0 -0
- package/css/tify/tify.css +6 -5
- package/css/tom-select/tom-select.bootstrap4.min.css +1 -1
- package/css/tom-select/tom-select.bootstrap5.min.css +1 -1
- package/css/tom-select/tom-select.default.min.css +1 -1
- package/css/tom-select/tom-select.default.min.css.map +1 -0
- package/css/tom-select/tom-select.min.css +1 -1
- package/cypress.config.js +84 -0
- package/dist/api.html +1 -1
- package/dist/css/design-system.css +607 -0
- package/dist/demo/bundle-test.html +4 -3
- package/dist/demo/components.css +46 -1
- package/dist/demo/design-system.html +710 -0
- package/dist/demo/dts-client.html +2 -2
- package/dist/demo/pb-autocomplete.html +23 -11
- package/dist/demo/pb-autocomplete2.html +66 -55
- package/dist/demo/pb-autocomplete3.html +17 -8
- package/dist/demo/pb-blacklab-highlight.html +28 -11
- package/dist/demo/pb-blacklab-results.html +3 -2
- package/dist/demo/pb-browse-docs.html +24 -24
- package/dist/demo/pb-browse-docs2.html +3 -3
- package/dist/demo/pb-clipboard.html +32 -28
- package/dist/demo/pb-code-editor.html +6 -6
- package/dist/demo/pb-code-highlight.html +63 -63
- package/dist/demo/pb-codepen.html +1 -1
- package/dist/demo/pb-collapse.html +1 -1
- package/dist/demo/pb-collapse2.html +2 -2
- package/dist/demo/pb-combo-box.html +135 -130
- package/dist/demo/pb-custom-form.html +64 -55
- package/dist/demo/pb-dialog.html +12 -6
- package/dist/demo/pb-document.html +1 -1
- package/dist/demo/pb-download.html +68 -59
- package/dist/demo/pb-drawer.html +67 -46
- package/dist/demo/pb-drawer2.html +65 -58
- package/dist/demo/pb-edit-app.html +2 -2
- package/dist/demo/pb-edit-xml.html +1 -1
- package/dist/demo/pb-facsimile-2.html +26 -11
- package/dist/demo/pb-facsimile-3.html +25 -10
- package/dist/demo/pb-facsimile-dedup-test-2.html +48 -0
- package/dist/demo/pb-facsimile-dedup-test.html +48 -0
- package/dist/demo/pb-facsimile.html +4 -4
- package/dist/demo/pb-formula.html +1 -1
- package/dist/demo/pb-grid.html +22 -8
- package/dist/demo/pb-highlight.html +2 -2
- package/dist/demo/pb-i18n-simple.html +1 -0
- package/dist/demo/pb-i18n.html +15 -5
- package/dist/demo/pb-image-strip-standalone.html +2 -2
- package/dist/demo/pb-image-strip-view.html +2 -2
- package/dist/demo/pb-leaflet-map.html +3 -3
- package/dist/demo/pb-leaflet-map2.html +2 -2
- package/dist/demo/pb-leaflet-map3.html +3 -3
- package/dist/demo/pb-link.html +1 -1
- package/dist/demo/pb-load.html +2 -6
- package/dist/demo/pb-login.html +1 -3
- package/dist/demo/pb-manage-odds.html +9 -4
- package/dist/demo/pb-markdown.html +1 -1
- package/dist/demo/pb-media-query.html +2 -2
- package/dist/demo/pb-mei.html +2 -2
- package/dist/demo/pb-mei2.html +2 -2
- package/dist/demo/pb-message.html +2 -3
- package/dist/demo/pb-odd-editor.html +54 -52
- package/dist/demo/pb-page-header.html +27 -0
- package/dist/demo/pb-popover.html +1 -1
- package/dist/demo/pb-print-preview.html +2 -2
- package/dist/demo/pb-progress.html +4 -4
- package/dist/demo/pb-repeat.html +32 -36
- package/dist/demo/pb-search.html +16 -5
- package/dist/demo/pb-search2.html +4 -4
- package/dist/demo/pb-search3.html +3 -3
- package/dist/demo/pb-search4.html +3 -3
- package/dist/demo/pb-select-feature.html +4 -4
- package/dist/demo/pb-select-feature2.html +4 -4
- package/dist/demo/pb-select-feature3.html +2 -2
- package/dist/demo/pb-select-i18n.html +58 -53
- package/dist/demo/pb-select-odd.html +1 -1
- package/dist/demo/pb-select.html +190 -75
- package/dist/demo/pb-select2.html +91 -37
- package/dist/demo/pb-select3.html +109 -41
- package/dist/demo/pb-svg.html +1 -1
- package/dist/demo/pb-table-grid.html +26 -15
- package/dist/demo/pb-tabs.html +15 -7
- package/dist/demo/pb-tify.html +7 -7
- package/dist/demo/pb-timeline.html +1 -1
- package/dist/demo/pb-timeline2.html +1 -1
- package/dist/demo/pb-toggle-feature.html +26 -23
- package/dist/demo/pb-toggle-feature2.html +4 -4
- package/dist/demo/pb-toggle-feature3.html +2 -2
- package/dist/demo/pb-toggle-feature4.html +56 -54
- package/dist/demo/pb-version.html +2 -2
- package/dist/demo/pb-view.html +78 -40
- package/dist/demo/pb-view2.html +69 -46
- package/dist/demo/pb-view3.html +53 -48
- package/dist/demo/pb-view4.html +70 -49
- package/dist/demo/pb-zoom.html +2 -2
- package/dist/{es-global-bridge-d8ce175d.js → es-global-bridge-D8ZcUcx_.js} +0 -4
- package/dist/focus-mixin-VCsFap6b.js +768 -0
- package/dist/images/icons.svg +217 -0
- package/dist/jinn-codemirror-DETLdm08.js +1 -0
- package/dist/lib/openseadragon.min.js +80 -0
- package/dist/lib/openseadragon.min.js.map +1 -0
- package/dist/pb-code-editor.js +25 -20
- package/dist/pb-component-docs.js +414 -3225
- package/dist/pb-components-bundle.js +3046 -4402
- package/dist/pb-dialog-tklYGWfc.js +121 -0
- package/dist/pb-edit-app.js +208 -107
- package/dist/pb-elements.json +716 -249
- package/dist/pb-facsimile.js +46 -0
- package/dist/pb-i18n-C0NDma4h.js +1 -0
- package/dist/pb-leaflet-map.js +23 -23
- package/dist/pb-mei.js +152 -134
- package/dist/pb-mixin-DHoWQheB.js +1 -0
- package/dist/pb-odd-editor.js +1671 -1231
- package/dist/pb-tify.js +1 -27
- package/dist/unsafe-html-D5VGo9Oq.js +1 -0
- package/dist/urls-BEONu_g4.js +1 -0
- package/eslint.config.mjs +92 -0
- package/gh-pages.js +5 -3
- package/i18n/common/en.json +6 -0
- package/i18n/common/pl.json +2 -2
- package/images/icons.svg +217 -0
- package/index.html +0 -5
- package/lib/leaflet-src.js.map +1 -0
- package/lib/leaflet.markercluster-src.js.map +1 -0
- package/lib/openseadragon.min.js +6 -6
- package/package.json +56 -81
- package/pb-elements.json +716 -249
- package/rollup.config.mjs +312 -0
- package/src/assets/components.css +5 -5
- package/src/assets/design-system.css +607 -0
- package/src/authority/airtable.js +20 -21
- package/src/authority/anton.js +129 -129
- package/src/authority/custom.js +70 -27
- package/src/authority/geonames.js +38 -32
- package/src/authority/gnd.js +50 -42
- package/src/authority/kbga.js +136 -134
- package/src/authority/metagrid.js +44 -46
- package/src/authority/reconciliation.js +66 -68
- package/src/authority/registry.js +4 -4
- package/src/docs/demo-utils.js +91 -0
- package/src/docs/pb-component-docs.js +287 -147
- package/src/docs/pb-component-view.js +380 -273
- package/src/docs/pb-components-list.js +115 -51
- package/src/docs/pb-demo-snippet.js +199 -174
- package/src/dts-client.js +306 -303
- package/src/dts-select-endpoint.js +125 -85
- package/src/parse-date-service.js +184 -135
- package/src/pb-ajax.js +175 -173
- package/src/pb-authority-lookup.js +198 -158
- package/src/pb-autocomplete.js +731 -313
- package/src/pb-blacklab-highlight.js +266 -260
- package/src/pb-blacklab-results.js +230 -225
- package/src/pb-browse-docs.js +601 -484
- package/src/pb-browse.js +68 -65
- package/src/pb-clipboard.js +97 -76
- package/src/pb-code-editor.js +111 -103
- package/src/pb-code-highlight.js +234 -204
- package/src/pb-codepen.js +81 -73
- package/src/pb-collapse.js +265 -152
- package/src/pb-combo-box.js +191 -191
- package/src/pb-components-bundle.js +1 -7
- package/src/pb-components.js +2 -6
- package/src/pb-custom-form.js +230 -141
- package/src/pb-dialog.js +99 -63
- package/src/pb-document.js +118 -91
- package/src/pb-download.js +214 -198
- package/src/pb-drawer.js +146 -149
- package/src/pb-edit-app.js +471 -240
- package/src/pb-edit-xml.js +101 -98
- package/src/pb-events.js +126 -107
- package/src/pb-facs-link.js +130 -101
- package/src/pb-facsimile.js +494 -410
- package/src/pb-fetch.js +389 -0
- package/src/pb-formula.js +152 -154
- package/src/pb-geolocation.js +130 -132
- package/src/pb-grid-action.js +59 -56
- package/src/pb-grid.js +388 -228
- package/src/pb-highlight.js +142 -142
- package/src/pb-hotkeys.js +40 -42
- package/src/pb-i18n.js +115 -127
- package/src/pb-icon-button.js +108 -0
- package/src/pb-icon.js +283 -0
- package/src/pb-image-strip.js +85 -79
- package/src/pb-lang.js +142 -57
- package/src/pb-leaflet-map.js +551 -483
- package/src/pb-link.js +132 -126
- package/src/pb-load.js +495 -428
- package/src/pb-login.js +303 -248
- package/src/pb-manage-odds.js +384 -338
- package/src/pb-map-icon.js +90 -90
- package/src/pb-map-layer.js +86 -86
- package/src/pb-markdown.js +107 -110
- package/src/pb-media-query.js +75 -73
- package/src/pb-mei.js +523 -303
- package/src/pb-message.js +144 -98
- package/src/pb-mixin.js +268 -265
- package/src/pb-navigation.js +83 -96
- package/src/pb-observable.js +39 -39
- package/src/pb-odd-editor.js +1209 -948
- package/src/pb-odd-elementspec-editor.js +375 -310
- package/src/pb-odd-model-editor.js +1189 -941
- package/src/pb-odd-parameter-editor.js +269 -170
- package/src/pb-odd-rendition-editor.js +184 -131
- package/src/pb-page.js +451 -422
- package/src/pb-paginate.js +260 -178
- package/src/pb-panel.js +217 -183
- package/src/pb-popover-themes.js +16 -9
- package/src/pb-popover.js +297 -288
- package/src/pb-print-preview.js +128 -128
- package/src/pb-progress.js +52 -52
- package/src/pb-repeat.js +141 -108
- package/src/pb-restricted.js +85 -78
- package/src/pb-search.js +258 -230
- package/src/pb-select-feature.js +210 -126
- package/src/pb-select-odd.js +184 -118
- package/src/pb-select-template.js +113 -78
- package/src/pb-select.js +330 -229
- package/src/pb-split-list.js +181 -176
- package/src/pb-svg.js +81 -80
- package/src/pb-table-column.js +55 -55
- package/src/pb-table-grid.js +334 -205
- package/src/pb-tabs.js +238 -61
- package/src/pb-tify.js +3331 -126
- package/src/pb-timeline.js +394 -255
- package/src/pb-toggle-feature.js +196 -188
- package/src/pb-upload.js +201 -176
- package/src/pb-version.js +22 -34
- package/src/pb-view-annotate.js +138 -102
- package/src/pb-view.js +1722 -1272
- package/src/pb-zoom.js +144 -46
- package/src/search-result-service.js +256 -223
- package/src/seed-element.js +14 -22
- package/src/settings.js +4 -4
- package/src/theming.js +98 -91
- package/src/urls.js +403 -289
- package/src/utils.js +53 -51
- package/vite.config.js +86 -0
- package/.github/workflows/main.yml +0 -24
- package/.github/workflows/release.js.yml +0 -34
- package/css/pb-styles.css +0 -51
- package/dist/iron-form-3b8dcaa7.js +0 -210
- package/dist/jinn-codemirror-da0e2d1f.js +0 -1
- package/dist/paper-checkbox-515a5284.js +0 -1597
- package/dist/paper-icon-button-b1d31571.js +0 -398
- package/dist/paper-listbox-a3b7175c.js +0 -1265
- package/dist/pb-i18n-0611135a.js +0 -1
- package/dist/pb-mixin-b1caa22e.js +0 -158
- package/dist/polymer-hack.js +0 -1
- package/dist/vaadin-element-mixin-fe4a4883.js +0 -527
- package/lib/Control.Geocoder.min.js +0 -2
- package/lib/Control.Geocoder.min.js.map +0 -1
- package/src/assets/pb-styles.css +0 -51
- package/src/pb-light-dom.js +0 -41
- package/src/polymer-hack.js +0 -6
package/src/urls.js
CHANGED
|
@@ -1,337 +1,451 @@
|
|
|
1
|
-
import { match, compile, pathToRegexp } from
|
|
2
|
-
import { PbEvents } from
|
|
3
|
-
import { getSubscribedChannels } from
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
239
|
-
|
|
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
|
-
|
|
243
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
323
|
-
|
|
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
|
-
|
|
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
|
-
|
|
330
|
-
|
|
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
|
-
|
|
336
|
-
|
|
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
|
+
}
|