@grayscale-dev/dragon 0.1.6 → 0.1.7
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 +4 -3
- package/dist/components/dui-input.d.ts +1 -2
- package/dist/index.js +84 -87
- package/dist/manifest.json +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,8 +150,9 @@ dui-input::part(input) {
|
|
|
150
150
|
|
|
151
151
|
- Example phone pattern: `^\(\d{3}\)\s\d{3}-\d{4}$`
|
|
152
152
|
- As the user types, input is normalized to the mask shape.
|
|
153
|
-
- `
|
|
154
|
-
-
|
|
153
|
+
- `regex-placeholder` provides explicit placeholder text for regex mode.
|
|
154
|
+
- If `regex-placeholder` is empty, no regex placeholder is shown.
|
|
155
|
+
- With `label-position="floating"`, regex placeholder appears only while focused.
|
|
155
156
|
|
|
156
157
|
Example:
|
|
157
158
|
|
|
@@ -160,7 +161,7 @@ Example:
|
|
|
160
161
|
label="Phone"
|
|
161
162
|
label-position="floating"
|
|
162
163
|
regex="^\(\d{3}\)\s\d{3}-\d{4}$"
|
|
163
|
-
|
|
164
|
+
regex-placeholder="(xxx) xxx-xxxx"
|
|
164
165
|
></dui-input>
|
|
165
166
|
```
|
|
166
167
|
|
|
@@ -12,8 +12,7 @@ export declare class DuiInput extends LitElement {
|
|
|
12
12
|
label: string;
|
|
13
13
|
labelPosition: 'floating' | 'above';
|
|
14
14
|
regex: string;
|
|
15
|
-
|
|
16
|
-
showRegexPlaceholer: boolean;
|
|
15
|
+
regexPlaceholder: string;
|
|
17
16
|
private inputEl?;
|
|
18
17
|
private internals?;
|
|
19
18
|
private defaultValue?;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { css as
|
|
2
|
-
import { property as
|
|
1
|
+
import { css as $, LitElement as V, html as m } from "lit";
|
|
2
|
+
import { property as p, query as w, customElement as z } from "lit/decorators.js";
|
|
3
3
|
import { ifDefined as x } from "lit/directives/if-defined.js";
|
|
4
|
-
var
|
|
5
|
-
for (var l =
|
|
6
|
-
(
|
|
7
|
-
return
|
|
4
|
+
var P = Object.defineProperty, S = Object.getOwnPropertyDescriptor, r = (t, e, i, a) => {
|
|
5
|
+
for (var l = a > 1 ? void 0 : a ? S(e, i) : e, n = t.length - 1, o; n >= 0; n--)
|
|
6
|
+
(o = t[n]) && (l = (a ? o(e, i, l) : o(l)) || l);
|
|
7
|
+
return a && l && P(e, i, l), l;
|
|
8
8
|
};
|
|
9
9
|
function E(t) {
|
|
10
10
|
const e = t.trim();
|
|
@@ -17,17 +17,17 @@ function E(t) {
|
|
|
17
17
|
function f(t, e) {
|
|
18
18
|
if (t[e] !== "{")
|
|
19
19
|
return { count: 1, nextIndex: e };
|
|
20
|
-
let i = e + 1,
|
|
20
|
+
let i = e + 1, a = "";
|
|
21
21
|
for (; i < t.length && /\d/.test(t[i]); )
|
|
22
|
-
|
|
23
|
-
return !
|
|
24
|
-
count: Number(
|
|
22
|
+
a += t[i], i += 1;
|
|
23
|
+
return !a || t[i] !== "}" ? { count: 1, nextIndex: e } : {
|
|
24
|
+
count: Number(a),
|
|
25
25
|
nextIndex: i + 1
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
function g(t, e, i) {
|
|
29
|
-
const
|
|
30
|
-
for (let l = 0; l <
|
|
29
|
+
const a = Number.isFinite(i) && i > 0 ? Math.floor(i) : 1;
|
|
30
|
+
for (let l = 0; l < a; l += 1)
|
|
31
31
|
e.kind === "slot" ? t.push({ kind: "slot", test: e.test, placeholder: e.placeholder }) : t.push({ kind: "literal", value: e.value });
|
|
32
32
|
}
|
|
33
33
|
function k(t) {
|
|
@@ -36,53 +36,53 @@ function k(t) {
|
|
|
36
36
|
if (e.startsWith("^") && (e = e.slice(1)), e.endsWith("$") && (e = e.slice(0, -1)), !e) return null;
|
|
37
37
|
const i = [];
|
|
38
38
|
for (let l = 0; l < e.length; l += 1) {
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
39
|
+
const n = e[l];
|
|
40
|
+
if (n === "\\") {
|
|
41
|
+
const u = e[l + 1];
|
|
42
|
+
if (!u) return null;
|
|
43
43
|
let d;
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
g(i, d,
|
|
44
|
+
u === "d" ? d = { kind: "slot", test: (c) => /^\d$/.test(c), placeholder: "x" } : u === "w" ? d = { kind: "slot", test: (c) => /^\w$/.test(c), placeholder: "x" } : u === "s" ? d = { kind: "literal", value: " " } : d = { kind: "literal", value: u };
|
|
45
|
+
const h = f(e, l + 2);
|
|
46
|
+
g(i, d, h.count), l = h.nextIndex - 1;
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
const d = e.slice(l + 1,
|
|
49
|
+
if (n === "[") {
|
|
50
|
+
const u = e.indexOf("]", l + 1);
|
|
51
|
+
if (u === -1) return null;
|
|
52
|
+
const d = e.slice(l + 1, u);
|
|
53
53
|
if (!d) return null;
|
|
54
|
-
const
|
|
54
|
+
const h = new RegExp(`^[${d}]$`), c = {
|
|
55
55
|
kind: "slot",
|
|
56
|
-
test: (y) =>
|
|
56
|
+
test: (y) => h.test(y),
|
|
57
57
|
placeholder: "x"
|
|
58
|
-
}, v = f(e,
|
|
58
|
+
}, v = f(e, u + 1);
|
|
59
59
|
g(i, c, v.count), l = v.nextIndex - 1;
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
62
|
-
if (
|
|
63
|
-
const
|
|
62
|
+
if (n === ".") {
|
|
63
|
+
const u = {
|
|
64
64
|
kind: "slot",
|
|
65
|
-
test: (
|
|
65
|
+
test: (h) => /^[\s\S]$/.test(h),
|
|
66
66
|
placeholder: "x"
|
|
67
67
|
}, d = f(e, l + 1);
|
|
68
|
-
g(i,
|
|
68
|
+
g(i, u, d.count), l = d.nextIndex - 1;
|
|
69
69
|
continue;
|
|
70
70
|
}
|
|
71
|
-
if (
|
|
71
|
+
if (n === "+" || n === "*" || n === "?" || n === "{" || n === "}")
|
|
72
72
|
return null;
|
|
73
|
-
const
|
|
74
|
-
g(i,
|
|
73
|
+
const o = { kind: "literal", value: n }, b = f(e, l + 1);
|
|
74
|
+
g(i, o, b.count), l = b.nextIndex - 1;
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const a = i.map((l) => l.kind === "literal" ? l.value : l.placeholder).join("");
|
|
77
77
|
return {
|
|
78
78
|
source: e,
|
|
79
79
|
tokens: i,
|
|
80
|
-
placeholder:
|
|
80
|
+
placeholder: a
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
let
|
|
83
|
+
let s = class extends V {
|
|
84
84
|
constructor() {
|
|
85
|
-
super(), this.value = "", this.placeholder = "", this.name = "", this.disabled = !1, this.required = !1, this.type = "text", this.label = "", this.labelPosition = "above", this.regex = "", this.
|
|
85
|
+
super(), this.value = "", this.placeholder = "", this.name = "", this.disabled = !1, this.required = !1, this.type = "text", this.label = "", this.labelPosition = "above", this.regex = "", this.regexPlaceholder = "", this.mask = null, this.isFocused = !1, "attachInternals" in this && (this.internals = this.attachInternals());
|
|
86
86
|
}
|
|
87
87
|
connectedCallback() {
|
|
88
88
|
if (super.connectedCallback(), this.mask = k(this.regex), this.defaultValue === void 0) {
|
|
@@ -92,7 +92,7 @@ let o = class extends $ {
|
|
|
92
92
|
this.value = this.normalizeMaskedValue(this.value), this.syncFormValue();
|
|
93
93
|
}
|
|
94
94
|
willUpdate(t) {
|
|
95
|
-
t.has("regex") && (this.mask = k(this.regex), this.defaultValue = this.normalizeMaskedValue(this.getAttribute("value") ?? ""))
|
|
95
|
+
t.has("regex") && (this.mask = k(this.regex), this.defaultValue = this.normalizeMaskedValue(this.getAttribute("value") ?? ""));
|
|
96
96
|
}
|
|
97
97
|
updated(t) {
|
|
98
98
|
if (t.has("value") || t.has("regex")) {
|
|
@@ -122,21 +122,21 @@ let o = class extends $ {
|
|
|
122
122
|
normalizeMaskedValue(t) {
|
|
123
123
|
if (!this.mask) return t;
|
|
124
124
|
const e = this.mask.tokens.filter(
|
|
125
|
-
(
|
|
125
|
+
(o) => o.kind === "slot"
|
|
126
126
|
), i = [];
|
|
127
|
-
let
|
|
128
|
-
for (const
|
|
129
|
-
if (
|
|
130
|
-
e[
|
|
127
|
+
let a = 0;
|
|
128
|
+
for (const o of t) {
|
|
129
|
+
if (a >= e.length) break;
|
|
130
|
+
e[a].test(o) && (i.push(o), a += 1);
|
|
131
131
|
}
|
|
132
|
-
let l = "",
|
|
133
|
-
for (const
|
|
134
|
-
if (
|
|
135
|
-
if (
|
|
132
|
+
let l = "", n = 0;
|
|
133
|
+
for (const o of this.mask.tokens)
|
|
134
|
+
if (o.kind === "slot") {
|
|
135
|
+
if (n >= i.length)
|
|
136
136
|
break;
|
|
137
|
-
l += i[
|
|
137
|
+
l += i[n], n += 1;
|
|
138
138
|
} else
|
|
139
|
-
i.length > 0 &&
|
|
139
|
+
i.length > 0 && n <= i.length && (l += o.value);
|
|
140
140
|
return l;
|
|
141
141
|
}
|
|
142
142
|
syncFormValue() {
|
|
@@ -170,10 +170,10 @@ let o = class extends $ {
|
|
|
170
170
|
this.isFocused = !1, this.requestUpdate();
|
|
171
171
|
}
|
|
172
172
|
render() {
|
|
173
|
-
const t = this.label.length > 0, e = t && this.labelPosition === "floating", i = this.value.length > 0,
|
|
174
|
-
let
|
|
175
|
-
e ?
|
|
176
|
-
const n = this.label ||
|
|
173
|
+
const t = this.label.length > 0, e = t && this.labelPosition === "floating", i = this.value.length > 0, a = this.regexPlaceholder.trim() || void 0;
|
|
174
|
+
let l;
|
|
175
|
+
e ? l = a && this.isFocused ? a : void 0 : a ? l = a : l = this.placeholder || void 0;
|
|
176
|
+
const n = this.label || l || this.placeholder || a || void 0;
|
|
177
177
|
return m`
|
|
178
178
|
<div class="field ${e ? "floating" : ""}" data-has-value=${i}>
|
|
179
179
|
${t ? m`<label for="input">${this.label}</label>` : null}
|
|
@@ -185,7 +185,7 @@ let o = class extends $ {
|
|
|
185
185
|
.name=${this.name}
|
|
186
186
|
?disabled=${this.disabled}
|
|
187
187
|
?required=${this.required}
|
|
188
|
-
.placeholder=${
|
|
188
|
+
.placeholder=${l ?? ""}
|
|
189
189
|
autocomplete=${x(this.autocomplete)}
|
|
190
190
|
aria-label=${x(n)}
|
|
191
191
|
@focus=${this.handleFocus}
|
|
@@ -198,8 +198,8 @@ let o = class extends $ {
|
|
|
198
198
|
`;
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
s.formAssociated = !0;
|
|
202
|
+
s.styles = $`
|
|
203
203
|
:host {
|
|
204
204
|
display: inline-block;
|
|
205
205
|
width: 100%;
|
|
@@ -274,47 +274,44 @@ o.styles = w`
|
|
|
274
274
|
}
|
|
275
275
|
`;
|
|
276
276
|
r([
|
|
277
|
-
|
|
278
|
-
],
|
|
277
|
+
p({ type: String })
|
|
278
|
+
], s.prototype, "value", 2);
|
|
279
279
|
r([
|
|
280
|
-
|
|
281
|
-
],
|
|
280
|
+
p({ type: String })
|
|
281
|
+
], s.prototype, "placeholder", 2);
|
|
282
282
|
r([
|
|
283
|
-
|
|
284
|
-
],
|
|
283
|
+
p({ type: String, reflect: !0 })
|
|
284
|
+
], s.prototype, "name", 2);
|
|
285
285
|
r([
|
|
286
|
-
|
|
287
|
-
],
|
|
286
|
+
p({ type: Boolean, reflect: !0 })
|
|
287
|
+
], s.prototype, "disabled", 2);
|
|
288
288
|
r([
|
|
289
|
-
|
|
290
|
-
],
|
|
289
|
+
p({ type: Boolean, reflect: !0 })
|
|
290
|
+
], s.prototype, "required", 2);
|
|
291
291
|
r([
|
|
292
|
-
|
|
293
|
-
],
|
|
292
|
+
p({ type: String, reflect: !0 })
|
|
293
|
+
], s.prototype, "type", 2);
|
|
294
294
|
r([
|
|
295
|
-
|
|
296
|
-
],
|
|
295
|
+
p({ type: String, reflect: !0 })
|
|
296
|
+
], s.prototype, "autocomplete", 2);
|
|
297
297
|
r([
|
|
298
|
-
|
|
299
|
-
],
|
|
298
|
+
p({ type: String })
|
|
299
|
+
], s.prototype, "label", 2);
|
|
300
300
|
r([
|
|
301
|
-
|
|
302
|
-
],
|
|
301
|
+
p({ type: String, attribute: "label-position" })
|
|
302
|
+
], s.prototype, "labelPosition", 2);
|
|
303
303
|
r([
|
|
304
|
-
|
|
305
|
-
],
|
|
304
|
+
p({ type: String, reflect: !0 })
|
|
305
|
+
], s.prototype, "regex", 2);
|
|
306
306
|
r([
|
|
307
|
-
|
|
308
|
-
],
|
|
307
|
+
p({ type: String, attribute: "regex-placeholder" })
|
|
308
|
+
], s.prototype, "regexPlaceholder", 2);
|
|
309
309
|
r([
|
|
310
|
-
|
|
311
|
-
],
|
|
312
|
-
r([
|
|
313
|
-
|
|
314
|
-
],
|
|
315
|
-
o = r([
|
|
316
|
-
P("dui-input")
|
|
317
|
-
], o);
|
|
310
|
+
w("input")
|
|
311
|
+
], s.prototype, "inputEl", 2);
|
|
312
|
+
s = r([
|
|
313
|
+
z("dui-input")
|
|
314
|
+
], s);
|
|
318
315
|
export {
|
|
319
|
-
|
|
316
|
+
s as DuiInput
|
|
320
317
|
};
|
package/dist/manifest.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"name": "placeholder",
|
|
20
|
-
"description": "Placeholder text shown when value is empty. Hidden in floating label mode unless regex placeholder is enabled while focused.",
|
|
20
|
+
"description": "Placeholder text shown when value is empty. Hidden in floating label mode unless explicit regex placeholder mode is enabled while focused.",
|
|
21
21
|
"type": "string",
|
|
22
22
|
"default": "",
|
|
23
23
|
"control": "text"
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"control": "text"
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
"name": "
|
|
34
|
-
"description": "
|
|
35
|
-
"type": "
|
|
36
|
-
"default":
|
|
37
|
-
"control": "
|
|
33
|
+
"name": "regex-placeholder",
|
|
34
|
+
"description": "Explicit placeholder text for regex mode. If omitted, regex placeholder is not shown.",
|
|
35
|
+
"type": "string",
|
|
36
|
+
"default": "",
|
|
37
|
+
"control": "text"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"name": "name",
|
|
@@ -111,10 +111,10 @@
|
|
|
111
111
|
"default": ""
|
|
112
112
|
},
|
|
113
113
|
{
|
|
114
|
-
"name": "
|
|
115
|
-
"description": "
|
|
116
|
-
"type": "
|
|
117
|
-
"default":
|
|
114
|
+
"name": "regexPlaceholder",
|
|
115
|
+
"description": "Explicit placeholder text used when regex-placeholder is provided.",
|
|
116
|
+
"type": "string",
|
|
117
|
+
"default": ""
|
|
118
118
|
},
|
|
119
119
|
{
|
|
120
120
|
"name": "labelPosition",
|
|
@@ -372,11 +372,11 @@
|
|
|
372
372
|
"order": 1
|
|
373
373
|
},
|
|
374
374
|
{
|
|
375
|
-
"id": "
|
|
375
|
+
"id": "regex-placeholder",
|
|
376
376
|
"kind": "attribute",
|
|
377
|
-
"ref": "
|
|
377
|
+
"ref": "regex-placeholder",
|
|
378
378
|
"group": "mask",
|
|
379
|
-
"label": "
|
|
379
|
+
"label": "Regex Placeholder",
|
|
380
380
|
"order": 2
|
|
381
381
|
},
|
|
382
382
|
{
|