@alauda/doom 1.18.2 → 1.19.0

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.
@@ -12,6 +12,7 @@ export * from './no-heading-punctuation.ts';
12
12
  export * from './no-heading-special-characters.ts';
13
13
  export * from './no-heading-sup-sub.ts';
14
14
  export * from './no-paragraph-indent.ts';
15
+ export * from './site.ts';
15
16
  export * from './table-size.ts';
16
17
  export * from './unit-case.ts';
17
18
  declare const doomLint: Plugin<[], Root>;
@@ -11,6 +11,7 @@ export * from "./no-heading-punctuation.js";
11
11
  export * from "./no-heading-special-characters.js";
12
12
  export * from "./no-heading-sup-sub.js";
13
13
  export * from "./no-paragraph-indent.js";
14
+ export * from "./site.js";
14
15
  export * from "./table-size.js";
15
16
  export * from "./unit-case.js";
16
17
  const doomLint = function () {
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const site: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,38 @@
1
+ import path from 'node:path';
2
+ import { lintRule } from 'unified-lint-rule';
3
+ import { visitParents } from 'unist-util-visit-parents';
4
+ import { SITES_FILE } from "../cli/constants.js";
5
+ import { pathExists } from "../utils/fs.js";
6
+ import { resolveStaticConfig } from "../utils/helpers.js";
7
+ const SITE_ELEMENTS = new Set([
8
+ 'ExternalApisOverview',
9
+ 'ExternalSite',
10
+ 'ExternalSiteLink',
11
+ ]);
12
+ const sitesConfigFilePath = path.resolve(SITES_FILE);
13
+ let sites;
14
+ export const site = lintRule('doom:lint-site', async (root, vfile) => {
15
+ if (!sites) {
16
+ if (await pathExists(sitesConfigFilePath, 'file')) {
17
+ sites = await resolveStaticConfig(sitesConfigFilePath);
18
+ }
19
+ else {
20
+ sites = [];
21
+ }
22
+ }
23
+ visitParents(root, 'mdxJsxFlowElement', (element, parents) => {
24
+ if (!sites?.length || !element.name || !SITE_ELEMENTS.has(element.name)) {
25
+ return;
26
+ }
27
+ const nameAttr = element.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'name');
28
+ const nameVal = nameAttr?.value;
29
+ if (typeof nameVal === 'string' &&
30
+ sites.some((site) => site.name === nameVal)) {
31
+ return;
32
+ }
33
+ vfile.message(`Invalid site \`name\` property value \`${typeof nameVal === 'string' ? nameVal : nameVal?.value}\` which should be static string matching a site name from \`${SITES_FILE}\` config.`, {
34
+ ancestors: [...parents, element],
35
+ place: (nameAttr ?? element).position,
36
+ });
37
+ });
38
+ });
package/lib/remarkrc.js CHANGED
@@ -10,7 +10,7 @@ import remarkLintLintMatchPunctuation from 'remark-lint-match-punctuation';
10
10
  import remarkLintNoChinesePunctuationInNumber from 'remark-lint-no-chinese-punctuation-in-number';
11
11
  import remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section';
12
12
  import remarkLintNoHiddenTableCell from 'remark-lint-no-hidden-table-cell';
13
- import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noParagraphIndent, tableSize, unitCase, } from "./remark-lint/index.js";
13
+ import doomLint, { checkDeadLinks, noDeepHeading, noDeepList, noParagraphIndent, site, tableSize, unitCase, } from "./remark-lint/index.js";
14
14
  export default {
15
15
  plugins: [
16
16
  remarkDirective,
@@ -27,6 +27,7 @@ export default {
27
27
  noDeepHeading,
28
28
  noDeepList,
29
29
  noParagraphIndent,
30
+ site,
30
31
  tableSize,
31
32
  unitCase,
32
33
  ],
@@ -1,4 +1,4 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useLang, useSite } from '@rspress/core/runtime';
3
3
  import { addTrailingSlash, isExternalUrl, normalizeHref, parseUrl, removeLeadingSlash, } from '@rspress/shared';
4
4
  import { DEFAULT_PAGE_EXTENSIONS } from '@rspress/shared/constants';
@@ -7,17 +7,16 @@ import virtual from 'doom-@global-virtual';
7
7
  import { useMemo } from 'react';
8
8
  import { isUnversioned } from '../../shared/helpers.js';
9
9
  import { useIsPrint } from '../hooks/index.js';
10
- import { Directive } from './Directive.js';
11
10
  const ExternalSiteLink_ = ({ name, href = '', className, ...props }) => {
12
11
  const isPrint = useIsPrint();
13
12
  const { site: siteData } = useSite();
14
13
  const site = useMemo(() => virtual.sites?.find((s) => s.name === name), [name]);
15
14
  const lang = useLang();
16
15
  if (!site) {
17
- return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
16
+ throw new Error(`No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``);
18
17
  }
19
18
  if (isExternalUrl(href)) {
20
- return _jsxs(Directive, { type: "danger", children: ["Invalid href `", href, "` found"] });
19
+ throw new Error(`Invalid href \`${href}\` found`);
21
20
  }
22
21
  let { url, hash } = parseUrl(href);
23
22
  const extname = url.split('.').at(-1);
@@ -34,7 +34,7 @@ export const ExternalSiteBase = ({ name, template }) => {
34
34
  const lang = useLang();
35
35
  const displayName = useMemo(() => site?.displayName?.[lang] || site?.displayName?.en || name.toUpperCase(), [lang, name, site?.displayName]);
36
36
  if (!site) {
37
- return (_jsxs(Directive, { type: "danger", children: ["No site with name `", name, "` found, please ensure it's already defined at `sites.yaml`"] }));
37
+ throw new Error(`No site with name \`${name}\` found, please ensure it's already defined at \`sites.yaml\``);
38
38
  }
39
39
  const Notes = template === 'apisOverview' ? ApisOverviewNotes : SiteNotes;
40
40
  const Note = Notes[lang] || Notes.en;
@@ -0,0 +1,5 @@
1
+ import { type ReactNode } from 'react';
2
+ export declare const AutoExpandable: ({ threshold, children, }: {
3
+ threshold?: number;
4
+ children: ReactNode;
5
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { IconDown, SvgWrapper } from '@rspress/core/theme';
3
+ import { clsx } from 'clsx';
4
+ import { useCallback, useEffect, useRef, useState } from 'react';
5
+ import classes from '@alauda/doom/styles/auto-expandable.module.scss';
6
+ export const AutoExpandable = ({ threshold = 240, children, }) => {
7
+ const ref = useRef(null);
8
+ const [expandable, setExpandable] = useState(false);
9
+ const [expanded, setExpanded] = useState(false);
10
+ useEffect(() => {
11
+ if (!ref.current) {
12
+ return;
13
+ }
14
+ if (ref.current.scrollHeight > threshold) {
15
+ // eslint-disable-next-line react-hooks/set-state-in-effect, @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
16
+ setExpandable(true);
17
+ }
18
+ }, [threshold]);
19
+ const onExpandChange = useCallback(() => {
20
+ setExpanded((expanded) => !expanded);
21
+ }, []);
22
+ return (_jsxs("div", { ref: ref, className: classes.container, children: [_jsx("div", { className: clsx({
23
+ [classes.expandable]: expandable,
24
+ [classes.expanded]: expanded,
25
+ }), children: children }), expandable && (_jsx("div", { className: classes.actionContainer, children: _jsxs("button", { className: classes.action, type: "button", onClick: onExpandChange, "aria-expanded": expanded, children: ["Show ", expanded ? 'less' : 'more', _jsx(SvgWrapper, { className: clsx(classes.arrow, {
26
+ [classes.expanded]: expanded,
27
+ }), icon: IconDown })] }) }))] }));
28
+ };
@@ -0,0 +1,2 @@
1
+ import { type CodeBlockProps } from '@rspress/core/theme-original';
2
+ export declare const CodeBlock: (props: CodeBlockProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CodeBlock as OriginalCodeBlock, } from '@rspress/core/theme-original';
3
+ import { AutoExpandable } from './AutoExpandable.js';
4
+ export const CodeBlock = (props) => (_jsx(AutoExpandable, { children: _jsx(OriginalCodeBlock, { ...props }) }));
@@ -1,4 +1,5 @@
1
1
  export * from '@rspress/core/theme-original';
2
2
  export { EditLink } from './EditLink.js';
3
3
  export { Layout } from './Layout.js';
4
+ export { CodeBlock } from './CodeBlock.js';
4
5
  export { Search } from './Search.js';
@@ -2,4 +2,5 @@
2
2
  export * from '@rspress/core/theme-original';
3
3
  export { EditLink } from './EditLink.js';
4
4
  export { Layout } from './Layout.js';
5
+ export { CodeBlock } from './CodeBlock.js';
5
6
  export { Search } from './Search.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.18.2",
3
+ "version": "1.19.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -0,0 +1,77 @@
1
+ .container {
2
+ &:has(.expandable :global .rp-codeblock) {
3
+ border: var(--rp-code-block-border);
4
+ border-radius: var(--rp-radius);
5
+ }
6
+
7
+ .expandable {
8
+ max-height: 200px;
9
+ overflow: auto;
10
+
11
+ :global .rp-codeblock {
12
+ border: 0;
13
+ margin: 0;
14
+ }
15
+
16
+ &.expanded {
17
+ max-height: none;
18
+ }
19
+ }
20
+ }
21
+
22
+ .action-container {
23
+ display: flex;
24
+ justify-content: center;
25
+ }
26
+
27
+ .action {
28
+ display: inline-flex;
29
+ justify-content: center;
30
+ align-items: center;
31
+ height: 36px;
32
+ padding: 0 12px;
33
+ gap: 6px;
34
+ margin: 1rem 0;
35
+
36
+ border-radius: 8px;
37
+ border: 1px solid var(--rp-c-divider-light);
38
+ background: var(--rp-c-bg);
39
+ color: var(--rp-c-text-2);
40
+
41
+ font-size: 14px;
42
+ font-weight: 500;
43
+ line-height: normal;
44
+
45
+ user-select: none;
46
+ white-space: nowrap;
47
+
48
+ transition:
49
+ background 0.2s,
50
+ border-color 0.2s,
51
+ color 0.2s,
52
+ box-shadow 0.2s,
53
+ transform 0.1s,
54
+ opacity 0.2s;
55
+
56
+ cursor: pointer;
57
+
58
+ &:hover {
59
+ background: var(--rp-c-bg-soft);
60
+ border-color: var(--rp-c-divider);
61
+ color: var(--rp-c-text-1);
62
+ box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
63
+ }
64
+
65
+ &:active {
66
+ background: var(--rp-c-bg-soft);
67
+ box-shadow: none;
68
+ }
69
+ }
70
+
71
+ .arrow {
72
+ transition: transform 0.2s;
73
+
74
+ &.expanded {
75
+ transform: rotate(180deg);
76
+ }
77
+ }