keystone_ui 0.78.0 → 0.79.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: facf365bdd0f3e806b1db58e72e26b58500b8db01ea8a016c5b89b39e5739d66
4
+ data.tar.gz: d098dc9c4105caa20816e8f47c2acd357697abb2e11f9918c05d4c2959fcd99b
5
5
  SHA512:
6
- metadata.gz: 81b1ce2589195e37bd88d677930b3d3d94e00a6609eecd6c44ed290970605d0de4febfd25d098177d8207a08eb8f371252c9d9c7f048c23645d2ba2964f035dd
7
- data.tar.gz: 3fa5d47c0b4d4da2ead387a0e8c52dc4067afbc4dcf13693f16b0fc32ac28f31654ac0af290a26d061101fb220dd8ca0904f56ec983960e4b580057e5e430912
6
+ metadata.gz: 3ce67331b86779a466fcc1090400fa6b839f856fddb731a6c78a3bc78e82a6eeef590e388e24fb1a25e0a9920a05046b6db3f9f2d34bddde7a65c5995b3e5979
7
+ data.tar.gz: 9807d78d7a16382b8224f61f8eadf99753e5df8de684011454b7b81261598505b11ed78e5c3b5354d724c244564380f9a34c4be04fb526f0629125d79abda39c
@@ -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
@@ -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.79.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, 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.
@@ -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: }, ...]`.
@@ -790,7 +805,8 @@ two exceptions: `ui_page`'s `padding:` treats any value other than `:none` as
790
805
  shows nothing, a breakdown in one run of text, a `:success` or `:danger`
791
806
  figure in plain colour, a joined funnel with no band, a locked column the
792
807
  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
808
+ column, a table row whose caret does not open its detail, a text diff whose
809
+ removed and added rows look like its shared rows, or a status dot
794
810
  that draws nothing — the app's Stimulus controllers or keystone_ui-styles version are
795
811
  out of date. Stop and hand that part to `keystone_ui-install`, and add no
796
812
  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
@@ -109,6 +110,13 @@ One decision: is keystone_ui set up in the app?
109
110
  dot shows only its state's colour, for places with no room for text, and its label
110
111
  is read only by screen readers. A status dot raises `ArgumentError` on any
111
112
  other state.
113
+ - **Text diffs.** A text diff compares two texts line by line and shows them
114
+ side by side, stacked on a phone, in the code block's look. Lines the two
115
+ share sit on the same row, a line only the first text has is marked removed
116
+ with a minus, a line only the second has is marked added with a plus, the
117
+ other side shows a blank row beside either one, and each side numbers its own
118
+ lines. On a phone the first text's column sits above the second's. It compares whole lines, so a line with one word
119
+ changed shows as one line removed and one added.
112
120
  - **Semantic colour.** The themed hue is `accent-*` and the themed neutrals are
113
121
  `surface-*`, CSS custom properties whose defaults (blue and zinc) come from
114
122
  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.79.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