@liftitapp/wa-conversations 0.12.0 → 0.14.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.
@@ -994,7 +994,7 @@ function templateOffer(input) {
994
994
  /**
995
995
  * ¿Los parámetros que tipeó el operador pasan las reglas del contrato? Es la misma validación que
996
996
  * hace el store (422 `invalid_template_params`) y se repite acá sólo para no habilitar «Enviar
997
- * plantilla» con algo que va a volver rechazado. El store sigue siendo quien decide.
997
+ * mensaje» con algo que va a volver rechazado. El store sigue siendo quien decide.
998
998
  */
999
999
  function templateParamsValid(params, expectedCount) {
1000
1000
  if (params.length !== expectedCount) return false;
@@ -1005,6 +1005,45 @@ function templateParamsValid(params, expectedCount) {
1005
1005
  return !/ {5,}/.test(value);
1006
1006
  });
1007
1007
  }
1008
+ /** El primer nombre del contacto: «Nelson Chaves» ⇒ «Nelson». Sin nombre, `''`. */
1009
+ function firstName$1(name) {
1010
+ return (typeof name === "string" ? name.trim().split(/\s+/)[0] : "") ?? "";
1011
+ }
1012
+ /**
1013
+ * Qué parámetros pone el host y cuáles tiene que escribir el operador (DEV-8832, D-2).
1014
+ *
1015
+ * El host sólo conoce el parámetro 1: el primer nombre del contacto. Si lo tiene, no se pide —
1016
+ * pedirle al operador algo que ya está en pantalla es el formulario técnico que este issue saca—.
1017
+ * Si el nombre es nulo o está en blanco, el 1 se pide; los parámetros 2..n se piden siempre.
1018
+ *
1019
+ * 🔴 Es la ÚNICA fuente de esta decisión: el panel no la repite, sólo pinta un input por índice de
1020
+ * `asked`.
1021
+ */
1022
+ function hostTemplateParams(count, contactName) {
1023
+ const known = firstName$1(contactName);
1024
+ const values = [];
1025
+ const asked = [];
1026
+ for (let index = 0; index < count; index += 1) if (index === 0 && known !== "") values.push(known);
1027
+ else {
1028
+ values.push("");
1029
+ asked.push(index);
1030
+ }
1031
+ return {
1032
+ values,
1033
+ asked
1034
+ };
1035
+ }
1036
+ /**
1037
+ * ¿Se puede enviar esta plantilla con estos parámetros? (DEV-8832, D-4).
1038
+ *
1039
+ * Sin el texto aprobado (Meta no lo devolvió para ese número) el operador no sabría qué manda, y
1040
+ * cada plantilla se cobra: nunca a ciegas. Con texto, mandan las reglas del contrato
1041
+ * (`templateParamsValid`).
1042
+ */
1043
+ function canSendTemplate(template, params) {
1044
+ if (template === null || template.body_text === null) return false;
1045
+ return templateParamsValid(params, template.body_param_count);
1046
+ }
1008
1047
  /**
1009
1048
  * La vista previa: el `body_text` aprobado con cada `{{n}}` reemplazado por su parámetro. Un
1010
1049
  * parámetro vacío deja el `{{n}}` a la vista, para que se note qué falta. Sin `body_text`, `null`.
@@ -1942,15 +1981,27 @@ function documentTypeOptions(types, query) {
1942
1981
  };
1943
1982
  }
1944
1983
  /**
1984
+ * DEV-9645: `true` si el tipo restringe por `scopeIds` (array) y el destino trae un `id` string no
1985
+ * vacío incluido en la lista — comparación exacta. Sin `scopeIds` no filtra por `id`. Un destino
1986
+ * sin `id` nunca coincide: falla cerrado (T-9645-01).
1987
+ */
1988
+ function matchesScopeIds(type, scope) {
1989
+ if (!Array.isArray(type.scopeIds)) return true;
1990
+ const id = scope.id;
1991
+ if (typeof id !== "string" || id === "") return false;
1992
+ return type.scopeIds.includes(id);
1993
+ }
1994
+ /**
1945
1995
  * El tipo define el alcance (D-4): las opciones son los alcances VÁLIDOS del host (se descartan
1946
- * los que no traen el dato que su `kind` exige); habilitadas sólo las que el tipo admite;
1947
- * seleccionada la actual si sigue permitida, si no la primera permitida en el orden del host. Con
1948
- * `type` null no se selecciona nada — no hay de qué derivar el alcance.
1996
+ * los que no traen el dato que su `kind` exige); habilitadas sólo las que el tipo admite por clase
1997
+ * y, si trae `scopeIds`, además por `id` (DEV-9645); seleccionada la actual si sigue permitida, si
1998
+ * no la primera permitida en el orden del host. Con `type` null no se selecciona nada — no hay de
1999
+ * qué derivar el alcance.
1949
2000
  */
1950
2001
  function resolveScope(type, scopes, current) {
1951
2002
  const options = (Array.isArray(scopes) ? scopes.filter(isValidScope) : []).map((scope) => ({
1952
2003
  scope,
1953
- allowed: type !== null && type.scopes.includes(scope.kind)
2004
+ allowed: type !== null && type.scopes.includes(scope.kind) && matchesScopeIds(type, scope)
1954
2005
  }));
1955
2006
  if (type === null) return {
1956
2007
  options,
@@ -1968,6 +2019,15 @@ function resolveScope(type, scopes, current) {
1968
2019
  };
1969
2020
  }
1970
2021
  /**
2022
+ * DEV-9645 (DC-4): el modal pinta «De quién es» como lista de destinos (tablero 553) si algún tipo
2023
+ * válido trae `scopeIds` como array o alguna persona válida trae un `role` no vacío. Si no, es el
2024
+ * input de hoy y se pinta el modal del tablero 196, sin cambios (C-7).
2025
+ */
2026
+ function usesTargetList(types, scopes) {
2027
+ if (Array.isArray(types) && types.some((type) => isValidType(type) && Array.isArray(type.scopeIds))) return true;
2028
+ return Array.isArray(scopes) && scopes.some((scope) => isValidScope(scope) && scope.kind === "person" && typeof scope.role === "string" && scope.role.trim() !== "");
2029
+ }
2030
+ /**
1971
2031
  * La marca de la burbuja (D-6): sólo lee `saved[messageId]` — el visor no AFIRMA el guardado, lo
1972
2032
  * LEE (mismo principio que la barra de takeover, DEV-5190). Un `messageId` ausente o una entrada
1973
2033
  * sin `typeName` útil no pinta marca: es mejor no mostrar nada que inventar un «Guardado como».
@@ -2923,6 +2983,11 @@ function MessageBubble({ message, optimistic = false, fetcher, savedDocument = n
2923
2983
  * `code`; radios de alcance con `data-scope-kind`; envío `.wa-thread__save-submit`; error
2924
2984
  * `[role="alert"]`.
2925
2985
  *
2986
+ * DEV-9645 (tablero 553): cuando `usesTargetList` da true, «De quién es» es una lista de destinos
2987
+ * `.wa-thread__save-targets`; cada fila es `.wa-thread__save-target` (con `data-selected` en la
2988
+ * elegida y `data-disabled` en las que el tipo no admite) y lleva su nota corta en
2989
+ * `.wa-thread__save-target-note`. El `id` del destino es opaco y NUNCA se pinta en el DOM.
2990
+ *
2926
2991
  * 🔴 Todo texto que origina el host o el lifter (nombres de tipo, `detail`, placa, nombre,
2927
2992
  * `file_name`, el mensaje de error) entra como hijo de texto, que React escapa — nunca
2928
2993
  * `dangerouslySetInnerHTML` (T-no6-04).
@@ -2951,6 +3016,42 @@ function sentWhenLabel(at) {
2951
3016
  const day = key === dayKey((/* @__PURE__ */ new Date()).toISOString()) ? "hoy" : dayLabel(at);
2952
3017
  return hour !== null ? `${day} ${hour}` : day;
2953
3018
  }
3019
+ /**
3020
+ * La nota corta de una fila de la lista de destinos (DEV-9645, DC-2). Sin tipo no hay nota; la
3021
+ * elegida dice «Se guarda aquí»; una habilitada sin elegir no lleva nota; una deshabilitada dice
3022
+ * por qué: la clase no coincide, o coincide pero el destino queda fuera de `scopeIds`.
3023
+ */
3024
+ function targetNote(type, target, allowed, selected) {
3025
+ if (type === null) return null;
3026
+ if (selected) return "Se guarda aquí";
3027
+ if (allowed) return null;
3028
+ return type.scopes.includes(target.kind) ? "No tiene este documento" : "No aplica a este tipo";
3029
+ }
3030
+ /** El rol de una persona tal cual lo escribió el host (DC-1), o null si no trae uno útil. */
3031
+ function targetRole(target) {
3032
+ if (target.kind !== "person") return null;
3033
+ return typeof target.role === "string" && target.role.trim() !== "" ? target.role : null;
3034
+ }
3035
+ /** Cómo nombra el copy a un destino (DEV-9645): «‹nombre› (‹rol›)», el nombre a secas o el vehículo. */
3036
+ function targetLabel(target) {
3037
+ if (target.kind === "vehicle") return `el vehículo ${target.plate}`;
3038
+ const role = targetRole(target);
3039
+ return role !== null ? `${target.name} (${role})` : target.name;
3040
+ }
3041
+ /**
3042
+ * El hint bajo la lista de destinos (DEV-9645), generado de los datos: a cuántos destinos aplica el
3043
+ * tipo y, si hay filas deshabilitadas junto a alguna permitida, por qué se ven así.
3044
+ */
3045
+ function targetListHint(type, options) {
3046
+ const allowed = options.filter((option) => option.allowed);
3047
+ if (allowed.length === 0) return `Ningún destino de este caso tiene ${type.name}: elige otro tipo.`;
3048
+ const lead = allowed.length === 1 ? `El tipo define a quién se guarda: ${type.name} solo aplica a ${targetLabel(allowed[0].scope)}.` : `El tipo define a quién se guarda: ${type.name} aplica a ${allowed.length} destinos, elige uno.`;
3049
+ return allowed.length < options.length ? `${lead} Quien no tiene ese documento aparece deshabilitado.` : lead;
3050
+ }
3051
+ /** La primera frase del aviso en modo lista (DEV-9645): nombra el expediente del destino elegido. */
3052
+ function targetNoticeLead(target) {
3053
+ return `Se guarda en el expediente ${target.kind === "vehicle" ? `del vehículo ${target.plate}` : `de ${targetLabel(target)}`} como carga manual, sin OCR, y queda pendiente de decisión.`;
3054
+ }
2954
3055
  function DocumentGlyph() {
2955
3056
  return /* @__PURE__ */ jsxs("svg", {
2956
3057
  width: 20,
@@ -3088,6 +3189,7 @@ function SaveDocumentDialog({ message, phone, input, onClose }) {
3088
3189
  const showCatalog = search.trim() !== "" || requested.length === 0;
3089
3190
  const { options: scopeOptions, selected: resolvedScope } = resolveScope(type, input.scopes, scope);
3090
3191
  const allowedScopeCount = scopeOptions.filter((option) => option.allowed).length;
3192
+ const targetList = usesTargetList(input.types, input.scopes);
3091
3193
  const handleTypeChange = (next) => {
3092
3194
  setType(next);
3093
3195
  };
@@ -3118,6 +3220,7 @@ function SaveDocumentDialog({ message, phone, input, onClose }) {
3118
3220
  onClose();
3119
3221
  };
3120
3222
  const sentWhen = sentWhenLabel(message.at);
3223
+ const noticeLead = targetList && resolvedScope !== null ? targetNoticeLead(resolvedScope) : "Se guarda en el expediente como carga manual, sin OCR, y queda pendiente de decisión.";
3121
3224
  return /* @__PURE__ */ jsx("div", {
3122
3225
  className: "wa-thread__save-overlay",
3123
3226
  onClick: handleOverlayClick,
@@ -3232,39 +3335,76 @@ function SaveDocumentDialog({ message, phone, input, onClose }) {
3232
3335
  }),
3233
3336
  /* @__PURE__ */ jsxs("fieldset", {
3234
3337
  className: "wa-thread__save-scopes",
3235
- children: [
3236
- /* @__PURE__ */ jsx("legend", { children: "De quién es" }),
3237
- scopeOptions.map(({ scope: scopeOption, allowed }, index) => /* @__PURE__ */ jsxs("label", {
3238
- className: "wa-thread__save-scope-option",
3239
- "data-selected": resolvedScope === scopeOption || void 0,
3240
- children: [
3241
- /* @__PURE__ */ jsx("input", {
3242
- type: "radio",
3243
- name: "wa-save-document-scope",
3244
- "data-scope-kind": scopeOption.kind,
3245
- checked: resolvedScope === scopeOption,
3246
- disabled: !allowed || submitting,
3247
- onChange: () => setScope(scopeOption)
3248
- }),
3249
- /* @__PURE__ */ jsx("span", {
3250
- "aria-hidden": "true",
3251
- children: scopeOption.kind === "vehicle" ? /* @__PURE__ */ jsx(VehicleGlyph, {}) : /* @__PURE__ */ jsx(PersonGlyph, {})
3252
- }),
3253
- scopeOption.kind === "vehicle" ? `Vehículo · ${scopeOption.plate}` : `Persona · ${scopeOption.name}`
3254
- ]
3255
- }, index)),
3256
- type !== null && /* @__PURE__ */ jsx("p", {
3257
- className: "wa-thread__save-scope-explain",
3258
- children: allowedScopeCount <= 1 ? `El tipo define el alcance: ${type.name} es ${resolvedScope?.kind === "person" ? "de la persona" : "del vehículo"}. Solo se puede cambiar en los tipos que admiten los dos.` : `${type.name} admite los dos alcances — elige de quién es este documento.`
3338
+ children: [/* @__PURE__ */ jsx("legend", { children: "De quién es" }), targetList ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
3339
+ className: "wa-thread__save-targets",
3340
+ children: scopeOptions.map(({ scope: target, allowed }, index) => {
3341
+ const selected = resolvedScope === target;
3342
+ const role = targetRole(target);
3343
+ const note = targetNote(type, target, allowed, selected);
3344
+ return /* @__PURE__ */ jsxs("label", {
3345
+ className: "wa-thread__save-scope-option wa-thread__save-target",
3346
+ "data-selected": selected || void 0,
3347
+ "data-disabled": !allowed || void 0,
3348
+ children: [
3349
+ /* @__PURE__ */ jsx("input", {
3350
+ type: "radio",
3351
+ name: "wa-save-document-scope",
3352
+ "data-scope-kind": target.kind,
3353
+ checked: selected,
3354
+ disabled: !allowed || submitting,
3355
+ onChange: () => setScope(target)
3356
+ }),
3357
+ /* @__PURE__ */ jsx("span", {
3358
+ "aria-hidden": "true",
3359
+ children: target.kind === "vehicle" ? /* @__PURE__ */ jsx(VehicleGlyph, {}) : /* @__PURE__ */ jsx(PersonGlyph, {})
3360
+ }),
3361
+ /* @__PURE__ */ jsx("span", {
3362
+ className: "wa-thread__save-target-name",
3363
+ children: target.kind === "vehicle" ? `Vehículo · ${target.plate}` : target.name
3364
+ }),
3365
+ role !== null && /* @__PURE__ */ jsx("span", {
3366
+ className: "wa-thread__save-target-role",
3367
+ children: role
3368
+ }),
3369
+ note !== null && /* @__PURE__ */ jsx("span", {
3370
+ className: "wa-thread__save-target-note",
3371
+ children: note
3372
+ })
3373
+ ]
3374
+ }, index);
3259
3375
  })
3260
- ]
3376
+ }), type !== null && /* @__PURE__ */ jsx("p", {
3377
+ className: "wa-thread__save-scope-explain",
3378
+ children: targetListHint(type, scopeOptions)
3379
+ })] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [scopeOptions.map(({ scope: scopeOption, allowed }, index) => /* @__PURE__ */ jsxs("label", {
3380
+ className: "wa-thread__save-scope-option",
3381
+ "data-selected": resolvedScope === scopeOption || void 0,
3382
+ children: [
3383
+ /* @__PURE__ */ jsx("input", {
3384
+ type: "radio",
3385
+ name: "wa-save-document-scope",
3386
+ "data-scope-kind": scopeOption.kind,
3387
+ checked: resolvedScope === scopeOption,
3388
+ disabled: !allowed || submitting,
3389
+ onChange: () => setScope(scopeOption)
3390
+ }),
3391
+ /* @__PURE__ */ jsx("span", {
3392
+ "aria-hidden": "true",
3393
+ children: scopeOption.kind === "vehicle" ? /* @__PURE__ */ jsx(VehicleGlyph, {}) : /* @__PURE__ */ jsx(PersonGlyph, {})
3394
+ }),
3395
+ scopeOption.kind === "vehicle" ? `Vehículo · ${scopeOption.plate}` : `Persona · ${scopeOption.name}`
3396
+ ]
3397
+ }, index)), type !== null && /* @__PURE__ */ jsx("p", {
3398
+ className: "wa-thread__save-scope-explain",
3399
+ children: allowedScopeCount <= 1 ? `El tipo define el alcance: ${type.name} es ${resolvedScope?.kind === "person" ? "de la persona" : "del vehículo"}. Solo se puede cambiar en los tipos que admiten los dos.` : `${type.name} admite los dos alcances — elige de quién es este documento.`
3400
+ })] })]
3261
3401
  }),
3262
3402
  /* @__PURE__ */ jsxs("div", {
3263
3403
  className: "wa-thread__save-notice",
3264
3404
  children: [/* @__PURE__ */ jsx("span", {
3265
3405
  "aria-hidden": "true",
3266
3406
  children: /* @__PURE__ */ jsx(InfoGlyph, {})
3267
- }), /* @__PURE__ */ jsxs("span", { children: ["Se guarda en el expediente como carga manual, sin OCR, y queda pendiente de decisión.", type !== null && (type.requested === true ? ` Cumple la solicitud abierta de ${type.name} y queda a tu nombre.` : " Queda a tu nombre.")] })]
3407
+ }), /* @__PURE__ */ jsxs("span", { children: [noticeLead, type !== null && (type.requested === true ? ` Cumple la solicitud abierta de ${type.name} y queda a tu nombre.` : " Queda a tu nombre.")] })]
3268
3408
  }),
3269
3409
  error !== null && /* @__PURE__ */ jsx("p", {
3270
3410
  role: "alert",
@@ -4099,7 +4239,9 @@ const THREAD_CSS = `
4099
4239
  }
4100
4240
 
4101
4241
  /* DEV-8758 — «Iniciar con plantilla» (tableros 391/392): con la ventana cerrada o sin hilo, el
4102
- composer es un formulario de plantilla. Mismo fondo y bordes que el composer de texto. */
4242
+ composer es un formulario de plantilla. Mismo fondo y bordes que el composer de texto.
4243
+ DEV-8832 (tablero 393) cambió el selector por chips de acción y agregó la vista previa con su
4244
+ rótulo y su nota. */
4103
4245
  .wa-composer--template {
4104
4246
  gap: 10px;
4105
4247
  }
@@ -4162,7 +4304,41 @@ const THREAD_CSS = `
4162
4304
  font-weight: 600;
4163
4305
  color: #616e7c;
4164
4306
  }
4165
- .wa-template__select,
4307
+ .wa-template__chips {
4308
+ display: flex;
4309
+ flex-wrap: wrap;
4310
+ gap: 6px;
4311
+ }
4312
+ .wa-template__chip {
4313
+ display: inline-flex;
4314
+ align-items: center;
4315
+ gap: 4px;
4316
+ padding: 4px 12px;
4317
+ border: 1px solid #E4E7EE;
4318
+ border-radius: 999px;
4319
+ font: inherit;
4320
+ font-size: 12px;
4321
+ color: #52606d;
4322
+ background: #ffffff;
4323
+ cursor: pointer;
4324
+ }
4325
+ /* El resaltado cuelga del MISMO atributo que lo anuncia al lector de pantalla: no puede verse
4326
+ elegido un chip que el lector anuncia como no elegido, ni al revés. */
4327
+ .wa-template__chip[aria-pressed='true'] {
4328
+ border-color: #4F5AED;
4329
+ font-weight: 600;
4330
+ color: #4F5AED;
4331
+ background: #EEF1FE;
4332
+ }
4333
+ .wa-template__chip:disabled {
4334
+ cursor: default;
4335
+ opacity: 0.6;
4336
+ }
4337
+ .wa-template__chip-check {
4338
+ width: 12px;
4339
+ height: 12px;
4340
+ flex: none;
4341
+ }
4166
4342
  .wa-template__input {
4167
4343
  padding: 7px 10px;
4168
4344
  border: 1px solid #E4E7EE;
@@ -4172,7 +4348,6 @@ const THREAD_CSS = `
4172
4348
  color: #2D3340;
4173
4349
  background: #F4F5F7;
4174
4350
  }
4175
- .wa-template__select:focus,
4176
4351
  .wa-template__input:focus {
4177
4352
  border-color: #4F5AED;
4178
4353
  outline: 2px solid rgba(79, 90, 237, 0.25);
@@ -4186,12 +4361,17 @@ const THREAD_CSS = `
4186
4361
  border-radius: 12px 12px 4px 12px;
4187
4362
  background: #EEF1FE;
4188
4363
  }
4189
- .wa-template__preview-tag {
4190
- display: block;
4191
- margin-bottom: 4px;
4192
- font-size: 10.5px;
4364
+ .wa-template__preview-label {
4365
+ font-size: 11px;
4193
4366
  font-weight: 600;
4194
- color: #4F5AED;
4367
+ color: #616e7c;
4368
+ }
4369
+ /* Alineada con la burbuja, a la derecha. */
4370
+ .wa-template__preview-note {
4371
+ align-self: flex-end;
4372
+ margin: 0;
4373
+ font-size: 10.5px;
4374
+ color: #9AA1AE;
4195
4375
  }
4196
4376
  .wa-template__preview-body {
4197
4377
  margin: 0;
@@ -4707,6 +4887,86 @@ const THREAD_CSS = `
4707
4887
  background: #f5f7fa;
4708
4888
  cursor: default;
4709
4889
  }
4890
+
4891
+ /*
4892
+ * DEV-9645: lista de destinos (tablero 553). Solo aplica cuando el host manda \`scopeIds\` o
4893
+ * \`role\`; la base de cada fila es \`.wa-thread__save-scope-option\` y estos modificadores van
4894
+ * encadenados a ella para ganarle en especificidad a \`:has(input:disabled)\` de arriba.
4895
+ */
4896
+ .wa-thread__save-targets {
4897
+ display: flex;
4898
+ flex-direction: column;
4899
+ gap: 6px;
4900
+ }
4901
+ .wa-thread__save-target {
4902
+ position: relative;
4903
+ }
4904
+ /* La radio queda oculta a la vista pero accesible: el estado lo cuenta la fila. */
4905
+ .wa-thread__save-target input[type='radio'] {
4906
+ position: absolute;
4907
+ width: 1px;
4908
+ height: 1px;
4909
+ margin: -1px;
4910
+ padding: 0;
4911
+ overflow: hidden;
4912
+ clip: rect(0 0 0 0);
4913
+ white-space: nowrap;
4914
+ border: 0;
4915
+ }
4916
+ .wa-thread__save-scope-option.wa-thread__save-target:has(input:focus-visible) {
4917
+ outline: 2px solid #4E5BEF;
4918
+ outline-offset: 2px;
4919
+ }
4920
+ .wa-thread__save-target-name {
4921
+ min-width: 0;
4922
+ font-size: 13px;
4923
+ font-weight: 600;
4924
+ }
4925
+ .wa-thread__save-target-role {
4926
+ flex: 0 0 auto;
4927
+ padding: 2px 8px;
4928
+ border-radius: 999px;
4929
+ font-size: 10.5px;
4930
+ font-weight: 600;
4931
+ color: #6B7280;
4932
+ background: #EEF0F3;
4933
+ }
4934
+ .wa-thread__save-target-note {
4935
+ flex: 0 0 auto;
4936
+ margin-left: auto;
4937
+ font-size: 11px;
4938
+ color: #9AA1AE;
4939
+ }
4940
+ /* Elegida: borde de 2px con el padding compensado para que la fila no salte. */
4941
+ .wa-thread__save-scope-option.wa-thread__save-target[data-selected='true'] {
4942
+ padding: 9px 11px;
4943
+ border: 2px solid #4E5BEF;
4944
+ color: #2D3340;
4945
+ background: #EEF0FE;
4946
+ }
4947
+ .wa-thread__save-target[data-selected='true'] .wa-thread__save-target-role {
4948
+ color: #4E5BEF;
4949
+ background: #FFFFFF;
4950
+ }
4951
+ .wa-thread__save-target[data-selected='true'] .wa-thread__save-target-note {
4952
+ font-weight: 600;
4953
+ color: #3A44C7;
4954
+ }
4955
+ /* Deshabilitada: colores explícitos del tablero, sin la opacidad genérica de 0.55. */
4956
+ .wa-thread__save-scope-option.wa-thread__save-target[data-disabled='true'] {
4957
+ border: 1px solid #E3E6EB;
4958
+ color: #9AA1AE;
4959
+ background: #F8F9FB;
4960
+ cursor: default;
4961
+ opacity: 1;
4962
+ }
4963
+ .wa-thread__save-target[data-disabled='true'] svg {
4964
+ color: #B6BCC6;
4965
+ }
4966
+ .wa-thread__save-target[data-disabled='true'] .wa-thread__save-target-role {
4967
+ color: #9AA1AE;
4968
+ background: #EEF0F3;
4969
+ }
4710
4970
  `;
4711
4971
  //#endregion
4712
4972
  //#region src/core/thread/useComposer.ts
@@ -5150,35 +5410,47 @@ function useSuggestion({ fetcher, phone, messages, outgoing = [], onPrefill }) {
5150
5410
  * «Iniciar con plantilla» (DEV-8758) — el composer cuando WhatsApp sólo deja escribir con una
5151
5411
  * plantilla aprobada: ventana de 24 h cerrada (tablero 391) o sin hilo (tablero 392).
5152
5412
  *
5413
+ * DEV-8832 (tablero 393) rehízo el formulario para que el operador lo entienda: un chip por acción
5414
+ * en vez del selector técnico, sin pedir lo que el host ya sabe (el primer nombre) y con la vista
5415
+ * previa obligatoria de lo que le llega a la persona.
5416
+ *
5153
5417
  * Presentacional: qué modo se pinta lo decide `templateOffer` y la red vive en `useTemplateStart`.
5154
5418
  * Interno del hilo — NO sale al barrel (mismo criterio que `Composer`).
5155
5419
  *
5156
5420
  * 🔴 Todo lo que viene del store (`label`, `body_text`) y el nombre del contacto entran como hijos
5157
5421
  * de texto, que React escapa. Nada de `dangerouslySetInnerHTML`.
5158
5422
  */
5159
- /** El primer nombre para prellenar `{{1}}`: «Nelson Chaves» ⇒ «Nelson». */
5160
- function firstName$1(name) {
5161
- return (typeof name === "string" ? name.trim().split(/\s+/)[0] : "") ?? "";
5423
+ /** La clave estable de una plantilla: el mismo nombre puede existir en dos idiomas. */
5424
+ function templateKey(option) {
5425
+ return `${option.name}#${option.language}`;
5426
+ }
5427
+ /** La etiqueta de un parámetro que se pide, sin el marcador técnico (D-2). */
5428
+ function askedParamLabel(index) {
5429
+ return index === 0 ? "Nombre de la persona" : `Dato ${index + 1}`;
5162
5430
  }
5163
5431
  function TemplateStartPanel({ mode, start, noThread, phone, contactName, senderLabel }) {
5164
- const selectId = useId();
5432
+ const chipsLabelId = useId();
5165
5433
  const items = start.response?.items ?? [];
5166
- const [selected, setSelected] = useState(0);
5167
- /** Lo que tipeó el operador, por plantilla: cambiar de plantilla no mezcla parámetros. */
5434
+ /** La acción que tocó el operador (`templateKey`). Con una sola plantilla no hace falta tocar. */
5435
+ const [picked, setPicked] = useState(null);
5436
+ /** Lo que tipeó el operador, por plantilla: cambiar de acción no mezcla parámetros. */
5168
5437
  const [typed, setTyped] = useState({});
5169
5438
  if (mode === "none") return null;
5170
- const template = items[Math.min(selected, Math.max(items.length - 1, 0))] ?? null;
5171
- const templateKey = template !== null ? `${template.name}#${template.language}` : "";
5172
- const params = template === null ? [] : typed[templateKey] ?? Array.from({ length: template.body_param_count }, (_, index) => index === 0 ? firstName$1(contactName) : "");
5439
+ const template = items.length === 1 ? items[0] ?? null : items.find((item) => templateKey(item) === picked) ?? null;
5440
+ const key = template !== null ? templateKey(template) : "";
5441
+ const host = hostTemplateParams(template?.body_param_count ?? 0, contactName);
5442
+ const typedForTemplate = typed[key] ?? [];
5443
+ const params = host.values.map((value, index) => host.asked.includes(index) ? typedForTemplate[index] ?? "" : value);
5173
5444
  const sending = start.sendState === "sending";
5174
- const canSend = mode === "form" && template !== null && !sending && templateParamsValid(params, template.body_param_count);
5445
+ const canSend = mode === "form" && !sending && canSendTemplate(template, params);
5175
5446
  const preview = template !== null ? renderTemplatePreview(template.body_text, params) : null;
5447
+ const recipient = firstName$1(contactName);
5176
5448
  const setParam = (index, value) => {
5177
- const next = [...params];
5449
+ const next = [...typedForTemplate];
5178
5450
  next[index] = value;
5179
5451
  setTyped({
5180
5452
  ...typed,
5181
- [templateKey]: next
5453
+ [key]: next
5182
5454
  });
5183
5455
  };
5184
5456
  const submit = () => {
@@ -5244,57 +5516,87 @@ function TemplateStartPanel({ mode, start, noThread, phone, contactName, senderL
5244
5516
  className: "wa-template__note",
5245
5517
  children: "No hay plantillas habilitadas para este número."
5246
5518
  }),
5247
- mode === "form" && template !== null && /* @__PURE__ */ jsxs("form", {
5519
+ mode === "form" && /* @__PURE__ */ jsxs("form", {
5248
5520
  className: "wa-template__form",
5249
5521
  onSubmit: (event) => {
5250
5522
  event.preventDefault();
5251
5523
  submit();
5252
5524
  },
5253
5525
  children: [
5254
- /* @__PURE__ */ jsxs("label", {
5526
+ /* @__PURE__ */ jsxs("div", {
5255
5527
  className: "wa-template__field",
5256
- htmlFor: selectId,
5257
5528
  children: [/* @__PURE__ */ jsx("span", {
5258
5529
  className: "wa-template__label",
5259
- children: "Plantilla"
5260
- }), /* @__PURE__ */ jsx("select", {
5261
- id: selectId,
5262
- className: "wa-template__select",
5263
- value: selected,
5264
- disabled: sending,
5265
- onChange: (event) => setSelected(Number(event.target.value)),
5266
- children: items.map((item, index) => /* @__PURE__ */ jsx("option", {
5267
- value: index,
5268
- children: item.label ?? item.name
5269
- }, `${item.name}#${item.language}`))
5530
+ id: chipsLabelId,
5531
+ children: "¿Qué quieres hacer?"
5532
+ }), /* @__PURE__ */ jsx("div", {
5533
+ className: "wa-template__chips",
5534
+ role: "group",
5535
+ "aria-labelledby": chipsLabelId,
5536
+ children: items.map((item) => {
5537
+ const itemKey = templateKey(item);
5538
+ const pressed = template !== null && templateKey(template) === itemKey;
5539
+ return /* @__PURE__ */ jsxs("button", {
5540
+ type: "button",
5541
+ className: "wa-template__chip",
5542
+ "aria-pressed": pressed,
5543
+ disabled: sending,
5544
+ onClick: () => setPicked(itemKey),
5545
+ children: [pressed && /* @__PURE__ */ jsx("svg", {
5546
+ className: "wa-template__chip-check",
5547
+ viewBox: "0 0 16 16",
5548
+ "aria-hidden": "true",
5549
+ focusable: "false",
5550
+ children: /* @__PURE__ */ jsx("path", {
5551
+ d: "M3.5 8.5l3 3 6-7",
5552
+ fill: "none",
5553
+ stroke: "currentColor",
5554
+ strokeWidth: "2",
5555
+ strokeLinecap: "round",
5556
+ strokeLinejoin: "round"
5557
+ })
5558
+ }), item.label ?? item.name]
5559
+ }, itemKey);
5560
+ })
5270
5561
  })]
5271
5562
  }),
5272
- params.map((value, index) => /* @__PURE__ */ jsxs("label", {
5563
+ template !== null && template.body_text === null && /* @__PURE__ */ jsx("p", {
5564
+ className: "wa-template__note",
5565
+ role: "status",
5566
+ children: "Esta acción no está disponible en este número"
5567
+ }),
5568
+ template !== null && template.body_text !== null && host.asked.map((index) => /* @__PURE__ */ jsxs("label", {
5273
5569
  className: "wa-template__field",
5274
- children: [/* @__PURE__ */ jsxs("span", {
5570
+ children: [/* @__PURE__ */ jsx("span", {
5275
5571
  className: "wa-template__label",
5276
- children: [
5277
- index === 0 ? "Nombre del lifter" : "Parámetro",
5278
- " · ",
5279
- `{{${index + 1}}}`
5280
- ]
5572
+ children: askedParamLabel(index)
5281
5573
  }), /* @__PURE__ */ jsx("input", {
5282
5574
  className: "wa-template__input",
5283
- value,
5575
+ value: typedForTemplate[index] ?? "",
5284
5576
  maxLength: 1024,
5285
5577
  disabled: sending,
5286
5578
  onChange: (event) => setParam(index, event.target.value)
5287
5579
  })]
5288
5580
  }, index)),
5289
5581
  preview !== null && /* @__PURE__ */ jsxs("div", {
5290
- className: "wa-template__preview",
5291
- children: [/* @__PURE__ */ jsxs("span", {
5292
- className: "wa-template__preview-tag",
5293
- children: ["Plantilla · ", template.name]
5294
- }), /* @__PURE__ */ jsx("p", {
5295
- className: "wa-template__preview-body",
5296
- children: preview
5297
- })]
5582
+ className: "wa-template__field",
5583
+ children: [
5584
+ /* @__PURE__ */ jsx("span", {
5585
+ className: "wa-template__preview-label",
5586
+ children: recipient !== "" ? `Así le llega a ${recipient}` : "Así le llega"
5587
+ }),
5588
+ /* @__PURE__ */ jsx("div", {
5589
+ className: "wa-template__preview",
5590
+ children: /* @__PURE__ */ jsx("p", {
5591
+ className: "wa-template__preview-body",
5592
+ children: preview
5593
+ })
5594
+ }),
5595
+ /* @__PURE__ */ jsx("p", {
5596
+ className: "wa-template__preview-note",
5597
+ children: "Mensaje aprobado por WhatsApp"
5598
+ })
5599
+ ]
5298
5600
  }),
5299
5601
  start.sendState === "error" && start.failure !== null && /* @__PURE__ */ jsxs("div", {
5300
5602
  className: "wa-template__error",
@@ -5312,7 +5614,7 @@ function TemplateStartPanel({ mode, start, noThread, phone, contactName, senderL
5312
5614
  start.sendState === "sent" && /* @__PURE__ */ jsx("p", {
5313
5615
  className: "wa-template__sent",
5314
5616
  role: "status",
5315
- children: "Plantilla enviada. El bot quedó en pausa."
5617
+ children: "Mensaje enviado. El bot quedó en pausa."
5316
5618
  }),
5317
5619
  /* @__PURE__ */ jsxs("div", {
5318
5620
  className: "wa-template__footer",
@@ -5323,7 +5625,7 @@ function TemplateStartPanel({ mode, start, noThread, phone, contactName, senderL
5323
5625
  type: "submit",
5324
5626
  className: "wa-composer__send",
5325
5627
  disabled: !canSend,
5326
- children: sending ? "Enviando…" : "Enviar plantilla"
5628
+ children: sending ? "Enviando…" : "Enviar mensaje"
5327
5629
  })]
5328
5630
  })
5329
5631
  ]
@@ -6490,4 +6792,4 @@ const WA_CONVERSATIONS_TAG = "wa-conversations";
6490
6792
  */
6491
6793
  const SAVE_DOCUMENT_EVENT = "wa-conversations:save-document";
6492
6794
  //#endregion
6493
- export { ConversationList, ConversationThread, DEFAULT_REFRESH_INTERVAL_MS, NARROW_MAX_WIDTH, REPLY_TEXT_MAX_LENGTH, SAVE_DOCUMENT_EVENT, SUGGESTION_STATUS, WA_CONVERSATIONS_TAG, WaConversations, WaFetchError, dedupeByWamid, discardSuggestion, isCtaLink, isNoThreadError, isSuggestion, loadConversations, loadTemplates, loadThread, mergeThread, mergeThreadPage, newClientMessageId, normalizeReplyMessage, normalizeStartResponse, normalizeTemplates, normalizeWindowState, readSendError, releaseConversation, renderTemplatePreview, sendFailureCopy, sendReply, startConversation, templateOffer, templateParamsValid, threadCtas, useComposer, useContainerLayout, useConversations, useSuggestion, useThread };
6795
+ export { ConversationList, ConversationThread, DEFAULT_REFRESH_INTERVAL_MS, NARROW_MAX_WIDTH, REPLY_TEXT_MAX_LENGTH, SAVE_DOCUMENT_EVENT, SUGGESTION_STATUS, WA_CONVERSATIONS_TAG, WaConversations, WaFetchError, canSendTemplate, dedupeByWamid, discardSuggestion, hostTemplateParams, isCtaLink, isNoThreadError, isSuggestion, loadConversations, loadTemplates, loadThread, mergeThread, mergeThreadPage, newClientMessageId, normalizeReplyMessage, normalizeStartResponse, normalizeTemplates, normalizeWindowState, readSendError, releaseConversation, renderTemplatePreview, sendFailureCopy, sendReply, startConversation, templateOffer, templateParamsValid, threadCtas, useComposer, useContainerLayout, useConversations, useSuggestion, useThread };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liftitapp/wa-conversations",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Visor de conversaciones de WhatsApp del ecosistema Liftit: lista, hilo, media y composer.",
5
5
  "author": "Liftit",
6
6
  "license": "UNLICENSED",