@teambit/preview 1.0.114 → 1.0.116
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/artifacts/__bit_junit.xml +2 -2
- package/artifacts/preview/teambit_preview_preview-preview.js +1 -1
- package/dist/{preview-1703992959524.js → preview-1704113440840.js} +2 -2
- package/dist/preview-modules.d.ts +1 -10
- package/dist/preview-modules.js +21 -25
- package/dist/preview-modules.js.map +1 -1
- package/dist/preview.composition.d.ts +1 -0
- package/dist/preview.graphql.d.ts +6 -0
- package/dist/preview.graphql.js +15 -1
- package/dist/preview.graphql.js.map +1 -1
- package/dist/preview.main.runtime.d.ts +35 -1
- package/dist/preview.main.runtime.js +63 -5
- package/dist/preview.main.runtime.js.map +1 -1
- package/dist/preview.preview.runtime.js +2 -4
- package/dist/preview.preview.runtime.js.map +1 -1
- package/dist/preview.start-plugin.d.ts +1 -0
- package/dist/types/preview-module.d.ts +1 -28
- package/dist/types/preview-module.js.map +1 -1
- package/package.json +18 -17
- package/preview-modules.tsx +1 -28
- package/preview.main.runtime.tsx +79 -3
- package/preview.preview.runtime.tsx +2 -3
- package/types/preview-module.ts +1 -32
package/preview-modules.tsx
CHANGED
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type ModuleId = string;
|
|
4
|
-
|
|
5
|
-
export class PreviewModules extends Map<ModuleId, PreviewModule> {
|
|
6
|
-
onSet = new Set<() => void>();
|
|
7
|
-
|
|
8
|
-
override set(id: ModuleId, preview: PreviewModule) {
|
|
9
|
-
super.set(id, preview);
|
|
10
|
-
this.onSet.forEach((callback) => callback());
|
|
11
|
-
return this;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
loadComponentPreviews(compId: string, previews: Record<string, ModuleFile[]>) {
|
|
15
|
-
Object.entries(previews).forEach(([previewName, moduleFile]) => {
|
|
16
|
-
const preview = this.get(previewName);
|
|
17
|
-
if (!preview) return; // TODO - ok for now
|
|
18
|
-
|
|
19
|
-
preview.componentMap[compId] = moduleFile;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const PREVIEW_MODULES = new PreviewModules();
|
|
25
|
-
|
|
26
|
-
export function linkModules(previewName: string, previewModule: PreviewModule) {
|
|
27
|
-
PREVIEW_MODULES.set(previewName, previewModule);
|
|
28
|
-
}
|
|
1
|
+
export { PreviewModules, linkModules, PREVIEW_MODULES } from '@teambit/preview.modules.preview-modules';
|
package/preview.main.runtime.tsx
CHANGED
|
@@ -119,6 +119,16 @@ export type PreviewAnyComponentData = {
|
|
|
119
119
|
*/
|
|
120
120
|
splitComponentBundle?: boolean;
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* don't allow other aspects implementing a preview definition to be included in your preview.
|
|
124
|
+
*/
|
|
125
|
+
onlyOverview?: boolean;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* use name query params to select a specific composition to render.
|
|
129
|
+
*/
|
|
130
|
+
useNameParam?: boolean;
|
|
131
|
+
|
|
122
132
|
/**
|
|
123
133
|
* don't allow other aspects implementing a preview definition to be included in your preview.
|
|
124
134
|
*/
|
|
@@ -130,6 +140,8 @@ export type PreviewAnyComponentData = {
|
|
|
130
140
|
*/
|
|
131
141
|
export type PreviewEnvComponentData = {
|
|
132
142
|
isScaling?: boolean;
|
|
143
|
+
supportsOnlyOverview?: boolean;
|
|
144
|
+
supportsUseNameParam?: boolean;
|
|
133
145
|
};
|
|
134
146
|
|
|
135
147
|
export type PreviewConfig = {
|
|
@@ -141,6 +153,7 @@ export type PreviewConfig = {
|
|
|
141
153
|
* default - no limit.
|
|
142
154
|
*/
|
|
143
155
|
maxChunkSize?: number;
|
|
156
|
+
onlyOverview?: boolean;
|
|
144
157
|
};
|
|
145
158
|
|
|
146
159
|
export type EnvPreviewConfig = {
|
|
@@ -244,6 +257,42 @@ export class PreviewMain {
|
|
|
244
257
|
return previewData;
|
|
245
258
|
}
|
|
246
259
|
|
|
260
|
+
/**
|
|
261
|
+
* check if the current version of env component supports skipping other included previews
|
|
262
|
+
* @param envComponent
|
|
263
|
+
* @returns
|
|
264
|
+
*/
|
|
265
|
+
doesEnvIncludesOnlyOverview(envComponent: Component): boolean {
|
|
266
|
+
const previewData = this.getPreviewData(envComponent);
|
|
267
|
+
return !!previewData?.supportsOnlyOverview;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* check if the current version of env component supports name query param
|
|
272
|
+
* @param envComponent
|
|
273
|
+
* @returns
|
|
274
|
+
*/
|
|
275
|
+
doesEnvUseNameParam(envComponent: Component): boolean {
|
|
276
|
+
const previewData = this.getPreviewData(envComponent);
|
|
277
|
+
return !!previewData?.supportsUseNameParam;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private async calculateIncludeOnlyOverview(component: Component): Promise<boolean> {
|
|
281
|
+
if (this.envs.isUsingCoreEnv(component)) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
const envComponent = await this.envs.getEnvComponent(component);
|
|
285
|
+
return this.doesEnvIncludesOnlyOverview(envComponent);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private async calculateUseNameParam(component: Component): Promise<boolean> {
|
|
289
|
+
if (this.envs.isUsingCoreEnv(component)) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
const envComponent = await this.envs.getEnvComponent(component);
|
|
293
|
+
return this.doesEnvUseNameParam(envComponent);
|
|
294
|
+
}
|
|
295
|
+
|
|
247
296
|
/**
|
|
248
297
|
* Calculate preview data on component load
|
|
249
298
|
* @param component
|
|
@@ -253,8 +302,13 @@ export class PreviewMain {
|
|
|
253
302
|
const doesScaling = await this.calcDoesScalingForComponent(component);
|
|
254
303
|
const dataFromEnv = await this.calcPreviewDataFromEnv(component);
|
|
255
304
|
const envData = (await this.calculateDataForEnvComponent(component)) || {};
|
|
305
|
+
const onlyOverview = await this.calculateIncludeOnlyOverview(component);
|
|
306
|
+
const useNameParam = await this.calculateUseNameParam(component);
|
|
307
|
+
|
|
256
308
|
const data: PreviewComponentData = {
|
|
257
309
|
doesScaling,
|
|
310
|
+
onlyOverview,
|
|
311
|
+
useNameParam,
|
|
258
312
|
...dataFromEnv,
|
|
259
313
|
...envData,
|
|
260
314
|
};
|
|
@@ -268,7 +322,7 @@ export class PreviewMain {
|
|
|
268
322
|
*/
|
|
269
323
|
async calcPreviewDataFromEnv(
|
|
270
324
|
component: Component
|
|
271
|
-
): Promise<Omit<PreviewAnyComponentData, 'doesScaling'> | undefined> {
|
|
325
|
+
): Promise<Omit<PreviewAnyComponentData, 'doesScaling' | 'onlyOverview' | 'useNameParam'> | undefined> {
|
|
272
326
|
// Prevent infinite loop that caused by the fact that the env of the aspect env or the env env is the same as the component
|
|
273
327
|
// so we can't load it since during load we are trying to get env component and load it again
|
|
274
328
|
if (
|
|
@@ -297,15 +351,17 @@ export class PreviewMain {
|
|
|
297
351
|
*/
|
|
298
352
|
private async calculateDataForEnvComponent(envComponent: Component): Promise<PreviewEnvComponentData | undefined> {
|
|
299
353
|
const isEnv = this.envs.isEnv(envComponent);
|
|
354
|
+
|
|
300
355
|
// If the component is not an env, we don't want to store anything in the data
|
|
301
356
|
if (!isEnv) return undefined;
|
|
357
|
+
|
|
302
358
|
const previewAspectConfig = this.getPreviewAspectConfig(envComponent);
|
|
303
359
|
|
|
304
360
|
const data = {
|
|
305
361
|
// default to true if the env doesn't have a preview config
|
|
306
362
|
isScaling: previewAspectConfig?.isScaling ?? true,
|
|
307
|
-
|
|
308
|
-
|
|
363
|
+
supportsOnlyOverview: true,
|
|
364
|
+
supportsUseNameParam: true,
|
|
309
365
|
};
|
|
310
366
|
return data;
|
|
311
367
|
}
|
|
@@ -429,6 +485,8 @@ export class PreviewMain {
|
|
|
429
485
|
}
|
|
430
486
|
|
|
431
487
|
async isSupportSkipIncludes(component: Component) {
|
|
488
|
+
if (!this.config.onlyOverview) return false;
|
|
489
|
+
|
|
432
490
|
const isCore = this.envs.isUsingCoreEnv(component);
|
|
433
491
|
if (isCore) return false;
|
|
434
492
|
|
|
@@ -437,6 +495,23 @@ export class PreviewMain {
|
|
|
437
495
|
return !!previewData?.skipIncludes;
|
|
438
496
|
}
|
|
439
497
|
|
|
498
|
+
/**
|
|
499
|
+
* check if the component preview should only include the overview (skipping rendering of the compostions and properties table)
|
|
500
|
+
*/
|
|
501
|
+
async getOnlyOverview(component: Component): Promise<boolean> {
|
|
502
|
+
if (!this.config.onlyOverview) return false;
|
|
503
|
+
const previewData = this.getPreviewData(component);
|
|
504
|
+
return previewData?.onlyOverview ?? false;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* check if the component preview should include the name query param
|
|
509
|
+
*/
|
|
510
|
+
async getUseNameParam(component: Component): Promise<boolean> {
|
|
511
|
+
const previewData = this.getPreviewData(component);
|
|
512
|
+
return previewData?.useNameParam ?? false;
|
|
513
|
+
}
|
|
514
|
+
|
|
440
515
|
/**
|
|
441
516
|
* This function is calculate the isScaling support flag for the component preview.
|
|
442
517
|
* This is calculated only for the env component and not for the component itself.
|
|
@@ -815,6 +890,7 @@ export class PreviewMain {
|
|
|
815
890
|
|
|
816
891
|
static defaultConfig = {
|
|
817
892
|
disabled: false,
|
|
893
|
+
onlyOverview: false,
|
|
818
894
|
};
|
|
819
895
|
|
|
820
896
|
static async provider(
|
|
@@ -104,11 +104,10 @@ export class PreviewPreview {
|
|
|
104
104
|
})
|
|
105
105
|
);
|
|
106
106
|
|
|
107
|
-
// remove `includes` (including compositions) when skipIncludes = true.
|
|
108
107
|
const query = this.getQuery();
|
|
109
|
-
const
|
|
108
|
+
const onlyOverview = this.getParam(query, 'onlyOverview');
|
|
110
109
|
|
|
111
|
-
const includes =
|
|
110
|
+
const includes = onlyOverview === 'true' ? [] : includesAll.filter((module) => !!module);
|
|
112
111
|
// during build / tag, the component is isolated, so all aspects are relevant, and do not require filtering
|
|
113
112
|
const componentAspects = this.isDev ? await this.getComponentAspects(componentId.toString()) : undefined;
|
|
114
113
|
const previewModule = await this.getPreviewModule(name, componentId);
|
package/types/preview-module.ts
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
type
|
|
2
|
-
(...args: any[]): void;
|
|
3
|
-
apiObject?: boolean;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A full index of the preview data
|
|
8
|
-
*/
|
|
9
|
-
export type PreviewModule<T = any> = {
|
|
10
|
-
/** Dictionary mapping components to their module files. */
|
|
11
|
-
componentMap: Record<string, ModuleFile<T>[]>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Dictionary mapping components to their preview metadata
|
|
15
|
-
*/
|
|
16
|
-
componentMapMetadata: Record<string, unknown>;
|
|
17
|
-
|
|
18
|
-
/** The 'main file' for this Preview type */
|
|
19
|
-
modulesMap: {
|
|
20
|
-
default: {
|
|
21
|
-
default: MainModuleExports;
|
|
22
|
-
};
|
|
23
|
-
[envId: string]: {
|
|
24
|
-
default: MainModuleExports;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
isSplitComponentBundle?: boolean;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/** single preview module, e.g. compositions file */
|
|
32
|
-
export type ModuleFile<T = any> = Record<string, T>;
|
|
1
|
+
export type { PreviewModule, ModuleFile } from '@teambit/preview.modules.preview-modules';
|