blue-web 1.36.2 → 1.37.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.
@@ -1,247 +1,196 @@
1
- function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
2
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
3
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
4
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
- function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
6
- function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
7
- function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
8
- function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
9
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
10
- var _observer = /*#__PURE__*/new WeakMap();
11
- var _valueArray = /*#__PURE__*/new WeakMap();
12
- var _refArray = /*#__PURE__*/new WeakMap();
13
- var _lightDom2 = /*#__PURE__*/new WeakMap();
14
- var _value2 = /*#__PURE__*/new WeakMap();
15
- var _length2 = /*#__PURE__*/new WeakMap();
16
- var _disabled2 = /*#__PURE__*/new WeakMap();
17
- var _controlClass = /*#__PURE__*/new WeakMap();
18
- var _control1Id = /*#__PURE__*/new WeakMap();
19
- var _styling = /*#__PURE__*/new WeakMap();
20
- var _InputSplitted_brand = /*#__PURE__*/new WeakSet();
21
- export class InputSplitted extends HTMLElement {
22
- get lightDom() {
23
- return _classPrivateFieldGet(_lightDom2, this);
24
- }
25
- set lightDom(_lightDom) {
26
- _classPrivateFieldSet(_lightDom2, this, _lightDom);
27
- if (this.lightDom === true) {
28
- this.innerHTML = _classPrivateFieldGet(_styling, this);
29
- } else {
30
- if (!this.shadowRoot) this.attachShadow({
31
- mode: "open",
32
- delegatesFocus: true
33
- });
34
- this.shadowRoot.innerHTML = _classPrivateFieldGet(_styling, this);
1
+ // src/js/input-splitted.ts
2
+ var InputSplitted = class extends HTMLElement {
3
+ #observer;
4
+ #valueArray = [];
5
+ #refArray = [];
6
+ #lightDom = false;
7
+ get lightDom() {
8
+ return this.#lightDom;
9
+ }
10
+ set lightDom(_lightDom) {
11
+ this.#lightDom = _lightDom;
12
+ if (this.lightDom === true) this.innerHTML = this.#styling;
13
+ else {
14
+ if (!this.shadowRoot) this.attachShadow({
15
+ mode: "open",
16
+ delegatesFocus: true
17
+ });
18
+ this.shadowRoot.innerHTML = this.#styling;
19
+ }
20
+ this.#initDom();
21
+ }
22
+ #value = "";
23
+ get value() {
24
+ return this.#value;
25
+ }
26
+ set value(_value) {
27
+ const oldValue = this.#value;
28
+ this.#value = _value;
29
+ this.#valueArray = this.value.split("");
30
+ for (let i = 0; i < this.length; i++) if (this.#refArray[i]) this.#refArray[i].value = this.#valueArray[i] || "";
31
+ if (oldValue !== _value) this.dispatchEvent(new CustomEvent("changeValue", {
32
+ bubbles: true,
33
+ detail: _value
34
+ }));
35
+ }
36
+ #length = 0;
37
+ get length() {
38
+ return this.#length;
39
+ }
40
+ set length(_length) {
41
+ this.#length = _length;
42
+ if (this.length > this.#refArray.length) {
43
+ for (let j = 0; j < this.length; j++) if (!this.#refArray[j] && this.didInit) this.#addInput(this.#refArray.length);
44
+ } else if (this.length < this.#refArray.length) {
45
+ const difference = Math.abs(this.#refArray.length - this.length);
46
+ for (let j = 0; j < difference; j++) this.#refArray.pop()?.remove();
47
+ }
48
+ this.#refArray = [...this.#refArray];
49
+ }
50
+ #disabled = false;
51
+ get disabled() {
52
+ return this.#disabled;
53
+ }
54
+ set disabled(_disabled) {
55
+ this.#disabled = _disabled;
56
+ const inputs = this.lightDom ? this.querySelectorAll("input") : this.shadowRoot.querySelectorAll("input");
57
+ for (const input of inputs) input.disabled = _disabled;
58
+ }
59
+ #controlClass = "";
60
+ get controlClass() {
61
+ return this.#controlClass;
62
+ }
63
+ set controlClass(value) {
64
+ this.#controlClass = value;
65
+ for (const el of this.#refArray) el.className = this.controlClass;
66
+ }
67
+ #control1Id = "";
68
+ get control1Id() {
69
+ return this.#control1Id;
70
+ }
71
+ set control1Id(value) {
72
+ this.#control1Id = value;
73
+ if (this.#refArray[0]) this.#refArray[0].id = this.control1Id;
74
+ }
75
+ #styling = `<style>
76
+ input {
77
+ display: var(--blue-input-splitted-display, revert);
78
+ background-color: var(--blue-input-splitted-background-color, revert);
79
+ border: var(--blue-input-splitted-border, revert);
80
+ border-radius: var(--blue-input-splitted-border-radius, revert);
81
+ box-shadow: var(--blue-input-splitted-box-shadow, revert);
82
+ color: var(--blue-input-splitted-color, revert);
83
+ margin: var(--blue-input-splitted-margin, revert);
84
+ padding: var(--blue-input-splitted-padding, revert);
85
+ text-align: var(--blue-input-splitted-text-align, revert);
86
+ width: var(--blue-input-splitted-width, revert);
35
87
  }
36
- _assertClassBrand(_InputSplitted_brand, this, _initDom).call(this);
37
- }
38
- get value() {
39
- return _classPrivateFieldGet(_value2, this);
40
- }
41
- set value(_value) {
42
- const oldValue = _classPrivateFieldGet(_value2, this);
43
- _classPrivateFieldSet(_value2, this, _value);
44
- _classPrivateFieldSet(_valueArray, this, this.value.split(""));
45
- for (let i = 0; i < this.length; i++) {
46
- if (_classPrivateFieldGet(_refArray, this)[i]) _classPrivateFieldGet(_refArray, this)[i].value = _classPrivateFieldGet(_valueArray, this)[i] || "";
47
- }
48
- if (oldValue !== _value) {
49
- this.dispatchEvent(new CustomEvent("changeValue", {
50
- bubbles: true,
51
- detail: _value
52
- }));
53
- }
54
- }
55
- get length() {
56
- return _classPrivateFieldGet(_length2, this);
57
- }
58
- set length(_length) {
59
- _classPrivateFieldSet(_length2, this, _length);
60
- if (this.length > _classPrivateFieldGet(_refArray, this).length) {
61
- // Added length
62
-
63
- for (let j = 0; j < this.length; j++) {
64
- if (!_classPrivateFieldGet(_refArray, this)[j] && this.didInit) {
65
- _assertClassBrand(_InputSplitted_brand, this, _addInput).call(this, _classPrivateFieldGet(_refArray, this).length);
66
- }
67
- }
68
- } else if (this.length < _classPrivateFieldGet(_refArray, this).length) {
69
- // Removed length
70
-
71
- const difference = Math.abs(_classPrivateFieldGet(_refArray, this).length - this.length);
72
- for (let j = 0; j < difference; j++) {
73
- const el = _classPrivateFieldGet(_refArray, this).pop();
74
- el === null || el === void 0 || el.remove();
75
- }
76
- }
77
- _classPrivateFieldSet(_refArray, this, [..._classPrivateFieldGet(_refArray, this)]);
78
- }
79
- get disabled() {
80
- return _classPrivateFieldGet(_disabled2, this);
81
- }
82
- set disabled(_disabled) {
83
- _classPrivateFieldSet(_disabled2, this, _disabled);
84
- const inputs = this.lightDom ? this.querySelectorAll("input") : this.shadowRoot.querySelectorAll("input");
85
- for (const input of inputs) {
86
- input.disabled = _disabled;
87
- }
88
- }
89
- get controlClass() {
90
- return _classPrivateFieldGet(_controlClass, this);
91
- }
92
- set controlClass(value) {
93
- _classPrivateFieldSet(_controlClass, this, value);
94
- for (const el of _classPrivateFieldGet(_refArray, this)) {
95
- el.className = this.controlClass;
96
- }
97
- }
98
- get control1Id() {
99
- return _classPrivateFieldGet(_control1Id, this);
100
- }
101
- set control1Id(value) {
102
- _classPrivateFieldSet(_control1Id, this, value);
103
- if (_classPrivateFieldGet(_refArray, this)[0]) {
104
- _classPrivateFieldGet(_refArray, this)[0].id = this.control1Id;
105
- }
106
- }
107
- constructor() {
108
- super();
109
- _classPrivateMethodInitSpec(this, _InputSplitted_brand);
110
- _classPrivateFieldInitSpec(this, _observer, void 0);
111
- _classPrivateFieldInitSpec(this, _valueArray, []);
112
- _classPrivateFieldInitSpec(this, _refArray, []);
113
- _classPrivateFieldInitSpec(this, _lightDom2, false);
114
- _classPrivateFieldInitSpec(this, _value2, "");
115
- _classPrivateFieldInitSpec(this, _length2, 0);
116
- _classPrivateFieldInitSpec(this, _disabled2, false);
117
- _classPrivateFieldInitSpec(this, _controlClass, "");
118
- _classPrivateFieldInitSpec(this, _control1Id, "");
119
- _classPrivateFieldInitSpec(this, _styling, /* html */"<style>\n input {\n display: var(--blue-input-splitted-display, revert);\n background-color: var(--blue-input-splitted-background-color, revert);\n border: var(--blue-input-splitted-border, revert);\n border-radius: var(--blue-input-splitted-border-radius, revert);\n box-shadow: var(--blue-input-splitted-box-shadow, revert);\n color: var(--blue-input-splitted-color, revert);\n margin: var(--blue-input-splitted-margin, revert);\n padding: var(--blue-input-splitted-padding, revert);\n text-align: var(--blue-input-splitted-text-align, revert);\n width: var(--blue-input-splitted-width, revert);\n }\n</style>");
120
- _defineProperty(this, "didInit", false);
121
- this.onFocus = this.onFocus.bind(this);
122
- }
123
- connectedCallback() {
124
- this.didInit = true;
125
- this.lightDom = this.getAttribute("light-dom") !== null;
126
- this.disabled = this.getAttribute("disabled") !== null;
127
- _assertClassBrand(_InputSplitted_brand, this, _initDom).call(this);
128
- this.value = this.getAttribute("value") || this.value;
129
- this.length = getLength(this);
130
- this.controlClass = this.getAttribute("control-class") || this.controlClass;
131
- this.control1Id = this.getAttribute("control-1-id") || this.control1Id;
132
- _assertClassBrand(_InputSplitted_brand, this, _observe).call(this);
133
- }
134
- onFocus() {
135
- if (_classPrivateFieldGet(_refArray, this)[0]) _classPrivateFieldGet(_refArray, this)[0].focus();
136
- }
137
- disconnectedCallback() {
138
- _assertClassBrand(_InputSplitted_brand, this, _unobserve).call(this);
139
- }
140
- static get formAssociated() {
141
- return true;
142
- }
143
- }
144
- function _addInput(i) {
145
- const input = document.createElement("input");
146
- _classPrivateFieldGet(_refArray, this).push(input);
147
- input.type = "text";
148
- input.className = this.controlClass;
149
- if (i === 0) {
150
- input.id = this.control1Id;
151
- }
152
- input.maxLength = 1;
153
- input.value = _classPrivateFieldGet(_valueArray, this)[i] || "";
154
- input.disabled = this.disabled;
155
- input.addEventListener("input", _ref => {
156
- let target = _ref.target;
157
- const inputTarget = target;
158
- if (inputTarget.value !== "" && _classPrivateFieldGet(_refArray, this)[i + 1]) {
159
- _classPrivateFieldGet(_refArray, this)[i + 1].focus();
160
- }
161
- _classPrivateFieldGet(_valueArray, this)[i] = inputTarget.value;
162
- this.value = _classPrivateFieldGet(_valueArray, this).join("");
163
- });
164
- input.addEventListener("keydown", _ref2 => {
165
- let key = _ref2.key,
166
- target = _ref2.target;
167
- const inputTarget = target;
168
- if (key === "Backspace" && inputTarget.value === "" && _classPrivateFieldGet(_refArray, this)[i - 1] !== undefined) {
169
- _classPrivateFieldGet(_refArray, this)[i - 1].focus();
170
- }
171
- });
172
- input.addEventListener("paste", _ref3 => {
173
- let clipboardData = _ref3.clipboardData;
174
- const pastedData = clipboardData.getData("Text");
175
- let k = 0;
176
- for (let j = i; j < this.length; j++) {
177
- _classPrivateFieldGet(_valueArray, this)[j] = pastedData.split("")[k];
178
- _classPrivateFieldGet(_refArray, this)[j].focus();
179
- k = k + 1;
180
- }
181
- this.value = _classPrivateFieldGet(_valueArray, this).join("");
182
- });
183
- if (this.lightDom) {
184
- this.appendChild(input);
185
- } else {
186
- this.shadowRoot.appendChild(input);
187
- }
188
- }
189
- function _initDom() {
190
- this.value = this.getAttribute("value") || "";
191
- this.length = getLength(this);
192
- if (this.lightDom) {
193
- this.innerHTML = _classPrivateFieldGet(_styling, this);
194
- this.addEventListener("focus", this.onFocus);
195
- } else {
196
- this.shadowRoot.innerHTML = _classPrivateFieldGet(_styling, this);
197
- this.shadowRoot.addEventListener("focus", this.onFocus);
198
- }
199
- _classPrivateFieldSet(_valueArray, this, this.value.split(""));
200
- _classPrivateFieldSet(_refArray, this, []);
201
- for (let i = 0; i < this.length; i++) {
202
- _assertClassBrand(_InputSplitted_brand, this, _addInput).call(this, i);
203
- }
204
- }
205
- function _observe() {
206
- // Observer prüft, ob sich HTML-Attribute geändert haben.
207
- // Props-Änderungen werden ohne bemerkt.
208
- _classPrivateFieldSet(_observer, this, _classPrivateFieldGet(_observer, this) || new MutationObserver(mutations => {
209
- mutations.forEach(m => {
210
- if (m.attributeName === "value") {
211
- this.value = this.getAttribute("value") || this.value;
212
- }
213
- if (m.attributeName === "length") {
214
- this.length = getLength(this);
215
- }
216
- if (m.attributeName === "control-class") {
217
- this.controlClass = this.getAttribute("control-class") || this.controlClass;
218
- }
219
- if (m.attributeName === "control-1-id") {
220
- this.control1Id = this.getAttribute("control-1-id") || this.control1Id;
221
- }
222
- if (m.attributeName === "light-dom") {
223
- this.lightDom = this.getAttribute("light-dom") !== null;
224
- }
225
- if (m.attributeName === "disabled") {
226
- this.disabled = this.getAttribute("disabled") !== null;
227
- }
228
- });
229
- }));
230
- _classPrivateFieldGet(_observer, this).observe(this, {
231
- attributeFilter: ["value", "length", "control-class", "control-1-id", "light-dom", "disabled"],
232
- attributeOldValue: true,
233
- childList: true,
234
- subtree: true
235
- });
236
- }
237
- function _unobserve() {
238
- if (_classPrivateFieldGet(_observer, this)) {
239
- _classPrivateFieldGet(_observer, this).takeRecords();
240
- _classPrivateFieldGet(_observer, this).disconnect();
241
- }
242
- }
88
+ </style>`;
89
+ didInit = false;
90
+ constructor() {
91
+ super();
92
+ this.onFocus = this.onFocus.bind(this);
93
+ }
94
+ connectedCallback() {
95
+ this.didInit = true;
96
+ this.lightDom = this.getAttribute("light-dom") !== null;
97
+ this.disabled = this.getAttribute("disabled") !== null;
98
+ this.#initDom();
99
+ this.value = this.getAttribute("value") || this.value;
100
+ this.length = getLength(this);
101
+ this.controlClass = this.getAttribute("control-class") || this.controlClass;
102
+ this.control1Id = this.getAttribute("control-1-id") || this.control1Id;
103
+ this.#observe();
104
+ }
105
+ #addInput(i) {
106
+ const input = document.createElement("input");
107
+ this.#refArray.push(input);
108
+ input.type = "text";
109
+ input.className = this.controlClass;
110
+ if (i === 0) input.id = this.control1Id;
111
+ input.maxLength = 1;
112
+ input.value = this.#valueArray[i] || "";
113
+ input.disabled = this.disabled;
114
+ input.addEventListener("input", ({ target }) => {
115
+ const inputTarget = target;
116
+ if (inputTarget.value !== "" && this.#refArray[i + 1]) this.#refArray[i + 1].focus();
117
+ this.#valueArray[i] = inputTarget.value;
118
+ this.value = this.#valueArray.join("");
119
+ });
120
+ input.addEventListener("keydown", ({ key, target }) => {
121
+ if (key === "Backspace" && target.value === "" && this.#refArray[i - 1] !== void 0) this.#refArray[i - 1].focus();
122
+ });
123
+ input.addEventListener("paste", ({ clipboardData }) => {
124
+ const pastedData = clipboardData.getData("Text");
125
+ let k = 0;
126
+ for (let j = i; j < this.length; j++) {
127
+ this.#valueArray[j] = pastedData.split("")[k];
128
+ this.#refArray[j].focus();
129
+ k = k + 1;
130
+ }
131
+ this.value = this.#valueArray.join("");
132
+ });
133
+ if (this.lightDom) this.appendChild(input);
134
+ else this.shadowRoot.appendChild(input);
135
+ }
136
+ onFocus() {
137
+ if (this.#refArray[0]) this.#refArray[0].focus();
138
+ }
139
+ #initDom() {
140
+ this.value = this.getAttribute("value") || "";
141
+ this.length = getLength(this);
142
+ if (this.lightDom) {
143
+ this.innerHTML = this.#styling;
144
+ this.addEventListener("focus", this.onFocus);
145
+ } else {
146
+ this.shadowRoot.innerHTML = this.#styling;
147
+ this.shadowRoot.addEventListener("focus", this.onFocus);
148
+ }
149
+ this.#valueArray = this.value.split("");
150
+ this.#refArray = [];
151
+ for (let i = 0; i < this.length; i++) this.#addInput(i);
152
+ }
153
+ #observe() {
154
+ this.#observer = this.#observer || new MutationObserver((mutations) => {
155
+ mutations.forEach((m) => {
156
+ if (m.attributeName === "value") this.value = this.getAttribute("value") || this.value;
157
+ if (m.attributeName === "length") this.length = getLength(this);
158
+ if (m.attributeName === "control-class") this.controlClass = this.getAttribute("control-class") || this.controlClass;
159
+ if (m.attributeName === "control-1-id") this.control1Id = this.getAttribute("control-1-id") || this.control1Id;
160
+ if (m.attributeName === "light-dom") this.lightDom = this.getAttribute("light-dom") !== null;
161
+ if (m.attributeName === "disabled") this.disabled = this.getAttribute("disabled") !== null;
162
+ });
163
+ });
164
+ this.#observer.observe(this, {
165
+ attributeFilter: [
166
+ "value",
167
+ "length",
168
+ "control-class",
169
+ "control-1-id",
170
+ "light-dom",
171
+ "disabled"
172
+ ],
173
+ attributeOldValue: true,
174
+ childList: true,
175
+ subtree: true
176
+ });
177
+ }
178
+ #unobserve() {
179
+ if (this.#observer) {
180
+ this.#observer.takeRecords();
181
+ this.#observer.disconnect();
182
+ }
183
+ }
184
+ disconnectedCallback() {
185
+ this.#unobserve();
186
+ }
187
+ static get formAssociated() {
188
+ return true;
189
+ }
190
+ };
243
191
  function getLength(element) {
244
- const attr = element.getAttribute("length");
245
- if (attr) return parseInt(attr);
192
+ const attr = element.getAttribute("length");
193
+ if (attr) return parseInt(attr);
246
194
  }
247
- customElements.define("bl-input-splitted", InputSplitted);
195
+ customElements.define("bl-input-splitted", InputSplitted);
196
+ export { InputSplitted };