jb-textarea 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/JBTextarea.d.ts +14 -12
- package/dist/JBTextarea.js +140 -346
- package/dist/JBTextarea.js.map +1 -1
- package/dist/JBTextarea.umd.js +347 -0
- package/dist/JBTextarea.umd.js.map +1 -0
- package/dist/Types.d.ts +5 -5
- package/lib/JBTextarea.ts +113 -26
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JBTextarea.umd.js","sources":["../../../node_modules/tslib/tslib.es6.js","../lib/JBTextarea.ts"],"sourcesContent":["/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\r\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\r\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\r\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\r\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\r\n var _, done = false;\r\n for (var i = decorators.length - 1; i >= 0; i--) {\r\n var context = {};\r\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\r\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\r\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\r\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\r\n if (kind === \"accessor\") {\r\n if (result === void 0) continue;\r\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\r\n if (_ = accept(result.get)) descriptor.get = _;\r\n if (_ = accept(result.set)) descriptor.set = _;\r\n if (_ = accept(result.init)) initializers.push(_);\r\n }\r\n else if (_ = accept(result)) {\r\n if (kind === \"field\") initializers.push(_);\r\n else descriptor[key] = _;\r\n }\r\n }\r\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\r\n done = true;\r\n};\r\n\r\nexport function __runInitializers(thisArg, initializers, value) {\r\n var useValue = arguments.length > 2;\r\n for (var i = 0; i < initializers.length; i++) {\r\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\r\n }\r\n return useValue ? value : void 0;\r\n};\r\n\r\nexport function __propKey(x) {\r\n return typeof x === \"symbol\" ? x : \"\".concat(x);\r\n};\r\n\r\nexport function __setFunctionName(f, name, prefix) {\r\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\r\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\r\n};\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n var desc = Object.getOwnPropertyDescriptor(m, k);\r\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\r\n desc = { enumerable: true, get: function() { return m[k]; } };\r\n }\r\n Object.defineProperty(o, k2, desc);\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n\r\nexport function __classPrivateFieldIn(state, receiver) {\r\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n}\r\n","import HTML from './JBTextarea.html';\r\nimport CSS from './JBTextarea.scss';\r\nimport { JBTextareaElements, JBTextareaValidationItem, ValidationResult, ValidationResultItem, ValidationResultSummary } from './Types';\r\nexport {JBTextareaValidationItem};\r\nexport class JBTextareaWebComponent extends HTMLElement {\r\n #value = '';\r\n get value() {\r\n return this.#value;\r\n }\r\n set value(value) {\r\n this.#value = value;\r\n this.#textareaElement.value = value;\r\n if(this.autoHeight){\r\n this.changeHeightToContentSize();\r\n }\r\n }\r\n constructor() {\r\n super();\r\n this.initWebComponent();\r\n this.initProp();\r\n }\r\n #textareaElement!: HTMLTextAreaElement;\r\n #elements!: JBTextareaElements;\r\n initWebComponent() {\r\n const shadowRoot = this.attachShadow({\r\n mode: 'open'\r\n });\r\n const html = `<style>${CSS}</style>` + '\\n' + HTML;\r\n const element = document.createElement('template');\r\n element.innerHTML = html;\r\n shadowRoot.appendChild(element.content.cloneNode(true));\r\n this.#textareaElement = shadowRoot.querySelector('.textarea-box textarea')!;\r\n this.#elements = {\r\n textarea: this.#textareaElement,\r\n label: shadowRoot.querySelector('label')!,\r\n labelValue:shadowRoot.querySelector('label .label-value')!,\r\n messageBox:shadowRoot.querySelector('.message-box')!\r\n }\r\n this.registerEventListener();\r\n }\r\n registerEventListener() {\r\n this.#elements.textarea.addEventListener('change', (e) => this.onInputChange(e));\r\n this.#elements.textarea.addEventListener('beforeinput', this.onInputBeforeInput.bind(this));\r\n this.#elements.textarea.addEventListener('input', (e) => this.onInputInput((e as unknown as InputEvent)));\r\n this.#elements.textarea.addEventListener('keypress', this.onInputKeyPress.bind(this));\r\n this.#elements.textarea.addEventListener('keyup', this.onInputKeyup.bind(this));\r\n this.#elements.textarea.addEventListener('keydown', this.onInputKeyDown.bind(this));\r\n }\r\n validationList:JBTextareaValidationItem[] = [];\r\n autoHeight = false;\r\n validation:ValidationResultSummary = {\r\n isValid: null,\r\n message: null\r\n }\r\n initProp() {\r\n this.value = this.getAttribute('value') || '';\r\n\r\n }\r\n static get observedAttributes() {\r\n return ['label', 'message', 'value', 'placeholder'];\r\n }\r\n attributeChangedCallback(name:string, oldValue:string, newValue:string) {\r\n // do something when an attribute has changed\r\n this.onAttributeChange(name, newValue);\r\n }\r\n onAttributeChange(name:string, value:string) {\r\n switch (name) {\r\n case 'label':\r\n this.#elements.labelValue.innerHTML = value;\r\n if(value == null || value == undefined || value == \"\"){\r\n this.#elements.label.classList.add('--hide');\r\n }else{\r\n this.#elements.label.classList.remove('--hide');\r\n }\r\n break;\r\n case 'message':\r\n this.#elements.messageBox.innerHTML = value;\r\n break;\r\n case 'placeholder':\r\n this.#textareaElement.setAttribute('placeholder', value);\r\n break;\r\n case 'value':\r\n this.value = value;\r\n break;\r\n }\r\n\r\n }\r\n changeHeightToContentSize() {\r\n this.#textareaElement.style.height = \"4px\";\r\n this.#textareaElement.style.height = (this.#textareaElement.scrollHeight)+\"px\";\r\n }\r\n onInputBeforeInput(e: InputEvent){\r\n this.#dispatchBeforeInputEvent(e);\r\n }\r\n #dispatchBeforeInputEvent(e: InputEvent): boolean {\r\n const eventInitDict = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n data: e.data,\r\n isComposing: e.isComposing,\r\n inputType: e.inputType,\r\n dataTransfer: e.dataTransfer,\r\n view: e.view,\r\n detail: e.detail,\r\n targetRanges: e.getTargetRanges(),\r\n };\r\n const event = new InputEvent('beforeinput', eventInitDict);\r\n this.dispatchEvent(event);\r\n if (event.defaultPrevented) {\r\n e.preventDefault();\r\n }\r\n return event.defaultPrevented;\r\n }\r\n onInputKeyDown(e:KeyboardEvent){\r\n const keyDownnInitObj:KeyboardEventInit = {\r\n key:e.key,\r\n keyCode:e.keyCode,\r\n code:e.code,\r\n ctrlKey:e.ctrlKey,\r\n shiftKey:e.shiftKey,\r\n altKey:e.altKey,\r\n charCode:e.charCode,\r\n which:e.which,\r\n cancelable: true,\r\n location:e.location,\r\n detail:e.detail,\r\n bubbles:e.bubbles,\r\n composed:e.composed,\r\n isComposing:e.isComposing,\r\n metaKey:e.metaKey,\r\n repeat:e.repeat,\r\n view:e.view\r\n };\r\n const event = new KeyboardEvent(\"keydown\",keyDownnInitObj);\r\n const isEventNotPrevented = this.dispatchEvent(event);\r\n if(!isEventNotPrevented){\r\n //if event prevented by e.preventDefault();\r\n e.preventDefault();\r\n }\r\n }\r\n onInputKeyPress(e:KeyboardEvent) {\r\n const keyPressInitObj:KeyboardEventInit = {\r\n key:e.key,\r\n keyCode:e.keyCode,\r\n code:e.code,\r\n ctrlKey:e.ctrlKey,\r\n shiftKey:e.shiftKey,\r\n altKey:e.altKey,\r\n charCode:e.charCode,\r\n which:e.which,\r\n cancelable: true,\r\n location:e.location,\r\n detail:e.detail,\r\n bubbles:e.bubbles,\r\n composed:e.composed,\r\n isComposing:e.isComposing,\r\n metaKey:e.metaKey,\r\n repeat:e.repeat,\r\n view:e.view\r\n };\r\n const event = new KeyboardEvent('keypress',keyPressInitObj);\r\n const isEventNotPrevented = this.dispatchEvent(event);\r\n if(!isEventNotPrevented){\r\n //if event prevented by e.preventDefault();\r\n e.preventDefault();\r\n }\r\n }\r\n onInputInput(e:InputEvent){\r\n if(this.autoHeight){\r\n this.changeHeightToContentSize();\r\n }\r\n this.#triggerInputEvent(e);\r\n }\r\n #triggerInputEvent(e:InputEvent){\r\n const inputInitObject:InputEventInit = {\r\n bubbles:e.bubbles,\r\n cancelable:e.cancelable,\r\n composed:e.composed,\r\n data:e.data,\r\n dataTransfer:e.dataTransfer,\r\n detail:e.detail,\r\n inputType:e.inputType,\r\n isComposing:e.isComposing,\r\n targetRanges:e.getTargetRanges(),\r\n view:e.view\r\n };\r\n const event = new InputEvent(\"input\",inputInitObject);\r\n this.dispatchEvent(event);\r\n }\r\n onInputKeyup(e:KeyboardEvent) {\r\n const inputText = (e.target as HTMLTextAreaElement).value;\r\n //here is the rare time we update _value directly becuase we want trigger event that may read value directly from dom\r\n this.#value = inputText;\r\n this.triggerInputValidation(false);\r\n const keyUpInitObj:KeyboardEventInit = {\r\n key:e.key,\r\n keyCode:e.keyCode,\r\n code:e.code,\r\n ctrlKey:e.ctrlKey,\r\n shiftKey:e.shiftKey,\r\n altKey:e.altKey,\r\n charCode:e.charCode,\r\n which:e.which,\r\n bubbles:e.bubbles,\r\n cancelable:e.cancelable,\r\n composed:e.composed,\r\n detail:e.detail,\r\n isComposing:e.isComposing,\r\n location:e.location,\r\n metaKey:e.metaKey,\r\n repeat:e.repeat,\r\n view:e.view\r\n };\r\n const event = new KeyboardEvent('keyup',keyUpInitObj);\r\n this.dispatchEvent(event);\r\n }\r\n onInputChange(e:Event) {\r\n const inputText = (e.target as HTMLTextAreaElement).value;\r\n this.triggerInputValidation(true);\r\n //here is the rare time we update _value directly becuase we want trigger event that may read value directly from dom\r\n this.#value = inputText;\r\n const validationObject = this.checkInputValidation(inputText);\r\n const event = new CustomEvent('change',{\r\n detail: {\r\n isValid: validationObject.isAllValid,\r\n validationObject:validationObject,\r\n },\r\n });\r\n this.dispatchEvent(event);\r\n }\r\n triggerInputValidation(showError = true) {\r\n // this method is for use out of component for example if user click on submit button and developer want to check if all fields are valid\r\n //takeAction determine if we want to show user error in web component difualtManner or developer will handle it by himself\r\n const inputText = this.#textareaElement.value;\r\n const validationResult = this.checkInputValidation(inputText);\r\n if (showError == true && !validationResult.isAllValid) {\r\n const firstFault = validationResult.validationList.find(x => !x.isValid);\r\n if(firstFault && firstFault.message){\r\n this.showValidationError(firstFault.message);\r\n }\r\n } else if (validationResult.isAllValid) {\r\n this.clearValidationError();\r\n }\r\n return validationResult;\r\n }\r\n checkInputValidation(inputText:string):ValidationResult{\r\n const validationResult:ValidationResult = {\r\n validationList: [],\r\n isAllValid: true\r\n };\r\n this.validationList.forEach((validation:JBTextareaValidationItem) => {\r\n const res = this.checkValidation(inputText, validation);\r\n validationResult.validationList.push(res);\r\n if (!res.isValid) {\r\n validationResult.isAllValid = false;\r\n }\r\n });\r\n return validationResult;\r\n }\r\n checkValidation(text:string, validation:JBTextareaValidationItem) {\r\n let testRes = true;\r\n if(validation.validator instanceof RegExp){\r\n testRes = validation.validator.test(text);\r\n validation.validator.lastIndex = 0;\r\n }\r\n if (typeof validation.validator == \"function\") {\r\n testRes = validation.validator(text);\r\n }\r\n if (!testRes) {\r\n return {\r\n isValid: false,\r\n message: validation.message,\r\n validation: validation\r\n };\r\n }\r\n return {\r\n isValid: true,\r\n message: '',\r\n validation: validation\r\n };\r\n }\r\n showValidationError(error:string) {\r\n this.validation = {\r\n isValid: false,\r\n message: error\r\n };\r\n this.#elements.messageBox.innerHTML = error;\r\n this.#elements.messageBox.classList.add('error');\r\n }\r\n clearValidationError() {\r\n this.validation = {\r\n isValid: true,\r\n message: null\r\n };\r\n const text = this.getAttribute('message') || '';\r\n this.#elements.messageBox.innerHTML = text;\r\n this.#elements.messageBox.classList.remove('error');\r\n }\r\n}\r\n\r\nconst myElementNotExists = !customElements.get('jb-textarea');\r\nif(myElementNotExists){\r\n //prevent duplicate registering\r\n window.customElements.define('jb-textarea', JBTextareaWebComponent);\r\n}"],"names":["CSS"],"mappings":";;;;;;IAAA;IACA;AACA;IACA;IACA;AACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;AAsQA;IACO,SAAS,sBAAsB,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE;IACjE,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAC;IACjG,IAAI,IAAI,OAAO,KAAK,KA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 -1,23 +1,23 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type JBTextareaElements = {
|
|
2
2
|
textarea: HTMLTextAreaElement;
|
|
3
3
|
label: HTMLLabelElement;
|
|
4
4
|
labelValue: HTMLSpanElement;
|
|
5
5
|
messageBox: HTMLDivElement;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type ValidationResultSummary = {
|
|
8
8
|
isValid: boolean | null;
|
|
9
9
|
message: string | null;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type ValidationResultItem = {
|
|
12
12
|
isValid: boolean | null;
|
|
13
13
|
message: string | null;
|
|
14
14
|
validation: JBTextareaValidationItem;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type ValidationResult = {
|
|
17
17
|
validationList: ValidationResultItem[];
|
|
18
18
|
isAllValid: boolean;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type JBTextareaValidationItem = {
|
|
21
21
|
validator: RegExp | ((value: string) => boolean);
|
|
22
22
|
message: string;
|
|
23
23
|
};
|
package/lib/JBTextarea.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import HTML from './JBTextarea.html';
|
|
2
2
|
import CSS from './JBTextarea.scss';
|
|
3
3
|
import { JBTextareaElements, JBTextareaValidationItem, ValidationResult, ValidationResultItem, ValidationResultSummary } from './Types';
|
|
4
|
+
export {JBTextareaValidationItem};
|
|
4
5
|
export class JBTextareaWebComponent extends HTMLElement {
|
|
5
6
|
#value = '';
|
|
6
7
|
get value() {
|
|
@@ -38,11 +39,12 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
38
39
|
this.registerEventListener();
|
|
39
40
|
}
|
|
40
41
|
registerEventListener() {
|
|
41
|
-
this.#
|
|
42
|
-
this.#
|
|
43
|
-
this.#
|
|
44
|
-
this.#
|
|
45
|
-
this.#
|
|
42
|
+
this.#elements.textarea.addEventListener('change', (e) => this.onInputChange(e));
|
|
43
|
+
this.#elements.textarea.addEventListener('beforeinput', this.onInputBeforeInput.bind(this));
|
|
44
|
+
this.#elements.textarea.addEventListener('input', (e) => this.onInputInput((e as unknown as InputEvent)));
|
|
45
|
+
this.#elements.textarea.addEventListener('keypress', this.onInputKeyPress.bind(this));
|
|
46
|
+
this.#elements.textarea.addEventListener('keyup', this.onInputKeyup.bind(this));
|
|
47
|
+
this.#elements.textarea.addEventListener('keydown', this.onInputKeyDown.bind(this));
|
|
46
48
|
}
|
|
47
49
|
validationList:JBTextareaValidationItem[] = [];
|
|
48
50
|
autoHeight = false;
|
|
@@ -57,11 +59,11 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
57
59
|
static get observedAttributes() {
|
|
58
60
|
return ['label', 'message', 'value', 'placeholder'];
|
|
59
61
|
}
|
|
60
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
62
|
+
attributeChangedCallback(name:string, oldValue:string, newValue:string) {
|
|
61
63
|
// do something when an attribute has changed
|
|
62
64
|
this.onAttributeChange(name, newValue);
|
|
63
65
|
}
|
|
64
|
-
onAttributeChange(name, value) {
|
|
66
|
+
onAttributeChange(name:string, value:string) {
|
|
65
67
|
switch (name) {
|
|
66
68
|
case 'label':
|
|
67
69
|
this.#elements.labelValue.innerHTML = value;
|
|
@@ -87,8 +89,31 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
87
89
|
this.#textareaElement.style.height = "4px";
|
|
88
90
|
this.#textareaElement.style.height = (this.#textareaElement.scrollHeight)+"px";
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
onInputBeforeInput(e: InputEvent){
|
|
93
|
+
this.#dispatchBeforeInputEvent(e);
|
|
94
|
+
}
|
|
95
|
+
#dispatchBeforeInputEvent(e: InputEvent): boolean {
|
|
96
|
+
const eventInitDict = {
|
|
97
|
+
bubbles: e.bubbles,
|
|
98
|
+
cancelable: e.cancelable,
|
|
99
|
+
composed: e.composed,
|
|
100
|
+
data: e.data,
|
|
101
|
+
isComposing: e.isComposing,
|
|
102
|
+
inputType: e.inputType,
|
|
103
|
+
dataTransfer: e.dataTransfer,
|
|
104
|
+
view: e.view,
|
|
105
|
+
detail: e.detail,
|
|
106
|
+
targetRanges: e.getTargetRanges(),
|
|
107
|
+
};
|
|
108
|
+
const event = new InputEvent('beforeinput', eventInitDict);
|
|
109
|
+
this.dispatchEvent(event);
|
|
110
|
+
if (event.defaultPrevented) {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
}
|
|
113
|
+
return event.defaultPrevented;
|
|
114
|
+
}
|
|
115
|
+
onInputKeyDown(e:KeyboardEvent){
|
|
116
|
+
const keyDownnInitObj:KeyboardEventInit = {
|
|
92
117
|
key:e.key,
|
|
93
118
|
keyCode:e.keyCode,
|
|
94
119
|
code:e.code,
|
|
@@ -98,6 +123,14 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
98
123
|
charCode:e.charCode,
|
|
99
124
|
which:e.which,
|
|
100
125
|
cancelable: true,
|
|
126
|
+
location:e.location,
|
|
127
|
+
detail:e.detail,
|
|
128
|
+
bubbles:e.bubbles,
|
|
129
|
+
composed:e.composed,
|
|
130
|
+
isComposing:e.isComposing,
|
|
131
|
+
metaKey:e.metaKey,
|
|
132
|
+
repeat:e.repeat,
|
|
133
|
+
view:e.view
|
|
101
134
|
};
|
|
102
135
|
const event = new KeyboardEvent("keydown",keyDownnInitObj);
|
|
103
136
|
const isEventNotPrevented = this.dispatchEvent(event);
|
|
@@ -106,22 +139,61 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
106
139
|
e.preventDefault();
|
|
107
140
|
}
|
|
108
141
|
}
|
|
109
|
-
onInputKeyPress() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
142
|
+
onInputKeyPress(e:KeyboardEvent) {
|
|
143
|
+
const keyPressInitObj:KeyboardEventInit = {
|
|
144
|
+
key:e.key,
|
|
145
|
+
keyCode:e.keyCode,
|
|
146
|
+
code:e.code,
|
|
147
|
+
ctrlKey:e.ctrlKey,
|
|
148
|
+
shiftKey:e.shiftKey,
|
|
149
|
+
altKey:e.altKey,
|
|
150
|
+
charCode:e.charCode,
|
|
151
|
+
which:e.which,
|
|
152
|
+
cancelable: true,
|
|
153
|
+
location:e.location,
|
|
154
|
+
detail:e.detail,
|
|
155
|
+
bubbles:e.bubbles,
|
|
156
|
+
composed:e.composed,
|
|
157
|
+
isComposing:e.isComposing,
|
|
158
|
+
metaKey:e.metaKey,
|
|
159
|
+
repeat:e.repeat,
|
|
160
|
+
view:e.view
|
|
161
|
+
};
|
|
162
|
+
const event = new KeyboardEvent('keypress',keyPressInitObj);
|
|
163
|
+
const isEventNotPrevented = this.dispatchEvent(event);
|
|
164
|
+
if(!isEventNotPrevented){
|
|
165
|
+
//if event prevented by e.preventDefault();
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
}
|
|
113
168
|
}
|
|
114
|
-
onInputInput(){
|
|
169
|
+
onInputInput(e:InputEvent){
|
|
115
170
|
if(this.autoHeight){
|
|
116
171
|
this.changeHeightToContentSize();
|
|
117
172
|
}
|
|
173
|
+
this.#triggerInputEvent(e);
|
|
174
|
+
}
|
|
175
|
+
#triggerInputEvent(e:InputEvent){
|
|
176
|
+
const inputInitObject:InputEventInit = {
|
|
177
|
+
bubbles:e.bubbles,
|
|
178
|
+
cancelable:e.cancelable,
|
|
179
|
+
composed:e.composed,
|
|
180
|
+
data:e.data,
|
|
181
|
+
dataTransfer:e.dataTransfer,
|
|
182
|
+
detail:e.detail,
|
|
183
|
+
inputType:e.inputType,
|
|
184
|
+
isComposing:e.isComposing,
|
|
185
|
+
targetRanges:e.getTargetRanges(),
|
|
186
|
+
view:e.view
|
|
187
|
+
};
|
|
188
|
+
const event = new InputEvent("input",inputInitObject);
|
|
189
|
+
this.dispatchEvent(event);
|
|
118
190
|
}
|
|
119
|
-
onInputKeyup(e) {
|
|
120
|
-
const inputText = e.target.value;
|
|
191
|
+
onInputKeyup(e:KeyboardEvent) {
|
|
192
|
+
const inputText = (e.target as HTMLTextAreaElement).value;
|
|
121
193
|
//here is the rare time we update _value directly becuase we want trigger event that may read value directly from dom
|
|
122
194
|
this.#value = inputText;
|
|
123
195
|
this.triggerInputValidation(false);
|
|
124
|
-
const keyUpInitObj = {
|
|
196
|
+
const keyUpInitObj:KeyboardEventInit = {
|
|
125
197
|
key:e.key,
|
|
126
198
|
keyCode:e.keyCode,
|
|
127
199
|
code:e.code,
|
|
@@ -130,12 +202,21 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
130
202
|
altKey:e.altKey,
|
|
131
203
|
charCode:e.charCode,
|
|
132
204
|
which:e.which,
|
|
205
|
+
bubbles:e.bubbles,
|
|
206
|
+
cancelable:e.cancelable,
|
|
207
|
+
composed:e.composed,
|
|
208
|
+
detail:e.detail,
|
|
209
|
+
isComposing:e.isComposing,
|
|
210
|
+
location:e.location,
|
|
211
|
+
metaKey:e.metaKey,
|
|
212
|
+
repeat:e.repeat,
|
|
213
|
+
view:e.view
|
|
133
214
|
};
|
|
134
215
|
const event = new KeyboardEvent('keyup',keyUpInitObj);
|
|
135
216
|
this.dispatchEvent(event);
|
|
136
217
|
}
|
|
137
|
-
onInputChange(e) {
|
|
138
|
-
const inputText = e.target.value;
|
|
218
|
+
onInputChange(e:Event) {
|
|
219
|
+
const inputText = (e.target as HTMLTextAreaElement).value;
|
|
139
220
|
this.triggerInputValidation(true);
|
|
140
221
|
//here is the rare time we update _value directly becuase we want trigger event that may read value directly from dom
|
|
141
222
|
this.#value = inputText;
|
|
@@ -155,7 +236,7 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
155
236
|
const validationResult = this.checkInputValidation(inputText);
|
|
156
237
|
if (showError == true && !validationResult.isAllValid) {
|
|
157
238
|
const firstFault = validationResult.validationList.find(x => !x.isValid);
|
|
158
|
-
if(firstFault){
|
|
239
|
+
if(firstFault && firstFault.message){
|
|
159
240
|
this.showValidationError(firstFault.message);
|
|
160
241
|
}
|
|
161
242
|
} else if (validationResult.isAllValid) {
|
|
@@ -163,12 +244,12 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
163
244
|
}
|
|
164
245
|
return validationResult;
|
|
165
246
|
}
|
|
166
|
-
checkInputValidation(inputText):ValidationResult{
|
|
247
|
+
checkInputValidation(inputText:string):ValidationResult{
|
|
167
248
|
const validationResult:ValidationResult = {
|
|
168
249
|
validationList: [],
|
|
169
250
|
isAllValid: true
|
|
170
251
|
};
|
|
171
|
-
this.validationList.forEach((validation) => {
|
|
252
|
+
this.validationList.forEach((validation:JBTextareaValidationItem) => {
|
|
172
253
|
const res = this.checkValidation(inputText, validation);
|
|
173
254
|
validationResult.validationList.push(res);
|
|
174
255
|
if (!res.isValid) {
|
|
@@ -177,9 +258,15 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
177
258
|
});
|
|
178
259
|
return validationResult;
|
|
179
260
|
}
|
|
180
|
-
checkValidation(text, validation) {
|
|
181
|
-
|
|
182
|
-
validation.validator
|
|
261
|
+
checkValidation(text:string, validation:JBTextareaValidationItem) {
|
|
262
|
+
let testRes = true;
|
|
263
|
+
if(validation.validator instanceof RegExp){
|
|
264
|
+
testRes = validation.validator.test(text);
|
|
265
|
+
validation.validator.lastIndex = 0;
|
|
266
|
+
}
|
|
267
|
+
if (typeof validation.validator == "function") {
|
|
268
|
+
testRes = validation.validator(text);
|
|
269
|
+
}
|
|
183
270
|
if (!testRes) {
|
|
184
271
|
return {
|
|
185
272
|
isValid: false,
|
|
@@ -193,7 +280,7 @@ export class JBTextareaWebComponent extends HTMLElement {
|
|
|
193
280
|
validation: validation
|
|
194
281
|
};
|
|
195
282
|
}
|
|
196
|
-
showValidationError(error) {
|
|
283
|
+
showValidationError(error:string) {
|
|
197
284
|
this.validation = {
|
|
198
285
|
isValid: false,
|
|
199
286
|
message: error
|