kiso 0.4.1.pre → 0.4.2.pre
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/CHANGELOG.md +8 -1
- data/app/helpers/kiso/app_component_helper.rb +11 -2
- data/app/helpers/kiso/component_helper.rb +19 -3
- data/app/helpers/kiso/ui_context_helper.rb +56 -7
- data/lib/kiso/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e7e4247e68272499ab572c3aa2ed94ad54860cf075f0b4e3240a1b11fd909d6
|
|
4
|
+
data.tar.gz: 87e9710cb6428055adad01d89a4357e735ac5c8b326c547b01d696d208501cf8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f0842c23bdf92f06c826614ac8eb81d427eb136ea5fa2d6f735886387790cccda7943d450e8e771a7405cb9d6017eb2c1a5b00386b499b2c079ff933b520ec2
|
|
7
|
+
data.tar.gz: 1322bed3abb54da45bb4163e7fa5ca5919efbb6af07f505606dc17e65ac100f5fbc6d438e336347bdb44a09f70a2a7f3c413df876ace869adcd2b7a758ee725a
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.2.pre] - 2026-03-08
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `scope:` prop for sharing domain locals from parent components to sub-parts — `appui(:room_card, scope: { room: room })` makes `room:` available to all sub-parts automatically without repeating it on every call. Explicit kwargs on sub-part calls override scope values. One level deep only (parent to its own sub-parts).
|
|
15
|
+
|
|
10
16
|
## [0.4.1.pre] - 2026-03-08
|
|
11
17
|
|
|
12
18
|
### Added
|
|
@@ -112,7 +118,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
112
118
|
- Lookbook component previews
|
|
113
119
|
- Bridgetown documentation site
|
|
114
120
|
|
|
115
|
-
[Unreleased]: https://github.com/steveclarke/kiso/compare/v0.4.
|
|
121
|
+
[Unreleased]: https://github.com/steveclarke/kiso/compare/v0.4.2.pre...HEAD
|
|
122
|
+
[0.4.2.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.4.2.pre
|
|
116
123
|
[0.4.1.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.4.1.pre
|
|
117
124
|
[0.4.0.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.4.0.pre
|
|
118
125
|
[0.3.0.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.3.0.pre
|
|
@@ -22,6 +22,9 @@ module Kiso
|
|
|
22
22
|
# inherit overrides automatically. For self-rendering components, the hash is
|
|
23
23
|
# also passed as a local so the partial can apply overrides to internally
|
|
24
24
|
# rendered elements.
|
|
25
|
+
# @param scope [Hash, nil] domain locals shared from parent to sub-parts via context stack.
|
|
26
|
+
# Sub-parts receive scope values as kwargs automatically. Explicit kwargs on sub-part
|
|
27
|
+
# calls override scope values. One level deep only — no ancestor resolution.
|
|
25
28
|
# @param kwargs [Hash] locals passed to the partial (e.g. +css_classes:+)
|
|
26
29
|
# @yield optional block for component content
|
|
27
30
|
# @return [ActiveSupport::SafeBuffer] rendered HTML
|
|
@@ -39,13 +42,19 @@ module Kiso
|
|
|
39
42
|
# appui(:pricing_card, :header) { "Header" }
|
|
40
43
|
# end
|
|
41
44
|
#
|
|
45
|
+
# @example Share domain locals with sub-parts
|
|
46
|
+
# appui(:room_card, scope: { room: room }) do
|
|
47
|
+
# appui(:room_card, :status)
|
|
48
|
+
# appui(:room_card, :meta)
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
42
51
|
# @example Render a collection
|
|
43
52
|
# appui(:pricing_card, collection: @plans)
|
|
44
|
-
def appui(component, part = nil, collection: nil, ui: nil, **kwargs, &block)
|
|
53
|
+
def appui(component, part = nil, collection: nil, ui: nil, scope: nil, **kwargs, &block)
|
|
45
54
|
kiso_render_component(
|
|
46
55
|
component, part,
|
|
47
56
|
path_prefix: "components",
|
|
48
|
-
collection: collection, ui: ui, merge_global_ui: false,
|
|
57
|
+
collection: collection, ui: ui, scope: scope, merge_global_ui: false,
|
|
49
58
|
**kwargs, &block
|
|
50
59
|
)
|
|
51
60
|
end
|
|
@@ -16,6 +16,9 @@ module Kiso
|
|
|
16
16
|
# inherit overrides automatically. For self-rendering components, the hash is
|
|
17
17
|
# also passed as a local so the partial can apply overrides to internally
|
|
18
18
|
# rendered elements.
|
|
19
|
+
# @param scope [Hash, nil] domain locals shared from parent to sub-parts via context stack.
|
|
20
|
+
# Sub-parts receive scope values as kwargs automatically. Explicit kwargs on sub-part
|
|
21
|
+
# calls override scope values. One level deep only — no ancestor resolution.
|
|
19
22
|
# @param kwargs [Hash] locals passed to the partial (e.g. +color:+, +variant:+, +css_classes:+)
|
|
20
23
|
# @yield optional block for component content
|
|
21
24
|
# @return [ActiveSupport::SafeBuffer] rendered HTML
|
|
@@ -33,13 +36,18 @@ module Kiso
|
|
|
33
36
|
# @example Render an alert with inner element overrides
|
|
34
37
|
# kui(:alert, icon: "info", ui: { close: "opacity-50" })
|
|
35
38
|
#
|
|
39
|
+
# @example Share domain locals with sub-parts
|
|
40
|
+
# kui(:card, scope: { project: @project }) do
|
|
41
|
+
# kui(:card, :header) # sub-part receives project: automatically
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
36
44
|
# @example Render a collection
|
|
37
45
|
# kui(:badge, collection: @tags)
|
|
38
|
-
def kui(component, part = nil, collection: nil, ui: nil, **kwargs, &block)
|
|
46
|
+
def kui(component, part = nil, collection: nil, ui: nil, scope: nil, **kwargs, &block)
|
|
39
47
|
kiso_render_component(
|
|
40
48
|
component, part,
|
|
41
49
|
path_prefix: "kiso/components",
|
|
42
|
-
collection: collection, ui: ui, merge_global_ui: true,
|
|
50
|
+
collection: collection, ui: ui, scope: scope, merge_global_ui: true,
|
|
43
51
|
**kwargs, &block
|
|
44
52
|
)
|
|
45
53
|
end
|
|
@@ -109,11 +117,12 @@ module Kiso
|
|
|
109
117
|
# @param path_prefix [String] partial path prefix (e.g. "kiso/components" or "components")
|
|
110
118
|
# @param collection [Array, nil] renders the partial once per item when present
|
|
111
119
|
# @param ui [Hash, nil] per-slot class overrides
|
|
120
|
+
# @param scope [Hash, nil] domain locals shared from parent to sub-parts
|
|
112
121
|
# @param merge_global_ui [Boolean] whether to merge global config ui layer
|
|
113
122
|
# @param kwargs [Hash] locals passed to the partial
|
|
114
123
|
# @param block [Proc] optional block for component content
|
|
115
124
|
# @return [ActiveSupport::SafeBuffer] rendered HTML
|
|
116
|
-
def kiso_render_component(component, part, path_prefix:, collection:, ui:, merge_global_ui: true, **kwargs, &block)
|
|
125
|
+
def kiso_render_component(component, part, path_prefix:, collection:, ui:, scope:, merge_global_ui: true, **kwargs, &block)
|
|
117
126
|
path = if part
|
|
118
127
|
"#{path_prefix}/#{component}/#{part}"
|
|
119
128
|
else
|
|
@@ -131,6 +140,10 @@ module Kiso
|
|
|
131
140
|
block ||= proc {}
|
|
132
141
|
|
|
133
142
|
if part
|
|
143
|
+
# Sub-part: merge scope from parent context (scope values first, explicit kwargs win)
|
|
144
|
+
parent_scope = kiso_current_scope(component)
|
|
145
|
+
kwargs = parent_scope.merge(kwargs) if parent_scope.present?
|
|
146
|
+
|
|
134
147
|
# Sub-part: merge slot override from parent's ui context
|
|
135
148
|
parent_ui = kiso_current_ui(component)
|
|
136
149
|
if (slot_classes = parent_ui[part].presence)
|
|
@@ -154,9 +167,11 @@ module Kiso
|
|
|
154
167
|
ui || {}
|
|
155
168
|
end
|
|
156
169
|
has_ui = merged_ui.present?
|
|
170
|
+
has_scope = scope.present?
|
|
157
171
|
|
|
158
172
|
# Push context for composed sub-parts to read (skip when empty)
|
|
159
173
|
kiso_push_ui_context(component, merged_ui) if has_ui
|
|
174
|
+
kiso_push_scope(component, scope) if has_scope
|
|
160
175
|
begin
|
|
161
176
|
locals = has_ui ? kwargs.merge(ui: merged_ui) : kwargs
|
|
162
177
|
|
|
@@ -167,6 +182,7 @@ module Kiso
|
|
|
167
182
|
end
|
|
168
183
|
ensure
|
|
169
184
|
kiso_pop_ui_context(component) if has_ui
|
|
185
|
+
kiso_pop_scope(component) if has_scope
|
|
170
186
|
end
|
|
171
187
|
end
|
|
172
188
|
end
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Kiso
|
|
4
|
-
# Manages
|
|
4
|
+
# Manages request-scoped context stacks for component communication.
|
|
5
5
|
#
|
|
6
|
-
# This is ERB's equivalent of Vue's provide/inject pattern.
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
6
|
+
# This is ERB's equivalent of Vue's provide/inject pattern. Two stacks:
|
|
7
|
+
#
|
|
8
|
+
# - **ui:** — per-slot CSS class overrides. When a parent component is
|
|
9
|
+
# rendered with +ui:+, the hash is pushed onto a stack. Sub-parts read
|
|
10
|
+
# their slot override automatically.
|
|
11
|
+
# - **scope:** — domain locals shared from parent to sub-parts. When a
|
|
12
|
+
# parent is rendered with +scope:+, the hash is pushed onto a stack.
|
|
13
|
+
# Sub-parts receive scope values as kwargs, with explicit kwargs
|
|
14
|
+
# taking priority. One level deep only — no ancestor resolution.
|
|
10
15
|
#
|
|
11
16
|
# Thread-safe because Rails creates a fresh view context (and therefore
|
|
12
17
|
# fresh instance variables) per request.
|
|
13
18
|
#
|
|
14
|
-
# @example
|
|
19
|
+
# @example ui: stack flow
|
|
15
20
|
# # Parent pushes:
|
|
16
21
|
# kiso_push_ui_context(:card, { header: "p-8", title: "text-xl" })
|
|
17
22
|
#
|
|
@@ -21,6 +26,16 @@ module Kiso
|
|
|
21
26
|
# # After parent renders:
|
|
22
27
|
# kiso_pop_ui_context(:card)
|
|
23
28
|
#
|
|
29
|
+
# @example scope: stack flow
|
|
30
|
+
# # Parent pushes:
|
|
31
|
+
# kiso_push_scope(:room_card, { room: room })
|
|
32
|
+
#
|
|
33
|
+
# # Sub-part reads (merged into kwargs before render):
|
|
34
|
+
# kiso_current_scope(:room_card) #=> { room: room }
|
|
35
|
+
#
|
|
36
|
+
# # After parent renders:
|
|
37
|
+
# kiso_pop_scope(:room_card)
|
|
38
|
+
#
|
|
24
39
|
# @see ComponentHelper#kui
|
|
25
40
|
module UiContextHelper
|
|
26
41
|
# Push a ui hash onto the context stack for a component.
|
|
@@ -49,11 +64,45 @@ module Kiso
|
|
|
49
64
|
kiso_ui_stack.dig(component, -1) || {}
|
|
50
65
|
end
|
|
51
66
|
|
|
67
|
+
# Push a scope hash onto the context stack for a component.
|
|
68
|
+
#
|
|
69
|
+
# Scope shares domain locals from a parent component with its sub-parts
|
|
70
|
+
# so callers don't have to repeat the same locals on every sub-part call.
|
|
71
|
+
#
|
|
72
|
+
# @param component [Symbol] the component name (e.g. +:room_card+)
|
|
73
|
+
# @param scope [Hash] domain locals to share with sub-parts
|
|
74
|
+
# @return [void]
|
|
75
|
+
def kiso_push_scope(component, scope)
|
|
76
|
+
kiso_scope_stack[component] ||= []
|
|
77
|
+
kiso_scope_stack[component].push(scope || {})
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Pop the most recent scope hash for a component.
|
|
81
|
+
#
|
|
82
|
+
# @param component [Symbol] the component name
|
|
83
|
+
# @return [Hash, nil] the popped scope hash
|
|
84
|
+
def kiso_pop_scope(component)
|
|
85
|
+
kiso_scope_stack[component]&.pop
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Read the current scope hash for a component (top of stack).
|
|
89
|
+
#
|
|
90
|
+
# @param component [Symbol] the component name
|
|
91
|
+
# @return [Hash] the current scope, or empty hash
|
|
92
|
+
def kiso_current_scope(component)
|
|
93
|
+
kiso_scope_stack.dig(component, -1) || {}
|
|
94
|
+
end
|
|
95
|
+
|
|
52
96
|
private
|
|
53
97
|
|
|
54
|
-
# @return [Hash{Symbol => Array<Hash>}] per-component stacks
|
|
98
|
+
# @return [Hash{Symbol => Array<Hash>}] per-component ui stacks
|
|
55
99
|
def kiso_ui_stack
|
|
56
100
|
@kiso_ui_stack ||= {}
|
|
57
101
|
end
|
|
102
|
+
|
|
103
|
+
# @return [Hash{Symbol => Array<Hash>}] per-component scope stacks
|
|
104
|
+
def kiso_scope_stack
|
|
105
|
+
@kiso_scope_stack ||= {}
|
|
106
|
+
end
|
|
58
107
|
end
|
|
59
108
|
end
|
data/lib/kiso/version.rb
CHANGED