@embeddable.com/sdk-react 2.2.8 → 2.2.10
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/lib/index.esm.js +47 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +47 -3
- package/lib/index.js.map +1 -1
- package/lib/utils/EntrypointModifier.d.ts +6 -0
- package/lib/utils/entrypointModifiers.d.ts +2 -0
- package/lib/utils/styledComponentsEntrypointModifier.d.ts +8 -0
- package/package.json +1 -1
- package/templates/embeddable-entry-point.jsx.template +4 -1
package/lib/index.esm.js
CHANGED
|
@@ -613,13 +613,41 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
613
613
|
};
|
|
614
614
|
};
|
|
615
615
|
|
|
616
|
+
/**
|
|
617
|
+
* Modifies entry point only if there is 'styled-components' in the client's package.json.
|
|
618
|
+
* Imports StyleSheetManager from styled-components and adds shadow root as "target".
|
|
619
|
+
* That will force styled-components to add classes to the customers web-component
|
|
620
|
+
* see https://styled-components.com/docs/api#stylesheetmanager
|
|
621
|
+
*/
|
|
622
|
+
const styledComponentsEntrypointModifier = {
|
|
623
|
+
getContentBegin() {
|
|
624
|
+
return "<StyleSheetManager target={rootEl.getRootNode()}>";
|
|
625
|
+
},
|
|
626
|
+
getContentEnd() {
|
|
627
|
+
return "</StyleSheetManager>";
|
|
628
|
+
},
|
|
629
|
+
getImports() {
|
|
630
|
+
return "import {StyleSheetManager} from 'styled-components'";
|
|
631
|
+
},
|
|
632
|
+
needToModify(ctx) {
|
|
633
|
+
var _a;
|
|
634
|
+
const packageJsonFilePath = path.resolve(ctx.client.rootDir, "package.json");
|
|
635
|
+
const packageJson = require(packageJsonFilePath);
|
|
636
|
+
return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
|
|
637
|
+
},
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
const entrypointModifiers = [
|
|
641
|
+
styledComponentsEntrypointModifier,
|
|
642
|
+
];
|
|
643
|
+
|
|
616
644
|
const oraP = import('ora');
|
|
617
645
|
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
618
646
|
var generate = async (ctx) => {
|
|
619
647
|
const ora = (await oraP).default;
|
|
620
648
|
const progress = ora("React: building components...").start();
|
|
621
649
|
const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
622
|
-
await
|
|
650
|
+
await prepareEntrypoint(ctx, filesList);
|
|
623
651
|
await runViteBuild(ctx);
|
|
624
652
|
progress.succeed("React: components built completed");
|
|
625
653
|
};
|
|
@@ -661,7 +689,10 @@ const IMPORT_REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
|
|
|
661
689
|
const ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN = "{{ERROR_FALLBACK_COMPONENT_IMPORT}}";
|
|
662
690
|
const ERROR_FALLBACK_COMPONENT_TOKEN = "{{ERROR_FALLBACK_COMPONENT}}";
|
|
663
691
|
const ERROR_FALLBACK_COMPONENT_DEFAULT_NAME = "ErrorFallbackComponent";
|
|
664
|
-
|
|
692
|
+
const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
|
|
693
|
+
const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
|
|
694
|
+
const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
|
|
695
|
+
async function prepareEntrypoint(ctx, filesList) {
|
|
665
696
|
const imports = filesList
|
|
666
697
|
.map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('./${path.relative(ctx.client.rootDir, filePath)}'))`)
|
|
667
698
|
.join(",\n");
|
|
@@ -671,11 +702,24 @@ async function injectImports(ctx, filesList) {
|
|
|
671
702
|
errorBoundaryImport = `import ${ERROR_FALLBACK_COMPONENT_DEFAULT_NAME} from './${path.relative(ctx.client.rootDir, ctx.client.errorFallbackComponent)}';`;
|
|
672
703
|
errorFallbackComponent = ERROR_FALLBACK_COMPONENT_DEFAULT_NAME;
|
|
673
704
|
}
|
|
705
|
+
const additionalContentImport = [];
|
|
706
|
+
let additionalContentBegin = [];
|
|
707
|
+
let additionalContentEnd = [];
|
|
708
|
+
for (const entrypointModifier of entrypointModifiers) {
|
|
709
|
+
if (entrypointModifier.needToModify(ctx)) {
|
|
710
|
+
additionalContentImport.push(entrypointModifier.getImports(ctx));
|
|
711
|
+
additionalContentBegin.push(entrypointModifier.getContentBegin(ctx));
|
|
712
|
+
additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
|
|
713
|
+
}
|
|
714
|
+
}
|
|
674
715
|
const content = await fs$1.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
675
716
|
await fs$1.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
676
717
|
.replace(IMPORT_REPLACE_TOKEN, imports)
|
|
677
718
|
.replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
|
|
678
|
-
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
|
|
719
|
+
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
|
|
720
|
+
.replace(ADDITIONAL_CONTENT_IMPORT_TOKEN, additionalContentImport.join("\n"))
|
|
721
|
+
.replace(ADDITIONAL_CONTENT_BEGIN_TOKEN, additionalContentBegin.join("\n"))
|
|
722
|
+
.replace(ADDITIONAL_CONTENT_END_TOKEN, additionalContentEnd.join("\n")));
|
|
679
723
|
}
|
|
680
724
|
|
|
681
725
|
var build = async (ctx) => {
|