clapton 0.0.21 → 0.0.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27fa8b6f3ac907d41af32dc550fa4556dc127895ace2e296969b49b8dc8f887a
4
- data.tar.gz: 8b5099fd20fc5f804d792c48da12b694755b18e8d51a9f65442ad61e1b2a7f6d
3
+ metadata.gz: f5a917233f15421e530f894af3f7fa67b46b79c78d8568cd158566610f6c2db5
4
+ data.tar.gz: 2935aea66e3fc3e7442606c0fcf55ffcea56b61bb36864c4fc77101680cc29ea
5
5
  SHA512:
6
- metadata.gz: be4dabb30c708af3c0ce9b1cb0a20eb1b58d79924e2303c880b2d4b0a563eb304d906d456b105b24999baaaebb05053d618136de336c0b5b579581f07817a9b6
7
- data.tar.gz: ddd55a8d86a0c9f5666c7fb686ed137c442e8d377341279856eb140d39a2eb08fe5538f05aa3be29ae9448ce1aee6e64eb0d93187c6bf8a1f45b1f4bdf44f12b
6
+ metadata.gz: 458297f32dca2583bfb675fb74bba00b781bef37d825b9a76e9116cea3c3bf0f98b18d1d6867d62b67d47638335c2f99d0ef3885358281f5fad63245e53e6d2f
7
+ data.tar.gz: 586febac7acaf53ed42c0dadaa696c5e136bee87de707214343cf36104f2b56625f3aef3cfa4dfd71bd34c8108243813b26f8ea8f8fa7d7aea7ac2b686e9c25a
data/README.md CHANGED
@@ -349,6 +349,15 @@ module ApplicationCable
349
349
  end
350
350
  ```
351
351
 
352
+ ### Using with importmap-rails
353
+
354
+ Use `clapton_javascript_tag` instead of `javascript_importmap_tags`.
355
+
356
+ ```diff
357
+ - <%= javascript_importmap_tags %>
358
+ + <%= clapton_javascript_tag %>
359
+ ```
360
+
352
361
  ### Events
353
362
 
354
363
  #### clapton:render
@@ -1,11 +1,10 @@
1
1
  module Clapton
2
2
  module ClaptonHelper
3
3
 
4
- def clapton_javascript_tag
4
+ def clapton_javascript_tag(entry_point = "application", importmap: nil)
5
5
  all_components = Dir.glob(Rails.root.join("app", "components", "**", "*.rb"))
6
- tags = <<~HTML
7
- <script type="importmap">
8
- {
6
+ clapton_json = JSON.parse <<~JSON
7
+ {
9
8
  "imports": {
10
9
  "client": "/clapton/client.js",
11
10
  "components": "/clapton/components.js",
@@ -15,10 +14,25 @@ module Clapton
15
14
  end.join(",\n") }
16
15
  }
17
16
  }
18
- </script>
19
- <script type="module" src="/clapton/client.js"></script>
20
- HTML
21
- tags.html_safe
17
+ JSON
18
+ if defined?(javascript_importmap_tags)
19
+ importmap ||= Rails.application.importmap
20
+ json = { imports: JSON.parse(importmap.to_json(resolver: self))["imports"].merge(clapton_json["imports"]) }
21
+ safe_join [
22
+ javascript_inline_importmap_tag(json.to_json),
23
+ javascript_importmap_module_preload_tags(importmap, entry_point:),
24
+ javascript_import_module_tag(entry_point),
25
+ tag.script(type: "module", src: "/clapton/client.js"),
26
+ ], "\n"
27
+ else
28
+ html = <<~HTML
29
+ <script type="importmap">
30
+ #{clapton_json.to_json}
31
+ </script>
32
+ <script type="module" src="/clapton/client.js"></script>
33
+ HTML
34
+ html.html_safe
35
+ end
22
36
  end
23
37
 
24
38
  def clapton_tag
@@ -47,12 +47,12 @@ module Clapton
47
47
  js += "\n"
48
48
  js += "import { c } from 'c';"
49
49
  js += "\n"
50
- code.scan(/(\w+)Component\.new/).each do |match|
51
- js += "import { #{match[0]}Component } from '#{match[0]}Component';"
52
- js += "\n"
50
+ Dir.glob(Rails.root.join("app", "components", "**", "*.rb")).each do |f|
51
+ if File.basename(file, ".rb") != File.basename(f, ".rb")
52
+ js += "import { #{File.basename(f, ".rb").camelize} } from '#{File.basename(f, ".rb").camelize}';"
53
+ js += "\n"
54
+ end
53
55
  end
54
- code = code.gsub(/([^a-zA-Z0-9])c\.(\w+?)\(/, '\1@c.\2(')
55
- code = code.gsub(/([^a-zA-Z0-9])c\.(\w+?)(\.|$)/, '\1@c.\2()\3')
56
56
  js += Ruby2JS.convert(code, preset: true)
57
57
  js += "\n"
58
58
  js += "export { #{File.basename(file, ".rb").camelize} };"
@@ -1448,6 +1448,13 @@ document.addEventListener("DOMContentLoaded", async () => {
1448
1448
  const event = new Event('clapton:render');
1449
1449
  document.dispatchEvent(event);
1450
1450
  });
1451
+ document.addEventListener("turbo:render", async () => {
1452
+ await initializeComponents();
1453
+ initializeActions();
1454
+ initializeInputs();
1455
+ const event = new Event('clapton:render');
1456
+ document.dispatchEvent(event);
1457
+ });
1451
1458
  window.addEventListener('beforeunload', () => {
1452
1459
  sessionStorage.setItem('scrollPosition', window.scrollY.toString());
1453
1460
  });
@@ -0,0 +1,160 @@
1
+ import { Clapton } from "components"
2
+
3
+ const bq = (...props: any[]) => {
4
+ return new Clapton.BlockQuote(...props)
5
+ }
6
+
7
+ const box = (...props: any[]) => {
8
+ return new Clapton.Box(...props)
9
+ }
10
+
11
+ const b = (...props: any[]) => {
12
+ return new Clapton.Bold(...props)
13
+ }
14
+
15
+ const button = (...props: any[]) => {
16
+ return new Clapton.Button(...props)
17
+ }
18
+
19
+ const check = (...props: any[]) => {
20
+ return new Clapton.Checkbox(props[0], props[1], props[2])
21
+ }
22
+
23
+ const code = (...props: any[]) => {
24
+ return new Clapton.Code(...props)
25
+ }
26
+
27
+ const datetime = (...props: any[]) => {
28
+ return new Clapton.DateTimeField(props[0], props[1], props[2])
29
+ }
30
+
31
+ const el = (...props: any[]) => {
32
+ return new Clapton.Element(props[0], props[1])
33
+ }
34
+
35
+ const embed = (...props: any[]) => {
36
+ return new Clapton.Embed(props[0])
37
+ }
38
+
39
+ const em = (...props: any[]) => {
40
+ return new Clapton.Emphasis(...props)
41
+ }
42
+
43
+ const form = (...props: any[]) => {
44
+ return new Clapton.Form(...props)
45
+ }
46
+
47
+ const h = (...props: any[]) => {
48
+ return new Clapton.Heading(props[0], props[1])
49
+ }
50
+
51
+ const img = (...props: any[]) => {
52
+ return new Clapton.Image(props[0], props[1], props[2])
53
+ }
54
+
55
+ const a = (...props: any[]) => {
56
+ return new Clapton.Link(props[0], props[1])
57
+ }
58
+
59
+ const li = (...props: any[]) => {
60
+ return new Clapton.ListItem(...props)
61
+ }
62
+
63
+ const ul = (...props: any[]) => {
64
+ return new Clapton.List(...props)
65
+ }
66
+
67
+ const ol = (...props: any[]) => {
68
+ return new Clapton.OrderedList(...props)
69
+ }
70
+
71
+ const p = (...props: any[]) => {
72
+ return new Clapton.Paragraph(...props)
73
+ }
74
+
75
+ const q = (...props: any[]) => {
76
+ return new Clapton.Quote(...props)
77
+ }
78
+
79
+ const radio = (...props: any[]) => {
80
+ return new Clapton.RadioButton(props[0], props[1], props[2])
81
+ }
82
+
83
+ const select = (...props: any[]) => {
84
+ return new Clapton.Select(props[0], props[1], props[2])
85
+ }
86
+
87
+ const span = (...props: any[]) => {
88
+ return new Clapton.Span(...props)
89
+ }
90
+
91
+ const textarea = (...props: any[]) => {
92
+ return new Clapton.TextArea(props[0], props[1], props[2])
93
+ }
94
+
95
+ const input = (...props: any[]) => {
96
+ return new Clapton.TextField(props[0], props[1], props[2])
97
+ }
98
+
99
+ const text = (...props: any[]) => {
100
+ return new Clapton.Text(props[0])
101
+ }
102
+
103
+ const c = (name: string, ...props: any[]) => {
104
+ switch (name) {
105
+ case "bq":
106
+ return bq(...props)
107
+ case "box":
108
+ return box(...props)
109
+ case "b":
110
+ return b(...props)
111
+ case "button":
112
+ return button(...props)
113
+ case "check":
114
+ return check(...props)
115
+ case "code":
116
+ return code(...props)
117
+ case "datetime":
118
+ return datetime(...props)
119
+ case "el":
120
+ return el(...props)
121
+ case "embed":
122
+ return embed(...props)
123
+ case "em":
124
+ return em(...props)
125
+ case "form":
126
+ return form(...props)
127
+ case "h":
128
+ return h(...props)
129
+ case "img":
130
+ return img(...props)
131
+ case "a":
132
+ return a(...props)
133
+ case "li":
134
+ return li(...props)
135
+ case "ul":
136
+ return ul(...props)
137
+ case "ol":
138
+ return ol(...props)
139
+ case "p":
140
+ return p(...props)
141
+ case "q":
142
+ return q(...props)
143
+ case "radio":
144
+ return radio(...props)
145
+ case "select":
146
+ return select(...props)
147
+ case "span":
148
+ return span(...props)
149
+ case "textarea":
150
+ return textarea(...props)
151
+ case "input":
152
+ return input(...props)
153
+ case "text":
154
+ return text(...props)
155
+ default:
156
+ return new Clapton.Component(...props)
157
+ }
158
+ }
159
+
160
+ export { c }
@@ -1,160 +1,3 @@
1
- import { Clapton } from "components"
2
-
3
- const bq = (...props: any[]) => {
4
- return new Clapton.BlockQuote(...props)
5
- }
6
-
7
- const box = (...props: any[]) => {
8
- return new Clapton.Box(...props)
9
- }
10
-
11
- const b = (...props: any[]) => {
12
- return new Clapton.Bold(...props)
13
- }
14
-
15
- const button = (...props: any[]) => {
16
- return new Clapton.Button(...props)
17
- }
18
-
19
- const check = (...props: any[]) => {
20
- return new Clapton.Checkbox(props[0], props[1], props[2])
21
- }
22
-
23
- const code = (...props: any[]) => {
24
- return new Clapton.Code(...props)
25
- }
26
-
27
- const datetime = (...props: any[]) => {
28
- return new Clapton.DateTimeField(props[0], props[1], props[2])
29
- }
30
-
31
- const el = (...props: any[]) => {
32
- return new Clapton.Element(props[0], props[1])
33
- }
34
-
35
- const embed = (...props: any[]) => {
36
- return new Clapton.Embed(props[0])
37
- }
38
-
39
- const em = (...props: any[]) => {
40
- return new Clapton.Emphasis(...props)
41
- }
42
-
43
- const form = (...props: any[]) => {
44
- return new Clapton.Form(...props)
45
- }
46
-
47
- const h = (...props: any[]) => {
48
- return new Clapton.Heading(props[0], props[1])
49
- }
50
-
51
- const img = (...props: any[]) => {
52
- return new Clapton.Image(props[0], props[1], props[2])
53
- }
54
-
55
- const a = (...props: any[]) => {
56
- return new Clapton.Link(props[0], props[1])
57
- }
58
-
59
- const li = (...props: any[]) => {
60
- return new Clapton.ListItem(...props)
61
- }
62
-
63
- const ul = (...props: any[]) => {
64
- return new Clapton.List(...props)
65
- }
66
-
67
- const ol = (...props: any[]) => {
68
- return new Clapton.OrderedList(...props)
69
- }
70
-
71
- const p = (...props: any[]) => {
72
- return new Clapton.Paragraph(...props)
73
- }
74
-
75
- const q = (...props: any[]) => {
76
- return new Clapton.Quote(...props)
77
- }
78
-
79
- const radio = (...props: any[]) => {
80
- return new Clapton.RadioButton(props[0], props[1], props[2])
81
- }
82
-
83
- const select = (...props: any[]) => {
84
- return new Clapton.Select(props[0], props[1], props[2])
85
- }
86
-
87
- const span = (...props: any[]) => {
88
- return new Clapton.Span(...props)
89
- }
90
-
91
- const textarea = (...props: any[]) => {
92
- return new Clapton.TextArea(props[0], props[1], props[2])
93
- }
94
-
95
- const input = (...props: any[]) => {
96
- return new Clapton.TextField(props[0], props[1], props[2])
97
- }
98
-
99
- const text = (...props: any[]) => {
100
- return new Clapton.Text(props[0])
101
- }
102
-
103
- const c = (name: string, ...props: any[]) => {
104
- switch (name) {
105
- case "bq":
106
- return bq(...props)
107
- case "box":
108
- return box(...props)
109
- case "b":
110
- return b(...props)
111
- case "button":
112
- return button(...props)
113
- case "check":
114
- return check(...props)
115
- case "code":
116
- return code(...props)
117
- case "datetime":
118
- return datetime(...props)
119
- case "el":
120
- return el(...props)
121
- case "embed":
122
- return embed(...props)
123
- case "em":
124
- return em(...props)
125
- case "form":
126
- return form(...props)
127
- case "h":
128
- return h(...props)
129
- case "img":
130
- return img(...props)
131
- case "a":
132
- return a(...props)
133
- case "li":
134
- return li(...props)
135
- case "ul":
136
- return ul(...props)
137
- case "ol":
138
- return ol(...props)
139
- case "p":
140
- return p(...props)
141
- case "q":
142
- return q(...props)
143
- case "radio":
144
- return radio(...props)
145
- case "select":
146
- return select(...props)
147
- case "span":
148
- return span(...props)
149
- case "textarea":
150
- return textarea(...props)
151
- case "input":
152
- return input(...props)
153
- case "text":
154
- return text(...props)
155
- default:
156
- return new Clapton.Component(...props)
157
- }
158
- }
1
+ import { c } from "./c-base"
159
2
 
160
3
  export default c
@@ -1,160 +1,3 @@
1
- import { Clapton } from "components"
2
-
3
- const bq = (...props: any[]) => {
4
- return new Clapton.BlockQuote(...props)
5
- }
6
-
7
- const box = (...props: any[]) => {
8
- return new Clapton.Box(...props)
9
- }
10
-
11
- const b = (...props: any[]) => {
12
- return new Clapton.Bold(...props)
13
- }
14
-
15
- const button = (...props: any[]) => {
16
- return new Clapton.Button(...props)
17
- }
18
-
19
- const check = (...props: any[]) => {
20
- return new Clapton.Checkbox(props[0], props[1], props[2])
21
- }
22
-
23
- const code = (...props: any[]) => {
24
- return new Clapton.Code(...props)
25
- }
26
-
27
- const datetime = (...props: any[]) => {
28
- return new Clapton.DateTimeField(props[0], props[1], props[2])
29
- }
30
-
31
- const el = (...props: any[]) => {
32
- return new Clapton.Element(props[0], props[1])
33
- }
34
-
35
- const embed = (...props: any[]) => {
36
- return new Clapton.Embed(props[0])
37
- }
38
-
39
- const em = (...props: any[]) => {
40
- return new Clapton.Emphasis(...props)
41
- }
42
-
43
- const form = (...props: any[]) => {
44
- return new Clapton.Form(...props)
45
- }
46
-
47
- const h = (...props: any[]) => {
48
- return new Clapton.Heading(props[0], props[1])
49
- }
50
-
51
- const img = (...props: any[]) => {
52
- return new Clapton.Image(props[0], props[1], props[2])
53
- }
54
-
55
- const a = (...props: any[]) => {
56
- return new Clapton.Link(props[0], props[1])
57
- }
58
-
59
- const li = (...props: any[]) => {
60
- return new Clapton.ListItem(...props)
61
- }
62
-
63
- const ul = (...props: any[]) => {
64
- return new Clapton.List(...props)
65
- }
66
-
67
- const ol = (...props: any[]) => {
68
- return new Clapton.OrderedList(...props)
69
- }
70
-
71
- const p = (...props: any[]) => {
72
- return new Clapton.Paragraph(...props)
73
- }
74
-
75
- const q = (...props: any[]) => {
76
- return new Clapton.Quote(...props)
77
- }
78
-
79
- const radio = (...props: any[]) => {
80
- return new Clapton.RadioButton(props[0], props[1], props[2])
81
- }
82
-
83
- const select = (...props: any[]) => {
84
- return new Clapton.Select(props[0], props[1], props[2])
85
- }
86
-
87
- const span = (...props: any[]) => {
88
- return new Clapton.Span(...props)
89
- }
90
-
91
- const textarea = (...props: any[]) => {
92
- return new Clapton.TextArea(props[0], props[1], props[2])
93
- }
94
-
95
- const input = (...props: any[]) => {
96
- return new Clapton.TextField(props[0], props[1], props[2])
97
- }
98
-
99
- const text = (...props: any[]) => {
100
- return new Clapton.Text(props[0])
101
- }
102
-
103
- const c = (name: string, ...props: any[]) => {
104
- switch (name) {
105
- case "bq":
106
- return bq(...props)
107
- case "box":
108
- return box(...props)
109
- case "b":
110
- return b(...props)
111
- case "button":
112
- return button(...props)
113
- case "check":
114
- return check(...props)
115
- case "code":
116
- return code(...props)
117
- case "datetime":
118
- return datetime(...props)
119
- case "el":
120
- return el(...props)
121
- case "embed":
122
- return embed(...props)
123
- case "em":
124
- return em(...props)
125
- case "form":
126
- return form(...props)
127
- case "h":
128
- return h(...props)
129
- case "img":
130
- return img(...props)
131
- case "a":
132
- return a(...props)
133
- case "li":
134
- return li(...props)
135
- case "ul":
136
- return ul(...props)
137
- case "ol":
138
- return ol(...props)
139
- case "p":
140
- return p(...props)
141
- case "q":
142
- return q(...props)
143
- case "radio":
144
- return radio(...props)
145
- case "select":
146
- return select(...props)
147
- case "span":
148
- return span(...props)
149
- case "textarea":
150
- return textarea(...props)
151
- case "input":
152
- return input(...props)
153
- case "text":
154
- return text(...props)
155
- default:
156
- return new Clapton.Component(...props)
157
- }
158
- }
1
+ import { c } from "./c-base"
159
2
 
160
3
  export { c }
@@ -46,6 +46,14 @@ document.addEventListener("DOMContentLoaded", async () => {
46
46
  document.dispatchEvent(event);
47
47
  });
48
48
 
49
+ document.addEventListener("turbo:render", async () => {
50
+ await initializeComponents();
51
+ initializeActions();
52
+ initializeInputs();
53
+ const event = new Event('clapton:render');
54
+ document.dispatchEvent(event);
55
+ });
56
+
49
57
  window.addEventListener('beforeunload', () => {
50
58
  sessionStorage.setItem('scrollPosition', window.scrollY.toString());
51
59
  });
@@ -1,3 +1,3 @@
1
1
  module Clapton
2
- VERSION = '0.0.21'
2
+ VERSION = '0.0.23'
3
3
  end
@@ -1,6 +1,10 @@
1
1
  namespace :clapton do
2
2
  task compile: :environment do
3
+ FileUtils.mkdir_p(Rails.root.join("public", "clapton")) unless Rails.root.join("public", "clapton").exist?
4
+ File.write(Rails.root.join("public", "clapton", "components.js"), File.read(File.join(__dir__, "..", "clapton", "javascripts", "dist", "components.js")))
5
+ File.write(Rails.root.join("public", "clapton", "client.js"), File.read(File.join(__dir__, "..", "clapton", "javascripts", "dist", "client.js")))
6
+ File.write(Rails.root.join("public", "clapton", "c.js"), File.read(File.join(__dir__, "..", "clapton", "javascripts", "dist", "c.js")))
7
+
3
8
  Clapton::Engine.compile_components
4
- puts "Clapton components compiled"
5
9
  end
6
10
  end
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.21
4
+ version: 0.0.23
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-16 00:00:00.000000000 Z
11
+ date: 2024-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -6706,6 +6706,7 @@ files:
6706
6706
  - lib/clapton/javascripts/src/actions/handle-action.spec.ts
6707
6707
  - lib/clapton/javascripts/src/actions/handle-action.ts
6708
6708
  - lib/clapton/javascripts/src/actions/initialize-actions.ts
6709
+ - lib/clapton/javascripts/src/c-base.ts
6709
6710
  - lib/clapton/javascripts/src/c-for-test.ts
6710
6711
  - lib/clapton/javascripts/src/c.ts
6711
6712
  - lib/clapton/javascripts/src/channel/clapton-channel.js