@directo-ui/astro 1.1.0 → 1.2.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/README.md +2 -0
- package/components.css +337 -2
- package/package.json +11 -7
- package/src/components/WariClientDetails.astro +87 -0
- package/src/components/WariClientSearch.astro +88 -0
- package/src/components/WariPassengerField.astro +84 -0
- package/src/components/WariRoute.astro +49 -0
- package/src/components/WariStepper.astro +9 -4
- package/src/components/WariSwitchList.astro +86 -8
- package/src/components/WariTripAttributes.astro +1 -1
- package/src/wari/motion.d.ts +14 -0
- package/src/wari/motion.js +60 -0
- package/src/wari/route-client.d.ts +10 -0
- package/src/wari/route-client.js +270 -0
- package/src/wari/route.d.ts +48 -0
- package/src/wari/route.js +71 -0
- package/src/wari/trip-client.js +152 -4
- package/src/wari/trip.d.ts +51 -0
- package/src/wari/trip.js +64 -4
- package/wari.d.ts +8 -2
- package/wari.js +6 -1
package/src/wari/trip.js
CHANGED
|
@@ -9,9 +9,22 @@ export const wariServices = [
|
|
|
9
9
|
{ value: 'van', label: 'Van', passengers: 7, luggage: 6, luggageAlt: 10, hourlyPrice: 140 },
|
|
10
10
|
];
|
|
11
11
|
export const wariExtras = [
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
{
|
|
13
|
+
value: 'carseat', label: 'Carseat', maxQuantity: 2,
|
|
14
|
+
choices: [{ value: '0-2', label: '0-2 años' }, { value: '3-5', label: '3-5 años' }, { value: '6-10', label: '6-10 años' }],
|
|
15
|
+
note: 'Solicítalo con al menos 2 horas de anticipación a la hora programada.',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
value: 'booster', label: 'Booster', description: 'Para niños de 4 hasta 12 años', maxQuantity: 2,
|
|
19
|
+
note: 'Solicítalo con al menos 2 horas de anticipación a la hora programada.',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
value: 'carga', label: 'Carga',
|
|
23
|
+
fields: [
|
|
24
|
+
{ name: 'weight', label: 'Peso aproximado', placeholder: 'Peso aprox.', inputMode: 'decimal', width: '96px' },
|
|
25
|
+
{ name: 'value', label: 'Valor estimado en soles', placeholder: 'S/Valor est.', inputMode: 'decimal' },
|
|
26
|
+
],
|
|
27
|
+
},
|
|
15
28
|
];
|
|
16
29
|
export const wariPaymentMethods = [
|
|
17
30
|
{ value: 'efectivo', label: 'Efectivo' },
|
|
@@ -19,7 +32,7 @@ export const wariPaymentMethods = [
|
|
|
19
32
|
{ value: 'vale', label: 'Vale corporativo' },
|
|
20
33
|
];
|
|
21
34
|
export const defaultTripAttributes = {
|
|
22
|
-
service: 'lite', hourly: false, delivery: false, extras: [], vehicles: 1, payment: 'efectivo',
|
|
35
|
+
service: 'lite', hourly: false, delivery: false, extras: [], extraQuantities: {}, extraChoices: {}, extraFields: {}, vehicles: 1, payment: 'efectivo',
|
|
23
36
|
};
|
|
24
37
|
export const formatSoles = (amount) => `S/${Number.isInteger(amount) ? amount : amount.toFixed(2)}`;
|
|
25
38
|
/** Lo que muestra el diseño a la derecha de cada servicio, según "Por horas" y "Envíos". */
|
|
@@ -67,3 +80,50 @@ export function toggleExtra(extras, value, options = wariExtras) {
|
|
|
67
80
|
set.add(value);
|
|
68
81
|
return options.filter(option => set.has(option.value)).map(option => option.value);
|
|
69
82
|
}
|
|
83
|
+
/** Cantidades solo de los extras activos con `maxQuantity`; un extra recién activado empieza en 1. */
|
|
84
|
+
export function syncExtraQuantities(extras, quantities, options = wariExtras) {
|
|
85
|
+
const result = {};
|
|
86
|
+
for (const option of options) {
|
|
87
|
+
if (!option.maxQuantity || !extras.includes(option.value))
|
|
88
|
+
continue;
|
|
89
|
+
result[option.value] = clampCount(quantities[option.value] ?? 1, 1, option.maxQuantity);
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Opciones por unidad solo de los extras activos con `choices`: un extra recién activado empieza con una unidad
|
|
95
|
+
* (la primera opción), se descartan valores que ya no existen y nunca hay más de `maxQuantity` unidades.
|
|
96
|
+
*/
|
|
97
|
+
export function syncExtraChoices(extras, choices, options = wariExtras) {
|
|
98
|
+
const result = {};
|
|
99
|
+
for (const option of options) {
|
|
100
|
+
if (!option.choices?.length || !extras.includes(option.value))
|
|
101
|
+
continue;
|
|
102
|
+
const valid = (choices[option.value] ?? []).filter(value => option.choices.some(choice => choice.value === value));
|
|
103
|
+
const max = option.maxQuantity ?? 1;
|
|
104
|
+
result[option.value] = (valid.length ? valid : [option.choices[0].value]).slice(0, Math.max(1, max));
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
/** Texto de los campos solo de los extras activos con `fields`; un extra recién activado empieza con los campos vacíos. */
|
|
109
|
+
export function syncExtraFields(extras, fields, options = wariExtras) {
|
|
110
|
+
const result = {};
|
|
111
|
+
for (const option of options) {
|
|
112
|
+
if (!option.fields?.length || !extras.includes(option.value))
|
|
113
|
+
continue;
|
|
114
|
+
result[option.value] = Object.fromEntries(option.fields.map(field => [field.name, fields[option.value]?.[field.name] ?? '']));
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Cantidades, opciones y campos coherentes con los extras activos. La cantidad de un extra con `choices` es su número
|
|
120
|
+
* de unidades; los extras inactivos no guardan nada.
|
|
121
|
+
*/
|
|
122
|
+
export function syncExtras(extras, current = {}, options = wariExtras) {
|
|
123
|
+
const extraChoices = syncExtraChoices(extras, current.extraChoices ?? {}, options);
|
|
124
|
+
const extraQuantities = syncExtraQuantities(extras, current.extraQuantities ?? {}, options);
|
|
125
|
+
for (const [value, units] of Object.entries(extraChoices))
|
|
126
|
+
extraQuantities[value] = units.length;
|
|
127
|
+
const extraFields = syncExtraFields(extras, current.extraFields ?? {}, options);
|
|
128
|
+
return { extraQuantities, extraChoices, extraFields };
|
|
129
|
+
}
|
package/wari.d.ts
CHANGED
|
@@ -9,12 +9,18 @@ export { default as WariSwitchList } from './src/components/WariSwitchList.astro
|
|
|
9
9
|
export { default as WariStepper } from './src/components/WariStepper.astro';
|
|
10
10
|
export { default as WariServiceMeta } from './src/components/WariServiceMeta.astro';
|
|
11
11
|
export { default as WariTripAttributes } from './src/components/WariTripAttributes.astro';
|
|
12
|
+
export { default as WariClientSearch } from './src/components/WariClientSearch.astro';
|
|
13
|
+
export { default as WariClientDetails } from './src/components/WariClientDetails.astro';
|
|
14
|
+
export { default as WariRoute } from './src/components/WariRoute.astro';
|
|
15
|
+
export { default as WariPassengerField } from './src/components/WariPassengerField.astro';
|
|
12
16
|
export type { WariSelectOption } from './src/components/WariSelect.astro';
|
|
13
|
-
export { clampCount, defaultTripAttributes, formatSoles, serviceMeta, toggleExtra, typeaheadIndex, wariExtras, wariPaymentMethods, wariServices } from './src/wari/trip';
|
|
14
|
-
export type { WariService, WariOption, WariTripAttributesValue, ServiceMeta } from './src/wari/trip';
|
|
17
|
+
export { clampCount, defaultTripAttributes, formatSoles, serviceMeta, syncExtraChoices, syncExtraFields, syncExtraQuantities, syncExtras, toggleExtra, typeaheadIndex, wariExtras, wariPaymentMethods, wariServices } from './src/wari/trip';
|
|
18
|
+
export type { WariService, WariOption, WariExtraField, WariExtrasState, WariTripAttributesValue, ServiceMeta } from './src/wari/trip';
|
|
15
19
|
export { calendarWeeks, formatDisplayDate, formatDisplayTime, parseDisplayDate, parseDisplayTime, parseISODate, parseTime24, toISODate, todayISO } from './src/wari/datetime';
|
|
16
20
|
export type { CalendarDay, TimeParts, Period } from './src/wari/datetime';
|
|
17
21
|
export type { MultiSelectOption } from './src/components/MultiSelect.astro';
|
|
18
22
|
export { wariStatuses, wariStatusLabel } from './src/wari/statuses';
|
|
19
23
|
export type { WariStatus } from './src/wari/statuses';
|
|
20
24
|
export * from './src/wari/logic';
|
|
25
|
+
export { addStop, addToll, createStop, defaultRouteValue, emptyPassenger, invertRoute, moveStop, normalizeRoute, removeStop, removeToll, stopLabel, stopPlaceholder, tollsTotal, updateStop } from './src/wari/route';
|
|
26
|
+
export type { WariPassenger, WariRouteStop, WariRouteValue } from './src/wari/route';
|
package/wari.js
CHANGED
|
@@ -10,7 +10,12 @@ export { default as WariSwitchList } from './src/components/WariSwitchList.astro
|
|
|
10
10
|
export { default as WariStepper } from './src/components/WariStepper.astro';
|
|
11
11
|
export { default as WariServiceMeta } from './src/components/WariServiceMeta.astro';
|
|
12
12
|
export { default as WariTripAttributes } from './src/components/WariTripAttributes.astro';
|
|
13
|
-
export {
|
|
13
|
+
export { default as WariClientSearch } from './src/components/WariClientSearch.astro';
|
|
14
|
+
export { default as WariClientDetails } from './src/components/WariClientDetails.astro';
|
|
15
|
+
export { default as WariRoute } from './src/components/WariRoute.astro';
|
|
16
|
+
export { default as WariPassengerField } from './src/components/WariPassengerField.astro';
|
|
17
|
+
export { clampCount, defaultTripAttributes, formatSoles, serviceMeta, syncExtraChoices, syncExtraFields, syncExtraQuantities, syncExtras, toggleExtra, typeaheadIndex, wariExtras, wariPaymentMethods, wariServices } from './src/wari/trip.js';
|
|
14
18
|
export { calendarWeeks, formatDisplayDate, formatDisplayTime, parseDisplayDate, parseDisplayTime, parseISODate, parseTime24, toISODate, todayISO } from './src/wari/datetime.js';
|
|
15
19
|
export { wariStatuses, wariStatusLabel } from './src/wari/statuses.js';
|
|
16
20
|
export { filterOptions, normalizeSearch, selectionState, selectionSummary, toggleAll, toggleValue } from './src/wari/logic.js';
|
|
21
|
+
export { addStop, addToll, createStop, defaultRouteValue, emptyPassenger, invertRoute, moveStop, normalizeRoute, removeStop, removeToll, stopLabel, stopPlaceholder, tollsTotal, updateStop } from './src/wari/route.js';
|