@schukai/monster 3.42.1 → 3.44.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.42.1",
3
+ "version": "3.44.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright schukai GmbH and contributors 2023. All Rights Reserved.
3
+ * Node module: @schukai/monster
4
+ * This file is licensed under the AGPLv3 License.
5
+ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
+ */
7
+
8
+ import { internalSymbol, instanceSymbol } from "../../../../constants.mjs";
9
+
10
+ export { DataFetchError };
11
+
12
+ /**
13
+ * Error message for API requests
14
+ *
15
+ * @license AGPLv3
16
+ * @since 3.43.0
17
+ * @copyright schukai GmbH
18
+ * @memberOf Monster.Data.Datasource.Server.RestAPI
19
+ * @summary the error is thrown by the rest api in case of error
20
+ */
21
+ class DataFetchError extends Error {
22
+ /**
23
+ *
24
+ * @param {string} message
25
+ * @param {Response} response
26
+ */
27
+ constructor(message, response) {
28
+ super(message);
29
+ this[internalSymbol] = {
30
+ response: response
31
+ };
32
+ }
33
+
34
+ /**
35
+ * This method is called by the `instanceof` operator.
36
+ * @returns {symbol}
37
+ * @since 2.1.0
38
+ */
39
+ static get [instanceSymbol]() {
40
+ return Symbol.for("@schukai/monster/data/datasource/server/restapi/datafetcherror@@instance");
41
+ }
42
+
43
+ /**
44
+ * @return {Response}
45
+ */
46
+ getResponse() {
47
+ return this[internalSymbol]["response"];
48
+ }
49
+
50
+ }
@@ -5,12 +5,13 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import { internalSymbol, instanceSymbol } from "../../../constants.mjs";
9
- import { isObject, isFunction } from "../../../types/is.mjs";
10
- import { Server } from "../server.mjs";
11
- import { WriteError } from "./restapi/writeerror.mjs";
8
+ import {internalSymbol, instanceSymbol} from "../../../constants.mjs";
9
+ import {isObject, isFunction} from "../../../types/is.mjs";
10
+ import {Server} from "../server.mjs";
11
+ import {WriteError} from "./restapi/writeerror.mjs";
12
+ import {DataFetchError} from "./restapi/data-fetch-error.mjs";
12
13
 
13
- export { RestAPI };
14
+ export {RestAPI};
14
15
 
15
16
  /**
16
17
  * @type {symbol}
@@ -188,7 +189,7 @@ function fetchData(init, key, callback) {
188
189
  const acceptedStatus = self.getOption(`${key}.acceptedStatus`, [200]);
189
190
 
190
191
  if (acceptedStatus.indexOf(resp.status) === -1) {
191
- throw Error(`the data cannot be ${key} (response ${resp.status})`);
192
+ throw new DataFetchError(`the response does not contain a accepted status (actual: ${resp.status}).`, response);
192
193
  }
193
194
 
194
195
  return resp.text();
@@ -205,7 +206,7 @@ function fetchData(init, key, callback) {
205
206
  body = `${body.substring(0, 97)}...`;
206
207
  }
207
208
 
208
- throw new Error(`the response does not contain a valid json (actual: ${body}).`);
209
+ throw new DataFetchError(`the response does not contain a valid json (actual: ${body}).`, response);
209
210
  }
210
211
 
211
212
  if (callback && isFunction(callback)) {
@@ -203,9 +203,9 @@ class CustomElement extends HTMLElement {
203
203
  this[internalSymbol] = new ProxyObserver({
204
204
  options: initOptionsFromAttributes(this, extend({}, this.defaults)),
205
205
  });
206
- initAttributeChangeMutationObserver.call(this);
207
- initOptionObserver.call(this);
208
206
  this[initMethodSymbol]();
207
+ initOptionObserver.call(this);
208
+ initAttributeChangeMutationObserver.call(this);
209
209
  }
210
210
 
211
211
  /**
@@ -229,6 +229,28 @@ class CustomElement extends HTMLElement {
229
229
  return [ATTRIBUTE_OPTIONS, ATTRIBUTE_DISABLED];
230
230
  }
231
231
 
232
+ /**
233
+ *
234
+ * @param attribute
235
+ * @param callback
236
+ * @returns {Monster.DOM.CustomElement}
237
+ */
238
+ addAttributeObserver(attribute, callback) {
239
+ validateFunction(callback);
240
+ this[attributeObserverSymbol][attribute] = callback;
241
+ return this;
242
+ }
243
+
244
+ /**
245
+ *
246
+ * @param attribute
247
+ * @returns {Monster.DOM.CustomElement}
248
+ */
249
+ removeAttributeObserver(attribute) {
250
+ delete this[attributeObserverSymbol][attribute];
251
+ return this;
252
+ }
253
+
232
254
  /**
233
255
  * Derived classes can override and extend this method as follows.
234
256
  *
@@ -611,14 +633,6 @@ class CustomElement extends HTMLElement {
611
633
  function initAttributeChangeMutationObserver() {
612
634
  const self = this;
613
635
 
614
- if (self[attributeObserverSymbol] === undefined) {
615
- self[attributeObserverSymbol] = {};
616
- }
617
-
618
- if(Object.keys(self[attributeObserverSymbol]).length === 0) {
619
- return;
620
- }
621
-
622
636
  new MutationObserver(function (mutations) {
623
637
  for (const mutation of mutations) {
624
638
  if (mutation.type === "attributes") {
@@ -628,7 +642,6 @@ function initAttributeChangeMutationObserver() {
628
642
  }).observe(self, {
629
643
  attributes: true,
630
644
  attributeOldValue: true,
631
- attributeFilter: Object.keys(self[attributeObserverSymbol]),
632
645
  });
633
646
  }
634
647
 
@@ -37,7 +37,7 @@ export { Updater, addObjectWithUpdaterToElement };
37
37
  * The updater class connects an object with the dom. In this way, structures and contents in the DOM can be programmatically adapted via attributes.
38
38
  *
39
39
  * For example, to include a string from an object, the attribute `data-monster-replace` can be used.
40
- * a further explanation can be found under {@tutorial dom-based-templating-implementation}.
40
+ * a further explanation can be found under [monsterjs.org](https://monsterjs.org/)
41
41
  *
42
42
  * Changes to attributes are made only when the direct values are changed. If you want to assign changes to other values
43
43
  * as well, you have to insert the attribute `data-monster-select-this`. This should be done with care, as it can reduce performance.
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.42.1");
145
+ monsterVersion = new Version("3.44.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.42.1")
10
+ monsterVersion = new Version("3.44.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13