@teipublisher/pb-components 2.25.4 → 2.25.6

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 (130) hide show
  1. package/.github/workflows/main.yml +3 -3
  2. package/.github/workflows/node.js.yml +3 -3
  3. package/.github/workflows/release.js.yml +4 -4
  4. package/.releaserc.json +1 -1
  5. package/CHANGELOG.md +15 -0
  6. package/Dockerfile +78 -70
  7. package/css/components.css +5 -5
  8. package/dist/demo/pb-drawer2.html +1 -1
  9. package/dist/demo/pb-leaflet-map.html +1 -1
  10. package/dist/demo/pb-repeat.html +1 -3
  11. package/dist/demo/pb-view3.html +1 -1
  12. package/dist/{paper-icon-button-0fb125c4.js → paper-icon-button-72125e67.js} +1 -1
  13. package/dist/pb-code-editor.js +25 -20
  14. package/dist/pb-component-docs.js +58 -54
  15. package/dist/pb-components-bundle.js +1827 -1520
  16. package/dist/pb-edit-app.js +167 -107
  17. package/dist/pb-elements.json +54 -54
  18. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  19. package/dist/pb-leaflet-map.js +23 -23
  20. package/dist/pb-mei.js +56 -41
  21. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  22. package/dist/pb-odd-editor.js +925 -758
  23. package/dist/pb-tify.js +2 -2
  24. package/dist/{vaadin-element-mixin-859a0132.js → vaadin-element-mixin-ad07ba25.js} +88 -61
  25. package/gh-pages.js +5 -3
  26. package/i18n/common/pl.json +2 -2
  27. package/package.json +2 -2
  28. package/pb-elements.json +54 -54
  29. package/src/assets/components.css +5 -5
  30. package/src/authority/airtable.js +20 -21
  31. package/src/authority/anton.js +129 -129
  32. package/src/authority/custom.js +23 -21
  33. package/src/authority/geonames.js +38 -32
  34. package/src/authority/gnd.js +47 -42
  35. package/src/authority/kbga.js +137 -134
  36. package/src/authority/metagrid.js +44 -46
  37. package/src/authority/reconciliation.js +66 -67
  38. package/src/authority/registry.js +4 -4
  39. package/src/docs/pb-component-docs.js +2 -2
  40. package/src/docs/pb-component-view.js +5 -5
  41. package/src/docs/pb-components-list.js +2 -2
  42. package/src/docs/pb-demo-snippet.js +2 -2
  43. package/src/dts-client.js +299 -297
  44. package/src/dts-select-endpoint.js +90 -82
  45. package/src/parse-date-service.js +184 -135
  46. package/src/pb-ajax.js +171 -167
  47. package/src/pb-authority-lookup.js +96 -81
  48. package/src/pb-autocomplete.js +292 -280
  49. package/src/pb-blacklab-highlight.js +264 -259
  50. package/src/pb-blacklab-results.js +236 -221
  51. package/src/pb-browse-docs.js +540 -475
  52. package/src/pb-browse.js +68 -65
  53. package/src/pb-clipboard.js +79 -76
  54. package/src/pb-code-editor.js +110 -102
  55. package/src/pb-code-highlight.js +209 -204
  56. package/src/pb-codepen.js +79 -72
  57. package/src/pb-collapse.js +149 -146
  58. package/src/pb-combo-box.js +190 -190
  59. package/src/pb-components-bundle.js +1 -1
  60. package/src/pb-custom-form.js +150 -149
  61. package/src/pb-document.js +89 -90
  62. package/src/pb-download.js +208 -195
  63. package/src/pb-drawer.js +145 -148
  64. package/src/pb-edit-app.js +301 -229
  65. package/src/pb-edit-xml.js +99 -96
  66. package/src/pb-events.js +114 -107
  67. package/src/pb-facs-link.js +104 -102
  68. package/src/pb-facsimile.js +411 -413
  69. package/src/pb-formula.js +151 -153
  70. package/src/pb-geolocation.js +129 -131
  71. package/src/pb-grid-action.js +53 -56
  72. package/src/pb-grid.js +231 -228
  73. package/src/pb-highlight.js +140 -140
  74. package/src/pb-hotkeys.js +40 -42
  75. package/src/pb-i18n.js +101 -104
  76. package/src/pb-image-strip.js +84 -78
  77. package/src/pb-lang.js +83 -70
  78. package/src/pb-leaflet-map.js +488 -485
  79. package/src/pb-link.js +126 -124
  80. package/src/pb-load.js +431 -426
  81. package/src/pb-login.js +275 -254
  82. package/src/pb-manage-odds.js +364 -318
  83. package/src/pb-map-icon.js +89 -89
  84. package/src/pb-map-layer.js +85 -85
  85. package/src/pb-markdown.js +90 -99
  86. package/src/pb-media-query.js +74 -72
  87. package/src/pb-mei.js +306 -295
  88. package/src/pb-message.js +143 -130
  89. package/src/pb-mixin.js +269 -264
  90. package/src/pb-navigation.js +80 -82
  91. package/src/pb-observable.js +38 -38
  92. package/src/pb-odd-editor.js +1056 -958
  93. package/src/pb-odd-elementspec-editor.js +348 -297
  94. package/src/pb-odd-model-editor.js +1058 -898
  95. package/src/pb-odd-parameter-editor.js +200 -178
  96. package/src/pb-odd-rendition-editor.js +136 -124
  97. package/src/pb-page.js +432 -422
  98. package/src/pb-paginate.js +202 -190
  99. package/src/pb-panel.js +191 -179
  100. package/src/pb-popover-themes.js +7 -5
  101. package/src/pb-popover.js +296 -287
  102. package/src/pb-print-preview.js +127 -127
  103. package/src/pb-progress.js +49 -49
  104. package/src/pb-repeat.js +105 -104
  105. package/src/pb-restricted.js +84 -77
  106. package/src/pb-search.js +238 -221
  107. package/src/pb-select-feature.js +127 -120
  108. package/src/pb-select-odd.js +132 -124
  109. package/src/pb-select-template.js +89 -78
  110. package/src/pb-select.js +251 -227
  111. package/src/pb-split-list.js +179 -174
  112. package/src/pb-svg.js +80 -79
  113. package/src/pb-table-column.js +54 -54
  114. package/src/pb-table-grid.js +221 -203
  115. package/src/pb-tabs.js +61 -63
  116. package/src/pb-tify.js +154 -154
  117. package/src/pb-timeline.js +271 -229
  118. package/src/pb-toggle-feature.js +198 -185
  119. package/src/pb-upload.js +184 -174
  120. package/src/pb-version.js +30 -30
  121. package/src/pb-view-annotate.js +132 -98
  122. package/src/pb-view.js +1282 -1263
  123. package/src/pb-zoom.js +40 -40
  124. package/src/polymer-hack.js +1 -1
  125. package/src/search-result-service.js +256 -223
  126. package/src/seed-element.js +13 -20
  127. package/src/settings.js +4 -4
  128. package/src/theming.js +91 -91
  129. package/src/urls.js +289 -289
  130. 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,446 +28,456 @@ 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
-
251
- registry.configure(this.urlPath === 'path', this.idHash, this.appRoot, this.urlTemplate, this.urlIgnore);
252
-
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
- }
250
+ registry.configure(
251
+ this.urlPath === 'path',
252
+ this.idHash,
253
+ this.appRoot,
254
+ this.urlTemplate,
255
+ this.urlIgnore,
256
+ );
269
257
 
270
- const stylesheetURLs = [
271
- // TODO: replace with this.toAbsoluteURL
272
- this.toAbsoluteURL('resources/css/components.css', this.endpoint)
273
- ];
274
- if (this.theme) {
275
- stylesheetURLs.push(this.toAbsoluteURL(this.theme, this.endpoint));
276
- }
277
- console.log('<pb-page> Loading component theme stylesheets from %s', stylesheetURLs.join(', '));
278
- this._themeSheet = await loadStylesheets(stylesheetURLs);
279
-
280
- // try to figure out what version of TEI Publisher the server is running
281
- if (!this.apiVersion) {
282
- // first check if it has a login endpoint, i.e. runs a version < 7
283
- // this is necessary to prevent a CORS failure
284
- const json = await fetch(`${this.endpoint}/login`)
285
- .then((res) => {
286
- if (res.ok) {
287
- return null;
288
- }
289
- // if not, access the actual /api/version endpoint to retrieve the API version
290
- return fetch(`${this.endpoint}/api/version`)
291
- .then((res2) => res2.json());
292
- })
293
- .catch(() => fetch(`${this.endpoint}/api/version`)
294
- .then((res2) => res2.json())
295
- );
296
-
297
- if (json) {
298
- this.apiVersion = json.api;
299
- 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}`);
300
- } else {
301
- console.log('<pb-page> No API version reported by server, assuming 0.9.0');
302
- this.apiVersion = '0.9.0';
303
- }
304
- }
258
+ this.endpoint = this.endpoint.replace(/\/+$/, '');
305
259
 
306
- if (!this.requireLanguage) {
307
- this.signalReady('pb-page-ready', {
308
- endpoint: this.endpoint,
309
- template: this.template,
310
- apiVersion: this.apiVersion
311
- });
312
- } else if (this._i18nInstance) {
313
- this.signalReady('pb-page-ready', {
314
- endpoint: this.endpoint,
315
- apiVersion: this.apiVersion,
316
- template: this.template,
317
- language: this._i18nInstance.language
318
- });
319
- }
260
+ if (this.locales && this._localeFallbacks.indexOf('app') === -1) {
261
+ this._localeFallbacks.push('app');
320
262
  }
263
+ this._localeFallbacks.push('common');
321
264
 
322
- firstUpdated() {
323
- super.firstUpdated();
324
-
325
- if (this.disabled) {
326
- return;
327
- }
328
-
329
- const slot = this.shadowRoot.querySelector('slot');
330
- slot.addEventListener('slotchange', () => {
331
- const ev = new CustomEvent('pb-page-loaded', {
332
- bubbles: true,
333
- composed: true
334
- });
335
- this.dispatchEvent(ev);
336
- }, { once: true });
337
-
338
- const defaultLocales = resolveURL('../i18n/') + '{{ns}}/{{lng}}.json';
339
- console.log('<pb-page> Loading locales. common: %s; additional: %s; namespaces: %o',
340
- defaultLocales, this.locales, this._localeFallbacks);
341
- const backends = this.locales ? [XHR, XHR] : [XHR];
342
- const backendOptions = [{
343
- loadPath: defaultLocales,
344
- crossDomain: true
345
- }];
346
- if (this.locales) {
347
- backendOptions.unshift({
348
- loadPath: this.locales,
349
- crossDomain: true
350
- });
351
- }
352
- const options = {
353
- fallbackLng: this.fallbackLanguage,
354
- defaultNS: 'common',
355
- ns: ['common'],
356
- debug: false,
357
- load: 'languageOnly',
358
- detection: {
359
- lookupQuerystring: 'lang'
360
- },
361
- backend: {
362
- backends,
363
- backendOptions
364
- }
365
- };
366
- if (this.language) {
367
- options.lng = this.language;
368
- }
369
- console.log('supported langs: %o', this.supportedLanguages);
370
- if (this.supportedLanguages) {
371
- options.supportedLngs = this.supportedLanguages;
372
- }
373
-
374
- if (this._localeFallbacks.length > 0) {
375
- const fallbacks = this._localeFallbacks.slice();
376
- options.defaultNS = fallbacks[0];
377
- options.fallbackNS = fallbacks.slice(1);
378
- options.ns = fallbacks;
379
- }
380
- console.log('<pb-page> i18next options: %o', options);
381
- this._i18nInstance = i18next.createInstance();
382
- this._i18nInstance
383
- .use(LanguageDetector)
384
- .use(Backend);
385
- this._i18nInstance.init(options)
386
- .then((t) => {
387
- initTranslation(t);
388
- // initialized and ready to go!
389
- this._updateI18n(t);
390
- this.signalReady('pb-i18n-update', { t, language: this._i18nInstance.language });
391
- if (this.requireLanguage && this.apiVersion) {
392
- this.signalReady('pb-page-ready', {
393
- endpoint: this.endpoint,
394
- apiVersion: this.apiVersion,
395
- template: this.template,
396
- language: this._i18nInstance.language
397
- });
398
- }
399
- });
265
+ const target = registry.state._target;
266
+ if (target) {
267
+ this.endpoint = target;
268
+ }
400
269
 
401
- this.subscribeTo('pb-i18n-language', ev => {
402
- const { language } = ev.detail;
403
- this._i18nInstance.changeLanguage(language).then(t => {
404
- this._updateI18n(t);
405
- this.emitTo('pb-i18n-update', { t, language: this._i18nInstance.language }, []);
406
- }, []);
407
- });
270
+ const apiVersion = registry.state._api;
271
+ if (apiVersion) {
272
+ this.apiVersion = apiVersion;
273
+ }
408
274
 
275
+ const stylesheetURLs = [
276
+ // TODO: replace with this.toAbsoluteURL
277
+ this.toAbsoluteURL('resources/css/components.css', this.endpoint),
278
+ ];
279
+ if (this.theme) {
280
+ stylesheetURLs.push(this.toAbsoluteURL(this.theme, this.endpoint));
281
+ }
282
+ console.log('<pb-page> Loading component theme stylesheets from %s', stylesheetURLs.join(', '));
283
+ this._themeSheet = await loadStylesheets(stylesheetURLs);
284
+
285
+ // try to figure out what version of TEI Publisher the server is running
286
+ if (!this.apiVersion) {
287
+ // first check if it has a login endpoint, i.e. runs a version < 7
288
+ // this is necessary to prevent a CORS failure
289
+ const json = await fetch(`${this.endpoint}/login`)
290
+ .then(res => {
291
+ if (res.ok) {
292
+ return null;
293
+ }
294
+ // if not, access the actual /api/version endpoint to retrieve the API version
295
+ return fetch(`${this.endpoint}/api/version`).then(res2 => res2.json());
296
+ })
297
+ .catch(() => fetch(`${this.endpoint}/api/version`).then(res2 => res2.json()));
298
+
299
+ if (json) {
300
+ this.apiVersion = json.api;
301
+ console.log(
302
+ `<pb-page> Server reports API version ${this.apiVersion} with app ${json.app.name}/${json.app.version} running on ${json.engine.name}/${json.engine.version}`,
303
+ );
304
+ } else {
305
+ console.log('<pb-page> No API version reported by server, assuming 0.9.0');
306
+ this.apiVersion = '0.9.0';
307
+ }
308
+ }
409
309
 
410
- // this.subscribeTo('pb-global-toggle', this._toggleFeatures.bind(this));
411
- this.addEventListener('pb-global-toggle', this._toggleFeatures.bind(this));
412
- this.unresolved = false;
310
+ if (!this.requireLanguage) {
311
+ this.signalReady('pb-page-ready', {
312
+ endpoint: this.endpoint,
313
+ template: this.template,
314
+ apiVersion: this.apiVersion,
315
+ });
316
+ } else if (this._i18nInstance) {
317
+ this.signalReady('pb-page-ready', {
318
+ endpoint: this.endpoint,
319
+ apiVersion: this.apiVersion,
320
+ template: this.template,
321
+ language: this._i18nInstance.language,
322
+ });
323
+ }
324
+ }
413
325
 
414
- console.log('<pb-page> endpoint: %s; trigger window resize', this.endpoint);
415
- this.querySelectorAll('app-header').forEach(h => h._notifyLayoutChanged());
326
+ firstUpdated() {
327
+ super.firstUpdated();
416
328
 
417
- typesetMath(this);
329
+ if (this.disabled) {
330
+ return;
418
331
  }
419
332
 
420
- _updateI18n(t) {
421
- this.querySelectorAll('[data-i18n]').forEach(elem => {
422
- const targets = elem.getAttribute('data-i18n');
423
- const regex = /(?:\[([^\]]+)\])?([^;]+)/g;
424
- let m = regex.exec(targets);
425
- while (m) {
426
- const translated = t(m[2]);
427
- if (m[1]) {
428
- elem.setAttribute(m[1], translated);
429
- } else {
430
- elem.innerHTML = translated;
431
- }
432
- m = regex.exec(targets);
433
- }
333
+ const slot = this.shadowRoot.querySelector('slot');
334
+ slot.addEventListener(
335
+ 'slotchange',
336
+ () => {
337
+ const ev = new CustomEvent('pb-page-loaded', {
338
+ bubbles: true,
339
+ composed: true,
434
340
  });
341
+ this.dispatchEvent(ev);
342
+ },
343
+ { once: true },
344
+ );
345
+
346
+ const defaultLocales = `${resolveURL('../i18n/')}{{ns}}/{{lng}}.json`;
347
+ console.log(
348
+ '<pb-page> Loading locales. common: %s; additional: %s; namespaces: %o',
349
+ defaultLocales,
350
+ this.locales,
351
+ this._localeFallbacks,
352
+ );
353
+ const backends = this.locales ? [XHR, XHR] : [XHR];
354
+ const backendOptions = [
355
+ {
356
+ loadPath: defaultLocales,
357
+ crossDomain: true,
358
+ },
359
+ ];
360
+ if (this.locales) {
361
+ backendOptions.unshift({
362
+ loadPath: this.locales,
363
+ crossDomain: true,
364
+ });
435
365
  }
436
-
437
- get stylesheet() {
438
- return this._themeSheet;
366
+ const options = {
367
+ fallbackLng: this.fallbackLanguage,
368
+ defaultNS: 'common',
369
+ ns: ['common'],
370
+ debug: false,
371
+ load: 'languageOnly',
372
+ detection: {
373
+ lookupQuerystring: 'lang',
374
+ },
375
+ backend: {
376
+ backends,
377
+ backendOptions,
378
+ },
379
+ };
380
+ if (this.language) {
381
+ options.lng = this.language;
439
382
  }
440
-
441
- /**
442
- * Handle the `pb-toggle` event sent by `pb-select-feature` or `pb-toggle-feature`
443
- * and dispatch actions to the elements on the page.
444
- */
445
- _toggleFeatures(ev) {
446
- const sc = ev.detail;
447
- this.querySelectorAll(sc.selector).forEach(node => {
448
- const command = sc.command || 'toggle';
449
- if (node.command) {
450
- node.command(command, sc.state);
451
- }
452
- if (sc.state) {
453
- node.classList.add(command);
454
- } else {
455
- node.classList.remove(command);
456
- }
457
- });
383
+ console.log('supported langs: %o', this.supportedLanguages);
384
+ if (this.supportedLanguages) {
385
+ options.supportedLngs = this.supportedLanguages;
458
386
  }
459
387
 
460
- render() {
461
- return html`<slot></slot>`;
388
+ if (this._localeFallbacks.length > 0) {
389
+ const fallbacks = this._localeFallbacks.slice();
390
+ options.defaultNS = fallbacks[0];
391
+ options.fallbackNS = fallbacks.slice(1);
392
+ options.ns = fallbacks;
462
393
  }
463
-
464
- static get styles() {
465
- return css`
466
- :host {
467
- display: block;
394
+ console.log('<pb-page> i18next options: %o', options);
395
+ this._i18nInstance = i18next.createInstance();
396
+ this._i18nInstance.use(LanguageDetector).use(Backend);
397
+ this._i18nInstance.init(options).then(t => {
398
+ initTranslation(t);
399
+ // initialized and ready to go!
400
+ this._updateI18n(t);
401
+ this.signalReady('pb-i18n-update', { t, language: this._i18nInstance.language });
402
+ if (this.requireLanguage && this.apiVersion) {
403
+ this.signalReady('pb-page-ready', {
404
+ endpoint: this.endpoint,
405
+ apiVersion: this.apiVersion,
406
+ template: this.template,
407
+ language: this._i18nInstance.language,
408
+ });
409
+ }
410
+ });
411
+
412
+ this.subscribeTo('pb-i18n-language', ev => {
413
+ const { language } = ev.detail;
414
+ this._i18nInstance.changeLanguage(language).then(t => {
415
+ this._updateI18n(t);
416
+ this.emitTo('pb-i18n-update', { t, language: this._i18nInstance.language }, []);
417
+ }, []);
418
+ });
419
+
420
+ // this.subscribeTo('pb-global-toggle', this._toggleFeatures.bind(this));
421
+ this.addEventListener('pb-global-toggle', this._toggleFeatures.bind(this));
422
+ this.unresolved = false;
423
+
424
+ console.log('<pb-page> endpoint: %s; trigger window resize', this.endpoint);
425
+ this.querySelectorAll('app-header').forEach(h => h._notifyLayoutChanged());
426
+
427
+ typesetMath(this);
428
+ }
429
+
430
+ _updateI18n(t) {
431
+ this.querySelectorAll('[data-i18n]').forEach(elem => {
432
+ const targets = elem.getAttribute('data-i18n');
433
+ const regex = /(?:\[([^\]]+)\])?([^;]+)/g;
434
+ let m = regex.exec(targets);
435
+ while (m) {
436
+ const translated = t(m[2]);
437
+ if (m[1]) {
438
+ elem.setAttribute(m[1], translated);
439
+ } else {
440
+ elem.innerHTML = translated;
468
441
  }
469
- `;
470
- }
442
+ m = regex.exec(targets);
443
+ }
444
+ });
445
+ }
446
+
447
+ get stylesheet() {
448
+ return this._themeSheet;
449
+ }
450
+
451
+ /**
452
+ * Handle the `pb-toggle` event sent by `pb-select-feature` or `pb-toggle-feature`
453
+ * and dispatch actions to the elements on the page.
454
+ */
455
+ _toggleFeatures(ev) {
456
+ const sc = ev.detail;
457
+ this.querySelectorAll(sc.selector).forEach(node => {
458
+ const command = sc.command || 'toggle';
459
+ if (node.command) {
460
+ node.command(command, sc.state);
461
+ }
462
+ if (sc.state) {
463
+ node.classList.add(command);
464
+ } else {
465
+ node.classList.remove(command);
466
+ }
467
+ });
468
+ }
469
+
470
+ render() {
471
+ return html`<slot></slot>`;
472
+ }
473
+
474
+ static get styles() {
475
+ return css`
476
+ :host {
477
+ display: block;
478
+ }
479
+ `;
480
+ }
471
481
  }
472
482
 
473
- customElements.define('pb-page', PbPage);
483
+ customElements.define('pb-page', PbPage);