@redneckz/wildless-cms-uni-blocks 0.8.8 → 0.8.9
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/bundle/EventBus/EventBus.d.ts +1 -4
- package/bundle/EventBus/defaultEventBus.d.ts +7 -0
- package/bundle/blocks.schema.json +1 -1
- package/bundle/bundle.umd.js +31 -66
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/ButtonBlock/ButtonBlockContent.d.ts +5 -1
- package/bundle/hooks/useRouter.d.ts +6 -2
- package/bundle/services/BlockRouter/BlockRouter.d.ts +3 -22
- package/bundle/services/BlockRouter/blockRouterEventBus.d.ts +11 -0
- package/bundle/services/BlockRouter/useBlockIntersectionObserver.d.ts +1 -2
- package/bundle/services/BlockRouter/useBlockRouterProvider.d.ts +1 -2
- package/dist/EventBus/EventBus.d.ts +1 -4
- package/dist/EventBus/EventBus.js +0 -1
- package/dist/EventBus/EventBus.js.map +1 -1
- package/dist/EventBus/defaultEventBus.d.ts +7 -0
- package/dist/EventBus/defaultEventBus.js +5 -0
- package/dist/EventBus/defaultEventBus.js.map +1 -0
- package/dist/components/ButtonBlock/ButtonBlock.js +2 -1
- package/dist/components/ButtonBlock/ButtonBlock.js.map +1 -1
- package/dist/components/ButtonBlock/ButtonBlockContent.d.ts +5 -1
- package/dist/components/Tabs/Tabs.js +4 -4
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/hooks/useLink.js +2 -3
- package/dist/hooks/useLink.js.map +1 -1
- package/dist/hooks/useRouter.d.ts +6 -2
- package/dist/hooks/useRouter.js.map +1 -1
- package/dist/services/BlockRouter/BlockRouter.d.ts +3 -22
- package/dist/services/BlockRouter/BlockRouter.js +11 -30
- package/dist/services/BlockRouter/BlockRouter.js.map +1 -1
- package/dist/services/BlockRouter/blockRouterEventBus.d.ts +11 -0
- package/dist/services/BlockRouter/blockRouterEventBus.js +5 -0
- package/dist/services/BlockRouter/blockRouterEventBus.js.map +1 -0
- package/dist/services/BlockRouter/useBlockIntersectionObserver.d.ts +1 -2
- package/dist/services/BlockRouter/useBlockIntersectionObserver.js +5 -16
- package/dist/services/BlockRouter/useBlockIntersectionObserver.js.map +1 -1
- package/dist/services/BlockRouter/useBlockRouterProvider.d.ts +1 -2
- package/dist/services/BlockRouter/useBlockRouterProvider.js +11 -12
- package/dist/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
- package/dist/ui-kit/BlockWrapper.js +2 -2
- package/dist/ui-kit/BlockWrapper.js.map +1 -1
- package/lib/EventBus/EventBus.d.ts +1 -4
- package/lib/EventBus/EventBus.js +0 -1
- package/lib/EventBus/EventBus.js.map +1 -1
- package/lib/EventBus/defaultEventBus.d.ts +7 -0
- package/lib/EventBus/defaultEventBus.js +3 -0
- package/lib/EventBus/defaultEventBus.js.map +1 -0
- package/lib/common.css +1 -1
- package/lib/components/ButtonBlock/ButtonBlock.js +2 -1
- package/lib/components/ButtonBlock/ButtonBlock.js.map +1 -1
- package/lib/components/ButtonBlock/ButtonBlockContent.d.ts +5 -1
- package/lib/components/Tabs/Tabs.js +4 -4
- package/lib/components/Tabs/Tabs.js.map +1 -1
- package/lib/hooks/useLink.js +2 -3
- package/lib/hooks/useLink.js.map +1 -1
- package/lib/hooks/useRouter.d.ts +6 -2
- package/lib/hooks/useRouter.js.map +1 -1
- package/lib/services/BlockRouter/BlockRouter.d.ts +3 -22
- package/lib/services/BlockRouter/BlockRouter.js +8 -28
- package/lib/services/BlockRouter/BlockRouter.js.map +1 -1
- package/lib/services/BlockRouter/blockRouterEventBus.d.ts +11 -0
- package/lib/services/BlockRouter/blockRouterEventBus.js +3 -0
- package/lib/services/BlockRouter/blockRouterEventBus.js.map +1 -0
- package/lib/services/BlockRouter/useBlockIntersectionObserver.d.ts +1 -2
- package/lib/services/BlockRouter/useBlockIntersectionObserver.js +6 -17
- package/lib/services/BlockRouter/useBlockIntersectionObserver.js.map +1 -1
- package/lib/services/BlockRouter/useBlockRouterProvider.d.ts +1 -2
- package/lib/services/BlockRouter/useBlockRouterProvider.js +12 -13
- package/lib/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
- package/lib/ui-kit/BlockWrapper.js +2 -2
- package/lib/ui-kit/BlockWrapper.js.map +1 -1
- package/mobile/bundle/EventBus/EventBus.d.ts +1 -4
- package/mobile/bundle/EventBus/defaultEventBus.d.ts +7 -0
- package/mobile/bundle/bundle.umd.js +27 -62
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/ButtonBlock/ButtonBlockContent.d.ts +5 -1
- package/mobile/bundle/hooks/useRouter.d.ts +6 -2
- package/mobile/bundle/services/BlockRouter/BlockRouter.d.ts +3 -22
- package/mobile/bundle/services/BlockRouter/blockRouterEventBus.d.ts +11 -0
- package/mobile/bundle/services/BlockRouter/useBlockIntersectionObserver.d.ts +1 -2
- package/mobile/bundle/services/BlockRouter/useBlockRouterProvider.d.ts +1 -2
- package/mobile/dist/EventBus/EventBus.d.ts +1 -4
- package/mobile/dist/EventBus/EventBus.js +0 -1
- package/mobile/dist/EventBus/EventBus.js.map +1 -1
- package/mobile/dist/EventBus/defaultEventBus.d.ts +7 -0
- package/mobile/dist/EventBus/defaultEventBus.js +5 -0
- package/mobile/dist/EventBus/defaultEventBus.js.map +1 -0
- package/mobile/dist/components/ButtonBlock/ButtonBlock.js +2 -1
- package/mobile/dist/components/ButtonBlock/ButtonBlock.js.map +1 -1
- package/mobile/dist/components/ButtonBlock/ButtonBlockContent.d.ts +5 -1
- package/mobile/dist/components/Tabs/Tabs.js +4 -4
- package/mobile/dist/components/Tabs/Tabs.js.map +1 -1
- package/mobile/dist/hooks/useLink.js +2 -3
- package/mobile/dist/hooks/useLink.js.map +1 -1
- package/mobile/dist/hooks/useRouter.d.ts +6 -2
- package/mobile/dist/hooks/useRouter.js.map +1 -1
- package/mobile/dist/services/BlockRouter/BlockRouter.d.ts +3 -22
- package/mobile/dist/services/BlockRouter/BlockRouter.js +11 -30
- package/mobile/dist/services/BlockRouter/BlockRouter.js.map +1 -1
- package/mobile/dist/services/BlockRouter/blockRouterEventBus.d.ts +11 -0
- package/mobile/dist/services/BlockRouter/blockRouterEventBus.js +5 -0
- package/mobile/dist/services/BlockRouter/blockRouterEventBus.js.map +1 -0
- package/mobile/dist/services/BlockRouter/useBlockIntersectionObserver.d.ts +1 -2
- package/mobile/dist/services/BlockRouter/useBlockIntersectionObserver.js +5 -16
- package/mobile/dist/services/BlockRouter/useBlockIntersectionObserver.js.map +1 -1
- package/mobile/dist/services/BlockRouter/useBlockRouterProvider.d.ts +1 -2
- package/mobile/dist/services/BlockRouter/useBlockRouterProvider.js +11 -12
- package/mobile/dist/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
- package/mobile/dist/ui-kit/BlockWrapper.js +2 -2
- package/mobile/dist/ui-kit/BlockWrapper.js.map +1 -1
- package/mobile/lib/EventBus/EventBus.d.ts +1 -4
- package/mobile/lib/EventBus/EventBus.js +0 -1
- package/mobile/lib/EventBus/EventBus.js.map +1 -1
- package/mobile/lib/EventBus/defaultEventBus.d.ts +7 -0
- package/mobile/lib/EventBus/defaultEventBus.js +3 -0
- package/mobile/lib/EventBus/defaultEventBus.js.map +1 -0
- package/mobile/lib/components/ButtonBlock/ButtonBlock.js +2 -1
- package/mobile/lib/components/ButtonBlock/ButtonBlock.js.map +1 -1
- package/mobile/lib/components/ButtonBlock/ButtonBlockContent.d.ts +5 -1
- package/mobile/lib/components/Tabs/Tabs.js +4 -4
- package/mobile/lib/components/Tabs/Tabs.js.map +1 -1
- package/mobile/lib/hooks/useLink.js +2 -3
- package/mobile/lib/hooks/useLink.js.map +1 -1
- package/mobile/lib/hooks/useRouter.d.ts +6 -2
- package/mobile/lib/hooks/useRouter.js.map +1 -1
- package/mobile/lib/services/BlockRouter/BlockRouter.d.ts +3 -22
- package/mobile/lib/services/BlockRouter/BlockRouter.js +8 -28
- package/mobile/lib/services/BlockRouter/BlockRouter.js.map +1 -1
- package/mobile/lib/services/BlockRouter/blockRouterEventBus.d.ts +11 -0
- package/mobile/lib/services/BlockRouter/blockRouterEventBus.js +3 -0
- package/mobile/lib/services/BlockRouter/blockRouterEventBus.js.map +1 -0
- package/mobile/lib/services/BlockRouter/useBlockIntersectionObserver.d.ts +1 -2
- package/mobile/lib/services/BlockRouter/useBlockIntersectionObserver.js +6 -17
- package/mobile/lib/services/BlockRouter/useBlockIntersectionObserver.js.map +1 -1
- package/mobile/lib/services/BlockRouter/useBlockRouterProvider.d.ts +1 -2
- package/mobile/lib/services/BlockRouter/useBlockRouterProvider.js +12 -13
- package/mobile/lib/services/BlockRouter/useBlockRouterProvider.js.map +1 -1
- package/mobile/lib/ui-kit/BlockWrapper.js +2 -2
- package/mobile/lib/ui-kit/BlockWrapper.js.map +1 -1
- package/mobile/src/EventBus/EventBus.ts +1 -7
- package/mobile/src/EventBus/defaultEventBus.ts +8 -0
- package/mobile/src/components/ButtonBlock/ButtonBlock.example.json +2 -2
- package/mobile/src/components/ButtonBlock/ButtonBlock.tsx +5 -2
- package/mobile/src/components/ButtonBlock/ButtonBlockContent.ts +5 -1
- package/mobile/src/components/Tabs/Tabs.tsx +4 -4
- package/mobile/src/hooks/useLink.ts +2 -3
- package/mobile/src/hooks/useRouter.ts +6 -2
- package/mobile/src/services/BlockRouter/BlockRouter.ts +8 -47
- package/mobile/src/services/BlockRouter/blockRouterEventBus.ts +13 -0
- package/mobile/src/services/BlockRouter/useBlockIntersectionObserver.ts +6 -23
- package/mobile/src/services/BlockRouter/useBlockRouterProvider.ts +13 -19
- package/mobile/src/ui-kit/BlockWrapper.tsx +2 -2
- package/package.json +1 -1
- package/src/EventBus/EventBus.ts +1 -7
- package/src/EventBus/defaultEventBus.ts +8 -0
- package/src/components/ButtonBlock/ButtonBlock.example.json +2 -2
- package/src/components/ButtonBlock/ButtonBlock.tsx +5 -2
- package/src/components/ButtonBlock/ButtonBlockContent.ts +5 -1
- package/src/components/Tabs/Tabs.tsx +4 -4
- package/src/hooks/useLink.ts +2 -3
- package/src/hooks/useRouter.ts +6 -2
- package/src/services/BlockRouter/BlockRouter.ts +8 -47
- package/src/services/BlockRouter/blockRouterEventBus.ts +13 -0
- package/src/services/BlockRouter/useBlockIntersectionObserver.ts +6 -23
- package/src/services/BlockRouter/useBlockRouterProvider.ts +13 -19
- package/src/ui-kit/BlockWrapper.tsx +2 -2
- package/bundle/EventBus/EventMap.d.ts +0 -4
- package/bundle/services/BlockRouter/useBlockRouter.d.ts +0 -2
- package/dist/EventBus/EventMap.d.ts +0 -4
- package/dist/EventBus/EventMap.js +0 -2
- package/dist/EventBus/EventMap.js.map +0 -1
- package/dist/services/BlockRouter/useBlockRouter.d.ts +0 -2
- package/dist/services/BlockRouter/useBlockRouter.js +0 -8
- package/dist/services/BlockRouter/useBlockRouter.js.map +0 -1
- package/lib/EventBus/EventMap.d.ts +0 -4
- package/lib/EventBus/EventMap.js +0 -2
- package/lib/EventBus/EventMap.js.map +0 -1
- package/lib/services/BlockRouter/useBlockRouter.d.ts +0 -2
- package/lib/services/BlockRouter/useBlockRouter.js +0 -5
- package/lib/services/BlockRouter/useBlockRouter.js.map +0 -1
- package/mobile/bundle/EventBus/EventMap.d.ts +0 -4
- package/mobile/bundle/services/BlockRouter/useBlockRouter.d.ts +0 -2
- package/mobile/dist/EventBus/EventMap.d.ts +0 -4
- package/mobile/dist/EventBus/EventMap.js +0 -2
- package/mobile/dist/EventBus/EventMap.js.map +0 -1
- package/mobile/dist/services/BlockRouter/useBlockRouter.d.ts +0 -2
- package/mobile/dist/services/BlockRouter/useBlockRouter.js +0 -8
- package/mobile/dist/services/BlockRouter/useBlockRouter.js.map +0 -1
- package/mobile/lib/EventBus/EventMap.d.ts +0 -4
- package/mobile/lib/EventBus/EventMap.js +0 -2
- package/mobile/lib/EventBus/EventMap.js.map +0 -1
- package/mobile/lib/services/BlockRouter/useBlockRouter.d.ts +0 -2
- package/mobile/lib/services/BlockRouter/useBlockRouter.js +0 -5
- package/mobile/lib/services/BlockRouter/useBlockRouter.js.map +0 -1
- package/mobile/src/EventBus/EventMap.ts +0 -5
- package/mobile/src/services/BlockRouter/useBlockRouter.ts +0 -5
- package/src/EventBus/EventMap.ts +0 -5
- package/src/services/BlockRouter/useBlockRouter.ts +0 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventBus } from '../../EventBus/EventBus';
|
|
2
|
+
import type { BlockDef } from '../../model/ContentPageDef';
|
|
3
|
+
export interface BlockIntersectionEvent {
|
|
4
|
+
block: BlockDef;
|
|
5
|
+
intersection: IntersectionObserverEntry;
|
|
6
|
+
}
|
|
7
|
+
interface EventMap {
|
|
8
|
+
intersection: BlockIntersectionEvent;
|
|
9
|
+
}
|
|
10
|
+
export declare const blockRouterEventBus: EventBus<EventMap>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockRouterEventBus.js","sourceRoot":"","sources":["../../../src/services/BlockRouter/blockRouterEventBus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAYnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,QAAQ,EAAY,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { BlockDef } from '../../model/ContentPageDef';
|
|
2
|
-
|
|
3
|
-
export declare function useBlockIntersectionObserver(block?: BlockDef, router?: BlockRouter): {
|
|
2
|
+
export declare function useBlockIntersectionObserver(block?: BlockDef): {
|
|
4
3
|
current: Element | null;
|
|
5
4
|
};
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
import { useCallback
|
|
1
|
+
import { useCallback } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useIntersectionObserver } from '../../hooks/useIntersectionObserver.js';
|
|
3
|
-
import {
|
|
4
|
-
export function useBlockIntersectionObserver(block
|
|
3
|
+
import { blockRouterEventBus } from './blockRouterEventBus.js';
|
|
4
|
+
export function useBlockIntersectionObserver(block) {
|
|
5
5
|
const observerCallback = useCallback((entries) => {
|
|
6
6
|
if (!block || !entries?.length) {
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
const intersection = entries[entries.length - 1];
|
|
10
|
-
|
|
11
|
-
}, [block
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (!ref.current) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
return router.eventBus.subscribe('goto', ({ anchor }) => {
|
|
18
|
-
if (ref.current && block?.anchor === anchor) {
|
|
19
|
-
ref.current.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}, [block, router]);
|
|
23
|
-
return ref;
|
|
10
|
+
blockRouterEventBus.fire('intersection', { block, intersection });
|
|
11
|
+
}, [block]);
|
|
12
|
+
return useIntersectionObserver(observerCallback, { sensitivity: 1 });
|
|
24
13
|
}
|
|
25
14
|
//# sourceMappingURL=useBlockIntersectionObserver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockIntersectionObserver.js","sourceRoot":"","sources":["../../../src/services/BlockRouter/useBlockIntersectionObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"useBlockIntersectionObserver.js","sourceRoot":"","sources":["../../../src/services/BlockRouter/useBlockIntersectionObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,UAAU,4BAA4B,CAAC,KAAgB;IAC3D,MAAM,gBAAgB,GAAG,WAAW,CAClC,CAAC,OAAoC,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE;YAC9B,OAAO;SACR;QAED,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjD,mBAAmB,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;IACpE,CAAC,EACD,CAAC,KAAK,CAAC,CACR,CAAC;IAEF,OAAO,uBAAuB,CAAC,gBAAgB,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function useBlockRouterProvider(router?: BlockRouter, scrollTarget?: EventTarget): void;
|
|
1
|
+
export declare function useBlockRouterProvider(scrollTarget?: EventTarget): void;
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { useEffect, useRef } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
|
+
import { useRouter } from '../../hooks/useRouter.js';
|
|
2
3
|
import { debounce } from '../../utils/debounce.js';
|
|
3
|
-
import {
|
|
4
|
+
import { trackBlock } from './BlockRouter.js';
|
|
5
|
+
import { blockRouterEventBus } from './blockRouterEventBus.js';
|
|
4
6
|
import { findActiveBlock } from './findActiveBlock.js';
|
|
5
7
|
const isScrolledEnough = () => globalThis.scrollY > (globalThis.innerHeight * 3) / 4;
|
|
6
|
-
export function useBlockRouterProvider(
|
|
8
|
+
export function useBlockRouterProvider(scrollTarget = globalThis) {
|
|
9
|
+
const router = useRouter();
|
|
7
10
|
const intersectionsMapRef = useRef(new Map());
|
|
8
|
-
useEffect(() =>
|
|
11
|
+
useEffect(() => blockRouterEventBus.subscribe('intersection', ({ block, intersection }) => {
|
|
9
12
|
if (intersectionsMapRef.current) {
|
|
10
13
|
intersectionsMapRef.current.set(block, intersection);
|
|
11
14
|
}
|
|
12
|
-
}), [
|
|
15
|
+
}), []);
|
|
13
16
|
useEffect(() => {
|
|
14
17
|
const handleScroll = debounce(() => {
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
if (isScrolledEnough()) {
|
|
19
|
+
const activeBlock = findActiveBlock([...(intersectionsMapRef.current || [])]);
|
|
20
|
+
trackBlock(router, activeBlock);
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
router.replace(activeBlock.anchor);
|
|
22
|
-
}
|
|
23
|
-
else if (!activeBlock) {
|
|
24
|
-
router.reset();
|
|
22
|
+
else {
|
|
23
|
+
trackBlock(router);
|
|
25
24
|
}
|
|
26
25
|
}, 100);
|
|
27
26
|
scrollTarget.addEventListener('scroll', handleScroll);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlockRouterProvider.js","sourceRoot":"","sources":["../../../src/services/BlockRouter/useBlockRouterProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"useBlockRouterProvider.js","sourceRoot":"","sources":["../../../src/services/BlockRouter/useBlockRouterProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,UAAU,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAErF,MAAM,UAAU,sBAAsB,CAAC,eAA4B,UAAU;IAC3E,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,MAAM,mBAAmB,GAAG,MAAM,CAA2C,IAAI,GAAG,EAAE,CAAC,CAAC;IAExF,SAAS,CACP,GAAG,EAAE,CACH,mBAAmB,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE;QACxE,IAAI,mBAAmB,CAAC,OAAO,EAAE;YAC/B,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SACtD;IACH,CAAC,CAAC,EACJ,EAAE,CACH,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,EAAE;YACjC,IAAI,gBAAgB,EAAE,EAAE;gBACtB,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,GAAG,CAAC,mBAAmB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC9E,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;aACjC;iBAAM;gBACL,UAAU,CAAC,MAAM,CAAC,CAAC;aACpB;QACH,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,YAAY,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAEtD,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,OAAO,EAAE,CAAC;YACvB,YAAY,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@redneckz/uni-jsx/jsx-runtime";
|
|
2
2
|
import { JSX } from '@redneckz/uni-jsx';
|
|
3
3
|
import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
4
|
-
import {
|
|
4
|
+
import { defaultEventBus } from '../EventBus/defaultEventBus.js';
|
|
5
5
|
import { useBlockIntersectionObserver } from '../services/BlockRouter/useBlockIntersectionObserver.js';
|
|
6
6
|
import { style } from '../utils/style.js';
|
|
7
7
|
export const blockStyles = {
|
|
@@ -15,7 +15,7 @@ export const BlockWrapper = JSX(({ className = '', version = 'primary', block, t
|
|
|
15
15
|
const Tag = tag;
|
|
16
16
|
const ref = useBlockIntersectionObserver(block);
|
|
17
17
|
const [isVisible, setVisible] = useState(true);
|
|
18
|
-
useEffect(() =>
|
|
18
|
+
useEffect(() => defaultEventBus.subscribe('tab', (event) => {
|
|
19
19
|
if (event.type === 'group') {
|
|
20
20
|
const hasSettings = block?.labels?.length || block?.anchor;
|
|
21
21
|
setVisible(event.label ? !hasSettings || Boolean(block?.labels?.includes(event.label)) : true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockWrapper.js","sourceRoot":"","sources":["../../src/ui-kit/BlockWrapper.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BlockWrapper.js","sourceRoot":"","sources":["../../src/ui-kit/BlockWrapper.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,sDAAsD,CAAC;AACpG,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAOvC,MAAM,CAAC,MAAM,WAAW,GAAiC;IACvD,OAAO,EAAE,4BAA4B;IACrC,SAAS,EAAE,4BAA4B;IACvC,IAAI,EAAE,mCAAmC;IACzC,WAAW,EAAE,kCAAkC;IAC/C,EAAE,EAAE,EAAE;CACP,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAC7B,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;IAClF,MAAM,GAAG,GAAQ,GAAG,CAAC;IAErB,MAAM,GAAG,GAAG,4BAA4B,CAAC,KAAK,CAAC,CAAC;IAEhD,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/C,SAAS,CACP,GAAG,EAAE,CACH,eAAe,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QACzC,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;YAC1B,MAAM,WAAW,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,KAAK,EAAE,MAAM,CAAC;YAC3D,UAAU,CACR,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CACnF,CAAC;SACH;aAAM;YACL,UAAU,CAAC,IAAI,CAAC,CAAC;SAClB;IACH,CAAC,CAAC,EACJ,CAAC,KAAK,CAAC,CACR,CAAC;IAEF,OAAO,SAAS,CAAC,CAAC,CAAC,CACjB,KAAC,GAAG,IACF,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KACtD,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KACxC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACpD,IAAI,EAAE,IAAI,YAET,QAAQ,GACL,CACP,CAAC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CACF,CAAC"}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type BaseEventMap = Record<string, any>;
|
|
4
|
-
|
|
5
|
-
export class EventBus<EM extends BaseEventMap> {
|
|
6
|
-
public static readonly inst = new EventBus<EventMap>();
|
|
7
|
-
|
|
1
|
+
export class EventBus<EM extends Record<string, any>> {
|
|
8
2
|
private subscribers: Partial<Record<keyof EM, Array<(ev: EM[keyof EM]) => void>>> = {};
|
|
9
3
|
private subjectsStateMap: Partial<EM> = {};
|
|
10
4
|
|
|
@@ -2,10 +2,13 @@ import { JSX } from '@redneckz/uni-jsx';
|
|
|
2
2
|
import type { UniBlockProps } from '../../model/JSXBlock';
|
|
3
3
|
import { BlockWrapper } from '../../ui-kit/BlockWrapper';
|
|
4
4
|
import { renderButtonsSection } from '../../ui-kit/Button/renderButtonsSection';
|
|
5
|
+
import { style } from '../../utils/style';
|
|
5
6
|
import type { ButtonBlockContent } from './ButtonBlockContent';
|
|
6
7
|
|
|
7
8
|
interface ButtonBlockProps extends ButtonBlockContent, UniBlockProps {}
|
|
8
9
|
|
|
9
|
-
export const ButtonBlock = JSX<ButtonBlockProps>(({ button, ...rest }) => (
|
|
10
|
-
<BlockWrapper {...rest}>
|
|
10
|
+
export const ButtonBlock = JSX<ButtonBlockProps>(({ button, className, ...rest }) => (
|
|
11
|
+
<BlockWrapper className={style('!bg-transparent', className)} {...rest}>
|
|
12
|
+
{renderButtonsSection([button])}
|
|
13
|
+
</BlockWrapper>
|
|
11
14
|
));
|
|
@@ -4,6 +4,10 @@ import type { ButtonWithIconProps } from '../../ui-kit/Button/ButtonProps';
|
|
|
4
4
|
* @title Блок Кнопка
|
|
5
5
|
*/
|
|
6
6
|
export interface ButtonBlockContent {
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* @title Кнопка
|
|
9
|
+
* @default {"icon": {"format": "webp", "size": { "width": 24, "height": 24 }},
|
|
10
|
+
* "iconRight": {"format": "webp", "size": { "width": 24, "height": 24 }}}
|
|
11
|
+
*/
|
|
8
12
|
button?: ButtonWithIconProps;
|
|
9
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSX } from '@redneckz/uni-jsx';
|
|
2
2
|
import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
3
|
-
import {
|
|
3
|
+
import { defaultEventBus } from '../../EventBus/defaultEventBus';
|
|
4
4
|
import type { UniBlockProps } from '../../model/JSXBlock';
|
|
5
5
|
import { BlockWrapper } from '../../ui-kit/BlockWrapper';
|
|
6
6
|
import { renderTab } from './renderTab';
|
|
@@ -21,7 +21,7 @@ export const Tabs = JSX<TabsBlockProps>((props) => {
|
|
|
21
21
|
|
|
22
22
|
useEffect(
|
|
23
23
|
() =>
|
|
24
|
-
|
|
24
|
+
defaultEventBus.subscribe('tab', (event) => {
|
|
25
25
|
const tab = tabs?.find(checkTab(event));
|
|
26
26
|
if (event.type === 'link' && tab) {
|
|
27
27
|
setCurrentTab(tab);
|
|
@@ -35,14 +35,14 @@ export const Tabs = JSX<TabsBlockProps>((props) => {
|
|
|
35
35
|
useEffect(
|
|
36
36
|
() =>
|
|
37
37
|
currentTab?.type === 'group'
|
|
38
|
-
?
|
|
38
|
+
? defaultEventBus.subject('tab', { type: currentTab.type, label: currentTab.ref })
|
|
39
39
|
: undefined,
|
|
40
40
|
[currentTab],
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
const handleClick = useCallback((selectedTab: TabData) => {
|
|
44
44
|
if (selectedTab?.type === 'group') {
|
|
45
|
-
|
|
45
|
+
defaultEventBus.fire('tab', { type: selectedTab.type, label: selectedTab.ref });
|
|
46
46
|
}
|
|
47
47
|
setCurrentTab(selectedTab);
|
|
48
48
|
}, []);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LinkProps } from '../model/LinkProps';
|
|
2
2
|
import { projectSettings } from '../ProjectSettings';
|
|
3
|
-
import {
|
|
3
|
+
import { gotoBlock } from '../services/BlockRouter/BlockRouter';
|
|
4
4
|
import { isHash, isLocalURL, joinPath } from '../utils/url';
|
|
5
5
|
import { handlerDecorator } from './handlerDecorator';
|
|
6
6
|
import { useRouter } from './useRouter';
|
|
@@ -15,7 +15,6 @@ interface Clickable {
|
|
|
15
15
|
|
|
16
16
|
export function useLink(isRemote?: boolean) {
|
|
17
17
|
const router = useRouter();
|
|
18
|
-
const blockRouter = useBlockRouter();
|
|
19
18
|
|
|
20
19
|
return <L extends Partial<LinkProps & Clickable>>(props: L): L & Clickable => ({
|
|
21
20
|
...props,
|
|
@@ -44,7 +43,7 @@ export function useLink(isRemote?: boolean) {
|
|
|
44
43
|
// Client routing
|
|
45
44
|
ev?.preventDefault();
|
|
46
45
|
if (isHash(href)) {
|
|
47
|
-
|
|
46
|
+
gotoBlock(router, href);
|
|
48
47
|
} else if (href) {
|
|
49
48
|
router.push(href);
|
|
50
49
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
interface RouterOptions {
|
|
2
|
+
scroll?: boolean;
|
|
3
|
+
}
|
|
4
|
+
|
|
1
5
|
export interface Router {
|
|
2
6
|
pathname: string;
|
|
3
7
|
query: Record<string, string | string[] | undefined>;
|
|
4
8
|
href?: string;
|
|
5
9
|
basePath?: string;
|
|
6
|
-
push: (url: string) => void;
|
|
7
|
-
replace: (url: string) => void;
|
|
10
|
+
push: (url: string, as?: string, options?: RouterOptions) => void;
|
|
11
|
+
replace: (url: string, as?: string, options?: RouterOptions) => void;
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
export function useRouter(): Router {
|
|
@@ -1,53 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Router } from '../../hooks/useRouter';
|
|
2
2
|
import type { BlockDef } from '../../model/ContentPageDef';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
anchor: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface BlockIntersectionEvent {
|
|
9
|
-
block: BlockDef;
|
|
10
|
-
intersection: IntersectionObserverEntry;
|
|
11
|
-
}
|
|
4
|
+
const normalizeAnchor = (anchor?: string) => anchor?.replace('#', '') || '';
|
|
12
5
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
intersection: BlockIntersectionEvent;
|
|
6
|
+
export function gotoBlock(router: Router, anchor?: string) {
|
|
7
|
+
router.replace(`#${normalizeAnchor(anchor)}`);
|
|
16
8
|
}
|
|
17
9
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export class BlockRouter {
|
|
23
|
-
public static readonly inst = new BlockRouter();
|
|
24
|
-
|
|
25
|
-
readonly eventBus = new EventBus<EventMap>();
|
|
26
|
-
|
|
27
|
-
constructor() {
|
|
28
|
-
const anchor = normalizeAnchor(globalThis.location?.hash);
|
|
29
|
-
if (anchor) {
|
|
30
|
-
this.eventBus.subject('goto', { anchor });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
goto(rawAnchor?: string) {
|
|
35
|
-
const anchor = normalizeAnchor(rawAnchor);
|
|
36
|
-
if (anchor) {
|
|
37
|
-
this.push(anchor);
|
|
38
|
-
this.eventBus.fire('goto', { anchor });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
push(rawAnchor: string) {
|
|
43
|
-
globalThis.history?.pushState(null, '', getURLWithAnchor(rawAnchor));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
replace(rawAnchor: string) {
|
|
47
|
-
globalThis.history?.replaceState(null, '', getURLWithAnchor(rawAnchor));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
reset() {
|
|
51
|
-
globalThis.history?.replaceState(null, '', getURLWithAnchor());
|
|
52
|
-
}
|
|
10
|
+
export function trackBlock(router: Router, block?: BlockDef) {
|
|
11
|
+
router.replace(`#${normalizeAnchor(block?.anchor)}`, undefined, {
|
|
12
|
+
scroll: false,
|
|
13
|
+
});
|
|
53
14
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventBus } from '../../EventBus/EventBus';
|
|
2
|
+
import type { BlockDef } from '../../model/ContentPageDef';
|
|
3
|
+
|
|
4
|
+
export interface BlockIntersectionEvent {
|
|
5
|
+
block: BlockDef;
|
|
6
|
+
intersection: IntersectionObserverEntry;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface EventMap {
|
|
10
|
+
intersection: BlockIntersectionEvent;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const blockRouterEventBus = new EventBus<EventMap>();
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { useCallback
|
|
1
|
+
import { useCallback } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
|
|
3
3
|
import type { BlockDef } from '../../model/ContentPageDef';
|
|
4
|
-
import {
|
|
4
|
+
import { blockRouterEventBus } from './blockRouterEventBus';
|
|
5
5
|
|
|
6
|
-
export function useBlockIntersectionObserver(
|
|
7
|
-
block?: BlockDef,
|
|
8
|
-
router: BlockRouter = BlockRouter.inst,
|
|
9
|
-
) {
|
|
6
|
+
export function useBlockIntersectionObserver(block?: BlockDef) {
|
|
10
7
|
const observerCallback = useCallback(
|
|
11
8
|
(entries: IntersectionObserverEntry[]) => {
|
|
12
9
|
if (!block || !entries?.length) {
|
|
@@ -14,24 +11,10 @@ export function useBlockIntersectionObserver(
|
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
const intersection = entries[entries.length - 1];
|
|
17
|
-
|
|
14
|
+
blockRouterEventBus.fire('intersection', { block, intersection });
|
|
18
15
|
},
|
|
19
|
-
[block
|
|
16
|
+
[block],
|
|
20
17
|
);
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (!ref.current) {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return router.eventBus.subscribe('goto', ({ anchor }) => {
|
|
30
|
-
if (ref.current && block?.anchor === anchor) {
|
|
31
|
-
ref.current.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}, [block, router]);
|
|
35
|
-
|
|
36
|
-
return ref;
|
|
19
|
+
return useIntersectionObserver(observerCallback, { sensitivity: 1 });
|
|
37
20
|
}
|
|
@@ -1,41 +1,35 @@
|
|
|
1
1
|
import { useEffect, useRef } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
|
+
import { useRouter } from '../../hooks/useRouter';
|
|
2
3
|
import type { BlockDef } from '../../model/ContentPageDef';
|
|
3
4
|
import { debounce } from '../../utils/debounce';
|
|
4
|
-
import {
|
|
5
|
+
import { trackBlock } from './BlockRouter';
|
|
6
|
+
import { blockRouterEventBus } from './blockRouterEventBus';
|
|
5
7
|
import { findActiveBlock } from './findActiveBlock';
|
|
6
8
|
|
|
7
9
|
const isScrolledEnough = () => globalThis.scrollY > (globalThis.innerHeight * 3) / 4;
|
|
8
10
|
|
|
9
|
-
export function useBlockRouterProvider(
|
|
10
|
-
router
|
|
11
|
-
|
|
12
|
-
) {
|
|
11
|
+
export function useBlockRouterProvider(scrollTarget: EventTarget = globalThis) {
|
|
12
|
+
const router = useRouter();
|
|
13
|
+
|
|
13
14
|
const intersectionsMapRef = useRef<Map<BlockDef, IntersectionObserverEntry>>(new Map());
|
|
14
15
|
|
|
15
16
|
useEffect(
|
|
16
17
|
() =>
|
|
17
|
-
|
|
18
|
+
blockRouterEventBus.subscribe('intersection', ({ block, intersection }) => {
|
|
18
19
|
if (intersectionsMapRef.current) {
|
|
19
20
|
intersectionsMapRef.current.set(block, intersection);
|
|
20
21
|
}
|
|
21
22
|
}),
|
|
22
|
-
[
|
|
23
|
+
[],
|
|
23
24
|
);
|
|
24
25
|
|
|
25
26
|
useEffect(() => {
|
|
26
27
|
const handleScroll = debounce(() => {
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const activeBlock = findActiveBlock([...(intersectionsMapRef.current || [])]);
|
|
34
|
-
|
|
35
|
-
if (activeBlock?.anchor) {
|
|
36
|
-
router.replace(activeBlock.anchor);
|
|
37
|
-
} else if (!activeBlock) {
|
|
38
|
-
router.reset();
|
|
28
|
+
if (isScrolledEnough()) {
|
|
29
|
+
const activeBlock = findActiveBlock([...(intersectionsMapRef.current || [])]);
|
|
30
|
+
trackBlock(router, activeBlock);
|
|
31
|
+
} else {
|
|
32
|
+
trackBlock(router);
|
|
39
33
|
}
|
|
40
34
|
}, 100);
|
|
41
35
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSX } from '@redneckz/uni-jsx';
|
|
2
2
|
import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
3
|
-
import {
|
|
3
|
+
import { defaultEventBus } from '../EventBus/defaultEventBus';
|
|
4
4
|
import type { BlockVersion } from '../model/BlockVersion';
|
|
5
5
|
import type { UniBlockProps } from '../model/JSXBlock';
|
|
6
6
|
import { useBlockIntersectionObserver } from '../services/BlockRouter/useBlockIntersectionObserver';
|
|
@@ -28,7 +28,7 @@ export const BlockWrapper = JSX<BlockWrapperProps>(
|
|
|
28
28
|
const [isVisible, setVisible] = useState(true);
|
|
29
29
|
useEffect(
|
|
30
30
|
() =>
|
|
31
|
-
|
|
31
|
+
defaultEventBus.subscribe('tab', (event) => {
|
|
32
32
|
if (event.type === 'group') {
|
|
33
33
|
const hasSettings = block?.labels?.length || block?.anchor;
|
|
34
34
|
setVisible(
|
package/package.json
CHANGED
package/src/EventBus/EventBus.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type BaseEventMap = Record<string, any>;
|
|
4
|
-
|
|
5
|
-
export class EventBus<EM extends BaseEventMap> {
|
|
6
|
-
public static readonly inst = new EventBus<EventMap>();
|
|
7
|
-
|
|
1
|
+
export class EventBus<EM extends Record<string, any>> {
|
|
8
2
|
private subscribers: Partial<Record<keyof EM, Array<(ev: EM[keyof EM]) => void>>> = {};
|
|
9
3
|
private subjectsStateMap: Partial<EM> = {};
|
|
10
4
|
|
|
@@ -2,10 +2,13 @@ import { JSX } from '@redneckz/uni-jsx';
|
|
|
2
2
|
import type { UniBlockProps } from '../../model/JSXBlock';
|
|
3
3
|
import { BlockWrapper } from '../../ui-kit/BlockWrapper';
|
|
4
4
|
import { renderButtonsSection } from '../../ui-kit/Button/renderButtonsSection';
|
|
5
|
+
import { style } from '../../utils/style';
|
|
5
6
|
import type { ButtonBlockContent } from './ButtonBlockContent';
|
|
6
7
|
|
|
7
8
|
interface ButtonBlockProps extends ButtonBlockContent, UniBlockProps {}
|
|
8
9
|
|
|
9
|
-
export const ButtonBlock = JSX<ButtonBlockProps>(({ button, ...rest }) => (
|
|
10
|
-
<BlockWrapper {...rest}>
|
|
10
|
+
export const ButtonBlock = JSX<ButtonBlockProps>(({ button, className, ...rest }) => (
|
|
11
|
+
<BlockWrapper className={style('!bg-transparent', className)} {...rest}>
|
|
12
|
+
{renderButtonsSection([button])}
|
|
13
|
+
</BlockWrapper>
|
|
11
14
|
));
|
|
@@ -4,6 +4,10 @@ import type { ButtonWithIconProps } from '../../ui-kit/Button/ButtonProps';
|
|
|
4
4
|
* @title Блок Кнопка
|
|
5
5
|
*/
|
|
6
6
|
export interface ButtonBlockContent {
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* @title Кнопка
|
|
9
|
+
* @default {"icon": {"format": "webp", "size": { "width": 24, "height": 24 }},
|
|
10
|
+
* "iconRight": {"format": "webp", "size": { "width": 24, "height": 24 }}}
|
|
11
|
+
*/
|
|
8
12
|
button?: ButtonWithIconProps;
|
|
9
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSX } from '@redneckz/uni-jsx';
|
|
2
2
|
import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
3
|
-
import {
|
|
3
|
+
import { defaultEventBus } from '../../EventBus/defaultEventBus';
|
|
4
4
|
import type { UniBlockProps } from '../../model/JSXBlock';
|
|
5
5
|
import { BlockWrapper } from '../../ui-kit/BlockWrapper';
|
|
6
6
|
import { renderTab } from './renderTab';
|
|
@@ -21,7 +21,7 @@ export const Tabs = JSX<TabsBlockProps>((props) => {
|
|
|
21
21
|
|
|
22
22
|
useEffect(
|
|
23
23
|
() =>
|
|
24
|
-
|
|
24
|
+
defaultEventBus.subscribe('tab', (event) => {
|
|
25
25
|
const tab = tabs?.find(checkTab(event));
|
|
26
26
|
if (event.type === 'link' && tab) {
|
|
27
27
|
setCurrentTab(tab);
|
|
@@ -35,14 +35,14 @@ export const Tabs = JSX<TabsBlockProps>((props) => {
|
|
|
35
35
|
useEffect(
|
|
36
36
|
() =>
|
|
37
37
|
currentTab?.type === 'group'
|
|
38
|
-
?
|
|
38
|
+
? defaultEventBus.subject('tab', { type: currentTab.type, label: currentTab.ref })
|
|
39
39
|
: undefined,
|
|
40
40
|
[currentTab],
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
const handleClick = useCallback((selectedTab: TabData) => {
|
|
44
44
|
if (selectedTab?.type === 'group') {
|
|
45
|
-
|
|
45
|
+
defaultEventBus.fire('tab', { type: selectedTab.type, label: selectedTab.ref });
|
|
46
46
|
}
|
|
47
47
|
setCurrentTab(selectedTab);
|
|
48
48
|
}, []);
|
package/src/hooks/useLink.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LinkProps } from '../model/LinkProps';
|
|
2
2
|
import { projectSettings } from '../ProjectSettings';
|
|
3
|
-
import {
|
|
3
|
+
import { gotoBlock } from '../services/BlockRouter/BlockRouter';
|
|
4
4
|
import { isHash, isLocalURL, joinPath } from '../utils/url';
|
|
5
5
|
import { handlerDecorator } from './handlerDecorator';
|
|
6
6
|
import { useRouter } from './useRouter';
|
|
@@ -15,7 +15,6 @@ interface Clickable {
|
|
|
15
15
|
|
|
16
16
|
export function useLink(isRemote?: boolean) {
|
|
17
17
|
const router = useRouter();
|
|
18
|
-
const blockRouter = useBlockRouter();
|
|
19
18
|
|
|
20
19
|
return <L extends Partial<LinkProps & Clickable>>(props: L): L & Clickable => ({
|
|
21
20
|
...props,
|
|
@@ -44,7 +43,7 @@ export function useLink(isRemote?: boolean) {
|
|
|
44
43
|
// Client routing
|
|
45
44
|
ev?.preventDefault();
|
|
46
45
|
if (isHash(href)) {
|
|
47
|
-
|
|
46
|
+
gotoBlock(router, href);
|
|
48
47
|
} else if (href) {
|
|
49
48
|
router.push(href);
|
|
50
49
|
}
|