@wework/ray-core
Advanced tools
Comparing version 1.8.6-alpha.6 to 1.8.6-alpha.12
@@ -1,2 +0,2 @@ | ||
export var CSS_CLASSES = { | ||
export const CSS_CLASSES = { | ||
ACTIVE: 'ray-select--active', | ||
@@ -8,4 +8,4 @@ REQUIRED: 'ray-select--required', | ||
}; | ||
export var STRINGS = { | ||
export const STRINGS = { | ||
INIT_SELECTOR: '.ray-select' | ||
}; |
@@ -1,9 +0,1 @@ | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -14,68 +6,48 @@ | ||
var Select = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Select, null, [{ | ||
key: "create", | ||
value: function create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
}, { | ||
key: "createAll", | ||
value: function createAll() { | ||
var _this = this; | ||
class Select { | ||
static get cssClasses() { | ||
return CSS_CLASSES; | ||
} | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; | ||
static get strings() { | ||
return STRINGS; | ||
} | ||
var _options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
static create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
// Finds all instances of select on the document or within a given element and instantiates them. | ||
var options = _objectSpread({ | ||
initSelector: this.strings.INIT_SELECTOR | ||
}, _options); | ||
static createAll(target = document, _options = {}) { | ||
// Finds all instances of select on the document or within a given element and instantiates them. | ||
const options = { | ||
initSelector: this.strings.INIT_SELECTOR, | ||
..._options | ||
}; | ||
validateNodeType(target); | ||
const selects = Array.from(target.querySelectorAll(options.initSelector)); | ||
selects.forEach(select => this.create(select, options)); | ||
} | ||
validateNodeType(target); | ||
var selects = Array.from(target.querySelectorAll(options.initSelector)); | ||
selects.forEach(function (select) { | ||
return _this.create(select, options); | ||
}); | ||
} | ||
}, { | ||
key: "cssClasses", | ||
get: function get() { | ||
return CSS_CLASSES; | ||
} | ||
}, { | ||
key: "strings", | ||
get: function get() { | ||
return STRINGS; | ||
} | ||
}]); | ||
function Select(root) { | ||
var _this2 = this; | ||
_classCallCheck(this, Select); | ||
_defineProperty(this, "onFocus", function () { | ||
_this2._root.classList.add(_this2.constructor.cssClasses.ACTIVE); | ||
constructor(root) { | ||
_defineProperty(this, "onFocus", () => { | ||
this._root.classList.add(this.constructor.cssClasses.ACTIVE); | ||
}); | ||
_defineProperty(this, "onBlur", function () { | ||
_this2._root.classList.remove(_this2.constructor.cssClasses.ACTIVE); | ||
_defineProperty(this, "onBlur", () => { | ||
this._root.classList.remove(this.constructor.cssClasses.ACTIVE); | ||
}); | ||
_defineProperty(this, "onChange", function () { | ||
_this2.assignClasses(); | ||
_defineProperty(this, "onChange", () => { | ||
this.assignClasses(); | ||
}); | ||
_defineProperty(this, "_getCurrentValueOptionElement", function () { | ||
return _this2._inputElement.options[_this2._inputElement.selectedIndex]; | ||
_defineProperty(this, "_getCurrentValueOptionElement", () => { | ||
return this._inputElement.options[this._inputElement.selectedIndex]; | ||
}); | ||
this._root = root; | ||
this._inputElement = this._root.querySelector(".".concat(this.constructor.cssClasses.EL__INPUT)); | ||
this._inputElement = this._root.querySelector(`.${this.constructor.cssClasses.EL__INPUT}`); | ||
if (!this._inputElement) { | ||
throw new Error("Select must have an input element with a class of .".concat(this.constructor.cssClasses.EL__INPUT)); | ||
throw new Error(`Select must have an input element with a class of .${this.constructor.cssClasses.EL__INPUT}`); | ||
} | ||
@@ -89,74 +61,65 @@ | ||
_createClass(Select, [{ | ||
key: "_bindEventListeners", | ||
value: function _bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
_bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._inputElement.addEventListener('change', this.onChange); | ||
} | ||
}, { | ||
key: "isRequired", | ||
value: function isRequired() { | ||
return this._inputElement.required; | ||
} | ||
}, { | ||
key: "value", | ||
value: function value() { | ||
// Current value of the Select | ||
return this._inputElement.value; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(value) { | ||
this._inputElement.value = value; | ||
this._inputElement.addEventListener('change', this.onChange); | ||
} | ||
this._inputElement.dispatchEvent(new Event('change')); | ||
} | ||
}, { | ||
key: "assignClasses", | ||
value: function assignClasses() { | ||
var option = this._getCurrentValueOptionElement(); | ||
isRequired() { | ||
return this._inputElement.required; | ||
} | ||
if (option && option.innerHTML) { | ||
if (option.dataset.rayPlaceholder) { | ||
this._root.classList.add(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
value() { | ||
// Current value of the Select | ||
return this._inputElement.value; | ||
} | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
set(value) { | ||
this._inputElement.value = value; | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
} | ||
this._inputElement.dispatchEvent(new Event('change')); | ||
} | ||
assignClasses() { | ||
const option = this._getCurrentValueOptionElement(); | ||
if (option && option.innerHTML) { | ||
if (option.dataset.rayPlaceholder) { | ||
this._root.classList.add(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE, this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
} | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE, this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
} | ||
} | ||
this._inputElement.removeEventListener('change', this.onChange); | ||
destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
this.constructor.instances.delete(this._root); | ||
} | ||
}]); | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
return Select; | ||
}(); | ||
this._inputElement.removeEventListener('change', this.onChange); | ||
this.constructor.instances.delete(this._root); | ||
} | ||
} | ||
_defineProperty(Select, "instances", new WeakMap()); | ||
export default Select; |
@@ -1,2 +0,2 @@ | ||
export var CSS_CLASSES = { | ||
export const CSS_CLASSES = { | ||
TEXT_FIELD: { | ||
@@ -19,9 +19,9 @@ BASE: 'ray-text-field', | ||
}; | ||
export var STRINGS = { | ||
export const STRINGS = { | ||
TEXT_FIELD: { | ||
INIT_SELECTOR: ".".concat(CSS_CLASSES.TEXT_FIELD.BASE) | ||
INIT_SELECTOR: `.${CSS_CLASSES.TEXT_FIELD.BASE}` | ||
}, | ||
TEXT_AREA: { | ||
INIT_SELECTOR: ".".concat(CSS_CLASSES.TEXT_AREA.BASE) | ||
INIT_SELECTOR: `.${CSS_CLASSES.TEXT_AREA.BASE}` | ||
} | ||
}; |
@@ -1,21 +0,1 @@ | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -26,59 +6,41 @@ | ||
var _InputComponent = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(_InputComponent, null, [{ | ||
key: "create", | ||
value: function create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
}, { | ||
key: "createAll", | ||
value: function createAll() { | ||
var _this = this; | ||
class _InputComponent { | ||
static create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; | ||
static createAll(target = document, _options = {}) { | ||
// Finds all instances of init selector on the document or within a given element and instantiates them. | ||
const options = { | ||
initSelector: this.strings.INIT_SELECTOR, | ||
..._options | ||
}; | ||
validateNodeType(target); | ||
const textFields = Array.from(target.querySelectorAll(options.initSelector)); | ||
textFields.forEach(textField => this.create(textField, options)); | ||
} | ||
var _options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// Finds all instances of init selector on the document or within a given element and instantiates them. | ||
var options = _objectSpread({ | ||
initSelector: this.strings.INIT_SELECTOR | ||
}, _options); | ||
validateNodeType(target); | ||
var textFields = Array.from(target.querySelectorAll(options.initSelector)); | ||
textFields.forEach(function (textField) { | ||
return _this.create(textField, options); | ||
}); | ||
} | ||
}]); | ||
function _InputComponent(root) { | ||
var _this2 = this; | ||
_classCallCheck(this, _InputComponent); | ||
_defineProperty(this, "onMousedown", function (event) { | ||
constructor(root) { | ||
_defineProperty(this, "onMousedown", event => { | ||
event.preventDefault(); | ||
_this2._inputElement.focus(); | ||
this._inputElement.focus(); | ||
}); | ||
_defineProperty(this, "onFocus", function () { | ||
_this2._root.classList.add(_this2.constructor.cssClasses.ACTIVE); | ||
_defineProperty(this, "onFocus", () => { | ||
this._root.classList.add(this.constructor.cssClasses.ACTIVE); | ||
}); | ||
_defineProperty(this, "onBlur", function () { | ||
_this2._root.classList.remove(_this2.constructor.cssClasses.ACTIVE); | ||
_defineProperty(this, "onBlur", () => { | ||
this._root.classList.remove(this.constructor.cssClasses.ACTIVE); | ||
_this2.assignClasses(); | ||
this.assignClasses(); | ||
}); | ||
this._root = root; | ||
this._inputElement = this._root.querySelector(".".concat(this.constructor.cssClasses.EL__INPUT)); | ||
this._labelElement = this._root.querySelector(".".concat(this.constructor.cssClasses.EL__LABEL)); | ||
this._inputElement = this._root.querySelector(`.${this.constructor.cssClasses.EL__INPUT}`); | ||
this._labelElement = this._root.querySelector(`.${this.constructor.cssClasses.EL__LABEL}`); | ||
if (!this._inputElement) { | ||
throw new Error("TextField must have an input element with a class of .".concat(this.constructor.cssClasses.EL__INPUT)); | ||
throw new Error(`TextField must have an input element with a class of .${this.constructor.cssClasses.EL__INPUT}`); | ||
} | ||
@@ -93,113 +55,74 @@ | ||
_createClass(_InputComponent, [{ | ||
key: "_bindEventListeners", | ||
value: function _bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
_bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._labelElement.addEventListener('mousedown', this.onMousedown); | ||
} | ||
}, { | ||
key: "value", | ||
value: function value() { | ||
// Current value of the TextField | ||
return this._inputElement.value; | ||
} | ||
}, { | ||
key: "isRequired", | ||
value: function isRequired() { | ||
return this._inputElement.required; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(value) { | ||
this._inputElement.value = value; | ||
} | ||
}, { | ||
key: "assignClasses", | ||
value: function assignClasses() { | ||
if (this.value()) { | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
this._labelElement.addEventListener('mousedown', this.onMousedown); | ||
} | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
} | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
value() { | ||
// Current value of the TextField | ||
return this._inputElement.value; | ||
} | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
isRequired() { | ||
return this._inputElement.required; | ||
} | ||
this._labelElement.removeEventListener('mousedown', this.onMousedown); | ||
set(value) { | ||
this._inputElement.value = value; | ||
} | ||
this.constructor.instances.delete(this._root); | ||
assignClasses() { | ||
if (this.value()) { | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
}]); | ||
return _InputComponent; | ||
}(); | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
} | ||
} | ||
var TextField = | ||
/*#__PURE__*/ | ||
function (_InputComponent2) { | ||
_inherits(TextField, _InputComponent2); | ||
destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
function TextField() { | ||
_classCallCheck(this, TextField); | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(TextField).apply(this, arguments)); | ||
this._labelElement.removeEventListener('mousedown', this.onMousedown); | ||
this.constructor.instances.delete(this._root); | ||
} | ||
_createClass(TextField, null, [{ | ||
key: "cssClasses", | ||
get: function get() { | ||
return CSS_CLASSES.TEXT_FIELD; | ||
} | ||
}, { | ||
key: "strings", | ||
get: function get() { | ||
return STRINGS.TEXT_FIELD; | ||
} | ||
}]); | ||
} | ||
return TextField; | ||
}(_InputComponent); | ||
class TextField extends _InputComponent { | ||
static get cssClasses() { | ||
return CSS_CLASSES.TEXT_FIELD; | ||
} | ||
_defineProperty(TextField, "instances", new WeakMap()); | ||
static get strings() { | ||
return STRINGS.TEXT_FIELD; | ||
} | ||
var TextArea = | ||
/*#__PURE__*/ | ||
function (_InputComponent3) { | ||
_inherits(TextArea, _InputComponent3); | ||
} | ||
function TextArea() { | ||
_classCallCheck(this, TextArea); | ||
_defineProperty(TextField, "instances", new WeakMap()); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(TextArea).apply(this, arguments)); | ||
class TextArea extends _InputComponent { | ||
static get cssClasses() { | ||
return CSS_CLASSES.TEXT_AREA; | ||
} | ||
_createClass(TextArea, null, [{ | ||
key: "cssClasses", | ||
get: function get() { | ||
return CSS_CLASSES.TEXT_AREA; | ||
} | ||
}, { | ||
key: "strings", | ||
get: function get() { | ||
return STRINGS.TEXT_AREA; | ||
} | ||
}]); | ||
static get strings() { | ||
return STRINGS.TEXT_AREA; | ||
} | ||
return TextArea; | ||
}(_InputComponent); | ||
} | ||
@@ -206,0 +129,0 @@ _defineProperty(TextArea, "instances", new WeakMap()); |
function attachAccessibilityEvents() { | ||
if (typeof document !== 'undefined') { | ||
var ENABLE_ACCESSIBILITY_CLASS = 'js-ray-enable-accessibility'; | ||
const ENABLE_ACCESSIBILITY_CLASS = 'js-ray-enable-accessibility'; | ||
document.addEventListener('keydown', function addAccessibilityClass() { | ||
@@ -5,0 +5,0 @@ document.body.classList.add(ENABLE_ACCESSIBILITY_CLASS); |
import * as components from '../../components'; | ||
export function initializeAllComponents() { | ||
Object.keys(components).forEach(function (componentKey) { | ||
var Component = components[componentKey]; | ||
Object.keys(components).forEach(componentKey => { | ||
const Component = components[componentKey]; | ||
Component.createAll(); | ||
@@ -6,0 +6,0 @@ }); |
{ | ||
"name": "@wework/ray-core", | ||
"version": "1.8.6-alpha.6+dcb03ee", | ||
"version": "1.8.6-alpha.12+40b87e4", | ||
"main": "umd/index.js", | ||
@@ -12,3 +12,3 @@ "module": "es/index.js", | ||
"storybook": "start-storybook -p 6006 -s ./stories/static", | ||
"build": "yarn prebuild && gulp html:source sass:source sass:compiled scripts:es scripts:umd scripts:compiled", | ||
"build": "gulp sass:source sass:compiled scripts:es scripts:umd scripts:compiled", | ||
"clean": "gulp clean", | ||
@@ -81,3 +81,3 @@ "prebuild": "yarn clean", | ||
], | ||
"gitHead": "dcb03eeb496ccc56656f8415f90b1ef68367842f", | ||
"gitHead": "40b87e44d1aa881118099c6bd0d8663211b5dee2", | ||
"repository": { | ||
@@ -84,0 +84,0 @@ "type": "git", |
@@ -21,3 +21,3 @@ (function (global, factory) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _select.default; | ||
@@ -28,3 +28,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _textField.TextField; | ||
@@ -35,3 +35,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _textField.TextArea; | ||
@@ -38,0 +38,0 @@ } |
@@ -20,3 +20,3 @@ (function (global, factory) { | ||
_exports.STRINGS = _exports.CSS_CLASSES = void 0; | ||
var CSS_CLASSES = { | ||
const CSS_CLASSES = { | ||
ACTIVE: 'ray-select--active', | ||
@@ -29,3 +29,3 @@ REQUIRED: 'ray-select--required', | ||
_exports.CSS_CLASSES = CSS_CLASSES; | ||
var STRINGS = { | ||
const STRINGS = { | ||
INIT_SELECTOR: '.ray-select' | ||
@@ -32,0 +32,0 @@ }; |
@@ -21,78 +21,50 @@ (function (global, factory) { | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var Select = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Select, null, [{ | ||
key: "create", | ||
value: function create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
}, { | ||
key: "createAll", | ||
value: function createAll() { | ||
var _this = this; | ||
class Select { | ||
static get cssClasses() { | ||
return _constants.CSS_CLASSES; | ||
} | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; | ||
static get strings() { | ||
return _constants.STRINGS; | ||
} | ||
var _options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
static create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
// Finds all instances of select on the document or within a given element and instantiates them. | ||
var options = _objectSpread({ | ||
initSelector: this.strings.INIT_SELECTOR | ||
}, _options); | ||
static createAll(target = document, _options = {}) { | ||
// Finds all instances of select on the document or within a given element and instantiates them. | ||
const options = { | ||
initSelector: this.strings.INIT_SELECTOR, | ||
..._options | ||
}; | ||
(0, _util.validateNodeType)(target); | ||
const selects = Array.from(target.querySelectorAll(options.initSelector)); | ||
selects.forEach(select => this.create(select, options)); | ||
} | ||
(0, _util.validateNodeType)(target); | ||
var selects = Array.from(target.querySelectorAll(options.initSelector)); | ||
selects.forEach(function (select) { | ||
return _this.create(select, options); | ||
}); | ||
} | ||
}, { | ||
key: "cssClasses", | ||
get: function get() { | ||
return _constants.CSS_CLASSES; | ||
} | ||
}, { | ||
key: "strings", | ||
get: function get() { | ||
return _constants.STRINGS; | ||
} | ||
}]); | ||
function Select(root) { | ||
var _this2 = this; | ||
_classCallCheck(this, Select); | ||
_defineProperty(this, "onFocus", function () { | ||
_this2._root.classList.add(_this2.constructor.cssClasses.ACTIVE); | ||
constructor(root) { | ||
_defineProperty(this, "onFocus", () => { | ||
this._root.classList.add(this.constructor.cssClasses.ACTIVE); | ||
}); | ||
_defineProperty(this, "onBlur", function () { | ||
_this2._root.classList.remove(_this2.constructor.cssClasses.ACTIVE); | ||
_defineProperty(this, "onBlur", () => { | ||
this._root.classList.remove(this.constructor.cssClasses.ACTIVE); | ||
}); | ||
_defineProperty(this, "onChange", function () { | ||
_this2.assignClasses(); | ||
_defineProperty(this, "onChange", () => { | ||
this.assignClasses(); | ||
}); | ||
_defineProperty(this, "_getCurrentValueOptionElement", function () { | ||
return _this2._inputElement.options[_this2._inputElement.selectedIndex]; | ||
_defineProperty(this, "_getCurrentValueOptionElement", () => { | ||
return this._inputElement.options[this._inputElement.selectedIndex]; | ||
}); | ||
this._root = root; | ||
this._inputElement = this._root.querySelector(".".concat(this.constructor.cssClasses.EL__INPUT)); | ||
this._inputElement = this._root.querySelector(`.${this.constructor.cssClasses.EL__INPUT}`); | ||
if (!this._inputElement) { | ||
throw new Error("Select must have an input element with a class of .".concat(this.constructor.cssClasses.EL__INPUT)); | ||
throw new Error(`Select must have an input element with a class of .${this.constructor.cssClasses.EL__INPUT}`); | ||
} | ||
@@ -106,72 +78,63 @@ | ||
_createClass(Select, [{ | ||
key: "_bindEventListeners", | ||
value: function _bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
_bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._inputElement.addEventListener('change', this.onChange); | ||
} | ||
}, { | ||
key: "isRequired", | ||
value: function isRequired() { | ||
return this._inputElement.required; | ||
} | ||
}, { | ||
key: "value", | ||
value: function value() { | ||
// Current value of the Select | ||
return this._inputElement.value; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(value) { | ||
this._inputElement.value = value; | ||
this._inputElement.addEventListener('change', this.onChange); | ||
} | ||
this._inputElement.dispatchEvent(new Event('change')); | ||
} | ||
}, { | ||
key: "assignClasses", | ||
value: function assignClasses() { | ||
var option = this._getCurrentValueOptionElement(); | ||
isRequired() { | ||
return this._inputElement.required; | ||
} | ||
if (option && option.innerHTML) { | ||
if (option.dataset.rayPlaceholder) { | ||
this._root.classList.add(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
value() { | ||
// Current value of the Select | ||
return this._inputElement.value; | ||
} | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
set(value) { | ||
this._inputElement.value = value; | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
} | ||
this._inputElement.dispatchEvent(new Event('change')); | ||
} | ||
assignClasses() { | ||
const option = this._getCurrentValueOptionElement(); | ||
if (option && option.innerHTML) { | ||
if (option.dataset.rayPlaceholder) { | ||
this._root.classList.add(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE, this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE); | ||
} | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.PLACEHOLDER_MODE, this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
} | ||
} | ||
this._inputElement.removeEventListener('change', this.onChange); | ||
destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
this.constructor.instances.delete(this._root); | ||
} | ||
}]); | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
return Select; | ||
}(); | ||
this._inputElement.removeEventListener('change', this.onChange); | ||
this.constructor.instances.delete(this._root); | ||
} | ||
} | ||
_defineProperty(Select, "instances", new WeakMap()); | ||
@@ -178,0 +141,0 @@ |
@@ -20,3 +20,3 @@ (function (global, factory) { | ||
_exports.STRINGS = _exports.CSS_CLASSES = void 0; | ||
var CSS_CLASSES = { | ||
const CSS_CLASSES = { | ||
TEXT_FIELD: { | ||
@@ -40,8 +40,8 @@ BASE: 'ray-text-field', | ||
_exports.CSS_CLASSES = CSS_CLASSES; | ||
var STRINGS = { | ||
const STRINGS = { | ||
TEXT_FIELD: { | ||
INIT_SELECTOR: ".".concat(CSS_CLASSES.TEXT_FIELD.BASE) | ||
INIT_SELECTOR: `.${CSS_CLASSES.TEXT_FIELD.BASE}` | ||
}, | ||
TEXT_AREA: { | ||
INIT_SELECTOR: ".".concat(CSS_CLASSES.TEXT_AREA.BASE) | ||
INIT_SELECTOR: `.${CSS_CLASSES.TEXT_AREA.BASE}` | ||
} | ||
@@ -48,0 +48,0 @@ }; |
@@ -21,81 +21,43 @@ (function (global, factory) { | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var _InputComponent = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(_InputComponent, null, [{ | ||
key: "create", | ||
value: function create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
}, { | ||
key: "createAll", | ||
value: function createAll() { | ||
var _this = this; | ||
class _InputComponent { | ||
static create(element, options) { | ||
return this.instances.get(element) || new this(element, options); | ||
} | ||
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; | ||
static createAll(target = document, _options = {}) { | ||
// Finds all instances of init selector on the document or within a given element and instantiates them. | ||
const options = { | ||
initSelector: this.strings.INIT_SELECTOR, | ||
..._options | ||
}; | ||
(0, _util.validateNodeType)(target); | ||
const textFields = Array.from(target.querySelectorAll(options.initSelector)); | ||
textFields.forEach(textField => this.create(textField, options)); | ||
} | ||
var _options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// Finds all instances of init selector on the document or within a given element and instantiates them. | ||
var options = _objectSpread({ | ||
initSelector: this.strings.INIT_SELECTOR | ||
}, _options); | ||
(0, _util.validateNodeType)(target); | ||
var textFields = Array.from(target.querySelectorAll(options.initSelector)); | ||
textFields.forEach(function (textField) { | ||
return _this.create(textField, options); | ||
}); | ||
} | ||
}]); | ||
function _InputComponent(root) { | ||
var _this2 = this; | ||
_classCallCheck(this, _InputComponent); | ||
_defineProperty(this, "onMousedown", function (event) { | ||
constructor(root) { | ||
_defineProperty(this, "onMousedown", event => { | ||
event.preventDefault(); | ||
_this2._inputElement.focus(); | ||
this._inputElement.focus(); | ||
}); | ||
_defineProperty(this, "onFocus", function () { | ||
_this2._root.classList.add(_this2.constructor.cssClasses.ACTIVE); | ||
_defineProperty(this, "onFocus", () => { | ||
this._root.classList.add(this.constructor.cssClasses.ACTIVE); | ||
}); | ||
_defineProperty(this, "onBlur", function () { | ||
_this2._root.classList.remove(_this2.constructor.cssClasses.ACTIVE); | ||
_defineProperty(this, "onBlur", () => { | ||
this._root.classList.remove(this.constructor.cssClasses.ACTIVE); | ||
_this2.assignClasses(); | ||
this.assignClasses(); | ||
}); | ||
this._root = root; | ||
this._inputElement = this._root.querySelector(".".concat(this.constructor.cssClasses.EL__INPUT)); | ||
this._labelElement = this._root.querySelector(".".concat(this.constructor.cssClasses.EL__LABEL)); | ||
this._inputElement = this._root.querySelector(`.${this.constructor.cssClasses.EL__INPUT}`); | ||
this._labelElement = this._root.querySelector(`.${this.constructor.cssClasses.EL__LABEL}`); | ||
if (!this._inputElement) { | ||
throw new Error("TextField must have an input element with a class of .".concat(this.constructor.cssClasses.EL__INPUT)); | ||
throw new Error(`TextField must have an input element with a class of .${this.constructor.cssClasses.EL__INPUT}`); | ||
} | ||
@@ -110,86 +72,62 @@ | ||
_createClass(_InputComponent, [{ | ||
key: "_bindEventListeners", | ||
value: function _bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
_bindEventListeners() { | ||
this._inputElement.addEventListener('focus', this.onFocus); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._inputElement.addEventListener('blur', this.onBlur); | ||
this._labelElement.addEventListener('mousedown', this.onMousedown); | ||
this._labelElement.addEventListener('mousedown', this.onMousedown); | ||
} | ||
value() { | ||
// Current value of the TextField | ||
return this._inputElement.value; | ||
} | ||
isRequired() { | ||
return this._inputElement.required; | ||
} | ||
set(value) { | ||
this._inputElement.value = value; | ||
} | ||
assignClasses() { | ||
if (this.value()) { | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
}, { | ||
key: "value", | ||
value: function value() { | ||
// Current value of the TextField | ||
return this._inputElement.value; | ||
} | ||
}, { | ||
key: "isRequired", | ||
value: function isRequired() { | ||
return this._inputElement.required; | ||
} | ||
}, { | ||
key: "set", | ||
value: function set(value) { | ||
this._inputElement.value = value; | ||
} | ||
}, { | ||
key: "assignClasses", | ||
value: function assignClasses() { | ||
if (this.value()) { | ||
this._root.classList.add(this.constructor.cssClasses.HAS_VALUE); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.HAS_VALUE); | ||
} | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
} | ||
if (this.isRequired()) { | ||
this._root.classList.add(this.constructor.cssClasses.REQUIRED); | ||
} else { | ||
this._root.classList.remove(this.constructor.cssClasses.REQUIRED); | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
} | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
destroy() { | ||
// Implement this method to release any resources / deregister any listeners they have | ||
// attached. An example of this might be deregistering a resize event from the window object. | ||
this._inputElement.removeEventListener('focus', this.onFocus); | ||
this._labelElement.removeEventListener('mousedown', this.onMousedown); | ||
this._inputElement.removeEventListener('blur', this.onBlur); | ||
this.constructor.instances.delete(this._root); | ||
} | ||
}]); | ||
this._labelElement.removeEventListener('mousedown', this.onMousedown); | ||
return _InputComponent; | ||
}(); | ||
this.constructor.instances.delete(this._root); | ||
} | ||
var TextField = | ||
/*#__PURE__*/ | ||
function (_InputComponent2) { | ||
_inherits(TextField, _InputComponent2); | ||
} | ||
function TextField() { | ||
_classCallCheck(this, TextField); | ||
class TextField extends _InputComponent { | ||
static get cssClasses() { | ||
return _constants.CSS_CLASSES.TEXT_FIELD; | ||
} | ||
return _possibleConstructorReturn(this, _getPrototypeOf(TextField).apply(this, arguments)); | ||
static get strings() { | ||
return _constants.STRINGS.TEXT_FIELD; | ||
} | ||
_createClass(TextField, null, [{ | ||
key: "cssClasses", | ||
get: function get() { | ||
return _constants.CSS_CLASSES.TEXT_FIELD; | ||
} | ||
}, { | ||
key: "strings", | ||
get: function get() { | ||
return _constants.STRINGS.TEXT_FIELD; | ||
} | ||
}]); | ||
} | ||
return TextField; | ||
}(_InputComponent); | ||
_exports.TextField = TextField; | ||
@@ -199,28 +137,13 @@ | ||
var TextArea = | ||
/*#__PURE__*/ | ||
function (_InputComponent3) { | ||
_inherits(TextArea, _InputComponent3); | ||
class TextArea extends _InputComponent { | ||
static get cssClasses() { | ||
return _constants.CSS_CLASSES.TEXT_AREA; | ||
} | ||
function TextArea() { | ||
_classCallCheck(this, TextArea); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(TextArea).apply(this, arguments)); | ||
static get strings() { | ||
return _constants.STRINGS.TEXT_AREA; | ||
} | ||
_createClass(TextArea, null, [{ | ||
key: "cssClasses", | ||
get: function get() { | ||
return _constants.CSS_CLASSES.TEXT_AREA; | ||
} | ||
}, { | ||
key: "strings", | ||
get: function get() { | ||
return _constants.STRINGS.TEXT_AREA; | ||
} | ||
}]); | ||
} | ||
return TextArea; | ||
}(_InputComponent); | ||
_exports.TextArea = TextArea; | ||
@@ -227,0 +150,0 @@ |
@@ -23,3 +23,3 @@ (function (global, factory) { | ||
if (typeof document !== 'undefined') { | ||
var ENABLE_ACCESSIBILITY_CLASS = 'js-ray-enable-accessibility'; | ||
const ENABLE_ACCESSIBILITY_CLASS = 'js-ray-enable-accessibility'; | ||
document.addEventListener('keydown', function addAccessibilityClass() { | ||
@@ -26,0 +26,0 @@ document.body.classList.add(ENABLE_ACCESSIBILITY_CLASS); |
@@ -26,4 +26,4 @@ (function (global, factory) { | ||
function initializeAllComponents() { | ||
Object.keys(components).forEach(function (componentKey) { | ||
var Component = components[componentKey]; | ||
Object.keys(components).forEach(componentKey => { | ||
const Component = components[componentKey]; | ||
Component.createAll(); | ||
@@ -30,0 +30,0 @@ }); |
@@ -24,3 +24,3 @@ (function (global, factory) { | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _settings.default; | ||
@@ -36,3 +36,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _components[key]; | ||
@@ -39,0 +39,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
637976
5819