@schukai/monster 3.82.1 → 3.83.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
 
4
4
 
5
+ ## [3.83.0] - 2024-10-27
6
+
7
+ ### Add Features
8
+
9
+ - New disableButton for monster-state-message-button [#254](https://gitlab.schukai.com/oss/libraries/javascript/monster/issues/254)
10
+
11
+
12
+
5
13
  ## [3.82.1] - 2024-10-16
6
14
 
7
15
  ### Bug Fixes
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.6.11","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"3.82.1"}
1
+ {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.6.11","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"3.83.0"}
@@ -121,6 +121,9 @@ class MessageStateButton extends Popper {
121
121
  throw new Error("the click action is not defined");
122
122
  },
123
123
  },
124
+ features: {
125
+ disableButton: false,
126
+ },
124
127
  });
125
128
  }
126
129
 
@@ -208,7 +211,7 @@ class MessageStateButton extends Popper {
208
211
 
209
212
  /**
210
213
  * @param {number} timeout
211
- * @return {Monster.Components.Form.MessageStateButton}
214
+ * @return {MessageStateButton}
212
215
  */
213
216
  showMessage(timeout) {
214
217
  super.showDialog();
@@ -363,7 +366,7 @@ function getTemplate() {
363
366
  <div data-monster-role="control" part="control">
364
367
 
365
368
  <monster-state-button exportparts="button:button-button,control:button-control"
366
- data-monster-attributes="data-monster-option-classes-button path:classes.button"
369
+ data-monster-attributes="data-monster-option-classes-button path:classes.button, disabled path:features.disableButton"
367
370
  part="button"
368
371
  name="button"
369
372
  data-monster-role="button">
@@ -199,8 +199,6 @@ class ConfigManager extends CustomElement {
199
199
  }
200
200
 
201
201
  /**
202
- *
203
- * @return {Monster.Components.Host.Host}
204
202
  */
205
203
  [assembleMethodSymbol]() {
206
204
  super[assembleMethodSymbol]();
@@ -10,20 +10,20 @@
10
10
  * For more information about purchasing a commercial license, please contact schukai GmbH.
11
11
  */
12
12
 
13
- import {instanceSymbol} from "../../constants.mjs";
14
- import {ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
15
- import {CustomElement} from "../../dom/customelement.mjs";
13
+ import { instanceSymbol } from "../../constants.mjs";
14
+ import { ATTRIBUTE_ROLE } from "../../dom/constants.mjs";
15
+ import { CustomElement } from "../../dom/customelement.mjs";
16
16
  import {
17
- assembleMethodSymbol,
18
- registerCustomElement,
17
+ assembleMethodSymbol,
18
+ registerCustomElement,
19
19
  } from "../../dom/customelement.mjs";
20
- import {findTargetElementFromEvent} from "../../dom/events.mjs";
21
- import {isFunction} from "../../types/is.mjs";
22
- import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
23
- import {IframeStyleSheet} from "./stylesheet/iframe.mjs";
24
- import {fireCustomEvent} from "../../dom/events.mjs";
20
+ import { findTargetElementFromEvent } from "../../dom/events.mjs";
21
+ import { isFunction } from "../../types/is.mjs";
22
+ import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
23
+ import { IframeStyleSheet } from "./stylesheet/iframe.mjs";
24
+ import { fireCustomEvent } from "../../dom/events.mjs";
25
25
 
26
- export {Iframe};
26
+ export { Iframe };
27
27
 
28
28
  /**
29
29
  * @private
@@ -62,134 +62,134 @@ const timerCallbackSymbol = Symbol("timerCallback");
62
62
  * @summary A cool and fancy Iframe that can make your life easier and also looks good.
63
63
  */
64
64
  class Iframe extends CustomElement {
65
- /**
66
- * This method is called by the `instanceof` operator.
67
- * @return {symbol}
68
- */
69
- static get [instanceSymbol]() {
70
- return Symbol.for("@schukai/monster/components/layout/iframe@@instance");
71
- }
72
-
73
- /**
74
- *
75
- * @return {Components.Layout.Iframe
76
- * @fires monster-iframe-clicked
77
- */
78
- [assembleMethodSymbol]() {
79
- super[assembleMethodSymbol]();
80
- initControlReferences.call(this);
81
- initEventHandler.call(this);
82
- calcHeight.call(this);
83
- return this;
84
- }
85
-
86
- /**
87
- * This method is called by the dom and should not be called directly.
88
- *
89
- * @return {void}
90
- */
91
- connectedCallback() {
92
- super.connectedCallback();
93
- attachResizeObserver.call(this);
94
-
95
- // disable scrolling in parent node
96
- if (this.parentNode && this.parentNode instanceof HTMLElement) {
97
- this.parentNode.style.overflow = "hidden";
98
- }
99
- }
100
-
101
- /**
102
- * This method is called by the dom and should not be called directly.
103
- *
104
- * @return {void}
105
- */
106
- disconnectedCallback() {
107
- super.disconnectedCallback();
108
- disconnectResizeObserver.call(this);
109
- }
110
-
111
- /**
112
- * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
113
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
114
- *
115
- * The individual configuration values can be found in the table.
116
- *
117
- * @property {Object} templates Template definitions
118
- * @property {string} templates.main Main template
119
- * @property {Object} labels Label definitions
120
- * @property {Object} actions Callbacks
121
- * @property {string} actions.click="throw Error" Callback when clicked
122
- * @property {Object} features Features
123
- * @property {boolean} features.allowFullScreen=true Allow fullscreen
124
- * @property {boolean} features.allowPaymentRequest=true Allow payment request
125
- * @property {boolean} features.replaceTargets=true Replace parent target in iframe
126
- * @property {string} loading="eager" Loading state
127
- * @property {string} referrerPolicy="no-referrer" Referrer policy
128
- * @property {string} src Source
129
- * @property {Object} classes CSS classes
130
- * @property {boolean} disabled=false Disabled state
131
- */
132
- get defaults() {
133
- return Object.assign({}, super.defaults, {
134
- templates: {
135
- main: getTemplate(),
136
- },
137
- src: null,
138
-
139
- /* "allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-top-navigation"*/
140
- sandbox: null,
141
-
142
- labels: {},
143
- classes: {},
144
-
145
- name: "",
146
-
147
- referrerPolicy: "no-referrer",
148
-
149
- disabled: false,
150
- features: {
151
- allowFullScreen: true,
152
- allowPaymentRequest: true,
153
- replaceTargets: true,
154
- },
155
-
156
- loading: "eager",
157
-
158
- actions: {
159
- click: () => {
160
- throw new Error("the click action is not defined");
161
- },
162
- },
163
- });
164
- }
165
-
166
- /**
167
- * @return {string}
168
- */
169
- static getTag() {
170
- return "monster-iframe";
171
- }
172
-
173
- /**
174
- * @return {CSSStyleSheet[]}
175
- */
176
- static getCSSStyleSheet() {
177
- return [IframeStyleSheet];
178
- }
65
+ /**
66
+ * This method is called by the `instanceof` operator.
67
+ * @return {symbol}
68
+ */
69
+ static get [instanceSymbol]() {
70
+ return Symbol.for("@schukai/monster/components/layout/iframe@@instance");
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @return {Components.Layout.Iframe
76
+ * @fires monster-iframe-clicked
77
+ */
78
+ [assembleMethodSymbol]() {
79
+ super[assembleMethodSymbol]();
80
+ initControlReferences.call(this);
81
+ initEventHandler.call(this);
82
+ calcHeight.call(this);
83
+ return this;
84
+ }
85
+
86
+ /**
87
+ * This method is called by the dom and should not be called directly.
88
+ *
89
+ * @return {void}
90
+ */
91
+ connectedCallback() {
92
+ super.connectedCallback();
93
+ attachResizeObserver.call(this);
94
+
95
+ // disable scrolling in parent node
96
+ if (this.parentNode && this.parentNode instanceof HTMLElement) {
97
+ this.parentNode.style.overflow = "hidden";
98
+ }
99
+ }
100
+
101
+ /**
102
+ * This method is called by the dom and should not be called directly.
103
+ *
104
+ * @return {void}
105
+ */
106
+ disconnectedCallback() {
107
+ super.disconnectedCallback();
108
+ disconnectResizeObserver.call(this);
109
+ }
110
+
111
+ /**
112
+ * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
113
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
114
+ *
115
+ * The individual configuration values can be found in the table.
116
+ *
117
+ * @property {Object} templates Template definitions
118
+ * @property {string} templates.main Main template
119
+ * @property {Object} labels Label definitions
120
+ * @property {Object} actions Callbacks
121
+ * @property {string} actions.click="throw Error" Callback when clicked
122
+ * @property {Object} features Features
123
+ * @property {boolean} features.allowFullScreen=true Allow fullscreen
124
+ * @property {boolean} features.allowPaymentRequest=true Allow payment request
125
+ * @property {boolean} features.replaceTargets=true Replace parent target in iframe
126
+ * @property {string} loading="eager" Loading state
127
+ * @property {string} referrerPolicy="no-referrer" Referrer policy
128
+ * @property {string} src Source
129
+ * @property {Object} classes CSS classes
130
+ * @property {boolean} disabled=false Disabled state
131
+ */
132
+ get defaults() {
133
+ return Object.assign({}, super.defaults, {
134
+ templates: {
135
+ main: getTemplate(),
136
+ },
137
+ src: null,
138
+
139
+ /* "allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-top-navigation"*/
140
+ sandbox: null,
141
+
142
+ labels: {},
143
+ classes: {},
144
+
145
+ name: "",
146
+
147
+ referrerPolicy: "no-referrer",
148
+
149
+ disabled: false,
150
+ features: {
151
+ allowFullScreen: true,
152
+ allowPaymentRequest: true,
153
+ replaceTargets: true,
154
+ },
155
+
156
+ loading: "eager",
157
+
158
+ actions: {
159
+ click: () => {
160
+ throw new Error("the click action is not defined");
161
+ },
162
+ },
163
+ });
164
+ }
165
+
166
+ /**
167
+ * @return {string}
168
+ */
169
+ static getTag() {
170
+ return "monster-iframe";
171
+ }
172
+
173
+ /**
174
+ * @return {CSSStyleSheet[]}
175
+ */
176
+ static getCSSStyleSheet() {
177
+ return [IframeStyleSheet];
178
+ }
179
179
  }
180
180
 
181
181
  /**
182
182
  * @private
183
183
  */
184
184
  function calcHeight() {
185
- this.style.boxSizing = "border-box";
185
+ this.style.boxSizing = "border-box";
186
186
 
187
- const height = calculateMaximumHeight.call(this, this.parentNode);
188
- if (height < 0 || isNaN(height)) {
189
- return;
190
- }
187
+ const height = calculateMaximumHeight.call(this, this.parentNode);
188
+ if (height < 0 || isNaN(height)) {
189
+ return;
190
+ }
191
191
 
192
- this[iframeElementSymbol].style.height = `${height}px`;
192
+ this[iframeElementSymbol].style.height = `${height}px`;
193
193
  }
194
194
 
195
195
  /**
@@ -198,90 +198,90 @@ function calcHeight() {
198
198
  * @return {*}
199
199
  */
200
200
  function calculateMaximumHeight(element) {
201
- let totalBottomBorder = 0;
202
- let totalBottomPadding = 0;
203
- let totalBottomMargin = 0;
204
- let totalOutlineHeight = 0;
205
- let totalBoxShadowHeight = 0;
206
- let currentElement = element;
207
-
208
- while (currentElement && currentElement !== document.body) {
209
- const style = window.getComputedStyle(currentElement);
210
- const boxSizing = style.boxSizing;
211
-
212
- const elementHeight = currentElement.getBoundingClientRect().height;
213
-
214
- const borderBottomWidth = parseFloat(style.borderBottomWidth);
215
- const paddingBottom = parseFloat(style.paddingBottom);
216
- const marginBottom = parseFloat(style.marginBottom);
217
-
218
- const outlineHeight = parseFloat(style.outlineWidth);
219
-
220
- totalBottomBorder += isNaN(borderBottomWidth) ? 0 : borderBottomWidth;
221
- totalBottomPadding +=
222
- isNaN(paddingBottom) || boxSizing === "border-box" ? 0 : paddingBottom;
223
- totalBottomMargin += isNaN(marginBottom) ? 0 : marginBottom;
224
- totalOutlineHeight += isNaN(outlineHeight) ? 0 : outlineHeight;
225
-
226
- const boxShadow = style.boxShadow;
227
- let boxShadowVerticalTotal = 0;
228
-
229
- if (boxShadow !== "none") {
230
- const boxShadowValues = boxShadow.split(" ");
231
- const verticalOffset = parseFloat(boxShadowValues[3]);
232
- const blurRadius = parseFloat(boxShadowValues[4]);
233
- const spreadRadius = parseFloat(boxShadowValues[5]);
234
-
235
- boxShadowVerticalTotal = verticalOffset + blurRadius + spreadRadius;
236
- }
237
-
238
- totalBoxShadowHeight += isNaN(boxShadowVerticalTotal)
239
- ? 0
240
- : boxShadowVerticalTotal;
241
-
242
- if (elementHeight > 200) {
243
- return (
244
- elementHeight -
245
- totalBottomBorder -
246
- totalBottomPadding -
247
- totalBottomMargin -
248
- totalOutlineHeight -
249
- totalBoxShadowHeight
250
- );
251
- }
252
-
253
- currentElement = currentElement.parentNode || currentElement.host;
254
- }
201
+ let totalBottomBorder = 0;
202
+ let totalBottomPadding = 0;
203
+ let totalBottomMargin = 0;
204
+ let totalOutlineHeight = 0;
205
+ let totalBoxShadowHeight = 0;
206
+ let currentElement = element;
207
+
208
+ while (currentElement && currentElement !== document.body) {
209
+ const style = window.getComputedStyle(currentElement);
210
+ const boxSizing = style.boxSizing;
211
+
212
+ const elementHeight = currentElement.getBoundingClientRect().height;
213
+
214
+ const borderBottomWidth = parseFloat(style.borderBottomWidth);
215
+ const paddingBottom = parseFloat(style.paddingBottom);
216
+ const marginBottom = parseFloat(style.marginBottom);
217
+
218
+ const outlineHeight = parseFloat(style.outlineWidth);
219
+
220
+ totalBottomBorder += isNaN(borderBottomWidth) ? 0 : borderBottomWidth;
221
+ totalBottomPadding +=
222
+ isNaN(paddingBottom) || boxSizing === "border-box" ? 0 : paddingBottom;
223
+ totalBottomMargin += isNaN(marginBottom) ? 0 : marginBottom;
224
+ totalOutlineHeight += isNaN(outlineHeight) ? 0 : outlineHeight;
225
+
226
+ const boxShadow = style.boxShadow;
227
+ let boxShadowVerticalTotal = 0;
228
+
229
+ if (boxShadow !== "none") {
230
+ const boxShadowValues = boxShadow.split(" ");
231
+ const verticalOffset = parseFloat(boxShadowValues[3]);
232
+ const blurRadius = parseFloat(boxShadowValues[4]);
233
+ const spreadRadius = parseFloat(boxShadowValues[5]);
234
+
235
+ boxShadowVerticalTotal = verticalOffset + blurRadius + spreadRadius;
236
+ }
237
+
238
+ totalBoxShadowHeight += isNaN(boxShadowVerticalTotal)
239
+ ? 0
240
+ : boxShadowVerticalTotal;
241
+
242
+ if (elementHeight > 200) {
243
+ return (
244
+ elementHeight -
245
+ totalBottomBorder -
246
+ totalBottomPadding -
247
+ totalBottomMargin -
248
+ totalOutlineHeight -
249
+ totalBoxShadowHeight
250
+ );
251
+ }
252
+
253
+ currentElement = currentElement.parentNode || currentElement.host;
254
+ }
255
255
  }
256
256
 
257
257
  /**
258
258
  * @private
259
259
  */
260
260
  function attachResizeObserver() {
261
- // against flickering
262
- this[resizeObserverSymbol] = new ResizeObserver(() => {
263
- if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
264
- try {
265
- this[timerCallbackSymbol].touch();
266
- return;
267
- } catch (e) {
268
- delete this[timerCallbackSymbol];
269
- }
270
- }
271
-
272
- this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
273
- calcHeight.call(this);
274
- });
275
- });
276
-
277
- this[resizeObserverSymbol].observe(this.ownerDocument.body);
278
- this[resizeObserverSymbol].observe(document.scrollingElement);
261
+ // against flickering
262
+ this[resizeObserverSymbol] = new ResizeObserver(() => {
263
+ if (this[timerCallbackSymbol] instanceof DeadMansSwitch) {
264
+ try {
265
+ this[timerCallbackSymbol].touch();
266
+ return;
267
+ } catch (e) {
268
+ delete this[timerCallbackSymbol];
269
+ }
270
+ }
271
+
272
+ this[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
273
+ calcHeight.call(this);
274
+ });
275
+ });
276
+
277
+ this[resizeObserverSymbol].observe(this.ownerDocument.body);
278
+ this[resizeObserverSymbol].observe(document.scrollingElement);
279
279
  }
280
280
 
281
281
  function disconnectResizeObserver() {
282
- if (this[resizeObserverSymbol] instanceof ResizeObserver) {
283
- this[resizeObserverSymbol].disconnect();
284
- }
282
+ if (this[resizeObserverSymbol] instanceof ResizeObserver) {
283
+ this[resizeObserverSymbol].disconnect();
284
+ }
285
285
  }
286
286
 
287
287
  /**
@@ -289,46 +289,48 @@ function disconnectResizeObserver() {
289
289
  * @return {initEventHandler}
290
290
  */
291
291
  function initEventHandler() {
292
- const self = this;
293
- const element = this[iframeElementSymbol];
294
-
295
- const type = "click";
296
-
297
- element.addEventListener(type, function (event) {
298
- const callback = self.getOption("actions.click");
299
-
300
- fireCustomEvent(self, "monster-iframe-clicked", {
301
- element: self,
302
- });
303
-
304
- if (!isFunction(callback)) {
305
- return;
306
- }
307
-
308
- const element = findTargetElementFromEvent(
309
- event,
310
- ATTRIBUTE_ROLE,
311
- "control",
312
- );
313
-
314
- if (!(element instanceof Node && self.hasNode(element))) {
315
- return;
316
- }
317
-
318
- callback.call(self, event);
319
- });
320
-
321
- this[iframeElementSymbol].addEventListener("load", () => {
322
- calcHeight.call(this);
323
- if (this.getOption("features.replaceTargets")) {
324
- const links = this[iframeElementSymbol].contentDocument.querySelectorAll('a[target="_parent"], form[target="_parent"], a[target="_top"], form[target="_top"]');
325
- links.forEach(function(link) {
326
- link.target = '_self';
327
- });
328
- }
329
- });
330
-
331
- return this;
292
+ const self = this;
293
+ const element = this[iframeElementSymbol];
294
+
295
+ const type = "click";
296
+
297
+ element.addEventListener(type, function (event) {
298
+ const callback = self.getOption("actions.click");
299
+
300
+ fireCustomEvent(self, "monster-iframe-clicked", {
301
+ element: self,
302
+ });
303
+
304
+ if (!isFunction(callback)) {
305
+ return;
306
+ }
307
+
308
+ const element = findTargetElementFromEvent(
309
+ event,
310
+ ATTRIBUTE_ROLE,
311
+ "control",
312
+ );
313
+
314
+ if (!(element instanceof Node && self.hasNode(element))) {
315
+ return;
316
+ }
317
+
318
+ callback.call(self, event);
319
+ });
320
+
321
+ this[iframeElementSymbol].addEventListener("load", () => {
322
+ calcHeight.call(this);
323
+ if (this.getOption("features.replaceTargets")) {
324
+ const links = this[iframeElementSymbol].contentDocument.querySelectorAll(
325
+ 'a[target="_parent"], form[target="_parent"], a[target="_top"], form[target="_top"]',
326
+ );
327
+ links.forEach(function (link) {
328
+ link.target = "_self";
329
+ });
330
+ }
331
+ });
332
+
333
+ return this;
332
334
  }
333
335
 
334
336
  /**
@@ -336,17 +338,17 @@ function initEventHandler() {
336
338
  * @return {void}
337
339
  */
338
340
  function initControlReferences() {
339
- if (!this.shadowRoot) {
340
- throw new Error("no shadow-root is defined");
341
- }
341
+ if (!this.shadowRoot) {
342
+ throw new Error("no shadow-root is defined");
343
+ }
342
344
 
343
- this[PanelElementSymbol] = this.shadowRoot.querySelector(
344
- "[data-monster-role=control]",
345
- );
345
+ this[PanelElementSymbol] = this.shadowRoot.querySelector(
346
+ "[data-monster-role=control]",
347
+ );
346
348
 
347
- this[iframeElementSymbol] = this.shadowRoot.querySelector(
348
- `[${ATTRIBUTE_ROLE}="control"] iframe`,
349
- );
349
+ this[iframeElementSymbol] = this.shadowRoot.querySelector(
350
+ `[${ATTRIBUTE_ROLE}="control"] iframe`,
351
+ );
350
352
  }
351
353
 
352
354
  /**
@@ -354,8 +356,8 @@ function initControlReferences() {
354
356
  * @return {string}
355
357
  */
356
358
  function getTemplate() {
357
- // language=HTML
358
- return `
359
+ // language=HTML
360
+ return `
359
361
  <div data-monster-role="control" part="control">
360
362
  <iframe data-monster-role="iframe"
361
363
  data-monster-attributes="sandbox path:sandbox,
@@ -205,5 +205,6 @@ export { Monster };
205
205
  * @license AGPLv3 or commercial license
206
206
  * @since 2.0.0
207
207
  * @copyright schukai GmbH
208
+ * @memberOf Monster
208
209
  */
209
210
  class Monster {}