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,16 +0,0 @@
1
- import { describe, it, expect } from "vitest"
2
- import { TextField } from "./text-field"
3
-
4
- describe("TextField", () => {
5
- it("returns empty string if no params", () => {
6
- expect(new TextField({}, "foo").renderWrapper).toBe("<input type='text' data-attribute='foo' value=''/>")
7
- })
8
-
9
- it("returns attributes and data attributes", () => {
10
- expect(new TextField({ foo: "bar" }, "foo", { id: "1", "data-foo": "bar" }).renderWrapper).toBe(`<input type='text' id='1' data-foo='bar' data-attribute='foo' value='bar'/>`)
11
- })
12
-
13
- it("returns attributes and data attributes with custom data attributes", () => {
14
- expect(new TextField({ foo: "bar" }, "foo", { id: "1", data: { foo: { baz: "qux", quux: "corge" } } }).renderWrapper).toBe(`<input type='text' id='1' data-attribute='foo' data-foo-baz='qux' data-foo-quux='corge' value='bar'/>`)
15
- })
16
- })
@@ -1,23 +0,0 @@
1
- import { htmlAttributes } from "../html/html-attributes";
2
-
3
- export class TextField {
4
- state: any;
5
- attribute: string;
6
- attributes: Record<string, any>;
7
-
8
- constructor(state: any, attribute: string, attributes: Record<string, any> = {}) {
9
- this.state = state;
10
- this.attributes = attributes;
11
- this.attribute = attribute;
12
- this.attributes["data-attribute"] = attribute;
13
- }
14
-
15
- get renderWrapper(): string {
16
- return `<input type='text' ${htmlAttributes(this.attributes)} value='${this.state[this.attribute] || ""}'/>`;
17
- }
18
-
19
- add_action(event: string, klass: string, fn: string, options: { debounce?: number } = {}): TextField {
20
- this.attributes["data-action"] = `${this.attributes["data-action"] || ""} ${event}->${klass}#${fn}@${options.debounce || 0}`;
21
- return this;
22
- }
23
- }
@@ -1,11 +0,0 @@
1
- import morphdom from "morphdom";
2
-
3
- export const updateComponent = async (component: HTMLElement, state: any, property: string, target: HTMLInputElement) => {
4
- state[property] = target.value;
5
- const componentName = component.dataset.component as string;
6
- const module = await import(`${componentName}`);
7
- const ComponentClass = module[componentName] as any;
8
- const instance = new ComponentClass(state, component.dataset.id);
9
- morphdom(component, instance.renderWrapper);
10
- instance.runEffects();
11
- };
@@ -1,16 +0,0 @@
1
- import { updateComponent } from "../dom/update-component";
2
-
3
- export const initializeInputs = () => {
4
- const inputElements = document.querySelectorAll("[data-attribute]");
5
- inputElements.forEach((element: any) => {
6
- const attribute = element.getAttribute("data-attribute");
7
- const component = element.closest(`[data-component]`) as HTMLElement;
8
- const state = JSON.parse(component.getAttribute("data-state") || "{}");
9
- if (!attribute || !component) return;
10
- if (element.tagName === "INPUT") {
11
- element.addEventListener("input", async (event: Event) => {
12
- await updateComponent(component, state, attribute, event.target as HTMLInputElement);
13
- });
14
- }
15
- });
16
- };