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