@embeddable.com/sdk-react 2.2.9 → 2.2.11

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