keystone_ui 0.78.0 → 0.80.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: 1caef93fc9a8ea85b3cb62b32540c5e13331092dfaf11b954bc9bdf0ed3f4cc6
4
- data.tar.gz: 22c5443af455f0aef44503f7d1b2a9203a95c879f0dfbf16a393964b215dcbf0
3
+ metadata.gz: 89de110dfb32394a6012de91de4120517f04870224e7ccb13afc436d6174b9ac
4
+ data.tar.gz: 6310807810ad3de4e4021fda9bdcec1d0c3d284872a9e70799aeb9419a81425b
5
5
  SHA512:
6
- metadata.gz: 81b1ce2589195e37bd88d677930b3d3d94e00a6609eecd6c44ed290970605d0de4febfd25d098177d8207a08eb8f371252c9d9c7f048c23645d2ba2964f035dd
7
- data.tar.gz: 3fa5d47c0b4d4da2ead387a0e8c52dc4067afbc4dcf13693f16b0fc32ac28f31654ac0af290a26d061101fb220dd8ca0904f56ec983960e4b580057e5e430912
6
+ metadata.gz: c2b1f52471717cbe9e10a6a1ea9bf5c2e0656257f7d82cdaf1983ea94ff15a9c62261215f4fdb53e8db934c14ff37638b398451f57da0948ea113bdc54cb1f61
7
+ data.tar.gz: 91cf44f8a528063da14e2319f4d1cae925a265bb298d64588ff9102f408821c5206e3ac71bafd291ac673fb29f33ea7a468d8f959c33984654b5d4a0e008513c
@@ -0,0 +1,11 @@
1
+ <div class="<%= Keystone::Ui::TextDiffComponent::WRAPPER_CLASSES %>">
2
+ <div class="<%= Keystone::Ui::TextDiffComponent::COLUMNS_CLASSES %>">
3
+ <% Keystone::Ui::TextDiffComponent::SIDES.each do |side| %>
4
+ <div class="<%= Keystone::Ui::TextDiffComponent::SIDE_CLASSES %>" data-diff-side="<%= side %>">
5
+ <% cells(side).each do |cell| %>
6
+ <div class="<%= [ Keystone::Ui::TextDiffComponent::ROW_CLASSES, cell&.dig(:mark) ].compact.join(" ") %>" data-diff-row><span class="<%= Keystone::Ui::TextDiffComponent::NUMBER_CLASSES %>" data-diff-number><%= cell&.dig(:number) %></span><span class="<%= Keystone::Ui::TextDiffComponent::SIGN_CLASSES %>" data-diff-sign><%= cell&.dig(:sign) %></span><span class="<%= Keystone::Ui::TextDiffComponent::TEXT_CLASSES %>" data-diff-text><%= cell&.dig(:text) %></span></div>
7
+ <% end %>
8
+ </div>
9
+ <% end %>
10
+ </div>
11
+ </div>
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Keystone
4
+ module Ui
5
+ class TextDiffComponent < ViewComponent::Base
6
+ SIDES = %w[before after].freeze
7
+ WRAPPER_CLASSES = "ks-code overflow-hidden"
8
+ COLUMNS_CLASSES = "grid grid-cols-1 sm:grid-cols-2"
9
+ SIDE_CLASSES = "ks-code-block min-w-0 overflow-x-auto font-mono text-sm leading-relaxed"
10
+ ROW_CLASSES = "flex h-[1lh]"
11
+ NUMBER_CLASSES = "w-8 shrink-0 select-none text-right"
12
+ SIGN_CLASSES = "w-6 shrink-0 select-none text-center"
13
+ TEXT_CLASSES = "whitespace-pre"
14
+
15
+ def initialize(before:, after:)
16
+ @before = before.to_s.lines(chomp: true)
17
+ @after = after.to_s.lines(chomp: true)
18
+ end
19
+
20
+ def cells(side)
21
+ rows.map { |row| row[SIDES.index(side)] }
22
+ end
23
+
24
+ private
25
+
26
+ def rows
27
+ @rows ||= compare
28
+ end
29
+
30
+ def compare
31
+ before_index = after_index = 0
32
+ rows = []
33
+ while before_index < @before.size || after_index < @after.size
34
+ if before_index < @before.size && after_index < @after.size && @before[before_index] == @after[after_index]
35
+ rows << [ { text: @before[before_index], number: before_index + 1 }, { text: @after[after_index], number: after_index + 1 } ]
36
+ before_index += 1
37
+ after_index += 1
38
+ elsif before_index < @before.size && (after_index == @after.size || shared[before_index + 1][after_index] >= shared[before_index][after_index + 1])
39
+ rows << [ { text: @before[before_index], number: before_index + 1, mark: "ks-diff-removed", sign: "-" }, nil ]
40
+ before_index += 1
41
+ else
42
+ rows << [ nil, { text: @after[after_index], number: after_index + 1, mark: "ks-diff-added", sign: "+" } ]
43
+ after_index += 1
44
+ end
45
+ end
46
+ rows
47
+ end
48
+
49
+ def shared
50
+ @shared ||= begin
51
+ table = Array.new(@before.size + 1) { Array.new(@after.size + 1, 0) }
52
+ (@before.size - 1).downto(0) do |before_index|
53
+ (@after.size - 1).downto(0) do |after_index|
54
+ table[before_index][after_index] = if @before[before_index] == @after[after_index]
55
+ table[before_index + 1][after_index + 1] + 1
56
+ else
57
+ [ table[before_index + 1][after_index], table[before_index][after_index + 1] ].max
58
+ end
59
+ end
60
+ end
61
+ table
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,12 +1,17 @@
1
1
  <div class="flex flex-col gap-3">
2
- <% entries.each do |entry| %>
2
+ <% rows.each do |row| %>
3
3
  <div data-timeline-row>
4
4
  <div class="<%= ROW_TEXT_CLASSES %>">
5
- <span data-timeline-label><%= entry[:label] %></span>
6
- <span data-timeline-duration><%= duration(entry) %></span>
5
+ <span data-timeline-label><%= row[:label] %></span>
6
+ <span data-timeline-duration><%= duration(row) %></span>
7
7
  </div>
8
8
  <div class="<%= TRACK_CLASSES %>">
9
- <div class="<%= BAR_CLASSES %>" data-timeline-bar style="<%= bar_style(entry) %>"></div>
9
+ <% row[:tries].each do |entry| %>
10
+ <% if entry[:queued_at] %>
11
+ <div class="<%= QUEUED_CLASSES %>" data-timeline-queued style="<%= queued_style(entry) %>"></div>
12
+ <% end %>
13
+ <div class="<%= bar_classes(entry) %>" data-timeline-bar style="<%= bar_style(entry) %>"><% if entry[:failed] %><span class="<%= SCREEN_READER_CLASSES %>">Failed</span><% end %></div>
14
+ <% end %>
10
15
  </div>
11
16
  </div>
12
17
  <% end %>
@@ -3,8 +3,11 @@
3
3
  module Keystone
4
4
  module Ui
5
5
  class TimelineComponent < ViewComponent::Base
6
- TRACK_CLASSES = "ks-progress-track relative w-full h-2 overflow-hidden"
7
- BAR_CLASSES = "ks-progress-bar absolute inset-y-0"
6
+ TRACK_CLASSES = "ks-timeline-track relative w-full h-2 overflow-hidden"
7
+ BAR_CLASSES = "ks-timeline-bar absolute inset-y-0"
8
+ FAILED_CLASSES = "ks-timeline-failed"
9
+ QUEUED_CLASSES = "ks-timeline-queued absolute inset-y-0"
10
+ SCREEN_READER_CLASSES = "sr-only"
8
11
  ROW_TEXT_CLASSES = "ks-meter-label flex justify-between text-sm"
9
12
  AXIS_CLASSES = "ks-meter-label flex justify-between text-xs"
10
13
 
@@ -18,8 +21,20 @@ module Keystone
18
21
  "left: #{percent(entry[:started_at] - axis_start)}%; width: #{percent(entry[:ended_at] - entry[:started_at])}%"
19
22
  end
20
23
 
21
- def duration(entry)
22
- written_duration(entry[:ended_at] - entry[:started_at])
24
+ def rows
25
+ entries.group_by { |entry| entry[:label] }.map { |label, tries| { label: label, tries: tries } }
26
+ end
27
+
28
+ def queued_style(entry)
29
+ "left: #{percent(entry[:queued_at] - axis_start)}%; width: #{percent(entry[:started_at] - entry[:queued_at])}%"
30
+ end
31
+
32
+ def bar_classes(entry)
33
+ [ BAR_CLASSES, (FAILED_CLASSES if entry[:failed]) ].compact.join(" ")
34
+ end
35
+
36
+ def duration(row)
37
+ written_duration(row[:tries].last[:ended_at] - row[:tries].first[:started_at])
23
38
  end
24
39
 
25
40
  def total_duration
@@ -41,7 +56,7 @@ module Keystone
41
56
  end
42
57
 
43
58
  def axis_start
44
- @axis_start ||= entries.map { |entry| entry[:started_at] }.min
59
+ @axis_start ||= entries.map { |entry| entry[:queued_at] || entry[:started_at] }.min
45
60
  end
46
61
 
47
62
  def axis_end
@@ -265,6 +265,10 @@ module KeystoneUiHelper
265
265
  render Keystone::Ui::CodeComponent.new(**args), &block
266
266
  end
267
267
 
268
+ def ui_text_diff(**args)
269
+ render Keystone::Ui::TextDiffComponent.new(**args)
270
+ end
271
+
268
272
  def ui_disclosure(**args, &block)
269
273
  render Keystone::Ui::DisclosureComponent.new(**args), &block
270
274
  end
@@ -73,6 +73,7 @@ module Keystone
73
73
  Keystone::Ui::BucketSeriesComponent,
74
74
  Keystone::Ui::PipelineComponent,
75
75
  Keystone::Ui::CodeComponent,
76
+ Keystone::Ui::TextDiffComponent,
76
77
  Keystone::Ui::DisclosureComponent,
77
78
  Keystone::Ui::ThemeToggleComponent,
78
79
  Keystone::Ui::TimelineComponent,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.78.0"
4
+ VERSION = "0.80.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: keystone_ui-develop
3
- description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, a page's main action as a phone top-bar icon or a button fixed to the bottom of the screen, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps, amounts shown in green or red as a gain or loss, status dots coloured by state, pictures held to half the screen, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
3
+ description: Use PROACTIVELY for building or editing screens in a Rails app that has keystone_ui — page shells with Back links and breadcrumbs, forms and fields, a search field that picks a record or enters a new one, data tables with saved columns, desktop navigation, sidebars and bottom tabs, a page's main action as a phone top-bar icon or a button fixed to the bottom of the screen, action menus for a record's Edit and Delete, dashboards with stat cards, charts, funnels, goal buckets and timelines of timed steps with retries, queued time and failed tries, amounts shown in green or red as a gain or loss, status dots coloured by state, pictures held to half the screen, two versions of a text compared line by line side by side, info buttons and breakdowns, marketing sections, a light/dark theme switch — MUST BE USED instead of hand-writing ERB and Tailwind for UI.
4
4
  tools: Bash, Read, Write, Edit, Grep
5
5
  scope: UI — pages, forms, tables, navigation, dashboards
6
6
  ---
@@ -83,6 +83,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
83
83
  - `ui_stat_card` — a single metric tile with optional change, link and info button.
84
84
  - `ui_copy_button` — a button that copies text to the clipboard.
85
85
  - `ui_code` — a block of code with an optional caption.
86
+ - `ui_text_diff` — two versions of a text side by side, with removed and added lines marked.
86
87
  - `ui_disclosure` — a native expandable section with a clickable summary.
87
88
  - `ui_calculation` — the steps behind a figure, closed under a summary row.
88
89
  - `ui_info` — an inline info button showing a summary, and optional detail, in floating panels.
@@ -97,7 +98,7 @@ not available in the app yet, that is `keystone_ui-install`'s job.
97
98
  - `ui_funnel` — a conversion funnel drawn as bars or one joined shape.
98
99
  - `ui_bucket` — an upright container filled toward a goal.
99
100
  - `ui_bucket_series` — a wrapping row of buckets.
100
- - `ui_timeline` — rows of timed steps, each a bar placed by its start and end on one shared time axis.
101
+ - `ui_timeline` — rows of timed steps on one shared time axis, each try of a step a bar on its row, with optional queued time and failed tries marked.
101
102
  - `ui_pipeline` — a staged flow diagram with buttons and breakable links that post to the app.
102
103
  - `ui_hero` — a marketing hero with title, call-to-action buttons and an aside.
103
104
  - `ui_cta_banner` — a marketing banner holding call-to-action buttons.
@@ -627,6 +628,20 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
627
628
  - `ui_code(language: nil, caption: nil)` takes a block holding the code.
628
629
  `caption:` is a strip above it and `language:` sets the `language-*`
629
630
  class for a highlighter.
631
+ - `ui_text_diff(before:, after:)` takes no block. It splits each text into
632
+ lines and draws the earlier version in the left column and the later one
633
+ in the right, stacked with the earlier above below `sm:`. Lines the two
634
+ share sit on the same row. A line only `before:` has is marked removed with
635
+ a `-` and a line only `after:` has is marked added with a `+`, each
636
+ coloured by keystone_ui-styles and each with a
637
+ blank row opposite, so a changed line shows as a removed row followed by
638
+ an added row. Each column numbers its own lines, and a long line scrolls
639
+ sideways inside its column. Lines must match exactly, spaces included, to
640
+ count as shared. A `nil` text is treated as empty, and both are shown as
641
+ plain text. The work grows with the line count of one text times the
642
+ other's, so pass texts a person reads, not whole files of thousands of
643
+ lines. Ask the developer which two versions a screen compares and which
644
+ is the earlier one.
630
645
  - `ui_disclosure(open: false)` takes a block yielding the component. Fill
631
646
  its `summary` slot with the header, and the rest of the block is the body.
632
647
  - `ui_accordion(items: [])` — `items:` is `[{ question:, answer: }, ...]`.
@@ -715,14 +730,28 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
715
730
  - `ui_bucket_series(buckets:)` takes an array of hashes with the keywords
716
731
  of `ui_bucket`, such as `[{ goal: 10, actual: 7, label: "Mon" }, ...]`.
717
732
  - `ui_timeline(entries:)` takes no block. `entries:` is
718
- `[{ label:, started_at:, ended_at: }, ...]` in the order to list them,
719
- with both times as `Time` values. The axis runs from the earliest
720
- `started_at` to the latest `ended_at`. Each entry is one row: its label
721
- and its duration on one line, then a track with a bar placed at its start
722
- and as wide as its share of the axis. Under the rows the axis reads `0s`
723
- on the left and the whole span on the right. Durations are written as
724
- `1h 0m 5s`, leaving out leading zero units, and a zero duration is `0s`.
725
- It needs at least one entry and a span longer than zero, so do not render
733
+ `[{ label:, started_at:, ended_at:, queued_at: nil, failed: false }, ...]`,
734
+ with every time a `Time` value.
735
+ - It draws one row per label, in the order each label first appears.
736
+ Entries that share a label, such as the tries of one step, share that
737
+ row and each draws its own bar, so pass a step's tries one after another
738
+ in the order they ran.
739
+ - Every bar is placed by its entry's `started_at` and `ended_at` on one
740
+ axis shared by all rows. The axis runs from the earliest `queued_at` or
741
+ `started_at` of any entry to the latest `ended_at`.
742
+ - An entry given `queued_at:` also draws the time from `queued_at` to
743
+ `started_at` before its bar, in the queued colour. Leave it out when the
744
+ wait is not known.
745
+ - An entry given `failed: true` draws its bar in the danger colour, and
746
+ screen readers read it as "Failed". Ask the developer which tries count
747
+ as failed and whether the queued time is shown.
748
+ - Each row shows its label and its duration on one line, then its track.
749
+ The row's duration runs from its first entry's `started_at` to its last
750
+ entry's `ended_at`, so queued time before the first try is not counted.
751
+ - Under the rows the axis reads `0s` on the left and the whole span on the
752
+ right. Durations are written as `1h 0m 5s`, leaving out leading zero
753
+ units, and a zero duration is `0s`.
754
+ - It needs at least one entry and a span longer than zero, so do not render
726
755
  it for an empty list or for entries that all start and end at one moment.
727
756
  - `ui_pipeline(title:, boxes:, links:, subtitle: nil)` — `boxes:` is
728
757
  `[{ label:, count:, accent:, action: }, ...]`, with `accent:` one of
@@ -790,7 +819,9 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
790
819
  shows nothing, a breakdown in one run of text, a `:success` or `:danger`
791
820
  figure in plain colour, a joined funnel with no band, a locked column the
792
821
  others show through, a Columns menu with no greyed name for a hidden
793
- column, a table row whose caret does not open its detail, or a status dot
822
+ column, a table row whose caret does not open its detail, a text diff whose
823
+ removed and added rows look like its shared rows, a timeline whose failed
824
+ tries or queued time look like its other bars, or a status dot
794
825
  that draws nothing — the app's Stimulus controllers or keystone_ui-styles version are
795
826
  out of date. Stop and hand that part to `keystone_ui-install`, and add no
796
827
  classes to fix it.
@@ -13,7 +13,8 @@ nothing and gives no steps.
13
13
  keystone_ui is a Rails engine gem that supplies a host app's UI as view helpers
14
14
  built on ViewComponent. Screens are built from named pieces — page shells,
15
15
  sections, panels, grids, forms and fields, search dropdowns, data tables, navigation, cards,
16
- badges, status dots, stat tiles, charts, timelines, funnels, goal buckets, pipelines, breakdowns and info buttons —
16
+ badges, status dots, stat tiles, charts, timelines, funnels, goal buckets, pipelines, breakdowns, code blocks,
17
+ text diffs and info buttons —
17
18
  instead of hand-written ERB and Tailwind. Every class the UI renders lives in the
18
19
  gem, so two pages built from the same helpers cannot disagree about spacing,
19
20
  colour or dark-mode treatment, and a change to a component reaches every page
@@ -59,10 +60,18 @@ One decision: is keystone_ui set up in the app?
59
60
  symbol they do not know, so a wrong guess fails at render time.
60
61
  - **Numbers and text are different inputs.** Progress bars, funnels, buckets
61
62
  and timelines do arithmetic, so they take numbers, and a bucket raises on
62
- `"9,000"`. A timeline takes each row's start and end as times and works out
63
- every duration, bar position and its axis from them. A
63
+ `"9,000"`. A timeline takes each entry's times and works out every duration,
64
+ bar position and its axis from them. A
64
65
  breakdown, a calculation and a toned figure take already-formatted text, show
65
66
  it as written and add nothing up.
67
+ - **Timelines.** A timeline entry is one try at a step: a label, a start time,
68
+ an end time, and optionally the time it was queued and whether it failed.
69
+ Entries sharing a label are drawn as several bars on one row, in the order
70
+ given, and the row's duration runs from its first try's start to its last
71
+ try's end. Queued time is drawn as its own segment before the bar, and a
72
+ failed try is marked failed both in colour and for screen readers. The axis
73
+ runs from the earliest queued or start time of any entry to the latest end
74
+ time.
66
75
  - **Going back.** A form or show page shell needs a way back: a back link, a
67
76
  trail of earlier pages shown as breadcrumbs, or a trail the app supplies for
68
77
  the request. A nav tab's own page passes an empty trail and shows no back
@@ -109,6 +118,13 @@ One decision: is keystone_ui set up in the app?
109
118
  dot shows only its state's colour, for places with no room for text, and its label
110
119
  is read only by screen readers. A status dot raises `ArgumentError` on any
111
120
  other state.
121
+ - **Text diffs.** A text diff compares two texts line by line and shows them
122
+ side by side, stacked on a phone, in the code block's look. Lines the two
123
+ share sit on the same row, a line only the first text has is marked removed
124
+ with a minus, a line only the second has is marked added with a plus, the
125
+ other side shows a blank row beside either one, and each side numbers its own
126
+ lines. On a phone the first text's column sits above the second's. It compares whole lines, so a line with one word
127
+ changed shows as one line removed and one added.
112
128
  - **Semantic colour.** The themed hue is `accent-*` and the themed neutrals are
113
129
  `surface-*`, CSS custom properties whose defaults (blue and zinc) come from
114
130
  the keystone_ui-styles gem. Retheming changes those values, not the
@@ -164,7 +164,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
164
164
  action menu, the action menu, the column picker, multi select, search select, copy button, theme toggle,
165
165
  checkbox row, radio card, option card, file upload and colour picker read
166
166
  these variables. So do the data display components: stat card, chart card,
167
- card link, CTA banner, feature grid, hero, data table, code, accordion,
167
+ card link, CTA banner, feature grid, hero, data table, code, text diff, accordion,
168
168
  disclosure, calculation, info button, breakdown, figure, tab switcher, progress,
169
169
  timeline, funnel, bucket, pipeline and swipe deck.
170
170
  So do the navigation components: navbar, nav item, nav dropdown, bottom nav,
@@ -70,6 +70,7 @@ develop:
70
70
  - ui_bucket_series
71
71
  - ui_pipeline
72
72
  - ui_code
73
+ - ui_text_diff
73
74
  - ui_disclosure
74
75
  - ui_calculation
75
76
  - ui_info
@@ -114,6 +115,8 @@ sources:
114
115
  - app/components/keystone/ui/checkbox_row_component.rb
115
116
  - app/components/keystone/ui/checkbox_row_component.html.erb
116
117
  - app/components/keystone/ui/code_component.rb
118
+ - app/components/keystone/ui/text_diff_component.rb
119
+ - app/components/keystone/ui/text_diff_component.html.erb
117
120
  - app/components/keystone/ui/color_picker_component.rb
118
121
  - app/components/keystone/ui/column_picker_component.rb
119
122
  - app/components/keystone/ui/column.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.78.0
4
+ version: 0.80.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -219,6 +219,8 @@ files:
219
219
  - app/components/keystone/ui/swipe_deck_component.rb
220
220
  - app/components/keystone/ui/tab_switcher_component.html.erb
221
221
  - app/components/keystone/ui/tab_switcher_component.rb
222
+ - app/components/keystone/ui/text_diff_component.html.erb
223
+ - app/components/keystone/ui/text_diff_component.rb
222
224
  - app/components/keystone/ui/textarea_component.html.erb
223
225
  - app/components/keystone/ui/textarea_component.rb
224
226
  - app/components/keystone/ui/theme_toggle_component.html.erb