lib/clapton/javascripts/dist/components-for-test.js in clapton-0.0.19 vs lib/clapton/javascripts/dist/components-for-test.js in clapton-0.0.20

- old
+ new

@@ -384,10 +384,31 @@ this.children.push(child); return this; } } + class Component { + constructor(state = {}, id = Math.random().toString(36).substring(2, 10), errors = []) { + this._state = state; + this.id = id; + this._errors = errors; + } + get render() { + return new Box({}); + } + get renderWrapper() { + const root = this.render; + if (root.attributes) { + root.attributes = { ...root.attributes, data: { ...root.attributes.data, component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } }; + } + else { + root.attributes = { data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } }; + } + return root.renderWrapper; + } + } + class TextField { constructor(state, attribute, attributes = {}) { this.state = state; this.attributes = attributes; this.attribute = attribute; @@ -422,113 +443,9 @@ return `<textarea ${htmlAttributes(this.attributes)}>${this.state[this.attribute] || ""}</textarea>`; } add_action(event, klass, fn, options = {}) { this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`; return this; - } - } - - const Clapton = { - 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 - }; - - class Presets { - bq(...props) { - return new Clapton.BlockQuote(...props); - } - box(...props) { - return new Clapton.Box(...props); - } - b(...props) { - return new Clapton.Bold(...props); - } - button(...props) { - return new Clapton.Button(...props); - } - check(...props) { - return new Clapton.Checkbox(props[0], props[1], props[2]); - } - code(...props) { - return new Clapton.Code(...props); - } - datetime(...props) { - return new Clapton.DateTimeField(props[0], props[1], props[2]); - } - el(...props) { - return new Clapton.Element(props[0], props[1]); - } - embed(...props) { - return new Clapton.Embed(props[0]); - } - em(...props) { - return new Clapton.Emphasis(...props); - } - form(...props) { - return new Clapton.Form(...props); - } - h(...props) { - return new Clapton.Heading(props[0], props[1]); - } - img(...props) { - return new Clapton.Image(props[0], props[1], props[2]); - } - a(...props) { - return new Clapton.Link(props[0], props[1]); - } - li(...props) { - return new Clapton.ListItem(...props); - } - ul(...props) { - return new Clapton.List(...props); - } - ol(...props) { - return new Clapton.OrderedList(...props); - } - p(...props) { - return new Clapton.Paragraph(...props); - } - q(...props) { - return new Clapton.Quote(...props); - } - radio(...props) { - return new Clapton.RadioButton(props[0], props[1], props[2]); - } - select(...props) { - return new Clapton.Select(props[0], props[1], props[2]); - } - span(...props) { - return new Clapton.Span(...props); - } - textarea(...props) { - return new Clapton.TextArea(props[0], props[1], props[2]); - } - input(...props) { - return new Clapton.TextField(props[0], props[1], props[2]); - } - text(...props) { - return new Clapton.Text(props[0]); - } - } - - class Component { - constructor(state = {}, id = Math.random().toString(36).substring(2, 10), errors = []) { - this._state = state; - this.id = id; - this._errors = errors; - this._c = new Presets(); - } - get render() { - return new Box({}); - } - get renderWrapper() { - const root = this.render; - if (root.attributes) { - root.attributes = { ...root.attributes, data: { ...root.attributes.data, component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } }; - } - else { - root.attributes = { data: { component: this.constructor.name, state: JSON.stringify(this._state), id: this.id, errors: this._errors } }; - } - return root.renderWrapper; } } exports.BlockQuote = BlockQuote; exports.Bold = Bold;