ariadne_view_components 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/ariadne-form-with.d.ts +20 -0
  3. data/app/assets/javascripts/ariadne-form.d.ts +22 -0
  4. data/app/assets/javascripts/ariadne.d.ts +1 -1
  5. data/app/assets/javascripts/ariadne_view_components.js +7 -1
  6. data/app/assets/javascripts/ariadne_view_components.js.map +1 -1
  7. data/app/assets/javascripts/comment-component.d.ts +13 -0
  8. data/app/assets/javascripts/rich-text-area-component.d.ts +4 -0
  9. data/app/{components/ariadne/time_ago_component.d.ts → assets/javascripts/time-ago-component.d.ts} +0 -0
  10. data/app/assets/stylesheets/application.ariadne_view_components.css +1 -0
  11. data/app/assets/stylesheets/prosemirror.css +323 -0
  12. data/app/components/ariadne/ariadne-form.ts +96 -0
  13. data/app/components/ariadne/ariadne.ts +8 -1
  14. data/app/components/ariadne/base_button.rb +6 -7
  15. data/app/components/ariadne/base_component.rb +13 -131
  16. data/app/components/ariadne/blankslate_component.html.erb +5 -5
  17. data/app/components/ariadne/blankslate_component.rb +4 -9
  18. data/app/components/ariadne/body_component.rb +1 -1
  19. data/app/components/ariadne/button_component.rb +7 -6
  20. data/app/components/ariadne/clipboard_copy_component.html.erb +3 -2
  21. data/app/components/ariadne/comment-component.ts +55 -0
  22. data/app/components/ariadne/comment_component.html.erb +17 -20
  23. data/app/components/ariadne/comment_component.rb +29 -17
  24. data/app/components/ariadne/component.rb +4 -4
  25. data/app/components/ariadne/container_component.rb +1 -1
  26. data/app/components/ariadne/counter_component.rb +4 -4
  27. data/app/components/ariadne/flash_component.html.erb +12 -12
  28. data/app/components/ariadne/flash_component.rb +16 -16
  29. data/app/components/ariadne/flex_component.rb +5 -7
  30. data/app/components/ariadne/footer_component.html.erb +1 -1
  31. data/app/components/ariadne/footer_component.rb +1 -1
  32. data/app/components/ariadne/grid_component.html.erb +4 -4
  33. data/app/components/ariadne/grid_component.rb +9 -9
  34. data/app/components/ariadne/header_component.html.erb +7 -7
  35. data/app/components/ariadne/header_component.rb +8 -8
  36. data/app/components/ariadne/heading_component.rb +3 -3
  37. data/app/components/ariadne/heroicon_component.rb +4 -4
  38. data/app/components/ariadne/inline_flex_component.rb +7 -7
  39. data/app/components/ariadne/link_component.rb +2 -2
  40. data/app/components/ariadne/list_component.rb +6 -5
  41. data/app/components/ariadne/narrow_container_component.html.erb +3 -0
  42. data/app/components/ariadne/narrow_container_component.rb +30 -0
  43. data/app/components/ariadne/panel_bar_component.html.erb +20 -0
  44. data/app/components/ariadne/panel_bar_component.rb +79 -0
  45. data/app/components/ariadne/pill_component.rb +2 -2
  46. data/app/components/ariadne/rich-text-area-component.ts +32 -0
  47. data/app/components/ariadne/rich_text_area_component.html.erb +6 -0
  48. data/app/components/ariadne/rich_text_area_component.rb +35 -0
  49. data/app/components/ariadne/slideover-component.ts +3 -3
  50. data/app/components/ariadne/slideover_component.html.erb +3 -3
  51. data/app/components/ariadne/slideover_component.rb +1 -1
  52. data/app/components/ariadne/tab_bar_component.html.erb +3 -0
  53. data/app/components/ariadne/tab_bar_component.rb +45 -0
  54. data/app/components/ariadne/tab_component.html.erb +7 -0
  55. data/app/components/ariadne/tab_component.rb +43 -0
  56. data/app/components/ariadne/{time_ago_component.ts → time-ago-component.ts} +0 -0
  57. data/app/components/ariadne/time_ago_component.rb +2 -2
  58. data/app/components/ariadne/timeline_component.html.erb +6 -6
  59. data/app/components/ariadne/tooltip-component.ts +3 -3
  60. data/app/components/ariadne/tooltip_component.html.erb +1 -1
  61. data/app/components/ariadne/tooltip_component.rb +1 -1
  62. data/app/lib/ariadne/action_view_extensions/form_helper.rb +4 -1
  63. data/app/lib/ariadne/fetch_or_fallback_helper.rb +3 -1
  64. data/app/lib/ariadne/form_builder.rb +10 -10
  65. data/app/lib/ariadne/icon_helper.rb +1 -1
  66. data/lib/ariadne/view_components/engine.rb +169 -3
  67. data/lib/ariadne/view_components/version.rb +1 -1
  68. data/lib/ariadne/view_components.rb +0 -1
  69. data/lib/rubocop/config/default.yml +0 -6
  70. data/lib/rubocop/cop/ariadne/no_tag_memoize.rb +1 -0
  71. data/lib/tasks/docs.rake +6 -1
  72. data/static/arguments.yml +99 -4
  73. data/static/audited_at.json +8 -2
  74. data/static/classes.yml +195 -181
  75. data/static/constants.json +112 -72
  76. data/static/statuses.json +8 -2
  77. metadata +42 -32
  78. data/app/assets/builds/ariadne_view_components.css +0 -1874
  79. data/app/components/ariadne/ariadne.d.ts +0 -1
  80. data/app/components/ariadne/ariadne.js +0 -9
  81. data/app/components/ariadne/clipboard-copy-component.d.ts +0 -4
  82. data/app/components/ariadne/clipboard-copy-component.js +0 -18
  83. data/app/components/ariadne/clipboard_copy_component.d.ts +0 -4
  84. data/app/components/ariadne/clipboard_copy_component.js +0 -18
  85. data/app/components/ariadne/slideover-component.d.ts +0 -9
  86. data/app/components/ariadne/slideover-component.js +0 -20
  87. data/app/components/ariadne/slideover_component.d.ts +0 -9
  88. data/app/components/ariadne/slideover_component.js +0 -19
  89. data/app/components/ariadne/time_ago_component.js +0 -1
  90. data/app/components/ariadne/tooltip-component.d.ts +0 -24
  91. data/app/components/ariadne/tooltip-component.js +0 -42
  92. data/lib/ariadne/classify/utilities.rb +0 -199
  93. data/lib/ariadne/classify/utilities.yml +0 -1817
  94. data/lib/ariadne/classify/validation.rb +0 -18
  95. data/lib/ariadne/classify.rb +0 -124
  96. data/lib/rubocop/cop/ariadne/ariadne_heroicon.rb +0 -252
  97. data/lib/rubocop/cop/ariadne/component_name_migration.rb +0 -35
  98. data/lib/rubocop/cop/ariadne/system_argument_instead_of_class.rb +0 -57
  99. data/lib/tasks/utilities.rake +0 -121
@@ -1 +0,0 @@
1
- import './time_ago_component';
@@ -1,9 +0,0 @@
1
- import { Application } from '@hotwired/stimulus';
2
- import ClipboardCopyComponent from './clipboard-copy-component';
3
- import SlideoverComponent from './slideover-component';
4
- import TooltipComponent from './tooltip-component';
5
- import './time_ago_component';
6
- const application = Application.start();
7
- application.register('clipboard-copy-component', ClipboardCopyComponent);
8
- application.register('slideover-component', SlideoverComponent);
9
- application.register('tooltip-component', TooltipComponent);
@@ -1,4 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class ClipboardCopyComponent extends Controller {
3
- copy(): void;
4
- }
@@ -1,18 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class ClipboardCopyComponent extends Controller {
3
- copy() {
4
- const value = this.element.attributes.getNamedItem('value');
5
- const forNode = this.element.attributes.getNamedItem('for');
6
- if (value) {
7
- navigator.clipboard.writeText(value.value);
8
- }
9
- else if (forNode) {
10
- const node = document.getElementById(forNode.value);
11
- navigator.clipboard.writeText((node === null || node === void 0 ? void 0 : node.textContent) || '');
12
- }
13
- else {
14
- // just copy inner text
15
- navigator.clipboard.writeText(this.element.textContent || '');
16
- }
17
- }
18
- }
@@ -1,4 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class ClipboardCopyComponent extends Controller {
3
- copy(): void;
4
- }
@@ -1,18 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class ClipboardCopyComponent extends Controller {
3
- copy() {
4
- const value = this.element.attributes.getNamedItem('value');
5
- const forNode = this.element.attributes.getNamedItem('for');
6
- if (value) {
7
- navigator.clipboard.writeText(value.value);
8
- }
9
- else if (forNode) {
10
- const node = document.getElementById(forNode.value);
11
- navigator.clipboard.writeText((node === null || node === void 0 ? void 0 : node.textContent) || '');
12
- }
13
- else {
14
- // just copy inner text
15
- navigator.clipboard.writeText(this.element.textContent || '');
16
- }
17
- }
18
- }
@@ -1,9 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class SlideoverComponent extends Controller {
3
- static targets: string[];
4
- readonly expandableTarget: HTMLDivElement;
5
- readonly expandWrapperTarget: HTMLDivElement;
6
- readonly slidePanelTargets: [HTMLDivElement];
7
- readonly buttonWrapperTarget: HTMLDivElement;
8
- toggle(): void;
9
- }
@@ -1,20 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class SlideoverComponent extends Controller {
3
- toggle() {
4
- var _a;
5
- this.expandableTarget.classList.toggle('hidden');
6
- this.expandWrapperTarget.classList.toggle('bg-filter-panel');
7
- for (const slidePanel of this.slidePanelTargets) {
8
- slidePanel.classList.toggle('hidden');
9
- }
10
- this.buttonWrapperTarget.classList.toggle('bg-filter-panel');
11
- if ((_a = document.getElementById('btnClose')) === null || _a === void 0 ? void 0 : _a.classList.contains('hidden')) {
12
- const formID = this.buttonWrapperTarget.getAttribute('data-slideover-component-form-id');
13
- if (formID) {
14
- const form = document.getElementById(formID);
15
- form === null || form === void 0 ? void 0 : form.submit();
16
- }
17
- }
18
- }
19
- }
20
- SlideoverComponent.targets = ['expandable', 'expandWrapper', 'slidePanel', 'buttonWrapper'];
@@ -1,9 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class SlideoverComponent extends Controller {
3
- static targets: string[];
4
- readonly expandableTarget: HTMLDivElement;
5
- readonly expandWrapperTarget: HTMLDivElement;
6
- readonly slidePanelTargets: [HTMLDivElement];
7
- readonly buttonWrapperTarget: HTMLDivElement;
8
- toggle(): void;
9
- }
@@ -1,19 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- export default class SlideoverComponent extends Controller {
3
- toggle() {
4
- var _a;
5
- // eslint-disable-next-line no-debugger
6
- debugger;
7
- this.expandableTarget.classList.toggle('hidden');
8
- this.expandWrapperTarget.classList.toggle('bg-filter-panel');
9
- for (const slidePanel of this.slidePanelTargets) {
10
- slidePanel.classList.toggle('hidden');
11
- }
12
- this.buttonWrapperTarget.classList.toggle('bg-filter-panel');
13
- if ((_a = document.getElementById('btnClose')) === null || _a === void 0 ? void 0 : _a.classList.contains('hidden')) {
14
- const form = this.buttonWrapperTarget.closest('form');
15
- form === null || form === void 0 ? void 0 : form.submit();
16
- }
17
- }
18
- }
19
- SlideoverComponent.targets = ['expandable', 'expandWrapper', 'slidePanel', 'buttonWrapper'];
@@ -1 +0,0 @@
1
- import '@github/time-elements';
@@ -1,24 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- import type { Instance, Placement } from '@popperjs/core';
3
- export default class TooltipComponent extends Controller {
4
- static targets: string[];
5
- readonly triggerTarget: HTMLElement;
6
- readonly tooltipTarget: HTMLElement;
7
- static values: {
8
- placement: {
9
- type: StringConstructor;
10
- default: string;
11
- };
12
- offset: {
13
- type: ArrayConstructor;
14
- default: number[];
15
- };
16
- };
17
- readonly placementValue: Placement;
18
- readonly offsetValue: Array<number>;
19
- popperInstance: Instance;
20
- connect(): void;
21
- disconnect(): void;
22
- show(): void;
23
- hide(): void;
24
- }
@@ -1,42 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- import { createPopper } from '@popperjs/core';
3
- export default class TooltipComponent extends Controller {
4
- // Create a new Popper instance
5
- connect() {
6
- this.popperInstance = createPopper(this.triggerTarget, this.tooltipTarget, {
7
- placement: this.placementValue,
8
- modifiers: [
9
- {
10
- name: 'offset',
11
- options: {
12
- offset: this.offsetValue
13
- }
14
- }
15
- ]
16
- });
17
- }
18
- // Destroy the Popper instance
19
- disconnect() {
20
- if (this.popperInstance) {
21
- this.popperInstance.destroy();
22
- }
23
- }
24
- show() {
25
- this.tooltipTarget.setAttribute('data-tooltip-show', '');
26
- this.tooltipTarget.classList.remove('invisible');
27
- // We need to tell Popper to update the tooltip position
28
- // after we show the tooltip, otherwise it will be incorrect
29
- this.popperInstance.update();
30
- this.dispatch('shown', { detail: { trigger: this.triggerTarget, tooltip: this.tooltipTarget } });
31
- }
32
- hide() {
33
- this.tooltipTarget.removeAttribute('data-tooltip-show');
34
- this.tooltipTarget.classList.add('invisible');
35
- this.dispatch('hidden', { detail: { trigger: this.triggerTarget, tooltip: this.tooltipTarget } });
36
- }
37
- }
38
- TooltipComponent.targets = ['trigger', 'tooltip'];
39
- TooltipComponent.values = {
40
- placement: { type: String, default: 'top' },
41
- offset: { type: Array, default: [0, 8] }
42
- };
@@ -1,199 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaml"
4
-
5
- # :nodoc:
6
- module Ariadne
7
- class Classify
8
- # Handler for AriadneCSS utility classes loaded from utilities.rake
9
- class Utilities
10
- # Load the utilities.yml file.
11
- # Disabling because we want to load symbols, strings, and integers from the .yml file
12
- UTILITIES = YAML.load(
13
- File.read(
14
- File.join(File.dirname(__FILE__), "./utilities.yml")
15
- )
16
- ).freeze
17
- BREAKPOINTS = ["", "-sm", "-md", "-lg", "-xl"].freeze
18
-
19
- # Replacements for some classnames that end up being a different argument key
20
- REPLACEMENT_KEYS = {
21
- "^anim" => "animation",
22
- "^v-align" => "vertical_align",
23
- "^d" => "display",
24
- "^wb" => "word_break",
25
- "^v" => "visibility",
26
- "^width" => "w",
27
- "^height" => "h",
28
- "^color-bg" => "bg",
29
- "^color-border" => "border_color",
30
- "^color-fg" => "color",
31
- }.freeze
32
-
33
- SUPPORTED_KEY_CACHE = Hash.new { |h, k| h[k] = !UTILITIES[k].nil? }
34
- BREAKPOINT_INDEX_CACHE = Hash.new { |h, k| h[k] = BREAKPOINTS.index(k) }
35
-
36
- class << self
37
- attr_accessor :validate_class_names
38
- alias_method :validate_class_names?, :validate_class_names
39
-
40
- def classname(key, val, breakpoint = "")
41
- # For cases when `argument: false` is passed in, treat like we would nil
42
- return nil unless val
43
-
44
- if (valid = validate(key, val, breakpoint))
45
- valid
46
- else
47
- # Get selector
48
- UTILITIES[key][val][BREAKPOINT_INDEX_CACHE[breakpoint]]
49
- end
50
- end
51
-
52
- # Does the Utility class support the given key
53
- #
54
- # returns Boolean
55
- def supported_key?(key)
56
- SUPPORTED_KEY_CACHE[key]
57
- end
58
-
59
- # Does the Utility class support the given key and value
60
- #
61
- # returns Boolean
62
- def supported_value?(key, val)
63
- supported_key?(key) && !UTILITIES[key][val].nil?
64
- end
65
-
66
- # Does the given selector exist in the utilities file
67
- #
68
- # returns Boolean
69
- def supported_selector?(selector)
70
- # This method is too slow to run in production
71
- return false unless validate_class_names?
72
-
73
- find_selector(selector).present?
74
- end
75
-
76
- # Is the key and value responsive
77
- #
78
- # returns Boolean
79
- def responsive?(key, val)
80
- supported_value?(key, val) && UTILITIES[key][val].count > 1
81
- end
82
-
83
- # Get the options for the given key
84
- #
85
- # returns Array or nil if key not supported
86
- def mappings(key)
87
- return unless supported_key?(key)
88
-
89
- UTILITIES[key].keys
90
- end
91
-
92
- # Extract hash from classes ie. "mr-1 mb-2 foo" => { mr: 1, mb: 2, classes: "foo" }
93
- def classes_to_hash(classes)
94
- # This method is too slow to run in production
95
- return { classes: classes } unless validate_class_names?
96
-
97
- obj = {}
98
- classes = classes.split
99
- # Loop through all classes supplied and reject ones we find a match for
100
- # So when we're at the end of the loop we have classes left with any non-system classes.
101
- classes.reject! do |classname|
102
- key, value, index = find_selector(classname)
103
- next false if key.nil?
104
-
105
- # Create array if nil
106
- obj[key] = Array.new(5, nil) if obj[key].nil?
107
- # Place the arguments in the responsive array based on index mr: [nil, 2]
108
- obj[key][index] = value
109
- next true
110
- end
111
-
112
- # Transform responsive arrays into arrays without trailing nil, so `mr: [1, nil, nil, nil, nil]` becomes `mr: 1`
113
- obj.transform_values! do |value|
114
- value = value.reverse.drop_while(&:nil?).reverse
115
- if value.count == 1
116
- value.first
117
- else
118
- value
119
- end
120
- end
121
-
122
- # Add back the non-system classes
123
- obj[:classes] = classes.join(" ") if classes.any?
124
- obj
125
- end
126
-
127
- def classes_to_args(classes)
128
- hash_to_args(classes_to_hash(classes))
129
- end
130
-
131
- def hash_to_args(hash)
132
- hash.map do |key, value|
133
- val = case value
134
- when Symbol
135
- ":#{value}"
136
- when String
137
- value.to_json
138
- else
139
- value
140
- end
141
-
142
- "#{key}: #{val}"
143
- end.join(", ")
144
- end
145
-
146
- def validate(key, val, breakpoint)
147
- unless supported_key?(key)
148
- raise ArgumentError, "#{key} is not a valid Ariadne utility key" if validate_class_names?
149
-
150
- return ""
151
- end
152
-
153
- unless breakpoint.empty? || responsive?(key, val)
154
- raise ArgumentError, "#{key} does not support responsive values" if validate_class_names?
155
-
156
- return ""
157
- end
158
-
159
- unless supported_value?(key, val)
160
- raise ArgumentError, "#{val} is not a valid value for :#{key}. Use one of #{mappings(key)}" if validate_class_names?
161
-
162
- return nil if [true, false].include?(val)
163
-
164
- return "#{key.to_s.dasherize}-#{val.to_s.dasherize}"
165
- end
166
-
167
- nil
168
- end
169
-
170
- private def find_selector(selector)
171
- key = infer_selector_key(selector)
172
- value_hash = UTILITIES[key]
173
-
174
- return nil if value_hash.blank?
175
-
176
- # Each value hash will also contain an array of classnames for breakpoints
177
- # Key argument `0`, classes `[ "mr-0", "mr-sm-0", "mr-md-0", "mr-lg-0", "mr-xl-0" ]`
178
- value_hash.each do |key_argument, classnames|
179
- # Skip each value hash until we get one with the selector
180
- next unless classnames.include?(selector)
181
-
182
- # Return [:mr, 0, 1]
183
- # has index of classname, so we can match it up with responsive array `mr: [nil, 0]`
184
- return [key, key_argument, classnames.index(selector)]
185
- end
186
-
187
- nil
188
- end
189
-
190
- private def infer_selector_key(selector)
191
- REPLACEMENT_KEYS.each do |k, v|
192
- return v.to_sym if selector.match?(Regexp.new(k))
193
- end
194
- selector.split("-").first.to_sym
195
- end
196
- end
197
- end
198
- end
199
- end