@redneckz/wildless-cms-uni-blocks 0.14.1026 → 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 (34) hide show
  1. package/bundle/blocks.schema.json +1 -1
  2. package/bundle/bundle.umd.js +196 -163
  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/lib/components/ButtonsBlock/ButtonsBlock.fixture.d.ts +1 -0
  11. package/lib/model/LinkProps.d.ts +2 -0
  12. package/lib/ui-kit/LinkButton/LinkButton.js +36 -2
  13. package/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
  14. package/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  15. package/mobile/bundle/bundle.umd.js +196 -163
  16. package/mobile/bundle/bundle.umd.min.js +1 -1
  17. package/mobile/bundle/model/LinkProps.d.ts +2 -0
  18. package/mobile/bundle/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  19. package/mobile/dist/model/LinkProps.d.ts +2 -0
  20. package/mobile/dist/ui-kit/LinkButton/LinkButton.js +36 -2
  21. package/mobile/dist/ui-kit/LinkButton/LinkButton.js.map +1 -1
  22. package/mobile/dist/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  23. package/mobile/lib/model/LinkProps.d.ts +2 -0
  24. package/mobile/lib/ui-kit/LinkButton/LinkButton.js +36 -2
  25. package/mobile/lib/ui-kit/LinkButton/LinkButton.js.map +1 -1
  26. package/mobile/lib/ui-kit/LinkButton/LinkButtonContent.d.ts +11 -0
  27. package/mobile/src/model/LinkProps.ts +2 -0
  28. package/mobile/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
  29. package/mobile/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
  30. package/package.json +1 -1
  31. package/src/components/ButtonsBlock/ButtonsBlock.fixture.tsx +21 -0
  32. package/src/model/LinkProps.ts +2 -0
  33. package/src/ui-kit/LinkButton/LinkButton.tsx +54 -2
  34. package/src/ui-kit/LinkButton/LinkButtonContent.ts +12 -0
@@ -400,24 +400,28 @@
400
400
  className,
401
401
  ].join(' ');
402
402
 
403
- /* eslint-disable @typescript-eslint/ban-types */
404
- const handlerDecorator = (handler) => {
405
- return handlerDecorator._impl(handler);
406
- };
407
- handlerDecorator._impl = (handler) => handler;
408
- handlerDecorator.setup = (impl) => {
409
- handlerDecorator._impl = impl;
410
- };
403
+ function copy(source, target) {
404
+ for (const [k, v] of source.entries()) {
405
+ if (v !== null && v !== undefined) {
406
+ target.setItem(k, v);
407
+ }
408
+ else {
409
+ target.removeItem(k);
410
+ }
411
+ }
412
+ }
411
413
 
412
- function useEmitterWithActions(eventBus, type) {
413
- const cache = useRef({});
414
- return useMemo(() => new Proxy({}, {
415
- get(_, actionType) {
416
- cache.current ||= {};
417
- cache.current[actionType] ||= action => eventBus.fire(type, { ...(action ?? {}), type: actionType });
418
- return cache.current[actionType];
414
+ function replicate(primary, secondary) {
415
+ copy(primary, secondary);
416
+ copy(secondary, primary);
417
+ return primary.bus.watch(({ type, event }) => {
418
+ if (event !== null && event !== undefined) {
419
+ secondary.setItem(type, event);
419
420
  }
420
- }), [eventBus, type]);
421
+ else {
422
+ secondary.removeItem(type);
423
+ }
424
+ });
421
425
  }
422
426
 
423
427
  class EventBus {
@@ -469,6 +473,146 @@
469
473
  }
470
474
  }
471
475
 
476
+ class StorageAdapter {
477
+ storage;
478
+ bus;
479
+ get size() {
480
+ return this.storage?.length ?? 0;
481
+ }
482
+ constructor(storage, bus = new EventBus()) {
483
+ this.storage = storage;
484
+ this.bus = bus;
485
+ }
486
+ hasItem(key) {
487
+ return Boolean(this.storage?.getItem(String(key)));
488
+ }
489
+ getItem(key) {
490
+ const _ = this.storage?.getItem(String(key)) ?? null;
491
+ try {
492
+ return JSON.parse(String(_));
493
+ }
494
+ catch (ex) {
495
+ return null;
496
+ }
497
+ }
498
+ entries() {
499
+ return Array.from({ length: this.size }, (_, i) => {
500
+ const k = String(this.storage?.key(i));
501
+ return [k, this.getItem(k)];
502
+ });
503
+ }
504
+ setItem(key, value) {
505
+ if (value !== null) {
506
+ this.storage?.setItem(String(key), JSON.stringify(value));
507
+ }
508
+ else {
509
+ this.storage?.removeItem(String(key));
510
+ }
511
+ this.bus?.subject(key, value);
512
+ }
513
+ removeItem(key) {
514
+ this.storage?.removeItem(String(key));
515
+ this.bus?.subject(key, null);
516
+ }
517
+ }
518
+
519
+ class Store {
520
+ bus;
521
+ store = new Map();
522
+ get size() {
523
+ return this.store.size;
524
+ }
525
+ constructor(bus = new EventBus()) {
526
+ this.bus = bus;
527
+ }
528
+ hasItem(key) {
529
+ return this.store.has(key);
530
+ }
531
+ getItem(key) {
532
+ return this.store.get(key);
533
+ }
534
+ entries() {
535
+ return this.store.entries();
536
+ }
537
+ setItem(key, value) {
538
+ this.store.set(key, value);
539
+ this.bus.subject(key, value);
540
+ }
541
+ removeItem(key) {
542
+ this.store.delete(key);
543
+ this.bus.subject(key, null);
544
+ }
545
+ }
546
+
547
+ function useRerender() {
548
+ const [, setCount] = useState(0);
549
+ return useCallback(() => setCount(_ => (_ + 1) % (1 << 16)), []);
550
+ }
551
+
552
+ const DEFAULT_METHODS = {};
553
+ /**
554
+ * MobX like reactivity (simplified).
555
+ * Can be used to migrate from Redux/MobX or something else
556
+ *
557
+ * @param store
558
+ * @returns reactive proxy backed by store
559
+ */
560
+ function useStore(store, methods = DEFAULT_METHODS) {
561
+ const deps = useRef(null);
562
+ const render = useRerender();
563
+ useEffect(() => store.bus.watch(ev => {
564
+ if (deps.current?.has(String(ev.type))) {
565
+ render();
566
+ }
567
+ }), [store, render]);
568
+ return useMemo(() => new Proxy(methods, {
569
+ get(_, key) {
570
+ deps.current ||= new Set();
571
+ deps.current.add(key);
572
+ return store.getItem(key);
573
+ },
574
+ has(_, key) {
575
+ deps.current ||= new Set();
576
+ deps.current.add(key);
577
+ return store.hasItem(key);
578
+ },
579
+ set(_, key, value) {
580
+ store.setItem(key, value);
581
+ return true;
582
+ },
583
+ deleteProperty(_, key) {
584
+ store.removeItem(key);
585
+ return true;
586
+ }
587
+ }), [store]);
588
+ }
589
+
590
+ const localStore = new Store(); // localStorage cache
591
+ replicate(localStore, new StorageAdapter(globalThis?.localStorage));
592
+ function useLocalStore(methods) {
593
+ return useStore(localStore, methods);
594
+ }
595
+
596
+ /* eslint-disable @typescript-eslint/ban-types */
597
+ const handlerDecorator = (handler) => {
598
+ return handlerDecorator._impl(handler);
599
+ };
600
+ handlerDecorator._impl = (handler) => handler;
601
+ handlerDecorator.setup = (impl) => {
602
+ handlerDecorator._impl = impl;
603
+ };
604
+
605
+ function useEmitterWithActions(eventBus, type) {
606
+ const cache = useRef({});
607
+ return useMemo(() => new Proxy({}, {
608
+ get(_, actionType) {
609
+ cache.current ||= {};
610
+ cache.current[actionType] ||= action => eventBus.fire(type, { ...(action ?? {}), type: actionType });
611
+ return cache.current[actionType];
612
+ }
613
+ }), [eventBus, type]);
614
+ }
615
+
472
616
  const defaultEventBus = new EventBus();
473
617
 
474
618
  const useDialogManager = () => useEmitterWithActions(defaultEventBus.emitter, 'dialog');
@@ -562,15 +706,48 @@
562
706
  }, [method, href]);
563
707
 
564
708
  /** @deprecated */
565
- const LinkButton = JSX(({ disabled, children, method = 'LINK', href, ...rest }) => {
709
+ const LinkButton = JSX(({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
566
710
  const handleFormSubmit = useFormSubmit({ method, href });
711
+ const linksStore = useLocalStore();
712
+ saveLinksToStore({ linksStore, href, id, additionalHrefs });
713
+ const adjustedHref = additionalHrefs
714
+ ? (linksStore.links || []).find((store) => store.id === id)?.lastLink
715
+ : href;
567
716
  const link = useLink();
568
- const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
717
+ const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
569
718
  const buttonInner = children ?? jsx(ButtonInner, { ...adjustedProps });
570
719
  return disabled ? (jsx(DisabledButton, { ...adjustedProps, children: buttonInner })) : (jsx(RegularButton, { ...adjustedProps, children: buttonInner }));
571
720
  });
572
721
  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 })));
573
722
  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 })));
723
+ const getRandomHref = (href = '', additionalHrefs = []) => {
724
+ const hrefs = [href, ...additionalHrefs];
725
+ return hrefs[Math.floor(Math.random() * hrefs.length)];
726
+ };
727
+ // Отсчитываем 7 длей с текущей даты
728
+ const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
729
+ // Сохраняем или заменяем рандомную ссылку в localStorage
730
+ const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }) => {
731
+ const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
732
+ // Если хранилища вообще нет
733
+ if (!linksStore.links) {
734
+ linksStore.links = [];
735
+ }
736
+ if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
737
+ // Получаем рандомную ссылку
738
+ const randomHref = getRandomHref(href, additionalHrefs);
739
+ // При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
740
+ const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
741
+ // Добавляем новый элемент
742
+ updatedLinks.push({
743
+ id: id ?? '',
744
+ lastLink: randomHref,
745
+ nextDueAt: getTimeAfter7days(),
746
+ });
747
+ // Добавляем это все в хранилище
748
+ linksStore.links = updatedLinks;
749
+ }
750
+ };
574
751
 
575
752
  // TODO Заменить LinkButton на Button и применить RoundedIcon
576
753
  function renderBackwardButton({ version, handleClick, text = 'Вернуться назад', alwaysVisible = false, }) {
@@ -1376,150 +1553,6 @@
1376
1553
  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" })] }) }));
1377
1554
  });
1378
1555
 
1379
- function copy(source, target) {
1380
- for (const [k, v] of source.entries()) {
1381
- if (v !== null && v !== undefined) {
1382
- target.setItem(k, v);
1383
- }
1384
- else {
1385
- target.removeItem(k);
1386
- }
1387
- }
1388
- }
1389
-
1390
- function replicate(primary, secondary) {
1391
- copy(primary, secondary);
1392
- copy(secondary, primary);
1393
- return primary.bus.watch(({ type, event }) => {
1394
- if (event !== null && event !== undefined) {
1395
- secondary.setItem(type, event);
1396
- }
1397
- else {
1398
- secondary.removeItem(type);
1399
- }
1400
- });
1401
- }
1402
-
1403
- class StorageAdapter {
1404
- storage;
1405
- bus;
1406
- get size() {
1407
- return this.storage?.length ?? 0;
1408
- }
1409
- constructor(storage, bus = new EventBus()) {
1410
- this.storage = storage;
1411
- this.bus = bus;
1412
- }
1413
- hasItem(key) {
1414
- return Boolean(this.storage?.getItem(String(key)));
1415
- }
1416
- getItem(key) {
1417
- const _ = this.storage?.getItem(String(key)) ?? null;
1418
- try {
1419
- return JSON.parse(String(_));
1420
- }
1421
- catch (ex) {
1422
- return null;
1423
- }
1424
- }
1425
- entries() {
1426
- return Array.from({ length: this.size }, (_, i) => {
1427
- const k = String(this.storage?.key(i));
1428
- return [k, this.getItem(k)];
1429
- });
1430
- }
1431
- setItem(key, value) {
1432
- if (value !== null) {
1433
- this.storage?.setItem(String(key), JSON.stringify(value));
1434
- }
1435
- else {
1436
- this.storage?.removeItem(String(key));
1437
- }
1438
- this.bus?.subject(key, value);
1439
- }
1440
- removeItem(key) {
1441
- this.storage?.removeItem(String(key));
1442
- this.bus?.subject(key, null);
1443
- }
1444
- }
1445
-
1446
- class Store {
1447
- bus;
1448
- store = new Map();
1449
- get size() {
1450
- return this.store.size;
1451
- }
1452
- constructor(bus = new EventBus()) {
1453
- this.bus = bus;
1454
- }
1455
- hasItem(key) {
1456
- return this.store.has(key);
1457
- }
1458
- getItem(key) {
1459
- return this.store.get(key);
1460
- }
1461
- entries() {
1462
- return this.store.entries();
1463
- }
1464
- setItem(key, value) {
1465
- this.store.set(key, value);
1466
- this.bus.subject(key, value);
1467
- }
1468
- removeItem(key) {
1469
- this.store.delete(key);
1470
- this.bus.subject(key, null);
1471
- }
1472
- }
1473
-
1474
- function useRerender() {
1475
- const [, setCount] = useState(0);
1476
- return useCallback(() => setCount(_ => (_ + 1) % (1 << 16)), []);
1477
- }
1478
-
1479
- const DEFAULT_METHODS = {};
1480
- /**
1481
- * MobX like reactivity (simplified).
1482
- * Can be used to migrate from Redux/MobX or something else
1483
- *
1484
- * @param store
1485
- * @returns reactive proxy backed by store
1486
- */
1487
- function useStore(store, methods = DEFAULT_METHODS) {
1488
- const deps = useRef(null);
1489
- const render = useRerender();
1490
- useEffect(() => store.bus.watch(ev => {
1491
- if (deps.current?.has(String(ev.type))) {
1492
- render();
1493
- }
1494
- }), [store, render]);
1495
- return useMemo(() => new Proxy(methods, {
1496
- get(_, key) {
1497
- deps.current ||= new Set();
1498
- deps.current.add(key);
1499
- return store.getItem(key);
1500
- },
1501
- has(_, key) {
1502
- deps.current ||= new Set();
1503
- deps.current.add(key);
1504
- return store.hasItem(key);
1505
- },
1506
- set(_, key, value) {
1507
- store.setItem(key, value);
1508
- return true;
1509
- },
1510
- deleteProperty(_, key) {
1511
- store.removeItem(key);
1512
- return true;
1513
- }
1514
- }), [store]);
1515
- }
1516
-
1517
- const localStore = new Store(); // localStorage cache
1518
- replicate(localStore, new StorageAdapter(globalThis?.localStorage));
1519
- function useLocalStore(methods) {
1520
- return useStore(localStore, methods);
1521
- }
1522
-
1523
1556
  const sessionStore = new Store(); // sessionStorage cache
1524
1557
  replicate(sessionStore, new StorageAdapter(globalThis?.sessionStorage));
1525
1558
  function useSessionStore() {
@@ -14380,7 +14413,7 @@
14380
14413
  slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
14381
14414
  });
14382
14415
 
14383
- const packageVersion = "0.14.1025";
14416
+ const packageVersion = "0.14.1026";
14384
14417
 
14385
14418
  exports.Blocks = Blocks;
14386
14419
  exports.ContentPage = ContentPage;