@magicfeedback/popup-sdk 1.5.0 → 1.7.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/dist/index.mjs CHANGED
@@ -1,15 +1,24 @@
1
1
  import {
2
2
  InMemoryStorage,
3
+ LABELS,
4
+ RESOLVE_LOCALE_JS,
5
+ RTL_LOCALES,
3
6
  STORAGE_KEYS,
7
+ SUPPORTED_LANGUAGES,
4
8
  TrackingManager,
5
9
  buildFontFaceCss,
6
10
  buildFontFamilyValue,
7
11
  buildSurveyIdentity,
8
12
  createDefaultStorage,
13
+ directionFor,
14
+ getLabels,
15
+ isRtlLanguage,
16
+ resolveActionLabels,
17
+ resolveLocale,
9
18
  sdkWarn,
10
19
  setLogger,
11
20
  style_default
12
- } from "./chunk-JSBMP4MI.mjs";
21
+ } from "./chunk-W6MPSWMS.mjs";
13
22
 
14
23
  // src/types/index.ts
15
24
  var POPUP_TRIGGER_CONDITION_STATUSES = [
@@ -212,9 +221,13 @@ var POSITION_MAP = {
212
221
  function jsonForScript(value) {
213
222
  return JSON.stringify(value ?? null).replace(/</g, "\\u003C").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
214
223
  }
224
+ function trimmedOrNull(value) {
225
+ const trimmed = typeof value === "string" ? value.trim() : "";
226
+ return trimmed ? value : null;
227
+ }
215
228
  function buildSurveyHtml(opts) {
216
229
  const env = opts.env === "development" ? "dev" : "prod";
217
- const version = opts.version ?? "2.2.4";
230
+ const version = opts.version ?? "2.2.22";
218
231
  const cdn = `https://cdn.jsdelivr.net/npm/@magicfeedback/native@${version}/dist/magicfeedback-sdk.browser.js`;
219
232
  const sid = jsonForScript(opts.surveyId);
220
233
  const pid = jsonForScript(opts.productId);
@@ -246,10 +259,22 @@ function buildSurveyHtml(opts) {
246
259
  const titleJson = jsonForScript(opts.title ?? "");
247
260
  const customCss = (opts.surveyCss ?? "").replace(/<\/\s*style/gi, "<\\/style");
248
261
  const progressPref = opts.showProgressBar === void 0 ? "null" : String(opts.showProgressBar);
249
- const backLabel = jsonForScript(opts.actions?.back?.label ?? "Back");
250
- const startLabel = jsonForScript(opts.actions?.start?.label ?? "Start survey");
251
- const completeLabel = jsonForScript(opts.actions?.complete?.label ?? "Complete survey");
252
- const submitLabel = jsonForScript(opts.actions?.accept?.label ?? "Send");
262
+ const initLabels = getLabels(opts.language);
263
+ const initActionLabels = resolveActionLabels(opts.actions, opts.language);
264
+ const backLabel = jsonForScript(initActionLabels.back);
265
+ const startLabel = jsonForScript(initActionLabels.start);
266
+ const completeLabel = jsonForScript(initActionLabels.complete);
267
+ const submitLabel = jsonForScript(initActionLabels.accept);
268
+ const labelsTableJson = jsonForScript(LABELS);
269
+ const actionOverridesJson = jsonForScript({
270
+ accept: trimmedOrNull(opts.actions?.accept?.label),
271
+ start: trimmedOrNull(opts.actions?.start?.label),
272
+ complete: trimmedOrNull(opts.actions?.complete?.label),
273
+ back: trimmedOrNull(opts.actions?.back?.label)
274
+ });
275
+ const initLangJson = jsonForScript(opts.language ?? "");
276
+ const initDirection = directionFor(opts.language);
277
+ const rtlLocalesJson = jsonForScript(RTL_LOCALES);
253
278
  return `<!DOCTYPE html><html><head>
254
279
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
255
280
  <meta name="color-scheme" content="${colorScheme}"/>
@@ -262,8 +287,8 @@ body{display:${bodyDisplay};justify-content:${pos.justifyContent};align-items:${
262
287
  .deepdots-popup-header{display:flex;justify-content:space-between;align-items:center;gap:12px;width:100%;flex:0 0 auto}
263
288
  /* Neutraliza la regla \`.deepdots-popup h2\` del CSS del survey (uppercase, centrado y
264
289
  margin-bottom 40px), pensada para los enunciados y no para el t\xEDtulo de la cabecera. */
265
- #dd-title{margin:0;font-family:var(--deepdots-font,'Montserrat',inherit);font-size:17px;font-weight:600;line-height:1.3;color:${textPrimary};text-transform:none;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
266
- #dd-close{background:transparent;border:none;width:32px;height:32px;display:flex;align-items:center;justify-content:center;border-radius:8px;cursor:pointer;color:${textPrimary};padding:4px;flex:0 0 auto;margin-left:auto}
290
+ #dd-title{margin:0;font-family:var(--deepdots-font,'Montserrat',inherit);font-size:17px;font-weight:600;line-height:1.3;color:${textPrimary};text-transform:none;text-align:start;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
291
+ #dd-close{background:transparent;border:none;width:32px;height:32px;display:flex;align-items:center;justify-content:center;border-radius:8px;cursor:pointer;color:${textPrimary};padding:4px;flex:0 0 auto;margin-inline-start:auto}
267
292
  /* Progreso alineado con la cabecera: sin padding horizontal propio, lo marca la tarjeta.
268
293
  El vertical es el mismo arriba y abajo, y del mismo valor que el padding de la tarjeta. */
269
294
  .deepdots-progress{display:none;flex-direction:column;gap:8px;width:100%;flex:0 0 auto;padding:16px 0;box-sizing:border-box}
@@ -291,7 +316,7 @@ body{display:${bodyDisplay};justify-content:${pos.justifyContent};align-items:${
291
316
  #dd-form-wrapper{width:100%;flex:1 1 auto}
292
317
  #mf{width:100%;box-sizing:border-box;visibility:hidden}
293
318
  .deepdots-popup-main *{max-width:100%;box-sizing:border-box}
294
- #dd-logo{max-height:40px;max-width:100%;object-fit:contain}
319
+ #dd-logo{max-height:40px;max-width:100%;object-fit:contain;display:block;margin:12px 0 0 0}
295
320
  .deepdots-error-hint{display:none;margin:12px 0 0 0;padding:10px 12px;border-radius:6px;background:#FEF3C7;color:#92400E;border:1px solid #FCD34D;font-size:13px}
296
321
  /* Pantalla final: el HTML del editor de la plataforma (imagen + texto), centrado. */
297
322
  .deepdots-success{display:none;width:100%;text-align:center;padding:24px 0;color:${textPrimary}}
@@ -320,35 +345,35 @@ body{display:${bodyDisplay};justify-content:${pos.justifyContent};align-items:${
320
345
  ${customCss}
321
346
  </style>
322
347
  </head><body>
323
- <div class="${popupClass}" id="dd-popup">
348
+ <div class="${popupClass}" id="dd-popup" dir="${initDirection}">
324
349
  <div class="deepdots-popup-header">
325
350
  <h2 id="dd-title" class="deepdots-popup-title" hidden></h2>
326
- <button type="button" id="dd-close" aria-label="Close popup">
327
- <svg width="28" height="28" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
328
- <path d="M6 6L18 18M6 18L18 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
351
+ <button type="button" id="dd-close" aria-label="${initLabels.closeAria}">
352
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
353
+ <path d="M5 5L19 19M5 19L19 5" stroke="currentColor" stroke-width="1.5" stroke-linecap="butt"/>
329
354
  </svg>
330
355
  </button>
331
356
  </div>
332
357
  <div class="deepdots-progress" id="dd-progress">
333
358
  <div class="deepdots-progress-head">
334
359
  <span id="dd-progress-label"><span id="dd-progress-current"></span><span id="dd-progress-total"></span></span>
335
- <span id="dd-progress-followup">Follow-up</span>
360
+ <span id="dd-progress-followup">${initLabels.followUp}</span>
336
361
  </div>
337
362
  <div class="deepdots-progress-track"><div id="dd-progress-bar"></div></div>
338
363
  </div>
339
364
  <div class="deepdots-popup-container-content" id="dd-content">
340
365
  <div class="deepdots-popup-main" id="dd-main">
341
366
  <div id="dd-form-wrapper">
342
- <div class="mf-spinner" id="dd-spinner" role="status" aria-label="Loading survey"><div class="mf-spinner-circle"></div></div>
367
+ <div class="mf-spinner" id="dd-spinner" role="status" aria-label="${initLabels.loadingAria}"><div class="mf-spinner-circle"></div></div>
343
368
  <div id="mf"></div>
344
369
  </div>
345
370
  <div class="deepdots-error-hint" id="dd-error" role="alert" aria-live="polite"></div>
346
371
  </div>
347
372
  <div class="deepdots-popup-footer" id="dd-footer">
348
- <button type="button" class="dd-nav-btn" id="dd-submit">Send</button>
349
- <button type="button" class="dd-nav-btn" id="dd-back">Back</button>
350
- <button type="button" class="dd-nav-btn" id="dd-complete">Complete survey</button>
351
- <button type="button" class="dd-nav-btn" id="dd-start">Start survey</button>
373
+ <button type="button" class="dd-nav-btn" id="dd-submit"></button>
374
+ <button type="button" class="dd-nav-btn" id="dd-back"></button>
375
+ <button type="button" class="dd-nav-btn" id="dd-complete"></button>
376
+ <button type="button" class="dd-nav-btn" id="dd-start"></button>
352
377
  </div>
353
378
  </div>
354
379
  </div>
@@ -377,6 +402,32 @@ ${customCss}
377
402
  var progressTotal=document.getElementById('dd-progress-total');
378
403
  var progressFollowUp=document.getElementById('dd-progress-followup');
379
404
  var progressBar=document.getElementById('dd-progress-bar');
405
+ var closeEl=document.getElementById('dd-close');
406
+
407
+ // --- i18n del chrome -------------------------------------------------------------------
408
+ // La tabla completa viaja embebida porque el idioma del survey (\`formData.lang[0]\`) solo se
409
+ // conoce ya dentro del WebView. \`ddResolveLocale\` es el espejo del \`resolveLocale\` de TS
410
+ // (paridad cubierta por test).
411
+ var DD_LABELS=${labelsTableJson};
412
+ var DD_ACTION_OVERRIDES=${actionOverridesJson};
413
+ ${RESOLVE_LOCALE_JS}
414
+ var DD_LABELS_ACTIVE=DD_LABELS[ddResolveLocale(${initLangJson})];
415
+ var DD_RTL=${rtlLocalesJson};
416
+ function ddIsRtl(lang){ return DD_RTL.indexOf(ddResolveLocale(lang))!==-1; }
417
+ function ddApplyLabels(lang){
418
+ var next=DD_LABELS[ddResolveLocale(lang)];
419
+ if(!next) return;
420
+ DD_LABELS_ACTIVE=next;
421
+ // El survey ya se ha volteado a s\xED mismo: el chrome tiene que acompa\xF1arlo.
422
+ popup.setAttribute('dir', ddIsRtl(lang) ? 'rtl' : 'ltr');
423
+ backBtn.textContent=DD_ACTION_OVERRIDES.back||next.back;
424
+ startBtn.textContent=DD_ACTION_OVERRIDES.start||next.start;
425
+ completeBtn.textContent=DD_ACTION_OVERRIDES.complete||next.complete;
426
+ submitBtn.textContent=DD_ACTION_OVERRIDES.accept||next.accept;
427
+ if(closeEl){ closeEl.setAttribute('aria-label',next.closeAria); }
428
+ if(spinner){ spinner.setAttribute('aria-label',next.loadingAria); }
429
+ progressFollowUp.textContent=next.followUp;
430
+ }
380
431
 
381
432
  function setTitle(t){
382
433
  if(!t) return;
@@ -417,8 +468,8 @@ ${customCss}
417
468
  progressCurrent.textContent=Math.round(pct)+'%';
418
469
  progressTotal.textContent='';
419
470
  } else {
420
- progressCurrent.textContent='Question '+label;
421
- progressTotal.textContent=' of '+total;
471
+ progressCurrent.textContent=DD_LABELS_ACTIVE.question+' '+label;
472
+ progressTotal.textContent=' '+DD_LABELS_ACTIVE.of+' '+total;
422
473
  }
423
474
  progressFollowUp.style.display=p&&p.followup?'inline-block':'none';
424
475
  }
@@ -428,7 +479,7 @@ ${customCss}
428
479
  completeBtn.textContent=${completeLabel};
429
480
  submitBtn.textContent=${submitLabel};
430
481
 
431
- document.getElementById('dd-close').onclick=function(){ emitJSON('popup_close'); };
482
+ closeEl.onclick=function(){ emitJSON('popup_close'); };
432
483
  backBtn.onclick=function(){ if(window.DeepdotsForm && window.DeepdotsForm.back){ window.DeepdotsForm.back(); } };
433
484
  startBtn.onclick=function(){
434
485
  if(window.DeepdotsForm && window.DeepdotsForm.startForm){
@@ -523,6 +574,14 @@ ${customCss}
523
574
  // fallback es un literal gen\xE9rico que ignora style.successMessage.
524
575
  addSuccessScreen:false,
525
576
  onLoadedEvent:function(args){
577
+ // Idioma del survey: manda sobre el del init para que el chrome no se quede en
578
+ // ingl\xE9s delante de un survey traducido.
579
+ var langs=args && args.formData ? args.formData.lang : null;
580
+ if(langs && langs.length){
581
+ for(var li=0;li<langs.length;li++){
582
+ if(typeof langs[li]==='string' && langs[li].trim()){ ddApplyLabels(langs[li]); break; }
583
+ }
584
+ }
526
585
  var s=args && args.formData ? args.formData.style : null;
527
586
  if(s && !stylesInjected){
528
587
  stylesInjected=true;
@@ -549,10 +608,14 @@ ${customCss}
549
608
  if(s.logoSize==='small'){ logoImg.style.maxHeight='30px'; }
550
609
  else if(s.logoSize==='medium'){ logoImg.style.maxHeight='50px'; }
551
610
  else if(s.logoSize==='large'){ logoImg.style.maxHeight='70px'; }
552
- if(s.logoPosition==='left'){ logoImg.style.margin='0 16px 20px 0'; logoImg.style.display='block'; logoImg.style.marginLeft='0'; }
553
- else if(s.logoPosition==='right'){ logoImg.style.margin='0 0 20px 16px'; logoImg.style.display='block'; logoImg.style.marginLeft='auto'; }
554
- else if(s.logoPosition==='center'){ logoImg.style.margin='0 auto 20px auto'; logoImg.style.display='block'; }
555
- main.insertBefore(logoImg, document.getElementById('dd-form-wrapper'));
611
+ // M\xE1rgenes l\xF3gicos: con un survey RTL el popup va con dir="rtl" y el logo
612
+ // tiene que acompa\xF1ar al chrome. En LTR el resultado es el mismo de antes.
613
+ if(s.logoPosition==='left'){ logoImg.style.margin='12px 0 0 0'; logoImg.style.setProperty('margin-inline-start','0'); logoImg.style.setProperty('margin-inline-end','16px'); }
614
+ else if(s.logoPosition==='right'){ logoImg.style.margin='12px 0 0 0'; logoImg.style.setProperty('margin-inline-start','auto'); logoImg.style.setProperty('margin-inline-end','0'); }
615
+ else if(s.logoPosition==='center'){ logoImg.style.margin='12px auto 0 auto'; }
616
+ // Encima de la barra de progreso, como hermano del header (espejo de ui/logo.ts en
617
+ // web). Fuera de #dd-main, as\xED el logo no se va con el scroll del formulario.
618
+ popup.insertBefore(logoImg, progressEl);
556
619
  }
557
620
  if(s.startMessage && s.startMessage!==''){ onStartPage=true; updateButtons('start'); }
558
621
  else { updateButtons('in_progress_first'); }
@@ -574,12 +637,12 @@ ${customCss}
574
637
  setLoading(false);
575
638
  if(error.toLowerCase().indexOf('no response')!==-1){
576
639
  // La p\xE1gina no ha cambiado: el estado de navegaci\xF3n se queda como estaba.
577
- errorHint.textContent='Please answer the required question to continue.';
640
+ errorHint.textContent=DD_LABELS_ACTIVE.errorRequired;
578
641
  errorHint.style.display='block';
579
642
  updateNavButtons();
580
643
  return;
581
644
  }
582
- errorHint.textContent='An error occurred while submitting. Please try again or close the popup.';
645
+ errorHint.textContent=DD_LABELS_ACTIVE.errorSubmit;
583
646
  errorHint.style.display='block';
584
647
  return;
585
648
  }
@@ -651,7 +714,8 @@ var ReactNativePopupRenderer = class {
651
714
  chrome: renderChrome,
652
715
  title: options?.title,
653
716
  showProgressBar: options?.showProgressBar,
654
- surveyCss: options?.surveyCss
717
+ surveyCss: options?.surveyCss,
718
+ language: options?.language
655
719
  });
656
720
  if (this.options.onShow) {
657
721
  this.options.onShow({ surveyId, productId, html });
@@ -747,7 +811,7 @@ var BrowserPopupRenderer = class {
747
811
  if (!this.container) return;
748
812
  this.visible = true;
749
813
  const container = this.container;
750
- void import("./renderPopup-PXJEND4Y.mjs").then(({ renderPopup }) => {
814
+ void import("./renderPopup-IHGYFMXO.mjs").then(({ renderPopup }) => {
751
815
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
752
816
  });
753
817
  }
@@ -2457,13 +2521,13 @@ var DeepdotsPopups = class {
2457
2521
  miniService,
2458
2522
  analyticsFeedbackSessionId,
2459
2523
  this.renderChrome,
2460
- { title, showProgressBar: this.showProgressBar, surveyCss: this.surveyCss }
2524
+ { title, showProgressBar: this.showProgressBar, surveyCss: this.surveyCss, language: this.language }
2461
2525
  );
2462
2526
  return;
2463
2527
  }
2464
2528
  if (!this.popupContainer) return;
2465
2529
  const container = this.popupContainer;
2466
- void import("./renderPopup-PXJEND4Y.mjs").then(({ renderPopup }) => {
2530
+ void import("./renderPopup-IHGYFMXO.mjs").then(({ renderPopup }) => {
2467
2531
  renderPopup(
2468
2532
  container,
2469
2533
  surveyId,
@@ -2477,7 +2541,7 @@ var DeepdotsPopups = class {
2477
2541
  sessionId,
2478
2542
  miniService,
2479
2543
  analyticsFeedbackSessionId,
2480
- { title, showProgressBar: this.showProgressBar, surveyCss: this.surveyCss }
2544
+ { title, showProgressBar: this.showProgressBar, surveyCss: this.surveyCss, language: this.language }
2481
2545
  );
2482
2546
  });
2483
2547
  }
@@ -2691,12 +2755,15 @@ export {
2691
2755
  CrashReporter,
2692
2756
  DeepdotsPopups,
2693
2757
  InMemoryStorage,
2758
+ LABELS,
2694
2759
  MAX_TRACKED_MESSAGES,
2695
2760
  MESSAGE_CHANNELS,
2696
2761
  MessageGuard,
2697
2762
  NoopPopupRenderer,
2698
2763
  POPUP_TRIGGER_CONDITION_STATUSES,
2764
+ RTL_LOCALES,
2699
2765
  ReactNativePopupRenderer,
2766
+ SUPPORTED_LANGUAGES,
2700
2767
  buildAnalyticsFeedbackBody,
2701
2768
  buildMessageParams,
2702
2769
  buildSurveyHtml,
@@ -2704,7 +2771,12 @@ export {
2704
2771
  crashRecordToParams,
2705
2772
  createDefaultRenderer,
2706
2773
  createFeedbackSink,
2774
+ directionFor,
2775
+ getLabels,
2776
+ isRtlLanguage,
2707
2777
  mmkvStorage,
2778
+ resolveActionLabels,
2779
+ resolveLocale,
2708
2780
  setupReactNative
2709
2781
  };
2710
2782
  //# sourceMappingURL=index.mjs.map