@octax-app/hot-date-react 0.0.7 → 0.0.9
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 +22 -2
- package/dist/{hot-date-B8i-uiIl.js → hot-date-DIgUxVss.js} +19 -13
- package/dist/hot-date-react.js +56 -52
- package/dist/hot-date.d.ts +1 -0
- package/dist/hot-date.js +1 -1
- package/dist/react/HotDate.d.ts +4 -3
- package/dist/react/format.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -187,6 +187,25 @@ When `value` is provided the input renders in display mode — showing the forma
|
|
|
187
187
|
onClick={(e) => console.log('clicked')}
|
|
188
188
|
onMouseEnter={(e) => console.log('mouse in')}
|
|
189
189
|
onMouseLeave={(e) => console.log('mouse out')}
|
|
190
|
+
onError={(err) => console.log(err)} // "Date is outside the allowed range." | undefined
|
|
191
|
+
/>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Error handling
|
|
195
|
+
|
|
196
|
+
`onError` fires whenever the typed input is invalid — out of range, wrong mode, or unparseable. It fires with `undefined` when the error clears (user types a valid date or empties the field). Only fires when the error state actually changes, not on every keystroke.
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
<HotDate
|
|
200
|
+
endDate={new Date()} // today is the latest allowed date
|
|
201
|
+
onError={(err) => {
|
|
202
|
+
if (err) setErrorMsg(err); // e.g. "Date is outside the allowed range."
|
|
203
|
+
else setErrorMsg(""); // cleared
|
|
204
|
+
}}
|
|
205
|
+
onChange={(value) => {
|
|
206
|
+
// value is "" when nothing is selected, "YYYY-MM-DD" when valid
|
|
207
|
+
setValue(value as string);
|
|
208
|
+
}}
|
|
190
209
|
/>
|
|
191
210
|
```
|
|
192
211
|
|
|
@@ -196,9 +215,10 @@ When `value` is provided the input renders in display mode — showing the forma
|
|
|
196
215
|
| --- | --- | --- | --- |
|
|
197
216
|
| `value` | `string \| null` | — | Controlled canonical value (`YYYY-MM-DD` or `YYYY-MM-DD/YYYY-MM-DD`). Enters display mode while unfocused. |
|
|
198
217
|
| `defaultValue` | `string \| null` | — | Uncontrolled initial value. Mounts in display mode; React does not drive updates after mount. |
|
|
199
|
-
| `onChange` | `(value: string \| [string, string]
|
|
200
|
-
| `onCommit` | `(value: string \| [string, string]
|
|
218
|
+
| `onChange` | `(value: string \| [string, string]) => void` | — | Fires on every valid parse. Returns `""` when no value. Range returns `[start, end]`. |
|
|
219
|
+
| `onCommit` | `(value: string \| [string, string]) => void` | — | Fires on Enter key commit. Returns `""` when no value. |
|
|
201
220
|
| `onClear` | `() => void` | — | Fires when input is cleared. |
|
|
221
|
+
| `onError` | `(error: string \| undefined) => void` | — | Fires when input is invalid (out of range, unparseable, wrong mode). Fires `undefined` when the error clears. Only fires on state change, not every keystroke. |
|
|
202
222
|
| `onFocus` | `(e: FocusEvent) => void` | — | Fires when the input gains focus. |
|
|
203
223
|
| `onBlur` | `(e: FocusEvent) => void` | — | Fires when the input loses focus. |
|
|
204
224
|
| `onKeyDown` | `(e: KeyboardEvent) => void` | — | Fires on keydown. |
|
|
@@ -78,7 +78,7 @@ function y(e) {
|
|
|
78
78
|
return /^\d+$/.test(t) ? Number(t) : l[t] ?? null;
|
|
79
79
|
}
|
|
80
80
|
//#endregion
|
|
81
|
-
//#region node_modules
|
|
81
|
+
//#region node_modules/@js-temporal/polyfill/dist/index.esm.js
|
|
82
82
|
var b = /* @__PURE__ */ c((/* @__PURE__ */ o(((e, t) => {
|
|
83
83
|
(function(n, r) {
|
|
84
84
|
typeof e == "object" && t !== void 0 ? t.exports = r() : typeof define == "function" && define.amd ? define(r) : (n ||= self, n.JSBI = r());
|
|
@@ -8805,6 +8805,7 @@ var Gc = class extends HTMLElement {
|
|
|
8805
8805
|
parser = new Pc();
|
|
8806
8806
|
internals;
|
|
8807
8807
|
styleObserver = null;
|
|
8808
|
+
fieldElement;
|
|
8808
8809
|
inputElement;
|
|
8809
8810
|
ghostElement;
|
|
8810
8811
|
ghostTypedElement;
|
|
@@ -8822,12 +8823,15 @@ var Gc = class extends HTMLElement {
|
|
|
8822
8823
|
super(), this.attachShadow({ mode: "open" }), this.shadowRoot?.append(Wc().content.cloneNode(!0));
|
|
8823
8824
|
let e = this.shadowRoot;
|
|
8824
8825
|
if (!e) throw Error("Unable to create shadow root.");
|
|
8825
|
-
this.inputElement = e.querySelector("input") ?? document.createElement("input"), this.ghostElement = e.querySelector(".ghost") ?? document.createElement("div"), this.ghostTypedElement = e.querySelector(".ghost-typed") ?? document.createElement("span"), this.ghostTailElement = e.querySelector(".ghost-tail") ?? document.createElement("span"), this.ghostHintElement = e.querySelector(".ghost-hint") ?? document.createElement("kbd"), this.ghostResolutionElement = e.querySelector(".ghost-resolution") ?? document.createElement("span"), this.ambiguityElement = document.createElement("div"), this.ambiguityElement.setAttribute("slot", "ambiguity"), this.ambiguityElement.hidden = !0, this.internals = typeof this.attachInternals == "function" ? this.attachInternals() : null, this.bindEvents();
|
|
8826
|
+
this.fieldElement = e.querySelector(".field") ?? document.createElement("div"), this.inputElement = e.querySelector("input") ?? document.createElement("input"), this.ghostElement = e.querySelector(".ghost") ?? document.createElement("div"), this.ghostTypedElement = e.querySelector(".ghost-typed") ?? document.createElement("span"), this.ghostTailElement = e.querySelector(".ghost-tail") ?? document.createElement("span"), this.ghostHintElement = e.querySelector(".ghost-hint") ?? document.createElement("kbd"), this.ghostResolutionElement = e.querySelector(".ghost-resolution") ?? document.createElement("span"), this.ambiguityElement = document.createElement("div"), this.ambiguityElement.setAttribute("slot", "ambiguity"), this.ambiguityElement.hidden = !0, this.internals = typeof this.attachInternals == "function" ? this.attachInternals() : null, this.bindEvents();
|
|
8826
8827
|
}
|
|
8827
8828
|
connectedCallback() {
|
|
8828
8829
|
this.ambiguityElement.parentNode !== this && this.append(this.ambiguityElement), this.updateStyles(), this.syncExternalStyles(), this.updateHintVisibility(), this.syncInputPresentation(), this.parseAndRender(), this.styleObserver || (this.styleObserver = new MutationObserver(() => this.syncExternalStyles()), this.styleObserver.observe(document.head, {
|
|
8829
8830
|
childList: !0,
|
|
8830
8831
|
subtree: !0
|
|
8832
|
+
}), this.styleObserver.observe(document.documentElement, {
|
|
8833
|
+
attributes: !0,
|
|
8834
|
+
attributeFilter: ["class"]
|
|
8831
8835
|
}));
|
|
8832
8836
|
}
|
|
8833
8837
|
disconnectedCallback() {
|
|
@@ -8976,26 +8980,28 @@ var Gc = class extends HTMLElement {
|
|
|
8976
8980
|
}
|
|
8977
8981
|
syncExternalStyles() {
|
|
8978
8982
|
if (!this.shadowRoot) return;
|
|
8983
|
+
let e = Array.from(document.documentElement.classList);
|
|
8984
|
+
this.fieldElement.className = "field" + (e.length ? " " + e.join(" ") : "");
|
|
8979
8985
|
try {
|
|
8980
8986
|
document.adoptedStyleSheets.length > 0 && (this.shadowRoot.adoptedStyleSheets = [...document.adoptedStyleSheets]);
|
|
8981
8987
|
} catch {}
|
|
8982
|
-
let
|
|
8983
|
-
document.querySelectorAll("link[rel=\"stylesheet\"]").forEach((
|
|
8984
|
-
if (!
|
|
8985
|
-
let
|
|
8986
|
-
|
|
8988
|
+
let t = new Set(Array.from(this.shadowRoot.querySelectorAll("link[data-ext]")).map((e) => e.href));
|
|
8989
|
+
document.querySelectorAll("link[rel=\"stylesheet\"]").forEach((e) => {
|
|
8990
|
+
if (!t.has(e.href)) {
|
|
8991
|
+
let t = document.createElement("link");
|
|
8992
|
+
t.rel = "stylesheet", t.href = e.href, t.dataset.ext = "", this.shadowRoot.append(t);
|
|
8987
8993
|
}
|
|
8988
8994
|
});
|
|
8989
|
-
let
|
|
8990
|
-
|
|
8991
|
-
let
|
|
8992
|
-
if (
|
|
8995
|
+
let n = Array.from(document.head.querySelectorAll("style")), r = Array.from(this.shadowRoot.querySelectorAll("style[data-ext-style]"));
|
|
8996
|
+
n.forEach((e, t) => {
|
|
8997
|
+
let n = e.textContent ?? "";
|
|
8998
|
+
if (r[t]) r[t].textContent !== n && (r[t].textContent = n);
|
|
8993
8999
|
else {
|
|
8994
9000
|
let e = document.createElement("style");
|
|
8995
|
-
e.dataset.extStyle = "", e.textContent =
|
|
9001
|
+
e.dataset.extStyle = "", e.textContent = n, this.shadowRoot.append(e);
|
|
8996
9002
|
}
|
|
8997
9003
|
});
|
|
8998
|
-
for (let e =
|
|
9004
|
+
for (let e = n.length; e < r.length; e++) r[e].remove();
|
|
8999
9005
|
requestAnimationFrame(() => {
|
|
9000
9006
|
let e = window.getComputedStyle(this.inputElement);
|
|
9001
9007
|
this.ghostElement.style.font = e.font;
|
package/dist/hot-date-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "./hot-date-
|
|
1
|
+
import { t as e } from "./hot-date-DIgUxVss.js";
|
|
2
2
|
import { useEffect as t, useRef as n, useState as r } from "react";
|
|
3
3
|
import { jsx as i } from "react/jsx-runtime";
|
|
4
4
|
//#region src/react/format.ts
|
|
@@ -58,7 +58,7 @@ function u(e) {
|
|
|
58
58
|
return l(e);
|
|
59
59
|
}
|
|
60
60
|
function d(e, t) {
|
|
61
|
-
if (!e) return
|
|
61
|
+
if (!e) return "";
|
|
62
62
|
if (e.includes("/")) {
|
|
63
63
|
let [n, r] = e.split("/"), i = t ?? "YYYY-MM-DD";
|
|
64
64
|
return [s(n, i), s(r, i)];
|
|
@@ -71,67 +71,70 @@ typeof customElements < "u" && (customElements.get("hot-date") || customElements
|
|
|
71
71
|
function f(e) {
|
|
72
72
|
if (e !== void 0) return typeof e == "string" ? e : `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
|
|
73
73
|
}
|
|
74
|
-
function p({ value: e, defaultValue: a, onChange: s, onCommit: c, onClear: l,
|
|
75
|
-
let
|
|
74
|
+
function p({ value: e, defaultValue: a, onChange: s, onCommit: c, onClear: l, onError: p, onFocus: m, onBlur: h, onKeyDown: g, onKeyUp: _, onInput: v, onPaste: y, onClick: b, onMouseEnter: x, onMouseLeave: S, onMouseDown: C, onMouseUp: w, onMouseMove: T, format: E, dateType: D = "point", startDate: O, endDate: k, className: A, style: j, placeholder: M, timezone: N, locale: P, weekStart: F, disabled: I, required: L, name: R, showHint: z, error: B, success: V, classNames: H }) {
|
|
75
|
+
let U = n(null), [W, G] = r(!!e), [K, q] = r(!1), J = n(void 0), Y = z ?? !0;
|
|
76
76
|
t(() => {
|
|
77
|
-
let e =
|
|
77
|
+
let e = U.current;
|
|
78
78
|
if (!e) return;
|
|
79
79
|
let t = (t, n) => {
|
|
80
80
|
n ? e.setAttribute(t, "") : e.removeAttribute(t);
|
|
81
81
|
}, n = (t, n) => {
|
|
82
82
|
n == null ? e.removeAttribute(t) : e.setAttribute(t, n);
|
|
83
83
|
};
|
|
84
|
-
n("placeholder",
|
|
84
|
+
n("placeholder", M), n("timezone", N), n("locale", P), n("week-start", F), n("start-date", f(O)), n("end-date", f(k)), n("mode", D), n("format", E), t("disabled", !!I), t("required", !!L), t("hide-hint", !Y), n("name", R);
|
|
85
85
|
}, [
|
|
86
|
-
j,
|
|
87
86
|
M,
|
|
88
87
|
N,
|
|
89
88
|
P,
|
|
90
|
-
|
|
89
|
+
F,
|
|
91
90
|
O,
|
|
91
|
+
k,
|
|
92
|
+
D,
|
|
92
93
|
E,
|
|
93
|
-
T,
|
|
94
|
-
F,
|
|
95
94
|
I,
|
|
96
95
|
L,
|
|
97
|
-
|
|
96
|
+
R,
|
|
97
|
+
Y
|
|
98
98
|
]);
|
|
99
|
-
let
|
|
99
|
+
let X = n(a);
|
|
100
100
|
return t(() => {
|
|
101
|
-
let e =
|
|
101
|
+
let e = U.current, t = X.current;
|
|
102
102
|
if (!e || t == null) return;
|
|
103
|
-
let n =
|
|
104
|
-
e.value = n,
|
|
103
|
+
let n = E ? o(t, E) ?? t : t;
|
|
104
|
+
e.value = n, G(!!n), n && (e.setAttribute("display-value", u(n)), e.forceDisplayMode?.(n));
|
|
105
105
|
}, []), t(() => {
|
|
106
|
-
let t =
|
|
106
|
+
let t = U.current;
|
|
107
107
|
if (!t || e === void 0) return;
|
|
108
|
-
let n = e ?
|
|
109
|
-
t.value = n,
|
|
108
|
+
let n = e ? E ? o(e, E) ?? e : e : null;
|
|
109
|
+
t.value = n, G(!!n), n ? (t.setAttribute("display-value", u(n)), K || t.forceDisplayMode?.(n)) : (t.removeAttribute("display-value"), K || t.forceDisplayMode?.(null));
|
|
110
110
|
}, [
|
|
111
111
|
e,
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
E,
|
|
113
|
+
K
|
|
114
114
|
]), t(() => {
|
|
115
|
-
let e =
|
|
115
|
+
let e = U.current;
|
|
116
116
|
if (!e) return;
|
|
117
|
-
let t = (e) => {
|
|
117
|
+
let t = e.shadowRoot?.querySelector("input") ?? null, n = (e) => {
|
|
118
118
|
let t = e.detail;
|
|
119
|
-
|
|
120
|
-
},
|
|
119
|
+
G(!!t.value), s?.(d(t.value, E));
|
|
120
|
+
}, r = (e) => {
|
|
121
121
|
let t = e.detail;
|
|
122
|
-
c?.(d(t.value,
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
}, i = (e) => {
|
|
126
|
-
K(!0), p?.(e);
|
|
122
|
+
c?.(d(t.value, E));
|
|
123
|
+
}, i = () => {
|
|
124
|
+
G(!1), l?.();
|
|
127
125
|
}, a = (e) => {
|
|
128
|
-
|
|
129
|
-
}, o = (e) =>
|
|
126
|
+
q(!0), m?.(e);
|
|
127
|
+
}, o = (e) => {
|
|
128
|
+
q(!1), h?.(e);
|
|
129
|
+
}, u = (e) => g?.(e), f = (e) => _?.(e), D = (e) => {
|
|
130
130
|
let t = e.detail;
|
|
131
|
-
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
v?.(t.rawInput);
|
|
132
|
+
}, O = (e) => {
|
|
133
|
+
let { status: t, parseResult: n } = e.detail, r = t === "invalid" && n.rawInput ? n.errors[0] ?? "Invalid date" : void 0;
|
|
134
|
+
r !== J.current && (J.current = r, p?.(r));
|
|
135
|
+
}, k = (e) => y?.(e), A = (e) => b?.(e), j = (e) => x?.(e), M = (e) => S?.(e), N = (e) => C?.(e), P = (e) => w?.(e), F = (e) => T?.(e);
|
|
136
|
+
return e.addEventListener("value-change", n), e.addEventListener("value-commit", r), e.addEventListener("clear", i), e.addEventListener("focusin", a), e.addEventListener("focusout", o), e.addEventListener("raw-input-change", D), e.addEventListener("parse-change", O), e.addEventListener("click", A), e.addEventListener("mouseenter", j), e.addEventListener("mouseleave", M), e.addEventListener("mousedown", N), e.addEventListener("mouseup", P), e.addEventListener("mousemove", F), t?.addEventListener("keydown", u), t?.addEventListener("keyup", f), t?.addEventListener("paste", k), () => {
|
|
137
|
+
e.removeEventListener("value-change", n), e.removeEventListener("value-commit", r), e.removeEventListener("clear", i), e.removeEventListener("focusin", a), e.removeEventListener("focusout", o), e.removeEventListener("raw-input-change", D), e.removeEventListener("parse-change", O), e.removeEventListener("click", A), e.removeEventListener("mouseenter", j), e.removeEventListener("mouseleave", M), e.removeEventListener("mousedown", N), e.removeEventListener("mouseup", P), e.removeEventListener("mousemove", F), t?.removeEventListener("keydown", u), t?.removeEventListener("keyup", f), t?.removeEventListener("paste", k);
|
|
135
138
|
};
|
|
136
139
|
}, [
|
|
137
140
|
s,
|
|
@@ -149,32 +152,33 @@ function p({ value: e, defaultValue: a, onChange: s, onCommit: c, onClear: l, on
|
|
|
149
152
|
S,
|
|
150
153
|
C,
|
|
151
154
|
w,
|
|
152
|
-
T
|
|
155
|
+
T,
|
|
156
|
+
E
|
|
153
157
|
]), t(() => {
|
|
154
|
-
let e =
|
|
158
|
+
let e = U.current;
|
|
155
159
|
if (!e) return;
|
|
156
160
|
let t = (e) => e ? typeof e == "function" ? e({
|
|
157
|
-
active:
|
|
158
|
-
disabled: !!
|
|
159
|
-
focused:
|
|
160
|
-
error: !!
|
|
161
|
-
success: !!
|
|
161
|
+
active: W,
|
|
162
|
+
disabled: !!I,
|
|
163
|
+
focused: K,
|
|
164
|
+
error: !!B,
|
|
165
|
+
success: !!V
|
|
162
166
|
}) : e : null, n = (n, r) => {
|
|
163
167
|
let i = t(r);
|
|
164
168
|
i ? e.setAttribute(n, i) : e.removeAttribute(n);
|
|
165
169
|
};
|
|
166
|
-
n("part-class-input",
|
|
170
|
+
n("part-class-input", H?.input), n("part-class-ghost", H?.ghost), n("part-class-hint", H?.hint);
|
|
167
171
|
}, [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
H,
|
|
173
|
+
W,
|
|
174
|
+
K,
|
|
175
|
+
I,
|
|
176
|
+
B,
|
|
177
|
+
V
|
|
174
178
|
]), /* @__PURE__ */ i("hot-date", {
|
|
175
|
-
ref:
|
|
176
|
-
class:
|
|
177
|
-
style:
|
|
179
|
+
ref: U,
|
|
180
|
+
class: A,
|
|
181
|
+
style: j
|
|
178
182
|
});
|
|
179
183
|
}
|
|
180
184
|
//#endregion
|
package/dist/hot-date.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class HotDateElement extends HTMLElement {
|
|
|
5
5
|
private readonly parser;
|
|
6
6
|
private readonly internals;
|
|
7
7
|
private styleObserver;
|
|
8
|
+
private readonly fieldElement;
|
|
8
9
|
private readonly inputElement;
|
|
9
10
|
private readonly ghostElement;
|
|
10
11
|
private readonly ghostTypedElement;
|
package/dist/hot-date.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "./hot-date-
|
|
1
|
+
import { t as e } from "./hot-date-DIgUxVss.js";
|
|
2
2
|
export { e as HotDateElement };
|
package/dist/react/HotDate.d.ts
CHANGED
|
@@ -15,9 +15,10 @@ type WEEK_START_MAP = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday'
|
|
|
15
15
|
export interface HotDateProps {
|
|
16
16
|
value?: string | null;
|
|
17
17
|
defaultValue?: string | null;
|
|
18
|
-
onChange?: (value: string | [string, string]
|
|
19
|
-
onCommit?: (value: string | [string, string]
|
|
18
|
+
onChange?: (value: string | [string, string]) => void;
|
|
19
|
+
onCommit?: (value: string | [string, string]) => void;
|
|
20
20
|
onClear?: () => void;
|
|
21
|
+
onError?: (error: string | undefined) => void;
|
|
21
22
|
onFocus?: (e: FocusEvent) => void;
|
|
22
23
|
onBlur?: (e: FocusEvent) => void;
|
|
23
24
|
onKeyDown?: (e: KeyboardEvent) => void;
|
|
@@ -76,5 +77,5 @@ declare module "react" {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
|
-
export declare function HotDate({ value, defaultValue, onChange, onCommit, onClear, onFocus, onBlur, onKeyDown, onKeyUp, onInput, onPaste, onClick, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onMouseMove, format, dateType, startDate, endDate, className, style, placeholder, timezone, locale, weekStart, disabled, required, name, showHint, error, success, classNames, }: HotDateProps): import("react/jsx-runtime").JSX.Element;
|
|
80
|
+
export declare function HotDate({ value, defaultValue, onChange, onCommit, onClear, onError, onFocus, onBlur, onKeyDown, onKeyUp, onInput, onPaste, onClick, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onMouseMove, format, dateType, startDate, endDate, className, style, placeholder, timezone, locale, weekStart, disabled, required, name, showHint, error, success, classNames, }: HotDateProps): import("react/jsx-runtime").JSX.Element;
|
|
80
81
|
export {};
|
package/dist/react/format.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare function parseFormatToIso(formatted: string, format: string): string | null;
|
|
2
2
|
export declare function formatDisplayValue(canonical: string | null): string;
|
|
3
|
-
export declare function applyFormat(canonical: string | null, format?: string): string | [string, string]
|
|
3
|
+
export declare function applyFormat(canonical: string | null, format?: string): string | [string, string];
|