bullet_train-fields 1.0.19 → 1.2.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: 955500ace762c8286cd55318ac27669c0967adfcd5198c6c88db4542f9c553a9
4
- data.tar.gz: 391e21fabc859f7ea4b209fc676d5e33a215dcc3defb14bb0726a05176d3976b
3
+ metadata.gz: d04eb382cf117ef08b66d7edf6db0178cb042696060de27d637b25c18202b6b9
4
+ data.tar.gz: 840e1a9b9975c23ac2895abf87a42aabfc442f4e3fc736a1bde34ec37f2e1960
5
5
  SHA512:
6
- metadata.gz: b6ba652dfd29a7550d65b51f05b8c68e318731e0fc40064a9d21f2306442608a026a12f9f5f14e4c55d2cbc1f8da1a4d1cc410fac03916bd0da0d37ab2cadfd5
7
- data.tar.gz: e70c866711efec589e7f64a4b32b42ceaa8e8b0f53487adb294ad5332bda66490e551d0db4dd620be4e26e420ba551f3b5e33390e8e341ded720901956d8942d
6
+ metadata.gz: 953af0dd524d37380390b1d1e612dcf636986425051f243563580e6d5616ac3b0f421c55696bbe79bf541760c343369343a5970f171a3efb4a7eaf2b7ae76db6
7
+ data.tar.gz: 9db0823ce9063a4195051d6984d6f1af4f556ec29fe5a99b59da2ce3d2977de0886ed7e82e17b59725bd7f92ec88ad795c9216a5efbc1571b495c032a484a664
@@ -5,9 +5,4 @@ module Fields::TrixEditorHelper
5
5
  def trix_sanitize(html)
6
6
  html_sanitize(html)
7
7
  end
8
-
9
- # TODO Confirm there are no references to this anywhere (in other repositories) and remove it.
10
- def trix_content(body)
11
- html_sanitize(body)
12
- end
13
8
  end
@@ -1,18 +1,32 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
  import '@simonwep/pickr/dist/themes/monolith.min.css'
3
3
 
4
- import Pickr from '@simonwep/pickr';
4
+ import Pickr from '@simonwep/pickr'
5
5
 
6
- const pickerHexInputSelector = 'input.pcr-result'
6
+ const generatedPickerHexInputSelector = 'input.pcr-result'
7
7
 
8
8
  export default class extends Controller {
9
- static targets = [ "colorPickerValue", "colorField", "colorInput", "userSelectedColor", "colorOptions", "pickerContainer", "togglePickerButton", "colorButton" ];
9
+ static targets = [
10
+ 'colorPickerValue',
11
+ 'colorField',
12
+ 'colorInput',
13
+ 'userSelectedColor',
14
+ 'colorOptions',
15
+ 'pickerContainer',
16
+ 'togglePickerButton',
17
+ 'colorButton',
18
+ ]
10
19
  static values = { initialColor: String }
11
- static classes = [ "colorSelected" ]
20
+ static classes = ['colorSelected']
12
21
 
13
22
  connect() {
14
23
  this.initPluginInstance()
15
- this.colorOptions = $(this.colorOptionsTarget).find('button').map(function (_, button) { return $(button).attr('data-color'); }).get()
24
+ this.colorOptions = $(this.colorOptionsTarget)
25
+ .find('button')
26
+ .map(function (_, button) {
27
+ return $(button).attr('data-color').toLowerCase()
28
+ })
29
+ .get()
16
30
  }
17
31
 
18
32
  disconnect() {
@@ -20,60 +34,59 @@ export default class extends Controller {
20
34
  }
21
35
 
22
36
  pickColor(event) {
23
- event.preventDefault();
37
+ event.preventDefault()
24
38
 
25
- const targetEl = event.target;
26
- const color = targetEl.dataset.color;
39
+ const targetEl = event.target
40
+ const color = targetEl.dataset.color
27
41
 
28
- $(this.colorInputTarget).val(color);
29
- $(this.colorPickerValueTarget).val(color);
30
- $(this.userSelectedColorTarget).data('color', color);
31
- this.highlightColorButtonsMatchingSelectedColor()
42
+ $(this.colorInputTarget).val(color)
43
+ $(this.colorPickerValueTarget).val(color)
44
+ $(this.userSelectedColorTarget).data('color', color)
32
45
 
33
- this.pickr.setColor(color);
46
+ this.pickr.setColor(color)
34
47
  }
35
48
 
36
49
  pickRandomColor(event) {
37
- event.preventDefault();
50
+ event.preventDefault()
38
51
 
39
- const r = Math.floor(Math.random() * 256);
40
- const g = Math.floor(Math.random() * 256);
41
- const b = Math.floor(Math.random() * 256);
52
+ const r = Math.floor(Math.random() * 256)
53
+ const g = Math.floor(Math.random() * 256)
54
+ const b = Math.floor(Math.random() * 256)
42
55
 
43
- this.pickr.setColor(`rgb ${r} ${g} ${b}`);
44
- const hexColor = this.pickr.getColor().toHEXA().toString();
45
- this.pickr.setColor(hexColor);
56
+ this.pickr.setColor(`rgb ${r} ${g} ${b}`)
57
+ const hexColor = this.pickr.getColor().toHEXA().toString()
58
+ this.pickr.setColor(hexColor)
46
59
 
47
- this.showUserSelectedColor(hexColor);
60
+ this.showUserSelectedColor(hexColor)
48
61
  }
49
62
 
50
63
  showUserSelectedColor(color) {
51
- $(this.colorInputTarget).val(color);
52
- $(this.colorPickerValueTarget).val(color);
53
-
54
- this.highlightColorButtonsMatchingSelectedColor()
64
+ $(this.colorInputTarget).val(color)
65
+ $(this.colorPickerValueTarget).val(color)
55
66
 
56
67
  $(this.userSelectedColorTarget)
57
- .addClass('ring-2')
58
- .addClass('ring-offset-2')
59
68
  .css('background-color', color)
60
69
  .css('--tw-ring-color', color)
61
70
  .attr('data-color', color)
62
- .show();
71
+ .show()
63
72
  }
64
73
 
65
74
  unpickColor(event) {
66
- event.preventDefault();
67
- $(this.colorPickerValueTarget).val('');
68
- $(this.colorInputTarget).val('');
69
- $(this.userSelectedColorTarget).hide();
70
- this.highlightColorButtonsMatchingSelectedColor()
75
+ event.preventDefault()
76
+ $(this.colorPickerValueTarget).val('')
77
+ $(this.colorInputTarget).val('')
78
+ $(this.userSelectedColorTarget).hide()
79
+ this.dispatchChangeEvent()
71
80
  }
72
-
81
+
82
+ dispatchChangeEvent() {
83
+ this.colorInputTarget.dispatchEvent(new Event('change'))
84
+ }
85
+
73
86
  highlightColorButtonsMatchingSelectedColor() {
74
87
  this.colorButtonTargets.forEach((button) => {
75
88
  const buttonColor = button.dataset?.color
76
- if (this.selectedColor !== undefined && buttonColor === this.selectedColor) {
89
+ if (this.selectedColor !== undefined && buttonColor.toLowerCase() === this.selectedColor.toLowerCase()) {
77
90
  button.classList.add(...this.colorSelectedClasses)
78
91
  } else {
79
92
  button.classList.remove(...this.colorSelectedClasses)
@@ -82,7 +95,7 @@ export default class extends Controller {
82
95
  }
83
96
 
84
97
  togglePickr(event) {
85
- event.preventDefault();
98
+ event.preventDefault()
86
99
  }
87
100
 
88
101
  initPluginInstance() {
@@ -102,22 +115,28 @@ export default class extends Controller {
102
115
  input: true,
103
116
  save: true,
104
117
  },
105
- }
106
- });
118
+ },
119
+ })
107
120
 
108
121
  this.pickr.on('save', (color, _instance) => {
109
- const hexaColor = color.toHEXA().toString()
122
+ const hexaColor = color.toHEXA().toString().toLowerCase()
110
123
  if (!this.colorOptions.includes(hexaColor)) {
111
- this.showUserSelectedColor(hexaColor);
124
+ this.showUserSelectedColor(hexaColor)
112
125
  }
113
- this.pickr.hide();
114
- });
126
+ this.dispatchChangeEvent()
127
+ this.highlightColorButtonsMatchingSelectedColor()
128
+ this.pickr.hide()
129
+ })
115
130
  }
116
-
131
+
117
132
  handleKeydown(event) {
118
- if (!event.target.matches(pickerHexInputSelector)) { return }
119
- if (event.key !== 'Enter') { return }
120
-
133
+ if (!event.target.matches(generatedPickerHexInputSelector)) {
134
+ return
135
+ }
136
+ if (event.key !== 'Enter') {
137
+ return
138
+ }
139
+
121
140
  event.preventDefault()
122
141
  event.stopPropagation()
123
142
  this.pickr.applyColor(false)
@@ -126,7 +145,7 @@ export default class extends Controller {
126
145
  teardownPluginInstance() {
127
146
  this.pickr.destroy()
128
147
  }
129
-
148
+
130
149
  get selectedColor() {
131
150
  return $(this.colorInputTarget).val()
132
151
  }
@@ -0,0 +1,57 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = [ "field" ]
5
+ static values = {
6
+ original: String,
7
+ dirty: Boolean
8
+ }
9
+
10
+ connect() {
11
+ this.recordOriginal()
12
+ }
13
+
14
+ recordOriginal() {
15
+ if (!this.hasOriginalValue) {
16
+ this.originalValue = this.value
17
+ }
18
+ this.dispatch('original-recorded', {
19
+ detail: { originalValue: this.originalValue },
20
+ target: this.field
21
+ })
22
+ }
23
+
24
+ revert(event) {
25
+ if (this.hasOriginalValue) {
26
+ this.value = this.originalValue
27
+ }
28
+ this.dispatch('reverted')
29
+ }
30
+
31
+ get field() {
32
+ if (this.hasFieldTarget) {
33
+ return this.fieldTarget
34
+ }
35
+ return this.element
36
+ }
37
+
38
+ get value() {
39
+ switch (this.field.type) {
40
+ case "checkbox":
41
+ return this.field.checked
42
+ }
43
+
44
+ return this.field.value
45
+ }
46
+
47
+ set value(newValue) {
48
+ switch (this.field.type) {
49
+ case "checkbox":
50
+ this.field.checked = (newValue === "true" || newValue === true)
51
+ break
52
+ default:
53
+ this.field.value = newValue
54
+ break
55
+ }
56
+ }
57
+ }
@@ -20,7 +20,7 @@ export default class extends Controller {
20
20
  this.progressBarTarget.style.width = "0%";
21
21
  this.progressBarTarget.setAttribute("aria-valuenow", 0);
22
22
  this.progressBarTarget.parentNode.classList.remove("hidden");
23
- this.progressLabel.innerText = "0%";
23
+ this.progressLabelTarget.innerText = "0%";
24
24
  }
25
25
  );
26
26
 
@@ -16,13 +16,13 @@ export default class extends Controller {
16
16
 
17
17
  initialize() {
18
18
  this.dispatchNativeEvent = this.dispatchNativeEvent.bind(this)
19
- if (this.isSelect2LoadedOnWindowJquery) {
20
- select2(window.$)
19
+ if (!this.isSelect2LoadedOnWindowJquery) {
20
+ select2()
21
21
  }
22
22
  }
23
23
 
24
24
  get isSelect2LoadedOnWindowJquery() {
25
- return (window.$ !== undefined && window.$.select2 === undefined)
25
+ return window?.$?.fn?.select2 !== undefined
26
26
  }
27
27
 
28
28
  connect() {
@@ -40,7 +40,9 @@ export default class extends Controller {
40
40
  }
41
41
 
42
42
  initPluginInstance() {
43
- let options = {};
43
+ let options = {
44
+ dropdownParent: $(this.element)
45
+ };
44
46
 
45
47
  if (!this.enableSearchValue) {
46
48
  options.minimumResultsForSearch = -1;
@@ -1,5 +1,6 @@
1
1
  import { identifierForContextKey } from "@hotwired/stimulus-webpack-helpers"
2
2
 
3
+ import FieldController from './fields/field_controller'
3
4
  import ButtonToggleController from './fields/button_toggle_controller'
4
5
  import CloudinaryImageController from './fields/cloudinary_image_controller'
5
6
  import ColorPickerController from './fields/color_picker_controller'
@@ -11,6 +12,7 @@ import PhoneController from './fields/phone_controller'
11
12
  import SuperSelectController from './fields/super_select_controller'
12
13
 
13
14
  export const controllerDefinitions = [
15
+ [FieldController, 'fields/field_controller.js'],
14
16
  [ButtonToggleController, 'fields/button_toggle_controller.js'],
15
17
  [CloudinaryImageController, 'fields/cloudinary_image_controller.js'],
16
18
  [ColorPickerController, 'fields/color_picker_controller.js'],
@@ -30,6 +32,7 @@ export const controllerDefinitions = [
30
32
  })
31
33
 
32
34
  export {
35
+ FieldController,
33
36
  ButtonToggleController,
34
37
  CloudinaryImageController,
35
38
  ColorPickerController,
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Fields
3
- VERSION = "1.0.19"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train-fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.19
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-25 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard
@@ -109,6 +109,7 @@ files:
109
109
  - app/javascript/controllers/fields/color_picker_controller.js
110
110
  - app/javascript/controllers/fields/date_controller.js
111
111
  - app/javascript/controllers/fields/emoji_picker_controller.js
112
+ - app/javascript/controllers/fields/field_controller.js
112
113
  - app/javascript/controllers/fields/file_field_controller.js
113
114
  - app/javascript/controllers/fields/password_controller.js
114
115
  - app/javascript/controllers/fields/phone_controller.js