bullet_train-fields 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/fields.esm.js +2 -0
- data/app/assets/javascripts/fields.esm.js.map +1 -0
- data/app/assets/javascripts/fields.js +2 -0
- data/app/assets/javascripts/fields.js.map +1 -0
- data/app/assets/javascripts/fields.modern.js +2 -0
- data/app/assets/javascripts/fields.modern.js.map +1 -0
- data/app/assets/javascripts/fields.umd.js +2 -0
- data/app/assets/javascripts/fields.umd.js.map +1 -0
- data/app/assets/javascripts/intl-tel-input-utils.js +502 -0
- data/app/javascript/controllers/fields/date_controller.js +8 -4
- data/app/javascript/controllers/fields/phone_controller.js +16 -6
- data/app/javascript/controllers/fields/super_select_controller.js +14 -3
- data/app/javascript/controllers/index.js +36 -0
- data/app/javascript/index.js +2 -0
- data/app/javascript/trix_editor.js +71 -0
- data/lib/bullet_train/fields/version.rb +1 -1
- metadata +13 -1
@@ -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 = {
|
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:
|
86
|
-
applyLabel:
|
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
|
-
|
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
|
-
|
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
|
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.
|
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,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
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train-fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
@@ -35,6 +35,15 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
37
|
- app/assets/config/bullet_train_fields_manifest.js
|
38
|
+
- app/assets/javascripts/fields.esm.js
|
39
|
+
- app/assets/javascripts/fields.esm.js.map
|
40
|
+
- app/assets/javascripts/fields.js
|
41
|
+
- app/assets/javascripts/fields.js.map
|
42
|
+
- app/assets/javascripts/fields.modern.js
|
43
|
+
- app/assets/javascripts/fields.modern.js.map
|
44
|
+
- app/assets/javascripts/fields.umd.js
|
45
|
+
- app/assets/javascripts/fields.umd.js.map
|
46
|
+
- app/assets/javascripts/intl-tel-input-utils.js
|
38
47
|
- app/controllers/account/cloudinary/upload_signatures_controller.rb
|
39
48
|
- app/controllers/concerns/fields/boolean_support.rb
|
40
49
|
- app/controllers/concerns/fields/controller_support.rb
|
@@ -54,6 +63,9 @@ files:
|
|
54
63
|
- app/javascript/controllers/fields/file_field_controller.js
|
55
64
|
- app/javascript/controllers/fields/phone_controller.js
|
56
65
|
- app/javascript/controllers/fields/super_select_controller.js
|
66
|
+
- app/javascript/controllers/index.js
|
67
|
+
- app/javascript/index.js
|
68
|
+
- app/javascript/trix_editor.js
|
57
69
|
- config/routes.rb
|
58
70
|
- lib/bullet_train/fields.rb
|
59
71
|
- lib/bullet_train/fields/engine.rb
|