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
@@ -1,6 +1,4 @@
1
- import { htmlAttributes } from "../html/html-attributes";
2
-
3
- export class Box {
1
+ export class Base {
4
2
  attributes: Record<string, any>;
5
3
  children: any[];
6
4
 
@@ -9,17 +7,17 @@ export class Box {
9
7
  this.attributes = attributes;
10
8
  }
11
9
 
12
- add(child: any): this {
10
+ add(child: any): Base {
13
11
  this.children.push(child);
14
12
  return this;
15
13
  }
16
14
 
17
- get renderWrapper(): string {
18
- return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
19
- }
20
-
21
15
  add_action(eventType: string, stateName: string, fnName: string, options: Record<string, any> = {}): this {
22
16
  this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${eventType}->${stateName}#${fnName}@${options.debounce || 0}`;
23
17
  return this;
24
18
  }
19
+
20
+ get renderWrapper() {
21
+ return "";
22
+ }
25
23
  }
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "vitest"
2
- import { BlockQuote } from "./block-quote"
2
+ import { BlockQuote} from "./block-quote"
3
3
  import { Text } from "./text"
4
4
 
5
5
  describe("BlockQuote", () => {
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class BlockQuote {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class BlockQuote extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<blockquote ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</blockquote>`;
14
7
  }
15
-
16
- add(child: any): BlockQuote {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Bold {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class Bold extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<strong ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</strong>`;
14
7
  }
15
-
16
- add(child: any): Bold {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,25 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Button {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.attributes = attributes;
9
- this.children = [];
10
- }
11
-
12
- add(child: any): Button {
13
- this.children.push(child);
14
- return this;
15
- }
16
-
4
+ export class Button extends Base {
17
5
  get renderWrapper(): string {
18
6
  return `<button ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</button>`;
19
7
  }
20
-
21
- add_action(event: string, klass: string, fn: string, options: Record<string, any> = {}): Button {
22
- this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
23
- return this;
24
- }
25
8
  }
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Code {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class Code extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<code ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</code>`;
14
7
  }
15
-
16
- add(child: any): Code {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,4 +1,4 @@
1
- import { Box } from "./box";
1
+ import { Div } from "./div";
2
2
 
3
3
  export class Component {
4
4
  id: string;
@@ -14,7 +14,7 @@ export class Component {
14
14
  }
15
15
 
16
16
  get render(): any {
17
- return new Box({});
17
+ return new Div({});
18
18
  }
19
19
 
20
20
  get renderWrapper(): string {
@@ -1,23 +1,23 @@
1
1
  import { describe, it, expect } from "vitest"
2
- import { Box } from "./box"
2
+ import { Div } from "./div"
3
3
  import { Text } from "./text"
4
4
 
5
- describe("Box", () => {
5
+ describe("Div", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Box().renderWrapper).toBe("<div ></div>")
7
+ expect(new Div().renderWrapper).toBe("<div ></div>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Box({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
11
+ expect(new Div({ id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Box({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
16
- expect(new Box({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<div id='1' data-foo='bar' data-baz='qux'></div>`)
17
- expect(new Box({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<div id='1' data-foo-baz='qux' data-foo-quux='corge'></div>`)
15
+ expect(new Div({ id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<div id='1' data-foo='bar'></div>`)
16
+ expect(new Div({ id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<div id='1' data-foo='bar' data-baz='qux'></div>`)
17
+ expect(new Div({ id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<div id='1' data-foo-baz='qux' data-foo-quux='corge'></div>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
- expect(new Box().add(new Text("Hello, world!")).renderWrapper).toBe(`<div >Hello, world!</div>`)
21
+ expect(new Div().add(new Text("Hello, world!")).renderWrapper).toBe(`<div >Hello, world!</div>`)
22
22
  })
23
23
  })
@@ -0,0 +1,8 @@
1
+ import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
3
+
4
+ export class Div extends Base {
5
+ get renderWrapper(): string {
6
+ return `<div ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</div>`;
7
+ }
8
+ }
@@ -1,22 +1,16 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Element {
4
- attributes: Record<string, any>;
5
- children: any[];
4
+ export class Element extends Base {
6
5
  type: string;
7
6
 
8
7
  constructor(type: string, attributes: Record<string, any> = {}) {
8
+ super(attributes)
9
9
  this.children = [];
10
10
  this.type = type;
11
- this.attributes = attributes;
12
11
  }
13
12
 
14
13
  get renderWrapper(): string {
15
14
  return `<${this.type} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</${this.type}>`;
16
15
  }
17
-
18
- add(child: any): Element {
19
- this.children.push(child);
20
- return this;
21
- }
22
16
  }
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Emphasis {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class Emphasis extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<em ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</em>`;
14
7
  }
15
-
16
- add(child: any): Emphasis {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Form {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class Form extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<form ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</form>`;
14
7
  }
15
-
16
- add(child: any): Form {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,21 +1,15 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Heading {
4
- attributes: Record<string, any>;
5
- children: any[];
4
+ export class Heading extends Base {
6
5
  level: number;
6
+
7
7
  constructor(level: number, attributes: Record<string, any> = {}) {
8
- this.children = [];
8
+ super(attributes)
9
9
  this.level = level;
10
- this.attributes = attributes;
11
10
  }
12
11
 
13
12
  get renderWrapper(): string {
14
13
  return `<h${this.level} ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</h${this.level}>`;
15
14
  }
16
-
17
- add(child: any): Heading {
18
- this.children.push(child);
19
- return this;
20
- }
21
15
  }
@@ -3,10 +3,10 @@ import { Image } from "./image"
3
3
 
4
4
  describe("Image", () => {
5
5
  it("returns empty string if no params", () => {
6
- expect(new Image("https://example.com/image.png", "").renderWrapper).toBe("<img src='https://example.com/image.png' alt='' />")
6
+ expect(new Image({ src: "https://example.com/image.png", alt: "" }).renderWrapper).toBe("<img src='https://example.com/image.png' alt=''/>")
7
7
  })
8
8
 
9
9
  it("returns attributes and data attributes", () => {
10
- expect(new Image("https://example.com/image.png", "test", { id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<img src='https://example.com/image.png' alt='test' id='1' data-foo='bar'/>`)
10
+ expect(new Image({ src: "https://example.com/image.png", alt: "test", id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<img src='https://example.com/image.png' alt='test' id='1' data-foo='bar'/>`)
11
11
  })
12
12
  })
@@ -1,19 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Image {
4
- attributes: Record<string, any>;
5
- children: any[];
6
- src: string;
7
- alt: string;
8
-
9
- constructor(src: string, alt: string, attributes: Record<string, any> = {}) {
10
- this.children = [];
11
- this.attributes = attributes;
12
- this.src = src;
13
- this.alt = alt;
14
- }
15
-
4
+ export class Image extends Base {
16
5
  get renderWrapper(): string {
17
- return `<img src='${this.src}' alt='${this.alt}' ${htmlAttributes(this.attributes)}/>`;
6
+ return `<img ${htmlAttributes(this.attributes)}/>`;
18
7
  }
19
8
  }
@@ -0,0 +1,16 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import { Input } from "./input"
3
+
4
+ describe("Input", () => {
5
+ it("returns empty string if no params", () => {
6
+ expect(new Input({}, "foo", { type: "text" }).renderWrapper).toMatch(/<input type='text' data-attribute='foo' data-id='.+' value=''\/>/)
7
+ })
8
+
9
+ it("returns attributes and data attributes", () => {
10
+ expect(new Input({ foo: "bar" }, "foo", { type: "text", id: "1", "data-foo": "bar" }).renderWrapper).toMatch(/<input type='text' id='1' data-foo='bar' data-attribute='foo' data-id='.+' value='bar'\/>/)
11
+ })
12
+
13
+ it("returns attributes and data attributes with custom data attributes", () => {
14
+ expect(new Input({ foo: "bar" }, "foo", { type: "text", id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toMatch(/<input type='text' id='1' data-attribute='foo' data-id='.+' data-foo-baz='qux' data-foo-quux='corge' value='bar'\/>/)
15
+ })
16
+ })
@@ -1,25 +1,27 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class DateTimeField {
4
+ export class Input extends Base {
4
5
  state: any;
5
6
  attribute: string;
6
- attributes: Record<string, any> = {};
7
7
 
8
8
  constructor(state: any, attribute: string, attributes: Record<string, any> = {}) {
9
- this.state = state;
9
+ super(attributes)
10
10
  this.attribute = attribute;
11
- this.attributes = attributes;
11
+ this.state = state
12
12
  this.attributes["data-attribute"] = attribute;
13
+ this.attributes["data-id"] = Math.random().toString(36).substring(2, 10);
13
14
  }
14
15
 
15
16
  get renderWrapper(): string {
16
- const value = this.state[this.attribute] ? this.datetime_local_value(this.state[this.attribute]) : "";
17
- return `<input type='datetime-local' ${htmlAttributes(this.attributes)} value='${value}'/>`;
18
- }
19
-
20
- add_action(event: string, klass: string, fn: string, options: { debounce?: number } = {}): DateTimeField {
21
- this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
22
- return this;
17
+ let value = this.state[this.attribute]
18
+ if (!this.attributes.type) {
19
+ this.attributes.type = "text"
20
+ }
21
+ if (this.attributes.type === "datetime-local" && value) {
22
+ value = this.datetime_local_value(value)
23
+ }
24
+ return `<input ${htmlAttributes(this.attributes)} value='${value || ""}'/>`;
23
25
  }
24
26
 
25
27
  datetime_local_value(value: string): string {
@@ -4,20 +4,20 @@ import { Text } from "./text"
4
4
 
5
5
  describe("Link", () => {
6
6
  it("returns empty string if no params", () => {
7
- expect(new Link("").renderWrapper).toBe("<a href='' ></a>")
7
+ expect(new Link({ href: "" }).renderWrapper).toBe("<a href=''></a>")
8
8
  })
9
9
 
10
10
  it("returns attributes and data attributes", () => {
11
- expect(new Link("#").add(new Text("")).renderWrapper).toBe(`<a href='#' ></a>`)
11
+ expect(new Link({ href: "#" }).add(new Text("")).renderWrapper).toBe(`<a href='#'></a>`)
12
12
  })
13
13
 
14
14
  it("returns attributes and data attributes with custom data attributes", () => {
15
- expect(new Link("#", { id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<a href='#' id='1' data-foo='bar'></a>`)
16
- expect(new Link("#", { id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<a href='#' id='1' data-foo='bar' data-baz='qux'></a>`)
17
- expect(new Link("#", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<a href='#' id='1' data-foo-baz='qux' data-foo-quux='corge'></a>`)
15
+ expect(new Link({ href: "#", id: "1", data: { foo: "bar" } }).renderWrapper).toBe(`<a href='#' id='1' data-foo='bar'></a>`)
16
+ expect(new Link({ href: "#", id: "1", data: { foo: "bar", baz: "qux" } }).renderWrapper).toBe(`<a href='#' id='1' data-foo='bar' data-baz='qux'></a>`)
17
+ expect(new Link({ href: "#", id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<a href='#' id='1' data-foo-baz='qux' data-foo-quux='corge'></a>`)
18
18
  })
19
19
 
20
20
  it("adds children", () => {
21
- expect(new Link("#").add(new Text("Hello")).renderWrapper).toBe(`<a href='#' >Hello</a>`)
21
+ expect(new Link({ href: "#" }).add(new Text("Hello")).renderWrapper).toBe(`<a href='#'>Hello</a>`)
22
22
  })
23
23
  })
@@ -1,21 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Link {
4
- attributes: Record<string, any>;
5
- children: any[];
6
- href: string;
7
- constructor(href: string, attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- this.href = href;
11
- }
12
-
4
+ export class Link extends Base {
13
5
  get renderWrapper(): string {
14
- return `<a href='${this.href}' ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</a>`;
15
- }
16
-
17
- add(child: any): Link {
18
- this.children.push(child);
19
- return this;
6
+ return `<a ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</a>`;
20
7
  }
21
8
  }
@@ -1,19 +1,7 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class ListItem {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
12
- add(child: any): this {
13
- this.children.push(child);
14
- return this;
15
- }
16
-
4
+ export class ListItem extends Base {
17
5
  get renderWrapper(): string {
18
6
  return `<li ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</li>`;
19
7
  }
@@ -1,19 +1,7 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class List {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
12
- add(child: any): this {
13
- this.children.push(child);
14
- return this;
15
- }
16
-
4
+ export class List extends Base {
17
5
  get renderWrapper(): string {
18
6
  return `<ul ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ul>`;
19
7
  }
@@ -1,19 +1,7 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class OrderedList {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
12
- add(child: any): this {
13
- this.children.push(child);
14
- return this;
15
- }
16
-
4
+ export class OrderedList extends Base {
17
5
  get renderWrapper(): string {
18
6
  return `<ol ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</ol>`;
19
7
  }
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Paragraph {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class Paragraph extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<p ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</p>`;
14
7
  }
15
-
16
- add(child: any): Paragraph {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Quote {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class Quote extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<q ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</q>`;
14
7
  }
15
-
16
- add(child: any): Quote {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,23 +1,21 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
4
  type SelectOption = {
4
5
  value: string;
5
6
  text: string;
6
7
  };
7
8
 
8
- export class Select {
9
- attributes: Record<string, any>;
10
- children: any[];
9
+ export class Select extends Base {
11
10
  options: SelectOption[];
12
11
  state: any;
13
12
  attribute: string;
14
13
 
15
14
  constructor(options: SelectOption[] = [], state: any, attribute: string, attributes: Record<string, any> = {}) {
16
- this.children = [];
15
+ super(attributes)
17
16
  this.options = options;
18
17
  this.state = state;
19
18
  this.attribute = attribute;
20
- this.attributes = attributes;
21
19
  }
22
20
 
23
21
  get renderWrapper(): string {
@@ -1,20 +1,8 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class Span {
4
- attributes: Record<string, any>;
5
- children: any[];
6
-
7
- constructor(attributes: Record<string, any> = {}) {
8
- this.children = [];
9
- this.attributes = attributes;
10
- }
11
-
4
+ export class Span extends Base {
12
5
  get renderWrapper(): string {
13
6
  return `<span ${htmlAttributes(this.attributes)}>${this.children.map(child => child.renderWrapper).join("")}</span>`;
14
7
  }
15
-
16
- add(child: any): Span {
17
- this.children.push(child);
18
- return this;
19
- }
20
8
  }
@@ -1,23 +1,18 @@
1
1
  import { htmlAttributes } from "../html/html-attributes";
2
+ import { Base } from "./base";
2
3
 
3
- export class TextArea {
4
+ export class TextArea extends Base {
4
5
  state: any;
5
6
  attribute: string;
6
- attributes: Record<string, any>;
7
7
 
8
8
  constructor(state: any, attribute: string, attributes: Record<string, any> = {}) {
9
- this.state = state;
10
- this.attributes = attributes;
9
+ super(attributes)
11
10
  this.attribute = attribute;
11
+ this.state = state
12
12
  this.attributes["data-attribute"] = attribute;
13
13
  }
14
14
 
15
15
  get renderWrapper(): string {
16
16
  return `<textarea ${htmlAttributes(this.attributes)}>${this.state[this.attribute] || ""}</textarea>`;
17
17
  }
18
-
19
- add_action(event: string, klass: string, fn: string, options: { debounce?: number } = {}): TextArea {
20
- this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
21
- return this;
22
- }
23
18
  }