@schukai/monster 3.119.0 → 3.120.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 (32) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +1 -1
  3. package/source/components/accessibility/stylesheet/locale-picker.mjs +1 -1
  4. package/source/components/content/stylesheet/viewer.mjs +1 -1
  5. package/source/components/content/viewer.mjs +301 -311
  6. package/source/components/datatable/stylesheet/change-button.mjs +1 -1
  7. package/source/components/datatable/stylesheet/column-bar.mjs +1 -1
  8. package/source/components/datatable/stylesheet/dataset.mjs +1 -1
  9. package/source/components/datatable/stylesheet/datatable.mjs +1 -1
  10. package/source/components/datatable/stylesheet/filter-select.mjs +1 -1
  11. package/source/components/datatable/stylesheet/filter.mjs +1 -1
  12. package/source/components/datatable/stylesheet/pagination.mjs +1 -1
  13. package/source/components/datatable/stylesheet/save-button.mjs +1 -1
  14. package/source/components/datatable/stylesheet/status.mjs +1 -1
  15. package/source/components/form/login.mjs +5 -0
  16. package/source/components/form/stylesheet/button-bar.mjs +1 -1
  17. package/source/components/form/stylesheet/button.mjs +1 -1
  18. package/source/components/form/stylesheet/popper-button.mjs +1 -1
  19. package/source/components/host/stylesheet/call-button.mjs +1 -1
  20. package/source/components/host/stylesheet/toggle-button.mjs +1 -1
  21. package/source/components/layout/stylesheet/collapse.mjs +1 -1
  22. package/source/components/layout/stylesheet/details.mjs +1 -1
  23. package/source/components/state/style/state.pcss +2 -0
  24. package/source/components/state/stylesheet/state.mjs +1 -1
  25. package/source/components/style/button.css +8 -16
  26. package/source/components/style/button.pcss +2 -0
  27. package/source/components/style/mixin/button.pcss +1 -6
  28. package/source/components/stylesheet/button.mjs +1 -1
  29. package/source/components/time/stylesheet/day.mjs +1 -1
  30. package/source/components/time/stylesheet/month-calendar.mjs +1 -1
  31. package/source/components/time/timeline/stylesheet/appointment.mjs +1 -1
  32. package/source/components/time/timeline/stylesheet/segment.mjs +1 -1
@@ -13,18 +13,18 @@
13
13
  */
14
14
 
15
15
  import {
16
- assembleMethodSymbol,
17
- CustomElement,
18
- registerCustomElement,
16
+ assembleMethodSymbol,
17
+ CustomElement,
18
+ registerCustomElement,
19
19
  } from "../../dom/customelement.mjs";
20
20
  import "../notify/notify.mjs";
21
- import {ViewerStyleSheet} from "./stylesheet/viewer.mjs";
22
- import {instanceSymbol} from "../../constants.mjs";
23
- import {isString} from "../../types/is.mjs";
24
- import {getGlobal} from "../../types/global.mjs";
25
- import {MediaType, parseMediaType} from "../../types/mediatype.mjs";
21
+ import { ViewerStyleSheet } from "./stylesheet/viewer.mjs";
22
+ import { instanceSymbol } from "../../constants.mjs";
23
+ import { isString } from "../../types/is.mjs";
24
+ import { getGlobal } from "../../types/global.mjs";
25
+ import { MediaType, parseMediaType } from "../../types/mediatype.mjs";
26
26
 
27
- export {Viewer};
27
+ export { Viewer };
28
28
 
29
29
  /**
30
30
  * @private
@@ -45,288 +45,278 @@ const viewerElementSymbol = Symbol("viewerElement");
45
45
  * @summary A simple viewer component for PDF, HTML and images.
46
46
  */
47
47
  class Viewer extends CustomElement {
48
- /**
49
- * This method is called by the `instanceof` operator.
50
- * @return {symbol}
51
- */
52
- static get [instanceSymbol]() {
53
- return Symbol.for("@schukai/monster/components/content/viewer@@instance");
54
- }
55
-
56
- /**
57
- * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
58
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
59
- *
60
- * The individual configuration values can be found in the table.
61
- *
62
- * @property {Object} templates Template definitions
63
- * @property {string} templates.main Main template
64
- * @property {string} content Content to be displayed in the viewer
65
- * @property {Object} classes Css classes
66
- * @property {string} classes.viewer Css class for the viewer
67
- */
68
- get defaults() {
69
- return Object.assign({}, super.defaults, {
70
- templates: {
71
- main: getTemplate(),
72
- },
73
- content: "<slot></slot>",
74
- classes: {
75
- viewer: "",
76
- }
77
- });
78
- }
79
-
80
- /**
81
- * Sets the content of an element based on the provided content and media type.
82
- *
83
- * @param {string} content - The content to be set.
84
- * @param {string} [mediaType="text/plain"] - The media type of the content. Defaults to "text/plain" if not specified.
85
- * @return {void} This method does not return a value.
86
- * @throws {Error} Throws an error if shadowRoot is not defined.
87
- */
88
- setContent(content, mediaType = "text/plain") {
89
-
90
- if (!this.shadowRoot) {
91
- throw new Error("no shadow-root is defined");
92
- }
93
-
94
- let type;
95
- try {
96
- const m = new parseMediaType(mediaType)
97
- switch (m.type) {
98
- case "image":
99
- return this.setImage(content)
100
- }
101
-
102
- mediaType = m.toString()
103
-
104
- } catch (error) {
105
- type = null
106
- }
107
-
108
- if (mediaType === undefined || mediaType === null || mediaType === "") {
109
- mediaType = "text/plain";
110
- }
111
-
112
- switch (mediaType) {
113
- case "text/html":
114
- this.setHTML(content);
115
- break;
116
- case "text/plain":
117
- this.setPlainText(content);
118
- break;
119
- case "application/pdf":
120
- this.setPDF(content);
121
- break;
122
- case "image/png":
123
- case "image/jpeg":
124
- case "image/gif":
125
- this.setImage(content);
126
- break;
127
- default:
128
- this.setOption("content", content);
129
- }
130
-
131
- }
132
-
133
- /**
134
- * Configures and embeds a PDF document into the application with customizable display settings.
135
- *
136
- * @param {Blob|URL|string} data The PDF data to be embedded. Can be provided as a Blob, URL or base64 string.
137
- * @param {boolean} [navigation=true] Determines whether the navigation pane is displayed in the PDF viewer.
138
- * @param {boolean} [toolbar=true] Controls the visibility of the toolbar in the PDF viewer.
139
- * @param {boolean} [scrollbar=false] Configures the display of the scrollbar in the PDF viewer.
140
- * @return {void} This method returns nothing but sets the embedded PDF as the content.
141
- */
142
- setPDF(data, navigation = true, toolbar = true, scrollbar = false) {
143
- const hashes =
144
- "#toolbar=" +
145
- (toolbar ? "1" : "0") +
146
- "&navpanes=" +
147
- (navigation ? "1" : "0") +
148
- "&scrollbar=" +
149
- (scrollbar ? "1" : "0");
150
-
151
- let pdfURL = "";
152
- if (isBlob(data)) {
153
- pdfURL = URL.createObjectURL(data);
154
- pdfURL += hashes;
155
- } else if (isURL(data)) {
156
- // check if the url already contains the hashes
157
- if (data?.hash?.indexOf("#") === -1) {
158
- pdfURL = data.toString() + hashes;
159
- } else {
160
- pdfURL = data.toString();
161
- }
162
-
163
-
164
- } else if (isString(data)) {
165
- //URL.createObjectURL(data);
166
- const blobObj = new Blob([atob(data)], {type: "application/pdf"});
167
- const url = window.URL.createObjectURL(blobObj);
168
-
169
- pdfURL = data;
170
- } else {
171
- throw new Error("Blob or URL expected");
172
- }
173
-
174
- const html =
175
- '<object data="' +
176
- pdfURL +
177
- '" width="100%" height="100%" type="application/pdf"></object>';
178
-
179
- this.setOption("content", html);
180
-
181
- }
182
-
183
- /**
184
- * Sets an image for the target by accepting a blob, URL, or string representation of the image.
185
- *
186
- * @param {(Blob|string)} data - The image data, which can be a Blob, a valid URL, or a string representation of the image.
187
- * @return {void} Does not return a value.
188
- */
189
- setImage(data) {
190
- if (isBlob(data)) {
191
- data = URL.createObjectURL(data);
192
- } else if (isURL(data)) {
193
- // nothing to do
194
- } else if (isString(data)) {
195
- // nothing to do
196
- } else {
197
- throw new Error("Blob or URL expected");
198
- }
199
-
200
- this.setOption("content", '<img src="' + data + '" alt="image" />');
201
- }
202
-
203
- /**
204
- *
205
- * if the data is a string, it is interpreted as HTML.
206
- * if the data is an url, the HTML is loaded from the url and set as content.
207
- * if the data is an HTMLElement, the outerHTML is used as content.
208
- *
209
- * @param {HTMLElement|URL|string|Blob} data
210
- */
211
- setHTML(data) {
212
- if (data instanceof Blob) {
213
- blobToText(data)
214
- .then((html) => {
215
- this.setOption("content", html);
216
- })
217
- .catch((error) => {
218
- throw new Error(error);
219
- });
220
-
221
- return;
222
- } else if (data instanceof HTMLElement) {
223
- data = data.outerHTML;
224
- } else if (isString(data)) {
225
- // nothing to do
226
- } else if (isURL(data)) {
227
- // fetch element
228
- getGlobal()
229
- .fetch(data)
230
- .then((response) => {
231
- return response.text();
232
- })
233
- .then((html) => {
234
- this.setOption("content", html);
235
- })
236
- .catch((error) => {
237
- throw new Error(error);
238
- });
239
- } else {
240
- throw new Error("HTMLElement or string expected");
241
- }
242
-
243
- this.setOption("content", data);
244
-
245
- }
246
-
247
- /**
248
- * Sets the plain text content by processing the input data, which can be of various types, including Blob,
249
- * HTMLElement, string, or a valid URL. The method extracts and sets the raw text content into a predefined option.
250
- *
251
- * @param {Blob|HTMLElement|string} data - The input data to be processed. It can be a Blob object, an HTMLElement,
252
- * a plain string, or a string formatted as a valid URL. The method determines
253
- * the data type and processes it accordingly.
254
- * @return {void} - This method does not return any value. It processes the content and updates the relevant option
255
- * property.
256
- */
257
- setPlainText(data) {
258
- if (data instanceof Blob) {
259
- blobToText(data)
260
- .then((html) => {
261
-
262
- const div = document.createElement("div");
263
- div.innerHTML = html;
264
- html = div.innerText
265
-
266
- this.setOption("content", html);
267
- })
268
- .catch((error) => {
269
- throw new Error(error);
270
- });
271
-
272
- return;
273
- } else if (data instanceof HTMLElement) {
274
- data = data.outerText
275
- } else if (isString(data)) {
276
- const div = document.createElement("div");
277
- div.innerHTML = data;
278
- data = div.innerText
279
-
280
- } else if (isURL(data)) {
281
- // fetch element
282
- getGlobal()
283
- .fetch(data)
284
- .then((response) => {
285
- return response.text();
286
- })
287
- .then((text) => {
288
-
289
- const div = document.createElement("div");
290
- div.innerHTML = text;
291
- text = div.innerText
292
-
293
- this.setOption("content", text);
294
- })
295
- .catch((error) => {
296
- throw new Error(error);
297
- });
298
- } else {
299
- throw new Error("HTMLElement or string expected");
300
- }
301
-
302
- this.setOption("content", data);
303
- }
304
-
305
- /**
306
- *
307
- * @return {Viewer}
308
- */
309
- [assembleMethodSymbol]() {
310
- super[assembleMethodSymbol]();
311
-
312
- initControlReferences.call(this);
313
- initEventHandler.call(this);
314
- }
315
-
316
- /**
317
- *
318
- * @return {string}
319
- */
320
- static getTag() {
321
- return "monster-viewer";
322
- }
323
-
324
- /**
325
- * @return {CSSStyleSheet[]}
326
- */
327
- static getCSSStyleSheet() {
328
- return [ViewerStyleSheet];
329
- }
48
+ /**
49
+ * This method is called by the `instanceof` operator.
50
+ * @return {symbol}
51
+ */
52
+ static get [instanceSymbol]() {
53
+ return Symbol.for("@schukai/monster/components/content/viewer@@instance");
54
+ }
55
+
56
+ /**
57
+ * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
58
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
59
+ *
60
+ * The individual configuration values can be found in the table.
61
+ *
62
+ * @property {Object} templates Template definitions
63
+ * @property {string} templates.main Main template
64
+ * @property {string} content Content to be displayed in the viewer
65
+ * @property {Object} classes Css classes
66
+ * @property {string} classes.viewer Css class for the viewer
67
+ */
68
+ get defaults() {
69
+ return Object.assign({}, super.defaults, {
70
+ templates: {
71
+ main: getTemplate(),
72
+ },
73
+ content: "<slot></slot>",
74
+ classes: {
75
+ viewer: "",
76
+ },
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Sets the content of an element based on the provided content and media type.
82
+ *
83
+ * @param {string} content - The content to be set.
84
+ * @param {string} [mediaType="text/plain"] - The media type of the content. Defaults to "text/plain" if not specified.
85
+ * @return {void} This method does not return a value.
86
+ * @throws {Error} Throws an error if shadowRoot is not defined.
87
+ */
88
+ setContent(content, mediaType = "text/plain") {
89
+ if (!this.shadowRoot) {
90
+ throw new Error("no shadow-root is defined");
91
+ }
92
+
93
+ let type;
94
+ try {
95
+ const m = new parseMediaType(mediaType);
96
+ switch (m.type) {
97
+ case "image":
98
+ return this.setImage(content);
99
+ }
100
+
101
+ mediaType = m.toString();
102
+ } catch (error) {
103
+ type = null;
104
+ }
105
+
106
+ if (mediaType === undefined || mediaType === null || mediaType === "") {
107
+ mediaType = "text/plain";
108
+ }
109
+
110
+ switch (mediaType) {
111
+ case "text/html":
112
+ this.setHTML(content);
113
+ break;
114
+ case "text/plain":
115
+ this.setPlainText(content);
116
+ break;
117
+ case "application/pdf":
118
+ this.setPDF(content);
119
+ break;
120
+ case "image/png":
121
+ case "image/jpeg":
122
+ case "image/gif":
123
+ this.setImage(content);
124
+ break;
125
+ default:
126
+ this.setOption("content", content);
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Configures and embeds a PDF document into the application with customizable display settings.
132
+ *
133
+ * @param {Blob|URL|string} data The PDF data to be embedded. Can be provided as a Blob, URL or base64 string.
134
+ * @param {boolean} [navigation=true] Determines whether the navigation pane is displayed in the PDF viewer.
135
+ * @param {boolean} [toolbar=true] Controls the visibility of the toolbar in the PDF viewer.
136
+ * @param {boolean} [scrollbar=false] Configures the display of the scrollbar in the PDF viewer.
137
+ * @return {void} This method returns nothing but sets the embedded PDF as the content.
138
+ */
139
+ setPDF(data, navigation = true, toolbar = true, scrollbar = false) {
140
+ const hashes =
141
+ "#toolbar=" +
142
+ (toolbar ? "1" : "0") +
143
+ "&navpanes=" +
144
+ (navigation ? "1" : "0") +
145
+ "&scrollbar=" +
146
+ (scrollbar ? "1" : "0");
147
+
148
+ let pdfURL = "";
149
+ if (isBlob(data)) {
150
+ pdfURL = URL.createObjectURL(data);
151
+ pdfURL += hashes;
152
+ } else if (isURL(data)) {
153
+ // check if the url already contains the hashes
154
+ if (data?.hash?.indexOf("#") === -1) {
155
+ pdfURL = data.toString() + hashes;
156
+ } else {
157
+ pdfURL = data.toString();
158
+ }
159
+ } else if (isString(data)) {
160
+ //URL.createObjectURL(data);
161
+ const blobObj = new Blob([atob(data)], { type: "application/pdf" });
162
+ const url = window.URL.createObjectURL(blobObj);
163
+
164
+ pdfURL = data;
165
+ } else {
166
+ throw new Error("Blob or URL expected");
167
+ }
168
+
169
+ const html =
170
+ '<object data="' +
171
+ pdfURL +
172
+ '" width="100%" height="100%" type="application/pdf"></object>';
173
+
174
+ this.setOption("content", html);
175
+ }
176
+
177
+ /**
178
+ * Sets an image for the target by accepting a blob, URL, or string representation of the image.
179
+ *
180
+ * @param {(Blob|string)} data - The image data, which can be a Blob, a valid URL, or a string representation of the image.
181
+ * @return {void} Does not return a value.
182
+ */
183
+ setImage(data) {
184
+ if (isBlob(data)) {
185
+ data = URL.createObjectURL(data);
186
+ } else if (isURL(data)) {
187
+ // nothing to do
188
+ } else if (isString(data)) {
189
+ // nothing to do
190
+ } else {
191
+ throw new Error("Blob or URL expected");
192
+ }
193
+
194
+ this.setOption("content", '<img src="' + data + '" alt="image" />');
195
+ }
196
+
197
+ /**
198
+ *
199
+ * if the data is a string, it is interpreted as HTML.
200
+ * if the data is an url, the HTML is loaded from the url and set as content.
201
+ * if the data is an HTMLElement, the outerHTML is used as content.
202
+ *
203
+ * @param {HTMLElement|URL|string|Blob} data
204
+ */
205
+ setHTML(data) {
206
+ if (data instanceof Blob) {
207
+ blobToText(data)
208
+ .then((html) => {
209
+ this.setOption("content", html);
210
+ })
211
+ .catch((error) => {
212
+ throw new Error(error);
213
+ });
214
+
215
+ return;
216
+ } else if (data instanceof HTMLElement) {
217
+ data = data.outerHTML;
218
+ } else if (isString(data)) {
219
+ // nothing to do
220
+ } else if (isURL(data)) {
221
+ // fetch element
222
+ getGlobal()
223
+ .fetch(data)
224
+ .then((response) => {
225
+ return response.text();
226
+ })
227
+ .then((html) => {
228
+ this.setOption("content", html);
229
+ })
230
+ .catch((error) => {
231
+ throw new Error(error);
232
+ });
233
+ } else {
234
+ throw new Error("HTMLElement or string expected");
235
+ }
236
+
237
+ this.setOption("content", data);
238
+ }
239
+
240
+ /**
241
+ * Sets the plain text content by processing the input data, which can be of various types, including Blob,
242
+ * HTMLElement, string, or a valid URL. The method extracts and sets the raw text content into a predefined option.
243
+ *
244
+ * @param {Blob|HTMLElement|string} data - The input data to be processed. It can be a Blob object, an HTMLElement,
245
+ * a plain string, or a string formatted as a valid URL. The method determines
246
+ * the data type and processes it accordingly.
247
+ * @return {void} - This method does not return any value. It processes the content and updates the relevant option
248
+ * property.
249
+ */
250
+ setPlainText(data) {
251
+ if (data instanceof Blob) {
252
+ blobToText(data)
253
+ .then((html) => {
254
+ const div = document.createElement("div");
255
+ div.innerHTML = html;
256
+ html = div.innerText;
257
+
258
+ this.setOption("content", html);
259
+ })
260
+ .catch((error) => {
261
+ throw new Error(error);
262
+ });
263
+
264
+ return;
265
+ } else if (data instanceof HTMLElement) {
266
+ data = data.outerText;
267
+ } else if (isString(data)) {
268
+ const div = document.createElement("div");
269
+ div.innerHTML = data;
270
+ data = div.innerText;
271
+ } else if (isURL(data)) {
272
+ // fetch element
273
+ getGlobal()
274
+ .fetch(data)
275
+ .then((response) => {
276
+ return response.text();
277
+ })
278
+ .then((text) => {
279
+ const div = document.createElement("div");
280
+ div.innerHTML = text;
281
+ text = div.innerText;
282
+
283
+ this.setOption("content", text);
284
+ })
285
+ .catch((error) => {
286
+ throw new Error(error);
287
+ });
288
+ } else {
289
+ throw new Error("HTMLElement or string expected");
290
+ }
291
+
292
+ this.setOption("content", data);
293
+ }
294
+
295
+ /**
296
+ *
297
+ * @return {Viewer}
298
+ */
299
+ [assembleMethodSymbol]() {
300
+ super[assembleMethodSymbol]();
301
+
302
+ initControlReferences.call(this);
303
+ initEventHandler.call(this);
304
+ }
305
+
306
+ /**
307
+ *
308
+ * @return {string}
309
+ */
310
+ static getTag() {
311
+ return "monster-viewer";
312
+ }
313
+
314
+ /**
315
+ * @return {CSSStyleSheet[]}
316
+ */
317
+ static getCSSStyleSheet() {
318
+ return [ViewerStyleSheet];
319
+ }
330
320
  }
331
321
 
332
322
  /**
@@ -335,12 +325,12 @@ class Viewer extends CustomElement {
335
325
  * @return {boolean}
336
326
  */
337
327
  function isURL(variable) {
338
- try {
339
- new URL(variable);
340
- return true;
341
- } catch (error) {
342
- return false;
343
- }
328
+ try {
329
+ new URL(variable);
330
+ return true;
331
+ } catch (error) {
332
+ return false;
333
+ }
344
334
  }
345
335
 
346
336
  /**
@@ -349,7 +339,7 @@ function isURL(variable) {
349
339
  * @return {boolean}
350
340
  */
351
341
  function isBlob(variable) {
352
- return variable instanceof Blob;
342
+ return variable instanceof Blob;
353
343
  }
354
344
 
355
345
  /**
@@ -358,12 +348,12 @@ function isBlob(variable) {
358
348
  * @return {Promise<unknown>}
359
349
  */
360
350
  function blobToText(blob) {
361
- return new Promise((resolve, reject) => {
362
- const reader = new FileReader();
363
- reader.onloadend = () => resolve(reader.result);
364
- reader.onerror = reject;
365
- reader.readAsText(blob);
366
- });
351
+ return new Promise((resolve, reject) => {
352
+ const reader = new FileReader();
353
+ reader.onloadend = () => resolve(reader.result);
354
+ reader.onerror = reject;
355
+ reader.readAsText(blob);
356
+ });
367
357
  }
368
358
 
369
359
  /**
@@ -372,18 +362,18 @@ function blobToText(blob) {
372
362
  * @throws {Error} no shadow-root is defined
373
363
  */
374
364
  function initControlReferences() {
375
- if (!this.shadowRoot) {
376
- throw new Error("no shadow-root is defined");
377
- }
365
+ if (!this.shadowRoot) {
366
+ throw new Error("no shadow-root is defined");
367
+ }
378
368
 
379
- this[viewerElementSymbol] = this.shadowRoot.getElementById("viewer");
369
+ this[viewerElementSymbol] = this.shadowRoot.getElementById("viewer");
380
370
  }
381
371
 
382
372
  /**
383
373
  * @private
384
374
  */
385
375
  function initEventHandler() {
386
- return this;
376
+ return this;
387
377
  }
388
378
 
389
379
  /**
@@ -391,8 +381,8 @@ function initEventHandler() {
391
381
  * @return {string}
392
382
  */
393
383
  function getTemplate() {
394
- // language=HTML
395
- return `
384
+ // language=HTML
385
+ return `
396
386
  <div id="viewer" data-monster-role="viewer" part="viewer"
397
387
  data-monster-replace="path:content"
398
388
  data-monster-attributes="class path:classes.viewer">