@mui/internal-docs-infra 0.1.1-alpha.10 → 0.1.1-alpha.11
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/package.json +1 -1
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +1 -1
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +6 -2
- package/pipeline/loaderUtils/getFileNameFromUrl.d.ts +1 -0
- package/pipeline/loaderUtils/getFileNameFromUrl.d.ts.map +1 -1
- package/pipeline/loaderUtils/getFileNameFromUrl.js +46 -12
- package/pipeline/loaderUtils/processRelativeImports.js +32 -9
- package/useCode/useCode.d.ts +1 -0
- package/useCode/useCode.d.ts.map +1 -1
- package/useCode/useCode.js +1 -0
- package/useCode/useFileNavigation.d.ts +1 -0
- package/useCode/useFileNavigation.d.ts.map +1 -1
- package/useCode/useFileNavigation.js +31 -3
- package/useDemo/useDemo.d.ts +1 -0
- package/useDemo/useDemo.d.ts.map +1 -1
- package/useDemo/useDemo.js +10 -10
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadPrecomputedCodeHighlighter.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadPrecomputedCodeHighlighter.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.ts"],"names":[],"mappings":"AAiCA,UAAU,aAAa;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD,SAAS,IAAI,IAAI,CAAC;IAClB,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAChD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,8BAA8B,CAClD,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CA8If"}
|
|
@@ -4,7 +4,9 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
4
4
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
5
|
import { loadVariant } from "../../CodeHighlighter/loadVariant.js";
|
|
6
6
|
import { createParseSource } from "../parseSource/index.js";
|
|
7
|
-
|
|
7
|
+
// TODO: re-enable following benchmarking
|
|
8
|
+
// import { TypescriptToJavascriptTransformer } from '../transformTypescriptToJavascript';
|
|
9
|
+
|
|
8
10
|
import { parseCreateFactoryCall } from "./parseCreateFactoryCall.js";
|
|
9
11
|
import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
|
|
10
12
|
import { replacePrecomputeValue } from "./replacePrecomputeValue.js";
|
|
@@ -89,7 +91,9 @@ function _loadPrecomputedCodeHighlighter() {
|
|
|
89
91
|
includeDependencies: true,
|
|
90
92
|
storeAt: 'flat' // TODO: this should be configurable
|
|
91
93
|
}); // Setup source transformers for TypeScript to JavaScript conversion
|
|
92
|
-
sourceTransformers = [TypescriptToJavascriptTransformer];
|
|
94
|
+
// const sourceTransformers: SourceTransformers = [TypescriptToJavascriptTransformer];
|
|
95
|
+
// TODO: maybe we should have `loadPrecomputedCodeHighlighterWithJsToTs`
|
|
96
|
+
sourceTransformers = []; // Create sourceParser promise for syntax highlighting
|
|
93
97
|
sourceParser = createParseSource(); // Process variants in parallel
|
|
94
98
|
variantPromises = Array.from(resolvedVariantMap.entries()).map(/*#__PURE__*/function () {
|
|
95
99
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Extracts the filename and extension from a URL or file path.
|
|
3
3
|
* This function is isomorphic and works in both Node.js and browser environments.
|
|
4
|
+
* It properly handles compound extensions like .module.css, .d.ts, .test.js, etc.
|
|
4
5
|
*
|
|
5
6
|
* @param url - The URL or file path to extract the filename from
|
|
6
7
|
* @returns An object containing the filename and extension
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFileNameFromUrl.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loaderUtils/getFileNameFromUrl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFileNameFromUrl.d.ts","sourceRoot":"","sources":["../../../src/pipeline/loaderUtils/getFileNameFromUrl.ts"],"names":[],"mappings":"AA2BA;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAavF"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
/**
|
|
3
|
+
* Known compound extensions that should be treated as a single unit
|
|
4
|
+
*/
|
|
5
|
+
var COMPOUND_EXTENSIONS = ['.module.css', '.module.scss', '.module.sass', '.module.less', '.d.ts', '.test.js', '.test.jsx', '.test.ts', '.test.tsx', '.spec.js', '.spec.jsx', '.spec.ts', '.spec.tsx', '.config.js', '.config.ts', '.setup.js', '.setup.ts', '.stories.js', '.stories.jsx', '.stories.ts', '.stories.tsx'];
|
|
6
|
+
|
|
1
7
|
/**
|
|
2
8
|
* Extracts the filename and extension from a URL or file path.
|
|
3
9
|
* This function is isomorphic and works in both Node.js and browser environments.
|
|
10
|
+
* It properly handles compound extensions like .module.css, .d.ts, .test.js, etc.
|
|
4
11
|
*
|
|
5
12
|
* @param url - The URL or file path to extract the filename from
|
|
6
13
|
* @returns An object containing the filename and extension
|
|
@@ -11,22 +18,49 @@ export function getFileNameFromUrl(url) {
|
|
|
11
18
|
var urlObj = new URL(url);
|
|
12
19
|
var pathname = urlObj.pathname;
|
|
13
20
|
var fileName = pathname.split('/').pop() || '';
|
|
14
|
-
|
|
15
|
-
// Extract extension (including the dot)
|
|
16
|
-
var lastDotIndex = fileName.lastIndexOf('.');
|
|
17
|
-
var extension = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
|
|
18
|
-
return {
|
|
19
|
-
fileName: fileName,
|
|
20
|
-
extension: extension
|
|
21
|
-
};
|
|
21
|
+
return extractFileNameAndExtension(fileName);
|
|
22
22
|
} catch (_unused) {
|
|
23
23
|
// If URL parsing fails, fall back to simple string manipulation
|
|
24
24
|
var _fileName = url.split('/').pop() || url;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
return extractFileNameAndExtension(_fileName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Helper function to extract filename and extension, handling compound extensions
|
|
31
|
+
*/
|
|
32
|
+
function extractFileNameAndExtension(fileName) {
|
|
33
|
+
if (!fileName) {
|
|
27
34
|
return {
|
|
28
|
-
fileName:
|
|
29
|
-
extension:
|
|
35
|
+
fileName: '',
|
|
36
|
+
extension: ''
|
|
30
37
|
};
|
|
31
38
|
}
|
|
39
|
+
|
|
40
|
+
// Check for compound extensions first
|
|
41
|
+
var _iterator = _createForOfIteratorHelper(COMPOUND_EXTENSIONS),
|
|
42
|
+
_step;
|
|
43
|
+
try {
|
|
44
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
45
|
+
var compoundExt = _step.value;
|
|
46
|
+
if (fileName.endsWith(compoundExt)) {
|
|
47
|
+
return {
|
|
48
|
+
fileName: fileName,
|
|
49
|
+
extension: compoundExt
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Fall back to simple extension detection
|
|
55
|
+
} catch (err) {
|
|
56
|
+
_iterator.e(err);
|
|
57
|
+
} finally {
|
|
58
|
+
_iterator.f();
|
|
59
|
+
}
|
|
60
|
+
var lastDotIndex = fileName.lastIndexOf('.');
|
|
61
|
+
var extension = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
|
|
62
|
+
return {
|
|
63
|
+
fileName: fileName,
|
|
64
|
+
extension: extension
|
|
65
|
+
};
|
|
32
66
|
}
|
|
@@ -127,7 +127,7 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
127
127
|
// First pass: collect all files and their path segments
|
|
128
128
|
Object.entries(importResult).forEach(function (_ref7) {
|
|
129
129
|
var _ref8 = _slicedToArray(_ref7, 2),
|
|
130
|
-
|
|
130
|
+
relativePath = _ref8[0],
|
|
131
131
|
importInfo = _ref8[1];
|
|
132
132
|
var resolvedPath = resolvedPathsMap.get(importInfo.path);
|
|
133
133
|
if (resolvedPath) {
|
|
@@ -136,7 +136,8 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
136
136
|
fileMapping.push({
|
|
137
137
|
resolvedPath: resolvedPath,
|
|
138
138
|
extension: fileExtension,
|
|
139
|
-
segments: pathSegments
|
|
139
|
+
segments: pathSegments,
|
|
140
|
+
originalImportPath: relativePath
|
|
140
141
|
});
|
|
141
142
|
}
|
|
142
143
|
});
|
|
@@ -150,9 +151,17 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
150
151
|
var isIndexFile = fileName.startsWith('index.');
|
|
151
152
|
var candidateName = void 0;
|
|
152
153
|
if (isIndexFile) {
|
|
153
|
-
//
|
|
154
|
-
var
|
|
155
|
-
|
|
154
|
+
// Check if the original import was a direct index file (e.g., "./index.ext")
|
|
155
|
+
var originalImportParts = file.originalImportPath.split('/');
|
|
156
|
+
var isDirectIndexImport = originalImportParts.length === 2 && originalImportParts[0] === '.' && originalImportParts[1].startsWith('index.');
|
|
157
|
+
if (isDirectIndexImport) {
|
|
158
|
+
// For direct index imports like "./index.ext", keep the original name
|
|
159
|
+
candidateName = "index".concat(file.extension);
|
|
160
|
+
} else {
|
|
161
|
+
// For nested index files like "./test/index.ext", use parent directory + extension
|
|
162
|
+
var parentDir = file.segments[file.segments.length - 2];
|
|
163
|
+
candidateName = "".concat(parentDir).concat(file.extension);
|
|
164
|
+
}
|
|
156
165
|
} else {
|
|
157
166
|
candidateName = fileName;
|
|
158
167
|
}
|
|
@@ -238,8 +247,15 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
238
247
|
var distinguishingSegment = _file.segments[_distinguishingIndex];
|
|
239
248
|
var finalName = void 0;
|
|
240
249
|
if (_isIndexFile) {
|
|
241
|
-
|
|
242
|
-
|
|
250
|
+
// Check if this was a direct index import
|
|
251
|
+
var _originalImportParts = _file.originalImportPath.split('/');
|
|
252
|
+
var _isDirectIndexImport = _originalImportParts.length === 2 && _originalImportParts[0] === '.' && _originalImportParts[1].startsWith('index.');
|
|
253
|
+
if (_isDirectIndexImport) {
|
|
254
|
+
finalName = "".concat(distinguishingSegment, "/index").concat(_file.extension);
|
|
255
|
+
} else {
|
|
256
|
+
var _parentDir = _file.segments[_file.segments.length - 2];
|
|
257
|
+
finalName = "".concat(distinguishingSegment, "/").concat(_parentDir).concat(_file.extension);
|
|
258
|
+
}
|
|
243
259
|
} else {
|
|
244
260
|
finalName = "".concat(distinguishingSegment, "/").concat(_fileName);
|
|
245
261
|
}
|
|
@@ -302,8 +318,15 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
302
318
|
var _distinguishingSegment = _file2.segments[distinguishingIndex];
|
|
303
319
|
var _finalName = void 0;
|
|
304
320
|
if (_isIndexFile2) {
|
|
305
|
-
|
|
306
|
-
|
|
321
|
+
// Check if this was a direct index import
|
|
322
|
+
var _originalImportParts2 = _file2.originalImportPath.split('/');
|
|
323
|
+
var _isDirectIndexImport2 = _originalImportParts2.length === 2 && _originalImportParts2[0] === '.' && _originalImportParts2[1].startsWith('index.');
|
|
324
|
+
if (_isDirectIndexImport2) {
|
|
325
|
+
_finalName = "".concat(_distinguishingSegment, "/index").concat(_file2.extension);
|
|
326
|
+
} else {
|
|
327
|
+
var _parentDir2 = _file2.segments[_file2.segments.length - 2];
|
|
328
|
+
_finalName = "".concat(_distinguishingSegment, "/").concat(_parentDir2).concat(_file2.extension);
|
|
329
|
+
}
|
|
307
330
|
} else {
|
|
308
331
|
_finalName = "".concat(_distinguishingSegment, "/").concat(_fileName2);
|
|
309
332
|
}
|
package/useCode/useCode.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface UseCodeResult<T extends {} = {}> {
|
|
|
23
23
|
component: React.ReactNode;
|
|
24
24
|
}>;
|
|
25
25
|
selectedFile: React.ReactNode;
|
|
26
|
+
selectedFileLines: number;
|
|
26
27
|
selectedFileName: string | undefined;
|
|
27
28
|
selectFileName: (fileName: string) => void;
|
|
28
29
|
expanded: boolean;
|
package/useCode/useCode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCode.d.ts","sourceRoot":"","sources":["../../src/useCode/useCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAS7D,KAAK,WAAW,GAAG;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,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AQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC7C,eAAe,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACxD,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;CACzB;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EACvC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAC7B,IAAI,CAAC,EAAE,WAAW,GACjB,aAAa,CAAC,CAAC,CAAC,CA6GlB"}
|
package/useCode/useCode.js
CHANGED
|
@@ -107,6 +107,7 @@ export function useCode(contentProps, opts) {
|
|
|
107
107
|
selectVariant: variantSelection.selectVariant,
|
|
108
108
|
files: fileNavigation.files,
|
|
109
109
|
selectedFile: fileNavigation.selectedFileComponent,
|
|
110
|
+
selectedFileLines: fileNavigation.selectedFileLines,
|
|
110
111
|
selectedFileName: fileNavigation.selectedFileName,
|
|
111
112
|
selectFileName: fileNavigation.selectFileName,
|
|
112
113
|
expanded: uiState.expanded,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileNavigation.d.ts","sourceRoot":"","sources":["../../src/useCode/useFileNavigation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM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,QAAa,EACb,kBAAuB,EACvB,WAAgB,EAChB,cAAc,EACd,eAAe,GAChB,EAAE,sBAAsB,GAAG,uBAAuB,CAgalD"}
|
|
@@ -215,7 +215,8 @@ export function useFileNavigation(_ref) {
|
|
|
215
215
|
|
|
216
216
|
// Otherwise, use the original untransformed files
|
|
217
217
|
if (selectedFileNameInternal === selectedVariant.fileName || !selectedFileNameInternal) {
|
|
218
|
-
|
|
218
|
+
var _selectedVariant$sour;
|
|
219
|
+
return (_selectedVariant$sour = selectedVariant.source) != null ? _selectedVariant$sour : null;
|
|
219
220
|
}
|
|
220
221
|
|
|
221
222
|
// Look in extraFiles
|
|
@@ -225,7 +226,8 @@ export function useFileNavigation(_ref) {
|
|
|
225
226
|
return extraFile;
|
|
226
227
|
}
|
|
227
228
|
if (extraFile && _typeof(extraFile) === 'object' && 'source' in extraFile) {
|
|
228
|
-
|
|
229
|
+
var _extraFile$source;
|
|
230
|
+
return (_extraFile$source = extraFile.source) != null ? _extraFile$source : null;
|
|
229
231
|
}
|
|
230
232
|
}
|
|
231
233
|
return null;
|
|
@@ -245,6 +247,9 @@ export function useFileNavigation(_ref) {
|
|
|
245
247
|
|
|
246
248
|
// Otherwise, create component from original untransformed files
|
|
247
249
|
if (selectedFileNameInternal === selectedVariant.fileName || !selectedFileNameInternal) {
|
|
250
|
+
if (selectedVariant.source == null) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
248
253
|
return stringOrHastToJsx(selectedVariant.source, shouldHighlight);
|
|
249
254
|
}
|
|
250
255
|
|
|
@@ -259,10 +264,29 @@ export function useFileNavigation(_ref) {
|
|
|
259
264
|
} else {
|
|
260
265
|
return null;
|
|
261
266
|
}
|
|
267
|
+
if (source == null) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
262
270
|
return stringOrHastToJsx(source, shouldHighlight);
|
|
263
271
|
}
|
|
264
272
|
return null;
|
|
265
273
|
}, [selectedVariant, selectedFileNameInternal, transformedFiles, shouldHighlight]);
|
|
274
|
+
var selectedFileLines = React.useMemo(function () {
|
|
275
|
+
if (selectedFile == null) {
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// If it's a string, split by newlines and count
|
|
280
|
+
if (typeof selectedFile === 'string') {
|
|
281
|
+
return selectedFile.split('\n').length;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// If it's a hast object, count the children length
|
|
285
|
+
if (selectedFile && _typeof(selectedFile) === 'object' && 'children' in selectedFile) {
|
|
286
|
+
return Array.isArray(selectedFile.children) ? selectedFile.children.length : 0;
|
|
287
|
+
}
|
|
288
|
+
return 0;
|
|
289
|
+
}, [selectedFile]);
|
|
266
290
|
|
|
267
291
|
// Convert files for the return interface
|
|
268
292
|
var files = React.useMemo(function () {
|
|
@@ -288,7 +312,7 @@ export function useFileNavigation(_ref) {
|
|
|
288
312
|
var result = [];
|
|
289
313
|
|
|
290
314
|
// Only add main file if it has a fileName
|
|
291
|
-
if (selectedVariant.fileName) {
|
|
315
|
+
if (selectedVariant.fileName && selectedVariant.source) {
|
|
292
316
|
result.push({
|
|
293
317
|
name: selectedVariant.fileName,
|
|
294
318
|
slug: generateFileSlug(mainSlug, selectedVariant.fileName, selectedVariantKey, isInitialVariant),
|
|
@@ -308,6 +332,9 @@ export function useFileNavigation(_ref) {
|
|
|
308
332
|
} else {
|
|
309
333
|
return; // Skip invalid entries
|
|
310
334
|
}
|
|
335
|
+
if (!source) {
|
|
336
|
+
return; // Skip null/undefined sources
|
|
337
|
+
}
|
|
311
338
|
result.push({
|
|
312
339
|
name: fileName,
|
|
313
340
|
slug: generateFileSlug(mainSlug, fileName, selectedVariantKey, isInitialVariant),
|
|
@@ -364,6 +391,7 @@ export function useFileNavigation(_ref) {
|
|
|
364
391
|
selectedFileName: selectedFileName,
|
|
365
392
|
selectedFile: selectedFile,
|
|
366
393
|
selectedFileComponent: selectedFileComponent,
|
|
394
|
+
selectedFileLines: selectedFileLines,
|
|
367
395
|
files: files,
|
|
368
396
|
selectFileName: selectFileName
|
|
369
397
|
};
|
package/useDemo/useDemo.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export declare function useDemo<T extends {} = {}>(contentProps: ContentProps<T>
|
|
|
60
60
|
component: React.ReactNode;
|
|
61
61
|
}>;
|
|
62
62
|
selectedFile: React.ReactNode;
|
|
63
|
+
selectedFileLines: number;
|
|
63
64
|
selectedFileName: string | undefined;
|
|
64
65
|
selectFileName: (fileName: string) => void;
|
|
65
66
|
expanded: boolean;
|
package/useDemo/useDemo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDemo.d.ts","sourceRoot":"","sources":["../../src/useDemo/useDemo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAQ7D;;;;;;;;;;;;;GAaG;AAEH,KAAK,WAAW,GAAG;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAMvF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,QAAQ,EACR,MAAe,EACf,MAAiB,GAClB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,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;AAGD,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW;;;;;;;;;;;;;YAxDnD,CAAC;;;;;;;;;;;;;;;;;;;EA4KzC"}
|
package/useDemo/useDemo.js
CHANGED
|
@@ -64,7 +64,7 @@ export function openWithForm(_ref) {
|
|
|
64
64
|
|
|
65
65
|
// TODO: take initialVariant and initialTransforms as parameters
|
|
66
66
|
export function useDemo(contentProps, opts) {
|
|
67
|
-
var
|
|
67
|
+
var code = useCode(contentProps, opts);
|
|
68
68
|
|
|
69
69
|
// Get context to access components if available (using React.useContext to avoid import conflicts)
|
|
70
70
|
var context = React.useContext(CodeHighlighterContext);
|
|
@@ -79,8 +79,8 @@ export function useDemo(contentProps, opts) {
|
|
|
79
79
|
|
|
80
80
|
// Get the component for the current variant
|
|
81
81
|
var component = React.useMemo(function () {
|
|
82
|
-
return effectiveComponents[
|
|
83
|
-
}, [effectiveComponents,
|
|
82
|
+
return effectiveComponents[code.selectedVariant] || null;
|
|
83
|
+
}, [effectiveComponents, code.selectedVariant]);
|
|
84
84
|
|
|
85
85
|
// Demo-specific ref and focus management
|
|
86
86
|
var ref = React.useRef(null);
|
|
@@ -97,7 +97,7 @@ export function useDemo(contentProps, opts) {
|
|
|
97
97
|
// Create StackBlitz demo callback
|
|
98
98
|
var openStackBlitz = React.useCallback(function () {
|
|
99
99
|
// Get the current variant code
|
|
100
|
-
var variantCode = effectiveCode[
|
|
100
|
+
var variantCode = effectiveCode[code.selectedVariant];
|
|
101
101
|
if (!variantCode || typeof variantCode === 'string') {
|
|
102
102
|
console.warn('No valid variant code available for StackBlitz demo');
|
|
103
103
|
return;
|
|
@@ -107,7 +107,7 @@ export function useDemo(contentProps, opts) {
|
|
|
107
107
|
|
|
108
108
|
// Determine if we should use TypeScript based on whether 'js' transform is NOT applied
|
|
109
109
|
// If 'js' transform is applied, it means we're showing the JS version of TS code
|
|
110
|
-
var useTypescript =
|
|
110
|
+
var useTypescript = code.selectedTransform !== 'js';
|
|
111
111
|
|
|
112
112
|
// Export variant with additional configuration files
|
|
113
113
|
var _exportVariant = exportVariant(variantCode, {
|
|
@@ -127,12 +127,12 @@ export function useDemo(contentProps, opts) {
|
|
|
127
127
|
rootFile: rootFile
|
|
128
128
|
});
|
|
129
129
|
openWithForm(stackBlitzDemo);
|
|
130
|
-
}, [effectiveCode,
|
|
130
|
+
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name]);
|
|
131
131
|
|
|
132
132
|
// Create CodeSandbox demo callback
|
|
133
133
|
var openCodeSandbox = React.useCallback(function () {
|
|
134
134
|
// Get the current variant code
|
|
135
|
-
var variantCode = effectiveCode[
|
|
135
|
+
var variantCode = effectiveCode[code.selectedVariant];
|
|
136
136
|
if (!variantCode || typeof variantCode === 'string') {
|
|
137
137
|
console.warn('No valid variant code available for CodeSandbox demo');
|
|
138
138
|
return;
|
|
@@ -142,7 +142,7 @@ export function useDemo(contentProps, opts) {
|
|
|
142
142
|
|
|
143
143
|
// Determine if we should use TypeScript based on whether 'js' transform is NOT applied
|
|
144
144
|
// If 'js' transform is applied, it means we're showing the JS version of TS code
|
|
145
|
-
var useTypescript =
|
|
145
|
+
var useTypescript = code.selectedTransform !== 'js';
|
|
146
146
|
|
|
147
147
|
// Export variant as CRA template with additional configuration files
|
|
148
148
|
var _exportVariantAsCra = exportVariantAsCra(variantCode, {
|
|
@@ -160,8 +160,8 @@ export function useDemo(contentProps, opts) {
|
|
|
160
160
|
rootFile: rootFile
|
|
161
161
|
});
|
|
162
162
|
openWithForm(codeSandboxDemo);
|
|
163
|
-
}, [effectiveCode,
|
|
164
|
-
return _objectSpread(_objectSpread({},
|
|
163
|
+
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name]);
|
|
164
|
+
return _objectSpread(_objectSpread({}, code), {}, {
|
|
165
165
|
// Demo-specific additions
|
|
166
166
|
component: component,
|
|
167
167
|
ref: ref,
|