@superinterface/react 2.16.1 → 2.16.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/index.js CHANGED
@@ -10,6 +10,47 @@ function _array_with_holes(arr) {
10
10
  function _array_without_holes(arr) {
11
11
  if (Array.isArray(arr)) return _array_like_to_array(arr);
12
12
  }
13
+ function _async_iterator(iterable) {
14
+ var method, async, sync, retry = 2;
15
+ for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
16
+ if (async && null != (method = iterable[async])) return method.call(iterable);
17
+ if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
18
+ async = "@@asyncIterator", sync = "@@iterator";
19
+ }
20
+ throw new TypeError("Object is not async iterable");
21
+ }
22
+ function AsyncFromSyncIterator(s) {
23
+ function AsyncFromSyncIteratorContinuation(r) {
24
+ if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
25
+ var done = r.done;
26
+ return Promise.resolve(r.value).then(function(value) {
27
+ return {
28
+ value: value,
29
+ done: done
30
+ };
31
+ });
32
+ }
33
+ return AsyncFromSyncIterator = function(s) {
34
+ this.s = s, this.n = s.next;
35
+ }, AsyncFromSyncIterator.prototype = {
36
+ s: null,
37
+ n: null,
38
+ next: function() {
39
+ return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
40
+ },
41
+ return: function(value) {
42
+ var ret = this.s.return;
43
+ return void 0 === ret ? Promise.resolve({
44
+ value: value,
45
+ done: !0
46
+ }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
47
+ },
48
+ throw: function(value) {
49
+ var thr = this.s.return;
50
+ return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
51
+ }
52
+ }, new AsyncFromSyncIterator(s);
53
+ }
13
54
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
14
55
  try {
15
56
  var info = gen[key](arg);
@@ -263,6 +304,20 @@ function _ts_generator(thisArg, body) {
263
304
  };
264
305
  }
265
306
  }
307
+ function _ts_values(o) {
308
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
309
+ if (m) return m.call(o);
310
+ if (o && typeof o.length === "number") return {
311
+ next: function() {
312
+ if (o && i >= o.length) o = void 0;
313
+ return {
314
+ value: o && o[i++],
315
+ done: !o
316
+ };
317
+ }
318
+ };
319
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
320
+ }
266
321
  var _2;
267
322
  var _detect;
268
323
  import { useRef } from "react";
@@ -2584,6 +2639,7 @@ var Preview = function() {
2584
2639
  };
2585
2640
  // src/components/threads/Thread/MessageForm/Field/Files/Control.tsx
2586
2641
  import { useCallback as useCallback2 } from "react";
2642
+ import { omit as omit4 } from "radash";
2587
2643
  import dayjs2 from "dayjs";
2588
2644
  import { FilePlusIcon } from "@radix-ui/react-icons";
2589
2645
  import { IconButton as IconButton3, Flex as Flex16 } from "@radix-ui/themes";
@@ -2703,50 +2759,174 @@ var Control2 = function() {
2703
2759
  var _useMessageFormContext = useMessageFormContext(), isDisabled = _useMessageFormContext.isDisabled, isLoading = _useMessageFormContext.isLoading, setFiles = _useMessageFormContext.setFiles;
2704
2760
  var createFile = useCreateFile().createFile;
2705
2761
  var addToast = useToasts().addToast;
2706
- var onChange = useCallback2(function(event) {
2707
- var files = event.target.files;
2708
- if (!files) return;
2709
- var newFiles = Array.from(files).map(function(file) {
2710
- var id = optimisticId();
2711
- createFile({
2712
- file: file
2713
- }, {
2714
- onSuccess: function(param) {
2715
- var file2 = param.file;
2716
- setFiles(function(prev) {
2717
- return _to_consumable_array(prev.filter(function(prevFile) {
2718
- return prevFile.id !== id;
2719
- })).concat([
2720
- file2
2721
- ]);
2722
- });
2723
- },
2724
- onError: function() {
2725
- addToast({
2726
- type: "error",
2727
- message: "Could not upload file. Please try again."
2728
- });
2729
- setFiles(function(prev) {
2730
- return prev.filter(function(prevFile) {
2731
- return prevFile.id !== id;
2762
+ var onChange = useCallback2(function() {
2763
+ var _ref = _async_to_generator(function(event) {
2764
+ var fileObjects, newFiles, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, err;
2765
+ return _ts_generator(this, function(_state) {
2766
+ switch(_state.label){
2767
+ case 0:
2768
+ fileObjects = event.target.files;
2769
+ if (!fileObjects) return [
2770
+ 2
2771
+ ];
2772
+ newFiles = Array.from(fileObjects).map(function(fileObject) {
2773
+ return {
2774
+ id: optimisticId(),
2775
+ filename: fileObject.name,
2776
+ object: "file",
2777
+ purpose: "assistants",
2778
+ created_at: dayjs2().unix(),
2779
+ bytes: fileObject.size,
2780
+ status: "processed",
2781
+ fileObject: fileObject
2782
+ };
2732
2783
  });
2733
- });
2784
+ setFiles(function(prev) {
2785
+ return _to_consumable_array(prev).concat(_to_consumable_array(newFiles.map(function(file) {
2786
+ return omit4(file, [
2787
+ "fileObject"
2788
+ ]);
2789
+ })));
2790
+ });
2791
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
2792
+ _state.label = 1;
2793
+ case 1:
2794
+ _state.trys.push([
2795
+ 1,
2796
+ 7,
2797
+ 8,
2798
+ 13
2799
+ ]);
2800
+ _loop = function() {
2801
+ var _value, newFile;
2802
+ return _ts_generator(this, function(_state) {
2803
+ switch(_state.label){
2804
+ case 0:
2805
+ _value = _step.value;
2806
+ newFile = _value;
2807
+ return [
2808
+ 4,
2809
+ createFile({
2810
+ file: newFile.fileObject
2811
+ }, {
2812
+ onSuccess: function(param) {
2813
+ var file = param.file;
2814
+ return setFiles(function(prev) {
2815
+ return _to_consumable_array(prev.filter(function(prevFile) {
2816
+ return prevFile.id !== newFile.id;
2817
+ })).concat([
2818
+ file
2819
+ ]);
2820
+ });
2821
+ },
2822
+ onError: function() {
2823
+ addToast({
2824
+ type: "error",
2825
+ message: "Could not upload file. Please try again."
2826
+ });
2827
+ setFiles(function(prev) {
2828
+ return prev.filter(function(prevFile) {
2829
+ return prevFile.id !== newFile.id;
2830
+ });
2831
+ });
2832
+ }
2833
+ })
2834
+ ];
2835
+ case 1:
2836
+ _state.sent();
2837
+ return [
2838
+ 2
2839
+ ];
2840
+ }
2841
+ });
2842
+ };
2843
+ _iterator = _async_iterator(newFiles);
2844
+ _state.label = 2;
2845
+ case 2:
2846
+ return [
2847
+ 4,
2848
+ _iterator.next()
2849
+ ];
2850
+ case 3:
2851
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
2852
+ 3,
2853
+ 6
2854
+ ];
2855
+ return [
2856
+ 5,
2857
+ _ts_values(_loop())
2858
+ ];
2859
+ case 4:
2860
+ _state.sent();
2861
+ _state.label = 5;
2862
+ case 5:
2863
+ _iteratorAbruptCompletion = false;
2864
+ return [
2865
+ 3,
2866
+ 2
2867
+ ];
2868
+ case 6:
2869
+ return [
2870
+ 3,
2871
+ 13
2872
+ ];
2873
+ case 7:
2874
+ err = _state.sent();
2875
+ _didIteratorError = true;
2876
+ _iteratorError = err;
2877
+ return [
2878
+ 3,
2879
+ 13
2880
+ ];
2881
+ case 8:
2882
+ _state.trys.push([
2883
+ 8,
2884
+ ,
2885
+ 11,
2886
+ 12
2887
+ ]);
2888
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
2889
+ 3,
2890
+ 10
2891
+ ];
2892
+ return [
2893
+ 4,
2894
+ _iterator.return()
2895
+ ];
2896
+ case 9:
2897
+ _state.sent();
2898
+ _state.label = 10;
2899
+ case 10:
2900
+ return [
2901
+ 3,
2902
+ 12
2903
+ ];
2904
+ case 11:
2905
+ if (_didIteratorError) {
2906
+ throw _iteratorError;
2907
+ }
2908
+ return [
2909
+ 7
2910
+ ];
2911
+ case 12:
2912
+ return [
2913
+ 7
2914
+ ];
2915
+ case 13:
2916
+ return [
2917
+ 2
2918
+ ];
2734
2919
  }
2735
2920
  });
2736
- return {
2737
- id: id,
2738
- filename: file.name,
2739
- object: "file",
2740
- purpose: "assistants",
2741
- created_at: dayjs2().unix(),
2742
- bytes: file.size,
2743
- status: "processed"
2744
- };
2745
- });
2746
- setFiles(function(prev) {
2747
- return _to_consumable_array(prev).concat(_to_consumable_array(newFiles));
2748
2921
  });
2749
- }, []);
2922
+ return function(event) {
2923
+ return _ref.apply(this, arguments);
2924
+ };
2925
+ }(), [
2926
+ addToast,
2927
+ createFile,
2928
+ setFiles
2929
+ ]);
2750
2930
  return /* @__PURE__ */ jsx50(Flex16, {
2751
2931
  pt: "2",
2752
2932
  pr: "2",
@@ -2764,6 +2944,7 @@ var Control2 = function() {
2764
2944
  /* @__PURE__ */ jsx50(FilePlusIcon, {}),
2765
2945
  /* @__PURE__ */ jsx50("input", {
2766
2946
  type: "file",
2947
+ multiple: true,
2767
2948
  accept: accept,
2768
2949
  onChange: onChange,
2769
2950
  style: {