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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d849c4052043a8f97f28b63570bf575b416400c6546d7c58d15b956926a852c5
4
- data.tar.gz: fececa0b9159f4b469d39f7006b28d3d33acce302a3c9b610e70d13b014a8747
3
+ metadata.gz: e887895f2c786bca205c1f00509a2ab95fbdf6baaba8ec8c3dc40af37f7a61e4
4
+ data.tar.gz: a070313a7a84a7e9199bd56ec341aae636318131eae4637beb930e4cce189305
5
5
  SHA512:
6
- metadata.gz: c4c079e3d67ce542b61b0eb49d220003659bb0e9f857dac5a86b2471b9b5d191edcf1e6d6d9b00fe05b4ebe9af25a05afeb307d00ccc4052f24c601f5f5b9629
7
- data.tar.gz: 771df3933b837efc574c93aa1df9f250e1b96794b2854fd115b349720df8c1186ec26531c82cb995412be5ae083ed54100c0f2fed67d0590c6a4daf59185276b
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 `selected` and `options` entry needs an `id` and a `label`. 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`.
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: }]`; default 10/25/50/100 |
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.liveForm === undefined) {
21
- window.liveForm = {}
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.liveForm.focused) {
25
- this.restoreFocus(window.liveForm.focused, window.liveForm.selectionStart, window.liveForm.selectionEnd)
26
- window.liveForm = {}
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.liveForm.selectionStart = active.selectionStart
45
- window.liveForm.selectionEnd = active.selectionEnd
46
- window.liveForm.focused = active.id
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
- <%- selected.each do |chip| -%>
17
- <div class="mdc-chip" data-value="<%= chip[:id] %>">
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="<%= chip[:id] %>">cancel</i>
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 || selected.map { |chip| chip[:id] }.join(','), data: { 'material-chips-input-target': 'hidden' } %>
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: [10, 25, 50, 100].map { |n| { value: n, label: n.to_s } }) %>
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.5'
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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_material
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Moiseev