@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/pb-load.js CHANGED
@@ -1,480 +1,547 @@
1
- import { LitElement, html, css } from 'lit-element';
1
+ import { LitElement, html, css } from 'lit';
2
2
  import { pbMixin, waitOnce } from './pb-mixin.js';
3
- import { translate } from "./pb-i18n.js";
4
- import { typesetMath } from "./pb-formula.js";
5
- import { registry } from "./urls.js";
6
- import '@polymer/iron-ajax';
7
- import '@polymer/paper-dialog';
8
- import '@polymer/paper-dialog-scrollable';
3
+ import { translate } from './pb-i18n.js';
4
+ import { typesetMath } from './pb-formula.js';
5
+ import { registry } from './urls.js';
6
+ import './pb-fetch.js';
7
+ import './pb-dialog.js';
8
+ import { themableMixin } from './theming.js';
9
9
 
10
10
  /**
11
11
  * Dynamically load data by calling a server-side script, optionally triggered by an event.
12
12
  * This is used for e.g. the document list on the start page or the table
13
13
  * of contents.
14
- *
14
+ *
15
15
  * @slot - default unnamed slot for content
16
16
  * @fires pb-start-update - Fired before the element updates its content
17
17
  * @fires pb-end-update - Fired after the element has finished updating its content
18
18
  * @fires pb-results-received - Fired when the component received content from the server
19
19
  * @fires pb-toggle - When received, changes the state of the feature
20
20
  */
21
- export class PbLoad extends pbMixin(LitElement) {
22
-
23
- static get properties() {
24
- return {
25
- ...super.properties,
26
- /** The URL for the AJAX request. If a relative URL is passed, it will be resolved
27
- * against the current API endpoint.
28
- */
29
- url: {
30
- type: String
31
- },
32
- /**
33
- * If set to true, the `url` property will be interpreted as a template string
34
- * containing placeholders for parameters in `{parameter-name}`. The placeholders
35
- * will be replaced by the actual parameters when building the final URL. Each parameter
36
- * used in the URL template will be removed from the request parameter list.
37
- */
38
- expand: {
39
- type: Boolean
40
- },
41
- /** ID of the pb-document this element is connected to. The document path to
42
- * load will be taken from the pb-document.
43
- */
44
- src: {
45
- type: String
46
- },
47
- /**
48
- * The container element into which the results returned by
49
- * the AJAX request will be loaded.
50
- */
51
- container: {
52
- type: String
53
- },
54
- /**
55
- * Should content be loaded immediately when the component is initialized?
56
- */
57
- auto: {
58
- type: Boolean
59
- },
60
- /**
61
- * Only load content once, not every time a `pb-load` event is received.
62
- */
63
- loadOnce: {
64
- type: Boolean
65
- },
66
- /**
67
- * If set, relative links (img, a) will be made absolute.
68
- */
69
- fixLinks: {
70
- type: Boolean,
71
- attribute: 'fix-links'
72
- },
73
- /**
74
- * Start offset to use for showing paginated content.
75
- */
76
- start: {
77
- type: Number
78
- },
79
- /**
80
- * If set, a parameter "language" will be added to the parameter list.
81
- * Also, a refresh will be triggered if a `pb-i18n-update` event is received,
82
- * e.g. due to the user selecting a different interface language.
83
- *
84
- * Also requires `requireLanguage` to be set on the surrounding `pb-page`.
85
- * See there for more information.
86
- */
87
- useLanguage: {
88
- type: Boolean,
89
- attribute: 'use-language'
90
- },
91
- /**
92
- * Indicates whether or not cross-site Access-Control requests should be made.
93
- * Default is false.
94
- */
95
- noCredentials: {
96
- type: Boolean,
97
- attribute: 'no-credentials'
98
- },
99
- /**
100
- * Indicates if the parameters of the request made should be saved to the browser
101
- * history and URL. Default: false.
102
- */
103
- history: {
104
- type: Boolean
105
- },
106
- /**
107
- * The event which will trigger a new request to be sent. Default is 'pb-load'.
108
- */
109
- event: {
110
- type: String
111
- },
112
- /**
113
- * Additional, user-defined parameters to be sent with the request.
114
- */
115
- userParams: {
116
- type: Object
117
- },
118
- /**
119
- * If set, silently ignore errors when sending the request.
120
- */
121
- silent: {
122
- type: Boolean
123
- },
124
- /**
125
- * Do not add internal parameters like 'start' or 'language' to the URL
126
- * but leave it untouched.
127
- */
128
- plain: {
129
- type: Boolean
21
+ export class PbLoad extends themableMixin(pbMixin(LitElement)) {
22
+ static get properties() {
23
+ return {
24
+ ...super.properties,
25
+ /** The URL for the AJAX request. If a relative URL is passed, it will be resolved
26
+ * against the current API endpoint.
27
+ */
28
+ url: {
29
+ type: String,
30
+ },
31
+ /**
32
+ * If set to true, the `url` property will be interpreted as a template string
33
+ * containing placeholders for parameters in `{parameter-name}`. The placeholders
34
+ * will be replaced by the actual parameters when building the final URL. Each parameter
35
+ * used in the URL template will be removed from the request parameter list.
36
+ */
37
+ expand: {
38
+ type: Boolean,
39
+ },
40
+ /** ID of the pb-document this element is connected to. The document path to
41
+ * load will be taken from the pb-document.
42
+ */
43
+ src: {
44
+ type: String,
45
+ },
46
+ /**
47
+ * The container element into which the results returned by
48
+ * the AJAX request will be loaded.
49
+ */
50
+ container: {
51
+ type: String,
52
+ },
53
+ /**
54
+ * Should content be loaded immediately when the component is initialized?
55
+ */
56
+ auto: {
57
+ type: Boolean,
58
+ },
59
+ /**
60
+ * Only load content once, not every time a `pb-load` event is received.
61
+ */
62
+ loadOnce: {
63
+ type: Boolean,
64
+ },
65
+ /**
66
+ * If set, relative links (img, a) will be made absolute.
67
+ */
68
+ fixLinks: {
69
+ type: Boolean,
70
+ attribute: 'fix-links',
71
+ },
72
+ /**
73
+ * Start offset to use for showing paginated content.
74
+ */
75
+ start: {
76
+ type: Number,
77
+ },
78
+ /**
79
+ * If set, a parameter "language" will be added to the parameter list.
80
+ * Also, a refresh will be triggered if a `pb-i18n-update` event is received,
81
+ * e.g. due to the user selecting a different interface language.
82
+ *
83
+ * Also requires `requireLanguage` to be set on the surrounding `pb-page`.
84
+ * See there for more information.
85
+ */
86
+ useLanguage: {
87
+ type: Boolean,
88
+ attribute: 'use-language',
89
+ },
90
+ /**
91
+ * Indicates whether or not cross-site Access-Control requests should be made.
92
+ * Default is false.
93
+ */
94
+ noCredentials: {
95
+ type: Boolean,
96
+ attribute: 'no-credentials',
97
+ },
98
+ /**
99
+ * Indicates if the parameters of the request made should be saved to the browser
100
+ * history and URL. Default: false.
101
+ */
102
+ history: {
103
+ type: Boolean,
104
+ },
105
+ /**
106
+ * The event which will trigger a new request to be sent. Default is 'pb-load'.
107
+ */
108
+ event: {
109
+ type: String,
110
+ },
111
+ /**
112
+ * Additional, user-defined parameters to be sent with the request.
113
+ */
114
+ userParams: {
115
+ type: Object,
116
+ },
117
+ /**
118
+ * If set, silently ignore errors when sending the request.
119
+ */
120
+ silent: {
121
+ type: Boolean,
122
+ },
123
+ /**
124
+ * Do not add internal parameters like 'start' or 'language' to the URL
125
+ * but leave it untouched.
126
+ */
127
+ plain: {
128
+ type: Boolean,
129
+ },
130
+ };
131
+ }
132
+
133
+ constructor() {
134
+ super();
135
+ this.auto = false;
136
+ this.loadOnce = false;
137
+ this.history = false;
138
+ this.event = 'pb-load';
139
+ this.loaded = false;
140
+ this.language = null;
141
+ this.noCredentials = false;
142
+ this.silent = false;
143
+ this._retryCount = 0;
144
+ this._maxRetries = 20; // Maximum retries for document resolution
145
+ }
146
+
147
+ connectedCallback() {
148
+ super.connectedCallback();
149
+ this.subscribeTo(this.event, ev => {
150
+ waitOnce('pb-page-ready', () => {
151
+ if (this.history) {
152
+ if (ev.detail && ev.detail.params) {
153
+ const { start } = ev.detail.params;
154
+ if (start) {
155
+ registry.commit(this, { start });
130
156
  }
131
- };
132
- }
133
-
134
- constructor() {
135
- super();
136
- this.auto = false;
137
- this.loadOnce = false;
138
- this.history = false;
139
- this.event = 'pb-load';
140
- this.loaded = false;
141
- this.language = null;
142
- this.noCredentials = false;
143
- this.silent = false;
144
- }
145
-
146
- connectedCallback() {
147
- super.connectedCallback();
148
- this.subscribeTo(this.event, (ev) => {
149
- waitOnce('pb-page-ready', () => {
150
- if (this.history) {
151
- if (ev.detail && ev.detail.params) {
152
- const start = ev.detail.params.start;
153
- if (start) {
154
- registry.commit(this, { start });
155
- }
156
- }
157
- this.userParams = registry.state;
158
- registry.subscribe(this, (state) => {
159
- if (state.start) {
160
- this.start = state.start;
161
- this.load();
162
- }
163
- });
164
- registry.replace(this, this.userParams);
165
- }
166
- this.load(ev);
167
- });
168
- });
169
-
170
- this.subscribeTo('pb-toggle', ev => {
171
- this.toggleFeature(ev);
172
- });
173
-
174
- this.subscribeTo('pb-i18n-update', ev => {
175
- const needsRefresh = this.language && this.language !== ev.detail.language;
176
- this.language = ev.detail.language;
177
- if (this.useLanguage && needsRefresh) {
178
- this.load();
157
+ }
158
+ this.userParams = registry.state;
159
+ registry.subscribe(this, state => {
160
+ if (state.start) {
161
+ this.start = state.start;
162
+ this.load();
179
163
  }
180
- }, []);
181
-
182
- if (this.history) {
183
- registry.subscribe(this, (state) => {
184
- this.start = state.start;
185
- this.userParams = state;
186
- this.load();
187
- });
164
+ });
165
+ registry.replace(this, this.userParams);
188
166
  }
189
-
190
- this.signalReady();
191
- }
192
-
193
- firstUpdated() {
194
- if (this.auto) {
195
- this.start = registry.state.start || 1;
196
- waitOnce('pb-page-ready', (data) => {
197
- if (data && data.language) {
198
- this.language = data.language;
199
- }
200
- this.wait(() => this.load());
201
- });
202
- } else {
203
- waitOnce('pb-page-ready', (data) => {
204
- if (data && data.language) {
205
- this.language = data.language;
206
- }
207
- });
167
+ this.load(ev);
168
+ });
169
+ });
170
+
171
+ this.subscribeTo('pb-toggle', ev => {
172
+ this.toggleFeature(ev);
173
+ });
174
+
175
+ // Subscribe to pb-document events to know when the document is ready
176
+ this.subscribeTo('pb-document', ev => {
177
+ if (ev.detail && ev.detail.id === this.src) {
178
+ console.log(`<pb-load> Document ${this.src} is ready, triggering load`);
179
+ this.load();
180
+ }
181
+ });
182
+
183
+ this.subscribeTo(
184
+ 'pb-i18n-update',
185
+ ev => {
186
+ const needsRefresh = this.language && this.language !== ev.detail.language;
187
+ this.language = ev.detail.language;
188
+ if (this.useLanguage && needsRefresh) {
189
+ this.load();
208
190
  }
191
+ },
192
+ [],
193
+ );
194
+
195
+ if (this.history) {
196
+ registry.subscribe(this, state => {
197
+ this.start = state.start;
198
+ this.userParams = state;
199
+ this.load();
200
+ });
209
201
  }
210
202
 
211
- attributeChangedCallback(name, oldValue, newValue) {
212
- super.attributeChangedCallback(name, oldValue, newValue);
213
- if (oldValue && oldValue !== newValue) {
214
- switch (name) {
215
- case 'url':
216
- case 'userParams':
217
- case 'start':
218
- if (this.auto && this.loader) {
219
- waitOnce('pb-page-ready', () => {
220
- this.wait(() => this.load());
221
- });
222
- }
223
- break;
224
- default:
225
- break;
226
- }
203
+ this.signalReady();
204
+ }
205
+
206
+ firstUpdated() {
207
+ if (this.auto) {
208
+ this.start = registry.state.start || 1;
209
+ waitOnce('pb-page-ready', data => {
210
+ if (data && data.language) {
211
+ this.language = data.language;
212
+ }
213
+ // Add a longer delay to ensure all components are properly initialized
214
+ // This includes pb-document elements that need time to set their properties
215
+ setTimeout(() => {
216
+ this.wait(() => this.load());
217
+ }, 200);
218
+ });
219
+ } else {
220
+ waitOnce('pb-page-ready', data => {
221
+ if (data && data.language) {
222
+ this.language = data.language;
227
223
  }
224
+ });
228
225
  }
229
-
230
- render() {
231
- return html`
232
- <slot></slot>
233
- <iron-ajax
234
- id="loadContent"
235
- verbose
236
- handle-as="text"
237
- method="get"
238
- ?with-credentials="${!this.noCredentials}"
239
- @response="${this._handleContent}"
240
- @error="${this._handleError}"></iron-ajax>
241
- <paper-dialog id="errorDialog">
242
- <h2>${translate('dialogs.error')}</h2>
243
- <paper-dialog-scrollable></paper-dialog-scrollable>
244
- <div class="buttons">
245
- <paper-button dialog-confirm="dialog-confirm" autofocus="autofocus">
246
- ${translate('dialogs.close')}
247
- </paper-button>
248
- </div>
249
- </paper-dialog>
250
- `;
226
+ }
227
+
228
+ attributeChangedCallback(name, oldValue, newValue) {
229
+ super.attributeChangedCallback(name, oldValue, newValue);
230
+ if (oldValue && oldValue !== newValue) {
231
+ switch (name) {
232
+ case 'url':
233
+ case 'userParams':
234
+ case 'start':
235
+ if (this.auto && this.loader) {
236
+ waitOnce('pb-page-ready', () => {
237
+ this.wait(() => this.load());
238
+ });
239
+ }
240
+ break;
241
+ default:
242
+ break;
243
+ }
251
244
  }
252
-
253
- static get styles() {
254
- return css`
255
- :host {
256
- display: block;
257
- }
258
- `;
245
+ }
246
+
247
+ render() {
248
+ return html`
249
+ <slot></slot>
250
+ <pb-fetch
251
+ id="loadContent"
252
+ verbose
253
+ handle-as="text"
254
+ method="get"
255
+ ?with-credentials="${!this.noCredentials}"
256
+ @response="${this._handleContent}"
257
+ @error="${this._handleError}"
258
+ ></pb-fetch>
259
+ <pb-dialog id="errorDialog" title="${translate('dialogs.error')}">
260
+ <p id="errorMessage"></p>
261
+ <div slot="footer">
262
+ <button rel="prev" type="button">${translate('dialogs.close')}</button>
263
+ </div>
264
+ </pb-dialog>
265
+ `;
266
+ }
267
+
268
+ static get styles() {
269
+ return css`
270
+ :host {
271
+ display: block;
272
+ }
273
+ `;
274
+ }
275
+
276
+ toggleFeature(ev) {
277
+ this.userParams = registry.getState(this);
278
+ console.log('<pb-load> toggle feature %o', this.userParams);
279
+ if (ev.detail.refresh) {
280
+ if (this.history) {
281
+ registry.commit(this, this.userParams);
282
+ }
283
+ this.load();
259
284
  }
260
-
261
- toggleFeature(ev) {
262
- this.userParams = registry.getState(this);
263
- console.log('<pb-load> toggle feature %o', this.userParams);
264
- if (ev.detail.refresh) {
265
- if (this.history) {
266
- registry.commit(this, this.userParams);
267
- }
268
- this.load();
285
+ }
286
+
287
+ getURL(params) {
288
+ let { url } = this;
289
+ if (this.expand) {
290
+ url = url.replace(/{([^})]+)}/g, (match, key) => {
291
+ if (!params[key]) {
292
+ return '';
269
293
  }
294
+ const param = encodeURIComponent(params[key] || key);
295
+ delete params[key];
296
+ return param;
297
+ });
270
298
  }
299
+ return this.toAbsoluteURL(url);
300
+ }
271
301
 
272
- getURL(params) {
273
- let url = this.url;
274
- if (this.expand) {
275
- url = url.replace(/{([^})]+)}/g, (match, key) => {
276
- if (!params[key]) {
277
- return '';
278
- }
279
- const param = encodeURIComponent(params[key] || key);
280
- delete params[key];
281
- return param;
282
- });
283
- }
284
- return this.toAbsoluteURL(url);
302
+ load(ev) {
303
+ if (!this.url) {
304
+ return;
305
+ }
306
+ if (this.loadOnce && this.loaded) {
307
+ return;
285
308
  }
286
309
 
287
- load(ev) {
288
- if (!this.url) {
289
- return;
290
- }
291
- if (this.loadOnce && this.loaded) {
292
- return;
293
- }
294
-
295
- this.emitTo('pb-start-update');
310
+ this.emitTo('pb-start-update');
296
311
 
297
- let params = {};
312
+ let params = {};
298
313
 
299
- if (ev) {
300
- if (ev instanceof Event) {
301
- if (ev.detail && ev.detail.params) {
302
- params = ev.detail.params;
303
- }
304
- } else {
305
- params = ev;
306
- }
314
+ if (ev) {
315
+ if (ev instanceof Event) {
316
+ if (ev.detail && ev.detail.params) {
317
+ params = ev.detail.params;
307
318
  }
319
+ } else {
320
+ params = ev;
321
+ }
322
+ }
308
323
 
309
- const doc = this.getDocument();
310
- if (!this.plain) {
311
- if (doc) {
312
- params.doc = doc.path;
313
- }
314
-
315
- // set start parameter to start property, but only if not provided otherwise already
316
- if (this.start && !params.start) {
317
- params.start = this.start;
318
- }
319
-
320
- if (this.language) {
321
- params.language = this.language;
322
- }
324
+ const doc = this.getDocument();
325
+ console.log(`<pb-load> getDocument() returned:`, doc, `src="${this.src}"`);
326
+ console.log(`<pb-load> Available elements with id "${this.src}":`, document.getElementById(this.src));
327
+ if (doc) {
328
+ console.log(`<pb-load> Document found, path="${doc.path}", odd="${doc.odd}", view="${doc.view}"`);
329
+ }
330
+ if (!this.plain) {
331
+ if (doc && doc.path) {
332
+ params.doc = doc.path;
333
+ console.log(`<pb-load> Setting params.doc to:`, doc.path);
334
+ this._retryCount = 0; // Reset retry counter when document is found
335
+ } else if (this.src) {
336
+ // Document not found but src is specified - wait for it to be available
337
+ if (this._retryCount < this._maxRetries) {
338
+ this._retryCount++;
339
+ const delay = Math.min(100 * this._retryCount, 1000); // Progressive delay up to 1 second
340
+ console.warn(`<pb-load> Document with id "${this.src}" not found or not ready, retrying in ${delay}ms (attempt ${this._retryCount}/${this._maxRetries})`);
341
+ setTimeout(() => {
342
+ this.load(ev);
343
+ }, delay);
344
+ return;
345
+ } else {
346
+ console.error(`<pb-load> Document with id "${this.src}" not found after ${this._maxRetries} attempts`);
347
+ // Instead of returning, show a loading state and keep trying
348
+ this.innerHTML = '<pb-i18n key="dialogs.loading">Loading...</pb-i18n>';
349
+ return;
323
350
  }
324
- params = this.prepareParameters(params);
325
-
326
- // filter null values
327
- for (const [k,v] of Object.entries(params)) {
328
- if (v === null) { delete params[k] }
351
+ } else {
352
+ // No document and no src specified - this might be intentional for plain mode
353
+ // But if we have {doc} in the URL template, we should warn
354
+ if (this.url && this.url.includes('{doc}')) {
355
+ console.warn(`<pb-load> URL template contains {doc} placeholder but no document is available and no src is specified`);
329
356
  }
357
+ }
330
358
 
331
- const url = this.getURL(params);
332
-
333
- console.log("<pb-load> Loading %s with parameters %o", url, params);
334
- const loader = this.shadowRoot.getElementById('loadContent');
335
- loader.params = params;
336
- loader.url = url;
337
- loader.generateRequest();
359
+ // set start parameter to start property, but only if not provided otherwise already
360
+ if (this.start && !params.start) {
361
+ params.start = this.start;
362
+ }
338
363
 
339
- if (this.loadOnce) {
340
- this.loaded = true;
341
- }
364
+ if (this.language) {
365
+ params.language = this.language;
366
+ }
342
367
  }
368
+ params = this.prepareParameters(params);
343
369
 
344
- /**
345
- * Allow subclasses to set parameters before the request is being sent.
346
- *
347
- * @param params Map of parameters
348
- * @return new or modified parameters map
349
- */
350
- prepareParameters(params) {
351
- if (this.userParams) {
352
- return Object.assign(params, this.userParams);
353
- }
354
- return params;
370
+ // filter null values
371
+ for (const [k, v] of Object.entries(params)) {
372
+ if (v === null) {
373
+ delete params[k];
374
+ }
355
375
  }
356
376
 
357
- _handleContent(ev) {
358
- const resp = this.shadowRoot.getElementById('loadContent').lastResponse;
359
- if (this.container) {
360
- this.style.display = 'none';
361
- document.querySelectorAll(this.container).forEach((elem) => {
362
- elem.innerHTML = resp;
363
- this._parseHeaders(ev.detail.xhr, elem);
364
- this._fixLinks(elem);
365
- this._onLoad(elem);
366
- });
367
- } else {
368
- this.style.display = '';
369
- this._clearContent();
377
+ const url = this.getURL(params);
370
378
 
371
- const div = document.createElement('div');
372
- div.innerHTML = resp;
373
- this._parseHeaders(ev.detail.xhr, div);
374
- div.slot = '';
375
- this.appendChild(div);
376
- this._fixLinks(div);
379
+ // Check if the URL still contains unresolved parameters
380
+ if (url.includes('{') && url.includes('}')) {
381
+ console.warn(`<pb-load> URL still contains unresolved parameters: ${url}`);
382
+ if (this.src) {
383
+ // Keep showing loading state and retry later
384
+ this.innerHTML = '<pb-i18n key="dialogs.loading">Loading...</pb-i18n>';
385
+ return;
386
+ }
387
+ }
377
388
 
378
- this._onLoad(div);
379
- }
389
+ console.log('<pb-load> Loading %s with parameters %o', url, params);
390
+ const loader = this.shadowRoot.getElementById('loadContent');
391
+ loader.params = params;
392
+ loader.url = url;
393
+ loader.generateRequest();
380
394
 
381
- this.emitTo('pb-end-update');
395
+ if (this.loadOnce) {
396
+ this.loaded = true;
382
397
  }
383
-
384
- _clearContent() {
385
- const contentSlot = this.shadowRoot.querySelector('slot:not([name])');
386
- if (contentSlot) {
387
- // clear content from slot
388
- contentSlot.assignedNodes().forEach((node) => node.parentNode.removeChild(node));
389
- }
398
+ }
399
+
400
+ /**
401
+ * Allow subclasses to set parameters before the request is being sent.
402
+ *
403
+ * @param params Map of parameters
404
+ * @return new or modified parameters map
405
+ */
406
+ prepareParameters(params) {
407
+ if (this.userParams) {
408
+ return Object.assign(params, this.userParams);
390
409
  }
391
-
392
- _handleError() {
393
- this.emitTo('pb-end-update');
394
- const loader = this.shadowRoot.getElementById('loadContent');
395
- const { response } = loader.lastError;
396
- if (this.silent) {
397
- console.error('Request failed: %s', response ? response.description : '');
398
- return;
399
- }
400
- let message;
401
- if (response) {
402
- message = response.description;
403
- } else {
404
- message = '<pb-i18n key="dialogs.serverError"></pb-i18n>';
405
- }
406
- const dialog = this.shadowRoot.getElementById('errorDialog');
407
- const body = dialog.querySelector("paper-dialog-scrollable");
408
- body.innerHTML = `<p><pb-i18n key="dialogs.serverError"></pb-i18n>: ${message} </p>`;
409
- dialog.open();
410
+ return params;
411
+ }
412
+
413
+ _handleContent(ev) {
414
+ const resp = this.shadowRoot.getElementById('loadContent').lastResponse;
415
+ if (this.container) {
416
+ this.style.display = 'none';
417
+ document.querySelectorAll(this.container).forEach(elem => {
418
+ elem.innerHTML = resp;
419
+ this._parseHeaders(ev.detail.xhr, elem);
420
+ this._fixLinks(elem);
421
+ this._onLoad(elem);
422
+ });
423
+ } else {
424
+ this.style.display = '';
425
+ this._clearContent();
426
+
427
+ const div = document.createElement('div');
428
+ div.innerHTML = resp;
429
+ this._parseHeaders(ev.detail.xhr, div);
430
+ div.slot = '';
431
+ this.appendChild(div);
432
+ this._fixLinks(div);
433
+
434
+ this._onLoad(div);
410
435
  }
411
436
 
412
- _parseHeaders(xhr, content) {
413
- // Try to determine number of pages and current position
414
- // Search for data-pagination-* attributes first and if they
415
- // can't be found, check HTTP headers
416
- //
417
- // However, if noCredentials is set, we won't be able to access the headers
418
- function getPaginationParam(type, noHeaders) {
419
- const elem = content.querySelector(`[data-pagination-${type}]`);
420
- if (elem) {
421
- return elem.getAttribute(`data-pagination-${type}`);
422
- }
423
- return noHeaders ? 0 : xhr.getResponseHeader(`pb-${type}`);
424
- }
437
+ this.emitTo('pb-end-update');
438
+ }
425
439
 
426
- const total = getPaginationParam('total', this.noCredentials);
427
- const start = getPaginationParam('start', this.noCredentials);
428
-
429
- if (this.start !== start) {
430
- this.start = parseInt(start);
431
- }
432
- this.emitTo('pb-results-received', {
433
- "count": total ? parseInt(total, 10) : 0,
434
- "start": this.start,
435
- "content": content,
436
- "params": this.shadowRoot.getElementById('loadContent').params
437
- });
440
+ _clearContent() {
441
+ const contentSlot = this.shadowRoot.querySelector('slot:not([name])');
442
+ if (contentSlot) {
443
+ // clear content from slot
444
+ contentSlot.assignedNodes().forEach(node => node.parentNode.removeChild(node));
438
445
  }
439
-
440
- _fixLinks(content) {
441
- typesetMath(content);
442
- if (this.fixLinks) {
443
- content.querySelectorAll('img').forEach((image) => {
444
- const oldSrc = image.getAttribute('src');
445
- const src = new URL(oldSrc, `${this.getEndpoint()}/`);
446
- image.src = src;
447
- });
448
- content.querySelectorAll('a').forEach((link) => {
449
- const oldHref = link.getAttribute('href');
450
- const href = new URL(oldHref, `${this.getEndpoint()}/`);
451
- link.href = href;
452
- });
453
- }
446
+ }
447
+
448
+ _handleError() {
449
+ this.emitTo('pb-end-update');
450
+ const loader = this.shadowRoot.getElementById('loadContent');
451
+ const { response } = loader.lastError;
452
+ if (this.silent) {
453
+ console.error('Request failed: %s', response ? response.description : '');
454
+ return;
454
455
  }
455
-
456
- _onLoad(content) {
456
+ let message;
457
+ if (response) {
458
+ message = response.description;
459
+ } else {
460
+ message = '<pb-i18n key="dialogs.serverError"></pb-i18n>';
461
+ }
462
+ const dialog = this.shadowRoot.getElementById('errorDialog');
463
+ const messageElement = this.shadowRoot.getElementById('errorMessage');
464
+ messageElement.innerHTML = `<pb-i18n key="dialogs.serverError"></pb-i18n>: ${message}`;
465
+ dialog.openDialog();
466
+ }
467
+
468
+ _parseHeaders(xhr, content) {
469
+ // Try to determine number of pages and current position
470
+ // Search for data-pagination-* attributes first and if they
471
+ // can't be found, check HTTP headers
472
+ //
473
+ // However, if noCredentials is set, we won't be able to access the headers
474
+ function getPaginationParam(type, noHeaders) {
475
+ const elem = content.querySelector(`[data-pagination-${type}]`);
476
+ if (elem) {
477
+ return elem.getAttribute(`data-pagination-${type}`);
478
+ }
479
+ return noHeaders ? 0 : xhr.getResponseHeader(`pb-${type}`);
457
480
  }
458
481
 
459
- /**
460
- * Fired before the element updates its content
461
- *
462
- * @event pb-start-update
463
- * @param {object} Parameters to be passed to the request
464
- */
465
-
466
- /**
467
- * Fired after the element has finished updating its content
468
- *
469
- * @event pb-end-update
470
- */
471
-
472
- /**
473
- * Fired after the element has received content from the server
474
- *
475
- * @event pb-results-received
476
- * @param {int} count number of results received (according to `pb-total` header)
477
- * @param {int} start offset into the result set (according to `pb-start` header)
478
- */
482
+ const total = getPaginationParam('total', this.noCredentials);
483
+ const start = getPaginationParam('start', this.noCredentials);
484
+
485
+ if (this.start !== start) {
486
+ this.start = parseInt(start);
487
+ }
488
+ this.emitTo('pb-results-received', {
489
+ count: total ? parseInt(total, 10) : 0,
490
+ start: this.start,
491
+ content,
492
+ params: this.shadowRoot.getElementById('loadContent').params,
493
+ });
494
+ }
495
+
496
+ _fixLinks(content) {
497
+ typesetMath(content);
498
+ if (this.fixLinks) {
499
+ content.querySelectorAll('img').forEach(image => {
500
+ const oldSrc = image.getAttribute('src');
501
+ if (!oldSrc) {
502
+ return;
503
+ }
504
+ try {
505
+ image.src = this.toAbsoluteURL(oldSrc);
506
+ } catch (err) {
507
+ console.warn('<pb-load> Unable to resolve image URL %s', oldSrc, err);
508
+ }
509
+ });
510
+ content.querySelectorAll('a').forEach(link => {
511
+ const oldHref = link.getAttribute('href');
512
+ if (!oldHref) {
513
+ return;
514
+ }
515
+ try {
516
+ link.href = this.toAbsoluteURL(oldHref);
517
+ } catch (err) {
518
+ console.warn('<pb-load> Unable to resolve link URL %s', oldHref, err);
519
+ }
520
+ });
521
+ }
522
+ }
523
+
524
+ _onLoad(content) {}
525
+
526
+ /**
527
+ * Fired before the element updates its content
528
+ *
529
+ * @event pb-start-update
530
+ * @param {object} Parameters to be passed to the request
531
+ */
532
+
533
+ /**
534
+ * Fired after the element has finished updating its content
535
+ *
536
+ * @event pb-end-update
537
+ */
538
+
539
+ /**
540
+ * Fired after the element has received content from the server
541
+ *
542
+ * @event pb-results-received
543
+ * @param {int} count number of results received (according to `pb-total` header)
544
+ * @param {int} start offset into the result set (according to `pb-start` header)
545
+ */
479
546
  }
480
- customElements.define('pb-load', PbLoad);
547
+ customElements.define('pb-load', PbLoad);