@teambit/ui-foundation.ui.rendering.html 0.0.0-38e5412ae35cabe897bc87f558e8995d70a34d52
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/dev-tools.tsx +10 -0
- package/dist/dev-tools.d.ts +2 -0
- package/dist/dev-tools.js +13 -0
- package/dist/dev-tools.js.map +1 -0
- package/dist/full-height-style.d.ts +2 -0
- package/dist/full-height-style.js +12 -0
- package/dist/full-height-style.js.map +1 -0
- package/dist/html.d.ts +30 -0
- package/dist/html.js +63 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/mount-point.d.ts +7 -0
- package/dist/mount-point.js +19 -0
- package/dist/mount-point.js.map +1 -0
- package/dist/preview-1753881650385.js +7 -0
- package/dist/ssr-styles.d.ts +3 -0
- package/dist/ssr-styles.js +20 -0
- package/dist/ssr-styles.js.map +1 -0
- package/dist/stored-assets.d.ts +6 -0
- package/dist/stored-assets.js +28 -0
- package/dist/stored-assets.js.map +1 -0
- package/full-height-style.tsx +6 -0
- package/html.tsx +87 -0
- package/index.ts +4 -0
- package/mount-point.tsx +14 -0
- package/package.json +48 -0
- package/ssr-styles.tsx +15 -0
- package/stored-assets.tsx +30 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
package/dev-tools.tsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export function CrossIframeDevTools() {
|
|
4
|
+
return (
|
|
5
|
+
<script>
|
|
6
|
+
{'/* Allow to use react dev-tools inside the examples */\n'}
|
|
7
|
+
{'try { window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__; } catch {}'}
|
|
8
|
+
</script>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CrossIframeDevTools = CrossIframeDevTools;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
function CrossIframeDevTools() {
|
|
9
|
+
return (react_1.default.createElement("script", null,
|
|
10
|
+
'/* Allow to use react dev-tools inside the examples */\n',
|
|
11
|
+
'try { window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__; } catch {}'));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=dev-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-tools.js","sourceRoot":"","sources":["../dev-tools.tsx"],"names":[],"mappings":";;;;;AAEA,kDAOC;AATD,kDAA0B;AAE1B,SAAgB,mBAAmB;IACjC,OAAO,CACL;QACG,0DAA0D;QAC1D,wGAAwG,CAClG,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FullHeightStyle = FullHeightStyle;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
function FullHeightStyle() {
|
|
9
|
+
// return <style> {'html { height: 100%; } body { margin: 0; height: 100%; } #root { height: 100%; }'} </style>;
|
|
10
|
+
return react_1.default.createElement("style", null, 'body { margin: 0; }');
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=full-height-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"full-height-style.js","sourceRoot":"","sources":["../full-height-style.tsx"],"names":[],"mappings":";;;;;AAEA,0CAGC;AALD,kDAA0B;AAE1B,SAAgB,eAAe;IAC7B,gHAAgH;IAChH,OAAO,6CAAQ,qBAAqB,CAAS,CAAC;AAChD,CAAC"}
|
package/dist/html.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fillMountPoint } from './mount-point';
|
|
3
|
+
export declare const LOAD_EVENT = "_DOM_LOADED_";
|
|
4
|
+
export declare const ERROR_EVENT = "_ERROR_OCCURRED_";
|
|
5
|
+
export type Assets = Partial<{
|
|
6
|
+
/** page title */
|
|
7
|
+
title: string;
|
|
8
|
+
/** js files to load */
|
|
9
|
+
js: string[];
|
|
10
|
+
/** css files to load */
|
|
11
|
+
css: string[];
|
|
12
|
+
/** raw css styles */
|
|
13
|
+
style: string[];
|
|
14
|
+
/** raw data to be stored in the dom. Use Html.popAssets to retrieve it from the dom */
|
|
15
|
+
json: Record<string, string>;
|
|
16
|
+
}>;
|
|
17
|
+
export interface HtmlProps extends React.HtmlHTMLAttributes<HTMLHtmlElement> {
|
|
18
|
+
withDevTools?: boolean;
|
|
19
|
+
fullHeight?: boolean;
|
|
20
|
+
assets?: Assets;
|
|
21
|
+
ssr?: boolean;
|
|
22
|
+
notifyParentOnLoad?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** html template for the main UI, when ssr is active */
|
|
25
|
+
export declare function Html({ assets, withDevTools, fullHeight, ssr, children, notifyParentOnLoad, ...rest }: HtmlProps): React.JSX.Element;
|
|
26
|
+
export declare namespace Html {
|
|
27
|
+
var fillContent: typeof fillMountPoint;
|
|
28
|
+
var popAssets: typeof import("./stored-assets").popAssets;
|
|
29
|
+
}
|
|
30
|
+
export declare function ssrCleanup(): void;
|
package/dist/html.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ERROR_EVENT = exports.LOAD_EVENT = void 0;
|
|
18
|
+
exports.Html = Html;
|
|
19
|
+
exports.ssrCleanup = ssrCleanup;
|
|
20
|
+
const react_1 = __importDefault(require("react"));
|
|
21
|
+
const dev_tools_1 = require("./dev-tools");
|
|
22
|
+
const mount_point_1 = require("./mount-point");
|
|
23
|
+
const stored_assets_1 = require("./stored-assets");
|
|
24
|
+
const ssr_styles_1 = require("./ssr-styles");
|
|
25
|
+
const full_height_style_1 = require("./full-height-style");
|
|
26
|
+
exports.LOAD_EVENT = '_DOM_LOADED_';
|
|
27
|
+
exports.ERROR_EVENT = '_ERROR_OCCURRED_';
|
|
28
|
+
const NotifyParentScript = () => (react_1.default.createElement("script", { dangerouslySetInnerHTML: {
|
|
29
|
+
__html: `
|
|
30
|
+
// only send loaded event when mounted in an iframe
|
|
31
|
+
if (window.parent && window !== window.parent) {
|
|
32
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
33
|
+
window.parent.postMessage({ event: '${exports.LOAD_EVENT}' }, '*');
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
`,
|
|
37
|
+
} }));
|
|
38
|
+
/** html template for the main UI, when ssr is active */
|
|
39
|
+
function Html(_a) {
|
|
40
|
+
var _b, _c, _d;
|
|
41
|
+
var { assets = {}, withDevTools = false, fullHeight, ssr, children = react_1.default.createElement(mount_point_1.MountPoint, null), notifyParentOnLoad = true } = _a, rest = __rest(_a, ["assets", "withDevTools", "fullHeight", "ssr", "children", "notifyParentOnLoad"]);
|
|
42
|
+
return (react_1.default.createElement("html", Object.assign({ lang: "en" }, rest),
|
|
43
|
+
react_1.default.createElement("head", null,
|
|
44
|
+
react_1.default.createElement("title", null, assets.title || 'bit scope'),
|
|
45
|
+
react_1.default.createElement("meta", { charSet: "utf-8" }),
|
|
46
|
+
react_1.default.createElement("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" }),
|
|
47
|
+
ssr && react_1.default.createElement(ssr_styles_1.SsrStyles, null),
|
|
48
|
+
fullHeight && react_1.default.createElement(full_height_style_1.FullHeightStyle, null),
|
|
49
|
+
withDevTools && react_1.default.createElement(dev_tools_1.CrossIframeDevTools, null), (_b = assets.style) === null || _b === void 0 ? void 0 :
|
|
50
|
+
_b.map((x, idx) => react_1.default.createElement("style", { key: idx }, x)), (_c = assets.css) === null || _c === void 0 ? void 0 :
|
|
51
|
+
_c.map((x, idx) => react_1.default.createElement("link", { key: idx, href: x, rel: "stylesheet", type: "text/css" })),
|
|
52
|
+
notifyParentOnLoad && react_1.default.createElement(NotifyParentScript, null)),
|
|
53
|
+
react_1.default.createElement("body", null,
|
|
54
|
+
children,
|
|
55
|
+
assets.json && react_1.default.createElement(stored_assets_1.StoredAssets, { data: assets.json }), (_d = assets.js) === null || _d === void 0 ? void 0 :
|
|
56
|
+
_d.map((x, idx) => react_1.default.createElement("script", { key: idx, src: x })))));
|
|
57
|
+
}
|
|
58
|
+
Html.fillContent = mount_point_1.fillMountPoint;
|
|
59
|
+
Html.popAssets = stored_assets_1.popAssets;
|
|
60
|
+
function ssrCleanup() {
|
|
61
|
+
(0, ssr_styles_1.removeSsrStyles)();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=html.js.map
|
package/dist/html.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../html.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA+CA,oBAgCC;AAKD,gCAEC;AAtFD,kDAA0B;AAC1B,2CAAkD;AAClD,+CAA2D;AAC3D,mDAA0D;AAC1D,6CAA0D;AAC1D,2DAAsD;AAEzC,QAAA,UAAU,GAAG,cAAc,CAAC;AAC5B,QAAA,WAAW,GAAG,kBAAkB,CAAC;AAuB9C,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAAC,CAC/B,0CACE,uBAAuB,EAAE;QACvB,MAAM,EAAE;;;;kDAIoC,kBAAU;;;OAGrD;KACF,GACO,CACX,CAAC;AAEF,wDAAwD;AACxD,SAAgB,IAAI,CAAC,EAQT;;QARS,EACnB,MAAM,GAAG,EAAE,EACX,YAAY,GAAG,KAAK,EACpB,UAAU,EACV,GAAG,EACH,QAAQ,GAAG,8BAAC,wBAAU,OAAG,EACzB,kBAAkB,GAAG,IAAI,OAEf,EADP,IAAI,cAPY,iFAQpB,CADQ;IAEP,OAAO,CACL,sDAAM,IAAI,EAAC,IAAI,IAAK,IAAI;QACtB;YACE,6CAAQ,MAAM,CAAC,KAAK,IAAI,WAAW,CAAS;YAC5C,wCAAM,OAAO,EAAC,OAAO,GAAG;YACxB,wCAAM,IAAI,EAAC,UAAU,EAAC,OAAO,EAAC,uCAAuC,GAAG;YAEvE,GAAG,IAAI,8BAAC,sBAAS,OAAG;YACpB,UAAU,IAAI,8BAAC,mCAAe,OAAG;YACjC,YAAY,IAAI,8BAAC,+BAAmB,OAAG,EAEvC,MAAA,MAAM,CAAC,KAAK;eAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,yCAAO,GAAG,EAAE,GAAG,IAAG,CAAC,CAAS,CAAC,EAC3D,MAAA,MAAM,CAAC,GAAG;eAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,wCAAM,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAC,YAAY,EAAC,IAAI,EAAC,UAAU,GAAG,CAAC;YACzF,kBAAkB,IAAI,8BAAC,kBAAkB,OAAG,CACxC;QACP;YACG,QAAQ;YACR,MAAM,CAAC,IAAI,IAAI,8BAAC,4BAAY,IAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAI,EAElD,MAAA,MAAM,CAAC,EAAE;eAAE,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,0CAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAI,CAAC,CACpD,CACF,CACR,CAAC;AACJ,CAAC;AAED,IAAI,CAAC,WAAW,GAAG,4BAAc,CAAC;AAClC,IAAI,CAAC,SAAS,GAAG,yBAAS,CAAC;AAE3B,SAAgB,UAAU;IACxB,IAAA,4BAAe,GAAE,CAAC;AACpB,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.popAssets = exports.mountPointId = exports.MountPoint = exports.ERROR_EVENT = exports.LOAD_EVENT = exports.ssrCleanup = exports.Html = void 0;
|
|
4
|
+
var html_1 = require("./html");
|
|
5
|
+
Object.defineProperty(exports, "Html", { enumerable: true, get: function () { return html_1.Html; } });
|
|
6
|
+
Object.defineProperty(exports, "ssrCleanup", { enumerable: true, get: function () { return html_1.ssrCleanup; } });
|
|
7
|
+
Object.defineProperty(exports, "LOAD_EVENT", { enumerable: true, get: function () { return html_1.LOAD_EVENT; } });
|
|
8
|
+
Object.defineProperty(exports, "ERROR_EVENT", { enumerable: true, get: function () { return html_1.ERROR_EVENT; } });
|
|
9
|
+
var mount_point_1 = require("./mount-point");
|
|
10
|
+
Object.defineProperty(exports, "MountPoint", { enumerable: true, get: function () { return mount_point_1.MountPoint; } });
|
|
11
|
+
Object.defineProperty(exports, "mountPointId", { enumerable: true, get: function () { return mount_point_1.mountPointId; } });
|
|
12
|
+
var stored_assets_1 = require("./stored-assets");
|
|
13
|
+
Object.defineProperty(exports, "popAssets", { enumerable: true, get: function () { return stored_assets_1.popAssets; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+BAAmE;AAA1D,4FAAA,IAAI,OAAA;AAAE,kGAAA,UAAU,OAAA;AAAE,kGAAA,UAAU,OAAA;AAAE,mGAAA,WAAW,OAAA;AAClD,6CAAyD;AAAhD,yGAAA,UAAU,OAAA;AAAE,2GAAA,YAAY,OAAA;AACjC,iDAA4C;AAAnC,0GAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const mountPointId = "root";
|
|
4
|
+
export declare function MountPoint({ children }: {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}): React.JSX.Element;
|
|
7
|
+
export declare function fillMountPoint(htmlTemplate: string, content: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mountPointId = void 0;
|
|
7
|
+
exports.MountPoint = MountPoint;
|
|
8
|
+
exports.fillMountPoint = fillMountPoint;
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
exports.mountPointId = 'root';
|
|
11
|
+
const placeholderRegex = /<div id="root"><\/div>/;
|
|
12
|
+
function MountPoint({ children }) {
|
|
13
|
+
return react_1.default.createElement("div", { id: exports.mountPointId }, children);
|
|
14
|
+
}
|
|
15
|
+
function fillMountPoint(htmlTemplate, content) {
|
|
16
|
+
const filled = htmlTemplate.replace(placeholderRegex, content);
|
|
17
|
+
return filled;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=mount-point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount-point.js","sourceRoot":"","sources":["../mount-point.tsx"],"names":[],"mappings":";;;;;;AAMA,gCAEC;AAED,wCAGC;AAZD,kDAA0B;AAEb,QAAA,YAAY,GAAG,MAAM,CAAC;AACnC,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAElD,SAAgB,UAAU,CAAC,EAAE,QAAQ,EAA4B;IAC/D,OAAO,uCAAK,EAAE,EAAE,oBAAY,IAAG,QAAQ,CAAO,CAAC;AACjD,CAAC;AAED,SAAgB,cAAc,CAAC,YAAoB,EAAE,OAAe;IAClE,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SsrStyles = SsrStyles;
|
|
7
|
+
exports.removeSsrStyles = removeSsrStyles;
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
function SsrStyles() {
|
|
10
|
+
return (react_1.default.createElement("style", { id: "before-hydrate-styles" },
|
|
11
|
+
".--ssr-hidden ",
|
|
12
|
+
'{',
|
|
13
|
+
"display: none;",
|
|
14
|
+
'}'));
|
|
15
|
+
}
|
|
16
|
+
function removeSsrStyles() {
|
|
17
|
+
var _a;
|
|
18
|
+
(_a = document.getElementById('before-hydrate-styles')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ssr-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssr-styles.js","sourceRoot":"","sources":["../ssr-styles.tsx"],"names":[],"mappings":";;;;;AAEA,8BAQC;AAED,0CAEC;AAdD,kDAA0B;AAE1B,SAAgB,SAAS;IACvB,OAAO,CACL,yCAAO,EAAE,EAAC,uBAAuB;;QAChB,GAAG;;QAEjB,GAAG,CACE,CACT,CAAC;AACJ,CAAC;AAED,SAAgB,eAAe;;IAC7B,MAAA,QAAQ,CAAC,cAAc,CAAC,uBAAuB,CAAC,0CAAE,MAAM,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.StoredAssets = StoredAssets;
|
|
7
|
+
exports.popAssets = popAssets;
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
function StoredAssets({ data }) {
|
|
10
|
+
return (react_1.default.createElement("div", { className: "state", style: { display: 'none' } }, Object.entries(data).map(([key, content]) => (
|
|
11
|
+
// TODO - we falsely assume content is html safe
|
|
12
|
+
react_1.default.createElement("script", { key: key, "data-aspect": key, type: "application/json", dangerouslySetInnerHTML: { __html: content } })))));
|
|
13
|
+
}
|
|
14
|
+
/** read and remove stored data from the dom */
|
|
15
|
+
function popAssets() {
|
|
16
|
+
var _a;
|
|
17
|
+
const rawAssets = new Map();
|
|
18
|
+
const inDom = Array.from(document.querySelectorAll('body > .state > *'));
|
|
19
|
+
inDom.forEach((elem) => {
|
|
20
|
+
const aspectName = elem.getAttribute('data-aspect');
|
|
21
|
+
if (!aspectName)
|
|
22
|
+
return;
|
|
23
|
+
rawAssets.set(aspectName, elem.innerHTML);
|
|
24
|
+
});
|
|
25
|
+
(_a = document.querySelector('body > .state')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
26
|
+
return rawAssets;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=stored-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-assets.js","sourceRoot":"","sources":["../stored-assets.tsx"],"names":[],"mappings":";;;;;AAEA,oCASC;AAGD,8BAeC;AA7BD,kDAA0B;AAE1B,SAAgB,YAAY,CAAC,EAAE,IAAI,EAAoC;IACrE,OAAO,CACL,uCAAK,SAAS,EAAC,OAAO,EAAC,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAC9C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;IAC5C,gDAAgD;IAChD,0CAAQ,GAAG,EAAE,GAAG,iBAAe,GAAG,EAAE,IAAI,EAAC,kBAAkB,EAAC,uBAAuB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAI,CAC7G,CAAC,CACE,CACP,CAAC;AACJ,CAAC;AAED,+CAA+C;AAC/C,SAAgB,SAAS;;IACvB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE5C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAEzE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QACpD,IAAI,CAAC,UAAU;YAAE,OAAO;QAExB,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,MAAA,QAAQ,CAAC,aAAa,CAAC,eAAe,CAAC,0CAAE,MAAM,EAAE,CAAC;IAElD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/html.tsx
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CrossIframeDevTools } from './dev-tools';
|
|
3
|
+
import { MountPoint, fillMountPoint } from './mount-point';
|
|
4
|
+
import { popAssets, StoredAssets } from './stored-assets';
|
|
5
|
+
import { SsrStyles, removeSsrStyles } from './ssr-styles';
|
|
6
|
+
import { FullHeightStyle } from './full-height-style';
|
|
7
|
+
|
|
8
|
+
export const LOAD_EVENT = '_DOM_LOADED_';
|
|
9
|
+
export const ERROR_EVENT = '_ERROR_OCCURRED_';
|
|
10
|
+
|
|
11
|
+
export type Assets = Partial<{
|
|
12
|
+
/** page title */
|
|
13
|
+
title: string;
|
|
14
|
+
/** js files to load */
|
|
15
|
+
js: string[];
|
|
16
|
+
/** css files to load */
|
|
17
|
+
css: string[];
|
|
18
|
+
/** raw css styles */
|
|
19
|
+
style: string[];
|
|
20
|
+
/** raw data to be stored in the dom. Use Html.popAssets to retrieve it from the dom */
|
|
21
|
+
json: Record<string, string>;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
export interface HtmlProps extends React.HtmlHTMLAttributes<HTMLHtmlElement> {
|
|
25
|
+
withDevTools?: boolean;
|
|
26
|
+
fullHeight?: boolean;
|
|
27
|
+
assets?: Assets;
|
|
28
|
+
ssr?: boolean;
|
|
29
|
+
notifyParentOnLoad?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const NotifyParentScript = () => (
|
|
33
|
+
<script
|
|
34
|
+
dangerouslySetInnerHTML={{
|
|
35
|
+
__html: `
|
|
36
|
+
// only send loaded event when mounted in an iframe
|
|
37
|
+
if (window.parent && window !== window.parent) {
|
|
38
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
39
|
+
window.parent.postMessage({ event: '${LOAD_EVENT}' }, '*');
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
`,
|
|
43
|
+
}}
|
|
44
|
+
></script>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
/** html template for the main UI, when ssr is active */
|
|
48
|
+
export function Html({
|
|
49
|
+
assets = {},
|
|
50
|
+
withDevTools = false,
|
|
51
|
+
fullHeight,
|
|
52
|
+
ssr,
|
|
53
|
+
children = <MountPoint />,
|
|
54
|
+
notifyParentOnLoad = true,
|
|
55
|
+
...rest
|
|
56
|
+
}: HtmlProps) {
|
|
57
|
+
return (
|
|
58
|
+
<html lang="en" {...rest}>
|
|
59
|
+
<head>
|
|
60
|
+
<title>{assets.title || 'bit scope'}</title>
|
|
61
|
+
<meta charSet="utf-8" />
|
|
62
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
63
|
+
|
|
64
|
+
{ssr && <SsrStyles />}
|
|
65
|
+
{fullHeight && <FullHeightStyle />}
|
|
66
|
+
{withDevTools && <CrossIframeDevTools />}
|
|
67
|
+
|
|
68
|
+
{assets.style?.map((x, idx) => <style key={idx}>{x}</style>)}
|
|
69
|
+
{assets.css?.map((x, idx) => <link key={idx} href={x} rel="stylesheet" type="text/css" />)}
|
|
70
|
+
{notifyParentOnLoad && <NotifyParentScript />}
|
|
71
|
+
</head>
|
|
72
|
+
<body>
|
|
73
|
+
{children}
|
|
74
|
+
{assets.json && <StoredAssets data={assets.json} />}
|
|
75
|
+
{/* load scripts after showing the the whole html */}
|
|
76
|
+
{assets.js?.map((x, idx) => <script key={idx} src={x} />)}
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Html.fillContent = fillMountPoint;
|
|
83
|
+
Html.popAssets = popAssets;
|
|
84
|
+
|
|
85
|
+
export function ssrCleanup() {
|
|
86
|
+
removeSsrStyles();
|
|
87
|
+
}
|
package/index.ts
ADDED
package/mount-point.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
export const mountPointId = 'root';
|
|
5
|
+
const placeholderRegex = /<div id="root"><\/div>/;
|
|
6
|
+
|
|
7
|
+
export function MountPoint({ children }: { children?: ReactNode }) {
|
|
8
|
+
return <div id={mountPointId}>{children}</div>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function fillMountPoint(htmlTemplate: string, content: string) {
|
|
12
|
+
const filled = htmlTemplate.replace(placeholderRegex, content);
|
|
13
|
+
return filled;
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/ui-foundation.ui.rendering.html",
|
|
3
|
+
"version": "0.0.0-38e5412ae35cabe897bc87f558e8995d70a34d52",
|
|
4
|
+
"homepage": "https://bit.cloud/teambit/ui-foundation/ui/rendering/html",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"componentId": {
|
|
7
|
+
"scope": "teambit.ui-foundation",
|
|
8
|
+
"name": "ui/rendering/html",
|
|
9
|
+
"version": "38e5412ae35cabe897bc87f558e8995d70a34d52"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"core-js": "^3.0.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/react": "^17.0.8",
|
|
16
|
+
"@types/mocha": "9.1.0",
|
|
17
|
+
"@types/node": "12.20.4",
|
|
18
|
+
"@types/react-dom": "^17.0.5",
|
|
19
|
+
"@types/jest": "^26.0.0",
|
|
20
|
+
"@babel/runtime": "7.20.0",
|
|
21
|
+
"@types/testing-library__jest-dom": "5.9.5"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^16.8.0 || ^17.0.0",
|
|
25
|
+
"react-dom": "^16.8.0 || ^17.0.0"
|
|
26
|
+
},
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"optionalDependencies": {},
|
|
29
|
+
"peerDependenciesMeta": {},
|
|
30
|
+
"private": false,
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=12.22.0"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/teambit/bit"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"bit",
|
|
40
|
+
"components",
|
|
41
|
+
"collaboration",
|
|
42
|
+
"web",
|
|
43
|
+
"react",
|
|
44
|
+
"react-components",
|
|
45
|
+
"angular",
|
|
46
|
+
"angular-components"
|
|
47
|
+
]
|
|
48
|
+
}
|
package/ssr-styles.tsx
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export function SsrStyles() {
|
|
4
|
+
return (
|
|
5
|
+
<style id="before-hydrate-styles">
|
|
6
|
+
.--ssr-hidden {'{'}
|
|
7
|
+
display: none;
|
|
8
|
+
{'}'}
|
|
9
|
+
</style>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function removeSsrStyles() {
|
|
14
|
+
document.getElementById('before-hydrate-styles')?.remove();
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export function StoredAssets({ data }: { data: Record<string, string> }) {
|
|
4
|
+
return (
|
|
5
|
+
<div className="state" style={{ display: 'none' }}>
|
|
6
|
+
{Object.entries(data).map(([key, content]) => (
|
|
7
|
+
// TODO - we falsely assume content is html safe
|
|
8
|
+
<script key={key} data-aspect={key} type="application/json" dangerouslySetInnerHTML={{ __html: content }} />
|
|
9
|
+
))}
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** read and remove stored data from the dom */
|
|
15
|
+
export function popAssets() {
|
|
16
|
+
const rawAssets = new Map<string, string>();
|
|
17
|
+
|
|
18
|
+
const inDom = Array.from(document.querySelectorAll('body > .state > *'));
|
|
19
|
+
|
|
20
|
+
inDom.forEach((elem) => {
|
|
21
|
+
const aspectName = elem.getAttribute('data-aspect');
|
|
22
|
+
if (!aspectName) return;
|
|
23
|
+
|
|
24
|
+
rawAssets.set(aspectName, elem.innerHTML);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
document.querySelector('body > .state')?.remove();
|
|
28
|
+
|
|
29
|
+
return rawAssets;
|
|
30
|
+
}
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|