@redneckz/wildless-cms-uni-blocks 0.14.1025 → 0.14.1027

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.
Files changed (54) hide show
  1. package/bundle/blocks.schema.json +1 -1
  2. package/bundle/bundle.umd.js +201 -164
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/bundle/model/LinkProps.d.ts +2 -0
  5. package/bundle/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  6. package/dist/model/LinkProps.d.ts +2 -0
  7. package/dist/ui-kit/LinkButton/LinkButton.js +36 -2
  8. package/dist/ui-kit/LinkButton/LinkButton.js.map +1 -1
  9. package/dist/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  10. package/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js +0 -1
  11. package/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
  12. package/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +5 -0
  13. package/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
  14. package/lib/components/ButtonsBlock/ButtonsBlock.fixture.d.ts +1 -0
  15. package/lib/model/LinkProps.d.ts +2 -0
  16. package/lib/ui-kit/LinkButton/LinkButton.js +36 -2
  17. package/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
  18. package/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  19. package/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js +0 -1
  20. package/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
  21. package/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +5 -0
  22. package/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
  23. package/mobile/bundle/bundle.umd.js +201 -164
  24. package/mobile/bundle/bundle.umd.min.js +1 -1
  25. package/mobile/bundle/model/LinkProps.d.ts +2 -0
  26. package/mobile/bundle/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  27. package/mobile/dist/model/LinkProps.d.ts +2 -0
  28. package/mobile/dist/ui-kit/LinkButton/LinkButton.js +36 -2
  29. package/mobile/dist/ui-kit/LinkButton/LinkButton.js.map +1 -1
  30. package/mobile/dist/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  31. package/mobile/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js +0 -1
  32. package/mobile/dist/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
  33. package/mobile/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +5 -0
  34. package/mobile/dist/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
  35. package/mobile/lib/model/LinkProps.d.ts +2 -0
  36. package/mobile/lib/ui-kit/LinkButton/LinkButton.js +36 -2
  37. package/mobile/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
  38. package/mobile/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  39. package/mobile/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js +0 -1
  40. package/mobile/lib/ui-kit/UserSurveyDialog/UserSurveyDialog.js.map +1 -1
  41. package/mobile/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js +5 -0
  42. package/mobile/lib/ui-kit/UserSurveyDialog/useUserSurveyDialog.js.map +1 -1
  43. package/mobile/src/model/LinkProps.ts +2 -0
  44. package/mobile/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
  45. package/mobile/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
  46. package/mobile/src/ui-kit/UserSurveyDialog/UserSurveyDialog.tsx +0 -1
  47. package/mobile/src/ui-kit/UserSurveyDialog/useUserSurveyDialog.ts +7 -0
  48. package/package.json +1 -1
  49. package/src/components/ButtonsBlock/ButtonsBlock.fixture.tsx +21 -0
  50. package/src/model/LinkProps.ts +2 -0
  51. package/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
  52. package/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
  53. package/src/ui-kit/UserSurveyDialog/UserSurveyDialog.tsx +0 -1
  54. package/src/ui-kit/UserSurveyDialog/useUserSurveyDialog.ts +7 -0
@@ -408,24 +408,28 @@
408
408
  className,
409
409
  ].join(' ');
410
410
 
411
- /* eslint-disable @typescript-eslint/ban-types */
412
- const handlerDecorator = (handler) => {
413
- return handlerDecorator._impl(handler);
414
- };
415
- handlerDecorator._impl = (handler) => handler;
416
- handlerDecorator.setup = (impl) => {
417
- handlerDecorator._impl = impl;
418
- };
411
+ function copy(source, target) {
412
+ for (const [k, v] of source.entries()) {
413
+ if (v !== null && v !== undefined) {
414
+ target.setItem(k, v);
415
+ }
416
+ else {
417
+ target.removeItem(k);
418
+ }
419
+ }
420
+ }
419
421
 
420
- function useEmitterWithActions(eventBus, type) {
421
- const cache = useRef({});
422
- return useMemo(() => new Proxy({}, {
423
- get(_, actionType) {
424
- cache.current ||= {};
425
- cache.current[actionType] ||= action => eventBus.fire(type, { ...(action ?? {}), type: actionType });
426
- return cache.current[actionType];
422
+ function replicate(primary, secondary) {
423
+ copy(primary, secondary);
424
+ copy(secondary, primary);
425
+ return primary.bus.watch(({ type, event }) => {
426
+ if (event !== null && event !== undefined) {
427
+ secondary.setItem(type, event);
427
428
  }
428
- }), [eventBus, type]);
429
+ else {
430
+ secondary.removeItem(type);
431
+ }
432
+ });
429
433
  }
430
434
 
431
435
  class EventBus {
@@ -477,6 +481,146 @@
477
481
  }
478
482
  }
479
483
 
484
+ class StorageAdapter {
485
+ storage;
486
+ bus;
487
+ get size() {
488
+ return this.storage?.length ?? 0;
489
+ }
490
+ constructor(storage, bus = new EventBus()) {
491
+ this.storage = storage;
492
+ this.bus = bus;
493
+ }
494
+ hasItem(key) {
495
+ return Boolean(this.storage?.getItem(String(key)));
496
+ }
497
+ getItem(key) {
498
+ const _ = this.storage?.getItem(String(key)) ?? null;
499
+ try {
500
+ return JSON.parse(String(_));
501
+ }
502
+ catch (ex) {
503
+ return null;
504
+ }
505
+ }
506
+ entries() {
507
+ return Array.from({ length: this.size }, (_, i) => {
508
+ const k = String(this.storage?.key(i));
509
+ return [k, this.getItem(k)];
510
+ });
511
+ }
512
+ setItem(key, value) {
513
+ if (value !== null) {
514
+ this.storage?.setItem(String(key), JSON.stringify(value));
515
+ }
516
+ else {
517
+ this.storage?.removeItem(String(key));
518
+ }
519
+ this.bus?.subject(key, value);
520
+ }
521
+ removeItem(key) {
522
+ this.storage?.removeItem(String(key));
523
+ this.bus?.subject(key, null);
524
+ }
525
+ }
526
+
527
+ class Store {
528
+ bus;
529
+ store = new Map();
530
+ get size() {
531
+ return this.store.size;
532
+ }
533
+ constructor(bus = new EventBus()) {
534
+ this.bus = bus;
535
+ }
536
+ hasItem(key) {
537
+ return this.store.has(key);
538
+ }
539
+ getItem(key) {
540
+ return this.store.get(key);
541
+ }
542
+ entries() {
543
+ return this.store.entries();
544
+ }
545
+ setItem(key, value) {
546
+ this.store.set(key, value);
547
+ this.bus.subject(key, value);
548
+ }
549
+ removeItem(key) {
550
+ this.store.delete(key);
551
+ this.bus.subject(key, null);
552
+ }
553
+ }
554
+
555
+ function useRerender() {
556
+ const [, setCount] = useState(0);
557
+ return useCallback(() => setCount(_ => (_ + 1) % (1 << 16)), []);
558
+ }
559
+
560
+ const DEFAULT_METHODS = {};
561
+ /**
562
+ * MobX like reactivity (simplified).
563
+ * Can be used to migrate from Redux/MobX or something else
564
+ *
565
+ * @param store
566
+ * @returns reactive proxy backed by store
567
+ */
568
+ function useStore(store, methods = DEFAULT_METHODS) {
569
+ const deps = useRef(null);
570
+ const render = useRerender();
571
+ useEffect(() => store.bus.watch(ev => {
572
+ if (deps.current?.has(String(ev.type))) {
573
+ render();
574
+ }
575
+ }), [store, render]);
576
+ return useMemo(() => new Proxy(methods, {
577
+ get(_, key) {
578
+ deps.current ||= new Set();
579
+ deps.current.add(key);
580
+ return store.getItem(key);
581
+ },
582
+ has(_, key) {
583
+ deps.current ||= new Set();
584
+ deps.current.add(key);
585
+ return store.hasItem(key);
586
+ },
587
+ set(_, key, value) {
588
+ store.setItem(key, value);
589
+ return true;
590
+ },
591
+ deleteProperty(_, key) {
592
+ store.removeItem(key);
593
+ return true;
594
+ }
595
+ }), [store]);
596
+ }
597
+
598
+ const localStore = new Store(); // localStorage cache
599
+ replicate(localStore, new StorageAdapter(globalThis?.localStorage));
600
+ function useLocalStore(methods) {
601
+ return useStore(localStore, methods);
602
+ }
603
+
604
+ /* eslint-disable @typescript-eslint/ban-types */
605
+ const handlerDecorator = (handler) => {
606
+ return handlerDecorator._impl(handler);
607
+ };
608
+ handlerDecorator._impl = (handler) => handler;
609
+ handlerDecorator.setup = (impl) => {
610
+ handlerDecorator._impl = impl;
611
+ };
612
+
613
+ function useEmitterWithActions(eventBus, type) {
614
+ const cache = useRef({});
615
+ return useMemo(() => new Proxy({}, {
616
+ get(_, actionType) {
617
+ cache.current ||= {};
618
+ cache.current[actionType] ||= action => eventBus.fire(type, { ...(action ?? {}), type: actionType });
619
+ return cache.current[actionType];
620
+ }
621
+ }), [eventBus, type]);
622
+ }
623
+
480
624
  const defaultEventBus = new EventBus();
481
625
 
482
626
  const useDialogManager = () => useEmitterWithActions(defaultEventBus.emitter, 'dialog');
@@ -570,15 +714,48 @@
570
714
  }, [method, href]);
571
715
 
572
716
  /** @deprecated */
573
- const LinkButton = JSX(({ disabled, children, method = 'LINK', href, ...rest }) => {
717
+ const LinkButton = JSX(({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
574
718
  const handleFormSubmit = useFormSubmit({ method, href });
719
+ const linksStore = useLocalStore();
720
+ saveLinksToStore({ linksStore, href, id, additionalHrefs });
721
+ const adjustedHref = additionalHrefs
722
+ ? (linksStore.links || []).find((store) => store.id === id)?.lastLink
723
+ : href;
575
724
  const link = useLink();
576
- const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
725
+ const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
577
726
  const buttonInner = children ?? jsx(ButtonInner, { ...adjustedProps });
578
727
  return disabled ? (jsx(DisabledButton, { ...adjustedProps, children: buttonInner })) : (jsx(RegularButton, { ...adjustedProps, children: buttonInner }));
579
728
  });
580
729
  const RegularButton = JSX(({ className = '', href, rel, target, ariaLabel, version, rounded, onClick, type, data, children, text, }) => (jsx("a", { className: getRegularButtonClasses({ className, version, rounded }), href: href, rel: rel, target: target, "aria-label": ariaLabel || `Ссылка на ${text}`, role: href ? 'link' : 'button', onClick: onClick, type: type, ...getAspectsAttributes(data), children: children })));
581
730
  const DisabledButton = JSX(({ className, ariaLabel, version, rounded, children }) => (jsx("button", { type: "button", "aria-disabled": "true", "aria-label": ariaLabel, tabIndex: -1, className: getDisabledButtonClasses({ className, rounded, version }), children: children })));
731
+ const getRandomHref = (href = '', additionalHrefs = []) => {
732
+ const hrefs = [href, ...additionalHrefs];
733
+ return hrefs[Math.floor(Math.random() * hrefs.length)];
734
+ };
735
+ // Отсчитываем 7 длей с текущей даты
736
+ const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
737
+ // Сохраняем или заменяем рандомную ссылку в localStorage
738
+ const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }) => {
739
+ const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
740
+ // Если хранилища вообще нет
741
+ if (!linksStore.links) {
742
+ linksStore.links = [];
743
+ }
744
+ if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
745
+ // Получаем рандомную ссылку
746
+ const randomHref = getRandomHref(href, additionalHrefs);
747
+ // При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
748
+ const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
749
+ // Добавляем новый элемент
750
+ updatedLinks.push({
751
+ id: id ?? '',
752
+ lastLink: randomHref,
753
+ nextDueAt: getTimeAfter7days(),
754
+ });
755
+ // Добавляем это все в хранилище
756
+ linksStore.links = updatedLinks;
757
+ }
758
+ };
582
759
 
583
760
  // TODO Заменить LinkButton на Button и применить RoundedIcon
584
761
  function renderBackwardButton({ version, handleClick, text = 'Вернуться назад', alwaysVisible = false, }) {
@@ -1384,150 +1561,6 @@
1384
1561
  return (jsx(Dialog, { maxWidth: "lg", onClose: onClose, children: jsxs("div", { className: "flex flex-col gap-lg items-center rounded-md space-x-m", children: [jsx(Img, { image: { icon: statusIcon, iconVersion: 'normal' }, width: "136", height: "136" }), jsx(Headline, { className: "w-full", title: ok ? 'Ваша заявка отправлена' : 'Не удалось отправить заявку', description: ok ? responseOKDescription : responseFailDescription, headlineVersion: "XS", isEmbedded: true }), jsx(Button, { type: "button", onClick: onClose, children: "\u0425\u043E\u0440\u043E\u0448\u043E" })] }) }));
1385
1562
  });
1386
1563
 
1387
- function copy(source, target) {
1388
- for (const [k, v] of source.entries()) {
1389
- if (v !== null && v !== undefined) {
1390
- target.setItem(k, v);
1391
- }
1392
- else {
1393
- target.removeItem(k);
1394
- }
1395
- }
1396
- }
1397
-
1398
- function replicate(primary, secondary) {
1399
- copy(primary, secondary);
1400
- copy(secondary, primary);
1401
- return primary.bus.watch(({ type, event }) => {
1402
- if (event !== null && event !== undefined) {
1403
- secondary.setItem(type, event);
1404
- }
1405
- else {
1406
- secondary.removeItem(type);
1407
- }
1408
- });
1409
- }
1410
-
1411
- class StorageAdapter {
1412
- storage;
1413
- bus;
1414
- get size() {
1415
- return this.storage?.length ?? 0;
1416
- }
1417
- constructor(storage, bus = new EventBus()) {
1418
- this.storage = storage;
1419
- this.bus = bus;
1420
- }
1421
- hasItem(key) {
1422
- return Boolean(this.storage?.getItem(String(key)));
1423
- }
1424
- getItem(key) {
1425
- const _ = this.storage?.getItem(String(key)) ?? null;
1426
- try {
1427
- return JSON.parse(String(_));
1428
- }
1429
- catch (ex) {
1430
- return null;
1431
- }
1432
- }
1433
- entries() {
1434
- return Array.from({ length: this.size }, (_, i) => {
1435
- const k = String(this.storage?.key(i));
1436
- return [k, this.getItem(k)];
1437
- });
1438
- }
1439
- setItem(key, value) {
1440
- if (value !== null) {
1441
- this.storage?.setItem(String(key), JSON.stringify(value));
1442
- }
1443
- else {
1444
- this.storage?.removeItem(String(key));
1445
- }
1446
- this.bus?.subject(key, value);
1447
- }
1448
- removeItem(key) {
1449
- this.storage?.removeItem(String(key));
1450
- this.bus?.subject(key, null);
1451
- }
1452
- }
1453
-
1454
- class Store {
1455
- bus;
1456
- store = new Map();
1457
- get size() {
1458
- return this.store.size;
1459
- }
1460
- constructor(bus = new EventBus()) {
1461
- this.bus = bus;
1462
- }
1463
- hasItem(key) {
1464
- return this.store.has(key);
1465
- }
1466
- getItem(key) {
1467
- return this.store.get(key);
1468
- }
1469
- entries() {
1470
- return this.store.entries();
1471
- }
1472
- setItem(key, value) {
1473
- this.store.set(key, value);
1474
- this.bus.subject(key, value);
1475
- }
1476
- removeItem(key) {
1477
- this.store.delete(key);
1478
- this.bus.subject(key, null);
1479
- }
1480
- }
1481
-
1482
- function useRerender() {
1483
- const [, setCount] = useState(0);
1484
- return useCallback(() => setCount(_ => (_ + 1) % (1 << 16)), []);
1485
- }
1486
-
1487
- const DEFAULT_METHODS = {};
1488
- /**
1489
- * MobX like reactivity (simplified).
1490
- * Can be used to migrate from Redux/MobX or something else
1491
- *
1492
- * @param store
1493
- * @returns reactive proxy backed by store
1494
- */
1495
- function useStore(store, methods = DEFAULT_METHODS) {
1496
- const deps = useRef(null);
1497
- const render = useRerender();
1498
- useEffect(() => store.bus.watch(ev => {
1499
- if (deps.current?.has(String(ev.type))) {
1500
- render();
1501
- }
1502
- }), [store, render]);
1503
- return useMemo(() => new Proxy(methods, {
1504
- get(_, key) {
1505
- deps.current ||= new Set();
1506
- deps.current.add(key);
1507
- return store.getItem(key);
1508
- },
1509
- has(_, key) {
1510
- deps.current ||= new Set();
1511
- deps.current.add(key);
1512
- return store.hasItem(key);
1513
- },
1514
- set(_, key, value) {
1515
- store.setItem(key, value);
1516
- return true;
1517
- },
1518
- deleteProperty(_, key) {
1519
- store.removeItem(key);
1520
- return true;
1521
- }
1522
- }), [store]);
1523
- }
1524
-
1525
- const localStore = new Store(); // localStorage cache
1526
- replicate(localStore, new StorageAdapter(globalThis?.localStorage));
1527
- function useLocalStore(methods) {
1528
- return useStore(localStore, methods);
1529
- }
1530
-
1531
1564
  const sessionStore = new Store(); // sessionStorage cache
1532
1565
  replicate(sessionStore, new StorageAdapter(globalThis?.sessionStorage));
1533
1566
  function useSessionStore() {
@@ -1978,7 +2011,6 @@
1978
2011
  const getTimeAfter30days = () => Date.now() + 30 * 24 * 60 * 60 * 1000;
1979
2012
  // Если пользователь проходил опрос то показываем другой, иначе показываем случайный тип опроса
1980
2013
  const getUserSurveyType = (lastShownType) => {
1981
- console.log('Расчитал');
1982
2014
  if (lastShownType) {
1983
2015
  return lastShownType === 'NPS' ? 'CSI' : 'NPS';
1984
2016
  }
@@ -1997,6 +2029,7 @@
1997
2029
  ? Date.now() - Number.parseInt(sessionStore.surveyTimerStart)
1998
2030
  : 0;
1999
2031
  const isShowSurvey = !isSurveySkipped &&
2032
+ !isOtherLanguagePortal &&
2000
2033
  (!userSurveyStore.userSurvey || userSurveyStore.userSurvey?.nextDueAt <= Date.now());
2001
2034
  const handleSkipSurvey = useCallback(() => {
2002
2035
  sessionStore.isSurveySkipped = true;
@@ -2035,6 +2068,10 @@
2035
2068
  }, [isShowSurvey]);
2036
2069
  return handleOpenSurveyAction;
2037
2070
  };
2071
+ const isOtherLanguagePortal = () => {
2072
+ const regexp = new RegExp('^/(cn|en)($|/.*)');
2073
+ return regexp.test(globalThis.location.pathname);
2074
+ };
2038
2075
 
2039
2076
  const SERVICE_TYPES = [{ key: 'ULTRASERVICE', text: 'Ультра' }];
2040
2077
  const SERVICE_DIRECTIONS = [
@@ -14146,7 +14183,7 @@
14146
14183
  slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
14147
14184
  });
14148
14185
 
14149
- const packageVersion = "0.14.1024";
14186
+ const packageVersion = "0.14.1026";
14150
14187
 
14151
14188
  exports.Blocks = Blocks;
14152
14189
  exports.ContentPage = ContentPage;