turbo_material 0.3.5 → 0.3.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/README.md +3 -3
- data/app/assets/javascripts/turbo_material/material_chips_input_controller.js +1 -1
- data/app/assets/javascripts/turbo_material/material_chips_select_controller.js +1 -1
- data/app/assets/javascripts/turbo_material/material_live_form_controller.js +8 -8
- data/app/views/components/_chips_input.html.erb +6 -4
- data/app/views/components/_data_table.html.erb +3 -1
- data/lib/turbo_material/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: e887895f2c786bca205c1f00509a2ab95fbdf6baaba8ec8c3dc40af37f7a61e4
|
|
4
|
+
data.tar.gz: a070313a7a84a7e9199bd56ec341aae636318131eae4637beb930e4cce189305
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2421ce96ea58b5e478bf18daa7a2b9b426a18f473de7e4b9f7f6a0a21ca0744c36e1e73ec9dfbed561ac45919894cc6b48c2d4736c3bfc9e13ee05b1f4f4ed87
|
|
7
|
+
data.tar.gz: dfdf9133262dc4ff964d0459f2c957d370e95d92c4dd454026c5e7ee78d990ab3696307f7e28658bc3938f85759a0a66f4ac68d48a9c3bf9450e2ddba4ccf003
|
data/README.md
CHANGED
|
@@ -414,7 +414,7 @@ Implements [Material Design Chips Input](https://github.com/material-components/
|
|
|
414
414
|
selected: [{ id: 1, label: 'Tag 1' }, { id: 2, label: 'Tag 2' }] %>
|
|
415
415
|
```
|
|
416
416
|
|
|
417
|
-
The hidden `name` field holds the comma-separated `id`s of the chips. Each `
|
|
417
|
+
The hidden `name` field holds the comma-separated `id`s of the chips. Each `options` entry needs an `id` and a `label`; `selected` entries take `id` or `value`, plus `label`. A blank `value:` option is ignored, so the hidden field still starts with the selected ids. The `url` endpoint receives `query`, `exclude` (current ids), `suffix`, `name` and `opened`, and responds with a Turbo Stream that re-renders `material_chips_input_options`.
|
|
418
418
|
|
|
419
419
|
#### Options
|
|
420
420
|
|
|
@@ -430,7 +430,7 @@ The hidden `name` field holds the comma-separated `id`s of the chips. Each `sele
|
|
|
430
430
|
| `suffix` | String | Suffix of the input |
|
|
431
431
|
| `type` | String | Type of the input |
|
|
432
432
|
| `url` | String | URL for fetching options |
|
|
433
|
-
| `selected` | Array | Selected chips, `[{ id:, label: }]` |
|
|
433
|
+
| `selected` | Array | Selected chips, `[{ id:, label: }]` or `[{ value:, label: }]` |
|
|
434
434
|
| `options` | Array | Available options, `[{ id:, label: }]` |
|
|
435
435
|
| `value` | String | Initial hidden value; defaults to the `selected` ids |
|
|
436
436
|
| `fixed` | Boolean | Whether the input is fixed |
|
|
@@ -488,7 +488,7 @@ Implements [Material Design Data Table](https://github.com/material-components/m
|
|
|
488
488
|
| `pagy` | Object | Pagy object for pagination |
|
|
489
489
|
| `table_headers_partial` | String | Partial name for table headers |
|
|
490
490
|
| `table_contents_partial` | String | Partial name for table contents |
|
|
491
|
-
| `per_page_options` | Array | Rows-per-page choices, `[{ value:, label: }]
|
|
491
|
+
| `per_page_options` | Array | Rows-per-page choices, `[{ value:, label: }]`. Defaults to the host's `per_page_options` helper if it has one, else 10/25/50/100 |
|
|
492
492
|
|
|
493
493
|
The rows-per-page form uses the gem's `material-live-form` Stimulus controller: it submits on change (debounced 2s for text input, configurable with `data-material-live-form-delay-value`) and keeps focus and caret position across the Turbo re-render. Rows need `data-row-id`. Selecting rows sends `PUT <url>/<row id>/select` and `PUT <url>/select_all`; sorting visits `<url>?order=<column>&reverse=<bool>`.
|
|
494
494
|
|
|
@@ -62,7 +62,7 @@ export default class extends Controller {
|
|
|
62
62
|
|
|
63
63
|
// Read chips from the DOM so server-rendered `selected` chips count too.
|
|
64
64
|
syncHidden() {
|
|
65
|
-
this.hiddenTarget.value = Array.from(this.chipsetEl.querySelectorAll('.mdc-chip[data-value]'), (chip) => chip.dataset.value).join(',');
|
|
65
|
+
this.hiddenTarget.value = Array.from(this.chipsetEl.querySelectorAll('.mdc-chip[data-value]'), (chip) => chip.dataset.value).filter(Boolean).join(',');
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
open() {
|
|
@@ -91,7 +91,7 @@ export default class extends Controller {
|
|
|
91
91
|
// Read chips from the DOM: MDCChipSet.chipsList keeps chips removed with removeChild.
|
|
92
92
|
syncHidden() {
|
|
93
93
|
if (!this.hasHiddenTarget) return;
|
|
94
|
-
this.hiddenTarget.value = Array.from(this.chipsetEl.querySelectorAll('.mdc-chip[data-value]'), (chip) => chip.dataset.value).join(',');
|
|
94
|
+
this.hiddenTarget.value = Array.from(this.chipsetEl.querySelectorAll('.mdc-chip[data-value]'), (chip) => chip.dataset.value).filter(Boolean).join(',');
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
toggle(event) {
|
|
@@ -17,13 +17,13 @@ export default class extends Controller {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
connect() {
|
|
20
|
-
if (window.
|
|
21
|
-
window.
|
|
20
|
+
if (window.materialLiveForm === undefined) {
|
|
21
|
+
window.materialLiveForm = {}
|
|
22
22
|
document.addEventListener('turbo:submit-start', this.submitStart)
|
|
23
23
|
document.addEventListener('turbo:submit-end', this.submitEnd)
|
|
24
|
-
} else if (window.
|
|
25
|
-
this.restoreFocus(window.
|
|
26
|
-
window.
|
|
24
|
+
} else if (window.materialLiveForm.focused) {
|
|
25
|
+
this.restoreFocus(window.materialLiveForm.focused, window.materialLiveForm.selectionStart, window.materialLiveForm.selectionEnd)
|
|
26
|
+
window.materialLiveForm = {}
|
|
27
27
|
}
|
|
28
28
|
this.element.classList.add('live-form');
|
|
29
29
|
}
|
|
@@ -41,9 +41,9 @@ export default class extends Controller {
|
|
|
41
41
|
submitEnd() {
|
|
42
42
|
document.body.classList.remove('turbo-loading')
|
|
43
43
|
const active = document.activeElement || document.body
|
|
44
|
-
window.
|
|
45
|
-
window.
|
|
46
|
-
window.
|
|
44
|
+
window.materialLiveForm.selectionStart = active.selectionStart
|
|
45
|
+
window.materialLiveForm.selectionEnd = active.selectionEnd
|
|
46
|
+
window.materialLiveForm.focused = active.id
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
restoreFocus(focusedId, selectionStart, selectionEnd) {
|
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
<span class="mdc-text-field__ripple"></span>
|
|
14
14
|
<span id="<%= id %>-label" class="mdc-floating-label top-6!"><%= label %></span>
|
|
15
15
|
<div class="mdc-chip-set mdc-chip-set--input pt-8! w-full" role="grid">
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
<%# selected chips may use :id (like options) or :value %>
|
|
17
|
+
<%- selected_ids = selected.map { |chip| chip[:id] || chip[:value] } -%>
|
|
18
|
+
<%- selected.zip(selected_ids).each do |chip, chip_id| -%>
|
|
19
|
+
<div class="mdc-chip" data-value="<%= chip_id %>">
|
|
18
20
|
<div class="mdc-chip__text"><%= chip[:label] %></div>
|
|
19
21
|
<i class="material-icons mdc-chip__icon mdc-chip__icon--trailing" tabindex="0" role="button"
|
|
20
|
-
data-action="click->material-chips-input#removeChip" data-value="<%=
|
|
22
|
+
data-action="click->material-chips-input#removeChip" data-value="<%= chip_id %>">cancel</i>
|
|
21
23
|
</div>
|
|
22
24
|
<%- end -%>
|
|
23
|
-
<%= form.hidden_field name.to_sym, value: value ||
|
|
25
|
+
<%= form.hidden_field name.to_sym, value: value.presence || selected_ids.compact_blank.join(','), data: { 'material-chips-input-target': 'hidden' } %>
|
|
24
26
|
<%= form.text_field "#{name}_".to_sym,
|
|
25
27
|
class: 'mdc-text-field__input', value: nil,
|
|
26
28
|
id: id, 'aria-labelledby' => id + '-label',
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
<%# locals: (name:, table_body:, url:, table_params:, records:, selected_records:, pagy:, table_headers_partial:, table_contents_partial:, per_page_options:
|
|
1
|
+
<%# locals: (name:, table_body:, url:, table_params:, records:, selected_records:, pagy:, table_headers_partial:, table_contents_partial:, per_page_options: nil) %>
|
|
2
|
+
<%# the local shadows a host `per_page_options` helper, so fall back to it explicitly %>
|
|
3
|
+
<%- per_page_options ||= respond_to?(:per_page_options) ? self.per_page_options : [10, 25, 50, 100].map { |n| { value: n, label: n.to_s } } -%>
|
|
2
4
|
<div class="mdc-data-table w-full" data-controller="material-data-table"
|
|
3
5
|
data-material-data-table-body-value="<%= table_body %>"
|
|
4
6
|
data-material-data-table-url-value="<%= url %>"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module TurboMaterial
|
|
4
|
-
VERSION = '0.3.
|
|
4
|
+
VERSION = '0.3.6'
|
|
5
5
|
MDC_VERSION = '14.0.0'
|
|
6
6
|
# SRI for MDC_VERSION's dist/*.min.{css,js}: "hash" (base64 SHA-256) from
|
|
7
7
|
# https://data.jsdelivr.com/v1/packages/npm/material-components-web@<version>. Update with MDC_VERSION.
|