@simple-builder/react 1.0.3 → 1.0.4

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.
@@ -1,74 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
-
5
- function _interopNamespace(e) {
6
- if (e && e.__esModule) return e;
7
- var n = Object.create(null);
8
- if (e) {
9
- Object.keys(e).forEach(function (k) {
10
- if (k !== 'default') {
11
- var d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: function () { return e[k]; }
15
- });
16
- }
17
- });
18
- }
19
- n.default = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
24
-
25
- // src/lib/builder.ts
26
- var builder = /* @__PURE__ */ (() => {
27
- const components = [];
28
- return {
29
- register: (component, config) => {
30
- if (components.find(({ name }) => name === config.name)) {
31
- console.log(
32
- `[simple-builder]: Component ${config.name} already registered.`
33
- );
34
- return;
35
- }
36
- components.push({
37
- component,
38
- ...config
39
- });
40
- },
41
- getComponents: () => components,
42
- getComponent: (name) => {
43
- return components.find((c) => c.name === name);
44
- },
45
- bindComponent: ({ content, ...block }, edit) => {
46
- const component = components.find(({ name }) => name === block.component);
47
- if (!component) {
48
- throw new Error(
49
- `[simple-builder]: Component ${block.component} not found`
50
- );
51
- }
52
- const Element = React.createElement(component.component, {
53
- key: block.id,
54
- builder: { id: block.id, content, edit },
55
- ...block.props
56
- });
57
- return Element;
58
- }
59
- };
60
- })();
61
- var BuildContainerInner = React__namespace.lazy(
62
- () => import('./build-container-client-MHVIH442.js')
63
- );
64
- var BuildContainer = (props) => {
65
- const { content, edit, name } = props;
66
- const items = Array.isArray(content) ? content : content?.[name] || [];
67
- if (!edit) {
68
- return items.map((item) => builder.bindComponent(item));
69
- }
70
- return /* @__PURE__ */ React__namespace.createElement(React__namespace.Suspense, { fallback: /* @__PURE__ */ React__namespace.createElement("div", null, "Loading...") }, /* @__PURE__ */ React__namespace.createElement(BuildContainerInner, { ...props }));
71
- };
72
-
73
- exports.BuildContainer = BuildContainer;
74
- exports.builder = builder;