@uploadcare/react-uploader 0.4.0-alpha.1 → 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/react-uploader.cjs +1 -1
- package/dist/react-uploader.d.ts +8 -1
- package/dist/react-uploader.js +102 -99
- package/package.json +1 -1
package/dist/react-uploader.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),v=require("@uploadcare/blocks");function j(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const i=j(v),F=new Set(["children","ref","style","className"]),I=(e={})=>Object==null?void 0:Object.keys(e).reduce((t,n)=>{var a,l;const o=e==null?void 0:e[n],c=`on${(l=(a=o==null?void 0:o.split("-"))==null?void 0:a.map(s=>s.charAt(0).toUpperCase()+s.slice(1)))==null?void 0:l.join("")}`;return t[c]=o,t},{}),y=new WeakMap,x=e=>{let t=y.get(e);return t===void 0&&(t=new Map,y.set(e,t)),t},h=({node:e,nameProp:t,valueProp:n,prevValueProp:a,event:l})=>{if(l!==void 0){if(n!==a){const o=x(e),c=o.has(l);let s=o.get(l);n!==void 0?c?s.handleEvent=n:(s={handleEvent:n},o.set(l,s),e.addEventListener(l,u=>s.handleEvent(u.detail))):c&&(o.delete(l),e.removeEventListener(l,s))}return}e[t]=n,n==null&&t in HTMLElement.prototype&&e.removeAttribute(t)},R=(e,t,n)=>{const a={},l={};return Object.entries(e).forEach(([o,c])=>{F.has(o)?a[o==="className"?"class":o]=c:t.has(o)||o in n.prototype?l[o]=c:a[o]=c}),{reactProps:a,customElProps:l}},f=({react:e,tag:t,elClass:n,schemaEvents:a})=>{const l=I(a),o=new Set(Object.keys(l??{})),c=e.forwardRef((s,u)=>{const d=e.useRef(new Map),g=e.useRef(null),{reactProps:A,customElProps:w}=R(s,o,n);return e.useLayoutEffect(()=>{if(g.current===null)return;const m=new Map;for(const p in w)h({node:g.current,nameProp:p,valueProp:w[p],prevValueProp:d.current.get(p),event:l[p]}),d.current.delete(p),m.set(p,s[p]);for(const[p,O]of d.current)h({node:g.current,nameProp:p,valueProp:void 0,prevValueProp:O,event:l[p]});d.current=m}),e.createElement(t??n.__tag,{...A,ref:e.useCallback(m=>{g.current=m,typeof u=="function"?u(m):u!==null&&(u.current=m)},[u])})});return c.displayName=n.name,c},E=f({react:r,tag:"lr-config",elClass:i.Config}),P=f({react:r,tag:"lr-upload-ctx-provider",elClass:i.UploadCtxProvider,schemaEvents:i.UploadCtxProvider.EventType}),M=e=>{const t={},n={};return Object.entries(e).forEach(([a,l])=>{a.startsWith("on")?t[a]=l:n[a]=l}),{eventHandlers:t,config:n}},B="0.4.0-alpha.2",S="React-Uploader",U=()=>`${S}/${B}`,C=({condition:e,fallback:t,children:n,...a})=>e?r.createElement(r.Suspense,{fallback:t,...a},n):r.createElement(r.Fragment,null,t),b=()=>{const[e,t]=r.useState(!1);return r.useEffect(()=>{typeof window<"u"&&t(!0)},[]),e};i.registerBlocks(i);const T=f({react:r,tag:"lr-file-uploader-regular",elClass:i.FileUploaderRegular}),_=({ctxName:e,className:t,classNameUploader:n,apiRef:a,fallback:l,...o})=>{const c=r.useMemo(()=>e??i.UID.generate(),[e]),{eventHandlers:s,config:u}=r.useMemo(()=>M(o),[o]),d=b();return r.createElement(C,{condition:d,fallback:l},r.createElement("div",{className:t},r.createElement(E,{userAgentIntegration:U(),"ctx-name":c,...u}),r.createElement(P,{ref:a,"ctx-name":c,...s}),r.createElement(T,{class:n,"ctx-name":c})))};i.registerBlocks(i);const L=f({react:r,tag:"lr-file-uploader-minimal",elClass:i.FileUploaderMinimal}),N=({ctxName:e,className:t,classNameUploader:n,apiRef:a,fallback:l,...o})=>{const c=r.useMemo(()=>e??i.UID.generate(),[e]),{eventHandlers:s,config:u}=r.useMemo(()=>M(o),[o]),d=b();return r.createElement(C,{condition:d,fallback:l},r.createElement("div",{className:t},r.createElement(E,{userAgentIntegration:U(),"ctx-name":c,...u}),r.createElement(P,{ref:a,"ctx-name":c,...s}),r.createElement(L,{class:n,"ctx-name":c})))};i.registerBlocks(i);const k=f({react:r,tag:"lr-file-uploader-inline",elClass:i.FileUploaderMinimal}),D=({ctxName:e,className:t,classNameUploader:n,apiRef:a,fallback:l,...o})=>{const c=r.useMemo(()=>e??i.UID.generate(),[e]),{eventHandlers:s,config:u}=r.useMemo(()=>M(o),[o]),d=b();return r.createElement(C,{condition:d,fallback:l},r.createElement("div",{className:t},r.createElement(E,{userAgentIntegration:U(),"ctx-name":c,...u}),r.createElement(P,{ref:a,"ctx-name":c,...s}),r.createElement(k,{class:n,"ctx-name":c})))};Object.defineProperty(exports,"UploadCtxProvider",{enumerable:!0,get:()=>v.UploadCtxProvider});Object.defineProperty(exports,"defineLocale",{enumerable:!0,get:()=>v.defineLocale});exports.FileUploaderInline=D;exports.FileUploaderMinimal=N;exports.FileUploaderRegular=_;
|
package/dist/react-uploader.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ConfigType } from '@uploadcare/blocks';
|
|
|
2
2
|
import { defineLocale } from '@uploadcare/blocks';
|
|
3
3
|
import type { EventMap } from '@uploadcare/blocks';
|
|
4
4
|
import { FC } from 'react';
|
|
5
|
+
import { default as React_2 } from 'react';
|
|
5
6
|
import type { Ref } from 'react';
|
|
6
7
|
import { UploadCtxProvider } from '@uploadcare/blocks';
|
|
7
8
|
|
|
@@ -17,7 +18,7 @@ declare type TDefaultProps = {
|
|
|
17
18
|
className?: string;
|
|
18
19
|
classNameUploader?: string;
|
|
19
20
|
ctxName?: string;
|
|
20
|
-
}
|
|
21
|
+
} & Pick<TProps_2, "fallback">;
|
|
21
22
|
|
|
22
23
|
export declare type TEventsSchema = {
|
|
23
24
|
[K in keyof EventMap as TPrefixOnAndCamelCase<K>]: (event: EventMap[K]["detail"]) => void;
|
|
@@ -29,6 +30,12 @@ declare type TPrefixOnAndCamelCase<S extends string> = TExtraPrefixOn<TToCamelCa
|
|
|
29
30
|
|
|
30
31
|
export declare type TProps = TDefaultProps & TRefUploadCtxProvider & TPropsWithEvents & TPropsWithConfig;
|
|
31
32
|
|
|
33
|
+
declare type TProps_2 = {
|
|
34
|
+
fallback?: React_2.ReactChild | React_2.ReactFragment | React_2.ReactPortal | null;
|
|
35
|
+
condition: boolean;
|
|
36
|
+
children: React_2.ReactNode;
|
|
37
|
+
};
|
|
38
|
+
|
|
32
39
|
declare type TPropsWithConfig = Partial<ConfigType>;
|
|
33
40
|
|
|
34
41
|
declare type TPropsWithEvents = Partial<TEventsSchema>;
|
package/dist/react-uploader.js
CHANGED
|
@@ -1,182 +1,185 @@
|
|
|
1
|
-
import
|
|
1
|
+
import a, { Suspense as y, useState as B, useEffect as R, useMemo as f } from "react";
|
|
2
2
|
import * as i from "@uploadcare/blocks";
|
|
3
3
|
import { UploadCtxProvider as q, defineLocale as z } from "@uploadcare/blocks";
|
|
4
|
-
const
|
|
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
|
-
}, {}), M = /* @__PURE__ */ new WeakMap(),
|
|
14
|
-
let
|
|
15
|
-
return
|
|
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
16
|
}, x = ({
|
|
17
17
|
node: e,
|
|
18
|
-
nameProp:
|
|
19
|
-
valueProp:
|
|
20
|
-
prevValueProp:
|
|
21
|
-
event:
|
|
18
|
+
nameProp: t,
|
|
19
|
+
valueProp: o,
|
|
20
|
+
prevValueProp: s,
|
|
21
|
+
event: n
|
|
22
22
|
}) => {
|
|
23
|
-
if (
|
|
24
|
-
if (
|
|
25
|
-
const
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(d) =>
|
|
30
|
-
)) :
|
|
23
|
+
if (n !== void 0) {
|
|
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
|
+
n,
|
|
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
|
|
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
|
|
53
|
+
const m = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const p in A)
|
|
55
55
|
x({
|
|
56
|
-
node:
|
|
57
|
-
nameProp:
|
|
58
|
-
valueProp: A[
|
|
59
|
-
prevValueProp:
|
|
60
|
-
event:
|
|
61
|
-
}),
|
|
62
|
-
for (const [
|
|
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
63
|
x({
|
|
64
|
-
node:
|
|
65
|
-
nameProp:
|
|
64
|
+
node: E.current,
|
|
65
|
+
nameProp: p,
|
|
66
66
|
valueProp: void 0,
|
|
67
|
-
prevValueProp:
|
|
68
|
-
event:
|
|
67
|
+
prevValueProp: F,
|
|
68
|
+
event: n[p]
|
|
69
69
|
});
|
|
70
|
-
|
|
71
|
-
}), e.createElement(
|
|
70
|
+
u.current = m;
|
|
71
|
+
}), e.createElement(t ?? o.__tag, {
|
|
72
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
|
-
react:
|
|
82
|
+
return l.displayName = o.name, l;
|
|
83
|
+
}, g = v({
|
|
84
|
+
react: a,
|
|
85
85
|
tag: "lr-config",
|
|
86
86
|
elClass: i.Config
|
|
87
|
-
}), P =
|
|
88
|
-
react:
|
|
87
|
+
}), P = v({
|
|
88
|
+
react: a,
|
|
89
89
|
tag: "lr-upload-ctx-provider",
|
|
90
90
|
elClass: i.UploadCtxProvider,
|
|
91
91
|
schemaEvents: i.UploadCtxProvider.EventType
|
|
92
92
|
}), C = (e) => {
|
|
93
|
-
const
|
|
94
|
-
return Object.entries(e).forEach(([
|
|
95
|
-
|
|
93
|
+
const t = {}, o = {};
|
|
94
|
+
return Object.entries(e).forEach(([s, n]) => {
|
|
95
|
+
s.startsWith("on") ? t[s] = n : o[s] = n;
|
|
96
96
|
}), {
|
|
97
|
-
eventHandlers:
|
|
98
|
-
config:
|
|
97
|
+
eventHandlers: t,
|
|
98
|
+
config: o
|
|
99
99
|
};
|
|
100
|
-
},
|
|
101
|
-
const [e,
|
|
102
|
-
return
|
|
103
|
-
typeof window < "u" &&
|
|
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
104
|
}, []), e;
|
|
105
105
|
};
|
|
106
106
|
i.registerBlocks(i);
|
|
107
|
-
const
|
|
108
|
-
react:
|
|
107
|
+
const _ = v({
|
|
108
|
+
react: a,
|
|
109
109
|
tag: "lr-file-uploader-regular",
|
|
110
110
|
elClass: i.FileUploaderRegular
|
|
111
111
|
}), X = ({
|
|
112
112
|
ctxName: e,
|
|
113
|
-
className:
|
|
114
|
-
classNameUploader:
|
|
115
|
-
apiRef:
|
|
113
|
+
className: t,
|
|
114
|
+
classNameUploader: o,
|
|
115
|
+
apiRef: s,
|
|
116
|
+
fallback: n,
|
|
116
117
|
...r
|
|
117
118
|
}) => {
|
|
118
|
-
const
|
|
119
|
+
const l = f(() => e ?? i.UID.generate(), [e]), { eventHandlers: c, config: d } = f(
|
|
119
120
|
() => C(r),
|
|
120
121
|
[r]
|
|
121
|
-
),
|
|
122
|
-
return /* @__PURE__ */
|
|
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(
|
|
123
124
|
P,
|
|
124
125
|
{
|
|
125
|
-
ref:
|
|
126
|
-
"ctx-name":
|
|
126
|
+
ref: s,
|
|
127
|
+
"ctx-name": l,
|
|
127
128
|
...c
|
|
128
129
|
}
|
|
129
|
-
), /* @__PURE__ */
|
|
130
|
+
), /* @__PURE__ */ a.createElement(_, { class: o, "ctx-name": l })));
|
|
130
131
|
};
|
|
131
132
|
i.registerBlocks(i);
|
|
132
|
-
const
|
|
133
|
-
react:
|
|
133
|
+
const H = v({
|
|
134
|
+
react: a,
|
|
134
135
|
tag: "lr-file-uploader-minimal",
|
|
135
136
|
elClass: i.FileUploaderMinimal
|
|
136
137
|
}), D = ({
|
|
137
138
|
ctxName: e,
|
|
138
|
-
className:
|
|
139
|
-
classNameUploader:
|
|
140
|
-
apiRef:
|
|
139
|
+
className: t,
|
|
140
|
+
classNameUploader: o,
|
|
141
|
+
apiRef: s,
|
|
142
|
+
fallback: n,
|
|
141
143
|
...r
|
|
142
144
|
}) => {
|
|
143
|
-
const
|
|
145
|
+
const l = f(() => e ?? i.UID.generate(), [e]), { eventHandlers: c, config: d } = f(
|
|
144
146
|
() => C(r),
|
|
145
147
|
[r]
|
|
146
|
-
),
|
|
147
|
-
return /* @__PURE__ */
|
|
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(
|
|
148
150
|
P,
|
|
149
151
|
{
|
|
150
|
-
ref:
|
|
151
|
-
"ctx-name":
|
|
152
|
+
ref: s,
|
|
153
|
+
"ctx-name": l,
|
|
152
154
|
...c
|
|
153
155
|
}
|
|
154
|
-
), /* @__PURE__ */
|
|
156
|
+
), /* @__PURE__ */ a.createElement(H, { class: o, "ctx-name": l })));
|
|
155
157
|
};
|
|
156
158
|
i.registerBlocks(i);
|
|
157
|
-
const
|
|
158
|
-
react:
|
|
159
|
+
const S = v({
|
|
160
|
+
react: a,
|
|
159
161
|
tag: "lr-file-uploader-inline",
|
|
160
162
|
elClass: i.FileUploaderMinimal
|
|
161
163
|
}), V = ({
|
|
162
164
|
ctxName: e,
|
|
163
|
-
className:
|
|
164
|
-
classNameUploader:
|
|
165
|
-
apiRef:
|
|
165
|
+
className: t,
|
|
166
|
+
classNameUploader: o,
|
|
167
|
+
apiRef: s,
|
|
168
|
+
fallback: n,
|
|
166
169
|
...r
|
|
167
170
|
}) => {
|
|
168
|
-
const
|
|
171
|
+
const l = f(() => e ?? i.UID.generate(), [e]), { eventHandlers: c, config: d } = f(
|
|
169
172
|
() => C(r),
|
|
170
173
|
[r]
|
|
171
|
-
),
|
|
172
|
-
return /* @__PURE__ */
|
|
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(
|
|
173
176
|
P,
|
|
174
177
|
{
|
|
175
|
-
ref:
|
|
176
|
-
"ctx-name":
|
|
178
|
+
ref: s,
|
|
179
|
+
"ctx-name": l,
|
|
177
180
|
...c
|
|
178
181
|
}
|
|
179
|
-
), /* @__PURE__ */
|
|
182
|
+
), /* @__PURE__ */ a.createElement(S, { class: o, "ctx-name": l })));
|
|
180
183
|
};
|
|
181
184
|
export {
|
|
182
185
|
V as FileUploaderInline,
|