@veritone-ce/design-system 2.8.1 → 2.8.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.
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+ 'use strict';
3
+
4
+ var uploady = require('./uploady.js');
5
+
6
+
7
+
8
+ exports.UploadyButton = uploady.UploadyButton;
9
+ exports.UploadyDropzone = uploady.UploadyDropzone;
10
+ exports.UploadyList = uploady.UploadyList;
11
+ exports.UploadyListItem = uploady.UploadyListItem;
12
+ exports.useUploadStatus = uploady.useUploadStatus;
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+ 'use client';
3
+ 'use strict';
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var React = require('react');
7
+ var uploady = require('@rpldy/uploady');
8
+ var index = require('../../Button/index.js');
9
+ var controlled = require('../../FileUploader/controlled.js');
10
+
11
+ function UploadyDropzone(props) {
12
+ const { upload, getOptions } = uploady.useUploady();
13
+ const [batchState, setBatchState] = React.useState(
14
+ uploady.BATCH_STATES.PENDING
15
+ );
16
+ uploady.useBatchFinalizeListener((batch) => {
17
+ setBatchState(batch.state);
18
+ });
19
+ uploady.useBatchProgressListener((batch) => {
20
+ setBatchState(batch.state);
21
+ });
22
+ return /* @__PURE__ */ jsxRuntime.jsx(
23
+ controlled.UploadDropzone,
24
+ {
25
+ ...props,
26
+ multiple: !getOptions().autoUpload,
27
+ state: batchState === uploady.BATCH_STATES.PROCESSING ? controlled.FILE_STATES.UPLOADING : batchState,
28
+ onDrop: (files) => {
29
+ upload(files);
30
+ setBatchState(uploady.BATCH_STATES.PENDING);
31
+ }
32
+ }
33
+ );
34
+ }
35
+ function UploadyList(props) {
36
+ const [items, setItems] = React.useState([]);
37
+ uploady.useBatchAddListener((batch) => {
38
+ setItems((items2) => items2.concat(batch.items));
39
+ });
40
+ return /* @__PURE__ */ jsxRuntime.jsx(controlled.UploadListContainer, { ...props, children: items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(UploadyListItem, { item }, index)) });
41
+ }
42
+ function UploadyListItem({ item }) {
43
+ const [itemState, setState] = React.useState(item.state);
44
+ const [progress, setProgress] = React.useState(0);
45
+ const abortItem = uploady.useAbortItem();
46
+ uploady.useItemFinalizeListener((item2) => {
47
+ setState(item2.state);
48
+ }, item.id);
49
+ uploady.useItemProgressListener((item2) => {
50
+ setProgress(item2.completed);
51
+ });
52
+ const onAbortItem = () => {
53
+ abortItem(item.id);
54
+ };
55
+ return /* @__PURE__ */ jsxRuntime.jsx(
56
+ controlled.UploadListItem,
57
+ {
58
+ item: {
59
+ file: item.file,
60
+ progress,
61
+ state: itemState
62
+ },
63
+ onAbort: onAbortItem
64
+ }
65
+ );
66
+ }
67
+ function useUploadStatus() {
68
+ const [batchState, setBatchState] = React.useState(
69
+ uploady.BATCH_STATES.PENDING
70
+ );
71
+ const [itemCount, setItemCount] = React.useState(0);
72
+ uploady.useBatchAddListener((batch) => {
73
+ setItemCount(batch.total);
74
+ });
75
+ const [loading, setLoading] = React.useState(false);
76
+ uploady.useBatchStartListener(() => {
77
+ setLoading(true);
78
+ });
79
+ uploady.useBatchFinalizeListener((batch) => {
80
+ setLoading(false);
81
+ setBatchState(batch.state);
82
+ });
83
+ return { loading, itemCount, batchState };
84
+ }
85
+ const UploadyButton = React.forwardRef(function UploadButton({ children, onClick, disabled, ...props }, ref) {
86
+ const { processPending } = uploady.useUploadyContext();
87
+ const { itemCount, batchState, loading } = useUploadStatus();
88
+ const onButtonClick = React.useCallback(
89
+ (e) => {
90
+ processPending();
91
+ onClick?.(e);
92
+ },
93
+ [processPending, onClick]
94
+ );
95
+ return /* @__PURE__ */ jsxRuntime.jsx(
96
+ index.default,
97
+ {
98
+ ref,
99
+ onClick: onButtonClick,
100
+ disabled: disabled || itemCount === 0 || batchState === uploady.BATCH_STATES.FINISHED,
101
+ loading,
102
+ ...props,
103
+ children: children || "Upload"
104
+ }
105
+ );
106
+ });
107
+
108
+ exports.UploadyButton = UploadyButton;
109
+ exports.UploadyDropzone = UploadyDropzone;
110
+ exports.UploadyList = UploadyList;
111
+ exports.UploadyListItem = UploadyListItem;
112
+ exports.useUploadStatus = useUploadStatus;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ export { UploadyButton, UploadyDropzone, UploadyList, UploadyListItem, useUploadStatus } from './uploady.js';
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+ 'use client';
3
+ import { jsx } from 'react/jsx-runtime';
4
+ import React__default, { useCallback, useState } from 'react';
5
+ import { useUploadyContext, BATCH_STATES, useBatchAddListener, useBatchStartListener, useBatchFinalizeListener, useUploady, useBatchProgressListener, useAbortItem, useItemFinalizeListener, useItemProgressListener } from '@rpldy/uploady';
6
+ import Button from '../../Button/index.js';
7
+ import { UploadDropzone, FILE_STATES, UploadListContainer, UploadListItem } from '../../FileUploader/controlled.js';
8
+
9
+ function UploadyDropzone(props) {
10
+ const { upload, getOptions } = useUploady();
11
+ const [batchState, setBatchState] = useState(
12
+ BATCH_STATES.PENDING
13
+ );
14
+ useBatchFinalizeListener((batch) => {
15
+ setBatchState(batch.state);
16
+ });
17
+ useBatchProgressListener((batch) => {
18
+ setBatchState(batch.state);
19
+ });
20
+ return /* @__PURE__ */ jsx(
21
+ UploadDropzone,
22
+ {
23
+ ...props,
24
+ multiple: !getOptions().autoUpload,
25
+ state: batchState === BATCH_STATES.PROCESSING ? FILE_STATES.UPLOADING : batchState,
26
+ onDrop: (files) => {
27
+ upload(files);
28
+ setBatchState(BATCH_STATES.PENDING);
29
+ }
30
+ }
31
+ );
32
+ }
33
+ function UploadyList(props) {
34
+ const [items, setItems] = useState([]);
35
+ useBatchAddListener((batch) => {
36
+ setItems((items2) => items2.concat(batch.items));
37
+ });
38
+ return /* @__PURE__ */ jsx(UploadListContainer, { ...props, children: items.map((item, index) => /* @__PURE__ */ jsx(UploadyListItem, { item }, index)) });
39
+ }
40
+ function UploadyListItem({ item }) {
41
+ const [itemState, setState] = useState(item.state);
42
+ const [progress, setProgress] = useState(0);
43
+ const abortItem = useAbortItem();
44
+ useItemFinalizeListener((item2) => {
45
+ setState(item2.state);
46
+ }, item.id);
47
+ useItemProgressListener((item2) => {
48
+ setProgress(item2.completed);
49
+ });
50
+ const onAbortItem = () => {
51
+ abortItem(item.id);
52
+ };
53
+ return /* @__PURE__ */ jsx(
54
+ UploadListItem,
55
+ {
56
+ item: {
57
+ file: item.file,
58
+ progress,
59
+ state: itemState
60
+ },
61
+ onAbort: onAbortItem
62
+ }
63
+ );
64
+ }
65
+ function useUploadStatus() {
66
+ const [batchState, setBatchState] = useState(
67
+ BATCH_STATES.PENDING
68
+ );
69
+ const [itemCount, setItemCount] = useState(0);
70
+ useBatchAddListener((batch) => {
71
+ setItemCount(batch.total);
72
+ });
73
+ const [loading, setLoading] = useState(false);
74
+ useBatchStartListener(() => {
75
+ setLoading(true);
76
+ });
77
+ useBatchFinalizeListener((batch) => {
78
+ setLoading(false);
79
+ setBatchState(batch.state);
80
+ });
81
+ return { loading, itemCount, batchState };
82
+ }
83
+ const UploadyButton = React__default.forwardRef(function UploadButton({ children, onClick, disabled, ...props }, ref) {
84
+ const { processPending } = useUploadyContext();
85
+ const { itemCount, batchState, loading } = useUploadStatus();
86
+ const onButtonClick = useCallback(
87
+ (e) => {
88
+ processPending();
89
+ onClick?.(e);
90
+ },
91
+ [processPending, onClick]
92
+ );
93
+ return /* @__PURE__ */ jsx(
94
+ Button,
95
+ {
96
+ ref,
97
+ onClick: onButtonClick,
98
+ disabled: disabled || itemCount === 0 || batchState === BATCH_STATES.FINISHED,
99
+ loading,
100
+ ...props,
101
+ children: children || "Upload"
102
+ }
103
+ );
104
+ });
105
+
106
+ export { UploadyButton, UploadyDropzone, UploadyList, UploadyListItem, useUploadStatus };
@@ -0,0 +1 @@
1
+ export * from './uploady.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritone-ce/design-system",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "private": false,
5
5
  "description": "Design System for Veritone CE",
6
6
  "keywords": [