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