@schukai/monster 3.69.2 → 3.71.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 (44) hide show
  1. package/CHANGELOG.md +29 -4
  2. package/package.json +1 -1
  3. package/source/components/datatable/dataset.mjs +278 -202
  4. package/source/components/datatable/datasource/dom.mjs +1 -1
  5. package/source/components/datatable/datasource/rest.mjs +410 -404
  6. package/source/components/datatable/filter.mjs +1 -0
  7. package/source/components/datatable/save-button.mjs +1 -9
  8. package/source/components/datatable/style/datatable.pcss +1 -1
  9. package/source/components/datatable/style/filter-controls-defaults.pcss +1 -1
  10. package/source/components/datatable/stylesheet/filter-controls-defaults.mjs +8 -17
  11. package/source/components/form/context-error.mjs +2 -0
  12. package/source/components/form/context-help.mjs +1 -0
  13. package/source/components/form/field-set.mjs +222 -225
  14. package/source/components/form/form.mjs +185 -545
  15. package/source/components/form/select.mjs +24 -9
  16. package/source/components/form/style/field-set.pcss +84 -7
  17. package/source/components/form/style/form.pcss +5 -3
  18. package/source/components/form/style/select.pcss +5 -4
  19. package/source/components/form/stylesheet/field-set.mjs +7 -14
  20. package/source/components/form/stylesheet/form.mjs +8 -17
  21. package/source/components/form/stylesheet/select.mjs +7 -14
  22. package/source/components/layout/style/collapse.pcss +0 -2
  23. package/source/components/layout/stylesheet/collapse.mjs +7 -14
  24. package/source/components/style/form.pcss +66 -3
  25. package/source/components/style/mixin/property.pcss +8 -1
  26. package/source/components/style/typography.pcss +4 -12
  27. package/source/components/stylesheet/form.mjs +8 -17
  28. package/source/components/stylesheet/mixin/form.mjs +7 -16
  29. package/source/components/stylesheet/mixin/property.mjs +6 -13
  30. package/source/components/stylesheet/typography.mjs +7 -16
  31. package/source/data/datasource/server/restapi.mjs +191 -180
  32. package/source/data/datasource/server.mjs +118 -74
  33. package/source/data/diff.mjs +1 -1
  34. package/source/dom/customelement.mjs +4 -0
  35. package/source/dom/updater.mjs +1 -1
  36. package/source/types/tokenlist.mjs +2 -2
  37. package/test/cases/components/form/form.mjs +1 -182
  38. package/test/cases/components/host/details.mjs +1 -1
  39. package/test/cases/components/host/host.mjs +1 -1
  40. package/test/cases/components/host/overlay.mjs +1 -1
  41. package/test/cases/data/diff.mjs +37 -0
  42. package/test/cases/dom/customcontrol.mjs +1 -1
  43. package/test/cases/dom/customelement.mjs +2 -2
  44. package/source/components/style/mixin/form.pcss +0 -242
@@ -12,8 +12,8 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import { isIterable, isString } from "../types/is.mjs";
16
- import { validateFunction, validateString } from "../types/validate.mjs";
15
+ import { isIterable, isString } from "./is.mjs";
16
+ import { validateFunction, validateString } from "./validate.mjs";
17
17
  import { Base } from "./base.mjs";
18
18
 
19
19
  export { TokenList };
@@ -10,13 +10,12 @@ import {storageObjectSymbol} from "../../../../source/data/datasource/storage.mj
10
10
  let expect = chai.expect;
11
11
  chai.use(chaiDom);
12
12
 
13
- const global = getGlobal();
14
-
15
13
  let html1 = `
16
14
  <div id="test1">
17
15
  <monster-form id="form1"></monster-form>
18
16
  </div>
19
17
  `;
18
+
20
19
  let html2 = `
21
20
  <div id="test2">
22
21
  <monster-form id="form2"
@@ -37,27 +36,6 @@ let html2 = `
37
36
  </monster-form>
38
37
  </div>
39
38
  `;
40
- let html3 = `
41
- <div id="test3">
42
- <monster-form id="form3">
43
- <div>
44
- <div>
45
- <input name="control1"
46
- id="control1"
47
- data-monster-attributes="value path:a"
48
- data-monster-bind="path:a">
49
- </div>
50
- </div>
51
- <div>
52
- <input name="control2"
53
- data-monster-attributes="value path:b"
54
- data-monster-bind="path:b">
55
- </div>
56
- <button id="button1" data-monster-datasource-handler="write">Button</button>
57
-
58
- </monster-form>
59
- </div>
60
- `;
61
39
 
62
40
  describe('Form', function () {
63
41
 
@@ -81,165 +59,6 @@ describe('Form', function () {
81
59
  localStorage.removeItem('test-key')
82
60
  })
83
61
 
84
-
85
- describe("register own datasources", function () {
86
-
87
- const sym = Symbol.for('@schukai/monster/data/datasource/@@data');
88
-
89
- let test3Datasource = class extends Datasource {
90
- constructor() {
91
- super();
92
- }
93
-
94
- read() {
95
- this[sym].setSubject({a: "test3", b: "test3"})
96
- return Promise.resolve();
97
- }
98
-
99
- get() {
100
- const self = this;
101
- return self[sym].getRealSubject();
102
- }
103
-
104
- }
105
-
106
- beforeEach(() => {
107
- let mocks = document.getElementById('mocks');
108
- mocks.innerHTML = html3;
109
-
110
- // register own datasource, after the form is loaded
111
- // because in the wild, the form is parsed before the datasource is registered
112
- form.registerDatasource('test3', test3Datasource);
113
-
114
-
115
- });
116
-
117
- it("should be able to register own datasources", function (done) {
118
- let m = form.getDatasources('test3')
119
- expect(m.get('test3')).is.a.equal(test3Datasource);
120
-
121
- const testDatasource = new test3Datasource();
122
-
123
- const formElement = document.getElementById('form3');
124
- formElement.setOption("datasource", testDatasource);
125
- formElement.refresh().then(() => {
126
- const v = formElement.getValues()
127
- expect(v).is.deep.equal({a: "test3", b: "test3"})
128
- done();
129
- }).catch(e => done(e))
130
-
131
-
132
- })
133
-
134
-
135
- })
136
-
137
- describe("register and unregister datasources", function () {
138
- const TestDatasource = class extends Datasource {
139
- constructor() {
140
- super();
141
- }
142
- }
143
-
144
- it("should register new datasource", function () {
145
-
146
- form.registerDatasource('test', TestDatasource);
147
- let m = form.getDatasources('test')
148
- expect(m.get('test')).is.a.equal(TestDatasource);
149
-
150
- form.unregisterDatasource('test');
151
- m = form.getDatasources('test')
152
-
153
- expect(m.get('test')).to.be.undefined;
154
- })
155
-
156
- })
157
-
158
-
159
- describe("example4-doc", function () {
160
-
161
- it("should init button with click event", function (done) {
162
-
163
- class MockDatasource extends Datasource {
164
-
165
- constructor() {
166
- super();
167
- }
168
-
169
- read() {
170
- return Promise.resolve({});
171
- }
172
-
173
- write(data) {
174
- // done();
175
- }
176
-
177
- [storageObjectSymbol]() {
178
- return localStorage;
179
- }
180
-
181
- }
182
-
183
- const form4 = document.createElement('monster-form');
184
- const datasource4 = new MockDatasource();
185
- expect(datasource4 instanceof Datasource).is.true;
186
- form4.setOption('datasource', datasource4)
187
-
188
- const input4 = document.createElement('input')
189
- input4.setAttribute('name', 'field');
190
- input4.setAttribute('data-monster-attributes', 'value path:headers.Host');
191
- input4.setAttribute('data-monster-bind', 'path:headers.Host');
192
- form4.appendChild(input4);
193
-
194
- const button4 = document.createElement('monster-state-button');
195
- button4.setOption('labels.button', 'click!')
196
- button4.setAttribute('data-monster-datasource-handler', 'write')
197
- button4.setOption('actions.click', () => {
198
-
199
- })
200
-
201
- form4.appendChild(button4);
202
-
203
- document.getElementById('mocks').appendChild(form4);
204
-
205
- new Processing().add(() => {
206
- button4.click();
207
- }
208
- ).run().then(() => {
209
- done();
210
- }).catch(e => done(e))
211
-
212
-
213
- })
214
-
215
-
216
- }
217
- )
218
-
219
- describe('document.createElement()', function () {
220
-
221
- it('should contain objectlink', function (done) {
222
-
223
- let mocks = document.getElementById('mocks');
224
- const formControl = document.createElement('monster-form');
225
- mocks.appendChild(formControl);
226
-
227
- setTimeout(() => {
228
- try {
229
- expect(document.getElementById('mocks')).contain.html('<monster-form data-monster-objectlink="Symbol(@schukai/monster/dom/custom-element@@options-updater-link)"></monster-form>')
230
- done();
231
- } catch (e) {
232
- return done(e);
233
- }
234
-
235
-
236
- }, 0)
237
-
238
-
239
- });
240
-
241
- });
242
-
243
62
  describe('HTML-Templates', function () {
244
63
 
245
64
  describe('create from template html1', function () {
@@ -55,7 +55,7 @@ describe('Details', function () {
55
55
  try {
56
56
 
57
57
  expect(document.getElementById('mocks')).contain.html(
58
- '<monster-details id="details1" data-monster-objectlink="Symbol(@schukai/monster/dom/custom-element@@options-updater-link)" data-monster-button-label="Details"></monster-details>')
58
+ '<monster-details id="details1" style="display: block;" data-monster-objectlink="Symbol(@schukai/monster/dom/custom-element@@options-updater-link)" data-monster-button-label="Details"></monster-details>')
59
59
  } catch (e) {
60
60
  return done(e);
61
61
  }
@@ -52,7 +52,7 @@ describe('Host', function () {
52
52
 
53
53
  setTimeout(() => {
54
54
  try {
55
- expect(document.getElementById('mocks')).contain.html('<monster-host data-monster-objectlink="Symbol(@schukai/monster/dom/custom-element@@options-updater-link)"></monster-host>')
55
+ expect(document.getElementById('mocks')).contain.html('<monster-host style="display: block;" data-monster-objectlink="Symbol(@schukai/monster/dom/custom-element@@options-updater-link)"></monster-host>')
56
56
  } catch (e) {
57
57
  return done(e);
58
58
  }
@@ -47,7 +47,7 @@ describe('Overlay', function () {
47
47
  setTimeout(() => {
48
48
  try {
49
49
  expect(document.getElementById('mocks')).contain.html(
50
- ' <monster-overlay data-monster-objectlink="Symbol(@schukai/monster/dom/custom-element@@options-updater-link)"></monster-overlay>')
50
+ ' <monster-overlay style="display: block;" data-monster-objectlink="Symbol(@schukai/monster/dom/custom-element@@options-updater-link)"></monster-overlay>')
51
51
  } catch (e) {
52
52
  return done(e);
53
53
  }
@@ -6,6 +6,43 @@ import {Queue} from "../../../source/types/queue.mjs";
6
6
 
7
7
  describe('Diff', function () {
8
8
 
9
+ describe('test to datasets', function () {
10
+
11
+ var obj1, obj2;
12
+
13
+ beforeEach(() => {
14
+ obj1 = [
15
+ {
16
+ "id": 1,
17
+ "name": "test"
18
+ },
19
+ {
20
+ "id": 2,
21
+ "name": "test2"
22
+ }
23
+ ]
24
+
25
+ obj2 = [
26
+ {
27
+ "id": 1,
28
+ "name": "test"
29
+ },
30
+ {
31
+ "id": "3",
32
+ "name": "test2"
33
+ }
34
+ ]
35
+
36
+ });
37
+
38
+ it('should return the difference between two datasets', function () {
39
+ let d = diff(obj1, obj2);
40
+ expect(JSON.stringify(d)).is.equal('[{"operator":"update","path":["1","id"],"first":{"value":2,"type":"number"},"second":{"value":"3","type":"string"}}]');
41
+ });
42
+
43
+
44
+ })
45
+
9
46
  describe('Diff special cases', function () {
10
47
 
11
48
  var obj1, obj2;
@@ -138,7 +138,7 @@ describe('DOM', function () {
138
138
 
139
139
  expect(document.getElementsByTagName('monster-customcontrol').length).is.equal(1);
140
140
  // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
141
- expect(document.getElementById('test1')).contain.html('<monster-customcontrol data-monster-error="Error: html is not set."></monster-customcontrol>')
141
+ expect(document.getElementById('test1')).contain.html('<monster-customcontrol style="display: block;" data-monster-error="Error: html is not set."></monster-customcontrol>')
142
142
  });
143
143
  });
144
144
 
@@ -242,7 +242,7 @@ describe('DOM', function () {
242
242
  expect(document.getElementsByTagName('monster-testclass').length).is.equal(1);
243
243
  // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
244
244
  // but data-monster-error="Error: html is not set."
245
- expect(document.getElementById('test1')).contain.html('<monster-testclass data-monster-error="Error: html is not set."></monster-testclass>');
245
+ expect(document.getElementById('test1')).contain.html('<monster-testclass style="display: block;" data-monster-error="Error: html is not set."></monster-testclass>');
246
246
  });
247
247
  });
248
248
 
@@ -256,7 +256,7 @@ describe('DOM', function () {
256
256
  try {
257
257
  expect(document.getElementsByTagName('monster-testclass2').length).is.equal(1);
258
258
  expect(document.getElementsByTagName('monster-testclass2').item(0).shadowRoot.innerHTML).is.equal('<h1></h1><article><p>test</p><div id="container"></div></article>');
259
- expect(document.getElementById('test1')).contain.html('<monster-testclass2 data-monster-objectlink="Symbol(' + updaterSymbolKey + ')"></monster-testclass2>');
259
+ expect(document.getElementById('test1')).contain.html('<monster-testclass2 style="display: block;" data-monster-objectlink="Symbol(' + updaterSymbolKey + ')"></monster-testclass2>');
260
260
  return done();
261
261
  } catch (e) {
262
262
  done(e);
@@ -1,242 +0,0 @@
1
- @import "hover.pcss";
2
-
3
- @define-mixin form {
4
-
5
- box-sizing: border-box;
6
- display: flex;
7
- flex-wrap: nowrap;
8
- position: relative;
9
- flex-direction: column;
10
- align-content: flex-start;
11
- align-items: flex-start;
12
- accent-color: var(--monster-color-secondary-2);
13
-
14
- & label {
15
- color: var(--monster-color-primary-1);
16
- background-color: var(--monster-bg-color-primary-1);
17
- display: grid;
18
- }
19
-
20
- & label:has(input[type="radio"]) {
21
- display: flex;
22
- flex-direction: row;
23
- flex-wrap: nowrap;
24
- justify-content: flex-start;
25
-
26
- & input {
27
- margin-right: 0.4rem;
28
- margin-left: 0.4rem;
29
- }
30
- }
31
-
32
- & label:has(input[type="radio"]) ~ label:has(input[type="radio"]) {
33
- margin-top: 0.2rem;
34
- }
35
-
36
- & label:has(input[type="checkbox"]) {
37
- display: flex;
38
- flex-direction: row;
39
- flex-wrap: nowrap;
40
- justify-content: flex-start;
41
-
42
- & input {
43
- margin-right: 0.4rem;
44
- margin-left: 0.4rem;
45
- }
46
-
47
- }
48
-
49
- & label:has(input[type="checkbox"]) ~ label:has(input[type="checkbox"]) {
50
- margin-top: 0.2rem;
51
- }
52
-
53
- & label ~ label {
54
- margin-top: 1rem;
55
- }
56
-
57
- & label ~ fieldset {
58
- margin-top: 1rem;
59
- }
60
-
61
- & button,
62
- & input,
63
- & select,
64
- & textarea {
65
- font-family: inherit;
66
- font-size: 100%;
67
- padding: 0.4rem 0.6rem;
68
- margin: 0;
69
- outline: none;
70
- box-sizing: border-box;
71
- accent-color: var(--monster-color-secondary-2);
72
-
73
- color: var(--monster-color-primary-1);
74
- background-color: var(--monster-bg-color-primary-1);
75
-
76
- }
77
-
78
-
79
- & button {
80
- color: var(--monster-color-tertiary-1);
81
- background-color: var(--monster-bg-color-tertiary-1);
82
-
83
- /** monster-border-primary-1 */
84
- border-width: var(--monster-border-width);
85
- border-radius: var(--monster-border-radius);
86
- border-style: var(--monster-border-style);
87
- border-color: var(--monster-bg-color-primary-3);
88
- }
89
-
90
- & option:checked {
91
- background-color: var(--monster-bg-color-primary-3);
92
- color: var(--monster-color-primary-3);
93
- }
94
-
95
- & option:focus {
96
- background-color: var(--monster-bg-color-primary-3);
97
- color: var(--monster-color-primary-3);
98
- }
99
-
100
- & option:hover {
101
- background-color: var(--monster-bg-color-primary-2);
102
- color: var(--monster-color-primary-2);
103
- }
104
-
105
- & input,
106
- & select,
107
- & textarea {
108
- border: 0;
109
- border-bottom-width: thin;
110
- border-radius: var(--monster-border-radius);
111
- border-bottom-style: var(--monster-border-style);
112
- border-bottom-color: var(--monster-bg-color-primary-1);
113
- }
114
-
115
-
116
- & input,
117
- & select,
118
- & textarea {
119
- border-width: thin;
120
- border-radius: var(--monster-border-radius);
121
- border-style: var(--monster-border-style);
122
- border-color: var(--monster-bg-color-primary-2);
123
- }
124
-
125
-
126
- & button,
127
- & input:not([type="radio"]):not([type="checkbox"]),
128
- & select,
129
- & textarea {
130
- width: 100%;
131
- }
132
-
133
- & label {
134
- width: 100%;
135
-
136
- & input:not([type="radio"]):not([type="checkbox"]),
137
- & select,
138
- & textarea {
139
- width: 100%;
140
- margin-top: 0.2rem;
141
- }
142
-
143
- }
144
-
145
- & label + input:not([type="radio"]):not([type="checkbox"]),
146
- & label + select,
147
- & label + textarea {
148
- width: 100%;
149
- margin-top: 0.2rem;
150
- }
151
-
152
-
153
- & fieldset {
154
- margin: 0;
155
- position: relative;
156
- padding: 2.5rem 2rem 2rem;
157
- border: 1px dotted var(--monster-bg-color-primary-4);
158
-
159
- background-color: var(--monster-bg-color-primary-1);
160
- color: var(--monster-color-primary-1);
161
-
162
- box-sizing: border-box;
163
- width: 100%;
164
- outline: none;
165
-
166
- & legend {
167
- position: absolute;
168
- top: 0;
169
- right: 0;
170
- padding: 0.1rem 2rem 0.2rem 0.5rem;
171
- max-width: 95%;
172
- text-align: right;
173
- text-transform: uppercase;
174
- text-overflow: ellipsis;
175
- font-size: 0.8rem;
176
- overflow: hidden;
177
- white-space: nowrap;
178
- }
179
-
180
- & label {
181
- }
182
-
183
- }
184
-
185
- & fieldset ~ fieldset {
186
- margin-top: 1rem;
187
- }
188
-
189
- & button {
190
- margin: 0.2rem 0;
191
- }
192
-
193
- & button:first-of-type {
194
- margin-top: 1rem;
195
- }
196
-
197
- & button:last-of-type {
198
- margin-bottom: 1rem;
199
- }
200
-
201
- & input:focus-visible {
202
- outline: none;
203
- }
204
-
205
-
206
- & button:focus,
207
- & input:focus,
208
- & select:focus,
209
- & textarea:focus {
210
- outline: 1px dashed var(--monster-color-selection-4);
211
- outline-offset: 2px;
212
- }
213
-
214
-
215
- @media (prefers-color-scheme: light) {
216
- & button,
217
- & input,
218
- & select,
219
- & textarea {
220
- background-color: var(--monster-bg-color-primary-1);
221
- color: var(--monster-color-primary-1);
222
- border-color: var(--monster-bg-color-primary-4);
223
- }
224
-
225
- & button:focus,
226
- & input:focus,
227
- & select:focus,
228
- & textarea:focus {
229
- outline: 1px dashed var(--monster-color-selection-3);
230
- }
231
-
232
- }
233
-
234
- & button:hover,
235
- & input:hover:not([type="radio"]):not([type="checkbox"]):not([type="range"]),
236
- & select:hover,
237
- & textarea:hover {
238
- @mixin box-hover;
239
- }
240
-
241
-
242
- }