keystone_ui 0.59.0 → 0.61.0

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: fa286726a479f478774e33da15f8ec93767df8e20227a6280e3835e575740333
4
- data.tar.gz: f1e259b398cca001b2174f90ebfe5ed0a9810ea7a9fc5f965d8c7c8abf55eb58
3
+ metadata.gz: 1162e3083759cf27249c3868a38a062293ef0d2eb810f05638949dfecb32df98
4
+ data.tar.gz: edf6931a9e8ec09beb70e6b40397cf4cfa1bcb63fdcfb45f0526ccb84a41b652
5
5
  SHA512:
6
- metadata.gz: b6ae5646277a7ddac4b926f709efaac74f4f3097c83cbb07ac8d24ac7a468e31086ba91327eef2da4b9fcaedfb384b8c64f4c22f663343294c3051481ec013e2
7
- data.tar.gz: f27bd1e717b7e0604480eec0d8500f18dfcbcac1dbe4ca8489fe468c0b1e33c1cde6aa807b8fbd6a71513afe2c3cc4ec4d50e73da9135d02eea0623fa28b3199
6
+ metadata.gz: 0bc9dbdbf3b83401432103e6781c30dc8736957f139ace11f2475d71a5a4ee9d69f307b91c93a5494c5853c01877fb7ea6ca7576dea00a468fb7265981cac0db
7
+ data.tar.gz: '083b71c45bad44f4af0b3a581d7f7c2e73ae39eb63036590dd0bb9f97e8904f6d57cb08f72a1254ef935f386c097c461386e8e7cc47e27694dd0a6eae69c361a'
@@ -2,6 +2,7 @@ import ColorPickerController from "keystone_ui/color_picker_controller"
2
2
  import MultiSelectController from "keystone_ui/multi_select_controller"
3
3
  import SearchSelectController from "keystone_ui/search_select_controller"
4
4
  import SwipeDeckController from "keystone_ui/swipe_deck_controller"
5
+ import SortableListController from "keystone_ui/sortable_list_controller"
5
6
  import ColumnPickerController from "keystone_ui/column_picker_controller"
6
7
  import FileUploadController from "keystone_ui/file_upload_controller"
7
8
  import DropdownController from "keystone_ui/dropdown_controller"
@@ -23,6 +24,7 @@ export function registerControllers(application) {
23
24
  application.register("multi-select", MultiSelectController)
24
25
  application.register("search-select", SearchSelectController)
25
26
  application.register("swipe-deck", SwipeDeckController)
27
+ application.register("sortable-list", SortableListController)
26
28
  application.register("column-picker", ColumnPickerController)
27
29
  application.register("file-upload", FileUploadController)
28
30
  application.register("dropdown", DropdownController)
@@ -40,4 +42,4 @@ export function registerControllers(application) {
40
42
  keepPageThemeInStep()
41
43
  }
42
44
 
43
- export { ColorPickerController, MultiSelectController, SwipeDeckController, ColumnPickerController, FileUploadController, DropdownController, DismissController, ModalController, ClipboardController, TabSwitcherController, AccordionController, StatCardInfoController, InfoController, AutoSubmitController, LineChartController }
45
+ export { ColorPickerController, MultiSelectController, SwipeDeckController, SortableListController, ColumnPickerController, FileUploadController, DropdownController, DismissController, ModalController, ClipboardController, TabSwitcherController, AccordionController, StatCardInfoController, InfoController, AutoSubmitController, LineChartController }
@@ -0,0 +1,61 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ["row", "control", "status"]
5
+
6
+ connect() {
7
+ this.controlTargets.forEach((control) => { control.hidden = false })
8
+ }
9
+
10
+ moveUp({ currentTarget }) {
11
+ const row = this.rowHolding(currentTarget)
12
+ const previous = row.previousElementSibling
13
+ if (previous) row.after(previous)
14
+ this.announce(row)
15
+ }
16
+
17
+ moveDown({ currentTarget }) {
18
+ const row = this.rowHolding(currentTarget)
19
+ const next = row.nextElementSibling
20
+ if (next) row.before(next)
21
+ this.announce(row)
22
+ }
23
+
24
+ grab({ currentTarget, pointerId, button }) {
25
+ if (button !== 0 || this.dragged) return
26
+
27
+ currentTarget.setPointerCapture(pointerId)
28
+ this.draggingPointer = pointerId
29
+ this.dragged = this.rowHolding(currentTarget)
30
+ this.startingIndex = this.rowTargets.indexOf(this.dragged)
31
+ this.dragged.dataset.dragging = "true"
32
+ }
33
+
34
+ drag({ clientY, pointerId }) {
35
+ const row = this.dragged
36
+ if (!row || pointerId !== this.draggingPointer) return
37
+ while (row.nextElementSibling && clientY > this.middleOf(row.nextElementSibling)) row.before(row.nextElementSibling)
38
+ while (row.previousElementSibling && clientY < this.middleOf(row.previousElementSibling)) row.after(row.previousElementSibling)
39
+ }
40
+
41
+ drop({ pointerId }) {
42
+ if (!this.dragged || pointerId !== this.draggingPointer) return
43
+ if (this.rowTargets.indexOf(this.dragged) !== this.startingIndex) this.announce(this.dragged)
44
+ delete this.dragged.dataset.dragging
45
+ this.dragged = null
46
+ }
47
+
48
+ middleOf(row) {
49
+ const { top, height } = row.getBoundingClientRect()
50
+ return top + height / 2
51
+ }
52
+
53
+ announce(row) {
54
+ const rows = this.rowTargets
55
+ this.statusTarget.textContent = `${row.dataset.label} is number ${rows.indexOf(row) + 1} of ${rows.length}.`
56
+ }
57
+
58
+ rowHolding(element) {
59
+ return element.closest('[data-sortable-list-target="row"]')
60
+ }
61
+ }
@@ -5,9 +5,10 @@ module Keystone
5
5
  class Column
6
6
  attr_reader :key, :header_text, :align
7
7
 
8
- def initialize(key, header_text, mobile_hidden: false, sortable: false, hideable: false, locked: false, align: nil)
8
+ def initialize(key, header_text, mobile_hidden: false, sortable: false, hideable: false, locked: false, align: nil, wrap: false)
9
9
  @key = key
10
10
  @align = align
11
+ @wrap = wrap
11
12
  @header_text = header_text
12
13
  @mobile_hidden = mobile_hidden
13
14
  @sortable = sortable
@@ -19,6 +20,7 @@ module Keystone
19
20
  def sortable? = @sortable
20
21
  def hideable? = @hideable && !@locked
21
22
  def locked? = @locked
23
+ def wrap? = @wrap
22
24
  end
23
25
  end
24
26
  end
@@ -133,7 +133,7 @@ module Keystone
133
133
 
134
134
  cell = {
135
135
  value: resolve_value(item, column.key),
136
- classes: aligned(tokens.join(" "), column)
136
+ classes: wrapped(aligned(tokens.join(" "), column), column)
137
137
  }
138
138
 
139
139
  link_block = @link_blocks[column.key]
@@ -208,6 +208,12 @@ module Keystone
208
208
  [ *classes.split.grep_v(/\Atext-(left|right)\z/), ALIGN_CLASSES.fetch(column.align) ].join(" ")
209
209
  end
210
210
 
211
+ def wrapped(classes, column)
212
+ return classes unless column.wrap?
213
+
214
+ classes.sub("whitespace-nowrap", "whitespace-normal")
215
+ end
216
+
211
217
  def resolve_value(item, key)
212
218
  if item.respond_to?(key)
213
219
  item.public_send(key)
@@ -0,0 +1,26 @@
1
+ <div data-controller="sortable-list">
2
+ <ul aria-label="<%= @label %>">
3
+ <% @rows.each do |row| %>
4
+ <li class="<%= ROW_CLASSES %>" data-sortable-list-target="row" data-label="<%= row[:label] %>">
5
+ <input type="hidden" name="<%= @name %>" value="<%= row[:id] %>">
6
+ <span hidden data-sortable-list-target="control" class="<%= HANDLE_CLASSES %>" data-action="pointerdown->sortable-list#grab pointermove->sortable-list#drag pointerup->sortable-list#drop pointercancel->sortable-list#drop">
7
+ <svg class="<%= ICON_CLASSES %>" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
8
+ <path stroke-linecap="round" d="M4 8h16M4 16h16" />
9
+ </svg>
10
+ </span>
11
+ <span class="<%= LABEL_CLASSES %>"><%= row[:label] %></span>
12
+ <button hidden data-sortable-list-target="control" type="button" class="<%= MOVE_BUTTON_CLASSES %>" aria-label="Move <%= row[:label] %> up" data-action="sortable-list#moveUp">
13
+ <svg class="<%= ICON_CLASSES %>" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
14
+ <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 15.75 7.5-7.5 7.5 7.5" />
15
+ </svg>
16
+ </button>
17
+ <button hidden data-sortable-list-target="control" type="button" class="<%= MOVE_BUTTON_CLASSES %>" aria-label="Move <%= row[:label] %> down" data-action="sortable-list#moveDown">
18
+ <svg class="<%= ICON_CLASSES %>" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
19
+ <path stroke-linecap="round" stroke-linejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" />
20
+ </svg>
21
+ </button>
22
+ </li>
23
+ <% end %>
24
+ </ul>
25
+ <div role="status" class="<%= STATUS_CLASSES %>" data-sortable-list-target="status"></div>
26
+ </div>
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class SortableListComponent < ViewComponent::Base
6
+ ROW_CLASSES = "ks-value-list-row items-center data-dragging:opacity-50"
7
+ LABEL_CLASSES = "ks-paragraph min-w-0 flex-1"
8
+ HANDLE_CLASSES = "ks-tone-muted flex size-11 shrink-0 cursor-grab touch-none select-none items-center justify-center"
9
+ MOVE_BUTTON_CLASSES = "ks-button ks-button-secondary ks-button-sm size-11 shrink-0"
10
+ ICON_CLASSES = "size-5"
11
+ STATUS_CLASSES = "sr-only"
12
+
13
+ def initialize(name:, label:, rows:)
14
+ @name = name
15
+ @label = label
16
+ @rows = rows
17
+ end
18
+ end
19
+ end
20
+ end
@@ -205,6 +205,10 @@ module KeystoneUiHelper
205
205
  render Keystone::Ui::SwipeDeckComponent.new(**args), &block
206
206
  end
207
207
 
208
+ def ui_sortable_list(**args)
209
+ render Keystone::Ui::SortableListComponent.new(**args)
210
+ end
211
+
208
212
  def ui_column_picker(**args)
209
213
  render Keystone::Ui::ColumnPickerComponent.new(**args)
210
214
  end
data/config/importmap.rb CHANGED
@@ -3,6 +3,7 @@ pin "keystone_ui/color_picker_controller", to: "keystone_ui/color_picker_control
3
3
  pin "keystone_ui/multi_select_controller", to: "keystone_ui/multi_select_controller.js"
4
4
  pin "keystone_ui/search_select_controller", to: "keystone_ui/search_select_controller.js"
5
5
  pin "keystone_ui/swipe_deck_controller", to: "keystone_ui/swipe_deck_controller.js"
6
+ pin "keystone_ui/sortable_list_controller", to: "keystone_ui/sortable_list_controller.js"
6
7
  pin "keystone_ui/column_picker_controller", to: "keystone_ui/column_picker_controller.js"
7
8
  pin "keystone_ui/file_upload_controller", to: "keystone_ui/file_upload_controller.js"
8
9
  pin "keystone_ui/dropdown_controller", to: "keystone_ui/dropdown_controller.js"
@@ -58,6 +58,7 @@ module Keystone
58
58
  Keystone::Ui::ColorPickerComponent,
59
59
  Keystone::Ui::MultiSelectComponent,
60
60
  Keystone::Ui::SwipeDeckComponent,
61
+ Keystone::Ui::SortableListComponent,
61
62
  Keystone::Ui::ColumnPickerComponent,
62
63
  Keystone::Ui::FormComponent,
63
64
  Keystone::Ui::FileUploadComponent,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.59.0"
4
+ VERSION = "0.61.0"
5
5
  end
@@ -58,6 +58,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
58
58
  - `ui_color_picker` — a colour swatch that writes a hex value into a hidden input.
59
59
  - `ui_radio_card` — a selectable card backed by a radio input.
60
60
  - `ui_checkbox_row` — a checkbox with its label and hint, toggled by a tap anywhere on the row.
61
+ - `ui_sortable_list` — a list of rows dragged into a new order, submitted with the form it sits in.
61
62
  - `ui_option_card` — a radio whose visible body is whatever its block renders.
62
63
  - `ui_data_table` — a table of records with links, row actions, sorting, hideable columns and the viewer's own row marked.
63
64
  - `Keystone::Ui::Column` — a table column with options a `{ key: "Label" }` hash cannot carry.
@@ -385,6 +386,14 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
385
386
  - A checked `ui_checkbox_row` submits `value` under `name`, an unchecked one
386
387
  submits nothing, and rows sharing an array name such as `"shown[]"`
387
388
  submit the checked values as a list.
389
+ - `ui_sortable_list(name:, label:, rows:)` is one field inside a `ui_form`,
390
+ for putting a short list in order. `rows:` is an array of
391
+ `{ id:, label: }` hashes, `label:` names the list for screen readers, and
392
+ `name:` names a hidden field in each row, so pass an array name such as
393
+ `"order[]"` and a different one for each list on a page. The form submits
394
+ the ids in the order shown, and the list makes no request of its own. A
395
+ row is dragged by its handle, or moved with its Move up and Move down
396
+ buttons. Without JavaScript the form submits the starting order.
388
397
  - `ui_option_card(name:, value:, selected: false, input_data: {}, label_data: {})`
389
398
  takes a block rendering the card's body. `input_data:` and `label_data:`
390
399
  become `data-*` attributes on the input and the label.
@@ -420,9 +429,12 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
420
429
  - `columns:` takes `{ key: "Label" }` hashes when every column is plain.
421
430
  Switch the whole set to `Keystone::Ui::Column` objects once one column
422
431
  needs an option.
423
- - `Keystone::Ui::Column.new(key, header_text, mobile_hidden: false, sortable: false, hideable: false, locked: false, align: nil)`
432
+ - `Keystone::Ui::Column.new(key, header_text, mobile_hidden: false, sortable: false, hideable: false, locked: false, align: nil, wrap: false)`
424
433
  — `mobile_hidden:` hides the column below `sm:`, `sortable:` gives it a
425
434
  sort header, and `hideable:` lets it be hidden and moved.
435
+ `wrap: true` lets long text in the column's cells wrap onto more lines
436
+ inside the cell instead of widening the table, every other cell keeps its
437
+ text on one line, and headings are unchanged.
426
438
  `locked: true` on the first column keeps it in view while the rest scrolls
427
439
  sideways, a locked column that is not first renders as an ordinary one,
428
440
  and a locked column is never hideable. Ask the developer whether a wide
@@ -55,6 +55,7 @@ develop:
55
55
  - ui_multi_select
56
56
  - ui_search_select
57
57
  - ui_swipe_deck
58
+ - ui_sortable_list
58
59
  - ui_column_picker
59
60
  - ui_form
60
61
  - ui_file_upload
@@ -165,6 +166,8 @@ sources:
165
166
  - app/components/keystone/ui/settings_link_component.rb
166
167
  - app/components/keystone/ui/show_page_component.rb
167
168
  - app/components/keystone/ui/show_page_component.html.erb
169
+ - app/components/keystone/ui/sortable_list_component.rb
170
+ - app/components/keystone/ui/sortable_list_component.html.erb
168
171
  - app/components/keystone/ui/stat_card_component.rb
169
172
  - app/components/keystone/ui/stat_card_component.html.erb
170
173
  - app/components/keystone/ui/swipe_deck_component.rb
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.59.0
4
+ version: 0.61.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -68,6 +68,7 @@ files:
68
68
  - app/assets/javascripts/keystone_ui/multi_select_controller.js
69
69
  - app/assets/javascripts/keystone_ui/page_theme.js
70
70
  - app/assets/javascripts/keystone_ui/search_select_controller.js
71
+ - app/assets/javascripts/keystone_ui/sortable_list_controller.js
71
72
  - app/assets/javascripts/keystone_ui/stat_card_info_controller.js
72
73
  - app/assets/javascripts/keystone_ui/swipe_deck_controller.js
73
74
  - app/assets/javascripts/keystone_ui/tab_switcher_controller.js
@@ -198,6 +199,8 @@ files:
198
199
  - app/components/keystone/ui/settings_link_component.rb
199
200
  - app/components/keystone/ui/show_page_component.html.erb
200
201
  - app/components/keystone/ui/show_page_component.rb
202
+ - app/components/keystone/ui/sortable_list_component.html.erb
203
+ - app/components/keystone/ui/sortable_list_component.rb
201
204
  - app/components/keystone/ui/stat_card_component.html.erb
202
205
  - app/components/keystone/ui/stat_card_component.rb
203
206
  - app/components/keystone/ui/swipe_deck_component.html.erb