@schukai/monster 3.12.2 → 3.13.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.12.2",
3
+ "version": "3.13.1",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Copyright schukai GmbH and contributors 2022. 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 { instanceSymbol } from "../../constants.mjs";
9
+ import { isObject } from "../../types/is.mjs";
10
+ import { Datasource } from "../datasource.mjs";
11
+
12
+ export {DomStorage};
13
+
14
+
15
+ /**
16
+ * The DomStorage is a class that stores data in memory.
17
+ *
18
+ * @license AGPLv3
19
+ * @copyright schukai GmbH
20
+ * @memberOf Monster.Data.Datasource
21
+ */
22
+ class DomStorage extends Datasource {
23
+ /**
24
+ * @param {Object} [options] options contains definitions for the datasource.
25
+ */
26
+ constructor(options) {
27
+ super();
28
+
29
+ if (isObject(options)) {
30
+ this.setOptions(options);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * This method is called by the `instanceof` operator.
36
+ * @returns {symbol}
37
+ */
38
+ static get [instanceSymbol]() {
39
+ return Symbol.for("@schukai/monster/data/datasource/storage/dom-storage");
40
+ }
41
+
42
+ /**
43
+ * @property {Object} defaults
44
+ * @property {Object} defaults.read
45
+ * @property {string} defaults.read.selector
46
+ * @property {Object} defaults.write
47
+ * @property {string} defaults.write.selector
48
+ */
49
+ get defaults() {
50
+ return Object.assign({}, super.defaults, {
51
+ read: {
52
+ selector: undefined,
53
+ },
54
+ write: {
55
+ selector: undefined,
56
+ }
57
+ });
58
+ }
59
+
60
+ /**
61
+ * @return {Promise}
62
+ * @throws {Error} The read selector is not defined
63
+ * @throws {Error} There are no storage element
64
+ */
65
+ read() {
66
+ const self = this;
67
+
68
+ let selector = self.getOption("read.selector", undefined);
69
+ if (!selector) {
70
+ throw new Error("The read selector is not defined");
71
+ }
72
+
73
+ let storage = document.querySelector(selector);
74
+ if (!storage) {
75
+ throw new Error("There are no storage element");
76
+ }
77
+
78
+ return new Promise((resolve, reject) => {
79
+ try {
80
+ let data = JSON.parse(storage.innerHTML);
81
+ self.set(data)
82
+ resolve(data);
83
+ } catch (e) {
84
+ reject(e);
85
+ }
86
+ ;
87
+ })
88
+ }
89
+
90
+ /**
91
+ * @return {Promise}
92
+ * @throws {Error} The write selector is not defined
93
+ * @throws {Error} There are no storage element
94
+ */
95
+ write() {
96
+
97
+ const self = this;
98
+
99
+ let selector = self.getOption("write.selector");
100
+ if (!selector) {
101
+ throw new Error("The write selector is not defined");
102
+ }
103
+
104
+ let storage = document.querySelector(selector);
105
+ if (!storage) {
106
+ throw new Error("There are no storage element");
107
+ }
108
+
109
+ return new Promise((resolve, reject) => {
110
+ try {
111
+ storage.innerHTML = JSON.stringify(self.get());
112
+ resolve(storage);
113
+ } catch (e) {
114
+ reject(e);
115
+ }
116
+ })
117
+
118
+
119
+ }
120
+
121
+ }
122
+
@@ -465,7 +465,6 @@ function transform(value) {
465
465
 
466
466
  case "i18n":
467
467
  case "translation":
468
-
469
468
  translations = getDocumentTranslations();
470
469
  if (!(translations instanceof Translations)) {
471
470
  throw new Error("missing translations");
@@ -614,7 +614,7 @@ function runUpdateContent(container, parts, subject) {
614
614
  parts.pop();
615
615
 
616
616
  // Unfortunately, static data is always changed as well, since it is not possible to react to changes here.
617
- const query = `[${ATTRIBUTE_UPDATER_REPLACE}^="path:${current}"], [${ATTRIBUTE_UPDATER_REPLACE}^="static:"]`;
617
+ const query = `[${ATTRIBUTE_UPDATER_REPLACE}^="path:${current}"], [${ATTRIBUTE_UPDATER_REPLACE}^="static:"], [${ATTRIBUTE_UPDATER_REPLACE}^="i18n:"]`;
618
618
  const e = container.querySelectorAll(`${query}`);
619
619
 
620
620
  const iterator = new Set([...e]);
@@ -702,7 +702,7 @@ function runUpdateAttributes(container, parts, subject) {
702
702
 
703
703
  let iterator = new Set();
704
704
 
705
- const query = `[${ATTRIBUTE_UPDATER_SELECT_THIS}], [${ATTRIBUTE_UPDATER_ATTRIBUTES}*="path:${current}"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="static:"]`;
705
+ const query = `[${ATTRIBUTE_UPDATER_SELECT_THIS}], [${ATTRIBUTE_UPDATER_ATTRIBUTES}*="path:${current}"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="static:"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="i18n:"]`;
706
706
 
707
707
  const e = container.querySelectorAll(query);
708
708
 
@@ -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.12.2");
145
+ monsterVersion = new Version("3.13.1");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -0,0 +1,18 @@
1
+ import {expect} from "chai"
2
+ import {DomStorage} from "../../../../../application/source/data/datasource/dom.mjs";
3
+
4
+
5
+ describe('ServeDomr', function () {
6
+
7
+ it('should init', function () {
8
+
9
+ const dom = new DomStorage({
10
+
11
+ })
12
+
13
+ expect(dom).to.be.not.null
14
+
15
+
16
+ })
17
+
18
+ });
@@ -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.12.2")
10
+ monsterVersion = new Version("3.13.1")
11
11
 
12
12
  let m = getMonsterVersion();
13
13