@teipublisher/pb-components 2.26.1-next.2 → 3.0.0

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 (154) 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 +2 -2
  5. package/CHANGELOG.md +267 -9
  6. package/Dockerfile +78 -70
  7. package/css/components.css +5 -5
  8. package/css/leaflet/images/layers.png +0 -0
  9. package/dist/demo/components.css +46 -1
  10. package/dist/demo/pb-browse-docs2.html +1 -1
  11. package/dist/demo/pb-dialog.html +3 -5
  12. package/dist/demo/pb-drawer2.html +1 -1
  13. package/dist/demo/pb-facsimile.html +2 -2
  14. package/dist/demo/pb-grid.html +19 -6
  15. package/dist/demo/pb-leaflet-map.html +1 -1
  16. package/dist/demo/pb-login.html +0 -2
  17. package/dist/demo/pb-message.html +1 -2
  18. package/dist/demo/pb-progress.html +2 -2
  19. package/dist/demo/pb-repeat.html +1 -3
  20. package/dist/demo/pb-search.html +7 -4
  21. package/dist/demo/pb-search3.html +1 -1
  22. package/dist/demo/pb-search4.html +2 -2
  23. package/dist/demo/pb-view3.html +1 -1
  24. package/dist/{iron-form-3b8dcaa7.js → iron-form-dfb3e3b1.js} +95 -95
  25. package/dist/paper-checkbox-645e1077.js +200 -0
  26. package/dist/{paper-icon-button-b1d31571.js → paper-icon-button-984162bd.js} +1 -1
  27. package/dist/{paper-checkbox-515a5284.js → paper-inky-focus-behavior-fa16796b.js} +58 -247
  28. package/dist/{paper-listbox-a3b7175c.js → paper-listbox-5f5d1cec.js} +152 -162
  29. package/dist/pb-code-editor.js +25 -20
  30. package/dist/pb-component-docs.js +68 -64
  31. package/dist/pb-components-bundle.js +1983 -2293
  32. package/dist/pb-edit-app.js +167 -107
  33. package/dist/pb-elements.json +176 -120
  34. package/dist/{pb-i18n-0611135a.js → pb-i18n-4cc00bfe.js} +1 -1
  35. package/dist/pb-leaflet-map.js +23 -23
  36. package/dist/pb-mei.js +56 -41
  37. package/dist/{pb-mixin-b1caa22e.js → pb-mixin-886ece32.js} +1 -1
  38. package/dist/pb-odd-editor.js +1023 -782
  39. package/dist/pb-tify.js +2 -2
  40. package/dist/vaadin-element-mixin-beb74ffd.js +545 -0
  41. package/gh-pages.js +5 -3
  42. package/i18n/common/en.json +6 -0
  43. package/i18n/common/pl.json +2 -2
  44. package/lib/openseadragon.min.js +6 -6
  45. package/package.json +3 -3
  46. package/pb-elements.json +176 -120
  47. package/src/assets/components.css +5 -5
  48. package/src/authority/airtable.js +20 -21
  49. package/src/authority/anton.js +129 -129
  50. package/src/authority/custom.js +23 -21
  51. package/src/authority/geonames.js +38 -32
  52. package/src/authority/gnd.js +50 -42
  53. package/src/authority/kbga.js +137 -134
  54. package/src/authority/metagrid.js +44 -46
  55. package/src/authority/reconciliation.js +66 -67
  56. package/src/authority/registry.js +4 -4
  57. package/src/docs/pb-component-docs.js +2 -2
  58. package/src/docs/pb-component-view.js +5 -5
  59. package/src/docs/pb-components-list.js +2 -2
  60. package/src/docs/pb-demo-snippet.js +2 -2
  61. package/src/dts-client.js +299 -297
  62. package/src/dts-select-endpoint.js +90 -82
  63. package/src/parse-date-service.js +184 -135
  64. package/src/pb-ajax.js +158 -171
  65. package/src/pb-authority-lookup.js +191 -156
  66. package/src/pb-autocomplete.js +292 -280
  67. package/src/pb-blacklab-highlight.js +264 -259
  68. package/src/pb-blacklab-results.js +236 -221
  69. package/src/pb-browse-docs.js +540 -475
  70. package/src/pb-browse.js +68 -65
  71. package/src/pb-clipboard.js +79 -76
  72. package/src/pb-code-editor.js +110 -102
  73. package/src/pb-code-highlight.js +209 -204
  74. package/src/pb-codepen.js +79 -72
  75. package/src/pb-collapse.js +211 -151
  76. package/src/pb-combo-box.js +190 -190
  77. package/src/pb-components-bundle.js +1 -1
  78. package/src/pb-components.js +1 -0
  79. package/src/pb-custom-form.js +173 -153
  80. package/src/pb-dialog.js +98 -62
  81. package/src/pb-document.js +89 -90
  82. package/src/pb-download.js +212 -196
  83. package/src/pb-drawer.js +145 -148
  84. package/src/pb-edit-app.js +301 -229
  85. package/src/pb-edit-xml.js +100 -97
  86. package/src/pb-events.js +114 -107
  87. package/src/pb-facs-link.js +104 -102
  88. package/src/pb-facsimile.js +474 -410
  89. package/src/pb-formula.js +151 -153
  90. package/src/pb-geolocation.js +129 -131
  91. package/src/pb-grid-action.js +53 -56
  92. package/src/pb-grid.js +231 -228
  93. package/src/pb-highlight.js +140 -140
  94. package/src/pb-hotkeys.js +40 -42
  95. package/src/pb-i18n.js +101 -104
  96. package/src/pb-image-strip.js +84 -78
  97. package/src/pb-lang.js +142 -57
  98. package/src/pb-leaflet-map.js +488 -485
  99. package/src/pb-link.js +126 -124
  100. package/src/pb-load.js +431 -429
  101. package/src/pb-login.js +299 -244
  102. package/src/pb-manage-odds.js +352 -336
  103. package/src/pb-map-icon.js +89 -89
  104. package/src/pb-map-layer.js +85 -85
  105. package/src/pb-markdown.js +90 -99
  106. package/src/pb-media-query.js +74 -72
  107. package/src/pb-mei.js +306 -295
  108. package/src/pb-message.js +139 -97
  109. package/src/pb-mixin.js +269 -264
  110. package/src/pb-navigation.js +80 -95
  111. package/src/pb-observable.js +38 -38
  112. package/src/pb-odd-editor.js +1054 -958
  113. package/src/pb-odd-elementspec-editor.js +349 -298
  114. package/src/pb-odd-model-editor.js +1075 -909
  115. package/src/pb-odd-parameter-editor.js +200 -178
  116. package/src/pb-odd-rendition-editor.js +136 -124
  117. package/src/pb-page.js +431 -422
  118. package/src/pb-paginate.js +228 -179
  119. package/src/pb-panel.js +198 -182
  120. package/src/pb-popover-themes.js +15 -8
  121. package/src/pb-popover.js +296 -287
  122. package/src/pb-print-preview.js +127 -127
  123. package/src/pb-progress.js +51 -51
  124. package/src/pb-repeat.js +105 -104
  125. package/src/pb-restricted.js +84 -77
  126. package/src/pb-search.js +256 -228
  127. package/src/pb-select-feature.js +127 -120
  128. package/src/pb-select-odd.js +132 -124
  129. package/src/pb-select-template.js +89 -78
  130. package/src/pb-select.js +251 -227
  131. package/src/pb-split-list.js +179 -174
  132. package/src/pb-svg.js +80 -79
  133. package/src/pb-table-column.js +54 -54
  134. package/src/pb-table-grid.js +221 -203
  135. package/src/pb-tabs.js +61 -63
  136. package/src/pb-tify.js +154 -154
  137. package/src/pb-timeline.js +382 -249
  138. package/src/pb-toggle-feature.js +195 -187
  139. package/src/pb-upload.js +184 -174
  140. package/src/pb-version.js +30 -30
  141. package/src/pb-view-annotate.js +135 -98
  142. package/src/pb-view.js +1282 -1270
  143. package/src/pb-zoom.js +127 -45
  144. package/src/polymer-hack.js +1 -1
  145. package/src/search-result-service.js +256 -223
  146. package/src/seed-element.js +13 -20
  147. package/src/settings.js +4 -4
  148. package/src/theming.js +98 -91
  149. package/src/urls.js +289 -289
  150. package/src/utils.js +53 -51
  151. package/css/pb-styles.css +0 -51
  152. package/dist/vaadin-element-mixin-6e4cee3a.js +0 -527
  153. package/src/assets/pb-styles.css +0 -51
  154. package/src/pb-light-dom.js +0 -40
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,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
-
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
+ 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
+ }
409
308
 
410
- // this.subscribeTo('pb-global-toggle', this._toggleFeatures.bind(this));
411
- this.addEventListener('pb-global-toggle', this._toggleFeatures.bind(this));
412
- 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
+ }
413
324
 
414
- console.log('<pb-page> endpoint: %s; trigger window resize', this.endpoint);
415
- this.querySelectorAll('app-header').forEach(h => h._notifyLayoutChanged());
325
+ firstUpdated() {
326
+ super.firstUpdated();
416
327
 
417
- typesetMath(this);
328
+ if (this.disabled) {
329
+ return;
418
330
  }
419
331
 
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
- }
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,
434
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
+ });
435
364
  }
436
-
437
- get stylesheet() {
438
- 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;
439
381
  }
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
- });
382
+ console.log('supported langs: %o', this.supportedLanguages);
383
+ if (this.supportedLanguages) {
384
+ options.supportedLngs = this.supportedLanguages;
458
385
  }
459
386
 
460
- render() {
461
- 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;
462
392
  }
463
-
464
- static get styles() {
465
- return css`
466
- :host {
467
- 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;
468
440
  }
469
- `;
470
- }
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
+ }
471
480
  }
472
481
 
473
- customElements.define('pb-page', PbPage);
482
+ customElements.define('pb-page', PbPage);