bullet_train-fields 1.0.2 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  import { Controller } from "stimulus"
2
- import I18n from "i18n-js/index.js.erb"
3
2
  require("daterangepicker/daterangepicker.css");
4
3
 
5
4
  // requires jQuery, moment, might want to consider a vanilla JS alternative
@@ -7,7 +6,12 @@ import 'daterangepicker';
7
6
 
8
7
  export default class extends Controller {
9
8
  static targets = [ "field", "clearButton", "currentTimeZoneWrapper", "timeZoneButtons", "timeZoneSelectWrapper", "timeZoneField" ]
10
- static values = { includeTime: Boolean, defaultTimeZones: Array }
9
+ static values = {
10
+ includeTime: Boolean,
11
+ defaultTimeZones: Array,
12
+ cancelButtonLabel: String,
13
+ applyButtonLabel: String
14
+ }
11
15
 
12
16
  connect() {
13
17
  this.initPluginInstance()
@@ -82,8 +86,8 @@ export default class extends Controller {
82
86
  timePickerIncrement: 5,
83
87
  autoUpdateInput: false,
84
88
  locale: {
85
- cancelLabel: I18n.t('fields.date_field.cancel'),
86
- applyLabel: I18n.t('fields.date_field.apply'),
89
+ cancelLabel: (this.hasCancelButtonLabelValue)? this.cancelButtonLabelValue: "cancel",
90
+ applyLabel: (this.hasApplyButtonLabelValue)? this.applyButtonLabelValue: "apply",
87
91
  format: this.includeTimeValue ? 'MM/DD/YYYY h:mm A' : 'MM/DD/YYYY'
88
92
  }
89
93
  })
@@ -1,5 +1,5 @@
1
1
  import { Controller } from "stimulus"
2
- import 'intl-tel-input/build/css/intlTelInput.css';
2
+ require("intl-tel-input/build/css/intlTelInput.css");
3
3
  import intlTelInput from 'intl-tel-input';
4
4
 
5
5
  export default class extends Controller {
@@ -14,13 +14,18 @@ export default class extends Controller {
14
14
  }
15
15
 
16
16
  initPluginInstance() {
17
- this.plugin = intlTelInput(this.fieldTarget, {
17
+ let options = {
18
18
  hiddenInput: this.fieldTarget.dataset.method,
19
- // See `config/webpack/environment.js` for where we copy this into place.
20
- // TODO Wish we could somehow incorporate webpacker's cache-breaking hash into this. Anyone know how?
21
- utilsScript: "/assets/intl-tel-input/utils.js",
22
19
  customContainer: "w-full"
23
- });
20
+ }
21
+
22
+ // TODO: add instructions on how to copy this asset into the application's assets path and write the meta tag into the head (via the engine?)
23
+ const utilsScriptPath = metaContent("intl_tel_input_utils_path")
24
+ if (utilsScriptPath) {
25
+ options['utilsScript'] = utilsScriptPath
26
+ }
27
+
28
+ this.plugin = intlTelInput(this.fieldTarget, options);
24
29
  }
25
30
 
26
31
  teardownPluginInstance() {
@@ -30,3 +35,8 @@ export default class extends Controller {
30
35
  this.plugin.destroy()
31
36
  }
32
37
  }
38
+
39
+ function metaContent (name) {
40
+ const element = document.head.querySelector(`meta[name="${name}"]`)
41
+ return element && element.content
42
+ }
@@ -1,7 +1,6 @@
1
1
  import { Controller } from "stimulus"
2
2
  require("select2/dist/css/select2.min.css");
3
- import $ from 'jquery';
4
- import 'select2';
3
+ import select2 from "select2";
5
4
 
6
5
  export default class extends Controller {
7
6
  static targets = [ "select" ]
@@ -11,8 +10,20 @@ export default class extends Controller {
11
10
  searchUrl: String,
12
11
  }
13
12
 
13
+ initialize() {
14
+ if (this.isSelect2LoadedOnWindowJquery) {
15
+ select2(window.$)
16
+ }
17
+ }
18
+
19
+ get isSelect2LoadedOnWindowJquery() {
20
+ return (window.$ !== undefined && window.$.select2 === undefined)
21
+ }
22
+
14
23
  connect() {
15
- this.initPluginInstance()
24
+ if (this.isSelect2LoadedOnWindowJquery) {
25
+ this.initPluginInstance()
26
+ }
16
27
  }
17
28
 
18
29
  disconnect() {
@@ -0,0 +1,36 @@
1
+ import { identifierForContextKey } from "@stimulus/webpack-helpers"
2
+
3
+ import ButtonToggleController from './fields/button_toggle_controller'
4
+ import CloudinaryImageController from './fields/cloudinary_image_controller'
5
+ import ColorPickerController from './fields/color_picker_controller'
6
+ import DateController from './fields/date_controller'
7
+ import FileFieldController from './fields/file_field_controller'
8
+ import PhoneController from './fields/phone_controller'
9
+ import SuperSelectController from './fields/super_select_controller'
10
+
11
+ export const controllerDefinitions = [
12
+ [ButtonToggleController, 'fields/button_toggle_controller.js'],
13
+ [CloudinaryImageController, 'fields/cloudinary_image_controller.js'],
14
+ [ColorPickerController, 'fields/color_picker_controller.js'],
15
+ [DateController, 'fields/date_controller.js'],
16
+ [FileFieldController, 'fields/file_field_controller.js'],
17
+ [PhoneController, 'fields/phone_controller.js'],
18
+ [SuperSelectController, 'fields/super_select_controller.js']
19
+ ].map(function(d) {
20
+ const key = d[1]
21
+ const controller = d[0]
22
+ return {
23
+ identifier: identifierForContextKey(key),
24
+ controllerConstructor: controller
25
+ }
26
+ })
27
+
28
+ export {
29
+ ButtonToggleController,
30
+ CloudinaryImageController,
31
+ ColorPickerController,
32
+ DateController,
33
+ FileFieldController,
34
+ PhoneController,
35
+ SuperSelectController
36
+ }
@@ -0,0 +1,2 @@
1
+ export * from './controllers'
2
+ export * from './trix_editor'
@@ -0,0 +1,71 @@
1
+ import Tribute from 'tributejs'
2
+ require("trix/dist/trix.css");
3
+
4
+ require("trix")
5
+ require("@rails/actiontext")
6
+
7
+ // only show the editor tool bar when the user is editing the field.
8
+ // inspired by https://github.com/basecamp/trix/issues/343 and `app/assets/stylesheets/account/fields/trix_editor.scss`
9
+
10
+ export function trixEditor() {
11
+ document.addEventListener('trix-initialize', function() {
12
+ addEventListener("trix-focus", updateTrixToolbarVisability);
13
+ addEventListener("trix-blur", updateTrixToolbarVisability);
14
+ updateTrixToolbarVisability();
15
+ initializeTribute();
16
+ })
17
+ }
18
+
19
+ function updateTrixToolbarVisability() {
20
+ document.querySelectorAll("trix-editor").forEach((editorElement, index) => {
21
+ var toolbarElement = editorElement.toolbarElement;
22
+ if (editorElement == document.activeElement) {
23
+ toolbarElement.classList.add('visible');
24
+ } else {
25
+ // don't hide the toolbar if we've unfocused to focus on the link dialog.
26
+ if (!toolbarElement.contains(document.activeElement)) {
27
+ toolbarElement.classList.remove('visible');
28
+ }
29
+ }
30
+ })
31
+ }
32
+
33
+ function initializeTribute() {
34
+ document.querySelectorAll("trix-editor").forEach((el, index) => {
35
+ var editor = el.editor;
36
+
37
+ var mentionConfig = {
38
+ trigger: '@',
39
+ values: JSON.parse(editor.element.dataset.mentions),
40
+ selectTemplate: function (item) {
41
+ item = item.original;
42
+ return '<a href="' + item.protocol + '://' + item.model + '/' + item.id + '">' + item.label + '</a>';
43
+ },
44
+ menuItemTemplate: function (item) {
45
+ return '<img src="' + item.original.photo + '" /> ' + item.string;
46
+ },
47
+ requireLeadingSpace: true,
48
+ replaceTextSuffix: ''
49
+ }
50
+
51
+ var topicConfig = {
52
+ trigger: '#',
53
+ values: JSON.parse(editor.element.dataset.topics),
54
+ selectTemplate: function (item) {
55
+ item = item.original;
56
+ return '<a href="' + item.protocol + '://' + item.model + '/' + item.id + '">' + item.label + '</a>';
57
+ },
58
+ menuItemTemplate: function (item) {
59
+ return '<img src="' + item.original.photo + '" /> ' + item.string;
60
+ },
61
+ requireLeadingSpace: true,
62
+ replaceTextSuffix: ''
63
+ }
64
+
65
+ var tribute = new Tribute({
66
+ collection: [topicConfig, mentionConfig],
67
+ });
68
+
69
+ tribute.attach(el);
70
+ })
71
+ }
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Fields
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.5"
4
4
  end
5
5
  end
@@ -1,6 +1,9 @@
1
1
  require "bullet_train/fields/version"
2
2
  require "bullet_train/fields/engine"
3
3
 
4
+ require "cloudinary"
5
+ require "phonelib"
6
+
4
7
  module BulletTrain
5
8
  module Fields
6
9
  # Your code goes here...
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.2
4
+ version: 1.0.5
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-02-24 00:00:00.000000000 Z
11
+ date: 2022-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.0
19
+ version: 6.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.0
26
+ version: 6.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: cloudinary
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: phonelib
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: chronic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  description: Bullet Train Fields
28
70
  email:
29
71
  - andrew.culver@gmail.com
@@ -35,6 +77,15 @@ files:
35
77
  - README.md
36
78
  - Rakefile
37
79
  - app/assets/config/bullet_train_fields_manifest.js
80
+ - app/assets/javascripts/fields.esm.js
81
+ - app/assets/javascripts/fields.esm.js.map
82
+ - app/assets/javascripts/fields.js
83
+ - app/assets/javascripts/fields.js.map
84
+ - app/assets/javascripts/fields.modern.js
85
+ - app/assets/javascripts/fields.modern.js.map
86
+ - app/assets/javascripts/fields.umd.js
87
+ - app/assets/javascripts/fields.umd.js.map
88
+ - app/assets/javascripts/intl-tel-input-utils.js
38
89
  - app/controllers/account/cloudinary/upload_signatures_controller.rb
39
90
  - app/controllers/concerns/fields/boolean_support.rb
40
91
  - app/controllers/concerns/fields/controller_support.rb
@@ -54,6 +105,9 @@ files:
54
105
  - app/javascript/controllers/fields/file_field_controller.js
55
106
  - app/javascript/controllers/fields/phone_controller.js
56
107
  - app/javascript/controllers/fields/super_select_controller.js
108
+ - app/javascript/controllers/index.js
109
+ - app/javascript/index.js
110
+ - app/javascript/trix_editor.js
57
111
  - config/routes.rb
58
112
  - lib/bullet_train/fields.rb
59
113
  - lib/bullet_train/fields/engine.rb