@teipublisher/pb-components 2.26.0-next-3.11 → 2.26.0-next-3.13

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 (133) hide show
  1. package/.github/workflows/main.yml +3 -3
  2. package/.github/workflows/node.js.yml +3 -3
  3. package/.github/workflows/release.js.yml +3 -3
  4. package/CHANGELOG.md +38 -0
  5. package/Dockerfile +78 -70
  6. package/css/components.css +5 -5
  7. package/dist/demo/components.css +2 -8
  8. package/dist/demo/pb-drawer2.html +1 -1
  9. package/dist/demo/pb-leaflet-map.html +1 -1
  10. package/dist/demo/pb-progress.html +2 -2
  11. package/dist/demo/pb-repeat.html +1 -3
  12. package/dist/demo/pb-view3.html +1 -1
  13. package/dist/{paper-icon-button-0fb125c4.js → paper-icon-button-72125e67.js} +1 -1
  14. package/dist/pb-code-editor.js +25 -20
  15. package/dist/pb-component-docs.js +58 -54
  16. package/dist/pb-components-bundle.js +1937 -1782
  17. package/dist/pb-edit-app.js +167 -107
  18. package/dist/pb-elements.json +45 -45
  19. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  20. package/dist/pb-leaflet-map.js +23 -23
  21. package/dist/pb-mei.js +56 -41
  22. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  23. package/dist/pb-odd-editor.js +923 -756
  24. package/dist/pb-tify.js +2 -2
  25. package/dist/{vaadin-element-mixin-6633322b.js → vaadin-element-mixin-84fb7d82.js} +181 -143
  26. package/gh-pages.js +5 -3
  27. package/i18n/common/pl.json +2 -2
  28. package/lib/openseadragon.min.js +1 -1
  29. package/package.json +2 -2
  30. package/pb-elements.json +45 -45
  31. package/src/assets/components.css +5 -5
  32. package/src/authority/airtable.js +20 -21
  33. package/src/authority/anton.js +129 -129
  34. package/src/authority/custom.js +23 -21
  35. package/src/authority/geonames.js +38 -32
  36. package/src/authority/gnd.js +47 -42
  37. package/src/authority/kbga.js +137 -134
  38. package/src/authority/metagrid.js +44 -46
  39. package/src/authority/reconciliation.js +66 -67
  40. package/src/authority/registry.js +4 -4
  41. package/src/docs/pb-component-docs.js +2 -2
  42. package/src/docs/pb-component-view.js +5 -5
  43. package/src/docs/pb-components-list.js +2 -2
  44. package/src/docs/pb-demo-snippet.js +2 -2
  45. package/src/dts-client.js +299 -297
  46. package/src/dts-select-endpoint.js +90 -82
  47. package/src/parse-date-service.js +184 -135
  48. package/src/pb-ajax.js +150 -146
  49. package/src/pb-authority-lookup.js +183 -146
  50. package/src/pb-autocomplete.js +292 -280
  51. package/src/pb-blacklab-highlight.js +264 -259
  52. package/src/pb-blacklab-results.js +236 -221
  53. package/src/pb-browse-docs.js +540 -475
  54. package/src/pb-browse.js +68 -65
  55. package/src/pb-clipboard.js +79 -76
  56. package/src/pb-code-editor.js +110 -102
  57. package/src/pb-code-highlight.js +209 -204
  58. package/src/pb-codepen.js +79 -72
  59. package/src/pb-collapse.js +212 -207
  60. package/src/pb-combo-box.js +190 -190
  61. package/src/pb-components-bundle.js +1 -1
  62. package/src/pb-custom-form.js +151 -149
  63. package/src/pb-dialog.js +96 -60
  64. package/src/pb-document.js +89 -90
  65. package/src/pb-download.js +210 -198
  66. package/src/pb-drawer.js +145 -148
  67. package/src/pb-edit-app.js +301 -229
  68. package/src/pb-edit-xml.js +98 -96
  69. package/src/pb-events.js +114 -107
  70. package/src/pb-facs-link.js +104 -102
  71. package/src/pb-facsimile.js +411 -413
  72. package/src/pb-formula.js +151 -153
  73. package/src/pb-geolocation.js +129 -131
  74. package/src/pb-grid-action.js +53 -56
  75. package/src/pb-grid.js +231 -228
  76. package/src/pb-highlight.js +140 -140
  77. package/src/pb-hotkeys.js +40 -42
  78. package/src/pb-i18n.js +101 -104
  79. package/src/pb-image-strip.js +84 -78
  80. package/src/pb-lang.js +132 -128
  81. package/src/pb-leaflet-map.js +488 -485
  82. package/src/pb-link.js +126 -124
  83. package/src/pb-load.js +431 -426
  84. package/src/pb-login.js +291 -248
  85. package/src/pb-manage-odds.js +364 -318
  86. package/src/pb-map-icon.js +89 -89
  87. package/src/pb-map-layer.js +85 -85
  88. package/src/pb-markdown.js +90 -99
  89. package/src/pb-media-query.js +74 -72
  90. package/src/pb-mei.js +306 -295
  91. package/src/pb-message.js +144 -144
  92. package/src/pb-mixin.js +269 -264
  93. package/src/pb-navigation.js +80 -82
  94. package/src/pb-observable.js +38 -38
  95. package/src/pb-odd-editor.js +1053 -955
  96. package/src/pb-odd-elementspec-editor.js +348 -297
  97. package/src/pb-odd-model-editor.js +1061 -901
  98. package/src/pb-odd-parameter-editor.js +200 -178
  99. package/src/pb-odd-rendition-editor.js +136 -124
  100. package/src/pb-page.js +431 -421
  101. package/src/pb-paginate.js +202 -190
  102. package/src/pb-panel.js +191 -179
  103. package/src/pb-popover-themes.js +7 -5
  104. package/src/pb-popover.js +296 -287
  105. package/src/pb-print-preview.js +127 -127
  106. package/src/pb-progress.js +51 -51
  107. package/src/pb-repeat.js +105 -104
  108. package/src/pb-restricted.js +84 -77
  109. package/src/pb-search.js +252 -241
  110. package/src/pb-select-feature.js +127 -120
  111. package/src/pb-select-odd.js +132 -124
  112. package/src/pb-select-template.js +89 -78
  113. package/src/pb-select.js +251 -227
  114. package/src/pb-split-list.js +179 -174
  115. package/src/pb-svg.js +80 -79
  116. package/src/pb-table-column.js +54 -54
  117. package/src/pb-table-grid.js +221 -203
  118. package/src/pb-tabs.js +61 -63
  119. package/src/pb-tify.js +154 -154
  120. package/src/pb-timeline.js +271 -229
  121. package/src/pb-toggle-feature.js +182 -175
  122. package/src/pb-upload.js +184 -174
  123. package/src/pb-version.js +30 -30
  124. package/src/pb-view-annotate.js +132 -98
  125. package/src/pb-view.js +1289 -1270
  126. package/src/pb-zoom.js +75 -59
  127. package/src/polymer-hack.js +1 -1
  128. package/src/search-result-service.js +256 -223
  129. package/src/seed-element.js +13 -20
  130. package/src/settings.js +4 -4
  131. package/src/theming.js +96 -96
  132. package/src/urls.js +289 -289
  133. package/src/utils.js +53 -51
package/src/pb-page.js CHANGED
@@ -5,10 +5,10 @@ import XHR from 'i18next-xhr-backend';
5
5
  import Backend from 'i18next-chained-backend';
6
6
  import { pbMixin, clearPageEvents } from './pb-mixin.js';
7
7
  import { resolveURL } from './utils.js';
8
- import { loadStylesheets } from "./theming.js";
9
- import { initTranslation } from "./pb-i18n.js";
10
- import { typesetMath } from "./pb-formula.js";
11
- import { registry } from "./urls.js";
8
+ import { loadStylesheets } from './theming.js';
9
+ import { initTranslation } from './pb-i18n.js';
10
+ import { typesetMath } from './pb-formula.js';
11
+ import { registry } from './urls.js';
12
12
 
13
13
  /**
14
14
  * Make sure there's only one instance of pb-page active at any time.
@@ -20,7 +20,7 @@ let _instance;
20
20
  * Among other things, this element determines the TEI Publisher
21
21
  * instance to which all elements will talk (property `endpoint`), and
22
22
  * initializes the i18n language module.
23
- *
23
+ *
24
24
  * @slot - default unnamed slot for content
25
25
  * @fires pb-page-ready - fired when the endpoint and language settings have been determined
26
26
  * @fires pb-i18n-update - fired when the user selected a different display language
@@ -28,445 +28,455 @@ let _instance;
28
28
  * @fires pb-toggle - when received, dispatch state changes to the elements on the page (see `pb-toggle-feature`, `pb-select-feature`)
29
29
  */
30
30
  export class PbPage extends pbMixin(LitElement) {
31
-
32
- static get properties() {
33
- return {
34
- ...super.properties,
35
- /**
36
- * TEI Publisher internal: set to the root URL of the current app
37
- */
38
- appRoot: {
39
- type: String,
40
- attribute: 'app-root'
41
- },
42
- /**
43
- * Can be used to define parameters which should be serialized in the
44
- * URL path rather than as query parameters. Expects a url pattern
45
- * relative to the application root
46
- * (supported patterns are documented in the
47
- * [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) library documentation).
48
- *
49
- * For example, a pattern `:lang/texts/:path/:id?` would support URLs like
50
- * `en/texts/text1/chapter1`. Whenever components change state e.g. due to a navigation
51
- * event – the standard parameters `path`, `lang` and `id` would be serialized into the
52
- * URL path pattern rather than query parameters.
53
- */
54
- urlTemplate: {
55
- type: String,
56
- attribute: 'url-template'
57
- },
58
- /**
59
- * A comma-separated list of parameter names which should not be reflected on the browser URL.
60
- * Use this to exclude e.g. the default `odd` parameter of a pb-view to be shown in the
61
- * browser URL.
62
- */
63
- urlIgnore: {
64
- type: String,
65
- attribute: 'url-ignore'
66
- },
67
- /**
68
- * Is the resource path part of the URL or should it be
69
- * encoded as a parameter? TEI Publisher uses the
70
- * URL path, but the webcomponent demos need to encode the resource path
71
- * in a query parameter.
72
- */
73
- urlPath: {
74
- type: String,
75
- attribute: 'url-path'
76
- },
77
- /**
78
- * If enabled, a hash in the URL (e.g. documentation.xml#introduction) will
79
- * be interpreted as an xml:id to navigate to when talking to the server.
80
- */
81
- idHash: {
82
- type: Boolean,
83
- attribute: 'id-hash'
84
- },
85
- /**
86
- * TEI Publisher internal: set to the current page template.
87
- */
88
- template: {
89
- type: String
90
- },
91
- /**
92
- * The base URL of the TEI Publisher instance. All nested elements will
93
- * talk to this instance. By default it is set to the URL the
94
- * page was loaded from.
95
- *
96
- * The endpoint can be overwritten by providing an HTTP request parameter
97
- * `_target` with an URL.
98
- */
99
- endpoint: {
100
- type: String,
101
- reflect: true
102
- },
103
- apiVersion: {
104
- type: String,
105
- attribute: 'api-version',
106
- reflect: true
107
- },
108
- /**
109
- * Optional URL pointing to a directory from which additional i18n
110
- * language files will be loaded. The URL should contain placeholders
111
- * for the language (`lng`) and the namespace (`ns`), e.g.
112
- *
113
- * `resources/i18n/{{ns}}_{{lng}}.json`
114
- *
115
- * or
116
- *
117
- * `resources/i18n/{{ns}}/{{lng}}.json`
118
- *
119
- * The latter assumes custom language files in a subdirectory, the first
120
- * expects the namespace to be specified at the start of the file name.
121
- *
122
- * The default namespace for custom language files is assumed to be `app`,
123
- * but you can define additional namespaces via `localeFallbackNS`.
124
- */
125
- locales: {
126
- type: String
127
- },
128
- /**
129
- * Optional list of whitespace separated namespaces which should be searched
130
- * for translations. By default, only the namespace `common` is queried.
131
- * If the `locales` property is specified, an additional namespace `app` is added.
132
- * You can add more namespace here, e.g. `custom`, if you want to provide
133
- * translations for custom apps or components.
134
- */
135
- localeFallbackNs: {
136
- type: String,
137
- attribute: 'locale-fallback-ns'
138
- },
139
- /**
140
- * Comma-separated list of languages supported. If the detected language
141
- * is not in this list, fall back to the configured fallback language.
142
- */
143
- supportedLanguages: {
144
- type: Array,
145
- attribute: 'supported-languages',
146
- converter(value) {
147
- return value.split(/\s*,\s*/);
148
- }
149
- },
150
- /**
151
- * The fallback language to use if the detected language is not supported.
152
- * Defaults to 'en'.
153
- */
154
- fallbackLanguage: {
155
- type: String,
156
- attribute: 'fallback-language'
157
- },
158
- /**
159
- * Set a language for i18n (e.g. 'en' or 'de'). If not set, browser language
160
- * detection will be used.
161
- */
162
- language: {
163
- type: String
164
- },
165
- /**
166
- * If set, the element will wait for a language being set by i18n before
167
- * it sends a `pb-page-ready` event. Elements like `pb-view` will wait
168
- * for this event before displaying content.
169
- *
170
- * Also, `pb-view` will pass the configured language to the server endpoint
171
- * where it will be available to ODD processing models in variable
172
- * `$parameters?language` and can thus be used to change output depending on
173
- * the user interface language.
174
- *
175
- * If you would like `pb-view` to refresh automatically whenever the language
176
- * setting changes, specify property `useLanguage` on the corresponding `pb-view`.
177
- */
178
- requireLanguage: {
179
- type: Boolean,
180
- attribute: 'require-language'
181
- },
182
- /**
183
- * Will be set while the component is loading and unset when
184
- * it is fully loaded. Use to avoid flash of unstyled content
185
- * via CSS: set `unresolved` on `pb-page` in the HTML and
186
- * add a CSS rule like:
187
- *
188
- * ```css
189
- * pb-page[unresolved] {
190
- * display: none;
191
- * }
192
- * ```
193
- */
194
- unresolved: {
195
- type: Boolean,
196
- reflect: true
197
- },
198
- theme: {
199
- type: String
200
- }
201
- };
31
+ static get properties() {
32
+ return {
33
+ ...super.properties,
34
+ /**
35
+ * TEI Publisher internal: set to the root URL of the current app
36
+ */
37
+ appRoot: {
38
+ type: String,
39
+ attribute: 'app-root',
40
+ },
41
+ /**
42
+ * Can be used to define parameters which should be serialized in the
43
+ * URL path rather than as query parameters. Expects a url pattern
44
+ * relative to the application root
45
+ * (supported patterns are documented in the
46
+ * [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) library documentation).
47
+ *
48
+ * For example, a pattern `:lang/texts/:path/:id?` would support URLs like
49
+ * `en/texts/text1/chapter1`. Whenever components change state e.g. due to a navigation
50
+ * event the standard parameters `path`, `lang` and `id` would be serialized into the
51
+ * URL path pattern rather than query parameters.
52
+ */
53
+ urlTemplate: {
54
+ type: String,
55
+ attribute: 'url-template',
56
+ },
57
+ /**
58
+ * A comma-separated list of parameter names which should not be reflected on the browser URL.
59
+ * Use this to exclude e.g. the default `odd` parameter of a pb-view to be shown in the
60
+ * browser URL.
61
+ */
62
+ urlIgnore: {
63
+ type: String,
64
+ attribute: 'url-ignore',
65
+ },
66
+ /**
67
+ * Is the resource path part of the URL or should it be
68
+ * encoded as a parameter? TEI Publisher uses the
69
+ * URL path, but the webcomponent demos need to encode the resource path
70
+ * in a query parameter.
71
+ */
72
+ urlPath: {
73
+ type: String,
74
+ attribute: 'url-path',
75
+ },
76
+ /**
77
+ * If enabled, a hash in the URL (e.g. documentation.xml#introduction) will
78
+ * be interpreted as an xml:id to navigate to when talking to the server.
79
+ */
80
+ idHash: {
81
+ type: Boolean,
82
+ attribute: 'id-hash',
83
+ },
84
+ /**
85
+ * TEI Publisher internal: set to the current page template.
86
+ */
87
+ template: {
88
+ type: String,
89
+ },
90
+ /**
91
+ * The base URL of the TEI Publisher instance. All nested elements will
92
+ * talk to this instance. By default it is set to the URL the
93
+ * page was loaded from.
94
+ *
95
+ * The endpoint can be overwritten by providing an HTTP request parameter
96
+ * `_target` with an URL.
97
+ */
98
+ endpoint: {
99
+ type: String,
100
+ reflect: true,
101
+ },
102
+ apiVersion: {
103
+ type: String,
104
+ attribute: 'api-version',
105
+ reflect: true,
106
+ },
107
+ /**
108
+ * Optional URL pointing to a directory from which additional i18n
109
+ * language files will be loaded. The URL should contain placeholders
110
+ * for the language (`lng`) and the namespace (`ns`), e.g.
111
+ *
112
+ * `resources/i18n/{{ns}}_{{lng}}.json`
113
+ *
114
+ * or
115
+ *
116
+ * `resources/i18n/{{ns}}/{{lng}}.json`
117
+ *
118
+ * The latter assumes custom language files in a subdirectory, the first
119
+ * expects the namespace to be specified at the start of the file name.
120
+ *
121
+ * The default namespace for custom language files is assumed to be `app`,
122
+ * but you can define additional namespaces via `localeFallbackNS`.
123
+ */
124
+ locales: {
125
+ type: String,
126
+ },
127
+ /**
128
+ * Optional list of whitespace separated namespaces which should be searched
129
+ * for translations. By default, only the namespace `common` is queried.
130
+ * If the `locales` property is specified, an additional namespace `app` is added.
131
+ * You can add more namespace here, e.g. `custom`, if you want to provide
132
+ * translations for custom apps or components.
133
+ */
134
+ localeFallbackNs: {
135
+ type: String,
136
+ attribute: 'locale-fallback-ns',
137
+ },
138
+ /**
139
+ * Comma-separated list of languages supported. If the detected language
140
+ * is not in this list, fall back to the configured fallback language.
141
+ */
142
+ supportedLanguages: {
143
+ type: Array,
144
+ attribute: 'supported-languages',
145
+ converter(value) {
146
+ return value.split(/\s*,\s*/);
147
+ },
148
+ },
149
+ /**
150
+ * The fallback language to use if the detected language is not supported.
151
+ * Defaults to 'en'.
152
+ */
153
+ fallbackLanguage: {
154
+ type: String,
155
+ attribute: 'fallback-language',
156
+ },
157
+ /**
158
+ * Set a language for i18n (e.g. 'en' or 'de'). If not set, browser language
159
+ * detection will be used.
160
+ */
161
+ language: {
162
+ type: String,
163
+ },
164
+ /**
165
+ * If set, the element will wait for a language being set by i18n before
166
+ * it sends a `pb-page-ready` event. Elements like `pb-view` will wait
167
+ * for this event before displaying content.
168
+ *
169
+ * Also, `pb-view` will pass the configured language to the server endpoint
170
+ * where it will be available to ODD processing models in variable
171
+ * `$parameters?language` and can thus be used to change output depending on
172
+ * the user interface language.
173
+ *
174
+ * If you would like `pb-view` to refresh automatically whenever the language
175
+ * setting changes, specify property `useLanguage` on the corresponding `pb-view`.
176
+ */
177
+ requireLanguage: {
178
+ type: Boolean,
179
+ attribute: 'require-language',
180
+ },
181
+ /**
182
+ * Will be set while the component is loading and unset when
183
+ * it is fully loaded. Use to avoid flash of unstyled content
184
+ * via CSS: set `unresolved` on `pb-page` in the HTML and
185
+ * add a CSS rule like:
186
+ *
187
+ * ```css
188
+ * pb-page[unresolved] {
189
+ * display: none;
190
+ * }
191
+ * ```
192
+ */
193
+ unresolved: {
194
+ type: Boolean,
195
+ reflect: true,
196
+ },
197
+ theme: {
198
+ type: String,
199
+ },
200
+ };
201
+ }
202
+
203
+ constructor() {
204
+ super();
205
+ this.unresolved = true;
206
+ this.endpoint = '.';
207
+ this.urlTemplate = null;
208
+ this.urlIgnore = null;
209
+ this.urlPath = 'path';
210
+ this.idHash = false;
211
+ this.apiVersion = undefined;
212
+ this.requireLanguage = false;
213
+ this.supportedLanguages = null;
214
+ this.fallbackLanguage = 'en';
215
+ this.theme = null;
216
+ this._localeFallbacks = [];
217
+ this._i18nInstance = null;
218
+
219
+ if (_instance) {
220
+ this.disabled = true;
221
+ } else {
222
+ _instance = this;
223
+
224
+ // clear global page events which might have been set by other pb-page instances.
225
+ // important while running the test suite.
226
+ clearPageEvents();
202
227
  }
203
-
204
- constructor() {
205
- super();
206
- this.unresolved = true;
207
- this.endpoint = ".";
208
- this.urlTemplate = null;
209
- this.urlIgnore = null;
210
- this.urlPath = 'path';
211
- this.idHash = false;
212
- this.apiVersion = undefined;
213
- this.requireLanguage = false;
214
- this.supportedLanguages = null;
215
- this.fallbackLanguage = 'en';
216
- this.theme = null;
217
- this._localeFallbacks = [];
218
- this._i18nInstance = null;
219
-
220
- if (_instance) {
221
- this.disabled = true;
222
- } else {
223
- _instance = this;
224
-
225
- // clear global page events which might have been set by other pb-page instances.
226
- // important while running the test suite.
227
- clearPageEvents();
228
- }
228
+ }
229
+
230
+ set localeFallbackNs(value) {
231
+ value.split(/\s+/).forEach(v => this._localeFallbacks.push(v));
232
+ }
233
+
234
+ disconnectedCallback() {
235
+ super.disconnectedCallback();
236
+ this._i18nInstance = null;
237
+ if (_instance === this) {
238
+ // clear to allow future instances
239
+ _instance = null;
229
240
  }
241
+ }
230
242
 
231
- set localeFallbackNs(value) {
232
- value.split(/\s+/).forEach(v => this._localeFallbacks.push(v));
233
- }
243
+ async connectedCallback() {
244
+ super.connectedCallback();
234
245
 
235
- disconnectedCallback() {
236
- super.disconnectedCallback();
237
- this._i18nInstance = null;
238
- if (_instance === this) {
239
- // clear to allow future instances
240
- _instance = null;
241
- }
246
+ if (this.disabled) {
247
+ return;
242
248
  }
243
249
 
244
- async connectedCallback() {
245
- super.connectedCallback();
246
-
247
- if (this.disabled) {
248
- return;
249
- }
250
+ registry.configure(
251
+ this.urlPath === 'path',
252
+ this.idHash,
253
+ this.appRoot,
254
+ this.urlTemplate,
255
+ this.urlIgnore,
256
+ );
250
257
 
251
- registry.configure(this.urlPath === 'path', this.idHash, this.appRoot, this.urlTemplate, this.urlIgnore);
258
+ this.endpoint = this.endpoint.replace(/\/+$/, '');
252
259
 
253
- this.endpoint = this.endpoint.replace(/\/+$/, '');
254
-
255
- if (this.locales && this._localeFallbacks.indexOf('app') === -1) {
256
- this._localeFallbacks.push('app');
257
- }
258
- this._localeFallbacks.push('common');
259
-
260
- const target = registry.state._target;
261
- if (target) {
262
- this.endpoint = target;
263
- }
264
-
265
- const apiVersion = registry.state._api;
266
- if (apiVersion) {
267
- this.apiVersion = apiVersion;
268
- }
269
-
270
- const stylesheetURLs = [];
271
- if (this.theme) {
272
- stylesheetURLs.push(this.toAbsoluteURL(this.theme, this.endpoint));
273
- } else {
274
- stylesheetURLs.push('components.css');
275
- }
276
- console.log('<pb-page> Loading component theme stylesheets from %s', stylesheetURLs.join(', '));
277
- this._themeSheet = await loadStylesheets(stylesheetURLs);
278
-
279
- // try to figure out what version of TEI Publisher the server is running
280
- if (!this.apiVersion) {
281
- // first check if it has a login endpoint, i.e. runs a version < 7
282
- // this is necessary to prevent a CORS failure
283
- const json = await fetch(`${this.endpoint}/login`)
284
- .then((res) => {
285
- if (res.ok) {
286
- return null;
287
- }
288
- // if not, access the actual /api/version endpoint to retrieve the API version
289
- return fetch(`${this.endpoint}/api/version`)
290
- .then((res2) => res2.json());
291
- })
292
- .catch(() => fetch(`${this.endpoint}/api/version`)
293
- .then((res2) => res2.json())
294
- );
295
-
296
- if (json) {
297
- this.apiVersion = json.api;
298
- console.log(`<pb-page> Server reports API version ${this.apiVersion} with app ${json.app.name}/${json.app.version} running on ${json.engine.name}/${json.engine.version}`);
299
- } else {
300
- console.log('<pb-page> No API version reported by server, assuming 0.9.0');
301
- this.apiVersion = '0.9.0';
302
- }
303
- }
304
-
305
- if (!this.requireLanguage) {
306
- this.signalReady('pb-page-ready', {
307
- endpoint: this.endpoint,
308
- template: this.template,
309
- apiVersion: this.apiVersion
310
- });
311
- } else if (this._i18nInstance) {
312
- this.signalReady('pb-page-ready', {
313
- endpoint: this.endpoint,
314
- apiVersion: this.apiVersion,
315
- template: this.template,
316
- language: this._i18nInstance.language
317
- });
318
- }
260
+ if (this.locales && this._localeFallbacks.indexOf('app') === -1) {
261
+ this._localeFallbacks.push('app');
319
262
  }
263
+ this._localeFallbacks.push('common');
320
264
 
321
- firstUpdated() {
322
- super.firstUpdated();
323
-
324
- if (this.disabled) {
325
- return;
326
- }
327
-
328
- const slot = this.shadowRoot.querySelector('slot');
329
- slot.addEventListener('slotchange', () => {
330
- const ev = new CustomEvent('pb-page-loaded', {
331
- bubbles: true,
332
- composed: true
333
- });
334
- this.dispatchEvent(ev);
335
- }, { once: true });
336
-
337
- const defaultLocales = resolveURL('../i18n/') + '{{ns}}/{{lng}}.json';
338
- console.log('<pb-page> Loading locales. common: %s; additional: %s; namespaces: %o',
339
- defaultLocales, this.locales, this._localeFallbacks);
340
- const backends = this.locales ? [XHR, XHR] : [XHR];
341
- const backendOptions = [{
342
- loadPath: defaultLocales,
343
- crossDomain: true
344
- }];
345
- if (this.locales) {
346
- backendOptions.unshift({
347
- loadPath: this.locales,
348
- crossDomain: true
349
- });
350
- }
351
- const options = {
352
- fallbackLng: this.fallbackLanguage,
353
- defaultNS: 'common',
354
- ns: ['common'],
355
- debug: false,
356
- load: 'languageOnly',
357
- detection: {
358
- lookupQuerystring: 'lang'
359
- },
360
- backend: {
361
- backends,
362
- backendOptions
363
- }
364
- };
365
- if (this.language) {
366
- options.lng = this.language;
367
- }
368
- console.log('supported langs: %o', this.supportedLanguages);
369
- if (this.supportedLanguages) {
370
- options.supportedLngs = this.supportedLanguages;
371
- }
372
-
373
- if (this._localeFallbacks.length > 0) {
374
- const fallbacks = this._localeFallbacks.slice();
375
- options.defaultNS = fallbacks[0];
376
- options.fallbackNS = fallbacks.slice(1);
377
- options.ns = fallbacks;
378
- }
379
- console.log('<pb-page> i18next options: %o', options);
380
- this._i18nInstance = i18next.createInstance();
381
- this._i18nInstance
382
- .use(LanguageDetector)
383
- .use(Backend);
384
- this._i18nInstance.init(options)
385
- .then((t) => {
386
- initTranslation(t);
387
- // initialized and ready to go!
388
- this._updateI18n(t);
389
- this.signalReady('pb-i18n-update', { t, language: this._i18nInstance.language });
390
- if (this.requireLanguage && this.apiVersion) {
391
- this.signalReady('pb-page-ready', {
392
- endpoint: this.endpoint,
393
- apiVersion: this.apiVersion,
394
- template: this.template,
395
- language: this._i18nInstance.language
396
- });
397
- }
398
- });
265
+ const target = registry.state._target;
266
+ if (target) {
267
+ this.endpoint = target;
268
+ }
399
269
 
400
- this.subscribeTo('pb-i18n-language', ev => {
401
- const { language } = ev.detail;
402
- this._i18nInstance.changeLanguage(language).then(t => {
403
- this._updateI18n(t);
404
- this.emitTo('pb-i18n-update', { t, language: this._i18nInstance.language }, []);
405
- }, []);
406
- });
270
+ const apiVersion = registry.state._api;
271
+ if (apiVersion) {
272
+ this.apiVersion = apiVersion;
273
+ }
407
274
 
275
+ const stylesheetURLs = [];
276
+ if (this.theme) {
277
+ stylesheetURLs.push(this.toAbsoluteURL(this.theme, this.endpoint));
278
+ } else {
279
+ stylesheetURLs.push('components.css');
280
+ }
281
+ console.log('<pb-page> Loading component theme stylesheets from %s', stylesheetURLs.join(', '));
282
+ this._themeSheet = await loadStylesheets(stylesheetURLs);
283
+
284
+ // try to figure out what version of TEI Publisher the server is running
285
+ if (!this.apiVersion) {
286
+ // first check if it has a login endpoint, i.e. runs a version < 7
287
+ // this is necessary to prevent a CORS failure
288
+ const json = await fetch(`${this.endpoint}/login`)
289
+ .then(res => {
290
+ if (res.ok) {
291
+ return null;
292
+ }
293
+ // if not, access the actual /api/version endpoint to retrieve the API version
294
+ return fetch(`${this.endpoint}/api/version`).then(res2 => res2.json());
295
+ })
296
+ .catch(() => fetch(`${this.endpoint}/api/version`).then(res2 => res2.json()));
297
+
298
+ if (json) {
299
+ this.apiVersion = json.api;
300
+ console.log(
301
+ `<pb-page> Server reports API version ${this.apiVersion} with app ${json.app.name}/${json.app.version} running on ${json.engine.name}/${json.engine.version}`,
302
+ );
303
+ } else {
304
+ console.log('<pb-page> No API version reported by server, assuming 0.9.0');
305
+ this.apiVersion = '0.9.0';
306
+ }
307
+ }
408
308
 
409
- // this.subscribeTo('pb-global-toggle', this._toggleFeatures.bind(this));
410
- this.addEventListener('pb-global-toggle', this._toggleFeatures.bind(this));
411
- this.unresolved = false;
309
+ if (!this.requireLanguage) {
310
+ this.signalReady('pb-page-ready', {
311
+ endpoint: this.endpoint,
312
+ template: this.template,
313
+ apiVersion: this.apiVersion,
314
+ });
315
+ } else if (this._i18nInstance) {
316
+ this.signalReady('pb-page-ready', {
317
+ endpoint: this.endpoint,
318
+ apiVersion: this.apiVersion,
319
+ template: this.template,
320
+ language: this._i18nInstance.language,
321
+ });
322
+ }
323
+ }
412
324
 
413
- console.log('<pb-page> endpoint: %s; trigger window resize', this.endpoint);
414
- this.querySelectorAll('app-header').forEach(h => h._notifyLayoutChanged());
325
+ firstUpdated() {
326
+ super.firstUpdated();
415
327
 
416
- typesetMath(this);
328
+ if (this.disabled) {
329
+ return;
417
330
  }
418
331
 
419
- _updateI18n(t) {
420
- this.querySelectorAll('[data-i18n]').forEach(elem => {
421
- const targets = elem.getAttribute('data-i18n');
422
- const regex = /(?:\[([^\]]+)\])?([^;]+)/g;
423
- let m = regex.exec(targets);
424
- while (m) {
425
- const translated = t(m[2]);
426
- if (m[1]) {
427
- elem.setAttribute(m[1], translated);
428
- } else {
429
- elem.innerHTML = translated;
430
- }
431
- m = regex.exec(targets);
432
- }
332
+ const slot = this.shadowRoot.querySelector('slot');
333
+ slot.addEventListener(
334
+ 'slotchange',
335
+ () => {
336
+ const ev = new CustomEvent('pb-page-loaded', {
337
+ bubbles: true,
338
+ composed: true,
433
339
  });
340
+ this.dispatchEvent(ev);
341
+ },
342
+ { once: true },
343
+ );
344
+
345
+ const defaultLocales = `${resolveURL('../i18n/')}{{ns}}/{{lng}}.json`;
346
+ console.log(
347
+ '<pb-page> Loading locales. common: %s; additional: %s; namespaces: %o',
348
+ defaultLocales,
349
+ this.locales,
350
+ this._localeFallbacks,
351
+ );
352
+ const backends = this.locales ? [XHR, XHR] : [XHR];
353
+ const backendOptions = [
354
+ {
355
+ loadPath: defaultLocales,
356
+ crossDomain: true,
357
+ },
358
+ ];
359
+ if (this.locales) {
360
+ backendOptions.unshift({
361
+ loadPath: this.locales,
362
+ crossDomain: true,
363
+ });
434
364
  }
435
-
436
- get stylesheet() {
437
- return this._themeSheet;
365
+ const options = {
366
+ fallbackLng: this.fallbackLanguage,
367
+ defaultNS: 'common',
368
+ ns: ['common'],
369
+ debug: false,
370
+ load: 'languageOnly',
371
+ detection: {
372
+ lookupQuerystring: 'lang',
373
+ },
374
+ backend: {
375
+ backends,
376
+ backendOptions,
377
+ },
378
+ };
379
+ if (this.language) {
380
+ options.lng = this.language;
438
381
  }
439
-
440
- /**
441
- * Handle the `pb-toggle` event sent by `pb-select-feature` or `pb-toggle-feature`
442
- * and dispatch actions to the elements on the page.
443
- */
444
- _toggleFeatures(ev) {
445
- const sc = ev.detail;
446
- this.querySelectorAll(sc.selector).forEach(node => {
447
- const command = sc.command || 'toggle';
448
- if (node.command) {
449
- node.command(command, sc.state);
450
- }
451
- if (sc.state) {
452
- node.classList.add(command);
453
- } else {
454
- node.classList.remove(command);
455
- }
456
- });
382
+ console.log('supported langs: %o', this.supportedLanguages);
383
+ if (this.supportedLanguages) {
384
+ options.supportedLngs = this.supportedLanguages;
457
385
  }
458
386
 
459
- render() {
460
- return html`<slot></slot>`;
387
+ if (this._localeFallbacks.length > 0) {
388
+ const fallbacks = this._localeFallbacks.slice();
389
+ options.defaultNS = fallbacks[0];
390
+ options.fallbackNS = fallbacks.slice(1);
391
+ options.ns = fallbacks;
461
392
  }
462
-
463
- static get styles() {
464
- return css`
465
- :host {
466
- display: block;
393
+ console.log('<pb-page> i18next options: %o', options);
394
+ this._i18nInstance = i18next.createInstance();
395
+ this._i18nInstance.use(LanguageDetector).use(Backend);
396
+ this._i18nInstance.init(options).then(t => {
397
+ initTranslation(t);
398
+ // initialized and ready to go!
399
+ this._updateI18n(t);
400
+ this.signalReady('pb-i18n-update', { t, language: this._i18nInstance.language });
401
+ if (this.requireLanguage && this.apiVersion) {
402
+ this.signalReady('pb-page-ready', {
403
+ endpoint: this.endpoint,
404
+ apiVersion: this.apiVersion,
405
+ template: this.template,
406
+ language: this._i18nInstance.language,
407
+ });
408
+ }
409
+ });
410
+
411
+ this.subscribeTo('pb-i18n-language', ev => {
412
+ const { language } = ev.detail;
413
+ this._i18nInstance.changeLanguage(language).then(t => {
414
+ this._updateI18n(t);
415
+ this.emitTo('pb-i18n-update', { t, language: this._i18nInstance.language }, []);
416
+ }, []);
417
+ });
418
+
419
+ // this.subscribeTo('pb-global-toggle', this._toggleFeatures.bind(this));
420
+ this.addEventListener('pb-global-toggle', this._toggleFeatures.bind(this));
421
+ this.unresolved = false;
422
+
423
+ console.log('<pb-page> endpoint: %s; trigger window resize', this.endpoint);
424
+ this.querySelectorAll('app-header').forEach(h => h._notifyLayoutChanged());
425
+
426
+ typesetMath(this);
427
+ }
428
+
429
+ _updateI18n(t) {
430
+ this.querySelectorAll('[data-i18n]').forEach(elem => {
431
+ const targets = elem.getAttribute('data-i18n');
432
+ const regex = /(?:\[([^\]]+)\])?([^;]+)/g;
433
+ let m = regex.exec(targets);
434
+ while (m) {
435
+ const translated = t(m[2]);
436
+ if (m[1]) {
437
+ elem.setAttribute(m[1], translated);
438
+ } else {
439
+ elem.innerHTML = translated;
467
440
  }
468
- `;
469
- }
441
+ m = regex.exec(targets);
442
+ }
443
+ });
444
+ }
445
+
446
+ get stylesheet() {
447
+ return this._themeSheet;
448
+ }
449
+
450
+ /**
451
+ * Handle the `pb-toggle` event sent by `pb-select-feature` or `pb-toggle-feature`
452
+ * and dispatch actions to the elements on the page.
453
+ */
454
+ _toggleFeatures(ev) {
455
+ const sc = ev.detail;
456
+ this.querySelectorAll(sc.selector).forEach(node => {
457
+ const command = sc.command || 'toggle';
458
+ if (node.command) {
459
+ node.command(command, sc.state);
460
+ }
461
+ if (sc.state) {
462
+ node.classList.add(command);
463
+ } else {
464
+ node.classList.remove(command);
465
+ }
466
+ });
467
+ }
468
+
469
+ render() {
470
+ return html`<slot></slot>`;
471
+ }
472
+
473
+ static get styles() {
474
+ return css`
475
+ :host {
476
+ display: block;
477
+ }
478
+ `;
479
+ }
470
480
  }
471
481
 
472
- customElements.define('pb-page', PbPage);
482
+ customElements.define('pb-page', PbPage);