@nnkogift/dhis2-form-utils-dhis2-ui 0.1.0-alpha.7 → 0.1.0-alpha.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/dist/index.cjs +65 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +60 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +66 -86
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,10 @@ function D2LongTextField({ control }) {
|
|
|
55
55
|
}
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function TypedTextField({
|
|
59
|
+
control,
|
|
60
|
+
type
|
|
61
|
+
}) {
|
|
59
62
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
60
63
|
const { validationText, hasError, hasWarning } = dhis2FormUtilsHooks.resolveFieldValidation(control);
|
|
61
64
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -79,16 +82,16 @@ function D2TypedTextField({ control, type }) {
|
|
|
79
82
|
);
|
|
80
83
|
}
|
|
81
84
|
function D2EmailField(props) {
|
|
82
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
85
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TypedTextField, { ...props, type: "email" });
|
|
83
86
|
}
|
|
84
87
|
function D2PhoneField(props) {
|
|
85
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TypedTextField, { ...props, type: "tel" });
|
|
86
89
|
}
|
|
87
90
|
function D2NumberField(props) {
|
|
88
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
91
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TypedTextField, { ...props, type: "number" });
|
|
89
92
|
}
|
|
90
93
|
function D2IntegerField(props) {
|
|
91
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
94
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TypedTextField, { ...props, type: "number" });
|
|
92
95
|
}
|
|
93
96
|
function D2PercentageField({ control }) {
|
|
94
97
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -105,14 +108,6 @@ function D2PercentageField({ control }) {
|
|
|
105
108
|
);
|
|
106
109
|
}
|
|
107
110
|
var todayIso = () => (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
108
|
-
var readDatePart = (value) => {
|
|
109
|
-
if (!value) return "";
|
|
110
|
-
return value.includes("T") ? value.slice(0, 10) : value;
|
|
111
|
-
};
|
|
112
|
-
var readTimePart = (value) => {
|
|
113
|
-
if (!value.includes("T")) return "";
|
|
114
|
-
return value.slice(11, 16);
|
|
115
|
-
};
|
|
116
111
|
function D2DateField({ control }) {
|
|
117
112
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
118
113
|
const { validationText, hasError, hasWarning } = dhis2FormUtilsHooks.resolveFieldValidation(control);
|
|
@@ -141,6 +136,22 @@ function D2DateField({ control }) {
|
|
|
141
136
|
}
|
|
142
137
|
);
|
|
143
138
|
}
|
|
139
|
+
function D2AgeField({ control }) {
|
|
140
|
+
const age = dhis2FormUtilsHooks.computeAgeFromDob(control.field.value);
|
|
141
|
+
const helpText = [control.fieldConfig.description, age ? `Age: ${age} years` : void 0].filter(Boolean).join(" \xB7 ");
|
|
142
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
143
|
+
D2DateField,
|
|
144
|
+
{
|
|
145
|
+
control: {
|
|
146
|
+
...control,
|
|
147
|
+
fieldConfig: {
|
|
148
|
+
...control.fieldConfig,
|
|
149
|
+
description: helpText || control.fieldConfig.description
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
}
|
|
144
155
|
function D2TimeField({ control }) {
|
|
145
156
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
146
157
|
const { validationText, hasError, hasWarning } = dhis2FormUtilsHooks.resolveFieldValidation(control);
|
|
@@ -164,6 +175,14 @@ function D2TimeField({ control }) {
|
|
|
164
175
|
}
|
|
165
176
|
);
|
|
166
177
|
}
|
|
178
|
+
var readDatePart = (value) => {
|
|
179
|
+
if (!value) return "";
|
|
180
|
+
return value.includes("T") ? value.slice(0, 10) : value;
|
|
181
|
+
};
|
|
182
|
+
var readTimePart = (value) => {
|
|
183
|
+
if (!value.includes("T")) return "";
|
|
184
|
+
return value.slice(11, 16);
|
|
185
|
+
};
|
|
167
186
|
function D2DateTimeField({ control }) {
|
|
168
187
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
169
188
|
const { validationText, hasError, hasWarning } = dhis2FormUtilsHooks.resolveFieldValidation(control);
|
|
@@ -220,27 +239,10 @@ function D2DateTimeField({ control }) {
|
|
|
220
239
|
)
|
|
221
240
|
] });
|
|
222
241
|
}
|
|
223
|
-
function D2AgeField({ control }) {
|
|
224
|
-
const age = dhis2FormUtilsHooks.computeAgeFromDob(control.field.value);
|
|
225
|
-
const helpText = [control.fieldConfig.description, age ? `Age: ${age} years` : void 0].filter(Boolean).join(" \xB7 ");
|
|
226
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
227
|
-
D2DateField,
|
|
228
|
-
{
|
|
229
|
-
control: {
|
|
230
|
-
...control,
|
|
231
|
-
fieldConfig: {
|
|
232
|
-
...control.fieldConfig,
|
|
233
|
-
description: helpText || control.fieldConfig.description
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
242
|
var BOOLEAN_OPTIONS = [
|
|
240
243
|
{ label: "Yes", value: "true" },
|
|
241
244
|
{ label: "No", value: "false" }
|
|
242
245
|
];
|
|
243
|
-
var RADIO_RENDER_HINTS = /* @__PURE__ */ new Set(["RADIO", "VERTICAL_RADIOBUTTONS", "HORIZONTAL_RADIOBUTTONS"]);
|
|
244
246
|
function D2BooleanField({ control }) {
|
|
245
247
|
const { fieldConfig, field, isMandatory, isDisabled } = react.useMemo(() => control, [control]);
|
|
246
248
|
const { validationText, hasError, hasWarning } = react.useMemo(
|
|
@@ -257,30 +259,21 @@ function D2BooleanField({ control }) {
|
|
|
257
259
|
required: isMandatory,
|
|
258
260
|
disabled: isDisabled,
|
|
259
261
|
validationText,
|
|
260
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
261
|
-
|
|
262
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "d2-boolean-options", children: BOOLEAN_OPTIONS.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
263
|
+
ui.Radio,
|
|
262
264
|
{
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
name: field.name,
|
|
266
|
+
label: option.label,
|
|
267
|
+
value: option.value,
|
|
268
|
+
checked: field.value === option.value,
|
|
269
|
+
disabled: isDisabled,
|
|
270
|
+
onChange: ({ value }) => {
|
|
271
|
+
field.onChange(value ?? "");
|
|
266
272
|
},
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
label: option.label,
|
|
272
|
-
value: option.value,
|
|
273
|
-
checked: field.value === option.value,
|
|
274
|
-
disabled: isDisabled,
|
|
275
|
-
onChange: ({ value }) => {
|
|
276
|
-
field.onChange(value ?? "");
|
|
277
|
-
},
|
|
278
|
-
onBlur: field.onBlur
|
|
279
|
-
},
|
|
280
|
-
option.label
|
|
281
|
-
))
|
|
282
|
-
}
|
|
283
|
-
)
|
|
273
|
+
onBlur: field.onBlur
|
|
274
|
+
},
|
|
275
|
+
option.label
|
|
276
|
+
)) })
|
|
284
277
|
}
|
|
285
278
|
);
|
|
286
279
|
}
|
|
@@ -308,6 +301,7 @@ function D2TrueOnlyField({ control }) {
|
|
|
308
301
|
}
|
|
309
302
|
);
|
|
310
303
|
}
|
|
304
|
+
var RADIO_RENDER_HINTS = /* @__PURE__ */ new Set(["RADIO", "VERTICAL_RADIOBUTTONS", "HORIZONTAL_RADIOBUTTONS"]);
|
|
311
305
|
function D2SelectField({ control }) {
|
|
312
306
|
const { fieldConfig, field, isMandatory, isDisabled } = control;
|
|
313
307
|
const { validationText, hasError, hasWarning } = dhis2FormUtilsHooks.resolveFieldValidation(control);
|
|
@@ -504,13 +498,13 @@ function D2ImageField({ control }) {
|
|
|
504
498
|
{
|
|
505
499
|
src: `${baseUrl}/api/fileResources/${value}/data`,
|
|
506
500
|
alt: fieldConfig.label,
|
|
507
|
-
|
|
501
|
+
className: "d2-image-preview"
|
|
508
502
|
}
|
|
509
503
|
) : null
|
|
510
504
|
] });
|
|
511
505
|
}
|
|
512
506
|
|
|
513
|
-
// ../../packages/map/src/coordinateValue.ts
|
|
507
|
+
// ../../packages/map/src/utils/coordinateValue.ts
|
|
514
508
|
var LNG_MIN = -180;
|
|
515
509
|
var LNG_MAX = 180;
|
|
516
510
|
var LAT_MIN = -90;
|
|
@@ -535,7 +529,7 @@ function joinCoordinateValue(lng, lat) {
|
|
|
535
529
|
return JSON.stringify([lng, lat]);
|
|
536
530
|
}
|
|
537
531
|
|
|
538
|
-
// ../../packages/map/src/geojsonValue.ts
|
|
532
|
+
// ../../packages/map/src/utils/geojsonValue.ts
|
|
539
533
|
var GEOMETRY_TYPES = /* @__PURE__ */ new Set([
|
|
540
534
|
"Point",
|
|
541
535
|
"MultiPoint",
|
|
@@ -566,7 +560,7 @@ function stringifyGeojsonGeometry(geometry) {
|
|
|
566
560
|
return JSON.stringify(geometry);
|
|
567
561
|
}
|
|
568
562
|
|
|
569
|
-
// ../../packages/map/src/defaultMapStyle.ts
|
|
563
|
+
// ../../packages/map/src/utils/defaultMapStyle.ts
|
|
570
564
|
var defaultMapStyle = {
|
|
571
565
|
version: 8,
|
|
572
566
|
sources: {
|
|
@@ -824,33 +818,19 @@ function CoordinateLocationModal({
|
|
|
824
818
|
] })
|
|
825
819
|
] });
|
|
826
820
|
}
|
|
827
|
-
var labelStyle = {
|
|
828
|
-
margin: 0,
|
|
829
|
-
fontSize: 11,
|
|
830
|
-
fontWeight: 600,
|
|
831
|
-
textTransform: "uppercase",
|
|
832
|
-
letterSpacing: 0.4,
|
|
833
|
-
color: ui.colors.grey700
|
|
834
|
-
};
|
|
835
|
-
var valueStyle = {
|
|
836
|
-
margin: 0,
|
|
837
|
-
fontSize: 14,
|
|
838
|
-
fontWeight: 500,
|
|
839
|
-
fontVariantNumeric: "tabular-nums"
|
|
840
|
-
};
|
|
841
821
|
function CoordinateSummary({ value }) {
|
|
842
822
|
const parsed = parseCoordinateValue(value);
|
|
843
823
|
if (!parsed) {
|
|
844
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
824
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "d2-field-muted", children: "No location set" });
|
|
845
825
|
}
|
|
846
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("dl", {
|
|
847
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
848
|
-
/* @__PURE__ */ jsxRuntime.jsx("dt", {
|
|
849
|
-
/* @__PURE__ */ jsxRuntime.jsx("dd", {
|
|
826
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "d2-coordinate-summary", children: [
|
|
827
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "d2-coordinate-axis", children: [
|
|
828
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "d2-coordinate-label", children: "Lat" }),
|
|
829
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { className: "d2-coordinate-value", children: parsed.lat.toFixed(5) })
|
|
850
830
|
] }),
|
|
851
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
852
|
-
/* @__PURE__ */ jsxRuntime.jsx("dt", {
|
|
853
|
-
/* @__PURE__ */ jsxRuntime.jsx("dd", {
|
|
831
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "d2-coordinate-axis", children: [
|
|
832
|
+
/* @__PURE__ */ jsxRuntime.jsx("dt", { className: "d2-coordinate-label", children: "Lng" }),
|
|
833
|
+
/* @__PURE__ */ jsxRuntime.jsx("dd", { className: "d2-coordinate-value", children: parsed.lng.toFixed(5) })
|
|
854
834
|
] })
|
|
855
835
|
] });
|
|
856
836
|
}
|
|
@@ -870,7 +850,7 @@ function D2CoordinateField({ control }) {
|
|
|
870
850
|
disabled: isDisabled,
|
|
871
851
|
validationText,
|
|
872
852
|
children: [
|
|
873
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
853
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "d2-field-row", children: [
|
|
874
854
|
/* @__PURE__ */ jsxRuntime.jsx(CoordinateSummary, { value }),
|
|
875
855
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
876
856
|
ui.Button,
|
|
@@ -1006,16 +986,16 @@ function countPositions(geometry) {
|
|
|
1006
986
|
function GeometrySummary({ value }) {
|
|
1007
987
|
const geometry = parseGeojsonGeometry(value);
|
|
1008
988
|
if (!geometry) {
|
|
1009
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
989
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "d2-field-muted", children: "No geometry set" });
|
|
1010
990
|
}
|
|
1011
991
|
if (geometry.type === "Point") {
|
|
1012
992
|
return /* @__PURE__ */ jsxRuntime.jsx(ui.Chip, { dense: true, children: geometry.type });
|
|
1013
993
|
}
|
|
1014
994
|
const count = geometry.type === "GeometryCollection" ? geometry.geometries.length : countPositions(geometry);
|
|
1015
995
|
const noun = geometry.type === "GeometryCollection" ? count === 1 ? "geometry" : "geometries" : "points";
|
|
1016
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
996
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "d2-geojson-summary", children: [
|
|
1017
997
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Chip, { dense: true, children: geometry.type }),
|
|
1018
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", {
|
|
998
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "d2-geojson-meta", children: [
|
|
1019
999
|
count,
|
|
1020
1000
|
" ",
|
|
1021
1001
|
noun
|
|
@@ -1038,7 +1018,7 @@ function D2GeoJsonField({ control }) {
|
|
|
1038
1018
|
disabled: isDisabled,
|
|
1039
1019
|
validationText,
|
|
1040
1020
|
children: [
|
|
1041
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1021
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "d2-field-row", children: [
|
|
1042
1022
|
/* @__PURE__ */ jsxRuntime.jsx(GeometrySummary, { value }),
|
|
1043
1023
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1044
1024
|
ui.Button,
|
|
@@ -1138,8 +1118,8 @@ function FeedbackPanel({ title, items }) {
|
|
|
1138
1118
|
if (!items.length) {
|
|
1139
1119
|
return null;
|
|
1140
1120
|
}
|
|
1141
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
1142
|
-
/* @__PURE__ */ jsxRuntime.jsx("h3", {
|
|
1121
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "d2-feedback-panel", children: [
|
|
1122
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "d2-feedback-panel-title", children: title }),
|
|
1143
1123
|
items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(ui.NoticeBox, { title: item.content, children: item.value ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1144
1124
|
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: item.content }),
|
|
1145
1125
|
": ",
|