clapton 0.0.17 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -7
- data/lib/clapton/javascripts/dist/client.js +14 -4
- data/lib/clapton/javascripts/dist/components-for-test.js +54 -45
- data/lib/clapton/javascripts/dist/components.js +54 -45
- data/lib/clapton/javascripts/src/channel/clapton-channel.js +1 -1
- data/lib/clapton/javascripts/src/client.ts +11 -2
- data/lib/clapton/javascripts/src/components/block-quote.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/block-quote.ts +2 -2
- data/lib/clapton/javascripts/src/components/bold.spec.ts +3 -3
- data/lib/clapton/javascripts/src/components/bold.ts +2 -2
- data/lib/clapton/javascripts/src/components/box.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/box.ts +2 -2
- data/lib/clapton/javascripts/src/components/button.spec.ts +5 -5
- data/lib/clapton/javascripts/src/components/button.ts +2 -2
- data/lib/clapton/javascripts/src/components/checkbox.spec.ts +3 -3
- data/lib/clapton/javascripts/src/components/checkbox.ts +1 -1
- data/lib/clapton/javascripts/src/components/code.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/code.ts +2 -2
- data/lib/clapton/javascripts/src/components/component.ts +12 -4
- data/lib/clapton/javascripts/src/components/datetime-field.spec.ts +3 -3
- data/lib/clapton/javascripts/src/components/datetime-field.ts +1 -1
- data/lib/clapton/javascripts/src/components/element.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/element.ts +2 -2
- data/lib/clapton/javascripts/src/components/embed.spec.ts +1 -1
- data/lib/clapton/javascripts/src/components/embed.ts +1 -1
- data/lib/clapton/javascripts/src/components/emphasis.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/emphasis.ts +2 -2
- data/lib/clapton/javascripts/src/components/form.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/form.ts +2 -2
- data/lib/clapton/javascripts/src/components/heading.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/heading.ts +2 -2
- data/lib/clapton/javascripts/src/components/image.spec.ts +2 -2
- data/lib/clapton/javascripts/src/components/image.ts +1 -1
- data/lib/clapton/javascripts/src/components/link.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/link.ts +2 -2
- data/lib/clapton/javascripts/src/components/list-item.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/list-item.ts +2 -2
- data/lib/clapton/javascripts/src/components/list.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/list.ts +2 -2
- data/lib/clapton/javascripts/src/components/ordered-list.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/ordered-list.ts +2 -2
- data/lib/clapton/javascripts/src/components/paragraph.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/paragraph.ts +2 -2
- data/lib/clapton/javascripts/src/components/presets.ts +1 -1
- data/lib/clapton/javascripts/src/components/quote.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/quote.ts +2 -2
- data/lib/clapton/javascripts/src/components/radio-button.spec.ts +3 -3
- data/lib/clapton/javascripts/src/components/radio-button.ts +1 -1
- data/lib/clapton/javascripts/src/components/select.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/select.ts +2 -2
- data/lib/clapton/javascripts/src/components/span.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/span.ts +2 -2
- data/lib/clapton/javascripts/src/components/text-area.spec.ts +3 -3
- data/lib/clapton/javascripts/src/components/text-area.ts +1 -1
- data/lib/clapton/javascripts/src/components/text-field.spec.ts +3 -3
- data/lib/clapton/javascripts/src/components/text-field.ts +1 -1
- data/lib/clapton/javascripts/src/components/text.spec.ts +2 -2
- data/lib/clapton/javascripts/src/components/text.ts +1 -1
- data/lib/clapton/javascripts/src/dom/update-component.ts +1 -1
- data/lib/clapton/test_helper/base.rb +1 -1
- data/lib/clapton/version.rb +1 -1
- data/lib/rails/generators/clapton_generator.rb +2 -0
- metadata +1 -1
@@ -45,8 +45,8 @@ class BlockQuote {
|
|
45
45
|
this.children = [];
|
46
46
|
this.attributes = attributes;
|
47
47
|
}
|
48
|
-
get
|
49
|
-
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
48
|
+
get renderWrapper() {
|
49
|
+
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
|
50
50
|
}
|
51
51
|
add(child) {
|
52
52
|
this.children.push(child);
|
@@ -63,8 +63,8 @@ class Box {
|
|
63
63
|
this.children.push(child);
|
64
64
|
return this;
|
65
65
|
}
|
66
|
-
get
|
67
|
-
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
66
|
+
get renderWrapper() {
|
67
|
+
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
|
68
68
|
}
|
69
69
|
add_action(eventType, stateName, fnName, options = {}) {
|
70
70
|
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${eventType}->${stateName}#${fnName}@${options.debounce || 0}`;
|
@@ -81,8 +81,8 @@ class Button {
|
|
81
81
|
this.children.push(child);
|
82
82
|
return this;
|
83
83
|
}
|
84
|
-
get
|
85
|
-
return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
84
|
+
get renderWrapper() {
|
85
|
+
return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</button>`;
|
86
86
|
}
|
87
87
|
add_action(event, klass, fn, options = {}) {
|
88
88
|
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
@@ -95,8 +95,8 @@ class Bold {
|
|
95
95
|
this.children = [];
|
96
96
|
this.attributes = attributes;
|
97
97
|
}
|
98
|
-
get
|
99
|
-
return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
98
|
+
get renderWrapper() {
|
99
|
+
return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</strong>`;
|
100
100
|
}
|
101
101
|
add(child) {
|
102
102
|
this.children.push(child);
|
@@ -111,7 +111,7 @@ class Checkbox {
|
|
111
111
|
this.attribute = attribute;
|
112
112
|
this.attributes["data-attribute"] = attribute;
|
113
113
|
}
|
114
|
-
get
|
114
|
+
get renderWrapper() {
|
115
115
|
return `<input type='checkbox' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
116
116
|
}
|
117
117
|
add_action(event, klass, fn, options = {}) {
|
@@ -125,8 +125,8 @@ class Code {
|
|
125
125
|
this.children = [];
|
126
126
|
this.attributes = attributes;
|
127
127
|
}
|
128
|
-
get
|
129
|
-
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
128
|
+
get renderWrapper() {
|
129
|
+
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</code>`;
|
130
130
|
}
|
131
131
|
add(child) {
|
132
132
|
this.children.push(child);
|
@@ -142,7 +142,7 @@ class DateTimeField {
|
|
142
142
|
this.attributes = attributes;
|
143
143
|
this.attributes["data-attribute"] = attribute;
|
144
144
|
}
|
145
|
-
get
|
145
|
+
get renderWrapper() {
|
146
146
|
const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
|
147
147
|
return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
|
148
148
|
}
|
@@ -182,8 +182,8 @@ class Element {
|
|
182
182
|
this.type = type;
|
183
183
|
this.attributes = attributes;
|
184
184
|
}
|
185
|
-
get
|
186
|
-
return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
185
|
+
get renderWrapper() {
|
186
|
+
return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</${this.type}>`;
|
187
187
|
}
|
188
188
|
add(child) {
|
189
189
|
this.children.push(child);
|
@@ -195,7 +195,7 @@ class Embed {
|
|
195
195
|
constructor(html) {
|
196
196
|
this.html = html;
|
197
197
|
}
|
198
|
-
get
|
198
|
+
get renderWrapper() {
|
199
199
|
return this.html;
|
200
200
|
}
|
201
201
|
}
|
@@ -205,8 +205,8 @@ class Emphasis {
|
|
205
205
|
this.children = [];
|
206
206
|
this.attributes = attributes;
|
207
207
|
}
|
208
|
-
get
|
209
|
-
return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
208
|
+
get renderWrapper() {
|
209
|
+
return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</em>`;
|
210
210
|
}
|
211
211
|
add(child) {
|
212
212
|
this.children.push(child);
|
@@ -219,8 +219,8 @@ class Form {
|
|
219
219
|
this.children = [];
|
220
220
|
this.attributes = attributes;
|
221
221
|
}
|
222
|
-
get
|
223
|
-
return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
222
|
+
get renderWrapper() {
|
223
|
+
return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</form>`;
|
224
224
|
}
|
225
225
|
add(child) {
|
226
226
|
this.children.push(child);
|
@@ -234,8 +234,8 @@ class Heading {
|
|
234
234
|
this.level = level;
|
235
235
|
this.attributes = attributes;
|
236
236
|
}
|
237
|
-
get
|
238
|
-
return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
237
|
+
get renderWrapper() {
|
238
|
+
return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</h${this.level}>`;
|
239
239
|
}
|
240
240
|
add(child) {
|
241
241
|
this.children.push(child);
|
@@ -250,7 +250,7 @@ class Image {
|
|
250
250
|
this.src = src;
|
251
251
|
this.alt = alt;
|
252
252
|
}
|
253
|
-
get
|
253
|
+
get renderWrapper() {
|
254
254
|
return `<img src='${this.src}' alt='${this.alt}' ${htmlAttributes(this.attributes)}/>`;
|
255
255
|
}
|
256
256
|
}
|
@@ -261,8 +261,8 @@ class Link {
|
|
261
261
|
this.attributes = attributes;
|
262
262
|
this.href = href;
|
263
263
|
}
|
264
|
-
get
|
265
|
-
return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
264
|
+
get renderWrapper() {
|
265
|
+
return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</a>`;
|
266
266
|
}
|
267
267
|
add(child) {
|
268
268
|
this.children.push(child);
|
@@ -279,8 +279,8 @@ class ListItem {
|
|
279
279
|
this.children.push(child);
|
280
280
|
return this;
|
281
281
|
}
|
282
|
-
get
|
283
|
-
return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
282
|
+
get renderWrapper() {
|
283
|
+
return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</li>`;
|
284
284
|
}
|
285
285
|
}
|
286
286
|
|
@@ -293,8 +293,8 @@ class List {
|
|
293
293
|
this.children.push(child);
|
294
294
|
return this;
|
295
295
|
}
|
296
|
-
get
|
297
|
-
return `<ul ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
296
|
+
get renderWrapper() {
|
297
|
+
return `<ul ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ul>`;
|
298
298
|
}
|
299
299
|
}
|
300
300
|
|
@@ -307,8 +307,8 @@ class OrderedList {
|
|
307
307
|
this.children.push(child);
|
308
308
|
return this;
|
309
309
|
}
|
310
|
-
get
|
311
|
-
return `<ol ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
310
|
+
get renderWrapper() {
|
311
|
+
return `<ol ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ol>`;
|
312
312
|
}
|
313
313
|
}
|
314
314
|
|
@@ -317,8 +317,8 @@ class Paragraph {
|
|
317
317
|
this.children = [];
|
318
318
|
this.attributes = attributes;
|
319
319
|
}
|
320
|
-
get
|
321
|
-
return `<p ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
320
|
+
get renderWrapper() {
|
321
|
+
return `<p ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</p>`;
|
322
322
|
}
|
323
323
|
add(child) {
|
324
324
|
this.children.push(child);
|
@@ -331,8 +331,8 @@ class Quote {
|
|
331
331
|
this.children = [];
|
332
332
|
this.attributes = attributes;
|
333
333
|
}
|
334
|
-
get
|
335
|
-
return `<q ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
334
|
+
get renderWrapper() {
|
335
|
+
return `<q ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</q>`;
|
336
336
|
}
|
337
337
|
add(child) {
|
338
338
|
this.children.push(child);
|
@@ -347,7 +347,7 @@ class RadioButton {
|
|
347
347
|
this.attribute = attribute;
|
348
348
|
this.attributes["data-attribute"] = attribute;
|
349
349
|
}
|
350
|
-
get
|
350
|
+
get renderWrapper() {
|
351
351
|
return `<input type='radio' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
352
352
|
}
|
353
353
|
add_action(event, klass, fn, options = {}) {
|
@@ -364,8 +364,8 @@ class Select {
|
|
364
364
|
this.attribute = attribute;
|
365
365
|
this.attributes = attributes;
|
366
366
|
}
|
367
|
-
get
|
368
|
-
return `<select ${htmlAttributes(this.attributes)}>${this.options.map(option => `<option value='${option.value}'${option.value === this.state[this.attribute] ? " selected" : ""}>${option.text}</option>`).join("")}${this.children.map(child => child.
|
367
|
+
get renderWrapper() {
|
368
|
+
return `<select ${htmlAttributes(this.attributes)}>${this.options.map(option => `<option value='${option.value}'${option.value === this.state[this.attribute] ? " selected" : ""}>${option.text}</option>`).join("")}${this.children.map(child => child.renderWrapper).join("")}</select>`;
|
369
369
|
}
|
370
370
|
}
|
371
371
|
|
@@ -374,8 +374,8 @@ class Span {
|
|
374
374
|
this.children = [];
|
375
375
|
this.attributes = attributes;
|
376
376
|
}
|
377
|
-
get
|
378
|
-
return `<span ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
377
|
+
get renderWrapper() {
|
378
|
+
return `<span ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</span>`;
|
379
379
|
}
|
380
380
|
add(child) {
|
381
381
|
this.children.push(child);
|
@@ -421,7 +421,7 @@ class Presets {
|
|
421
421
|
return new Clapton.Heading(props[0], props[1]);
|
422
422
|
}
|
423
423
|
img(...props) {
|
424
|
-
return new Clapton.Image(props[0], props[1]);
|
424
|
+
return new Clapton.Image(props[0], props[1], props[2]);
|
425
425
|
}
|
426
426
|
a(...props) {
|
427
427
|
return new Clapton.Link(props[0], props[1]);
|
@@ -466,11 +466,20 @@ class Component {
|
|
466
466
|
this._state = state;
|
467
467
|
this.id = id;
|
468
468
|
this._errors = errors;
|
469
|
-
this._root = new Box({ data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } });
|
470
469
|
this._c = new Presets();
|
471
470
|
}
|
472
471
|
get render() {
|
473
|
-
return
|
472
|
+
return new Box({});
|
473
|
+
}
|
474
|
+
get renderWrapper() {
|
475
|
+
const root = this.render;
|
476
|
+
if (root.attributes) {
|
477
|
+
root.attributes = { ...root.attributes, data: { ...root.attributes.data, component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } };
|
478
|
+
}
|
479
|
+
else {
|
480
|
+
root.attributes = { data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } };
|
481
|
+
}
|
482
|
+
return root.renderWrapper;
|
474
483
|
}
|
475
484
|
}
|
476
485
|
|
@@ -481,7 +490,7 @@ class TextField {
|
|
481
490
|
this.attribute = attribute;
|
482
491
|
this.attributes["data-attribute"] = attribute;
|
483
492
|
}
|
484
|
-
get
|
493
|
+
get renderWrapper() {
|
485
494
|
return `<input type='text' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
486
495
|
}
|
487
496
|
add_action(event, klass, fn, options = {}) {
|
@@ -494,7 +503,7 @@ class Text {
|
|
494
503
|
constructor(value) {
|
495
504
|
this.value = value;
|
496
505
|
}
|
497
|
-
get
|
506
|
+
get renderWrapper() {
|
498
507
|
return this.value;
|
499
508
|
}
|
500
509
|
}
|
@@ -506,7 +515,7 @@ class TextArea {
|
|
506
515
|
this.attribute = attribute;
|
507
516
|
this.attributes["data-attribute"] = attribute;
|
508
517
|
}
|
509
|
-
get
|
518
|
+
get renderWrapper() {
|
510
519
|
return `<textarea ${htmlAttributes(this.attributes)}>${this.state[this.attribute] || ""}</textarea>`;
|
511
520
|
}
|
512
521
|
add_action(event, klass, fn, options = {}) {
|
@@ -16,7 +16,7 @@ export const claptonChannel = consumer.subscriptions.create("Clapton::ClaptonCha
|
|
16
16
|
const component = document.querySelector(`[data-id="${data.component.id}"]`)
|
17
17
|
const module = await import(`${data.component.name}`);
|
18
18
|
const instance = new module[data.component.name](data.state, data.component.id, errors);
|
19
|
-
morphdom(component, instance.
|
19
|
+
morphdom(component, instance.renderWrapper, {
|
20
20
|
onBeforeElUpdated: (_fromEl, toEl) => {
|
21
21
|
toEl.setAttribute("data-set-event-handler", "true");
|
22
22
|
return true;
|
@@ -21,13 +21,20 @@ const initializeComponents = async () => {
|
|
21
21
|
};
|
22
22
|
|
23
23
|
const createAndAppendComponent = async (component: ComponentDefinition, element: HTMLElement) => {
|
24
|
+
if (!element) {
|
25
|
+
return;
|
26
|
+
}
|
24
27
|
const componentDom = document.createElement('div');
|
25
28
|
const module = await import(`${component.component}`);
|
26
29
|
const instance = new (module[component.component] as any)(component.state);
|
27
|
-
componentDom.innerHTML = instance.
|
30
|
+
componentDom.innerHTML = instance.renderWrapper;
|
28
31
|
const firstChild = componentDom.firstChild as HTMLElement;
|
29
32
|
if (firstChild) {
|
30
|
-
element.
|
33
|
+
if (element.children.length > 0) {
|
34
|
+
element.appendChild(firstChild);
|
35
|
+
} else {
|
36
|
+
element.outerHTML = firstChild.outerHTML;
|
37
|
+
}
|
31
38
|
}
|
32
39
|
};
|
33
40
|
|
@@ -35,4 +42,6 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
35
42
|
await initializeComponents();
|
36
43
|
initializeActions();
|
37
44
|
initializeInputs();
|
45
|
+
const event = new Event('clapton:render');
|
46
|
+
document.dispatchEvent(event);
|
38
47
|
});
|
@@ -4,23 +4,23 @@ import { Text } from "./text"
|
|
4
4
|
|
5
5
|
describe("BlockQuote", () => {
|
6
6
|
it("returns empty string if no params", () => {
|
7
|
-
expect(new BlockQuote().
|
7
|
+
expect(new BlockQuote().renderWrapper).toBe("<blockquote ></blockquote>")
|
8
8
|
})
|
9
9
|
|
10
10
|
it("returns attributes and data attributes", () => {
|
11
|
-
expect(new BlockQuote({ id: "1", "data-foo": "bar" }).
|
11
|
+
expect(new BlockQuote({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
|
12
12
|
})
|
13
13
|
|
14
14
|
it("returns attributes and data attributes with custom data attributes", () => {
|
15
|
-
expect(new BlockQuote({ id: "1", data: { foo: "bar" } }).
|
16
|
-
expect(new BlockQuote({ id: "1", data: { foo: "bar", baz: "qux" } }).
|
17
|
-
expect(new BlockQuote({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).
|
15
|
+
expect(new BlockQuote({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar'></blockquote>`)
|
16
|
+
expect(new BlockQuote({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<blockquote id='1' data-foo='bar' data-baz='qux'></blockquote>`)
|
17
|
+
expect(new BlockQuote({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<blockquote id='1' data-foo-baz='qux' data-foo-quux='corge'></blockquote>`)
|
18
18
|
})
|
19
19
|
|
20
20
|
it("adds children", () => {
|
21
21
|
const text = new Text("Hello")
|
22
22
|
const blockQuote = new BlockQuote()
|
23
23
|
blockQuote.add(text)
|
24
|
-
expect(blockQuote.
|
24
|
+
expect(blockQuote.renderWrapper).toBe(`<blockquote >Hello</blockquote>`)
|
25
25
|
})
|
26
26
|
})
|
@@ -9,8 +9,8 @@ export class BlockQuote {
|
|
9
9
|
this.attributes = attributes;
|
10
10
|
}
|
11
11
|
|
12
|
-
get
|
13
|
-
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
12
|
+
get renderWrapper(): string {
|
13
|
+
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
|
14
14
|
}
|
15
15
|
|
16
16
|
add(child: any): BlockQuote {
|
@@ -4,11 +4,11 @@ import { Bold } from "./bold"
|
|
4
4
|
|
5
5
|
describe("Bold", () => {
|
6
6
|
it("returns empty string if no params", () => {
|
7
|
-
expect(new Bold().
|
7
|
+
expect(new Bold().renderWrapper).toBe("<strong ></strong>")
|
8
8
|
})
|
9
9
|
|
10
10
|
it("returns attributes and data attributes", () => {
|
11
|
-
expect(new Bold({ id: "1", "data-foo": "bar" }).
|
11
|
+
expect(new Bold({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<strong id='1' data-foo='bar'></strong>`)
|
12
12
|
})
|
13
13
|
|
14
14
|
|
@@ -16,6 +16,6 @@ describe("Bold", () => {
|
|
16
16
|
const text = new Text("Hello")
|
17
17
|
const bold = new Bold()
|
18
18
|
bold.add(text)
|
19
|
-
expect(bold.
|
19
|
+
expect(bold.renderWrapper).toBe(`<strong >Hello</strong>`)
|
20
20
|
})
|
21
21
|
})
|
@@ -9,8 +9,8 @@ export class Bold {
|
|
9
9
|
this.attributes = attributes;
|
10
10
|
}
|
11
11
|
|
12
|
-
get
|
13
|
-
return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
12
|
+
get renderWrapper(): string {
|
13
|
+
return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</strong>`;
|
14
14
|
}
|
15
15
|
|
16
16
|
add(child: any): Bold {
|
@@ -4,20 +4,20 @@ import { Text } from "./text"
|
|
4
4
|
|
5
5
|
describe("Box", () => {
|
6
6
|
it("returns empty string if no params", () => {
|
7
|
-
expect(new Box().
|
7
|
+
expect(new Box().renderWrapper).toBe("<div ></div>")
|
8
8
|
})
|
9
9
|
|
10
10
|
it("returns attributes and data attributes", () => {
|
11
|
-
expect(new Box({ id: "1", "data-foo": "bar" }).
|
11
|
+
expect(new Box({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
|
12
12
|
})
|
13
13
|
|
14
14
|
it("returns attributes and data attributes with custom data attributes", () => {
|
15
|
-
expect(new Box({ id: "1", data: { foo: "bar" } }).
|
16
|
-
expect(new Box({ id: "1", data: { foo: "bar", baz: "qux" } }).
|
17
|
-
expect(new Box({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).
|
15
|
+
expect(new Box({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
|
16
|
+
expect(new Box({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<div id='1' data-foo='bar' data-baz='qux'></div>`)
|
17
|
+
expect(new Box({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<div id='1' data-foo-baz='qux' data-foo-quux='corge'></div>`)
|
18
18
|
})
|
19
19
|
|
20
20
|
it("adds children", () => {
|
21
|
-
expect(new Box().add(new Text("Hello, world!")).
|
21
|
+
expect(new Box().add(new Text("Hello, world!")).renderWrapper).toBe(`<div >Hello, world!</div>`)
|
22
22
|
})
|
23
23
|
})
|
@@ -14,8 +14,8 @@ export class Box {
|
|
14
14
|
return this;
|
15
15
|
}
|
16
16
|
|
17
|
-
get
|
18
|
-
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
17
|
+
get renderWrapper(): string {
|
18
|
+
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
|
19
19
|
}
|
20
20
|
|
21
21
|
add_action(eventType: string, stateName: string, fnName: string, options: Record<string, any> = {}): this {
|
@@ -3,16 +3,16 @@ import { Button } from "./button"
|
|
3
3
|
|
4
4
|
describe("Button", () => {
|
5
5
|
it("returns empty string if no params", () => {
|
6
|
-
expect(new Button().
|
6
|
+
expect(new Button().renderWrapper).toBe("<button ></button>")
|
7
7
|
})
|
8
8
|
|
9
9
|
it("returns attributes and data attributes", () => {
|
10
|
-
expect(new Button({ id: "1", "data-foo": "bar" }).
|
10
|
+
expect(new Button({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<button id='1' data-foo='bar'></button>`)
|
11
11
|
})
|
12
12
|
|
13
13
|
it("returns attributes and data attributes with custom data attributes", () => {
|
14
|
-
expect(new Button({ id: "1", data: { foo: "bar" } }).
|
15
|
-
expect(new Button({ id: "1", data: { foo: "bar", baz: "qux" } }).
|
16
|
-
expect(new Button({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).
|
14
|
+
expect(new Button({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<button id='1' data-foo='bar'></button>`)
|
15
|
+
expect(new Button({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<button id='1' data-foo='bar' data-baz='qux'></button>`)
|
16
|
+
expect(new Button({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<button id='1' data-foo-baz='qux' data-foo-quux='corge'></button>`)
|
17
17
|
})
|
18
18
|
})
|
@@ -14,8 +14,8 @@ export class Button {
|
|
14
14
|
return this;
|
15
15
|
}
|
16
16
|
|
17
|
-
get
|
18
|
-
return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
17
|
+
get renderWrapper(): string {
|
18
|
+
return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</button>`;
|
19
19
|
}
|
20
20
|
|
21
21
|
add_action(event: string, klass: string, fn: string, options: Record<string, any> = {}): Button {
|
@@ -3,14 +3,14 @@ import { Checkbox } from "./checkbox"
|
|
3
3
|
|
4
4
|
describe("Checkbox", () => {
|
5
5
|
it("returns empty string if no params", () => {
|
6
|
-
expect(new Checkbox({}, "foo").
|
6
|
+
expect(new Checkbox({}, "foo").renderWrapper).toBe("<input type='checkbox' data-attribute='foo' value=''/>")
|
7
7
|
})
|
8
8
|
|
9
9
|
it("returns attributes and data attributes", () => {
|
10
|
-
expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", "data-foo": "bar" }).
|
10
|
+
expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<input type='checkbox' id='1' data-foo='bar' data-attribute='foo' value='bar'/>`)
|
11
11
|
})
|
12
12
|
|
13
13
|
it("returns attributes and data attributes with custom data attributes", () => {
|
14
|
-
expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).
|
14
|
+
expect(new Checkbox({ foo: "bar" }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<input type='checkbox' id='1' data-attribute='foo' data-foo-baz='qux' data-foo-quux='corge' value='bar'/>`)
|
15
15
|
})
|
16
16
|
})
|
@@ -12,7 +12,7 @@ export class Checkbox {
|
|
12
12
|
this.attributes["data-attribute"] = attribute;
|
13
13
|
}
|
14
14
|
|
15
|
-
get
|
15
|
+
get renderWrapper(): string {
|
16
16
|
return `<input type='checkbox' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
17
17
|
}
|
18
18
|
|
@@ -4,23 +4,23 @@ import { Text } from "./text"
|
|
4
4
|
|
5
5
|
describe("Code", () => {
|
6
6
|
it("returns empty string if no params", () => {
|
7
|
-
expect(new Code().
|
7
|
+
expect(new Code().renderWrapper).toBe("<code ></code>")
|
8
8
|
})
|
9
9
|
|
10
10
|
it("returns attributes and data attributes", () => {
|
11
|
-
expect(new Code({ id: "1", "data-foo": "bar" }).
|
11
|
+
expect(new Code({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<code id='1' data-foo='bar'></code>`)
|
12
12
|
})
|
13
13
|
|
14
14
|
it("returns attributes and data attributes with custom data attributes", () => {
|
15
|
-
expect(new Code({ id: "1", data: { foo: "bar" } }).
|
16
|
-
expect(new Code({ id: "1", data: { foo: "bar", baz: "qux" } }).
|
17
|
-
expect(new Code({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).
|
15
|
+
expect(new Code({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<code id='1' data-foo='bar'></code>`)
|
16
|
+
expect(new Code({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<code id='1' data-foo='bar' data-baz='qux'></code>`)
|
17
|
+
expect(new Code({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<code id='1' data-foo-baz='qux' data-foo-quux='corge'></code>`)
|
18
18
|
})
|
19
19
|
|
20
20
|
it("adds children", () => {
|
21
21
|
const text = new Text("Hello")
|
22
22
|
const code = new Code()
|
23
23
|
code.add(text)
|
24
|
-
expect(code.
|
24
|
+
expect(code.renderWrapper).toBe(`<code >Hello</code>`)
|
25
25
|
})
|
26
26
|
})
|
@@ -9,8 +9,8 @@ export class Code {
|
|
9
9
|
this.attributes = attributes;
|
10
10
|
}
|
11
11
|
|
12
|
-
get
|
13
|
-
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.
|
12
|
+
get renderWrapper(): string {
|
13
|
+
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</code>`;
|
14
14
|
}
|
15
15
|
|
16
16
|
add(child: any): Code {
|
@@ -5,18 +5,26 @@ export class Component {
|
|
5
5
|
id: string;
|
6
6
|
_state: any;
|
7
7
|
_errors: any[];
|
8
|
-
_root: Box;
|
9
8
|
_c: Presets;
|
10
9
|
|
11
10
|
constructor(state: any = {}, id: string = Math.random().toString(36).substring(2, 10), errors: any[] = []) {
|
12
11
|
this._state = state;
|
13
12
|
this.id = id;
|
14
13
|
this._errors = errors;
|
15
|
-
this._root = new Box({ data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } });
|
16
14
|
this._c = new Presets()
|
17
15
|
}
|
18
16
|
|
19
|
-
get render():
|
20
|
-
return
|
17
|
+
get render(): any {
|
18
|
+
return new Box({});
|
19
|
+
}
|
20
|
+
|
21
|
+
get renderWrapper(): string {
|
22
|
+
const root = this.render;
|
23
|
+
if (root.attributes) {
|
24
|
+
root.attributes = { ...root.attributes, data: { ...root.attributes.data, component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } };
|
25
|
+
} else {
|
26
|
+
root.attributes = { data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } };
|
27
|
+
}
|
28
|
+
return root.renderWrapper;
|
21
29
|
}
|
22
30
|
}
|
@@ -3,14 +3,14 @@ import { DateTimeField } from "./datetime-field"
|
|
3
3
|
|
4
4
|
describe("DateTimeField", () => {
|
5
5
|
it("returns empty string if no params", () => {
|
6
|
-
expect(new DateTimeField({}, "foo").
|
6
|
+
expect(new DateTimeField({}, "foo").renderWrapper).toBe("<input type='datetime-local' data-attribute='foo' value=''/>")
|
7
7
|
})
|
8
8
|
|
9
9
|
it("returns attributes and data attributes", () => {
|
10
|
-
expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", "data-foo": "bar" }).
|
10
|
+
expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", "data-foo": "bar" }).renderWrapper).toMatch(/<input type='datetime-local' id='1' data-foo='bar' data-attribute='foo' value='.+'\/>/)
|
11
11
|
})
|
12
12
|
|
13
13
|
it("returns attributes and data attributes with custom data attributes", () => {
|
14
|
-
expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).
|
14
|
+
expect(new DateTimeField({ foo: new Date("2024-10-12T12:00") }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toMatch(/<input type='datetime-local' id='1' data-attribute='foo' data-foo-baz='qux' data-foo-quux='corge' value='.+'\/>/)
|
15
15
|
})
|
16
16
|
})
|
@@ -12,7 +12,7 @@ export class DateTimeField {
|
|
12
12
|
this.attributes["data-attribute"] = attribute;
|
13
13
|
}
|
14
14
|
|
15
|
-
get
|
15
|
+
get renderWrapper(): string {
|
16
16
|
const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
|
17
17
|
return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
|
18
18
|
}
|