clapton 0.0.13 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/helpers/clapton/clapton_helper.rb +16 -1
- data/lib/clapton/engine.rb +20 -10
- data/lib/clapton/javascripts/dist/client.js +38 -27
- data/lib/clapton/javascripts/dist/components-for-test.js +439 -0
- data/lib/clapton/javascripts/dist/components.js +356 -382
- data/lib/clapton/javascripts/node_modules/diff-dom/LICENSE.txt +165 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/README.md +224 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/TraceLogger.d.ts +28 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/apply.d.ts +4 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/fromVirtual.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/index.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/undo.d.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/helpers.d.ts +11 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/index.d.ts +10 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/types.d.ts +104 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/apply.d.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/diff.d.ts +22 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromDOM.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromString.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/helpers.d.ts +40 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/index.d.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/dts/index.d.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.d.ts +136 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.js +1996 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/module.js +1991 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/dist/module.js.map +1 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/index.html +62 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/package.json +54 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/rollup.config.mjs +67 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/TraceLogger.ts +143 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/apply.ts +227 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/fromVirtual.ts +83 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/index.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/undo.ts +90 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/helpers.ts +40 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/index.ts +121 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/types.ts +154 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/apply.ts +349 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/diff.ts +855 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromDOM.ts +74 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromString.ts +239 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/helpers.ts +461 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/index.ts +3 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/src/index.ts +2 -0
- data/lib/clapton/javascripts/node_modules/diff-dom/tsconfig.json +103 -0
- data/lib/clapton/javascripts/rollup.config.mjs +17 -2
- data/lib/clapton/javascripts/src/actions/handle-action.ts +6 -6
- data/lib/clapton/javascripts/src/actions/initialize-actions.ts +6 -3
- data/lib/clapton/javascripts/src/channel/clapton-channel.js +6 -3
- data/lib/clapton/javascripts/src/client.ts +15 -15
- data/lib/clapton/javascripts/src/components-for-test.ts +29 -0
- data/lib/clapton/javascripts/src/components.ts +4 -1
- data/lib/clapton/javascripts/src/dom/update-component.ts +4 -4
- data/lib/clapton/javascripts/src/inputs/initialize-inputs.ts +2 -2
- data/lib/clapton/test_helper/base.rb +1 -1
- data/lib/clapton/version.rb +1 -2
- metadata +49 -3
- data/lib/clapton/javascripts/src/dom/update-component.spec.ts +0 -32
@@ -2,28 +2,28 @@ import { initializeActions } from "actions/initialize-actions";
|
|
2
2
|
import { initializeInputs } from "inputs/initialize-inputs";
|
3
3
|
|
4
4
|
interface ComponentDefinition {
|
5
|
-
component:
|
5
|
+
component: string;
|
6
6
|
state: any;
|
7
7
|
id: string;
|
8
8
|
}
|
9
9
|
|
10
|
-
|
11
|
-
render: string;
|
12
|
-
[key: string]: any;
|
13
|
-
}
|
14
|
-
|
15
|
-
const initializeComponents = () => {
|
10
|
+
const initializeComponents = async () => {
|
16
11
|
const components = document.querySelector("#clapton")?.getAttribute("data-clapton") || "[]";
|
17
|
-
JSON.parse(components)
|
18
|
-
|
12
|
+
const componentArray = JSON.parse(components);
|
13
|
+
for (const component of componentArray) {
|
14
|
+
await createAndAppendComponent(component, document.querySelector("#clapton")!);
|
15
|
+
}
|
16
|
+
const elements = document.querySelectorAll(".clapton-component");
|
17
|
+
for (const element of elements) {
|
19
18
|
const component = JSON.parse(element.getAttribute("data-clapton") || "{}");
|
20
|
-
createAndAppendComponent(component, element as HTMLElement);
|
21
|
-
}
|
19
|
+
await createAndAppendComponent(component, element as HTMLElement);
|
20
|
+
}
|
22
21
|
};
|
23
22
|
|
24
|
-
const createAndAppendComponent = (component: ComponentDefinition, element: HTMLElement) => {
|
23
|
+
const createAndAppendComponent = async (component: ComponentDefinition, element: HTMLElement) => {
|
25
24
|
const componentDom = document.createElement('div');
|
26
|
-
const
|
25
|
+
const module = await import(`${component.component}`);
|
26
|
+
const instance = new (module[component.component] as any)(component.state);
|
27
27
|
componentDom.innerHTML = instance.render;
|
28
28
|
const firstChild = componentDom.firstChild as HTMLElement;
|
29
29
|
if (firstChild) {
|
@@ -31,8 +31,8 @@ const createAndAppendComponent = (component: ComponentDefinition, element: HTMLE
|
|
31
31
|
}
|
32
32
|
};
|
33
33
|
|
34
|
-
document.addEventListener("DOMContentLoaded", () => {
|
35
|
-
initializeComponents();
|
34
|
+
document.addEventListener("DOMContentLoaded", async () => {
|
35
|
+
await initializeComponents();
|
36
36
|
initializeActions();
|
37
37
|
initializeInputs();
|
38
38
|
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { BlockQuote } from "./components/block-quote"
|
2
|
+
import { Box } from "./components/box"
|
3
|
+
import { Button } from "./components/button"
|
4
|
+
import { Checkbox } from "./components/checkbox"
|
5
|
+
import { Code } from "./components/code"
|
6
|
+
import { DateTimeField } from "./components/datetime-field"
|
7
|
+
import { Element } from "./components/element"
|
8
|
+
import { Embed } from "./components/embed"
|
9
|
+
import { Emphasis } from "./components/emphasis"
|
10
|
+
import { Form } from "./components/form"
|
11
|
+
import { Heading } from "./components/heading"
|
12
|
+
import { Image } from "./components/image"
|
13
|
+
import { Link } from "./components/link"
|
14
|
+
import { ListItem } from "./components/list-item"
|
15
|
+
import { List } from "./components/list"
|
16
|
+
import { OrderedList } from "./components/ordered-list"
|
17
|
+
import { Paragraph } from "./components/paragraph"
|
18
|
+
import { Quote } from "./components/quote"
|
19
|
+
import { RadioButton } from "./components/radio-button"
|
20
|
+
import { Select } from "./components/select"
|
21
|
+
import { Span } from "./components/span"
|
22
|
+
import { Component } from "./components/component"
|
23
|
+
import { TextField } from "./components/text-field"
|
24
|
+
import { Text } from "./components/text"
|
25
|
+
|
26
|
+
|
27
|
+
export {
|
28
|
+
Box, Component, Text, TextField, Button, DateTimeField, BlockQuote, Checkbox, Code, Element, Emphasis, Form, Heading, Image, Link, List, ListItem, OrderedList, Paragraph, Quote, RadioButton, Select, Span, Embed
|
29
|
+
};
|
@@ -23,4 +23,7 @@ import { Component } from "./components/component"
|
|
23
23
|
import { TextField } from "./components/text-field"
|
24
24
|
import { Text } from "./components/text"
|
25
25
|
|
26
|
-
|
26
|
+
|
27
|
+
export const Clapton = {
|
28
|
+
Box, Component, Text, TextField, Button, DateTimeField, BlockQuote, Checkbox, Code, Element, Emphasis, Form, Heading, Image, Link, List, ListItem, OrderedList, Paragraph, Quote, RadioButton, Select, Span, Embed
|
29
|
+
};
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import morphdom from "morphdom";
|
2
2
|
|
3
|
-
export const updateComponent = (component: HTMLElement, state: any, property: string, target: HTMLInputElement) => {
|
3
|
+
export const updateComponent = async (component: HTMLElement, state: any, property: string, target: HTMLInputElement) => {
|
4
4
|
state[property] = target.value;
|
5
|
-
component.
|
6
|
-
const
|
7
|
-
const ComponentClass =
|
5
|
+
const componentName = component.dataset.component as string;
|
6
|
+
const module = await import(`${componentName}`);
|
7
|
+
const ComponentClass = module[componentName] as any;
|
8
8
|
const instance = new ComponentClass(state, component.dataset.id);
|
9
9
|
morphdom(component, instance.render);
|
10
10
|
};
|
@@ -8,8 +8,8 @@ export const initializeInputs = () => {
|
|
8
8
|
const state = JSON.parse(component.getAttribute("data-state") || "{}");
|
9
9
|
if (!attribute || !component) return;
|
10
10
|
if (element.tagName === "INPUT") {
|
11
|
-
element.addEventListener("input", (event: Event) => {
|
12
|
-
updateComponent(component, state, attribute, event.target as HTMLInputElement);
|
11
|
+
element.addEventListener("input", async (event: Event) => {
|
12
|
+
await updateComponent(component, state, attribute, event.target as HTMLInputElement);
|
13
13
|
});
|
14
14
|
}
|
15
15
|
});
|
@@ -4,7 +4,7 @@ module Clapton
|
|
4
4
|
require "execjs"
|
5
5
|
|
6
6
|
def render_component(component, **kwargs)
|
7
|
-
js = File.read(File.join(__dir__, "..", "javascripts", "dist", "components.js"))
|
7
|
+
js = File.read(File.join(__dir__, "..", "javascripts", "dist", "components-for-test.js"))
|
8
8
|
Dir.glob(Rails.root.join("app", "components", "**", "*.rb")).each do |file|
|
9
9
|
js += Ruby2JS.convert(File.read(file), preset: true)
|
10
10
|
js += "\n"
|
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.15
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/clapton.rb
|
132
132
|
- lib/clapton/engine.rb
|
133
133
|
- lib/clapton/javascripts/dist/client.js
|
134
|
+
- lib/clapton/javascripts/dist/components-for-test.js
|
134
135
|
- lib/clapton/javascripts/dist/components.js
|
135
136
|
- lib/clapton/javascripts/node_modules/@adobe/css-tools/LICENSE
|
136
137
|
- lib/clapton/javascripts/node_modules/@adobe/css-tools/Readme.md
|
@@ -2168,6 +2169,51 @@ files:
|
|
2168
2169
|
- lib/clapton/javascripts/node_modules/dequal/lite/index.mjs
|
2169
2170
|
- lib/clapton/javascripts/node_modules/dequal/package.json
|
2170
2171
|
- lib/clapton/javascripts/node_modules/dequal/readme.md
|
2172
|
+
- lib/clapton/javascripts/node_modules/diff-dom/LICENSE.txt
|
2173
|
+
- lib/clapton/javascripts/node_modules/diff-dom/README.md
|
2174
|
+
- lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js
|
2175
|
+
- lib/clapton/javascripts/node_modules/diff-dom/browser/diffDOM.js.map
|
2176
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/TraceLogger.d.ts
|
2177
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/apply.d.ts
|
2178
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/fromVirtual.d.ts
|
2179
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/index.d.ts
|
2180
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/dom/undo.d.ts
|
2181
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/helpers.d.ts
|
2182
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/index.d.ts
|
2183
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/types.d.ts
|
2184
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/apply.d.ts
|
2185
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/diff.d.ts
|
2186
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromDOM.d.ts
|
2187
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/fromString.d.ts
|
2188
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/helpers.d.ts
|
2189
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/diffDOM/virtual/index.d.ts
|
2190
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/dts/index.d.ts
|
2191
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/index.d.ts
|
2192
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/index.js
|
2193
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/index.js.map
|
2194
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js
|
2195
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/index.min.js.map
|
2196
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/module.js
|
2197
|
+
- lib/clapton/javascripts/node_modules/diff-dom/dist/module.js.map
|
2198
|
+
- lib/clapton/javascripts/node_modules/diff-dom/index.html
|
2199
|
+
- lib/clapton/javascripts/node_modules/diff-dom/package.json
|
2200
|
+
- lib/clapton/javascripts/node_modules/diff-dom/rollup.config.mjs
|
2201
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/TraceLogger.ts
|
2202
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/apply.ts
|
2203
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/fromVirtual.ts
|
2204
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/index.ts
|
2205
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/dom/undo.ts
|
2206
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/helpers.ts
|
2207
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/index.ts
|
2208
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/types.ts
|
2209
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/apply.ts
|
2210
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/diff.ts
|
2211
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromDOM.ts
|
2212
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/fromString.ts
|
2213
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/helpers.ts
|
2214
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/diffDOM/virtual/index.ts
|
2215
|
+
- lib/clapton/javascripts/node_modules/diff-dom/src/index.ts
|
2216
|
+
- lib/clapton/javascripts/node_modules/diff-dom/tsconfig.json
|
2171
2217
|
- lib/clapton/javascripts/node_modules/dom-accessibility-api/LICENSE.md
|
2172
2218
|
- lib/clapton/javascripts/node_modules/dom-accessibility-api/README.md
|
2173
2219
|
- lib/clapton/javascripts/node_modules/dom-accessibility-api/dist/accessible-description.d.ts
|
@@ -6658,6 +6704,7 @@ files:
|
|
6658
6704
|
- lib/clapton/javascripts/src/actions/initialize-actions.ts
|
6659
6705
|
- lib/clapton/javascripts/src/channel/clapton-channel.js
|
6660
6706
|
- lib/clapton/javascripts/src/client.ts
|
6707
|
+
- lib/clapton/javascripts/src/components-for-test.ts
|
6661
6708
|
- lib/clapton/javascripts/src/components.ts
|
6662
6709
|
- lib/clapton/javascripts/src/components/block-quote.spec.ts
|
6663
6710
|
- lib/clapton/javascripts/src/components/block-quote.ts
|
@@ -6709,7 +6756,6 @@ files:
|
|
6709
6756
|
- lib/clapton/javascripts/src/components/text-field.ts
|
6710
6757
|
- lib/clapton/javascripts/src/components/text.spec.ts
|
6711
6758
|
- lib/clapton/javascripts/src/components/text.ts
|
6712
|
-
- lib/clapton/javascripts/src/dom/update-component.spec.ts
|
6713
6759
|
- lib/clapton/javascripts/src/dom/update-component.ts
|
6714
6760
|
- lib/clapton/javascripts/src/html/html-attributes.spec.ts
|
6715
6761
|
- lib/clapton/javascripts/src/html/html-attributes.ts
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import { updateComponent } from "./update-component";
|
2
|
-
import { describe, it, expect } from "vitest";
|
3
|
-
|
4
|
-
describe("updateComponent", () => {
|
5
|
-
it("updates the component", () => {
|
6
|
-
const component = document.createElement("div");
|
7
|
-
component.innerHTML = `<div data-component="TestComponent" data-state='{"testAttribute": "initial"}'></div>`;
|
8
|
-
|
9
|
-
const input = document.createElement("div");
|
10
|
-
input.innerHTML = `<input value="updated" data-attribute="testAttribute">`;
|
11
|
-
|
12
|
-
class TestComponent {
|
13
|
-
state: any;
|
14
|
-
constructor(state: any) {
|
15
|
-
this.state = state;
|
16
|
-
}
|
17
|
-
get render() {
|
18
|
-
return `<div>${this.state.testAttribute}</div>`;
|
19
|
-
}
|
20
|
-
};
|
21
|
-
(window as any).TestComponent = TestComponent;
|
22
|
-
|
23
|
-
updateComponent(
|
24
|
-
component.firstChild as HTMLElement,
|
25
|
-
JSON.parse(component.getAttribute("data-state") || "{}"),
|
26
|
-
"testAttribute",
|
27
|
-
input.firstChild as HTMLInputElement
|
28
|
-
);
|
29
|
-
|
30
|
-
expect(component.textContent).toBe("updated");
|
31
|
-
});
|
32
|
-
});
|