@uploadcare/react-uploader 0.4.0-alpha.0 → 0.4.0-alpha.1
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/dist/libs.css +1 -0
- package/dist/react-uploader.cjs +1 -239
- package/dist/react-uploader.js +141 -171
- package/package.json +1 -1
- package/dist/style.css +0 -3
package/dist/react-uploader.js
CHANGED
|
@@ -1,217 +1,187 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import { UploadCtxProvider, defineLocale } from "@uploadcare/blocks";
|
|
4
|
-
const
|
|
1
|
+
import l, { Suspense as F, useState as y, useEffect as B, useMemo as m } from "react";
|
|
2
|
+
import * as i from "@uploadcare/blocks";
|
|
3
|
+
import { UploadCtxProvider as q, defineLocale as z } from "@uploadcare/blocks";
|
|
4
|
+
const L = /* @__PURE__ */ new Set([
|
|
5
5
|
"children",
|
|
6
6
|
"ref",
|
|
7
7
|
"style",
|
|
8
8
|
"className"
|
|
9
|
-
]),
|
|
10
|
-
var
|
|
11
|
-
const
|
|
12
|
-
return
|
|
13
|
-
}, {}),
|
|
14
|
-
let
|
|
15
|
-
return
|
|
16
|
-
},
|
|
9
|
+
]), R = (e = {}) => Object == null ? void 0 : Object.keys(e).reduce((n, a) => {
|
|
10
|
+
var o, r;
|
|
11
|
+
const t = e == null ? void 0 : e[a], c = `on${(r = (o = t == null ? void 0 : t.split("-")) == null ? void 0 : o.map((s) => s.charAt(0).toUpperCase() + s.slice(1))) == null ? void 0 : r.join("")}`;
|
|
12
|
+
return n[c] = t, n;
|
|
13
|
+
}, {}), M = /* @__PURE__ */ new WeakMap(), k = (e) => {
|
|
14
|
+
let n = M.get(e);
|
|
15
|
+
return n === void 0 && (n = /* @__PURE__ */ new Map(), M.set(e, n)), n;
|
|
16
|
+
}, x = ({
|
|
17
17
|
node: e,
|
|
18
|
-
nameProp:
|
|
19
|
-
valueProp:
|
|
18
|
+
nameProp: n,
|
|
19
|
+
valueProp: a,
|
|
20
20
|
prevValueProp: o,
|
|
21
|
-
event:
|
|
21
|
+
event: r
|
|
22
22
|
}) => {
|
|
23
|
-
if (
|
|
24
|
-
if (
|
|
25
|
-
const t =
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(
|
|
30
|
-
)) : c && (t.delete(
|
|
23
|
+
if (r !== void 0) {
|
|
24
|
+
if (a !== o) {
|
|
25
|
+
const t = k(e), c = t.has(r);
|
|
26
|
+
let s = t.get(r);
|
|
27
|
+
a !== void 0 ? c ? s.handleEvent = a : (s = { handleEvent: a }, t.set(r, s), e.addEventListener(
|
|
28
|
+
r,
|
|
29
|
+
(d) => s.handleEvent(d.detail)
|
|
30
|
+
)) : c && (t.delete(r), e.removeEventListener(r, s));
|
|
31
31
|
}
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
e[
|
|
35
|
-
},
|
|
36
|
-
const o = {},
|
|
34
|
+
e[n] = a, a == null && n in HTMLElement.prototype && e.removeAttribute(n);
|
|
35
|
+
}, O = (e, n, a) => {
|
|
36
|
+
const o = {}, r = {};
|
|
37
37
|
return Object.entries(e).forEach(([t, c]) => {
|
|
38
|
-
|
|
39
|
-
}), { reactProps: o, customElProps:
|
|
40
|
-
},
|
|
38
|
+
L.has(t) ? o[t === "className" ? "class" : t] = c : n.has(t) || t in a.prototype ? r[t] = c : o[t] = c;
|
|
39
|
+
}), { reactProps: o, customElProps: r };
|
|
40
|
+
}, f = ({
|
|
41
41
|
react: e,
|
|
42
42
|
// https://react.dev/warnings/invalid-hook-call-warning
|
|
43
|
-
tag:
|
|
44
|
-
elClass:
|
|
43
|
+
tag: n,
|
|
44
|
+
elClass: a,
|
|
45
45
|
schemaEvents: o
|
|
46
46
|
}) => {
|
|
47
|
-
const
|
|
48
|
-
(
|
|
49
|
-
const
|
|
47
|
+
const r = R(o), t = new Set(Object.keys(r ?? {})), c = e.forwardRef(
|
|
48
|
+
(s, d) => {
|
|
49
|
+
const E = e.useRef(/* @__PURE__ */ new Map()), g = e.useRef(null), { reactProps: I, customElProps: A } = O(s, t, a);
|
|
50
50
|
return e.useLayoutEffect(() => {
|
|
51
|
-
if (
|
|
51
|
+
if (g.current === null)
|
|
52
52
|
return;
|
|
53
|
-
const
|
|
54
|
-
for (const
|
|
55
|
-
|
|
56
|
-
node:
|
|
57
|
-
nameProp:
|
|
58
|
-
valueProp:
|
|
59
|
-
prevValueProp:
|
|
60
|
-
event:
|
|
61
|
-
}),
|
|
62
|
-
for (const [
|
|
63
|
-
|
|
64
|
-
node:
|
|
65
|
-
nameProp:
|
|
53
|
+
const p = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const u in A)
|
|
55
|
+
x({
|
|
56
|
+
node: g.current,
|
|
57
|
+
nameProp: u,
|
|
58
|
+
valueProp: A[u],
|
|
59
|
+
prevValueProp: E.current.get(u),
|
|
60
|
+
event: r[u]
|
|
61
|
+
}), E.current.delete(u), p.set(u, s[u]);
|
|
62
|
+
for (const [u, b] of E.current)
|
|
63
|
+
x({
|
|
64
|
+
node: g.current,
|
|
65
|
+
nameProp: u,
|
|
66
66
|
valueProp: void 0,
|
|
67
|
-
prevValueProp:
|
|
68
|
-
event:
|
|
67
|
+
prevValueProp: b,
|
|
68
|
+
event: r[u]
|
|
69
69
|
});
|
|
70
|
-
|
|
71
|
-
}), e.createElement(
|
|
72
|
-
...
|
|
70
|
+
E.current = p;
|
|
71
|
+
}), e.createElement(n ?? a.__tag, {
|
|
72
|
+
...I,
|
|
73
73
|
ref: e.useCallback(
|
|
74
|
-
(
|
|
75
|
-
|
|
74
|
+
(p) => {
|
|
75
|
+
g.current = p, typeof d == "function" ? d(p) : d !== null && (d.current = p);
|
|
76
76
|
},
|
|
77
|
-
[
|
|
77
|
+
[d]
|
|
78
78
|
)
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
);
|
|
82
|
-
return c.displayName =
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
react: React,
|
|
82
|
+
return c.displayName = a.name, c;
|
|
83
|
+
}, v = f({
|
|
84
|
+
react: l,
|
|
86
85
|
tag: "lr-config",
|
|
87
|
-
elClass:
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
react: React,
|
|
86
|
+
elClass: i.Config
|
|
87
|
+
}), P = f({
|
|
88
|
+
react: l,
|
|
91
89
|
tag: "lr-upload-ctx-provider",
|
|
92
|
-
elClass:
|
|
93
|
-
schemaEvents:
|
|
94
|
-
})
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
} else {
|
|
102
|
-
config[key] = value;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return {
|
|
106
|
-
eventHandlers,
|
|
107
|
-
config
|
|
90
|
+
elClass: i.UploadCtxProvider,
|
|
91
|
+
schemaEvents: i.UploadCtxProvider.EventType
|
|
92
|
+
}), C = (e) => {
|
|
93
|
+
const n = {}, a = {};
|
|
94
|
+
return Object.entries(e).forEach(([o, r]) => {
|
|
95
|
+
o.startsWith("on") ? n[o] = r : a[o] = r;
|
|
96
|
+
}), {
|
|
97
|
+
eventHandlers: n,
|
|
98
|
+
config: a
|
|
108
99
|
};
|
|
100
|
+
}, T = "0.4.0-alpha.1", j = "React-Uploader", U = () => `${j}/${T}`, h = ({ condition: e, fallback: n, children: a, ...o }) => e ? /* @__PURE__ */ l.createElement(F, { fallback: n, ...o }, a) : /* @__PURE__ */ l.createElement(l.Fragment, null, n), w = () => {
|
|
101
|
+
const [e, n] = y(!1);
|
|
102
|
+
return B(() => {
|
|
103
|
+
typeof window < "u" && n(!0);
|
|
104
|
+
}, []), e;
|
|
109
105
|
};
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
return `${NAME_EXTENTION}/${version}`;
|
|
114
|
-
};
|
|
115
|
-
const ConditionalSuspense = ({ condition, fallback, children, ...rest }) => {
|
|
116
|
-
return condition ? /* @__PURE__ */ React.createElement(Suspense, { fallback, ...rest }, children) : /* @__PURE__ */ React.createElement(React.Fragment, null, fallback);
|
|
117
|
-
};
|
|
118
|
-
const useIsBrowser = () => {
|
|
119
|
-
const [isBrowser, setIsBrowser] = useState(false);
|
|
120
|
-
useEffect(() => {
|
|
121
|
-
if (typeof window !== "undefined") {
|
|
122
|
-
setIsBrowser(true);
|
|
123
|
-
}
|
|
124
|
-
}, []);
|
|
125
|
-
return isBrowser;
|
|
126
|
-
};
|
|
127
|
-
LR.registerBlocks(LR);
|
|
128
|
-
const AdapterFileUploaderRegular = b({
|
|
129
|
-
react: React,
|
|
106
|
+
i.registerBlocks(i);
|
|
107
|
+
const N = f({
|
|
108
|
+
react: l,
|
|
130
109
|
tag: "lr-file-uploader-regular",
|
|
131
|
-
elClass:
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
...props
|
|
110
|
+
elClass: i.FileUploaderRegular
|
|
111
|
+
}), X = ({
|
|
112
|
+
ctxName: e,
|
|
113
|
+
className: n,
|
|
114
|
+
classNameUploader: a,
|
|
115
|
+
apiRef: o,
|
|
116
|
+
...r
|
|
139
117
|
}) => {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
return /* @__PURE__ */ React.createElement(ConditionalSuspense, { condition: isBrowser, fallback: /* @__PURE__ */ React.createElement("h1", null, "Loading ...") }, /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(AdapterConfig, { userAgentIntegration: getUserAgentIntegration(), "ctx-name": CTX_NAME, ...config }), /* @__PURE__ */ React.createElement(
|
|
147
|
-
AdapterUploadCtxProvider,
|
|
118
|
+
const t = m(() => e ?? i.UID.generate(), [e]), { eventHandlers: c, config: s } = m(
|
|
119
|
+
() => C(r),
|
|
120
|
+
[r]
|
|
121
|
+
), d = w();
|
|
122
|
+
return /* @__PURE__ */ l.createElement(h, { condition: d, fallback: /* @__PURE__ */ l.createElement("h1", null, "Loading ...") }, /* @__PURE__ */ l.createElement("div", { className: n }, /* @__PURE__ */ l.createElement(v, { userAgentIntegration: U(), "ctx-name": t, ...s }), /* @__PURE__ */ l.createElement(
|
|
123
|
+
P,
|
|
148
124
|
{
|
|
149
|
-
ref:
|
|
150
|
-
"ctx-name":
|
|
151
|
-
...
|
|
125
|
+
ref: o,
|
|
126
|
+
"ctx-name": t,
|
|
127
|
+
...c
|
|
152
128
|
}
|
|
153
|
-
), /* @__PURE__ */
|
|
129
|
+
), /* @__PURE__ */ l.createElement(N, { class: a, "ctx-name": t })));
|
|
154
130
|
};
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
react:
|
|
131
|
+
i.registerBlocks(i);
|
|
132
|
+
const _ = f({
|
|
133
|
+
react: l,
|
|
158
134
|
tag: "lr-file-uploader-minimal",
|
|
159
|
-
elClass:
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
...props
|
|
135
|
+
elClass: i.FileUploaderMinimal
|
|
136
|
+
}), D = ({
|
|
137
|
+
ctxName: e,
|
|
138
|
+
className: n,
|
|
139
|
+
classNameUploader: a,
|
|
140
|
+
apiRef: o,
|
|
141
|
+
...r
|
|
167
142
|
}) => {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
return /* @__PURE__ */ React.createElement(ConditionalSuspense, { condition: isBrowser, fallback: /* @__PURE__ */ React.createElement("h1", null, "Loading ...") }, /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(AdapterConfig, { userAgentIntegration: getUserAgentIntegration(), "ctx-name": CTX_NAME, ...config }), /* @__PURE__ */ React.createElement(
|
|
175
|
-
AdapterUploadCtxProvider,
|
|
143
|
+
const t = m(() => e ?? i.UID.generate(), [e]), { eventHandlers: c, config: s } = m(
|
|
144
|
+
() => C(r),
|
|
145
|
+
[r]
|
|
146
|
+
), d = w();
|
|
147
|
+
return /* @__PURE__ */ l.createElement(h, { condition: d, fallback: /* @__PURE__ */ l.createElement("h1", null, "Loading ...") }, /* @__PURE__ */ l.createElement("div", { className: n }, /* @__PURE__ */ l.createElement(v, { userAgentIntegration: U(), "ctx-name": t, ...s }), /* @__PURE__ */ l.createElement(
|
|
148
|
+
P,
|
|
176
149
|
{
|
|
177
|
-
ref:
|
|
178
|
-
"ctx-name":
|
|
179
|
-
...
|
|
150
|
+
ref: o,
|
|
151
|
+
"ctx-name": t,
|
|
152
|
+
...c
|
|
180
153
|
}
|
|
181
|
-
), /* @__PURE__ */
|
|
154
|
+
), /* @__PURE__ */ l.createElement(_, { class: a, "ctx-name": t })));
|
|
182
155
|
};
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
react:
|
|
156
|
+
i.registerBlocks(i);
|
|
157
|
+
const H = f({
|
|
158
|
+
react: l,
|
|
186
159
|
tag: "lr-file-uploader-inline",
|
|
187
|
-
elClass:
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
...props
|
|
160
|
+
elClass: i.FileUploaderMinimal
|
|
161
|
+
}), V = ({
|
|
162
|
+
ctxName: e,
|
|
163
|
+
className: n,
|
|
164
|
+
classNameUploader: a,
|
|
165
|
+
apiRef: o,
|
|
166
|
+
...r
|
|
195
167
|
}) => {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
return /* @__PURE__ */ React.createElement(ConditionalSuspense, { condition: isBrowser, fallback: /* @__PURE__ */ React.createElement("h1", null, "Loading ...") }, /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(AdapterConfig, { userAgentIntegration: getUserAgentIntegration(), "ctx-name": CTX_NAME, ...config }), /* @__PURE__ */ React.createElement(
|
|
203
|
-
AdapterUploadCtxProvider,
|
|
168
|
+
const t = m(() => e ?? i.UID.generate(), [e]), { eventHandlers: c, config: s } = m(
|
|
169
|
+
() => C(r),
|
|
170
|
+
[r]
|
|
171
|
+
), d = w();
|
|
172
|
+
return /* @__PURE__ */ l.createElement(h, { condition: d, fallback: /* @__PURE__ */ l.createElement("h1", null, "Loading ...") }, /* @__PURE__ */ l.createElement("div", { className: n }, /* @__PURE__ */ l.createElement(v, { userAgentIntegration: U(), "ctx-name": t, ...s }), /* @__PURE__ */ l.createElement(
|
|
173
|
+
P,
|
|
204
174
|
{
|
|
205
|
-
ref:
|
|
206
|
-
"ctx-name":
|
|
207
|
-
...
|
|
175
|
+
ref: o,
|
|
176
|
+
"ctx-name": t,
|
|
177
|
+
...c
|
|
208
178
|
}
|
|
209
|
-
), /* @__PURE__ */
|
|
179
|
+
), /* @__PURE__ */ l.createElement(H, { class: a, "ctx-name": t })));
|
|
210
180
|
};
|
|
211
181
|
export {
|
|
212
|
-
FileUploaderInline,
|
|
213
|
-
FileUploaderMinimal,
|
|
214
|
-
FileUploaderRegular,
|
|
215
|
-
UploadCtxProvider,
|
|
216
|
-
defineLocale
|
|
182
|
+
V as FileUploaderInline,
|
|
183
|
+
D as FileUploaderMinimal,
|
|
184
|
+
X as FileUploaderRegular,
|
|
185
|
+
q as UploadCtxProvider,
|
|
186
|
+
z as defineLocale
|
|
217
187
|
};
|