@vonaffenfels/slate-editor 1.0.65 → 1.0.67

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.
@@ -45,15 +45,24 @@ module.exports = async function componentLoader() {
45
45
  console.log(`Disabled SSR for ${component.file}`);
46
46
  }
47
47
 
48
- return `COMPONENT_REGISTRY["${component.namePath.toLowerCase()}"] = dynamic(() => import("${component.file}").then(v => {
49
- return v?.["${component.exportName}"] || v?.["${component.name}"] || v.default;
50
- })${allowSSR ? ",{ssr: true}" : ""});`;
48
+ return `COMPONENT_REGISTRY["${component.namePath.toLowerCase()}"] = dynamic(() => import("${component.file}").then(v => makeExport(v, ["${component.exportName}", "${component.name}"]))${!allowSSR ? ",{ssr: false}" : ""});`;
51
49
  });
52
50
 
53
51
  const fileContent = `
54
52
  import dynamic from 'next/dynamic';
55
53
 
56
54
  const COMPONENT_REGISTRY = {};
55
+ const MissingComponent = () => null;
56
+ const makeExport = (component, names) => {
57
+ const ElementComponent = [...names, "default"].reduce((acc, name) => acc || component[name], null);
58
+
59
+ if(!ElementComponent) {
60
+ console.error(\`Missing export for \${names.join(" / ")}\`);
61
+ return MissingComponent;
62
+ }
63
+
64
+ return ElementComponent;
65
+ }
57
66
 
58
67
  ${componentImports.join("\n")}
59
68
 
@@ -62,14 +71,14 @@ module.exports = async function componentLoader() {
62
71
 
63
72
  if(!COMPONENT_REGISTRY[localBlock]) {
64
73
  console.warn(\`No Component found for \${block}\`);
65
- return null;
74
+ return MissingComponent;
66
75
  }
67
76
 
68
77
  return COMPONENT_REGISTRY[localBlock];
69
78
  }
70
79
  `;
71
80
 
72
- //writeFileSync("./componentLoader.static.DEBUG.js", fileContent);
81
+ writeFileSync("./componentLoader.static.DEBUG.js", fileContent);
73
82
 
74
83
  return fileContent;
75
84
  };