@schukai/monster 4.38.5 → 4.38.6
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/CHANGELOG.md
CHANGED
package/package.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.3","@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":"4.38.
|
1
|
+
{"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.7.3","@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":"4.38.6"}
|
@@ -16,9 +16,9 @@ import { Datasource, dataSourceSymbol } from "../datasource.mjs";
|
|
16
16
|
import { DatasourceStyleSheet } from "../stylesheet/datasource.mjs";
|
17
17
|
import { instanceSymbol } from "../../../constants.mjs";
|
18
18
|
import {
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
assembleMethodSymbol,
|
20
|
+
registerCustomElement,
|
21
|
+
getSlottedElements,
|
22
22
|
} from "../../../dom/customelement.mjs";
|
23
23
|
import { isArray } from "../../../types/is.mjs";
|
24
24
|
|
@@ -37,174 +37,174 @@ const dataChangeEventHandlerSymbol = Symbol("dataChangeEventHandler");
|
|
37
37
|
* @summary A dom datasource
|
38
38
|
*/
|
39
39
|
class Dom extends Datasource {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
40
|
+
/**
|
41
|
+
* This method is called by the `instanceof` operator.
|
42
|
+
* @return {symbol}
|
43
|
+
*/
|
44
|
+
static get [instanceSymbol]() {
|
45
|
+
return Symbol.for("@schukai/monster/components/datasource/dom@@instance");
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
|
50
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
51
|
+
*
|
52
|
+
* The individual configuration values can be found in the table.
|
53
|
+
*
|
54
|
+
* @property {Object} templates Template definitions
|
55
|
+
* @property {string} templates.main Main template
|
56
|
+
* @property {Object} features Feature definitions
|
57
|
+
* @property {boolean} features.autoInit Automatically initializes the component
|
58
|
+
*/
|
59
|
+
get defaults() {
|
60
|
+
return Object.assign({}, super.defaults, {
|
61
|
+
templates: {
|
62
|
+
main: getTemplate(),
|
63
|
+
},
|
64
|
+
|
65
|
+
features: {
|
66
|
+
autoInit: true,
|
67
|
+
},
|
68
|
+
|
69
|
+
/** @private */
|
70
|
+
sys: {
|
71
|
+
pagination: {
|
72
|
+
pages: 1,
|
73
|
+
objectsPerPage: 10,
|
74
|
+
currentPage: 1,
|
75
|
+
},
|
76
|
+
},
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* @return {void}
|
82
|
+
*/
|
83
|
+
[assembleMethodSymbol]() {
|
84
|
+
super[assembleMethodSymbol]();
|
85
|
+
initEventHandler.call(this);
|
86
|
+
updateDataSource.call(this);
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* This method set the current page of the pagination
|
91
|
+
*
|
92
|
+
* @param {string} page
|
93
|
+
* @return {Dom}
|
94
|
+
*/
|
95
|
+
setParameters({ page }) {
|
96
|
+
this.setOption("sys.pagination.currentPage", page);
|
97
|
+
return this;
|
98
|
+
}
|
99
|
+
|
100
|
+
/**
|
101
|
+
*
|
102
|
+
* @return {CSSStyleSheet[]}
|
103
|
+
*/
|
104
|
+
static getCSSStyleSheet() {
|
105
|
+
return [DatasourceStyleSheet];
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @private
|
110
|
+
* @return {string}
|
111
|
+
*/
|
112
|
+
static getTag() {
|
113
|
+
return "monster-datasource-dom";
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Reloads the data
|
118
|
+
* @return {Promise<never>|*}
|
119
|
+
*/
|
120
|
+
reload() {}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* @return {void}
|
124
|
+
*/
|
125
|
+
connectedCallback() {
|
126
|
+
super.connectedCallback();
|
127
|
+
|
128
|
+
if (this.getOption("features.autoInit")) {
|
129
|
+
updateDataSource.call(this);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* @return {int}
|
135
|
+
*/
|
136
|
+
currentPage() {
|
137
|
+
return this.getOption("sys.pagination.currentPage");
|
138
|
+
}
|
139
139
|
}
|
140
140
|
|
141
141
|
/**
|
142
142
|
* @private
|
143
143
|
*/
|
144
144
|
function initEventHandler() {
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
145
|
+
/**
|
146
|
+
* @param {Event} event
|
147
|
+
*/
|
148
|
+
this[dataChangeEventHandlerSymbol] = (event) => {
|
149
|
+
updateDataSource.call(this);
|
150
|
+
};
|
151
|
+
|
152
|
+
new MutationObserver(this[dataChangeEventHandlerSymbol]).observe(this, {
|
153
|
+
childList: true,
|
154
|
+
subtree: true,
|
155
|
+
characterData: true,
|
156
|
+
});
|
157
157
|
}
|
158
158
|
|
159
159
|
/**
|
160
160
|
* @private
|
161
161
|
*/
|
162
162
|
function updateDataSource() {
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
163
|
+
let data = null;
|
164
|
+
getSlottedElements.call(this).forEach((element) => {
|
165
|
+
if (!(element instanceof HTMLScriptElement)) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
if (element.type !== "application/json") {
|
169
|
+
return;
|
170
|
+
}
|
171
|
+
|
172
|
+
const d = JSON.parse(element.textContent);
|
173
|
+
if (data === null) {
|
174
|
+
if (isArray(d)) {
|
175
|
+
data = [];
|
176
|
+
} else {
|
177
|
+
data = {};
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
if (isArray(data) && !isArray(d)) {
|
182
|
+
throw new Error("Type mismatch");
|
183
|
+
}
|
184
|
+
|
185
|
+
if (!isArray(data) && isArray(d)) {
|
186
|
+
throw new Error("Type mismatch");
|
187
|
+
}
|
188
|
+
|
189
|
+
if (isArray(data)) {
|
190
|
+
data.push(...d);
|
191
|
+
return;
|
192
|
+
}
|
193
|
+
|
194
|
+
data = Object.assign({}, d);
|
195
|
+
});
|
196
|
+
|
197
|
+
if (data === null) {
|
198
|
+
data = [];
|
199
|
+
}
|
200
|
+
|
201
|
+
// set pagination
|
202
|
+
this.setOption("sys.pagination.objectsPerPage", 1);
|
203
|
+
this.setOption("sys.pagination.pages", data.length);
|
204
|
+
this.setOption("sys.pagination.currentPage", 1);
|
205
|
+
|
206
|
+
/** call setter */
|
207
|
+
this.data = data;
|
208
208
|
}
|
209
209
|
|
210
210
|
/**
|
@@ -212,8 +212,8 @@ function updateDataSource() {
|
|
212
212
|
* @return {string}
|
213
213
|
*/
|
214
214
|
function getTemplate() {
|
215
|
-
|
216
|
-
|
215
|
+
// language=HTML
|
216
|
+
return `
|
217
217
|
<slot data-monster-role="datasource"></slot>`;
|
218
218
|
}
|
219
219
|
|