formstrap 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47528e297776dc1c0bfaf1d0d15fcbe65a6872631c1275d4cfcd1af722b92bad
4
- data.tar.gz: b8002a2e136bc2b14ae89b41a7641d9562cf23a151d6f37c94bb07d7fdcbcc99
3
+ metadata.gz: ee49a6e7a9f068d3403b4ebfd46c19cf07b6c293e8893f1e561e8ae20ed0af77
4
+ data.tar.gz: f85517d919e6c9360ac31c7f1aa7b8f2ff3705ea31a2a6a76f0b72ae82f58c30
5
5
  SHA512:
6
- metadata.gz: 402ca1e7525e7847453c7026d46828c6c60f73020cd77d927757cdbbecfbb29e3dbfad79cc08b3ffcb1e95be5b66d490fa437f4d52eda80c1180a68f2e7d5b6f
7
- data.tar.gz: 764ed214b9c39f07a01a7028b0a2b65ef4c3719717db522efd86936231eba94151f008d81274920af8d697ececef6fc60deca7ab3db0bfaa9c82b9ae4c727301
6
+ metadata.gz: ab80f8fd25603f0c9ce6f5ea6c92dc025b62f7b932f0b0e7bd7867bd4432845f902a6f5f7ba6492a6455ae9f3eb93fe411497a9dc2cf346538e3a610a05fd253
7
+ data.tar.gz: a5db302d1730c5f0cb801ddf248d24a0c5111ec0f8ae6d7aaa24d5a36c0e50913f1939a71df275c47429016162b59e47024a4be0e186e23b661c3393321cb9e4
@@ -3,22 +3,20 @@ import { Controller } from '@hotwired/stimulus'
3
3
  import Sortable from 'sortablejs'
4
4
 
5
5
  export default class extends Controller {
6
+ static get values () {
7
+ return {
8
+ name: String
9
+ }
10
+ }
11
+
6
12
  static get targets () {
7
13
  return ['item', 'template', 'thumbnails', 'modalButton', 'placeholder', 'count', 'editButton', 'validationInput']
8
14
  }
9
15
 
10
16
  connect () {
11
- document.addEventListener('mediaSelectionSubmitted', (event) => {
12
- if (event.detail.name === this.element.dataset.name) {
13
- this.selectItems(event.detail.items)
14
- }
15
- })
16
-
17
- // Init sorting
18
- if (this.hasSorting()) {
19
- this.initSortable()
20
- }
21
-
17
+ this.randomizeName()
18
+ this.listenForMediaSelection()
19
+ this.initializeSorting()
22
20
  this.validate()
23
21
  }
24
22
 
@@ -48,6 +46,34 @@ export default class extends Controller {
48
46
  }
49
47
 
50
48
  // Methods
49
+ randomizeName () {
50
+ this.nameValue = crypto.randomUUID().substring(0, 8)
51
+ this.updateModalButtonUrls()
52
+ }
53
+
54
+ updateModalButtonUrls () {
55
+ this.modalButtonTargets.forEach((button) => {
56
+ const url = new URL(button.getAttribute('href'))
57
+ url.searchParams.set('name', this.nameValue)
58
+ button.setAttribute('href', url.toString())
59
+ })
60
+ }
61
+
62
+ listenForMediaSelection () {
63
+ document.addEventListener('mediaSelectionSubmitted', (event) => {
64
+ if (event.detail.name === this.nameValue) {
65
+ this.selectItems(event.detail.items)
66
+ this.updateModalButtonUrls()
67
+ }
68
+ })
69
+ }
70
+
71
+ initializeSorting () {
72
+ if (this.hasSorting()) {
73
+ this.initSortable()
74
+ }
75
+ }
76
+
51
77
  initSortable () {
52
78
  Sortable.create(this.thumbnailsTarget, {
53
79
  handle: '.media-drag-sort-handle',
@@ -171,9 +197,8 @@ export default class extends Controller {
171
197
 
172
198
  createItem (item) {
173
199
  // Copy template
174
- const template = this.templateTarget
175
- const html = this.randomizeIds(template)
176
- this.thumbnailsTarget.insertAdjacentHTML('beforeend', html)
200
+ const templateHtml = this.templateTarget.innerHTML
201
+ this.thumbnailsTarget.insertAdjacentHTML('beforeend', templateHtml)
177
202
 
178
203
  // Set new values
179
204
  const newItem = this.itemTargets.pop()
@@ -192,12 +217,6 @@ export default class extends Controller {
192
217
  oldThumbnail.parentNode.replaceChild(newThumbnail, oldThumbnail)
193
218
  }
194
219
 
195
- randomizeIds (template) {
196
- const regex = new RegExp(template.dataset.templateIdRegex, 'g')
197
- const randomNumber = crypto.randomUUID().substring(0, 8)
198
- return template.innerHTML.replace(regex, randomNumber)
199
- }
200
-
201
220
  removeAllDeselectedItems (items) {
202
221
  this.removeDeselectedItems(items, this.itemTargets)
203
222
  }
@@ -4,7 +4,7 @@ import I18n from '../config/i18n'
4
4
 
5
5
  export default class extends Controller {
6
6
  connect () {
7
- if (this.element.hasAttribute('multiple')) {
7
+ if (this.element.hasAttribute('multiple') || this.element.dataset.tomSelect === 'true') {
8
8
  this.initTomSelect()
9
9
  }
10
10
  }
@@ -11076,18 +11076,18 @@ var sortable_esm_default = Sortable;
11076
11076
 
11077
11077
  // app/assets/javascripts/formstrap/controllers/media_controller.js
11078
11078
  var media_controller_default = class extends Controller {
11079
+ static get values() {
11080
+ return {
11081
+ name: String
11082
+ };
11083
+ }
11079
11084
  static get targets() {
11080
11085
  return ["item", "template", "thumbnails", "modalButton", "placeholder", "count", "editButton", "validationInput"];
11081
11086
  }
11082
11087
  connect() {
11083
- document.addEventListener("mediaSelectionSubmitted", (event) => {
11084
- if (event.detail.name === this.element.dataset.name) {
11085
- this.selectItems(event.detail.items);
11086
- }
11087
- });
11088
- if (this.hasSorting()) {
11089
- this.initSortable();
11090
- }
11088
+ this.randomizeName();
11089
+ this.listenForMediaSelection();
11090
+ this.initializeSorting();
11091
11091
  this.validate();
11092
11092
  }
11093
11093
  destroy(event) {
@@ -11106,6 +11106,30 @@ var media_controller_default = class extends Controller {
11106
11106
  button.setAttribute("href", url.toString());
11107
11107
  });
11108
11108
  }
11109
+ randomizeName() {
11110
+ this.nameValue = crypto.randomUUID().substring(0, 8);
11111
+ this.updateModalButtonUrls();
11112
+ }
11113
+ updateModalButtonUrls() {
11114
+ this.modalButtonTargets.forEach((button) => {
11115
+ const url = new URL(button.getAttribute("href"));
11116
+ url.searchParams.set("name", this.nameValue);
11117
+ button.setAttribute("href", url.toString());
11118
+ });
11119
+ }
11120
+ listenForMediaSelection() {
11121
+ document.addEventListener("mediaSelectionSubmitted", (event) => {
11122
+ if (event.detail.name === this.nameValue) {
11123
+ this.selectItems(event.detail.items);
11124
+ this.updateModalButtonUrls();
11125
+ }
11126
+ });
11127
+ }
11128
+ initializeSorting() {
11129
+ if (this.hasSorting()) {
11130
+ this.initSortable();
11131
+ }
11132
+ }
11109
11133
  initSortable() {
11110
11134
  sortable_esm_default.create(this.thumbnailsTarget, {
11111
11135
  handle: ".media-drag-sort-handle",
@@ -11197,9 +11221,8 @@ var media_controller_default = class extends Controller {
11197
11221
  item.classList.remove("d-none");
11198
11222
  }
11199
11223
  createItem(item) {
11200
- const template = this.templateTarget;
11201
- const html = this.randomizeIds(template);
11202
- this.thumbnailsTarget.insertAdjacentHTML("beforeend", html);
11224
+ const templateHtml = this.templateTarget.innerHTML;
11225
+ this.thumbnailsTarget.insertAdjacentHTML("beforeend", templateHtml);
11203
11226
  const newItem = this.itemTargets.pop();
11204
11227
  newItem.querySelector('input[name*="[blob_id]"]').value = item.blobId;
11205
11228
  newItem.querySelector('input[name*="[_destroy]"]').value = false;
@@ -11211,11 +11234,6 @@ var media_controller_default = class extends Controller {
11211
11234
  const newThumbnail = item.thumbnail.cloneNode(true);
11212
11235
  oldThumbnail.parentNode.replaceChild(newThumbnail, oldThumbnail);
11213
11236
  }
11214
- randomizeIds(template) {
11215
- const regex = new RegExp(template.dataset.templateIdRegex, "g");
11216
- const randomNumber = crypto.randomUUID().substring(0, 8);
11217
- return template.innerHTML.replace(regex, randomNumber);
11218
- }
11219
11237
  removeAllDeselectedItems(items) {
11220
11238
  this.removeDeselectedItems(items, this.itemTargets);
11221
11239
  }
@@ -13374,7 +13392,7 @@ var repeater_controller_default = class extends Controller {
13374
13392
  var import_tom_select = __toESM(require_tom_select_complete());
13375
13393
  var select_controller_default = class extends Controller {
13376
13394
  connect() {
13377
- if (this.element.hasAttribute("multiple")) {
13395
+ if (this.element.hasAttribute("multiple") || this.element.dataset.tomSelect === "true") {
13378
13396
  this.initTomSelect();
13379
13397
  }
13380
13398
  }
@@ -15,7 +15,6 @@
15
15
  }
16
16
 
17
17
  .rx-container {
18
- overflow: hidden;
19
18
  padding: 0 !important;
20
19
  border: var(--bs-border-width) solid var(--bs-border-color);
21
20
  border-radius: var(--bs-border-radius);
@@ -1299,7 +1299,6 @@ span.flatpickr-weekday {
1299
1299
  --bs-input-focus-color: var(--bs-body-color);
1300
1300
  }
1301
1301
  .rx-container {
1302
- overflow: hidden;
1303
1302
  padding: 0 !important;
1304
1303
  border: var(--bs-border-width) solid var(--bs-border-color);
1305
1304
  border-radius: var(--bs-border-radius);
@@ -18,7 +18,6 @@ module Formstrap
18
18
  class: ["mb-3", ("form-floating" if float)],
19
19
  data: {
20
20
  controller: "media",
21
- name: name,
22
21
  sort: sort,
23
22
  accept: accept,
24
23
  required: required.nil? ? 0 : required
@@ -122,7 +121,7 @@ module Formstrap
122
121
  end
123
122
 
124
123
  def modal_url
125
- formstrap_media_path(
124
+ formstrap_media_url(
126
125
  name: name,
127
126
  ids: blob_ids,
128
127
  min: min,
@@ -28,8 +28,6 @@ module Formstrap
28
28
  theme: "light",
29
29
  # Popup when highlighting text
30
30
  context: false,
31
- # Top toolbar
32
- toolbar: true,
33
31
  popups: {
34
32
  # Options in addbar popup (press + button)
35
33
  addbar: %w[format bold italic deleted list table link embed],
@@ -11,13 +11,16 @@ module Formstrap
11
11
  end
12
12
 
13
13
  def default_options
14
- {
14
+ options = {
15
15
  redactor: {
16
16
  context: !toolbar,
17
17
  extrabar: toolbar,
18
- toolbar: toolbar
19
18
  }
20
19
  }
20
+
21
+ options[:redactor][:toolbar] = false if @toolbar == false
22
+
23
+ options
21
24
  end
22
25
  end
23
26
  end
@@ -1,3 +1,3 @@
1
1
  module Formstrap
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontierdotbe/formstrap",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Bootstrap-powered Form Helpers",
5
5
  "module": "app/assets/javascripts/formstrap.js",
6
6
  "main": "app/assets/javascripts/formstrap.js",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jef Vlamings
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-16 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An extensive Bootstrap form library to power your Ruby On Rails application.
14
14
  email: