para 0.12.2 → 0.12.3

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: e5f4c1a9a889b3800d615452bda318bac05fc3d49b88c612af3cd2a714cb3fe8
4
- data.tar.gz: a665a5affd7b2a3938baf185c41221eed335b42be7dabf8ff1d17145212dfecb
3
+ metadata.gz: d2e8f3dd97232094cbf6840ad5ec462068c43019dec82f3c872d48bb5f0d8ffa
4
+ data.tar.gz: 2b3d6cd3dbfa31daef6cdca4e3e040843f10e350f02c9687dec51f1c641de12c
5
5
  SHA512:
6
- metadata.gz: 7a71ed497361f0b442965a7331159d9c2c2dfd7f745674f8698f446e1a6651f3bdfacd96f314f2e00d657ba13390f55ca317221aca45284d6770419bd820be79
7
- data.tar.gz: 6e1bb4347edeacd0f067dc401e77ce72926ed9ae9d4e61326799376d3ca7063db196a275c58b79d96c29e21ba5004d56f8cdbb976c98dfac22f91522b352955a
6
+ metadata.gz: 1c5d0d01332d290463ac6b3c856e2260ee62625ceb9a9e76ea0887f13188ce7df691b23be95e40b20b271a19c5650975844944c6bf1f50262b8677eaa7189d86
7
+ data.tar.gz: 29ad0aba0dc5ac675f601e8891641aa28e38649550202a03858c46a9703e2a257a52e09bf5ee21ce74f6ca21e877c141888f081ffdba6b88c69fb1bafa4cadd3
@@ -8,3 +8,6 @@ application.register("para-admin-flash-message", ParaAdminFlashMessageController
8
8
 
9
9
  import SelectizeFieldController from "./selectize_field_controller";
10
10
  application.register("selectize-field", SelectizeFieldController);
11
+
12
+ import NestedManyInputController from "./nested_many_input_controller";
13
+ application.register("nested-many-input", NestedManyInputController);
@@ -1,52 +1,70 @@
1
- Para.NestedManyField = class NestedManyField {
2
- constructor($field1) {
1
+ import { Controller } from '@hotwired/stimulus';
2
+
3
+ export default class extends Controller {
4
+ connect() {
3
5
  this.stoppingPropagation = this.stoppingPropagation.bind(this);
4
6
  this.afterInsertField = this.afterInsertField.bind(this);
5
7
  this.beforeRemoveField = this.beforeRemoveField.bind(this);
6
- // When a sub field is removed, update every sub field position
8
+ this.handleOrderingUpdated = this.handleOrderingUpdated.bind(this);
7
9
  this.afterRemoveField = this.afterRemoveField.bind(this);
8
10
  this.collapseShown = this.collapseShown.bind(this);
9
- this.$field = $field1;
11
+
12
+ this.$field = $(this.element);
10
13
  this.$fieldsList = this.$field.find('.fields-list');
11
- this.initializeOrderable();
14
+ this.initializeSortable();
12
15
  this.initializeCocoon();
13
16
  this.$field.on('shown.bs.collapse', this.stoppingPropagation(this.collapseShown));
14
17
  }
15
18
 
16
- initializeOrderable() {
17
- this.orderable = this.$field.hasClass('orderable');
18
- if (!this.orderable) {
19
- return;
20
- }
19
+ initializeSortable() {
20
+ this.isSortable = this.$field.hasClass('orderable');
21
+
22
+ if (!this.isSortable) return;
23
+
21
24
  return this.$fieldsList.sortable({
22
25
  handle: '.order-anchor',
23
26
  animation: 150,
24
- onUpdate: $.proxy(this.handleOrderingUpdated, this)
27
+ onUpdate: this.handleOrderingUpdated
25
28
  });
26
29
  }
27
30
 
28
31
  handleOrderingUpdated() {
29
32
  var formFields;
30
33
  formFields = [];
34
+
31
35
  return this.$fieldsList.find('.form-fields:visible').each(function(_i, el) {
32
- var $el, $parent, isNestedField, j, len;
36
+ let $parent, isNestedField, j, len;
37
+
33
38
  for (j = 0, len = formFields.length; j < len; j++) {
34
39
  $parent = formFields[j];
35
40
  isNestedField = $parent.find(el).length;
36
41
  }
42
+
37
43
  if (isNestedField) {
38
44
  return;
39
45
  }
40
- $el = $(el);
46
+
47
+ const $el = $(el);
41
48
  $el.find('.resource-position-field:eq(0)').val(formFields.length);
42
49
  return formFields.push($el);
43
50
  });
44
51
  }
45
52
 
46
53
  initializeCocoon() {
47
- this.$fieldsList.on('cocoon:after-insert', this.stoppingPropagation(this.afterInsertField));
48
- this.$fieldsList.on('cocoon:before-remove', this.stoppingPropagation(this.beforeRemoveField));
49
- return this.$fieldsList.on('cocoon:after-remove', this.stoppingPropagation(this.afterRemoveField));
54
+ this.$fieldsList.on(
55
+ 'cocoon:after-insert',
56
+ this.stoppingPropagation(this.afterInsertField)
57
+ );
58
+
59
+ this.$fieldsList.on(
60
+ 'cocoon:before-remove',
61
+ this.stoppingPropagation(this.beforeRemoveField)
62
+ );
63
+
64
+ return this.$fieldsList.on(
65
+ 'cocoon:after-remove',
66
+ this.stoppingPropagation(this.afterRemoveField)
67
+ );
50
68
  }
51
69
 
52
70
  stoppingPropagation(callback) {
@@ -61,9 +79,9 @@ Para.NestedManyField = class NestedManyField {
61
79
  if (($collapsible = $element.find('[data-open-on-insert="true"]')).length) {
62
80
  this.openInsertedField($collapsible);
63
81
  }
64
- if (this.orderable) {
82
+ if (this.isSortable) {
65
83
  this.$fieldsList.sortable('destroy');
66
- this.initializeOrderable();
84
+ this.initializeSortable();
67
85
  this.handleOrderingUpdated();
68
86
  }
69
87
  return $element.simpleForm();
@@ -90,22 +108,24 @@ Para.NestedManyField = class NestedManyField {
90
108
  }
91
109
 
92
110
  collapseShown(e) {
93
- var $target;
94
- $target = $(e.target);
95
- if ($target.is("[data-rendered]") || $target.data("rendered")) {
96
- return this.initializeCollapseContent($target);
111
+ const { target } = e;
112
+
113
+ if (target.dataset.isRendered) {
114
+ return this.initializeCollapseContent(target);
97
115
  } else {
98
- this.loadCollapseContent($target);
99
- return this.scrollToTarget($target);
116
+ this.loadCollapseContent(target);
117
+ return this.scrollToTarget(target);
100
118
  }
101
119
  }
102
120
 
103
- initializeCollapseContent($target) {
104
- this.scrollToTarget($target);
105
- return this.focusFirstField($target);
121
+ initializeCollapseContent(target) {
122
+ this.scrollToTarget(target);
123
+ return this.focusFirstVisibleInputInside(target);
106
124
  }
107
125
 
108
- scrollToTarget($target) {
126
+ scrollToTarget(target) {
127
+ const $target = $(target);
128
+
109
129
  var $affixNavTabs, $field, scrollOffset;
110
130
  $field = this.$field.find(`[data-toggle='collapse'][href='#${$target.attr('id')}']`);
111
131
  scrollOffset = -($('[data-header]').outerHeight() + 30);
@@ -117,35 +137,32 @@ Para.NestedManyField = class NestedManyField {
117
137
  });
118
138
  }
119
139
 
120
- focusFirstField($target) {
121
- return $target.find('input, textarea, select').eq('0').focus();
140
+ focusFirstVisibleInputInside(target) {
141
+ setTimeout(() => {
142
+ target.querySelector('input:not([type="hidden"]), textarea, select')?.focus();
143
+ }, 100);
122
144
  }
123
145
 
124
- loadCollapseContent($target) {
125
- var data, targetUrl;
126
- targetUrl = $target.data("render-path");
127
- if (!targetUrl) {
128
- return;
129
- }
130
- data = {
131
- "id": $target.data("id"),
132
- "object_name": $target.data("object-name"),
133
- "model_name": $target.data("model-name")
146
+ loadCollapseContent(target) {
147
+ const $target = $(target);
148
+ const targetUrl = target.dataset.renderPath;
149
+
150
+ if (!targetUrl) return;
151
+
152
+ const data = {
153
+ id: target.dataset.id,
154
+ object_name: target.dataset.objectName,
155
+ model_name: target.dataset.modelName
134
156
  };
135
- return $.get(targetUrl, data).then((resp) => {
136
- var $content;
137
- $content = $(resp);
138
- $target.find("[data-nested-form-container]:eq(0)").html($content);
157
+
158
+ $.get(targetUrl, data).then((resp) => {
159
+ const $content = $(resp);
160
+ $target.find('[data-nested-form-container]:eq(0)').html($content);
139
161
  $content.simpleForm();
140
- this.focusFirstField($target);
141
- return $target.data("rendered", true);
162
+
163
+ this.focusFirstVisibleInputInside(target);
164
+
165
+ target.dataset.isRendered = true;
142
166
  });
143
167
  }
144
-
145
168
  };
146
-
147
- $.simpleForm.onDomReady(function($document) {
148
- return $document.find('.nested-many-field').each(function(i, el) {
149
- return new Para.NestedManyField($(el));
150
- });
151
- });
@@ -14,9 +14,7 @@ import "./vendor/jquery.sortable";
14
14
 
15
15
  import "./application";
16
16
 
17
- import "./inputs/material-input";
18
17
  import "./inputs/multi-select-input";
19
- import "./inputs/nested_many";
20
18
 
21
19
  import "./admin/async-progress";
22
20
  import "./admin/filters-form";
@@ -1,4 +1,4 @@
1
- .nested-many-field{ class: [('orderable' if orderable), ('nested-many-field-inset' if inset)] }
1
+ .nested-many-field{ class: [('orderable' if orderable), ('nested-many-field-inset' if inset)], data: { controller: "nested-many-input" } }
2
2
  .fields-list{ id: dom_identifier }
3
3
  = form.simple_fields_for attribute_name, resources, nested_attribute_name: attribute_name, orderable: orderable, track_attribute_mappings: render_partial do |nested_form|
4
4
  = render partial: find_partial_for(model, 'nested_many/container', partial_dir: 'inputs'), locals: { form: nested_form, model: nested_form.object.class, subclass: subclass, allow_destroy_if: allow_destroy_if, nested_locals: nested_locals, inset: inset, uncollapsed: uncollapsed, render_partial: render_partial, remote_partial_params: remote_partial_params }
data/lib/para/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Para
4
- VERSION = '0.12.2'
4
+ VERSION = '0.12.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-26 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_decorator
@@ -479,13 +479,12 @@ files:
479
479
  - app/javascripts/para/application.js
480
480
  - app/javascripts/para/controllers/application.js
481
481
  - app/javascripts/para/controllers/index.js
482
+ - app/javascripts/para/controllers/nested_many_input_controller.js
482
483
  - app/javascripts/para/controllers/para_admin_flash_message_controller.js
483
484
  - app/javascripts/para/controllers/para_admin_modal_controller.js
484
485
  - app/javascripts/para/controllers/selectize_field_controller.js
485
486
  - app/javascripts/para/index.js
486
- - app/javascripts/para/inputs/material-input.js
487
487
  - app/javascripts/para/inputs/multi-select-input.js
488
- - app/javascripts/para/inputs/nested_many.js
489
488
  - app/javascripts/para/lib/fetch.js
490
489
  - app/javascripts/para/plugins-includes.js.erb
491
490
  - app/javascripts/para/simple_form_extension/colorpicker.js
@@ -793,7 +792,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
793
792
  - !ruby/object:Gem::Version
794
793
  version: '0'
795
794
  requirements: []
796
- rubygems_version: 3.4.8
795
+ rubygems_version: 3.5.17
797
796
  signing_key:
798
797
  specification_version: 4
799
798
  summary: Rails admin engine
@@ -1,7 +0,0 @@
1
- $(document).on('page:change turbo:load turbo:frame-load', function() {
2
- return $('body').on('focusin focusout', 'input, select, textarea', function(e) {
3
- var focused;
4
- focused = e.type === 'focusin';
5
- return $(e.target).closest('.form-group').toggleClass('focused', focused);
6
- });
7
- });