@alauda/doom 2.5.2 → 2.5.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.
package/lib/cli/index.js CHANGED
@@ -85,7 +85,7 @@ program
85
85
  cwd: CWD,
86
86
  });
87
87
  let isRestarting = false;
88
- cliWatcher.on('all', async (eventName, filepath) => {
88
+ cliWatcher.on('all', async (...[eventName, filepath]) => {
89
89
  console.log(eventName, filepath);
90
90
  if (eventName === 'add' ||
91
91
  eventName === 'unlink' ||
@@ -13,6 +13,7 @@ export * from './no-empty-table-cell.ts';
13
13
  export * from './no-heading-punctuation.ts';
14
14
  export * from './no-heading-special-characters.ts';
15
15
  export * from './no-heading-sup-sub.ts';
16
+ export * from './no-legacy-os-names.ts';
16
17
  export * from './no-multi-open-api-paths.ts';
17
18
  export * from './no-paragraph-indent.ts';
18
19
  export * from './no-unmatched-anchor.ts';
@@ -12,6 +12,7 @@ export * from "./no-empty-table-cell.js";
12
12
  export * from "./no-heading-punctuation.js";
13
13
  export * from "./no-heading-special-characters.js";
14
14
  export * from "./no-heading-sup-sub.js";
15
+ export * from "./no-legacy-os-names.js";
15
16
  export * from "./no-multi-open-api-paths.js";
16
17
  export * from "./no-paragraph-indent.js";
17
18
  export * from "./no-unmatched-anchor.js";
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const noLegacyOSNames: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -0,0 +1,51 @@
1
+ import { lintRule } from 'unified-lint-rule';
2
+ import { visitParents } from 'unist-util-visit-parents';
3
+ const LEGACY_OS_NAME_REGEX = /(?<![\p{L}\p{N}])(?:micro\s*os|micros|kube\s*os)(?![\p{L}\p{N}])/giu;
4
+ const isStringValueNode = (node) => !!node &&
5
+ typeof node === 'object' &&
6
+ 'value' in node &&
7
+ typeof node.value === 'string';
8
+ const reportLegacyOSNames = (value, report) => {
9
+ for (const { 0: legacyName } of value.matchAll(LEGACY_OS_NAME_REGEX)) {
10
+ report(legacyName);
11
+ }
12
+ };
13
+ const createMessage = (legacyName) => `Unexpected legacy OS name "${legacyName}", use "Alauda OS" or "alauda os" instead`;
14
+ const getAttributeStringValue = (value) => {
15
+ if (typeof value === 'string') {
16
+ return value;
17
+ }
18
+ return value.value;
19
+ };
20
+ export const noLegacyOSNames = lintRule('doom-lint:no-legacy-os-names', (root, vfile) => {
21
+ visitParents(root, (node, parents) => {
22
+ if (!isStringValueNode(node)) {
23
+ return;
24
+ }
25
+ reportLegacyOSNames(node.value, (legacyName) => {
26
+ vfile.message(createMessage(legacyName), {
27
+ ancestors: [...parents, node],
28
+ place: node.position,
29
+ });
30
+ });
31
+ });
32
+ visitParents(root, ['mdxJsxFlowElement', 'mdxJsxTextElement'], (element, parents) => {
33
+ for (const attribute of element.attributes) {
34
+ if (attribute.type !== 'mdxJsxAttribute' ||
35
+ typeof attribute.value === 'boolean' ||
36
+ attribute.value == null) {
37
+ continue;
38
+ }
39
+ const value = getAttributeStringValue(attribute.value);
40
+ if (value == null) {
41
+ continue;
42
+ }
43
+ reportLegacyOSNames(value, (legacyName) => {
44
+ vfile.message(createMessage(legacyName), {
45
+ ancestors: [...parents, element],
46
+ place: attribute.position,
47
+ });
48
+ });
49
+ }
50
+ });
51
+ });
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, headingAnchorFormat, noDeepHeading, noDeepList, noMultiOpenAPIPaths, noParagraphIndent, noUnmatchedAnchor, site, tableSize, titleRequired, unitCase, } from "./remark-lint/index.js";
13
+ import doomLint, { checkDeadLinks, headingAnchorFormat, noDeepHeading, noDeepList, noLegacyOSNames, noMultiOpenAPIPaths, noParagraphIndent, noUnmatchedAnchor, site, tableSize, titleRequired, unitCase, } from "./remark-lint/index.js";
14
14
  export default {
15
15
  plugins: [
16
16
  remarkDirective,
@@ -27,6 +27,7 @@ export default {
27
27
  headingAnchorFormat,
28
28
  noDeepHeading,
29
29
  noDeepList,
30
+ noLegacyOSNames,
30
31
  noMultiOpenAPIPaths,
31
32
  noParagraphIndent,
32
33
  noUnmatchedAnchor,
@@ -1,2 +1,3 @@
1
1
  import { type CodeBlockProps } from '@rspress/core/theme-original';
2
+ export declare const getCodeBlockCopyText: (codeBlockElement: Element | null) => string;
2
3
  export declare const CodeBlock: (props: CodeBlockProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,66 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { CodeBlock as OriginalCodeBlock, } from '@rspress/core/theme-original';
2
+ import { CodeBlock as OriginalCodeBlock, copyToClipboard, } from '@rspress/core/theme-original';
3
+ import { useCallback } from 'react';
3
4
  import { AutoExpandable } from './AutoExpandable.js';
4
- export const CodeBlock = (props) => (_jsx(AutoExpandable, { children: _jsx(OriginalCodeBlock, { ...props }) }));
5
+ const COPIED_CLASS = 'rp-code-copy-button--copied';
6
+ const COPY_IGNORE_SELECTOR = '.rp-copy-ignore, .linenumber';
7
+ const timeoutIdMap = new WeakMap();
8
+ const getCopySourceElement = (codeBlockElement) => codeBlockElement?.querySelector('pre code') ??
9
+ codeBlockElement?.querySelector('code') ??
10
+ codeBlockElement?.querySelector('pre') ??
11
+ null;
12
+ const removeIgnoredElements = (element) => {
13
+ for (const ignoredElement of element.querySelectorAll(COPY_IGNORE_SELECTOR)) {
14
+ ignoredElement.remove();
15
+ }
16
+ };
17
+ export const getCodeBlockCopyText = (codeBlockElement) => {
18
+ const sourceElement = getCopySourceElement(codeBlockElement);
19
+ if (!sourceElement) {
20
+ return '';
21
+ }
22
+ const clonedSourceElement = sourceElement.cloneNode(true);
23
+ if (!(clonedSourceElement instanceof Element)) {
24
+ return sourceElement.textContent;
25
+ }
26
+ removeIgnoredElements(clonedSourceElement);
27
+ const lines = clonedSourceElement.querySelectorAll('.line');
28
+ if (lines.length) {
29
+ return Array.from(lines, (line) => line.textContent).join('\n');
30
+ }
31
+ return clonedSourceElement.textContent;
32
+ };
33
+ const markCopied = (copyButtonElement) => {
34
+ copyButtonElement.classList.add(COPIED_CLASS);
35
+ const timeoutId = timeoutIdMap.get(copyButtonElement);
36
+ if (timeoutId) {
37
+ clearTimeout(timeoutId);
38
+ }
39
+ timeoutIdMap.set(copyButtonElement, setTimeout(() => {
40
+ copyButtonElement.classList.remove(COPIED_CLASS);
41
+ copyButtonElement.blur();
42
+ timeoutIdMap.delete(copyButtonElement);
43
+ }, 2000));
44
+ };
45
+ const copyCodeBlock = async (codeBlockElement, copyButtonElement) => {
46
+ const text = getCodeBlockCopyText(codeBlockElement);
47
+ const isCopied = await copyToClipboard(text);
48
+ if (isCopied) {
49
+ markCopied(copyButtonElement);
50
+ }
51
+ };
52
+ export const CodeBlock = (props) => {
53
+ const onClickCapture = useCallback((event) => {
54
+ if (!(event.target instanceof Element)) {
55
+ return;
56
+ }
57
+ const copyButtonElement = event.target.closest('.rp-code-copy-button');
58
+ if (!copyButtonElement) {
59
+ return;
60
+ }
61
+ event.preventDefault();
62
+ event.stopPropagation();
63
+ void copyCodeBlock(copyButtonElement.closest('.rp-codeblock'), copyButtonElement);
64
+ }, []);
65
+ return (_jsx(AutoExpandable, { children: _jsx("div", { onClickCapture: onClickCapture, children: _jsx(OriginalCodeBlock, { ...props }) }) }));
66
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -44,7 +44,7 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@alauda/doc-stream-sdk": "0.1.0",
47
- "@alauda/doom-export": "^0.4.1",
47
+ "@alauda/doom-export": "^0.4.2",
48
48
  "@cspell/eslint-plugin": "^10.0.0",
49
49
  "@eslint-react/eslint-plugin": "^5.8.3",
50
50
  "@eslint/js": "^10.0.1",