hokusai-zero 0.1.5 → 0.1.6
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 +4 -4
- data/ext/extconf.rb +16 -13
- data/hokusai.gemspec +1 -1
- data/ui/examples/counter.rb +36 -28
- data/ui/examples/forum.rb +25 -24
- data/ui/examples/spreadsheet/csv.rb +3 -1
- data/ui/examples/spreadsheet.rb +4 -2
- data/ui/src/hokusai/backends/raylib.rb +4 -0
- data/ui/src/hokusai/block.rb +29 -4
- data/ui/src/hokusai/blocks/cursor.rb +1 -1
- data/ui/src/hokusai/blocks/input.rb +1 -1
- data/ui/src/hokusai/blocks/text.rb +6 -4
- data/ui/src/hokusai/font.rb +1 -1
- data/ui/src/hokusai/mounting/loop_entry.rb +3 -3
- data/ui/src/hokusai/mounting/mount_entry.rb +7 -17
- data/ui/src/hokusai/node.rb +0 -9
- data/ui/src/hokusai/node_mounter.rb +3 -3
- data/ui/src/hokusai/util/clamping_iterator.rb +6 -4
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f58887af318a4986f8526a3868146766c62dbc6fa72e1a6a6f1a52cf1b4623e2
|
|
4
|
+
data.tar.gz: 76df215d1555e0930643485c626aa7d1ab8511d4430095f10f79b3ceff041c50
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53552edadd8e5d20f770e6b9331963296bc406c629084fb781c4a5307cfca514c71a23d89db38a48abc87794ef6950738b6a19315373a68dcf8e751ed32030f5
|
|
7
|
+
data.tar.gz: d2172018d5129c5be0078ab04dd4d611ddb9bbca61296d8786fbb14c1f57c21fc28bb1de55c3ed05e2f6afc2fb9fd043704417f0c1c18f62bd61528fff8af04e
|
data/ext/extconf.rb
CHANGED
|
@@ -3,16 +3,19 @@ require "mini_portile2"
|
|
|
3
3
|
|
|
4
4
|
if MiniPortile.darwin?
|
|
5
5
|
suffix = "dylib"
|
|
6
|
+
ext = "zip"
|
|
6
7
|
elsif MiniPortile.linux?
|
|
7
8
|
suffix = "so"
|
|
9
|
+
ext = "tar.gz"
|
|
8
10
|
elsif MiniPortile.windows?
|
|
9
11
|
suffix = "dll"
|
|
12
|
+
ext = "zip"
|
|
10
13
|
else
|
|
11
14
|
raise "Currently only supporting darwin and linux"
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
tree_sitter = MiniPortile.new("libtree-sitter", "master", make_command: "make")
|
|
15
|
-
tree_sitter.files = ["https://github.com/tree-sitter/tree-sitter/archive/refs/heads/master
|
|
18
|
+
tree_sitter.files = ["https://github.com/tree-sitter/tree-sitter/archive/refs/heads/master.#{ext}"]
|
|
16
19
|
tree_sitter.tap do |t|
|
|
17
20
|
if t.source_directory
|
|
18
21
|
t.prepare_build_directory
|
|
@@ -25,7 +28,7 @@ tree_sitter.tap do |t|
|
|
|
25
28
|
def t.install
|
|
26
29
|
return if installed?
|
|
27
30
|
|
|
28
|
-
execute('install', %Q(#{make_cmd} all install CC=gcc AR=ar), { env: { "PREFIX" => File.expand_path(port_path) }})
|
|
31
|
+
execute('install', %Q(#{make_cmd} all install CC=gcc AR=ar PREFIX=#{File.expand_path(port_path)}), { env: { "PREFIX" => File.expand_path(port_path) }})
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
t.install
|
|
@@ -34,7 +37,7 @@ end
|
|
|
34
37
|
tree_sitter.activate
|
|
35
38
|
|
|
36
39
|
md4c = MiniPortileCMake.new("md4c", "0.5.2")
|
|
37
|
-
md4c.files = ["https://github.com/mity/md4c/archive/refs/tags/release-0.5.2
|
|
40
|
+
md4c.files = ["https://github.com/mity/md4c/archive/refs/tags/release-0.5.2.#{ext}"]
|
|
38
41
|
|
|
39
42
|
def md4c.cmake_compile_flags
|
|
40
43
|
[*super, "-DBUILD_SHARED_LIBS=OFF"]
|
|
@@ -48,23 +51,23 @@ cwd = "#{__dir__}"
|
|
|
48
51
|
|
|
49
52
|
files = %w[ast/src/core/hml.c ast/src/core/ast.c ast/rc/core/style.c ast/src/core/input.c ast/src/core/component.c ast/src/core/util.c ast/src/core/text.c grammar/src/parser.c grammar/src/scanner.c ast/include/hashmap.c]
|
|
50
53
|
objects = %w[hml.o ast.o style.o input.o component.o util.o text.o parser.o scanner.o hashmap.o]
|
|
51
|
-
libraries = ["#{tree_sitter.path}/lib/libtree-sitter.a", "#{md4c.path}/lib/libmd4c.a"]
|
|
52
|
-
|
|
54
|
+
libraries = [File.expand_path("#{tree_sitter.path}/lib/libtree-sitter.a"), File.expand_path("#{md4c.path}/lib/libmd4c.a")]
|
|
55
|
+
src_files = ["#{tree_sitter.path}/lib/libtree-sitter.a", "#{md4c.path}/lib/libmd4c.a", "#{pre}/ast/src/core/hml.c", "#{pre}/ast/src/core/ast.c", "#{pre}/ast/src/core/style.c", "#{pre}/ast/src/core/input.c", "#{pre}/ast/src/core/component.c", "#{pre}/ast/src/core/util.c", "#{pre}/ast/src/core/text.c", "#{pre}/grammar/src/parser.c", "#{pre}/grammar/src/scanner.c", "#{pre}/ast/include/hashmap.c"]
|
|
53
56
|
if MiniPortile.windows?
|
|
54
57
|
cflags = "-shared -Wall -Wl,--export-all-symbols -Wl,--enable-auto-import"
|
|
55
58
|
mkdir = "mkdir #{pre}\\vendor\\lib"
|
|
56
59
|
else
|
|
57
|
-
cflags = "-shared -Wall"
|
|
60
|
+
cflags = "-fPIC -shared -Wall"
|
|
58
61
|
mkdir = "mkdir -p #{pre}/vendor/lib"
|
|
59
62
|
end
|
|
60
63
|
|
|
61
64
|
File.open("Makefile", "w") do |io|
|
|
62
65
|
io << <<~EOF
|
|
63
|
-
src_files = #{files.map {|file| "#{pre}/#{file}"}.join(" ")}
|
|
64
|
-
object_files = #{objects.map {|file| "#{cwd}/#{file}"}.join(" ")}
|
|
66
|
+
src_files = #{files.map {|file| File.expand_path("#{pre}/#{file}")}.join(" ")}
|
|
67
|
+
object_files = #{objects.map {|file| File.expand_path("#{cwd}/#{file}")}.join(" ")}
|
|
65
68
|
libraries = #{libraries.join(" ")}
|
|
66
|
-
src_files = #{
|
|
67
|
-
includes = -I#{pre}/ast/include -I#{pre}/ast/src -I#{pre}/grammar/src -I#{tree_sitter.path}/include -I#{md4c.path}/include
|
|
69
|
+
src_files = #{src_files.map { |file| File.expand_path(file)}.join(" ")}
|
|
70
|
+
includes = -I#{File.expand_path("#{pre}/ast/include")} -I#{File.expand_path("#{pre}/ast/src")} -I#{File.expand_path("#{pre}/grammar/src")} -I#{File.expand_path("#{tree_sitter.path}/include")} -I#{File.expand_path("#{md4c.path}/include")}
|
|
68
71
|
all: clean hokusai
|
|
69
72
|
|
|
70
73
|
.PHONY: hokuasi
|
|
@@ -75,10 +78,10 @@ File.open("Makefile", "w") do |io|
|
|
|
75
78
|
hokusai:
|
|
76
79
|
#{"\t"}#{mkdir}
|
|
77
80
|
#{"\t"}gcc -c $(includes) $(src_files) $(libraries)
|
|
78
|
-
#{"\t"}gcc #{cflags} $(includes) -o #{pre}/vendor/lib/libhokusai.#{suffix} $(object_files) $(libraries)
|
|
81
|
+
#{"\t"}gcc #{cflags} $(includes) -o #{File.expand_path("#{pre}/vendor/lib/libhokusai.#{suffix}")} $(object_files) $(libraries)
|
|
79
82
|
|
|
80
83
|
clean:
|
|
81
|
-
#{"\t"}rm -f vendor/lib/libhokusai.*
|
|
82
|
-
#{"\t"}rm -f vendor/lib/libmd4c.*
|
|
84
|
+
#{"\t"}rm -f #{File.expand_path("vendor/lib/libhokusai.*")}
|
|
85
|
+
#{"\t"}rm -f #{File.expand_path("vendor/lib/libmd4c.*")}
|
|
83
86
|
EOF
|
|
84
87
|
end
|
data/hokusai.gemspec
CHANGED
data/ui/examples/counter.rb
CHANGED
|
@@ -33,33 +33,38 @@ module Demos
|
|
|
33
33
|
control_padding: 5;
|
|
34
34
|
control_rounding: 5;
|
|
35
35
|
}
|
|
36
|
+
modalContent {
|
|
37
|
+
width: 300.0;
|
|
38
|
+
height: 300.0;
|
|
39
|
+
background: rgb(255, 255, 255);
|
|
40
|
+
}
|
|
36
41
|
EOF
|
|
37
42
|
|
|
38
43
|
template <<-EOF
|
|
39
44
|
[template]
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
vblock
|
|
46
|
+
hblock
|
|
47
|
+
label#count {
|
|
48
|
+
:content="count"
|
|
49
|
+
size="130"
|
|
50
|
+
:color="count_color"
|
|
51
|
+
}
|
|
52
|
+
modal { :active="over_20" @close="close_modal" }
|
|
53
|
+
vblock { ...modalContent }
|
|
54
|
+
text { content="okay" }
|
|
55
|
+
hblock
|
|
56
|
+
vblock#add { ...additionStyles }
|
|
57
|
+
label {
|
|
58
|
+
content="Add"
|
|
59
|
+
@click="increment"
|
|
60
|
+
...additionLabel
|
|
61
|
+
}
|
|
62
|
+
vblock#subtract { ...subtractStyles }
|
|
63
|
+
label {
|
|
64
|
+
content="Subtract"
|
|
65
|
+
@click="decrement"
|
|
66
|
+
...subtractLabel
|
|
47
67
|
}
|
|
48
|
-
hblock
|
|
49
|
-
vblock#add { ...additionStyles }
|
|
50
|
-
label {
|
|
51
|
-
content="Add"
|
|
52
|
-
@click="increment"
|
|
53
|
-
...additionLabel
|
|
54
|
-
}
|
|
55
|
-
vblock#subtract { ...subtractStyles }
|
|
56
|
-
label {
|
|
57
|
-
content="Subtract"
|
|
58
|
-
@click="decrement"
|
|
59
|
-
...subtractLabel
|
|
60
|
-
}
|
|
61
|
-
[if="count_positive"]
|
|
62
|
-
scrollbar { ...scrollbar }
|
|
63
68
|
EOF
|
|
64
69
|
|
|
65
70
|
uses(
|
|
@@ -67,21 +72,23 @@ module Demos
|
|
|
67
72
|
hblock: Hokusai::Blocks::Hblock,
|
|
68
73
|
label: Hokusai::Blocks::Label,
|
|
69
74
|
scrollbar: Hokusai::Blocks::Scrollbar,
|
|
70
|
-
image: Hokusai::Blocks::Image
|
|
75
|
+
image: Hokusai::Blocks::Image,
|
|
76
|
+
modal: Hokusai::Blocks::Modal,
|
|
77
|
+
text: Hokusai::Blocks::Text
|
|
71
78
|
)
|
|
72
79
|
|
|
73
|
-
attr_accessor :count, :keys
|
|
80
|
+
attr_accessor :count, :keys, :modal_open
|
|
74
81
|
|
|
75
82
|
def count_positive
|
|
76
83
|
count > 0
|
|
77
84
|
end
|
|
78
85
|
|
|
79
|
-
def
|
|
80
|
-
|
|
86
|
+
def over_20
|
|
87
|
+
count > 20
|
|
81
88
|
end
|
|
82
89
|
|
|
83
|
-
def
|
|
84
|
-
|
|
90
|
+
def close_modal
|
|
91
|
+
self.count = 0
|
|
85
92
|
end
|
|
86
93
|
|
|
87
94
|
def increment(event)
|
|
@@ -99,6 +106,7 @@ module Demos
|
|
|
99
106
|
def initialize(**args)
|
|
100
107
|
@count = 0
|
|
101
108
|
@keys = ""
|
|
109
|
+
@modal_open = false
|
|
102
110
|
super(**args)
|
|
103
111
|
end
|
|
104
112
|
end
|
data/ui/examples/forum.rb
CHANGED
|
@@ -70,29 +70,29 @@ module Demos
|
|
|
70
70
|
label {
|
|
71
71
|
...appTitle
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
hblock { :
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
post
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
selectable
|
|
74
|
+
panel#app { ...panelStyle }
|
|
75
|
+
vblock { :height="50.0" }
|
|
76
|
+
hblock { :height="forum_height" }
|
|
77
|
+
hblock { :width="margin_width" }
|
|
78
|
+
vblock { :width="panel_width" }
|
|
79
|
+
[for="post in posts"]
|
|
80
|
+
post {
|
|
81
|
+
@height_updated="update_forum_height"
|
|
82
|
+
:width="panel_width"
|
|
83
|
+
:index="index"
|
|
84
|
+
:key="index"
|
|
85
|
+
:post="post"
|
|
86
|
+
}
|
|
87
|
+
vblock.recents
|
|
88
|
+
hblock.header { width="100" }
|
|
89
|
+
image { ...ernestImage }
|
|
90
|
+
vblock { width="20" }
|
|
91
|
+
vblock { width="300" }
|
|
92
|
+
text { ...recentsLabel }
|
|
93
|
+
music { height="50" }
|
|
94
|
+
[for="item in files"]
|
|
95
|
+
file { height="30" :item="item" :key="index" :index="index" }
|
|
96
96
|
EOF
|
|
97
97
|
|
|
98
98
|
uses(
|
|
@@ -106,7 +106,8 @@ module Demos
|
|
|
106
106
|
text: Hokusai::Blocks::Text,
|
|
107
107
|
label: Hokusai::Blocks::Label,
|
|
108
108
|
titlebar: Hokusai::Blocks::Titlebar::OSX,
|
|
109
|
-
image: Hokusai::Blocks::Image
|
|
109
|
+
image: Hokusai::Blocks::Image,
|
|
110
|
+
selectable: Hokusai::Blocks::Selectable
|
|
110
111
|
)
|
|
111
112
|
|
|
112
113
|
def update_forum_height(height, index)
|
|
@@ -12,6 +12,7 @@ module Demos
|
|
|
12
12
|
padding: padding(5.0, 5.0, 5.0, 5.0);
|
|
13
13
|
size: 20;
|
|
14
14
|
text_color: rgb(244, 244, 244);
|
|
15
|
+
text_selection_color: rgb(74, 74, 95);
|
|
15
16
|
}
|
|
16
17
|
EOF
|
|
17
18
|
|
|
@@ -181,7 +182,8 @@ module Demos
|
|
|
181
182
|
hblock: Hokusai::Blocks::Hblock,
|
|
182
183
|
panel: Hokusai::Blocks::Panel,
|
|
183
184
|
row: Spreadsheet::Row,
|
|
184
|
-
label: Hokusai::Blocks::Label
|
|
185
|
+
label: Hokusai::Blocks::Label,
|
|
186
|
+
selectable: Hokusai::Blocks::Selectable
|
|
185
187
|
)
|
|
186
188
|
|
|
187
189
|
computed! :csv
|
data/ui/examples/spreadsheet.rb
CHANGED
|
@@ -45,7 +45,8 @@ module Demos
|
|
|
45
45
|
label { ...appTitle size="14" content="somecsv.csv" }
|
|
46
46
|
label { ...appTitle size="14" :content="status" }
|
|
47
47
|
[if="has_spreadsheet"]
|
|
48
|
-
|
|
48
|
+
selectable
|
|
49
|
+
csv { @modified="set_status" :csv="spreadsheet" @keypress="handle_keypress" }
|
|
49
50
|
EOF
|
|
50
51
|
|
|
51
52
|
uses(
|
|
@@ -56,7 +57,8 @@ module Demos
|
|
|
56
57
|
label: Hokusai::Blocks::Label,
|
|
57
58
|
titlebar: Hokusai::Blocks::Titlebar::OSX,
|
|
58
59
|
image: Hokusai::Blocks::Image,
|
|
59
|
-
csv: Spreadsheet::CSV
|
|
60
|
+
csv: Spreadsheet::CSV,
|
|
61
|
+
selectable: Hokusai::Blocks::Selectable
|
|
60
62
|
)
|
|
61
63
|
|
|
62
64
|
attr_reader :spreadsheet
|
data/ui/src/hokusai/block.rb
CHANGED
|
@@ -30,6 +30,10 @@ module Hokusai
|
|
|
30
30
|
@provides ||= {}
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def self.injectables
|
|
34
|
+
@injectables ||= []
|
|
35
|
+
end
|
|
36
|
+
|
|
33
37
|
# Sets the template for this block
|
|
34
38
|
#
|
|
35
39
|
# @param [String] template to set
|
|
@@ -118,16 +122,18 @@ module Hokusai
|
|
|
118
122
|
end
|
|
119
123
|
|
|
120
124
|
def self.inject(name, aliased = name)
|
|
125
|
+
injectables << name
|
|
126
|
+
|
|
121
127
|
define_method(aliased) do
|
|
122
|
-
|
|
123
|
-
provider.call
|
|
124
|
-
end
|
|
128
|
+
@injections[name]&.call
|
|
125
129
|
end
|
|
126
130
|
end
|
|
127
131
|
|
|
128
132
|
def self.inject!(name, aliased)
|
|
133
|
+
injectables << name
|
|
134
|
+
|
|
129
135
|
define_method(aliased) do
|
|
130
|
-
if provider =
|
|
136
|
+
if provider = @injections[name]
|
|
131
137
|
return provider.call
|
|
132
138
|
end
|
|
133
139
|
|
|
@@ -147,6 +153,25 @@ module Hokusai
|
|
|
147
153
|
raise Hokusai::Error.new("Must supply node argument to #{self.class}.new") unless args[:node]
|
|
148
154
|
|
|
149
155
|
@node = args[:node]
|
|
156
|
+
@injections = {}
|
|
157
|
+
|
|
158
|
+
self.class.injectables.each do |name|
|
|
159
|
+
if value = args[:providers][name]
|
|
160
|
+
@injections[name] = value
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def providers
|
|
166
|
+
self.class.provides.map do |k, v|
|
|
167
|
+
if v.is_a?(Symbol)
|
|
168
|
+
[k, -> { public_send(v) }]
|
|
169
|
+
elsif v.is_a?(Proc)
|
|
170
|
+
[k, v]
|
|
171
|
+
else
|
|
172
|
+
[k, -> { v }]
|
|
173
|
+
end
|
|
174
|
+
end.to_h
|
|
150
175
|
end
|
|
151
176
|
|
|
152
177
|
def children?
|
|
@@ -9,7 +9,7 @@ class Hokusai::Blocks::Cursor < Hokusai::Block
|
|
|
9
9
|
computed :x, default: 0.0
|
|
10
10
|
computed :y, default: 0.0
|
|
11
11
|
computed :show, default: false
|
|
12
|
-
computed :speed, default: 0.
|
|
12
|
+
computed :speed, default: 0.5
|
|
13
13
|
computed :cursor_width, default: 2.0
|
|
14
14
|
computed :cursor_height, default: 0.0
|
|
15
15
|
computed :color, default: DEFAULT_COLOR, convert: Hokusai::Color
|
|
@@ -195,7 +195,7 @@ class Hokusai::Blocks::Input < Hokusai::Block
|
|
|
195
195
|
flush
|
|
196
196
|
|
|
197
197
|
if table.pieces.size > 10
|
|
198
|
-
self.table = Util::PieceTable.new(table.to_s)
|
|
198
|
+
self.table = ::Hokusai::Util::PieceTable.new(table.to_s)
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
self.start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
@@ -69,7 +69,7 @@ class Hokusai::Blocks::Text < Hokusai::Block
|
|
|
69
69
|
iterator.on_draw do |text, x, y, group|
|
|
70
70
|
if selector = selection
|
|
71
71
|
if cursor_offset&.zero? && !selector.started
|
|
72
|
-
selector.cursor = [x, y + offset_y, 0.0, size.to_f]
|
|
72
|
+
# selector.cursor = [x, y + offset_y, 0.0, size.to_f]
|
|
73
73
|
|
|
74
74
|
self.last_cursor_offset = cursor_offset
|
|
75
75
|
end
|
|
@@ -113,6 +113,8 @@ class Hokusai::Blocks::Text < Hokusai::Block
|
|
|
113
113
|
system("open #{group.link}")
|
|
114
114
|
when /linux/
|
|
115
115
|
system("xdg-open #{group.link}")
|
|
116
|
+
when /msys|mingw/
|
|
117
|
+
system("Start-Process \"#{group.link}\"")
|
|
116
118
|
end
|
|
117
119
|
|
|
118
120
|
self.click_position = nil
|
|
@@ -126,9 +128,9 @@ class Hokusai::Blocks::Text < Hokusai::Block
|
|
|
126
128
|
end
|
|
127
129
|
|
|
128
130
|
iterator.on_draw_selection do |x, y, width, height|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
commands.rect(x, y, width, height) do |command|
|
|
132
|
+
command.color = selection_color
|
|
133
|
+
end
|
|
132
134
|
end
|
|
133
135
|
|
|
134
136
|
iterator.on_selection_change do |start, stop|
|
data/ui/src/hokusai/font.rb
CHANGED
|
@@ -224,7 +224,7 @@ module Hokusai
|
|
|
224
224
|
end
|
|
225
225
|
|
|
226
226
|
def char_is_selected(char)
|
|
227
|
-
return false if select_begin.nil? || select_end.nil?
|
|
227
|
+
return false if select_begin.nil? || select_end.nil? || (select_end - select_begin).zero?
|
|
228
228
|
|
|
229
229
|
(select_begin..select_end).include?(char.offset)
|
|
230
230
|
end
|
|
@@ -27,7 +27,7 @@ module Hokusai
|
|
|
27
27
|
|
|
28
28
|
INDEX_KEY = "index".freeze
|
|
29
29
|
|
|
30
|
-
def_delegators :@entry, :ast, :block, :target, :parent
|
|
30
|
+
def_delegators :@entry, :ast, :block, :target, :parent, :providers
|
|
31
31
|
|
|
32
32
|
def initialize(mount_entry)
|
|
33
33
|
@entry = mount_entry
|
|
@@ -78,12 +78,12 @@ module Hokusai
|
|
|
78
78
|
block.node.meta << child_block
|
|
79
79
|
|
|
80
80
|
node.ast.children.each_with_index do |child, idx|
|
|
81
|
-
entries_to_return << MountEntry.new(index, child, child_block, child_block, child_block, context: nil)
|
|
81
|
+
entries_to_return << MountEntry.new(index, child, child_block, child_block, child_block, context: nil, providers: providers.merge(child_block.providers))
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
siblings = []
|
|
85
85
|
portal.ast.children.each_with_index do |child, idx|
|
|
86
|
-
siblings << MountEntry.new(idx, child, child_block, child_block, target, context: ctx)
|
|
86
|
+
siblings << MountEntry.new(idx, child, child_block, child_block, target, context: ctx, providers: providers.merge(child_block.providers))
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
secondary_entries << siblings
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
module Hokusai
|
|
2
2
|
module Mounting
|
|
3
3
|
class MountEntry
|
|
4
|
-
attr_reader :block, :parent, :ast, :target, :index, :ctx
|
|
4
|
+
attr_reader :block, :parent, :ast, :target, :index, :ctx, :providers
|
|
5
5
|
|
|
6
|
-
def initialize(index, ast, block, parent, target = parent, context: nil)
|
|
6
|
+
def initialize(index, ast, block, parent, target = parent, context: nil, providers: {})
|
|
7
7
|
@index = index
|
|
8
8
|
@ast = ast
|
|
9
9
|
@block = block
|
|
10
10
|
@parent = parent
|
|
11
11
|
@target = target
|
|
12
|
+
@providers = providers
|
|
12
13
|
@ctx = context
|
|
13
14
|
end
|
|
14
15
|
|
|
@@ -28,6 +29,7 @@ module Hokusai
|
|
|
28
29
|
StringIO.open do |io|
|
|
29
30
|
io << "#{block.class} | #{ast.type} (#{index})\n"
|
|
30
31
|
io << "#{block.node.ast.children.map(&:type)}"
|
|
32
|
+
io << "providers: #{providers.map {|k,v| k }.join(", ")}\n"
|
|
31
33
|
io << "parent: #{parent.class}\n"
|
|
32
34
|
io << "target: #{target.class}\n\n"
|
|
33
35
|
end.string
|
|
@@ -35,7 +37,7 @@ module Hokusai
|
|
|
35
37
|
|
|
36
38
|
def with_block(new_block, supercede_parent: false)
|
|
37
39
|
parent_block = supercede_parent ? block : parent
|
|
38
|
-
MountEntry.new(index, ast, new_block, parent_block, target, context: ctx)
|
|
40
|
+
MountEntry.new(index, ast, new_block, parent_block, target, context: ctx, providers: providers)
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def mount(context: nil)
|
|
@@ -46,23 +48,11 @@ module Hokusai
|
|
|
46
48
|
node.add_styles(target.class)
|
|
47
49
|
node.add_props_from_block(target, context: context || ctx)
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
# handle provides / dependency injection
|
|
52
|
+
child_block = klass.new(node: node, providers: providers)
|
|
50
53
|
child_block.node.meta.publisher.add(target) # todo
|
|
51
54
|
UpdateEntry.new(child_block, block, target).register(context: context || ctx)
|
|
52
55
|
|
|
53
|
-
block.class.provides.each do |k, v|
|
|
54
|
-
if v.is_a?(Symbol)
|
|
55
|
-
Node.provide(child_block.node, k, ->{ block.public_send(v) })
|
|
56
|
-
|
|
57
|
-
# child_block.node.meta.provides[k] = -> { block.public_send(v) }
|
|
58
|
-
# child_block.class.provides[k] = -> { block.public_send(v) }
|
|
59
|
-
else
|
|
60
|
-
Node.provide(child_block.node, k, v)
|
|
61
|
-
# child_block.node.meta.provides[k] = v
|
|
62
|
-
# child_block.class.provides[k] = v
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
56
|
block.node.meta << child_block
|
|
67
57
|
|
|
68
58
|
yield child_block
|
data/ui/src/hokusai/node.rb
CHANGED
|
@@ -12,15 +12,6 @@ module Hokusai
|
|
|
12
12
|
|
|
13
13
|
def_delegators :@ast, :slot?, :type, :event
|
|
14
14
|
|
|
15
|
-
def self.provides
|
|
16
|
-
@provides ||= {}
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.provide(node, key, value)
|
|
20
|
-
provides[node.uuid] ||= {}
|
|
21
|
-
provides[node.uuid][key] = value
|
|
22
|
-
end
|
|
23
|
-
|
|
24
15
|
def self.parse(template, name = "root", parent = nil)
|
|
25
16
|
ast = Ast.parse(template, name)
|
|
26
17
|
|
|
@@ -13,7 +13,7 @@ module Hokusai
|
|
|
13
13
|
@primary_stack = []
|
|
14
14
|
|
|
15
15
|
node.ast.children.each_with_index do |child, index|
|
|
16
|
-
primary_stack << Mounting::MountEntry.new(index, child, root, root, previous_target || root)
|
|
16
|
+
primary_stack << Mounting::MountEntry.new(index, child, root, root, previous_target || root, providers: root.providers)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -78,7 +78,7 @@ module Hokusai
|
|
|
78
78
|
|
|
79
79
|
entry.ast.children.each_with_index do |child, child_index|
|
|
80
80
|
child.has_if_condition?
|
|
81
|
-
items << Mounting::MountEntry.new(child_index, child, child_block, entry.parent, entry.target, context: entry.ctx)
|
|
81
|
+
items << Mounting::MountEntry.new(child_index, child, child_block, entry.parent, entry.target, context: entry.ctx, providers: entry.providers.merge(child_block.providers))
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
secondary_stack.unshift items
|
|
@@ -88,7 +88,7 @@ module Hokusai
|
|
|
88
88
|
primary_items = []
|
|
89
89
|
|
|
90
90
|
child_block.node.ast.children.each_with_index do |child, child_index|
|
|
91
|
-
primary_items << Mounting::MountEntry.new(child_index, child, child_block, child_block, context: entry.ctx)
|
|
91
|
+
primary_items << Mounting::MountEntry.new(child_index, child, child_block, child_block, context: entry.ctx, providers: entry.providers.merge(child_block.providers))
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
self.primary_stack = primary_items + primary_stack
|
|
@@ -15,11 +15,11 @@ module Hokusai::Util
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def draw(font_size, boundary, selection: nil)
|
|
18
|
-
|
|
18
|
+
selection_extract(font_size, boundary, selection: selection)
|
|
19
19
|
draw_text(font_size, boundary)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
selection_update(selection)
|
|
21
|
+
self.start_select = 0.0
|
|
22
|
+
self.stop_select = nil
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def selection_extract(font_size, boundary, selection: nil)
|
|
@@ -165,6 +165,8 @@ module Hokusai::Util
|
|
|
165
165
|
if start = start_select
|
|
166
166
|
on_selection_change_cb&.call(start, stop_select)
|
|
167
167
|
end
|
|
168
|
+
|
|
169
|
+
nil
|
|
168
170
|
end
|
|
169
171
|
ensure
|
|
170
172
|
@i += 1
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hokusai-zero
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- skinnyjames
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-04-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ffi
|