clapton 0.0.24 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -113
- data/app/channels/clapton/clapton_channel.rb +4 -0
- data/lib/clapton/javascripts/dist/c-for-test.js +124 -268
- data/lib/clapton/javascripts/dist/c.js +124 -268
- data/lib/clapton/javascripts/dist/client.js +6 -31
- data/lib/clapton/javascripts/dist/components-for-test.js +73 -245
- data/lib/clapton/javascripts/dist/components.js +72 -241
- data/lib/clapton/javascripts/src/actions/handle-action.ts +3 -2
- data/lib/clapton/javascripts/src/c-base.ts +57 -30
- data/lib/clapton/javascripts/src/channel/clapton-channel.js +3 -2
- data/lib/clapton/javascripts/src/client.ts +0 -3
- data/lib/clapton/javascripts/src/components/{box.ts → base.ts} +6 -8
- data/lib/clapton/javascripts/src/components/block-quote.spec.ts +1 -1
- data/lib/clapton/javascripts/src/components/block-quote.ts +2 -14
- data/lib/clapton/javascripts/src/components/bold.ts +2 -14
- data/lib/clapton/javascripts/src/components/button.ts +2 -19
- data/lib/clapton/javascripts/src/components/code.ts +2 -14
- data/lib/clapton/javascripts/src/components/component.ts +2 -2
- data/lib/clapton/javascripts/src/components/{box.spec.ts → div.spec.ts} +8 -8
- data/lib/clapton/javascripts/src/components/div.ts +8 -0
- data/lib/clapton/javascripts/src/components/element.ts +3 -9
- data/lib/clapton/javascripts/src/components/emphasis.ts +2 -14
- data/lib/clapton/javascripts/src/components/form.ts +2 -14
- data/lib/clapton/javascripts/src/components/heading.ts +4 -10
- data/lib/clapton/javascripts/src/components/image.spec.ts +2 -2
- data/lib/clapton/javascripts/src/components/image.ts +3 -14
- data/lib/clapton/javascripts/src/components/input.spec.ts +16 -0
- data/lib/clapton/javascripts/src/components/{datetime-field.ts → input.ts} +13 -11
- data/lib/clapton/javascripts/src/components/link.spec.ts +6 -6
- data/lib/clapton/javascripts/src/components/link.ts +3 -16
- data/lib/clapton/javascripts/src/components/list-item.ts +2 -14
- data/lib/clapton/javascripts/src/components/list.ts +2 -14
- data/lib/clapton/javascripts/src/components/ordered-list.ts +2 -14
- data/lib/clapton/javascripts/src/components/paragraph.ts +2 -14
- data/lib/clapton/javascripts/src/components/quote.ts +2 -14
- data/lib/clapton/javascripts/src/components/select.ts +3 -5
- data/lib/clapton/javascripts/src/components/span.ts +2 -14
- data/lib/clapton/javascripts/src/components/text-area.ts +4 -9
- data/lib/clapton/javascripts/src/components-for-test.ts +3 -6
- data/lib/clapton/javascripts/src/components.ts +3 -6
- data/lib/clapton/test_helper/base.rb +4 -4
- data/lib/clapton/version.rb +1 -1
- metadata +7 -16
- data/lib/clapton/javascripts/dist/c +0 -559
- data/lib/clapton/javascripts/dist/c-base.js +0 -589
- data/lib/clapton/javascripts/src/components/checkbox.spec.ts +0 -16
- data/lib/clapton/javascripts/src/components/checkbox.ts +0 -23
- data/lib/clapton/javascripts/src/components/datetime-field.spec.ts +0 -16
- data/lib/clapton/javascripts/src/components/radio-button.spec.ts +0 -16
- data/lib/clapton/javascripts/src/components/radio-button.ts +0 -23
- data/lib/clapton/javascripts/src/components/text-field.spec.ts +0 -16
- data/lib/clapton/javascripts/src/components/text-field.ts +0 -23
- data/lib/clapton/javascripts/src/dom/update-component.ts +0 -11
- data/lib/clapton/javascripts/src/inputs/initialize-inputs.ts +0 -16
@@ -40,21 +40,7 @@ const escapeHtml = (unsafe) => {
|
|
40
40
|
.replace(/'/g, "'");
|
41
41
|
};
|
42
42
|
|
43
|
-
class
|
44
|
-
constructor(attributes = {}) {
|
45
|
-
this.children = [];
|
46
|
-
this.attributes = attributes;
|
47
|
-
}
|
48
|
-
get renderWrapper() {
|
49
|
-
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
|
50
|
-
}
|
51
|
-
add(child) {
|
52
|
-
this.children.push(child);
|
53
|
-
return this;
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
class Box {
|
43
|
+
class Base {
|
58
44
|
constructor(attributes = {}) {
|
59
45
|
this.children = [];
|
60
46
|
this.attributes = attributes;
|
@@ -63,132 +49,54 @@ class Box {
|
|
63
49
|
this.children.push(child);
|
64
50
|
return this;
|
65
51
|
}
|
66
|
-
get renderWrapper() {
|
67
|
-
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
|
68
|
-
}
|
69
52
|
add_action(eventType, stateName, fnName, options = {}) {
|
70
53
|
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${eventType}->${stateName}#${fnName}@${options.debounce || 0}`;
|
71
54
|
return this;
|
72
55
|
}
|
56
|
+
get renderWrapper() {
|
57
|
+
return "";
|
58
|
+
}
|
73
59
|
}
|
74
60
|
|
75
|
-
class
|
76
|
-
constructor(attributes = {}) {
|
77
|
-
this.attributes = attributes;
|
78
|
-
this.children = [];
|
79
|
-
}
|
80
|
-
add(child) {
|
81
|
-
this.children.push(child);
|
82
|
-
return this;
|
83
|
-
}
|
61
|
+
class BlockQuote extends Base {
|
84
62
|
get renderWrapper() {
|
85
|
-
return `<
|
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;
|
63
|
+
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
|
90
64
|
}
|
91
65
|
}
|
92
66
|
|
93
|
-
class
|
94
|
-
constructor(attributes = {}) {
|
95
|
-
this.children = [];
|
96
|
-
this.attributes = attributes;
|
97
|
-
}
|
67
|
+
class Div extends Base {
|
98
68
|
get renderWrapper() {
|
99
|
-
return `<
|
100
|
-
}
|
101
|
-
add(child) {
|
102
|
-
this.children.push(child);
|
103
|
-
return this;
|
69
|
+
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
|
104
70
|
}
|
105
71
|
}
|
106
72
|
|
107
|
-
class
|
108
|
-
constructor(state, attribute, attributes = {}) {
|
109
|
-
this.state = state;
|
110
|
-
this.attributes = attributes;
|
111
|
-
this.attribute = attribute;
|
112
|
-
this.attributes["data-attribute"] = attribute;
|
113
|
-
}
|
73
|
+
class Button extends Base {
|
114
74
|
get renderWrapper() {
|
115
|
-
return `<
|
116
|
-
}
|
117
|
-
add_action(event, klass, fn, options = {}) {
|
118
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
119
|
-
return this;
|
75
|
+
return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</button>`;
|
120
76
|
}
|
121
77
|
}
|
122
78
|
|
123
|
-
class
|
124
|
-
constructor(attributes = {}) {
|
125
|
-
this.children = [];
|
126
|
-
this.attributes = attributes;
|
127
|
-
}
|
79
|
+
class Bold extends Base {
|
128
80
|
get renderWrapper() {
|
129
|
-
return `<
|
130
|
-
}
|
131
|
-
add(child) {
|
132
|
-
this.children.push(child);
|
133
|
-
return this;
|
81
|
+
return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</strong>`;
|
134
82
|
}
|
135
83
|
}
|
136
84
|
|
137
|
-
class
|
138
|
-
constructor(state, attribute, attributes = {}) {
|
139
|
-
this.attributes = {};
|
140
|
-
this.state = state;
|
141
|
-
this.attribute = attribute;
|
142
|
-
this.attributes = attributes;
|
143
|
-
this.attributes["data-attribute"] = attribute;
|
144
|
-
}
|
85
|
+
class Code extends Base {
|
145
86
|
get renderWrapper() {
|
146
|
-
|
147
|
-
return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
|
148
|
-
}
|
149
|
-
add_action(event, klass, fn, options = {}) {
|
150
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
151
|
-
return this;
|
152
|
-
}
|
153
|
-
datetime_local_value(value) {
|
154
|
-
if (!value) {
|
155
|
-
return "";
|
156
|
-
}
|
157
|
-
const date = new Date(value);
|
158
|
-
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
|
159
|
-
let month = date.getMonth() + 1;
|
160
|
-
let day = date.getDate();
|
161
|
-
let hours = date.getHours();
|
162
|
-
let minutes = date.getMinutes();
|
163
|
-
if (month < 10) {
|
164
|
-
month = `0${month}`;
|
165
|
-
}
|
166
|
-
if (day < 10) {
|
167
|
-
day = `0${day}`;
|
168
|
-
}
|
169
|
-
if (hours < 10) {
|
170
|
-
hours = `0${hours}`;
|
171
|
-
}
|
172
|
-
if (minutes < 10) {
|
173
|
-
minutes = `0${minutes}`;
|
174
|
-
}
|
175
|
-
return `${date.getFullYear()}-${month}-${day}T${hours}:${minutes}`;
|
87
|
+
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</code>`;
|
176
88
|
}
|
177
89
|
}
|
178
90
|
|
179
|
-
class Element {
|
91
|
+
class Element extends Base {
|
180
92
|
constructor(type, attributes = {}) {
|
93
|
+
super(attributes);
|
181
94
|
this.children = [];
|
182
95
|
this.type = type;
|
183
|
-
this.attributes = attributes;
|
184
96
|
}
|
185
97
|
get renderWrapper() {
|
186
98
|
return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</${this.type}>`;
|
187
99
|
}
|
188
|
-
add(child) {
|
189
|
-
this.children.push(child);
|
190
|
-
return this;
|
191
|
-
}
|
192
100
|
}
|
193
101
|
|
194
102
|
class Embed {
|
@@ -200,187 +108,86 @@ class Embed {
|
|
200
108
|
}
|
201
109
|
}
|
202
110
|
|
203
|
-
class Emphasis {
|
204
|
-
constructor(attributes = {}) {
|
205
|
-
this.children = [];
|
206
|
-
this.attributes = attributes;
|
207
|
-
}
|
111
|
+
class Emphasis extends Base {
|
208
112
|
get renderWrapper() {
|
209
113
|
return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</em>`;
|
210
114
|
}
|
211
|
-
add(child) {
|
212
|
-
this.children.push(child);
|
213
|
-
return this;
|
214
|
-
}
|
215
115
|
}
|
216
116
|
|
217
|
-
class Form {
|
218
|
-
constructor(attributes = {}) {
|
219
|
-
this.children = [];
|
220
|
-
this.attributes = attributes;
|
221
|
-
}
|
117
|
+
class Form extends Base {
|
222
118
|
get renderWrapper() {
|
223
119
|
return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</form>`;
|
224
120
|
}
|
225
|
-
add(child) {
|
226
|
-
this.children.push(child);
|
227
|
-
return this;
|
228
|
-
}
|
229
121
|
}
|
230
122
|
|
231
|
-
class Heading {
|
123
|
+
class Heading extends Base {
|
232
124
|
constructor(level, attributes = {}) {
|
233
|
-
|
125
|
+
super(attributes);
|
234
126
|
this.level = level;
|
235
|
-
this.attributes = attributes;
|
236
127
|
}
|
237
128
|
get renderWrapper() {
|
238
129
|
return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</h${this.level}>`;
|
239
130
|
}
|
240
|
-
add(child) {
|
241
|
-
this.children.push(child);
|
242
|
-
return this;
|
243
|
-
}
|
244
131
|
}
|
245
132
|
|
246
|
-
class Image {
|
247
|
-
constructor(src, alt, attributes = {}) {
|
248
|
-
this.children = [];
|
249
|
-
this.attributes = attributes;
|
250
|
-
this.src = src;
|
251
|
-
this.alt = alt;
|
252
|
-
}
|
133
|
+
class Image extends Base {
|
253
134
|
get renderWrapper() {
|
254
|
-
return `<img
|
135
|
+
return `<img ${htmlAttributes(this.attributes)}/>`;
|
255
136
|
}
|
256
137
|
}
|
257
138
|
|
258
|
-
class Link {
|
259
|
-
constructor(href, attributes = {}) {
|
260
|
-
this.children = [];
|
261
|
-
this.attributes = attributes;
|
262
|
-
this.href = href;
|
263
|
-
}
|
139
|
+
class Link extends Base {
|
264
140
|
get renderWrapper() {
|
265
|
-
return `<a
|
266
|
-
}
|
267
|
-
add(child) {
|
268
|
-
this.children.push(child);
|
269
|
-
return this;
|
141
|
+
return `<a ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</a>`;
|
270
142
|
}
|
271
143
|
}
|
272
144
|
|
273
|
-
class ListItem {
|
274
|
-
constructor(attributes = {}) {
|
275
|
-
this.children = [];
|
276
|
-
this.attributes = attributes;
|
277
|
-
}
|
278
|
-
add(child) {
|
279
|
-
this.children.push(child);
|
280
|
-
return this;
|
281
|
-
}
|
145
|
+
class ListItem extends Base {
|
282
146
|
get renderWrapper() {
|
283
147
|
return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</li>`;
|
284
148
|
}
|
285
149
|
}
|
286
150
|
|
287
|
-
class List {
|
288
|
-
constructor(attributes = {}) {
|
289
|
-
this.children = [];
|
290
|
-
this.attributes = attributes;
|
291
|
-
}
|
292
|
-
add(child) {
|
293
|
-
this.children.push(child);
|
294
|
-
return this;
|
295
|
-
}
|
151
|
+
class List extends Base {
|
296
152
|
get renderWrapper() {
|
297
153
|
return `<ul ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ul>`;
|
298
154
|
}
|
299
155
|
}
|
300
156
|
|
301
|
-
class OrderedList {
|
302
|
-
constructor(attributes = {}) {
|
303
|
-
this.children = [];
|
304
|
-
this.attributes = attributes;
|
305
|
-
}
|
306
|
-
add(child) {
|
307
|
-
this.children.push(child);
|
308
|
-
return this;
|
309
|
-
}
|
157
|
+
class OrderedList extends Base {
|
310
158
|
get renderWrapper() {
|
311
159
|
return `<ol ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ol>`;
|
312
160
|
}
|
313
161
|
}
|
314
162
|
|
315
|
-
class Paragraph {
|
316
|
-
constructor(attributes = {}) {
|
317
|
-
this.children = [];
|
318
|
-
this.attributes = attributes;
|
319
|
-
}
|
163
|
+
class Paragraph extends Base {
|
320
164
|
get renderWrapper() {
|
321
165
|
return `<p ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</p>`;
|
322
166
|
}
|
323
|
-
add(child) {
|
324
|
-
this.children.push(child);
|
325
|
-
return this;
|
326
|
-
}
|
327
167
|
}
|
328
168
|
|
329
|
-
class Quote {
|
330
|
-
constructor(attributes = {}) {
|
331
|
-
this.children = [];
|
332
|
-
this.attributes = attributes;
|
333
|
-
}
|
169
|
+
class Quote extends Base {
|
334
170
|
get renderWrapper() {
|
335
171
|
return `<q ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</q>`;
|
336
172
|
}
|
337
|
-
add(child) {
|
338
|
-
this.children.push(child);
|
339
|
-
return this;
|
340
|
-
}
|
341
173
|
}
|
342
174
|
|
343
|
-
class
|
344
|
-
constructor(state, attribute, attributes = {}) {
|
345
|
-
this.state = state;
|
346
|
-
this.attributes = attributes;
|
347
|
-
this.attribute = attribute;
|
348
|
-
this.attributes["data-attribute"] = attribute;
|
349
|
-
}
|
350
|
-
get renderWrapper() {
|
351
|
-
return `<input type='radio' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
352
|
-
}
|
353
|
-
add_action(event, klass, fn, options = {}) {
|
354
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
355
|
-
return this;
|
356
|
-
}
|
357
|
-
}
|
358
|
-
|
359
|
-
class Select {
|
175
|
+
class Select extends Base {
|
360
176
|
constructor(options = [], state, attribute, attributes = {}) {
|
361
|
-
|
177
|
+
super(attributes);
|
362
178
|
this.options = options;
|
363
179
|
this.state = state;
|
364
180
|
this.attribute = attribute;
|
365
|
-
this.attributes = attributes;
|
366
181
|
}
|
367
182
|
get renderWrapper() {
|
368
183
|
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
184
|
}
|
370
185
|
}
|
371
186
|
|
372
|
-
class Span {
|
373
|
-
constructor(attributes = {}) {
|
374
|
-
this.children = [];
|
375
|
-
this.attributes = attributes;
|
376
|
-
}
|
187
|
+
class Span extends Base {
|
377
188
|
get renderWrapper() {
|
378
189
|
return `<span ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</span>`;
|
379
190
|
}
|
380
|
-
add(child) {
|
381
|
-
this.children.push(child);
|
382
|
-
return this;
|
383
|
-
}
|
384
191
|
}
|
385
192
|
|
386
193
|
class Component {
|
@@ -390,7 +197,7 @@ class Component {
|
|
390
197
|
this._errors = errors;
|
391
198
|
}
|
392
199
|
get render() {
|
393
|
-
return new
|
200
|
+
return new Div({});
|
394
201
|
}
|
395
202
|
get renderWrapper() {
|
396
203
|
const root = this.render;
|
@@ -425,19 +232,47 @@ class Component {
|
|
425
232
|
}
|
426
233
|
Component._effects = [];
|
427
234
|
|
428
|
-
class
|
235
|
+
class Input extends Base {
|
429
236
|
constructor(state, attribute, attributes = {}) {
|
430
|
-
|
431
|
-
this.attributes = attributes;
|
237
|
+
super(attributes);
|
432
238
|
this.attribute = attribute;
|
239
|
+
this.state = state;
|
433
240
|
this.attributes["data-attribute"] = attribute;
|
241
|
+
this.attributes["data-id"] = Math.random().toString(36).substring(2, 10);
|
434
242
|
}
|
435
243
|
get renderWrapper() {
|
436
|
-
|
244
|
+
let value = this.state[this.attribute];
|
245
|
+
if (!this.attributes.type) {
|
246
|
+
this.attributes.type = "text";
|
247
|
+
}
|
248
|
+
if (this.attributes.type === "datetime-local" && value) {
|
249
|
+
value = this.datetime_local_value(value);
|
250
|
+
}
|
251
|
+
return `<input ${htmlAttributes(this.attributes)} value='${value || ""}'/>`;
|
437
252
|
}
|
438
|
-
|
439
|
-
|
440
|
-
|
253
|
+
datetime_local_value(value) {
|
254
|
+
if (!value) {
|
255
|
+
return "";
|
256
|
+
}
|
257
|
+
const date = new Date(value);
|
258
|
+
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
|
259
|
+
let month = date.getMonth() + 1;
|
260
|
+
let day = date.getDate();
|
261
|
+
let hours = date.getHours();
|
262
|
+
let minutes = date.getMinutes();
|
263
|
+
if (month < 10) {
|
264
|
+
month = `0${month}`;
|
265
|
+
}
|
266
|
+
if (day < 10) {
|
267
|
+
day = `0${day}`;
|
268
|
+
}
|
269
|
+
if (hours < 10) {
|
270
|
+
hours = `0${hours}`;
|
271
|
+
}
|
272
|
+
if (minutes < 10) {
|
273
|
+
minutes = `0${minutes}`;
|
274
|
+
}
|
275
|
+
return `${date.getFullYear()}-${month}-${day}T${hours}:${minutes}`;
|
441
276
|
}
|
442
277
|
}
|
443
278
|
|
@@ -450,31 +285,27 @@ class Text {
|
|
450
285
|
}
|
451
286
|
}
|
452
287
|
|
453
|
-
class TextArea {
|
288
|
+
class TextArea extends Base {
|
454
289
|
constructor(state, attribute, attributes = {}) {
|
455
|
-
|
456
|
-
this.attributes = attributes;
|
290
|
+
super(attributes);
|
457
291
|
this.attribute = attribute;
|
292
|
+
this.state = state;
|
458
293
|
this.attributes["data-attribute"] = attribute;
|
459
294
|
}
|
460
295
|
get renderWrapper() {
|
461
296
|
return `<textarea ${htmlAttributes(this.attributes)}>${this.state[this.attribute] || ""}</textarea>`;
|
462
297
|
}
|
463
|
-
add_action(event, klass, fn, options = {}) {
|
464
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
465
|
-
return this;
|
466
|
-
}
|
467
298
|
}
|
468
299
|
|
469
300
|
const Clapton = {
|
470
|
-
|
301
|
+
Div, Component, Text, Input, Button, BlockQuote, Code, Element, Emphasis, Form, Heading, Image, Link, List, ListItem, OrderedList, Paragraph, Quote, Select, Span, Embed, Bold, TextArea
|
471
302
|
};
|
472
303
|
|
473
|
-
const
|
304
|
+
const blockquote = (...props) => {
|
474
305
|
return new Clapton.BlockQuote(...props);
|
475
306
|
};
|
476
|
-
const
|
477
|
-
return new Clapton.
|
307
|
+
const div = (...props) => {
|
308
|
+
return new Clapton.Div(...props);
|
478
309
|
};
|
479
310
|
const b = (...props) => {
|
480
311
|
return new Clapton.Bold(...props);
|
@@ -482,15 +313,9 @@ const b = (...props) => {
|
|
482
313
|
const button = (...props) => {
|
483
314
|
return new Clapton.Button(...props);
|
484
315
|
};
|
485
|
-
const check = (...props) => {
|
486
|
-
return new Clapton.Checkbox(props[0], props[1], props[2]);
|
487
|
-
};
|
488
316
|
const code = (...props) => {
|
489
317
|
return new Clapton.Code(...props);
|
490
318
|
};
|
491
|
-
const datetime = (...props) => {
|
492
|
-
return new Clapton.DateTimeField(props[0], props[1], props[2]);
|
493
|
-
};
|
494
319
|
const el = (...props) => {
|
495
320
|
return new Clapton.Element(props[0], props[1]);
|
496
321
|
};
|
@@ -503,14 +328,29 @@ const em = (...props) => {
|
|
503
328
|
const form = (...props) => {
|
504
329
|
return new Clapton.Form(...props);
|
505
330
|
};
|
506
|
-
const
|
507
|
-
return new Clapton.Heading(
|
331
|
+
const h1 = (...props) => {
|
332
|
+
return new Clapton.Heading(1, props[1]);
|
333
|
+
};
|
334
|
+
const h2 = (...props) => {
|
335
|
+
return new Clapton.Heading(2, props[1]);
|
336
|
+
};
|
337
|
+
const h3 = (...props) => {
|
338
|
+
return new Clapton.Heading(3, props[1]);
|
339
|
+
};
|
340
|
+
const h4 = (...props) => {
|
341
|
+
return new Clapton.Heading(4, props[1]);
|
342
|
+
};
|
343
|
+
const h5 = (...props) => {
|
344
|
+
return new Clapton.Heading(5, props[1]);
|
345
|
+
};
|
346
|
+
const h6 = (...props) => {
|
347
|
+
return new Clapton.Heading(6, props[1]);
|
508
348
|
};
|
509
349
|
const img = (...props) => {
|
510
|
-
return new Clapton.Image(props[0]
|
350
|
+
return new Clapton.Image(props[0]);
|
511
351
|
};
|
512
352
|
const a = (...props) => {
|
513
|
-
return new Clapton.Link(props[0]
|
353
|
+
return new Clapton.Link(props[0]);
|
514
354
|
};
|
515
355
|
const li = (...props) => {
|
516
356
|
return new Clapton.ListItem(...props);
|
@@ -527,9 +367,6 @@ const p = (...props) => {
|
|
527
367
|
const q = (...props) => {
|
528
368
|
return new Clapton.Quote(...props);
|
529
369
|
};
|
530
|
-
const radio = (...props) => {
|
531
|
-
return new Clapton.RadioButton(props[0], props[1], props[2]);
|
532
|
-
};
|
533
370
|
const select = (...props) => {
|
534
371
|
return new Clapton.Select(props[0], props[1], props[2]);
|
535
372
|
};
|
@@ -540,7 +377,7 @@ const textarea = (...props) => {
|
|
540
377
|
return new Clapton.TextArea(props[0], props[1], props[2]);
|
541
378
|
};
|
542
379
|
const input = (...props) => {
|
543
|
-
return new Clapton.
|
380
|
+
return new Clapton.Input(props[0], props[1], props[2]);
|
544
381
|
};
|
545
382
|
const text = (...props) => {
|
546
383
|
return new Clapton.Text(props[0]);
|
@@ -548,19 +385,19 @@ const text = (...props) => {
|
|
548
385
|
const c = (name, ...props) => {
|
549
386
|
switch (name) {
|
550
387
|
case "bq":
|
551
|
-
return
|
388
|
+
return blockquote(...props);
|
552
389
|
case "box":
|
553
|
-
return
|
390
|
+
return div(...props);
|
391
|
+
case "blockquote":
|
392
|
+
return blockquote(...props);
|
393
|
+
case "div":
|
394
|
+
return div(...props);
|
554
395
|
case "b":
|
555
396
|
return b(...props);
|
556
397
|
case "button":
|
557
398
|
return button(...props);
|
558
|
-
case "check":
|
559
|
-
return check(...props);
|
560
399
|
case "code":
|
561
400
|
return code(...props);
|
562
|
-
case "datetime":
|
563
|
-
return datetime(...props);
|
564
401
|
case "el":
|
565
402
|
return el(...props);
|
566
403
|
case "embed":
|
@@ -570,7 +407,19 @@ const c = (name, ...props) => {
|
|
570
407
|
case "form":
|
571
408
|
return form(...props);
|
572
409
|
case "h":
|
573
|
-
return
|
410
|
+
return h1(...props);
|
411
|
+
case "h1":
|
412
|
+
return h1(...props);
|
413
|
+
case "h2":
|
414
|
+
return h2(...props);
|
415
|
+
case "h3":
|
416
|
+
return h3(...props);
|
417
|
+
case "h4":
|
418
|
+
return h4(...props);
|
419
|
+
case "h5":
|
420
|
+
return h5(...props);
|
421
|
+
case "h6":
|
422
|
+
return h6(...props);
|
574
423
|
case "img":
|
575
424
|
return img(...props);
|
576
425
|
case "a":
|
@@ -585,8 +434,6 @@ const c = (name, ...props) => {
|
|
585
434
|
return p(...props);
|
586
435
|
case "q":
|
587
436
|
return q(...props);
|
588
|
-
case "radio":
|
589
|
-
return radio(...props);
|
590
437
|
case "select":
|
591
438
|
return select(...props);
|
592
439
|
case "span":
|
@@ -597,8 +444,17 @@ const c = (name, ...props) => {
|
|
597
444
|
return input(...props);
|
598
445
|
case "text":
|
599
446
|
return text(...props);
|
447
|
+
case "radio":
|
448
|
+
props[3].type = "radio";
|
449
|
+
return input(...props);
|
450
|
+
case "datetime":
|
451
|
+
props[3].type = "datetime-local";
|
452
|
+
return input(...props);
|
453
|
+
case "check":
|
454
|
+
props[3].type = "checkbox";
|
455
|
+
return input(...props);
|
600
456
|
default:
|
601
|
-
return new Clapton.
|
457
|
+
return new Clapton.Element(name, ...props);
|
602
458
|
}
|
603
459
|
};
|
604
460
|
|
@@ -1285,32 +1285,6 @@ function getConfig(name) {
|
|
1285
1285
|
}
|
1286
1286
|
}
|
1287
1287
|
|
1288
|
-
const updateComponent = async (component, state, property, target) => {
|
1289
|
-
state[property] = target.value;
|
1290
|
-
const componentName = component.dataset.component;
|
1291
|
-
const module = await import(`${componentName}`);
|
1292
|
-
const ComponentClass = module[componentName];
|
1293
|
-
const instance = new ComponentClass(state, component.dataset.id);
|
1294
|
-
morphdom(component, instance.renderWrapper);
|
1295
|
-
instance.runEffects();
|
1296
|
-
};
|
1297
|
-
|
1298
|
-
const initializeInputs = () => {
|
1299
|
-
const inputElements = document.querySelectorAll("[data-attribute]");
|
1300
|
-
inputElements.forEach((element) => {
|
1301
|
-
const attribute = element.getAttribute("data-attribute");
|
1302
|
-
const component = element.closest(`[data-component]`);
|
1303
|
-
const state = JSON.parse(component.getAttribute("data-state") || "{}");
|
1304
|
-
if (!attribute || !component)
|
1305
|
-
return;
|
1306
|
-
if (element.tagName === "INPUT") {
|
1307
|
-
element.addEventListener("input", async (event) => {
|
1308
|
-
await updateComponent(component, state, attribute, event.target);
|
1309
|
-
});
|
1310
|
-
}
|
1311
|
-
});
|
1312
|
-
};
|
1313
|
-
|
1314
1288
|
const consumer = createConsumer();
|
1315
1289
|
|
1316
1290
|
const claptonChannel = consumer.subscriptions.create("Clapton::ClaptonChannel", {
|
@@ -1327,12 +1301,14 @@ const claptonChannel = consumer.subscriptions.create("Clapton::ClaptonChannel",
|
|
1327
1301
|
const instance = new module[data.component.name](data.state, data.component.id, errors);
|
1328
1302
|
morphdom(component, instance.renderWrapper, {
|
1329
1303
|
onBeforeElUpdated: (_fromEl, toEl) => {
|
1304
|
+
if (_fromEl.dataset.id === data.focus) {
|
1305
|
+
return false;
|
1306
|
+
}
|
1330
1307
|
toEl.setAttribute("data-set-event-handler", "true");
|
1331
1308
|
return true;
|
1332
1309
|
}
|
1333
1310
|
});
|
1334
1311
|
|
1335
|
-
initializeInputs();
|
1336
1312
|
initializeActions();
|
1337
1313
|
instance.runEffects();
|
1338
1314
|
}
|
@@ -1352,7 +1328,7 @@ const handleAction = async (target, stateName, fn) => {
|
|
1352
1328
|
const attribute = target.dataset.attribute;
|
1353
1329
|
if (attribute) {
|
1354
1330
|
const state = JSON.parse(component.dataset.state || "{}");
|
1355
|
-
if (target.
|
1331
|
+
if (target.dataset.attribute) {
|
1356
1332
|
state[attribute] = target.value;
|
1357
1333
|
component.dataset.state = JSON.stringify(state);
|
1358
1334
|
}
|
@@ -1368,7 +1344,8 @@ const handleAction = async (target, stateName, fn) => {
|
|
1368
1344
|
action: fn,
|
1369
1345
|
attributes: JSON.parse(targetComponent.dataset.state || "{}"),
|
1370
1346
|
},
|
1371
|
-
params: JSON.parse(component.dataset.state || "{}")
|
1347
|
+
params: JSON.parse(component.dataset.state || "{}"),
|
1348
|
+
focus: target.dataset.id,
|
1372
1349
|
}
|
1373
1350
|
});
|
1374
1351
|
};
|
@@ -1447,14 +1424,12 @@ const createAndAppendComponent = async (component, element) => {
|
|
1447
1424
|
document.addEventListener("DOMContentLoaded", async () => {
|
1448
1425
|
await initializeComponents();
|
1449
1426
|
initializeActions();
|
1450
|
-
initializeInputs();
|
1451
1427
|
const event = new Event('clapton:render');
|
1452
1428
|
document.dispatchEvent(event);
|
1453
1429
|
});
|
1454
1430
|
document.addEventListener("turbo:render", async () => {
|
1455
1431
|
await initializeComponents();
|
1456
1432
|
initializeActions();
|
1457
|
-
initializeInputs();
|
1458
1433
|
const event = new Event('clapton:render');
|
1459
1434
|
document.dispatchEvent(event);
|
1460
1435
|
});
|