@r2wc/react-to-web-component 1.0.0-alpha.1 → 1.0.0-alpha.3
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 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const c=require("react"),u=require("react-dom"),o=require("@r2wc/core");function s(e,t,n){const r=c.createElement(t,n);return u.render(r,e),{container:e,ReactComponent:t}}function i({container:e,ReactComponent:t},n){const r=c.createElement(t,n);u.render(r,e)}function m({container:e}){u.unmountComponentAtNode(e)}function d(e,t={}){return o(e,t,{mount:s,update:i,unmount:m})}module.exports=d;
|
|
@@ -1,116 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
parse: (t) => parseFloat(t)
|
|
10
|
-
}, T = {
|
|
11
|
-
stringify: (t) => t ? "true" : "false",
|
|
12
|
-
parse: (t) => /^[ty1-9]/i.test(t)
|
|
13
|
-
}, $ = {
|
|
14
|
-
stringify: (t) => t.name,
|
|
15
|
-
parse: (t, e) => {
|
|
16
|
-
const n = (() => {
|
|
17
|
-
if (typeof window < "u" && t in window)
|
|
18
|
-
return window[t];
|
|
19
|
-
if (typeof global < "u" && t in global)
|
|
20
|
-
return global[t];
|
|
21
|
-
})();
|
|
22
|
-
return typeof n == "function" ? n.bind(e) : void 0;
|
|
23
|
-
}
|
|
24
|
-
}, E = {
|
|
25
|
-
stringify: (t) => JSON.stringify(t),
|
|
26
|
-
parse: (t) => JSON.parse(t)
|
|
27
|
-
}, g = {
|
|
28
|
-
string: x,
|
|
29
|
-
number: N,
|
|
30
|
-
boolean: T,
|
|
31
|
-
function: $,
|
|
32
|
-
json: E
|
|
33
|
-
}, w = Symbol.for("r2wc.render"), b = Symbol.for("r2wc.connected"), p = Symbol.for("r2wc.context"), i = Symbol.for("r2wc.props");
|
|
34
|
-
function L(t, e, n) {
|
|
35
|
-
var c, O, S;
|
|
36
|
-
e.props || (e.props = t.propTypes ? Object.keys(t.propTypes) : []);
|
|
37
|
-
const y = (Array.isArray(e.props) ? e.props.slice() : Object.keys(e.props)).filter((r) => r !== "container"), u = {}, d = {}, m = {};
|
|
38
|
-
for (const r of y) {
|
|
39
|
-
u[r] = Array.isArray(e.props) ? "string" : e.props[r];
|
|
40
|
-
const o = P(r);
|
|
41
|
-
d[r] = o, m[o] = r;
|
|
42
|
-
}
|
|
43
|
-
class j extends HTMLElement {
|
|
44
|
-
constructor() {
|
|
45
|
-
super(), l(this, c, !0), l(this, O), l(this, S, {}), l(this, "container"), e.shadow ? this.container = this.attachShadow({
|
|
46
|
-
mode: e.shadow
|
|
47
|
-
}) : this.container = this, this[i].container = this.container;
|
|
48
|
-
for (const o of y) {
|
|
49
|
-
const f = d[o], a = this.getAttribute(f), s = u[o];
|
|
50
|
-
a && (this[i][o] = g[s].parse(a, this));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
static get observedAttributes() {
|
|
54
|
-
return Object.keys(m);
|
|
55
|
-
}
|
|
56
|
-
connectedCallback() {
|
|
57
|
-
this[b] = !0, this[w]();
|
|
58
|
-
}
|
|
59
|
-
disconnectedCallback() {
|
|
60
|
-
this[b] = !1, this[p] && n.unmount(this[p]);
|
|
61
|
-
}
|
|
62
|
-
attributeChangedCallback(o, f, a) {
|
|
63
|
-
const s = m[o], h = u[s];
|
|
64
|
-
s in u && (this[i][s] = g[h].parse(a, this), this[w]());
|
|
65
|
-
}
|
|
66
|
-
[(c = b, O = p, S = i, w)]() {
|
|
67
|
-
this[b] && (this[p] ? n.update(this[p], this[i]) : this[p] = n.mount(
|
|
68
|
-
this.container,
|
|
69
|
-
t,
|
|
70
|
-
this[i]
|
|
71
|
-
));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
for (const r of y) {
|
|
75
|
-
const o = d[r], f = u[r];
|
|
76
|
-
Object.defineProperty(j.prototype, r, {
|
|
77
|
-
enumerable: !0,
|
|
78
|
-
configurable: !0,
|
|
79
|
-
get() {
|
|
80
|
-
return this[i][r];
|
|
81
|
-
},
|
|
82
|
-
set(a) {
|
|
83
|
-
this[i][r] = a;
|
|
84
|
-
const s = g[f].stringify;
|
|
85
|
-
if (s) {
|
|
86
|
-
const h = s(a);
|
|
87
|
-
this.getAttribute(o) !== h && this.setAttribute(o, h);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return j;
|
|
93
|
-
}
|
|
94
|
-
function P(t = "") {
|
|
95
|
-
return t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
96
|
-
}
|
|
97
|
-
function J(t, e, n) {
|
|
98
|
-
const c = k.createElement(e, n);
|
|
99
|
-
return A.render(c, t), {
|
|
100
|
-
container: t,
|
|
101
|
-
ReactComponent: e
|
|
1
|
+
import m from "react";
|
|
2
|
+
import o from "react-dom";
|
|
3
|
+
import u from "@r2wc/core";
|
|
4
|
+
function c(e, t, n) {
|
|
5
|
+
const r = m.createElement(t, n);
|
|
6
|
+
return o.render(r, e), {
|
|
7
|
+
container: e,
|
|
8
|
+
ReactComponent: t
|
|
102
9
|
};
|
|
103
10
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
|
|
11
|
+
function f({ container: e, ReactComponent: t }, n) {
|
|
12
|
+
const r = m.createElement(t, n);
|
|
13
|
+
o.render(r, e);
|
|
107
14
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
15
|
+
function i({ container: e }) {
|
|
16
|
+
o.unmountComponentAtNode(e);
|
|
110
17
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
18
|
+
function p(e, t = {}) {
|
|
19
|
+
return u(e, t, { mount: c, update: f, unmount: i });
|
|
113
20
|
}
|
|
114
21
|
export {
|
|
115
|
-
|
|
22
|
+
p as default
|
|
116
23
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r2wc/react-to-web-component",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "Convert React components to native Web Components.",
|
|
5
5
|
"homepage": "https://www.bitovi.com/frontend-javascript-consulting/react-consulting",
|
|
6
6
|
"author": "Bitovi",
|
|
@@ -45,12 +45,8 @@
|
|
|
45
45
|
"@r2wc/core": "^1.0.0-alpha.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@testing-library/jest-dom": "^5.16.5",
|
|
49
48
|
"@types/react": "^17.0.0",
|
|
50
|
-
"@types/react-dom": "^17.0.0"
|
|
51
|
-
"vite": "^4.3.1",
|
|
52
|
-
"vite-plugin-dts": "^2.3.0",
|
|
53
|
-
"vitest": "^0.30.1"
|
|
49
|
+
"@types/react-dom": "^17.0.0"
|
|
54
50
|
},
|
|
55
51
|
"peerDependencies": {
|
|
56
52
|
"react": "^16.0.0 || ^17.0.0",
|