clapton 0.0.24 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -113
  3. data/app/channels/clapton/clapton_channel.rb +4 -0
  4. data/lib/clapton/javascripts/dist/c-for-test.js +124 -268
  5. data/lib/clapton/javascripts/dist/c.js +124 -268
  6. data/lib/clapton/javascripts/dist/client.js +6 -31
  7. data/lib/clapton/javascripts/dist/components-for-test.js +73 -245
  8. data/lib/clapton/javascripts/dist/components.js +72 -241
  9. data/lib/clapton/javascripts/src/actions/handle-action.ts +3 -2
  10. data/lib/clapton/javascripts/src/c-base.ts +57 -30
  11. data/lib/clapton/javascripts/src/channel/clapton-channel.js +3 -2
  12. data/lib/clapton/javascripts/src/client.ts +0 -3
  13. data/lib/clapton/javascripts/src/components/{box.ts → base.ts} +6 -8
  14. data/lib/clapton/javascripts/src/components/block-quote.spec.ts +1 -1
  15. data/lib/clapton/javascripts/src/components/block-quote.ts +2 -14
  16. data/lib/clapton/javascripts/src/components/bold.ts +2 -14
  17. data/lib/clapton/javascripts/src/components/button.ts +2 -19
  18. data/lib/clapton/javascripts/src/components/code.ts +2 -14
  19. data/lib/clapton/javascripts/src/components/component.ts +2 -2
  20. data/lib/clapton/javascripts/src/components/{box.spec.ts → div.spec.ts} +8 -8
  21. data/lib/clapton/javascripts/src/components/div.ts +8 -0
  22. data/lib/clapton/javascripts/src/components/element.ts +3 -9
  23. data/lib/clapton/javascripts/src/components/emphasis.ts +2 -14
  24. data/lib/clapton/javascripts/src/components/form.ts +2 -14
  25. data/lib/clapton/javascripts/src/components/heading.ts +4 -10
  26. data/lib/clapton/javascripts/src/components/image.spec.ts +2 -2
  27. data/lib/clapton/javascripts/src/components/image.ts +3 -14
  28. data/lib/clapton/javascripts/src/components/input.spec.ts +16 -0
  29. data/lib/clapton/javascripts/src/components/{datetime-field.ts → input.ts} +13 -11
  30. data/lib/clapton/javascripts/src/components/link.spec.ts +6 -6
  31. data/lib/clapton/javascripts/src/components/link.ts +3 -16
  32. data/lib/clapton/javascripts/src/components/list-item.ts +2 -14
  33. data/lib/clapton/javascripts/src/components/list.ts +2 -14
  34. data/lib/clapton/javascripts/src/components/ordered-list.ts +2 -14
  35. data/lib/clapton/javascripts/src/components/paragraph.ts +2 -14
  36. data/lib/clapton/javascripts/src/components/quote.ts +2 -14
  37. data/lib/clapton/javascripts/src/components/select.ts +3 -5
  38. data/lib/clapton/javascripts/src/components/span.ts +2 -14
  39. data/lib/clapton/javascripts/src/components/text-area.ts +4 -9
  40. data/lib/clapton/javascripts/src/components-for-test.ts +3 -6
  41. data/lib/clapton/javascripts/src/components.ts +3 -6
  42. data/lib/clapton/test_helper/base.rb +4 -4
  43. data/lib/clapton/version.rb +1 -1
  44. metadata +7 -16
  45. data/lib/clapton/javascripts/dist/c +0 -559
  46. data/lib/clapton/javascripts/dist/c-base.js +0 -589
  47. data/lib/clapton/javascripts/src/components/checkbox.spec.ts +0 -16
  48. data/lib/clapton/javascripts/src/components/checkbox.ts +0 -23
  49. data/lib/clapton/javascripts/src/components/datetime-field.spec.ts +0 -16
  50. data/lib/clapton/javascripts/src/components/radio-button.spec.ts +0 -16
  51. data/lib/clapton/javascripts/src/components/radio-button.ts +0 -23
  52. data/lib/clapton/javascripts/src/components/text-field.spec.ts +0 -16
  53. data/lib/clapton/javascripts/src/components/text-field.ts +0 -23
  54. data/lib/clapton/javascripts/src/dom/update-component.ts +0 -11
  55. data/lib/clapton/javascripts/src/inputs/initialize-inputs.ts +0 -16
@@ -40,155 +40,63 @@ const escapeHtml = (unsafe) => {
40
40
  .replace(/'/g, "'");
41
41
  };
42
42
 
43
- class BlockQuote {
43
+ class Base {
44
44
  constructor(attributes = {}) {
45
45
  this.children = [];
46
46
  this.attributes = attributes;
47
47
  }
48
- get renderWrapper() {
49
- return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
50
- }
51
48
  add(child) {
52
49
  this.children.push(child);
53
50
  return this;
54
51
  }
55
- }
56
-
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;
65
- }
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 Button {
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 `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</button>`;
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 Bold {
94
- constructor(attributes = {}) {
95
- this.children = [];
96
- this.attributes = attributes;
97
- }
67
+ class Div extends Base {
98
68
  get renderWrapper() {
99
- return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</strong>`;
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 Checkbox {
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 `<input type='checkbox' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
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 Code {
124
- constructor(attributes = {}) {
125
- this.children = [];
126
- this.attributes = attributes;
127
- }
79
+ class Bold extends Base {
128
80
  get renderWrapper() {
129
- return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</code>`;
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 DateTimeField {
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
- const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
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
- this.children = [];
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 src='${this.src}' alt='${this.alt}' ${htmlAttributes(this.attributes)}/>`;
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 href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</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 RadioButton {
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
- this.children = [];
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 Box({});
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 TextField {
235
+ class Input extends Base {
429
236
  constructor(state, attribute, attributes = {}) {
430
- this.state = state;
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
- return `<input type='text' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
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
- add_action(event, klass, fn, options = {}) {
439
- this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
440
- return this;
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,24 +285,20 @@ class Text {
450
285
  }
451
286
  }
452
287
 
453
- class TextArea {
288
+ class TextArea extends Base {
454
289
  constructor(state, attribute, attributes = {}) {
455
- this.state = state;
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
- Box, Component, Text, TextField, Button, DateTimeField, BlockQuote, Checkbox, Code, Element, Emphasis, Form, Heading, Image, Link, List, ListItem, OrderedList, Paragraph, Quote, RadioButton, Select, Span, Embed, Bold, TextArea
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
304
  export { Clapton };
@@ -12,7 +12,7 @@ export const handleAction = async (target: HTMLElement, stateName: string, fn: s
12
12
  const attribute = target.dataset.attribute;
13
13
  if (attribute) {
14
14
  const state = JSON.parse(component.dataset.state || "{}");
15
- if (target.tagName === "INPUT") {
15
+ if (target.dataset.attribute) {
16
16
  state[attribute] = (target as HTMLInputElement).value;
17
17
  component.dataset.state = JSON.stringify(state);
18
18
  }
@@ -30,7 +30,8 @@ export const handleAction = async (target: HTMLElement, stateName: string, fn: s
30
30
  action: fn,
31
31
  attributes: JSON.parse(targetComponent.dataset.state || "{}"),
32
32
  },
33
- params: JSON.parse(component.dataset.state || "{}")
33
+ params: JSON.parse(component.dataset.state || "{}"),
34
+ focus: target.dataset.id,
34
35
  }
35
36
  }
36
37
  );
@@ -1,11 +1,11 @@
1
1
  import { Clapton } from "components"
2
2
 
3
- const bq = (...props: any[]) => {
3
+ const blockquote = (...props: any[]) => {
4
4
  return new Clapton.BlockQuote(...props)
5
5
  }
6
6
 
7
- const box = (...props: any[]) => {
8
- return new Clapton.Box(...props)
7
+ const div = (...props: any[]) => {
8
+ return new Clapton.Div(...props)
9
9
  }
10
10
 
11
11
  const b = (...props: any[]) => {
@@ -16,18 +16,10 @@ const button = (...props: any[]) => {
16
16
  return new Clapton.Button(...props)
17
17
  }
18
18
 
19
- const check = (...props: any[]) => {
20
- return new Clapton.Checkbox(props[0], props[1], props[2])
21
- }
22
-
23
19
  const code = (...props: any[]) => {
24
20
  return new Clapton.Code(...props)
25
21
  }
26
22
 
27
- const datetime = (...props: any[]) => {
28
- return new Clapton.DateTimeField(props[0], props[1], props[2])
29
- }
30
-
31
23
  const el = (...props: any[]) => {
32
24
  return new Clapton.Element(props[0], props[1])
33
25
  }
@@ -44,16 +36,36 @@ const form = (...props: any[]) => {
44
36
  return new Clapton.Form(...props)
45
37
  }
46
38
 
47
- const h = (...props: any[]) => {
48
- return new Clapton.Heading(props[0], props[1])
39
+ const h1 = (...props: any[]) => {
40
+ return new Clapton.Heading(1, props[1])
41
+ }
42
+
43
+ const h2 = (...props: any[]) => {
44
+ return new Clapton.Heading(2, props[1])
45
+ }
46
+
47
+ const h3 = (...props: any[]) => {
48
+ return new Clapton.Heading(3, props[1])
49
+ }
50
+
51
+ const h4 = (...props: any[]) => {
52
+ return new Clapton.Heading(4, props[1])
53
+ }
54
+
55
+ const h5 = (...props: any[]) => {
56
+ return new Clapton.Heading(5, props[1])
57
+ }
58
+
59
+ const h6 = (...props: any[]) => {
60
+ return new Clapton.Heading(6, props[1])
49
61
  }
50
62
 
51
63
  const img = (...props: any[]) => {
52
- return new Clapton.Image(props[0], props[1], props[2])
64
+ return new Clapton.Image(props[0])
53
65
  }
54
66
 
55
67
  const a = (...props: any[]) => {
56
- return new Clapton.Link(props[0], props[1])
68
+ return new Clapton.Link(props[0])
57
69
  }
58
70
 
59
71
  const li = (...props: any[]) => {
@@ -76,10 +88,6 @@ const q = (...props: any[]) => {
76
88
  return new Clapton.Quote(...props)
77
89
  }
78
90
 
79
- const radio = (...props: any[]) => {
80
- return new Clapton.RadioButton(props[0], props[1], props[2])
81
- }
82
-
83
91
  const select = (...props: any[]) => {
84
92
  return new Clapton.Select(props[0], props[1], props[2])
85
93
  }
@@ -93,7 +101,7 @@ const textarea = (...props: any[]) => {
93
101
  }
94
102
 
95
103
  const input = (...props: any[]) => {
96
- return new Clapton.TextField(props[0], props[1], props[2])
104
+ return new Clapton.Input(props[0], props[1], props[2])
97
105
  }
98
106
 
99
107
  const text = (...props: any[]) => {
@@ -103,19 +111,19 @@ const text = (...props: any[]) => {
103
111
  const c = (name: string, ...props: any[]) => {
104
112
  switch (name) {
105
113
  case "bq":
106
- return bq(...props)
114
+ return blockquote(...props)
107
115
  case "box":
108
- return box(...props)
116
+ return div(...props)
117
+ case "blockquote":
118
+ return blockquote(...props)
119
+ case "div":
120
+ return div(...props)
109
121
  case "b":
110
122
  return b(...props)
111
123
  case "button":
112
124
  return button(...props)
113
- case "check":
114
- return check(...props)
115
125
  case "code":
116
126
  return code(...props)
117
- case "datetime":
118
- return datetime(...props)
119
127
  case "el":
120
128
  return el(...props)
121
129
  case "embed":
@@ -125,7 +133,19 @@ const c = (name: string, ...props: any[]) => {
125
133
  case "form":
126
134
  return form(...props)
127
135
  case "h":
128
- return h(...props)
136
+ return h1(...props)
137
+ case "h1":
138
+ return h1(...props)
139
+ case "h2":
140
+ return h2(...props)
141
+ case "h3":
142
+ return h3(...props)
143
+ case "h4":
144
+ return h4(...props)
145
+ case "h5":
146
+ return h5(...props)
147
+ case "h6":
148
+ return h6(...props)
129
149
  case "img":
130
150
  return img(...props)
131
151
  case "a":
@@ -140,8 +160,6 @@ const c = (name: string, ...props: any[]) => {
140
160
  return p(...props)
141
161
  case "q":
142
162
  return q(...props)
143
- case "radio":
144
- return radio(...props)
145
163
  case "select":
146
164
  return select(...props)
147
165
  case "span":
@@ -152,8 +170,17 @@ const c = (name: string, ...props: any[]) => {
152
170
  return input(...props)
153
171
  case "text":
154
172
  return text(...props)
173
+ case "radio":
174
+ props[3].type = "radio"
175
+ return input(...props)
176
+ case "datetime":
177
+ props[3].type = "datetime-local"
178
+ return input(...props)
179
+ case "check":
180
+ props[3].type = "checkbox"
181
+ return input(...props)
155
182
  default:
156
- return new Clapton.Component(...props)
183
+ return new Clapton.Element(name, ...props)
157
184
  }
158
185
  }
159
186
 
@@ -1,7 +1,6 @@
1
1
  import morphdom from "morphdom"
2
2
  import { createConsumer } from "@rails/actioncable"
3
3
  import { initializeActions } from "../actions/initialize-actions.ts"
4
- import { initializeInputs } from "../inputs/initialize-inputs.ts"
5
4
  const consumer = createConsumer()
6
5
 
7
6
  export const claptonChannel = consumer.subscriptions.create("Clapton::ClaptonChannel", {
@@ -18,12 +17,14 @@ export const claptonChannel = consumer.subscriptions.create("Clapton::ClaptonCha
18
17
  const instance = new module[data.component.name](data.state, data.component.id, errors);
19
18
  morphdom(component, instance.renderWrapper, {
20
19
  onBeforeElUpdated: (_fromEl, toEl) => {
20
+ if (_fromEl.dataset.id === data.focus) {
21
+ return false;
22
+ }
21
23
  toEl.setAttribute("data-set-event-handler", "true");
22
24
  return true;
23
25
  }
24
26
  });
25
27
 
26
- initializeInputs();
27
28
  initializeActions();
28
29
  instance.runEffects();
29
30
  }
@@ -1,5 +1,4 @@
1
1
  import { initializeActions } from "actions/initialize-actions";
2
- import { initializeInputs } from "inputs/initialize-inputs";
3
2
 
4
3
  interface ComponentDefinition {
5
4
  component: string;
@@ -42,7 +41,6 @@ const createAndAppendComponent = async (component: ComponentDefinition, element:
42
41
  document.addEventListener("DOMContentLoaded", async () => {
43
42
  await initializeComponents();
44
43
  initializeActions();
45
- initializeInputs();
46
44
  const event = new Event('clapton:render');
47
45
  document.dispatchEvent(event);
48
46
  });
@@ -50,7 +48,6 @@ document.addEventListener("DOMContentLoaded", async () => {
50
48
  document.addEventListener("turbo:render", async () => {
51
49
  await initializeComponents();
52
50
  initializeActions();
53
- initializeInputs();
54
51
  const event = new Event('clapton:render');
55
52
  document.dispatchEvent(event);
56
53
  });