@teambit/preview.ui.preview-placeholder 0.0.539 → 0.0.542
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/dist/preview-placeholder.js +16 -7
- package/dist/preview-placeholder.js.map +1 -1
- package/dist/preview-placeholder.module.scss +16 -0
- package/package.json +4 -4
- package/preview-placeholder.module.scss +16 -0
- package/preview-placeholder.tsx +30 -13
- /package/dist/{preview-1741111850470.js → preview-1744773530378.js} +0 -0
|
@@ -34,7 +34,7 @@ const react_1 = __importStar(require("react"));
|
|
|
34
34
|
const compositions_1 = require("@teambit/compositions");
|
|
35
35
|
const design_ui_heading_1 = require("@teambit/design.ui.heading");
|
|
36
36
|
const toolbox_string_capitalize_1 = require("@teambit/toolbox.string.capitalize");
|
|
37
|
-
const
|
|
37
|
+
const base_ui_loaders_skeleton_1 = require("@teambit/base-ui.loaders.skeleton");
|
|
38
38
|
const docs_1 = require("@teambit/docs");
|
|
39
39
|
const preview_placeholder_module_scss_1 = __importDefault(require("./preview-placeholder.module.scss"));
|
|
40
40
|
function getCompositions(component) {
|
|
@@ -65,16 +65,25 @@ function getDescription(component) {
|
|
|
65
65
|
return descriptionItem.value || '';
|
|
66
66
|
}
|
|
67
67
|
function PreviewPlaceholder(_a) {
|
|
68
|
-
var _b;
|
|
68
|
+
var _b, _c;
|
|
69
69
|
var { component, componentDescriptor, Container = ({ children, className }) => react_1.default.createElement("div", { className: className }, children), shouldShowPreview = ((_b = component === null || component === void 0 ? void 0 : component.compositions.length) !== null && _b !== void 0 ? _b : 0) > 0 && (component === null || component === void 0 ? void 0 : component.buildStatus) !== 'pending', } = _a;
|
|
70
70
|
const compositions = component === null || component === void 0 ? void 0 : component.compositions;
|
|
71
71
|
const description = componentDescriptor && getDescription(componentDescriptor);
|
|
72
72
|
const displayName = componentDescriptor && getDisplayName(componentDescriptor);
|
|
73
|
+
const serverUrl = (_c = component === null || component === void 0 ? void 0 : component.server) === null || _c === void 0 ? void 0 : _c.url;
|
|
74
|
+
const prevServerUrlRef = (0, react_1.useRef)(serverUrl);
|
|
75
|
+
const [forceRender, setForceRender] = react_1.default.useState(0);
|
|
76
|
+
(0, react_1.useEffect)(() => {
|
|
77
|
+
if (prevServerUrlRef.current !== serverUrl && shouldShowPreview) {
|
|
78
|
+
prevServerUrlRef.current = serverUrl;
|
|
79
|
+
setForceRender(prev => prev + 1);
|
|
80
|
+
}
|
|
81
|
+
}, [serverUrl, shouldShowPreview]);
|
|
73
82
|
const selectedPreview = (0, react_1.useMemo)(() => {
|
|
74
83
|
if (!shouldShowPreview || !component)
|
|
75
84
|
return undefined;
|
|
76
85
|
return selectDefaultComposition(component);
|
|
77
|
-
}, [component, shouldShowPreview]);
|
|
86
|
+
}, [component, shouldShowPreview, forceRender]);
|
|
78
87
|
if (!component || !componentDescriptor)
|
|
79
88
|
return null;
|
|
80
89
|
if (!shouldShowPreview || !compositions || !compositions.length) {
|
|
@@ -86,11 +95,11 @@ function PreviewPlaceholder(_a) {
|
|
|
86
95
|
react_1.default.createElement("span", { className: preview_placeholder_module_scss_1.default.description }, description))));
|
|
87
96
|
}
|
|
88
97
|
const name = component.id.toString();
|
|
89
|
-
if (!shouldShowPreview && component.buildStatus === 'pending')
|
|
98
|
+
if (!serverUrl || (!shouldShowPreview && (component.buildStatus === 'pending')))
|
|
90
99
|
return (react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.previewPlaceholder, "data-tip": "", "data-for": name },
|
|
91
|
-
react_1.default.createElement(
|
|
92
|
-
|
|
93
|
-
return (react_1.default.createElement(
|
|
100
|
+
react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.skeletonContainer },
|
|
101
|
+
react_1.default.createElement(base_ui_loaders_skeleton_1.BlockSkeleton, { lines: 12, className: preview_placeholder_module_scss_1.default.skeletonBlock }))));
|
|
102
|
+
return (react_1.default.createElement("div", { key: `${name}-${serverUrl}-${forceRender}` },
|
|
94
103
|
react_1.default.createElement(compositions_1.ComponentComposition, { component: component, composition: selectedPreview, pubsub: false, includeEnv: true, loading: 'lazy', viewport: 1280 }),
|
|
95
104
|
react_1.default.createElement("div", { className: preview_placeholder_module_scss_1.default.previewOverlay })));
|
|
96
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-placeholder.js","sourceRoot":"","sources":["../preview-placeholder.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"preview-placeholder.js","sourceRoot":"","sources":["../preview-placeholder.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,0CAMC;AAED,wCAGC;AASD,wCAIC;AAED,gDAuEC;AA3GD,+CAAoF;AACpF,wDAA8F;AAC9F,kEAAoD;AACpD,kFAAgE;AAGhE,gFAAkE;AAClE,wCAA2C;AAC3C,wGAAuD;AAEvD,SAAgB,eAAe,CAAC,SAA8B;IAC5D,MAAM,KAAK,GAAQ,SAAS,CAAC,GAAG,CAAC,iCAAkB,CAAC,EAAE,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC;IAC7C,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IAC7B,OAAO,0BAAW,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;AAC7C,CAAC;AAED,SAAgB,cAAc,CAAC,SAA8B;IAC3D,MAAM,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,sCAAU,EAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,SAA8B,EAAE,IAAY;;IACnE,MAAM,IAAI,GA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ify-content: center;
|
|
6
6
|
height: 100%;
|
|
7
|
+
width: 100%;
|
|
7
8
|
color: #c7c7c7;
|
|
8
9
|
pointer-events: auto;
|
|
9
10
|
> span:first-child {
|
|
@@ -76,3 +77,18 @@
|
|
|
76
77
|
z-index: 100;
|
|
77
78
|
cursor: pointer;
|
|
78
79
|
}
|
|
80
|
+
|
|
81
|
+
.skeletonContainer {
|
|
82
|
+
width: 100%;
|
|
83
|
+
height: 100%;
|
|
84
|
+
position: relative;
|
|
85
|
+
color: var(--skeleton-color, #e0e0e0);
|
|
86
|
+
opacity: 0.7;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.skeletonBlock {
|
|
90
|
+
width: 100%;
|
|
91
|
+
height: 100%;
|
|
92
|
+
min-height: 200px;
|
|
93
|
+
display: block;
|
|
94
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/preview.ui.preview-placeholder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.542",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/preview/ui/preview-placeholder",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.preview",
|
|
8
8
|
"name": "ui/preview-placeholder",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.542"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"core-js": "^3.0.0",
|
|
13
|
+
"@teambit/base-ui.loaders.skeleton": "1.0.1",
|
|
13
14
|
"@teambit/design.ui.heading": "1.0.16",
|
|
14
|
-
"@teambit/
|
|
15
|
-
"@teambit/component-descriptor": "0.0.433",
|
|
15
|
+
"@teambit/component-descriptor": "0.0.435",
|
|
16
16
|
"@teambit/toolbox.string.capitalize": "0.0.500"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
align-items: center;
|
|
5
5
|
justify-content: center;
|
|
6
6
|
height: 100%;
|
|
7
|
+
width: 100%;
|
|
7
8
|
color: #c7c7c7;
|
|
8
9
|
pointer-events: auto;
|
|
9
10
|
> span:first-child {
|
|
@@ -76,3 +77,18 @@
|
|
|
76
77
|
z-index: 100;
|
|
77
78
|
cursor: pointer;
|
|
78
79
|
}
|
|
80
|
+
|
|
81
|
+
.skeletonContainer {
|
|
82
|
+
width: 100%;
|
|
83
|
+
height: 100%;
|
|
84
|
+
position: relative;
|
|
85
|
+
color: var(--skeleton-color, #e0e0e0);
|
|
86
|
+
opacity: 0.7;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.skeletonBlock {
|
|
90
|
+
width: 100%;
|
|
91
|
+
height: 100%;
|
|
92
|
+
min-height: 200px;
|
|
93
|
+
display: block;
|
|
94
|
+
}
|
package/preview-placeholder.tsx
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import React, { useMemo, ComponentType, ReactNode } from 'react';
|
|
1
|
+
import React, { useMemo, useEffect, useRef, ComponentType, ReactNode } from 'react';
|
|
2
2
|
import { CompositionsAspect, ComponentComposition, Composition } from '@teambit/compositions';
|
|
3
3
|
import { H3, H5 } from '@teambit/design.ui.heading';
|
|
4
4
|
import { capitalize } from '@teambit/toolbox.string.capitalize';
|
|
5
|
-
import { Icon } from '@teambit/evangelist.elements.icon';
|
|
6
5
|
import { ComponentModel } from '@teambit/component';
|
|
7
6
|
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
7
|
+
import { BlockSkeleton } from '@teambit/base-ui.loaders.skeleton';
|
|
8
8
|
import { DocsAspect } from '@teambit/docs';
|
|
9
|
-
|
|
10
9
|
import styles from './preview-placeholder.module.scss';
|
|
11
10
|
|
|
12
11
|
export function getCompositions(component: ComponentDescriptor) {
|
|
@@ -14,7 +13,6 @@ export function getCompositions(component: ComponentDescriptor) {
|
|
|
14
13
|
if (!entry) return [];
|
|
15
14
|
const compositions = entry.data.compositions;
|
|
16
15
|
if (!compositions) return [];
|
|
17
|
-
|
|
18
16
|
return Composition.fromArray(compositions);
|
|
19
17
|
}
|
|
20
18
|
|
|
@@ -50,11 +48,22 @@ export function PreviewPlaceholder({
|
|
|
50
48
|
const compositions = component?.compositions;
|
|
51
49
|
const description = componentDescriptor && getDescription(componentDescriptor);
|
|
52
50
|
const displayName = componentDescriptor && getDisplayName(componentDescriptor);
|
|
51
|
+
const serverUrl = component?.server?.url;
|
|
52
|
+
|
|
53
|
+
const prevServerUrlRef = useRef(serverUrl);
|
|
54
|
+
const [forceRender, setForceRender] = React.useState(0);
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (prevServerUrlRef.current !== serverUrl && shouldShowPreview) {
|
|
58
|
+
prevServerUrlRef.current = serverUrl;
|
|
59
|
+
setForceRender(prev => prev + 1);
|
|
60
|
+
}
|
|
61
|
+
}, [serverUrl, shouldShowPreview]);
|
|
53
62
|
|
|
54
63
|
const selectedPreview = useMemo(() => {
|
|
55
64
|
if (!shouldShowPreview || !component) return undefined;
|
|
56
65
|
return selectDefaultComposition(component);
|
|
57
|
-
}, [component, shouldShowPreview]);
|
|
66
|
+
}, [component, shouldShowPreview, forceRender]);
|
|
58
67
|
|
|
59
68
|
if (!component || !componentDescriptor) return null;
|
|
60
69
|
|
|
@@ -71,21 +80,30 @@ export function PreviewPlaceholder({
|
|
|
71
80
|
</Container>
|
|
72
81
|
);
|
|
73
82
|
}
|
|
83
|
+
|
|
74
84
|
const name = component.id.toString();
|
|
75
85
|
|
|
76
|
-
if (!shouldShowPreview && component.buildStatus === 'pending')
|
|
86
|
+
if (!serverUrl || (!shouldShowPreview && (component.buildStatus === 'pending')))
|
|
77
87
|
return (
|
|
78
88
|
<div className={styles.previewPlaceholder} data-tip="" data-for={name}>
|
|
79
|
-
<
|
|
80
|
-
|
|
89
|
+
<div className={styles.skeletonContainer}>
|
|
90
|
+
<BlockSkeleton lines={12} className={styles.skeletonBlock} />
|
|
91
|
+
</div>
|
|
81
92
|
</div>
|
|
82
93
|
);
|
|
83
94
|
|
|
84
95
|
return (
|
|
85
|
-
|
|
86
|
-
<ComponentComposition
|
|
96
|
+
<div key={`${name}-${serverUrl}-${forceRender}`}>
|
|
97
|
+
<ComponentComposition
|
|
98
|
+
component={component}
|
|
99
|
+
composition={selectedPreview}
|
|
100
|
+
pubsub={false}
|
|
101
|
+
includeEnv={true}
|
|
102
|
+
loading={'lazy'}
|
|
103
|
+
viewport={1280}
|
|
104
|
+
/>
|
|
87
105
|
<div className={styles.previewOverlay} />
|
|
88
|
-
|
|
106
|
+
</div>
|
|
89
107
|
);
|
|
90
108
|
}
|
|
91
109
|
|
|
@@ -93,6 +111,5 @@ const PREVIEW_COMPOSITION_SUFFIX = 'Preview';
|
|
|
93
111
|
|
|
94
112
|
function selectDefaultComposition(component: ComponentModel) {
|
|
95
113
|
const { compositions } = component;
|
|
96
|
-
|
|
97
114
|
return compositions.find((x) => x.identifier.endsWith(PREVIEW_COMPOSITION_SUFFIX));
|
|
98
|
-
}
|
|
115
|
+
}
|
|
File without changes
|