@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 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
- - `show-regex-placeholder` shows a generated placeholder such as `(xxx) xxx-xxxx`.
154
- - With `label-position="floating"`, the regex placeholder appears only while focused.
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
- show-regex-placeholder
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
- showRegexPlaceholder: boolean;
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 w, LitElement as $, html as m } from "lit";
2
- import { property as u, query as V, customElement as P } from "lit/decorators.js";
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 z = Object.defineProperty, R = Object.getOwnPropertyDescriptor, r = (t, e, i, s) => {
5
- for (var l = s > 1 ? void 0 : s ? R(e, i) : e, a = t.length - 1, n; a >= 0; a--)
6
- (n = t[a]) && (l = (s ? n(e, i, l) : n(l)) || l);
7
- return s && l && z(e, i, l), l;
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, s = "";
20
+ let i = e + 1, a = "";
21
21
  for (; i < t.length && /\d/.test(t[i]); )
22
- s += t[i], i += 1;
23
- return !s || t[i] !== "}" ? { count: 1, nextIndex: e } : {
24
- count: Number(s),
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 s = Number.isFinite(i) && i > 0 ? Math.floor(i) : 1;
30
- for (let l = 0; l < s; l += 1)
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 a = e[l];
40
- if (a === "\\") {
41
- const h = e[l + 1];
42
- if (!h) return null;
39
+ const n = e[l];
40
+ if (n === "\\") {
41
+ const u = e[l + 1];
42
+ if (!u) return null;
43
43
  let d;
44
- h === "d" ? d = { kind: "slot", test: (c) => /^\d$/.test(c), placeholder: "x" } : h === "w" ? d = { kind: "slot", test: (c) => /^\w$/.test(c), placeholder: "x" } : h === "s" ? d = { kind: "literal", value: " " } : d = { kind: "literal", value: h };
45
- const p = f(e, l + 2);
46
- g(i, d, p.count), l = p.nextIndex - 1;
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 (a === "[") {
50
- const h = e.indexOf("]", l + 1);
51
- if (h === -1) return null;
52
- const d = e.slice(l + 1, h);
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 p = new RegExp(`^[${d}]$`), c = {
54
+ const h = new RegExp(`^[${d}]$`), c = {
55
55
  kind: "slot",
56
- test: (y) => p.test(y),
56
+ test: (y) => h.test(y),
57
57
  placeholder: "x"
58
- }, v = f(e, h + 1);
58
+ }, v = f(e, u + 1);
59
59
  g(i, c, v.count), l = v.nextIndex - 1;
60
60
  continue;
61
61
  }
62
- if (a === ".") {
63
- const h = {
62
+ if (n === ".") {
63
+ const u = {
64
64
  kind: "slot",
65
- test: (p) => /^[\s\S]$/.test(p),
65
+ test: (h) => /^[\s\S]$/.test(h),
66
66
  placeholder: "x"
67
67
  }, d = f(e, l + 1);
68
- g(i, h, d.count), l = d.nextIndex - 1;
68
+ g(i, u, d.count), l = d.nextIndex - 1;
69
69
  continue;
70
70
  }
71
- if (a === "+" || a === "*" || a === "?" || a === "{" || a === "}")
71
+ if (n === "+" || n === "*" || n === "?" || n === "{" || n === "}")
72
72
  return null;
73
- const n = { kind: "literal", value: a }, b = f(e, l + 1);
74
- g(i, n, b.count), l = b.nextIndex - 1;
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 s = i.map((l) => l.kind === "literal" ? l.value : l.placeholder).join("");
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: s
80
+ placeholder: a
81
81
  };
82
82
  }
83
- let o = class extends $ {
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.showRegexPlaceholder = !1, this.showRegexPlaceholer = !1, this.mask = null, this.isFocused = !1, "attachInternals" in this && (this.internals = this.attachInternals());
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") ?? "")), t.has("showRegexPlaceholer") && this.showRegexPlaceholer && (this.showRegexPlaceholder = !0);
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
- (n) => n.kind === "slot"
125
+ (o) => o.kind === "slot"
126
126
  ), i = [];
127
- let s = 0;
128
- for (const n of t) {
129
- if (s >= e.length) break;
130
- e[s].test(n) && (i.push(n), s += 1);
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 = "", a = 0;
133
- for (const n of this.mask.tokens)
134
- if (n.kind === "slot") {
135
- if (a >= i.length)
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[a], a += 1;
137
+ l += i[n], n += 1;
138
138
  } else
139
- i.length > 0 && a <= i.length && (l += n.value);
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, s = (this.showRegexPlaceholder || this.showRegexPlaceholer) && this.mask !== null, l = s ? this.mask?.placeholder : void 0;
174
- let a;
175
- e ? a = s && this.isFocused ? l : void 0 : s ? a = l : a = this.placeholder || void 0;
176
- const n = this.label || a || this.placeholder || l || void 0;
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=${a ?? ""}
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
- o.formAssociated = !0;
202
- o.styles = w`
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
- u({ type: String })
278
- ], o.prototype, "value", 2);
277
+ p({ type: String })
278
+ ], s.prototype, "value", 2);
279
279
  r([
280
- u({ type: String })
281
- ], o.prototype, "placeholder", 2);
280
+ p({ type: String })
281
+ ], s.prototype, "placeholder", 2);
282
282
  r([
283
- u({ type: String, reflect: !0 })
284
- ], o.prototype, "name", 2);
283
+ p({ type: String, reflect: !0 })
284
+ ], s.prototype, "name", 2);
285
285
  r([
286
- u({ type: Boolean, reflect: !0 })
287
- ], o.prototype, "disabled", 2);
286
+ p({ type: Boolean, reflect: !0 })
287
+ ], s.prototype, "disabled", 2);
288
288
  r([
289
- u({ type: Boolean, reflect: !0 })
290
- ], o.prototype, "required", 2);
289
+ p({ type: Boolean, reflect: !0 })
290
+ ], s.prototype, "required", 2);
291
291
  r([
292
- u({ type: String, reflect: !0 })
293
- ], o.prototype, "type", 2);
292
+ p({ type: String, reflect: !0 })
293
+ ], s.prototype, "type", 2);
294
294
  r([
295
- u({ type: String, reflect: !0 })
296
- ], o.prototype, "autocomplete", 2);
295
+ p({ type: String, reflect: !0 })
296
+ ], s.prototype, "autocomplete", 2);
297
297
  r([
298
- u({ type: String })
299
- ], o.prototype, "label", 2);
298
+ p({ type: String })
299
+ ], s.prototype, "label", 2);
300
300
  r([
301
- u({ type: String, attribute: "label-position" })
302
- ], o.prototype, "labelPosition", 2);
301
+ p({ type: String, attribute: "label-position" })
302
+ ], s.prototype, "labelPosition", 2);
303
303
  r([
304
- u({ type: String, reflect: !0 })
305
- ], o.prototype, "regex", 2);
304
+ p({ type: String, reflect: !0 })
305
+ ], s.prototype, "regex", 2);
306
306
  r([
307
- u({ type: Boolean, attribute: "show-regex-placeholder", reflect: !0 })
308
- ], o.prototype, "showRegexPlaceholder", 2);
307
+ p({ type: String, attribute: "regex-placeholder" })
308
+ ], s.prototype, "regexPlaceholder", 2);
309
309
  r([
310
- u({ type: Boolean, attribute: "show-regex-placeholer", reflect: !0 })
311
- ], o.prototype, "showRegexPlaceholer", 2);
312
- r([
313
- V("input")
314
- ], o.prototype, "inputEl", 2);
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
- o as DuiInput
316
+ s as DuiInput
320
317
  };
@@ -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": "show-regex-placeholder",
34
- "description": "If true and regex is valid, placeholder is generated from the regex mask (for floating labels, shown only while focused).",
35
- "type": "boolean",
36
- "default": false,
37
- "control": "boolean"
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": "showRegexPlaceholder",
115
- "description": "Enables regex-derived placeholder text.",
116
- "type": "boolean",
117
- "default": false
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": "show-regex-placeholder",
375
+ "id": "regex-placeholder",
376
376
  "kind": "attribute",
377
- "ref": "show-regex-placeholder",
377
+ "ref": "regex-placeholder",
378
378
  "group": "mask",
379
- "label": "Show Regex Placeholder",
379
+ "label": "Regex Placeholder",
380
380
  "order": 2
381
381
  },
382
382
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grayscale-dev/dragon",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Framework-agnostic Web Components built with Lit.",
5
5
  "type": "module",
6
6
  "files": [