@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
@@ -14,6 +14,8 @@ export declare type Target = '' | '_self' | '_blank' | '_parent' | '_top';
14
14
  export declare type HrefProps = {
15
15
  /** @title URL (href) */
16
16
  href?: string;
17
+ /** @title Дополнительные ссылки для A/B-тестирования */
18
+ additionalHrefs?: string[];
17
19
  };
18
20
  export declare type LinkCommonProps = HrefProps & {
19
21
  /** @default "" */
@@ -20,4 +20,15 @@ export interface LinkButtonContent extends ButtonCommonContent {
20
20
  iconRight?: Picture;
21
21
  /** @title Верхний текст */
22
22
  aboveText?: string;
23
+ /** @title Уникальный идентификатор кнопки */
24
+ id?: string;
23
25
  }
26
+ declare type LinkStoreItem = {
27
+ id: string;
28
+ lastLink: string;
29
+ nextDueAt: number;
30
+ };
31
+ export declare type LinkStoreSlice = {
32
+ links: LinkStoreItem[] | null;
33
+ };
34
+ export {};
@@ -14,6 +14,8 @@ export declare type Target = '' | '_self' | '_blank' | '_parent' | '_top';
14
14
  export declare type HrefProps = {
15
15
  /** @title URL (href) */
16
16
  href?: string;
17
+ /** @title Дополнительные ссылки для A/B-тестирования */
18
+ additionalHrefs?: string[];
17
19
  };
18
20
  export declare type LinkCommonProps = HrefProps & {
19
21
  /** @default "" */
@@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
2
2
  exports.LinkButton = void 0;
3
3
  const jsx_runtime_1 = require("@redneckz/uni-jsx/jsx-runtime");
4
4
  const uni_jsx_1 = require("@redneckz/uni-jsx");
5
+ const useLocalStore_1 = require("@redneckz/uni-jsx/lib/Store/useLocalStore");
5
6
  const useLink_1 = require("../../hooks/useLink");
6
7
  const dataAttributes_1 = require("../../utils/dataAttributes");
7
8
  const ButtonInner_1 = require("./ButtonInner");
@@ -9,13 +10,46 @@ const getDisabledButtonClasses_1 = require("./getDisabledButtonClasses");
9
10
  const getRegularButtonClasses_1 = require("./getRegularButtonClasses");
10
11
  const useFormSubmit_1 = require("./useFormSubmit");
11
12
  /** @deprecated */
12
- exports.LinkButton = (0, uni_jsx_1.JSX)(({ disabled, children, method = 'LINK', href, ...rest }) => {
13
+ exports.LinkButton = (0, uni_jsx_1.JSX)(({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
13
14
  const handleFormSubmit = (0, useFormSubmit_1.useFormSubmit)({ method, href });
15
+ const linksStore = (0, useLocalStore_1.useLocalStore)();
16
+ saveLinksToStore({ linksStore, href, id, additionalHrefs });
17
+ const adjustedHref = additionalHrefs
18
+ ? (linksStore.links || []).find((store) => store.id === id)?.lastLink
19
+ : href;
14
20
  const link = (0, useLink_1.useLink)();
15
- const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
21
+ const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
16
22
  const buttonInner = children ?? (0, jsx_runtime_1.jsx)(ButtonInner_1.ButtonInner, { ...adjustedProps });
17
23
  return disabled ? ((0, jsx_runtime_1.jsx)(DisabledButton, { ...adjustedProps, children: buttonInner })) : ((0, jsx_runtime_1.jsx)(RegularButton, { ...adjustedProps, children: buttonInner }));
18
24
  });
19
25
  const RegularButton = (0, uni_jsx_1.JSX)(({ className = '', href, rel, target, ariaLabel, version, rounded, onClick, type, data, children, text, }) => ((0, jsx_runtime_1.jsx)("a", { className: (0, getRegularButtonClasses_1.getRegularButtonClasses)({ className, version, rounded }), href: href, rel: rel, target: target, "aria-label": ariaLabel || `Ссылка на ${text}`, role: href ? 'link' : 'button', onClick: onClick, type: type, ...(0, dataAttributes_1.getAspectsAttributes)(data), children: children })));
20
26
  const DisabledButton = (0, uni_jsx_1.JSX)(({ className, ariaLabel, version, rounded, children }) => ((0, jsx_runtime_1.jsx)("button", { type: "button", "aria-disabled": "true", "aria-label": ariaLabel, tabIndex: -1, className: (0, getDisabledButtonClasses_1.getDisabledButtonClasses)({ className, rounded, version }), children: children })));
27
+ const getRandomHref = (href = '', additionalHrefs = []) => {
28
+ const hrefs = [href, ...additionalHrefs];
29
+ return hrefs[Math.floor(Math.random() * hrefs.length)];
30
+ };
31
+ // Отсчитываем 7 длей с текущей даты
32
+ const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
33
+ // Сохраняем или заменяем рандомную ссылку в localStorage
34
+ const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }) => {
35
+ const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
36
+ // Если хранилища вообще нет
37
+ if (!linksStore.links) {
38
+ linksStore.links = [];
39
+ }
40
+ if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
41
+ // Получаем рандомную ссылку
42
+ const randomHref = getRandomHref(href, additionalHrefs);
43
+ // При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
44
+ const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
45
+ // Добавляем новый элемент
46
+ updatedLinks.push({
47
+ id: id ?? '',
48
+ lastLink: randomHref,
49
+ nextDueAt: getTimeAfter7days(),
50
+ });
51
+ // Добавляем это все в хранилище
52
+ linksStore.links = updatedLinks;
53
+ }
54
+ };
21
55
  //# sourceMappingURL=LinkButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LinkButton.js","sourceRoot":"","sources":["../../../src/ui-kit/LinkButton/LinkButton.tsx"],"names":[],"mappings":";;;AAAA,+CAAwC;AACxC,iDAA8C;AAC9C,+DAAkE;AAClE,+CAA4C;AAC5C,yEAAsE;AACtE,uEAAoE;AAEpE,mDAAgD;AAEhD,kBAAkB;AACL,QAAA,UAAU,GAAG,IAAA,aAAG,EAC3B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,M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;QAExE,0BAA0B;QAC1B,YAAY,CAAC,IAAI,CAAC;YAChB,EAAE,EAAE,EAAE,IAAI,EAAE;YACZ,QAAQ,EAAE,UAAU;YACpB,SAAS,EAAE,iBAAiB,EAAE;SAC/B,CAAC,CAAC;QACH,gCAAgC;QAChC,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC;KACjC;AACH,CAAC,CAAC"}
@@ -20,4 +20,15 @@ export interface LinkButtonContent extends ButtonCommonContent {
20
20
  iconRight?: Picture;
21
21
  /** @title Верхний текст */
22
22
  aboveText?: string;
23
+ /** @title Уникальный идентификатор кнопки */
24
+ id?: string;
23
25
  }
26
+ declare type LinkStoreItem = {
27
+ id: string;
28
+ lastLink: string;
29
+ nextDueAt: number;
30
+ };
31
+ export declare type LinkStoreSlice = {
32
+ links: LinkStoreItem[] | null;
33
+ };
34
+ export {};
@@ -1,5 +1,6 @@
1
1
  import '../../setup-fixture';
2
2
  declare const _default: {
3
3
  default: any;
4
+ abTesting: any;
4
5
  };
5
6
  export default _default;
@@ -14,6 +14,8 @@ export declare type Target = '' | '_self' | '_blank' | '_parent' | '_top';
14
14
  export declare type HrefProps = {
15
15
  /** @title URL (href) */
16
16
  href?: string;
17
+ /** @title Дополнительные ссылки для A/B-тестирования */
18
+ additionalHrefs?: string[];
17
19
  };
18
20
  export declare type LinkCommonProps = HrefProps & {
19
21
  /** @default "" */
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "@redneckz/uni-jsx/jsx-runtime";
2
2
  import { JSX } from '@redneckz/uni-jsx';
3
+ import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
3
4
  import { useLink } from '../../hooks/useLink.js';
4
5
  import { getAspectsAttributes } from '../../utils/dataAttributes.js';
5
6
  import { ButtonInner } from './ButtonInner.js';
@@ -7,13 +8,46 @@ import { getDisabledButtonClasses } from './getDisabledButtonClasses.js';
7
8
  import { getRegularButtonClasses } from './getRegularButtonClasses.js';
8
9
  import { useFormSubmit } from './useFormSubmit.js';
9
10
  /** @deprecated */
10
- export const LinkButton = JSX(({ disabled, children, method = 'LINK', href, ...rest }) => {
11
+ export const LinkButton = JSX(({ disabled, children, method = 'LINK', href, id, additionalHrefs, ...rest }) => {
11
12
  const handleFormSubmit = useFormSubmit({ method, href });
13
+ const linksStore = useLocalStore();
14
+ saveLinksToStore({ linksStore, href, id, additionalHrefs });
15
+ const adjustedHref = additionalHrefs
16
+ ? (linksStore.links || []).find((store) => store.id === id)?.lastLink
17
+ : href;
12
18
  const link = useLink();
13
- const adjustedProps = link({ onClick: handleFormSubmit, href, ...rest });
19
+ const adjustedProps = link({ onClick: handleFormSubmit, href: adjustedHref, ...rest });
14
20
  const buttonInner = children ?? _jsx(ButtonInner, { ...adjustedProps });
15
21
  return disabled ? (_jsx(DisabledButton, { ...adjustedProps, children: buttonInner })) : (_jsx(RegularButton, { ...adjustedProps, children: buttonInner }));
16
22
  });
17
23
  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 })));
18
24
  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 })));
25
+ const getRandomHref = (href = '', additionalHrefs = []) => {
26
+ const hrefs = [href, ...additionalHrefs];
27
+ return hrefs[Math.floor(Math.random() * hrefs.length)];
28
+ };
29
+ // Отсчитываем 7 длей с текущей даты
30
+ const getTimeAfter7days = () => Date.now() + 7 * 24 * 60 * 60 * 1000;
31
+ // Сохраняем или заменяем рандомную ссылку в localStorage
32
+ const saveLinksToStore = ({ linksStore, id, href, additionalHrefs }) => {
33
+ const buttonLinkStore = (linksStore.links || []).find((store) => store.id === id);
34
+ // Если хранилища вообще нет
35
+ if (!linksStore.links) {
36
+ linksStore.links = [];
37
+ }
38
+ if ((!buttonLinkStore || buttonLinkStore.nextDueAt <= Date.now()) && additionalHrefs) {
39
+ // Получаем рандомную ссылку
40
+ const randomHref = getRandomHref(href, additionalHrefs);
41
+ // При наличии ссылки для этой кнопки в хранилище удаляем этот элемент из массива ссылок
42
+ const updatedLinks = linksStore.links?.filter((item) => item.id !== id);
43
+ // Добавляем новый элемент
44
+ updatedLinks.push({
45
+ id: id ?? '',
46
+ lastLink: randomHref,
47
+ nextDueAt: getTimeAfter7days(),
48
+ });
49
+ // Добавляем это все в хранилище
50
+ linksStore.links = updatedLinks;
51
+ }
52
+ };
19
53
  //# sourceMappingURL=LinkButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LinkButton.js","sourceRoot":"","sources":["../../../src/ui-kit/LinkButton/LinkButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,kBAAkB;AAClB,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAC3B,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE;IACzD,MAAM,gBAAgB,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAEzD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MA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0BAA0B;QAC1B,YAAY,CAAC,IAAI,CAAC;YAChB,EAAE,EAAE,EAAE,IAAI,EAAE;YACZ,QAAQ,EAAE,UAAU;YACpB,SAAS,EAAE,iBAAiB,EAAE;SAC/B,CAAC,CAAC;QACH,gCAAgC;QAChC,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC;KACjC;AACH,CAAC,CAAC"}
@@ -20,4 +20,15 @@ export interface LinkButtonContent extends ButtonCommonContent {
20
20
  iconRight?: Picture;
21
21
  /** @title Верхний текст */
22
22
  aboveText?: string;
23
+ /** @title Уникальный идентификатор кнопки */
24
+ id?: string;
23
25
  }
26
+ declare type LinkStoreItem = {
27
+ id: string;
28
+ lastLink: string;
29
+ nextDueAt: number;
30
+ };
31
+ export declare type LinkStoreSlice = {
32
+ links: LinkStoreItem[] | null;
33
+ };
34
+ export {};
@@ -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() {
@@ -14150,7 +14183,7 @@
14150
14183
  slots: () => [HEADER_SLOT, FOOTER_SLOT, STICKY_FOOTER_SLOT],
14151
14184
  });
14152
14185
 
14153
- const packageVersion = "0.14.1025";
14186
+ const packageVersion = "0.14.1026";
14154
14187
 
14155
14188
  exports.Blocks = Blocks;
14156
14189
  exports.ContentPage = ContentPage;