clapton 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/helpers/clapton/clapton_helper.rb +16 -1
- data/lib/clapton/engine.rb +20 -10
- data/lib/clapton/javascripts/dist/client.js +38 -27
- data/lib/clapton/javascripts/dist/components-for-test.js +439 -0
- data/lib/clapton/javascripts/dist/components.js +356 -382
- data/lib/clapton/javascripts/node_modules/diff-dom/LICENSE.txt +165 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/README.md +224 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/TraceLogger.d.ts +28 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/apply.d.ts +4 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/fromVirtual.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/index.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/undo.d.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/helpers.d.ts +11 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/index.d.ts +10 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/types.d.ts +104 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/apply.d.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/diff.d.ts +22 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromDOM.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromString.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/helpers.d.ts +40 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/index.d.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/index.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.d.ts +136 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.js +1996 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/module.js +1991 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/module.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/index.html +62 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/package.json +54 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/rollup.config.mjs +67 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/TraceLogger.ts +143 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/apply.ts +227 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/fromVirtual.ts +83 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/index.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/undo.ts +90 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/helpers.ts +40 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/index.ts +121 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/types.ts +154 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/apply.ts +349 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/diff.ts +855 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromDOM.ts +74 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromString.ts +239 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/helpers.ts +461 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/index.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/index.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/tsconfig.json +103 -0
- data/lib/clapton/javascripts/rollup.config.mjs +17 -2
- data/lib/clapton/javascripts/src/actions/handle-action.ts +6 -6
- data/lib/clapton/javascripts/src/actions/initialize-actions.ts +6 -3
- data/lib/clapton/javascripts/src/channel/clapton-channel.js +6 -3
- data/lib/clapton/javascripts/src/client.ts +15 -15
- data/lib/clapton/javascripts/src/components-for-test.ts +29 -0
- data/lib/clapton/javascripts/src/components.ts +4 -1
- data/lib/clapton/javascripts/src/dom/update-component.ts +4 -4
- data/lib/clapton/javascripts/src/inputs/initialize-inputs.ts +2 -2
- data/lib/clapton/test_helper/base.rb +1 -1
- data/lib/clapton/version.rb +1 -2
- metadata +49 -3
- data/lib/clapton/javascripts/src/dom/update-component.spec.ts +0 -32
@@ -1,439 +1,413 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
const htmlAttributes = (params) => {
|
2
|
+
const customDataAttributes = params.data || {};
|
3
|
+
const others = Object.keys(params).filter(key => key !== "data");
|
4
|
+
const flattenDataAttributes = (data, prefix = "data") => {
|
5
|
+
return Object.keys(data).reduce((acc, key) => {
|
6
|
+
const value = data[key];
|
7
|
+
if (typeof value === "object" && value !== null) {
|
8
|
+
acc.push(...flattenDataAttributes(value, `${prefix}-${key}`));
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
acc.push(`${prefix}-${key}='${escapeHtml(value)}'`);
|
12
|
+
}
|
13
|
+
return acc;
|
14
|
+
}, []);
|
15
|
+
};
|
16
|
+
return [
|
17
|
+
others.map(key => {
|
18
|
+
if (key === "disabled") {
|
19
|
+
if (params[key] === false) {
|
20
|
+
return "";
|
12
21
|
}
|
13
22
|
else {
|
14
|
-
|
15
|
-
}
|
16
|
-
return acc;
|
17
|
-
}, []);
|
18
|
-
};
|
19
|
-
return [
|
20
|
-
others.map(key => {
|
21
|
-
if (key === "disabled") {
|
22
|
-
if (params[key] === false) {
|
23
|
-
return "";
|
24
|
-
}
|
25
|
-
else {
|
26
|
-
return `${key}`;
|
27
|
-
}
|
23
|
+
return `${key}`;
|
28
24
|
}
|
29
|
-
|
30
|
-
}
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
25
|
+
}
|
26
|
+
return `${key}='${escapeHtml(params[key])}'`;
|
27
|
+
}).join(" "),
|
28
|
+
flattenDataAttributes(customDataAttributes).join(" ")
|
29
|
+
].filter(Boolean).join(" ");
|
30
|
+
};
|
31
|
+
const escapeHtml = (unsafe) => {
|
32
|
+
if (typeof unsafe !== "string") {
|
33
|
+
return "";
|
34
|
+
}
|
35
|
+
return unsafe
|
36
|
+
.replace(/&/g, "&")
|
37
|
+
.replace(/</g, "<")
|
38
|
+
.replace(/>/g, ">")
|
39
|
+
.replace(/"/g, """)
|
40
|
+
.replace(/'/g, "'");
|
41
|
+
};
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
54
|
-
add(child) {
|
55
|
-
this.children.push(child);
|
56
|
-
return this;
|
57
|
-
}
|
43
|
+
class BlockQuote {
|
44
|
+
constructor(attributes = {}) {
|
45
|
+
this.children = [];
|
46
|
+
this.attributes = attributes;
|
47
|
+
}
|
48
|
+
get render() {
|
49
|
+
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</blockquote>`;
|
58
50
|
}
|
51
|
+
add(child) {
|
52
|
+
this.children.push(child);
|
53
|
+
return this;
|
54
|
+
}
|
55
|
+
}
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
}
|
69
|
-
get render() {
|
70
|
-
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</div>`;
|
71
|
-
}
|
72
|
-
add_action(eventType, stateName, fnName, options = {}) {
|
73
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${eventType}->${stateName}#${fnName}@${options.debounce || 0}`;
|
74
|
-
return this;
|
75
|
-
}
|
57
|
+
class Box {
|
58
|
+
constructor(attributes = {}) {
|
59
|
+
this.children = [];
|
60
|
+
this.attributes = attributes;
|
61
|
+
}
|
62
|
+
add(child) {
|
63
|
+
this.children.push(child);
|
64
|
+
return this;
|
76
65
|
}
|
66
|
+
get render() {
|
67
|
+
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</div>`;
|
68
|
+
}
|
69
|
+
add_action(eventType, stateName, fnName, options = {}) {
|
70
|
+
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${eventType}->${stateName}#${fnName}@${options.debounce || 0}`;
|
71
|
+
return this;
|
72
|
+
}
|
73
|
+
}
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
}
|
90
|
-
add_action(event, klass, fn, options = {}) {
|
91
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
92
|
-
return this;
|
93
|
-
}
|
75
|
+
class Button {
|
76
|
+
constructor(attributes = {}) {
|
77
|
+
this.attributes = attributes;
|
78
|
+
this.children = [];
|
79
|
+
}
|
80
|
+
add(child) {
|
81
|
+
this.children.push(child);
|
82
|
+
return this;
|
83
|
+
}
|
84
|
+
get render() {
|
85
|
+
return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</button>`;
|
94
86
|
}
|
87
|
+
add_action(event, klass, fn, options = {}) {
|
88
|
+
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
89
|
+
return this;
|
90
|
+
}
|
91
|
+
}
|
95
92
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
get render() {
|
104
|
-
return `<input type='checkbox' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
105
|
-
}
|
106
|
-
add_action(event, klass, fn, options = {}) {
|
107
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
108
|
-
return this;
|
109
|
-
}
|
93
|
+
class Checkbox {
|
94
|
+
constructor(state, attribute, attributes = {}) {
|
95
|
+
this.state = state;
|
96
|
+
this.attributes = attributes;
|
97
|
+
this.attribute = attribute;
|
98
|
+
this.attributes["data-attribute"] = attribute;
|
110
99
|
}
|
100
|
+
get render() {
|
101
|
+
return `<input type='checkbox' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
102
|
+
}
|
103
|
+
add_action(event, klass, fn, options = {}) {
|
104
|
+
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
105
|
+
return this;
|
106
|
+
}
|
107
|
+
}
|
111
108
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
}
|
117
|
-
get render() {
|
118
|
-
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</code>`;
|
119
|
-
}
|
120
|
-
add(child) {
|
121
|
-
this.children.push(child);
|
122
|
-
return this;
|
123
|
-
}
|
109
|
+
class Code {
|
110
|
+
constructor(attributes = {}) {
|
111
|
+
this.children = [];
|
112
|
+
this.attributes = attributes;
|
124
113
|
}
|
114
|
+
get render() {
|
115
|
+
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</code>`;
|
116
|
+
}
|
117
|
+
add(child) {
|
118
|
+
this.children.push(child);
|
119
|
+
return this;
|
120
|
+
}
|
121
|
+
}
|
125
122
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
123
|
+
class DateTimeField {
|
124
|
+
constructor(state, attribute, attributes = {}) {
|
125
|
+
this.attributes = {};
|
126
|
+
this.state = state;
|
127
|
+
this.attribute = attribute;
|
128
|
+
this.attributes = attributes;
|
129
|
+
this.attributes["data-attribute"] = attribute;
|
130
|
+
}
|
131
|
+
get render() {
|
132
|
+
const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
|
133
|
+
return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
|
134
|
+
}
|
135
|
+
add_action(event, klass, fn, options = {}) {
|
136
|
+
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
137
|
+
return this;
|
138
|
+
}
|
139
|
+
datetime_local_value(value) {
|
140
|
+
if (!value) {
|
141
|
+
return "";
|
133
142
|
}
|
134
|
-
|
135
|
-
|
136
|
-
|
143
|
+
const date = new Date(value);
|
144
|
+
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
|
145
|
+
let month = date.getMonth() + 1;
|
146
|
+
let day = date.getDate();
|
147
|
+
let hours = date.getHours();
|
148
|
+
let minutes = date.getMinutes();
|
149
|
+
if (month < 10) {
|
150
|
+
month = `0${month}`;
|
137
151
|
}
|
138
|
-
|
139
|
-
|
140
|
-
return this;
|
152
|
+
if (day < 10) {
|
153
|
+
day = `0${day}`;
|
141
154
|
}
|
142
|
-
|
143
|
-
|
144
|
-
return "";
|
145
|
-
}
|
146
|
-
const date = new Date(value);
|
147
|
-
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
|
148
|
-
let month = date.getMonth() + 1;
|
149
|
-
let day = date.getDate();
|
150
|
-
let hours = date.getHours();
|
151
|
-
let minutes = date.getMinutes();
|
152
|
-
if (month < 10) {
|
153
|
-
month = `0${month}`;
|
154
|
-
}
|
155
|
-
if (day < 10) {
|
156
|
-
day = `0${day}`;
|
157
|
-
}
|
158
|
-
if (hours < 10) {
|
159
|
-
hours = `0${hours}`;
|
160
|
-
}
|
161
|
-
if (minutes < 10) {
|
162
|
-
minutes = `0${minutes}`;
|
163
|
-
}
|
164
|
-
return `${date.getFullYear()}-${month}-${day}T${hours}:${minutes}`;
|
155
|
+
if (hours < 10) {
|
156
|
+
hours = `0${hours}`;
|
165
157
|
}
|
166
|
-
|
167
|
-
|
168
|
-
class Element {
|
169
|
-
constructor(type, attributes = {}) {
|
170
|
-
this.children = [];
|
171
|
-
this.type = type;
|
172
|
-
this.attributes = attributes;
|
173
|
-
}
|
174
|
-
get render() {
|
175
|
-
return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</${this.type}>`;
|
176
|
-
}
|
177
|
-
add(child) {
|
178
|
-
this.children.push(child);
|
179
|
-
return this;
|
158
|
+
if (minutes < 10) {
|
159
|
+
minutes = `0${minutes}`;
|
180
160
|
}
|
161
|
+
return `${date.getFullYear()}-${month}-${day}T${hours}:${minutes}`;
|
181
162
|
}
|
163
|
+
}
|
182
164
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
165
|
+
class Element {
|
166
|
+
constructor(type, attributes = {}) {
|
167
|
+
this.children = [];
|
168
|
+
this.type = type;
|
169
|
+
this.attributes = attributes;
|
170
|
+
}
|
171
|
+
get render() {
|
172
|
+
return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</${this.type}>`;
|
190
173
|
}
|
174
|
+
add(child) {
|
175
|
+
this.children.push(child);
|
176
|
+
return this;
|
177
|
+
}
|
178
|
+
}
|
191
179
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
this.attributes = attributes;
|
196
|
-
}
|
197
|
-
get render() {
|
198
|
-
return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</em>`;
|
199
|
-
}
|
200
|
-
add(child) {
|
201
|
-
this.children.push(child);
|
202
|
-
return this;
|
203
|
-
}
|
180
|
+
class Embed {
|
181
|
+
constructor(html) {
|
182
|
+
this.html = html;
|
204
183
|
}
|
184
|
+
get render() {
|
185
|
+
return this.html;
|
186
|
+
}
|
187
|
+
}
|
205
188
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
}
|
189
|
+
class Emphasis {
|
190
|
+
constructor(attributes = {}) {
|
191
|
+
this.children = [];
|
192
|
+
this.attributes = attributes;
|
193
|
+
}
|
194
|
+
get render() {
|
195
|
+
return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</em>`;
|
196
|
+
}
|
197
|
+
add(child) {
|
198
|
+
this.children.push(child);
|
199
|
+
return this;
|
218
200
|
}
|
201
|
+
}
|
219
202
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
return this;
|
232
|
-
}
|
203
|
+
class Form {
|
204
|
+
constructor(attributes = {}) {
|
205
|
+
this.children = [];
|
206
|
+
this.attributes = attributes;
|
207
|
+
}
|
208
|
+
get render() {
|
209
|
+
return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</form>`;
|
210
|
+
}
|
211
|
+
add(child) {
|
212
|
+
this.children.push(child);
|
213
|
+
return this;
|
233
214
|
}
|
215
|
+
}
|
234
216
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
217
|
+
class Heading {
|
218
|
+
constructor(level, attributes = {}) {
|
219
|
+
this.children = [];
|
220
|
+
this.level = level;
|
221
|
+
this.attributes = attributes;
|
222
|
+
}
|
223
|
+
get render() {
|
224
|
+
return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</h${this.level}>`;
|
225
|
+
}
|
226
|
+
add(child) {
|
227
|
+
this.children.push(child);
|
228
|
+
return this;
|
245
229
|
}
|
230
|
+
}
|
246
231
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
}
|
256
|
-
add(child) {
|
257
|
-
this.children.push(child);
|
258
|
-
return this;
|
259
|
-
}
|
232
|
+
class Image {
|
233
|
+
constructor(src, alt, attributes = {}) {
|
234
|
+
this.children = [];
|
235
|
+
this.attributes = attributes;
|
236
|
+
this.src = src;
|
237
|
+
this.alt = alt;
|
238
|
+
}
|
239
|
+
get render() {
|
240
|
+
return `<img src='${this.src}' alt='${this.alt}' ${htmlAttributes(this.attributes)}/>`;
|
260
241
|
}
|
242
|
+
}
|
261
243
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
}
|
271
|
-
get render() {
|
272
|
-
return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</li>`;
|
273
|
-
}
|
244
|
+
class Link {
|
245
|
+
constructor(href, attributes = {}) {
|
246
|
+
this.children = [];
|
247
|
+
this.attributes = attributes;
|
248
|
+
this.href = href;
|
249
|
+
}
|
250
|
+
get render() {
|
251
|
+
return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</a>`;
|
274
252
|
}
|
253
|
+
add(child) {
|
254
|
+
this.children.push(child);
|
255
|
+
return this;
|
256
|
+
}
|
257
|
+
}
|
275
258
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
}
|
281
|
-
add(child) {
|
282
|
-
this.children.push(child);
|
283
|
-
return this;
|
284
|
-
}
|
285
|
-
get render() {
|
286
|
-
return `<ul ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</ul>`;
|
287
|
-
}
|
259
|
+
class ListItem {
|
260
|
+
constructor(attributes = {}) {
|
261
|
+
this.children = [];
|
262
|
+
this.attributes = attributes;
|
288
263
|
}
|
264
|
+
add(child) {
|
265
|
+
this.children.push(child);
|
266
|
+
return this;
|
267
|
+
}
|
268
|
+
get render() {
|
269
|
+
return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</li>`;
|
270
|
+
}
|
271
|
+
}
|
289
272
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
}
|
299
|
-
get render() {
|
300
|
-
return `<ol ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</ol>`;
|
301
|
-
}
|
273
|
+
class List {
|
274
|
+
constructor(attributes = {}) {
|
275
|
+
this.children = [];
|
276
|
+
this.attributes = attributes;
|
277
|
+
}
|
278
|
+
add(child) {
|
279
|
+
this.children.push(child);
|
280
|
+
return this;
|
302
281
|
}
|
282
|
+
get render() {
|
283
|
+
return `<ul ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</ul>`;
|
284
|
+
}
|
285
|
+
}
|
303
286
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
}
|
287
|
+
class OrderedList {
|
288
|
+
constructor(attributes = {}) {
|
289
|
+
this.children = [];
|
290
|
+
this.attributes = attributes;
|
291
|
+
}
|
292
|
+
add(child) {
|
293
|
+
this.children.push(child);
|
294
|
+
return this;
|
295
|
+
}
|
296
|
+
get render() {
|
297
|
+
return `<ol ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</ol>`;
|
316
298
|
}
|
299
|
+
}
|
317
300
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
}
|
326
|
-
add(child) {
|
327
|
-
this.children.push(child);
|
328
|
-
return this;
|
329
|
-
}
|
301
|
+
class Paragraph {
|
302
|
+
constructor(attributes = {}) {
|
303
|
+
this.children = [];
|
304
|
+
this.attributes = attributes;
|
305
|
+
}
|
306
|
+
get render() {
|
307
|
+
return `<p ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</p>`;
|
330
308
|
}
|
309
|
+
add(child) {
|
310
|
+
this.children.push(child);
|
311
|
+
return this;
|
312
|
+
}
|
313
|
+
}
|
331
314
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
this.attribute = attribute;
|
337
|
-
this.attributes["data-attribute"] = attribute;
|
338
|
-
}
|
339
|
-
get render() {
|
340
|
-
return `<input type='radio' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
341
|
-
}
|
342
|
-
add_action(event, klass, fn, options = {}) {
|
343
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
344
|
-
return this;
|
345
|
-
}
|
315
|
+
class Quote {
|
316
|
+
constructor(attributes = {}) {
|
317
|
+
this.children = [];
|
318
|
+
this.attributes = attributes;
|
346
319
|
}
|
320
|
+
get render() {
|
321
|
+
return `<q ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</q>`;
|
322
|
+
}
|
323
|
+
add(child) {
|
324
|
+
this.children.push(child);
|
325
|
+
return this;
|
326
|
+
}
|
327
|
+
}
|
347
328
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
this.attributes = attributes;
|
355
|
-
}
|
356
|
-
get render() {
|
357
|
-
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.render).join("")}</select>`;
|
358
|
-
}
|
329
|
+
class RadioButton {
|
330
|
+
constructor(state, attribute, attributes = {}) {
|
331
|
+
this.state = state;
|
332
|
+
this.attributes = attributes;
|
333
|
+
this.attribute = attribute;
|
334
|
+
this.attributes["data-attribute"] = attribute;
|
359
335
|
}
|
336
|
+
get render() {
|
337
|
+
return `<input type='radio' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
338
|
+
}
|
339
|
+
add_action(event, klass, fn, options = {}) {
|
340
|
+
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
341
|
+
return this;
|
342
|
+
}
|
343
|
+
}
|
360
344
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
return this;
|
372
|
-
}
|
345
|
+
class Select {
|
346
|
+
constructor(options = [], state, attribute, attributes = {}) {
|
347
|
+
this.children = [];
|
348
|
+
this.options = options;
|
349
|
+
this.state = state;
|
350
|
+
this.attribute = attribute;
|
351
|
+
this.attributes = attributes;
|
352
|
+
}
|
353
|
+
get render() {
|
354
|
+
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.render).join("")}</select>`;
|
373
355
|
}
|
356
|
+
}
|
374
357
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
this._errors = errors;
|
380
|
-
this._root = new Box({ data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } });
|
381
|
-
}
|
382
|
-
get render() {
|
383
|
-
return this._root.render;
|
384
|
-
}
|
358
|
+
class Span {
|
359
|
+
constructor(attributes = {}) {
|
360
|
+
this.children = [];
|
361
|
+
this.attributes = attributes;
|
385
362
|
}
|
363
|
+
get render() {
|
364
|
+
return `<span ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</span>`;
|
365
|
+
}
|
366
|
+
add(child) {
|
367
|
+
this.children.push(child);
|
368
|
+
return this;
|
369
|
+
}
|
370
|
+
}
|
386
371
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
}
|
397
|
-
add_action(event, klass, fn, options = {}) {
|
398
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
399
|
-
return this;
|
400
|
-
}
|
372
|
+
class Component {
|
373
|
+
constructor(state = {}, id = Math.random().toString(36).substring(2, 10), errors = []) {
|
374
|
+
this._state = state;
|
375
|
+
this.id = id;
|
376
|
+
this._errors = errors;
|
377
|
+
this._root = new Box({ data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } });
|
378
|
+
}
|
379
|
+
get render() {
|
380
|
+
return this._root.render;
|
401
381
|
}
|
382
|
+
}
|
402
383
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
}
|
384
|
+
class TextField {
|
385
|
+
constructor(state, attribute, attributes = {}) {
|
386
|
+
this.state = state;
|
387
|
+
this.attributes = attributes;
|
388
|
+
this.attribute = attribute;
|
389
|
+
this.attributes["data-attribute"] = attribute;
|
410
390
|
}
|
391
|
+
get render() {
|
392
|
+
return `<input type='text' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
393
|
+
}
|
394
|
+
add_action(event, klass, fn, options = {}) {
|
395
|
+
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
396
|
+
return this;
|
397
|
+
}
|
398
|
+
}
|
411
399
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
exports.Embed = Embed;
|
421
|
-
exports.Emphasis = Emphasis;
|
422
|
-
exports.Form = Form;
|
423
|
-
exports.Heading = Heading;
|
424
|
-
exports.Image = Image;
|
425
|
-
exports.Link = Link;
|
426
|
-
exports.List = List;
|
427
|
-
exports.ListItem = ListItem;
|
428
|
-
exports.OrderedList = OrderedList;
|
429
|
-
exports.Paragraph = Paragraph;
|
430
|
-
exports.Quote = Quote;
|
431
|
-
exports.RadioButton = RadioButton;
|
432
|
-
exports.Select = Select;
|
433
|
-
exports.Span = Span;
|
434
|
-
exports.Text = Text;
|
435
|
-
exports.TextField = TextField;
|
400
|
+
class Text {
|
401
|
+
constructor(value) {
|
402
|
+
this.value = value;
|
403
|
+
}
|
404
|
+
get render() {
|
405
|
+
return this.value;
|
406
|
+
}
|
407
|
+
}
|
436
408
|
|
437
|
-
|
409
|
+
const Clapton = {
|
410
|
+
Box, Component, Text, TextField, Button, DateTimeField, BlockQuote, Checkbox, Code, Element, Emphasis, Form, Heading, Image, Link, List, ListItem, OrderedList, Paragraph, Quote, RadioButton, Select, Span, Embed
|
411
|
+
};
|
438
412
|
|
439
|
-
|
413
|
+
export { Clapton };
|