@mintlify/common 1.0.934 → 1.0.935

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.
@@ -22,25 +22,110 @@ function getVisibilityFor(node) {
22
22
  }
23
23
  return undefined;
24
24
  }
25
- function transformChildren(children) {
26
- return children.flatMap((child) => transformNode(child));
25
+ function getStringAttribute(node, name) {
26
+ for (const attr of node.attributes) {
27
+ if (attr.type === 'mdxJsxAttribute' && attr.name === name && typeof attr.value === 'string') {
28
+ return attr.value;
29
+ }
30
+ }
31
+ return undefined;
32
+ }
33
+ // `export * from` is intentionally ignored: it exposes no statically-knowable
34
+ // names and creates no page-local JSX bindings in MDX, so there is nothing to
35
+ // collect for ghost-tag stripping.
36
+ function collectEsmIdentifiers(children) {
37
+ var _a, _b, _c;
38
+ const names = new Set();
39
+ for (const child of children) {
40
+ if (child.type !== 'mdxjsEsm')
41
+ continue;
42
+ for (const statement of (_c = (_b = (_a = child.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body) !== null && _c !== void 0 ? _c : []) {
43
+ if (statement.type === 'ImportDeclaration') {
44
+ for (const specifier of statement.specifiers) {
45
+ names.add(specifier.local.name);
46
+ }
47
+ }
48
+ if (statement.type === 'ExportNamedDeclaration') {
49
+ if (statement.declaration) {
50
+ if (statement.declaration.type === 'VariableDeclaration') {
51
+ for (const declarator of statement.declaration.declarations) {
52
+ if (declarator.id.type === 'Identifier') {
53
+ names.add(declarator.id.name);
54
+ }
55
+ }
56
+ }
57
+ else if (statement.declaration.id) {
58
+ names.add(statement.declaration.id.name);
59
+ }
60
+ }
61
+ // Re-exports: `export { Panel } from '...'` keep names in specifiers
62
+ for (const specifier of statement.specifiers) {
63
+ if (specifier.local.type === 'Identifier') {
64
+ names.add(specifier.local.name);
65
+ }
66
+ if (specifier.exported.type === 'Identifier') {
67
+ names.add(specifier.exported.name);
68
+ }
69
+ }
70
+ }
71
+ if (statement.type === 'ExportDefaultDeclaration') {
72
+ const declaration = statement.declaration;
73
+ if ((declaration.type === 'FunctionDeclaration' || declaration.type === 'ClassDeclaration') &&
74
+ declaration.id) {
75
+ names.add(declaration.id.name);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ return names;
27
81
  }
28
- function transformNode(node) {
29
- if (isMdxJsxElement(node) && node.name === 'Visibility') {
30
- const audience = getVisibilityFor(node);
31
- if (audience === 'humans') {
32
- return [];
82
+ function transformChildren(children, strippedNames) {
83
+ return children.flatMap((child) => transformNode(child, strippedNames));
84
+ }
85
+ function transformNode(node, strippedNames) {
86
+ var _a;
87
+ // The output is terminal agent-facing markdown, never re-parsed as MDX, so
88
+ // ESM is dropped wholesale even when kept content references its components.
89
+ if (node.type === 'mdxjsEsm') {
90
+ return [];
91
+ }
92
+ if (isMdxJsxElement(node)) {
93
+ if (node.name === 'Visibility') {
94
+ const audience = getVisibilityFor(node);
95
+ if (audience === 'humans') {
96
+ return [];
97
+ }
98
+ if (audience === 'agents') {
99
+ return transformChildren(node.children, strippedNames);
100
+ }
33
101
  }
34
- if (audience === 'agents') {
35
- return transformChildren(node.children);
102
+ // Usages of components whose page-local definition was stripped above
103
+ // would serialize as unresolvable ghost tags; unwrap them so only their
104
+ // real child content (if any) survives. A title attribute often labels
105
+ // that content, so carry it over as emphasized text.
106
+ const baseName = (_a = node.name) === null || _a === void 0 ? void 0 : _a.split('.')[0];
107
+ if (baseName && strippedNames.has(baseName)) {
108
+ const unwrapped = transformChildren(node.children, strippedNames);
109
+ const title = getStringAttribute(node, 'title');
110
+ if (node.type === 'mdxJsxFlowElement' && title) {
111
+ return [
112
+ {
113
+ type: 'paragraph',
114
+ children: [{ type: 'strong', children: [{ type: 'text', value: title }] }],
115
+ },
116
+ ...unwrapped,
117
+ ];
118
+ }
119
+ return unwrapped;
36
120
  }
37
121
  }
38
122
  if ('children' in node && Array.isArray(node.children)) {
39
- const next = transformChildren(node.children);
123
+ const next = transformChildren(node.children, strippedNames);
40
124
  node.children = next;
41
125
  }
42
126
  return [node];
43
127
  }
44
128
  export const remarkVisibilityForMarkdown = () => (tree) => {
45
- tree.children = transformChildren(tree.children);
129
+ const strippedNames = collectEsmIdentifiers(tree.children);
130
+ tree.children = transformChildren(tree.children, strippedNames);
46
131
  };