mlform 0.1.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/LICENSE +21 -0
- package/README.md +132 -0
- package/dist/FieldStrategy-pPekBtH-.js +2318 -0
- package/dist/ModelTypes-B9_veCKB.js +5 -0
- package/dist/ReportStrategy-DY3GC_mJ.js +23 -0
- package/dist/boolean-field-Cd3uhIPj.js +104 -0
- package/dist/category-field-D_Ms1x9u.js +73 -0
- package/dist/classifier-prediction-C5QzorTo.js +193 -0
- package/dist/custom-element-ttkHUa8w.js +13 -0
- package/dist/date-field-Cg_ja679.js +162 -0
- package/dist/error-card-BwjPChwf.js +195 -0
- package/dist/field-wrapper-DqIQl76d.js +177 -0
- package/dist/ml-layout-Dx63KKf7.js +332 -0
- package/dist/mlform/extensions.mjs +38 -0
- package/dist/mlform/strategies.mjs +292 -0
- package/dist/mlform.mjs +709 -0
- package/dist/number-field-CC2DrVEb.js +165 -0
- package/dist/property-jKFNMQpR.js +561 -0
- package/dist/range-field-Cr7LEtsJ.js +98 -0
- package/dist/regressor-prediction-C18dHlfK.js +236 -0
- package/dist/src/core/app/DescriptorItem.d.ts +6 -0
- package/dist/src/core/app/DescriptorRegistry.d.ts +13 -0
- package/dist/src/core/app/DescriptorService.d.ts +22 -0
- package/dist/src/core/app/DescriptorStrategy.d.ts +11 -0
- package/dist/src/core/app/index.d.ts +4 -0
- package/dist/src/core/domain/index.d.ts +24 -0
- package/dist/src/core/index.d.ts +3 -0
- package/dist/src/core/ui/error-card.d.ts +38 -0
- package/dist/src/core/ui/field-wrapper.d.ts +23 -0
- package/dist/src/core/ui/index.d.ts +3 -0
- package/dist/src/core/ui/ml-layout.d.ts +23 -0
- package/dist/src/extensions/app/FieldStrategy.d.ts +10 -0
- package/dist/src/extensions/app/ReportStrategy.d.ts +9 -0
- package/dist/src/extensions/app/index.d.ts +2 -0
- package/dist/src/extensions/domain/BaseField.d.ts +7 -0
- package/dist/src/extensions/domain/BaseModel.d.ts +6 -0
- package/dist/src/extensions/domain/index.d.ts +2 -0
- package/dist/src/extensions/index.d.ts +3 -0
- package/dist/src/extensions/ui/field-element.d.ts +9 -0
- package/dist/src/extensions/ui/index.d.ts +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/mlform/index.d.ts +1 -0
- package/dist/src/mlform/mlform.d.ts +27 -0
- package/dist/src/mlform/mlform.types.d.ts +11 -0
- package/dist/src/strategies/app/BooleanStrategy.d.ts +12 -0
- package/dist/src/strategies/app/CategoryStrategy.d.ts +13 -0
- package/dist/src/strategies/app/ClassifierStrategy.d.ts +15 -0
- package/dist/src/strategies/app/DateStrategy.d.ts +15 -0
- package/dist/src/strategies/app/NumberStrategy.d.ts +29 -0
- package/dist/src/strategies/app/RegressorStrategy.d.ts +15 -0
- package/dist/src/strategies/app/TextStrategy.d.ts +16 -0
- package/dist/src/strategies/app/index.d.ts +7 -0
- package/dist/src/strategies/domain/BooleanField.d.ts +10 -0
- package/dist/src/strategies/domain/CategoryField.d.ts +11 -0
- package/dist/src/strategies/domain/ClassifierModel.d.ts +11 -0
- package/dist/src/strategies/domain/DateField.d.ts +13 -0
- package/dist/src/strategies/domain/FieldTypes.d.ts +7 -0
- package/dist/src/strategies/domain/ModelTypes.d.ts +4 -0
- package/dist/src/strategies/domain/NumberField.d.ts +15 -0
- package/dist/src/strategies/domain/RegressorModel.d.ts +11 -0
- package/dist/src/strategies/domain/TextField.d.ts +14 -0
- package/dist/src/strategies/domain/index.d.ts +9 -0
- package/dist/src/strategies/index.d.ts +1 -0
- package/dist/src/strategies/ui/boolean-field.d.ts +13 -0
- package/dist/src/strategies/ui/category-field.d.ts +14 -0
- package/dist/src/strategies/ui/classifier-prediction.d.ts +39 -0
- package/dist/src/strategies/ui/date-field.d.ts +18 -0
- package/dist/src/strategies/ui/index.d.ts +8 -0
- package/dist/src/strategies/ui/number-field.d.ts +19 -0
- package/dist/src/strategies/ui/range-field.d.ts +17 -0
- package/dist/src/strategies/ui/regressor-prediction.d.ts +29 -0
- package/dist/src/strategies/ui/text-field.d.ts +17 -0
- package/dist/state-CLlTRyl1.js +12 -0
- package/dist/test/_fixtures/DummyField.d.ts +9 -0
- package/dist/test/setup.d.ts +1 -0
- package/dist/test/unit/DummyField.test.d.ts +1 -0
- package/dist/text-field-DwP-Fa1w.js +114 -0
- package/package.json +57 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { FieldElement as p } from "./mlform/extensions.mjs";
|
|
2
|
+
import { a as m, n as u, x as c } from "./property-jKFNMQpR.js";
|
|
3
|
+
import { t as d } from "./custom-element-ttkHUa8w.js";
|
|
4
|
+
var h = Object.defineProperty, f = Object.getOwnPropertyDescriptor, b = (r, t, i) => t in r ? h(r, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[t] = i, l = (r, t, i, n) => {
|
|
5
|
+
for (var e = n > 1 ? void 0 : n ? f(t, i) : t, s = r.length - 1, o; s >= 0; s--)
|
|
6
|
+
(o = r[s]) && (e = (n ? o(t, i, e) : o(e)) || e);
|
|
7
|
+
return n && e && h(t, i, e), e;
|
|
8
|
+
}, v = (r, t, i) => b(r, t + "", i);
|
|
9
|
+
let a = class extends p {
|
|
10
|
+
unit = "";
|
|
11
|
+
step = "1";
|
|
12
|
+
firstUpdated() {
|
|
13
|
+
if (this.placeholder || (this.placeholder = this.step), this.defaultValue) {
|
|
14
|
+
this.value = Number(this.defaultValue);
|
|
15
|
+
const r = new InputEvent("input", {
|
|
16
|
+
bubbles: !0,
|
|
17
|
+
composed: !0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(r, "target", {
|
|
20
|
+
value: { value: this.defaultValue },
|
|
21
|
+
writable: !1
|
|
22
|
+
}), this.onInput(r);
|
|
23
|
+
} else
|
|
24
|
+
this.value = NaN;
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
return c`
|
|
28
|
+
<div class="input-wrapper">
|
|
29
|
+
<input
|
|
30
|
+
type="text"
|
|
31
|
+
inputmode="decimal"
|
|
32
|
+
autocomplete="off"
|
|
33
|
+
@input=${this.onInput}
|
|
34
|
+
.step=${Number(this.step)}
|
|
35
|
+
.min=${Number(this.min)}
|
|
36
|
+
.max=${Number(this.max)}
|
|
37
|
+
.placeholder=${this.placeholder}
|
|
38
|
+
.value=${Number.isNaN(this.value) ? "" : this.value}
|
|
39
|
+
/>
|
|
40
|
+
<span class="unit">${this.unit}</span>
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
onInput(r) {
|
|
45
|
+
if (this.value = Number(r.target.value.trim()), !this.value) {
|
|
46
|
+
this.dispatchState("empty");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!/^[0-9.,\s-]+$/.test(this.value.toString())) {
|
|
50
|
+
this.dispatchState(
|
|
51
|
+
"error",
|
|
52
|
+
"Only digits, comma, dot, space, and a leading minus are allowed."
|
|
53
|
+
);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const i = (this.value.toString().match(/-/g) || []).length;
|
|
57
|
+
if (i > 1 || i === 1 && !this.value.toString().startsWith("-")) {
|
|
58
|
+
this.dispatchState(
|
|
59
|
+
"error",
|
|
60
|
+
"Minus sign must appear once and only at the beginning."
|
|
61
|
+
);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!/^-?(?:\d{1,3}(?:([,\s])\d{3}(?:\1\d{3})*)|\d+)(?:[.]\d+)?$/.test(this.value.toString())) {
|
|
65
|
+
this.dispatchState(
|
|
66
|
+
"error",
|
|
67
|
+
"Invalid number format (check grouping or decimal separator)."
|
|
68
|
+
);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const e = this.parseLocaleNumber(this.value.toString());
|
|
72
|
+
if (this.min && this.max && (e < parseFloat(this.min) || e > parseFloat(this.max))) {
|
|
73
|
+
this.dispatchState(
|
|
74
|
+
"error",
|
|
75
|
+
`Number must be between
|
|
76
|
+
${this.min} ${this.unit} and
|
|
77
|
+
${this.max ?? ""} ${this.unit}`
|
|
78
|
+
);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (this.min && e < parseFloat(this.min)) {
|
|
82
|
+
this.dispatchState(
|
|
83
|
+
"error",
|
|
84
|
+
`Number must be greater than or equal to ${this.min} ${this.unit}`
|
|
85
|
+
);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (this.max && e > parseFloat(this.max)) {
|
|
89
|
+
this.dispatchState(
|
|
90
|
+
"error",
|
|
91
|
+
`Number must be less than or equal to ${this.max} ${this.unit}`
|
|
92
|
+
);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.dispatchState(
|
|
96
|
+
"success",
|
|
97
|
+
`Valid Number: ${e.toLocaleString("en-US", {})} ${this.unit}`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
parseLocaleNumber(r) {
|
|
101
|
+
let t = r.replace(/\s+/g, ""), i = "";
|
|
102
|
+
t.startsWith("-") && (i = "-", t = t.slice(1));
|
|
103
|
+
const n = t.lastIndexOf("."), e = Math.max(n);
|
|
104
|
+
let s, o = "";
|
|
105
|
+
return e !== -1 ? (s = t.slice(0, e), o = t.slice(e + 1)) : s = t, s = s.replace(/[.,]/g, ""), parseFloat(i + (o ? `${s}.${o}` : s));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
v(a, "styles", [
|
|
109
|
+
p.baseStyles,
|
|
110
|
+
m`
|
|
111
|
+
.input-wrapper {
|
|
112
|
+
position: relative;
|
|
113
|
+
}
|
|
114
|
+
input[type="text"] {
|
|
115
|
+
width: 100%;
|
|
116
|
+
padding: 0.75rem calc(var(--unit-w) + 2rem) 0.75rem 1rem;
|
|
117
|
+
font-size: 1rem;
|
|
118
|
+
border: 1px solid var(--ml-color-border);
|
|
119
|
+
border-radius: var(--radius);
|
|
120
|
+
outline: none;
|
|
121
|
+
transition: border-color 0.2s ease;
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
overflow-x: auto;
|
|
124
|
+
overflow-y: hidden;
|
|
125
|
+
-webkit-overflow-scrolling: touch;
|
|
126
|
+
}
|
|
127
|
+
input[type="text"]:focus {
|
|
128
|
+
border-color: var(--ml-color-accent);
|
|
129
|
+
}
|
|
130
|
+
.unit {
|
|
131
|
+
position: absolute;
|
|
132
|
+
right: 1rem;
|
|
133
|
+
top: 50%;
|
|
134
|
+
min-width: var(--unit-w);
|
|
135
|
+
transform: translateY(-50%);
|
|
136
|
+
font-size: 0.9rem;
|
|
137
|
+
color: var(--ml-color-secondary);
|
|
138
|
+
pointer-events: none;
|
|
139
|
+
}
|
|
140
|
+
`
|
|
141
|
+
]);
|
|
142
|
+
l([
|
|
143
|
+
u({ type: String })
|
|
144
|
+
], a.prototype, "unit", 2);
|
|
145
|
+
l([
|
|
146
|
+
u({ type: String })
|
|
147
|
+
], a.prototype, "step", 2);
|
|
148
|
+
l([
|
|
149
|
+
u({ type: String })
|
|
150
|
+
], a.prototype, "min", 2);
|
|
151
|
+
l([
|
|
152
|
+
u({ type: String })
|
|
153
|
+
], a.prototype, "max", 2);
|
|
154
|
+
l([
|
|
155
|
+
u({ type: String })
|
|
156
|
+
], a.prototype, "defaultValue", 2);
|
|
157
|
+
l([
|
|
158
|
+
u({ type: String })
|
|
159
|
+
], a.prototype, "placeholder", 2);
|
|
160
|
+
a = l([
|
|
161
|
+
d("number-field")
|
|
162
|
+
], a);
|
|
163
|
+
export {
|
|
164
|
+
a as NumberField
|
|
165
|
+
};
|