@redneckz/wildless-cms-uni-blocks 0.3.89 → 0.3.90

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 (144) hide show
  1. package/bundle/blocks.schema.json +1 -1
  2. package/bundle/bundle.umd.js +73 -12
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/dist/EventBus/EventBus.d.ts +10 -0
  5. package/dist/EventBus/EventBus.js +30 -0
  6. package/dist/EventBus/EventBus.js.map +1 -0
  7. package/dist/EventBus/EventMap.d.ts +4 -0
  8. package/dist/EventBus/EventMap.js +2 -0
  9. package/dist/EventBus/EventMap.js.map +1 -0
  10. package/dist/components/Blocks.d.ts +1 -0
  11. package/dist/components/Blocks.js +2 -0
  12. package/dist/components/Blocks.js.map +1 -1
  13. package/dist/components/ContentPage/ContentPage.d.ts +1 -0
  14. package/dist/components/ContentPage/ContentPage.js +4 -4
  15. package/dist/components/ContentPage/ContentPage.js.map +1 -1
  16. package/dist/components/ContentPage/ContentPageContext.d.ts +1 -0
  17. package/dist/components/ContentPage/normalizeBlock.d.ts +1 -0
  18. package/dist/components/Tabs/Tabs.d.ts +8 -0
  19. package/dist/components/Tabs/Tabs.js +18 -0
  20. package/dist/components/Tabs/Tabs.js.map +1 -0
  21. package/dist/components/Tabs/TabsContent.d.ts +18 -0
  22. package/dist/components/Tabs/TabsContent.js +2 -0
  23. package/dist/components/Tabs/TabsContent.js.map +1 -0
  24. package/dist/components/Tabs/renderTab.d.ts +12 -0
  25. package/dist/components/Tabs/renderTab.js +19 -0
  26. package/dist/components/Tabs/renderTab.js.map +1 -0
  27. package/dist/react/setup-fixture.js +1 -0
  28. package/dist/react/setup-fixture.js.map +1 -1
  29. package/dist/types.d.ts +3 -0
  30. package/dist/ui-kit/BlockWrapper.d.ts +3 -2
  31. package/dist/ui-kit/BlockWrapper.js +10 -2
  32. package/dist/ui-kit/BlockWrapper.js.map +1 -1
  33. package/lib/EventBus/EventBus.d.ts +10 -0
  34. package/lib/EventBus/EventBus.js +27 -0
  35. package/lib/EventBus/EventBus.js.map +1 -0
  36. package/lib/EventBus/EventMap.d.ts +4 -0
  37. package/lib/EventBus/EventMap.js +2 -0
  38. package/lib/EventBus/EventMap.js.map +1 -0
  39. package/lib/common.css +1 -1
  40. package/lib/components/Blocks.d.ts +1 -0
  41. package/lib/components/Blocks.js +2 -0
  42. package/lib/components/Blocks.js.map +1 -1
  43. package/lib/components/ContentPage/ContentPage.d.ts +1 -0
  44. package/lib/components/ContentPage/ContentPage.js +4 -4
  45. package/lib/components/ContentPage/ContentPage.js.map +1 -1
  46. package/lib/components/ContentPage/ContentPageContext.d.ts +1 -0
  47. package/lib/components/ContentPage/normalizeBlock.d.ts +1 -0
  48. package/lib/components/Tabs/Tabs.d.ts +8 -0
  49. package/lib/components/Tabs/Tabs.fixture.d.ts +5 -0
  50. package/lib/components/Tabs/Tabs.js +16 -0
  51. package/lib/components/Tabs/Tabs.js.map +1 -0
  52. package/lib/components/Tabs/TabsContent.d.ts +18 -0
  53. package/lib/components/Tabs/TabsContent.js +2 -0
  54. package/lib/components/Tabs/TabsContent.js.map +1 -0
  55. package/lib/components/Tabs/renderTab.d.ts +12 -0
  56. package/lib/components/Tabs/renderTab.js +16 -0
  57. package/lib/components/Tabs/renderTab.js.map +1 -0
  58. package/lib/react/setup-fixture.js +1 -0
  59. package/lib/react/setup-fixture.js.map +1 -1
  60. package/lib/types.d.ts +3 -0
  61. package/lib/ui-kit/BlockWrapper.d.ts +3 -2
  62. package/lib/ui-kit/BlockWrapper.js +10 -2
  63. package/lib/ui-kit/BlockWrapper.js.map +1 -1
  64. package/mobile/bundle/bundle.umd.js +40 -6
  65. package/mobile/bundle/bundle.umd.min.js +1 -1
  66. package/mobile/dist/EventBus/EventBus.d.ts +10 -0
  67. package/mobile/dist/EventBus/EventBus.js +30 -0
  68. package/mobile/dist/EventBus/EventBus.js.map +1 -0
  69. package/mobile/dist/EventBus/EventMap.d.ts +4 -0
  70. package/mobile/dist/EventBus/EventMap.js +2 -0
  71. package/mobile/dist/EventBus/EventMap.js.map +1 -0
  72. package/mobile/dist/components/ContentPage/ContentPage.d.ts +1 -0
  73. package/mobile/dist/components/ContentPage/ContentPage.js +4 -4
  74. package/mobile/dist/components/ContentPage/ContentPage.js.map +1 -1
  75. package/mobile/dist/components/ContentPage/ContentPageContext.d.ts +1 -0
  76. package/mobile/dist/components/Tabs/Tabs.d.ts +8 -0
  77. package/mobile/dist/components/Tabs/Tabs.js +18 -0
  78. package/mobile/dist/components/Tabs/Tabs.js.map +1 -0
  79. package/mobile/dist/components/Tabs/TabsContent.d.ts +18 -0
  80. package/mobile/dist/components/Tabs/TabsContent.js +2 -0
  81. package/mobile/dist/components/Tabs/TabsContent.js.map +1 -0
  82. package/mobile/dist/components/Tabs/renderTab.d.ts +12 -0
  83. package/mobile/dist/components/Tabs/renderTab.js +19 -0
  84. package/mobile/dist/components/Tabs/renderTab.js.map +1 -0
  85. package/mobile/dist/react/setup-fixture.js +1 -0
  86. package/mobile/dist/react/setup-fixture.js.map +1 -1
  87. package/mobile/dist/types.d.ts +3 -0
  88. package/mobile/dist/ui-kit/BlockWrapper.d.ts +3 -2
  89. package/mobile/dist/ui-kit/BlockWrapper.js +10 -2
  90. package/mobile/dist/ui-kit/BlockWrapper.js.map +1 -1
  91. package/mobile/lib/EventBus/EventBus.d.ts +10 -0
  92. package/mobile/lib/EventBus/EventBus.js +27 -0
  93. package/mobile/lib/EventBus/EventBus.js.map +1 -0
  94. package/mobile/lib/EventBus/EventMap.d.ts +4 -0
  95. package/mobile/lib/EventBus/EventMap.js +2 -0
  96. package/mobile/lib/EventBus/EventMap.js.map +1 -0
  97. package/mobile/lib/components/ContentPage/ContentPage.d.ts +1 -0
  98. package/mobile/lib/components/ContentPage/ContentPage.js +4 -4
  99. package/mobile/lib/components/ContentPage/ContentPage.js.map +1 -1
  100. package/mobile/lib/components/ContentPage/ContentPageContext.d.ts +1 -0
  101. package/mobile/lib/components/Tabs/Tabs.d.ts +8 -0
  102. package/mobile/lib/components/Tabs/Tabs.js +16 -0
  103. package/mobile/lib/components/Tabs/Tabs.js.map +1 -0
  104. package/mobile/lib/components/Tabs/TabsContent.d.ts +18 -0
  105. package/mobile/lib/components/Tabs/TabsContent.js +2 -0
  106. package/mobile/lib/components/Tabs/TabsContent.js.map +1 -0
  107. package/mobile/lib/components/Tabs/renderTab.d.ts +12 -0
  108. package/mobile/lib/components/Tabs/renderTab.js +16 -0
  109. package/mobile/lib/components/Tabs/renderTab.js.map +1 -0
  110. package/mobile/lib/react/setup-fixture.js +1 -0
  111. package/mobile/lib/react/setup-fixture.js.map +1 -1
  112. package/mobile/lib/types.d.ts +3 -0
  113. package/mobile/lib/ui-kit/BlockWrapper.d.ts +3 -2
  114. package/mobile/lib/ui-kit/BlockWrapper.js +10 -2
  115. package/mobile/lib/ui-kit/BlockWrapper.js.map +1 -1
  116. package/mobile/src/EventBus/EventBus.ts +38 -0
  117. package/mobile/src/EventBus/EventMap.ts +5 -0
  118. package/mobile/src/components/Blocks.spec.tsx +2 -1
  119. package/mobile/src/components/ContentPage/ContentPage.tsx +7 -4
  120. package/mobile/src/components/ContentPage/ContentPageContext.tsx +1 -0
  121. package/mobile/src/components/Tabs/Tabs.example.json +17 -0
  122. package/mobile/src/components/Tabs/Tabs.tsx +35 -0
  123. package/mobile/src/components/Tabs/TabsContent.ts +19 -0
  124. package/mobile/src/components/Tabs/renderTab.tsx +51 -0
  125. package/mobile/src/components/__snapshots__/Blocks.spec.tsx.snap +6 -0
  126. package/mobile/src/react/setup-fixture.ts +1 -0
  127. package/mobile/src/types.ts +3 -0
  128. package/mobile/src/ui-kit/BlockWrapper.tsx +19 -4
  129. package/package.json +1 -1
  130. package/src/EventBus/EventBus.ts +38 -0
  131. package/src/EventBus/EventMap.ts +5 -0
  132. package/src/components/Blocks.spec.tsx +2 -1
  133. package/src/components/Blocks.ts +2 -0
  134. package/src/components/ContentPage/ContentPage.tsx +7 -4
  135. package/src/components/ContentPage/ContentPageContext.tsx +1 -0
  136. package/src/components/Tabs/Tabs.example.json +17 -0
  137. package/src/components/Tabs/Tabs.fixture.tsx +18 -0
  138. package/src/components/Tabs/Tabs.tsx +35 -0
  139. package/src/components/Tabs/TabsContent.ts +19 -0
  140. package/src/components/Tabs/renderTab.tsx +51 -0
  141. package/src/components/__snapshots__/Blocks.spec.tsx.snap +6 -0
  142. package/src/react/setup-fixture.ts +1 -0
  143. package/src/types.ts +3 -0
  144. package/src/ui-kit/BlockWrapper.tsx +19 -4
@@ -1,8 +1,10 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { ContentPageContext } from '../components/ContentPage/ContentPageContext';
2
+ import type { ContentPageContext } from '../components/ContentPage/ContentPageContext';
3
+ import { EventBus } from '../EventBus/EventBus';
4
+ import type { UniBlockProps } from '../types';
3
5
  import { changeHashOnObserve } from '../utils/changeHashOnObserve';
4
6
 
5
- interface BlockWrapperProps {
7
+ interface BlockWrapperProps extends UniBlockProps, Record<string, any> {
6
8
  context: ContentPageContext;
7
9
  className?: string;
8
10
  anchor?: string;
@@ -10,10 +12,23 @@ interface BlockWrapperProps {
10
12
  }
11
13
 
12
14
  export const BlockWrapper = JSX<BlockWrapperProps>(
13
- ({ anchor, className, context, children, tag = 'section' }) => {
15
+ ({ anchor, className, context, children, tag = 'section', labels }) => {
16
+ const Tag: any = tag;
17
+
14
18
  const { IntersectionObserverTag } = context;
19
+ const [shouldRenderBlock, setShouldRenderBlock] = context.useState(true);
15
20
 
16
- const Tag: any = tag;
21
+ context.useEffect(
22
+ () =>
23
+ EventBus.inst.subscribe('tab', (event) => {
24
+ setShouldRenderBlock(!labels?.length || !event.label || labels.includes(event.label));
25
+ }),
26
+ [labels],
27
+ );
28
+
29
+ if (!shouldRenderBlock) {
30
+ return null;
31
+ }
17
32
 
18
33
  return anchor ? (
19
34
  <IntersectionObserverTag
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.3.89",
3
+ "version": "0.3.90",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -0,0 +1,38 @@
1
+ import type { EventMap } from './EventMap';
2
+
3
+ type Subscriber = (ev: EventMap[keyof EventMap]) => void;
4
+
5
+ export class EventBus {
6
+ public static readonly inst = new EventBus();
7
+
8
+ private subscribers: Partial<Record<keyof EventMap, Subscriber[]>> = {};
9
+ private subjectsStateMap: Partial<EventMap> = {};
10
+
11
+ subscribe<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void) {
12
+ this.subscribers[type] ||= [];
13
+ this.subscribers[type]?.push(listener);
14
+
15
+ const latestEvent = this.subjectsStateMap[type];
16
+
17
+ if (latestEvent) {
18
+ listener(latestEvent as EventMap[T]);
19
+ }
20
+
21
+ return () => {
22
+ this.unsubscribe(type, listener);
23
+ };
24
+ }
25
+
26
+ private unsubscribe<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void) {
27
+ this.subscribers[type] = this.subscribers[type]?.filter((s) => s !== listener);
28
+ }
29
+
30
+ fire<T extends keyof EventMap>(type: T, event: EventMap[T]) {
31
+ this.subjectsStateMap[type] = event;
32
+ this.subscribers[type]?.forEach((s) => s(event));
33
+ }
34
+
35
+ subject<T extends keyof EventMap>(type: T, event: EventMap[T]) {
36
+ this.subjectsStateMap[type] = event;
37
+ }
38
+ }
@@ -0,0 +1,5 @@
1
+ import type { TabActivationEvent } from '../components/Tabs/Tabs';
2
+
3
+ export interface EventMap {
4
+ tab: TabActivationEvent;
5
+ }
@@ -1,6 +1,6 @@
1
1
  import { setup } from '@redneckz/uni-jsx';
2
2
  import { render } from '@testing-library/react';
3
- import { useState } from 'react';
3
+ import { useEffect, useState } from 'react';
4
4
  import runtime from 'react/jsx-runtime';
5
5
  import { Blocks } from './Blocks';
6
6
  import type { ContentPageContext } from './ContentPage/ContentPageContext';
@@ -15,6 +15,7 @@ const emptyFn = () => {
15
15
 
16
16
  const context: ContentPageContext = {
17
17
  useState,
18
+ useEffect,
18
19
  useRouter: () => ({
19
20
  pathname: '/credits',
20
21
  query: {},
@@ -28,6 +28,7 @@ import { ProductTile } from './ProductTile/ProductTile';
28
28
  import { PromoTile } from './PromoTile/PromoTile';
29
29
  import { Recommendation } from './Recommendation/Recommendation';
30
30
  import { StepsBlock } from './StepsBlock/StepsBlock';
31
+ import { Tabs } from './Tabs/Tabs';
31
32
  import { TariffsTable } from './TariffsTable/TariffsTable';
32
33
  import { TextBlock } from './TextBlock/TextBlock';
33
34
  import { Tile } from './Tile/Tile';
@@ -66,4 +67,5 @@ export const Blocks = {
66
67
  Placeholder,
67
68
  GroupBlock,
68
69
  BonusBenefitsBlock,
70
+ Tabs,
69
71
  };
@@ -32,6 +32,7 @@ export interface ContentPageProps extends UniBlockProps {
32
32
 
33
33
  export interface RenderBlockFunc {
34
34
  block: BlockDef;
35
+ page: ContentPageDef;
35
36
  blockDecorator: BlockDecorator;
36
37
  blocksRegistry: BlocksRegistry;
37
38
  context: ContentPageContext;
@@ -59,7 +60,7 @@ export const ContentPage = JSX<ContentPageProps>(
59
60
  {header?.blocks?.length ? (
60
61
  <div className={`${style2className(header?.style)}`}>
61
62
  {header.blocks.map((block, i) =>
62
- renderBlock({ block, blockDecorator, blocksRegistry, context }, i),
63
+ renderBlock({ block, page: data, blockDecorator, blocksRegistry, context }, i),
63
64
  )}
64
65
  </div>
65
66
  ) : null}
@@ -67,7 +68,7 @@ export const ContentPage = JSX<ContentPageProps>(
67
68
  {blocks?.length ? (
68
69
  <div className="container grid grid-cols-12 gap-1">
69
70
  {blocks.map((block, i) =>
70
- renderBlock({ block, blockDecorator, blocksRegistry, context }, i),
71
+ renderBlock({ block, blockDecorator, blocksRegistry, context, page: data }, i),
71
72
  )}
72
73
  </div>
73
74
  ) : null}
@@ -87,7 +88,7 @@ export const ContentPage = JSX<ContentPageProps>(
87
88
  );
88
89
 
89
90
  function renderBlock(
90
- { block, blockDecorator, blocksRegistry, context }: RenderBlockFunc,
91
+ { block, blockDecorator, blocksRegistry, context, page }: RenderBlockFunc,
91
92
  i: number,
92
93
  ) {
93
94
  const { type } = block;
@@ -101,7 +102,7 @@ function renderBlock(
101
102
  blockClassName: `scroll-mt-12 ${style2className(block.style)}`,
102
103
  block,
103
104
  render: (props) => {
104
- const { version, content, anchor } = props.block;
105
+ const { version, content, anchor, labels } = props.block;
105
106
 
106
107
  return (
107
108
  <BlockComponent
@@ -109,7 +110,9 @@ function renderBlock(
109
110
  className={props.blockClassName}
110
111
  version={version}
111
112
  context={context}
113
+ page={page}
112
114
  anchor={anchor}
115
+ labels={labels}
113
116
  {...content}
114
117
  />
115
118
  );
@@ -53,6 +53,7 @@ export interface ContentPageContext {
53
53
  useGeolocation: GeolocationHook;
54
54
  useLikeService: () => LikeService;
55
55
  useSearch: () => Search;
56
+ useEffect: <Deps extends any[]>(effect: () => (() => void) | void, deps?: Deps) => void;
56
57
  handlerDecorator?: HandlerDecorator;
57
58
  IntersectionObserverTag: IntersectionObserverComponent;
58
59
  }
@@ -0,0 +1,17 @@
1
+ {
2
+ "showCounter": true,
3
+ "tabs": [
4
+ {
5
+ "id": "tab1",
6
+ "text": "Вкладка 1"
7
+ },
8
+ {
9
+ "id": "tab2",
10
+ "text": "Вкладка 2"
11
+ },
12
+ {
13
+ "id": "tab3",
14
+ "text": "Вкладка 3"
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,18 @@
1
+ import { context } from '../../react/setup-fixture';
2
+ import { Tabs } from './Tabs';
3
+
4
+ export default {
5
+ default: (
6
+ <div className="container grid grid-cols-12">
7
+ <Tabs
8
+ context={context}
9
+ className="col-span-12"
10
+ tabs={[
11
+ { id: 'tab1', title: 'Вкладка 1' },
12
+ { id: 'tab2', title: 'Вкладка 2' },
13
+ { id: 'tab3', title: 'Вкладка 3' },
14
+ ]}
15
+ />
16
+ </div>
17
+ ),
18
+ };
@@ -0,0 +1,35 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import { EventBus } from '../../EventBus/EventBus';
3
+ import type { UniBlockProps } from '../../types';
4
+ import { BlockWrapper } from '../../ui-kit/BlockWrapper';
5
+ import { renderTab } from './renderTab';
6
+ import type { Tab, TabsContent } from './TabsContent';
7
+
8
+ export interface TabActivationEvent {
9
+ label?: string;
10
+ }
11
+
12
+ export interface TabsProps extends TabsContent, UniBlockProps {}
13
+
14
+ export const Tabs = JSX<TabsProps>((props) => {
15
+ const { context, className, tabs, page, showCounter } = props;
16
+
17
+ const [currentTab, setCurrentTab] = context.useState(tabs ? tabs[0] : undefined);
18
+
19
+ context.useEffect(() => EventBus.inst.subject('tab', { label: currentTab?.id }), [currentTab]);
20
+
21
+ const handleClick = (selectedTab: Tab) => {
22
+ EventBus.inst.fire('tab', { label: selectedTab.id });
23
+ setCurrentTab(selectedTab);
24
+ };
25
+
26
+ return (
27
+ <BlockWrapper
28
+ context={context}
29
+ className={`mb-2 box-border flex gap-x-1 ${className}`}
30
+ role="tablist"
31
+ >
32
+ {tabs?.map(renderTab({ onClick: handleClick, currentTab, page, showCounter }))}
33
+ </BlockWrapper>
34
+ );
35
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @title Таб
3
+ */
4
+ export interface Tab {
5
+ /** @title Tег */
6
+ id?: string;
7
+ /** @title Название */
8
+ title?: string;
9
+ }
10
+
11
+ /**
12
+ * @title Вкладки
13
+ */
14
+ export interface TabsContent {
15
+ /** @title Табы */
16
+ tabs?: Tab[];
17
+ /** @title Показывать счетчик блоков во вкладках */
18
+ showCounter?: boolean;
19
+ }
@@ -0,0 +1,51 @@
1
+ import type { ContentPageDef } from '../../types';
2
+ import type { Tab } from './TabsContent';
3
+
4
+ interface RenderTabProps {
5
+ onClick: OnTabClick;
6
+ currentTab?: Tab;
7
+ page?: ContentPageDef;
8
+ showCounter?: boolean;
9
+ }
10
+
11
+ type OnTabClick = (tab: Tab) => void;
12
+
13
+ const badgeStyle = 'min-w-[22px] w-[22px] h-[22px] rounded-full text-xs ml-2';
14
+
15
+ export const renderTab =
16
+ ({ onClick, currentTab, showCounter, page }: RenderTabProps) =>
17
+ (tab: Tab, i: number) => {
18
+ const isActive = currentTab === tab;
19
+
20
+ const tabBg = isActive ? 'bg-primary-main' : 'group bg-white';
21
+ const tabText = `text-m ${
22
+ isActive ? 'text-white' : 'text-secondary-text group-hover:text-primary-main'
23
+ }`;
24
+ const counterBlockStyle = `${badgeStyle}
25
+ ${
26
+ isActive
27
+ ? 'bg-white/30 text-white'
28
+ : 'bg-main-divider text-secondary-text group-hover:text-primary-main'
29
+ }`;
30
+
31
+ const count = tab.id
32
+ ? page?.blocks?.filter((block) => block?.labels?.includes(tab.id as string)).length
33
+ : page?.blocks?.length;
34
+
35
+ return (
36
+ <div
37
+ key={String(i)}
38
+ className={`flex h-12 w-full flex-1 cursor-pointer mr-2 last:mr-0 box-content ${tabBg}`}
39
+ role="tab"
40
+ aria-selected={isActive}
41
+ onClick={() => onClick(tab)}
42
+ >
43
+ <div className="flex flex-1 items-center justify-center">
44
+ {tab?.title ? <h3 className={tabText}>{tab?.title}</h3> : null}
45
+ {showCounter ? (
46
+ <div className={`flex items-center justify-center ${counterBlockStyle}`}>{count}</div>
47
+ ) : null}
48
+ </div>
49
+ </div>
50
+ );
51
+ };
@@ -821,6 +821,12 @@ exports[`Blocks StepsBlock should render block "StepsBlock" without content 1`]
821
821
  />
822
822
  `;
823
823
 
824
+ exports[`Blocks Tabs should render block "Tabs" without content 1`] = `
825
+ <section
826
+ class="mb-2 box-border flex gap-x-1 undefined"
827
+ />
828
+ `;
829
+
824
830
  exports[`Blocks TariffsTable should render block "TariffsTable" without content 1`] = `
825
831
  <section
826
832
  class="bg-white font-sans py-[50px] pl-[50px] overflow-hidden text-primary-text relative "
@@ -83,6 +83,7 @@ export const context: ContentPageContext = {
83
83
  setTerm: (text: string) => setTerm(text),
84
84
  };
85
85
  },
86
+ useEffect,
86
87
  IntersectionObserverTag,
87
88
  };
88
89
 
package/src/types.ts CHANGED
@@ -15,6 +15,7 @@ export interface BaseBlockDef {
15
15
  version?: BlockVersion;
16
16
  hidden?: boolean;
17
17
  anchor?: string;
18
+ labels?: string[];
18
19
  }
19
20
 
20
21
  export interface BlockDef extends BaseBlockDef {
@@ -56,6 +57,8 @@ export interface ContentPageDef extends ContentPageMeta {
56
57
  export interface UniBlockProps {
57
58
  className?: string;
58
59
  context: ContentPageContext;
60
+ page?: ContentPageDef;
61
+ labels?: string[];
59
62
  anchor?: string;
60
63
  }
61
64
 
@@ -1,8 +1,10 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { ContentPageContext } from '../components/ContentPage/ContentPageContext';
2
+ import type { ContentPageContext } from '../components/ContentPage/ContentPageContext';
3
+ import { EventBus } from '../EventBus/EventBus';
4
+ import type { UniBlockProps } from '../types';
3
5
  import { changeHashOnObserve } from '../utils/changeHashOnObserve';
4
6
 
5
- interface BlockWrapperProps {
7
+ interface BlockWrapperProps extends UniBlockProps, Record<string, any> {
6
8
  context: ContentPageContext;
7
9
  className?: string;
8
10
  anchor?: string;
@@ -10,10 +12,23 @@ interface BlockWrapperProps {
10
12
  }
11
13
 
12
14
  export const BlockWrapper = JSX<BlockWrapperProps>(
13
- ({ anchor, className, context, children, tag = 'section' }) => {
15
+ ({ anchor, className, context, children, tag = 'section', labels }) => {
16
+ const Tag: any = tag;
17
+
14
18
  const { IntersectionObserverTag } = context;
19
+ const [shouldRenderBlock, setShouldRenderBlock] = context.useState(true);
15
20
 
16
- const Tag: any = tag;
21
+ context.useEffect(
22
+ () =>
23
+ EventBus.inst.subscribe('tab', (event) => {
24
+ setShouldRenderBlock(!labels?.length || !event.label || labels.includes(event.label));
25
+ }),
26
+ [labels],
27
+ );
28
+
29
+ if (!shouldRenderBlock) {
30
+ return null;
31
+ }
17
32
 
18
33
  return anchor ? (
19
34
  <IntersectionObserverTag