rook-cli 1.3.2 → 1.3.5
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.
- package/package.json +3 -2
- package/rook-framework/PRD-INSTALL-COMMAND.md +379 -0
- package/rook-framework/PRD.md +1214 -0
- package/rook-framework/README.md +143 -0
- package/rook-framework/assets/rk-accordion.js +99 -0
- package/rook-framework/assets/rk-alert-dialog.js +132 -0
- package/rook-framework/assets/rk-bottom-app-bar.js +88 -0
- package/rook-framework/assets/rk-carousel.js +145 -0
- package/rook-framework/assets/rk-collapsible.js +151 -0
- package/rook-framework/assets/rk-dialog.js +161 -0
- package/rook-framework/assets/rk-drawer.js +214 -0
- package/rook-framework/assets/rk-framework-core.css +2554 -0
- package/rook-framework/assets/rk-framework-tokens.css +101 -0
- package/rook-framework/assets/rk-modal.js +91 -0
- package/rook-framework/assets/rk-popover.js +264 -0
- package/rook-framework/assets/rk-progress.js +81 -0
- package/rook-framework/assets/rk-quantity.js +91 -0
- package/rook-framework/assets/rk-scroll-area.js +286 -0
- package/rook-framework/assets/rk-sheet.js +157 -0
- package/rook-framework/assets/rk-tabs.js +179 -0
- package/rook-framework/assets/rk-toggle.js +153 -0
- package/rook-framework/blocks/rk-accordion.liquid +97 -0
- package/rook-framework/blocks/rk-badge.liquid +103 -0
- package/rook-framework/blocks/rk-button.liquid +166 -0
- package/rook-framework/blocks/rk-divider.liquid +100 -0
- package/rook-framework/blocks/rk-form-field.liquid +120 -0
- package/rook-framework/blocks/rk-icon.liquid +134 -0
- package/rook-framework/blocks/rk-image.liquid +198 -0
- package/rook-framework/blocks/rk-installments.liquid +99 -0
- package/rook-framework/blocks/rk-pix-discount.liquid +99 -0
- package/rook-framework/blocks/rk-price.liquid +128 -0
- package/rook-framework/blocks/rk-quantity.liquid +108 -0
- package/rook-framework/blocks/rk-quick-add.liquid +137 -0
- package/rook-framework/blocks/rk-skeleton.liquid +104 -0
- package/rook-framework/blocks/rk-typography.liquid +183 -0
- package/rook-framework/config/rk-color-scheme-group.json +138 -0
- package/rook-framework/config/rk-settings_schema.json +259 -0
- package/rook-framework/snippets/rk-accordion.liquid +31 -0
- package/rook-framework/snippets/rk-alert-dialog.liquid +83 -0
- package/rook-framework/snippets/rk-aspect-ratio.liquid +23 -0
- package/rook-framework/snippets/rk-badge.liquid +17 -0
- package/rook-framework/snippets/rk-bottom-app-bar.liquid +51 -0
- package/rook-framework/snippets/rk-button.liquid +49 -0
- package/rook-framework/snippets/rk-card.liquid +64 -0
- package/rook-framework/snippets/rk-carousel.liquid +74 -0
- package/rook-framework/snippets/rk-checkbox.liquid +34 -0
- package/rook-framework/snippets/rk-collapsible.liquid +52 -0
- package/rook-framework/snippets/rk-color-schemes-standalone.liquid +61 -0
- package/rook-framework/snippets/rk-color-schemes.liquid +43 -0
- package/rook-framework/snippets/rk-dialog.liquid +85 -0
- package/rook-framework/snippets/rk-divider.liquid +25 -0
- package/rook-framework/snippets/rk-drawer.liquid +81 -0
- package/rook-framework/snippets/rk-external-assets copy.liquid +33 -0
- package/rook-framework/snippets/rk-external-assets.liquid +68 -0
- package/rook-framework/snippets/rk-form-field.liquid +83 -0
- package/rook-framework/snippets/rk-gap-style.liquid +32 -0
- package/rook-framework/snippets/rk-icon.liquid +28 -0
- package/rook-framework/snippets/rk-image.liquid +60 -0
- package/rook-framework/snippets/rk-input.liquid +35 -0
- package/rook-framework/snippets/rk-installments.liquid +54 -0
- package/rook-framework/snippets/rk-item.liquid +69 -0
- package/rook-framework/snippets/rk-layout-style.liquid +37 -0
- package/rook-framework/snippets/rk-modal.liquid +31 -0
- package/rook-framework/snippets/rk-pix-discount.liquid +34 -0
- package/rook-framework/snippets/rk-popover.liquid +77 -0
- package/rook-framework/snippets/rk-price.liquid +48 -0
- package/rook-framework/snippets/rk-progress.liquid +38 -0
- package/rook-framework/snippets/rk-quantity.liquid +56 -0
- package/rook-framework/snippets/rk-quick-add.liquid +67 -0
- package/rook-framework/snippets/rk-scripts.liquid +17 -0
- package/rook-framework/snippets/rk-scroll-area.liquid +60 -0
- package/rook-framework/snippets/rk-sheet.liquid +86 -0
- package/rook-framework/snippets/rk-size-style.liquid +48 -0
- package/rook-framework/snippets/rk-skeleton.liquid +25 -0
- package/rook-framework/snippets/rk-spacing-padding.liquid +18 -0
- package/rook-framework/snippets/rk-spacing-style.liquid +54 -0
- package/rook-framework/snippets/rk-spinner.liquid +43 -0
- package/rook-framework/snippets/rk-swatch.liquid +33 -0
- package/rook-framework/snippets/rk-table.liquid +44 -0
- package/rook-framework/snippets/rk-tabs.liquid +52 -0
- package/rook-framework/snippets/rk-textarea.liquid +42 -0
- package/rook-framework/snippets/rk-toggle-group.liquid +27 -0
- package/rook-framework/snippets/rk-toggle.liquid +58 -0
- package/rook-framework/snippets/rk-typography.liquid +27 -0
- package/rook-framework/snippets/rk-variables.liquid +76 -0
- package/src/app.js +24 -0
- package/src/commands/InstallCommand.js +133 -0
- package/src/mcp/server.js +111 -1
- package/src/services/FrameworkInstaller.js +485 -0
- package/src/templates/block.liquid.txt +0 -15
- package/src/ui/PromptUI.js +15 -1
- package/src/utils/logger.js +1 -1
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
Rook UI Core — Scroll Area Controller
|
|
3
|
+
Web Component: <rk-scroll-area>
|
|
4
|
+
========================================================================== */
|
|
5
|
+
|
|
6
|
+
if (!customElements.get('rk-scroll-area')) {
|
|
7
|
+
class RkScrollArea extends HTMLElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.viewport = null;
|
|
11
|
+
this.trackY = null;
|
|
12
|
+
this.thumbY = null;
|
|
13
|
+
this.trackX = null;
|
|
14
|
+
this.thumbX = null;
|
|
15
|
+
this.corner = null;
|
|
16
|
+
|
|
17
|
+
this._dragging = null; // 'y' | 'x' | null
|
|
18
|
+
this._dragStart = 0;
|
|
19
|
+
this._scrollStart = 0;
|
|
20
|
+
this._hideTimer = null;
|
|
21
|
+
|
|
22
|
+
this._onScroll = this._onScroll.bind(this);
|
|
23
|
+
this._onResize = this._debounce(this._recalculate.bind(this), 100);
|
|
24
|
+
this._onPointerMove = this._onPointerMove.bind(this);
|
|
25
|
+
this._onPointerUp = this._onPointerUp.bind(this);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
connectedCallback() {
|
|
29
|
+
this.viewport = this.querySelector('.rk-scroll-area__viewport');
|
|
30
|
+
this.trackY = this.querySelector('.rk-scroll-area__scrollbar--vertical');
|
|
31
|
+
this.thumbY = this.trackY?.querySelector('.rk-scroll-area__thumb');
|
|
32
|
+
this.trackX = this.querySelector('.rk-scroll-area__scrollbar--horizontal');
|
|
33
|
+
this.thumbX = this.trackX?.querySelector('.rk-scroll-area__thumb');
|
|
34
|
+
this.corner = this.querySelector('.rk-scroll-area__corner');
|
|
35
|
+
|
|
36
|
+
if (!this.viewport) return;
|
|
37
|
+
|
|
38
|
+
this._bindEvents();
|
|
39
|
+
this._recalculate();
|
|
40
|
+
|
|
41
|
+
// ResizeObserver for dynamic content
|
|
42
|
+
this._resizeObserver = new ResizeObserver(() => this._recalculate());
|
|
43
|
+
this._resizeObserver.observe(this.viewport);
|
|
44
|
+
|
|
45
|
+
// Also observe the direct content child
|
|
46
|
+
const content = this.viewport.firstElementChild;
|
|
47
|
+
if (content) {
|
|
48
|
+
this._resizeObserver.observe(content);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
disconnectedCallback() {
|
|
53
|
+
this._resizeObserver?.disconnect();
|
|
54
|
+
window.removeEventListener('resize', this._onResize);
|
|
55
|
+
document.removeEventListener('pointermove', this._onPointerMove);
|
|
56
|
+
document.removeEventListener('pointerup', this._onPointerUp);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* ------------------------------------------------------------------ */
|
|
60
|
+
/* Events */
|
|
61
|
+
/* ------------------------------------------------------------------ */
|
|
62
|
+
|
|
63
|
+
_bindEvents() {
|
|
64
|
+
this.viewport.addEventListener('scroll', this._onScroll, { passive: true });
|
|
65
|
+
window.addEventListener('resize', this._onResize);
|
|
66
|
+
|
|
67
|
+
// Thumb drag — vertical
|
|
68
|
+
if (this.thumbY) {
|
|
69
|
+
this.thumbY.addEventListener('pointerdown', (e) => this._onPointerDown(e, 'y'));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Thumb drag — horizontal
|
|
73
|
+
if (this.thumbX) {
|
|
74
|
+
this.thumbX.addEventListener('pointerdown', (e) => this._onPointerDown(e, 'x'));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Track click — vertical (jump to position)
|
|
78
|
+
if (this.trackY) {
|
|
79
|
+
this.trackY.addEventListener('pointerdown', (e) => {
|
|
80
|
+
if (e.target === this.trackY) this._onTrackClick(e, 'y');
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Track click — horizontal (jump to position)
|
|
85
|
+
if (this.trackX) {
|
|
86
|
+
this.trackX.addEventListener('pointerdown', (e) => {
|
|
87
|
+
if (e.target === this.trackX) this._onTrackClick(e, 'x');
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Visibility mode: hover
|
|
92
|
+
const visibility = this.dataset.visibility || 'auto';
|
|
93
|
+
if (visibility === 'hover') {
|
|
94
|
+
this.addEventListener('pointerenter', () => this._showScrollbars());
|
|
95
|
+
this.addEventListener('pointerleave', () => this._scheduleHide());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* ------------------------------------------------------------------ */
|
|
100
|
+
/* Scroll handler */
|
|
101
|
+
/* ------------------------------------------------------------------ */
|
|
102
|
+
|
|
103
|
+
_onScroll() {
|
|
104
|
+
this._syncThumbs();
|
|
105
|
+
|
|
106
|
+
const visibility = this.dataset.visibility || 'auto';
|
|
107
|
+
if (visibility === 'auto') {
|
|
108
|
+
this._showScrollbars();
|
|
109
|
+
this._scheduleHide();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* ------------------------------------------------------------------ */
|
|
114
|
+
/* Thumb calculations */
|
|
115
|
+
/* ------------------------------------------------------------------ */
|
|
116
|
+
|
|
117
|
+
_recalculate() {
|
|
118
|
+
if (!this.viewport) return;
|
|
119
|
+
|
|
120
|
+
const vp = this.viewport;
|
|
121
|
+
const hasOverflowY = vp.scrollHeight > vp.clientHeight;
|
|
122
|
+
const hasOverflowX = vp.scrollWidth > vp.clientWidth;
|
|
123
|
+
|
|
124
|
+
// Toggle scrollbar visibility based on overflow
|
|
125
|
+
if (this.trackY) {
|
|
126
|
+
this.trackY.classList.toggle('rk-scroll-area__scrollbar--hidden', !hasOverflowY);
|
|
127
|
+
}
|
|
128
|
+
if (this.trackX) {
|
|
129
|
+
this.trackX.classList.toggle('rk-scroll-area__scrollbar--hidden', !hasOverflowX);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Corner visibility
|
|
133
|
+
if (this.corner) {
|
|
134
|
+
this.corner.classList.toggle('rk-scroll-area__corner--hidden', !(hasOverflowY && hasOverflowX));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Calculate thumb sizes
|
|
138
|
+
if (this.thumbY && hasOverflowY) {
|
|
139
|
+
const ratio = vp.clientHeight / vp.scrollHeight;
|
|
140
|
+
const trackHeight = this.trackY.clientHeight;
|
|
141
|
+
const thumbHeight = Math.max(ratio * trackHeight, 24);
|
|
142
|
+
this.thumbY.style.height = `${thumbHeight}px`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (this.thumbX && hasOverflowX) {
|
|
146
|
+
const ratio = vp.clientWidth / vp.scrollWidth;
|
|
147
|
+
const trackWidth = this.trackX.clientWidth;
|
|
148
|
+
const thumbWidth = Math.max(ratio * trackWidth, 24);
|
|
149
|
+
this.thumbX.style.width = `${thumbWidth}px`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this._syncThumbs();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_syncThumbs() {
|
|
156
|
+
if (!this.viewport) return;
|
|
157
|
+
const vp = this.viewport;
|
|
158
|
+
|
|
159
|
+
// Vertical thumb position
|
|
160
|
+
if (this.thumbY && this.trackY) {
|
|
161
|
+
const scrollableY = vp.scrollHeight - vp.clientHeight;
|
|
162
|
+
if (scrollableY > 0) {
|
|
163
|
+
const ratio = vp.scrollTop / scrollableY;
|
|
164
|
+
const trackHeight = this.trackY.clientHeight;
|
|
165
|
+
const thumbHeight = this.thumbY.offsetHeight;
|
|
166
|
+
const maxOffset = trackHeight - thumbHeight;
|
|
167
|
+
this.thumbY.style.transform = `translateY(${ratio * maxOffset}px)`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Horizontal thumb position
|
|
172
|
+
if (this.thumbX && this.trackX) {
|
|
173
|
+
const scrollableX = vp.scrollWidth - vp.clientWidth;
|
|
174
|
+
if (scrollableX > 0) {
|
|
175
|
+
const ratio = vp.scrollLeft / scrollableX;
|
|
176
|
+
const trackWidth = this.trackX.clientWidth;
|
|
177
|
+
const thumbWidth = this.thumbX.offsetWidth;
|
|
178
|
+
const maxOffset = trackWidth - thumbWidth;
|
|
179
|
+
this.thumbX.style.transform = `translateX(${ratio * maxOffset}px)`;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* ------------------------------------------------------------------ */
|
|
185
|
+
/* Thumb drag */
|
|
186
|
+
/* ------------------------------------------------------------------ */
|
|
187
|
+
|
|
188
|
+
_onPointerDown(e, axis) {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
e.stopPropagation();
|
|
191
|
+
this._dragging = axis;
|
|
192
|
+
|
|
193
|
+
if (axis === 'y') {
|
|
194
|
+
this._dragStart = e.clientY;
|
|
195
|
+
this._scrollStart = this.viewport.scrollTop;
|
|
196
|
+
this.thumbY.classList.add('rk-scroll-area__thumb--active');
|
|
197
|
+
} else {
|
|
198
|
+
this._dragStart = e.clientX;
|
|
199
|
+
this._scrollStart = this.viewport.scrollLeft;
|
|
200
|
+
this.thumbX.classList.add('rk-scroll-area__thumb--active');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
document.addEventListener('pointermove', this._onPointerMove);
|
|
204
|
+
document.addEventListener('pointerup', this._onPointerUp);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
_onPointerMove(e) {
|
|
208
|
+
if (!this._dragging || !this.viewport) return;
|
|
209
|
+
|
|
210
|
+
const vp = this.viewport;
|
|
211
|
+
|
|
212
|
+
if (this._dragging === 'y') {
|
|
213
|
+
const delta = e.clientY - this._dragStart;
|
|
214
|
+
const scrollableY = vp.scrollHeight - vp.clientHeight;
|
|
215
|
+
const trackHeight = this.trackY.clientHeight;
|
|
216
|
+
const thumbHeight = this.thumbY.offsetHeight;
|
|
217
|
+
const scrollRatio = scrollableY / (trackHeight - thumbHeight);
|
|
218
|
+
vp.scrollTop = this._scrollStart + delta * scrollRatio;
|
|
219
|
+
} else {
|
|
220
|
+
const delta = e.clientX - this._dragStart;
|
|
221
|
+
const scrollableX = vp.scrollWidth - vp.clientWidth;
|
|
222
|
+
const trackWidth = this.trackX.clientWidth;
|
|
223
|
+
const thumbWidth = this.thumbX.offsetWidth;
|
|
224
|
+
const scrollRatio = scrollableX / (trackWidth - thumbWidth);
|
|
225
|
+
vp.scrollLeft = this._scrollStart + delta * scrollRatio;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
_onPointerUp() {
|
|
230
|
+
this.thumbY?.classList.remove('rk-scroll-area__thumb--active');
|
|
231
|
+
this.thumbX?.classList.remove('rk-scroll-area__thumb--active');
|
|
232
|
+
this._dragging = null;
|
|
233
|
+
document.removeEventListener('pointermove', this._onPointerMove);
|
|
234
|
+
document.removeEventListener('pointerup', this._onPointerUp);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* ------------------------------------------------------------------ */
|
|
238
|
+
/* Track click (jump to position) */
|
|
239
|
+
/* ------------------------------------------------------------------ */
|
|
240
|
+
|
|
241
|
+
_onTrackClick(e, axis) {
|
|
242
|
+
if (!this.viewport) return;
|
|
243
|
+
const vp = this.viewport;
|
|
244
|
+
|
|
245
|
+
if (axis === 'y') {
|
|
246
|
+
const trackRect = this.trackY.getBoundingClientRect();
|
|
247
|
+
const clickRatio = (e.clientY - trackRect.top) / trackRect.height;
|
|
248
|
+
vp.scrollTop = clickRatio * (vp.scrollHeight - vp.clientHeight);
|
|
249
|
+
} else {
|
|
250
|
+
const trackRect = this.trackX.getBoundingClientRect();
|
|
251
|
+
const clickRatio = (e.clientX - trackRect.left) / trackRect.width;
|
|
252
|
+
vp.scrollLeft = clickRatio * (vp.scrollWidth - vp.clientWidth);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* ------------------------------------------------------------------ */
|
|
257
|
+
/* Visibility management */
|
|
258
|
+
/* ------------------------------------------------------------------ */
|
|
259
|
+
|
|
260
|
+
_showScrollbars() {
|
|
261
|
+
clearTimeout(this._hideTimer);
|
|
262
|
+
this.classList.add('rk-scroll-area--scrolling');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
_scheduleHide() {
|
|
266
|
+
clearTimeout(this._hideTimer);
|
|
267
|
+
this._hideTimer = setTimeout(() => {
|
|
268
|
+
this.classList.remove('rk-scroll-area--scrolling');
|
|
269
|
+
}, 1200);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* ------------------------------------------------------------------ */
|
|
273
|
+
/* Helpers */
|
|
274
|
+
/* ------------------------------------------------------------------ */
|
|
275
|
+
|
|
276
|
+
_debounce(fn, delay) {
|
|
277
|
+
let timer;
|
|
278
|
+
return (...args) => {
|
|
279
|
+
clearTimeout(timer);
|
|
280
|
+
timer = setTimeout(() => fn(...args), delay);
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
customElements.define('rk-scroll-area', RkScrollArea);
|
|
286
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
Rook UI Core — Sheet Controller
|
|
3
|
+
Web Component: <rk-sheet-element>
|
|
4
|
+
========================================================================== */
|
|
5
|
+
|
|
6
|
+
if (!customElements.get('rk-sheet-element')) {
|
|
7
|
+
class RkSheetElement extends HTMLElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.sheet = null;
|
|
11
|
+
this.overlay = null;
|
|
12
|
+
this.panel = null;
|
|
13
|
+
this.previousFocus = null;
|
|
14
|
+
|
|
15
|
+
this._onKeyDown = this._onKeyDown.bind(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
this.sheet = this.querySelector('.rk-sheet');
|
|
20
|
+
this.overlay = this.querySelector('.rk-sheet__overlay');
|
|
21
|
+
this.panel = this.querySelector('.rk-sheet__panel');
|
|
22
|
+
|
|
23
|
+
if (!this.sheet || !this.panel) return;
|
|
24
|
+
|
|
25
|
+
this._bindEvents();
|
|
26
|
+
this._setupOpenTriggers();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* ------------------------------------------------------------------ */
|
|
30
|
+
/* Events */
|
|
31
|
+
/* ------------------------------------------------------------------ */
|
|
32
|
+
|
|
33
|
+
_bindEvents() {
|
|
34
|
+
// Close buttons
|
|
35
|
+
this.querySelectorAll('[data-action="close"]').forEach((el) => {
|
|
36
|
+
el.addEventListener('click', () => this.close());
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Overlay click (configurable)
|
|
40
|
+
if (this.overlay) {
|
|
41
|
+
const overlayClose = this.dataset.overlayClose !== 'false';
|
|
42
|
+
if (overlayClose) {
|
|
43
|
+
this.overlay.addEventListener('click', () => this.close());
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_setupOpenTriggers() {
|
|
49
|
+
const sheetId = this.dataset.sheetId || this.sheet?.id;
|
|
50
|
+
if (!sheetId) return;
|
|
51
|
+
|
|
52
|
+
document.querySelectorAll(`[data-sheet-open="${sheetId}"]`).forEach((trigger) => {
|
|
53
|
+
trigger.addEventListener('click', (e) => {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
this.open();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* ------------------------------------------------------------------ */
|
|
61
|
+
/* Public API */
|
|
62
|
+
/* ------------------------------------------------------------------ */
|
|
63
|
+
|
|
64
|
+
isOpen() {
|
|
65
|
+
return this.sheet?.classList.contains('rk-sheet--active');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
open() {
|
|
69
|
+
if (!this.sheet || this.isOpen()) return;
|
|
70
|
+
|
|
71
|
+
this.previousFocus = document.activeElement;
|
|
72
|
+
this.sheet.classList.add('rk-sheet--active');
|
|
73
|
+
document.body.style.overflow = 'hidden';
|
|
74
|
+
document.addEventListener('keydown', this._onKeyDown);
|
|
75
|
+
|
|
76
|
+
// Focus first interactive element
|
|
77
|
+
requestAnimationFrame(() => {
|
|
78
|
+
const firstFocusable = this.panel.querySelector(
|
|
79
|
+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
80
|
+
);
|
|
81
|
+
if (firstFocusable) {
|
|
82
|
+
firstFocusable.focus();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.dispatchEvent(
|
|
87
|
+
new CustomEvent('rk:sheet:open', {
|
|
88
|
+
bubbles: true,
|
|
89
|
+
detail: { id: this.sheet.id },
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
close() {
|
|
95
|
+
if (!this.sheet || !this.isOpen()) return;
|
|
96
|
+
|
|
97
|
+
this.sheet.classList.remove('rk-sheet--active');
|
|
98
|
+
document.body.style.overflow = '';
|
|
99
|
+
document.removeEventListener('keydown', this._onKeyDown);
|
|
100
|
+
|
|
101
|
+
if (this.previousFocus) {
|
|
102
|
+
this.previousFocus.focus();
|
|
103
|
+
this.previousFocus = null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.dispatchEvent(
|
|
107
|
+
new CustomEvent('rk:sheet:close', {
|
|
108
|
+
bubbles: true,
|
|
109
|
+
detail: { id: this.sheet.id },
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* ------------------------------------------------------------------ */
|
|
115
|
+
/* Keyboard (ESC + Tab trap) */
|
|
116
|
+
/* ------------------------------------------------------------------ */
|
|
117
|
+
|
|
118
|
+
_onKeyDown(e) {
|
|
119
|
+
if (!this.isOpen()) return;
|
|
120
|
+
|
|
121
|
+
if (e.key === 'Escape') {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
this.close();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (e.key === 'Tab') {
|
|
128
|
+
this._trapFocus(e);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_trapFocus(e) {
|
|
133
|
+
const focusable = this.panel?.querySelectorAll(
|
|
134
|
+
'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
if (!focusable || focusable.length === 0) return;
|
|
138
|
+
|
|
139
|
+
const first = focusable[0];
|
|
140
|
+
const last = focusable[focusable.length - 1];
|
|
141
|
+
|
|
142
|
+
if (e.shiftKey) {
|
|
143
|
+
if (document.activeElement === first) {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
last.focus();
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
if (document.activeElement === last) {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
first.focus();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
customElements.define('rk-sheet-element', RkSheetElement);
|
|
157
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
Rook UI Core — Tabs Controller
|
|
3
|
+
Web Component: <rk-tabs-element>
|
|
4
|
+
========================================================================== */
|
|
5
|
+
|
|
6
|
+
if (!customElements.get('rk-tabs-element')) {
|
|
7
|
+
class RkTabsElement extends HTMLElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.tabs = [];
|
|
11
|
+
this.panels = [];
|
|
12
|
+
this.activeTabId = null;
|
|
13
|
+
|
|
14
|
+
this._onKeyDown = this._onKeyDown.bind(this);
|
|
15
|
+
this._onClick = this._onClick.bind(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
// Find all tabs and panels within the element
|
|
20
|
+
this.tabs = Array.from(this.querySelectorAll('[role="tab"]'));
|
|
21
|
+
this.panels = Array.from(this.querySelectorAll('[role="tabpanel"]'));
|
|
22
|
+
|
|
23
|
+
if (this.tabs.length === 0 || this.panels.length === 0) return;
|
|
24
|
+
|
|
25
|
+
this._bindEvents();
|
|
26
|
+
this._setupA11y();
|
|
27
|
+
|
|
28
|
+
// Set initial state
|
|
29
|
+
const defaultId = this.dataset.defaultValue;
|
|
30
|
+
const tabToActivate = this.tabs.find((tab) => tab.id === defaultId) || this.tabs[0];
|
|
31
|
+
|
|
32
|
+
if (tabToActivate) {
|
|
33
|
+
this.activateTab(tabToActivate.id, false);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* ------------------------------------------------------------------ */
|
|
38
|
+
/* Setup */
|
|
39
|
+
/* ------------------------------------------------------------------ */
|
|
40
|
+
|
|
41
|
+
_setupA11y() {
|
|
42
|
+
// Ensure tablist has role
|
|
43
|
+
const tabList = this.querySelector('.rk-tabs__list');
|
|
44
|
+
if (tabList && !tabList.hasAttribute('role')) {
|
|
45
|
+
tabList.setAttribute('role', 'tablist');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.tabs.forEach((tab) => {
|
|
49
|
+
tab.setAttribute('tabindex', '-1');
|
|
50
|
+
tab.setAttribute('aria-selected', 'false');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.panels.forEach((panel) => {
|
|
54
|
+
panel.setAttribute('tabindex', '0');
|
|
55
|
+
if (!panel.hasAttribute('hidden')) {
|
|
56
|
+
panel.setAttribute('hidden', 'true');
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_bindEvents() {
|
|
62
|
+
const tabList = this.querySelector('.rk-tabs__list');
|
|
63
|
+
if (tabList) {
|
|
64
|
+
tabList.addEventListener('keydown', this._onKeyDown);
|
|
65
|
+
tabList.addEventListener('click', this._onClick);
|
|
66
|
+
} else {
|
|
67
|
+
this.tabs.forEach((tab) => {
|
|
68
|
+
tab.addEventListener('keydown', this._onKeyDown);
|
|
69
|
+
tab.addEventListener('click', this._onClick);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ------------------------------------------------------------------ */
|
|
75
|
+
/* Interactions */
|
|
76
|
+
/* ------------------------------------------------------------------ */
|
|
77
|
+
|
|
78
|
+
_onClick(e) {
|
|
79
|
+
const target = e.target.closest('[role="tab"]');
|
|
80
|
+
if (!target || target.disabled || target.getAttribute('aria-disabled') === 'true') return;
|
|
81
|
+
|
|
82
|
+
this.activateTab(target.id, true);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_onKeyDown(e) {
|
|
86
|
+
const target = e.target.closest('[role="tab"]');
|
|
87
|
+
if (!target) return;
|
|
88
|
+
|
|
89
|
+
const currentIndex = this.tabs.indexOf(target);
|
|
90
|
+
let nextIndex = currentIndex;
|
|
91
|
+
|
|
92
|
+
const orientation = this.dataset.orientation || 'horizontal';
|
|
93
|
+
|
|
94
|
+
switch (e.key) {
|
|
95
|
+
case 'ArrowRight':
|
|
96
|
+
if (orientation === 'horizontal') nextIndex = currentIndex + 1;
|
|
97
|
+
break;
|
|
98
|
+
case 'ArrowLeft':
|
|
99
|
+
if (orientation === 'horizontal') nextIndex = currentIndex - 1;
|
|
100
|
+
break;
|
|
101
|
+
case 'ArrowDown':
|
|
102
|
+
if (orientation === 'vertical') nextIndex = currentIndex + 1;
|
|
103
|
+
break;
|
|
104
|
+
case 'ArrowUp':
|
|
105
|
+
if (orientation === 'vertical') nextIndex = currentIndex - 1;
|
|
106
|
+
break;
|
|
107
|
+
case 'Home':
|
|
108
|
+
nextIndex = 0;
|
|
109
|
+
break;
|
|
110
|
+
case 'End':
|
|
111
|
+
nextIndex = this.tabs.length - 1;
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
return; // Let other keys behave normally
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
e.preventDefault(); // Prevent page scroll for arrows
|
|
118
|
+
|
|
119
|
+
// Wrap around
|
|
120
|
+
if (nextIndex >= this.tabs.length) {
|
|
121
|
+
nextIndex = 0;
|
|
122
|
+
} else if (nextIndex < 0) {
|
|
123
|
+
nextIndex = this.tabs.length - 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const nextTab = this.tabs[nextIndex];
|
|
127
|
+
|
|
128
|
+
// Skip disabled tabs
|
|
129
|
+
if (nextTab.disabled || nextTab.getAttribute('aria-disabled') === 'true') {
|
|
130
|
+
return; // Simple approach: do not move if next is disabled. (Complex approach: loop until non-disabled).
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
nextTab.focus();
|
|
134
|
+
|
|
135
|
+
// Auto-activate on focus in Shadcn/UI default behavior
|
|
136
|
+
this.activateTab(nextTab.id, true);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* ------------------------------------------------------------------ */
|
|
140
|
+
/* Public API */
|
|
141
|
+
/* ------------------------------------------------------------------ */
|
|
142
|
+
|
|
143
|
+
activateTab(tabId, focus = false) {
|
|
144
|
+
if (this.activeTabId === tabId) return;
|
|
145
|
+
|
|
146
|
+
this.tabs.forEach((tab) => {
|
|
147
|
+
const isSelected = tab.id === tabId;
|
|
148
|
+
tab.setAttribute('aria-selected', isSelected ? 'true' : 'false');
|
|
149
|
+
tab.setAttribute('tabindex', isSelected ? '0' : '-1');
|
|
150
|
+
|
|
151
|
+
if (isSelected && focus) {
|
|
152
|
+
tab.focus();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
this.panels.forEach((panel) => {
|
|
157
|
+
const controlledBy = panel.getAttribute('aria-labelledby');
|
|
158
|
+
if (controlledBy === tabId) {
|
|
159
|
+
panel.removeAttribute('hidden');
|
|
160
|
+
panel.classList.add('rk-tabs__panel--active');
|
|
161
|
+
} else {
|
|
162
|
+
panel.setAttribute('hidden', 'true');
|
|
163
|
+
panel.classList.remove('rk-tabs__panel--active');
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
this.activeTabId = tabId;
|
|
168
|
+
|
|
169
|
+
this.dispatchEvent(
|
|
170
|
+
new CustomEvent('rk:tabs:change', {
|
|
171
|
+
bubbles: true,
|
|
172
|
+
detail: { activeTabId: tabId },
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
customElements.define('rk-tabs-element', RkTabsElement);
|
|
179
|
+
}
|