@ancon/wildcat-utils 1.40.33 → 1.40.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.40.33",
3
+ "version": "1.40.34",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -1 +1 @@
1
- "use strict";const o=require("react"),k=require("dayjs"),j=require("@ancon/wildcat-printing"),G=require("../shared/hooks/usePrevious.js"),I=require("../shared/hooks/useMountedRef.js"),e=require("./types.js"),R=["TSP654"],V=1;function z(b,q,L,N,O=!1){const{useAppStore:T,useStarPrinterDiscover:_}=q,{selectedClientPrinterSelector:F}=L;function M(){const t=I(),g=T(),p=_(),l=o.useRef(void 0),[s,x]=o.useState(b),[a,P]=o.useState(),[S,f]=o.useState(),D=G(S),[A,v]=o.useState(),[U,w]=o.useState(N),r=o.useCallback(c=>{t!=null&&t.current&&x(c)},[t]),h=o.useCallback(async c=>{var u;(u=l.current)==null||u.stop(),r(e.StarCloudScanStatus.ScanningComplete);const i=String.fromCharCode(...c).trim();w(O?i.replace(/[\D]/gi,""):i)},[r]),m=o.useCallback(async({macAddress:c,ipAddress:i})=>{function u(n){r(e.StarCloudScanStatus.CommunicationError),t!=null&&t.current&&v(n==null?void 0:n.message)}const d={inputDevice:{onConnected:()=>{const n=((a==null?void 0:a.inputDeviceCount)||0)+1;r(n>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),P({inputDeviceCount:n,lastConnectedOn:new Date})},onDisconnected:()=>{const n=((a==null?void 0:a.inputDeviceCount)||0)-1>=0?((a==null?void 0:a.inputDeviceCount)||0)-1:0;r(n>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),P({inputDeviceCount:n})},onCommunicationError:u,onDataReceived:n=>f({data:n,lastReceivedOn:new Date})}};if(l.current=j.monitor(i||c,d),t!=null&&t.current)try{await l.current.start()}catch(n){r(e.StarCloudScanStatus.CommunicationError),t!=null&&t.current&&v(n==null?void 0:n.message)}},[a,r,t]),y=o.useCallback(async()=>{t!=null&&t.current&&(r(e.StarCloudScanStatus.WaitingForPrinter),v(void 0),f(void 0),P(void 0),w(void 0));const c=F(g.getState()),{macAddress:i,serialNumber:u}=c;try{const n=(await p(2e3)).find(C=>i&&C.macAddress.toLowerCase()===i.toLowerCase()||u&&C.serialNumber===u);if(t!=null&&t.current){if(n){if(R.some(C=>{var E;return(E=n.model)==null?void 0:E.toLowerCase().includes(C.toLowerCase())})){r(e.StarCloudScanStatus.UnsupportedPrinter);return}m(n)}r(n?e.StarCloudScanStatus.PrinterDetected:e.StarCloudScanStatus.PrinterNotDetected)}}catch{t!=null&&t.current&&r(e.StarCloudScanStatus.PrinterNotDetected)}},[t,g,r,p,m]),W=s===e.StarCloudScanStatus.WaitingForPrinter||s===e.StarCloudScanStatus.PrinterDetected||s===e.StarCloudScanStatus.ReadyToScan||s===e.StarCloudScanStatus.ScanningComplete,H=s===e.StarCloudScanStatus.PrinterNotDetected||s===e.StarCloudScanStatus.ScanFailed||s===e.StarCloudScanStatus.CommunicationError||s===e.StarCloudScanStatus.UnsupportedPrinter;return o.useEffect(()=>{if(!D&&(S==null?void 0:S.data)&&a&&(a!=null&&a.lastConnectedOn)){const{lastConnectedOn:i}=a,{lastReceivedOn:u,data:d}=S;k(u).diff(k(i),"second",!0)>V?h(d):f(void 0)}},[S,D,a,h]),o.useEffect(()=>(s===e.StarCloudScanStatus.WaitingForPrinter&&y(),()=>{var c;(c=l.current)==null||c.stop()}),[]),{startScan:y,changeDeviceStatus:r,scanStatus:s,reading:U,connectionError:A,isLoading:W,isError:H}}return M}module.exports=z;
1
+ "use strict";const o=require("react"),k=require("dayjs"),R=require("@ancon/wildcat-printing"),j=require("../shared/hooks/usePrevious.js"),G=require("../shared/hooks/useMountedRef.js"),e=require("./types.js"),I=["TSP654"],V=1;function z(b,q,L,O,T=!1){const{useAppStore:N,useStarPrinterDiscover:_}=q,{selectedClientPrinterSelector:F}=L;function M(){const n=G(),v=N(),D=_(),f=o.useRef(void 0),[s,x]=o.useState(b),[a,l]=o.useState(),[S,P]=o.useState(),g=j(S),[A,p]=o.useState(),[U,w]=o.useState(O),r=o.useCallback(c=>{n!=null&&n.current&&x(c)},[n]),y=o.useCallback(async c=>{var i;(i=f.current)==null||i.stop(),r(e.StarCloudScanStatus.ScanningComplete);const u=String.fromCharCode(...c).trim();w(T?u.replace(/[\D]/gi,""):u)},[r]),h=o.useCallback(async({macAddress:c,ipAddress:u})=>{function i(t){r(e.StarCloudScanStatus.CommunicationError),n!=null&&n.current&&p(t==null?void 0:t.message)}const C={onStarted:t=>{if(t&&t.inputDevicesCount>0){const{inputDevicesCount:d}=t;r(e.StarCloudScanStatus.ReadyToScan),l({inputDeviceCount:d,lastConnectedOn:new Date})}},onStopped:t=>{t&&i(t),l(void 0)},inputDevice:{onConnected:()=>{const t=((a==null?void 0:a.inputDeviceCount)||0)+1;r(t>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),l({inputDeviceCount:t,lastConnectedOn:new Date})},onDisconnected:()=>{const t=((a==null?void 0:a.inputDeviceCount)||0)-1>=0?((a==null?void 0:a.inputDeviceCount)||0)-1:0;r(t>0?e.StarCloudScanStatus.ReadyToScan:e.StarCloudScanStatus.PrinterDetected),l({inputDeviceCount:t})},onCommunicationError:i,onDataReceived:t=>P({data:t,lastReceivedOn:new Date})}};if(f.current=R.monitor(u||c,C),n!=null&&n.current)try{await f.current.start()}catch(t){r(e.StarCloudScanStatus.CommunicationError),n!=null&&n.current&&p(t==null?void 0:t.message)}},[a,r,n]),m=o.useCallback(async()=>{n!=null&&n.current&&(r(e.StarCloudScanStatus.WaitingForPrinter),p(void 0),P(void 0),l(void 0),w(void 0));const c=F(v.getState()),{macAddress:u,serialNumber:i}=c;try{const t=(await D(2e3)).find(d=>u&&d.macAddress.toLowerCase()===u.toLowerCase()||i&&d.serialNumber===i);if(n!=null&&n.current){if(t){if(I.some(d=>{var E;return(E=t.model)==null?void 0:E.toLowerCase().includes(d.toLowerCase())})){r(e.StarCloudScanStatus.UnsupportedPrinter);return}h(t)}r(t?e.StarCloudScanStatus.PrinterDetected:e.StarCloudScanStatus.PrinterNotDetected)}}catch{n!=null&&n.current&&r(e.StarCloudScanStatus.PrinterNotDetected)}},[n,v,r,D,h]),W=s===e.StarCloudScanStatus.WaitingForPrinter||s===e.StarCloudScanStatus.PrinterDetected||s===e.StarCloudScanStatus.ReadyToScan||s===e.StarCloudScanStatus.ScanningComplete,H=s===e.StarCloudScanStatus.PrinterNotDetected||s===e.StarCloudScanStatus.ScanFailed||s===e.StarCloudScanStatus.CommunicationError||s===e.StarCloudScanStatus.UnsupportedPrinter;return o.useEffect(()=>{if(!g&&(S==null?void 0:S.data)&&a&&(a!=null&&a.lastConnectedOn)){const{lastConnectedOn:u}=a,{lastReceivedOn:i,data:C}=S;k(i).diff(k(u),"second",!0)>V?y(C):P(void 0)}},[S,g,a,y]),o.useEffect(()=>(s===e.StarCloudScanStatus.WaitingForPrinter&&m(),()=>{var c;(c=f.current)==null||c.stop()}),[]),{startScan:m,changeDeviceStatus:r,scanStatus:s,reading:U,connectionError:A,isLoading:W,isError:H}}return M}module.exports=z;
@@ -1,118 +1,130 @@
1
- import { useRef as V, useState as l, useCallback as f, useEffect as N } from "react";
2
- import O from "dayjs";
1
+ import { useRef as V, useState as S, useCallback as p, useEffect as O } from "react";
2
+ import T from "dayjs";
3
3
  import { monitor as q } from "@ancon/wildcat-printing";
4
4
  import z from "../shared/hooks/usePrevious.mjs";
5
5
  import B from "../shared/hooks/useMountedRef.mjs";
6
6
  import { StarCloudScanStatus as e } from "./types.mjs";
7
7
  const J = ["TSP654"], K = 1;
8
- function tt(T, k, F, M, b = !1) {
8
+ function tt(N, k, F, M, b = !1) {
9
9
  const { useAppStore: x, useStarPrinterDiscover: A } = k, { selectedClientPrinterSelector: U } = F;
10
10
  function W() {
11
- const t = B(), v = x(), D = A(), C = V(void 0), [i, H] = l(T), [r, m] = l(), [d, P] = l(), g = z(d), [j, p] = l(), [G, w] = l(M), o = f(
11
+ const n = B(), P = x(), D = A(), f = V(void 0), [i, H] = S(N), [o, C] = S(), [d, m] = S(), g = z(d), [R, v] = S(), [j, w] = S(M), r = p(
12
12
  (c) => {
13
- t != null && t.current && H(c);
13
+ n != null && n.current && H(c);
14
14
  },
15
- [t]
16
- ), y = f(
15
+ [n]
16
+ ), y = p(
17
17
  async (c) => {
18
- var a;
19
- (a = C.current) == null || a.stop(), o(e.ScanningComplete);
20
- const s = String.fromCharCode(...c).trim();
18
+ var s;
19
+ (s = f.current) == null || s.stop(), r(e.ScanningComplete);
20
+ const a = String.fromCharCode(...c).trim();
21
21
  w(
22
- b ? s.replace(/[\D]/gi, "") : s
22
+ b ? a.replace(/[\D]/gi, "") : a
23
23
  );
24
24
  },
25
- [o]
26
- ), E = f(
27
- async ({ macAddress: c, ipAddress: s }) => {
28
- function a(n) {
29
- o(e.CommunicationError), t != null && t.current && p(n == null ? void 0 : n.message);
25
+ [r]
26
+ ), E = p(
27
+ async ({ macAddress: c, ipAddress: a }) => {
28
+ function s(t) {
29
+ r(e.CommunicationError), n != null && n.current && v(t == null ? void 0 : t.message);
30
30
  }
31
- const u = {
31
+ const l = {
32
+ onStarted: (t) => {
33
+ if (t && t.inputDevicesCount > 0) {
34
+ const { inputDevicesCount: u } = t;
35
+ r(e.ReadyToScan), C({
36
+ inputDeviceCount: u,
37
+ lastConnectedOn: /* @__PURE__ */ new Date()
38
+ });
39
+ }
40
+ },
41
+ onStopped: (t) => {
42
+ t && s(t), C(void 0);
43
+ },
32
44
  inputDevice: {
33
45
  onConnected: () => {
34
- const n = ((r == null ? void 0 : r.inputDeviceCount) || 0) + 1;
35
- o(
36
- n > 0 ? e.ReadyToScan : e.PrinterDetected
37
- ), m({
38
- inputDeviceCount: n,
46
+ const t = ((o == null ? void 0 : o.inputDeviceCount) || 0) + 1;
47
+ r(
48
+ t > 0 ? e.ReadyToScan : e.PrinterDetected
49
+ ), C({
50
+ inputDeviceCount: t,
39
51
  lastConnectedOn: /* @__PURE__ */ new Date()
40
52
  });
41
53
  },
42
54
  onDisconnected: () => {
43
- const n = ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 >= 0 ? ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 : 0;
44
- o(
45
- n > 0 ? e.ReadyToScan : e.PrinterDetected
46
- ), m({
47
- inputDeviceCount: n
55
+ const t = ((o == null ? void 0 : o.inputDeviceCount) || 0) - 1 >= 0 ? ((o == null ? void 0 : o.inputDeviceCount) || 0) - 1 : 0;
56
+ r(
57
+ t > 0 ? e.ReadyToScan : e.PrinterDetected
58
+ ), C({
59
+ inputDeviceCount: t
48
60
  });
49
61
  },
50
- onCommunicationError: a,
51
- onDataReceived: (n) => P({ data: n, lastReceivedOn: /* @__PURE__ */ new Date() })
62
+ onCommunicationError: s,
63
+ onDataReceived: (t) => m({ data: t, lastReceivedOn: /* @__PURE__ */ new Date() })
52
64
  }
53
65
  };
54
- if (C.current = q(s || c, u), t != null && t.current)
66
+ if (f.current = q(a || c, l), n != null && n.current)
55
67
  try {
56
- await C.current.start();
57
- } catch (n) {
58
- o(e.CommunicationError), t != null && t.current && p(n == null ? void 0 : n.message);
68
+ await f.current.start();
69
+ } catch (t) {
70
+ r(e.CommunicationError), n != null && n.current && v(t == null ? void 0 : t.message);
59
71
  }
60
72
  },
61
- [r, o, t]
62
- ), h = f(async () => {
63
- t != null && t.current && (o(e.WaitingForPrinter), p(void 0), P(void 0), m(void 0), w(void 0));
64
- const c = U(v.getState()), { macAddress: s, serialNumber: a } = c;
73
+ [o, r, n]
74
+ ), h = p(async () => {
75
+ n != null && n.current && (r(e.WaitingForPrinter), v(void 0), m(void 0), C(void 0), w(void 0));
76
+ const c = U(P.getState()), { macAddress: a, serialNumber: s } = c;
65
77
  try {
66
- const n = (await D(2e3)).find(
67
- (S) => s && S.macAddress.toLowerCase() === s.toLowerCase() || a && S.serialNumber === a
78
+ const t = (await D(2e3)).find(
79
+ (u) => a && u.macAddress.toLowerCase() === a.toLowerCase() || s && u.serialNumber === s
68
80
  );
69
- if (t != null && t.current) {
70
- if (n) {
81
+ if (n != null && n.current) {
82
+ if (t) {
71
83
  if (J.some(
72
- (S) => {
84
+ (u) => {
73
85
  var L;
74
- return (L = n.model) == null ? void 0 : L.toLowerCase().includes(S.toLowerCase());
86
+ return (L = t.model) == null ? void 0 : L.toLowerCase().includes(u.toLowerCase());
75
87
  }
76
88
  )) {
77
- o(e.UnsupportedPrinter);
89
+ r(e.UnsupportedPrinter);
78
90
  return;
79
91
  }
80
- E(n);
92
+ E(t);
81
93
  }
82
- o(
83
- n ? e.PrinterDetected : e.PrinterNotDetected
94
+ r(
95
+ t ? e.PrinterDetected : e.PrinterNotDetected
84
96
  );
85
97
  }
86
98
  } catch {
87
- t != null && t.current && o(e.PrinterNotDetected);
99
+ n != null && n.current && r(e.PrinterNotDetected);
88
100
  }
89
101
  }, [
90
- t,
91
- v,
92
- o,
102
+ n,
103
+ P,
104
+ r,
93
105
  D,
94
106
  E
95
- ]), I = i === e.WaitingForPrinter || i === e.PrinterDetected || i === e.ReadyToScan || i === e.ScanningComplete, R = i === e.PrinterNotDetected || i === e.ScanFailed || i === e.CommunicationError || i === e.UnsupportedPrinter;
96
- return N(() => {
97
- if (!g && (d == null ? void 0 : d.data) && r && (r != null && r.lastConnectedOn)) {
98
- const { lastConnectedOn: s } = r, { lastReceivedOn: a, data: u } = d;
99
- O(a).diff(
100
- O(s),
107
+ ]), G = i === e.WaitingForPrinter || i === e.PrinterDetected || i === e.ReadyToScan || i === e.ScanningComplete, I = i === e.PrinterNotDetected || i === e.ScanFailed || i === e.CommunicationError || i === e.UnsupportedPrinter;
108
+ return O(() => {
109
+ if (!g && (d == null ? void 0 : d.data) && o && (o != null && o.lastConnectedOn)) {
110
+ const { lastConnectedOn: a } = o, { lastReceivedOn: s, data: l } = d;
111
+ T(s).diff(
112
+ T(a),
101
113
  "second",
102
114
  !0
103
- ) > K ? y(u) : P(void 0);
115
+ ) > K ? y(l) : m(void 0);
104
116
  }
105
- }, [d, g, r, y]), N(() => (i === e.WaitingForPrinter && h(), () => {
117
+ }, [d, g, o, y]), O(() => (i === e.WaitingForPrinter && h(), () => {
106
118
  var c;
107
- (c = C.current) == null || c.stop();
119
+ (c = f.current) == null || c.stop();
108
120
  }), []), {
109
121
  startScan: h,
110
- changeDeviceStatus: o,
122
+ changeDeviceStatus: r,
111
123
  scanStatus: i,
112
- reading: G,
113
- connectionError: j,
114
- isLoading: I,
115
- isError: R
124
+ reading: j,
125
+ connectionError: R,
126
+ isLoading: G,
127
+ isError: I
116
128
  };
117
129
  }
118
130
  return W;