keystone_ui 0.83.0 → 0.85.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: 67a56427f22ff9c7ae35a6c75cb9b093685ad735f4aa74d6369becb3cfd43a7c
4
- data.tar.gz: 2d62089b40ae9778a19603c4ef693aa3a97742defe3b7d54d15dc0b46702622f
3
+ metadata.gz: 85457be1129db7d375f22f600c702f0c2d75c8d93e1dbb9443cbf6c59ab57294
4
+ data.tar.gz: 677ef89d8e94bf3fc4a8fd46df2ce7d7e99e91766bdc6ffee2bcc19c1c293e2f
5
5
  SHA512:
6
- metadata.gz: d5fed99a13700d260fcfbc176eb29c4a1292711a3452524f5022b2a0865dabacccb417391a1e8594e49cae99e8ec87178c836915b955cdc61f82f3fa736fc636
7
- data.tar.gz: a629ce6735d60acd71d5adf22fd0b03837b3b18344cc00938225762c08551e29c7fa6132d08956148fc564d48ec74884783751189c827e0f3ba3a0bfe35b87d3
6
+ metadata.gz: bc60e2d038b07b075cef52782834681100eb2c3e7814e600f11db7f7e7d3045f3ece2067799039cc94e1a6eea2b88c43cee24c24238db589b67e1f399ddbedfe
7
+ data.tar.gz: 00432aab92887c8f5d5e2ad30f80cb9a3c3b2a05513987731058e6adfebee1c84ea454963c624e022585ee17af8e38f7dc7abc38d89bf1d20a5f861cf9e50ed8
@@ -3,13 +3,7 @@
3
3
  module Keystone
4
4
  module Ui
5
5
  class BadgeComponent < ViewComponent::Base
6
- VARIANT_CLASSES = {
7
- neutral: "ks-badge-neutral",
8
- success: "ks-badge-success",
9
- danger: "ks-badge-danger",
10
- warning: "ks-badge-warning",
11
- info: "ks-badge-info"
12
- }.freeze
6
+ VARIANT_CLASSES = States::NAMES.to_h { |state| [ state, "ks-badge-#{state}" ] }.freeze
13
7
 
14
8
  attr_reader :label
15
9
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ module States
6
+ NAMES = %i[neutral success danger warning info].freeze
7
+ end
8
+ end
9
+ end
@@ -3,13 +3,7 @@
3
3
  module Keystone
4
4
  module Ui
5
5
  class StatusDotComponent < ViewComponent::Base
6
- STATE_CLASSES = {
7
- neutral: "ks-status-dot-neutral",
8
- success: "ks-status-dot-success",
9
- danger: "ks-status-dot-danger",
10
- warning: "ks-status-dot-warning",
11
- info: "ks-status-dot-info"
12
- }.freeze
6
+ STATE_CLASSES = States::NAMES.to_h { |state| [ state, "ks-status-dot-#{state}" ] }.freeze
13
7
 
14
8
  LABEL_CLASSES = "sr-only"
15
9
 
@@ -1,4 +1,7 @@
1
1
  <div class="<%= Keystone::Ui::TextDiffComponent::WRAPPER_CLASSES %>">
2
+ <% if notice %>
3
+ <div class="<%= Keystone::Ui::TextDiffComponent::NOTICE_CLASSES %>" data-diff-notice><%= notice %></div>
4
+ <% end %>
2
5
  <div class="<%= Keystone::Ui::TextDiffComponent::COLUMNS_CLASSES %>">
3
6
  <% Keystone::Ui::TextDiffComponent::SIDES.each do |side| %>
4
7
  <div class="<%= Keystone::Ui::TextDiffComponent::SIDE_CLASSES %>" data-diff-side="<%= side %>">
@@ -11,12 +11,25 @@ module Keystone
11
11
  NUMBER_CLASSES = "w-8 shrink-0 select-none text-right"
12
12
  SIGN_CLASSES = "w-6 shrink-0 select-none text-center"
13
13
  TEXT_CLASSES = "whitespace-pre"
14
+ NOTICE_CLASSES = "ks-code-caption text-xs"
14
15
 
15
16
  def initialize(before:, after:)
16
17
  @before = before.to_s.lines(chomp: true)
17
18
  @after = after.to_s.lines(chomp: true)
18
19
  end
19
20
 
21
+ def notice
22
+ if @before == @after
23
+ "These texts are the same."
24
+ elsif too_long?
25
+ "These texts are too long to compare."
26
+ end
27
+ end
28
+
29
+ def too_long?
30
+ @before.size + @after.size > KeystoneUi.configuration.text_diff_line_limit
31
+ end
32
+
20
33
  def cells(side)
21
34
  rows.map { |row| row[SIDES.index(side)] }
22
35
  end
@@ -24,7 +37,13 @@ module Keystone
24
37
  private
25
38
 
26
39
  def rows
27
- @rows ||= compare
40
+ @rows ||= too_long? ? side_by_side : compare
41
+ end
42
+
43
+ def side_by_side
44
+ Array.new([ @before.size, @after.size ].max) do |index|
45
+ [ @before, @after ].map { |version| { text: version[index], number: index + 1 } if index < version.size }
46
+ end
28
47
  end
29
48
 
30
49
  def compare
@@ -4,12 +4,13 @@ require "keystone_ui/navigation_group"
4
4
 
5
5
  module KeystoneUi
6
6
  class Configuration
7
- attr_accessor :accent, :surface, :theme_mode_supplier, :look_supplier, :trail_supplier, :preference_supplier, :current_tab_supplier
7
+ attr_accessor :accent, :surface, :theme_mode_supplier, :look_supplier, :trail_supplier, :preference_supplier, :current_tab_supplier, :text_diff_line_limit
8
8
  attr_reader :tailwind_imports, :tailwind_sources, :looks, :default_look, :navigation_groups
9
9
 
10
10
  def initialize
11
11
  @accent = :blue
12
12
  @surface = :zinc
13
+ @text_diff_line_limit = 2000
13
14
  @tailwind_imports = []
14
15
  @tailwind_sources = []
15
16
  @looks = {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.83.0"
4
+ VERSION = "0.85.0"
5
5
  end
@@ -625,13 +625,15 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
625
625
  `full_size_url:`, tapping the picture opens that address in a new tab, so
626
626
  pass `src:` a smaller version and `full_size_url:` the original file. Ask
627
627
  the developer which version of an uploaded image each address points at.
628
- - `ui_badge(label:, variant: :neutral, class: nil)` — `variant:` is
629
- `:neutral` `:success` `:danger` `:warning` `:info`.
630
- - `ui_status_dot(state:, label:)` — `state:` is `:neutral` `:success`
631
- `:danger` `:warning` `:info`, and any other value raises `ArgumentError`
628
+ - `ui_badge(label:, variant: :neutral, class: nil)` — `variant:` is one of
629
+ the five states `:neutral` `:success` `:danger` `:warning` `:info`, and
630
+ any other value raises `KeyError` naming it when the badge is drawn.
631
+ - `ui_status_dot(state:, label:)` — `state:` is one of the same five states
632
+ a badge's `variant:` takes, and any other value raises `ArgumentError`
632
633
  naming it. `label:` is not shown on screen and is read out by screen
633
634
  readers, so pass words that say what the state means. The dot takes the
634
- colour of a `ui_badge` of the same name. Use it where a badge's words
635
+ colour of a `ui_badge` of the same state, so a record's state can be
636
+ passed to either one unchanged. Use it where a badge's words
635
637
  would crowd the row, such as beside a name in a list, and ask the
636
638
  developer which states a record has and what each one means.
637
639
  - `ui_alert(message:, type: :info, title: nil, dismissible: false, class: nil)`
@@ -660,11 +662,22 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
660
662
  blank row opposite, so a changed line shows as a removed row followed by
661
663
  an added row. Each column numbers its own lines, and a long line scrolls
662
664
  sideways inside its column. Lines must match exactly, spaces included, to
663
- count as shared. A `nil` text is treated as empty, and both are shown as
664
- plain text. The work grows with the line count of one text times the
665
- other's, so pass texts a person reads, not whole files of thousands of
666
- lines. Ask the developer which two versions a screen compares and which
667
- is the earlier one.
665
+ count as shared, apart from their line endings, so a line ending in a
666
+ Windows line break matches the same line ending in a Unix one. A `nil`
667
+ text is treated as empty, and both are shown as plain text.
668
+ - When the two texts hold the same lines, including two empty texts, a
669
+ notice above the columns reads "These texts are the same." and no row is
670
+ marked.
671
+ - When the two texts together hold more lines than the app's line limit,
672
+ 2,000 unless the app's keystone_ui configuration sets another, it does not
673
+ compare them. It shows "These texts are too long to compare." above the
674
+ columns and draws line 1 beside line 1, line 2 beside line 2 and so on,
675
+ with no row marked and no `-` or `+`. The notice wording is fixed. Ask the
676
+ developer whether a screen can be given texts that long, and hand changing
677
+ the limit to `keystone_ui-install`, since the comparison's work grows with
678
+ the line count of one text times the other's.
679
+ - Ask the developer which two versions a screen compares and which is the
680
+ earlier one.
668
681
  - `ui_disclosure(open: false)` takes a block yielding the component. Fill
669
682
  its `summary` slot with the header, and the rest of the block is the body.
670
683
  - `ui_accordion(items: [])` — `items:` is `[{ question:, answer: }, ...]`.
@@ -31,7 +31,8 @@ This local declares no commands. The working surfaces belong to the other two:
31
31
 
32
32
  - **Getting the gem into a host app** — the install generator, the
33
33
  configuration block, the theme and look attributes on the layout, the palette,
34
- registered looks, the navigation groups, and the suppliers for trails, themes,
34
+ registered looks, the navigation groups, the text diff's line limit, and the
35
+ suppliers for trails, themes,
35
36
  looks, the current tab and saved preferences → **`keystone_ui-install`**.
36
37
  - **Building screens with it** — which helper renders what, the keywords each
37
38
  takes, and how they nest → **`keystone_ui-develop`**.
@@ -129,18 +130,25 @@ One decision: is keystone_ui set up in the app?
129
130
  - **Action menus.** Each action is a label, an address and an HTTP method. A
130
131
  plain visit is a link, and any other method is a button, so an action that
131
132
  changes data is never a bare link. A delete asks for confirmation by default.
132
- - **Status states.** A badge and a status dot share five states: neutral,
133
- success, danger, warning and info. A badge shows its label as text. A status
134
- dot shows only its state's colour, for places with no room for text, and its label
135
- is read only by screen readers. A status dot raises `ArgumentError` on any
136
- other state.
133
+ - **Status states.** A badge and a status dot read one list of five states:
134
+ neutral, success, danger, warning and info. A state added to that list is
135
+ accepted by both, so the two never disagree about which states exist. A badge
136
+ shows its label as text. A status dot shows only its state's colour, for
137
+ places with no room for text, and its label is read only by screen readers.
138
+ Neither accepts a state outside the list: a status dot raises `ArgumentError`
139
+ naming the states it expects, and a badge raises `KeyError` when it renders.
137
140
  - **Text diffs.** A text diff compares two texts line by line and shows them
138
141
  side by side, stacked on a phone, in the code block's look. Lines the two
139
142
  share sit on the same row, a line only the first text has is marked removed
140
143
  with a minus, a line only the second has is marked added with a plus, the
141
144
  other side shows a blank row beside either one, and each side numbers its own
142
- lines. On a phone the first text's column sits above the second's. It compares whole lines, so a line with one word
143
- changed shows as one line removed and one added.
145
+ lines. On a phone the first text's column sits above the second's. It
146
+ compares whole lines, so a line with one word changed shows as one line
147
+ removed and one added. Windows and Unix line endings compare as equal. Two
148
+ identical texts show a notice saying they are the same above the columns.
149
+ When the two texts together hold more lines than the host's line limit, 2,000
150
+ by default, it does not compare them: it lines them up by position with no
151
+ marks or signs, and the notice says they are too long to compare.
144
152
  - **Semantic colour.** The themed hue is `accent-*` and the themed neutrals are
145
153
  `surface-*`, CSS custom properties whose defaults (blue and zinc) come from
146
154
  the keystone_ui-styles gem. Retheming changes those values, not the
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: keystone_ui-install
3
- description: Use to hook Keystone UI into a project — adding the gem, running the install generator to wire Tailwind, the Stimulus controllers and the layout's theme attributes, and configuring the palette, the theme mode supplier, registered looks, the breadcrumb trail supplier, the saved table layout supplier, the navigation groups and current tab supplier, and extra Tailwind imports and sources.
3
+ description: Use to hook Keystone UI into a project — adding the gem, running the install generator to wire Tailwind, the Stimulus controllers and the layout's theme attributes, and configuring the palette, the theme mode supplier, registered looks, the breadcrumb trail supplier, the saved table layout supplier, the navigation groups and current tab supplier, the text diff's line limit, and extra Tailwind imports and sources.
4
4
  tools: Bash, Read, Edit
5
5
  scope: UI — pages, forms, tables, navigation, dashboards
6
6
  ---
@@ -36,6 +36,8 @@ built on ViewComponent; hook it in before building any screen with those helpers
36
36
  `current_tab_supplier` (a callable that supplies the key of the declared tab
37
37
  the current page belongs to, so the navigation marks it and its group
38
38
  active),
39
+ `text_diff_line_limit` (the most lines a text diff's two texts may hold
40
+ together before it stops comparing them, 2,000 unless set),
39
41
  and the `tailwind_imports` and `tailwind_sources` lists (extra CSS files and
40
42
  scan paths added to the Tailwind build).
41
43
  - `keystone_theme_attributes` — a layout helper placed inside the `<html>` tag.
@@ -160,7 +162,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
160
162
  @import "./look.css";
161
163
  ```
162
164
 
163
- Buttons, panels, cards, alerts, badges, form fields, the modal, the mobile
165
+ Buttons, panels, cards, alerts, badges, status dots, form fields, the modal, the mobile
164
166
  action menu, the action menu, the column picker, multi select, search select, copy button, theme toggle,
165
167
  checkbox row, radio card, option card, file upload and colour picker read
166
168
  these variables. So do the data display components: stat card, chart card,
@@ -196,6 +198,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
196
198
  group.tab :quotes, label: "Quotes", href: ->(view) { view.quotes_path }, permitted: ->(view) { view.policy(Quote).index? }
197
199
  end
198
200
  config.current_tab_supplier = ->(view) { view.controller.try(:navigation_tab) }
201
+ config.text_diff_line_limit = 5000
199
202
  config.tailwind_imports << "/absolute/path/to/extra.css"
200
203
  config.tailwind_sources << "/absolute/path/to/components/**/*.{erb,rb}"
201
204
  end
@@ -347,6 +350,14 @@ built on ViewComponent; hook it in before building any screen with those helpers
347
350
  callable must answer for every page the layout draws, so a page with no
348
351
  tab returns `nil` rather than raising. Ask the developer how a page names
349
352
  its tab, such as a method on each controller, before writing the callable.
353
+ - `text_diff_line_limit` — an integer, 2,000 unless set. When the two texts
354
+ given to a text diff hold more lines together than this, the diff does not
355
+ compare them. It shows the lines side by side, paired by position, with no
356
+ added or removed marks, under the notice
357
+ `These texts are too long to compare.` The time and memory a comparison
358
+ takes grow with the line count of one text times the line count of the
359
+ other, so a higher limit makes each long diff slower to render. Leave it
360
+ unset unless the developer asks for a different limit.
350
361
  - `tailwind_imports` and `tailwind_sources` — lists to append to, never
351
362
  assign. Each import becomes an `@import` line and each source becomes an
352
363
  `@source` line in `keystone_source.css` on the next boot. They are for
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.83.0
4
+ version: 0.85.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -214,6 +214,7 @@ files:
214
214
  - app/components/keystone/ui/sortable_list_component.rb
215
215
  - app/components/keystone/ui/stat_card_component.html.erb
216
216
  - app/components/keystone/ui/stat_card_component.rb
217
+ - app/components/keystone/ui/states.rb
217
218
  - app/components/keystone/ui/status_dot_component.rb
218
219
  - app/components/keystone/ui/swipe_deck_component.html.erb
219
220
  - app/components/keystone/ui/swipe_deck_component.rb