@redocly/theme 0.71.0-next.1 → 0.71.0-next.3

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.
@@ -1,4 +1,4 @@
1
- import type { CSSProperties, ReactNode, PropsWithChildren, JSX } from 'react';
1
+ import type { KeyboardEvent, MouseEvent, CSSProperties, ReactNode, PropsWithChildren, JSX } from 'react';
2
2
  import type { LinkProps } from '../../core/types';
3
3
  export type DropdownMenuItemProps = Partial<Pick<LinkProps, 'to' | 'target' | 'external'>> & {
4
4
  prefix?: ReactNode;
@@ -12,7 +12,7 @@ export type DropdownMenuItemProps = Partial<Pick<LinkProps, 'to' | 'target' | 'e
12
12
  separator?: boolean;
13
13
  disabled?: boolean;
14
14
  dangerous?: boolean;
15
- onAction?: () => void;
15
+ onAction?: (event: KeyboardEvent | MouseEvent) => void;
16
16
  active?: boolean;
17
17
  };
18
18
  export declare function DropdownMenuItem({ children, content, active, onAction, to, dangerous, prefix, suffix, disabled, separator, dataAttributes, className, separatorLine, style, role, ...otherProps }: PropsWithChildren<DropdownMenuItemProps>): JSX.Element;
@@ -53,12 +53,12 @@ const styled_components_1 = __importStar(require("styled-components"));
53
53
  const Link_1 = require("../../components/Link/Link");
54
54
  function DropdownMenuItem(_a) {
55
55
  var { children, content, active, onAction, to, dangerous, prefix, suffix, disabled, separator, dataAttributes, className, separatorLine, style, role = 'menuitem' } = _a, otherProps = __rest(_a, ["children", "content", "active", "onAction", "to", "dangerous", "prefix", "suffix", "disabled", "separator", "dataAttributes", "className", "separatorLine", "style", "role"]);
56
- const handleClick = () => {
57
- onAction === null || onAction === void 0 ? void 0 : onAction();
56
+ const handleClick = (event) => {
57
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
58
58
  };
59
59
  const handleKeyDown = (event) => {
60
60
  if (event.key === 'Enter' || event.key === ' ') {
61
- onAction === null || onAction === void 0 ? void 0 : onAction();
61
+ onAction === null || onAction === void 0 ? void 0 : onAction(event);
62
62
  }
63
63
  };
64
64
  className = className || '' + (active ? ' active' : '');
package/lib/index.d.ts CHANGED
@@ -289,6 +289,7 @@ export * from './icons/ColorPaletteIcon/ColorPaletteIcon';
289
289
  export * from './icons/IdeaIcon/IdeaIcon';
290
290
  export * from './icons/NewChatIcon/NewChatIcon';
291
291
  export * from './layouts/RootLayout';
292
+ export * from './layouts/CustomContexts';
292
293
  export * from './layouts/PageLayout';
293
294
  export * from './layouts/NotFound';
294
295
  export * from './layouts/Forbidden';
package/lib/index.js CHANGED
@@ -354,6 +354,7 @@ __exportStar(require("./icons/IdeaIcon/IdeaIcon"), exports);
354
354
  __exportStar(require("./icons/NewChatIcon/NewChatIcon"), exports);
355
355
  /* Layouts */
356
356
  __exportStar(require("./layouts/RootLayout"), exports);
357
+ __exportStar(require("./layouts/CustomContexts"), exports);
357
358
  __exportStar(require("./layouts/PageLayout"), exports);
358
359
  __exportStar(require("./layouts/NotFound"), exports);
359
360
  __exportStar(require("./layouts/Forbidden"), exports);
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { JSX } from 'react';
3
+ type CustomContextsProps = React.PropsWithChildren<{}>;
4
+ export declare function CustomContexts({ children }: CustomContextsProps): JSX.Element;
5
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CustomContexts = CustomContexts;
7
+ const react_1 = __importDefault(require("react"));
8
+ // Eject this component to wrap every page in custom React context providers.
9
+ function CustomContexts({ children }) {
10
+ return react_1.default.createElement(react_1.default.Fragment, null, children);
11
+ }
12
+ //# sourceMappingURL=CustomContexts.js.map
@@ -10,14 +10,16 @@ const Footer_1 = require("../components/Footer/Footer");
10
10
  const SkipContent_1 = require("../components/SkipContent/SkipContent");
11
11
  const AIAssistantButton_1 = require("../components/Buttons/AIAssistantButton");
12
12
  const hooks_1 = require("../core/hooks");
13
+ const CustomContexts_1 = require("../layouts/CustomContexts");
13
14
  function RootLayout({ children }) {
14
15
  const { useSearchFeatures } = (0, hooks_1.useThemeHooks)();
15
16
  const { askAi } = useSearchFeatures();
16
17
  return (react_1.default.createElement("div", { "data-component-name": "layouts/RootLayout" },
17
- react_1.default.createElement(SkipContent_1.SkipContent, null),
18
- react_1.default.createElement(Navbar_1.Navbar, null),
19
- children,
20
- react_1.default.createElement(Footer_1.Footer, null),
21
- askAi && react_1.default.createElement(AIAssistantButton_1.AIAssistantButton, null)));
18
+ react_1.default.createElement(CustomContexts_1.CustomContexts, null,
19
+ react_1.default.createElement(SkipContent_1.SkipContent, null),
20
+ react_1.default.createElement(Navbar_1.Navbar, null),
21
+ children,
22
+ react_1.default.createElement(Footer_1.Footer, null),
23
+ askAi && react_1.default.createElement(AIAssistantButton_1.AIAssistantButton, null))));
22
24
  }
23
25
  //# sourceMappingURL=RootLayout.js.map
@@ -0,0 +1,15 @@
1
+ import type { MarkdocSchemaWrapper } from '../../markdoc/tags/types';
2
+ /** The part of a node the check reads; a stored plain-JSON AST node satisfies it too. */
3
+ type VisibilityNodeLike = {
4
+ tag?: string;
5
+ attributes?: Record<string, unknown>;
6
+ };
7
+ /** True for a node whose content must never reach the rendered page. */
8
+ export declare function isForAgentsOnly(node: VisibilityNodeLike): boolean;
9
+ /**
10
+ * A `renderTag` that empties nodes hidden from the page and leaves every other tag to the
11
+ * caller's own walk. Used by the text extractors that read a raw AST, which no tag schema runs on.
12
+ */
13
+ export declare function skipAgentsOnlyContent(node: VisibilityNodeLike): string | undefined;
14
+ export declare const visibility: MarkdocSchemaWrapper;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.visibility = void 0;
4
+ exports.isForAgentsOnly = isForAgentsOnly;
5
+ exports.skipAgentsOnlyContent = skipAgentsOnlyContent;
6
+ /** True for a node whose content must never reach the rendered page. */
7
+ function isForAgentsOnly(node) {
8
+ var _a;
9
+ return node.tag === 'visibility' && ((_a = node.attributes) === null || _a === void 0 ? void 0 : _a.for) === 'agents';
10
+ }
11
+ /**
12
+ * A `renderTag` that empties nodes hidden from the page and leaves every other tag to the
13
+ * caller's own walk. Used by the text extractors that read a raw AST, which no tag schema runs on.
14
+ */
15
+ function skipAgentsOnlyContent(node) {
16
+ return isForAgentsOnly(node) ? '' : undefined;
17
+ }
18
+ exports.visibility = {
19
+ schema: {
20
+ attributes: {
21
+ for: { type: String, required: true, matches: ['humans', 'agents'] },
22
+ },
23
+ transform(node, config) {
24
+ return isForAgentsOnly(node) ? [] : node.transformChildren(config);
25
+ },
26
+ renderForLlms(node, { getBody }) {
27
+ return node.attributes.for === 'humans' ? '' : getBody();
28
+ },
29
+ },
30
+ tagName: 'visibility',
31
+ };
32
+ //# sourceMappingURL=visibility.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.71.0-next.1",
3
+ "version": "0.71.0-next.3",
4
4
  "description": "Shared UI components lib",
5
5
  "keywords": [
6
6
  "theme",
@@ -69,7 +69,7 @@
69
69
  "webpack": "5.105.2"
70
70
  },
71
71
  "dependencies": {
72
- "@redocly/config": "0.65.0",
72
+ "@redocly/config": "0.66.0",
73
73
  "@tanstack/react-query": "5.62.3",
74
74
  "@tanstack/react-virtual": "3.13.0",
75
75
  "@xyflow/react": "12.8.3",
@@ -1,7 +1,14 @@
1
1
  import React from 'react';
2
2
  import styled, { css } from 'styled-components';
3
3
 
4
- import type { KeyboardEvent, CSSProperties, ReactNode, PropsWithChildren, JSX } from 'react';
4
+ import type {
5
+ KeyboardEvent,
6
+ MouseEvent,
7
+ CSSProperties,
8
+ ReactNode,
9
+ PropsWithChildren,
10
+ JSX,
11
+ } from 'react';
5
12
  import type { LinkProps } from '@redocly/theme/core/types';
6
13
 
7
14
  import { Link } from '@redocly/theme/components/Link/Link';
@@ -21,7 +28,7 @@ export type DropdownMenuItemProps = Partial<Pick<LinkProps, 'to' | 'target' | 'e
21
28
  separator?: boolean;
22
29
  disabled?: boolean;
23
30
  dangerous?: boolean;
24
- onAction?: () => void;
31
+ onAction?: (event: KeyboardEvent | MouseEvent) => void;
25
32
  active?: boolean;
26
33
  };
27
34
 
@@ -43,13 +50,13 @@ export function DropdownMenuItem({
43
50
  role = 'menuitem',
44
51
  ...otherProps
45
52
  }: PropsWithChildren<DropdownMenuItemProps>): JSX.Element {
46
- const handleClick = () => {
47
- onAction?.();
53
+ const handleClick = (event: MouseEvent) => {
54
+ onAction?.(event);
48
55
  };
49
56
 
50
57
  const handleKeyDown = (event: KeyboardEvent) => {
51
58
  if (event.key === 'Enter' || event.key === ' ') {
52
- onAction?.();
59
+ onAction?.(event);
53
60
  }
54
61
  };
55
62
 
package/src/index.ts CHANGED
@@ -318,6 +318,7 @@ export * from '@redocly/theme/icons/IdeaIcon/IdeaIcon';
318
318
  export * from '@redocly/theme/icons/NewChatIcon/NewChatIcon';
319
319
  /* Layouts */
320
320
  export * from '@redocly/theme/layouts/RootLayout';
321
+ export * from '@redocly/theme/layouts/CustomContexts';
321
322
  export * from '@redocly/theme/layouts/PageLayout';
322
323
  export * from '@redocly/theme/layouts/NotFound';
323
324
  export * from '@redocly/theme/layouts/Forbidden';
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+
3
+ import type { JSX } from 'react';
4
+
5
+ type CustomContextsProps = React.PropsWithChildren<{}>;
6
+
7
+ // Eject this component to wrap every page in custom React context providers.
8
+ export function CustomContexts({ children }: CustomContextsProps): JSX.Element {
9
+ return <>{children}</>;
10
+ }
@@ -7,6 +7,7 @@ import { Footer } from '@redocly/theme/components/Footer/Footer';
7
7
  import { SkipContent } from '@redocly/theme/components/SkipContent/SkipContent';
8
8
  import { AIAssistantButton } from '@redocly/theme/components/Buttons/AIAssistantButton';
9
9
  import { useThemeHooks } from '@redocly/theme/core/hooks';
10
+ import { CustomContexts } from '@redocly/theme/layouts/CustomContexts';
10
11
 
11
12
  export type LayoutConfig = {
12
13
  children: React.ReactNode;
@@ -18,11 +19,13 @@ export function RootLayout({ children }: LayoutConfig): JSX.Element {
18
19
 
19
20
  return (
20
21
  <div data-component-name="layouts/RootLayout">
21
- <SkipContent />
22
- <Navbar />
23
- {children}
24
- <Footer />
25
- {askAi && <AIAssistantButton />}
22
+ <CustomContexts>
23
+ <SkipContent />
24
+ <Navbar />
25
+ {children}
26
+ <Footer />
27
+ {askAi && <AIAssistantButton />}
28
+ </CustomContexts>
26
29
  </div>
27
30
  );
28
31
  }
@@ -0,0 +1,33 @@
1
+ import type { Config, Node } from '@markdoc/markdoc';
2
+ import type { MarkdocSchemaWrapper } from '@redocly/theme/markdoc/tags/types';
3
+
4
+ /** The part of a node the check reads; a stored plain-JSON AST node satisfies it too. */
5
+ type VisibilityNodeLike = { tag?: string; attributes?: Record<string, unknown> };
6
+
7
+ /** True for a node whose content must never reach the rendered page. */
8
+ export function isForAgentsOnly(node: VisibilityNodeLike): boolean {
9
+ return node.tag === 'visibility' && node.attributes?.for === 'agents';
10
+ }
11
+
12
+ /**
13
+ * A `renderTag` that empties nodes hidden from the page and leaves every other tag to the
14
+ * caller's own walk. Used by the text extractors that read a raw AST, which no tag schema runs on.
15
+ */
16
+ export function skipAgentsOnlyContent(node: VisibilityNodeLike): string | undefined {
17
+ return isForAgentsOnly(node) ? '' : undefined;
18
+ }
19
+
20
+ export const visibility: MarkdocSchemaWrapper = {
21
+ schema: {
22
+ attributes: {
23
+ for: { type: String, required: true, matches: ['humans', 'agents'] },
24
+ },
25
+ transform(node: Node, config: Config) {
26
+ return isForAgentsOnly(node) ? [] : node.transformChildren(config);
27
+ },
28
+ renderForLlms(node: Node, { getBody }) {
29
+ return node.attributes.for === 'humans' ? '' : getBody();
30
+ },
31
+ },
32
+ tagName: 'visibility',
33
+ };