@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.
@@ -1,217 +1,190 @@
1
- import React, { Suspense, useState, useEffect, useMemo } from "react";
2
- import * as LR from "@uploadcare/blocks";
3
- import { UploadCtxProvider, defineLocale } from "@uploadcare/blocks";
4
- const P = /* @__PURE__ */ new Set([
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
- ]), w = (e = {}) => Object == null ? void 0 : Object.keys(e).reduce((r, s) => {
10
- var t, c;
11
- const o = e == null ? void 0 : e[s], n = `on${(c = (t = o == null ? void 0 : o.split("-")) == null ? void 0 : t.map((i) => i.charAt(0).toUpperCase() + i.slice(1))) == null ? void 0 : c.join("")}`;
12
- return r[n] = o, r;
13
- }, {}), m = /* @__PURE__ */ new WeakMap(), g = (e) => {
14
- let r = m.get(e);
15
- return r === void 0 && (r = /* @__PURE__ */ new Map(), m.set(e, r)), r;
16
- }, E = ({
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: r,
19
- valueProp: s,
20
- prevValueProp: o,
18
+ nameProp: t,
19
+ valueProp: o,
20
+ prevValueProp: s,
21
21
  event: n
22
22
  }) => {
23
23
  if (n !== void 0) {
24
- if (s !== o) {
25
- const t = g(e), c = t.has(n);
26
- let i = t.get(n);
27
- s !== void 0 ? c ? i.handleEvent = s : (i = { handleEvent: s }, t.set(n, i), e.addEventListener(
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
- (a) => i.handleEvent(a.detail)
30
- )) : c && (t.delete(n), e.removeEventListener(n, i));
29
+ (d) => c.handleEvent(d.detail)
30
+ )) : l && (r.delete(n), e.removeEventListener(n, c));
31
31
  }
32
32
  return;
33
33
  }
34
- e[r] = s, s == null && r in HTMLElement.prototype && e.removeAttribute(r);
35
- }, M = (e, r, s) => {
36
- const o = {}, n = {};
37
- return Object.entries(e).forEach(([t, c]) => {
38
- P.has(t) ? o[t === "className" ? "class" : t] = c : r.has(t) || t in s.prototype ? n[t] = c : o[t] = c;
39
- }), { reactProps: o, customElProps: n };
40
- }, b = ({
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: r,
44
- elClass: s,
45
- schemaEvents: o
43
+ tag: t,
44
+ elClass: o,
45
+ schemaEvents: s
46
46
  }) => {
47
- const n = w(o), t = new Set(Object.keys(n ?? {})), c = e.forwardRef(
48
- (i, a) => {
49
- const f = e.useRef(/* @__PURE__ */ new Map()), p = e.useRef(null), { reactProps: h, customElProps: d } = M(i, t, s);
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 (p.current === null)
51
+ if (E.current === null)
52
52
  return;
53
- const u = /* @__PURE__ */ new Map();
54
- for (const l in d)
55
- E({
56
- node: p.current,
57
- nameProp: l,
58
- valueProp: d[l],
59
- prevValueProp: f.current.get(l),
60
- event: n[l]
61
- }), f.current.delete(l), u.set(l, i[l]);
62
- for (const [l, v] of f.current)
63
- E({
64
- node: p.current,
65
- nameProp: l,
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: v,
68
- event: n[l]
67
+ prevValueProp: F,
68
+ event: n[p]
69
69
  });
70
- f.current = u;
71
- }), e.createElement(r ?? s.__tag, {
72
- ...h,
70
+ u.current = m;
71
+ }), e.createElement(t ?? o.__tag, {
72
+ ...I,
73
73
  ref: e.useCallback(
74
- (u) => {
75
- p.current = u, typeof a == "function" ? a(u) : a !== null && (a.current = u);
74
+ (m) => {
75
+ E.current = m, typeof d == "function" ? d(m) : d !== null && (d.current = m);
76
76
  },
77
- [a]
77
+ [d]
78
78
  )
79
79
  });
80
80
  }
81
81
  );
82
- return c.displayName = s.name, c;
83
- };
84
- const AdapterConfig = b({
85
- react: React,
82
+ return l.displayName = o.name, l;
83
+ }, g = v({
84
+ react: a,
86
85
  tag: "lr-config",
87
- elClass: LR.Config
88
- });
89
- const AdapterUploadCtxProvider = b({
90
- react: React,
86
+ elClass: i.Config
87
+ }), P = v({
88
+ react: a,
91
89
  tag: "lr-upload-ctx-provider",
92
- elClass: LR.UploadCtxProvider,
93
- schemaEvents: LR.UploadCtxProvider.EventType
94
- });
95
- const getCalcPropertyOfProps = (props) => {
96
- const eventHandlers = {};
97
- const config = {};
98
- Object.entries(props).forEach(([key, value]) => {
99
- if (key.startsWith("on")) {
100
- eventHandlers[key] = value;
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
- const version = "0.4.0-alpha.0";
111
- const NAME_EXTENTION = "React-Uploader";
112
- const getUserAgentIntegration = () => {
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: LR.FileUploaderRegular
132
- });
133
- const FileUploaderRegular = ({
134
- ctxName,
135
- className,
136
- classNameUploader,
137
- apiRef,
138
- ...props
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 CTX_NAME = useMemo(() => ctxName ?? LR.UID.generate(), [ctxName]);
141
- const { eventHandlers, config } = useMemo(
142
- () => getCalcPropertyOfProps(props),
143
- [props]
144
- );
145
- const isBrowser = useIsBrowser();
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: apiRef,
150
- "ctx-name": CTX_NAME,
151
- ...eventHandlers
126
+ ref: s,
127
+ "ctx-name": l,
128
+ ...c
152
129
  }
153
- ), /* @__PURE__ */ React.createElement(AdapterFileUploaderRegular, { class: classNameUploader, "ctx-name": CTX_NAME })));
130
+ ), /* @__PURE__ */ a.createElement(_, { class: o, "ctx-name": l })));
154
131
  };
155
- LR.registerBlocks(LR);
156
- const AdapterFileUploaderMinimal = b({
157
- react: React,
132
+ i.registerBlocks(i);
133
+ const H = v({
134
+ react: a,
158
135
  tag: "lr-file-uploader-minimal",
159
- elClass: LR.FileUploaderMinimal
160
- });
161
- const FileUploaderMinimal = ({
162
- ctxName,
163
- className,
164
- classNameUploader,
165
- apiRef,
166
- ...props
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 CTX_NAME = useMemo(() => ctxName ?? LR.UID.generate(), [ctxName]);
169
- const { eventHandlers, config } = useMemo(
170
- () => getCalcPropertyOfProps(props),
171
- [props]
172
- );
173
- const isBrowser = useIsBrowser();
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: apiRef,
178
- "ctx-name": CTX_NAME,
179
- ...eventHandlers
152
+ ref: s,
153
+ "ctx-name": l,
154
+ ...c
180
155
  }
181
- ), /* @__PURE__ */ React.createElement(AdapterFileUploaderMinimal, { class: classNameUploader, "ctx-name": CTX_NAME })));
156
+ ), /* @__PURE__ */ a.createElement(H, { class: o, "ctx-name": l })));
182
157
  };
183
- LR.registerBlocks(LR);
184
- const AdapterFileUploaderInline = b({
185
- react: React,
158
+ i.registerBlocks(i);
159
+ const S = v({
160
+ react: a,
186
161
  tag: "lr-file-uploader-inline",
187
- elClass: LR.FileUploaderMinimal
188
- });
189
- const FileUploaderInline = ({
190
- ctxName,
191
- className,
192
- classNameUploader,
193
- apiRef,
194
- ...props
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 CTX_NAME = useMemo(() => ctxName ?? LR.UID.generate(), [ctxName]);
197
- const { eventHandlers, config } = useMemo(
198
- () => getCalcPropertyOfProps(props),
199
- [props]
200
- );
201
- const isBrowser = useIsBrowser();
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: apiRef,
206
- "ctx-name": CTX_NAME,
207
- ...eventHandlers
178
+ ref: s,
179
+ "ctx-name": l,
180
+ ...c
208
181
  }
209
- ), /* @__PURE__ */ React.createElement(AdapterFileUploaderInline, { class: classNameUploader, "ctx-name": CTX_NAME })));
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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadcare/react-uploader",
3
3
  "description": "React component for file uploads using Uploadcare",
4
- "version": "0.4.0-alpha.0",
4
+ "version": "0.4.0-alpha.2",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "files": [