@brillout/docpress 0.16.35 → 0.16.36

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.
@@ -10,7 +10,6 @@
10
10
  display: flex;
11
11
  flex-direction: row-reverse;
12
12
  gap: 2px;
13
- z-index: 3;
14
13
  top: var(--top-position);
15
14
  right: 42px;
16
15
  }
@@ -18,6 +17,7 @@
18
17
  .choice-select {
19
18
  background: #eee;
20
19
  font-size: 13.3333px;
20
+ z-index: 3;
21
21
 
22
22
  -webkit-user-select: none; /* Safari */
23
23
  -moz-user-select: none; /* Firefox */
@@ -58,6 +58,7 @@
58
58
  .choice-select[aria-expanded='true'] {
59
59
  overflow: visible;
60
60
  border-width: 0;
61
+ z-index: 5;
61
62
 
62
63
  .choice-select__list {
63
64
  border-style: solid;
@@ -109,7 +109,7 @@ function ChoiceGroup({ children, choiceGroup, parentChoiceGroup }: ChoiceGroupPr
109
109
  ))}
110
110
  </select>
111
111
  {children}
112
- {lvl === 0 && (
112
+ {lvl === 0 && !choiceGroup.hidden && (
113
113
  <div className={`choice-group__selects`}>
114
114
  {choiceGroupAll
115
115
  .slice()
@@ -28,9 +28,8 @@ function remarkChoiceGroup() {
28
28
  }
29
29
  })
30
30
 
31
- const replaced = new WeakSet()
32
31
  visit(tree, (node) => {
33
- if (!('children' in node) || replaced.has(node)) return 'skip'
32
+ if (!('children' in node) || node.data?.customDataIsVisited) return 'skip'
34
33
 
35
34
  let start = -1
36
35
  let end = 0
@@ -43,9 +42,10 @@ function remarkChoiceGroup() {
43
42
 
44
43
  for (const choiceNodes of choiceNodesFiltered) {
45
44
  const replacement = generateChoiceGroupCode(choiceNodes, node)
45
+ replacement.data ??= {}
46
+ replacement.data.customDataIsVisited = true
46
47
  replacements.push(replacement)
47
48
  }
48
- replaced.add(replacements)
49
49
 
50
50
  node.children.splice(start, end - start, ...replacements)
51
51
 
@@ -56,7 +56,7 @@ function remarkChoiceGroup() {
56
56
  for (; end < node.children.length; end++) {
57
57
  const child = node.children[end]!
58
58
 
59
- if (!['code', 'mdxJsxFlowElement', 'containerDirective'].includes(child.type)) {
59
+ if (!['code', 'containerDirective'].includes(child.type)) {
60
60
  process()
61
61
  continue
62
62
  }
@@ -85,7 +85,6 @@ function filterChoices(nodes: ChoiceNode['children']) {
85
85
  .map((node) => {
86
86
  const choice = node.data!.customDataChoice!
87
87
  const nodes = nodesByChoice.get(choice) ?? []
88
- node.data!.customDataChoice = undefined
89
88
  nodes.push(node)
90
89
  nodesByChoice.set(choice, nodes)
91
90
  })
@@ -99,6 +98,7 @@ function filterChoices(nodes: ChoiceNode['children']) {
99
98
 
100
99
  declare module 'mdast' {
101
100
  export interface Data {
101
+ customDataIsVisited?: boolean
102
102
  customDataChoice?: string
103
103
  customDataFilter?: string
104
104
  customDataParentChoiceGroup?: {
@@ -33,6 +33,9 @@ function remarkDetype() {
33
33
  // Skip if 'ts-only' meta is present
34
34
  if (node.meta?.includes('ts-only')) return
35
35
 
36
+ // Skip if 'customDataChoice' is 'TypeScript'
37
+ if (node.data?.customDataChoice === 'TypeScript') return
38
+
36
39
  // Collect this node for post-processing
37
40
  code_nodes.push({ codeBlock: node, index, parent })
38
41
  })
@@ -54,9 +57,6 @@ function transformYaml(node: CodeNode) {
54
57
  // Skip wrapping if the YAML code block hasn't changed
55
58
  if (codeBlockContentJs === codeBlock.value) return
56
59
 
57
- const meta = parseMetaString(codeBlock.meta, ['choice'])
58
- const { choice } = meta.props
59
- codeBlock.meta = meta.rest
60
60
  const { position, ...rest } = codeBlock
61
61
 
62
62
  // Create a new code node for the JS version based on the modified YAML
@@ -71,21 +71,16 @@ function transformYaml(node: CodeNode) {
71
71
  { choiceValue: 'TypeScript', children: [codeBlock] },
72
72
  ]
73
73
  const replacement = generateChoiceGroupCode(choiceNodes, parent, true)
74
- replacement.data ??= { customDataChoice: choice, customDataFilter: 'codeLang' }
75
74
 
76
75
  parent.children.splice(index, 1, replacement)
77
76
  }
78
77
 
79
78
  async function transformTsToJs(node: CodeNode, file: VFile) {
80
79
  const { codeBlock, index, parent } = node
81
- const meta = parseMetaString(codeBlock.meta, ['max-width', 'choice'])
80
+ const meta = parseMetaString(codeBlock.meta, ['max-width'])
82
81
  const maxWidth = Number(meta.props['max-width'])
83
- const { choice } = meta.props
84
82
  codeBlock.meta = meta.rest
85
83
 
86
- codeBlock.data ??= { customDataChoice: choice, customDataFilter: 'codeLang' }
87
- if (choice === 'TypeScript') return
88
-
89
84
  let codeBlockReplacedJs = replaceFileNameSuffixes(codeBlock.value)
90
85
  let codeBlockContentJs = ''
91
86
 
@@ -126,7 +121,7 @@ async function transformTsToJs(node: CodeNode, file: VFile) {
126
121
  // No wrapping needed if JS and TS code are still identical
127
122
  if (codeBlockContentJs === codeBlock.value) return
128
123
 
129
- const { position, lang, data, ...rest } = codeBlock
124
+ const { position, lang, ...rest } = codeBlock
130
125
 
131
126
  const tsCode: Code = { ...rest, lang }
132
127
  const jsCode: Code = {
@@ -145,8 +140,6 @@ async function transformTsToJs(node: CodeNode, file: VFile) {
145
140
  const hide = codeBlockReplacedJs === codeBlockContentJs
146
141
  const replacement = generateChoiceGroupCode(choiceNodes, parent, hide)
147
142
 
148
- replacement.data ??= { ...data }
149
-
150
143
  parent.children.splice(index, 1, replacement)
151
144
  }
152
145
 
@@ -4,7 +4,6 @@ import type { Code, Root } from 'mdast'
4
4
  import type { VFile } from '@mdx-js/mdx/internal-create-format-aware-processors'
5
5
  import { visit } from 'unist-util-visit'
6
6
  import convert_ from 'npm-to-yarn'
7
- import { parseMetaString } from './rehypeMetaToProps.js'
8
7
  import { generateChoiceGroupCode } from './utils/generateChoiceGroupCode.js'
9
8
  import { assertUsage } from '../utils/assert.js'
10
9
  import pc from '@brillout/picocolors'
@@ -25,15 +24,8 @@ function remarkPkgManager() {
25
24
  }. Replace it with the equivalent 'npm' command for the package manager toggle to work.`,
26
25
  )
27
26
  if (!node.value.includes('npm ') && !node.value.includes('npx ')) return
28
- let choice: string | undefined = undefined
29
27
  const nodes = new Map<string, Code>()
30
28
 
31
- if (node.meta) {
32
- const meta = parseMetaString(node.meta, ['choice'])
33
- choice = meta.props['choice']
34
- node.meta = meta.rest
35
- }
36
-
37
29
  node.value = node.value.replaceAll('npm i ', 'npm install ')
38
30
  nodes.set('npm', node)
39
31
 
@@ -49,7 +41,6 @@ function remarkPkgManager() {
49
41
  const choiceNodes = [...nodes].map(([name, node]) => ({ choiceValue: name, children: [node] }))
50
42
  const replacement = generateChoiceGroupCode(choiceNodes, parent)
51
43
 
52
- replacement.data ??= { customDataChoice: choice, customDataFilter: replacement.type }
53
44
  parent.children.splice(index, 1, replacement)
54
45
  })
55
46
  }
@@ -25,6 +25,11 @@ const CHOICES_BUILT_IN: Record<string, { choices: string[]; default: string }> =
25
25
 
26
26
  function generateChoiceGroupCode(choiceNodes: ChoiceNode[], parent: Parent, hide: boolean = false): MdxJsxFlowElement {
27
27
  let lvl: number = 0
28
+ const customHidden = choiceNodes.some((node) =>
29
+ node.children.some((node) => node.type === 'containerDirective' && node.children[0]!.type !== 'code'),
30
+ )
31
+ const hidden = hide || customHidden
32
+
28
33
  const { choiceGroup, mergedChoiceNodes } = resolveChoiceGroupNodes(choiceNodes)
29
34
  const attributes: MdxJsxAttribute[] = []
30
35
  const children: MdxJsxFlowElement[] = []
@@ -66,7 +71,7 @@ function generateChoiceGroupCode(choiceNodes: ChoiceNode[], parent: Parent, hide
66
71
  }
67
72
 
68
73
  attributes.push(
69
- expressionToAttribute('choiceGroup', { ...choiceGroup, hidden: choiceNodes.length === 1 || hide, lvl }),
74
+ expressionToAttribute('choiceGroup', { ...choiceGroup, hidden: choiceNodes.length === 1 || hidden, lvl }),
70
75
  )
71
76
 
72
77
  const choiceGroupNode: MdxJsxFlowElement = {
@@ -3,6 +3,7 @@ import type { Root } from 'mdast';
3
3
  declare function remarkChoiceGroup(): (tree: Root) => void;
4
4
  declare module 'mdast' {
5
5
  interface Data {
6
+ customDataIsVisited?: boolean;
6
7
  customDataChoice?: string;
7
8
  customDataFilter?: string;
8
9
  customDataParentChoiceGroup?: {
@@ -24,9 +24,8 @@ function remarkChoiceGroup() {
24
24
  }
25
25
  }
26
26
  });
27
- const replaced = new WeakSet();
28
27
  visit(tree, (node) => {
29
- if (!('children' in node) || replaced.has(node))
28
+ if (!('children' in node) || node.data?.customDataIsVisited)
30
29
  return 'skip';
31
30
  let start = -1;
32
31
  let end = 0;
@@ -38,16 +37,17 @@ function remarkChoiceGroup() {
38
37
  const replacements = [];
39
38
  for (const choiceNodes of choiceNodesFiltered) {
40
39
  const replacement = generateChoiceGroupCode(choiceNodes, node);
40
+ replacement.data ?? (replacement.data = {});
41
+ replacement.data.customDataIsVisited = true;
41
42
  replacements.push(replacement);
42
43
  }
43
- replaced.add(replacements);
44
44
  node.children.splice(start, end - start, ...replacements);
45
45
  end = start;
46
46
  start = -1;
47
47
  };
48
48
  for (; end < node.children.length; end++) {
49
49
  const child = node.children[end];
50
- if (!['code', 'mdxJsxFlowElement', 'containerDirective'].includes(child.type)) {
50
+ if (!['code', 'containerDirective'].includes(child.type)) {
51
51
  process();
52
52
  continue;
53
53
  }
@@ -72,7 +72,6 @@ function filterChoices(nodes) {
72
72
  .map((node) => {
73
73
  const choice = node.data.customDataChoice;
74
74
  const nodes = nodesByChoice.get(choice) ?? [];
75
- node.data.customDataChoice = undefined;
76
75
  nodes.push(node);
77
76
  nodesByChoice.set(choice, nodes);
78
77
  });
@@ -22,6 +22,9 @@ function remarkDetype() {
22
22
  // Skip if 'ts-only' meta is present
23
23
  if (node.meta?.includes('ts-only'))
24
24
  return;
25
+ // Skip if 'customDataChoice' is 'TypeScript'
26
+ if (node.data?.customDataChoice === 'TypeScript')
27
+ return;
25
28
  // Collect this node for post-processing
26
29
  code_nodes.push({ codeBlock: node, index, parent });
27
30
  });
@@ -41,9 +44,6 @@ function transformYaml(node) {
41
44
  // Skip wrapping if the YAML code block hasn't changed
42
45
  if (codeBlockContentJs === codeBlock.value)
43
46
  return;
44
- const meta = parseMetaString(codeBlock.meta, ['choice']);
45
- const { choice } = meta.props;
46
- codeBlock.meta = meta.rest;
47
47
  const { position, ...rest } = codeBlock;
48
48
  // Create a new code node for the JS version based on the modified YAML
49
49
  const yamlJsCode = {
@@ -56,18 +56,13 @@ function transformYaml(node) {
56
56
  { choiceValue: 'TypeScript', children: [codeBlock] },
57
57
  ];
58
58
  const replacement = generateChoiceGroupCode(choiceNodes, parent, true);
59
- replacement.data ?? (replacement.data = { customDataChoice: choice, customDataFilter: 'codeLang' });
60
59
  parent.children.splice(index, 1, replacement);
61
60
  }
62
61
  async function transformTsToJs(node, file) {
63
62
  const { codeBlock, index, parent } = node;
64
- const meta = parseMetaString(codeBlock.meta, ['max-width', 'choice']);
63
+ const meta = parseMetaString(codeBlock.meta, ['max-width']);
65
64
  const maxWidth = Number(meta.props['max-width']);
66
- const { choice } = meta.props;
67
65
  codeBlock.meta = meta.rest;
68
- codeBlock.data ?? (codeBlock.data = { customDataChoice: choice, customDataFilter: 'codeLang' });
69
- if (choice === 'TypeScript')
70
- return;
71
66
  let codeBlockReplacedJs = replaceFileNameSuffixes(codeBlock.value);
72
67
  let codeBlockContentJs = '';
73
68
  // Remove TypeScript from the TS/TSX/Vue code node
@@ -104,7 +99,7 @@ async function transformTsToJs(node, file) {
104
99
  // No wrapping needed if JS and TS code are still identical
105
100
  if (codeBlockContentJs === codeBlock.value)
106
101
  return;
107
- const { position, lang, data, ...rest } = codeBlock;
102
+ const { position, lang, ...rest } = codeBlock;
108
103
  const tsCode = { ...rest, lang };
109
104
  const jsCode = {
110
105
  ...rest,
@@ -120,7 +115,6 @@ async function transformTsToJs(node, file) {
120
115
  // Add `hide` prop to `<ChoiceGroup>` if the only change was replacing `.ts` with `.js`
121
116
  const hide = codeBlockReplacedJs === codeBlockContentJs;
122
117
  const replacement = generateChoiceGroupCode(choiceNodes, parent, hide);
123
- replacement.data ?? (replacement.data = { ...data });
124
118
  parent.children.splice(index, 1, replacement);
125
119
  }
126
120
  // Replace all '.ts' extensions with '.js'
@@ -1,7 +1,6 @@
1
1
  export { remarkPkgManager };
2
2
  import { visit } from 'unist-util-visit';
3
3
  import convert_ from 'npm-to-yarn';
4
- import { parseMetaString } from './rehypeMetaToProps.js';
5
4
  import { generateChoiceGroupCode } from './utils/generateChoiceGroupCode.js';
6
5
  import { assertUsage } from '../utils/assert.js';
7
6
  import pc from '@brillout/picocolors';
@@ -18,13 +17,7 @@ function remarkPkgManager() {
18
17
  assertUsage(!node.value.includes('pnpm'), `Found a 'pnpm' command in the code block at: ${pc.bold(pc.blue(file.path))}, line ${node.position?.start.line}. Replace it with the equivalent 'npm' command for the package manager toggle to work.`);
19
18
  if (!node.value.includes('npm ') && !node.value.includes('npx '))
20
19
  return;
21
- let choice = undefined;
22
20
  const nodes = new Map();
23
- if (node.meta) {
24
- const meta = parseMetaString(node.meta, ['choice']);
25
- choice = meta.props['choice'];
26
- node.meta = meta.rest;
27
- }
28
21
  node.value = node.value.replaceAll('npm i ', 'npm install ');
29
22
  nodes.set('npm', node);
30
23
  for (const pm of PKG_MANAGERS) {
@@ -37,7 +30,6 @@ function remarkPkgManager() {
37
30
  }
38
31
  const choiceNodes = [...nodes].map(([name, node]) => ({ choiceValue: name, children: [node] }));
39
32
  const replacement = generateChoiceGroupCode(choiceNodes, parent);
40
- replacement.data ?? (replacement.data = { customDataChoice: choice, customDataFilter: replacement.type });
41
33
  parent.children.splice(index, 1, replacement);
42
34
  });
43
35
  };
@@ -14,6 +14,8 @@ const CHOICES_BUILT_IN = {
14
14
  };
15
15
  function generateChoiceGroupCode(choiceNodes, parent, hide = false) {
16
16
  let lvl = 0;
17
+ const customHidden = choiceNodes.some((node) => node.children.some((node) => node.type === 'containerDirective' && node.children[0].type !== 'code'));
18
+ const hidden = hide || customHidden;
17
19
  const { choiceGroup, mergedChoiceNodes } = resolveChoiceGroupNodes(choiceNodes);
18
20
  const attributes = [];
19
21
  const children = [];
@@ -49,7 +51,7 @@ function generateChoiceGroupCode(choiceNodes, parent, hide = false) {
49
51
  lvl = parentLvl + 1;
50
52
  parent.data.customDataParentChoiceGroup = undefined;
51
53
  }
52
- attributes.push(expressionToAttribute('choiceGroup', { ...choiceGroup, hidden: choiceNodes.length === 1 || hide, lvl }));
54
+ attributes.push(expressionToAttribute('choiceGroup', { ...choiceGroup, hidden: choiceNodes.length === 1 || hidden, lvl }));
53
55
  const choiceGroupNode = {
54
56
  type: 'mdxJsxFlowElement',
55
57
  name: 'ChoiceGroup',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.16.35",
3
+ "version": "0.16.36",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",