@redocly/theme 0.71.0-next.1 → 0.71.0-next.2
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/lib/components/Dropdown/DropdownMenuItem.d.ts +2 -2
- package/lib/components/Dropdown/DropdownMenuItem.js +3 -3
- package/lib/markdoc/tags/visibility.d.ts +15 -0
- package/lib/markdoc/tags/visibility.js +32 -0
- package/package.json +2 -2
- package/src/components/Dropdown/DropdownMenuItem.tsx +12 -5
- package/src/markdoc/tags/visibility.ts +33 -0
|
@@ -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' : '');
|
|
@@ -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.
|
|
3
|
+
"version": "0.71.0-next.2",
|
|
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.
|
|
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 {
|
|
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
|
|
|
@@ -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
|
+
};
|