@mui/internal-docs-infra 0.1.1-alpha.13 → 0.1.1-alpha.14

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.
@@ -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
- // Export variant with additional configuration files
113
- var _exportVariant = exportVariant(variantCode, {
114
- title: title,
115
- description: description,
116
- useTypescript: useTypescript
117
- }),
118
- exported = _exportVariant.exported,
119
- rootFile = _exportVariant.rootFile;
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
- // Export variant as CRA template with additional configuration files
148
- var _exportVariantAsCra = exportVariantAsCra(variantCode, {
149
- title: title,
150
- description: description,
151
- useTypescript: useTypescript
152
- }),
153
- craExport = _exportVariantAsCra.exported,
154
- rootFile = _exportVariantAsCra.rootFile;
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
- }