clapton 0.0.24 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -113
- data/lib/clapton/javascripts/dist/c-for-test.js +108 -271
- data/lib/clapton/javascripts/dist/c.js +108 -271
- data/lib/clapton/javascripts/dist/components-for-test.js +69 -245
- data/lib/clapton/javascripts/dist/components.js +68 -241
- data/lib/clapton/javascripts/src/c-base.ts +45 -33
- 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} +9 -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 -14
- 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/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clapton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moeki Kawakami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -130,8 +130,6 @@ files:
|
|
130
130
|
- config/routes.rb
|
131
131
|
- lib/clapton.rb
|
132
132
|
- lib/clapton/engine.rb
|
133
|
-
- lib/clapton/javascripts/dist/c
|
134
|
-
- lib/clapton/javascripts/dist/c-base.js
|
135
133
|
- lib/clapton/javascripts/dist/c-for-test.js
|
136
134
|
- lib/clapton/javascripts/dist/c.js
|
137
135
|
- lib/clapton/javascripts/dist/client.js
|
@@ -6713,21 +6711,18 @@ files:
|
|
6713
6711
|
- lib/clapton/javascripts/src/client.ts
|
6714
6712
|
- lib/clapton/javascripts/src/components-for-test.ts
|
6715
6713
|
- lib/clapton/javascripts/src/components.ts
|
6714
|
+
- lib/clapton/javascripts/src/components/base.ts
|
6716
6715
|
- lib/clapton/javascripts/src/components/block-quote.spec.ts
|
6717
6716
|
- lib/clapton/javascripts/src/components/block-quote.ts
|
6718
6717
|
- lib/clapton/javascripts/src/components/bold.spec.ts
|
6719
6718
|
- lib/clapton/javascripts/src/components/bold.ts
|
6720
|
-
- lib/clapton/javascripts/src/components/box.spec.ts
|
6721
|
-
- lib/clapton/javascripts/src/components/box.ts
|
6722
6719
|
- lib/clapton/javascripts/src/components/button.spec.ts
|
6723
6720
|
- lib/clapton/javascripts/src/components/button.ts
|
6724
|
-
- lib/clapton/javascripts/src/components/checkbox.spec.ts
|
6725
|
-
- lib/clapton/javascripts/src/components/checkbox.ts
|
6726
6721
|
- lib/clapton/javascripts/src/components/code.spec.ts
|
6727
6722
|
- lib/clapton/javascripts/src/components/code.ts
|
6728
6723
|
- lib/clapton/javascripts/src/components/component.ts
|
6729
|
-
- lib/clapton/javascripts/src/components/
|
6730
|
-
- lib/clapton/javascripts/src/components/
|
6724
|
+
- lib/clapton/javascripts/src/components/div.spec.ts
|
6725
|
+
- lib/clapton/javascripts/src/components/div.ts
|
6731
6726
|
- lib/clapton/javascripts/src/components/element.spec.ts
|
6732
6727
|
- lib/clapton/javascripts/src/components/element.ts
|
6733
6728
|
- lib/clapton/javascripts/src/components/embed.spec.ts
|
@@ -6740,6 +6735,8 @@ files:
|
|
6740
6735
|
- lib/clapton/javascripts/src/components/heading.ts
|
6741
6736
|
- lib/clapton/javascripts/src/components/image.spec.ts
|
6742
6737
|
- lib/clapton/javascripts/src/components/image.ts
|
6738
|
+
- lib/clapton/javascripts/src/components/input.spec.ts
|
6739
|
+
- lib/clapton/javascripts/src/components/input.ts
|
6743
6740
|
- lib/clapton/javascripts/src/components/link.spec.ts
|
6744
6741
|
- lib/clapton/javascripts/src/components/link.ts
|
6745
6742
|
- lib/clapton/javascripts/src/components/list-item.spec.ts
|
@@ -6752,16 +6749,12 @@ files:
|
|
6752
6749
|
- lib/clapton/javascripts/src/components/paragraph.ts
|
6753
6750
|
- lib/clapton/javascripts/src/components/quote.spec.ts
|
6754
6751
|
- lib/clapton/javascripts/src/components/quote.ts
|
6755
|
-
- lib/clapton/javascripts/src/components/radio-button.spec.ts
|
6756
|
-
- lib/clapton/javascripts/src/components/radio-button.ts
|
6757
6752
|
- lib/clapton/javascripts/src/components/select.spec.ts
|
6758
6753
|
- lib/clapton/javascripts/src/components/select.ts
|
6759
6754
|
- lib/clapton/javascripts/src/components/span.spec.ts
|
6760
6755
|
- lib/clapton/javascripts/src/components/span.ts
|
6761
6756
|
- lib/clapton/javascripts/src/components/text-area.spec.ts
|
6762
6757
|
- lib/clapton/javascripts/src/components/text-area.ts
|
6763
|
-
- lib/clapton/javascripts/src/components/text-field.spec.ts
|
6764
|
-
- lib/clapton/javascripts/src/components/text-field.ts
|
6765
6758
|
- lib/clapton/javascripts/src/components/text.spec.ts
|
6766
6759
|
- lib/clapton/javascripts/src/components/text.ts
|
6767
6760
|
- lib/clapton/javascripts/src/dom/update-component.ts
|
@@ -1,559 +0,0 @@
|
|
1
|
-
var c = (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}`));
|
12
|
-
}
|
13
|
-
else {
|
14
|
-
acc.push(`${prefix}-${key}='${escapeHtml(value)}'`);
|
15
|
-
}
|
16
|
-
return acc;
|
17
|
-
}, []);
|
18
|
-
};
|
19
|
-
return [
|
20
|
-
others.map(key => {
|
21
|
-
if (key === "disabled") {
|
22
|
-
if (params[key] === false) {
|
23
|
-
return "";
|
24
|
-
}
|
25
|
-
else {
|
26
|
-
return `${key}`;
|
27
|
-
}
|
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, "<")
|
41
|
-
.replace(/>/g, ">")
|
42
|
-
.replace(/"/g, """)
|
43
|
-
.replace(/'/g, "'");
|
44
|
-
};
|
45
|
-
|
46
|
-
class BlockQuote {
|
47
|
-
constructor(attributes = {}) {
|
48
|
-
this.children = [];
|
49
|
-
this.attributes = attributes;
|
50
|
-
}
|
51
|
-
get renderWrapper() {
|
52
|
-
return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
|
53
|
-
}
|
54
|
-
add(child) {
|
55
|
-
this.children.push(child);
|
56
|
-
return this;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
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 renderWrapper() {
|
70
|
-
return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
|
71
|
-
}
|
72
|
-
add_action(eventType, stateName, fnName, options = {}) {
|
73
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${eventType}->${stateName}#${fnName}@${options.debounce || 0}`;
|
74
|
-
return this;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
class Button {
|
79
|
-
constructor(attributes = {}) {
|
80
|
-
this.attributes = attributes;
|
81
|
-
this.children = [];
|
82
|
-
}
|
83
|
-
add(child) {
|
84
|
-
this.children.push(child);
|
85
|
-
return this;
|
86
|
-
}
|
87
|
-
get renderWrapper() {
|
88
|
-
return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</button>`;
|
89
|
-
}
|
90
|
-
add_action(event, klass, fn, options = {}) {
|
91
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
92
|
-
return this;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
class Bold {
|
97
|
-
constructor(attributes = {}) {
|
98
|
-
this.children = [];
|
99
|
-
this.attributes = attributes;
|
100
|
-
}
|
101
|
-
get renderWrapper() {
|
102
|
-
return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</strong>`;
|
103
|
-
}
|
104
|
-
add(child) {
|
105
|
-
this.children.push(child);
|
106
|
-
return this;
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
class Checkbox {
|
111
|
-
constructor(state, attribute, attributes = {}) {
|
112
|
-
this.state = state;
|
113
|
-
this.attributes = attributes;
|
114
|
-
this.attribute = attribute;
|
115
|
-
this.attributes["data-attribute"] = attribute;
|
116
|
-
}
|
117
|
-
get renderWrapper() {
|
118
|
-
return `<input type='checkbox' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
119
|
-
}
|
120
|
-
add_action(event, klass, fn, options = {}) {
|
121
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
122
|
-
return this;
|
123
|
-
}
|
124
|
-
}
|
125
|
-
|
126
|
-
class Code {
|
127
|
-
constructor(attributes = {}) {
|
128
|
-
this.children = [];
|
129
|
-
this.attributes = attributes;
|
130
|
-
}
|
131
|
-
get renderWrapper() {
|
132
|
-
return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</code>`;
|
133
|
-
}
|
134
|
-
add(child) {
|
135
|
-
this.children.push(child);
|
136
|
-
return this;
|
137
|
-
}
|
138
|
-
}
|
139
|
-
|
140
|
-
class DateTimeField {
|
141
|
-
constructor(state, attribute, attributes = {}) {
|
142
|
-
this.attributes = {};
|
143
|
-
this.state = state;
|
144
|
-
this.attribute = attribute;
|
145
|
-
this.attributes = attributes;
|
146
|
-
this.attributes["data-attribute"] = attribute;
|
147
|
-
}
|
148
|
-
get renderWrapper() {
|
149
|
-
const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
|
150
|
-
return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
|
151
|
-
}
|
152
|
-
add_action(event, klass, fn, options = {}) {
|
153
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
154
|
-
return this;
|
155
|
-
}
|
156
|
-
datetime_local_value(value) {
|
157
|
-
if (!value) {
|
158
|
-
return "";
|
159
|
-
}
|
160
|
-
const date = new Date(value);
|
161
|
-
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
|
162
|
-
let month = date.getMonth() + 1;
|
163
|
-
let day = date.getDate();
|
164
|
-
let hours = date.getHours();
|
165
|
-
let minutes = date.getMinutes();
|
166
|
-
if (month < 10) {
|
167
|
-
month = `0${month}`;
|
168
|
-
}
|
169
|
-
if (day < 10) {
|
170
|
-
day = `0${day}`;
|
171
|
-
}
|
172
|
-
if (hours < 10) {
|
173
|
-
hours = `0${hours}`;
|
174
|
-
}
|
175
|
-
if (minutes < 10) {
|
176
|
-
minutes = `0${minutes}`;
|
177
|
-
}
|
178
|
-
return `${date.getFullYear()}-${month}-${day}T${hours}:${minutes}`;
|
179
|
-
}
|
180
|
-
}
|
181
|
-
|
182
|
-
class Element {
|
183
|
-
constructor(type, attributes = {}) {
|
184
|
-
this.children = [];
|
185
|
-
this.type = type;
|
186
|
-
this.attributes = attributes;
|
187
|
-
}
|
188
|
-
get renderWrapper() {
|
189
|
-
return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</${this.type}>`;
|
190
|
-
}
|
191
|
-
add(child) {
|
192
|
-
this.children.push(child);
|
193
|
-
return this;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
class Embed {
|
198
|
-
constructor(html) {
|
199
|
-
this.html = html;
|
200
|
-
}
|
201
|
-
get renderWrapper() {
|
202
|
-
return this.html;
|
203
|
-
}
|
204
|
-
}
|
205
|
-
|
206
|
-
class Emphasis {
|
207
|
-
constructor(attributes = {}) {
|
208
|
-
this.children = [];
|
209
|
-
this.attributes = attributes;
|
210
|
-
}
|
211
|
-
get renderWrapper() {
|
212
|
-
return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</em>`;
|
213
|
-
}
|
214
|
-
add(child) {
|
215
|
-
this.children.push(child);
|
216
|
-
return this;
|
217
|
-
}
|
218
|
-
}
|
219
|
-
|
220
|
-
class Form {
|
221
|
-
constructor(attributes = {}) {
|
222
|
-
this.children = [];
|
223
|
-
this.attributes = attributes;
|
224
|
-
}
|
225
|
-
get renderWrapper() {
|
226
|
-
return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</form>`;
|
227
|
-
}
|
228
|
-
add(child) {
|
229
|
-
this.children.push(child);
|
230
|
-
return this;
|
231
|
-
}
|
232
|
-
}
|
233
|
-
|
234
|
-
class Heading {
|
235
|
-
constructor(level, attributes = {}) {
|
236
|
-
this.children = [];
|
237
|
-
this.level = level;
|
238
|
-
this.attributes = attributes;
|
239
|
-
}
|
240
|
-
get renderWrapper() {
|
241
|
-
return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</h${this.level}>`;
|
242
|
-
}
|
243
|
-
add(child) {
|
244
|
-
this.children.push(child);
|
245
|
-
return this;
|
246
|
-
}
|
247
|
-
}
|
248
|
-
|
249
|
-
class Image {
|
250
|
-
constructor(src, alt, attributes = {}) {
|
251
|
-
this.children = [];
|
252
|
-
this.attributes = attributes;
|
253
|
-
this.src = src;
|
254
|
-
this.alt = alt;
|
255
|
-
}
|
256
|
-
get renderWrapper() {
|
257
|
-
return `<img src='${this.src}' alt='${this.alt}' ${htmlAttributes(this.attributes)}/>`;
|
258
|
-
}
|
259
|
-
}
|
260
|
-
|
261
|
-
class Link {
|
262
|
-
constructor(href, attributes = {}) {
|
263
|
-
this.children = [];
|
264
|
-
this.attributes = attributes;
|
265
|
-
this.href = href;
|
266
|
-
}
|
267
|
-
get renderWrapper() {
|
268
|
-
return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</a>`;
|
269
|
-
}
|
270
|
-
add(child) {
|
271
|
-
this.children.push(child);
|
272
|
-
return this;
|
273
|
-
}
|
274
|
-
}
|
275
|
-
|
276
|
-
class ListItem {
|
277
|
-
constructor(attributes = {}) {
|
278
|
-
this.children = [];
|
279
|
-
this.attributes = attributes;
|
280
|
-
}
|
281
|
-
add(child) {
|
282
|
-
this.children.push(child);
|
283
|
-
return this;
|
284
|
-
}
|
285
|
-
get renderWrapper() {
|
286
|
-
return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</li>`;
|
287
|
-
}
|
288
|
-
}
|
289
|
-
|
290
|
-
class List {
|
291
|
-
constructor(attributes = {}) {
|
292
|
-
this.children = [];
|
293
|
-
this.attributes = attributes;
|
294
|
-
}
|
295
|
-
add(child) {
|
296
|
-
this.children.push(child);
|
297
|
-
return this;
|
298
|
-
}
|
299
|
-
get renderWrapper() {
|
300
|
-
return `<ul ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ul>`;
|
301
|
-
}
|
302
|
-
}
|
303
|
-
|
304
|
-
class OrderedList {
|
305
|
-
constructor(attributes = {}) {
|
306
|
-
this.children = [];
|
307
|
-
this.attributes = attributes;
|
308
|
-
}
|
309
|
-
add(child) {
|
310
|
-
this.children.push(child);
|
311
|
-
return this;
|
312
|
-
}
|
313
|
-
get renderWrapper() {
|
314
|
-
return `<ol ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ol>`;
|
315
|
-
}
|
316
|
-
}
|
317
|
-
|
318
|
-
class Paragraph {
|
319
|
-
constructor(attributes = {}) {
|
320
|
-
this.children = [];
|
321
|
-
this.attributes = attributes;
|
322
|
-
}
|
323
|
-
get renderWrapper() {
|
324
|
-
return `<p ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</p>`;
|
325
|
-
}
|
326
|
-
add(child) {
|
327
|
-
this.children.push(child);
|
328
|
-
return this;
|
329
|
-
}
|
330
|
-
}
|
331
|
-
|
332
|
-
class Quote {
|
333
|
-
constructor(attributes = {}) {
|
334
|
-
this.children = [];
|
335
|
-
this.attributes = attributes;
|
336
|
-
}
|
337
|
-
get renderWrapper() {
|
338
|
-
return `<q ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</q>`;
|
339
|
-
}
|
340
|
-
add(child) {
|
341
|
-
this.children.push(child);
|
342
|
-
return this;
|
343
|
-
}
|
344
|
-
}
|
345
|
-
|
346
|
-
class RadioButton {
|
347
|
-
constructor(state, attribute, attributes = {}) {
|
348
|
-
this.state = state;
|
349
|
-
this.attributes = attributes;
|
350
|
-
this.attribute = attribute;
|
351
|
-
this.attributes["data-attribute"] = attribute;
|
352
|
-
}
|
353
|
-
get renderWrapper() {
|
354
|
-
return `<input type='radio' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
355
|
-
}
|
356
|
-
add_action(event, klass, fn, options = {}) {
|
357
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
358
|
-
return this;
|
359
|
-
}
|
360
|
-
}
|
361
|
-
|
362
|
-
class Select {
|
363
|
-
constructor(options = [], state, attribute, attributes = {}) {
|
364
|
-
this.children = [];
|
365
|
-
this.options = options;
|
366
|
-
this.state = state;
|
367
|
-
this.attribute = attribute;
|
368
|
-
this.attributes = attributes;
|
369
|
-
}
|
370
|
-
get renderWrapper() {
|
371
|
-
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>`;
|
372
|
-
}
|
373
|
-
}
|
374
|
-
|
375
|
-
class Span {
|
376
|
-
constructor(attributes = {}) {
|
377
|
-
this.children = [];
|
378
|
-
this.attributes = attributes;
|
379
|
-
}
|
380
|
-
get renderWrapper() {
|
381
|
-
return `<span ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</span>`;
|
382
|
-
}
|
383
|
-
add(child) {
|
384
|
-
this.children.push(child);
|
385
|
-
return this;
|
386
|
-
}
|
387
|
-
}
|
388
|
-
|
389
|
-
class Component {
|
390
|
-
constructor(state = {}, id = Math.random().toString(36).substring(2, 10), errors = []) {
|
391
|
-
this._state = state;
|
392
|
-
this.id = id;
|
393
|
-
this._errors = errors;
|
394
|
-
}
|
395
|
-
get render() {
|
396
|
-
return new Box({});
|
397
|
-
}
|
398
|
-
get renderWrapper() {
|
399
|
-
const root = this.render;
|
400
|
-
if (root.attributes) {
|
401
|
-
root.attributes = { ...root.attributes, data: { ...root.attributes.data, component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } };
|
402
|
-
}
|
403
|
-
else {
|
404
|
-
root.attributes = { data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } };
|
405
|
-
}
|
406
|
-
return root.renderWrapper;
|
407
|
-
}
|
408
|
-
}
|
409
|
-
|
410
|
-
class TextField {
|
411
|
-
constructor(state, attribute, attributes = {}) {
|
412
|
-
this.state = state;
|
413
|
-
this.attributes = attributes;
|
414
|
-
this.attribute = attribute;
|
415
|
-
this.attributes["data-attribute"] = attribute;
|
416
|
-
}
|
417
|
-
get renderWrapper() {
|
418
|
-
return `<input type='text' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
|
419
|
-
}
|
420
|
-
add_action(event, klass, fn, options = {}) {
|
421
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
422
|
-
return this;
|
423
|
-
}
|
424
|
-
}
|
425
|
-
|
426
|
-
class Text {
|
427
|
-
constructor(value) {
|
428
|
-
this.value = value;
|
429
|
-
}
|
430
|
-
get renderWrapper() {
|
431
|
-
return this.value;
|
432
|
-
}
|
433
|
-
}
|
434
|
-
|
435
|
-
class TextArea {
|
436
|
-
constructor(state, attribute, attributes = {}) {
|
437
|
-
this.state = state;
|
438
|
-
this.attributes = attributes;
|
439
|
-
this.attribute = attribute;
|
440
|
-
this.attributes["data-attribute"] = attribute;
|
441
|
-
}
|
442
|
-
get renderWrapper() {
|
443
|
-
return `<textarea ${htmlAttributes(this.attributes)}>${this.state[this.attribute] || ""}</textarea>`;
|
444
|
-
}
|
445
|
-
add_action(event, klass, fn, options = {}) {
|
446
|
-
this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
|
447
|
-
return this;
|
448
|
-
}
|
449
|
-
}
|
450
|
-
|
451
|
-
const Clapton = {
|
452
|
-
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
|
453
|
-
};
|
454
|
-
|
455
|
-
const bq = (...props) => {
|
456
|
-
return new Clapton.BlockQuote(...props);
|
457
|
-
};
|
458
|
-
const box = (...props) => {
|
459
|
-
return new Clapton.Box(...props);
|
460
|
-
};
|
461
|
-
const b = (...props) => {
|
462
|
-
return new Clapton.Bold(...props);
|
463
|
-
};
|
464
|
-
const button = (...props) => {
|
465
|
-
return new Clapton.Button(...props);
|
466
|
-
};
|
467
|
-
const check = (...props) => {
|
468
|
-
return new Clapton.Checkbox(props[0], props[1], props[2]);
|
469
|
-
};
|
470
|
-
const code = (...props) => {
|
471
|
-
return new Clapton.Code(...props);
|
472
|
-
};
|
473
|
-
const datetime = (...props) => {
|
474
|
-
return new Clapton.DateTimeField(props[0], props[1], props[2]);
|
475
|
-
};
|
476
|
-
const el = (...props) => {
|
477
|
-
return new Clapton.Element(props[0], props[1]);
|
478
|
-
};
|
479
|
-
const embed = (...props) => {
|
480
|
-
return new Clapton.Embed(props[0]);
|
481
|
-
};
|
482
|
-
const em = (...props) => {
|
483
|
-
return new Clapton.Emphasis(...props);
|
484
|
-
};
|
485
|
-
const form = (...props) => {
|
486
|
-
return new Clapton.Form(...props);
|
487
|
-
};
|
488
|
-
const h = (...props) => {
|
489
|
-
return new Clapton.Heading(props[0], props[1]);
|
490
|
-
};
|
491
|
-
const img = (...props) => {
|
492
|
-
return new Clapton.Image(props[0], props[1], props[2]);
|
493
|
-
};
|
494
|
-
const a = (...props) => {
|
495
|
-
return new Clapton.Link(props[0], props[1]);
|
496
|
-
};
|
497
|
-
const li = (...props) => {
|
498
|
-
return new Clapton.ListItem(...props);
|
499
|
-
};
|
500
|
-
const ul = (...props) => {
|
501
|
-
return new Clapton.List(...props);
|
502
|
-
};
|
503
|
-
const ol = (...props) => {
|
504
|
-
return new Clapton.OrderedList(...props);
|
505
|
-
};
|
506
|
-
const p = (...props) => {
|
507
|
-
return new Clapton.Paragraph(...props);
|
508
|
-
};
|
509
|
-
const q = (...props) => {
|
510
|
-
return new Clapton.Quote(...props);
|
511
|
-
};
|
512
|
-
const radio = (...props) => {
|
513
|
-
return new Clapton.RadioButton(props[0], props[1], props[2]);
|
514
|
-
};
|
515
|
-
const select = (...props) => {
|
516
|
-
return new Clapton.Select(props[0], props[1], props[2]);
|
517
|
-
};
|
518
|
-
const span = (...props) => {
|
519
|
-
return new Clapton.Span(...props);
|
520
|
-
};
|
521
|
-
const textarea = (...props) => {
|
522
|
-
return new Clapton.TextArea(props[0], props[1], props[2]);
|
523
|
-
};
|
524
|
-
const input = (...props) => {
|
525
|
-
return new Clapton.TextField(props[0], props[1], props[2]);
|
526
|
-
};
|
527
|
-
const text = (...props) => {
|
528
|
-
return new Clapton.Text(props[0]);
|
529
|
-
};
|
530
|
-
|
531
|
-
exports.a = a;
|
532
|
-
exports.b = b;
|
533
|
-
exports.box = box;
|
534
|
-
exports.bq = bq;
|
535
|
-
exports.button = button;
|
536
|
-
exports.check = check;
|
537
|
-
exports.code = code;
|
538
|
-
exports.datetime = datetime;
|
539
|
-
exports.el = el;
|
540
|
-
exports.em = em;
|
541
|
-
exports.embed = embed;
|
542
|
-
exports.form = form;
|
543
|
-
exports.h = h;
|
544
|
-
exports.img = img;
|
545
|
-
exports.input = input;
|
546
|
-
exports.li = li;
|
547
|
-
exports.ol = ol;
|
548
|
-
exports.p = p;
|
549
|
-
exports.q = q;
|
550
|
-
exports.radio = radio;
|
551
|
-
exports.select = select;
|
552
|
-
exports.span = span;
|
553
|
-
exports.text = text;
|
554
|
-
exports.textarea = textarea;
|
555
|
-
exports.ul = ul;
|
556
|
-
|
557
|
-
return exports;
|
558
|
-
|
559
|
-
})({});
|