basecoat-cli 0.3.9 → 0.3.10-beta.2
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/dist/assets/jinja/carousel.html.jinja +111 -0
- package/dist/assets/jinja/select.html.jinja +35 -15
- package/dist/assets/js/all.js +185 -50
- package/dist/assets/js/all.min.js +1 -1
- package/dist/assets/js/carousel.js +192 -0
- package/dist/assets/js/carousel.min.js +1 -0
- package/dist/assets/js/select.js +185 -50
- package/dist/assets/js/select.min.js +1 -1
- package/dist/assets/nunjucks/carousel.njk +111 -0
- package/dist/assets/nunjucks/select.njk +36 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),
|
|
1
|
+
(()=>{const e=e=>{const t=e.querySelector(":scope > button"),r=t.querySelector(":scope > span"),n=e.querySelector(":scope > [data-popover]"),i=n?n.querySelector('[role="listbox"]'):null,a=e.querySelector(':scope > input[type="hidden"]'),s=e.querySelector('header input[type="text"]');if(!(t&&n&&i&&a)){const r=[];return t||r.push("trigger"),n||r.push("popover"),i||r.push("listbox"),a||r.push("input"),void console.error(`Select component initialisation failed. Missing element(s): ${r.join(", ")}`,e)}const o=Array.from(i.querySelectorAll('[role="option"]')),c=o.filter((e=>"true"!==e.getAttribute("aria-disabled")));let l=[...c],d=-1;const u="true"===i.getAttribute("aria-multiselectable"),f=u?new Set:null,p=u?e.dataset.placeholder||"":null,v=e=>e.dataset.value??e.textContent.trim(),h=e=>{if(d>-1&&c[d]&&c[d].classList.remove("active"),d=e,d>-1){const e=c[d];e.classList.add("active"),e.id?t.setAttribute("aria-activedescendant",e.id):t.removeAttribute("aria-activedescendant")}else t.removeAttribute("aria-activedescendant")},b=()=>{const e=getComputedStyle(n);return parseFloat(e.transitionDuration)>0||parseFloat(e.transitionDelay)>0},m=(t,n=!0)=>{let i;if(u){const e=Array.isArray(t)?t:[];f.clear(),e.forEach((e=>f.add(e)));const n=c.filter((e=>f.has(e)));0===n.length?(r.textContent=p,r.classList.add("text-muted-foreground")):(r.textContent=n.map((e=>e.dataset.label||e.textContent.trim())).join(", "),r.classList.remove("text-muted-foreground")),i=n.map(v),a.value=JSON.stringify(i)}else{const e=t;if(!e)return;r.innerHTML=e.innerHTML,i=v(e),a.value=i}c.forEach((e=>{(u?f.has(e):e===t)?e.setAttribute("aria-selected","true"):e.removeAttribute("aria-selected")})),n&&e.dispatchEvent(new CustomEvent("change",{detail:{value:i},bubbles:!0}))},y=(e=!0)=>{if("true"!==n.getAttribute("aria-hidden")){if(s){const e=()=>{s.value="",l=[...c],o.forEach((e=>e.setAttribute("aria-hidden","false")))};b()?n.addEventListener("transitionend",e,{once:!0}):e()}e&&t.focus(),n.setAttribute("aria-hidden","true"),t.setAttribute("aria-expanded","false"),h(-1)}},A=e=>{f.has(e)?f.delete(e):f.add(e),m(c.filter((e=>f.has(e))))},E=e=>{if(u){const t=c.find((t=>v(t)===e&&!f.has(t)));if(!t)return;f.add(t),m(c.filter((e=>f.has(e))))}else{const t=c.find((t=>v(t)===e));if(!t)return;a.value!==e&&m(t),y()}},g=e=>{if(!u)return;const t=c.find((t=>v(t)===e&&f.has(t)));t&&(f.delete(t),m(c.filter((e=>f.has(e)))))},w=e=>{if(!u)return;const t=c.find((t=>v(t)===e));t&&A(t)};if(s){const e=()=>{const e=s.value.trim().toLowerCase();h(-1),l=[],o.forEach((t=>{if(t.hasAttribute("data-force"))return t.setAttribute("aria-hidden","false"),void(c.includes(t)&&l.push(t));const r=(t.dataset.filter||t.textContent).trim().toLowerCase(),n=(t.dataset.keywords||"").toLowerCase().split(/[\s,]+/).filter(Boolean).some((t=>t.includes(e))),i=r.includes(e)||n;t.setAttribute("aria-hidden",String(!i)),i&&c.includes(t)&&l.push(t)}))};s.addEventListener("input",e)}if(u){const e=c.filter((e=>"true"===e.getAttribute("aria-selected")));try{const t=JSON.parse(a.value||"[]"),r=new Set(c.map(v)),n=Array.isArray(t)?t.filter((e=>r.has(e))):[],i=[];n.length>0?n.forEach((e=>{const t=c.find((t=>v(t)===e&&!i.includes(t)));t&&i.push(t)})):i.push(...e),m(i,!1)}catch(t){m(e,!1)}}else{const e=c.find((e=>v(e)===a.value))||c[0];e&&m(e,!1)}const L=e=>{const r="false"===n.getAttribute("aria-hidden");if(!["ArrowDown","ArrowUp","Enter","Home","End","Escape"].includes(e.key))return;if(!r)return void("Enter"!==e.key&&"Escape"!==e.key&&(e.preventDefault(),t.click()));if(e.preventDefault(),"Escape"===e.key)return void y();if("Enter"===e.key){if(d>-1){const e=c[d];u?A(e):(a.value!==v(e)&&m(e),y())}return}if(0===l.length)return;const i=d>-1?l.indexOf(c[d]):-1;let s=i;switch(e.key){case"ArrowDown":i<l.length-1&&(s=i+1);break;case"ArrowUp":i>0?s=i-1:-1===i&&(s=0);break;case"Home":s=0;break;case"End":s=l.length-1}if(s!==i){const e=l[s];h(c.indexOf(e)),e.scrollIntoView({block:"nearest",behavior:"smooth"})}};i.addEventListener("mousemove",(e=>{const t=e.target.closest('[role="option"]');if(t&&l.includes(t)){const e=c.indexOf(t);e!==d&&h(e)}})),i.addEventListener("mouseleave",(()=>{const e=i.querySelector('[role="option"][aria-selected="true"]');h(e?c.indexOf(e):-1)})),t.addEventListener("keydown",L),s&&s.addEventListener("keydown",L);t.addEventListener("click",(()=>{"true"===t.getAttribute("aria-expanded")?y():(()=>{document.dispatchEvent(new CustomEvent("basecoat:popover",{detail:{source:e}})),s&&(b()?n.addEventListener("transitionend",(()=>{s.focus()}),{once:!0}):s.focus()),n.setAttribute("aria-hidden","false"),t.setAttribute("aria-expanded","true");const r=i.querySelector('[role="option"][aria-selected="true"]');r&&(h(c.indexOf(r)),r.scrollIntoView({block:"nearest"}))})()})),i.addEventListener("click",(e=>{const r=e.target.closest('[role="option"]');if(!r)return;const n=c.find((e=>e===r));n&&(u?(A(n),h(c.indexOf(n)),s?s.focus():t.focus()):(a.value!==v(n)&&m(n),y()))})),document.addEventListener("click",(t=>{e.contains(t.target)||y(!1)})),document.addEventListener("basecoat:popover",(t=>{t.detail.source!==e&&y(!1)})),n.setAttribute("aria-hidden","true"),Object.defineProperty(e,"value",{get:()=>u?c.filter((e=>f.has(e))).map(v):a.value,set:e=>{if(u){const t=Array.isArray(e)?e:null!=e?[e]:[],r=[];t.forEach((e=>{const t=c.find((t=>v(t)===e&&!r.includes(t)));t&&r.push(t)})),m(r)}else{const t=c.find((t=>v(t)===e));t&&(m(t),y())}}}),e.select=E,e.selectByValue=E,u&&(e.deselect=g,e.toggle=w,e.selectAll=()=>m(c),e.selectNone=()=>m([])),e.dataset.selectInitialized=!0,e.dispatchEvent(new CustomEvent("basecoat:initialized"))};window.basecoat&&window.basecoat.register("select","div.select:not([data-select-initialized])",e)})();
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{#
|
|
2
|
+
Renders a carousel component with navigation controls and optional indicators.
|
|
3
|
+
|
|
4
|
+
@param id {string} [optional] - Unique identifier for the carousel component. Auto-generated if not provided.
|
|
5
|
+
@param slides {array} - An array of objects representing carousel slides.
|
|
6
|
+
Each object should have:
|
|
7
|
+
- content {string}: HTML content for the slide.
|
|
8
|
+
- attrs {object} [optional]: Additional HTML attributes for the slide item.
|
|
9
|
+
@param loop {boolean} [optional] [default=false] - Enable continuous looping.
|
|
10
|
+
@param autoplay {number} [optional] [default=0] - Auto-advance delay in milliseconds (0 = disabled).
|
|
11
|
+
@param align {string} [optional] [default='start'] - Slide alignment ('start' or 'center').
|
|
12
|
+
@param orientation {string} [optional] [default='horizontal'] - Carousel orientation ('horizontal' or 'vertical').
|
|
13
|
+
@param show_controls {boolean} [optional] [default=true] - Show previous/next navigation buttons.
|
|
14
|
+
@param show_indicators {boolean} [optional] [default=true] - Show slide indicator dots.
|
|
15
|
+
@param main_attrs {object} [optional] - Additional HTML attributes for the main container.
|
|
16
|
+
@param viewport_attrs {object} [optional] - Additional HTML attributes for the viewport container.
|
|
17
|
+
#}
|
|
18
|
+
{% macro carousel(
|
|
19
|
+
id=None,
|
|
20
|
+
slides=[],
|
|
21
|
+
loop=false,
|
|
22
|
+
autoplay=0,
|
|
23
|
+
align='start',
|
|
24
|
+
orientation='horizontal',
|
|
25
|
+
show_controls=true,
|
|
26
|
+
show_indicators=true,
|
|
27
|
+
main_attrs={},
|
|
28
|
+
viewport_attrs={}
|
|
29
|
+
)
|
|
30
|
+
%}
|
|
31
|
+
{% set id = id or ("carousel-" + (range(100000, 999999) | random | string)) %}
|
|
32
|
+
<div
|
|
33
|
+
class="carousel {{ main_attrs.class }}"
|
|
34
|
+
id="{{ id }}"
|
|
35
|
+
data-carousel-loop="{{ 'true' if loop else 'false' }}"
|
|
36
|
+
{% if autoplay > 0 %}data-carousel-autoplay="{{ autoplay }}"{% endif %}
|
|
37
|
+
data-orientation="{{ orientation }}"
|
|
38
|
+
role="region"
|
|
39
|
+
aria-roledescription="carousel"
|
|
40
|
+
aria-label="Carousel"
|
|
41
|
+
tabindex="0"
|
|
42
|
+
{% for key, value in main_attrs %}
|
|
43
|
+
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
44
|
+
{% endfor %}
|
|
45
|
+
>
|
|
46
|
+
<div
|
|
47
|
+
class="carousel-viewport {{ viewport_attrs.class }}"
|
|
48
|
+
{% for key, value in viewport_attrs %}
|
|
49
|
+
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
50
|
+
{% endfor %}
|
|
51
|
+
>
|
|
52
|
+
<div
|
|
53
|
+
class="carousel-slides"
|
|
54
|
+
data-orientation="{{ orientation }}"
|
|
55
|
+
>
|
|
56
|
+
{% for slide in slides %}
|
|
57
|
+
<div
|
|
58
|
+
class="carousel-item"
|
|
59
|
+
role="group"
|
|
60
|
+
aria-roledescription="slide"
|
|
61
|
+
aria-label="{{ loop.index }} of {{ slides | length }}"
|
|
62
|
+
{% if align == 'center' %}data-align="center"{% endif %}
|
|
63
|
+
{% if slide.attrs %}
|
|
64
|
+
{% for key, value in slide.attrs %}
|
|
65
|
+
{{ key }}="{{ value }}"
|
|
66
|
+
{% endfor %}
|
|
67
|
+
{% endif %}
|
|
68
|
+
>
|
|
69
|
+
{{ slide.content | safe }}
|
|
70
|
+
</div>
|
|
71
|
+
{% endfor %}
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
{% if show_controls %}
|
|
76
|
+
<div class="carousel-controls">
|
|
77
|
+
<button
|
|
78
|
+
type="button"
|
|
79
|
+
class="carousel-prev"
|
|
80
|
+
aria-label="Previous slide"
|
|
81
|
+
>
|
|
82
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
83
|
+
<path d="m15 18-6-6 6-6"/>
|
|
84
|
+
</svg>
|
|
85
|
+
</button>
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
class="carousel-next"
|
|
89
|
+
aria-label="Next slide"
|
|
90
|
+
>
|
|
91
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
92
|
+
<path d="m9 18 6-6-6-6"/>
|
|
93
|
+
</svg>
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
{% endif %}
|
|
97
|
+
|
|
98
|
+
{% if show_indicators %}
|
|
99
|
+
<div class="carousel-indicators" role="tablist" aria-label="Slides">
|
|
100
|
+
{% for slide in slides %}
|
|
101
|
+
<button
|
|
102
|
+
type="button"
|
|
103
|
+
role="tab"
|
|
104
|
+
aria-label="Slide {{ loop.index }}"
|
|
105
|
+
{% if loop.index == 1 %}aria-current="true"{% else %}aria-current="false"{% endif %}
|
|
106
|
+
></button>
|
|
107
|
+
{% endfor %}
|
|
108
|
+
</div>
|
|
109
|
+
{% endif %}
|
|
110
|
+
</div>
|
|
111
|
+
{% endmacro %}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Renders a select or combobox component.
|
|
3
3
|
|
|
4
4
|
@param id {string} [optional] - Unique identifier for the select component.
|
|
5
|
-
@param selected {string} [optional] - The initially selected value.
|
|
5
|
+
@param selected {string|array} [optional] - The initially selected value(s).
|
|
6
6
|
@param name {string} [optional] - The name attribute for the hidden input storing the selected value.
|
|
7
|
+
@param multiple {boolean} [optional] [default=false] - Enables multiple selection mode.
|
|
8
|
+
@param placeholder {string} [optional] - Placeholder text shown when no options are selected (multiple mode only).
|
|
7
9
|
@param main_attrs {object} [optional] - Additional HTML attributes for the main container div.
|
|
8
10
|
@param trigger_attrs {object} [optional] - Additional HTML attributes for the trigger button.
|
|
9
11
|
@param popover_attrs {object} [optional] - Additional HTML attributes for the popover content div.
|
|
@@ -17,6 +19,8 @@
|
|
|
17
19
|
selected=None,
|
|
18
20
|
name=None,
|
|
19
21
|
items=None,
|
|
22
|
+
multiple=false,
|
|
23
|
+
placeholder=None,
|
|
20
24
|
main_attrs={},
|
|
21
25
|
trigger_attrs={},
|
|
22
26
|
popover_attrs={},
|
|
@@ -27,8 +31,15 @@
|
|
|
27
31
|
) %}
|
|
28
32
|
{% set id = id or ("select-" + (range(100000, 999999) | random | string)) %}
|
|
29
33
|
|
|
34
|
+
{% if selected is defined and selected is iterable and selected is not string %}
|
|
35
|
+
{% set selectedArray = selected %}
|
|
36
|
+
{% elif selected is defined %}
|
|
37
|
+
{% set selectedArray = [selected] %}
|
|
38
|
+
{% else %}
|
|
39
|
+
{% set selectedArray = [] %}
|
|
40
|
+
{% endif %}
|
|
30
41
|
{% set first_option = [] %}
|
|
31
|
-
{% set
|
|
42
|
+
{% set selected_options = [] %}
|
|
32
43
|
|
|
33
44
|
{% if items %}
|
|
34
45
|
{% for item in items %}
|
|
@@ -37,33 +48,41 @@
|
|
|
37
48
|
{% if not first_option[0] %}
|
|
38
49
|
{% set first_option = (first_option.push(sub_item), first_option) %}
|
|
39
50
|
{% endif %}
|
|
40
|
-
{% if
|
|
41
|
-
{% set
|
|
51
|
+
{% if sub_item.value in selectedArray %}
|
|
52
|
+
{% set selected_options = (selected_options.push(sub_item), selected_options) %}
|
|
42
53
|
{% endif %}
|
|
43
54
|
{% endfor %}
|
|
44
55
|
{% else %}
|
|
45
56
|
{% if not first_option[0] %}
|
|
46
57
|
{% set first_option = (first_option.push(item), first_option) %}
|
|
47
58
|
{% endif %}
|
|
48
|
-
{% if
|
|
49
|
-
{% set
|
|
59
|
+
{% if item.value in selectedArray %}
|
|
60
|
+
{% set selected_options = (selected_options.push(item), selected_options) %}
|
|
50
61
|
{% endif %}
|
|
51
62
|
{% endif %}
|
|
52
63
|
{% endfor %}
|
|
53
64
|
{% endif %}
|
|
54
65
|
|
|
55
|
-
{% set default_option =
|
|
66
|
+
{% set default_option = (selected_options[0] if selected_options[0] else (first_option[0] if first_option[0] else None)) %}
|
|
67
|
+
{% set labels = [] %}
|
|
68
|
+
{% if multiple and selected_options %}
|
|
69
|
+
{% for opt in selected_options %}
|
|
70
|
+
{% set labels = (labels.push(opt.label), labels) %}
|
|
71
|
+
{% endfor %}
|
|
72
|
+
{% endif %}
|
|
73
|
+
{% set default_label = (labels | join(', ') if (multiple and selected_options) else ((placeholder or '') if (multiple and not selected_options) else (default_option.label if default_option else ''))) %}
|
|
56
74
|
|
|
57
75
|
<div
|
|
58
76
|
id="{{ id }}"
|
|
59
77
|
class="select {{ main_attrs.class }}"
|
|
78
|
+
{% if multiple and placeholder %}data-placeholder="{{ placeholder }}"{% endif %}
|
|
60
79
|
{% for key, value in main_attrs %}
|
|
61
80
|
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
62
81
|
{% endfor %}
|
|
63
82
|
>
|
|
64
83
|
<button
|
|
65
84
|
type="button"
|
|
66
|
-
class="btn-outline
|
|
85
|
+
class="btn-outline {{ trigger_attrs.class }}"
|
|
67
86
|
id="{{ id }}-trigger"
|
|
68
87
|
aria-haspopup="listbox"
|
|
69
88
|
aria-expanded="false"
|
|
@@ -72,7 +91,7 @@
|
|
|
72
91
|
{% if key != 'class' %}{{ key }}="{{ value }}"{% endif %}
|
|
73
92
|
{% endfor %}
|
|
74
93
|
>
|
|
75
|
-
<span class="truncate">{{
|
|
94
|
+
<span class="truncate">{{ default_label }}</span>
|
|
76
95
|
{% if is_combobox %}
|
|
77
96
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevrons-up-down-icon lucide-chevrons-up-down text-muted-foreground opacity-50 shrink-0"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>
|
|
78
97
|
{% else %}
|
|
@@ -110,12 +129,13 @@
|
|
|
110
129
|
id="{{ id }}-listbox"
|
|
111
130
|
aria-orientation="vertical"
|
|
112
131
|
aria-labelledby="{{ id }}-trigger"
|
|
132
|
+
{% if multiple %}aria-multiselectable="true"{% endif %}
|
|
113
133
|
{% for key, value in listbox_attrs %}
|
|
114
134
|
{{ key }}="{{ value }}"
|
|
115
135
|
{% endfor %}
|
|
116
136
|
>
|
|
117
137
|
{% if items and items.length > 0 %}
|
|
118
|
-
{{ render_select_items(items,
|
|
138
|
+
{{ render_select_items(items, selectedArray, id ~ "-items" if id else "items") }}
|
|
119
139
|
{% else %}
|
|
120
140
|
{{ caller() if caller }}
|
|
121
141
|
{% endif %}
|
|
@@ -124,7 +144,7 @@
|
|
|
124
144
|
<input
|
|
125
145
|
type="hidden"
|
|
126
146
|
name="{{ name or id ~ '-value' }}"
|
|
127
|
-
value="{{ (default_option.value if default_option) or '' }}"
|
|
147
|
+
value="{% if multiple %}{{ selectedArray | dump }}{% else %}{{ (default_option.value if default_option) or '' }}{% endif %}"
|
|
128
148
|
{% for key, value in input_attrs %}
|
|
129
149
|
{% if key != 'name' and key != 'value' %}{{ key }}="{{ value }}"{% endif %}
|
|
130
150
|
{% endfor %}
|
|
@@ -138,7 +158,7 @@
|
|
|
138
158
|
@param items {array} - The array of items to render.
|
|
139
159
|
@param parent_id_prefix {string} [optional] - The prefix for the item id.
|
|
140
160
|
#}
|
|
141
|
-
{% macro render_select_items(items,
|
|
161
|
+
{% macro render_select_items(items, selectedArray, parent_id_prefix="items") %}
|
|
142
162
|
{% for item in items %}
|
|
143
163
|
{% set item_id = parent_id_prefix ~ "-" ~ loop.index %}
|
|
144
164
|
{% if item.type == "group" %}
|
|
@@ -153,7 +173,7 @@
|
|
|
153
173
|
{% endif %}
|
|
154
174
|
>
|
|
155
175
|
<div role="heading" id="{{ group_label_id }}">{{ item.label }}</div>
|
|
156
|
-
{{ render_select_items(item.items,
|
|
176
|
+
{{ render_select_items(item.items, selectedArray, item_id) if item.items }}
|
|
157
177
|
</div>
|
|
158
178
|
{% elif item.type == "separator" %}
|
|
159
179
|
<hr role="separator" />
|
|
@@ -161,8 +181,8 @@
|
|
|
161
181
|
<div
|
|
162
182
|
id="{{ item_id }}"
|
|
163
183
|
role="option"
|
|
164
|
-
data-value="{{ item.value }}"
|
|
165
|
-
{% if
|
|
184
|
+
{% if item.value is defined and item.value is not none %}data-value="{{ item.value }}"{% endif %}
|
|
185
|
+
{% if item.value in selectedArray %}aria-selected="true"{% endif %}
|
|
166
186
|
{% if item.attrs %}
|
|
167
187
|
{% for key, value in item.attrs %}
|
|
168
188
|
{{ key }}="{{ value }}"
|
|
@@ -173,4 +193,4 @@
|
|
|
173
193
|
</div>
|
|
174
194
|
{% endif %}
|
|
175
195
|
{% endfor %}
|
|
176
|
-
{% endmacro %}
|
|
196
|
+
{% endmacro %}
|