clapton 0.0.12 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -0
  3. data/app/helpers/clapton/clapton_helper.rb +16 -1
  4. data/lib/clapton/engine.rb +16 -10
  5. data/lib/clapton/javascripts/dist/client.js +65 -39
  6. data/lib/clapton/javascripts/dist/components-for-test.js +439 -0
  7. data/lib/clapton/javascripts/dist/components.js +357 -369
  8. data/lib/clapton/javascripts/node_modules/diff-dom/LICENSE.txt +165 -0
  9. data/lib/clapton/javascripts/node_modules/diff-dom/README.md +224 -0
  10. data/lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js +2 -0
  11. data/lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js.map +1 -0
  12. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/TraceLogger.d.ts +28 -0
  13. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/apply.d.ts +4 -0
  14. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/fromVirtual.d.ts +2 -0
  15. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/index.d.ts +2 -0
  16. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/undo.d.ts +3 -0
  17. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/helpers.d.ts +11 -0
  18. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/index.d.ts +10 -0
  19. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/types.d.ts +104 -0
  20. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/apply.d.ts +3 -0
  21. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/diff.d.ts +22 -0
  22. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromDOM.d.ts +2 -0
  23. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromString.d.ts +2 -0
  24. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/helpers.d.ts +40 -0
  25. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/index.d.ts +3 -0
  26. data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/index.d.ts +2 -0
  27. data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.d.ts +136 -0
  28. data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.js +1996 -0
  29. data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.js.map +1 -0
  30. data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js +2 -0
  31. data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js.map +1 -0
  32. data/lib/clapton/javascripts/node_modules/diff-dom/dist/module.js +1991 -0
  33. data/lib/clapton/javascripts/node_modules/diff-dom/dist/module.js.map +1 -0
  34. data/lib/clapton/javascripts/node_modules/diff-dom/index.html +62 -0
  35. data/lib/clapton/javascripts/node_modules/diff-dom/package.json +54 -0
  36. data/lib/clapton/javascripts/node_modules/diff-dom/rollup.config.mjs +67 -0
  37. data/lib/clapton/javascripts/node_modules/diff-dom/src/TraceLogger.ts +143 -0
  38. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/apply.ts +227 -0
  39. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/fromVirtual.ts +83 -0
  40. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/index.ts +2 -0
  41. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/undo.ts +90 -0
  42. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/helpers.ts +40 -0
  43. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/index.ts +121 -0
  44. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/types.ts +154 -0
  45. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/apply.ts +349 -0
  46. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/diff.ts +855 -0
  47. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromDOM.ts +74 -0
  48. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromString.ts +239 -0
  49. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/helpers.ts +461 -0
  50. data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/index.ts +3 -0
  51. data/lib/clapton/javascripts/node_modules/diff-dom/src/index.ts +2 -0
  52. data/lib/clapton/javascripts/node_modules/diff-dom/tsconfig.json +103 -0
  53. data/lib/clapton/javascripts/rollup.config.mjs +17 -2
  54. data/lib/clapton/javascripts/src/actions/handle-action.ts +6 -1
  55. data/lib/clapton/javascripts/src/actions/initialize-actions.ts +11 -0
  56. data/lib/clapton/javascripts/src/channel/clapton-channel.js +8 -4
  57. data/lib/clapton/javascripts/src/client.ts +15 -18
  58. data/lib/clapton/javascripts/src/components/box.ts +5 -0
  59. data/lib/clapton/javascripts/src/components/embed.spec.ts +8 -0
  60. data/lib/clapton/javascripts/src/components/embed.ts +11 -0
  61. data/lib/clapton/javascripts/src/components-for-test.ts +29 -0
  62. data/lib/clapton/javascripts/src/components.ts +5 -1
  63. data/lib/clapton/javascripts/src/dom/update-component.ts +3 -2
  64. data/lib/clapton/javascripts/src/inputs/initialize-inputs.ts +3 -3
  65. data/lib/clapton/test_helper/base.rb +1 -1
  66. data/lib/clapton/version.rb +2 -1
  67. metadata +51 -3
  68. data/lib/clapton/javascripts/src/dom/update-component.spec.ts +0 -32
@@ -1,425 +1,413 @@
1
- var Clapton = (function (exports) {
2
- 'use strict';
3
-
4
- const htmlAttributes = (params) => {
5
- const customDataAttributes = params.data || {};
6
- const others = Object.keys(params).filter(key => key !== "data");
7
- const flattenDataAttributes = (data, prefix = "data") => {
8
- return Object.keys(data).reduce((acc, key) => {
9
- const value = data[key];
10
- if (typeof value === "object" && value !== null) {
11
- acc.push(...flattenDataAttributes(value, `${prefix}-${key}`));
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
- acc.push(`${prefix}-${key}='${escapeHtml(value)}'`);
23
+ return `${key}`;
15
24
  }
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
- }
28
- }
29
- return `${key}='${escapeHtml(params[key])}'`;
30
- }).join(" "),
31
- flattenDataAttributes(customDataAttributes).join(" ")
32
- ].filter(Boolean).join(" ");
33
- };
34
- const escapeHtml = (unsafe) => {
35
- if (typeof unsafe !== "string") {
36
- return "";
37
- }
38
- return unsafe
39
- .replace(/&/g, "&")
40
- .replace(/</g, "&lt;")
41
- .replace(/>/g, "&gt;")
42
- .replace(/"/g, "&quot;")
43
- .replace(/'/g, "&#039;");
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, "&amp;")
37
+ .replace(/</g, "&lt;")
38
+ .replace(/>/g, "&gt;")
39
+ .replace(/"/g, "&quot;")
40
+ .replace(/'/g, "&#039;");
41
+ };
45
42
 
46
- class BlockQuote {
47
- constructor(attributes = {}) {
48
- this.children = [];
49
- this.attributes = attributes;
50
- }
51
- get render() {
52
- return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</blockquote>`;
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>`;
50
+ }
51
+ add(child) {
52
+ this.children.push(child);
53
+ return this;
58
54
  }
55
+ }
59
56
 
60
- class Box {
61
- constructor(attributes = {}) {
62
- this.children = [];
63
- this.attributes = attributes;
64
- }
65
- add(child) {
66
- this.children.push(child);
67
- return this;
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
- class Button {
75
- constructor(attributes = {}) {
76
- this.attributes = attributes;
77
- this.children = [];
78
- }
79
- add(child) {
80
- this.children.push(child);
81
- return this;
82
- }
83
- get render() {
84
- return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</button>`;
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
- class Checkbox {
93
- constructor(state, attribute, attributes = {}) {
94
- this.state = state;
95
- this.attributes = attributes;
96
- this.attribute = attribute;
97
- this.attributes["data-attribute"] = attribute;
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
- class Code {
109
- constructor(attributes = {}) {
110
- this.children = [];
111
- this.attributes = attributes;
112
- }
113
- get render() {
114
- return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</code>`;
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
- class DateTimeField {
123
- constructor(state, attribute, attributes = {}) {
124
- this.attributes = {};
125
- this.state = state;
126
- this.attribute = attribute;
127
- this.attributes = attributes;
128
- this.attributes["data-attribute"] = attribute;
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
- get render() {
131
- const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
132
- return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
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
- add_action(event, klass, fn, options = {}) {
135
- this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
136
- return this;
152
+ if (day < 10) {
153
+ day = `0${day}`;
137
154
  }
138
- datetime_local_value(value) {
139
- if (!value) {
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
- class Element {
165
- constructor(type, attributes = {}) {
166
- this.children = [];
167
- this.type = type;
168
- this.attributes = attributes;
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
- class Emphasis {
180
- constructor(attributes = {}) {
181
- this.children = [];
182
- this.attributes = attributes;
183
- }
184
- get render() {
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
- class Form {
194
- constructor(attributes = {}) {
195
- this.children = [];
196
- this.attributes = attributes;
197
- }
198
- get render() {
199
- return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</form>`;
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
- class Heading {
208
- constructor(level, attributes = {}) {
209
- this.children = [];
210
- this.level = level;
211
- this.attributes = attributes;
212
- }
213
- get render() {
214
- return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</h${this.level}>`;
215
- }
216
- add(child) {
217
- this.children.push(child);
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
- class Image {
223
- constructor(src, alt, attributes = {}) {
224
- this.children = [];
225
- this.attributes = attributes;
226
- this.src = src;
227
- this.alt = alt;
228
- }
229
- get render() {
230
- return `<img src='${this.src}' alt='${this.alt}' ${htmlAttributes(this.attributes)}/>`;
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
- class Link {
235
- constructor(href, attributes = {}) {
236
- this.children = [];
237
- this.attributes = attributes;
238
- this.href = href;
239
- }
240
- get render() {
241
- return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</a>`;
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
- class ListItem {
250
- constructor(attributes = {}) {
251
- this.children = [];
252
- this.attributes = attributes;
253
- }
254
- add(child) {
255
- this.children.push(child);
256
- return this;
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
- class List {
264
- constructor(attributes = {}) {
265
- this.children = [];
266
- this.attributes = attributes;
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
- class OrderedList {
278
- constructor(attributes = {}) {
279
- this.children = [];
280
- this.attributes = attributes;
281
- }
282
- add(child) {
283
- this.children.push(child);
284
- return this;
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
- class Paragraph {
292
- constructor(attributes = {}) {
293
- this.children = [];
294
- this.attributes = attributes;
295
- }
296
- get render() {
297
- return `<p ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</p>`;
298
- }
299
- add(child) {
300
- this.children.push(child);
301
- return this;
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
- class Quote {
306
- constructor(attributes = {}) {
307
- this.children = [];
308
- this.attributes = attributes;
309
- }
310
- get render() {
311
- return `<q ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</q>`;
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
- class RadioButton {
320
- constructor(state, attribute, attributes = {}) {
321
- this.state = state;
322
- this.attributes = attributes;
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
- class Select {
336
- constructor(options = [], state, attribute, attributes = {}) {
337
- this.children = [];
338
- this.options = options;
339
- this.state = state;
340
- this.attribute = attribute;
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
- class Span {
349
- constructor(attributes = {}) {
350
- this.children = [];
351
- this.attributes = attributes;
352
- }
353
- get render() {
354
- return `<span ${htmlAttributes(this.attributes)}>${this.children.map(child => child.render).join("")}</span>`;
355
- }
356
- add(child) {
357
- this.children.push(child);
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
- class Component {
363
- constructor(state = {}, id = Math.random().toString(36).substring(2, 10), errors = []) {
364
- this._state = state;
365
- this.id = id;
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
- class TextField {
375
- constructor(state, attribute, attributes = {}) {
376
- this.state = state;
377
- this.attributes = attributes;
378
- this.attribute = attribute;
379
- this.attributes["data-attribute"] = attribute;
380
- }
381
- get render() {
382
- return `<input type='text' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
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
- class Text {
391
- constructor(value) {
392
- this.value = value;
393
- }
394
- get render() {
395
- return this.value;
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
- exports.BlockQuote = BlockQuote;
400
- exports.Box = Box;
401
- exports.Button = Button;
402
- exports.Checkbox = Checkbox;
403
- exports.Code = Code;
404
- exports.Component = Component;
405
- exports.DateTimeField = DateTimeField;
406
- exports.Element = Element;
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
- return exports;
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 };