@mui/internal-docs-infra 0.1.1-alpha.13 → 0.1.1-alpha.15
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/CodeHighlighter/CodeHighlighterClient.d.ts.map +1 -1
- package/CodeHighlighter/CodeHighlighterClient.js +45 -16
- package/CodeHighlighter/addPathsToVariant.d.ts +18 -0
- package/CodeHighlighter/addPathsToVariant.d.ts.map +1 -0
- package/CodeHighlighter/addPathsToVariant.js +352 -0
- package/{useDemo → CodeHighlighter}/examineVariant.d.ts +1 -1
- package/CodeHighlighter/examineVariant.d.ts.map +1 -0
- package/CodeHighlighter/examineVariant.js +103 -0
- package/CodeHighlighter/mergeMetadata.d.ts +40 -0
- package/CodeHighlighter/mergeMetadata.d.ts.map +1 -0
- package/CodeHighlighter/mergeMetadata.js +189 -0
- package/CodeHighlighter/types.d.ts +3 -0
- package/CodeHighlighter/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/useDemo/exportVariant.d.ts +82 -14
- package/useDemo/exportVariant.d.ts.map +1 -1
- package/useDemo/exportVariant.js +196 -101
- package/useDemo/flattenVariant.d.ts +2 -0
- package/useDemo/flattenVariant.d.ts.map +1 -1
- package/useDemo/flattenVariant.js +19 -178
- package/useDemo/useDemo.d.ts +7 -0
- package/useDemo/useDemo.d.ts.map +1 -1
- package/useDemo/useDemo.js +37 -18
- package/useDemo/examineVariant.d.ts.map +0 -1
- package/useDemo/examineVariant.js +0 -134
|
@@ -1,204 +1,45 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
4
3
|
/**
|
|
5
4
|
* Flatten variant utility to convert a VariantCode into a flat files list
|
|
6
5
|
* Handles relative path resolution and metadata file scoping
|
|
6
|
+
* Uses addPathsToVariant for the core logic, then flattens the result
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { stringOrHastToString } from "../pipeline/hastUtils/index.js";
|
|
10
|
-
import {
|
|
11
|
-
import { createPathContext } from "./examineVariant.js";
|
|
12
|
-
/**
|
|
13
|
-
* Resolve a relative path from a base URL to get the target directory structure
|
|
14
|
-
*/
|
|
15
|
-
function resolveRelativePath(baseUrl, relativePath) {
|
|
16
|
-
var url = new URL(baseUrl);
|
|
17
|
-
var pathSegments = url.pathname.split('/').filter(Boolean);
|
|
18
|
-
pathSegments.pop(); // Remove filename to get directory
|
|
19
|
-
|
|
20
|
-
var relativeSegments = relativePath.split('/');
|
|
21
|
-
var _iterator = _createForOfIteratorHelper(relativeSegments),
|
|
22
|
-
_step;
|
|
23
|
-
try {
|
|
24
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
25
|
-
var segment = _step.value;
|
|
26
|
-
if (segment === '..') {
|
|
27
|
-
pathSegments.pop();
|
|
28
|
-
} else if (segment !== '.' && segment !== '') {
|
|
29
|
-
pathSegments.push(segment);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
} catch (err) {
|
|
33
|
-
_iterator.e(err);
|
|
34
|
-
} finally {
|
|
35
|
-
_iterator.f();
|
|
36
|
-
}
|
|
37
|
-
return pathSegments.join('/');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Process the main file and determine its final path
|
|
42
|
-
*/
|
|
43
|
-
function processMainFile(variant, context) {
|
|
44
|
-
var effectiveFileName = variant.fileName;
|
|
45
|
-
|
|
46
|
-
// If fileName is missing but we have a URL, derive it from the URL
|
|
47
|
-
if (!effectiveFileName && context.hasUrl) {
|
|
48
|
-
var _getFileNameFromUrl = getFileNameFromUrl(context.actualUrl),
|
|
49
|
-
fileName = _getFileNameFromUrl.fileName;
|
|
50
|
-
effectiveFileName = fileName;
|
|
51
|
-
}
|
|
52
|
-
if (!effectiveFileName || variant.source === undefined) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
var mainFilePath;
|
|
56
|
-
if (context.hasUrl && context.maxBackNavigation > 0) {
|
|
57
|
-
// URL with back navigation - calculate relative path from root level
|
|
58
|
-
// TypeScript knows context.actualUrl is defined when context.hasUrl is true
|
|
59
|
-
var urlObj = new URL(context.actualUrl);
|
|
60
|
-
var fullPath = urlObj.pathname.substring(1); // Remove leading slash
|
|
61
|
-
var relativePath = context.rootLevel ? fullPath.substring(context.rootLevel.length) : fullPath;
|
|
62
|
-
mainFilePath = relativePath.replace(/\/[^/]+$/, "/".concat(effectiveFileName));
|
|
63
|
-
} else if (context.hasUrl && variant.extraFiles && Object.keys(variant.extraFiles).length > 0) {
|
|
64
|
-
// URL with extra files but no back navigation
|
|
65
|
-
if (context.hasMetadata) {
|
|
66
|
-
// For metadata cases, preserve the full directory structure
|
|
67
|
-
mainFilePath = context.urlDirectory.length > 0 ? "".concat(context.urlDirectory.join('/'), "/").concat(effectiveFileName) : effectiveFileName;
|
|
68
|
-
} else {
|
|
69
|
-
// Check if all extra files are current directory references
|
|
70
|
-
var allCurrentDir = Object.keys(variant.extraFiles).every(function (path) {
|
|
71
|
-
return path.startsWith('./') || !path.startsWith('../') && !path.startsWith('.');
|
|
72
|
-
});
|
|
73
|
-
if (allCurrentDir) {
|
|
74
|
-
// For current directory references without metadata, flatten to root
|
|
75
|
-
mainFilePath = effectiveFileName;
|
|
76
|
-
} else {
|
|
77
|
-
// Use just the immediate parent directory
|
|
78
|
-
var lastSegment = context.urlDirectory[context.urlDirectory.length - 1];
|
|
79
|
-
mainFilePath = lastSegment ? "".concat(lastSegment, "/").concat(effectiveFileName) : effectiveFileName;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
// Simple case - just use the filename
|
|
84
|
-
mainFilePath = effectiveFileName;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Add src/ prefix if we have metadata
|
|
88
|
-
if (context.hasMetadata) {
|
|
89
|
-
// When there are metadata files, simplify the main file path
|
|
90
|
-
if (context.hasUrl && !context.maxBackNavigation) {
|
|
91
|
-
// No back navigation - just use the filename
|
|
92
|
-
mainFilePath = effectiveFileName;
|
|
93
|
-
}
|
|
94
|
-
mainFilePath = "src/".concat(mainFilePath);
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
path: mainFilePath,
|
|
98
|
-
hasDirectory: mainFilePath.includes('/')
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Process metadata files to determine their final paths
|
|
104
|
-
*/
|
|
105
|
-
function processMetadataFile(relativePath) {
|
|
106
|
-
// Extract everything after the back navigation, preserving directory structure
|
|
107
|
-
return relativePath.replace(/^(\.\.\/)+/, '');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Process extra file paths to determine their final paths
|
|
112
|
-
*/
|
|
113
|
-
function processExtraFilePath(relativePath, context, mainFile) {
|
|
114
|
-
if (relativePath.startsWith('./')) {
|
|
115
|
-
// Current directory reference - just remove the ./
|
|
116
|
-
return relativePath.substring(2);
|
|
117
|
-
}
|
|
118
|
-
if (relativePath.startsWith('../')) {
|
|
119
|
-
// Back navigation - resolve relative to URL or create synthetic paths
|
|
120
|
-
if (context.hasUrl) {
|
|
121
|
-
// TypeScript knows context.actualUrl is defined when context.hasUrl is true
|
|
122
|
-
var resolved = resolveRelativePath(context.actualUrl, relativePath);
|
|
123
|
-
if (context.rootLevel) {
|
|
124
|
-
var rootLevelClean = context.rootLevel.replace(/\/$/, '');
|
|
125
|
-
if (resolved.startsWith("".concat(rootLevelClean, "/"))) {
|
|
126
|
-
return resolved.substring(rootLevelClean.length + 1);
|
|
127
|
-
}
|
|
128
|
-
if (resolved === rootLevelClean) {
|
|
129
|
-
return relativePath.split('/').pop() || relativePath;
|
|
130
|
-
}
|
|
131
|
-
return resolved;
|
|
132
|
-
}
|
|
133
|
-
return resolved;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Fallback: if somehow we don't have a URL (shouldn't happen anymore with synthetic URLs)
|
|
137
|
-
return relativePath.split('/').pop() || relativePath;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Regular relative path (like 'dir/utils.ts')
|
|
141
|
-
if (context.hasUrl && !context.hasMetadata && mainFile != null && mainFile.hasDirectory) {
|
|
142
|
-
// Place relative to main file's directory if it has one
|
|
143
|
-
var lastSegment = context.urlDirectory[context.urlDirectory.length - 1];
|
|
144
|
-
return lastSegment ? "".concat(lastSegment, "/").concat(relativePath) : relativePath;
|
|
145
|
-
}
|
|
146
|
-
return relativePath;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Process an extra file to determine its final path
|
|
151
|
-
*/
|
|
152
|
-
function processExtraFile(relativePath, file, context, mainFile) {
|
|
153
|
-
var finalPath;
|
|
154
|
-
if (file.metadata) {
|
|
155
|
-
finalPath = processMetadataFile(relativePath);
|
|
156
|
-
} else {
|
|
157
|
-
finalPath = processExtraFilePath(relativePath, context, mainFile);
|
|
158
|
-
|
|
159
|
-
// Add src/ prefix if we have metadata (all paths are relative to main file)
|
|
160
|
-
if (context.hasMetadata) {
|
|
161
|
-
finalPath = "src/".concat(finalPath);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return finalPath;
|
|
165
|
-
}
|
|
166
|
-
|
|
10
|
+
import { addPathsToVariant } from "../CodeHighlighter/addPathsToVariant.js";
|
|
167
11
|
/**
|
|
168
12
|
* Flatten a VariantCode into a flat files structure
|
|
169
13
|
* Resolves relative paths and handles metadata file scoping
|
|
14
|
+
* Uses addPathsToVariant for path resolution logic
|
|
170
15
|
*/
|
|
171
16
|
export function flattenVariant(variant) {
|
|
172
17
|
var result = {};
|
|
173
|
-
var context = createPathContext(variant);
|
|
174
18
|
|
|
175
|
-
//
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
19
|
+
// Use addPathsToVariant to get the structured paths
|
|
20
|
+
var variantWithPaths = addPathsToVariant(variant);
|
|
21
|
+
|
|
22
|
+
// Add main file if it exists
|
|
23
|
+
if (variantWithPaths.path && variantWithPaths.source !== undefined) {
|
|
24
|
+
result[variantWithPaths.path] = {
|
|
25
|
+
source: stringOrHastToString(variantWithPaths.source)
|
|
180
26
|
};
|
|
181
27
|
}
|
|
182
28
|
|
|
183
|
-
//
|
|
184
|
-
if (
|
|
185
|
-
for (var _i = 0, _Object$entries = Object.entries(
|
|
29
|
+
// Add extra files if they exist
|
|
30
|
+
if (variantWithPaths.extraFiles) {
|
|
31
|
+
for (var _i = 0, _Object$entries = Object.entries(variantWithPaths.extraFiles); _i < _Object$entries.length; _i++) {
|
|
186
32
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
187
33
|
relativePath = _Object$entries$_i[0],
|
|
188
|
-
|
|
189
|
-
var file = typeof fileContent === 'string' ? {
|
|
190
|
-
source: fileContent
|
|
191
|
-
} : fileContent;
|
|
192
|
-
|
|
34
|
+
fileWithPath = _Object$entries$_i[1];
|
|
193
35
|
// Skip files with no source content
|
|
194
|
-
if (!
|
|
36
|
+
if (!fileWithPath.source && fileWithPath.source !== '') {
|
|
195
37
|
continue;
|
|
196
38
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
metadata: file.metadata
|
|
39
|
+
result[fileWithPath.path] = _objectSpread({
|
|
40
|
+
source: stringOrHastToString(fileWithPath.source || '')
|
|
41
|
+
}, fileWithPath.metadata && {
|
|
42
|
+
metadata: fileWithPath.metadata
|
|
202
43
|
});
|
|
203
44
|
}
|
|
204
45
|
}
|
package/useDemo/useDemo.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { UseCopierOpts } from "../useCopier/index.js";
|
|
3
3
|
import type { ContentProps } from "../CodeHighlighter/types.js";
|
|
4
|
+
import { type ExportConfig } from "./exportVariant.js";
|
|
4
5
|
/**
|
|
5
6
|
* Demo templates use the exportVariant/exportVariantAsCra with flattenVariant pattern:
|
|
6
7
|
*
|
|
@@ -23,6 +24,12 @@ type UseDemoOpts = {
|
|
|
23
24
|
stackBlitzPrefix?: string;
|
|
24
25
|
initialVariant?: string;
|
|
25
26
|
initialTransform?: string;
|
|
27
|
+
/** Common export configuration applied to both StackBlitz and CodeSandbox */
|
|
28
|
+
export?: ExportConfig;
|
|
29
|
+
/** StackBlitz-specific export configuration (merged with common export config) */
|
|
30
|
+
exportStackBlitz?: ExportConfig;
|
|
31
|
+
/** CodeSandbox-specific export configuration (merged with common export config) */
|
|
32
|
+
exportCodeSandbox?: ExportConfig;
|
|
26
33
|
};
|
|
27
34
|
/**
|
|
28
35
|
* Helper to create HTML form element with hidden inputs
|
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;
|
|
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;AAI7D,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAInE;;;;;;;;;;;;;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;IAC1B,6EAA6E;IAC7E,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,kFAAkF;IAClF,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,YAAY,CAAC;CAClC,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,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CAaP;AAGD,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW;;;;;;;;;;;;;YA9D3F,CAAD;;;;;;;;;;;;;;;;;;;EAqNC"}
|
package/useDemo/useDemo.js
CHANGED
|
@@ -66,6 +66,15 @@ export function openWithForm(_ref) {
|
|
|
66
66
|
export function useDemo(contentProps, opts) {
|
|
67
67
|
var code = useCode(contentProps, opts);
|
|
68
68
|
|
|
69
|
+
// Extract export configuration options
|
|
70
|
+
var _ref4 = opts || {},
|
|
71
|
+
_ref4$export = _ref4["export"],
|
|
72
|
+
commonExportConfig = _ref4$export === void 0 ? {} : _ref4$export,
|
|
73
|
+
_ref4$exportStackBlit = _ref4.exportStackBlitz,
|
|
74
|
+
stackBlitzExportConfig = _ref4$exportStackBlit === void 0 ? {} : _ref4$exportStackBlit,
|
|
75
|
+
_ref4$exportCodeSandb = _ref4.exportCodeSandbox,
|
|
76
|
+
codeSandboxExportConfig = _ref4$exportCodeSandb === void 0 ? {} : _ref4$exportCodeSandb;
|
|
77
|
+
|
|
69
78
|
// Get context to access components if available (using React.useContext to avoid import conflicts)
|
|
70
79
|
var context = React.useContext(CodeHighlighterContext);
|
|
71
80
|
var slug = React.useMemo(function () {
|
|
@@ -109,14 +118,19 @@ export function useDemo(contentProps, opts) {
|
|
|
109
118
|
// If 'js' transform is applied, it means we're showing the JS version of TS code
|
|
110
119
|
var useTypescript = code.selectedTransform !== 'js';
|
|
111
120
|
|
|
112
|
-
//
|
|
113
|
-
var
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
// Merge common export config with StackBlitz-specific config
|
|
122
|
+
var mergedConfig = _objectSpread(_objectSpread(_objectSpread({}, commonExportConfig), stackBlitzExportConfig), {}, {
|
|
123
|
+
variantName: code.selectedVariant,
|
|
124
|
+
title: title,
|
|
125
|
+
description: description,
|
|
126
|
+
useTypescript: useTypescript
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Use custom export function if provided, otherwise use default exportVariant
|
|
130
|
+
var exportFunction = mergedConfig.exportFunction || exportVariant;
|
|
131
|
+
var _exportFunction = exportFunction(variantCode, mergedConfig),
|
|
132
|
+
exported = _exportFunction.exported,
|
|
133
|
+
rootFile = _exportFunction.rootFile;
|
|
120
134
|
|
|
121
135
|
// Flatten the variant to get a flat file structure
|
|
122
136
|
var flattenedFiles = flattenVariant(exported);
|
|
@@ -127,7 +141,7 @@ export function useDemo(contentProps, opts) {
|
|
|
127
141
|
rootFile: rootFile
|
|
128
142
|
});
|
|
129
143
|
openWithForm(stackBlitzDemo);
|
|
130
|
-
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name]);
|
|
144
|
+
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name, commonExportConfig, stackBlitzExportConfig]);
|
|
131
145
|
|
|
132
146
|
// Create CodeSandbox demo callback
|
|
133
147
|
var openCodeSandbox = React.useCallback(function () {
|
|
@@ -144,14 +158,19 @@ export function useDemo(contentProps, opts) {
|
|
|
144
158
|
// If 'js' transform is applied, it means we're showing the JS version of TS code
|
|
145
159
|
var useTypescript = code.selectedTransform !== 'js';
|
|
146
160
|
|
|
147
|
-
//
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
161
|
+
// Merge common export config with CodeSandbox-specific config
|
|
162
|
+
var mergedConfig = _objectSpread(_objectSpread(_objectSpread({}, commonExportConfig), codeSandboxExportConfig), {}, {
|
|
163
|
+
variantName: code.selectedVariant,
|
|
164
|
+
title: title,
|
|
165
|
+
description: description,
|
|
166
|
+
useTypescript: useTypescript
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Use custom export function if provided, otherwise use default exportVariantAsCra
|
|
170
|
+
var exportFunction = mergedConfig.exportFunction || exportVariantAsCra;
|
|
171
|
+
var _exportFunction2 = exportFunction(variantCode, mergedConfig),
|
|
172
|
+
craExport = _exportFunction2.exported,
|
|
173
|
+
rootFile = _exportFunction2.rootFile;
|
|
155
174
|
|
|
156
175
|
// Flatten the variant to get a flat file structure
|
|
157
176
|
var flattenedFiles = flattenVariant(craExport);
|
|
@@ -160,7 +179,7 @@ export function useDemo(contentProps, opts) {
|
|
|
160
179
|
rootFile: rootFile
|
|
161
180
|
});
|
|
162
181
|
openWithForm(codeSandboxDemo);
|
|
163
|
-
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name]);
|
|
182
|
+
}, [effectiveCode, code.selectedVariant, code.selectedTransform, contentProps.name, commonExportConfig, codeSandboxExportConfig]);
|
|
164
183
|
return _objectSpread(_objectSpread({}, code), {}, {
|
|
165
184
|
// Demo-specific additions
|
|
166
185
|
component: component,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"examineVariant.d.ts","sourceRoot":"","sources":["../../src/useDemo/examineVariant.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,UAAU,eAAe;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,UAAU,kBAAmB,SAAQ,eAAe;IAClD,MAAM,EAAE,IAAI,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,qBAAsB,SAAQ,eAAe;IACrD,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,MAAM,MAAM,WAAW,GAAG,kBAAkB,GAAG,qBAAqB,CAAC;AA8FrE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,CA0CnE"}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
/**
|
|
4
|
-
* Variant examination utility for analyzing variant structure and paths
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Extract directory segments from URL pathname
|
|
9
|
-
*/
|
|
10
|
-
function getDirectoryFromUrl(url) {
|
|
11
|
-
var urlObj = new URL(url);
|
|
12
|
-
var segments = urlObj.pathname.split('/').filter(Boolean);
|
|
13
|
-
segments.pop(); // Remove filename
|
|
14
|
-
return segments;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Calculate the maximum back navigation level from extra files
|
|
19
|
-
*/
|
|
20
|
-
function calculateMaxBackNavigation(extraFiles) {
|
|
21
|
-
var maxBackNavigation = 0;
|
|
22
|
-
for (var _i = 0, _Object$entries = Object.entries(extraFiles); _i < _Object$entries.length; _i++) {
|
|
23
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
24
|
-
relativePath = _Object$entries$_i[0],
|
|
25
|
-
fileContent = _Object$entries$_i[1];
|
|
26
|
-
if (relativePath.startsWith('.')) {
|
|
27
|
-
var backCount = (relativePath.match(/\.\.\//g) || []).length;
|
|
28
|
-
|
|
29
|
-
// For metadata files, subtract 1 from their back navigation count
|
|
30
|
-
var file = typeof fileContent === 'string' ? {
|
|
31
|
-
source: fileContent
|
|
32
|
-
} : fileContent;
|
|
33
|
-
var adjustedBackCount = file.metadata ? Math.max(0, backCount - 1) : backCount;
|
|
34
|
-
maxBackNavigation = Math.max(maxBackNavigation, adjustedBackCount);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return maxBackNavigation;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Generate a synthetic path using alphabetic progression (a/b/c/d/e/...)
|
|
42
|
-
*/
|
|
43
|
-
function generateSyntheticPath(levels) {
|
|
44
|
-
if (levels <= 0) {
|
|
45
|
-
return '';
|
|
46
|
-
}
|
|
47
|
-
var parts = [];
|
|
48
|
-
for (var i = 0; i < levels; i += 1) {
|
|
49
|
-
var charCode = 97 + i % 26; // 97 is 'a', cycles through a-z
|
|
50
|
-
parts.push(String.fromCharCode(charCode));
|
|
51
|
-
}
|
|
52
|
-
return parts.join('/') + (levels > 0 ? '/' : '');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Calculate root level path based on URL and max back navigation
|
|
57
|
-
*/
|
|
58
|
-
function calculateRootLevel(url, maxBackNavigation) {
|
|
59
|
-
if (!url || maxBackNavigation === 0) {
|
|
60
|
-
return '';
|
|
61
|
-
}
|
|
62
|
-
var pathSegments = getDirectoryFromUrl(url);
|
|
63
|
-
|
|
64
|
-
// Go back by maxBackNavigation levels
|
|
65
|
-
for (var i = 0; i < maxBackNavigation; i += 1) {
|
|
66
|
-
pathSegments.pop();
|
|
67
|
-
}
|
|
68
|
-
var rootLevel = pathSegments.join('/');
|
|
69
|
-
return rootLevel && !rootLevel.endsWith('/') ? "".concat(rootLevel, "/") : rootLevel;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Calculate the path inward from the root to the variant location
|
|
74
|
-
*/
|
|
75
|
-
function calculatePathInwardFromRoot(url, maxBackNavigation) {
|
|
76
|
-
if (!url || maxBackNavigation === 0) {
|
|
77
|
-
return '';
|
|
78
|
-
}
|
|
79
|
-
var pathSegments = getDirectoryFromUrl(url);
|
|
80
|
-
|
|
81
|
-
// The path inward is the segments that remain after going back by maxBackNavigation
|
|
82
|
-
// but we want the path from root to the variant location, not to the parent directory
|
|
83
|
-
var variantDepthFromRoot = pathSegments.length - maxBackNavigation;
|
|
84
|
-
if (variantDepthFromRoot <= 0) {
|
|
85
|
-
return '';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Get segments starting from the root level up to (but not including) the current directory
|
|
89
|
-
var rootSegments = pathSegments.slice(0, pathSegments.length - maxBackNavigation);
|
|
90
|
-
var variantSegments = pathSegments.slice(rootSegments.length);
|
|
91
|
-
return variantSegments.length > 0 ? "".concat(variantSegments.join('/'), "/") : '';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Create path context for processing files with extended information
|
|
96
|
-
*/
|
|
97
|
-
export function createPathContext(variant) {
|
|
98
|
-
var hasUrl = Boolean(variant.url);
|
|
99
|
-
var actualUrl = variant.url;
|
|
100
|
-
var hasMetadata = variant.extraFiles ? Object.values(variant.extraFiles).some(function (file) {
|
|
101
|
-
return _typeof(file) === 'object' && file.metadata;
|
|
102
|
-
}) : false;
|
|
103
|
-
var maxBackNavigation = variant.extraFiles ? calculateMaxBackNavigation(variant.extraFiles) : 0;
|
|
104
|
-
|
|
105
|
-
// If no URL but we have back navigation, create a synthetic URL
|
|
106
|
-
if (!hasUrl && maxBackNavigation > 0 && variant.fileName) {
|
|
107
|
-
var syntheticPath = generateSyntheticPath(maxBackNavigation);
|
|
108
|
-
actualUrl = "file:///".concat(syntheticPath).concat(variant.fileName);
|
|
109
|
-
hasUrl = true;
|
|
110
|
-
}
|
|
111
|
-
var urlDirectory = hasUrl && actualUrl ? getDirectoryFromUrl(actualUrl) : [];
|
|
112
|
-
var rootLevel = calculateRootLevel(actualUrl, maxBackNavigation);
|
|
113
|
-
var pathInwardFromRoot = calculatePathInwardFromRoot(actualUrl, maxBackNavigation);
|
|
114
|
-
if (hasUrl && actualUrl) {
|
|
115
|
-
return {
|
|
116
|
-
hasUrl: true,
|
|
117
|
-
hasMetadata: hasMetadata,
|
|
118
|
-
maxBackNavigation: maxBackNavigation,
|
|
119
|
-
urlDirectory: urlDirectory,
|
|
120
|
-
rootLevel: rootLevel,
|
|
121
|
-
pathInwardFromRoot: pathInwardFromRoot,
|
|
122
|
-
actualUrl: actualUrl
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
hasUrl: false,
|
|
127
|
-
hasMetadata: hasMetadata,
|
|
128
|
-
maxBackNavigation: maxBackNavigation,
|
|
129
|
-
urlDirectory: urlDirectory,
|
|
130
|
-
rootLevel: rootLevel,
|
|
131
|
-
pathInwardFromRoot: pathInwardFromRoot,
|
|
132
|
-
actualUrl: undefined
|
|
133
|
-
};
|
|
134
|
-
}
|