formstrap 0.3.5 → 0.4.1

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: 2752e4d93f3ae7a69795c95cf1e65783fccd46979b278b8af14a8b800a053486
4
- data.tar.gz: 156040c387523ad94ec3479d50c22f16db234cc93673588a84eed7eb45004f80
3
+ metadata.gz: 47528e297776dc1c0bfaf1d0d15fcbe65a6872631c1275d4cfcd1af722b92bad
4
+ data.tar.gz: b8002a2e136bc2b14ae89b41a7641d9562cf23a151d6f37c94bb07d7fdcbcc99
5
5
  SHA512:
6
- metadata.gz: 10a219f54dbf8e2bbf7b38b39876108488fa8bc03c10df60ebe52fa7225d202c27d7ef6918e1886474f3e866beddfb7f440a1b3c2fd14528eb78961590920031
7
- data.tar.gz: f60dc0b894f4cc4697fad1ce34de958e40340ddc6b62cc3c95c65233969d250b51ae30a74158d54c784e20237008150c54f8b6ae08a1ad915993ac5e723b3af2
6
+ metadata.gz: 402ca1e7525e7847453c7026d46828c6c60f73020cd77d927757cdbbecfbb29e3dbfad79cc08b3ffcb1e95be5b66d490fa437f4d52eda80c1180a68f2e7d5b6f
7
+ data.tar.gz: 764ed214b9c39f07a01a7028b0a2b65ef4c3719717db522efd86936231eba94151f008d81274920af8d697ececef6fc60deca7ab3db0bfaa9c82b9ae4c727301
@@ -1,3 +1,4 @@
1
+ /* global crypto */
1
2
  import { Controller } from '@hotwired/stimulus'
2
3
  import Sortable from 'sortablejs'
3
4
 
@@ -193,7 +194,7 @@ export default class extends Controller {
193
194
 
194
195
  randomizeIds (template) {
195
196
  const regex = new RegExp(template.dataset.templateIdRegex, 'g')
196
- const randomNumber = Math.floor(100000000 + Math.random() * 900000000)
197
+ const randomNumber = crypto.randomUUID().substring(0, 8)
197
198
  return template.innerHTML.replace(regex, randomNumber)
198
199
  }
199
200
 
@@ -126,7 +126,8 @@ export default class extends Controller {
126
126
  const formData = new FormData()
127
127
 
128
128
  // Replace all occurrences of "page[blocks_attributes][0]" with "block"
129
- const regex = /\w+\[([^\]]+)s_attributes]\[\d+]/g
129
+ // Replace all occurrences of "form[fields_attributes][random]" with "field"
130
+ const regex = /\w+\[([^\]]+)s_attributes]\[[^\]]+]/g
130
131
  const formElements = fields.querySelectorAll('input[name]:not([name$="[id]"]), select[name]:not([name$="[id]"]), textarea[name]:not([name$="[id]"]), button[name]:not([name$="[id]"])')
131
132
  formElements.forEach((element) => {
132
133
  const currentName = element.getAttribute('name')
@@ -1,5 +1,6 @@
1
1
  /* global Redactor */
2
2
  import { Controller } from '@hotwired/stimulus'
3
+ import 'redactor'
3
4
 
4
5
  export default class extends Controller {
5
6
  connect () {
@@ -1,3 +1,4 @@
1
+ /* global crypto */
1
2
  import { Controller } from '@hotwired/stimulus'
2
3
  import Sortable from 'sortablejs'
3
4
 
@@ -23,7 +24,6 @@ export default class extends Controller {
23
24
  this.resetPositions()
24
25
  }
25
26
  })
26
-
27
27
  this.toggleEmpty()
28
28
  }
29
29
 
@@ -38,8 +38,7 @@ export default class extends Controller {
38
38
  }
39
39
 
40
40
  updatePopupButtonIndices (index) {
41
- const popup = document.querySelector(`[data-popup-target="popup"][data-popup-id="repeater-buttons-${this.idValue}"]`)
42
- const buttons = popup.querySelectorAll('[data-popup-target="button"]')
41
+ const buttons = document.querySelectorAll(`[data-popup-target="button"][data-popup-id="repeater-buttons-${this.idValue}"]`)
43
42
  buttons.forEach((button) => {
44
43
  button.dataset.rowIndex = index
45
44
  })
@@ -53,7 +52,7 @@ export default class extends Controller {
53
52
 
54
53
  // Prepare html from template
55
54
  let template = this.getTemplate(templateName).content.cloneNode(true)
56
- template = this.replaceIdsWithTimestamps(template)
55
+ template = this.randomizeIds(template)
57
56
 
58
57
  // Fallback to last row if no index is set
59
58
  if (rowIndex) {
@@ -107,44 +106,24 @@ export default class extends Controller {
107
106
  })[0]
108
107
  }
109
108
 
110
- replaceIdsWithTimestamps (template) {
111
- const pattern = 'rrrrrrrrr'
112
- const replacement = new Date().getTime().toString()
109
+ randomizeIds (template) {
110
+ const randomNumber = crypto.randomUUID().substring(0, 8)
111
+ const pattern = `_${this.idValue}_`
113
112
  const regex = new RegExp(pattern, 'g')
114
113
 
115
- // Replace ids
116
- template.querySelectorAll(`input[id*="${pattern}"], select[id*="${pattern}"], textarea[id*="${pattern}"], button[id*="${pattern}"]`).forEach((node) => {
117
- const idValue = node.getAttribute('id')
118
- node.setAttribute('id', idValue.replace(pattern, replacement))
119
- })
120
-
121
- // Search and replace pattern in templates
122
- template.querySelectorAll('template').forEach((node) => {
123
- node.innerHTML = node.innerHTML.replace(regex, replacement)
124
- })
125
-
126
- // Replace labels
127
- template.querySelectorAll(`label[for*="${pattern}"]`).forEach((node) => {
128
- const forValue = node.getAttribute('for')
129
- node.setAttribute('for', forValue.replace(pattern, replacement))
130
- })
131
-
132
- // Replace names
133
- template.querySelectorAll(`input[name*="${pattern}"], select[name*="${pattern}"], textarea[name*="${pattern}"], button[name*="${pattern}"]`).forEach((node) => {
134
- const nameValue = node.getAttribute('name')
135
- node.setAttribute('name', nameValue.replace(pattern, replacement))
136
- })
137
-
138
- // Replace offcanvas targets
139
- template.querySelectorAll(`div[data-bs-target="#offcanvas-${pattern}"]`).forEach((node) => {
140
- const targetValue = node.getAttribute('data-bs-target')
141
- node.setAttribute('data-bs-target', targetValue.replace(pattern, replacement))
142
- })
114
+ // Loop through each node in the template
115
+ template.querySelectorAll('*').forEach(node => {
116
+ // Replace attribute values
117
+ for (const attribute of node.attributes) {
118
+ if (attribute.value.includes(pattern)) {
119
+ attribute.value = attribute.value.replace(pattern, randomNumber)
120
+ }
121
+ }
143
122
 
144
- // Replace offcanvas ids
145
- template.querySelectorAll(`.offcanvas[id="offcanvas-${pattern}"]`).forEach((node) => {
146
- const idValue = node.getAttribute('id')
147
- node.setAttribute('id', idValue.replace(pattern, replacement))
123
+ // Replace template content
124
+ if (node.nodeName === 'TEMPLATE' && node.innerHTML.includes(pattern)) {
125
+ node.innerHTML = node.innerHTML.replace(regex, randomNumber)
126
+ }
148
127
  })
149
128
 
150
129
  return template
@@ -11213,7 +11213,7 @@ var media_controller_default = class extends Controller {
11213
11213
  }
11214
11214
  randomizeIds(template) {
11215
11215
  const regex = new RegExp(template.dataset.templateIdRegex, "g");
11216
- const randomNumber = Math.floor(1e8 + Math.random() * 9e8);
11216
+ const randomNumber = crypto.randomUUID().substring(0, 8);
11217
11217
  return template.innerHTML.replace(regex, randomNumber);
11218
11218
  }
11219
11219
  removeAllDeselectedItems(items) {
@@ -11498,7 +11498,7 @@ var nested_preview_controller_default = class extends Controller {
11498
11498
  buildFormData() {
11499
11499
  const fields = this.fieldsTarget;
11500
11500
  const formData = new FormData();
11501
- const regex = /\w+\[([^\]]+)s_attributes]\[\d+]/g;
11501
+ const regex = /\w+\[([^\]]+)s_attributes]\[[^\]]+]/g;
11502
11502
  const formElements = fields.querySelectorAll('input[name]:not([name$="[id]"]), select[name]:not([name$="[id]"]), textarea[name]:not([name$="[id]"]), button[name]:not([name$="[id]"])');
11503
11503
  formElements.forEach((element) => {
11504
11504
  const currentName = element.getAttribute("name");
@@ -13229,6 +13229,7 @@ __publicField(preview_controller_default, "values", {
13229
13229
  });
13230
13230
 
13231
13231
  // app/assets/javascripts/formstrap/controllers/redactor_controller.js
13232
+ import "redactor";
13232
13233
  var redactor_controller_default = class extends Controller {
13233
13234
  connect() {
13234
13235
  this.initRedactor();
@@ -13275,8 +13276,7 @@ var repeater_controller_default = class extends Controller {
13275
13276
  return this.rowTargets.includes(row);
13276
13277
  }
13277
13278
  updatePopupButtonIndices(index2) {
13278
- const popup = document.querySelector(`[data-popup-target="popup"][data-popup-id="repeater-buttons-${this.idValue}"]`);
13279
- const buttons = popup.querySelectorAll('[data-popup-target="button"]');
13279
+ const buttons = document.querySelectorAll(`[data-popup-target="button"][data-popup-id="repeater-buttons-${this.idValue}"]`);
13280
13280
  buttons.forEach((button) => {
13281
13281
  button.dataset.rowIndex = index2;
13282
13282
  });
@@ -13287,7 +13287,7 @@ var repeater_controller_default = class extends Controller {
13287
13287
  const templateName = button.dataset.templateName;
13288
13288
  const rowIndex = button.dataset.rowIndex;
13289
13289
  let template = this.getTemplate(templateName).content.cloneNode(true);
13290
- template = this.replaceIdsWithTimestamps(template);
13290
+ template = this.randomizeIds(template);
13291
13291
  if (rowIndex) {
13292
13292
  const row = this.rowTargets[rowIndex];
13293
13293
  this.listTarget.insertBefore(template, row.nextSibling);
@@ -13323,32 +13323,19 @@ var repeater_controller_default = class extends Controller {
13323
13323
  return template.dataset.templateName === name;
13324
13324
  })[0];
13325
13325
  }
13326
- replaceIdsWithTimestamps(template) {
13327
- const pattern = "rrrrrrrrr";
13328
- const replacement = new Date().getTime().toString();
13326
+ randomizeIds(template) {
13327
+ const randomNumber = crypto.randomUUID().substring(0, 8);
13328
+ const pattern = `_${this.idValue}_`;
13329
13329
  const regex = new RegExp(pattern, "g");
13330
- template.querySelectorAll(`input[id*="${pattern}"], select[id*="${pattern}"], textarea[id*="${pattern}"], button[id*="${pattern}"]`).forEach((node) => {
13331
- const idValue = node.getAttribute("id");
13332
- node.setAttribute("id", idValue.replace(pattern, replacement));
13333
- });
13334
- template.querySelectorAll("template").forEach((node) => {
13335
- node.innerHTML = node.innerHTML.replace(regex, replacement);
13336
- });
13337
- template.querySelectorAll(`label[for*="${pattern}"]`).forEach((node) => {
13338
- const forValue = node.getAttribute("for");
13339
- node.setAttribute("for", forValue.replace(pattern, replacement));
13340
- });
13341
- template.querySelectorAll(`input[name*="${pattern}"], select[name*="${pattern}"], textarea[name*="${pattern}"], button[name*="${pattern}"]`).forEach((node) => {
13342
- const nameValue = node.getAttribute("name");
13343
- node.setAttribute("name", nameValue.replace(pattern, replacement));
13344
- });
13345
- template.querySelectorAll(`div[data-bs-target="#offcanvas-${pattern}"]`).forEach((node) => {
13346
- const targetValue = node.getAttribute("data-bs-target");
13347
- node.setAttribute("data-bs-target", targetValue.replace(pattern, replacement));
13348
- });
13349
- template.querySelectorAll(`.offcanvas[id="offcanvas-${pattern}"]`).forEach((node) => {
13350
- const idValue = node.getAttribute("id");
13351
- node.setAttribute("id", idValue.replace(pattern, replacement));
13330
+ template.querySelectorAll("*").forEach((node) => {
13331
+ for (const attribute of node.attributes) {
13332
+ if (attribute.value.includes(pattern)) {
13333
+ attribute.value = attribute.value.replace(pattern, randomNumber);
13334
+ }
13335
+ }
13336
+ if (node.nodeName === "TEMPLATE" && node.innerHTML.includes(pattern)) {
13337
+ node.innerHTML = node.innerHTML.replace(regex, randomNumber);
13338
+ }
13352
13339
  });
13353
13340
  return template;
13354
13341
  }
@@ -99,7 +99,7 @@
99
99
  display: none;
100
100
  }
101
101
 
102
- .rx-form-input, .rx-form-textarea {
102
+ .rx-form-input, .rx-form-textarea, .rx-form-select {
103
103
  border-radius: var(--bs-border-radius);
104
104
  background: var(--bs-body-bg);
105
105
  border: var(--bs-border-width) solid var(--bs-border-color);